diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index 16e116535440fc3b637ef67fd5bd6c7975684da6..e1570016c3a897ed34b4cee01c06130ddaebf984 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -16,6 +16,8 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") group("ani_packages") { deps = [ + "${ability_runtime_path}/frameworks/ets/ani/ability_auto_startup_callback:autostartupcallback_ani", + "${ability_runtime_path}/frameworks/ets/ani/ability_auto_startup_manager:auto_startup_manager", "${ability_runtime_path}/frameworks/ets/ani/ability_delegator:ability_delegator_registry_ani_kit", "${ability_runtime_path}/frameworks/ets/ani/ability_manager:ability_manager_ani_kit", "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", diff --git a/frameworks/ets/ani/ability_auto_startup_callback/BUILD.gn b/frameworks/ets/ani/ability_auto_startup_callback/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..66f33aa780b37b83fd9c79493638aa79319c6294 --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_callback/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 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("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("autostartupcallback_ani") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + + include_dirs = [ + "./include", + "${ability_runtime_path}/frameworks/ets/ani/ani_common/include", + "${ability_runtime_path}/frameworks/ets/ani/enum_convert", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/inner_api/runtime/include", + "${ability_runtime_utils_path}/global/constant", + ] + + sources = [ + "./src/ets_ability_auto_startup_callback.cpp", + "./src/ets_ability_auto_startup_manager_utils.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util", + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_native_path}/ability/native:ability_business_error", + "${ability_runtime_native_path}/ability/native:auto_startup_callback", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", + ] + + external_deps = [ + "ability_base:session_info", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + "runtime_core:ani", + "window_manager:libwm", + ] + + if (ability_runtime_graphics) { + defines = [ + "SUPPORT_GRAPHICS", + "SUPPORT_SCREEN", + ] + } + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_callback.h b/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..f15891b1a8cc849e7826733d2fba3b9f2ecb750d --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_callback.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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_ABILITY_RUNTIME_ETS_ABILITY_AUTO_STARTUP_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_ETS_ABILITY_AUTO_STARTUP_CALLBACK_H + +#include +#include +#include + +#include "ani.h" +#include "ani_common_util.h" +#include "auto_startup_callback_stub.h" +#include "auto_startup_info.h" +#include "ets_native_reference.h" +#include "parcel.h" + +namespace OHOS { +namespace AbilityRuntime { +/** + * + * @class EtsAbilityAutoStartupCallBack + */ +class EtsAbilityAutoStartupCallBack : public AutoStartupCallBackStub { +public: + explicit EtsAbilityAutoStartupCallBack(ani_env *env); + virtual ~EtsAbilityAutoStartupCallBack(); + void Register(ani_object value); + void UnRegister(ani_object value); + void OnAutoStartupOn(const AutoStartupInfo &info) override; + void OnAutoStartupOff(const AutoStartupInfo &info) override; + bool IsCallbacksEmpty(); + +private: + void EtsCallFunction(const AutoStartupInfo &info, const std::string &methodName); + void EtsCallFunctionWorker(const AutoStartupInfo &info, const std::string &methodName); + bool IsEtsCallbackEquals(const AppExecFwk::ETSNativeReference &callback, ani_object value); + + ani_env *env_; + std::vector callbacks_; + std::mutex mutexlock_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ETS_ABILITY_AUTO_STARTUP_CALLBACK_H diff --git a/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_manager_utils.h b/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_manager_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..e254a1247326cdbb27e841987b2f4fcd717c9565 --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_callback/include/ets_ability_auto_startup_manager_utils.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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_ABILITY_RUNTIME_ANI_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H +#define OHOS_ABILITY_RUNTIME_ANI_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H + +#include "ani.h" +#include "auto_startup_info.h" + +namespace OHOS { +namespace AbilityRuntime { +bool UnwrapAutoStartupInfo(ani_env *env, ani_object param, AutoStartupInfo &info); +ani_object ConvertAutoStartupInfos(ani_env *env, const std::vector &infos); +ani_object CreateAniAutoStartupInfo(ani_env *env, const AutoStartupInfo &info); +} // namespace AbilityRuntime +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H \ No newline at end of file diff --git a/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_callback.cpp b/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac6022d0d88d4cc6d16cb4dec225420d89a5897e --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_callback.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2025 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 "ets_ability_auto_startup_callback.h" + +#include "ets_ability_auto_startup_manager_utils.h" +#include "ets_error_utils.h" +#include "ets_runtime.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +const std::string METHOD_ON = "onAutoStartupOn"; +const std::string METHOD_OFF = "onAutoStartupOff"; +constexpr const char *SIGNATURE_AUTO_STARTUP_INFO = "Lapplication/AutoStartupInfo/AutoStartupInfo;:V"; +} // namespace +EtsAbilityAutoStartupCallBack::EtsAbilityAutoStartupCallBack(ani_env *env) : env_(env) {} + +EtsAbilityAutoStartupCallBack::~EtsAbilityAutoStartupCallBack() {} + +void EtsAbilityAutoStartupCallBack::OnAutoStartupOn(const AutoStartupInfo &info) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + EtsCallFunction(info, METHOD_ON); +} + +void EtsAbilityAutoStartupCallBack::OnAutoStartupOff(const AutoStartupInfo &info) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + EtsCallFunction(info, METHOD_OFF); +} + +void EtsAbilityAutoStartupCallBack::Register(ani_object value) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called Register"); + std::lock_guard lock(mutexlock_); + for (const auto &callback : callbacks_) { + if (IsEtsCallbackEquals(callback, value)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "callback exist"); + return; + } + } + + ani_ref ref = nullptr; + ani_status status = ANI_ERROR; + if ((status = env_->GlobalReference_Create(value, &ref)) != ANI_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "status : %{public}d", status); + return; + } + + AppExecFwk::ETSNativeReference stRef; + stRef.aniObj = value; + stRef.aniRef = ref; + callbacks_.emplace_back(stRef); + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Register end"); +} + +void EtsAbilityAutoStartupCallBack::UnRegister(ani_object value) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called UnRegister"); + std::lock_guard lock(mutexlock_); + ani_boolean isUndefined = false; + if (env_->Reference_IsUndefined(value, &isUndefined) != ANI_OK || isUndefined == true) { + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "invalid callback, clear all callback"); + for (auto &callback : callbacks_) { + env_->GlobalReference_Delete(callback.aniRef); + } + callbacks_.clear(); + return; + } + + auto it = std::find_if(callbacks_.begin(), callbacks_.end(), + [&value](const AppExecFwk::ETSNativeReference &item) { + return item.aniObj == value; + }); + if (it == callbacks_.end()) { + env_->GlobalReference_Delete(it->aniRef); + callbacks_.erase(it); + } + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "UnRegister end"); +} + +bool EtsAbilityAutoStartupCallBack::IsCallbacksEmpty() +{ + return callbacks_.empty(); +} + +void EtsAbilityAutoStartupCallBack::EtsCallFunction(const AutoStartupInfo &info, const std::string &methodName) +{ + wptr stub = iface_cast(AsObject()); + sptr obj = stub.promote(); + if (obj == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null obj"); + return; + } + + obj->EtsCallFunctionWorker(info, methodName); + + AppExecFwk::AsyncCallback(env_, nullptr, EtsErrorUtil::CreateErrorByNativeErr( + env_, static_cast(AbilityErrorCode::ERROR_CODE_INNER)), nullptr); +} + +void EtsAbilityAutoStartupCallBack::EtsCallFunctionWorker(const AutoStartupInfo &info, const std::string &methodName) +{ + std::lock_guard lock(mutexlock_); + for (auto callback : callbacks_) { + if (callback.aniRef == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null obj"); + continue; + } + + ani_status status = ANI_ERROR; + auto autoStartupInfoObj = CreateAniAutoStartupInfo(env_, info); + if ((status = env_->Object_CallMethodByName_Void(reinterpret_cast(callback.aniRef), + methodName.c_str(), SIGNATURE_AUTO_STARTUP_INFO, autoStartupInfoObj)) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "status: %{public}d", status); + return; + } + } +} + +bool EtsAbilityAutoStartupCallBack::IsEtsCallbackEquals( + const AppExecFwk::ETSNativeReference &callback, ani_object value) +{ + if (callback.aniObj == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null object"); + return false; + } + + ani_boolean result = false; + if (env_->Reference_StrictEquals(callback.aniObj, value, &result) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "objects not match"); + return false; + } + + return static_cast(result); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_manager_utils.cpp b/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_manager_utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c06d29d396371eeacfa9014c614814f3c98e0816 --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_callback/src/ets_ability_auto_startup_manager_utils.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2025 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 "ets_ability_auto_startup_manager_utils.h" + +#include "ani_common_util.h" +#include "global_constant.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr const char *CLASSNAME_ARRAY = "Lescompat/Array;"; +constexpr const char *SIGNATURE_AUTO_STARTUP_INFO = "Lapplication/AutoStartupInfo/AutoStartupInfoInner;"; +} +bool UnwrapAutoStartupInfo(ani_env *env, ani_object param, AutoStartupInfo &info) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "UnwrapAutoStartupInfo called"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null env"); + return false; + } + if (!AppExecFwk::GetStringProperty(env, param, "bundleName", info.bundleName)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get bundleName"); + return false; + } + if (!AppExecFwk::GetStringProperty(env, param, "abilityName", info.abilityName)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get abilityName"); + return false; + } + if (AppExecFwk::IsExistsProperty(env, param, "appCloneIndex")) { + ani_int appCloneIndex = 0; + if (!AppExecFwk::GetIntPropertyObject(env, param, "appCloneIndex", appCloneIndex)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get appCloneIndex"); + return false; + } + info.appCloneIndex = appCloneIndex; + } + if (!AppExecFwk::GetStringProperty(env, param, "moduleName", info.moduleName)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to get moduleName"); + return false; + } + return true; +} + +static bool SetAutoStartupInfo(ani_env *env, ani_object object, const AutoStartupInfo &info) +{ + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null env"); + return false; + } + if (!AppExecFwk::SetRefProperty(env, object, "bundleName", AppExecFwk::GetAniString(env, info.bundleName))) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to set bundleName"); + return false; + } + if (!AppExecFwk::SetRefProperty(env, object, "moduleName", AppExecFwk::GetAniString(env, info.moduleName))) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to set moduleName"); + return false; + } + if (!AppExecFwk::SetRefProperty(env, object, "abilityName", AppExecFwk::GetAniString(env, info.abilityName))) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to set abilityName"); + return false; + } + if (!AppExecFwk::SetRefProperty( + env, object, "abilityTypeName", AppExecFwk::GetAniString(env, info.abilityTypeName))) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to set abilityTypeName"); + return false; + } + if (info.appCloneIndex >= 0 && info.appCloneIndex < GlobalConstant::MAX_APP_CLONE_INDEX) { + if (!AppExecFwk::SetIntPropertyObject(env, object, "appCloneIndex", info.appCloneIndex)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to set appCloneIndex"); + return false; + } + } + if (!AppExecFwk::SetIntPropertyObject(env, object, "userId", info.userId)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to set userId"); + return false; + } + if (!AppExecFwk::SetIntPropertyObject(env, object, "setterUserId", info.setterUserId)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to set setterUserId"); + return false; + } + if (!AppExecFwk::SetRefProperty( + env, object, "canUserModify", AppExecFwk::CreateBoolean(env, info.canUserModify))) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to set canUserModify"); + return false; + } + return true; +} + +ani_object ConvertAutoStartupInfos(ani_env *env, const std::vector &infos) +{ + ani_class arrayCls = nullptr; + ani_status status = ANI_OK; + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null env"); + return nullptr; + } + status = env->FindClass(CLASSNAME_ARRAY, &arrayCls); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "FindClass failed status : %{public}d", status); + return nullptr; + } + ani_method arrayCtor; + status = env->Class_FindMethod(arrayCls, "", "I:V", &arrayCtor); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "find ctor failed status : %{public}d", status); + return nullptr; + } + ani_object arrayObj; + status = env->Object_New(arrayCls, arrayCtor, &arrayObj, infos.size()); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Object_New array status : %{public}d", status); + return arrayObj; + } + ani_size index = 0; + for (auto &info : infos) { + ani_object ani_info = CreateAniAutoStartupInfo(env, info); + if (ani_info == nullptr) { + TAG_LOGW(AAFwkTag::AUTO_STARTUP, "null ani_info"); + break; + } + status = env->Object_CallMethodByName_Void(arrayObj, "$_set", "ILstd/core/Object;:V", index, ani_info); + if (status != ANI_OK) { + TAG_LOGW(AAFwkTag::AUTO_STARTUP, "Object_CallMethodByName_Void failed status : %{public}d", status); + break; + } + index++; + } + return arrayObj; +} + +ani_object CreateAniAutoStartupInfo(ani_env *env, const AutoStartupInfo &info) +{ + ani_class cls {}; + ani_status status = ANI_ERROR; + ani_method method {}; + ani_object object = nullptr; + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null env"); + return nullptr; + } + if ((status = env->FindClass(SIGNATURE_AUTO_STARTUP_INFO, &cls)) + != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "find class failed status : %{public}d", status); + return nullptr; + } + if (cls == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null cls"); + return nullptr; + } + if ((status = env->Class_FindMethod(cls, "", ":V", &method)) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "find ctor failed status : %{public}d", status); + return nullptr; + } + if ((status = env->Object_New(cls, method, &object)) != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Object_New failed status : %{public}d", status); + return nullptr; + } + if (object == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null object"); + return nullptr; + } + if (!SetAutoStartupInfo(env, object, info)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "SetBusinessAbilityInfo failed"); + return nullptr; + } + return object; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/ability_auto_startup_manager/BUILD.gn b/frameworks/ets/ani/ability_auto_startup_manager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9083a0109a873c7aa3187f3bd33c6274ce5a8692 --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_manager/BUILD.gn @@ -0,0 +1,61 @@ +# Copyright (c) 2025 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("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("auto_startup_manager") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + + include_dirs = [ + "./include", + "${ability_runtime_path}/frameworks/ets/ani/ability_auto_startup_callback/include", + ] + + sources = [ "./src/ets_ability_auto_startup_manager.cpp" ] + + configs = [] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util", + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_native_path}/ability/native:ability_business_error", + "${ability_runtime_path}/frameworks/ets/ani/ability_auto_startup_callback:autostartupcallback_ani", + "${ability_runtime_path}/frameworks/ets/ani/ani_common:ani_common", + ] + + external_deps = [ + "access_token:libtokenid_sdk", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + "runtime_core:ani", + "samgr:samgr_proxy", + ] + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/ets/ani/ability_auto_startup_manager/include/ets_ability_auto_startup_manager.h b/frameworks/ets/ani/ability_auto_startup_manager/include/ets_ability_auto_startup_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..0ff2777298d50faba1a3668599b3cd6c31e90dbe --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_manager/include/ets_ability_auto_startup_manager.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 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_ABILITY_RUNTIME_ETS_ABILITY_AUTO_STARTUP_MANAGER_H +#define OHOS_ABILITY_RUNTIME_ETS_ABILITY_AUTO_STARTUP_MANAGER_H + +#include "ani.h" +#include "ets_ability_auto_startup_callback.h" +#include "ets_runtime.h" +#include "native_engine/native_engine.h" +#include "native_engine/native_value.h" + +namespace OHOS { +namespace AbilityRuntime { +class EtsAbilityAutoStartupManager { +public: + EtsAbilityAutoStartupManager() = default; + ~EtsAbilityAutoStartupManager() = default; + static void RegisterAutoStartupCallback(ani_env *env, ani_string aniType, ani_object callback); + static void UnregisterAutoStartupCallback(ani_env *env, ani_string aniType, ani_object callback); + static void SetApplicationAutoStartup(ani_env *env, ani_object info, ani_object callback); + static void CancelApplicationAutoStartup(ani_env *env, ani_object info, ani_object callback); + static void QueryAllAutoStartupApplications(ani_env *env, ani_object callback); + static bool CheckCallerIsSystemApp(); + + static sptr etsAutoStartupCallback_; +}; +void EtsAbilityAutoStartupManagerInit(ani_env *env); +} // namespace AbilityRuntime +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNTIME_ETS_ABILITY_AUTO_STARTUP_MANAGER_H \ No newline at end of file diff --git a/frameworks/ets/ani/ability_auto_startup_manager/src/ets_ability_auto_startup_manager.cpp b/frameworks/ets/ani/ability_auto_startup_manager/src/ets_ability_auto_startup_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4a2acaef1f96414fc763a56b3a32d76d5329e852 --- /dev/null +++ b/frameworks/ets/ani/ability_auto_startup_manager/src/ets_ability_auto_startup_manager.cpp @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2025 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 "ets_ability_auto_startup_manager.h" + +#include "ability_business_error.h" +#include "ability_manager_client.h" +#include "ability_manager_interface.h" +#include "auto_startup_info.h" +#include "hilog_tag_wrapper.h" +#include "ipc_skeleton.h" +#include "ets_ability_auto_startup_manager_utils.h" +#include "ets_error_utils.h" +#include "permission_constants.h" +#include "tokenid_kit.h" + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AAFwk; +namespace { +constexpr int32_t INVALID_PARAM = static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM); +constexpr const char *ETS_AUTO_STARTUP_MANAGER_NAMESPACE = + "L@ohos/app/ability/autoStartupManager/autoStartupManager;"; +constexpr const char *ON_OFF_TYPE_SYSTEM = "systemAutoStartup"; +} // namespace + +sptr EtsAbilityAutoStartupManager::etsAutoStartupCallback_ = nullptr; + +bool EtsAbilityAutoStartupManager::CheckCallerIsSystemApp() +{ + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "not system app"); + return false; + } + return true; +} + +void EtsAbilityAutoStartupManager::RegisterAutoStartupCallback( + ani_env *env, ani_string aniType, ani_object callback) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + + std::string type; + if (!AppExecFwk::GetStdString(env, aniType, type) || type != ON_OFF_TYPE_SYSTEM) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "invalid param"); + EtsErrorUtil::ThrowError(env, INVALID_PARAM, "Parameter error. Convert type fail."); + return; + } + + if (!CheckCallerIsSystemApp()) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "not system app"); + EtsErrorUtil::ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP); + return; + } + + if (etsAutoStartupCallback_ == nullptr) { + etsAutoStartupCallback_ = new (std::nothrow) EtsAbilityAutoStartupCallBack(env); + if (etsAutoStartupCallback_ == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null etsAutoStartupCallback_"); + EtsErrorUtil::ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER); + return; + } + + auto ret = AbilityManagerClient::GetInstance()->RegisterAutoStartupSystemCallback( + etsAutoStartupCallback_->AsObject()); + if (ret != ERR_OK) { + etsAutoStartupCallback_ = nullptr; + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "reg callback failed[%{public}d]", ret); + if (ret == CHECK_PERMISSION_FAILED) { + EtsErrorUtil::ThrowNoPermissionError(env, PermissionConstants::PERMISSION_MANAGE_APP_BOOT); + } else { + EtsErrorUtil::ThrowError(env, EtsErrorUtil::CreateErrorByNativeErr(env, ret)); + } + return; + } + } + + etsAutoStartupCallback_->Register(callback); +} + +void EtsAbilityAutoStartupManager::UnregisterAutoStartupCallback( + ani_env *env, ani_string aniType, ani_object callback) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + + std::string type; + if (!AppExecFwk::GetStdString(env, aniType, type) || type != ON_OFF_TYPE_SYSTEM) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "parse type failed"); + EtsErrorUtil::ThrowError(env, INVALID_PARAM, "Parameter error. Convert type fail."); + return; + } + + if (!CheckCallerIsSystemApp()) { + EtsErrorUtil::ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP); + return; + } + + if (etsAutoStartupCallback_ == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null etsAutoStartupCallback_"); + EtsErrorUtil::ThrowError(env, AbilityErrorCode::ERROR_CODE_INNER); + return; + } + + etsAutoStartupCallback_->UnRegister(callback); + if (etsAutoStartupCallback_->IsCallbacksEmpty()) { + auto ret = AbilityManagerClient::GetInstance()->UnregisterAutoStartupSystemCallback( + etsAutoStartupCallback_->AsObject()); + if (ret != ERR_OK) { + if (ret == CHECK_PERMISSION_FAILED) { + EtsErrorUtil::ThrowNoPermissionError(env, PermissionConstants::PERMISSION_MANAGE_APP_BOOT); + } else { + EtsErrorUtil::ThrowError(env, EtsErrorUtil::CreateErrorByNativeErr(env, ret)); + } + } + etsAutoStartupCallback_ = nullptr; + } +} + +void EtsAbilityAutoStartupManager::SetApplicationAutoStartup(ani_env *env, ani_object info, ani_object callback) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + + if (!CheckCallerIsSystemApp()) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "not system app"); + AppExecFwk::AsyncCallback(env, callback, + EtsErrorUtil::CreateError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP), nullptr); + return; + } + + AutoStartupInfo autoStartupInfo; + if (!UnwrapAutoStartupInfo(env, info, autoStartupInfo)) { + AppExecFwk::AsyncCallback(env, callback, + EtsErrorUtil::CreateError(env, INVALID_PARAM, "unwrap AutoStartupInfo failed"), nullptr); + return; + } + + auto ret = AbilityManagerClient::GetInstance()->SetApplicationAutoStartup(autoStartupInfo); + + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, static_cast(ret)), nullptr); +} + +void EtsAbilityAutoStartupManager::CancelApplicationAutoStartup(ani_env *env, ani_object info, ani_object callback) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + + if (!CheckCallerIsSystemApp()) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "not system app"); + AppExecFwk::AsyncCallback(env, callback, + EtsErrorUtil::CreateError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP), nullptr); + return; + } + + AutoStartupInfo autoStartupInfo; + if (!UnwrapAutoStartupInfo(env, info, autoStartupInfo)) { + AppExecFwk::AsyncCallback(env, callback, + EtsErrorUtil::CreateError(env, INVALID_PARAM, "Parameter error. Convert autoStartupInfo fail."), nullptr); + return; + } + + auto ret = AbilityManagerClient::GetInstance()->CancelApplicationAutoStartup(autoStartupInfo); + + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, static_cast(ret)), nullptr); +} + +void EtsAbilityAutoStartupManager::QueryAllAutoStartupApplications(ani_env *env, ani_object callback) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + if (!CheckCallerIsSystemApp()) { + AppExecFwk::AsyncCallback(env, callback, + EtsErrorUtil::CreateError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP), nullptr); + return; + } + + std::vector infos; + auto ret = AbilityManagerClient::GetInstance()->QueryAllAutoStartupApplications(infos); + if (ret != ERR_OK) { + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, static_cast(ret)), nullptr); + return; + } + ani_object result = ConvertAutoStartupInfos(env, infos); + AppExecFwk::AsyncCallback(env, callback, + AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, static_cast(ERR_OK)), result); +} + +void EtsAbilityAutoStartupManagerInit(ani_env *env) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "call EtsAbilityAutoStartupManagerInit"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null env"); + return; + } + ani_status status = ANI_ERROR; + if (env->ResetError() != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "ResetError failed"); + } + ani_namespace ns = nullptr; + status = env->FindNamespace(ETS_AUTO_STARTUP_MANAGER_NAMESPACE, &ns); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "FindNamespace abilityManager failed status : %{public}d", status); + return; + } + std::array methods = { + ani_native_function {"nativeOnApplicationAutoStartupStateChangeSync", nullptr, + reinterpret_cast(EtsAbilityAutoStartupManager::RegisterAutoStartupCallback)}, + ani_native_function {"nativeOffApplicationAutoStartupStateChangeSync", nullptr, + reinterpret_cast(EtsAbilityAutoStartupManager::UnregisterAutoStartupCallback)}, + ani_native_function {"nativeSetApplicationAutoStartup", nullptr, + reinterpret_cast(EtsAbilityAutoStartupManager::SetApplicationAutoStartup)}, + ani_native_function {"nativeCancelApplicationAutoStartup", nullptr, + reinterpret_cast(EtsAbilityAutoStartupManager::CancelApplicationAutoStartup)}, + ani_native_function {"nativeQueryAllAutoStartupApplications", nullptr, + reinterpret_cast(EtsAbilityAutoStartupManager::QueryAllAutoStartupApplications)}, + }; + status = env->Namespace_BindNativeFunctions(ns, methods.data(), methods.size()); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Namespace_BindNativeFunctions failed status : %{public}d", status); + } + if (env->ResetError() != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "ResetError failed"); + } +} + +extern "C" { +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "in AbilityAutoStartupManagerEts.ANI_Constructor"); + if (vm == nullptr || result == nullptr) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null vm or result"); + return ANI_INVALID_ARGS; + } + + ani_env *env = nullptr; + ani_status status = ANI_ERROR; + status = vm->GetEnv(ANI_VERSION_1, &env); + if (status != ANI_OK) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEnv failed, status=%{public}d", status); + return ANI_NOT_FOUND; + } + EtsAbilityAutoStartupManagerInit(env); + *result = ANI_VERSION_1; + TAG_LOGD(AAFwkTag::AUTO_STARTUP, "AbilityAutoStartupManagerEts.ANI_Constructor finished"); + return ANI_OK; +} +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ets/@ohos.app.ability.autoStartupManager.ets b/frameworks/ets/ets/@ohos.app.ability.autoStartupManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..40e7ec55260ae192b340a9f2a814e45ab7e863fd --- /dev/null +++ b/frameworks/ets/ets/@ohos.app.ability.autoStartupManager.ets @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2025 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 AutoStartupCallback from 'application.AutoStartupCallback'; +import AutoStartupInfo from 'application.AutoStartupInfo'; +import { AsyncCallback, BusinessError } from '@ohos.base'; +import AsyncCallbackWrapper from './utils/AbilityUtils'; + +export default namespace autoStartupManager { + loadLibrary("auto_startup_manager.z") + + export native function nativeOnApplicationAutoStartupStateChangeSync(type: string, callback: AutoStartupCallback): void; + export native function nativeOffApplicationAutoStartupStateChangeSync(type: string, callback?: AutoStartupCallback): void; + export native function nativeSetApplicationAutoStartup(info: AutoStartupInfo, callback: AsyncCallbackWrapper): void; + export native function nativeCancelApplicationAutoStartup(info: AutoStartupInfo, callback: AsyncCallbackWrapper): void; + export native function nativeQueryAllAutoStartupApplications(callback: AsyncCallbackWrapper>): void; + + export function on(type: 'systemAutoStartup', callback: AutoStartupCallback): void { + autoStartupManager.nativeOnApplicationAutoStartupStateChangeSync('systemAutoStartup', callback); + } + + export function off(type: 'systemAutoStartup', callback?: AutoStartupCallback): void { + autoStartupManager.nativeOffApplicationAutoStartupStateChangeSync('systemAutoStartup', callback); + } + + export function setApplicationAutoStartup(info: AutoStartupInfo, callback: AsyncCallback): void { + let myCall = new AsyncCallbackWrapper(callback); + taskpool.execute((): void => { + autoStartupManager.nativeSetApplicationAutoStartup(info, myCall); + }); + } + + export function setApplicationAutoStartup(info: AutoStartupInfo): Promise { + let p = new Promise((resolve: (data: undefined)=>void, reject:(err: BusinessError) => void): void => { + let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { + if (err == null || err.code == 0) { + resolve(undefined); + } else { + reject(err); + } + }); + taskpool.execute((): void => { + autoStartupManager.nativeSetApplicationAutoStartup(info, myCall); + }); + }); + return p; + } + + export function cancelApplicationAutoStartup(info: AutoStartupInfo, callback: AsyncCallback): void { + let myCall = new AsyncCallbackWrapper(callback); + taskpool.execute((): void => { + autoStartupManager.nativeCancelApplicationAutoStartup(info, myCall); + }); + } + + export function cancelApplicationAutoStartup(info: AutoStartupInfo): Promise { + let p = new Promise((resolve: (data: undefined)=>void, reject:(err: BusinessError) => void): void => { + let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { + if (err == null || err.code == 0) { + resolve(undefined); + } else { + reject(err); + } + }); + taskpool.execute((): void => { + autoStartupManager.nativeCancelApplicationAutoStartup(info, myCall); + }); + }); + return p; + } + + export function queryAllAutoStartupApplications(callback: AsyncCallback>): void { + let myCall = new AsyncCallbackWrapper>(callback); + taskpool.execute((): void => { + autoStartupManager.nativeQueryAllAutoStartupApplications(myCall); + }); + } + + export function queryAllAutoStartupApplications(): Promise> { + let p = new Promise>((resolve: (data: Array) => void, + reject: (err: BusinessError) => void): void => { + let myCall = new AsyncCallbackWrapper>((err: BusinessError | null, + data: Array | undefined) => { + if (err == null || err.code == 0) { + resolve(data as Array); + } else { + reject(err); + } + }); + taskpool.execute((): void => { + autoStartupManager.nativeQueryAllAutoStartupApplications(myCall); + }).catch((err: Error): void => { + reject(err as BusinessError); + }); + }); + return p; + } +} \ No newline at end of file diff --git a/frameworks/ets/ets/BUILD.gn b/frameworks/ets/ets/BUILD.gn index 07d5b3ee261f8c23f30b27aca5905e8199862821..a7e7203e088abb7096edd1735706e0556eface57 100644 --- a/frameworks/ets/ets/BUILD.gn +++ b/frameworks/ets/ets/BUILD.gn @@ -937,6 +937,53 @@ ohos_prebuilt_etc("ability_runtime_auto_fill_type_abc_etc") { deps = [ ":ability_runtime_auto_fill_type_abc" ] } +generate_static_abc("ability_runtime_auto_startup_callback_abc") { + base_url = "./" + files = [ "./application/AutoStartupCallback.ets" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/ability_runtime_auto_startup_callback_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_auto_startup_callback_abc_etc") { + source = "$target_out_dir/ability_runtime_auto_startup_callback_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_auto_startup_callback_abc" ] +} + +generate_static_abc("ability_runtime_auto_startup_info_abc") { + base_url = "./" + files = [ "./application/AutoStartupInfo.ets" ] + + is_boot_abc = "True" + device_dst_file = "/system/framework/ability_runtime_auto_startup_info_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_auto_startup_info_abc_etc") { + source = "$target_out_dir/ability_runtime_auto_startup_info_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_auto_startup_info_abc" ] +} + +generate_static_abc("ability_runtime_auto_startup_manager_abc") { + base_url = "./" + files = [ "./@ohos.app.ability.autoStartupManager.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/ability_runtime_auto_startup_manager_abc.abc" +} + +ohos_prebuilt_etc("ability_runtime_auto_startup_manager_abc_etc") { + source = "$target_out_dir/ability_runtime_auto_startup_manager_abc.abc" + module_install_dir = "framework" + subsystem_name = "ability" + part_name = "ability_runtime" + deps = [ ":ability_runtime_auto_startup_manager_abc" ] +} + generate_static_abc("ability_runtime_error_code_abc") { base_url = "./" files = [ "./@ohos.ability.errorCode.ets" ] @@ -1255,6 +1302,9 @@ group("ets_packages") { ":ability_runtime_application_context_abc_etc", ":ability_runtime_auto_fill_manager_abc_etc", ":ability_runtime_auto_fill_type_abc_etc", + ":ability_runtime_auto_startup_callback_abc_etc", + ":ability_runtime_auto_startup_info_abc_etc", + ":ability_runtime_auto_startup_manager_abc_etc", ":ability_runtime_application_state_change_callback_abc_etc", ":ability_runtime_base_context_abc_etc", ":ability_runtime_caller_callee_abc_etc", diff --git a/frameworks/ets/ets/application/AutoStartupCallback.ets b/frameworks/ets/ets/application/AutoStartupCallback.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f236c85882cc61d7c14445b3c50acbcb5f47ce5 --- /dev/null +++ b/frameworks/ets/ets/application/AutoStartupCallback.ets @@ -0,0 +1,14 @@ +import AutoStartupInfo from 'application.AutoStartupInfo'; + +export interface AutoStartupCallback { + onAutoStartupOn(info: AutoStartupInfo): void; + onAutoStartupOff(info: AutoStartupInfo): void; +} + +class AutoStartupCallbackInner implements AutoStartupCallback { + onAutoStartupOn(info: AutoStartupInfo): void { + } + + onAutoStartupOff(info: AutoStartupInfo): void { + } +} \ No newline at end of file diff --git a/frameworks/ets/ets/application/AutoStartupInfo.ets b/frameworks/ets/ets/application/AutoStartupInfo.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f17cdc5df151089945434c148b65fda993a54c7 --- /dev/null +++ b/frameworks/ets/ets/application/AutoStartupInfo.ets @@ -0,0 +1,21 @@ +export interface AutoStartupInfo { + bundleName: string; + moduleName?: string; + abilityName: string; + abilityTypeName?: string; + appCloneIndex?: int; + readonly userId?: int; + readonly setterUserId?: int; + readonly canUserModify?: boolean; +} + +class AutoStartupInfoInner implements AutoStartupInfo { + bundleName: string = ''; + moduleName?: string = ''; + abilityName: string = ''; + abilityTypeName?: string = ''; + appCloneIndex?: int = 0; + readonly userId?: int = 0; + readonly setterUserId?: int = 0; + readonly canUserModify?: boolean = false; +}