mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
!274 新增需求:支持通过config.json静态配置公共事件,支持通过wokscheduler静态拉起订阅者。
Merge pull request !274 from JayLeeHW/static_subscriber
This commit is contained in:
@@ -84,6 +84,35 @@ config("ability_public_config") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("static_subscriber_ipc") {
|
||||
include_dirs = [
|
||||
"${SUBSYSTEM_DIR}/include",
|
||||
"//base/notification/ces_standard/interfaces/innerkits/native/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content/",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${SUBSYSTEM_DIR}/src/static_subscriber_proxy.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/static_subscriber_stub.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:want",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
subsystem_name = "aafwk"
|
||||
part_name = "aafwk_standard"
|
||||
}
|
||||
|
||||
ohos_shared_library("abilitykit_native") {
|
||||
include_dirs = [
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/native_rdb",
|
||||
@@ -118,22 +147,26 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${SUBSYSTEM_DIR}/src/extension_base.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/extension_impl.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_runtime/form_extension_provider_client.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_runtime/js_form_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_runtime/js_form_extension_context.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/js_service_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/js_service_extension_context.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/service_extension.cpp",
|
||||
|
||||
#"${SUBSYSTEM_DIR}/src/dummy_data_ability_predicates.cpp",
|
||||
#"${SUBSYSTEM_DIR}/src/dummy_result_set.cpp",
|
||||
#"${SUBSYSTEM_DIR}/src/dummy_values_bucket.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_js_event_handler.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_provider_client.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_runtime/form_extension_provider_client.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_runtime/js_form_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/form_runtime/js_form_extension_context.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/js_service_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/js_service_extension_context.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/js_static_subscriber_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/js_static_subscriber_extension_context.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/mission_information.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/new_ability_impl.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/page_ability_impl.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/service_ability_impl.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/service_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/static_subscriber_extension.cpp",
|
||||
"${SUBSYSTEM_DIR}/src/static_subscriber_stub_imp.cpp",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/src/ability_start_setting.cpp",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/src/launch_param.cpp",
|
||||
|
||||
@@ -166,6 +199,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/extension_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/form_extension_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/service_extension_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/static_subscriber_extension_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/application_context.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/context_container.cpp",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/src/context_deal.cpp",
|
||||
@@ -189,6 +223,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
":static_subscriber_ipc",
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
|
||||
@@ -213,6 +248,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"aafwk_standard:runtime",
|
||||
"appexecfwk_standard:fmskit_native",
|
||||
"bytrace_standard:bytrace_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ipc_js:rpc",
|
||||
|
||||
@@ -123,7 +123,6 @@ public:
|
||||
* @return None.
|
||||
*/
|
||||
void SetCompatibleVersion(int compatibleVersion);
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr;
|
||||
sptr<IRemoteObject> token_;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APPEXECFWK_I_STATIC_SUBSCRIBER_H
|
||||
#define OHOS_APPEXECFWK_I_STATIC_SUBSCRIBER_H
|
||||
|
||||
#include <string_ex.h>
|
||||
#include <iremote_broker.h>
|
||||
#include "common_event_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using EventFwk::CommonEventData;
|
||||
|
||||
class IStaticSubscriber : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AppExecFwk.IStaticSubscriber");
|
||||
|
||||
/**
|
||||
* @brief Called when subscriber received common event.
|
||||
*
|
||||
* @param data Indicates the common event data..
|
||||
*/
|
||||
virtual ErrCode OnCommonEventTriggered(CommonEventData* data) = 0;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_APPEXECFWK_I_STATIC_SUBSCRIBER_H
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ABILITYRUNTIME_OHOS_JS_STATIC_SUBSCRIBER_EXTENSION_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_JS_STATIC_SUBSCRIBER_EXTENSION_H
|
||||
|
||||
#include "common_event_data.h"
|
||||
#include "static_subscriber_extension.h"
|
||||
|
||||
class NativeReference;
|
||||
class NativeValue;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class JsRuntime;
|
||||
/**
|
||||
* @brief js-level static subscriber extension.
|
||||
*/
|
||||
class JsStaticSubscriberExtension : public StaticSubscriberExtension {
|
||||
public:
|
||||
JsStaticSubscriberExtension(JsRuntime& jsRuntime);
|
||||
virtual ~JsStaticSubscriberExtension() override;
|
||||
|
||||
/**
|
||||
* @brief Create JsStaticSubscriberExtension.
|
||||
*
|
||||
* @param runtime The runtime.
|
||||
* @return The JsStaticSubscriberExtension instance.
|
||||
*/
|
||||
static JsStaticSubscriberExtension* Create(const std::unique_ptr<Runtime>& runtime);
|
||||
|
||||
void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
|
||||
const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
|
||||
const sptr<IRemoteObject>& token) override;
|
||||
|
||||
void OnStart(const AAFwk::Want& want) override;
|
||||
|
||||
sptr<IRemoteObject> OnConnect(const AAFwk::Want& want) override;
|
||||
|
||||
void OnDisconnect(const AAFwk::Want& want) override;
|
||||
|
||||
void OnStop() override;
|
||||
|
||||
void OnCommonEventTriggered(EventFwk::CommonEventData* data) override;
|
||||
private:
|
||||
JsRuntime& jsRuntime_;
|
||||
std::unique_ptr<NativeReference> jsObj_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_JS_STATIC_SUBSCRIBER_EXTENSION_H
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ABILITY_RUNTIME_JS_STATIC_SUBSCRIBER_EXTENSION_CONTEXT_H
|
||||
#define ABILITY_RUNTIME_JS_STATIC_SUBSCRIBER_EXTENSION_CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "static_subscriber_extension_context.h"
|
||||
|
||||
class NativeEngine;
|
||||
class NativeValue;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue* CreateJsStaticSubscriberExtensionContext(NativeEngine& engine,
|
||||
std::shared_ptr<StaticSubscriberExtensionContext> context);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_JS_STATIC_SUBSCRIBER_EXTENSION_CONTEXT_H
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ABILITYRUNTIME_OHOS_STATIC_SUBSCRIBER_EXTENSION_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_STATIC_SUBSCRIBER_EXTENSION_H
|
||||
|
||||
#include "common_event_data.h"
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class StaticSubscriberExtensionContext;
|
||||
class Runtime;
|
||||
|
||||
class StaticSubscriberExtension : public ExtensionBase<StaticSubscriberExtensionContext> {
|
||||
public:
|
||||
StaticSubscriberExtension() = default;
|
||||
virtual ~StaticSubscriberExtension() = default;
|
||||
|
||||
std::shared_ptr<StaticSubscriberExtensionContext> CreateAndInitContext(
|
||||
const std::shared_ptr<AbilityLocalRecord>& record,
|
||||
const std::shared_ptr<OHOSApplication>& application,
|
||||
std::shared_ptr<AbilityHandler>& handler,
|
||||
const sptr<IRemoteObject>& token) override;
|
||||
|
||||
void Init(const std::shared_ptr<AbilityLocalRecord>& record,
|
||||
const std::shared_ptr<OHOSApplication>& application,
|
||||
std::shared_ptr<AbilityHandler>& handler,
|
||||
const sptr<IRemoteObject>& token) override;
|
||||
|
||||
static StaticSubscriberExtension* Create(const std::unique_ptr<Runtime>& runtime);
|
||||
|
||||
virtual void OnCommonEventTriggered(EventFwk::CommonEventData* data);
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_STATIC_SUBSCRIBER_EXTENSION_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APPEXECFWK_STATIC_SUBSCRIBER_PROXY_H
|
||||
#define OHOS_APPEXECFWK_STATIC_SUBSCRIBER_PROXY_H
|
||||
|
||||
#include <iremote_proxy.h>
|
||||
#include "istatic_subscriber.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class StaticSubscriberProxy : public IRemoteProxy<IStaticSubscriber> {
|
||||
public:
|
||||
explicit StaticSubscriberProxy(const sptr<IRemoteObject>& remote)
|
||||
: IRemoteProxy<IStaticSubscriber>(remote) {}
|
||||
|
||||
virtual ~StaticSubscriberProxy() {}
|
||||
|
||||
ErrCode OnCommonEventTriggered(CommonEventData* data) override;
|
||||
|
||||
private:
|
||||
static constexpr int COMMAND_ON_COMMON_EVENT_TRIGGERED = MIN_TRANSACTION_ID;
|
||||
|
||||
static inline BrokerDelegator<StaticSubscriberProxy> delegator_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_APPEXECFWK_STATIC_SUBSCRIBER_PROXY_H
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APPEXECFWK_STATIC_SUBSCRIBER_STUB_H
|
||||
#define OHOS_APPEXECFWK_STATIC_SUBSCRIBER_STUB_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include "istatic_subscriber.h"
|
||||
#include "static_subscriber_extension.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class StaticSubscriberStub : public IRemoteStub<IStaticSubscriber> {
|
||||
public:
|
||||
StaticSubscriberStub() {}
|
||||
|
||||
virtual ~StaticSubscriberStub() {}
|
||||
|
||||
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
private:
|
||||
static constexpr int COMMAND_ON_COMMON_EVENT_TRIGGERED = MIN_TRANSACTION_ID;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_APPEXECFWK_STATIC_SUBSCRIBER_STUB_H
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_APPEXECFWK_STATIC_SUBSCRIBER_STUB_IMP_H
|
||||
#define OHOS_APPEXECFWK_STATIC_SUBSCRIBER_STUB_IMP_H
|
||||
|
||||
#include <memory>
|
||||
#include "js_static_subscriber_extension.h"
|
||||
#include "static_subscriber_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
using AbilityRuntime::JsStaticSubscriberExtension;
|
||||
class StaticSubscriberStubImp : public StaticSubscriberStub {
|
||||
public:
|
||||
explicit StaticSubscriberStubImp(const std::shared_ptr<JsStaticSubscriberExtension>& extension)
|
||||
: extension_(extension) {}
|
||||
|
||||
virtual ~StaticSubscriberStubImp() {}
|
||||
|
||||
ErrCode OnCommonEventTriggered(CommonEventData* data) override;
|
||||
private:
|
||||
std::weak_ptr<JsStaticSubscriberExtension> extension_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_APPEXECFWK_STATIC_SUBSCRIBER_STUB_IMP_H
|
||||
|
||||
@@ -43,6 +43,7 @@ constexpr static char ACE_DATA_ABILITY_NAME[] = "AceDataAbility";
|
||||
constexpr static char ACE_FORM_ABILITY_NAME[] = "AceFormAbility";
|
||||
constexpr static char BASE_SERVICE_EXTENSION[] = "ServiceExtension";
|
||||
constexpr static char FORM_EXTENSION[] = "FormExtension";
|
||||
// constexpr static char STATIC_SUBSCRIBER_EXTENSION[] = "StaticSubscriberExtension";
|
||||
constexpr int TARGET_VERSION_THRESHOLDS = 8;
|
||||
|
||||
/**
|
||||
@@ -99,6 +100,9 @@ std::string AbilityThread::CreateAbilityName(const std::shared_ptr<AbilityLocalR
|
||||
} else if (abilityInfo->type == AbilityType::DATA) {
|
||||
abilityName = ACE_DATA_ABILITY_NAME;
|
||||
} else if (abilityInfo->type == AbilityType::EXTENSION) {
|
||||
/* if (abilityInfo->extensionAbilityType == ExtensionAbilityType::STATICSUBSCRIBER) {
|
||||
abilittName = STATIC_SUBSCRIBER_EXTENSION;
|
||||
} */
|
||||
abilityName = BASE_SERVICE_EXTENSION;
|
||||
if (abilityInfo->formEnabled == true) {
|
||||
abilityName = FORM_EXTENSION;
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "js_static_subscriber_extension.h"
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_static_subscriber_extension_context.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "static_subscriber_stub_imp.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
}
|
||||
|
||||
using namespace OHOS::AppExecFwk;
|
||||
JsStaticSubscriberExtension* JsStaticSubscriberExtension::Create(const std::unique_ptr<Runtime>& runtime)
|
||||
{
|
||||
return new JsStaticSubscriberExtension(static_cast<JsRuntime&>(*runtime));
|
||||
}
|
||||
|
||||
JsStaticSubscriberExtension::JsStaticSubscriberExtension(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime) {}
|
||||
JsStaticSubscriberExtension::~JsStaticSubscriberExtension() = default;
|
||||
|
||||
void JsStaticSubscriberExtension::Init(const std::shared_ptr<AbilityLocalRecord>& record,
|
||||
const std::shared_ptr<OHOSApplication>& application,
|
||||
std::shared_ptr<AbilityHandler>& handler,
|
||||
const sptr<IRemoteObject>& token)
|
||||
{
|
||||
StaticSubscriberExtension::Init(record, application, handler, token);
|
||||
std::string srcPath(Extension::abilityInfo_->package);
|
||||
srcPath.append("/assets/js/");
|
||||
if (!Extension::abilityInfo_->srcPath.empty()) {
|
||||
srcPath.append(Extension::abilityInfo_->srcPath);
|
||||
}
|
||||
srcPath.append("/").append(Extension::abilityInfo_->name).append(".abc");
|
||||
|
||||
std::string moduleName(Extension::abilityInfo_->moduleName);
|
||||
moduleName.append("::").append(abilityInfo_->name);
|
||||
HILOG_INFO("JsStaticSubscriberExtension::Init moduleName:%{public}s,srcPath:%{public}s.",
|
||||
moduleName.c_str(), srcPath.c_str());
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& engine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath);
|
||||
if (jsObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get jsObj_");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JsStaticSubscriberExtension::Init ConvertNativeValueTo.");
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(jsObj_->Get());
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get JsStaticSubscriberExtension object");
|
||||
return;
|
||||
}
|
||||
|
||||
auto context = GetContext();
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("Failed to get context");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JsStaticSubscriberExtension::Init CreateJsStaticSubscriberExtensionContext.");
|
||||
NativeValue* contextObj = CreateJsStaticSubscriberExtensionContext(engine, context);
|
||||
auto shellContextRef = jsRuntime_.LoadSystemModule("application.StaticSubscriberExtensionContext",
|
||||
&contextObj, ARGC_ONE);
|
||||
contextObj = shellContextRef->Get();
|
||||
HILOG_INFO("JsStaticSubscriberExtension::Init Bind.");
|
||||
context->Bind(jsRuntime_, shellContextRef.release());
|
||||
HILOG_INFO("JsStaticSubscriberExtension::SetProperty.");
|
||||
obj->SetProperty("context", contextObj);
|
||||
HILOG_INFO("JsStaticSubscriberExtension::Init end.");
|
||||
}
|
||||
|
||||
void JsStaticSubscriberExtension::OnStart(const AAFwk::Want& want)
|
||||
{
|
||||
Extension::OnStart(want);
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void JsStaticSubscriberExtension::OnStop()
|
||||
{
|
||||
Extension::OnStop();
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> JsStaticSubscriberExtension::OnConnect(const AAFwk::Want& want)
|
||||
{
|
||||
Extension::OnConnect(want);
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
sptr<StaticSubscriberStubImp> remoteObject = new (std::nothrow) StaticSubscriberStubImp(
|
||||
std::static_pointer_cast<JsStaticSubscriberExtension>(shared_from_this()));
|
||||
HILOG_INFO("%{public}s end. ", __func__);
|
||||
return remoteObject->AsObject();
|
||||
}
|
||||
|
||||
void JsStaticSubscriberExtension::OnDisconnect(const AAFwk::Want& want)
|
||||
{
|
||||
Extension::OnDisconnect(want);
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void JsStaticSubscriberExtension::OnCommonEventTriggered(EventFwk::CommonEventData* data)
|
||||
{
|
||||
StaticSubscriberExtension::OnCommonEventTriggered(data);
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
if (data == nullptr) {
|
||||
HILOG_ERROR("%{public}s common event data == nullptr", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
NativeValue* jCommonEventData = nativeEngine.CreateObject();
|
||||
NativeObject* commonEventData = ConvertNativeValueTo<NativeObject>(jCommonEventData);
|
||||
Want want = data->GetWant();
|
||||
commonEventData->SetProperty("event", nativeEngine.CreateString(want.GetAction().c_str(), want.GetAction().size()));
|
||||
commonEventData->SetProperty("bundleName", nativeEngine.CreateString(want.GetBundle().c_str(),
|
||||
want.GetBundle().size()));
|
||||
commonEventData->SetProperty("code", nativeEngine.CreateNumber(data->GetCode()));
|
||||
commonEventData->SetProperty("data", nativeEngine.CreateString(data->GetData().c_str(), data->GetData().size()));
|
||||
napi_value napiParams = AppExecFwk::WrapWantParams(reinterpret_cast<napi_env>(&nativeEngine), want.GetParams());
|
||||
NativeValue* nativeParams = reinterpret_cast<NativeValue*>(napiParams);
|
||||
commonEventData->SetProperty("parameters", nativeParams);
|
||||
|
||||
NativeValue* argv[] = {jCommonEventData};
|
||||
if (!jsObj_) {
|
||||
HILOG_WARN("Not found StaticSubscriberExtension.js");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* value = jsObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get StaticSubscriberExtension object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onCommonEventTriggered");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onCommonEventTriggered from StaticSubscriberExtension object");
|
||||
return;
|
||||
}
|
||||
nativeEngine.CallFunction(value, method, argv, ARGC_ONE);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "js_static_subscriber_extension_context.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
#include "js_extension_context.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_common_want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
class JsStaticSubscriberExtensionContext final {
|
||||
public:
|
||||
explicit JsStaticSubscriberExtensionContext(const std::shared_ptr<StaticSubscriberExtensionContext>& context)
|
||||
: context_(context) {}
|
||||
~JsStaticSubscriberExtensionContext() = default;
|
||||
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
HILOG_INFO("JsStaticSubscriberExtensionContext::Finalizer is called");
|
||||
std::unique_ptr<JsStaticSubscriberExtensionContext>(
|
||||
static_cast<JsStaticSubscriberExtensionContext*>(data));
|
||||
}
|
||||
private:
|
||||
std::weak_ptr<StaticSubscriberExtensionContext> context_;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
NativeValue* CreateJsStaticSubscriberExtensionContext(NativeEngine& engine,
|
||||
std::shared_ptr<StaticSubscriberExtensionContext> context)
|
||||
{
|
||||
HILOG_INFO("CreateJsStaticSubscriberExtensionContext begin");
|
||||
NativeValue *objValue = CreateJsExtensionContext(engine, context);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
std::unique_ptr<JsStaticSubscriberExtensionContext> jsContext =
|
||||
std::make_unique<JsStaticSubscriberExtensionContext>(context);
|
||||
object->SetNativePointer(jsContext.release(), JsStaticSubscriberExtensionContext::Finalizer, nullptr);
|
||||
return objValue;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "static_subscriber_extension.h"
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "extension_base.cpp"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_static_subscriber_extension.h"
|
||||
#include "runtime.h"
|
||||
#include "static_subscriber_extension_context.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
StaticSubscriberExtension* StaticSubscriberExtension::Create(const std::unique_ptr<Runtime>& runtime)
|
||||
{
|
||||
if (!runtime) {
|
||||
return new StaticSubscriberExtension();
|
||||
}
|
||||
HILOG_INFO("StaticSubscriberExtension::Create runtime");
|
||||
switch (runtime->GetLanguage()) {
|
||||
case Runtime::Language::JS:
|
||||
return JsStaticSubscriberExtension::Create(runtime);
|
||||
|
||||
default:
|
||||
return new StaticSubscriberExtension();
|
||||
}
|
||||
}
|
||||
|
||||
void StaticSubscriberExtension::Init(const std::shared_ptr<AbilityLocalRecord>& record,
|
||||
const std::shared_ptr<OHOSApplication>& application,
|
||||
std::shared_ptr<AbilityHandler>& handler,
|
||||
const sptr<IRemoteObject>& token)
|
||||
{
|
||||
HILOG_INFO("StaticSubscriberExtension begin init");
|
||||
ExtensionBase<StaticSubscriberExtensionContext>::Init(record, application, handler, token);
|
||||
}
|
||||
|
||||
std::shared_ptr<StaticSubscriberExtensionContext> StaticSubscriberExtension::CreateAndInitContext(
|
||||
const std::shared_ptr<AbilityLocalRecord>& record,
|
||||
const std::shared_ptr<OHOSApplication>& application,
|
||||
std::shared_ptr<AbilityHandler>& handler,
|
||||
const sptr<IRemoteObject>& token)
|
||||
{
|
||||
std::shared_ptr<StaticSubscriberExtensionContext> context =
|
||||
ExtensionBase<StaticSubscriberExtensionContext>::CreateAndInitContext(record, application, handler, token);
|
||||
if (record == nullptr) {
|
||||
HILOG_ERROR("StaticSubscriberExtension::CreateAndInitContext record is nullptr");
|
||||
return context;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
void StaticSubscriberExtension::OnCommonEventTriggered(EventFwk::CommonEventData* data)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "static_subscriber_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
ErrCode StaticSubscriberProxy::OnCommonEventTriggered(CommonEventData* inData)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
data.WriteParcelable(inData);
|
||||
|
||||
int32_t st = Remote()->SendRequest(COMMAND_ON_COMMON_EVENT_TRIGGERED, data, reply, option);
|
||||
if (st != ERR_NONE) {
|
||||
return st;
|
||||
}
|
||||
|
||||
ErrCode ec = reply.ReadInt32();
|
||||
if (FAILED(ec)) {
|
||||
return ec;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "static_subscriber_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
int StaticSubscriberStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
|
||||
MessageOption& option)
|
||||
{
|
||||
switch (code) {
|
||||
case COMMAND_ON_COMMON_EVENT_TRIGGERED: {
|
||||
CommonEventData* inData = data.ReadParcelable<CommonEventData>();
|
||||
ErrCode ec = OnCommonEventTriggered(inData);
|
||||
reply.WriteInt32(ec);
|
||||
return ERR_NONE;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
return ERR_TRANSACTION_FAILED;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "static_subscriber_stub_imp.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
ErrCode StaticSubscriberStubImp::OnCommonEventTriggered(CommonEventData* data)
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
auto extension = extension_.lock();
|
||||
if (extension != nullptr) {
|
||||
extension->OnCommonEventTriggered(data);
|
||||
HILOG_INFO("%{public}s end successfully.", __func__);
|
||||
return 0;
|
||||
}
|
||||
HILOG_INFO("%{public}s end failed.", __func__);
|
||||
return -1;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -31,6 +31,8 @@ group("napi_packages") {
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/particleAbility:particleability",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/service_extension_context:serviceextensioncontext_napi",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/serviceextension:serviceextension_napi",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/static_subscriber_extension:staticsubscriberextension_napi",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/static_subscriber_extension_context:staticsubscriberextensioncontext_napi",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/wantConstant:wantconstant",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//ark/ts2abc/ts2panda/ts2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ts2abc_gen_abc("gen_static_subscriber_extension_abc") {
|
||||
src_js = rebase_path("static_subscriber_extension.js")
|
||||
dst_file = rebase_path(target_out_dir + "/static_subscriber_extension.abc")
|
||||
in_puts = [ "static_subscriber_extension.js" ]
|
||||
out_puts = [ target_out_dir + "/static_subscriber_extension.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("static_subscriber_extension_js") {
|
||||
input = "static_subscriber_extension.js"
|
||||
output = target_out_dir + "/static_subscriber_extension.o"
|
||||
}
|
||||
|
||||
gen_js_obj("static_subscriber_extension_abc") {
|
||||
input = get_label_info(":gen_static_subscriber_extension_abc",
|
||||
"target_out_dir") + "/static_subscriber_extension.abc"
|
||||
output = target_out_dir + "/static_subscriber_extension_abc.o"
|
||||
dep = ":gen_static_subscriber_extension_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("staticsubscriberextension_napi") {
|
||||
sources = [ "static_subscriber_extension_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":static_subscriber_extension_abc",
|
||||
":static_subscriber_extension_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/application"
|
||||
subsystem_name = "aafwk"
|
||||
part_name = "aafwk_standard"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class StaticSubscriberExtension {
|
||||
onCommonEventTriggered(event) {
|
||||
console.log('onCommonEventTriggered, event:' + event.code);
|
||||
}
|
||||
}
|
||||
|
||||
export default StaticSubscriberExtension
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_static_subscriber_extension_js_start[];
|
||||
extern const char _binary_static_subscriber_extension_js_end[];
|
||||
extern const char _binary_static_subscriber_extension_abc_start[];
|
||||
extern const char _binary_static_subscriber_extension_abc_end[];
|
||||
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_application_StaticSubscriberExtension_AutoRegister()
|
||||
{
|
||||
auto moduleManager = NativeModuleManager::GetInstance();
|
||||
NativeModule newModuleInfo = {
|
||||
.name = "application.StaticSubscriberExtension",
|
||||
.fileName = "application/libstaticsubscriberextension_napi.so/StaticSubscriberExtension.js",
|
||||
};
|
||||
|
||||
moduleManager->Register(&newModuleInfo);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_StaticSubscriberExtension_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_static_subscriber_extension_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_static_subscriber_extension_js_end -
|
||||
_binary_static_subscriber_extension_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// StaticSubscriberExtension JS register
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_StaticSubscriberExtension_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_static_subscriber_extension_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_static_subscriber_extension_abc_end -
|
||||
_binary_static_subscriber_extension_abc_start;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//ark/ts2abc/ts2panda/ts2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ts2abc_gen_abc("gen_static_subscriber_extension_context_abc") {
|
||||
src_js = rebase_path("static_subscriber_extension_context.js")
|
||||
dst_file =
|
||||
rebase_path(target_out_dir + "/static_subscriber_extension_context.abc")
|
||||
in_puts = [ "static_subscriber_extension_context.js" ]
|
||||
out_puts = [ target_out_dir + "/static_subscriber_extension_context.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("static_subscriber_extension_context_js") {
|
||||
input = "static_subscriber_extension_context.js"
|
||||
output = target_out_dir + "/static_subscriber_extension_context.o"
|
||||
}
|
||||
|
||||
gen_js_obj("static_subscriber_extension_context_abc") {
|
||||
input = get_label_info(":gen_static_subscriber_extension_context_abc",
|
||||
"target_out_dir") +
|
||||
"/static_subscriber_extension_context.abc"
|
||||
output = target_out_dir + "/static_subscriber_extension_context_abc.o"
|
||||
dep = ":gen_static_subscriber_extension_context_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("staticsubscriberextensioncontext_napi") {
|
||||
sources = [ "static_subscriber_extension_context_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":static_subscriber_extension_context_abc",
|
||||
":static_subscriber_extension_context_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/application"
|
||||
subsystem_name = "aafwk"
|
||||
part_name = "aafwk_standard"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var ExtensionContext = requireNapi("application.ExtensionContext")
|
||||
|
||||
class StaticSubscriberExtensionContext extends ExtensionContext {
|
||||
constructor(obj) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
||||
|
||||
export default StaticSubscriberExtensionContext
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_static_subscriber_extension_context_js_start[];
|
||||
extern const char _binary_static_subscriber_extension_context_js_end[];
|
||||
extern const char _binary_static_subscriber_extension_context_abc_start[];
|
||||
extern const char _binary_static_subscriber_extension_context_abc_end[];
|
||||
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_application_StaticSubscriberExtensionContext_AutoRegister()
|
||||
{
|
||||
auto moduleManager = NativeModuleManager::GetInstance();
|
||||
NativeModule newModuleInfo = {
|
||||
.name = "application.StaticSubscriberExtensionContext",
|
||||
.fileName = "application/libstaticsubscriberextensioncontext_napi.so/StaticSubscriberExtensionContext.js",
|
||||
};
|
||||
|
||||
moduleManager->Register(&newModuleInfo);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_StaticSubscriberExtensionContext_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_static_subscriber_extension_context_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_static_subscriber_extension_context_js_end -
|
||||
_binary_static_subscriber_extension_context_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// StaticSubscriberExtensionContext JS register
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_StaticSubscriberExtensionContext_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_static_subscriber_extension_context_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_static_subscriber_extension_context_abc_end -
|
||||
_binary_static_subscriber_extension_context_abc_start;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
"//foundation/aafwk/standard/tools:tools_target",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits:innerkits_target",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:static_subscriber_ipc",
|
||||
"//foundation/aafwk/standard/sa_profile:aafwk_sa_profile",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi:napi_packages",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_native",
|
||||
|
||||
Reference in New Issue
Block a user