diff --git a/frameworks/kits/ability/native/BUILD.gn b/frameworks/kits/ability/native/BUILD.gn index 1f2bbb6e55..2dccf83bef 100644 --- a/frameworks/kits/ability/native/BUILD.gn +++ b/frameworks/kits/ability/native/BUILD.gn @@ -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", diff --git a/frameworks/kits/ability/native/include/ability_local_record.h b/frameworks/kits/ability/native/include/ability_local_record.h index 5352b51e43..aedd0e9222 100644 --- a/frameworks/kits/ability/native/include/ability_local_record.h +++ b/frameworks/kits/ability/native/include/ability_local_record.h @@ -123,7 +123,6 @@ public: * @return None. */ void SetCompatibleVersion(int compatibleVersion); - private: std::shared_ptr abilityInfo_ = nullptr; sptr token_; diff --git a/frameworks/kits/ability/native/include/istatic_subscriber.h b/frameworks/kits/ability/native/include/istatic_subscriber.h new file mode 100644 index 0000000000..8ff87119b0 --- /dev/null +++ b/frameworks/kits/ability/native/include/istatic_subscriber.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_I_STATIC_SUBSCRIBER_H +#define OHOS_APPEXECFWK_I_STATIC_SUBSCRIBER_H + +#include +#include +#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 + diff --git a/frameworks/kits/ability/native/include/js_static_subscriber_extension.h b/frameworks/kits/ability/native/include/js_static_subscriber_extension.h new file mode 100644 index 0000000000..cabcb0bc0d --- /dev/null +++ b/frameworks/kits/ability/native/include/js_static_subscriber_extension.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); + + void Init(const std::shared_ptr& record, + const std::shared_ptr& application, + std::shared_ptr& handler, + const sptr& token) override; + + void OnStart(const AAFwk::Want& want) override; + + sptr 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 jsObj_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // FOUNDATION_ABILITYRUNTIME_OHOS_JS_STATIC_SUBSCRIBER_EXTENSION_H \ No newline at end of file diff --git a/frameworks/kits/ability/native/include/js_static_subscriber_extension_context.h b/frameworks/kits/ability/native/include/js_static_subscriber_extension_context.h new file mode 100644 index 0000000000..a1212a61ab --- /dev/null +++ b/frameworks/kits/ability/native/include/js_static_subscriber_extension_context.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 + +#include "static_subscriber_extension_context.h" + +class NativeEngine; +class NativeValue; + +namespace OHOS { +namespace AbilityRuntime { +NativeValue* CreateJsStaticSubscriberExtensionContext(NativeEngine& engine, + std::shared_ptr context); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // ABILITY_RUNTIME_JS_STATIC_SUBSCRIBER_EXTENSION_CONTEXT_H \ No newline at end of file diff --git a/frameworks/kits/ability/native/include/static_subscriber_extension.h b/frameworks/kits/ability/native/include/static_subscriber_extension.h new file mode 100644 index 0000000000..8555ae6fee --- /dev/null +++ b/frameworks/kits/ability/native/include/static_subscriber_extension.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 { +public: + StaticSubscriberExtension() = default; + virtual ~StaticSubscriberExtension() = default; + + std::shared_ptr CreateAndInitContext( + const std::shared_ptr& record, + const std::shared_ptr& application, + std::shared_ptr& handler, + const sptr& token) override; + + void Init(const std::shared_ptr& record, + const std::shared_ptr& application, + std::shared_ptr& handler, + const sptr& token) override; + + static StaticSubscriberExtension* Create(const std::unique_ptr& runtime); + + virtual void OnCommonEventTriggered(EventFwk::CommonEventData* data); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // FOUNDATION_ABILITYRUNTIME_OHOS_STATIC_SUBSCRIBER_EXTENSION_H \ No newline at end of file diff --git a/frameworks/kits/ability/native/include/static_subscriber_proxy.h b/frameworks/kits/ability/native/include/static_subscriber_proxy.h new file mode 100644 index 0000000000..e4a9eda063 --- /dev/null +++ b/frameworks/kits/ability/native/include/static_subscriber_proxy.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 +#include "istatic_subscriber.h" + +namespace OHOS { +namespace AppExecFwk { +class StaticSubscriberProxy : public IRemoteProxy { +public: + explicit StaticSubscriberProxy(const sptr& remote) + : IRemoteProxy(remote) {} + + virtual ~StaticSubscriberProxy() {} + + ErrCode OnCommonEventTriggered(CommonEventData* data) override; + +private: + static constexpr int COMMAND_ON_COMMON_EVENT_TRIGGERED = MIN_TRANSACTION_ID; + + static inline BrokerDelegator delegator_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_APPEXECFWK_STATIC_SUBSCRIBER_PROXY_H + diff --git a/frameworks/kits/ability/native/include/static_subscriber_stub.h b/frameworks/kits/ability/native/include/static_subscriber_stub.h new file mode 100644 index 0000000000..a1689dbe0d --- /dev/null +++ b/frameworks/kits/ability/native/include/static_subscriber_stub.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 +#include "istatic_subscriber.h" +#include "static_subscriber_extension.h" + +namespace OHOS { +namespace AppExecFwk { +class StaticSubscriberStub : public IRemoteStub { +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 + diff --git a/frameworks/kits/ability/native/include/static_subscriber_stub_imp.h b/frameworks/kits/ability/native/include/static_subscriber_stub_imp.h new file mode 100644 index 0000000000..4c607ce10a --- /dev/null +++ b/frameworks/kits/ability/native/include/static_subscriber_stub_imp.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 +#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& extension) + : extension_(extension) {} + + virtual ~StaticSubscriberStubImp() {} + + ErrCode OnCommonEventTriggered(CommonEventData* data) override; +private: + std::weak_ptr extension_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_APPEXECFWK_STATIC_SUBSCRIBER_STUB_IMP_H + diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index cee7f5e6f3..6b697f11ef 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -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_ptrtype == 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; diff --git a/frameworks/kits/ability/native/src/js_static_subscriber_extension.cpp b/frameworks/kits/ability/native/src/js_static_subscriber_extension.cpp new file mode 100644 index 0000000000..d3b16557d9 --- /dev/null +++ b/frameworks/kits/ability/native/src/js_static_subscriber_extension.cpp @@ -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) +{ + return new JsStaticSubscriberExtension(static_cast(*runtime)); +} + +JsStaticSubscriberExtension::JsStaticSubscriberExtension(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime) {} +JsStaticSubscriberExtension::~JsStaticSubscriberExtension() = default; + +void JsStaticSubscriberExtension::Init(const std::shared_ptr& record, + const std::shared_ptr& application, + std::shared_ptr& handler, + const sptr& 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(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 JsStaticSubscriberExtension::OnConnect(const AAFwk::Want& want) +{ + Extension::OnConnect(want); + HILOG_INFO("%{public}s begin.", __func__); + sptr remoteObject = new (std::nothrow) StaticSubscriberStubImp( + std::static_pointer_cast(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(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(&nativeEngine), want.GetParams()); + NativeValue* nativeParams = reinterpret_cast(napiParams); + commonEventData->SetProperty("parameters", nativeParams); + + NativeValue* argv[] = {jCommonEventData}; + if (!jsObj_) { + HILOG_WARN("Not found StaticSubscriberExtension.js"); + return; + } + + NativeValue* value = jsObj_->Get(); + NativeObject* obj = ConvertNativeValueTo(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 \ No newline at end of file diff --git a/frameworks/kits/ability/native/src/js_static_subscriber_extension_context.cpp b/frameworks/kits/ability/native/src/js_static_subscriber_extension_context.cpp new file mode 100644 index 0000000000..e350c9ee33 --- /dev/null +++ b/frameworks/kits/ability/native/src/js_static_subscriber_extension_context.cpp @@ -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& context) + : context_(context) {} + ~JsStaticSubscriberExtensionContext() = default; + + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + HILOG_INFO("JsStaticSubscriberExtensionContext::Finalizer is called"); + std::unique_ptr( + static_cast(data)); + } +private: + std::weak_ptr context_; +}; +} // namespace + +NativeValue* CreateJsStaticSubscriberExtensionContext(NativeEngine& engine, + std::shared_ptr context) +{ + HILOG_INFO("CreateJsStaticSubscriberExtensionContext begin"); + NativeValue *objValue = CreateJsExtensionContext(engine, context); + NativeObject *object = ConvertNativeValueTo(objValue); + + std::unique_ptr jsContext = + std::make_unique(context); + object->SetNativePointer(jsContext.release(), JsStaticSubscriberExtensionContext::Finalizer, nullptr); + return objValue; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/kits/ability/native/src/static_subscriber_extension.cpp b/frameworks/kits/ability/native/src/static_subscriber_extension.cpp new file mode 100644 index 0000000000..2bf23e4f8d --- /dev/null +++ b/frameworks/kits/ability/native/src/static_subscriber_extension.cpp @@ -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) +{ + 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& record, + const std::shared_ptr& application, + std::shared_ptr& handler, + const sptr& token) +{ + HILOG_INFO("StaticSubscriberExtension begin init"); + ExtensionBase::Init(record, application, handler, token); +} + +std::shared_ptr StaticSubscriberExtension::CreateAndInitContext( + const std::shared_ptr& record, + const std::shared_ptr& application, + std::shared_ptr& handler, + const sptr& token) +{ + std::shared_ptr context = + ExtensionBase::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 \ No newline at end of file diff --git a/frameworks/kits/ability/native/src/static_subscriber_proxy.cpp b/frameworks/kits/ability/native/src/static_subscriber_proxy.cpp new file mode 100644 index 0000000000..7d25387d32 --- /dev/null +++ b/frameworks/kits/ability/native/src/static_subscriber_proxy.cpp @@ -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 diff --git a/frameworks/kits/ability/native/src/static_subscriber_stub.cpp b/frameworks/kits/ability/native/src/static_subscriber_stub.cpp new file mode 100644 index 0000000000..16c617ed2f --- /dev/null +++ b/frameworks/kits/ability/native/src/static_subscriber_stub.cpp @@ -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(); + 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 diff --git a/frameworks/kits/ability/native/src/static_subscriber_stub_imp.cpp b/frameworks/kits/ability/native/src/static_subscriber_stub_imp.cpp new file mode 100644 index 0000000000..98c2bd561c --- /dev/null +++ b/frameworks/kits/ability/native/src/static_subscriber_stub_imp.cpp @@ -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 diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index 4f3a620bf6..5c89216ac9 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -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", ] } diff --git a/interfaces/kits/napi/aafwk/static_subscriber_extension/BUILD.gn b/interfaces/kits/napi/aafwk/static_subscriber_extension/BUILD.gn new file mode 100644 index 0000000000..19f75fa65c --- /dev/null +++ b/interfaces/kits/napi/aafwk/static_subscriber_extension/BUILD.gn @@ -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" +} diff --git a/interfaces/kits/napi/aafwk/static_subscriber_extension/static_subscriber_extension.js b/interfaces/kits/napi/aafwk/static_subscriber_extension/static_subscriber_extension.js new file mode 100644 index 0000000000..4e31c2ff63 --- /dev/null +++ b/interfaces/kits/napi/aafwk/static_subscriber_extension/static_subscriber_extension.js @@ -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 \ No newline at end of file diff --git a/interfaces/kits/napi/aafwk/static_subscriber_extension/static_subscriber_extension_module.cpp b/interfaces/kits/napi/aafwk/static_subscriber_extension/static_subscriber_extension_module.cpp new file mode 100644 index 0000000000..4a0bd21ded --- /dev/null +++ b/interfaces/kits/napi/aafwk/static_subscriber_extension/static_subscriber_extension_module.cpp @@ -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; + } +} \ No newline at end of file diff --git a/interfaces/kits/napi/aafwk/static_subscriber_extension_context/BUILD.gn b/interfaces/kits/napi/aafwk/static_subscriber_extension_context/BUILD.gn new file mode 100644 index 0000000000..e6837c238c --- /dev/null +++ b/interfaces/kits/napi/aafwk/static_subscriber_extension_context/BUILD.gn @@ -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" +} diff --git a/interfaces/kits/napi/aafwk/static_subscriber_extension_context/static_subscriber_extension_context.js b/interfaces/kits/napi/aafwk/static_subscriber_extension_context/static_subscriber_extension_context.js new file mode 100644 index 0000000000..7df95b9b7d --- /dev/null +++ b/interfaces/kits/napi/aafwk/static_subscriber_extension_context/static_subscriber_extension_context.js @@ -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 \ No newline at end of file diff --git a/interfaces/kits/napi/aafwk/static_subscriber_extension_context/static_subscriber_extension_context_module.cpp b/interfaces/kits/napi/aafwk/static_subscriber_extension_context/static_subscriber_extension_context_module.cpp new file mode 100644 index 0000000000..3731cfe899 --- /dev/null +++ b/interfaces/kits/napi/aafwk/static_subscriber_extension_context/static_subscriber_extension_context_module.cpp @@ -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; + } +} diff --git a/ohos.build b/ohos.build index cf7185cccb..4173475df0 100755 --- a/ohos.build +++ b/ohos.build @@ -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",