From 81415ad6b3bf4c34f6eb5545051348fec19158b6 Mon Sep 17 00:00:00 2001 From: lanhaoyu Date: Tue, 9 Sep 2025 11:26:44 +0800 Subject: [PATCH] 0728 sync to master Signed-off-by: lanhaoyu --- interfaces/kits/ani/BUILD.gn | 9 + interfaces/kits/ani/app_control/BUILD.gn | 99 + .../kits/ani/app_control/ani_app_control.cpp | 469 +++ .../app_control/ani_app_control_common.cpp | 279 ++ .../ani/app_control/ani_app_control_common.h | 37 + .../ani_app_control_unsupported.cpp | 140 + .../ets/@ohos.bundle.appControl.ets | 266 ++ interfaces/kits/ani/bundle_installer/BUILD.gn | 1 + .../bundle_installer/ani_bundle_installer.cpp | 36 +- .../ets/@ohos.bundle.installer.ets | 27 +- .../ets/@ohos.bundle.installerInner.ets | 108 +- interfaces/kits/ani/bundle_manager/BUILD.gn | 94 +- .../ani/bundle_manager/ani_bundle_manager.cpp | 1330 +++++-- .../ets/@ohos.bundle.bundleManager.ets | 912 ++++- .../ets/bundleManager/AbilityInfo.ets | 24 +- .../ets/bundleManager/AbilityInfoInner.ets | 109 +- .../ets/bundleManager/AppProvisionInfo.ets | 34 + .../bundleManager/AppProvisionInfoInner.ets | 70 + .../ets/bundleManager/ApplicationInfo.ets | 20 +- .../bundleManager/ApplicationInfoInner.ets | 107 +- .../ets/bundleManager/BundleInfo.ets | 34 +- .../ets/bundleManager/BundleInfoInner.ets | 113 +- .../bundleManager/ExtensionAbilityInfo.ets | 10 +- .../ExtensionAbilityInfoInner.ets | 60 +- .../ets/bundleManager/HapModuleInfo.ets | 8 +- .../ets/bundleManager/HapModuleInfoInner.ets | 84 +- .../ets/bundleManager/Metadata.ets | 2 +- .../ets/bundleManager/MetadataInner.ets | 10 +- .../ets/bundleManager/PermissionDef.ets | 21 + .../ets/bundleManager/PermissionDefInner.ets | 34 + .../ets/bundleManager/PluginBundleInfo.ets | 31 + .../bundleManager/PluginBundleInfoInner.ets | 61 + .../RecoverableApplicationInfo.ets | 26 + .../RecoverableApplicationInfoInner.ets | 44 + .../ets/bundleManager/SharedBundleInfo.ets | 30 + .../bundleManager/SharedBundleInfoInner.ets | 54 + .../ets/bundleManager/Skill.ets | 4 +- .../ets/bundleManager/SkillInner.ets | 35 +- interfaces/kits/ani/bundle_monitor/BUILD.gn | 1 + .../ets/@ohos.bundle.bundleMonitor.ets | 17 +- interfaces/kits/ani/common/BUILD.gn | 1 + .../kits/ani/common/business_error_ani.cpp | 8 +- .../kits/ani/common/business_error_ani.h | 1 + interfaces/kits/ani/common/common_fun_ani.cpp | 3248 ++++++++++------- interfaces/kits/ani/common/common_fun_ani.h | 421 ++- interfaces/kits/ani/common/enum_util.h | 151 +- .../kits/ani/default_app_manager/BUILD.gn | 98 + .../ani_default_app_manager.cpp | 225 ++ .../ani_default_app_manager_unsupported.cpp | 107 + .../ets/@ohos.bundle.defaultAppManager.ets | 222 ++ interfaces/kits/ani/freeInstall/BUILD.gn | 1 + .../ets/bundleManager/BundlePackInfo.ets | 10 +- .../ets/bundleManager/BundlePackInfoInner.ets | 113 +- .../ets/bundleManager/DispatchInfoInner.ets | 6 + .../kits/ani/launcher_bundle_manager/BUILD.gn | 1 + .../ani_launcher_bundle_manager.cpp | 141 +- ...ni_launcher_bundle_manager_unsupported.cpp | 24 +- .../@ohos.bundle.launcherBundleManager.ets | 41 +- .../ets/bundleManager/ElementNameInner.ets | 15 + .../ets/bundleManager/LauncherAbilityInfo.ets | 8 +- .../LauncherAbilityInfoInner.ets | 23 +- interfaces/kits/ani/overlay/BUILD.gn | 1 + .../ani/overlay/ets/@ohos.bundle.overlay.ets | 62 + .../ets/bundleManager/OverlayModuleInfo.ets | 4 +- .../bundleManager/OverlayModuleInfoInner.ets | 17 +- interfaces/kits/ani/resource_manager/BUILD.gn | 6 +- .../resource_manager/ani_resource_manager.cpp | 131 +- .../ani_resource_manager_common.cpp | 107 + .../ani_resource_manager_common.h | 33 + .../ani_resource_manager_unsupport.cpp | 20 +- .../@ohos.bundle.bundleResourceManager.ets | 49 +- .../ets/bundleManager/BundleResourceInfo.ets | 2 +- .../bundleManager/BundleResourceInfoInner.ets | 13 +- .../LauncherAbilityResourceInfo.ets | 7 +- .../LauncherAbilityResourceInfoInner.ets | 22 +- .../shortcut_manager/ani_shortcut_manager.cpp | 101 +- .../ets/@ohos.bundle.shortcutManager.ets | 72 +- .../ets/bundleManager/ShortcutInfo.ets | 59 +- interfaces/kits/ani/zlib/BUILD.gn | 3 +- interfaces/kits/ani/zlib/ani_zlib.cpp | 20 +- 80 files changed, 8226 insertions(+), 2218 deletions(-) create mode 100644 interfaces/kits/ani/app_control/BUILD.gn create mode 100644 interfaces/kits/ani/app_control/ani_app_control.cpp create mode 100644 interfaces/kits/ani/app_control/ani_app_control_common.cpp create mode 100644 interfaces/kits/ani/app_control/ani_app_control_common.h create mode 100644 interfaces/kits/ani/app_control/ani_app_control_unsupported.cpp create mode 100644 interfaces/kits/ani/app_control/ets/@ohos.bundle.appControl.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfo.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfoInner.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDef.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDefInner.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfo.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfoInner.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfo.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfoInner.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfo.ets create mode 100644 interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfoInner.ets create mode 100644 interfaces/kits/ani/default_app_manager/BUILD.gn create mode 100644 interfaces/kits/ani/default_app_manager/ani_default_app_manager.cpp create mode 100644 interfaces/kits/ani/default_app_manager/ani_default_app_manager_unsupported.cpp create mode 100644 interfaces/kits/ani/default_app_manager/ets/@ohos.bundle.defaultAppManager.ets create mode 100644 interfaces/kits/ani/resource_manager/ani_resource_manager_common.cpp create mode 100644 interfaces/kits/ani/resource_manager/ani_resource_manager_common.h diff --git a/interfaces/kits/ani/BUILD.gn b/interfaces/kits/ani/BUILD.gn index 411c64d8c0..96db5c8429 100644 --- a/interfaces/kits/ani/BUILD.gn +++ b/interfaces/kits/ani/BUILD.gn @@ -20,19 +20,28 @@ group("ani_common") { group("ani_bms_packages") { deps = [ + "app_control:ani_app_control", + "app_control:app_control_etc", "bundle_installer:ani_bundle_installer", "bundle_installer:bundle_installer_etc", "bundle_manager:ability_info_etc", "bundle_manager:ani_bundle_manager", + "bundle_manager:app_provision_info_etc", "bundle_manager:application_info_etc", "bundle_manager:bundle_info_etc", "bundle_manager:bundle_manager_etc", "bundle_manager:extension_ability_info_etc", "bundle_manager:hap_module_info_etc", "bundle_manager:metadata_etc", + "bundle_manager:permission_def_etc", + "bundle_manager:plugin_bundle_info_etc", + "bundle_manager:recoverable_application_info_etc", + "bundle_manager:share_bundle_info_etc", "bundle_manager:skill_etc", "bundle_monitor:ani_bundle_monitor", "bundle_monitor:bundle_monitor_etc", + "default_app_manager:ani_default_app_manager", + "default_app_manager:default_app_manager_etc", "freeInstall:ani_freeInstall", "freeInstall:bundle_pack_info_etc", "freeInstall:dispatch_info_etc", diff --git a/interfaces/kits/ani/app_control/BUILD.gn b/interfaces/kits/ani/app_control/BUILD.gn new file mode 100644 index 0000000000..91d6bded7a --- /dev/null +++ b/interfaces/kits/ani/app_control/BUILD.gn @@ -0,0 +1,99 @@ +# 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/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") + +ohos_shared_library("ani_app_control") { + shlib_type = "ani" + branch_protector_ret = "pac_ret" + + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + integer_overflow = true + ubsan = true + } + + include_dirs = [ + "${inner_api_path}/appexecfwk_core/include", + "${kits_path}/ani/common", + "${kits_path}/js/common", + ] + + defines = [ + "APP_LOG_TAG = \"BMS\"", + "LOG_DOMAIN = 0xD001120", + ] + + if (bundle_framework_app_control) { + sources = [ + "ani_app_control.cpp", + "ani_app_control_common.cpp", + ] + } else { + sources = [ "ani_app_control_unsupported.cpp" ] + } + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + "${kits_path}/ani/common:bms_ani_common", + "${kits_path}/js/common:bundle_napi_common", + ] + + cflags = [ + "-Os", + "-fstack-protector-strong", + ] + + cflags_cc = [ + "-Os", + "-fstack-protector-strong", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ani_common", + "ability_runtime:runtime", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "napi:ace_napi", + "runtime_core:ani", + "runtime_core:ani_helpers", + "samgr:samgr_proxy", + ] + + subsystem_name = "bundlemanager" + part_name = "bundle_framework" +} + +generate_static_abc("app_control") { + base_url = "./ets" + files = [ "./ets/@ohos.bundle.appControl.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/app_control.abc" +} + +ohos_prebuilt_etc("app_control_etc") { + source = "$target_out_dir/app_control.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":app_control" ] +} diff --git a/interfaces/kits/ani/app_control/ani_app_control.cpp b/interfaces/kits/ani/app_control/ani_app_control.cpp new file mode 100644 index 0000000000..8f8c17334d --- /dev/null +++ b/interfaces/kits/ani/app_control/ani_app_control.cpp @@ -0,0 +1,469 @@ +/* + * 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 + +#include "ani_app_control_common.h" +#include "ani_common_want.h" +#include "app_control_interface.h" +#include "app_log_wrapper.h" +#include "bundle_errors.h" +#include "business_error_ani.h" +#include "common_fun_ani.h" +#include "common_func.h" +#include "ipc_skeleton.h" +#include "napi_constants.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace OHOS::AAFwk; +namespace { +constexpr const char* NS_NAME_APPCONTROL = "@ohos.bundle.appControl.appControl"; +constexpr const char* PROPERTYNAME_APPID = "appId"; +constexpr const char* PROPERTYNAME_APPINDEX = "appIndex"; +constexpr const char* PROPERTYNAME_DISPOSEDRULE = "disposedRule"; +constexpr const char* PARAM_LENGTH_ERROR = "parameter length invalid"; +constexpr uint32_t MAX_VECTOR_NUM = 1000; +} // namespace + +static void AniSetDisposedStatus(ani_env* env, ani_string aniAppId, ani_object aniWant, ani_boolean aniIsSync) +{ + APP_LOGD("ani SetDisposedStatus called"); + std::string appId; + if (!CommonFunAni::ParseString(env, aniAppId, appId)) { + APP_LOGE("appId %{public}s invalid", appId.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_ID, TYPE_STRING); + return; + } + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + if (appId.empty()) { + APP_LOGE("appId is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPID, + isSync ? SET_DISPOSED_STATUS_SYNC : SET_DISPOSED_STATUS, + isSync ? "" : PERMISSION_DISPOSED_STATUS); + return; + } + Want want; + if (!AniAppControlCommon::ParseWantWithoutVerification(env, aniWant, want)) { + APP_LOGE("want invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, DISPOSED_WANT, TYPE_WANT); + return; + } + + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? SET_DISPOSED_STATUS_SYNC : SET_DISPOSED_STATUS, + isSync ? "" : PERMISSION_DISPOSED_STATUS); + return; + } + + ErrCode ret = appControlProxy->SetDisposedStatus(appId, want); + if (ret != ERR_OK) { + APP_LOGE("SetDisposedStatus failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + isSync ? SET_DISPOSED_STATUS_SYNC : SET_DISPOSED_STATUS, PERMISSION_DISPOSED_STATUS); + } +} + +static ani_object AniGetDisposedStatus(ani_env* env, ani_string aniAppId, ani_boolean aniIsSync) +{ + APP_LOGD("ani GetDisposedStatus called"); + std::string appId; + if (!CommonFunAni::ParseString(env, aniAppId, appId)) { + APP_LOGE("appId %{public}s invalid", appId.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_ID, TYPE_STRING); + return nullptr; + } + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + if (appId.empty()) { + APP_LOGE("appId is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPID, + isSync ? GET_DISPOSED_STATUS_SYNC : GET_DISPOSED_STATUS, + isSync ? "" : PERMISSION_DISPOSED_STATUS); + return nullptr; + } + + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? GET_DISPOSED_STATUS_SYNC : GET_DISPOSED_STATUS, + isSync ? "" : PERMISSION_DISPOSED_STATUS); + return nullptr; + } + + Want want; + ErrCode ret = appControlProxy->GetDisposedStatus(appId, want); + if (ret != ERR_OK) { + APP_LOGE("GetDisposedStatusSync failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + isSync ? GET_DISPOSED_STATUS_SYNC : GET_DISPOSED_STATUS, PERMISSION_DISPOSED_STATUS); + return nullptr; + } + + return CommonFunAni::ConvertWantInfo(env, want); +} + +static void AniDeleteDisposedStatus(ani_env* env, ani_string aniAppId, ani_int aniAppIndex, ani_boolean aniIsSync) +{ + APP_LOGD("ani DeleteDisposedStatus called"); + std::string appId; + if (!CommonFunAni::ParseString(env, aniAppId, appId)) { + APP_LOGE("appId %{public}s invalid", appId.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_ID, TYPE_STRING); + return; + } + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + if (appId.empty()) { + APP_LOGE("appId is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPID, + isSync ? DELETE_DISPOSED_STATUS_SYNC : DELETE_DISPOSED_STATUS, + isSync ? "" : PERMISSION_DISPOSED_STATUS); + return; + } + + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? DELETE_DISPOSED_STATUS_SYNC : DELETE_DISPOSED_STATUS, + isSync ? "" : PERMISSION_DISPOSED_STATUS); + return; + } + + ErrCode ret = ERR_OK; + if (aniAppIndex == Constants::MAIN_APP_INDEX) { + ret = appControlProxy->DeleteDisposedStatus(appId); + } else { + ret = appControlProxy->DeleteDisposedRuleForCloneApp(appId, aniAppIndex); + } + if (ret != ERR_OK) { + APP_LOGE("DeleteDisposedStatusSync failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + isSync ? DELETE_DISPOSED_STATUS_SYNC : DELETE_DISPOSED_STATUS, PERMISSION_DISPOSED_STATUS); + } +} + +static ani_object AniGetDisposedRule(ani_env* env, ani_string aniAppId, ani_int aniAppIndex) +{ + APP_LOGD("ani GetDisposedRule called"); + std::string appId; + if (!CommonFunAni::ParseString(env, aniAppId, appId)) { + APP_LOGE("appId %{public}s invalid", appId.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_ID, TYPE_STRING); + return nullptr; + } + if (appId.empty()) { + APP_LOGE("appId is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPID, GET_DISPOSED_STATUS_SYNC, ""); + return nullptr; + } + + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_DISPOSED_STATUS_SYNC, ""); + return nullptr; + } + + DisposedRule disposedRule; + ErrCode ret = ERR_OK; + if (aniAppIndex == Constants::MAIN_APP_INDEX) { + ret = appControlProxy->GetDisposedRule(appId, disposedRule); + } else { + ret = appControlProxy->GetDisposedRuleForCloneApp(appId, disposedRule, aniAppIndex); + } + if (ret != ERR_OK) { + APP_LOGE("GetDisposedRule failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + GET_DISPOSED_STATUS_SYNC, PERMISSION_DISPOSED_STATUS); + return nullptr; + } + + return AniAppControlCommon::ConvertDisposedRule(env, disposedRule); +} + +static void AniSetDisposedRule(ani_env* env, ani_string aniAppId, ani_object aniRule, ani_int aniAppIndex) +{ + APP_LOGD("ani SetDisposedRule called"); + std::string appId; + if (!CommonFunAni::ParseString(env, aniAppId, appId)) { + APP_LOGE("appId %{public}s invalid", appId.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_ID, TYPE_STRING); + return; + } + if (appId.empty()) { + APP_LOGE("appId is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPID, SET_DISPOSED_RULE, ""); + return; + } + DisposedRule rule; + if (!AniAppControlCommon::ParseDisposedRule(env, aniRule, rule)) { + APP_LOGE("rule invalid!"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, DISPOSED_RULE, DISPOSED_RULE_TYPE); + return; + } + + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, SET_DISPOSED_RULE, ""); + return; + } + + ErrCode ret = ERR_OK; + if (aniAppIndex == Constants::MAIN_APP_INDEX) { + ret = appControlProxy->SetDisposedRule(appId, rule); + } else { + ret = appControlProxy->SetDisposedRuleForCloneApp(appId, rule, aniAppIndex); + } + if (ret != ERR_OK) { + APP_LOGE("SetDisposedRule failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + SET_DISPOSED_RULE, PERMISSION_DISPOSED_STATUS); + } +} + +static void AniSetUninstallDisposedRule(ani_env* env, + ani_string aniAppIdentifier, ani_object aniRule, ani_int aniAppIndex) +{ + APP_LOGD("ani SetUninstallDisposedRule called"); + std::string appIdentifier; + if (!CommonFunAni::ParseString(env, aniAppIdentifier, appIdentifier)) { + APP_LOGE("appIdentifier %{public}s invalid", appIdentifier.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_IDENTIFIER, TYPE_STRING); + return; + } + if (appIdentifier.empty()) { + APP_LOGE("appIdentifier is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPIDENTIFIER, SET_UNINSTALL_DISPOSED_RULE, ""); + return; + } + UninstallDisposedRule rule; + if (!AniAppControlCommon::ParseUninstallDisposedRule(env, aniRule, rule)) { + APP_LOGE("rule invalid!"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, + UNINSTALL_DISPOSED_RULE, UNINSTALL_DISPOSED_RULE_TYPE); + return; + } + int32_t userId = Constants::UNSPECIFIED_USERID; + + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, SET_UNINSTALL_DISPOSED_RULE, ""); + return; + } + + ErrCode ret = appControlProxy->SetUninstallDisposedRule(appIdentifier, rule, aniAppIndex, userId); + if (ret != ERR_OK) { + APP_LOGE("SetUninstallDisposedRule failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + SET_UNINSTALL_DISPOSED_RULE, PERMISSION_DISPOSED_STATUS); + } +} + +static ani_object AniGetUninstallDisposedRule(ani_env* env, ani_string aniAppIdentifier, ani_int aniAppIndex) +{ + APP_LOGD("ani GetUninstallDisposedRule called"); + std::string appIdentifier; + if (!CommonFunAni::ParseString(env, aniAppIdentifier, appIdentifier)) { + APP_LOGE("appIdentifier %{public}s invalid", appIdentifier.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_IDENTIFIER, TYPE_STRING); + return nullptr; + } + if (appIdentifier.empty()) { + APP_LOGE("appIdentifier is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPIDENTIFIER, GET_UNINSTALL_DISPOSED_RULE, ""); + return nullptr; + } + int32_t userId = Constants::UNSPECIFIED_USERID; + + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_UNINSTALL_DISPOSED_RULE, ""); + return nullptr; + } + + UninstallDisposedRule uninstallDisposedRule; + ErrCode ret = appControlProxy->GetUninstallDisposedRule(appIdentifier, aniAppIndex, userId, uninstallDisposedRule); + if (ret != ERR_OK) { + APP_LOGE("GetUninstallDisposedRule failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + GET_UNINSTALL_DISPOSED_RULE, PERMISSION_DISPOSED_STATUS); + return nullptr; + } + + return AniAppControlCommon::ConvertUninstallDisposedRule(env, uninstallDisposedRule); +} + +static void AniDeleteUninstallDisposedRule(ani_env* env, ani_string aniAppIdentifier, ani_int aniAppIndex) +{ + APP_LOGD("ani DeleteUninstallDisposedRule called"); + std::string appIdentifier; + if (!CommonFunAni::ParseString(env, aniAppIdentifier, appIdentifier)) { + APP_LOGE("appIdentifier %{public}s invalid", appIdentifier.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_IDENTIFIER, TYPE_STRING); + return; + } + if (appIdentifier.empty()) { + APP_LOGE("appIdentifier is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPIDENTIFIER, DELETE_UNINSTALL_DISPOSED_RULE, ""); + return; + } + int32_t userId = Constants::UNSPECIFIED_USERID; + + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, DELETE_UNINSTALL_DISPOSED_RULE, ""); + return; + } + + ErrCode ret = appControlProxy->DeleteUninstallDisposedRule(appIdentifier, aniAppIndex, userId); + if (ret != ERR_OK) { + APP_LOGE("DeleteUninstallDisposedRule failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + DELETE_UNINSTALL_DISPOSED_RULE, PERMISSION_DISPOSED_STATUS); + } +} + +static bool ParseDisposedRuleConfiguration( + ani_env* env, ani_object object, DisposedRuleConfiguration& disposedRuleConfiguration) +{ + if (env == nullptr || object == nullptr) { + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_TYPE_CHECK_ERROR); + return false; + } + + // appId: string + ani_string appId = nullptr; + if (!CommonFunAni::CallGetter(env, object, PROPERTYNAME_APPID, &appId)) { + APP_LOGE("appId invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_ID, TYPE_STRING); + return false; + } + disposedRuleConfiguration.appId = CommonFunAni::AniStrToString(env, appId); + if (disposedRuleConfiguration.appId.empty()) { + APP_LOGE("appId empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPID, SET_DISPOSED_RULES, ""); + return false; + } + + // appIndex: int + ani_int appIndex = Constants::MAIN_APP_INDEX; + if (!CommonFunAni::CallGetter(env, object, PROPERTYNAME_APPINDEX, &appIndex)) { + APP_LOGE("appIndex invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); + return false; + } + if (appIndex < Constants::MAIN_APP_INDEX || appIndex > Constants::CLONE_APP_INDEX_MAX) { + APP_LOGE("appIndex invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPINDEX, SET_DISPOSED_RULES, ""); + return false; + } + disposedRuleConfiguration.appIndex = appIndex; + + // disposedRule: DisposedRule + ani_object disposedRuleObject = nullptr; + if (!CommonFunAni::CallGetter(env, object, PROPERTYNAME_DISPOSEDRULE, &disposedRuleObject) || + !AniAppControlCommon::ParseDisposedRule(env, disposedRuleObject, disposedRuleConfiguration.disposedRule)) { + APP_LOGE("disposedRule invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, DISPOSED_RULE, DISPOSED_RULE_TYPE); + return false; + } + return true; +} + +static void SetDisposedRules(ani_env* env, ani_object aniDisposedRuleConfigurations) +{ + APP_LOGD("ani SetDisposedRules called"); + std::vector disposedRuleConfigurations; + if (!CommonFunAni::ParseAniArray(env, aniDisposedRuleConfigurations, disposedRuleConfigurations, + ParseDisposedRuleConfiguration)) { + APP_LOGE("Parse disposedRuleConfigurations invalid"); + return; + } + uint32_t arrayLength = disposedRuleConfigurations.size(); + if (arrayLength == 0 || arrayLength > MAX_VECTOR_NUM) { + APP_LOGE("disposedRuleConfigurations length invalid!"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_LENGTH_ERROR); + return; + } + auto appControlProxy = CommonFunc::GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("appControlProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, SET_DISPOSED_RULES, ""); + return; + } + + int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + ErrCode ret = appControlProxy->SetDisposedRules(disposedRuleConfigurations, userId); + if (ret != ERR_OK) { + APP_LOGE("SetDisposedRules failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, CommonFunc::ConvertErrCode(ret), SET_DISPOSED_RULES, PERMISSION_DISPOSED_STATUS); + } +} + +extern "C" { +ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) +{ + APP_LOGI("ANI_Constructor appControl called"); + ani_env* env; + ani_status status = vm->GetEnv(ANI_VERSION_1, &env); + RETURN_ANI_STATUS_IF_NOT_OK(status, "Unsupported ANI_VERSION_1"); + + arkts::ani_signature::Namespace nsName = + arkts::ani_signature::Builder::BuildNamespace(NS_NAME_APPCONTROL); + ani_namespace kitNs = nullptr; + status = env->FindNamespace(nsName.Descriptor().c_str(), &kitNs); + if (status != ANI_OK) { + APP_LOGE("FindNamespace: %{public}s fail with %{public}d", NS_NAME_APPCONTROL, status); + return status; + } + + std::array methods = { + ani_native_function { "setDisposedStatusNative", nullptr, reinterpret_cast(AniSetDisposedStatus) }, + ani_native_function { "getDisposedStatusNative", nullptr, reinterpret_cast(AniGetDisposedStatus) }, + ani_native_function { "deleteDisposedStatusNative", nullptr, reinterpret_cast(AniDeleteDisposedStatus) }, + ani_native_function { "getDisposedRuleNative", nullptr, reinterpret_cast(AniGetDisposedRule) }, + ani_native_function { "setDisposedRuleNative", nullptr, reinterpret_cast(AniSetDisposedRule) }, + ani_native_function { "setUninstallDisposedRuleNative", nullptr, + reinterpret_cast(AniSetUninstallDisposedRule) }, + ani_native_function { "getUninstallDisposedRuleNative", nullptr, + reinterpret_cast(AniGetUninstallDisposedRule) }, + ani_native_function { "deleteUninstallDisposedRuleNative", nullptr, + reinterpret_cast(AniDeleteUninstallDisposedRule) }, + ani_native_function { "setDisposedRules", nullptr, reinterpret_cast(SetDisposedRules) }, + }; + + status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); + if (status != ANI_OK) { + APP_LOGE("Namespace_BindNativeFunctions: %{public}s fail with %{public}d", NS_NAME_APPCONTROL, status); + return status; + } + + *result = ANI_VERSION_1; + + APP_LOGI("ANI_Constructor finished"); + + return ANI_OK; +} +} +} // AppExecFwk +} // OHOS \ No newline at end of file diff --git a/interfaces/kits/ani/app_control/ani_app_control_common.cpp b/interfaces/kits/ani/app_control/ani_app_control_common.cpp new file mode 100644 index 0000000000..e94bf04558 --- /dev/null +++ b/interfaces/kits/ani/app_control/ani_app_control_common.cpp @@ -0,0 +1,279 @@ +/* + * 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 + +#include "ani_app_control_common.h" +#include "ani_common_want.h" +#include "common_fun_ani.h" + +namespace OHOS { +namespace AppExecFwk { +using Want = OHOS::AAFwk::Want; + +namespace { +constexpr const char* CLASSNAME_DISPOSED_RULE_INNER = "@ohos.bundle.appControl.appControl.DisposedRuleInner"; +constexpr const char* CLASSNAME_DISPOSED_UNINSTALL_RULE_INNER = + "@ohos.bundle.appControl.appControl.UninstallDisposedRuleInner"; +constexpr const char* CLASSNAME_WANT = "@ohos.app.ability.Want.Want"; +constexpr const char* PROPERTYNAME_WANT = "want"; +constexpr const char* PROPERTYNAME_COMPONENT_TYPE = "componentType"; +constexpr const char* PROPERTYNAME_DISPOSED_TYPE = "disposedType"; +constexpr const char* PROPERTYNAME_CONTROL_TYPE = "controlType"; +constexpr const char* PROPERTYNAME_ELEMENT_LIST = "elementList"; +constexpr const char* PROPERTYNAME_PRIORITY = "priority"; +constexpr const char* PROPERTYNAME_UNINSTALL_COMPONENT_TYPE = "uninstallComponentType"; +constexpr const char* PROPERTYNAME_BUNDLE_NAME = "bundleName"; +constexpr const char* PROPERTYNAME_ABILITY_NAME = "abilityName"; +constexpr const char* PROPERTYNAME_DEVICEID = "deviceId"; +constexpr const char* PROPERTYNAME_URI = "uri"; +constexpr const char* PROPERTYNAME_TYPE = "type"; +constexpr const char* PROPERTYNAME_FLAGS = "flags"; +constexpr const char* PROPERTYNAME_ACTION = "action"; +constexpr const char* PROPERTYNAME_ENTITIES = "entities"; +constexpr const char* PROPERTYNAME_MODULE_NAME = "moduleName"; +} + +ani_object AniAppControlCommon::ConvertDisposedRule(ani_env* env, const DisposedRule& disposedRule) +{ + RETURN_NULL_IF_NULL(env); + + // want: Want + ani_object want = nullptr; + if (disposedRule.want != nullptr) { + want = WrapWant(env, *disposedRule.want); + RETURN_NULL_IF_NULL(want); + } + + // elementList: Array + ani_object elementList = CommonFunAni::ConvertAniArray( + env, disposedRule.elementList, CommonFunAni::ConvertElementName); + RETURN_NULL_IF_NULL(elementList); + + ani_value args[] = { + { .r = EnumUtils::EnumNativeToETS_AppControl_ComponentType( + env, static_cast(disposedRule.componentType)) }, + { .r = EnumUtils::EnumNativeToETS_AppControl_DisposedType( + env, static_cast(disposedRule.disposedType)) }, + { .r = EnumUtils::EnumNativeToETS_AppControl_ControlType(env, static_cast(disposedRule.controlType)) }, + { .r = elementList }, + { .i = disposedRule.priority }, + { .r = want }, + }; + static const std::string ctorSig = + arkts::ani_signature::SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_APPCONTROL_COMPONENT_TYPE) // componentType: ComponentType + .AddClass(CommonFunAniNS::CLASSNAME_APPCONTROL_DISPOSED_TYPE) // disposedType: DisposedType + .AddClass(CommonFunAniNS::CLASSNAME_APPCONTROL_CONTROL_TYPE) // controlType: ControlType + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // elementList: Array + .AddInt() // priority: int + .BuildSignatureDescriptor(); + static const std::string ctorSigWithWant = + arkts::ani_signature::SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_APPCONTROL_COMPONENT_TYPE) // componentType: ComponentType + .AddClass(CommonFunAniNS::CLASSNAME_APPCONTROL_DISPOSED_TYPE) // disposedType: DisposedType + .AddClass(CommonFunAniNS::CLASSNAME_APPCONTROL_CONTROL_TYPE) // controlType: ControlType + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // elementList: Array + .AddInt() // priority: int + .AddClass(CLASSNAME_WANT) // want: Want + .BuildSignatureDescriptor(); + return CommonFunAni::CreateNewObjectByClassV2( + env, CLASSNAME_DISPOSED_RULE_INNER, disposedRule.want == nullptr? ctorSig: ctorSigWithWant, args); +} + +ani_object AniAppControlCommon::ConvertUninstallDisposedRule(ani_env* env, + const UninstallDisposedRule& uninstallDisposedRule) +{ + RETURN_NULL_IF_NULL(env); + + // want: Want + ani_object want = nullptr; + if (uninstallDisposedRule.want != nullptr) { + want = WrapWant(env, *uninstallDisposedRule.want); + RETURN_NULL_IF_NULL(want); + } + + ani_value args[] = { + { .r = EnumUtils::EnumNativeToETS_AppControl_UninstallComponentType( + env, static_cast(uninstallDisposedRule.uninstallComponentType)) }, + { .i = uninstallDisposedRule.priority }, + { .r = want }, + }; + static const std::string ctorSig = + arkts::ani_signature::SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_APPCONTROL_UNINSTALL_COMPONENT_TYPE) // uninstallComponentType + .AddInt() // priority: int + .BuildSignatureDescriptor(); + static const std::string ctorSigWithWant = + arkts::ani_signature::SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_APPCONTROL_UNINSTALL_COMPONENT_TYPE) // uninstallComponentType + .AddInt() // priority: int + .AddClass(CLASSNAME_WANT) // want: Want + .BuildSignatureDescriptor(); + return CommonFunAni::CreateNewObjectByClassV2(env, CLASSNAME_DISPOSED_UNINSTALL_RULE_INNER, + uninstallDisposedRule.want == nullptr ? ctorSig : ctorSigWithWant, args); +} + +bool AniAppControlCommon::ParseWantWithoutVerification(ani_env* env, ani_object object, Want& want) +{ + RETURN_FALSE_IF_NULL(env); + RETURN_FALSE_IF_NULL(object); + + // bundleName?: string + ani_string string = nullptr; + std::string bundleName = ""; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_BUNDLE_NAME, &string)) { + bundleName = CommonFunAni::AniStrToString(env, string); + } + + // abilityName?: string + std::string abilityName = ""; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_ABILITY_NAME, &string)) { + abilityName = CommonFunAni::AniStrToString(env, string); + } + + // deviceId?: string + std::string deviceId = ""; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_DEVICEID, &string)) { + deviceId = CommonFunAni::AniStrToString(env, string); + } + + // uri?: string + std::string uri = ""; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_URI, &string)) { + uri = CommonFunAni::AniStrToString(env, string); + } + + // type?: string + std::string type = ""; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_TYPE, &string)) { + type = CommonFunAni::AniStrToString(env, string); + } + + // flags?: number + ani_double doubleValue = 0; + int32_t flags = 0; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_FLAGS, &doubleValue)) { + flags = doubleValue; + } + + // action?: string + std::string action = ""; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_ACTION, &string)) { + action = CommonFunAni::AniStrToString(env, string); + } + + // entities?: Array + ani_array array = nullptr; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_ENTITIES, &array)) { + std::vector entities; + if (CommonFunAni::ParseStrArray(env, array, entities)) { + for (size_t idx = 0; idx < entities.size(); ++idx) { + APP_LOGD("entity:%{public}s", entities[idx].c_str()); + want.AddEntity(entities[idx]); + } + } + } + + // moduleName?: string + std::string moduleName = ""; + if (CommonFunAni::CallGetFieldOptional(env, object, PROPERTYNAME_MODULE_NAME, &string)) { + moduleName = CommonFunAni::AniStrToString(env, string); + } + + want.SetAction(action); + want.SetUri(uri); + want.SetType(type); + want.SetFlags(flags); + ElementName elementName(deviceId, bundleName, abilityName, moduleName); + want.SetElement(elementName); + + return true; +} + +bool AniAppControlCommon::ParseDisposedRule(ani_env* env, ani_object object, DisposedRule& disposedRule) +{ + RETURN_FALSE_IF_NULL(env); + RETURN_FALSE_IF_NULL(object); + + ani_object objectValue = nullptr; + ani_enum_item enumItem = nullptr; + ani_array array = nullptr; + ani_int intValue = 0; + + // want: Want + Want want; + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_WANT, &objectValue)); + if (!UnwrapWant(env, objectValue, want)) { + APP_LOGE("parse want failed"); + return false; + } + disposedRule.want = std::make_shared(want); + + // componentType: ComponentType + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_COMPONENT_TYPE, &enumItem)); + RETURN_FALSE_IF_FALSE(EnumUtils::EnumETSToNative(env, enumItem, disposedRule.componentType)); + + // disposedType: DisposedType + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_DISPOSED_TYPE, &enumItem)); + RETURN_FALSE_IF_FALSE(EnumUtils::EnumETSToNative(env, enumItem, disposedRule.disposedType)); + + // controlType: ControlType + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_CONTROL_TYPE, &enumItem)); + RETURN_FALSE_IF_FALSE(EnumUtils::EnumETSToNative(env, enumItem, disposedRule.controlType)); + + // elementList: Array + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_ELEMENT_LIST, &array)); + RETURN_FALSE_IF_FALSE(CommonFunAni::ParseAniArray( + env, array, disposedRule.elementList, CommonFunAni::ParseElementName)); + + // priority: int + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_PRIORITY, &intValue)); + disposedRule.priority = intValue; + + return true; +} + +bool AniAppControlCommon::ParseUninstallDisposedRule(ani_env* env, + ani_object object, UninstallDisposedRule& uninstallDisposedRule) +{ + RETURN_FALSE_IF_NULL(env); + RETURN_FALSE_IF_NULL(object); + + ani_object objectValue = nullptr; + ani_enum_item enumItem = nullptr; + ani_int intValue = 0; + + // want: Want + Want want; + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_WANT, &objectValue)); + if (!UnwrapWant(env, objectValue, want)) { + APP_LOGE("parse want failed"); + return false; + } + uninstallDisposedRule.want = std::make_shared(want); + + // uninstallComponentType: UninstallComponentType + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_UNINSTALL_COMPONENT_TYPE, &enumItem)); + RETURN_FALSE_IF_FALSE(EnumUtils::EnumETSToNative(env, enumItem, uninstallDisposedRule.uninstallComponentType)); + + // priority: int + RETURN_FALSE_IF_FALSE(CommonFunAni::CallGetter(env, object, PROPERTYNAME_PRIORITY, &intValue)); + uninstallDisposedRule.priority = intValue; + + return true; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/ani/app_control/ani_app_control_common.h b/interfaces/kits/ani/app_control/ani_app_control_common.h new file mode 100644 index 0000000000..7eaa7a854b --- /dev/null +++ b/interfaces/kits/ani/app_control/ani_app_control_common.h @@ -0,0 +1,37 @@ +/* + * 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 BUNDLE_FRAMEWORK_INTERFACES_KITS_ANI_APP_CONTROL_COMMON_H +#define BUNDLE_FRAMEWORK_INTERFACES_KITS_ANI_APP_CONTROL_COMMON_H + +#include +#include "disposed_rule.h" + +namespace OHOS { +namespace AppExecFwk { +using Want = OHOS::AAFwk::Want; + +class AniAppControlCommon { +public: + static ani_object ConvertDisposedRule(ani_env* env, const DisposedRule& disposedRule); + static ani_object ConvertUninstallDisposedRule(ani_env* env, const UninstallDisposedRule& uninstallDisposedRule); + static bool ParseWantWithoutVerification(ani_env* env, ani_object object, Want& want); + static bool ParseDisposedRule(ani_env* env, ani_object object, DisposedRule& disposedRule); + static bool ParseUninstallDisposedRule(ani_env* env, + ani_object object, UninstallDisposedRule& uninstallDisposedRule); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // BUNDLE_FRAMEWORK_INTERFACES_KITS_ANI_APP_CONTROL_COMMON_H \ No newline at end of file diff --git a/interfaces/kits/ani/app_control/ani_app_control_unsupported.cpp b/interfaces/kits/ani/app_control/ani_app_control_unsupported.cpp new file mode 100644 index 0000000000..31a9b3ef2a --- /dev/null +++ b/interfaces/kits/ani/app_control/ani_app_control_unsupported.cpp @@ -0,0 +1,140 @@ +/* + * 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 + +#include "app_control_interface.h" +#include "app_log_wrapper.h" +#include "bundle_errors.h" +#include "business_error_ani.h" +#include "common_fun_ani.h" +#include "napi_constants.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +constexpr const char* NS_NAME_APPCONTROL = "@ohos.bundle.appControl.appControl"; +} // namespace + +static void AniSetDisposedStatus(ani_env* env, ani_string aniAppId, ani_object aniWant, ani_boolean aniIsSync) +{ + APP_LOGI("AppControl not supported"); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? SET_DISPOSED_STATUS_SYNC : SET_DISPOSED_STATUS, ""); +} + +static ani_object AniGetDisposedStatus(ani_env* env, ani_string aniAppId, ani_boolean aniIsSync) +{ + APP_LOGI("AppControl not supported"); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? GET_DISPOSED_STATUS_SYNC : GET_DISPOSED_STATUS, ""); + return nullptr; +} + +static void AniDeleteDisposedStatus(ani_env* env, ani_string aniAppId, ani_int aniAppIndex, ani_boolean aniIsSync) +{ + APP_LOGI("AppControl not supported"); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? DELETE_DISPOSED_STATUS_SYNC : DELETE_DISPOSED_STATUS, ""); +} + +static ani_object AniGetDisposedRule(ani_env* env, ani_string aniAppId, ani_int aniAppIndex) +{ + APP_LOGI("AppControl not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_DISPOSED_STATUS_SYNC, ""); + return nullptr; +} + +static void AniSetDisposedRule(ani_env* env, ani_string aniAppId, ani_object aniRule, ani_int aniAppIndex) +{ + APP_LOGI("AppControl not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, SET_DISPOSED_STATUS_SYNC, ""); +} + +static void AniSetUninstallDisposedRule(ani_env* env, + ani_string aniAppIdentifier, ani_object aniRule, ani_int aniAppIndex) +{ + APP_LOGI("AppControl not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, SET_UNINSTALL_DISPOSED_RULE, ""); +} + +static ani_object AniGetUninstallDisposedRule(ani_env* env, ani_string aniAppIdentifier, ani_int aniAppIndex) +{ + APP_LOGI("AppControl not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_UNINSTALL_DISPOSED_RULE, ""); + return nullptr; +} + +static void AniDeleteUninstallDisposedRule(ani_env* env, ani_string aniAppIdentifier, ani_int aniAppIndex) +{ + APP_LOGI("AppControl not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, DELETE_UNINSTALL_DISPOSED_RULE, ""); +} + +static void SetDisposedRules(ani_env* env, ani_object aniDisposedRuleConfigurations) +{ + APP_LOGI("AppControl not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, SET_DISPOSED_RULES, ""); +} + +extern "C" { +ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) +{ + APP_LOGI("ANI_Constructor appControl called"); + ani_env* env; + ani_status status = vm->GetEnv(ANI_VERSION_1, &env); + RETURN_ANI_STATUS_IF_NOT_OK(status, "Unsupported ANI_VERSION_1"); + + arkts::ani_signature::Namespace nsName = + arkts::ani_signature::Builder::BuildNamespace(NS_NAME_APPCONTROL); + ani_namespace kitNs = nullptr; + status = env->FindNamespace(nsName.Descriptor().c_str(), &kitNs); + if (status != ANI_OK) { + APP_LOGE("FindNamespace: %{public}s fail with %{public}d", NS_NAME_APPCONTROL, status); + return status; + } + + std::array methods = { + ani_native_function { "setDisposedStatusNative", nullptr, reinterpret_cast(AniSetDisposedStatus) }, + ani_native_function { "getDisposedStatusNative", nullptr, reinterpret_cast(AniGetDisposedStatus) }, + ani_native_function { "deleteDisposedStatusNative", nullptr, reinterpret_cast(AniDeleteDisposedStatus) }, + ani_native_function { "getDisposedRuleNative", nullptr, reinterpret_cast(AniGetDisposedRule) }, + ani_native_function { "setDisposedRuleNative", nullptr, reinterpret_cast(AniSetDisposedRule) }, + ani_native_function { "setUninstallDisposedRuleNative", nullptr, + reinterpret_cast(AniSetUninstallDisposedRule) }, + ani_native_function { "getUninstallDisposedRuleNative", nullptr, + reinterpret_cast(AniGetUninstallDisposedRule) }, + ani_native_function { "deleteUninstallDisposedRuleNative", nullptr, + reinterpret_cast(AniDeleteUninstallDisposedRule) }, + ani_native_function { "setDisposedRules", nullptr, reinterpret_cast(SetDisposedRules) }, + }; + + status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); + if (status != ANI_OK) { + APP_LOGE("Namespace_BindNativeFunctions: %{public}s fail with %{public}d", NS_NAME_APPCONTROL, status); + return status; + } + + *result = ANI_VERSION_1; + + APP_LOGI("ANI_Constructor finished"); + + return ANI_OK; +} +} +} // AppExecFwk +} // OHOS \ No newline at end of file diff --git a/interfaces/kits/ani/app_control/ets/@ohos.bundle.appControl.ets b/interfaces/kits/ani/app_control/ets/@ohos.bundle.appControl.ets new file mode 100644 index 0000000000..cfde5c5204 --- /dev/null +++ b/interfaces/kits/ani/app_control/ets/@ohos.bundle.appControl.ets @@ -0,0 +1,266 @@ +/* + * 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. + */ + +/** + * @file + * @kit AbilityKit + */ + +import { AsyncCallback, BusinessError } from '@ohos.base'; +import { ElementName } from 'bundleManager.ElementName'; +import Want from '@ohos.app.ability.Want'; + +export default namespace appControl { + loadLibraryWithPermissionCheck("ani_app_control.z", "@ohos.bundle.appControl"); + + export enum ComponentType { + UI_ABILITY = 1, + UI_EXTENSION = 2 + } + + export enum UninstallComponentType { + EXTENSION = 1, + } + + export enum DisposedType { + BLOCK_APPLICATION = 1, + BLOCK_ABILITY = 2, + NON_BLOCK = 3 + } + + export enum ControlType { + ALLOWED_LIST = 1, + DISALLOWED_LIST = 2 + } + + export interface DisposedRule { + want: Want; + componentType: ComponentType; + disposedType: DisposedType; + controlType: ControlType; + elementList: Array; + priority: int; + } + + export interface UninstallDisposedRule { + want: Want; + uninstallComponentType: UninstallComponentType; + priority: int; + } + + export interface DisposedRuleConfiguration { + appId: string; + appIndex: int; + disposedRule: DisposedRule; + } + + export class DisposedRuleInner implements DisposedRule { + public want: Want = {}; + public componentType: ComponentType = ComponentType.UI_ABILITY; + public disposedType: DisposedType = DisposedType.BLOCK_APPLICATION; + public controlType: ControlType = ControlType.ALLOWED_LIST; + public elementList: Array; + public priority: int; + + constructor() { } + constructor(componentType: ComponentType, + disposedType: DisposedType, + controlType: ControlType, + elementList: Array, + priority: int) { + this.componentType = componentType; + this.disposedType = disposedType; + this.controlType = controlType; + this.elementList = elementList; + this.priority = priority; + } + constructor(componentType: ComponentType, + disposedType: DisposedType, + controlType: ControlType, + elementList: Array, + priority: int, + want: Want) { + this.componentType = componentType; + this.disposedType = disposedType; + this.controlType = controlType; + this.elementList = elementList; + this.priority = priority; + this.want = want; + } + } + + export class UninstallDisposedRuleInner implements UninstallDisposedRule { + public want: Want = {}; + public uninstallComponentType: UninstallComponentType = UninstallComponentType.EXTENSION; + public priority: int; + + constructor() { } + constructor(uninstallComponentType: UninstallComponentType, priority: int) { + this.uninstallComponentType = uninstallComponentType; + this.priority = priority; + } + constructor(uninstallComponentType: UninstallComponentType, priority: int, want: Want) { + this.uninstallComponentType = uninstallComponentType; + this.priority = priority; + this.want = want; + } + } + + export class DisposedRuleConfigurationInner implements DisposedRuleConfiguration { + public appId: string = ''; + public appIndex: int; + public disposedRule: DisposedRule = new DisposedRuleInner; + } + + export native function setDisposedStatusNative(appId: string, disposedWant: Want, isSync: boolean): void; + export native function getDisposedStatusNative(appId: string, isSync: boolean): Want; + export native function deleteDisposedStatusNative(appId: string, appIndex: int, isSync: boolean): void; + export native function getDisposedRuleNative(appId: string, appIndex: int): DisposedRule; + export native function setDisposedRuleNative(appId: string, rule: DisposedRule, appIndex: int): void; + export native function setUninstallDisposedRuleNative(appIdentifier: string, rule: UninstallDisposedRule, appIndex: int): void; + export native function getUninstallDisposedRuleNative(appIdentifier: string, appIndex: int): UninstallDisposedRule; + export native function deleteUninstallDisposedRuleNative(appIdentifier: string, appIndex: int): void; + export native function setDisposedRules(disposedRuleConfigurations: Array): void; + + + function setDisposedStatus(appId: string, disposedWant: Want, callback: AsyncCallback): void { + let cb = (): void => { + return appControl.setDisposedStatusNative(appId, disposedWant, false); + }; + let p1 = taskpool.execute(cb); + p1.then(() => { + callback(null, undefined); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function setDisposedStatus(appId: string, disposedWant: Want): Promise { + let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void) : void => { + let cb = (): void => { + return appControl.setDisposedStatusNative(appId, disposedWant, false); + }; + let p1 = taskpool.execute(cb); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function setDisposedStatusSync(appId: string, disposedWant: Want): void { + return appControl.setDisposedStatusNative(appId, disposedWant, true); + } + + function getDisposedStatus(appId: string, callback: AsyncCallback): void { + let cb = (): Want => { + return appControl.getDisposedStatusNative(appId, false); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let result: Want = e as Want; + callback(null, result); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getDisposedStatus(appId: string): Promise { + let p = new Promise((resolve: (want: Want) => void, reject: (error: BusinessError) => void) => { + let cb = (): Want => { + return appControl.getDisposedStatusNative(appId, false); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let result: Want = e as Want; + resolve(result); + }, (err: Error): void => { + reject(err as BusinessError); + }); + }); + return p; + } + + function getDisposedStatusSync(appId: string): Want { + return appControl.getDisposedStatusNative(appId, true); + } + + function deleteDisposedStatus(appId: string, callback: AsyncCallback): void { + let cb = (): void => { + return appControl.deleteDisposedStatusNative(appId, 0, false); + }; + let p1 = taskpool.execute(cb); + p1.then(() => { + callback(null, undefined); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function deleteDisposedStatus(appId: string): Promise { + let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void) : void => { + let cb = (): void => { + return appControl.deleteDisposedStatusNative(appId, 0, false); + }; + let p1 = taskpool.execute(cb); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function deleteDisposedStatusSync(appId: string, appIndex?: int): void + { + let appIndexInfo = appIndex ?? 0; + return appControl.deleteDisposedStatusNative(appId, appIndexInfo, true); + } + + function getDisposedRule(appId: string, appIndex?: int): DisposedRule + { + let appIndexInfo = appIndex ?? 0; + return appControl.getDisposedRuleNative(appId, appIndexInfo); + } + + function setDisposedRule(appId: string, rule: DisposedRule, appIndex?: int): void + { + let appIndexInfo = appIndex ?? 0; + appControl.setDisposedRuleNative(appId, rule, appIndexInfo); + } + + function setUninstallDisposedRule(appIdentifier: string, rule: UninstallDisposedRule, appIndex?: int): void + { + let appIndexInfo = appIndex ?? 0; + appControl.setUninstallDisposedRuleNative(appIdentifier, rule, appIndexInfo); + } + + function getUninstallDisposedRule(appIdentifier: string, appIndex?: int): UninstallDisposedRule + { + let appIndexInfo = appIndex ?? 0; + return appControl.getUninstallDisposedRuleNative(appIdentifier, appIndexInfo); + } + + function deleteUninstallDisposedRule(appIdentifier: string, appIndex?: int): void + { + let appIndexInfo = appIndex ?? 0; + appControl.deleteUninstallDisposedRuleNative(appIdentifier, appIndexInfo); + } +} diff --git a/interfaces/kits/ani/bundle_installer/BUILD.gn b/interfaces/kits/ani/bundle_installer/BUILD.gn index b762f7e670..e078b73c23 100644 --- a/interfaces/kits/ani/bundle_installer/BUILD.gn +++ b/interfaces/kits/ani/bundle_installer/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") ohos_shared_library("ani_bundle_installer") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { diff --git a/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp b/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp index 5fbe484511..71d252799a 100644 --- a/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp +++ b/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp @@ -376,7 +376,7 @@ static void AniRemoveExtResource(ani_env* env, [[maybe_unused]] ani_object insta } } -static ani_double AniCreateAppClone(ani_env* env, [[maybe_unused]] ani_object installerObj, +static ani_int AniCreateAppClone(ani_env* env, [[maybe_unused]] ani_object installerObj, ani_string aniBundleName, ani_object aniCrtAppCloneParam) { APP_LOGD("ani CreateAppClone called"); @@ -384,7 +384,7 @@ static ani_double AniCreateAppClone(ani_env* env, [[maybe_unused]] ani_object in if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { APP_LOGE("parse bundleName failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); - return (ani_double)Constants::INITIAL_APP_INDEX; + return static_cast(Constants::INITIAL_APP_INDEX); } int32_t userId; int32_t appIdx; @@ -396,11 +396,11 @@ static ani_double AniCreateAppClone(ani_env* env, [[maybe_unused]] ani_object in if (res != SUCCESS) { BusinessErrorAni::ThrowCommonError(env, res, CREATE_APP_CLONE, Constants::PERMISSION_INSTALL_CLONE_BUNDLE); } - return (ani_double)appIdx; + return appIdx; } static void AniDestroyAppClone(ani_env* env, [[maybe_unused]] ani_object installerObj, - ani_string aniBundleName, ani_double aniAppIndex, ani_object aniDestroyAppCloneParam) + ani_string aniBundleName, ani_int aniAppIndex, ani_object aniDestroyAppCloneParam) { APP_LOGD("ani DestroyAppClone called"); std::string bundleName; @@ -409,12 +409,6 @@ static void AniDestroyAppClone(ani_env* env, [[maybe_unused]] ani_object install BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return; } - int32_t appIdx = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIdx)) { - APP_LOGE("Cast appIdx failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return; - } DestroyAppCloneParam destroyCloneParam; if (!CommonFunAni::ParseDestroyAppCloneParam(env, aniDestroyAppCloneParam, destroyCloneParam)) { APP_LOGE("DestroyAppCloneParam parse invalid"); @@ -425,7 +419,7 @@ static void AniDestroyAppClone(ani_env* env, [[maybe_unused]] ani_object install destroyCloneParam.userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } ErrCode result = CommonFunc::ConvertErrCode(InstallerHelper::InnerDestroyAppClone(bundleName, - destroyCloneParam.userId, appIdx, destroyCloneParam)); + destroyCloneParam.userId, aniAppIndex, destroyCloneParam)); if (result != SUCCESS) { BusinessErrorAni::ThrowCommonError(env, result, DESTROY_APP_CLONE, Constants::PERMISSION_UNINSTALL_CLONE_BUNDLE); @@ -433,7 +427,7 @@ static void AniDestroyAppClone(ani_env* env, [[maybe_unused]] ani_object install } static void AniInstallPreexistingApp(ani_env* env, [[maybe_unused]] ani_object installerObj, - ani_string aniBundleName, ani_double aniUserId) + ani_string aniBundleName, ani_int aniUserId) { APP_LOGD("ani InstallPreexistingApp called"); std::string bundleName; @@ -442,16 +436,10 @@ static void AniInstallPreexistingApp(ani_env* env, [[maybe_unused]] ani_object i BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return; } - int32_t userId = Constants::UNSPECIFIED_USERID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGE("Cast appIdx failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return; - } - if (userId == Constants::UNSPECIFIED_USERID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + if (aniUserId == Constants::UNSPECIFIED_USERID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } - ErrCode result = CommonFunc::ConvertErrCode(InstallerHelper::InnerInstallPreexistingApp(bundleName, userId)); + ErrCode result = CommonFunc::ConvertErrCode(InstallerHelper::InnerInstallPreexistingApp(bundleName, aniUserId)); if (result != SUCCESS) { BusinessErrorAni::ThrowCommonError(env, result, INSTALL_PREEXISTING_APP, Constants::PERMISSION_INSTALL_BUNDLE); @@ -547,10 +535,10 @@ static ani_object AniGetBundleInstaller(ani_env* env, ani_boolean aniIsSync) return nullptr; } g_isSystemApp = true; - ani_class installerClz = CommonFunAni::CreateClassByName(env, - Builder::BuildClass(INNERINSTALLER_CLASSNAME).Descriptor()); + static const std::string installerClzName = Builder::BuildClass(INNERINSTALLER_CLASSNAME).Descriptor(); + ani_class installerClz = CommonFunAni::CreateClassByName(env, installerClzName); RETURN_NULL_IF_NULL(installerClz); - return CommonFunAni::CreateNewObjectByClass(env, installerClz); + return CommonFunAni::CreateNewObjectByClass(env, installerClzName, installerClz); } static void GetInstallerMethods(std::array &installerMethods) diff --git a/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installer.ets b/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installer.ets index 70491d64f7..86c04f40c5 100644 --- a/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installer.ets +++ b/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installer.ets @@ -13,11 +13,6 @@ * limitations under the License. */ -/** - * @file - * @kit AbilityKit - */ - import { AsyncCallback, BusinessError } from '@ohos.base'; namespace installer { @@ -94,11 +89,11 @@ namespace installer { removeExtResource(bundleName: string, moduleNames: Array): Promise; - createAppClone(bundleName: string, createAppCloneParam?: CreateAppCloneParam): Promise; + createAppClone(bundleName: string, createAppCloneParam?: CreateAppCloneParam): Promise; - destroyAppClone(bundleName: string, appIndex: number, options?: number | DestroyAppCloneParam): Promise; + destroyAppClone(bundleName: string, appIndex: int, options?: int | DestroyAppCloneParam): Promise; - installPreexistingApp(bundleName: string, userId?: number): Promise; + installPreexistingApp(bundleName: string, userId?: int): Promise; installPlugin(hostBundleName: string, pluginFilePaths: Array, pluginParam?: PluginParam): Promise; @@ -121,11 +116,11 @@ namespace installer { } export interface InstallParam { - userId?: number; - installFlag?: number; + userId?: int; + installFlag?: int; isKeepData?: boolean; hashParams?: Array; - crowdtestDeadline?: number; + crowdtestDeadline?: long; sharedBundleDirPaths?: Array; specifiedDistributionType?: string; additionalInfo?: string; @@ -135,21 +130,21 @@ namespace installer { export interface UninstallParam { bundleName: string; - versionCode?: number; + versionCode?: int; } export interface CreateAppCloneParam { - userId?: number; - appIndex?: number; + userId?: int; + appIndex?: int; } export interface DestroyAppCloneParam { - userId?: number; + userId?: int; parameters?: Array; } export interface PluginParam { - userId?: number; + userId?: int; parameters?: Array; } } diff --git a/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets b/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets index de740d56fc..13acca1251 100644 --- a/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets +++ b/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets @@ -13,11 +13,6 @@ * limitations under the License. */ -/** - * @file - * @kit AbilityKit - */ - import { AsyncCallback, BusinessError } from '@ohos.base'; import installer from '@ohos.bundle.installer'; @@ -37,11 +32,11 @@ export class ParametersInner implements installer.Parameters { } export class InstallParamInner implements installer.InstallParam { - userId?: number; - installFlag?: number; + userId?: int; + installFlag?: int; isKeepData?: boolean; hashParams?: Array; - crowdtestDeadline?: number; + crowdtestDeadline?: long; sharedBundleDirPaths?: Array; specifiedDistributionType?: string; additionalInfo?: string; @@ -51,16 +46,16 @@ export class InstallParamInner implements installer.InstallParam { export class UninstallParamInner implements installer.UninstallParam { bundleName: string = ""; - versionCode?: number; + versionCode?: int; } export class CreateAppCloneParamInner implements installer.CreateAppCloneParam { - userId?: number; - appIndex?: number; + userId?: int; + appIndex?: int; } export class DestroyAppCloneParamInner implements installer.DestroyAppCloneParam { - userId?: number; + userId?: int; parameters?: Array; constructor() { super(); @@ -73,11 +68,58 @@ export class DestroyAppCloneParamInner implements installer.DestroyAppCloneParam } export class PluginParamInner implements installer.PluginParam { - userId?: number; + userId?: int; parameters?: Array; } -const UNSPECIFIED_USERID: number = -2; +const UNSPECIFIED_USERID: int = -2; +const SPECIFIED_DISTRIBUTION_TYPE_MAX_SIZE : number = 128; +const ADDITIONAL_INFO_MAX_SIZE: number = 3000; +const ERROR_PARAM_CHECK_ERROR: int = 401; +const SPECIFIED_DISTRIBUTION_TYPE_ERROR: string = "BusinessError 401: The size of specifiedDistributionType is greater than 128"; +const ADDITIONALINFO_ERROR: string = "BusinessError 401: The size of additionalInfo is greater than 3000"; +const PARAMETERTYPE_ERROR: string = "BusinessError 401: Parameter error. The type of parameters must be corresponding type."; + +function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'Error'; + err.message = message; + return err; +} + +function checkInstallParam(params: installer.InstallParam, needExtras: boolean): void { + + const hashParams = params.hashParams ?? new Array; + const moduleNameSet = new Set(); + for (const hashParam of hashParams) { + if (hashParam.moduleName === "" || hashParam.hashValue === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAMETERTYPE_ERROR); + } + if (moduleNameSet.has(hashParam.moduleName)) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAMETERTYPE_ERROR); + } + moduleNameSet.add(hashParam.moduleName); + } + + const pgoParams = params.pgoParams ?? new Array; + for (const pgoParam of pgoParams) { + if (pgoParam.moduleName === "" || pgoParam.pgoFilePath === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAMETERTYPE_ERROR); + } + } + if (!needExtras) { + return; + } + let specifiedDistributionType: string = params.specifiedDistributionType ?? ""; + if (specifiedDistributionType.length > SPECIFIED_DISTRIBUTION_TYPE_MAX_SIZE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, SPECIFIED_DISTRIBUTION_TYPE_ERROR); + } + let additionalInfo: string = params.additionalInfo ?? ""; + if (additionalInfo.length > ADDITIONAL_INFO_MAX_SIZE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, ADDITIONALINFO_ERROR); + } +} export class BundleInstallerInner implements installer.BundleInstaller { native installNative(hapFilePaths: Array, installParam: installer.InstallParam): void; @@ -88,13 +130,16 @@ export class BundleInstallerInner implements installer.BundleInstaller { native uninstallUpdatesNative(bundleName: string, installParam: installer.InstallParam): void; native addExtResourceNative(bundleName: string, filePaths: Array): void; native removeExtResourceNative(bundleName: string, moduleNames: Array): void; - native createAppCloneNative(bundleName: string, createAppCloneParam: installer.CreateAppCloneParam): number; - native destroyAppCloneNative(bundleName: string, appIndex: number, options: installer.DestroyAppCloneParam): void; - native installPreexistingAppNative(bundleName: string, userId: number): void; + native createAppCloneNative(bundleName: string, createAppCloneParam: installer.CreateAppCloneParam): int; + native destroyAppCloneNative(bundleName: string, appIndex: int, options: installer.DestroyAppCloneParam): void; + native installPreexistingAppNative(bundleName: string, userId: int): void; native installPluginNative(hostBundleName: string, pluginFilePaths: Array, pluginParam: installer.PluginParam): void; native uninstallPluginNative(hostBundleName: string, pluginBundleName: string, pluginParam: installer.PluginParam): void; install(hapFilePaths: Array, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, true); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -110,6 +155,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { } install(hapFilePaths: Array, installParam: installer.InstallParam, callback: AsyncCallback): void { + checkInstallParam(installParam, true); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.installNative(hapFilePaths, installParam); } let p1 = taskpool.execute(execFun); @@ -135,6 +181,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } uninstall(bundleName: string, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, false); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -150,8 +199,10 @@ export class BundleInstallerInner implements installer.BundleInstaller { } uninstall(bundleName: string, installParam: installer.InstallParam, callback: AsyncCallback): void { + checkInstallParam(installParam, false); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.uninstallNative(bundleName, installParam); } + let p1 = taskpool.execute(execFun); p1.then(() => { callback(null, undefined); @@ -175,6 +226,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } recover(bundleName: string, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, false); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -190,6 +244,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { } recover(bundleName: string, installParam: installer.InstallParam, callback: AsyncCallback): void { + checkInstallParam(installParam, false); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.recoverNative(bundleName, installParam); } let p1 = taskpool.execute(execFun); @@ -240,6 +295,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } updateBundleForSelf(hapFilePaths: Array, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, true); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -255,6 +313,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { } updateBundleForSelf(hapFilePaths: Array, installParam: installer.InstallParam, callback: AsyncCallback): void { + checkInstallParam(installParam, true); let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.updateBundleForSelfNative(hapFilePaths, installParam); } let p1 = taskpool.execute(execFun); @@ -280,6 +339,9 @@ export class BundleInstallerInner implements installer.BundleInstaller { } uninstallUpdates(bundleName: string, installParam?: installer.InstallParam): Promise { + if (installParam) { + checkInstallParam(installParam, false); + } let emptyParam = new InstallParamInner(); let params = installParam ?? emptyParam; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { @@ -320,14 +382,14 @@ export class BundleInstallerInner implements installer.BundleInstaller { return p; } - createAppClone(bundleName: string, createAppCloneParam?: installer.CreateAppCloneParam): Promise { + createAppClone(bundleName: string, createAppCloneParam?: installer.CreateAppCloneParam): Promise { let emptyParam = new CreateAppCloneParamInner(); let params = createAppCloneParam ?? emptyParam; - let p = new Promise((resolve: (v:number) => void, reject: (error: BusinessError) => void):void => { - let execFun = ():number=>{ return this.createAppCloneNative(bundleName, params); } + let p = new Promise((resolve: (v:int) => void, reject: (error: BusinessError) => void):void => { + let execFun = ():int=>{ return this.createAppCloneNative(bundleName, params); } let p1 = taskpool.execute(execFun); p1.then((appIdx: NullishType) => { - resolve(appIdx as number); + resolve(appIdx as int); }, (err: Error): void => { reject(err as BusinessError); }); @@ -335,7 +397,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { return p; } - destroyAppClone(bundleName: string, appIndex: number, options?: number | installer.DestroyAppCloneParam): Promise { + destroyAppClone(bundleName: string, appIndex: int, options?: int | installer.DestroyAppCloneParam): Promise { let defaultParam = new DestroyAppCloneParamInner(); let option = options ?? defaultParam; if (option instanceof installer.DestroyAppCloneParam) { @@ -357,7 +419,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { return p; } - installPreexistingApp(bundleName: string, userId?: number): Promise { + installPreexistingApp(bundleName: string, userId?: int): Promise { let userIdNum = userId ?? UNSPECIFIED_USERID; let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void):void => { let execFun = ():NullishType=>{ this.installPreexistingAppNative(bundleName, userIdNum); } diff --git a/interfaces/kits/ani/bundle_manager/BUILD.gn b/interfaces/kits/ani/bundle_manager/BUILD.gn index 737a910eb5..ac9c016ac8 100644 --- a/interfaces/kits/ani/bundle_manager/BUILD.gn +++ b/interfaces/kits/ani/bundle_manager/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") ohos_shared_library("ani_bundle_manager") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { @@ -66,13 +67,13 @@ ohos_shared_library("ani_bundle_manager") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", "runtime_core:ani", "runtime_core:ani_helpers", "samgr:samgr_proxy", - "ffrt:libffrt", ] if (global_resmgr_enable) { @@ -225,10 +226,101 @@ ohos_prebuilt_etc("skill_etc") { deps = [ ":skill" ] } +generate_static_abc("permission_def") { + base_url = "./ets" + files = [ + "./ets/bundleManager/PermissionDef.ets", + "./ets/bundleManager/PermissionDefInner.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/permission_def.abc" +} + +ohos_prebuilt_etc("permission_def_etc") { + source = "$target_out_dir/permission_def.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":permission_def" ] +} + +generate_static_abc("share_bundle_info") { + base_url = "./ets" + files = [ + "./ets/bundleManager/SharedBundleInfo.ets", + "./ets/bundleManager/SharedBundleInfoInner.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/share_bundle_info.abc" +} + +ohos_prebuilt_etc("share_bundle_info_etc") { + source = "$target_out_dir/share_bundle_info.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":share_bundle_info" ] +} + +generate_static_abc("app_provision_info") { + base_url = "./ets" + files = [ + "./ets/bundleManager/AppProvisionInfo.ets", + "./ets/bundleManager/AppProvisionInfoInner.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/app_provision_info.abc" +} + +ohos_prebuilt_etc("app_provision_info_etc") { + source = "$target_out_dir/app_provision_info.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":app_provision_info" ] +} + +generate_static_abc("recoverable_application_info") { + base_url = "./ets" + files = [ + "./ets/bundleManager/RecoverableApplicationInfo.ets", + "./ets/bundleManager/RecoverableApplicationInfoInner.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/recoverable_application_info.abc" +} + +ohos_prebuilt_etc("recoverable_application_info_etc") { + source = "$target_out_dir/recoverable_application_info.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":recoverable_application_info" ] +} + +generate_static_abc("plugin_bundle_info") { + base_url = "./ets" + files = [ + "./ets/bundleManager/PluginBundleInfo.ets", + "./ets/bundleManager/PluginBundleInfoInner.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/plugin_bundle_info.abc" +} + +ohos_prebuilt_etc("plugin_bundle_info_etc") { + source = "$target_out_dir/plugin_bundle_info.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":plugin_bundle_info" ] +} + ohos_copy("copy_bundleManager_ets") { sources = [ "./ets/bundleManager/AbilityInfoInner.ets", "./ets/bundleManager/ApplicationInfoInner.ets", + "./ets/bundleManager/BundleInfoInner.ets", "./ets/bundleManager/ExtensionAbilityInfoInner.ets", ] outputs = [ "$ohos_ets_inner_path/bundleManager/{{source_file_part}}" ] diff --git a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp index 3a79760087..5316346d51 100644 --- a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp +++ b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp @@ -34,11 +34,13 @@ #include "bundle_mgr_interface.h" #include "bundle_mgr_proxy.h" #include "business_error_ani.h" +#include "clean_cache_callback.h" #include "common_fun_ani.h" #include "common_func.h" #include "enum_util.h" #include "ipc_skeleton.h" #include "napi_constants.h" +#include "process_cache_callback_host.h" namespace OHOS { namespace AppExecFwk { @@ -51,6 +53,23 @@ static std::unordered_map g_aniCache; static std::string g_aniOwnBundleName; static std::mutex g_aniOwnBundleNameMutex; constexpr int32_t EMPTY_USER_ID = -500; +static std::set g_supportedProfileList = { 1 }; +static std::map appDistributionTypeMap = { + { ENUM_ONE, Constants::APP_DISTRIBUTION_TYPE_APP_GALLERY }, + { ENUM_TWO, Constants::APP_DISTRIBUTION_TYPE_ENTERPRISE }, + { ENUM_THREE, Constants::APP_DISTRIBUTION_TYPE_ENTERPRISE_NORMAL }, + { ENUM_FOUR, Constants::APP_DISTRIBUTION_TYPE_ENTERPRISE_MDM }, + { ENUM_FIVE, Constants::APP_DISTRIBUTION_TYPE_OS_INTEGRATION }, + { ENUM_SIX, Constants::APP_DISTRIBUTION_TYPE_CROWDTESTING }, + { ENUM_SEVEN, Constants::APP_DISTRIBUTION_TYPE_NONE }, +}; +constexpr int32_t EMPTY_VALUE = -500; +constexpr const char* EMPTY_STRING = "ani empty string"; +enum AbilityProfileType : uint32_t { + ABILITY_PROFILE = 0, + EXTENSION_PROFILE = 1, + UNKNOWN_PROFILE = 2 +}; } // namespace static void CheckToCache( @@ -173,15 +192,9 @@ static bool ParseAniWantList(ani_env* env, ani_object aniWants, std::vector lock(g_aniCacheMutex); auto item = g_aniCache.find(query); if (item != g_aniCache.end()) { @@ -201,7 +214,7 @@ static ani_object GetBundleInfoForSelfNative(ani_env* env, ani_double aniBundleF } BundleInfo bundleInfo; - ErrCode ret = iBundleMgr->GetBundleInfoForSelf(bundleFlags, bundleInfo); + ErrCode ret = iBundleMgr->GetBundleInfoForSelf(aniBundleFlags, bundleInfo); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("GetBundleInfoForSelf failed ret: %{public}d", ret); @@ -211,8 +224,8 @@ static ani_object GetBundleInfoForSelfNative(ani_env* env, ani_double aniBundleF return nullptr; } - ani_object objectBundleInfo = CommonFunAni::ConvertBundleInfo(env, bundleInfo, bundleFlags); - if (!CommonFunc::CheckBundleFlagWithPermission(bundleFlags)) { + ani_object objectBundleInfo = CommonFunAni::ConvertBundleInfo(env, bundleInfo, aniBundleFlags); + if (!CommonFunc::CheckBundleFlagWithPermission(aniBundleFlags)) { CheckToCache(env, bundleInfo.uid, uid, query, objectBundleInfo); } @@ -220,22 +233,12 @@ static ani_object GetBundleInfoForSelfNative(ani_env* env, ani_double aniBundleF } static ani_object GetBundleInfoNative(ani_env* env, - ani_string aniBundleName, ani_double aniBundleFlags, ani_double aniUserId, ani_boolean aniIsSync) + ani_string aniBundleName, ani_int aniBundleFlags, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGD("ani GetBundleInfo called"); - int32_t bundleFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniBundleFlags, &bundleFlags)) { - APP_LOGE("Cast aniBundleFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_FLAGS, TYPE_NUMBER); - return nullptr; - } - int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); - } int32_t callingUid = IPCSkeleton::GetCallingUid(); - if (userId == EMPTY_USER_ID) { - userId = callingUid / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = callingUid / Constants::BASE_USER_RANGE; } std::string bundleName; if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { @@ -250,8 +253,8 @@ static ani_object GetBundleInfoNative(ani_env* env, return nullptr; } - ANIQuery query(bundleName, GET_BUNDLE_INFO, bundleFlags, userId); - if (!CommonFunc::CheckBundleFlagWithPermission(bundleFlags)) { + ANIQuery query(bundleName, GET_BUNDLE_INFO, aniBundleFlags, aniUserId); + if (!CommonFunc::CheckBundleFlagWithPermission(aniBundleFlags)) { std::shared_lock lock(g_aniCacheMutex); auto item = g_aniCache.find(query); if (item != g_aniCache.end()) { @@ -267,7 +270,7 @@ static ani_object GetBundleInfoNative(ani_env* env, return nullptr; } BundleInfo bundleInfo; - ErrCode ret = iBundleMgr->GetBundleInfoV9(bundleName, bundleFlags, bundleInfo, userId); + ErrCode ret = iBundleMgr->GetBundleInfoV9(bundleName, aniBundleFlags, bundleInfo, aniUserId); if (ret != ERR_OK) { APP_LOGE("GetBundleInfoV9 failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), @@ -276,8 +279,8 @@ static ani_object GetBundleInfoNative(ani_env* env, return nullptr; } - ani_object objectBundleInfo = CommonFunAni::ConvertBundleInfo(env, bundleInfo, bundleFlags); - if (!CommonFunc::CheckBundleFlagWithPermission(bundleFlags)) { + ani_object objectBundleInfo = CommonFunAni::ConvertBundleInfo(env, bundleInfo, aniBundleFlags); + if (!CommonFunc::CheckBundleFlagWithPermission(aniBundleFlags)) { CheckToCache(env, bundleInfo.uid, callingUid, query, objectBundleInfo); } @@ -285,19 +288,9 @@ static ani_object GetBundleInfoNative(ani_env* env, } static ani_object GetApplicationInfoNative(ani_env* env, - ani_string aniBundleName, ani_double aniApplicationFlags, ani_double aniUserId, ani_boolean aniIsSync) + ani_string aniBundleName, ani_int aniApplicationFlags, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGD("ani GetApplicationInfo called"); - int32_t applicationFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniApplicationFlags, &applicationFlags)) { - APP_LOGE("Cast aniApplicationFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_FLAGS, TYPE_NUMBER); - return nullptr; - } - int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); - } std::string bundleName; if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { APP_LOGE("bundleName %{public}s invalid", bundleName.c_str()); @@ -305,8 +298,8 @@ static ani_object GetApplicationInfoNative(ani_env* env, return nullptr; } int32_t callingUid = IPCSkeleton::GetCallingUid(); - if (userId == EMPTY_USER_ID) { - userId = callingUid / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = callingUid / Constants::BASE_USER_RANGE; } bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); @@ -316,7 +309,7 @@ static ani_object GetApplicationInfoNative(ani_env* env, return nullptr; } - const ANIQuery query(bundleName, GET_APPLICATION_INFO, applicationFlags, userId); + const ANIQuery query(bundleName, GET_APPLICATION_INFO, aniApplicationFlags, aniUserId); { std::shared_lock lock(g_aniCacheMutex); auto item = g_aniCache.find(query); @@ -332,9 +325,9 @@ static ani_object GetApplicationInfoNative(ani_env* env, return nullptr; } ApplicationInfo appInfo; - ErrCode ret = iBundleMgr->GetApplicationInfoV9(bundleName, applicationFlags, userId, appInfo); + ErrCode ret = iBundleMgr->GetApplicationInfoV9(bundleName, aniApplicationFlags, aniUserId, appInfo); if (ret != ERR_OK) { - APP_LOGE("GetApplicationInfoV9 failed ret: %{public}d,userId: %{public}d", ret, userId); + APP_LOGE("GetApplicationInfoV9 failed ret: %{public}d,userId: %{public}d", ret, aniUserId); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), isSync ? GET_APPLICATION_INFO_SYNC : GET_APPLICATION_INFO, isSync ? BUNDLE_PERMISSIONS : Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); @@ -347,21 +340,11 @@ static ani_object GetApplicationInfoNative(ani_env* env, return objectApplicationInfo; } -static ani_object GetAllBundleInfoNative(ani_env* env, ani_double aniBundleFlags, ani_double aniUserId) +static ani_object GetAllBundleInfoNative(ani_env* env, ani_int aniBundleFlags, ani_int aniUserId) { APP_LOGD("ani GetAllBundleInfo called"); - int32_t bundleFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniBundleFlags, &bundleFlags)) { - APP_LOGE("Cast aniBundleFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_FLAGS, TYPE_NUMBER); - return nullptr; - } - int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); - } - if (userId == EMPTY_USER_ID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } auto iBundleMgr = CommonFunc::GetBundleMgr(); @@ -371,34 +354,23 @@ static ani_object GetAllBundleInfoNative(ani_env* env, ani_double aniBundleFlags return nullptr; } std::vector bundleInfos; - ErrCode ret = iBundleMgr->GetBundleInfosV9(bundleFlags, bundleInfos, userId); + ErrCode ret = iBundleMgr->GetBundleInfosV9(aniBundleFlags, bundleInfos, aniUserId); if (ret != ERR_OK) { APP_LOGE("GetBundleInfosV9 failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), GET_BUNDLE_INFOS, Constants::PERMISSION_GET_INSTALLED_BUNDLE_LIST); return nullptr; } - APP_LOGI("GetBundleInfosV9 ret: %{public}d, bundleInfos size: %{public}zu", ret, bundleInfos.size()); + APP_LOGD("GetBundleInfosV9 ret: %{public}d, bundleInfos size: %{public}zu", ret, bundleInfos.size()); - return CommonFunAni::ConvertAniArray(env, bundleInfos, CommonFunAni::ConvertBundleInfo, bundleFlags); + return CommonFunAni::ConvertAniArray(env, bundleInfos, CommonFunAni::ConvertBundleInfo, aniBundleFlags); } -static ani_object GetAllApplicationInfoNative(ani_env* env, ani_double aniApplicationFlags, ani_double aniUserId) +static ani_object GetAllApplicationInfoNative(ani_env* env, ani_int aniApplicationFlags, ani_int aniUserId) { APP_LOGD("ani GetAllApplicationInfo called"); - int32_t applicationFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniApplicationFlags, &applicationFlags)) { - APP_LOGE("Cast aniApplicationFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_FLAGS, TYPE_NUMBER); - return nullptr; - } - int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); - } - - if (userId == EMPTY_USER_ID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } auto iBundleMgr = CommonFunc::GetBundleMgr(); @@ -408,20 +380,20 @@ static ani_object GetAllApplicationInfoNative(ani_env* env, ani_double aniApplic return nullptr; } std::vector appInfos; - ErrCode ret = iBundleMgr->GetApplicationInfosV9(applicationFlags, userId, appInfos); + ErrCode ret = iBundleMgr->GetApplicationInfosV9(aniApplicationFlags, aniUserId, appInfos); if (ret != ERR_OK) { APP_LOGE("GetApplicationInfosV9 failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), GET_APPLICATION_INFOS, Constants::PERMISSION_GET_INSTALLED_BUNDLE_LIST); return nullptr; } - APP_LOGI("applicationInfos size: %{public}zu", appInfos.size()); + APP_LOGD("applicationInfos size: %{public}zu", appInfos.size()); return CommonFunAni::ConvertAniArray(env, appInfos, CommonFunAni::ConvertApplicationInfo); } static ani_boolean IsApplicationEnabledNative(ani_env* env, - ani_string aniBundleName, ani_double aniAppIndex, ani_boolean aniIsSync) + ani_string aniBundleName, ani_int aniAppIndex, ani_boolean aniIsSync) { APP_LOGD("ani IsApplicationEnabled called"); bool isEnable = false; @@ -431,12 +403,6 @@ static ani_boolean IsApplicationEnabledNative(ani_env* env, BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return isEnable; } - int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { - APP_LOGE("Cast aniAppIndex failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return isEnable; - } auto iBundleMgr = CommonFunc::GetBundleMgr(); if (iBundleMgr == nullptr) { APP_LOGE("GetBundleMgr failed"); @@ -449,8 +415,8 @@ static ani_boolean IsApplicationEnabledNative(ani_env* env, return isEnable; } ErrCode ret = ERR_OK; - if (appIndex != 0) { - ret = iBundleMgr->IsCloneApplicationEnabled(bundleName, appIndex, isEnable); + if (aniAppIndex != 0) { + ret = iBundleMgr->IsCloneApplicationEnabled(bundleName, aniAppIndex, isEnable); } else { ret = iBundleMgr->IsApplicationEnabled(bundleName, isEnable); } @@ -464,30 +430,19 @@ static ani_boolean IsApplicationEnabledNative(ani_env* env, } static ani_object QueryAbilityInfoSyncNative(ani_env* env, - ani_object aniWant, ani_double aniAbilityFlags, ani_double aniUserId, ani_boolean aniIsSync) + ani_object aniWant, ani_int aniAbilityFlags, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGD("ani QueryAbilityInfoSync called"); OHOS::AAFwk::Want want; - int32_t abilityFlags = 0; - int32_t userId = EMPTY_USER_ID; if (!ParseAniWant(env, aniWant, want)) { APP_LOGE("ParseAniWant failed"); BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, INVALID_WANT_ERROR); return nullptr; } - if (!CommonFunAni::TryCastDoubleTo(aniAbilityFlags, &abilityFlags)) { - APP_LOGE("Cast aniAbilityFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, ABILITY_FLAGS, TYPE_NUMBER); - return nullptr; - } - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } - - if (userId == EMPTY_USER_ID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; - } - const ANIQuery query(want.ToString(), QUERY_ABILITY_INFOS_SYNC, abilityFlags, userId); + const ANIQuery query(want.ToString(), QUERY_ABILITY_INFOS_SYNC, aniAbilityFlags, aniUserId); { std::shared_lock lock(g_aniCacheMutex); auto item = g_aniCache.find(query); @@ -503,7 +458,7 @@ static ani_object QueryAbilityInfoSyncNative(ani_env* env, return nullptr; } std::vector abilityInfos; - ErrCode ret = iBundleMgr->QueryAbilityInfosV9(want, abilityFlags, userId, abilityInfos); + ErrCode ret = iBundleMgr->QueryAbilityInfosV9(want, aniAbilityFlags, aniUserId, abilityInfos); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("QueryAbilityInfosV9 failed ret: %{public}d", ret); @@ -517,17 +472,10 @@ static ani_object QueryAbilityInfoSyncNative(ani_env* env, return aniAbilityInfos; } -static ani_object GetAppCloneIdentityNative(ani_env* env, ani_double aniUid) +static ani_object GetAppCloneIdentityNative(ani_env* env, ani_int aniUid) { APP_LOGD("ani GetAppCloneIdentity called"); - int32_t uid = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUid, &uid)) { - APP_LOGE("Cast aniUid failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::UID, TYPE_NUMBER); - return nullptr; - } - - bool queryOwn = (uid == IPCSkeleton::GetCallingUid()); + bool queryOwn = (aniUid == IPCSkeleton::GetCallingUid()); std::string bundleName; int32_t appIndex = 0; if (queryOwn) { @@ -539,7 +487,7 @@ static ani_object GetAppCloneIdentityNative(ani_env* env, ani_double aniUid) } } - ErrCode ret = BundleManagerHelper::InnerGetAppCloneIdentity(uid, bundleName, appIndex); + ErrCode ret = BundleManagerHelper::InnerGetAppCloneIdentity(aniUid, bundleName, appIndex); if (ret != ERR_OK) { APP_LOGE("GetNameAndIndexForUid failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, ret, GET_APP_CLONE_IDENTITY, APP_CLONE_IDENTITY_PERMISSIONS); @@ -610,7 +558,7 @@ static ani_string GetAbilityLabelNative(ani_env* env, } static ani_object GetLaunchWantForBundleNative(ani_env* env, - ani_string aniBundleName, ani_double aniUserId, ani_boolean aniIsSync) + ani_string aniBundleName, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGD("ani GetLaunchWantForBundle called"); std::string bundleName; @@ -619,12 +567,8 @@ static ani_object GetLaunchWantForBundleNative(ani_env* env, BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } - int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); - } - if (userId == EMPTY_USER_ID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } auto iBundleMgr = CommonFunc::GetBundleMgr(); @@ -634,7 +578,7 @@ static ani_object GetLaunchWantForBundleNative(ani_env* env, return nullptr; } OHOS::AAFwk::Want want; - ErrCode ret = iBundleMgr->GetLaunchWantForBundle(bundleName, want, userId); + ErrCode ret = iBundleMgr->GetLaunchWantForBundle(bundleName, want, aniUserId); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("GetLaunchWantForBundle failed ret: %{public}d", ret); @@ -647,7 +591,7 @@ static ani_object GetLaunchWantForBundleNative(ani_env* env, } static ani_object GetAppCloneBundleInfoNative(ani_env* env, ani_string aniBundleName, - ani_double aniAppIndex, ani_double aniBundleFlags, ani_double aniUserId) + ani_int aniAppIndex, ani_int aniBundleFlags, ani_int aniUserId) { APP_LOGD("ani GetAppCloneBundleInfo called"); std::string bundleName; @@ -656,24 +600,8 @@ static ani_object GetAppCloneBundleInfoNative(ani_env* env, ani_string aniBundle BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } - int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { - APP_LOGE("Cast aniAppIndex failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return nullptr; - } - int32_t bundleFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniBundleFlags, &bundleFlags)) { - APP_LOGE("Cast aniBundleFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_FLAGS, TYPE_NUMBER); - return nullptr; - } - int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, use default value"); - } - if (userId == EMPTY_USER_ID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } auto iBundleMgr = CommonFunc::GetBundleMgr(); @@ -683,7 +611,7 @@ static ani_object GetAppCloneBundleInfoNative(ani_env* env, ani_string aniBundle return nullptr; } BundleInfo bundleInfo; - ErrCode ret = iBundleMgr->GetCloneBundleInfo(bundleName, bundleFlags, appIndex, bundleInfo, userId); + ErrCode ret = iBundleMgr->GetCloneBundleInfo(bundleName, aniBundleFlags, aniAppIndex, bundleInfo, aniUserId); if (ret != ERR_OK) { APP_LOGE("GetCloneBundleInfo failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), @@ -691,7 +619,7 @@ static ani_object GetAppCloneBundleInfoNative(ani_env* env, ani_string aniBundle return nullptr; } - return CommonFunAni::ConvertBundleInfo(env, bundleInfo, bundleFlags); + return CommonFunAni::ConvertBundleInfo(env, bundleInfo, aniBundleFlags); } static ani_string GetSpecifiedDistributionType(ani_env* env, ani_string aniBundleName) @@ -726,19 +654,12 @@ static ani_string GetSpecifiedDistributionType(ani_env* env, ani_string aniBundl return aniSpecifiedDistributionType; } -static ani_string GetBundleNameByUidNative(ani_env* env, ani_double aniUserId, ani_boolean aniIsSync) +static ani_string GetBundleNameByUidNative(ani_env* env, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGD("ani GetBundleNameByUid called"); - int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGE("Cast userId failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::UID, TYPE_NUMBER); - return nullptr; - } - std::string bundleName; ani_string aniBundleName = nullptr; - bool queryOwn = (userId == IPCSkeleton::GetCallingUid()); + bool queryOwn = (aniUserId == IPCSkeleton::GetCallingUid()); if (queryOwn) { std::lock_guard lock(g_aniOwnBundleNameMutex); if (!g_aniOwnBundleName.empty()) { @@ -754,7 +675,7 @@ static ani_string GetBundleNameByUidNative(ani_env* env, ani_double aniUserId, a } } int32_t appIndex = 0; - ErrCode ret = BundleManagerHelper::InnerGetAppCloneIdentity(userId, bundleName, appIndex); + ErrCode ret = BundleManagerHelper::InnerGetAppCloneIdentity(aniUserId, bundleName, appIndex); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { BusinessErrorAni::ThrowCommonError( @@ -779,28 +700,17 @@ static ani_string GetBundleNameByUidNative(ani_env* env, ani_double aniUserId, a } static ani_object QueryAbilityInfoWithWantsNative(ani_env* env, - ani_object aniWants, ani_double aniAbilityFlags, ani_double aniUserId) + ani_object aniWants, ani_int aniAbilityFlags, ani_int aniUserId) { APP_LOGD("ani QueryAbilityInfoWithWants called"); std::vector wants; - int32_t abilityFlags = 0; - int32_t userId = EMPTY_USER_ID; if (!ParseAniWantList(env, aniWants, wants) || wants.empty()) { APP_LOGE("ParseAniWant failed"); BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, INVALID_WANT_ERROR); return nullptr; } - if (!CommonFunAni::TryCastDoubleTo(aniAbilityFlags, &abilityFlags)) { - APP_LOGE("Cast aniAbilityFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, ABILITY_FLAGS, TYPE_NUMBER); - return nullptr; - } - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); - } - - if (userId == EMPTY_USER_ID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } std::string bundleNames = "["; for (uint32_t i = 0; i < wants.size(); i++) { @@ -808,7 +718,7 @@ static ani_object QueryAbilityInfoWithWantsNative(ani_env* env, bundleNames += wants[i].ToString(); } bundleNames += "]"; - const ANIQuery query(bundleNames, BATCH_QUERY_ABILITY_INFOS, abilityFlags, userId); + const ANIQuery query(bundleNames, BATCH_QUERY_ABILITY_INFOS, aniAbilityFlags, aniUserId); { std::shared_lock lock(g_aniCacheMutex); auto item = g_aniCache.find(query); @@ -819,7 +729,7 @@ static ani_object QueryAbilityInfoWithWantsNative(ani_env* env, } std::vector abilityInfos; - ErrCode ret = BundleManagerHelper::InnerBatchQueryAbilityInfos(wants, abilityFlags, userId, abilityInfos); + ErrCode ret = BundleManagerHelper::InnerBatchQueryAbilityInfos(wants, aniAbilityFlags, aniUserId, abilityInfos); if (ret != ERR_OK) { APP_LOGE("BatchQueryAbilityInfos failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, ret, BATCH_QUERY_ABILITY_INFOS, BUNDLE_PERMISSIONS); @@ -857,7 +767,7 @@ static ani_string GetDynamicIconNative(ani_env* env, ani_string aniBundleName) } static ani_boolean IsAbilityEnabledNative(ani_env* env, - ani_object aniAbilityInfo, ani_double aniAppIndex, ani_boolean aniIsSync) + ani_object aniAbilityInfo, ani_int aniAppIndex, ani_boolean aniIsSync) { APP_LOGD("ani IsAbilityEnabled called"); bool isEnable = false; @@ -867,13 +777,7 @@ static ani_boolean IsAbilityEnabledNative(ani_env* env, BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, ABILITY_INFO, TYPE_OBJECT); return isEnable; } - int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { - APP_LOGE("Cast aniAppIndex failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return isEnable; - } - ErrCode ret = BundleManagerHelper::InnerIsAbilityEnabled(abilityInfo, isEnable, appIndex); + ErrCode ret = BundleManagerHelper::InnerIsAbilityEnabled(abilityInfo, isEnable, aniAppIndex); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("IsAbilityEnabled failed ret: %{public}d", ret); @@ -883,7 +787,7 @@ static ani_boolean IsAbilityEnabledNative(ani_env* env, } static void SetAbilityEnabledNative(ani_env* env, - ani_object aniAbilityInfo, ani_boolean aniIsEnable, ani_double aniAppIndex, ani_boolean aniIsSync) + ani_object aniAbilityInfo, ani_boolean aniIsEnable, ani_int aniAppIndex, ani_boolean aniIsSync) { APP_LOGD("ani SetAbilityEnabled called"); AbilityInfo abilityInfo; @@ -893,13 +797,7 @@ static void SetAbilityEnabledNative(ani_env* env, BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, ABILITY_INFO, TYPE_OBJECT); return; } - int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { - APP_LOGE("Cast aniAppIndex failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return; - } - ErrCode ret = BundleManagerHelper::InnerSetAbilityEnabled(abilityInfo, isEnable, appIndex); + ErrCode ret = BundleManagerHelper::InnerSetAbilityEnabled(abilityInfo, isEnable, aniAppIndex); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("SetAbilityEnabled failed ret: %{public}d", ret); @@ -910,7 +808,7 @@ static void SetAbilityEnabledNative(ani_env* env, } static void SetApplicationEnabledNative(ani_env* env, - ani_string aniBundleName, ani_boolean aniIsEnable, ani_double aniAppIndex, ani_boolean aniIsSync) + ani_string aniBundleName, ani_boolean aniIsEnable, ani_int aniAppIndex, ani_boolean aniIsSync) { APP_LOGD("ani SetApplicationEnabled called"); bool isEnable = CommonFunAni::AniBooleanToBool(aniIsEnable); @@ -920,13 +818,7 @@ static void SetApplicationEnabledNative(ani_env* env, BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return; } - int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { - APP_LOGE("Cast aniAppIndex failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return; - } - ErrCode ret = BundleManagerHelper::InnerSetApplicationEnabled(bundleName, isEnable, appIndex); + ErrCode ret = BundleManagerHelper::InnerSetApplicationEnabled(bundleName, isEnable, aniAppIndex); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("SetApplicationEnabled failed ret: %{public}d", ret); @@ -938,14 +830,12 @@ static void SetApplicationEnabledNative(ani_env* env, static ani_object QueryExtensionAbilityInfoNative(ani_env* env, ani_object aniWant, ani_enum_item aniExtensionAbilityType, ani_string aniExtensionAbilityTypeName, - ani_double aniExtensionAbilityFlags, ani_double aniUserId, + ani_int aniExtensionAbilityFlags, ani_int aniUserId, ani_boolean aniIsExtensionTypeName, ani_boolean aniIsSync) { APP_LOGD("ani QueryExtensionAbilityInfo called"); OHOS::AAFwk::Want want; ExtensionAbilityType extensionAbilityType = ExtensionAbilityType::UNSPECIFIED; - int32_t flags = 0; - int32_t userId = EMPTY_USER_ID; std::string extensionTypeName; bool isExtensionTypeName = CommonFunAni::AniBooleanToBool(aniIsExtensionTypeName); @@ -967,20 +857,12 @@ static ani_object QueryExtensionAbilityInfoNative(ani_env* env, return nullptr; } } - if (!CommonFunAni::TryCastDoubleTo(aniExtensionAbilityFlags, &flags)) { - APP_LOGE("Cast aniExtensionAbilityFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, FLAGS, TYPE_NUMBER); - return nullptr; - } - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); - } - if (userId == EMPTY_USER_ID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } std::string key = want.ToString() + std::to_string(static_cast(extensionAbilityType)); - const ANIQuery query(key, QUERY_EXTENSION_INFOS_SYNC, flags, userId); + const ANIQuery query(key, QUERY_EXTENSION_INFOS_SYNC, aniExtensionAbilityFlags, aniUserId); { std::shared_lock lock(g_aniCacheMutex); auto item = g_aniCache.find(query); @@ -1001,16 +883,17 @@ static ani_object QueryExtensionAbilityInfoNative(ani_env* env, if (!isExtensionTypeName) { if (extensionAbilityType == ExtensionAbilityType::UNSPECIFIED) { APP_LOGD("Query aniExtensionAbilityInfo sync without type"); - ret = iBundleMgr->QueryExtensionAbilityInfosV9(want, flags, userId, extensionInfos); + ret = iBundleMgr->QueryExtensionAbilityInfosV9(want, aniExtensionAbilityFlags, aniUserId, extensionInfos); } else { APP_LOGD("Query aniExtensionAbilityInfo sync with type %{public}d", static_cast(extensionAbilityType)); - ret = iBundleMgr->QueryExtensionAbilityInfosV9(want, extensionAbilityType, flags, userId, extensionInfos); + ret = iBundleMgr->QueryExtensionAbilityInfosV9( + want, extensionAbilityType, aniExtensionAbilityFlags, aniUserId, extensionInfos); } } else { APP_LOGD("Query aniExtensionAbilityInfo sync with extensionTypeName %{public}s", extensionTypeName.c_str()); ret = iBundleMgr->QueryExtensionAbilityInfosWithTypeName( - want, extensionTypeName, flags, userId, extensionInfos); + want, extensionTypeName, aniExtensionAbilityFlags, aniUserId, extensionInfos); } bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); @@ -1027,12 +910,9 @@ static ani_object QueryExtensionAbilityInfoNative(ani_env* env, } static ani_object QueryExAbilityInfoSyncWithoutWant(ani_env* env, ani_string aniExtensionAbilityTypeName, - ani_double aniExtensionAbilityFlags, ani_double aniUserId) + ani_int aniExtensionAbilityFlags, ani_int aniUserId) { APP_LOGD("ani QueryExAbilityInfoSyncWithoutWant called"); - int32_t flags = 0; - int32_t userId = EMPTY_USER_ID; - std::string extensionTypeName; if (!CommonFunAni::ParseString(env, aniExtensionAbilityTypeName, extensionTypeName)) { APP_LOGE("parse extensionTypeName failed"); @@ -1044,16 +924,8 @@ static ani_object QueryExAbilityInfoSyncWithoutWant(ani_env* env, ani_string ani BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_EXTENSION_ABILITY_TYPE_EMPTY_ERROR); return nullptr; } - if (!CommonFunAni::TryCastDoubleTo(aniExtensionAbilityFlags, &flags)) { - APP_LOGE("Cast aniExtensionAbilityFlags failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, FLAGS, TYPE_NUMBER); - return nullptr; - } - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("Parse userId failed, set this parameter to the caller userId"); - } - if (userId == EMPTY_USER_ID) { - userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; } auto iBundleMgr = CommonFunc::GetBundleMgr(); @@ -1064,7 +936,8 @@ static ani_object QueryExAbilityInfoSyncWithoutWant(ani_env* env, ani_string ani } std::vector extensionInfos; ErrCode ret = iBundleMgr->QueryExtensionAbilityInfosOnlyWithTypeName(extensionTypeName, - (flags < 0 ? 0 : static_cast(flags)), userId, extensionInfos); + (aniExtensionAbilityFlags < 0 ? 0 : static_cast(aniExtensionAbilityFlags)), aniUserId, + extensionInfos); if (ret != ERR_OK) { APP_LOGE("QueryExAbilityInfoSync without want failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), @@ -1074,7 +947,8 @@ static ani_object QueryExAbilityInfoSyncWithoutWant(ani_env* env, ani_string ani return CommonFunAni::ConvertAniArray(env, extensionInfos, CommonFunAni::ConvertExtensionInfo); } -static void EnableDynamicIconNative(ani_env* env, ani_string aniBundleName, ani_string aniModuleName) +static void EnableDynamicIconNative( + ani_env* env, ani_string aniBundleName, ani_string aniModuleName, ani_object aniBundleOptions) { APP_LOGD("ani EnableDynamicIcon called"); std::string bundleName; @@ -1089,13 +963,965 @@ static void EnableDynamicIconNative(ani_env* env, ani_string aniBundleName, ani_ BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, MODULE_NAME, TYPE_STRING); return; } - - ErrCode ret = BundleManagerHelper::InnerEnableDynamicIcon(bundleName, moduleName, 0, 0, true); + int32_t appIndex = 0; + int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + bool isDefault = CommonFunAni::ParseBundleOptions(env, aniBundleOptions, appIndex, userId); + + ErrCode ret = BundleManagerHelper::InnerEnableDynamicIcon(bundleName, moduleName, appIndex, userId, isDefault); if (ret != ERR_OK) { APP_LOGE("EnableDynamicIcon failed ret: %{public}d", ret); - BusinessErrorAni::ThrowCommonError(env, ret, - ENABLE_DYNAMIC_ICON, Constants::PERMISSION_ACCESS_DYNAMIC_ICON); + BusinessErrorAni::ThrowCommonError(env, ret, ENABLE_DYNAMIC_ICON, + isDefault ? Constants::PERMISSION_ACCESS_DYNAMIC_ICON : BUNDLE_ENABLE_AND_DISABLE_ALL_DYNAMIC_PERMISSIONS); + } +} + +static ani_object GetBundleArchiveInfoNative( + ani_env* env, ani_string aniHapFilePath, ani_int aniBundleFlags, ani_boolean aniIsSync) +{ + APP_LOGD("ani GetBundleArchiveInfoNative called"); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + std::string hapFilePath; + if (!CommonFunAni::ParseString(env, aniHapFilePath, hapFilePath)) { + APP_LOGE("hapFilePath parse failed"); + if (isSync) { + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, HAP_FILE_PATH, TYPE_STRING); + } else { + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_TYPE_CHECK_ERROR); + } + return nullptr; + } + BundleInfo bundleInfo; + ErrCode ret = BundleManagerHelper::InnerGetBundleArchiveInfo(hapFilePath, aniBundleFlags, bundleInfo); + if (ret != ERR_OK) { + APP_LOGE("InnerGetBundleArchiveInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, isSync ? GET_BUNDLE_ARCHIVE_INFO_SYNC : GET_BUNDLE_ARCHIVE_INFO, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + return CommonFunAni::ConvertBundleInfo(env, bundleInfo, aniBundleFlags); +} + +static ani_object GetLaunchWant(ani_env* env) +{ + APP_LOGD("ani GetLaunchWant called"); + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return nullptr; + } + OHOS::AAFwk::Want want; + ErrCode ret = iBundleMgr->GetLaunchWant(want); + if (ret != ERR_OK) { + APP_LOGE("GetLaunchWant failed ret: %{public}d", ret); + BusinessErrorAni::ThrowError(env, ERROR_GET_LAUNCH_WANT_INVALID, ERR_MSG_LAUNCH_WANT_INVALID); + return nullptr; + } + ElementName elementName = want.GetElement(); + if (elementName.GetBundleName().empty() || elementName.GetAbilityName().empty()) { + APP_LOGE("bundleName or abilityName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_GET_LAUNCH_WANT_INVALID, ERR_MSG_LAUNCH_WANT_INVALID); + return nullptr; + } + + return CommonFunAni::ConvertWantInfo(env, want); +} + +static ErrCode InnerGetProfile(const std::string& moduleName, const std::string& abilityName, + const std::string& metadataName, AbilityProfileType profileType, std::vector& profileVec) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("can not get iBundleMgr"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + + if (abilityName.empty()) { + APP_LOGE("InnerGetProfile failed due to empty abilityName"); + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; + } + + if (moduleName.empty()) { + APP_LOGE("InnerGetProfile failed due to empty moduleName"); + return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST; + } + auto baseFlag = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE); + ErrCode result; + BundleMgrClient client; + BundleInfo bundleInfo; + if (profileType == AbilityProfileType::ABILITY_PROFILE) { + auto getAbilityFlag = baseFlag + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY); + result = iBundleMgr->GetBundleInfoForSelf(getAbilityFlag, bundleInfo); + if (result != ERR_OK) { + APP_LOGE("GetBundleInfoForSelf failed"); + return result; + } + AbilityInfo targetAbilityInfo; + result = BundleManagerHelper::GetAbilityFromBundleInfo( + bundleInfo, abilityName, moduleName, targetAbilityInfo); + if (result != ERR_OK) { + return result; + } + if (!client.GetProfileFromAbility(targetAbilityInfo, metadataName, profileVec)) { + APP_LOGE("GetProfileFromExtension failed"); + return ERR_BUNDLE_MANAGER_PROFILE_NOT_EXIST; + } + return ERR_OK; + } + + if (profileType == AbilityProfileType::EXTENSION_PROFILE) { + auto getExtensionFlag = baseFlag + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY); + result = iBundleMgr->GetBundleInfoForSelf(getExtensionFlag, bundleInfo); + if (result != ERR_OK) { + APP_LOGE("GetBundleInfoForSelf failed"); + return result; + } + + ExtensionAbilityInfo targetExtensionInfo; + result = BundleManagerHelper::GetExtensionFromBundleInfo( + bundleInfo, abilityName, moduleName, targetExtensionInfo); + if (result != ERR_OK) { + return result; + } + if (!client.GetProfileFromExtension(targetExtensionInfo, metadataName, profileVec)) { + APP_LOGE("GetProfileFromExtension failed"); + return ERR_BUNDLE_MANAGER_PROFILE_NOT_EXIST; + } + return ERR_OK; + } + + APP_LOGE("InnerGetProfile failed due to type is invalid"); + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; +} + +static ani_object GetProfileByAbilityNative(ani_env* env, ani_string aniModuleName, ani_string aniAbilityName, + ani_string aniMetadataName, ani_enum_item aniProfileType, ani_boolean aniIsSync) +{ + APP_LOGD("ani GetProfileByAbilityNative called"); + std::string moduleName; + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + if (!CommonFunAni::ParseString(env, aniModuleName, moduleName)) { + APP_LOGE("moduleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::MODULE_NAME, TYPE_STRING); + return nullptr; + } + if (isSync && moduleName.empty()) { + APP_LOGE("param failed due to empty moduleName"); + BusinessErrorAni::ThrowCommonError(env, ERROR_MODULE_NOT_EXIST, "", ""); + return nullptr; + } + std::string abilityName; + if (!CommonFunAni::ParseString(env, aniAbilityName, abilityName)) { + APP_LOGE("abilityName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::ABILITY_NAME, TYPE_STRING); + return nullptr; + } + if (isSync && abilityName.empty()) { + APP_LOGE("param failed due to empty abilityName"); + BusinessErrorAni::ThrowCommonError(env, ERROR_ABILITY_NOT_EXIST, "", ""); + return nullptr; + } + std::string metadataName; + if (!CommonFunAni::ParseString(env, aniMetadataName, metadataName)) { + APP_LOGW("Parse metadataName failed, The default value is undefined"); + } + AbilityProfileType profileType = AbilityProfileType::UNKNOWN_PROFILE; + if (!EnumUtils::EnumETSToNative(env, aniProfileType, profileType)) { + APP_LOGE("Parse profileType failed"); + return nullptr; + } + std::vector profileVec; + ErrCode ret = InnerGetProfile(moduleName, abilityName, metadataName, profileType, profileVec); + if (ret != ERR_OK) { + APP_LOGE("InnerGetProfile failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + (isSync ? (profileType == AbilityProfileType::EXTENSION_PROFILE ? + GET_PROFILE_BY_EXTENSION_ABILITY_SYNC : GET_PROFILE_BY_ABILITY_SYNC) : ""), ""); + return nullptr; + } + return CommonFunAni::ConvertAniArrayString(env, profileVec); +} + +static ani_object GetPermissionDefNative(ani_env* env, ani_string aniPermissionName, ani_boolean aniIsSync) +{ + APP_LOGD("ani GetPermissionDefNative called"); + std::string permissionName; + if (!CommonFunAni::ParseString(env, aniPermissionName, permissionName)) { + APP_LOGE("permissionName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PERMISSION_NAME, TYPE_STRING); + return nullptr; + } + PermissionDef permissionDef; + ErrCode ret = BundleManagerHelper::InnerGetPermissionDef(permissionName, permissionDef); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + if (ret != ERR_OK) { + APP_LOGE("InnerGetPermissionDef failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, isSync ? GET_PERMISSION_DEF_SYNC : GET_PERMISSION_DEF, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + return CommonFunAni::ConvertPermissionDef(env, permissionDef); +} + +static void CleanBundleCacheFilesNative(ani_env* env, ani_string aniBundleName, ani_int aniAppIndex) +{ + APP_LOGD("ani CleanBundleCacheFilesNative called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return; + } + if (aniAppIndex < Constants::MAIN_APP_INDEX || aniAppIndex > Constants::CLONE_APP_INDEX_MAX) { + APP_LOGE("appIndex: %{public}d not in valid range", aniAppIndex); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPINDEX, Constants::APP_INDEX, TYPE_NUMBER); + return; + } + + sptr cleanCacheCallback = new (std::nothrow) CleanCacheCallback(); + ErrCode ret = BundleManagerHelper::InnerCleanBundleCacheCallback(bundleName, aniAppIndex, cleanCacheCallback); + if ((ret == ERR_OK) && (cleanCacheCallback != nullptr)) { + APP_LOGI("clean exec wait"); + if (cleanCacheCallback->WaitForCompletion()) { + ret = cleanCacheCallback->GetErr() ? ERR_OK : ERROR_BUNDLE_SERVICE_EXCEPTION; + } else { + APP_LOGI("clean exec timeout"); + ret = ERROR_BUNDLE_SERVICE_EXCEPTION; + } + } + if (ret != ERR_OK) { + APP_LOGE("CleanBundleCacheFiles failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, CLEAN_BUNDLE_CACHE_FILES, Constants::PERMISSION_REMOVECACHEFILE); + } +} + +static ani_long GetAllBundleCacheSizeNative(ani_env* env) +{ + APP_LOGD("ani GetAllBundleCacheSizeNative called"); + sptr cacheCallback = new (std::nothrow) ProcessCacheCallbackHost(); + if (cacheCallback == nullptr) { + APP_LOGE("cacheCallback is null"); + return 0; + } + + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return 0; + } + + ErrCode ret = CommonFunc::ConvertErrCode(iBundleMgr->GetAllBundleCacheStat(cacheCallback)); + APP_LOGI("GetAllBundleCacheStat call, result is %{public}d", ret); + if (ret != ERR_OK) { + APP_LOGE("GetAllBundleCacheSize failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_ALL_BUNDLE_CACHE_SIZE, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return 0; + } + + uint64_t cacheSize = 0; + APP_LOGI("GetCacheStat wait"); + cacheSize = cacheCallback->GetCacheStat(); + APP_LOGI("GetCacheStat finished"); + if (cacheSize > uint64_t(INT64_MAX)) { + APP_LOGW("value out of range for int64"); + cacheSize = uint64_t(INT64_MAX); + } + + return static_cast(cacheSize); +} + +static void CleanAllBundleCacheNative(ani_env* env) +{ + APP_LOGD("ani CleanAllBundleCacheNative called"); + sptr cacheCallback = new (std::nothrow) ProcessCacheCallbackHost(); + if (cacheCallback == nullptr) { + APP_LOGE("cacheCallback is null"); + return; + } + + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return; + } + + ErrCode ret = CommonFunc::ConvertErrCode(iBundleMgr->CleanAllBundleCache(cacheCallback)); + APP_LOGI("CleanAllBundleCache call, result is %{public}d", ret); + if (ret != ERR_OK) { + APP_LOGE("CleanAllBundleCache failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, CLEAN_ALL_BUNDLE_CACHE, Constants::PERMISSION_REMOVECACHEFILE); + return; + } + + APP_LOGI("GetCleanRet wait"); + auto result = cacheCallback->GetCleanRet(); + APP_LOGI("GetCleanRet finished"); + if (result != 0) { + APP_LOGE("CleanAllBundleCache failed, result %{public}d", result); + } +} + +static ani_object GetAppProvisionInfoNative( + ani_env* env, ani_string aniBundleName, ani_int aniUserId, ani_boolean aniIsSync) +{ + APP_LOGD("ani GetAppProvisionInfoNative called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + if (bundleName.empty()) { + APP_LOGE("bundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + } + AppProvisionInfo appProvisionInfo; + ErrCode ret = BundleManagerHelper::InnerGetAppProvisionInfo(bundleName, aniUserId, appProvisionInfo); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + if (ret != ERR_OK) { + APP_LOGE("InnerGetAppProvisionInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, isSync ? GET_APP_PROVISION_INFO_SYNC : GET_APP_PROVISION_INFO, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + return CommonFunAni::ConvertAppProvisionInfo(env, appProvisionInfo); +} + +static ani_boolean CanOpenLink(ani_env* env, ani_string aniLink) +{ + APP_LOGD("ani CanOpenLink called"); + bool canOpen = false; + std::string link; + if (!CommonFunAni::ParseString(env, aniLink, link)) { + APP_LOGE("link parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, LINK, TYPE_STRING); + return canOpen; + } + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return canOpen; + } + ErrCode ret = iBundleMgr->CanOpenLink(link, canOpen); + if (ret != ERR_OK) { + APP_LOGE("CanOpenLink failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), CAN_OPEN_LINK, ""); + } + return canOpen; +} + +static ani_object GetAllPreinstalledApplicationInfoNative(ani_env* env) +{ + APP_LOGD("ani GetAllPreinstalledApplicationInfoNative called"); + std::vector preinstalledApplicationInfos; + ErrCode ret = BundleManagerHelper::InnerGetAllPreinstalledApplicationInfos(preinstalledApplicationInfos); + if (ret != ERR_OK) { + APP_LOGE("InnerGetAllPreinstalledApplicationInfos failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_ALL_PREINSTALLED_APP_INFOS, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + return CommonFunAni::ConvertAniArray( + env, preinstalledApplicationInfos, CommonFunAni::ConvertPreinstalledApplicationInfo); +} + +static ani_object GetAllBundleInfoByDeveloperId(ani_env* env, ani_string aniDeveloperId) +{ + APP_LOGD("ani GetAllBundleInfoByDeveloperId called"); + std::string developerId; + if (!CommonFunAni::ParseString(env, aniDeveloperId, developerId)) { + APP_LOGE("developerId parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, DEVELOPER_ID, TYPE_STRING); + return nullptr; } + if (developerId.empty()) { + APP_LOGE("developerId is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_DEVELOPER_ID_EMPTY_ERROR); + return nullptr; + } + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return nullptr; + } + std::vector bundleInfos; + int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + ErrCode ret = iBundleMgr->GetAllBundleInfoByDeveloperId(developerId, bundleInfos, userId); + if (ret != ERR_OK) { + APP_LOGE("GetAllBundleInfoByDeveloperId failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), GET_ALL_BUNDLE_INFO_BY_DEVELOPER_ID, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + return CommonFunAni::ConvertAniArray(env, bundleInfos, CommonFunAni::ConvertBundleInfo, + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)); +} + +static void SwitchUninstallState(ani_env* env, ani_string aniBundleName, ani_boolean aniState) +{ + APP_LOGD("ani SwitchUninstallState called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return; + } + bool state = CommonFunAni::AniBooleanToBool(aniState); + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return; + } + ErrCode ret = iBundleMgr->SwitchUninstallState(bundleName, state); + if (ret != ERR_OK) { + APP_LOGE("SwitchUninstallState failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), SWITCH_UNINSTALL_STATE, ""); + } +} + +static ani_object GetSignatureInfo(ani_env* env, ani_int aniUid) +{ + APP_LOGD("ani GetSignatureInfo called"); + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return nullptr; + } + SignatureInfo signatureInfo; + ErrCode ret = iBundleMgr->GetSignatureInfoByUid(aniUid, signatureInfo); + if (ret != ERR_OK) { + APP_LOGE("GetSignatureInfoByUid failed ret: %{public}d, uid is %{public}d", ret, aniUid); + BusinessErrorAni::ThrowCommonError( + env, CommonFunc::ConvertErrCode(ret), GET_SIGNATURE_INFO, GET_SIGNATURE_INFO_PERMISSIONS); + return nullptr; + } + return CommonFunAni::ConvertSignatureInfo(env, signatureInfo); +} + +static ani_object GetAllAppCloneBundleInfoNative( + ani_env* env, ani_string aniBundleName, ani_int aniBundleFlags, ani_int aniUserId) +{ + APP_LOGD("ani GetAllAppCloneBundleInfoNative called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + std::vector bundleInfos; + ErrCode ret = BundleManagerHelper::InnerGetAllAppCloneBundleInfo( + bundleName, aniBundleFlags, aniUserId, bundleInfos); + if (ret != ERR_OK) { + APP_LOGE("InnerGetAllAppCloneBundleInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_ALL_APP_CLONE_BUNDLE_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + APP_LOGD("GetAllAppCloneBundleInfoNative bundleInfos size: %{public}zu", bundleInfos.size()); + + return CommonFunAni::ConvertAniArray(env, bundleInfos, CommonFunAni::ConvertBundleInfo, aniBundleFlags); +} + +static ani_object GetAllSharedBundleInfoNative(ani_env* env) +{ + APP_LOGD("ani GetAllSharedBundleInfoNative called"); + std::vector sharedBundles; + ErrCode ret = BundleManagerHelper::InnerGetAllSharedBundleInfo(sharedBundles); + if (ret != ERR_OK) { + APP_LOGE("InnerGetAllSharedBundleInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_ALL_SHARED_BUNDLE_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + return CommonFunAni::ConvertAniArray(env, sharedBundles, CommonFunAni::ConvertSharedBundleInfo); +} + +static ani_object GetSharedBundleInfoNative(ani_env* env, ani_string aniBundleName, ani_string aniModuleName) +{ + APP_LOGD("ani GetSharedBundleInfoNative called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + std::string moduleName; + if (!CommonFunAni::ParseString(env, aniModuleName, moduleName)) { + APP_LOGE("moduleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::MODULE_NAME, TYPE_STRING); + return nullptr; + } + if (bundleName.empty()) { + APP_LOGE("bundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } + if (moduleName.empty()) { + APP_LOGE("moduleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + return nullptr; + } + std::vector sharedBundles; + ErrCode ret = BundleManagerHelper::InnerGetSharedBundleInfo(bundleName, moduleName, sharedBundles); + if (ret != ERR_OK) { + APP_LOGE("InnerGetSharedBundleInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_SHARED_BUNDLE_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + return CommonFunAni::ConvertAniArray(env, sharedBundles, CommonFunAni::ConvertSharedBundleInfo); +} + +static ani_string GetAdditionalInfo(ani_env* env, ani_string aniBundleName) +{ + APP_LOGD("ani GetAdditionalInfo called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + if (bundleName.empty()) { + APP_LOGE("bundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, + RESOURCE_NAME_OF_GET_SPECIFIED_DISTRIBUTION_TYPE, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + std::string additionalInfo; + ErrCode ret = iBundleMgr->GetAdditionalInfo(bundleName, additionalInfo); + if (ret != ERR_OK) { + APP_LOGE("GetAdditionalInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), RESOURCE_NAME_OF_GET_ADDITIONAL_INFO, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + ani_string aniAdditionalInfo = nullptr; + if (!CommonFunAni::StringToAniStr(env, additionalInfo, aniAdditionalInfo)) { + APP_LOGE("StringToAniStr failed"); + return nullptr; + } + return aniAdditionalInfo; +} + +static ani_string GetJsonProfileNative(ani_env* env, ani_enum_item aniProfileType, ani_string aniBundleName, + ani_string aniModuleName, ani_int aniUserId) +{ + APP_LOGD("ani GetJsonProfileNative called"); + ProfileType profileType = ProfileType::INTENT_PROFILE; + if (!EnumUtils::EnumETSToNative(env, aniProfileType, profileType)) { + APP_LOGE("Parse profileType failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PROFILE_TYPE, TYPE_NUMBER); + return nullptr; + } + if (g_supportedProfileList.find(profileType) == g_supportedProfileList.end()) { + APP_LOGE("JS request profile error, type is %{public}d, profile not exist", profileType); + BusinessErrorAni::ThrowCommonError(env, ERROR_PROFILE_NOT_EXIST, PROFILE_TYPE, TYPE_NUMBER); + return nullptr; + } + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + if (bundleName.empty()) { + APP_LOGE("bundleName is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_BUNDLE_NOT_EXIST, GET_JSON_PROFILE, BUNDLE_PERMISSIONS); + return nullptr; + } + std::string moduleName; + if (!CommonFunAni::ParseString(env, aniModuleName, moduleName)) { + APP_LOGW("parse moduleName failed, try to get profile from entry module"); + } else if (moduleName.empty()) { + APP_LOGE("moduleName is empty"); + BusinessErrorAni::ThrowCommonError(env, ERROR_MODULE_NOT_EXIST, GET_JSON_PROFILE, BUNDLE_PERMISSIONS); + return nullptr; + } + if (moduleName == EMPTY_STRING) { + moduleName = ""; + } + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return nullptr; + } + std::string profile; + ErrCode ret = iBundleMgr->GetJsonProfile(profileType, bundleName, moduleName, profile, aniUserId); + if (ret != ERR_OK) { + APP_LOGE("GetJsonProfile failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), GET_JSON_PROFILE, BUNDLE_PERMISSIONS); + return nullptr; + } + ani_string aniProfile = nullptr; + if (!CommonFunAni::StringToAniStr(env, profile, aniProfile)) { + APP_LOGE("StringToAniStr failed"); + return nullptr; + } + return aniProfile; +} + +static ani_object GetExtResourceNative(ani_env* env, ani_string aniBundleName) +{ + APP_LOGD("ani GetExtResourceNative called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + std::vector moduleNames; + ErrCode ret = BundleManagerHelper::InnerGetExtResource(bundleName, moduleNames); + if (ret != ERR_OK) { + APP_LOGE("InnerGetExtResource failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_EXT_RESOURCE, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + return CommonFunAni::ConvertAniArrayString(env, moduleNames); +} + +static void DisableDynamicIconNative(ani_env* env, ani_string aniBundleName, ani_object aniBundleOptions) +{ + APP_LOGD("ani DisableDynamicIconNative called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return; + } + int32_t appIndex = 0; + int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + bool isDefault = CommonFunAni::ParseBundleOptions(env, aniBundleOptions, appIndex, userId); + + ErrCode ret = BundleManagerHelper::InnerDisableDynamicIcon(bundleName, appIndex, userId, isDefault); + if (ret != ERR_OK) { + APP_LOGE("InnerDisableDynamicIcon failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, DISABLE_DYNAMIC_ICON, + isDefault ? Constants::PERMISSION_ACCESS_DYNAMIC_ICON : BUNDLE_ENABLE_AND_DISABLE_ALL_DYNAMIC_PERMISSIONS); + } +} + +static ani_object GetDynamicIconInfoNative(ani_env* env, ani_string aniBundleName) +{ + APP_LOGD("ani GetDynamicIconInfoNative called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + + std::vector dynamicIconInfos; + ErrCode ret = BundleManagerHelper::InnerGetDynamicIconInfo(bundleName, dynamicIconInfos); + if (ret != ERR_OK) { + APP_LOGE("InnerGetDynamicIconInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, GET_DYNAMIC_ICON_INFO, BUNDLE_GET_ALL_DYNAMIC_PERMISSIONS); + return nullptr; + } + return CommonFunAni::ConvertAniArray(env, dynamicIconInfos, CommonFunAni::ConvertDynamicIconInfo); +} + +static ani_object GetAllDynamicIconInfoNative(ani_env* env, ani_int aniUserId) +{ + APP_LOGD("ani GetAllDynamicIconInfoNative called"); + aniUserId = (aniUserId == EMPTY_USER_ID) ? Constants::UNSPECIFIED_USERID + : (aniUserId < 0) ? Constants::INVALID_USERID : aniUserId; + std::vector dynamicIconInfos; + ErrCode ret = BundleManagerHelper::InnerGetAllDynamicIconInfo(aniUserId, dynamicIconInfos); + if (ret != ERR_OK) { + APP_LOGE("InnerGetAllDynamicIconInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, GET_ALL_DYNAMIC_ICON, BUNDLE_GET_ALL_DYNAMIC_PERMISSIONS); + return nullptr; + } + return CommonFunAni::ConvertAniArray(env, dynamicIconInfos, CommonFunAni::ConvertDynamicIconInfo); +} + +static void VerifyAbcNative(ani_env* env, ani_object aniAbcPaths, ani_boolean aniDeleteOriginalFiles) +{ + APP_LOGD("ani VerifyAbcNative called"); + std::vector abcPaths; + if (!CommonFunAni::ParseStrArray(env, aniAbcPaths, abcPaths)) { + APP_LOGE("ParseStrArray failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, VERIFY_ABC, TYPE_ARRAY); + return; + } + bool flag = CommonFunAni::AniBooleanToBool(aniDeleteOriginalFiles); + + ErrCode ret = BundleManagerHelper::InnerVerify(abcPaths, flag); + if (ret != ERR_OK) { + APP_LOGE("InnerVerify failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, VERIFY_ABC, Constants::PERMISSION_RUN_DYN_CODE); + } +} + +static void DeleteAbcNative(ani_env* env, ani_string aniAbcPath) +{ + APP_LOGD("ani DeleteAbcNative called"); + std::string deletePath; + if (!CommonFunAni::ParseString(env, aniAbcPath, deletePath)) { + APP_LOGE("deletePath parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, DELETE_ABC, TYPE_STRING); + return; + } + + ErrCode ret = BundleManagerHelper::InnerDeleteAbc(deletePath); + if (ret != ERR_OK) { + APP_LOGE("InnerDeleteAbc failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, DELETE_ABC, Constants::PERMISSION_RUN_DYN_CODE); + } +} + +static ani_object GetRecoverableApplicationInfoNative(ani_env* env) +{ + APP_LOGD("ani GetRecoverableApplicationInfoNative called"); + std::vector recoverableApplicationInfos; + ErrCode ret = BundleManagerHelper::InnerGetRecoverableApplicationInfo(recoverableApplicationInfos); + if (ret != ERR_OK) { + APP_LOGE("InnerGetRecoverableApplicationInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_RECOVERABLE_APPLICATION_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + return CommonFunAni::ConvertAniArray( + env, recoverableApplicationInfos, CommonFunAni::ConvertRecoverableApplicationInfo); +} + +static void SetAdditionalInfo(ani_env* env, ani_string aniBundleName, ani_string aniAdditionalInfo) +{ + APP_LOGD("ani SetAdditionalInfo called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::BUNDLE_NAME, TYPE_STRING); + return; + } + if (bundleName.empty()) { + APP_LOGE("bundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return; + } + std::string additionalInfo; + if (!CommonFunAni::ParseString(env, aniAdditionalInfo, additionalInfo)) { + APP_LOGE("additionalInfo parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, ADDITIONAL_INFO, TYPE_STRING); + return; + } + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return; + } + ErrCode ret = iBundleMgr->SetAdditionalInfo(bundleName, additionalInfo); + if (ret != ERR_OK) { + APP_LOGE("SetAdditionalInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), RESOURCE_NAME_OF_SET_ADDITIONAL_INFO, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + } +} + +static ani_object GetDeveloperIdsNative(ani_env* env, ani_int aniAppDistributionType) +{ + APP_LOGD("ani GetDeveloperIdsNative called"); + if (aniAppDistributionType != EMPTY_VALUE && + appDistributionTypeMap.find(aniAppDistributionType) == appDistributionTypeMap.end()) { + APP_LOGE("request error, type %{public}d is invalid", aniAppDistributionType); + BusinessErrorAni::ThrowEnumError(env, APP_DISTRIBUTION_TYPE, APP_DISTRIBUTION_TYPE_ENUM); + return nullptr; + } + std::string distributionType = std::string { appDistributionTypeMap[aniAppDistributionType] }; + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return nullptr; + } + std::vector developerIds; + int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + ErrCode ret = iBundleMgr->GetDeveloperIds(distributionType, developerIds, userId); + if (ret != ERR_OK) { + APP_LOGE( + "GetDeveloperIds failed ret: %{public}d, appDistributionType is %{public}s", ret, distributionType.c_str()); + BusinessErrorAni::ThrowCommonError( + env, CommonFunc::ConvertErrCode(ret), GET_DEVELOPER_IDS, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + return CommonFunAni::ConvertAniArrayString(env, developerIds); +} + +static ani_object GetAllPluginInfoNative(ani_env* env, ani_string aniHostBundleName, ani_int aniUserId) +{ + APP_LOGD("ani GetAllPluginInfoNative called"); + std::string hostBundleName; + if (!CommonFunAni::ParseString(env, aniHostBundleName, hostBundleName)) { + APP_LOGE("Plugin bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, HOST_BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + } + std::vector pluginBundleInfos; + ErrCode ret = BundleManagerHelper::InnerGetAllPluginInfo(hostBundleName, aniUserId, pluginBundleInfos); + if (ret != ERR_OK) { + APP_LOGE("InnerGetAllPluginInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_ALL_PLUGIN_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + return CommonFunAni::ConvertAniArray(env, pluginBundleInfos, CommonFunAni::ConvertPluginBundleInfo); +} + +static void MigrateDataNative(ani_env* env, ani_object aniSourcePaths, ani_string aniDestinationPath) +{ + APP_LOGD("ani MigrateDataNative called"); + std::vector sourcePaths; + if (!CommonFunAni::ParseStrArray(env, aniSourcePaths, sourcePaths)) { + APP_LOGE("ParseStrArray failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, SOURCE_PATHS, TYPE_ARRAY); + return; + } + std::string destinationPath; + if (!CommonFunAni::ParseString(env, aniDestinationPath, destinationPath)) { + APP_LOGE("DestinationPath parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, DESTINATION_PATH, TYPE_STRING); + return; + } + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, ERR_MSG_BUNDLE_SERVICE_EXCEPTION); + return; + } + + ErrCode ret = iBundleMgr->MigrateData(sourcePaths, destinationPath); + if (ret != ERR_OK) { + APP_LOGE("MigrateData failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, + CommonFunc::ConvertErrCode(ret), MIGRATE_DATA, Constants::PERMISSION_MIGRATE_DATA); + } +} + +static ani_string GetSandboxDataDir(ani_env* env, ani_string aniBundleName, ani_int aniAppIndex) +{ + APP_LOGD("ani GetSandboxDataDir called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("bundleName parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + if (aniAppIndex < Constants::MAIN_APP_INDEX || aniAppIndex > Constants::CLONE_APP_INDEX_MAX) { + APP_LOGE("appIndex: %{public}d not in valid range", aniAppIndex); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPINDEX, Constants::APP_INDEX, TYPE_NUMBER); + return nullptr; + } + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, GET_SANDBOX_DATA_DIR_SYNC, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + std::string sandboxDataDir; + ErrCode ret = iBundleMgr->GetSandboxDataDir(bundleName, aniAppIndex, sandboxDataDir); + if (ret != ERR_OK) { + APP_LOGE("GetSandboxDataDirSync failed ret %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), GET_SANDBOX_DATA_DIR_SYNC, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + ani_string aniSandboxDataDir = nullptr; + if (!CommonFunAni::StringToAniStr(env, sandboxDataDir, aniSandboxDataDir)) { + APP_LOGE("StringToAniStr failed"); + return nullptr; + } + return aniSandboxDataDir; +} + +static ani_object GetAppCloneIdentityBySandboxDataDir(ani_env* env, ani_string aniSandboxDataDir) +{ + APP_LOGD("ani GetAppCloneIdentityBySandboxDataDir called"); + std::string sandboxDataDir; + if (!CommonFunAni::ParseString(env, aniSandboxDataDir, sandboxDataDir)) { + APP_LOGE("sandboxDataDir parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, SANDBOX_DATA_DIR, TYPE_STRING); + return nullptr; + } + std::string bundleName; + int32_t appIndex = 0; + CommonFunc::GetBundleNameAndIndexBySandboxDataDir(sandboxDataDir, bundleName, appIndex); + + return CommonFunAni::ConvertAppCloneIdentity(env, bundleName, appIndex); +} + +static ani_object GetAbilityInfoNative(ani_env* env, ani_string aniUri, ani_int aniAbilityFlags) +{ + APP_LOGD("ani GetAbilityInfoNative called"); + std::string uri; + if (!CommonFunAni::ParseString(env, aniUri, uri)) { + APP_LOGE("uri parse failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, URI, TYPE_STRING); + return nullptr; + } + if (uri.empty()) { + APP_LOGE("uri empty"); + BusinessErrorAni::ThrowCommonError( + env, ERROR_ABILITY_NOT_EXIST, GET_ABILITY_INFOS, GET_ABILITYINFO_PERMISSIONS); + return nullptr; + } + uint32_t flags = static_cast(aniAbilityFlags); + int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + const ANIQuery query(uri, GET_ABILITY_INFOS, flags, userId); + { + std::shared_lock lock(g_aniCacheMutex); + auto item = g_aniCache.find(query); + if (item != g_aniCache.end()) { + APP_LOGD("has cache, no need to query from host"); + return reinterpret_cast(item->second); + } + } + std::vector abilityInfos; + ErrCode ret = BundleManagerHelper::InnerGetAbilityInfos(uri, flags, abilityInfos); + if (ret != ERR_OK) { + APP_LOGE("InnerGetAbilityInfos failed ret %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, ret, GET_ABILITY_INFOS, GET_ABILITYINFO_PERMISSIONS); + return nullptr; + } + ani_object aniAbilityInfos = CommonFunAni::ConvertAniArray(env, abilityInfos, CommonFunAni::ConvertAbilityInfo); + if (abilityInfos.size() == EXPLICIT_QUERY_RESULT_LEN) { + CheckToCache(env, abilityInfos[0].uid, IPCSkeleton::GetCallingUid(), query, aniAbilityInfos); + } + return aniAbilityInfos; } static void CleanBundleCacheFilesForSelfNative(ani_env* env) @@ -1171,6 +1997,52 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) ani_native_function { "queryAbilityInfoWithWantsNative", nullptr, reinterpret_cast(QueryAbilityInfoWithWantsNative) }, ani_native_function { "enableDynamicIconNative", nullptr, reinterpret_cast(EnableDynamicIconNative) }, + ani_native_function { "getBundleArchiveInfoNative", nullptr, + reinterpret_cast(GetBundleArchiveInfoNative) }, + ani_native_function { "getLaunchWant", nullptr, reinterpret_cast(GetLaunchWant) }, + ani_native_function { "getProfileByAbilityNative", nullptr, + reinterpret_cast(GetProfileByAbilityNative) }, + ani_native_function { "getPermissionDefNative", nullptr, reinterpret_cast(GetPermissionDefNative) }, + ani_native_function { "cleanBundleCacheFilesNative", nullptr, + reinterpret_cast(CleanBundleCacheFilesNative) }, + ani_native_function { "getAllBundleCacheSizeNative", nullptr, + reinterpret_cast(GetAllBundleCacheSizeNative) }, + ani_native_function { "cleanAllBundleCacheNative", nullptr, + reinterpret_cast(CleanAllBundleCacheNative) }, + ani_native_function { "getAppProvisionInfoNative", nullptr, + reinterpret_cast(GetAppProvisionInfoNative) }, + ani_native_function { "canOpenLink", nullptr, reinterpret_cast(CanOpenLink) }, + ani_native_function { "getAllPreinstalledApplicationInfoNative", nullptr, + reinterpret_cast(GetAllPreinstalledApplicationInfoNative) }, + ani_native_function { "getAllBundleInfoByDeveloperId", nullptr, + reinterpret_cast(GetAllBundleInfoByDeveloperId) }, + ani_native_function { "switchUninstallState", nullptr, reinterpret_cast(SwitchUninstallState) }, + ani_native_function { "getSignatureInfo", nullptr, reinterpret_cast(GetSignatureInfo) }, + ani_native_function { "getAllAppCloneBundleInfoNative", nullptr, + reinterpret_cast(GetAllAppCloneBundleInfoNative) }, + ani_native_function { "getAllSharedBundleInfoNative", nullptr, + reinterpret_cast(GetAllSharedBundleInfoNative) }, + ani_native_function { "getSharedBundleInfoNative", nullptr, + reinterpret_cast(GetSharedBundleInfoNative) }, + ani_native_function { "getAdditionalInfo", nullptr, reinterpret_cast(GetAdditionalInfo) }, + ani_native_function { "getJsonProfileNative", nullptr, reinterpret_cast(GetJsonProfileNative) }, + ani_native_function { "getExtResourceNative", nullptr, reinterpret_cast(GetExtResourceNative) }, + ani_native_function { "disableDynamicIconNative", nullptr, reinterpret_cast(DisableDynamicIconNative) }, + ani_native_function { "getDynamicIconInfoNative", nullptr, reinterpret_cast(GetDynamicIconInfoNative) }, + ani_native_function { "getAllDynamicIconInfoNative", nullptr, + reinterpret_cast(GetAllDynamicIconInfoNative) }, + ani_native_function { "verifyAbcNative", nullptr, reinterpret_cast(VerifyAbcNative) }, + ani_native_function { "deleteAbcNative", nullptr, reinterpret_cast(DeleteAbcNative) }, + ani_native_function { "getRecoverableApplicationInfoNative", nullptr, + reinterpret_cast(GetRecoverableApplicationInfoNative) }, + ani_native_function { "setAdditionalInfo", nullptr, reinterpret_cast(SetAdditionalInfo) }, + ani_native_function { "getDeveloperIdsNative", nullptr, reinterpret_cast(GetDeveloperIdsNative) }, + ani_native_function { "getAllPluginInfoNative", nullptr, reinterpret_cast(GetAllPluginInfoNative) }, + ani_native_function { "migrateDataNative", nullptr, reinterpret_cast(MigrateDataNative) }, + ani_native_function { "getSandboxDataDir", nullptr, reinterpret_cast(GetSandboxDataDir) }, + ani_native_function { "getAppCloneIdentityBySandboxDataDir", nullptr, + reinterpret_cast(GetAppCloneIdentityBySandboxDataDir) }, + ani_native_function { "getAbilityInfoNative", nullptr, reinterpret_cast(GetAbilityInfoNative) }, ani_native_function { "cleanBundleCacheFilesForSelfNative", nullptr, reinterpret_cast(CleanBundleCacheFilesForSelfNative) }, }; diff --git a/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets b/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets index 1157bdc0f0..2cf2c02ae5 100644 --- a/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets +++ b/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets @@ -13,19 +13,33 @@ * limitations under the License. */ -import { BundleInfo, AppCloneIdentity } from 'bundleManager.BundleInfo'; +import { BundleInfo, AppCloneIdentity, SignatureInfo, BundleOptions, DynamicIconInfo } from 'bundleManager.BundleInfo'; import { AsyncCallback, BusinessError } from '@ohos.base'; -import { ApplicationInfo } from 'bundleManager.ApplicationInfo'; +import { PreinstalledApplicationInfo, ApplicationInfo } from 'bundleManager.ApplicationInfo'; import { AbilityInfo } from 'bundleManager.AbilityInfo'; import { ExtensionAbilityInfo } from 'bundleManager.ExtensionAbilityInfo'; +import { PermissionDef } from 'bundleManager.PermissionDef'; +import { SharedBundleInfo } from 'bundleManager.SharedBundleInfo' +import { AppProvisionInfo } from 'bundleManager.AppProvisionInfo' +import { RecoverableApplicationInfo } from 'bundleManager.RecoverableApplicationInfo' +import { PluginBundleInfo } from 'bundleManager.PluginBundleInfo'; import Want from '@ohos.app.ability.Want'; +import { BundleOptionsInner } from './bundleManager/BundleInfoInner'; namespace bundleManager { loadLibraryWithPermissionCheck("ani_bundle_manager.z", "@ohos.bundle.bundleManager"); - const EMPTY_USER_ID: number = -500; + const EMPTY_VALUE: int = -500; + const EMPTY_STRING: string = "ani empty string"; + const MAIN_APP_INDEX: int = 0; + const CLONE_APP_INDEX_MAX: int = 5; + const ERROR_INVALID_APPINDEX_CODE: int = 17700061; + const ERROR_INVALID_APPINDEX_MSG: string = "BusinessError 17700061: The specified app index is invalid."; const ERROR_PARAM_CHECK_ERROR: int = 401; + const PARAM_BUNDLENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. parameter bundleName is empty"; + const ERROR_ABILITY_NOT_EXIST: int = 17700003; + const GETABILITYINFO_ERROR_MSG: string = "BusinessError 17700003: The specified ability is not found."; const PARAM_BUNDLENAME_TYPE_ERROR: string = "BusinessError 401: Parameter error. The type of bundleName must be string."; const PARAM_TYPE_CHECK_ERROR: string = "param type check error"; @@ -193,56 +207,62 @@ namespace bundleManager { FLAG_PREINSTALLED_APP_UPDATE = 0x00000040, } - export native function getBundleInfoForSelfNative(bundleFlags: number, isSync: boolean): BundleInfo; + export enum AbilityProfileType { + ABILITY_PROFILE = 0, + EXTENSION_PROFILE = 1, + UNKNOWN_PROFILE = 2 + } + + export native function getBundleInfoForSelfNative(bundleFlags: int, isSync: boolean): BundleInfo; - export native function getBundleInfoNative(bundleName: string, bundleFlags: number, userId: number, isSync: boolean) : BundleInfo; + export native function getBundleInfoNative(bundleName: string, bundleFlags: int, userId: int, isSync: boolean) : BundleInfo; - export native function getApplicationInfoNative(bundleName: string, applicationFlags: number, userId: number, isSync: boolean): ApplicationInfo; + export native function getApplicationInfoNative(bundleName: string, applicationFlags: int, userId: int, isSync: boolean): ApplicationInfo; - export native function getAllBundleInfoNative(bundleFlags: number, userId: number): Array; + export native function getAllBundleInfoNative(bundleFlags: int, userId: int): Array; - export native function getAllApplicationInfoNative(appFlags: number, userId: number): Array; + export native function getAllApplicationInfoNative(appFlags: int, userId: int): Array; - export native function isApplicationEnabledNative(bundleName: string, appIndex: number, isSync: boolean): boolean; + export native function isApplicationEnabledNative(bundleName: string, appIndex: int, isSync: boolean): boolean; - export native function queryAbilityInfoSyncNative(want: Want, abilityFlags: number, userId: number, isSync: boolean): Array; + export native function queryAbilityInfoSyncNative(want: Want, abilityFlags: int, userId: int, isSync: boolean): Array; - export native function getAppCloneIdentityNative(uid: number): AppCloneIdentity; + export native function getAppCloneIdentityNative(uid: int): AppCloneIdentity; export native function getAbilityLabelNative(bundleName: string, moduleName: string, abilityName: string, isSync: boolean): string; - export native function getLaunchWantForBundleNative(bundleName: string, userId: number, isSync: boolean): Want; + export native function getLaunchWantForBundleNative(bundleName: string, userId: int, isSync: boolean): Want; - export native function getAppCloneBundleInfoNative(bundleName: string, appIndex: number, - bundleFlags: number, userId: number): BundleInfo; + export native function getAppCloneBundleInfoNative(bundleName: string, appIndex: int, + bundleFlags: int, userId: int): BundleInfo; export native function getSpecifiedDistributionType(bundleName: string): string; - export native function getBundleNameByUidNative(uid: number, isSync: boolean): string; + export native function getBundleNameByUidNative(uid: int, isSync: boolean): string; - export native function isAbilityEnabledNative(info: AbilityInfo, appIndex: number, isSync: boolean): boolean; + export native function isAbilityEnabledNative(info: AbilityInfo, appIndex: int, isSync: boolean): boolean; - export native function setAbilityEnabledNative(info: AbilityInfo, isEnabled: boolean, appIndex: number, isSync: boolean): void; + export native function setAbilityEnabledNative(info: AbilityInfo, isEnabled: boolean, appIndex: int, isSync: boolean): void; - export native function setApplicationEnabledNative(bundleName: string, isEnabled: boolean, appIndex: number, isSync: boolean): void; + export native function setApplicationEnabledNative(bundleName: string, isEnabled: boolean, appIndex: int, isSync: boolean): void; export native function getDynamicIconNative(bundleName: string): string; - export native function queryAbilityInfoWithWantsNative(wants: Array, abilityFlags: number, - userId: number): Array; + export native function queryAbilityInfoWithWantsNative(wants: Array, abilityFlags: int, + userId: int): Array; export native function queryExtensionAbilityInfoNative(want: Want, extensionAbilityType: ExtensionAbilityType, - extensionAbilityTypeName: string, extensionAbilityFlags: number, - userId: number, isExtensionTypeName: boolean, isSync: boolean): Array; + extensionAbilityTypeName: string, extensionAbilityFlags: int, + userId: int, isExtensionTypeName: boolean, isSync: boolean): Array; - export native function queryExAbilityInfoSyncWithoutWantNative(extensionAbilityType: string, extensionAbilityFlags: number, - userId: number): Array; + export native function queryExAbilityInfoSyncWithoutWantNative(extensionAbilityType: string, extensionAbilityFlags: int, + userId: int): Array; - export native function enableDynamicIconNative(bundleName: string, moduleName: string): void; + export native function enableDynamicIconNative(bundleName: string, moduleName: string, option: BundleOptions): void; export native function cleanBundleCacheFilesForSelfNative(): void; - function getBundleInfoForSelfSync(bundleFlags: number): BundleInfo { + function getBundleInfoForSelfSync(bundleFlags: int): BundleInfo { return bundleManager.getBundleInfoForSelfNative(bundleFlags, true); } @@ -250,24 +270,90 @@ namespace bundleManager { return bundleManager.getAbilityLabelNative(bundleName, moduleName, abilityName, true); } - function getBundleNameByUidSync(uid: number): string { + function getBundleNameByUidSync(uid: int): string { return bundleManager.getBundleNameByUidNative(uid, true); } + export native function getBundleArchiveInfoNative(hapFilePath: string, bundleFlags: int, isSync: boolean): BundleInfo; + + export native function getLaunchWant(): Want; + + export native function getProfileByAbilityNative(moduleName: string, + abilityName: string, metadataName: string, profileType: AbilityProfileType, isSync: boolean): Array; + + export native function getPermissionDefNative(permissionName: string, isSync: boolean): PermissionDef; + + export native function cleanBundleCacheFilesNative(bundleName: string, appIndex: int): void; + + export native function getAllBundleCacheSizeNative(): long; + + export native function cleanAllBundleCacheNative(): void; + + export native function getAppProvisionInfoNative(bundleName: string, userId: int, isSync: boolean): AppProvisionInfo; + + export native function canOpenLink(link: string): boolean; + + export native function getAllPreinstalledApplicationInfoNative(): Array; + + export native function getAllBundleInfoByDeveloperId(developerId: string): Array; + + export native function switchUninstallState(bundleName: string, state: boolean): void; + + export native function getSignatureInfo(uid: int): SignatureInfo; + + export native function getAllAppCloneBundleInfoNative(bundleName: string, + bundleFlags: int, userId: int): Array; + + export native function getAllSharedBundleInfoNative(): Array; + + export native function getSharedBundleInfoNative(bundleName: string, moduleName: string): Array; + + export native function getAdditionalInfo(bundleName: string): string; + + export native function getJsonProfileNative(profileType: ProfileType, bundleName: string, moduleName: string, userId: int): string; + + export native function getExtResourceNative(bundleName: string): Array; + + export native function disableDynamicIconNative(bundleName: string, option: BundleOptions): void; + + export native function getDynamicIconInfoNative(bundleName: string): Array; + + export native function getAllDynamicIconInfoNative(userId: int): Array; + + export native function verifyAbcNative(abcPaths: Array, deleteOriginalFiles: boolean): void; + + export native function getRecoverableApplicationInfoNative(): Array; + + export native function setAdditionalInfo(bundleName: string, additionalInfo: string): void; + + export native function deleteAbcNative(abcPath: string): void; + + export native function getDeveloperIdsNative(appDistributionType: int): Array; + + export native function getAllPluginInfoNative(hostBundleName: string, userId: int): Array; + + export native function migrateDataNative(sourcePaths: Array, destinationPath: string): void; + + export native function getSandboxDataDir(bundleName: string, appIndex: int): string; + + export native function getAppCloneIdentityBySandboxDataDir(sandboxDataDir: string): AppCloneIdentity; + + export native function getAbilityInfoNative(uri: string, abilityFlags: int): Array; + function isApplicationEnabledSync(bundleName: string): boolean { return bundleManager.isApplicationEnabledNative(bundleName, 0, true); } - function queryAbilityInfoSync(want: Want, abilityFlags: number, userId?: number): Array { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + function queryAbilityInfoSync(want: Want, abilityFlags: int, userId?: int): Array { + let userIdInfo: int = userId ?? EMPTY_VALUE; return bundleManager.queryAbilityInfoSyncNative(want, abilityFlags, userIdInfo, true); } - function getLaunchWantForBundleSync(bundleName: string, userId?: number): Want { + function getLaunchWantForBundleSync(bundleName: string, userId?: int): Want { if (bundleName === "") { throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TYPE_CHECK_ERROR); } - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; return bundleManager.getLaunchWantForBundleNative(bundleName, userIdInfo, true); } @@ -284,26 +370,61 @@ namespace bundleManager { } function queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: ExtensionAbilityType, - extensionAbilityFlags: number, userId?: number): Array { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + extensionAbilityFlags: int, userId?: int): Array { + let userIdInfo: int = userId ?? EMPTY_VALUE; return bundleManager.queryExtensionAbilityInfoNative( want, extensionAbilityType, "", extensionAbilityFlags, userIdInfo, false, true); } - function queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: string, extensionAbilityFlags: number, - userId?: number): Array { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + function queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: string, extensionAbilityFlags: int, + userId?: int): Array { + let userIdInfo: int = userId ?? EMPTY_VALUE; return bundleManager.queryExtensionAbilityInfoNative( want, ExtensionAbilityType.UNSPECIFIED, extensionAbilityType, extensionAbilityFlags, userIdInfo, true, true); } - function queryExtensionAbilityInfoSync(extensionAbilityType: string, extensionAbilityFlags: number, - userId?: number): Array { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + function queryExtensionAbilityInfoSync(extensionAbilityType: string, extensionAbilityFlags: int, + userId?: int): Array { + let userIdInfo: int = userId ?? EMPTY_VALUE; return bundleManager.queryExAbilityInfoSyncWithoutWantNative(extensionAbilityType, extensionAbilityFlags, userIdInfo); } - function getBundleInfoForSelf(bundleFlags: number, callback: AsyncCallback): void { + function getBundleArchiveInfoSync(hapFilePath: string, bundleFlags: int): BundleInfo { + return bundleManager.getBundleArchiveInfoNative(hapFilePath, bundleFlags, true); + } + + function getProfileByAbilitySync(moduleName: string, abilityName: string, metadataName?: string): Array { + let metadataNameInfo: string = metadataName ?? ""; + return bundleManager.getProfileByAbilityNative(moduleName, abilityName, metadataNameInfo, AbilityProfileType.ABILITY_PROFILE, true); + } + + function getProfileByExtensionAbilitySync(moduleName: string, + extensionAbilityName: string, metadataName?: string): Array { + let metadataNameInfo: string = metadataName ?? ""; + return bundleManager.getProfileByAbilityNative(moduleName, extensionAbilityName, metadataNameInfo, AbilityProfileType.EXTENSION_PROFILE, true); + } + + function getPermissionDefSync(permissionName: string): PermissionDef { + return bundleManager.getPermissionDefNative(permissionName, true); + } + + function getAppProvisionInfoSync(bundleName: string, userId?: int): AppProvisionInfo { + let userIdInfo: int = userId ?? EMPTY_VALUE; + return bundleManager.getAppProvisionInfoNative(bundleName, userIdInfo, true); + } + + function getJsonProfile(profileType: ProfileType, bundleName: string, moduleName?: string, userId?: int): string { + let userIdInfo: int = userId ?? -2; + let moduleNameInfo: string = moduleName ?? EMPTY_STRING; + return bundleManager.getJsonProfileNative(profileType, bundleName, moduleNameInfo, userIdInfo); + } + + function getDeveloperIds(appDistributionType?: int): Array { + let appDistributionTypeInfo: int = appDistributionType ?? EMPTY_VALUE; + return bundleManager.getDeveloperIdsNative(appDistributionTypeInfo); + } + + function getBundleInfoForSelf(bundleFlags: int, callback: AsyncCallback):void { let execFun = (): BundleInfo => { return bundleManager.getBundleInfoForSelfNative(bundleFlags, false); }; @@ -316,7 +437,7 @@ namespace bundleManager { }); } - function getBundleInfoForSelf(bundleFlags: number):Promise { + function getBundleInfoForSelf(bundleFlags: int):Promise { let p = new Promise((resolve: (bundleInfo: BundleInfo) => void, reject: (error: BusinessError) => void) => { let execFun = (): BundleInfo => { return bundleManager.getBundleInfoForSelfNative(bundleFlags, false); @@ -333,17 +454,17 @@ namespace bundleManager { return p; } - function getBundleInfoSync(bundleName: string, bundleFlags: number, userId: number): BundleInfo { + function getBundleInfoSync(bundleName: string, bundleFlags: int, userId: int): BundleInfo { return bundleManager.getBundleInfoNative(bundleName, bundleFlags, userId, true); } - function getBundleInfoSync(bundleName: string, bundleFlags: number): BundleInfo { - return bundleManager.getBundleInfoNative(bundleName, bundleFlags, EMPTY_USER_ID, true); + function getBundleInfoSync(bundleName: string, bundleFlags: int): BundleInfo { + return bundleManager.getBundleInfoNative(bundleName, bundleFlags, EMPTY_VALUE, true); } - function getBundleInfo(bundleName: string, bundleFlags: number, userId?: number): Promise { + function getBundleInfo(bundleName: string, bundleFlags: int, userId?: int): Promise { let p = new Promise((resolve: (bundleInfo: BundleInfo) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): BundleInfo => { return bundleManager.getBundleInfoNative(bundleName, bundleFlags, userIdInfo, false); }; @@ -359,9 +480,9 @@ namespace bundleManager { return p; } - function getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback): void { + function getBundleInfo(bundleName: string, bundleFlags: int, callback: AsyncCallback): void { let execFun = (): BundleInfo => { - return bundleManager.getBundleInfoNative(bundleName, bundleFlags, EMPTY_USER_ID, false); + return bundleManager.getBundleInfoNative(bundleName, bundleFlags, EMPTY_VALUE, false); }; let p1 = taskpool.execute(execFun); p1.then((e: NullishType) => { @@ -372,7 +493,7 @@ namespace bundleManager { }); } - function getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback): void { + function getBundleInfo(bundleName: string, bundleFlags: int, userId: int, callback: AsyncCallback): void { let execFun = (): BundleInfo => { return bundleManager.getBundleInfoNative(bundleName, bundleFlags, userId, false); }; @@ -385,18 +506,18 @@ namespace bundleManager { }); } - function getApplicationInfoSync(bundleName: string, applicationFlags: number): ApplicationInfo { - return bundleManager.getApplicationInfoNative(bundleName, applicationFlags, EMPTY_USER_ID, true); + function getApplicationInfoSync(bundleName: string, applicationFlags: int): ApplicationInfo { + return bundleManager.getApplicationInfoNative(bundleName, applicationFlags, EMPTY_VALUE, true); } - function getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number): ApplicationInfo { + function getApplicationInfoSync(bundleName: string, applicationFlags: int, userId: int): ApplicationInfo { return bundleManager.getApplicationInfoNative(bundleName, applicationFlags, userId, true); } - function getAllBundleInfo(bundleFlags: number, userId?: number): Promise> { + function getAllBundleInfo(bundleFlags: int, userId?: int): Promise> { let p = new Promise>((resolve: (bundleInfos: Array) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): Array => { return bundleManager.getAllBundleInfoNative(bundleFlags, userIdInfo); }; @@ -412,9 +533,9 @@ namespace bundleManager { return p; } - function getAllBundleInfo(bundleFlags: number, callback: AsyncCallback>): void { + function getAllBundleInfo(bundleFlags: int, callback: AsyncCallback>): void { let execFun = (): Array => { - return bundleManager.getAllBundleInfoNative(bundleFlags, EMPTY_USER_ID); + return bundleManager.getAllBundleInfoNative(bundleFlags, EMPTY_VALUE); }; let p1 = taskpool.execute(execFun); p1.then((e: NullishType) => { @@ -425,7 +546,7 @@ namespace bundleManager { }); } - function getAllBundleInfo(bundleFlags: number, userId: number, callback: AsyncCallback>): void { + function getAllBundleInfo(bundleFlags: int, userId: int, callback: AsyncCallback>): void { let execFun = (): Array => { return bundleManager.getAllBundleInfoNative(bundleFlags, userId); }; @@ -438,10 +559,10 @@ namespace bundleManager { }); } - function getAllApplicationInfo(appFlags: number, userId?: number): Promise> { + function getAllApplicationInfo(appFlags: int, userId?: int): Promise> { let p = new Promise>((resolve: (applicationInfos: Array) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): Array => { return bundleManager.getAllApplicationInfoNative(appFlags, userIdInfo); }; @@ -457,9 +578,9 @@ namespace bundleManager { return p; } - function getAllApplicationInfo(appFlags: number, callback: AsyncCallback>): void { + function getAllApplicationInfo(appFlags: int, callback: AsyncCallback>): void { let execFun = (): Array => { - return bundleManager.getAllApplicationInfoNative(appFlags, EMPTY_USER_ID); + return bundleManager.getAllApplicationInfoNative(appFlags, EMPTY_VALUE); }; let p1 = taskpool.execute(execFun); p1.then((e: NullishType) => { @@ -470,7 +591,7 @@ namespace bundleManager { }); } - function getAllApplicationInfo(appFlags: number, userId: number, + function getAllApplicationInfo(appFlags: int, userId: int, callback: AsyncCallback>): void { let execFun = (): Array => { return bundleManager.getAllApplicationInfoNative(appFlags, userId); @@ -484,7 +605,7 @@ namespace bundleManager { }); } - function isApplicationEnabled(bundleName: string, appIndex: number): Promise { + function isApplicationEnabled(bundleName: string, appIndex: int): Promise { let p = new Promise((resolve: (isEnabled: boolean) => void, reject: (error: BusinessError) => void) => { let execFun = (): boolean => { return bundleManager.isApplicationEnabledNative(bundleName, appIndex, false); @@ -531,10 +652,10 @@ namespace bundleManager { }); } - function queryAbilityInfo(want: Want, abilityFlags: number, userId?: number): Promise> { + function queryAbilityInfo(want: Want, abilityFlags: int, userId?: int): Promise> { let p = new Promise>((resolve: (abilityInfos: Array) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): Array => { return bundleManager.queryAbilityInfoSyncNative(want, abilityFlags, userIdInfo, false); }; @@ -550,9 +671,9 @@ namespace bundleManager { return p; } - function queryAbilityInfo(want: Want, abilityFlags: number, callback: AsyncCallback>): void { + function queryAbilityInfo(want: Want, abilityFlags: int, callback: AsyncCallback>): void { let execFun = (): Array => { - return bundleManager.queryAbilityInfoSyncNative(want, abilityFlags, EMPTY_USER_ID, false); + return bundleManager.queryAbilityInfoSyncNative(want, abilityFlags, EMPTY_VALUE, false); }; let p1 = taskpool.execute(execFun); p1.then((e: NullishType) => { @@ -564,7 +685,7 @@ namespace bundleManager { } function queryAbilityInfo(want: Want, - abilityFlags: number, userId: number, callback: AsyncCallback>): void { + abilityFlags: int, userId: int, callback: AsyncCallback>): void { let execFun = (): Array => { return bundleManager.queryAbilityInfoSyncNative(want, abilityFlags, userId, false); }; @@ -577,10 +698,10 @@ namespace bundleManager { }); } - function getApplicationInfo(bundleName: string, appFlags: number, userId?: number): Promise { + function getApplicationInfo(bundleName: string, appFlags: int, userId?: int): Promise { let p = new Promise(( resolve: (applicationInfo: ApplicationInfo) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): ApplicationInfo => { return bundleManager.getApplicationInfoNative(bundleName, appFlags, userIdInfo, false); }; @@ -596,9 +717,9 @@ namespace bundleManager { return p; } - function getApplicationInfo(bundleName: string, appFlags: number, callback: AsyncCallback): void { + function getApplicationInfo(bundleName: string, appFlags: int, callback: AsyncCallback): void { let execFun = (): ApplicationInfo => { - return bundleManager.getApplicationInfoNative(bundleName, appFlags, EMPTY_USER_ID, false); + return bundleManager.getApplicationInfoNative(bundleName, appFlags, EMPTY_VALUE, false); }; let p1 = taskpool.execute(execFun); p1.then((e: NullishType) => { @@ -610,7 +731,7 @@ namespace bundleManager { } function getApplicationInfo(bundleName: string, - appFlags: number, userId: number, callback: AsyncCallback): void { + appFlags: int, userId: int, callback: AsyncCallback): void { let execFun = (): ApplicationInfo => { return bundleManager.getApplicationInfoNative(bundleName, appFlags, userId, false); }; @@ -623,7 +744,7 @@ namespace bundleManager { }); } - function getAppCloneIdentity(uid: number): Promise { + function getAppCloneIdentity(uid: int): Promise { let p = new Promise(( resolve: (appCloneIdentity: AppCloneIdentity) => void, reject: (error: BusinessError) => void) => { let execFun = (): AppCloneIdentity => { @@ -673,13 +794,13 @@ namespace bundleManager { }); } - function getLaunchWantForBundle(bundleName: string, userId?: number): Promise { + function getLaunchWantForBundle(bundleName: string, userId?: int): Promise { if (bundleName === "") { throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_TYPE_ERROR); } let p = new Promise(( resolve: (want: Want) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): Want => { return bundleManager.getLaunchWantForBundleNative(bundleName, userIdInfo, false); }; @@ -695,7 +816,7 @@ namespace bundleManager { return p; } - function getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback): void { + function getLaunchWantForBundle(bundleName: string, userId: int, callback: AsyncCallback): void { if (bundleName === "") { throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_TYPE_ERROR); } @@ -716,7 +837,7 @@ namespace bundleManager { throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_TYPE_ERROR); } let execFun = (): Want => { - return bundleManager.getLaunchWantForBundleNative(bundleName, EMPTY_USER_ID, false); + return bundleManager.getLaunchWantForBundleNative(bundleName, EMPTY_VALUE, false); }; let p1 = taskpool.execute(execFun); p1.then((e: NullishType) => { @@ -727,11 +848,11 @@ namespace bundleManager { }); } - function getAppCloneBundleInfo(bundleName: string, appIndex: number, - bundleFlags: number, userId?: number): Promise { + function getAppCloneBundleInfo(bundleName: string, appIndex: int, + bundleFlags: int, userId?: int): Promise { let p = new Promise((resolve: (bundleInfo: BundleInfo) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): BundleInfo => { return bundleManager.getAppCloneBundleInfoNative(bundleName, appIndex, bundleFlags, userIdInfo); }; @@ -747,7 +868,7 @@ namespace bundleManager { return p; } - function getBundleNameByUid(uid: number, callback: AsyncCallback): void { + function getBundleNameByUid(uid: int, callback: AsyncCallback): void { let execFun = (): string => { return bundleManager.getBundleNameByUidNative(uid, false); }; @@ -760,7 +881,7 @@ namespace bundleManager { }); } - function getBundleNameByUid(uid: number): Promise { + function getBundleNameByUid(uid: int): Promise { let p = new Promise((resolve: (result: string) => void, reject: (error: BusinessError) => void) => { let execFun = (): string => { return bundleManager.getBundleNameByUidNative(uid, false); @@ -778,10 +899,10 @@ namespace bundleManager { } function queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, - extensionAbilityFlags: number, callback: AsyncCallback>): void { + extensionAbilityFlags: int, callback: AsyncCallback>): void { let execFun = (): Array => { return bundleManager.queryExtensionAbilityInfoNative( - want, extensionAbilityType, "", extensionAbilityFlags, EMPTY_USER_ID, false, false); + want, extensionAbilityType, "", extensionAbilityFlags, EMPTY_VALUE, false, false); }; let p1 = taskpool.execute(execFun); p1.then((e: NullishType) => { @@ -793,7 +914,7 @@ namespace bundleManager { } function queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, - extensionAbilityFlags: number, userId: number, callback: AsyncCallback>): void { + extensionAbilityFlags: int, userId: int, callback: AsyncCallback>): void { let execFun = (): Array => { return bundleManager.queryExtensionAbilityInfoNative( want, extensionAbilityType, "", extensionAbilityFlags, userId, false, false); @@ -808,11 +929,11 @@ namespace bundleManager { } function queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, - extensionAbilityFlags: number, userId?: number): Promise> { + extensionAbilityFlags: int, userId?: int): Promise> { let p = new Promise>(( resolve: (extensionAbilityInfos: Array) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): Array => { return bundleManager.queryExtensionAbilityInfoNative( want, extensionAbilityType, "", extensionAbilityFlags, userIdInfo, false, false); @@ -829,7 +950,7 @@ namespace bundleManager { return p; } - function isAbilityEnabled(info: AbilityInfo, appIndex: number): Promise { + function isAbilityEnabled(info: AbilityInfo, appIndex: int): Promise { let p = new Promise((resolve: (isEnabled: boolean) => void, reject: (error: BusinessError) => void) => { let execFun = (): boolean => { return bundleManager.isAbilityEnabledNative(info, appIndex, false); @@ -876,7 +997,7 @@ namespace bundleManager { }); } - function setAbilityEnabled(info: AbilityInfo, appIndex: number, isEnabled: boolean): Promise { + function setAbilityEnabled(info: AbilityInfo, appIndex: int, isEnabled: boolean): Promise { let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { let execFun = (): void => { return bundleManager.setAbilityEnabledNative(info, isEnabled, appIndex, false); @@ -920,7 +1041,7 @@ namespace bundleManager { }); } - function setApplicationEnabled(bundleName: string, appIndex: number, isEnabled: boolean): Promise { + function setApplicationEnabled(bundleName: string, appIndex: int, isEnabled: boolean): Promise { let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { let execFun = (): void => { return bundleManager.setApplicationEnabledNative(bundleName, isEnabled, appIndex, false); @@ -982,10 +1103,10 @@ namespace bundleManager { return p; } - function queryAbilityInfo(wants: Array, abilityFlags: number, userId?: number): Promise> { + function queryAbilityInfo(wants: Array, abilityFlags: int, userId?: int): Promise> { let p = new Promise>((resolve: (abilityInfos: Array) => void, reject: (error: BusinessError) => void) => { - let userIdInfo: number = userId ?? EMPTY_USER_ID; + let userIdInfo: int = userId ?? EMPTY_VALUE; let execFun = (): Array => { return bundleManager.queryAbilityInfoWithWantsNative(wants, abilityFlags, userIdInfo); }; @@ -1003,8 +1124,9 @@ namespace bundleManager { function enableDynamicIcon(bundleName: string, moduleName: string): Promise { let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { + let bundleOptions = new BundleOptionsInner(); let execFun = (): void => { - return bundleManager.enableDynamicIconNative(bundleName, moduleName); + return bundleManager.enableDynamicIconNative(bundleName, moduleName, bundleOptions); }; let p1 = taskpool.execute(execFun); p1.then((): void => { @@ -1016,6 +1138,608 @@ namespace bundleManager { ); return p; } + + function enableDynamicIcon(bundleName: string, moduleName: string, option?: BundleOptions): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { + let bundleOptions = option ?? new BundleOptionsInner(); + let execFun = (): void => { + return bundleManager.enableDynamicIconNative(bundleName, moduleName, bundleOptions); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getBundleArchiveInfo(hapFilePath: string, bundleFlags: int, callback: AsyncCallback): void { + let execFun = (): BundleInfo => { + return bundleManager.getBundleArchiveInfoNative(hapFilePath, bundleFlags, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let resultBundleInfo: BundleInfo = e as BundleInfo; + callback(null, resultBundleInfo); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getBundleArchiveInfo(hapFilePath: string, bundleFlags: int): Promise { + let p = new Promise((resolve: (bundleInfo: BundleInfo) => void, + reject: (error: Error) => void) => { + let execFun = (): BundleInfo => { + return bundleManager.getBundleArchiveInfoNative(hapFilePath, bundleFlags, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let resultBundleInfo: BundleInfo = e as BundleInfo; + resolve(resultBundleInfo); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise> { + let p = new Promise>((resolve: (profile: Array) + => void, reject: (error: Error) => void) => { + let metadataNameInfo: string = metadataName ?? ""; + let execFun = (): Array => { + return bundleManager.getProfileByAbilityNative(moduleName, abilityName, metadataNameInfo, AbilityProfileType.ABILITY_PROFILE, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let profile: Array = e as Array; + resolve(profile); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getProfileByAbility(moduleName: string, + abilityName: string, metadataName: string, callback: AsyncCallback>) { + let execFun = (): Array => { + return bundleManager.getProfileByAbilityNative(moduleName, abilityName, metadataName, AbilityProfileType.ABILITY_PROFILE, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let profile: Array = e as Array; + callback(null, profile); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getProfileByExtensionAbility(moduleName: string, + extensionAbilityName: string, metadataName?: string): Promise> { + let p = new Promise>((resolve: (profile: Array) + => void, reject: (error: Error) => void) => { + let metadataNameInfo: string = metadataName ?? ""; + let execFun = (): Array => { + return bundleManager.getProfileByAbilityNative(moduleName, extensionAbilityName, metadataNameInfo, AbilityProfileType.EXTENSION_PROFILE, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let profile: Array = e as Array; + resolve(profile); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getProfileByExtensionAbility(moduleName: string, + extensionAbilityName: string, metadataName: string, callback: AsyncCallback>): void { + let execFun = (): Array => { + return bundleManager.getProfileByAbilityNative(moduleName, extensionAbilityName, metadataName, AbilityProfileType.EXTENSION_PROFILE, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let profile: Array = e as Array; + callback(null, profile); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getPermissionDef(permissionName: string): Promise { + let p = new Promise((resolve: (profile: PermissionDef) + => void, reject: (error: Error) => void) => { + let execFun = (): PermissionDef => { + return bundleManager.getPermissionDefNative(permissionName, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let permissionDef: PermissionDef = e as PermissionDef; + resolve(permissionDef); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getPermissionDef(permissionName: string, callback: AsyncCallback): void { + let execFun = (): PermissionDef => { + return bundleManager.getPermissionDefNative(permissionName, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let permissionDef: PermissionDef = e as PermissionDef; + callback(null, permissionDef); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback): void { + let execFun = (): void => { + return bundleManager.cleanBundleCacheFilesNative(bundleName, 0); + }; + let p1 = taskpool.execute(execFun); + p1.then(() => { + callback(null, undefined); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function cleanBundleCacheFiles(bundleName: string): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: Error) => void) : void => { + let execFun = (): void => { + return bundleManager.cleanBundleCacheFilesNative(bundleName, 0); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function cleanBundleCacheFiles(bundleName: string, appIndex: int): Promise { + if (appIndex < MAIN_APP_INDEX || appIndex > CLONE_APP_INDEX_MAX) { + throw createBusinessError(ERROR_INVALID_APPINDEX_CODE, ERROR_INVALID_APPINDEX_MSG); + } + let p = new Promise((resolve: (v:undefined) => void, reject: (error: Error) => void) : void => { + let execFun = (): void => { + return bundleManager.cleanBundleCacheFilesNative(bundleName, appIndex); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAllBundleCacheSize(): Promise { + let p = new Promise((resolve: (size: long) => void, reject: (error: Error) => void) => { + let execFun = (): long => { + return bundleManager.getAllBundleCacheSizeNative(); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let size: long = e as long; + resolve(size); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function cleanAllBundleCache(): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: Error) => void) : void => { + let execFun = (): void => { + return bundleManager.cleanAllBundleCacheNative(); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAppProvisionInfo(bundleName: string, userId?: int): Promise { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } + let p = new Promise((resolve: (appProvisionInfo: AppProvisionInfo) + => void, reject: (error: Error) => void) => { + let userIdInfo: int = userId ?? EMPTY_VALUE; + let execFun = (): AppProvisionInfo => { + return bundleManager.getAppProvisionInfoNative(bundleName, userIdInfo, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let appProvisionInfo: AppProvisionInfo = e as AppProvisionInfo; + resolve(appProvisionInfo); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAppProvisionInfo(bundleName: string, userId: int, callback: AsyncCallback): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } + let execFun = (): AppProvisionInfo => { + return bundleManager.getAppProvisionInfoNative(bundleName, userId, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let appProvisionInfo: AppProvisionInfo = e as AppProvisionInfo; + callback(null, appProvisionInfo); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getAppProvisionInfo(bundleName: string, callback: AsyncCallback): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } + let execFun = (): AppProvisionInfo => { + return bundleManager.getAppProvisionInfoNative(bundleName, EMPTY_VALUE, false); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let appProvisionInfo: AppProvisionInfo = e as AppProvisionInfo; + callback(null, appProvisionInfo); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getAllPreinstalledApplicationInfo(): Promise> { + let p = new Promise>((resolve: + (applicationInfo: Array) => void, reject: (error: Error) => void) => { + let execFun = (): Array => { + return bundleManager.getAllPreinstalledApplicationInfoNative(); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let applicationInfo: Array = e as Array; + resolve(applicationInfo); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAllAppCloneBundleInfo(bundleName: string, bundleFlags: + int, userId?: int): Promise> { + let p = new Promise>((resolve: (bundleInfos: Array) + => void, reject: (error: Error) => void) => { + let userIdInfo: int = userId ?? -2; + let execFun = (): Array => { + return bundleManager.getAllAppCloneBundleInfoNative(bundleName, bundleFlags, userIdInfo); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let resultBundleInfos: Array = e as Array; + resolve(resultBundleInfos); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAllSharedBundleInfo(): Promise> { + let p = new Promise>((resolve: (sharedBundleInfos: Array) + => void, reject: (error: BusinessError) => void) => { + let execFun = (): Array => { + return bundleManager.getAllSharedBundleInfoNative(); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let sharedBundleInfos: Array = e as Array; + resolve(sharedBundleInfos); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAllSharedBundleInfo(callback: AsyncCallback>): void { + let execFun = (): Array => { + return bundleManager.getAllSharedBundleInfoNative(); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let sharedBundleInfos: Array = e as Array; + callback(null, sharedBundleInfos); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getSharedBundleInfo(bundleName: string, moduleName: string): Promise> { + let p = new Promise>((resolve: (sharedBundleInfos: Array) + => void, reject: (error: BusinessError) => void) => { + let execFun = (): Array => { + return bundleManager.getSharedBundleInfoNative(bundleName, moduleName); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let sharedBundleInfos: Array = e as Array; + resolve(sharedBundleInfos); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getSharedBundleInfo(bundleName: string, moduleName: string, + callback: AsyncCallback>): void { + let execFun = (): Array => { + return bundleManager.getSharedBundleInfoNative(bundleName, moduleName); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let sharedBundleInfos: Array = e as Array; + callback(null, sharedBundleInfos); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getExtResource(bundleName: string): Promise> { + let p = new Promise>((resolve: (extResource: Array) + => void, reject: (error: BusinessError) => void) => { + let execFun = (): Array => { + return bundleManager.getExtResourceNative(bundleName); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let extResource: Array = e as Array; + resolve(extResource); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function disableDynamicIcon(bundleName: string): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { + let bundleOptions = new BundleOptionsInner(); + let execFun = (): void => { + return bundleManager.disableDynamicIconNative(bundleName, bundleOptions); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function disableDynamicIcon(bundleName: string, option?: BundleOptions): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { + let bundleOptions = option ?? new BundleOptionsInner(); + let execFun = (): void => { + return bundleManager.disableDynamicIconNative(bundleName, bundleOptions); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getDynamicIconInfo(bundleName: string): Promise> { + let p = new Promise>((resolve: (dynamicIconInfos: Array) + => void, reject: (error: BusinessError) => void) => { + let execFun = (): Array => { + return bundleManager.getDynamicIconInfoNative(bundleName); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let dynamicIconInfos: Array = e as Array; + resolve(dynamicIconInfos); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAllDynamicIconInfo(userId?: int): Promise> { + let p = new Promise>((resolve: (dynamicIconInfos: Array) + => void, reject: (error: BusinessError) => void) => { + let userIdInfo: int = userId ?? EMPTY_VALUE; + let execFun = (): Array => { + return bundleManager.getAllDynamicIconInfoNative(userIdInfo); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let dynamicIconInfos: Array = e as Array; + resolve(dynamicIconInfos); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function verifyAbc(abcPaths: Array, deleteOriginalFiles: boolean): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { + let execFun = (): void => { + return bundleManager.verifyAbcNative(abcPaths, deleteOriginalFiles); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function verifyAbc(abcPaths: Array, deleteOriginalFiles: boolean, callback: AsyncCallback): void { + let execFun = (): void => { + return bundleManager.verifyAbcNative(abcPaths, deleteOriginalFiles); + }; + let p1 = taskpool.execute(execFun); + p1.then(() => { + callback(null, undefined); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getRecoverableApplicationInfo(): Promise> { + let p = new Promise>((resolve: + (applicationInfo: Array) => void, reject: (error: BusinessError) => void) => { + let execFun = (): Array => { + return bundleManager.getRecoverableApplicationInfoNative(); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let applicationInfo: Array = e as Array; + resolve(applicationInfo); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getRecoverableApplicationInfo(callback: AsyncCallback>): void { + let execFun = (): Array => { + return bundleManager.getRecoverableApplicationInfoNative(); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let applicationInfo: Array = e as Array; + callback(null, applicationInfo); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function deleteAbc(abcPath: string): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { + let execFun = (): void => { + return bundleManager.deleteAbcNative(abcPath); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAllPluginInfo(hostBundleName: string, userId?: int): Promise> { + let p = new Promise>((resolve: (pluginBundleInfo: Array) + => void, reject: (error: BusinessError) => void) => { + let userIdInfo: int = userId ?? EMPTY_VALUE; + let execFun = (): Array => { + return bundleManager.getAllPluginInfoNative(hostBundleName, userIdInfo); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let pluginBundleInfo: Array = e as Array; + resolve(pluginBundleInfo); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function migrateData(sourcePaths: Array, destinationPath: string): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { + let execFun = (): void => { + return bundleManager.migrateDataNative(sourcePaths, destinationPath); + }; + let p1 = taskpool.execute(execFun); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function getAbilityInfo(uri: string, abilityFlags: int): Promise> { + if (uri === "") { + throw createBusinessError(ERROR_ABILITY_NOT_EXIST, GETABILITYINFO_ERROR_MSG); + } + let p = new Promise>((resolve: (abilityInfos: Array) + => void, reject: (error: BusinessError) => void) => { + let execFun = (): Array => { + return bundleManager.getAbilityInfoNative(uri, abilityFlags); + }; + let p1 = taskpool.execute(execFun); + p1.then((e: NullishType) => { + let abilityInfos: Array = e as Array; + resolve(abilityInfos); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + function cleanBundleCacheFilesForSelf(): Promise { let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void) : void => { let execFun = (): void => { diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfo.ets index e9f0d46209..5bb3c63fdb 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfo.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfo.ets @@ -23,33 +23,33 @@ export interface AbilityInfo { readonly moduleName: string; readonly name: string; readonly label: string; - readonly labelId: number; + readonly labelId: long; readonly description: string; - readonly descriptionId: number; + readonly descriptionId: long; readonly icon: string; - readonly iconId: number; + readonly iconId: long; readonly process: string; readonly exported: boolean; readonly orientation: bundleManager.DisplayOrientation; readonly launchType: bundleManager.LaunchType; readonly permissions: Array; readonly deviceTypes: Array; - readonly applicationInfo: ApplicationInfo; + readonly applicationInfo: ApplicationInfo | null; readonly metadata: Array; readonly enabled: boolean; readonly supportWindowModes: Array; readonly windowSize: WindowSize; readonly excludeFromDock: boolean; readonly skills: Array; - readonly appIndex: number; - readonly orientationId: number; + readonly appIndex: int; + readonly orientationId: long; } export interface WindowSize { - readonly maxWindowRatio: number; - readonly minWindowRatio: number; - readonly maxWindowWidth: number; - readonly minWindowWidth: number; - readonly maxWindowHeight: number; - readonly minWindowHeight: number; + readonly maxWindowRatio: double; + readonly minWindowRatio: double; + readonly maxWindowWidth: long; + readonly minWindowWidth: long; + readonly maxWindowHeight: long; + readonly minWindowHeight: long; } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfoInner.ets index fa4f2c7c43..bf85410609 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfoInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfoInner.ets @@ -25,33 +25,118 @@ export class AbilityInfoInner implements AbilityInfo { readonly moduleName: string = ""; readonly name: string = ""; readonly label: string = ""; - readonly labelId: number; + readonly labelId: long; readonly description: string = ""; - readonly descriptionId: number; + readonly descriptionId: long; readonly icon: string = ""; - readonly iconId: number; + readonly iconId: long; readonly process: string = ""; readonly exported: boolean; readonly orientation: bundleManager.DisplayOrientation = bundleManager.DisplayOrientation.UNSPECIFIED; readonly launchType: bundleManager.LaunchType = bundleManager.LaunchType.SINGLETON; readonly permissions: Array = new Array; readonly deviceTypes: Array = new Array; - readonly applicationInfo: ApplicationInfo = new ApplicationInfoInner; + readonly applicationInfo: ApplicationInfo | null = null; readonly metadata: Array = new Array; readonly enabled: boolean; readonly supportWindowModes: Array = new Array; readonly windowSize: WindowSize = new WindowSizeInner; readonly excludeFromDock: boolean; readonly skills: Array = new Array; - readonly appIndex: number; - readonly orientationId: number; + readonly appIndex: int; + readonly orientationId: long; + + constructor() { } + constructor(bundleName: string, + moduleName: string, + name: string, + label: string, + labelId: long, + description: string, + descriptionId: long, + icon: string, + iconId: long, + process: string, + exported: boolean, + orientation: bundleManager.DisplayOrientation, + launchType: bundleManager.LaunchType, + permissions: Array, + deviceTypes: Array, + applicationInfo: ApplicationInfo, + metadata: Array, + enabled: boolean, + supportWindowModes: Array, + windowSize: WindowSize, + excludeFromDock: boolean, + skills: Array, + appIndex: int, + orientationId: long) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.name = name; + this.label = label; + this.labelId = labelId; + this.description = description; + this.descriptionId = descriptionId; + this.icon = icon; + this.iconId = iconId; + this.process = process; + this.exported = exported; + this.orientation = orientation; + this.launchType = launchType; + this.permissions = permissions; + this.deviceTypes = deviceTypes; + this.applicationInfo = applicationInfo; + this.metadata = metadata; + this.enabled = enabled; + this.supportWindowModes = supportWindowModes; + this.windowSize = windowSize; + this.excludeFromDock = excludeFromDock; + this.skills = skills; + this.appIndex = appIndex; + this.orientationId = orientationId; + } + constructor(bundleName: string, + moduleName: string, + name: string, + label: string, + labelId: long, + description: string, + descriptionId: long, + icon: string, + iconId: long) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.name = name; + this.label = label; + this.labelId = labelId; + this.description = description; + this.descriptionId = descriptionId; + this.icon = icon; + this.iconId = iconId; + } } export class WindowSizeInner implements WindowSize { - readonly maxWindowRatio: number; - readonly minWindowRatio: number; - readonly maxWindowWidth: number; - readonly minWindowWidth: number; - readonly maxWindowHeight: number; - readonly minWindowHeight: number; + readonly maxWindowRatio: double; + readonly minWindowRatio: double; + readonly maxWindowWidth: long; + readonly minWindowWidth: long; + readonly maxWindowHeight: long; + readonly minWindowHeight: long; + + constructor() { } + constructor(maxWindowRatio: double, + minWindowRatio: double, + maxWindowWidth: long, + minWindowWidth: long, + maxWindowHeight: long, + minWindowHeight: long) { + this.maxWindowRatio = maxWindowRatio; + this.minWindowRatio = minWindowRatio; + this.maxWindowWidth = maxWindowWidth; + this.minWindowWidth = minWindowWidth; + this.maxWindowHeight = maxWindowHeight; + this.minWindowHeight = minWindowHeight; + } } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfo.ets new file mode 100644 index 0000000000..a1606cee0f --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfo.ets @@ -0,0 +1,34 @@ +/* + * 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. + */ + +export interface AppProvisionInfo { + readonly versionCode: long; + readonly versionName: string; + readonly uuid: string; + readonly type: string; + readonly appDistributionType: string; + readonly validity: Validity; + readonly developerId: string; + readonly certificate: string; + readonly apl: string; + readonly issuer: string; + readonly appIdentifier: string; + readonly organization: string; +} + +export interface Validity { + readonly notBefore: long; + readonly notAfter: long; +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfoInner.ets new file mode 100644 index 0000000000..5424edec5d --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfoInner.ets @@ -0,0 +1,70 @@ +/* + * 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 { AppProvisionInfo, Validity } from 'bundleManager.AppProvisionInfo' + +export class AppProvisionInfoInner implements AppProvisionInfo { + public readonly versionCode: long; + public readonly versionName: string = ''; + public readonly uuid: string = ''; + public readonly type: string = ''; + public readonly appDistributionType: string = ''; + public readonly validity: Validity = new ValidityInner; + public readonly developerId: string = ''; + public readonly certificate: string = ''; + public readonly apl: string = ''; + public readonly issuer: string = ''; + public readonly appIdentifier: string = ''; + public readonly organization: string = ''; + + constructor() { } + constructor(versionCode: long, + versionName: string, + uuid: string, + type: string, + appDistributionType: string, + validity: Validity, + developerId: string, + certificate: string, + apl: string, + issuer: string, + appIdentifier: string, + organization: string) { + this.versionCode = versionCode; + this.versionName = versionName; + this.uuid = uuid; + this.type = type; + this.appDistributionType = appDistributionType; + this.validity = validity; + this.developerId = developerId; + this.certificate = certificate; + this.apl = apl; + this.issuer = issuer; + this.appIdentifier = appIdentifier; + this.organization = organization; + } +} + +export class ValidityInner implements Validity { + public readonly notBefore: long; + public readonly notAfter: long; + + constructor() { } + constructor(notBefore: long, + notAfter: long) { + this.notBefore = notBefore; + this.notAfter = notAfter; + } +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfo.ets index 3699f46f3d..fb4788dac9 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfo.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfo.ets @@ -20,19 +20,19 @@ import bundleManager from '@ohos.bundle.bundleManager'; export interface ApplicationInfo { readonly name: string; readonly description: string; - readonly descriptionId: number; + readonly descriptionId: long; readonly enabled: boolean; readonly label: string; - readonly labelId: number; + readonly labelId: long; readonly icon: string; - readonly iconId: number; + readonly iconId: long; readonly process: string; readonly permissions: Array; readonly codePath: string; readonly metadataArray: Array; readonly removable: boolean; - readonly accessTokenId: number; - readonly uid: number; + readonly accessTokenId: long; + readonly uid: int; readonly iconResource: Resource; readonly labelResource: Resource; readonly descriptionResource: Resource; @@ -44,12 +44,12 @@ export interface ApplicationInfo { readonly dataUnclearable: boolean; readonly nativeLibraryPath: string; readonly multiAppMode: MultiAppMode; - readonly appIndex: number; + readonly appIndex: int; readonly installSource: string; readonly releaseType: string; readonly cloudFileSyncEnabled: boolean; readonly cloudStructuredDataSyncEnabled?: boolean; - readonly flags?: number; + readonly flags?: int; } export interface ModuleMetadata { @@ -59,12 +59,12 @@ export interface ModuleMetadata { export interface MultiAppMode { readonly multiAppModeType: bundleManager.MultiAppModeType; - readonly maxCount: number; + readonly maxCount: int; } export interface PreinstalledApplicationInfo { readonly bundleName: string; readonly moduleName: string; - readonly iconId: number; - readonly labelId: number; + readonly iconId: long; + readonly labelId: long; } \ No newline at end of file diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfoInner.ets index 82a9b34f35..807b53a12d 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfoInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfoInner.ets @@ -22,19 +22,19 @@ import { ResourceInner } from 'global.resourceInner'; export class ApplicationInfoInner implements ApplicationInfo { readonly name: string = ""; readonly description: string = ""; - readonly descriptionId: number; + readonly descriptionId: long; readonly enabled: boolean; readonly label: string = ""; - readonly labelId: number; + readonly labelId: long; readonly icon: string = ""; - readonly iconId: number; + readonly iconId: long; readonly process: string = ""; readonly permissions: Array = new Array; readonly codePath: string = ""; readonly metadataArray: Array = new Array; readonly removable: boolean; - readonly accessTokenId: number; - readonly uid: number; + readonly accessTokenId: long; + readonly uid: int; readonly iconResource: Resource = new ResourceInner; readonly labelResource: Resource = new ResourceInner; readonly descriptionResource: Resource = new ResourceInner; @@ -46,27 +46,114 @@ export class ApplicationInfoInner implements ApplicationInfo { readonly dataUnclearable: boolean; readonly nativeLibraryPath: string = ""; readonly multiAppMode: MultiAppMode = new MultiAppModeInner; - readonly appIndex: number; + readonly appIndex: int; readonly installSource: string = ""; readonly releaseType: string = ""; readonly cloudFileSyncEnabled: boolean; readonly cloudStructuredDataSyncEnabled?: boolean|undefined; - readonly flags?: number|undefined; + readonly flags?: int|undefined; + + constructor() { } + constructor(name: string, + description: string, + descriptionId: long, + enabled: boolean, + label: string, + labelId: long, + icon: string, + iconId: long, + process: string, + permissions: Array, + codePath: string, + metadataArray: Array, + removable: boolean, + accessTokenId: long, + uid: int, + iconResource: Resource, + labelResource: Resource, + descriptionResource: Resource, + appDistributionType: string, + appProvisionType: string, + systemApp: boolean, + bundleType: bundleManager.BundleType, + debug: boolean, + dataUnclearable: boolean, + nativeLibraryPath: string, + multiAppMode: MultiAppMode, + appIndex: int, + installSource: string, + releaseType: string, + cloudFileSyncEnabled: boolean, + cloudStructuredDataSyncEnabled?: boolean, + flags?: int) { + this.name = name; + this.description = description; + this.descriptionId = descriptionId; + this.enabled = enabled; + this.label = label; + this.labelId = labelId; + this.icon = icon; + this.iconId = iconId; + this.process = process; + this.permissions = permissions; + this.codePath = codePath; + this.metadataArray = metadataArray; + this.removable = removable; + this.accessTokenId = accessTokenId; + this.uid = uid; + this.iconResource = iconResource; + this.labelResource = labelResource; + this.descriptionResource = descriptionResource; + this.appDistributionType = appDistributionType; + this.appProvisionType = appProvisionType; + this.systemApp = systemApp; + this.bundleType = bundleType; + this.debug = debug; + this.dataUnclearable = dataUnclearable; + this.nativeLibraryPath = nativeLibraryPath; + this.multiAppMode = multiAppMode; + this.appIndex = appIndex; + this.installSource = installSource; + this.releaseType = releaseType; + this.cloudFileSyncEnabled = cloudFileSyncEnabled; + this.cloudStructuredDataSyncEnabled = cloudStructuredDataSyncEnabled; + this.flags = flags; + } } export class ModuleMetadataInner implements ModuleMetadata { readonly moduleName: string = ""; readonly metadata: Array = new Array; + + constructor() { } + constructor(moduleName: string, metadata: Array) { + this.moduleName = moduleName; + this.metadata = metadata; + } } export class MultiAppModeInner implements MultiAppMode { readonly multiAppModeType: bundleManager.MultiAppModeType = bundleManager.MultiAppModeType.UNSPECIFIED; - readonly maxCount: number; + readonly maxCount: int; + + constructor() { } + constructor(multiAppModeType: bundleManager.MultiAppModeType, maxCount: int) { + this.multiAppModeType = multiAppModeType; + this.maxCount = maxCount; + } } export class PreinstalledApplicationInfoInner implements PreinstalledApplicationInfo { readonly bundleName: string = ""; readonly moduleName: string = ""; - readonly iconId: number; - readonly labelId: number; + readonly iconId: long; + readonly labelId: long; + + constructor() { } + constructor(bundleName: string, moduleName: string, iconId: long, labelId: long) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.iconId = iconId; + this.labelId = labelId; + } } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfo.ets index 63841555ba..88b4ac156c 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfo.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfo.ets @@ -20,27 +20,27 @@ import bundleManager from '@ohos.bundle.bundleManager'; export interface BundleInfo { readonly name: string; readonly vendor: string; - readonly versionCode: number; + readonly versionCode: long; readonly versionName: string; - readonly minCompatibleVersionCode: number; - readonly targetVersion: number; - readonly appInfo: ApplicationInfo; + readonly minCompatibleVersionCode: int; + readonly targetVersion: int; + readonly appInfo: ApplicationInfo | null; readonly hapModulesInfo: Array; readonly reqPermissionDetails: Array; readonly permissionGrantStates: Array; - readonly signatureInfo: SignatureInfo; - readonly installTime: number; - readonly updateTime: number; + readonly signatureInfo: SignatureInfo | null; + readonly installTime: long; + readonly updateTime: long; readonly routerMap: Array; - readonly appIndex: number; - readonly firstInstallTime?: number; + readonly appIndex: int; + readonly firstInstallTime?: long; } export interface ReqPermissionDetail { name: string; moduleName: string; reason: string; - reasonId: number; + reasonId: long; usedScene: UsedScene; } @@ -58,5 +58,17 @@ export interface SignatureInfo { export interface AppCloneIdentity { readonly bundleName: string; - readonly appIndex: number; + readonly appIndex: int; +} + +export interface DynamicIconInfo { + readonly bundleName: string; + readonly moduleName: string; + readonly userId: int; + readonly appIndex: int; +} + +export interface BundleOptions { + userId?: int; + appIndex?: int; } \ No newline at end of file diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfoInner.ets index 066a791848..b87b0f4dec 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfoInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfoInner.ets @@ -16,39 +16,94 @@ import { ApplicationInfo } from 'bundleManager.ApplicationInfo'; import { HapModuleInfo, RouterItem } from 'bundleManager.HapModuleInfo'; import bundleManager from '@ohos.bundle.bundleManager'; -import { BundleInfo, ReqPermissionDetail, UsedScene, SignatureInfo, AppCloneIdentity } from 'bundleManager.BundleInfo'; +import { BundleInfo, ReqPermissionDetail, UsedScene, SignatureInfo, AppCloneIdentity, DynamicIconInfo, + BundleOptions} from 'bundleManager.BundleInfo'; import { ApplicationInfoInner } from './ApplicationInfoInner'; export class BundleInfoInner implements BundleInfo { readonly name: string = ""; readonly vendor: string = ""; - readonly versionCode: number; + readonly versionCode: long; readonly versionName: string = ""; - readonly minCompatibleVersionCode: number; - readonly targetVersion: number; - readonly appInfo: ApplicationInfo = new ApplicationInfoInner; + readonly minCompatibleVersionCode: int; + readonly targetVersion: int; + readonly appInfo: ApplicationInfo | null = null; readonly hapModulesInfo: Array = new Array; readonly reqPermissionDetails: Array = new Array; readonly permissionGrantStates: Array = new Array; - readonly signatureInfo: SignatureInfo = new SignatureInfoInner; + readonly signatureInfo: SignatureInfo | null = null; + readonly installTime: long; + readonly updateTime: long; readonly routerMap: Array = new Array; - readonly installTime: number; - readonly updateTime: number; - readonly appIndex: number; - readonly firstInstallTime?: number; + readonly appIndex: int; + readonly firstInstallTime?: long; + + constructor() { } + constructor(name: string, + vendor: string, + versionCode: long, + versionName: string, + minCompatibleVersionCode: int, + targetVersion: int, + appInfo: ApplicationInfo, + hapModulesInfo: Array, + reqPermissionDetails: Array, + permissionGrantStates: Array, + signatureInfo: SignatureInfo, + installTime: long, + updateTime: long, + routerMap: Array, + appIndex: int, + firstInstallTime?: long) { + this.name = name; + this.vendor = vendor; + this.versionCode = versionCode; + this.versionName = versionName; + this.minCompatibleVersionCode = minCompatibleVersionCode; + this.targetVersion = targetVersion; + this.appInfo = appInfo; + this.hapModulesInfo = hapModulesInfo; + this.reqPermissionDetails = reqPermissionDetails; + this.permissionGrantStates = permissionGrantStates; + this.signatureInfo = signatureInfo; + this.installTime = installTime; + this.updateTime = updateTime; + this.routerMap = routerMap; + this.appIndex = appIndex; + this.firstInstallTime = firstInstallTime; + } + constructor(name: string, hapModulesInfo: Array) { + this.name = name; + this.hapModulesInfo = hapModulesInfo; + } } export class ReqPermissionDetailInner implements ReqPermissionDetail { name: string = ""; moduleName: string = ""; reason: string = ""; - reasonId: number; + reasonId: long; usedScene: UsedScene = new UsedSceneInner; + + constructor() { } + constructor(name: string, moduleName: string, reason: string, reasonId: long, usedScene: UsedScene) { + this.name = name; + this.moduleName = moduleName; + this.reason = reason; + this.reasonId = reasonId; + this.usedScene = usedScene; + } } export class UsedSceneInner implements UsedScene { abilities: Array = new Array; when: string = ""; + + constructor() { } + constructor(abilities: Array, when: string) { + this.abilities = abilities; + this.when = when; + } } export class SignatureInfoInner implements SignatureInfo { @@ -56,9 +111,43 @@ export class SignatureInfoInner implements SignatureInfo { readonly fingerprint: string = ""; readonly appIdentifier: string = ""; readonly certificate?: string | undefined; + + constructor() { } + constructor(appId: string, fingerprint: string, appIdentifier: string, certificate?: string) { + this.appId = appId; + this.fingerprint = fingerprint; + this.appIdentifier = appIdentifier; + this.certificate = certificate; + } } export class AppCloneIdentityInner implements AppCloneIdentity { readonly bundleName: string = ""; - readonly appIndex: number; + readonly appIndex: int; + + constructor() { } + constructor(bundleName: string, appIndex: int) { + this.bundleName = bundleName; + this.appIndex = appIndex; + } +} + +export class DynamicIconInfoInner implements DynamicIconInfo { + public readonly bundleName: string = ''; + public readonly moduleName: string = ''; + public readonly userId: int; + public readonly appIndex: int; + + constructor() { } + constructor(bundleName: string, moduleName: string, userId: int, appIndex: int) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.userId = userId; + this.appIndex = appIndex; + } +} + +export class BundleOptionsInner implements BundleOptions { + public userId?: int | undefined; + public appIndex?: int | undefined; } \ No newline at end of file diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfo.ets index 0e54076f5a..87ec0233fd 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfo.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfo.ets @@ -22,19 +22,19 @@ export interface ExtensionAbilityInfo { readonly bundleName: string; readonly moduleName: string; readonly name: string; - readonly labelId: number; - readonly descriptionId: number; - readonly iconId: number; + readonly labelId: long; + readonly descriptionId: long; + readonly iconId: long; readonly exported: boolean; readonly extensionAbilityType: bundleManager.ExtensionAbilityType; readonly extensionAbilityTypeName: string; readonly permissions: Array; - readonly applicationInfo: ApplicationInfo; + readonly applicationInfo: ApplicationInfo | null; readonly metadata: Array; readonly enabled: boolean; readonly readPermission: string; readonly writePermission: string; readonly skills: Array; - readonly appIndex: number; + readonly appIndex: int; } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfoInner.ets index 0ed1bc765a..33ef75321a 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfoInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfoInner.ets @@ -24,19 +24,69 @@ export class ExtensionAbilityInfoInner implements ExtensionAbilityInfo { readonly bundleName: string = ""; readonly moduleName: string = ""; readonly name: string = ""; - readonly labelId: number; - readonly descriptionId: number; - readonly iconId: number; + readonly labelId: long; + readonly descriptionId: long; + readonly iconId: long; readonly exported: boolean; readonly extensionAbilityType: bundleManager.ExtensionAbilityType = bundleManager.ExtensionAbilityType.UNSPECIFIED; readonly extensionAbilityTypeName: string = ""; readonly permissions: Array = new Array; - readonly applicationInfo: ApplicationInfo = new ApplicationInfoInner; + readonly applicationInfo: ApplicationInfo | null = null; readonly metadata: Array = new Array; readonly enabled: boolean; readonly readPermission: string = ""; readonly writePermission: string = ""; readonly skills: Array = new Array; - readonly appIndex: number; + readonly appIndex: int; + + constructor() { } + constructor(bundleName: string, + moduleName: string, + name: string, + labelId: long, + descriptionId: long, + iconId: long, + exported: boolean, + extensionAbilityType: bundleManager.ExtensionAbilityType, + extensionAbilityTypeName: string, + permissions: Array, + applicationInfo: ApplicationInfo, + metadata: Array, + enabled: boolean, + readPermission: string, + writePermission: string, + skills: Array, + appIndex: int) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.name = name; + this.labelId = labelId; + this.descriptionId = descriptionId; + this.iconId = iconId; + this.exported = exported; + this.extensionAbilityType = extensionAbilityType; + this.extensionAbilityTypeName = extensionAbilityTypeName; + this.permissions = permissions; + this.applicationInfo = applicationInfo; + this.metadata = metadata; + this.enabled = enabled; + this.readPermission = readPermission; + this.writePermission = writePermission; + this.skills = skills; + this.appIndex = appIndex; + } + constructor(bundleName: string, + moduleName: string, + name: string, + labelId: long, + descriptionId: long, + iconId: long) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.name = name; + this.labelId = labelId; + this.descriptionId = descriptionId; + this.iconId = iconId; + } } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfo.ets index acf8162843..edd50608a3 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfo.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfo.ets @@ -21,11 +21,11 @@ import bundleManager from '@ohos.bundle.bundleManager'; export interface HapModuleInfo { readonly name: string; readonly icon: string; - readonly iconId: number; + readonly iconId: long; readonly label: string; - readonly labelId: number; + readonly labelId: long; readonly description: string; - readonly descriptionId: number; + readonly descriptionId: long; readonly mainElementName: string; readonly abilitiesInfo: Array; readonly extensionAbilitiesInfo: Array; @@ -45,7 +45,7 @@ export interface HapModuleInfo { export interface Dependency { readonly moduleName: string; readonly bundleName: string; - readonly versionCode: number; + readonly versionCode: long; } export interface PreloadItem { diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfoInner.ets index 4022bb7ffb..b4bf851970 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfoInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfoInner.ets @@ -22,11 +22,11 @@ import { HapModuleInfo, Dependency, PreloadItem, RouterItem, DataItem } from 'bu export class HapModuleInfoInner implements HapModuleInfo { readonly name: string = ""; readonly icon: string = ""; - readonly iconId: number; + readonly iconId: long; readonly label: string = ""; - readonly labelId: number; + readonly labelId: long; readonly description: string = ""; - readonly descriptionId: number; + readonly descriptionId: long; readonly mainElementName: string = ""; readonly abilitiesInfo: Array = new Array; readonly extensionAbilitiesInfo: Array = new Array; @@ -41,16 +41,77 @@ export class HapModuleInfoInner implements HapModuleInfo { readonly routerMap: Array = new Array; readonly nativeLibraryPath: string = ""; readonly codePath: string = ""; + + constructor() { } + constructor(name: string, + icon: string, + iconId: long, + label: string, + labelId: long, + description: string, + descriptionId: long, + mainElementName: string, + abilitiesInfo: Array, + extensionAbilitiesInfo: Array, + metadata: Array, + deviceTypes: Array, + installationFree: boolean, + hashValue: string, + type: bundleManager.ModuleType, + dependencies: Array, + preloads: Array, + fileContextMenuConfig: string, + routerMap: Array, + nativeLibraryPath: string, + codePath: string) { + this.name = name; + this.icon = icon; + this.iconId = iconId; + this.label = label; + this.labelId = labelId; + this.description = description; + this.descriptionId = descriptionId; + this.mainElementName = mainElementName; + this.abilitiesInfo = abilitiesInfo; + this.extensionAbilitiesInfo = extensionAbilitiesInfo; + this.metadata = metadata; + this.deviceTypes = deviceTypes; + this.installationFree = installationFree; + this.hashValue = hashValue; + this.type = type; + this.dependencies = dependencies; + this.preloads = preloads; + this.fileContextMenuConfig = fileContextMenuConfig; + this.routerMap = routerMap; + this.nativeLibraryPath = nativeLibraryPath; + this.codePath = codePath; + } + constructor(abilitiesInfo: Array, extensionAbilitiesInfo: Array) { + this.abilitiesInfo = abilitiesInfo; + this.extensionAbilitiesInfo = extensionAbilitiesInfo; + } } export class DependencyInner implements Dependency { readonly moduleName: string = ""; readonly bundleName: string = ""; - readonly versionCode: number; + readonly versionCode: long; + + constructor() { } + constructor(moduleName: string, bundleName: string, versionCode: long) { + this.moduleName = moduleName; + this.bundleName = bundleName; + this.versionCode = versionCode; + } } export class PreloadItemInner implements PreloadItem { readonly moduleName: string = ""; + + constructor() { } + constructor(moduleName: string) { + this.moduleName = moduleName; + } } export class RouterItemInner implements RouterItem { @@ -59,9 +120,24 @@ export class RouterItemInner implements RouterItem { readonly buildFunction: string = ""; readonly customData: string = ""; readonly data: Array = new Array; + + constructor() { } + constructor(name: string, pageSourceFile: string, buildFunction: string, customData: string, data: Array) { + this.name = name; + this.pageSourceFile = pageSourceFile; + this.buildFunction = buildFunction; + this.customData = customData; + this.data = data; + } } export class DataItemInner implements DataItem { readonly key: string = ""; readonly value: string = ""; + + constructor() { } + constructor(key: string, value: string) { + this.key = key; + this.value = value; + } } \ No newline at end of file diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/Metadata.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/Metadata.ets index 8005f976a3..44f70e8a58 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/Metadata.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/Metadata.ets @@ -17,5 +17,5 @@ export interface Metadata { name: string; value: string; resource: string; - readonly valueId?: number; + readonly valueId?: long; } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/MetadataInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/MetadataInner.ets index 4fa5d528ec..c3e59cea7c 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/MetadataInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/MetadataInner.ets @@ -19,5 +19,13 @@ export class MetadataInner implements Metadata { name: string = ""; value: string = ""; resource: string = ""; - readonly valueId?: number; + readonly valueId?: long; + + constructor() { } + constructor(name: string, value: string, resource: string, valueId?: long) { + this.name = name; + this.value = value; + this.resource = resource; + this.valueId = valueId; + } } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDef.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDef.ets new file mode 100644 index 0000000000..079933c245 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDef.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +export interface PermissionDef { + readonly permissionName: string; + readonly grantMode: int; + readonly labelId: long; + readonly descriptionId: long; +} \ No newline at end of file diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDefInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDefInner.ets new file mode 100644 index 0000000000..a10b8f3a22 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDefInner.ets @@ -0,0 +1,34 @@ +/* + * 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 { PermissionDef } from 'bundleManager.PermissionDef' + +export class PermissionDefInner implements PermissionDef { + public readonly permissionName: string = ''; + public readonly grantMode: int; + public readonly labelId: long; + public readonly descriptionId: long; + + constructor() { } + constructor(permissionName: string, + grantMode: int, + labelId: long, + descriptionId: long) { + this.permissionName = permissionName; + this.grantMode = grantMode; + this.labelId = labelId; + this.descriptionId = descriptionId; + } +} \ No newline at end of file diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfo.ets new file mode 100644 index 0000000000..869773e098 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfo.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +export interface PluginBundleInfo { + readonly label: string; + readonly labelId: long; + readonly icon: string; + readonly iconId: long; + readonly pluginBundleName: string; + readonly versionCode: long; + readonly versionName: string; + readonly pluginModuleInfos: Array; +} + +export interface PluginModuleInfo { + readonly moduleName: string; + readonly descriptionId: long; + readonly description: string; +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfoInner.ets new file mode 100644 index 0000000000..83b8c42b90 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfoInner.ets @@ -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 { PluginBundleInfo, PluginModuleInfo } from 'bundleManager.PluginBundleInfo'; + +export class PluginBundleInfoInner implements PluginBundleInfo { + public readonly label: string = ''; + public readonly labelId: long; + public readonly icon: string = ''; + public readonly iconId: long; + public readonly pluginBundleName: string = ''; + public readonly versionCode: long; + public readonly versionName: string = ''; + public readonly pluginModuleInfos: Array = new Array; + + constructor() { } + constructor(label: string, + labelId: long, + icon: string, + iconId: long, + pluginBundleName: string, + versionCode: long, + versionName: string, + pluginModuleInfos: Array) { + this.label = label; + this.labelId = labelId; + this.icon = icon; + this.iconId = iconId; + this.pluginBundleName = pluginBundleName; + this.versionCode = versionCode; + this.versionName = versionName; + this.pluginModuleInfos = pluginModuleInfos; + } +} + +export class PluginModuleInfoInner implements PluginModuleInfo { + public readonly moduleName: string = ''; + public readonly descriptionId: long; + public readonly description: string = ''; + + constructor() { } + constructor(moduleName: string, + descriptionId: long, + description: string) { + this.moduleName = moduleName; + this.descriptionId = descriptionId; + this.description = description; + } +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfo.ets new file mode 100644 index 0000000000..368cb40ffe --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfo.ets @@ -0,0 +1,26 @@ +/* + * 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 bundleManager from '@ohos.bundle.bundleManager'; + +export interface RecoverableApplicationInfo { + readonly bundleName: string; + readonly moduleName: string; + readonly labelId: long; + readonly iconId: long; + readonly systemApp: boolean; + readonly bundleType: bundleManager.BundleType; + readonly codePaths: Array; +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfoInner.ets new file mode 100644 index 0000000000..f1ea78f369 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfoInner.ets @@ -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. + */ + +import bundleManager from '@ohos.bundle.bundleManager'; +import { RecoverableApplicationInfo } from 'bundleManager.RecoverableApplicationInfo' + +export class RecoverableApplicationInfoInner implements RecoverableApplicationInfo { + public readonly bundleName: string = ''; + public readonly moduleName: string = ''; + public readonly labelId: long; + public readonly iconId: long; + public readonly systemApp: boolean; + public readonly bundleType: bundleManager.BundleType = bundleManager.BundleType.APP; + public readonly codePaths: Array = new Array; + + constructor() { } + constructor(bundleName: string, + moduleName: string, + labelId: long, + iconId: long, + systemApp: boolean, + bundleType: bundleManager.BundleType, + codePaths: Array) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.labelId = labelId; + this.iconId = iconId; + this.systemApp = systemApp; + this.bundleType = bundleType; + this.codePaths = codePaths; + } +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfo.ets new file mode 100644 index 0000000000..b7f9311d72 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfo.ets @@ -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. + */ + +import bundleManager from '@ohos.bundle.bundleManager'; + +export interface SharedBundleInfo { + readonly name: string; + readonly compatiblePolicy: bundleManager.CompatiblePolicy; + readonly sharedModuleInfo: Array; +} + +export interface SharedModuleInfo { + readonly name: string; + readonly versionCode: long; + readonly versionName: string; + readonly description: string; + readonly descriptionId: long; +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfoInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfoInner.ets new file mode 100644 index 0000000000..498bd8da99 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfoInner.ets @@ -0,0 +1,54 @@ +/* + * 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 bundleManager from '@ohos.bundle.bundleManager'; +import { SharedBundleInfo, SharedModuleInfo } from 'bundleManager.SharedBundleInfo' + +export class SharedBundleInfoInner implements SharedBundleInfo { + public readonly name: string = ''; + public readonly compatiblePolicy: bundleManager.CompatiblePolicy = + bundleManager.CompatiblePolicy.BACKWARD_COMPATIBILITY; + public readonly sharedModuleInfo: Array = new Array; + + constructor() { } + constructor(name: string, + compatiblePolicy: bundleManager.CompatiblePolicy, + sharedModuleInfo: Array) { + this.name = name; + this.compatiblePolicy = compatiblePolicy; + this.sharedModuleInfo = sharedModuleInfo; + } +} + +export class SharedModuleInfoInner implements SharedModuleInfo { + public readonly name: string = ''; + public readonly versionCode: long; + public readonly versionName: string = ''; + public readonly description: string = ''; + public readonly descriptionId: long; + + constructor() { } + constructor(name: string, + versionCode: long, + versionName: string, + description: string, + descriptionId: long) { + this.name = name; + this.versionCode = versionCode; + this.versionName = versionName; + this.description = description; + this.descriptionId = descriptionId; + } +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/Skill.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/Skill.ets index 9fa231ab73..21835f1ff3 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/Skill.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/Skill.ets @@ -23,12 +23,12 @@ export interface Skill { export interface SkillUri { readonly scheme: string; readonly host: string; - readonly port: number; + readonly port: int; readonly path: string; readonly pathStartWith: string; readonly pathRegex: string; readonly type: string; readonly utd: string; - readonly maxFileSupported: number; + readonly maxFileSupported: int; readonly linkFeature: string; } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/SkillInner.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/SkillInner.ets index 0cb6db443e..4496d46e2b 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/SkillInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/SkillInner.ets @@ -20,17 +20,48 @@ export class SkillInner implements Skill { readonly entities: Array = new Array; readonly uris: Array = new Array; readonly domainVerify: boolean; + + constructor() { } + constructor(actions: Array, entities: Array, uris: Array, domainVerify: boolean) { + this.actions = actions; + this.entities = entities; + this.uris = uris; + this.domainVerify = domainVerify; + } } export class SkillUriInner implements SkillUri { readonly scheme: string = ""; readonly host: string = ""; - readonly port: number; + readonly port: int; readonly path: string = ""; readonly pathStartWith: string = ""; readonly pathRegex: string = ""; readonly type: string = ""; readonly utd: string = ""; - readonly maxFileSupported: number; + readonly maxFileSupported: int; readonly linkFeature: string = ""; + + constructor() { } + constructor(scheme: string, + host: string, + port: int, + path: string, + pathStartWith: string, + pathRegex: string, + type: string, + utd: string, + maxFileSupported: int, + linkFeature: string) { + this.scheme = scheme; + this.host = host; + this.port = port; + this.path = path; + this.pathStartWith = pathStartWith; + this.pathRegex = pathRegex; + this.type = type; + this.utd = utd; + this.maxFileSupported = maxFileSupported; + this.linkFeature = linkFeature; + } } diff --git a/interfaces/kits/ani/bundle_monitor/BUILD.gn b/interfaces/kits/ani/bundle_monitor/BUILD.gn index dd51e57a17..fa08ae6183 100644 --- a/interfaces/kits/ani/bundle_monitor/BUILD.gn +++ b/interfaces/kits/ani/bundle_monitor/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") ohos_shared_library("ani_bundle_monitor") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { diff --git a/interfaces/kits/ani/bundle_monitor/ets/@ohos.bundle.bundleMonitor.ets b/interfaces/kits/ani/bundle_monitor/ets/@ohos.bundle.bundleMonitor.ets index 1b5ad11e8f..59efe8a6af 100644 --- a/interfaces/kits/ani/bundle_monitor/ets/@ohos.bundle.bundleMonitor.ets +++ b/interfaces/kits/ani/bundle_monitor/ets/@ohos.bundle.bundleMonitor.ets @@ -21,14 +21,23 @@ export default namespace bundleMonitor { export interface BundleChangedInfo { readonly bundleName: string; - readonly userId: number; - readonly appIndex: number; + readonly userId: int; + readonly appIndex: int; } export class BundleChangedInfoInner implements BundleChangedInfo { readonly bundleName: string; - readonly userId: number; - readonly appIndex: number; + readonly userId: int; + readonly appIndex: int; + + constructor() { } + constructor(bundleName: string, + userId: int, + appIndex: int) { + this.bundleName = bundleName; + this.userId = userId; + this.appIndex = appIndex; + } } type BundleChangedEvent = 'add' | 'update' | 'remove'; diff --git a/interfaces/kits/ani/common/BUILD.gn b/interfaces/kits/ani/common/BUILD.gn index 789e9fc86f..febafb002b 100644 --- a/interfaces/kits/ani/common/BUILD.gn +++ b/interfaces/kits/ani/common/BUILD.gn @@ -68,6 +68,7 @@ ohos_shared_library("bms_ani_common") { "hilog:libhilog", "ipc:ipc_core", "runtime_core:ani", + "runtime_core:ani_helpers", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/interfaces/kits/ani/common/business_error_ani.cpp b/interfaces/kits/ani/common/business_error_ani.cpp index 7eabdeb7f6..e40645b10e 100644 --- a/interfaces/kits/ani/common/business_error_ani.cpp +++ b/interfaces/kits/ani/common/business_error_ani.cpp @@ -26,7 +26,7 @@ namespace OHOS { namespace AppExecFwk { namespace { constexpr const char* ERROR_MESSAGE_PLACEHOLDER = "$"; -constexpr const char* BUSINESS_ERROR_CLASS = "L@ohos/base/BusinessError;"; +constexpr const char* BUSINESS_ERROR_CLASS = "@ohos.base.BusinessError"; } // namespace void BusinessErrorAni::ThrowError(ani_env *env, int32_t err, const std::string &msg) @@ -58,12 +58,12 @@ ani_object BusinessErrorAni::WrapError(ani_env *env, const std::string &msg) ani_ref undefRef; env->GetUndefined(&undefRef); - ani_status status = env->FindClass("Lescompat/Error;", &cls); + ani_status status = env->FindClass("escompat.Error", &cls); if (status != ANI_OK) { APP_LOGE("FindClass err : %{public}d", status); return nullptr; } - status = env->Class_FindMethod(cls, "", "Lstd/core/String;Lescompat/ErrorOptions;:V", &method); + status = env->Class_FindMethod(cls, "", "C{std.core.String}C{escompat.ErrorOptions}:", &method); if (status != ANI_OK) { APP_LOGE("Class_FindMethod err : %{public}d", status); return nullptr; @@ -90,7 +90,7 @@ ani_object BusinessErrorAni::CreateError(ani_env *env, int32_t code, const std:: APP_LOGE("FindClass err : %{public}d", status); return nullptr; } - status = env->Class_FindMethod(cls, "", "DLescompat/Error;:V", &method); + status = env->Class_FindMethod(cls, "", "dC{escompat.Error}:", &method); if (status != ANI_OK) { APP_LOGE("Class_FindMethod err : %{public}d", status); return nullptr; diff --git a/interfaces/kits/ani/common/business_error_ani.h b/interfaces/kits/ani/common/business_error_ani.h index fd2c3e6cb2..54d5fd2668 100644 --- a/interfaces/kits/ani/common/business_error_ani.h +++ b/interfaces/kits/ani/common/business_error_ani.h @@ -19,6 +19,7 @@ #include #include "appexecfwk_errors.h" #include "bundle_errors.h" +#include namespace OHOS { namespace AppExecFwk { diff --git a/interfaces/kits/ani/common/common_fun_ani.cpp b/interfaces/kits/ani/common/common_fun_ani.cpp index 5fe1739d90..ff3f778d94 100644 --- a/interfaces/kits/ani/common/common_fun_ani.cpp +++ b/interfaces/kits/ani/common/common_fun_ani.cpp @@ -13,222 +13,132 @@ * limitations under the License. */ +#include #include #include +#include "ani_signature_builder.h" #include "app_log_wrapper.h" #include "common_fun_ani.h" namespace OHOS { namespace AppExecFwk { +using namespace arkts::ani_signature; using Want = OHOS::AAFwk::Want; namespace { -constexpr const char* CLASSNAME_ABILITYINFO = "LbundleManager/AbilityInfoInner/AbilityInfoInner;"; -constexpr const char* CLASSNAME_EXTENSIONABILITYINFO = - "LbundleManager/ExtensionAbilityInfoInner/ExtensionAbilityInfoInner;"; -constexpr const char* CLASSNAME_WINDOWSIZE = "LbundleManager/AbilityInfoInner/WindowSizeInner;"; -constexpr const char* CLASSNAME_APPLICATIONINFO = "LbundleManager/ApplicationInfoInner/ApplicationInfoInner;"; -constexpr const char* CLASSNAME_MODULEMETADATA = "LbundleManager/ApplicationInfoInner/ModuleMetadataInner;"; -constexpr const char* CLASSNAME_MULTIAPPMODE = "LbundleManager/ApplicationInfoInner/MultiAppModeInner;"; -constexpr const char* CLASSNAME_BUNDLEINFO = "LbundleManager/BundleInfoInner/BundleInfoInner;"; -constexpr const char* CLASSNAME_PERMISSION = "LbundleManager/BundleInfoInner/ReqPermissionDetailInner;"; -constexpr const char* CLASSNAME_USEDSCENE = "LbundleManager/BundleInfoInner/UsedSceneInner;"; -constexpr const char* CLASSNAME_SIGNATUREINFO = "LbundleManager/BundleInfoInner/SignatureInfoInner;"; -constexpr const char* CLASSNAME_APPCLONEIDENTITY = "LbundleManager/BundleInfoInner/AppCloneIdentityInner;"; -constexpr const char* CLASSNAME_METADATA = "LbundleManager/MetadataInner/MetadataInner;"; -constexpr const char* CLASSNAME_RESOURCE = "Lglobal/resourceInner/ResourceInner;"; -constexpr const char* CLASSNAME_ROUTERITEM = "LbundleManager/HapModuleInfoInner/RouterItemInner;"; -constexpr const char* CLASSNAME_PRELOADITEM = "LbundleManager/HapModuleInfoInner/PreloadItemInner;"; -constexpr const char* CLASSNAME_DEPENDENCY = "LbundleManager/HapModuleInfoInner/DependencyInner;"; -constexpr const char* CLASSNAME_HAPMODULEINFO = "LbundleManager/HapModuleInfoInner/HapModuleInfoInner;"; -constexpr const char* CLASSNAME_DATAITEM = "LbundleManager/HapModuleInfoInner/DataItemInner;"; -constexpr const char* CLASSNAME_ELEMENTNAME = "LbundleManager/ElementNameInner/ElementNameInner;"; -constexpr const char* CLASSNAME_SKILL = "LbundleManager/SkillInner/SkillInner;"; -constexpr const char* CLASSNAME_SKILLURI = "LbundleManager/SkillInner/SkillUriInner;"; -constexpr const char* CLASSNAME_BUNDLERESINFO = "LbundleManager/BundleResourceInfoInner/BundleResourceInfoInner;"; -constexpr const char* CLASSNAME_LAUNCHER_ABILITY_RESOURCE_INFO_INNER = - "LbundleManager/LauncherAbilityResourceInfoInner/LauncherAbilityResourceInfoInner;"; -constexpr const char* CLASSNAME_SHORTCUTINFO = "LbundleManager/ShortcutInfo/ShortcutInfoInner;"; -constexpr const char* CLASSNAME_SHORTCUTWANT = "LbundleManager/ShortcutInfo/ShortcutWantInner;"; -constexpr const char* CLASSNAME_SHORTCUT_PARAMETERITEM = "LbundleManager/ShortcutInfo/ParameterItemInner;"; +constexpr const char* CLASSNAME_ABILITY_INFO_INNER = "bundleManager.AbilityInfoInner.AbilityInfoInner"; +constexpr const char* CLASSNAME_EXTENSION_ABILITY_INFO_INNER = + "bundleManager.ExtensionAbilityInfoInner.ExtensionAbilityInfoInner"; +constexpr const char* CLASSNAME_WINDOW_SIZE = "bundleManager.AbilityInfo.WindowSize"; +constexpr const char* CLASSNAME_WINDOW_SIZE_INNER = "bundleManager.AbilityInfoInner.WindowSizeInner"; +constexpr const char* CLASSNAME_APPLICATION_INFO = "bundleManager.ApplicationInfo.ApplicationInfo"; +constexpr const char* CLASSNAME_APPLICATION_INFO_INNER = "bundleManager.ApplicationInfoInner.ApplicationInfoInner"; +constexpr const char* CLASSNAME_MODULE_METADATA_INNER = "bundleManager.ApplicationInfoInner.ModuleMetadataInner"; +constexpr const char* CLASSNAME_MULTI_APP_MODE = "bundleManager.ApplicationInfo.MultiAppMode"; +constexpr const char* CLASSNAME_MULTI_APP_MODE_INNER = "bundleManager.ApplicationInfoInner.MultiAppModeInner"; +constexpr const char* CLASSNAME_BUNDLE_INFO_INNER = "bundleManager.BundleInfoInner.BundleInfoInner"; +constexpr const char* CLASSNAME_PERMISSION_INNER = "bundleManager.BundleInfoInner.ReqPermissionDetailInner"; +constexpr const char* CLASSNAME_USED_SCENE = "bundleManager.BundleInfo.UsedScene"; +constexpr const char* CLASSNAME_USED_SCENE_INNER = "bundleManager.BundleInfoInner.UsedSceneInner"; +constexpr const char* CLASSNAME_SIGNATURE_INFO = "bundleManager.BundleInfo.SignatureInfo"; +constexpr const char* CLASSNAME_SIGNATURE_INFO_INNER = "bundleManager.BundleInfoInner.SignatureInfoInner"; +constexpr const char* CLASSNAME_APP_CLONE_IDENTITY_INNER = "bundleManager.BundleInfoInner.AppCloneIdentityInner"; +constexpr const char* CLASSNAME_DYNAMIC_ICON_INFO_INNER = "bundleManager.BundleInfoInner.DynamicIconInfoInner"; +constexpr const char* CLASSNAME_PERMISSION_DEF_INNER = "bundleManager.PermissionDefInner.PermissionDefInner"; +constexpr const char* CLASSNAME_SHARED_BUNDLE_INFO_INNER = "bundleManager.SharedBundleInfoInner.SharedBundleInfoInner"; +constexpr const char* CLASSNAME_SHARED_MODULE_INFO_INNER = "bundleManager.SharedBundleInfoInner.SharedModuleInfoInner"; +constexpr const char* CLASSNAME_APP_PROVISION_INFO_INNER = "bundleManager.AppProvisionInfoInner.AppProvisionInfoInner"; +constexpr const char* CLASSNAME_VALIDITY = "bundleManager.AppProvisionInfo.Validity"; +constexpr const char* CLASSNAME_VALIDITY_INNER = "bundleManager.AppProvisionInfoInner.ValidityInner"; +constexpr const char* CLASSNAME_RECOVERABLE_APPLICATION_INFO_INNER = + "bundleManager.RecoverableApplicationInfoInner.RecoverableApplicationInfoInner"; +constexpr const char* CLASSNAME_PREINSTALLED_APPLICATION_INFO_INNER = + "bundleManager.ApplicationInfoInner.PreinstalledApplicationInfoInner"; +constexpr const char* CLASSNAME_PLUGIN_BUNDLE_INFO_INNER = "bundleManager.PluginBundleInfoInner.PluginBundleInfoInner"; +constexpr const char* CLASSNAME_PLUGIN_MODULE_INFO_INNER = "bundleManager.PluginBundleInfoInner.PluginModuleInfoInner"; +constexpr const char* CLASSNAME_METADATA_INNER = "bundleManager.MetadataInner.MetadataInner"; +constexpr const char* CLASSNAME_RESOURCE = "global.resource.Resource"; +constexpr const char* CLASSNAME_RESOURCE_INNER = "global.resourceInner.ResourceInner"; +constexpr const char* CLASSNAME_ROUTER_ITEM_INNER = "bundleManager.HapModuleInfoInner.RouterItemInner"; +constexpr const char* CLASSNAME_PRELOAD_ITEM_INNER = "bundleManager.HapModuleInfoInner.PreloadItemInner"; +constexpr const char* CLASSNAME_DEPENDENCY_INNER = "bundleManager.HapModuleInfoInner.DependencyInner"; +constexpr const char* CLASSNAME_HAP_MODULE_INFO_INNER = "bundleManager.HapModuleInfoInner.HapModuleInfoInner"; +constexpr const char* CLASSNAME_DATA_ITEM_INNER = "bundleManager.HapModuleInfoInner.DataItemInner"; +constexpr const char* CLASSNAME_ELEMENT_NAME = "bundleManager.ElementName.ElementName"; +constexpr const char* CLASSNAME_ELEMENT_NAME_INNER = "bundleManager.ElementNameInner.ElementNameInner"; +constexpr const char* CLASSNAME_SKILL_INNER = "bundleManager.SkillInner.SkillInner"; +constexpr const char* CLASSNAME_SKILL_URI_INNER = "bundleManager.SkillInner.SkillUriInner"; +constexpr const char* CLASSNAME_SHORTCUT_INFO_INNER = "bundleManager.ShortcutInfo.ShortcutInfoInner"; +constexpr const char* CLASSNAME_SHORTCUT_WANT_INNER = "bundleManager.ShortcutInfo.ShortcutWantInner"; +constexpr const char* CLASSNAME_SHORTCUT_PARAMETER_ITEM_INNER = "bundleManager.ShortcutInfo.ParameterItemInner"; constexpr const char* CLASSNAME_LAUNCHER_ABILITY_INFO_INNER = - "LbundleManager/LauncherAbilityInfoInner/LauncherAbilityInfoInner;"; + "bundleManager.LauncherAbilityInfoInner.LauncherAbilityInfoInner"; constexpr const char* CLASSNAME_BUNDLE_CHANGED_INFO_INNER = - "L@ohos/bundle/bundleMonitor/bundleMonitor/BundleChangedInfoInner;"; -constexpr const char* CLASSNAME_BUNDLE_PACK_INFO_INNER = "LbundleManager/BundlePackInfoInner/BundlePackInfoInner;"; -constexpr const char* CLASSNAME_PACKAGE_CONFIG_INNER = "LbundleManager/BundlePackInfoInner/PackageConfigInner;"; -constexpr const char* CLASSNAME_PACKAGE_SUMMARY_INNER = "LbundleManager/BundlePackInfoInner/PackageSummaryInner;"; -constexpr const char* CLASSNAME_BUNDLE_CONFIG_INFO_INNER = "LbundleManager/BundlePackInfoInner/BundleConfigInfoInner;"; -constexpr const char* CLASSNAME_EXTENSION_ABILITY_INNER = "LbundleManager/BundlePackInfoInner/ExtensionAbilityInner;"; -constexpr const char* CLASSNAME_MODULE_CONFIG_INFO_INNER = "LbundleManager/BundlePackInfoInner/ModuleConfigInfoInner;"; -constexpr const char* CLASSNAME_MODULE_DISTRO_INFO_INNER = "LbundleManager/BundlePackInfoInner/ModuleDistroInfoInner;"; + "@ohos.bundle.bundleMonitor.bundleMonitor.BundleChangedInfoInner"; +constexpr const char* CLASSNAME_BUNDLE_PACK_INFO_INNER = "bundleManager.BundlePackInfoInner.BundlePackInfoInner"; +constexpr const char* CLASSNAME_PACKAGE_CONFIG_INNER = "bundleManager.BundlePackInfoInner.PackageConfigInner"; +constexpr const char* CLASSNAME_PACKAGE_SUMMARY = "bundleManager.BundlePackInfo.PackageSummary"; +constexpr const char* CLASSNAME_PACKAGE_SUMMARY_INNER = "bundleManager.BundlePackInfoInner.PackageSummaryInner"; +constexpr const char* CLASSNAME_BUNDLE_CONFIG_INFO = "bundleManager.BundlePackInfo.BundleConfigInfo"; +constexpr const char* CLASSNAME_BUNDLE_CONFIG_INFO_INNER = "bundleManager.BundlePackInfoInner.BundleConfigInfoInner"; +constexpr const char* CLASSNAME_EXTENSION_ABILITY_INNER = "bundleManager.BundlePackInfoInner.ExtensionAbilityInner"; +constexpr const char* CLASSNAME_MODULE_CONFIG_INFO_INNER = "bundleManager.BundlePackInfoInner.ModuleConfigInfoInner"; +constexpr const char* CLASSNAME_MODULE_DISTRO_INFO = "bundleManager.BundlePackInfo.ModuleDistroInfo"; +constexpr const char* CLASSNAME_MODULE_DISTRO_INFO_INNER = "bundleManager.BundlePackInfoInner.ModuleDistroInfoInner"; constexpr const char* CLASSNAME_MODULE_ABILITY_INFO_INNER = - "LbundleManager/BundlePackInfoInner/ModuleAbilityInfoInner;"; -constexpr const char* CLASSNAME_ABILITY_FORM_INFO_INNER = "LbundleManager/BundlePackInfoInner/AbilityFormInfoInner;"; -constexpr const char* CLASSNAME_VERSION_INNER = "LbundleManager/BundlePackInfoInner/VersionInner;"; -constexpr const char* CLASSNAME_API_VERSION_INNER = "LbundleManager/BundlePackInfoInner/ApiVersionInner;"; -constexpr const char* CLASSNAME_DISPATCH_INFO_INNER = "LbundleManager/DispatchInfoInner/DispatchInfoInner;"; -constexpr const char* CLASSNAME_OVERLAY_MOUDLE_INFO_INNER = - "LbundleManager/OverlayModuleInfoInner/OverlayModuleInfoInner;"; -constexpr const char* CLASSNAME_WANT = "L@ohos/app/ability/Want/Want;"; + "bundleManager.BundlePackInfoInner.ModuleAbilityInfoInner"; +constexpr const char* CLASSNAME_ABILITY_FORM_INFO_INNER = "bundleManager.BundlePackInfoInner.AbilityFormInfoInner"; +constexpr const char* CLASSNAME_VERSION = "bundleManager.BundlePackInfo.Version"; +constexpr const char* CLASSNAME_VERSION_INNER = "bundleManager.BundlePackInfoInner.VersionInner"; +constexpr const char* CLASSNAME_API_VERSION = "bundleManager.BundlePackInfo.ApiVersion"; +constexpr const char* CLASSNAME_API_VERSION_INNER = "bundleManager.BundlePackInfoInner.ApiVersionInner"; +constexpr const char* CLASSNAME_DISPATCH_INFO_INNER = "bundleManager.DispatchInfoInner.DispatchInfoInner"; +constexpr const char* CLASSNAME_OVERLAY_MODULE_INFO_INNER = + "bundleManager.OverlayModuleInfoInner.OverlayModuleInfoInner"; +constexpr const char* CLASSNAME_WANT = "@ohos.app.ability.Want.Want"; +constexpr const char* CLASSNAME_ZLIB_CHECKSUM_INTERNAL = "@ohos.zlib.zlib.ChecksumInternal"; +constexpr const char* CLASSNAME_ZLIB_GZIP_INTERNAL = "@ohos.zlib.zlib.GZipInternal"; +constexpr const char* CLASSNAME_DISPOSED_RULE_INNER = "@ohos.bundle.appControl.appControl.DisposedRuleInner"; +constexpr const char* CLASSNAME_DISPOSED_UNINSTALL_RULE_INNER = + "@ohos.bundle.appControl.appControl.UninstallDisposedRuleInner"; +constexpr const char* CLASSNAME_BUNDLE_RES_INFO_INNER = + "bundleManager.BundleResourceInfoInner.BundleResourceInfoInner"; +constexpr const char* CLASSNAME_LAUNCHER_ABILITY_RESOURCE_INFO_INNER = + "bundleManager.LauncherAbilityResourceInfoInner.LauncherAbilityResourceInfoInner"; constexpr const char* PROPERTYNAME_NAME = "name"; -constexpr const char* PROPERTYNAME_VENDOR = "vendor"; -constexpr const char* PROPERTYNAME_VERSIONCODE = "versionCode"; -constexpr const char* PROPERTYNAME_VERSIONNAME = "versionName"; -constexpr const char* PROPERTYNAME_MINCOMPATIBLEVERSIONCODE = "minCompatibleVersionCode"; -constexpr const char* PROPERTYNAME_TARGETVERSION = "targetVersion"; -constexpr const char* PROPERTYNAME_APPINFO = "appInfo"; -constexpr const char* PROPERTYNAME_HAPMODULESINFO = "hapModulesInfo"; -constexpr const char* PROPERTYNAME_REQPERMISSIONDETAILS = "reqPermissionDetails"; -constexpr const char* PROPERTYNAME_PERMISSIONGRANTSTATES = "permissionGrantStates"; -constexpr const char* PROPERTYNAME_SIGNATUREINFO = "signatureInfo"; -constexpr const char* PROPERTYNAME_INSTALLTIME = "installTime"; -constexpr const char* PROPERTYNAME_UPDATETIME = "updateTime"; -constexpr const char* PROPERTYNAME_FIRSTINSTALLTIME = "firstInstallTime"; -constexpr const char* PROPERTYNAME_ROUTERMAP = "routerMap"; -constexpr const char* PROPERTYNAME_APPINDEX = "appIndex"; +constexpr const char* PROPERTYNAME_VERSION_CODE = "versionCode"; +constexpr const char* PROPERTYNAME_APP_INDEX = "appIndex"; constexpr const char* PROPERTYNAME_KEY = "key"; constexpr const char* PROPERTYNAME_VALUE = "value"; -constexpr const char* PROPERTYNAME_RESOURCE = "resource"; -constexpr const char* PROPERTYNAME_VALUEID = "valueId"; -constexpr const char* PROPERTYNAME_MAXCOUNT = "maxCount"; -constexpr const char* PROPERTYNAME_MULTIAPPMODETYPE = "multiAppModeType"; -constexpr const char* PROPERTYNAME_MODULENAME = "moduleName"; -constexpr const char* PROPERTYNAME_METADATA = "metadata"; -constexpr const char* PROPERTYNAME_DESCRIPTION = "description"; -constexpr const char* PROPERTYNAME_DESCRIPTIONID = "descriptionId"; -constexpr const char* PROPERTYNAME_ENABLED = "enabled"; +constexpr const char* PROPERTYNAME_MODULE_NAME = "moduleName"; constexpr const char* PROPERTYNAME_LABEL = "label"; -constexpr const char* PROPERTYNAME_LABELID = "labelId"; +constexpr const char* PROPERTYNAME_LABEL_ID = "labelId"; constexpr const char* PROPERTYNAME_ICON = "icon"; -constexpr const char* PROPERTYNAME_ICONID = "iconId"; -constexpr const char* PROPERTYNAME_PROCESS = "process"; -constexpr const char* PROPERTYNAME_PERMISSIONS = "permissions"; -constexpr const char* PROPERTYNAME_CODEPATH = "codePath"; -constexpr const char* PROPERTYNAME_METADATAARRAY = "metadataArray"; -constexpr const char* PROPERTYNAME_REMOVABLE = "removable"; -constexpr const char* PROPERTYNAME_ACCESSTOKENID = "accessTokenId"; -constexpr const char* PROPERTYNAME_UID = "uid"; -constexpr const char* PROPERTYNAME_ICONRESOURCE = "iconResource"; -constexpr const char* PROPERTYNAME_LABELRESOURCE = "labelResource"; -constexpr const char* PROPERTYNAME_DESCRIPTIONRESOURCE = "descriptionResource"; -constexpr const char* PROPERTYNAME_APPDISTRIBUTIONTYPE = "appDistributionType"; -constexpr const char* PROPERTYNAME_APPPROVISIONTYPE = "appProvisionType"; -constexpr const char* PROPERTYNAME_SYSTEMAPP = "systemApp"; -constexpr const char* PROPERTYNAME_BUNDLETYPE = "bundleType"; -constexpr const char* PROPERTYNAME_DEBUG = "debug"; -constexpr const char* PROPERTYNAME_DATAUNCLEARABLE = "dataUnclearable"; -constexpr const char* PROPERTYNAME_NATIVELIBRARYPATH = "nativeLibraryPath"; -constexpr const char* PROPERTYNAME_MULTIAPPMODE = "multiAppMode"; -constexpr const char* PROPERTYNAME_INSTALLSOURCE = "installSource"; -constexpr const char* PROPERTYNAME_RELEASETYPE = "releaseType"; -constexpr const char* PROPERTYNAME_CLOUDFILESYNCENABLED = "cloudFileSyncEnabled"; -constexpr const char* PROPERTYNAME_CLOUDSTRUCTUREDDATASYNCENABLED = "cloudStructuredDataSyncEnabled"; -constexpr const char* PROPERTYNAME_FLAGS = "flags"; -constexpr const char* PROPERTYNAME_BUNDLENAME = "bundleName"; -constexpr const char* PROPERTYNAME_EXPORTED = "exported"; -constexpr const char* PROPERTYNAME_TYPE = "type"; -constexpr const char* PROPERTYNAME_ORIENTATION = "orientation"; -constexpr const char* PROPERTYNAME_LAUNCHTYPE = "launchType"; -constexpr const char* PROPERTYNAME_READPERMISSION = "readPermission"; -constexpr const char* PROPERTYNAME_WRITEPERMISSION = "writePermission"; -constexpr const char* PROPERTYNAME_URI = "uri"; -constexpr const char* PROPERTYNAME_DEVICETYPES = "deviceTypes"; -constexpr const char* PROPERTYNAME_APPLICATIONINFO = "applicationInfo"; -constexpr const char* PROPERTYNAME_SUPPORTWINDOWMODES = "supportWindowModes"; -constexpr const char* PROPERTYNAME_WINDOWSIZE = "windowSize"; -constexpr const char* PROPERTYNAME_EXCLUDEFROMDOCK = "excludeFromDock"; -constexpr const char* PROPERTYNAME_SKILLS = "skills"; -constexpr const char* PROPERTYNAME_ORIENTATIONID = "orientationId"; -constexpr const char* PROPERTYNAME_MAXWINDOWRATIO = "maxWindowRatio"; -constexpr const char* PROPERTYNAME_MINWINDOWRATIO = "minWindowRatio"; -constexpr const char* PROPERTYNAME_MAXWINDOWWIDTH = "maxWindowWidth"; -constexpr const char* PROPERTYNAME_MINWINDOWWIDTH = "minWindowWidth"; -constexpr const char* PROPERTYNAME_MAXWINDOWHEIGHT = "maxWindowHeight"; -constexpr const char* PROPERTYNAME_MINWINDOWHEIGHT = "minWindowHeight"; -constexpr const char* PROPERTYNAME_EXTENSIONABILITYTYPE = "extensionAbilityType"; -constexpr const char* PROPERTYNAME_EXTENSIONABILITYTYPENAME = "extensionAbilityTypeName"; +constexpr const char* PROPERTYNAME_ICON_ID = "iconId"; +constexpr const char* PROPERTYNAME_BUNDLE_NAME = "bundleName"; constexpr const char* PROPERTYNAME_ID = "id"; -constexpr const char* PROPERTYNAME_APPID = "appId"; -constexpr const char* PROPERTYNAME_FINGERPRINT = "fingerprint"; -constexpr const char* PROPERTYNAME_APPIDENTIFIER = "appIdentifier"; -constexpr const char* PROPERTYNAME_CERTIFICATE = "certificate"; -constexpr const char* PROPERTYNAME_PAGESOURCEFILE = "pageSourceFile"; -constexpr const char* PROPERTYNAME_BUILDFUNCTION = "buildFunction"; -constexpr const char* PROPERTYNAME_CUSTOMDATA = "customData"; -constexpr const char* PROPERTYNAME_DATA = "data"; -constexpr const char* PROPERTYNAME_REASON = "reason"; -constexpr const char* PROPERTYNAME_REASONID = "reasonId"; -constexpr const char* PROPERTYNAME_USEDSCENE = "usedScene"; -constexpr const char* PROPERTYNAME_WHEN = "when"; -constexpr const char* PROPERTYNAME_ABILITIES = "abilities"; -constexpr const char* PROPERTYNAME_MAINELEMENTNAME = "mainElementName"; -constexpr const char* PROPERTYNAME_ABILITIESINFO = "abilitiesInfo"; -constexpr const char* PROPERTYNAME_EXTENSIONABILITIESINFO = "extensionAbilitiesInfo"; -constexpr const char* PROPERTYNAME_INSTALLATIONFREE = "installationFree"; -constexpr const char* PROPERTYNAME_HASHVALUE = "hashValue"; -constexpr const char* PROPERTYNAME_DEPENDENCIES = "dependencies"; -constexpr const char* PROPERTYNAME_PRELOADS = "preloads"; -constexpr const char* PROPERTYNAME_FILECONTEXTMENUCONFIG = "fileContextMenuConfig"; -constexpr const char* PROPERTYNAME_DEVICEID = "deviceId"; -constexpr const char* PROPERTYNAME_ABILITYNAME = "abilityName"; -constexpr const char* PROPERTYNAME_SHORTNAME = "shortName"; -constexpr const char* PROPERTYNAME_SCHEME = "scheme"; -constexpr const char* PROPERTYNAME_HOST = "host"; -constexpr const char* PROPERTYNAME_PORT = "port"; -constexpr const char* PROPERTYNAME_PATH = "path"; -constexpr const char* PROPERTYNAME_PATHSTARTWITH = "pathStartWith"; -constexpr const char* PROPERTYNAME_PATHREGEX = "pathRegex"; -constexpr const char* PROPERTYNAME_UTD = "utd"; -constexpr const char* PROPERTYNAME_MAXFILESUPPORTED = "maxFileSupported"; -constexpr const char* PROPERTYNAME_LINKFEATURE = "linkFeature"; -constexpr const char* PROPERTYNAME_ACTIONS = "actions"; +constexpr const char* PROPERTYNAME_HASH_VALUE = "hashValue"; +constexpr const char* PROPERTYNAME_DEVICE_ID = "deviceId"; +constexpr const char* PROPERTYNAME_ABILITY_NAME = "abilityName"; constexpr const char* PROPERTYNAME_ENTITIES = "entities"; -constexpr const char* PROPERTYNAME_URIS = "uris"; -constexpr const char* PROPERTYNAME_DOMAINVERIFY = "domainVerify"; -constexpr const char* PROPERTYNAME_HOSTABILITY = "hostAbility"; +constexpr const char* PROPERTYNAME_HOST_ABILITY = "hostAbility"; constexpr const char* PROPERTYNAME_WANTS = "wants"; -constexpr const char* PROPERTYNAME_SOURCETYPE = "sourceType"; -constexpr const char* PROPERTYNAME_TARGETBUNDLE = "targetBundle"; -constexpr const char* PROPERTYNAME_TARGETMODULE = "targetModule"; -constexpr const char* PROPERTYNAME_TARGETABILITY = "targetAbility"; +constexpr const char* PROPERTYNAME_SOURCE_TYPE = "sourceType"; +constexpr const char* PROPERTYNAME_TARGET_BUNDLE = "targetBundle"; +constexpr const char* PROPERTYNAME_TARGET_MODULE = "targetModule"; +constexpr const char* PROPERTYNAME_TARGET_ABILITY = "targetAbility"; constexpr const char* PROPERTYNAME_PARAMETERS = "parameters"; -constexpr const char* PROPERTYNAME_ELEMENTNAME = "elementName"; -constexpr const char* PROPERTYNAME_USERID = "userId"; -constexpr const char* PROPERTYNAME_HASHPARAMS = "hashParams"; -constexpr const char* PROPERTYNAME_PGOFILEPATH = "pgoFilePath"; -constexpr const char* PROPERTYNAME_PGOPARAMS = "pgoParams"; -constexpr const char* PROPERTYNAME_SPECIFIEDDISTRIBUTIONTYPE = "specifiedDistributionType"; -constexpr const char* PROPERTYNAME_ISKEEPDATA = "isKeepData"; -constexpr const char* PROPERTYNAME_INSTALLFLAG = "installFlag"; -constexpr const char* PROPERTYNAME_CROWDTESTDEADLINE = "crowdtestDeadline"; -constexpr const char* PROPERTYNAME_SHAREDBUNDLEDIRPATHS = "sharedBundleDirPaths"; -constexpr const char* PROPERTYNAME_ADDITIONALINFO = "additionalInfo"; -constexpr const char* PROPERTYNAME_CODE = "code"; -constexpr const char* PROPERTYNAME_VERSION = "version"; -constexpr const char* PROPERTYNAME_UPDATEENABLED = "updateEnabled"; -constexpr const char* PROPERTYNAME_SCHEDULEDUPDATETIME = "scheduledUpdateTime"; -constexpr const char* PROPERTYNAME_UPDATEDURATION = "updateDuration"; -constexpr const char* PROPERTYNAME_SUPPORTDIMENSIONS = "supportDimensions"; -constexpr const char* PROPERTYNAME_DEFAULTDIMENSION = "defaultDimension"; -constexpr const char* PROPERTYNAME_FORMS = "forms"; -constexpr const char* PROPERTYNAME_DELIVERYWITHINSTALL = "deliveryWithInstall"; -constexpr const char* PROPERTYNAME_MODULETYPE = "moduleType"; -constexpr const char* PROPERTYNAME_COMPATIBLE = "compatible"; -constexpr const char* PROPERTYNAME_TARGET = "target"; -constexpr const char* PROPERTYNAME_MAINABILITY = "mainAbility"; -constexpr const char* PROPERTYNAME_APIVERSION = "apiVersion"; -constexpr const char* PROPERTYNAME_DISTRO = "distro"; -constexpr const char* PROPERTYNAME_EXTENSIONABILITIES = "extensionAbilities"; -constexpr const char* PROPERTYNAME_APP = "app"; -constexpr const char* PROPERTYNAME_MODULES = "modules"; -constexpr const char* PROPERTYNAME_PACKAGES = "packages"; -constexpr const char* PROPERTYNAME_SUMMARY = "summary"; -constexpr const char* PROPERTYNAME_DISPATCHAPIVERSION = "dispatchAPIVersion"; -constexpr const char* PROPERTYNAME_TARGETMOUDLENAME = "targetModuleName"; -constexpr const char* PROPERTYNAME_PRIORITY = "priority"; -constexpr const char* PROPERTYNAME_STATE = "state"; +constexpr const char* PROPERTYNAME_USER_ID = "userId"; +constexpr const char* PROPERTYNAME_HASH_PARAMS = "hashParams"; +constexpr const char* PROPERTYNAME_PGO_FILE_PATH = "pgoFilePath"; +constexpr const char* PROPERTYNAME_PGO_PARAMS = "pgoParams"; +constexpr const char* PROPERTYNAME_SPECIFIED_DISTRIBUTION_TYPE = "specifiedDistributionType"; +constexpr const char* PROPERTYNAME_IS_KEEP_DATA = "isKeepData"; +constexpr const char* PROPERTYNAME_INSTALL_FLAG = "installFlag"; +constexpr const char* PROPERTYNAME_CROWD_TEST_DEADLINE = "crowdtestDeadline"; +constexpr const char* PROPERTYNAME_SHARED_BUNDLE_DIR_PATHS = "sharedBundleDirPaths"; +constexpr const char* PROPERTYNAME_ADDITIONAL_INFO = "additionalInfo"; constexpr const char* PROPERTYNAME_VISIBLE = "visible"; constexpr const char* PROPERTYNAME_ACTION = "action"; @@ -236,6 +146,119 @@ constexpr const char* PATH_PREFIX = "/data/app/el1/bundle/public"; constexpr const char* CODE_PATH_PREFIX = "/data/storage/el1/bundle/"; constexpr const char* CONTEXT_DATA_STORAGE_BUNDLE = "/data/storage/el1/bundle/"; constexpr int32_t ILLEGAL_APP_INDEX = -1; + +struct ANIClassCacheItem { + ani_ref classRef = nullptr; + std::map classMethodMap; +}; +static std::mutex g_aniClassCacherMutex; +static std::map g_aniClassCache = { + { CommonFunAniNS::CLASSNAME_BOOLEAN, { } }, + { CommonFunAniNS::CLASSNAME_INT, { } }, + { CommonFunAniNS::CLASSNAME_LONG, { } }, + { CommonFunAniNS::CLASSNAME_DOUBLE, { } }, + { CommonFunAniNS::CLASSNAME_ARRAY, { } }, + { CLASSNAME_BUNDLE_INFO_INNER, { } }, + { CLASSNAME_APPLICATION_INFO_INNER, { } }, + { CLASSNAME_MODULE_METADATA_INNER, { } }, + { CLASSNAME_METADATA_INNER, { } }, + { CLASSNAME_RESOURCE_INNER, { } }, + { CLASSNAME_MULTI_APP_MODE_INNER, { } }, + { CLASSNAME_HAP_MODULE_INFO_INNER, { } }, + { CLASSNAME_ABILITY_INFO_INNER, { } }, + { CLASSNAME_SKILL_INNER, { } }, + { CLASSNAME_WINDOW_SIZE_INNER, { } }, + { CLASSNAME_EXTENSION_ABILITY_INFO_INNER, { } }, + { CLASSNAME_DEPENDENCY_INNER, { } }, + { CLASSNAME_PRELOAD_ITEM_INNER, { } }, + { CLASSNAME_ROUTER_ITEM_INNER, { } }, + { CLASSNAME_DATA_ITEM_INNER, { } }, + { CLASSNAME_APP_PROVISION_INFO_INNER, { } }, + { CLASSNAME_ZLIB_CHECKSUM_INTERNAL, { } }, + { CLASSNAME_ZLIB_GZIP_INTERNAL, { } }, + { CLASSNAME_DISPOSED_RULE_INNER, { } }, + { CLASSNAME_DISPOSED_UNINSTALL_RULE_INNER, { } }, + { CLASSNAME_BUNDLE_RES_INFO_INNER, { } }, + { CLASSNAME_LAUNCHER_ABILITY_RESOURCE_INFO_INNER, { } }, +}; + +static ani_class GetCacheClass(ani_env* env, const std::string& className) +{ + RETURN_NULL_IF_NULL(env); + + std::lock_guard lock(g_aniClassCacherMutex); + auto iter = g_aniClassCache.find(className); + if (iter == g_aniClassCache.end()) { + return nullptr; + } + if (iter->second.classRef != nullptr) { + return reinterpret_cast(iter->second.classRef); + } + + ani_class cls = nullptr; + ani_status status = env->FindClass(className.c_str(), &cls); + if (status != ANI_OK) { + APP_LOGE("FindClass %{public}s failed %{public}d", className.c_str(), status); + return nullptr; + } + ani_ref ref = nullptr; + status = env->GlobalReference_Create(cls, &ref); + if (status == ANI_OK) { + iter->second.classRef = ref; + } + + return cls; +} + +static ani_method GetCacheCtorMethod(ani_env* env, const std::string& className, ani_class cls, + const std::string& ctorSig = Builder::BuildSignatureDescriptor({})) +{ + RETURN_NULL_IF_NULL(env); + RETURN_NULL_IF_NULL(cls); + + std::lock_guard lock(g_aniClassCacherMutex); + auto iter = g_aniClassCache.find(className); + if (iter == g_aniClassCache.end()) { + return nullptr; + } + + auto iterMethod = iter->second.classMethodMap.find(ctorSig); + if (iterMethod != iter->second.classMethodMap.end() && iterMethod->second != nullptr) { + return iterMethod->second; + } + + ani_method method = nullptr; + ani_status status = + env->Class_FindMethod(cls, Builder::BuildConstructorName().c_str(), ctorSig.c_str(), &method); + if (status != ANI_OK) { + APP_LOGE("Class_FindMethod ctorSig %{public}s failed %{public}d", ctorSig.c_str(), status); + return nullptr; + } + iter->second.classMethodMap[ctorSig] = method; + + return method; +} + +static ani_method GetCtorMethod(ani_env* env, const std::string& className, ani_class cls, + const std::string& ctorSig = Builder::BuildSignatureDescriptor({})) +{ + RETURN_NULL_IF_NULL(env); + RETURN_NULL_IF_NULL(cls); + + ani_method method = GetCacheCtorMethod(env, className, cls, ctorSig); + if (method != nullptr) { + return method; + } + + ani_status status = + env->Class_FindMethod(cls, Builder::BuildConstructorName().c_str(), ctorSig.c_str(), &method); + if (status != ANI_OK) { + APP_LOGE("Class_FindMethod ctorSig %{public}s failed %{public}d", ctorSig.c_str(), status); + return nullptr; + } + + return method; +} } // namespace std::string CommonFunAni::AniStrToString(ani_env* env, ani_string aniStr) @@ -256,7 +279,7 @@ std::string CommonFunAni::AniStrToString(ani_env* env, ani_string aniStr) buffer.resize(strSize + 1); ani_size retSize = 0; status = env->String_GetUTF8(aniStr, buffer.data(), buffer.size(), &retSize); - if (status != ANI_OK || retSize == 0) { + if (status != ANI_OK) { APP_LOGE("String_GetUTF8SubString failed %{public}d", status); return ""; } @@ -293,28 +316,28 @@ ani_class CommonFunAni::CreateClassByName(ani_env* env, const std::string& class { RETURN_NULL_IF_NULL(env); - ani_class cls = nullptr; - ani_status status = env->FindClass(className.c_str(), &cls); - if (status != ANI_OK) { - APP_LOGE("FindClass failed %{public}d", status); - return nullptr; + ani_class cls = GetCacheClass(env, className); + if (cls == nullptr) { + ani_status status = env->FindClass(className.c_str(), &cls); + if (status != ANI_OK) { + APP_LOGE("FindClass %{public}s failed %{public}d", className.c_str(), status); + return nullptr; + } } + return cls; } -ani_object CommonFunAni::CreateNewObjectByClass(ani_env* env, ani_class cls) +ani_object CommonFunAni::CreateNewObjectByClass(ani_env* env, const std::string& className, ani_class cls) { RETURN_NULL_IF_NULL(env); + RETURN_NULL_IF_NULL(cls); - ani_method method = nullptr; - ani_status status = env->Class_FindMethod(cls, "", ":V", &method); - if (status != ANI_OK) { - APP_LOGE("Class_FindMethod failed %{public}d", status); - return nullptr; - } + ani_method method = GetCtorMethod(env, className, cls); + RETURN_NULL_IF_NULL(method); ani_object object = nullptr; - status = env->Object_New(cls, method, &object); + ani_status status = env->Object_New(cls, method, &object); if (status != ANI_OK) { APP_LOGE("Object_New failed %{public}d", status); return nullptr; @@ -322,147 +345,315 @@ ani_object CommonFunAni::CreateNewObjectByClass(ani_env* env, ani_class cls) return object; } -ani_object CommonFunAni::ConvertBundleInfo(ani_env* env, const BundleInfo& bundleInfo, int32_t flags) +ani_object CommonFunAni::CreateNewObjectByClassV2( + ani_env* env, const std::string& className, const std::string& ctorSig, const ani_value* args) { RETURN_NULL_IF_NULL(env); + RETURN_NULL_IF_NULL(args); - ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLEINFO); + ani_class cls = CreateClassByName(env, className); RETURN_NULL_IF_NULL(cls); - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); + ani_method method = GetCtorMethod(env, className, cls, ctorSig); + RETURN_NULL_IF_NULL(method); + ani_object object = nullptr; + ani_status status = env->Object_New_A(cls, method, &object, args); + if (status != ANI_OK) { + APP_LOGE("Object_New_A failed %{public}d", status); + return nullptr; + } + return object; +} - ani_string string = nullptr; +ani_object CommonFunAni::ConvertBundleInfo(ani_env* env, const BundleInfo& bundleInfo, int32_t flags) +{ + RETURN_NULL_IF_NULL(env); // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleInfo.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleInfo.name, name)); // vendor: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleInfo.vendor, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VENDOR, string)); - - // versionCode: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONCODE, bundleInfo.versionCode)); + ani_string vendor = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleInfo.vendor, vendor)); // versionName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleInfo.versionName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONNAME, string)); - - // minCompatibleVersionCode: number - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_MINCOMPATIBLEVERSIONCODE, bundleInfo.minCompatibleVersionCode)); - - // targetVersion: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TARGETVERSION, bundleInfo.targetVersion)); + ani_string versionName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleInfo.versionName, versionName)); // appInfo: ApplicationInfo + ani_ref appInfo = nullptr; if ((static_cast(flags) & static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)) == static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)) { - ani_object aObject = ConvertApplicationInfo(env, bundleInfo.applicationInfo); - RETURN_NULL_IF_NULL(aObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINFO, aObject)); + appInfo = ConvertApplicationInfo(env, bundleInfo.applicationInfo); } else { - RETURN_NULL_IF_FALSE(CallSetterNull(env, cls, object, PROPERTYNAME_APPINFO)); + ani_status status = env->GetNull(&appInfo); + if (status != ANI_OK) { + APP_LOGE("GetNull appInfo failed %{public}d", status); + return nullptr; + } } + RETURN_NULL_IF_NULL(appInfo); // hapModulesInfo: Array - ani_object aHapModuleInfosObject = ConvertAniArray(env, bundleInfo.hapModuleInfos, ConvertHapModuleInfo); - RETURN_NULL_IF_NULL(aHapModuleInfosObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_HAPMODULESINFO, aHapModuleInfosObject)); + ani_object hapModulesInfo = ConvertAniArray(env, bundleInfo.hapModuleInfos, ConvertHapModuleInfo); + RETURN_NULL_IF_NULL(hapModulesInfo); // reqPermissionDetails: Array - ani_object aPermissionArrayObject = ConvertAniArray(env, bundleInfo.reqPermissionDetails, ConvertRequestPermission); - RETURN_NULL_IF_NULL(aPermissionArrayObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_REQPERMISSIONDETAILS, aPermissionArrayObject)); + ani_object reqPermissionDetails = ConvertAniArray(env, bundleInfo.reqPermissionDetails, ConvertRequestPermission); + RETURN_NULL_IF_NULL(reqPermissionDetails); // permissionGrantStates: Array - ani_object aPermissionGrantStates = ConvertAniArrayEnum( + ani_object permissionGrantStates = ConvertAniArrayEnum( env, bundleInfo.reqPermissionStates, EnumUtils::EnumNativeToETS_BundleManager_PermissionGrantState); - RETURN_NULL_IF_NULL(aPermissionGrantStates); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PERMISSIONGRANTSTATES, aPermissionGrantStates)); + RETURN_NULL_IF_NULL(permissionGrantStates); // signatureInfo: SignatureInfo + ani_ref signatureInfo = nullptr; if ((static_cast(flags) & static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)) == static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)) { - ani_object aniSignatureInfoObj = ConvertSignatureInfo(env, bundleInfo.signatureInfo); - RETURN_NULL_IF_NULL(aniSignatureInfoObj); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SIGNATUREINFO, aniSignatureInfoObj)); + signatureInfo = ConvertSignatureInfo(env, bundleInfo.signatureInfo); } else { - RETURN_NULL_IF_FALSE(CallSetterNull(env, cls, object, PROPERTYNAME_SIGNATUREINFO)); + ani_status status = env->GetNull(&signatureInfo); + if (status != ANI_OK) { + APP_LOGE("GetNull signatureInfo failed %{public}d", status); + return nullptr; + } } + RETURN_NULL_IF_NULL(signatureInfo); - // installTime: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_INSTALLTIME, bundleInfo.installTime)); + // routerMap: Array + ani_object routerMap = ConvertAniArray(env, bundleInfo.routerArray, ConvertRouterItem); + RETURN_NULL_IF_NULL(routerMap); + + // firstInstallTime?: long + ani_object firstInstallTime = BoxValue(env, bundleInfo.firstInstallTime); + RETURN_NULL_IF_FALSE(firstInstallTime); + + ani_value args[] = { + { .r = name }, + { .r = vendor }, + { .l = static_cast(bundleInfo.versionCode) }, + { .r = versionName }, + { .i = static_cast(bundleInfo.minCompatibleVersionCode) }, + { .i = static_cast(bundleInfo.targetVersion) }, + { .r = appInfo }, + { .r = hapModulesInfo }, + { .r = reqPermissionDetails }, + { .r = permissionGrantStates }, + { .r = signatureInfo }, + { .l = bundleInfo.installTime }, + { .l = bundleInfo.updateTime }, + { .r = routerMap }, + { .i = bundleInfo.appIndex }, + { .r = firstInstallTime }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // vendor: string + .AddLong() // versionCode: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // versionName: string + .AddInt() // minCompatibleVersionCode: int + .AddInt() // targetVersion: int + .AddClass(CLASSNAME_APPLICATION_INFO) // appInfo: ApplicationInfo + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // hapModulesInfo: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // reqPermissionDetails: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // permissionGrantStates: Array + .AddClass(CLASSNAME_SIGNATURE_INFO) // signatureInfo: SignatureInfo + .AddLong() // installTime: long + .AddLong() // updateTime: long + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // routerMap: Array + .AddInt() // appIndex: int + .AddClass(CommonFunAniNS::CLASSNAME_LONG) // firstInstallTime?: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_INFO_INNER, ctorSig, args); +} - // updateTime: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_UPDATETIME, bundleInfo.updateTime)); +ani_object CommonFunAni::ConvertDefaultAppAbilityInfo(ani_env* env, const AbilityInfo& abilityInfo) +{ + RETURN_NULL_IF_NULL(env); - // routerMap: Array - ani_object aRouterMapObject = ConvertAniArray(env, bundleInfo.routerArray, ConvertRouterItem); - RETURN_NULL_IF_NULL(aRouterMapObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ROUTERMAP, aRouterMapObject)); + // bundleName: string + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.bundleName, bundleName)); - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, bundleInfo.appIndex)); + // moduleName: string + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.moduleName, moduleName)); - // firstInstallTime?: number - RETURN_NULL_IF_FALSE( - CallSetterOptional(env, cls, object, PROPERTYNAME_FIRSTINSTALLTIME, bundleInfo.firstInstallTime)); + // name: string + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.name, name)); - return object; + // label: string + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.label, label)); + + // description: string + ani_string description = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.description, description)); + + // icon: string + ani_string icon = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.iconPath, icon)); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .r = name }, + { .r = label }, + { .l = static_cast(abilityInfo.labelId) }, + { .r = description }, + { .l = static_cast(abilityInfo.descriptionId) }, + { .r = icon }, + { .l = static_cast(abilityInfo.iconId) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label: string + .AddLong() // labelId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // description: string + .AddLong() // descriptionId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // icon: string + .AddLong() // iconId: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_ABILITY_INFO_INNER, ctorSig, args); } -ani_object CommonFunAni::ConvertMetadata(ani_env* env, const Metadata& metadata) +ani_object CommonFunAni::ConvertDefaultAppExtensionInfo(ani_env* env, const ExtensionAbilityInfo& extensionInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_METADATA); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); + // bundleName: string + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.bundleName, bundleName)); - ani_string string = nullptr; + // moduleName: string + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.moduleName, moduleName)); // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.name, name)); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .r = name }, + { .l = static_cast(extensionInfo.labelId) }, + { .l = static_cast(extensionInfo.descriptionId) }, + { .l = static_cast(extensionInfo.iconId) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddLong() // labelId: long + .AddLong() // descriptionId: long + .AddLong() // iconId: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_EXTENSION_ABILITY_INFO_INNER, ctorSig, args); +} - // value: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.value, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VALUE, string)); +ani_object CommonFunAni::ConvertDefaultAppHapModuleInfo(ani_env* env, const BundleInfo& bundleInfo) +{ + RETURN_NULL_IF_NULL(env); - // resource: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.resource, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_RESOURCE, string)); + // abilitiesInfo: Array + ani_object abilitiesInfo = ConvertAniArray(env, bundleInfo.abilityInfos, ConvertDefaultAppAbilityInfo); + RETURN_NULL_IF_NULL(abilitiesInfo); - // valueId?: number - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_VALUEID, metadata.valueId)); + // extensionAbilitiesInfo: Array + ani_object extensionAbilitiesInfo = ConvertAniArray(env, bundleInfo.extensionInfos, ConvertDefaultAppExtensionInfo); + RETURN_NULL_IF_NULL(extensionAbilitiesInfo); + + ani_value args[] = { + { .r = abilitiesInfo }, + { .r = extensionAbilitiesInfo }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // abilitiesInfo: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // extensionAbilitiesInfo: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_HAP_MODULE_INFO_INNER, ctorSig, args); +} - return object; +ani_object CommonFunAni::ConvertDefaultAppBundleInfo(ani_env* env, const BundleInfo& bundleInfo) +{ + RETURN_NULL_IF_NULL(env); + + // name: string + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleInfo.name, name)); + + // hapModulesInfo: Array + std::vector bundleInfos = { bundleInfo }; + ani_object hapModulesInfo = ConvertAniArray(env, bundleInfos, ConvertDefaultAppHapModuleInfo); + RETURN_NULL_IF_NULL(hapModulesInfo); + + ani_value args[] = { + { .r = name }, + { .r = hapModulesInfo }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // hapModulesInfo: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_INFO_INNER, ctorSig, args); } -ani_object CommonFunAni::ConvertMultiAppMode(ani_env* env, const MultiAppModeData& multiAppMode) +ani_object CommonFunAni::ConvertMetadata(ani_env* env, const Metadata& metadata) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_MULTIAPPMODE); - RETURN_NULL_IF_NULL(cls); + // name: string + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.name, name)); - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); + // value: string + ani_string value = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.value, value)); - // maxCount: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAXCOUNT, multiAppMode.maxCount)); + // resource: string + ani_string resource = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.resource, resource)); + + // valueId?: long + ani_object valueId = BoxValue(env, static_cast(metadata.valueId)); + RETURN_NULL_IF_NULL(valueId); + + ani_value args[] = { + { .r = name }, + { .r = value }, + { .r = resource }, + { .r = valueId }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // value: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // resource: string + .AddClass(CommonFunAniNS::CLASSNAME_LONG) // valueId?: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_METADATA_INNER, ctorSig, args); +} - // multiAppModeType: bundleManager.MultiAppModeType - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MULTIAPPMODETYPE, - EnumUtils::EnumNativeToETS_BundleManager_MultiAppModeType( - env, static_cast(multiAppMode.multiAppModeType)))); +ani_object CommonFunAni::ConvertMultiAppMode(ani_env* env, const MultiAppModeData& multiAppMode) +{ + RETURN_NULL_IF_NULL(env); - return object; + ani_value args[] = { + { .r = EnumUtils::EnumNativeToETS_BundleManager_MultiAppModeType( + env, static_cast(multiAppMode.multiAppModeType)) }, + { .i = multiAppMode.maxCount }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_MULTI_APP_MODE_TYPE) // multiAppModeType + .AddInt() // maxCount: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_MULTI_APP_MODE_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertModuleMetaInfosItem( @@ -470,424 +661,448 @@ ani_object CommonFunAni::ConvertModuleMetaInfosItem( { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_MODULEMETADATA); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, item.first, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, item.first, moduleName)); // metadata: Array - ani_object aMetadataObject = ConvertAniArray(env, item.second, ConvertMetadata); - RETURN_NULL_IF_NULL(aMetadataObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_METADATA, aMetadataObject)); - - return object; + ani_object metadata = ConvertAniArray(env, item.second, ConvertMetadata); + RETURN_NULL_IF_NULL(metadata); + + ani_value args[] = { + { .r = moduleName }, + { .r = metadata }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // metadata: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_MODULE_METADATA_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertApplicationInfo(ani_env* env, const ApplicationInfo& appInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_APPLICATIONINFO); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.name, name)); // description: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.description, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTION, string)); - - // descriptionId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, appInfo.descriptionId)); - - // enabled: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ENABLED, BoolToAniBoolean(appInfo.enabled))); + ani_string description = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.description, description)); // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.label, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); - - // labelId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, appInfo.labelId)); + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.label, label)); // icon: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.iconPath, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); - - // iconId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, appInfo.iconId)); + ani_string icon = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.iconPath, icon)); // process: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.process, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PROCESS, string)); + ani_string process = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.process, process)); // permissions: Array - ani_ref aPermissions = ConvertAniArrayString(env, appInfo.permissions); - RETURN_NULL_IF_NULL(aPermissions); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PERMISSIONS, aPermissions)); + ani_ref permissions = ConvertAniArrayString(env, appInfo.permissions); + RETURN_NULL_IF_NULL(permissions); // codePath: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.codePath, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_CODEPATH, string)); + ani_string codePath = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.codePath, codePath)); // metadataArray: Array - ani_object aMetadataArrayObject = ConvertAniArray(env, appInfo.metadata, ConvertModuleMetaInfosItem); - RETURN_NULL_IF_NULL(aMetadataArrayObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_METADATAARRAY, aMetadataArrayObject)); - - // removable: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_REMOVABLE, BoolToAniBoolean(appInfo.removable))); - - // accessTokenId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ACCESSTOKENID, appInfo.accessTokenId)); - - // uid: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_UID, appInfo.uid)); + ani_object metadataArray = ConvertAniArray(env, appInfo.metadata, ConvertModuleMetaInfosItem); + RETURN_NULL_IF_NULL(metadataArray); // iconResource: Resource - ani_object aIconResource = ConvertResource(env, appInfo.iconResource); - RETURN_NULL_IF_NULL(aIconResource); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONRESOURCE, aIconResource)); + ani_object iconResource = ConvertResource(env, appInfo.iconResource); + RETURN_NULL_IF_NULL(iconResource); // labelResource: Resource - ani_object aLabelResource = ConvertResource(env, appInfo.labelResource); - RETURN_NULL_IF_NULL(aLabelResource); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELRESOURCE, aLabelResource)); + ani_object labelResource = ConvertResource(env, appInfo.labelResource); + RETURN_NULL_IF_NULL(labelResource); // descriptionResource: Resource - ani_object aDescriptionResource = ConvertResource(env, appInfo.descriptionResource); - RETURN_NULL_IF_NULL(aDescriptionResource); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONRESOURCE, aDescriptionResource)); + ani_object descriptionResource = ConvertResource(env, appInfo.descriptionResource); + RETURN_NULL_IF_NULL(descriptionResource); // appDistributionType: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.appDistributionType, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPDISTRIBUTIONTYPE, string)); + ani_string appDistributionType = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.appDistributionType, appDistributionType)); // appProvisionType: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.appProvisionType, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPPROVISIONTYPE, string)); - - // systemApp: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SYSTEMAPP, BoolToAniBoolean(appInfo.isSystemApp))); - - // bundleType: bundleManager.BundleType - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLETYPE, - EnumUtils::EnumNativeToETS_BundleManager_BundleType(env, static_cast(appInfo.bundleType)))); - - // debug: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DEBUG, BoolToAniBoolean(appInfo.debug))); - - // dataUnclearable: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_DATAUNCLEARABLE, BoolToAniBoolean(!appInfo.userDataClearable))); + ani_string appProvisionType = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.appProvisionType, appProvisionType)); // nativeLibraryPath: string + ani_string nativeLibraryPath = nullptr; std::string externalNativeLibraryPath = ""; if (!appInfo.nativeLibraryPath.empty()) { externalNativeLibraryPath = CONTEXT_DATA_STORAGE_BUNDLE + appInfo.nativeLibraryPath; } - RETURN_NULL_IF_FALSE(StringToAniStr(env, externalNativeLibraryPath, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NATIVELIBRARYPATH, string)); + RETURN_NULL_IF_FALSE(StringToAniStr(env, externalNativeLibraryPath, nativeLibraryPath)); // multiAppMode: MultiAppMode - ani_object aniMultiAppModeObj = ConvertMultiAppMode(env, appInfo.multiAppMode); - RETURN_NULL_IF_NULL(aniMultiAppModeObj); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MULTIAPPMODE, aniMultiAppModeObj)); - - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, appInfo.appIndex)); + ani_object multiAppMode = ConvertMultiAppMode(env, appInfo.multiAppMode); + RETURN_NULL_IF_NULL(multiAppMode); // installSource: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.installSource, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_INSTALLSOURCE, string)); + ani_string installSource = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.installSource, installSource)); // releaseType: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.apiReleaseType, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_RELEASETYPE, string)); - - // cloudFileSyncEnabled: boolean - RETURN_NULL_IF_FALSE(CallSetter( - env, cls, object, PROPERTYNAME_CLOUDFILESYNCENABLED, BoolToAniBoolean(appInfo.cloudFileSyncEnabled))); + ani_string releaseType = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.apiReleaseType, releaseType)); // cloudStructuredDataSyncEnabled?: boolean - RETURN_NULL_IF_FALSE(CallSetterOptional( - env, cls, object, PROPERTYNAME_CLOUDSTRUCTUREDDATASYNCENABLED, - BoolToAniBoolean(appInfo.cloudStructuredDataSyncEnabled))); - - // flags?: number - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_FLAGS, appInfo.applicationFlags)); - - return object; + ani_object cloudStructuredDataSyncEnabled = BoxValue(env, + BoolToAniBoolean(appInfo.cloudStructuredDataSyncEnabled)); + RETURN_NULL_IF_NULL(cloudStructuredDataSyncEnabled); + + // flags?: int + ani_object flags = BoxValue(env, appInfo.applicationFlags); + RETURN_NULL_IF_NULL(flags); + + ani_value args[] = { + { .r = name }, + { .r = description }, + { .l = static_cast(appInfo.descriptionId) }, + { .z = BoolToAniBoolean(appInfo.enabled) }, + { .r = label }, + { .l = static_cast(appInfo.labelId) }, + { .r = icon }, + { .l = static_cast(appInfo.iconId) }, + { .r = process }, + { .r = permissions }, + { .r = codePath }, + { .r = metadataArray }, + { .z = BoolToAniBoolean(appInfo.removable) }, + { .l = static_cast(appInfo.accessTokenId) }, + { .i = appInfo.uid }, + { .r = iconResource }, + { .r = labelResource }, + { .r = descriptionResource }, + { .r = appDistributionType }, + { .r = appProvisionType }, + { .z = BoolToAniBoolean(appInfo.isSystemApp) }, + { .r = EnumUtils::EnumNativeToETS_BundleManager_BundleType(env, static_cast(appInfo.bundleType)) }, + { .z = BoolToAniBoolean(appInfo.debug) }, + { .z = BoolToAniBoolean(!appInfo.userDataClearable) }, + { .r = nativeLibraryPath }, + { .r = multiAppMode }, + { .i = appInfo.appIndex }, + { .r = installSource }, + { .r = releaseType }, + { .z = BoolToAniBoolean(appInfo.cloudFileSyncEnabled) }, + { .r = cloudStructuredDataSyncEnabled }, + { .r = flags }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // description: string + .AddLong() // descriptionId: long + .AddBoolean() // enabled: boolean + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label: string + .AddLong() // labelId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // icon: string + .AddLong() // iconId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // process: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // permissions: Array + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // codePath: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // metadataArray: Array + .AddBoolean() // removable: boolean + .AddLong() // accessTokenId: long + .AddInt() // uid: int + .AddClass(CLASSNAME_RESOURCE) // iconResource: Resource + .AddClass(CLASSNAME_RESOURCE) // labelResource: Resource + .AddClass(CLASSNAME_RESOURCE) // descriptionResource: Resource + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // appDistributionType: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // appProvisionType: string + .AddBoolean() // systemApp: boolean + .AddClass(CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_BUNDLE_TYPE) // bundleType: bundleManager.BundleType + .AddBoolean() // debug: boolean + .AddBoolean() // dataUnclearable: boolean + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // nativeLibraryPath: string + .AddClass(CLASSNAME_MULTI_APP_MODE) // multiAppMode: MultiAppMode + .AddInt() // appIndex: int + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // installSource: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // releaseType: string + .AddBoolean() // cloudFileSyncEnabled: boolean + .AddClass(CommonFunAniNS::CLASSNAME_BOOLEAN) // cloudStructuredDataSyncEnabled?: boolean + .AddClass(CommonFunAniNS::CLASSNAME_INT) // flags?: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_APPLICATION_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertAbilityInfo(ani_env* env, const AbilityInfo& abilityInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_ABILITYINFO); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.bundleName, bundleName)); // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.moduleName, moduleName)); // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.name, name)); // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.label, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); - - // labelId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, abilityInfo.labelId)); + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.label, label)); // description: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.description, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTION, string)); - - // descriptionId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, abilityInfo.descriptionId)); + ani_string description = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.description, description)); // icon: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.iconPath, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); - - // iconId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, abilityInfo.iconId)); + ani_string icon = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.iconPath, icon)); // process: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.process, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PROCESS, string)); - - // exported: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_EXPORTED, BoolToAniBoolean(abilityInfo.visible))); - - // orientation: bundleManager.DisplayOrientation - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ORIENTATION, - EnumUtils::EnumNativeToETS_BundleManager_DisplayOrientation( - env, static_cast(abilityInfo.orientation)))); - - // launchType: bundleManager.LaunchType - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LAUNCHTYPE, - EnumUtils::EnumNativeToETS_BundleManager_LaunchType(env, static_cast(abilityInfo.launchMode)))); + ani_string process = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.process, process)); // permissions: Array - ani_ref aPermissions = ConvertAniArrayString(env, abilityInfo.permissions); - RETURN_NULL_IF_NULL(aPermissions); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PERMISSIONS, aPermissions)); + ani_ref permissions = ConvertAniArrayString(env, abilityInfo.permissions); + RETURN_NULL_IF_NULL(permissions); // deviceTypes: Array - ani_ref aDeviceTypes = ConvertAniArrayString(env, abilityInfo.deviceTypes); - RETURN_NULL_IF_NULL(aDeviceTypes); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DEVICETYPES, aDeviceTypes)); + ani_ref deviceTypes = ConvertAniArrayString(env, abilityInfo.deviceTypes); + RETURN_NULL_IF_NULL(deviceTypes); // applicationInfo: ApplicationInfo + ani_ref applicationInfo = nullptr; if (!abilityInfo.applicationInfo.name.empty()) { - ani_object aObject = ConvertApplicationInfo(env, abilityInfo.applicationInfo); - RETURN_NULL_IF_NULL(aObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPLICATIONINFO, aObject)); + applicationInfo = ConvertApplicationInfo(env, abilityInfo.applicationInfo); } else { - RETURN_NULL_IF_FALSE(CallSetterNull(env, cls, object, PROPERTYNAME_APPLICATIONINFO)); + ani_status status = env->GetNull(&applicationInfo); + if (status != ANI_OK) { + APP_LOGE("GetNull applicationInfo failed %{public}d", status); + return nullptr; + } } + RETURN_NULL_IF_NULL(applicationInfo); // metadata: Array - ani_object aMetadataObject = ConvertAniArray(env, abilityInfo.metadata, ConvertMetadata); - RETURN_NULL_IF_NULL(aMetadataObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_METADATA, aMetadataObject)); - - // enabled: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ENABLED, BoolToAniBoolean(abilityInfo.enabled))); + ani_object metadata = ConvertAniArray(env, abilityInfo.metadata, ConvertMetadata); + RETURN_NULL_IF_NULL(metadata); // supportWindowModes: Array - ani_object aSupportWindowModes = + ani_object supportWindowModes = ConvertAniArrayEnum(env, abilityInfo.windowModes, EnumUtils::EnumNativeToETS_BundleManager_SupportWindowMode); - RETURN_NULL_IF_NULL(aSupportWindowModes); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SUPPORTWINDOWMODES, aSupportWindowModes)); + RETURN_NULL_IF_NULL(supportWindowModes); // windowSize: WindowSize - ani_object aniWindowSizeObj = ConvertWindowSize(env, abilityInfo); - RETURN_NULL_IF_NULL(aniWindowSizeObj); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_WINDOWSIZE, aniWindowSizeObj)); - - // excludeFromDock: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_EXCLUDEFROMDOCK, BoolToAniBoolean(abilityInfo.excludeFromDock))); + ani_object windowSize = ConvertWindowSize(env, abilityInfo); + RETURN_NULL_IF_NULL(windowSize); // skills: Array - ani_object aSkillsObject = ConvertAniArray(env, abilityInfo.skills, ConvertAbilitySkill); - RETURN_NULL_IF_NULL(aSkillsObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SKILLS, aSkillsObject)); - - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, abilityInfo.appIndex)); - - // orientationId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ORIENTATIONID, abilityInfo.orientationId)); - - return object; + ani_object skills = ConvertAniArray(env, abilityInfo.skills, ConvertAbilitySkill); + RETURN_NULL_IF_NULL(skills); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .r = name }, + { .r = label }, + { .l = static_cast(abilityInfo.labelId) }, + { .r = description }, + { .l = static_cast(abilityInfo.descriptionId) }, + { .r = icon }, + { .l = static_cast(abilityInfo.iconId) }, + { .r = process }, + { .z = BoolToAniBoolean(abilityInfo.visible) }, + { .r = EnumUtils::EnumNativeToETS_BundleManager_DisplayOrientation( + env, static_cast(abilityInfo.orientation)) }, + { .r = EnumUtils::EnumNativeToETS_BundleManager_LaunchType( + env, static_cast(abilityInfo.launchMode)) }, + { .r = permissions }, + { .r = deviceTypes }, + { .r = applicationInfo }, + { .r = metadata }, + { .z = BoolToAniBoolean(abilityInfo.enabled) }, + { .r = supportWindowModes }, + { .r = windowSize }, + { .z = BoolToAniBoolean(abilityInfo.excludeFromDock) }, + { .r = skills }, + { .i = abilityInfo.appIndex }, + { .l = static_cast(abilityInfo.orientationId) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label: string + .AddLong() // labelId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // description: string + .AddLong() // descriptionId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // icon: string + .AddLong() // iconId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // process: string + .AddBoolean() // exported: boolean + .AddClass(CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_DISPLAY_ORIENTATION) // orientation + .AddClass(CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_LAUNCH_TYPE) // launchType: bundleManager.LaunchType + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // permissions: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // deviceTypes: Array + .AddClass(CLASSNAME_APPLICATION_INFO) // applicationInfo: ApplicationInfo + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // metadata: Array + .AddBoolean() // enabled: boolean + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // supportWindowModes: Array + .AddClass(CLASSNAME_WINDOW_SIZE) // windowSize: WindowSize + .AddBoolean() // excludeFromDock: boolean + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // skills: Array + .AddInt() // appIndex: int + .AddLong() // orientationId: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_ABILITY_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertWindowSize(ani_env* env, const AbilityInfo& abilityInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_WINDOWSIZE); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - // maxWindowRatio: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAXWINDOWRATIO, abilityInfo.maxWindowRatio)); - - // minWindowRatio: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MINWINDOWRATIO, abilityInfo.minWindowRatio)); - - // maxWindowWidth: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAXWINDOWWIDTH, abilityInfo.maxWindowWidth)); - - // minWindowWidth: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MINWINDOWWIDTH, abilityInfo.minWindowWidth)); - - // maxWindowHeight: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAXWINDOWHEIGHT, abilityInfo.maxWindowHeight)); - - // minWindowHeight: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MINWINDOWHEIGHT, abilityInfo.minWindowHeight)); - - return object; + ani_value args[] = { + { .d = abilityInfo.maxWindowRatio }, + { .d = abilityInfo.minWindowRatio }, + { .l = static_cast(abilityInfo.maxWindowWidth) }, + { .l = static_cast(abilityInfo.minWindowWidth) }, + { .l = static_cast(abilityInfo.maxWindowHeight) }, + { .l = static_cast(abilityInfo.minWindowHeight) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddDouble() // maxWindowRatio: double + .AddDouble() // minWindowRatio: double + .AddLong() // maxWindowWidth: long + .AddLong() // minWindowWidth: long + .AddLong() // maxWindowHeight: long + .AddLong() // minWindowHeight: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_WINDOW_SIZE_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertExtensionInfo(ani_env* env, const ExtensionAbilityInfo& extensionInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_EXTENSIONABILITYINFO); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.bundleName, bundleName)); // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.moduleName, moduleName)); // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); - - // labelId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, extensionInfo.labelId)); - - // descriptionId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, extensionInfo.descriptionId)); - - // iconId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, extensionInfo.iconId)); - - // exported: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_EXPORTED, extensionInfo.visible)); - - // extensionAbilityType: bundleManager.ExtensionAbilityType - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_EXTENSIONABILITYTYPE, - EnumUtils::EnumNativeToETS_BundleManager_ExtensionAbilityType(env, static_cast(extensionInfo.type)))); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.name, name)); // extensionAbilityTypeName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.extensionTypeName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_EXTENSIONABILITYTYPENAME, string)); + ani_string extensionAbilityTypeName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.extensionTypeName, extensionAbilityTypeName)); // permissions: Array - ani_ref aPermissions = ConvertAniArrayString(env, extensionInfo.permissions); - RETURN_NULL_IF_NULL(aPermissions); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PERMISSIONS, aPermissions)); + ani_ref permissions = ConvertAniArrayString(env, extensionInfo.permissions); + RETURN_NULL_IF_NULL(permissions); // applicationInfo: ApplicationInfo + ani_ref applicationInfo = nullptr; if (!extensionInfo.applicationInfo.name.empty()) { - ani_object aObject = ConvertApplicationInfo(env, extensionInfo.applicationInfo); - RETURN_NULL_IF_NULL(aObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPLICATIONINFO, aObject)); + applicationInfo = ConvertApplicationInfo(env, extensionInfo.applicationInfo); } else { - RETURN_NULL_IF_FALSE(CallSetterNull(env, cls, object, PROPERTYNAME_APPLICATIONINFO)); + ani_status status = env->GetNull(&applicationInfo); + if (status != ANI_OK) { + APP_LOGE("GetNull applicationInfo failed %{public}d", status); + return nullptr; + } } + RETURN_NULL_IF_NULL(applicationInfo); // metadata: Array - ani_object aMetadataObject = ConvertAniArray(env, extensionInfo.metadata, ConvertMetadata); - RETURN_NULL_IF_NULL(aMetadataObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_METADATA, aMetadataObject)); - - // enabled: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ENABLED, extensionInfo.enabled)); + ani_object metadata = ConvertAniArray(env, extensionInfo.metadata, ConvertMetadata); + RETURN_NULL_IF_NULL(metadata); // readPermission: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.readPermission, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_READPERMISSION, string)); + ani_string readPermission = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.readPermission, readPermission)); // writePermission: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.writePermission, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_WRITEPERMISSION, string)); + ani_string writePermission = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.writePermission, writePermission)); // skills: Array - ani_object aSkillsObject = ConvertAniArray(env, extensionInfo.skills, ConvertExtensionAbilitySkill); - RETURN_NULL_IF_NULL(aSkillsObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SKILLS, aSkillsObject)); - - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, extensionInfo.appIndex)); - - return object; + ani_object skills = ConvertAniArray(env, extensionInfo.skills, ConvertExtensionAbilitySkill); + RETURN_NULL_IF_NULL(skills); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .r = name }, + { .l = static_cast(extensionInfo.labelId) }, + { .l = static_cast(extensionInfo.descriptionId) }, + { .l = static_cast(extensionInfo.iconId) }, + { .z = BoolToAniBoolean(extensionInfo.visible) }, + { .r = EnumUtils::EnumNativeToETS_BundleManager_ExtensionAbilityType( + env, static_cast(extensionInfo.type)) }, + { .r = extensionAbilityTypeName }, + { .r = permissions }, + { .r = applicationInfo }, + { .r = metadata }, + { .z = BoolToAniBoolean(extensionInfo.enabled) }, + { .r = readPermission }, + { .r = writePermission }, + { .r = skills }, + { .i = extensionInfo.appIndex }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddLong() // labelId: long + .AddLong() // descriptionId: long + .AddLong() // iconId: long + .AddBoolean() // exported: boolean + .AddClass(CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_EXTENSION_ABILITY_TYPE) // extensionAbilityType + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // extensionAbilityTypeName: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // permissions: Array + .AddClass(CLASSNAME_APPLICATION_INFO) // applicationInfo: ApplicationInfo + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // metadata: Array + .AddBoolean() // enabled: boolean + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // readPermission: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // writePermission: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // skills: Array + .AddInt() // appIndex: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_EXTENSION_ABILITY_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertResource(ani_env* env, const Resource& resource) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_RESOURCE); + ani_class cls = CreateClassByName(env, CLASSNAME_RESOURCE_INNER); RETURN_NULL_IF_NULL(cls); - ani_object object = CreateNewObjectByClass(env, cls); + ani_object object = CreateNewObjectByClass(env, CLASSNAME_RESOURCE_INNER, cls); RETURN_NULL_IF_NULL(object); ani_string string = nullptr; // bundleName: string RETURN_NULL_IF_FALSE(StringToAniStr(env, resource.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLE_NAME, string)); // moduleName: string RETURN_NULL_IF_FALSE(StringToAniStr(env, resource.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULE_NAME, string)); // id: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ID, resource.id)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ID, static_cast(resource.id))); return object; } @@ -896,132 +1111,147 @@ ani_object CommonFunAni::ConvertSignatureInfo(ani_env* env, const SignatureInfo& { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SIGNATUREINFO); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // appId: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, signatureInfo.appId, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPID, string)); + ani_string appId = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, signatureInfo.appId, appId)); // fingerprint: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, signatureInfo.fingerprint, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_FINGERPRINT, string)); + ani_string fingerprint = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, signatureInfo.fingerprint, fingerprint)); // appIdentifier: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, signatureInfo.appIdentifier, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPIDENTIFIER, string)); + ani_string appIdentifier = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, signatureInfo.appIdentifier, appIdentifier)); // certificate?: string - if (StringToAniStr(env, signatureInfo.certificate, string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_CERTIFICATE, string)); - } - - return object; + ani_string certificate = nullptr; + ani_ref certificateRef = nullptr; + if (StringToAniStr(env, signatureInfo.certificate, certificate)) { + certificateRef = certificate; + } else { + env->GetUndefined(&certificateRef); + } + + ani_value args[] = { + { .r = appId }, + { .r = fingerprint }, + { .r = appIdentifier }, + { .r = certificateRef }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // appId: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // fingerprint: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // appIdentifier: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // certificate?: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_SIGNATURE_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertKeyValuePair( - ani_env* env, const std::pair& item, const char* className) + ani_env* env, const std::pair& item, const std::string& className) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_DATAITEM); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // key: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, item.first, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_KEY, string)); + ani_string key = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, item.first, key)); // value: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, item.second, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VALUE, string)); - - return object; + ani_string value = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, item.second, value)); + + ani_value args[] = { + { .r = key }, + { .r = value }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // key: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // value: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, className, ctorSig, args); } inline ani_object CommonFunAni::ConvertDataItem(ani_env* env, const std::pair& item) { - return ConvertKeyValuePair(env, item, CLASSNAME_DATAITEM); + return ConvertKeyValuePair(env, item, CLASSNAME_DATA_ITEM_INNER); } ani_object CommonFunAni::ConvertRouterItem(ani_env* env, const RouterItem& routerItem) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_ROUTERITEM); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, routerItem.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, routerItem.name, name)); // pageSourceFile: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, routerItem.pageSourceFile, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PAGESOURCEFILE, string)); + ani_string pageSourceFile = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, routerItem.pageSourceFile, pageSourceFile)); // buildFunction: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, routerItem.buildFunction, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUILDFUNCTION, string)); + ani_string buildFunction = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, routerItem.buildFunction, buildFunction)); // customData: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, routerItem.customData, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_CUSTOMDATA, string)); + ani_string customData = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, routerItem.customData, customData)); // data: Array ani_object aDataArrayObject = ConvertAniArray(env, routerItem.data, ConvertDataItem); RETURN_NULL_IF_NULL(aDataArrayObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DATA, aDataArrayObject)); - return object; + ani_value args[] = { + { .r = name }, + { .r = pageSourceFile }, + { .r = buildFunction }, + { .r = customData }, + { .r = aDataArrayObject }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // pageSourceFile: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // buildFunction: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // customData: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // data: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_ROUTER_ITEM_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertRequestPermission(ani_env* env, const RequestPermission& requestPermission) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_PERMISSION); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, requestPermission.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, requestPermission.name, name)); // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, requestPermission.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, requestPermission.moduleName, moduleName)); // reason: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, requestPermission.reason, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_REASON, string)); - - // reasonId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_REASONID, requestPermission.reasonId)); + ani_string reason = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, requestPermission.reason, reason)); // usedScene: UsedScene - ani_object aObject = ConvertRequestPermissionUsedScene(env, requestPermission.usedScene); - RETURN_NULL_IF_NULL(aObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_USEDSCENE, aObject)); - - return object; + ani_object usedScene = ConvertRequestPermissionUsedScene(env, requestPermission.usedScene); + RETURN_NULL_IF_NULL(usedScene); + + ani_value args[] = { + { .r = name }, + { .r = moduleName }, + { .r = reason }, + { .l = static_cast(requestPermission.reasonId) }, + { .r = usedScene }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // reason: string + .AddLong() // reasonId: long + .AddClass(CLASSNAME_USED_SCENE) // usedScene: UsedScene + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_PERMISSION_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertRequestPermissionUsedScene( @@ -1029,593 +1259,912 @@ ani_object CommonFunAni::ConvertRequestPermissionUsedScene( { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_USEDSCENE); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // when: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, requestPermissionUsedScene.when, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_WHEN, string)); - // abilities: Array - ani_ref aAbilities = ConvertAniArrayString(env, requestPermissionUsedScene.abilities); - RETURN_NULL_IF_NULL(aAbilities); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ABILITIES, aAbilities)); + ani_object abilities = ConvertAniArrayString(env, requestPermissionUsedScene.abilities); + RETURN_NULL_IF_NULL(abilities); - return object; + // when: string + ani_string when = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, requestPermissionUsedScene.when, when)); + + ani_value args[] = { + { .r = abilities }, + { .r = when }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // abilities: Array + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // when: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_USED_SCENE_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertPreloadItem(ani_env* env, const PreloadItem& preloadItem) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_PRELOADITEM); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, preloadItem.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); - - return object; + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, preloadItem.moduleName, moduleName)); + + ani_value args[] = { + { .r = moduleName }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_PRELOAD_ITEM_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertDependency(ani_env* env, const Dependency& dependency) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_DEPENDENCY); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, dependency.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, dependency.moduleName, moduleName)); // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, dependency.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); - - // versionCode: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONCODE, dependency.versionCode)); - - return object; + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, dependency.bundleName, bundleName)); + + ani_value args[] = { + { .r = moduleName }, + { .r = bundleName }, + { .l = static_cast(dependency.versionCode) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddLong() // versionCode: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_DEPENDENCY_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertHapModuleInfo(ani_env* env, const HapModuleInfo& hapModuleInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_HAPMODULEINFO); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.name, name)); // icon: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.iconPath, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); - - // iconId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, hapModuleInfo.iconId)); + ani_string icon = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.iconPath, icon)); // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.label, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); - - // labelId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, hapModuleInfo.labelId)); + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.label, label)); // description: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.description, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTION, string)); - - // descriptionId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, hapModuleInfo.descriptionId)); + ani_string description = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.description, description)); // mainElementName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.mainElementName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAINELEMENTNAME, string)); + ani_string mainElementName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.mainElementName, mainElementName)); // abilitiesInfo: Array - ani_object aAbilityInfoObject = ConvertAniArray(env, hapModuleInfo.abilityInfos, ConvertAbilityInfo); - RETURN_NULL_IF_NULL(aAbilityInfoObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ABILITIESINFO, aAbilityInfoObject)); + ani_object abilitiesInfo = ConvertAniArray(env, hapModuleInfo.abilityInfos, ConvertAbilityInfo); + RETURN_NULL_IF_NULL(abilitiesInfo); // extensionAbilitiesInfo: Array - ani_object aExtensionAbilityInfoObject = ConvertAniArray(env, hapModuleInfo.extensionInfos, ConvertExtensionInfo); - RETURN_NULL_IF_NULL(aExtensionAbilityInfoObject); - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_EXTENSIONABILITIESINFO, aExtensionAbilityInfoObject)); + ani_object extensionAbilitiesInfo = ConvertAniArray(env, hapModuleInfo.extensionInfos, ConvertExtensionInfo); + RETURN_NULL_IF_NULL(extensionAbilitiesInfo); // metadata: Array - ani_object aMetadataObject = ConvertAniArray(env, hapModuleInfo.metadata, ConvertMetadata); - RETURN_NULL_IF_NULL(aMetadataObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_METADATA, aMetadataObject)); + ani_object metadata = ConvertAniArray(env, hapModuleInfo.metadata, ConvertMetadata); + RETURN_NULL_IF_NULL(metadata); // deviceTypes: Array - ani_ref aDeviceTypes = ConvertAniArrayString(env, hapModuleInfo.deviceTypes); - RETURN_NULL_IF_NULL(aDeviceTypes); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DEVICETYPES, aDeviceTypes)); - - // installationFree: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_INSTALLATIONFREE, BoolToAniBoolean(hapModuleInfo.installationFree))); + ani_object deviceTypes = ConvertAniArrayString(env, hapModuleInfo.deviceTypes); + RETURN_NULL_IF_NULL(deviceTypes); // hashValue: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.hashValue, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_HASHVALUE, string)); - - // type: bundleManager.ModuleType - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TYPE, - EnumUtils::EnumNativeToETS_BundleManager_ModuleType(env, static_cast(hapModuleInfo.moduleType)))); + ani_string hashValue = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.hashValue, hashValue)); // dependencies: Array - ani_object aDependenciesObject = ConvertAniArray(env, hapModuleInfo.dependencies, ConvertDependency); - RETURN_NULL_IF_NULL(aDependenciesObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DEPENDENCIES, aDependenciesObject)); + ani_object dependencies = ConvertAniArray(env, hapModuleInfo.dependencies, ConvertDependency); + RETURN_NULL_IF_NULL(dependencies); // preloads: Array - ani_object aPreloadsObject = ConvertAniArray(env, hapModuleInfo.preloads, ConvertPreloadItem); - RETURN_NULL_IF_NULL(aPreloadsObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PRELOADS, aPreloadsObject)); + ani_object preloads = ConvertAniArray(env, hapModuleInfo.preloads, ConvertPreloadItem); + RETURN_NULL_IF_NULL(preloads); // fileContextMenuConfig: string - if (!hapModuleInfo.fileContextMenu.empty()) { - RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.fileContextMenu, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_FILECONTEXTMENUCONFIG, string)); - } + ani_string fileContextMenuConfig = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, hapModuleInfo.fileContextMenu, fileContextMenuConfig)); // routerMap: Array - ani_object aRouterMapObject = ConvertAniArray(env, hapModuleInfo.routerArray, ConvertRouterItem); - RETURN_NULL_IF_NULL(aRouterMapObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ROUTERMAP, aRouterMapObject)); + ani_object routerMap = ConvertAniArray(env, hapModuleInfo.routerArray, ConvertRouterItem); + RETURN_NULL_IF_NULL(routerMap); // nativeLibraryPath: string + ani_string nativeLibraryPath = nullptr; std::string externalNativeLibraryPath = ""; if (!hapModuleInfo.nativeLibraryPath.empty() && !hapModuleInfo.moduleName.empty()) { externalNativeLibraryPath = CONTEXT_DATA_STORAGE_BUNDLE + hapModuleInfo.nativeLibraryPath; } - RETURN_NULL_IF_FALSE(StringToAniStr(env, externalNativeLibraryPath, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NATIVELIBRARYPATH, string)); + RETURN_NULL_IF_FALSE(StringToAniStr(env, externalNativeLibraryPath, nativeLibraryPath)); // codePath: string - std::string codePath = hapModuleInfo.hapPath; + ani_string codePath = nullptr; + std::string hapPath = hapModuleInfo.hapPath; size_t result = hapModuleInfo.hapPath.find(PATH_PREFIX); if (result != std::string::npos) { size_t pos = hapModuleInfo.hapPath.find_last_of('/'); - codePath = CODE_PATH_PREFIX; + hapPath = CODE_PATH_PREFIX; if (pos != std::string::npos && pos != hapModuleInfo.hapPath.size() - 1) { - codePath.append(hapModuleInfo.hapPath.substr(pos + 1)); + hapPath.append(hapModuleInfo.hapPath.substr(pos + 1)); } } - RETURN_NULL_IF_FALSE(StringToAniStr(env, codePath, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_CODEPATH, string)); - - return object; + RETURN_NULL_IF_FALSE(StringToAniStr(env, hapPath, codePath)); + + ani_value args[] = { + { .r = name }, + { .r = icon }, + { .l = static_cast(hapModuleInfo.iconId) }, + { .r = label }, + { .l = static_cast(hapModuleInfo.labelId) }, + { .r = description }, + { .l = static_cast(hapModuleInfo.descriptionId) }, + { .r = mainElementName }, + { .r = abilitiesInfo }, + { .r = extensionAbilitiesInfo }, + { .r = metadata }, + { .r = deviceTypes }, + { .z = BoolToAniBoolean(hapModuleInfo.installationFree) }, + { .r = hashValue }, + { .r = EnumUtils::EnumNativeToETS_BundleManager_ModuleType( + env, static_cast(hapModuleInfo.moduleType)) }, + { .r = dependencies }, + { .r = preloads }, + { .r = fileContextMenuConfig }, + { .r = routerMap }, + { .r = nativeLibraryPath }, + { .r = codePath }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // icon: string + .AddLong() // iconId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label: string + .AddLong() // labelId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // description: string + .AddLong() // descriptionId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // mainElementName: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // abilitiesInfo: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // extensionAbilitiesInfo: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // metadata: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // deviceTypes: Array + .AddBoolean() // installationFree: boolean + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // hashValue: string + .AddClass(CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_MODULE_TYPE) // type: bundleManager.ModuleType + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // dependencies: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // preloads: Array + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // fileContextMenuConfig: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // routerMap: Array + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // nativeLibraryPath: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // codePath: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_HAP_MODULE_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertElementName(ani_env* env, const ElementName& elementName) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_ELEMENTNAME); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; + ani_ref refUndefined = nullptr; + ani_status status = env->GetUndefined(&refUndefined); + if (status != ANI_OK) { + APP_LOGE("GetUndefined failed %{public}d", status); + return nullptr; + } // deviceId?: string - if (StringToAniStr(env, elementName.GetDeviceID(), string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_DEVICEID, string)); + ani_ref deviceId = refUndefined; + ani_string deviceIdString = nullptr; + if (StringToAniStr(env, elementName.GetDeviceID(), deviceIdString)) { + deviceId = deviceIdString; } // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, elementName.GetBundleName(), string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, elementName.GetBundleName(), bundleName)); // moduleName?: string - if (StringToAniStr(env, elementName.GetModuleName(), string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_ref moduleName = refUndefined; + ani_string moduleNameString = nullptr; + if (StringToAniStr(env, elementName.GetModuleName(), moduleNameString)) { + moduleName = moduleNameString; } // abilityName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, elementName.GetAbilityName(), string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ABILITYNAME, string)); + ani_string abilityName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, elementName.GetAbilityName(), abilityName)); // uri?: string - if (StringToAniStr(env, elementName.GetURI(), string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_URI, string)); + ani_ref uri = refUndefined; + ani_string uriString = nullptr; + if (StringToAniStr(env, elementName.GetURI(), uriString)) { + uri = uriString; } // shortName?: string - if (StringToAniStr(env, "", string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_SHORTNAME, string)); - } - - return object; + ani_ref shortName = refUndefined; + ani_string shortNameString = nullptr; + if (StringToAniStr(env, "", shortNameString)) { + shortName = shortNameString; + } + + ani_value args[] = { + { .r = bundleName }, + { .r = abilityName }, + { .r = deviceId }, + { .r = moduleName }, + { .r = uri }, + { .r = shortName }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // abilityName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // deviceId?: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName?: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // uri?: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // shortName?: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_ELEMENT_NAME_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertAbilitySkillUriInner(ani_env* env, const SkillUri& skillUri, bool isExtension) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SKILLURI); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // scheme: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.scheme, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SCHEME, string)); + ani_string scheme = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.scheme, scheme)); // host: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.host, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_HOST, string)); + ani_string host = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.host, host)); - // port: number - int32_t nPort = 0; + // port: int + int32_t port = 0; if (!skillUri.port.empty()) { - auto [ptr, ec] = std::from_chars(skillUri.port.data(), skillUri.port.data() + skillUri.port.size(), nPort); + auto [ptr, ec] = std::from_chars(skillUri.port.data(), skillUri.port.data() + skillUri.port.size(), port); if (ec != std::errc() || ptr != skillUri.port.data() + skillUri.port.size()) { APP_LOGE("skillUri port convert failed"); return nullptr; } } - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PORT, nPort)); // path: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.path, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PATH, string)); + ani_string path = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.path, path)); // pathStartWith: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.pathStartWith, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PATHSTARTWITH, string)); + ani_string pathStartWith = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.pathStartWith, pathStartWith)); // pathRegex: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.pathRegex, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PATHREGEX, string)); + ani_string pathRegex = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.pathRegex, pathRegex)); // type: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.type, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TYPE, string)); + ani_string type = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.type, type)); // utd: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.utd, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_UTD, string)); - - // maxFileSupported: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAXFILESUPPORTED, skillUri.maxFileSupported)); - - if (!isExtension) { - // linkFeature: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.linkFeature, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LINKFEATURE, string)); - } - - return object; + ani_string utd = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.utd, utd)); + + // linkFeature: string + ani_string linkFeature = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, isExtension? std::string(): skillUri.linkFeature, linkFeature)); + + ani_value args[] = { + { .r = scheme }, + { .r = host }, + { .i = port }, + { .r = path }, + { .r = pathStartWith }, + { .r = pathRegex }, + { .r = type }, + { .r = utd }, + { .i = skillUri.maxFileSupported }, + { .r = linkFeature }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // scheme: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // host: string + .AddInt() // port: int + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // path: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // pathStartWith: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // pathRegex: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // type: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // utd: string + .AddInt() // maxFileSupported: int + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // linkFeature: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_SKILL_URI_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertAbilitySkillInner(ani_env* env, const Skill& skill, bool isExtension) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SKILL); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - // actions: Array - ani_ref aActions = ConvertAniArrayString(env, skill.actions); - RETURN_NULL_IF_NULL(aActions); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ACTIONS, aActions)); + ani_object actions = ConvertAniArrayString(env, skill.actions); + RETURN_NULL_IF_NULL(actions); // entities: Array - ani_ref aEntities = ConvertAniArrayString(env, skill.entities); - RETURN_NULL_IF_NULL(aEntities); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ENTITIES, aEntities)); + ani_object entities = ConvertAniArrayString(env, skill.entities); + RETURN_NULL_IF_NULL(entities); // uris: Array - ani_object aSkillUri = + ani_object uris = ConvertAniArray(env, skill.uris, isExtension ? ConvertExtensionAbilitySkillUri : ConvertAbilitySkillUri); - RETURN_NULL_IF_NULL(aSkillUri); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_URIS, aSkillUri)); + RETURN_NULL_IF_NULL(uris); + + ani_value args[] = { + { .r = actions }, + { .r = entities }, + { .r = uris }, + { .z = BoolToAniBoolean(isExtension? false: skill.domainVerify) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // actions: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // entities: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // uris: Array + .AddBoolean() // domainVerify: boolean + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_SKILL_INNER, ctorSig, args); +} - if (!isExtension) { - // domainVerify: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_DOMAINVERIFY, BoolToAniBoolean(skill.domainVerify))); - } +ani_object CommonFunAni::ConvertAppCloneIdentity(ani_env* env, const std::string& bundleName, const int32_t appIndex) +{ + RETURN_NULL_IF_NULL(env); - return object; + // name: string + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleName, name)); + + ani_value args[] = { + { .r = name }, + { .i = appIndex }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddInt() // appIndex: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_APP_CLONE_IDENTITY_INNER, ctorSig, args); } -ani_object CommonFunAni::ConvertAppCloneIdentity(ani_env* env, const std::string& bundleName, const int32_t appIndex) +ani_object CommonFunAni::ConvertPermissionDef(ani_env* env, const PermissionDef& permissionDef) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_APPCLONEIDENTITY); - RETURN_NULL_IF_NULL(cls); + // permissionName: string + ani_string permissionName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, permissionDef.permissionName, permissionName)); + + ani_value args[] = { + { .r = permissionName }, + { .i = permissionDef.grantMode }, + { .l = static_cast(permissionDef.labelId) }, + { .l = static_cast(permissionDef.descriptionId) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // permissionName: string + .AddInt() // grantMode: int + .AddLong() // labelId: long + .AddLong() // descriptionId: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_PERMISSION_DEF_INNER, ctorSig, args); +} - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); +ani_object CommonFunAni::ConvertSharedBundleInfo(ani_env* env, const SharedBundleInfo& sharedBundleInfo) +{ + RETURN_NULL_IF_NULL(env); + + // name: string + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, sharedBundleInfo.name, name)); + + // sharedModuleInfo: Array + ani_object sharedModuleInfo = + ConvertAniArray(env, sharedBundleInfo.sharedModuleInfos, ConvertSharedModuleInfo); + RETURN_NULL_IF_NULL(sharedModuleInfo); + + ani_value args[] = { + { .r = name }, + { .r = EnumUtils::EnumNativeToETS_BundleManager_CompatiblePolicy( + env, static_cast(CompatiblePolicy::BACKWARD_COMPATIBILITY)) }, + { .r = sharedModuleInfo }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // permissionName: string + .AddClass(CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_COMPATIBLE_POLICY) // compatiblePolicy + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // sharedModuleInfo: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_SHARED_BUNDLE_INFO_INNER, ctorSig, args); +} - ani_string string = nullptr; +ani_object CommonFunAni::ConvertSharedModuleInfo(ani_env* env, const SharedModuleInfo& sharedModuleInfo) +{ + RETURN_NULL_IF_NULL(env); // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, sharedModuleInfo.name, name)); - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, appIndex)); + // versionName: string + ani_string versionName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, sharedModuleInfo.versionName, versionName)); - return object; + // description: string + ani_string description = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, sharedModuleInfo.description, description)); + + ani_value args[] = { + { .r = name }, + { .l = static_cast(sharedModuleInfo.versionCode) }, + { .r = versionName }, + { .r = description }, + { .l = static_cast(sharedModuleInfo.descriptionId) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddLong() // versionCode: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // versionName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // description: string + .AddLong() // descriptionId: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_SHARED_MODULE_INFO_INNER, ctorSig, args); } -ani_object CommonFunAni::ConvertBundleResourceInfo(ani_env* env, const BundleResourceInfo& bundleResInfo) +ani_object CommonFunAni::ConvertAppProvisionInfo(ani_env* env, const AppProvisionInfo& appProvisionInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLERESINFO); - RETURN_NULL_IF_NULL(cls); + // versionName: string + ani_string versionName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.versionName, versionName)); - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); + // uuid: string + ani_string uuid = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.uuid, uuid)); - ani_string string = nullptr; + // type: string + ani_string type = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.type, type)); - // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleResInfo.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + // appDistributionType: string + ani_string appDistributionType = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.appDistributionType, appDistributionType)); - // icon: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleResInfo.icon, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + // validity: Validity + ani_object validity = ConvertValidity(env, appProvisionInfo.validity); + RETURN_NULL_IF_NULL(validity); - // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleResInfo.label, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); + // developerId: string + ani_string developerId = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.developerId, developerId)); - // drawableDecriptor: drawableDecriptor + // certificate: string + ani_string certificate = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.certificate, certificate)); - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, bundleResInfo.appIndex)); + // apl: string + ani_string apl = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.apl, apl)); - return object; + // issuer: string + ani_string issuer = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.issuer, issuer)); + + // appIdentifier: string + ani_string appIdentifier = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.appIdentifier, appIdentifier)); + + // organization: string + ani_string organization = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.organization, organization)); + + ani_value args[] = { + { .l = static_cast(appProvisionInfo.versionCode) }, + { .r = versionName }, + { .r = uuid }, + { .r = type }, + { .r = appDistributionType }, + { .r = validity }, + { .r = developerId }, + { .r = certificate }, + { .r = apl }, + { .r = issuer }, + { .r = appIdentifier }, + { .r = organization }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddLong() // versionCode: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // versionName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // uuid: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // type: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // appDistributionType: string + .AddClass(CLASSNAME_VALIDITY) // validity: Validity + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // developerId: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // certificate: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // apl: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // issuer: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // appIdentifier: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // organization: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_APP_PROVISION_INFO_INNER, ctorSig, args); } -ani_object CommonFunAni::ConvertLauncherAbilityResourceInfo( - ani_env* env, const LauncherAbilityResourceInfo& launcherAbilityResourceInfo) +ani_object CommonFunAni::ConvertValidity(ani_env* env, const Validity& validity) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_LAUNCHER_ABILITY_RESOURCE_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); + ani_value args[] = { + { .l = validity.notBefore }, + { .l = validity.notAfter }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddLong() // notBefore: long + .AddLong() // notAfter: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_VALIDITY_INNER, ctorSig, args); +} - ani_string string = nullptr; +ani_object CommonFunAni::ConvertRecoverableApplicationInfo( + ani_env* env, const RecoverableApplicationInfo& recoverableApplicationInfo) +{ + RETURN_NULL_IF_NULL(env); // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, recoverableApplicationInfo.bundleName, bundleName)); // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, recoverableApplicationInfo.moduleName, moduleName)); + + // codePaths: Array + ani_ref codePaths = ConvertAniArrayString(env, recoverableApplicationInfo.codePaths); + RETURN_NULL_IF_NULL(codePaths); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .l = static_cast(recoverableApplicationInfo.labelId) }, + { .l = static_cast(recoverableApplicationInfo.iconId) }, + { .z = BoolToAniBoolean(recoverableApplicationInfo.systemApp) }, + { .r = EnumUtils::EnumNativeToETS_BundleManager_BundleType( + env, static_cast(recoverableApplicationInfo.bundleType)) }, + { .r = codePaths }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddLong() // labelId: long + .AddLong() // iconId: long + .AddBoolean() // systemApp: boolean + .AddClass(CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_BUNDLE_TYPE) // bundleType: bundleManager.BundleType + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // codePaths: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_RECOVERABLE_APPLICATION_INFO_INNER, ctorSig, args); +} - // abilityName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.abilityName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ABILITYNAME, string)); +ani_object CommonFunAni::ConvertPreinstalledApplicationInfo( + ani_env* env, const PreinstalledApplicationInfo& reinstalledApplicationInfo) +{ + RETURN_NULL_IF_NULL(env); - // icon: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.icon, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + // bundleName: string + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, reinstalledApplicationInfo.bundleName, bundleName)); + + // moduleName: string + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, reinstalledApplicationInfo.moduleName, moduleName)); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .l = static_cast(reinstalledApplicationInfo.iconId) }, + { .l = static_cast(reinstalledApplicationInfo.labelId) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddLong() // iconId: long + .AddLong() // labelId: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_PREINSTALLED_APPLICATION_INFO_INNER, ctorSig, args); +} + +ani_object CommonFunAni::ConvertPluginBundleInfo(ani_env* env, const PluginBundleInfo& pluginBundleInfo) +{ + RETURN_NULL_IF_NULL(env); // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.label, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginBundleInfo.label, label)); - // drawableDescriptor: DrawableDescriptor; + // icon: string + ani_string icon = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginBundleInfo.icon, icon)); - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, launcherAbilityResourceInfo.appIndex)); + // pluginBundleName: string + ani_string pluginBundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginBundleInfo.pluginBundleName, pluginBundleName)); - return object; + // versionName: string + ani_string versionName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginBundleInfo.versionName, versionName)); + + // pluginModuleInfos: Array + ani_object pluginModuleInfos = + ConvertAniArray(env, pluginBundleInfo.pluginModuleInfos, ConvertPluginModuleInfo); + RETURN_NULL_IF_NULL(pluginModuleInfos); + + ani_value args[] = { + { .r = label }, + { .l = static_cast(pluginBundleInfo.labelId) }, + { .r = icon }, + { .l = static_cast(pluginBundleInfo.iconId) }, + { .r = pluginBundleName }, + { .l = static_cast(pluginBundleInfo.versionCode) }, + { .r = versionName }, + { .r = pluginModuleInfos }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label: string + .AddLong() // labelId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // icon: string + .AddLong() // iconId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // pluginBundleName: string + .AddLong() // versionCode: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // versionName: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // pluginModuleInfos: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_PLUGIN_BUNDLE_INFO_INNER, ctorSig, args); } -ani_object CommonFunAni::ConvertShortcutInfo(ani_env* env, const ShortcutInfo& shortcutInfo) +ani_object CommonFunAni::ConvertPluginModuleInfo(ani_env* env, const PluginModuleInfo& pluginModuleInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SHORTCUTINFO); - RETURN_NULL_IF_NULL(cls); + // moduleName: string + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginModuleInfo.moduleName, moduleName)); - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); + // description: string + ani_string description = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginModuleInfo.description, description)); + + ani_value args[] = { + { .r = moduleName }, + { .l = static_cast(pluginModuleInfo.descriptionId) }, + { .r = description }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddLong() // descriptionId: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // description: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_PLUGIN_MODULE_INFO_INNER, ctorSig, args); +} - ani_string string = nullptr; +ani_object CommonFunAni::ConvertShortcutInfo(ani_env* env, const ShortcutInfo& shortcutInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_ref refUndefined = nullptr; + ani_status status = env->GetUndefined(&refUndefined); + if (status != ANI_OK) { + APP_LOGE("GetUndefined failed %{public}d", status); + return nullptr; + } // id: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, shortcutInfo.id, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ID, string)); + ani_string id = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, shortcutInfo.id, id)); // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, shortcutInfo.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, shortcutInfo.bundleName, bundleName)); // moduleName?: string - if (StringToAniStr(env, shortcutInfo.moduleName, string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_ref moduleName = refUndefined; + ani_string moduleNameString = nullptr; + if (StringToAniStr(env, shortcutInfo.moduleName, moduleNameString)) { + moduleName = moduleNameString; } // hostAbility?: string - if (StringToAniStr(env, shortcutInfo.hostAbility, string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_HOSTABILITY, string)); + ani_ref hostAbility = refUndefined; + ani_string hostAbilityString = nullptr; + if (StringToAniStr(env, shortcutInfo.hostAbility, hostAbilityString)) { + hostAbility = hostAbilityString; } // icon?: string - if (StringToAniStr(env, shortcutInfo.icon, string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_ICON, string)); + ani_ref icon = refUndefined; + ani_string iconString = nullptr; + if (StringToAniStr(env, shortcutInfo.icon, iconString)) { + icon = iconString; } - // iconId?: number - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_ICONID, shortcutInfo.iconId)); + // iconId?: long + ani_object iconId = BoxValue(env, static_cast(shortcutInfo.iconId)); + RETURN_NULL_IF_FALSE(iconId); // label?: string - if (StringToAniStr(env, shortcutInfo.label, string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_LABEL, string)); + ani_ref label = refUndefined; + ani_string labelString = nullptr; + if (StringToAniStr(env, shortcutInfo.label, labelString)) { + label = labelString; } - // labelId?: number - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_LABELID, shortcutInfo.labelId)); + // labelId?: long + ani_object labelId = BoxValue(env, static_cast(shortcutInfo.labelId)); + RETURN_NULL_IF_FALSE(labelId); // wants?: Array - ani_object aShortcutWantObject = ConvertAniArray(env, shortcutInfo.intents, ConvertShortcutIntent); - RETURN_NULL_IF_NULL(aShortcutWantObject); - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_WANTS, aShortcutWantObject)); - - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, shortcutInfo.appIndex)); - - // sourceType: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SOURCETYPE, shortcutInfo.sourceType)); + ani_object wants = ConvertAniArray(env, shortcutInfo.intents, ConvertShortcutIntent); + RETURN_NULL_IF_NULL(wants); // visible?: boolean - RETURN_NULL_IF_FALSE(CallSetterOptional( - env, cls, object, PROPERTYNAME_VISIBLE, BoolToAniBoolean(shortcutInfo.visible))); - - return object; + ani_object visible = BoxValue(env, BoolToAniBoolean(shortcutInfo.visible)); + RETURN_NULL_IF_FALSE(visible); + + ani_value args[] = { + { .r = id }, + { .r = bundleName }, + { .i = shortcutInfo.appIndex }, + { .i = shortcutInfo.sourceType }, + { .r = moduleName }, + { .r = hostAbility }, + { .r = icon }, + { .r = iconId }, + { .r = label }, + { .r = labelId }, + { .r = wants }, + { .r = visible }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // id: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddInt() // appIndex: int + .AddInt() // sourceType: int + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName?: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // hostAbility?: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // icon?: string + .AddClass(CommonFunAniNS::CLASSNAME_LONG) // iconId?: long + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label?: string + .AddClass(CommonFunAniNS::CLASSNAME_LONG) // labelId?: long + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // wants?: Array + .AddClass(CommonFunAniNS::CLASSNAME_BOOLEAN) // visible?: boolean + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_SHORTCUT_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertShortcutIntent(ani_env* env, const ShortcutIntent& shortcutIntent) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SHORTCUTWANT); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; + ani_ref refUndefined = nullptr; + ani_status status = env->GetUndefined(&refUndefined); + if (status != ANI_OK) { + APP_LOGE("GetUndefined failed %{public}d", status); + return nullptr; + } // targetBundle: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, shortcutIntent.targetBundle, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TARGETBUNDLE, string)); + ani_string targetBundle = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, shortcutIntent.targetBundle, targetBundle)); // targetModule?: string - if (StringToAniStr(env, shortcutIntent.targetModule, string)) { - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_TARGETMODULE, string)); + ani_ref targetModule = refUndefined; + ani_string targetModuleString = nullptr; + if (StringToAniStr(env, shortcutIntent.targetModule, targetModuleString)) { + targetModule = targetModuleString; } // targetAbility: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, shortcutIntent.targetClass, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TARGETABILITY, string)); + ani_string targetAbility = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, shortcutIntent.targetClass, targetAbility)); // parameters?: Array - ani_object aParameters = ConvertAniArray(env, shortcutIntent.parameters, ConvertShortcutIntentParameter); - RETURN_NULL_IF_NULL(aParameters); - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_PARAMETERS, aParameters)); - - return object; + ani_object parameters = ConvertAniArray(env, shortcutIntent.parameters, ConvertShortcutIntentParameter); + RETURN_NULL_IF_NULL(parameters); + + ani_value args[] = { + { .r = targetBundle }, + { .r = targetAbility }, + { .r = targetModule }, + { .r = parameters }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // targetBundle: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // targetAbility: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // targetModule?: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // parameters?: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_SHORTCUT_WANT_INNER, ctorSig, args); } inline ani_object CommonFunAni::ConvertShortcutIntentParameter( ani_env* env, const std::pair& item) { - return ConvertKeyValuePair(env, item, CLASSNAME_SHORTCUT_PARAMETERITEM); + return ConvertKeyValuePair(env, item, CLASSNAME_SHORTCUT_PARAMETER_ITEM_INNER); } ani_object CommonFunAni::ConvertLauncherAbilityInfo(ani_env* env, const LauncherAbilityInfo& launcherAbility) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_LAUNCHER_ABILITY_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - // applicationInfo: ApplicationInfo - ani_object aObject = ConvertApplicationInfo(env, launcherAbility.applicationInfo); - RETURN_NULL_IF_NULL(aObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPLICATIONINFO, aObject)); + ani_object applicationInfo = ConvertApplicationInfo(env, launcherAbility.applicationInfo); + RETURN_NULL_IF_NULL(applicationInfo); // elementName: ElementName - ani_object aElementNameObject = ConvertElementName(env, launcherAbility.elementName); - RETURN_NULL_IF_NULL(aElementNameObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ELEMENTNAME, aElementNameObject)); - - // labelId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, launcherAbility.labelId)); - - // iconId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, launcherAbility.iconId)); - - // userId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_USERID, launcherAbility.userId)); - - // installTime: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_INSTALLTIME, launcherAbility.installTime)); - - return object; + ani_object elementName = ConvertElementName(env, launcherAbility.elementName); + RETURN_NULL_IF_NULL(elementName); + + ani_value args[] = { + { .r = applicationInfo }, + { .r = elementName }, + { .l = static_cast(launcherAbility.labelId) }, + { .l = static_cast(launcherAbility.iconId) }, + { .i = launcherAbility.userId }, + { .l = launcherAbility.installTime }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CLASSNAME_APPLICATION_INFO) // applicationInfo: ApplicationInfo + .AddClass(CLASSNAME_ELEMENT_NAME) // elementName: ElementName + .AddLong() // labelId: long + .AddLong() // iconId: long + .AddInt() // userId: int + .AddLong() // installTime: long + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_LAUNCHER_ABILITY_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertOverlayModuleInfo(ani_env* env, const OverlayModuleInfo& overlayModuleInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_OVERLAY_MOUDLE_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, overlayModuleInfo.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, overlayModuleInfo.bundleName, bundleName)); // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, overlayModuleInfo.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, overlayModuleInfo.moduleName, moduleName)); // targetModuleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, overlayModuleInfo.targetModuleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TARGETMOUDLENAME, string)); - - // priority: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PRIORITY, overlayModuleInfo.priority)); - - // state: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_STATE, overlayModuleInfo.state)); - - return object; + ani_string targetModuleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, overlayModuleInfo.targetModuleName, targetModuleName)); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .r = targetModuleName }, + { .i = overlayModuleInfo.priority }, + { .i = overlayModuleInfo.state }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // targetModuleName: string + .AddInt() // priority: int + .AddInt() // state: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_OVERLAY_MODULE_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::CreateBundleChangedInfo( @@ -1623,373 +2172,385 @@ ani_object CommonFunAni::CreateBundleChangedInfo( { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLE_CHANGED_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); - - // userId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_USERID, userId)); - - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, appIndex)); - - return object; + ani_string aniBundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleName, aniBundleName)); + + ani_value args[] = { + { .r = aniBundleName }, + { .i = userId }, + { .i = appIndex }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddInt() // userId: int + .AddInt() // appIndex: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_CHANGED_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertVersion(ani_env* env, const Version& version) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_VERSION_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - - // minCompatibleVersionCode: number - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_MINCOMPATIBLEVERSIONCODE, version.minCompatibleVersionCode)); - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, version.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); - - // code: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_CODE, version.code)); - - return object; + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, version.name, name)); + + ani_value args[] = { + { .i = static_cast(version.minCompatibleVersionCode) }, + { .r = name }, + { .i = static_cast(version.code) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddInt() // minCompatibleVersionCode: int + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddInt() // code: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_VERSION_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertPackageApp(ani_env* env, const PackageApp& packageApp) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLE_CONFIG_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, packageApp.bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, packageApp.bundleName, bundleName)); // version: Version - ani_object aObject = ConvertVersion(env, packageApp.version); - RETURN_NULL_IF_NULL(aObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSION, aObject)); - - return object; + ani_object version = ConvertVersion(env, packageApp.version); + RETURN_NULL_IF_NULL(version); + + ani_value args[] = { + { .r = bundleName }, + { .r = version }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CLASSNAME_VERSION) // version: Version + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_CONFIG_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertAbilityFormInfo(ani_env* env, const AbilityFormInfo& abilityFormInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_ABILITY_FORM_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityFormInfo.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityFormInfo.name, name)); // type: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityFormInfo.type, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TYPE, string)); - - // updateEnabled: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_UPDATEENABLED, BoolToAniBoolean(abilityFormInfo.updateEnabled))); + ani_string type = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityFormInfo.type, type)); // scheduledUpdateTime: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityFormInfo.scheduledUpdateTime, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SCHEDULEDUPDATETIME, string)); - - // updateDuration: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_UPDATEDURATION, abilityFormInfo.updateDuration)); + ani_string scheduledUpdateTime = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityFormInfo.scheduledUpdateTime, scheduledUpdateTime)); // supportDimensions: Array - ani_ref aSupportDimensions = ConvertAniArrayString(env, abilityFormInfo.supportDimensions); - RETURN_NULL_IF_NULL(aSupportDimensions); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SUPPORTDIMENSIONS, aSupportDimensions)); + ani_ref supportDimensions = ConvertAniArrayString(env, abilityFormInfo.supportDimensions); + RETURN_NULL_IF_NULL(supportDimensions); // defaultDimension: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityFormInfo.defaultDimension, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DEFAULTDIMENSION, string)); - - return object; + ani_string defaultDimension = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityFormInfo.defaultDimension, defaultDimension)); + + ani_value args[] = { + { .r = name }, + { .r = type }, + { .z = BoolToAniBoolean(abilityFormInfo.updateEnabled) }, + { .r = scheduledUpdateTime }, + { .i = static_cast(abilityFormInfo.updateDuration) }, + { .r = supportDimensions }, + { .r = defaultDimension }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // type: string + .AddBoolean() // updateEnabled: boolean + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // scheduledUpdateTime: string + .AddInt() // updateDuration: int + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // supportDimensions: Array + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // defaultDimension: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_ABILITY_FORM_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertModuleAbilityInfo(ani_env* env, const ModuleAbilityInfo& moduleAbilityInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_MODULE_ABILITY_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, moduleAbilityInfo.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, moduleAbilityInfo.name, name)); // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, moduleAbilityInfo.label, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); - - // exported: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_EXPORTED, BoolToAniBoolean(moduleAbilityInfo.visible))); + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, moduleAbilityInfo.label, label)); // forms: Array - ani_object aAbilityFormInfoObject = ConvertAniArray(env, moduleAbilityInfo.forms, ConvertAbilityFormInfo); - RETURN_NULL_IF_NULL(aAbilityFormInfoObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_FORMS, aAbilityFormInfoObject)); - - return object; + ani_object forms = ConvertAniArray(env, moduleAbilityInfo.forms, ConvertAbilityFormInfo); + RETURN_NULL_IF_NULL(forms); + + ani_value args[] = { + { .r = name }, + { .r = label }, + { .z = BoolToAniBoolean(moduleAbilityInfo.visible) }, + { .r = forms }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label: string + .AddBoolean() // exported: boolean + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // forms: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_MODULE_ABILITY_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertModuleDistro(ani_env* env, const ModuleDistro& moduleDistro) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_MODULE_DISTRO_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - - // deliveryWithInstall: boolean - RETURN_NULL_IF_FALSE(CallSetter( - env, cls, object, PROPERTYNAME_DELIVERYWITHINSTALL, BoolToAniBoolean(moduleDistro.deliveryWithInstall))); - - // installationFree: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_INSTALLATIONFREE, BoolToAniBoolean(moduleDistro.installationFree))); - // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, moduleDistro.moduleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, moduleDistro.moduleName, moduleName)); // moduleType: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, moduleDistro.moduleType, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULETYPE, string)); - - return object; + ani_string moduleType = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, moduleDistro.moduleType, moduleType)); + + ani_value args[] = { + { .z = BoolToAniBoolean(moduleDistro.deliveryWithInstall) }, + { .z = BoolToAniBoolean(moduleDistro.installationFree) }, + { .r = moduleName }, + { .r = moduleType }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddBoolean() // deliveryWithInstall: boolean + .AddBoolean() // installationFree: boolean + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleType: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_MODULE_DISTRO_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertApiVersion(ani_env* env, const ApiVersion& apiVersion) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_API_VERSION_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // releaseType: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, apiVersion.releaseType, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_RELEASETYPE, string)); - - // compatible: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_COMPATIBLE, apiVersion.compatible)); - - // target: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TARGET, apiVersion.target)); - - return object; + ani_string releaseType = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, apiVersion.releaseType, releaseType)); + + ani_value args[] = { + { .r = releaseType }, + { .i = static_cast(apiVersion.compatible) }, + { .i = static_cast(apiVersion.target) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // releaseType: string + .AddInt() // compatible: int + .AddInt() // target: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_API_VERSION_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertExtensionAbilities(ani_env* env, const ExtensionAbilities& extensionAbilities) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_EXTENSION_ABILITY_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionAbilities.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionAbilities.name, name)); // forms: Array - ani_object aAbilityFormInfoObject = ConvertAniArray(env, extensionAbilities.forms, ConvertAbilityFormInfo); - RETURN_NULL_IF_NULL(aAbilityFormInfoObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_FORMS, aAbilityFormInfoObject)); - - return object; + ani_object forms = ConvertAniArray(env, extensionAbilities.forms, ConvertAbilityFormInfo); + RETURN_NULL_IF_NULL(forms); + + ani_value args[] = { + { .r = name }, + { .r = forms }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // forms: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_EXTENSION_ABILITY_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertPackageModule(ani_env* env, const PackageModule& packageModule) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_MODULE_CONFIG_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // mainAbility: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, packageModule.mainAbility, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAINABILITY, string)); + ani_string mainAbility = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, packageModule.mainAbility, mainAbility)); // apiVersion: ApiVersion - ani_object aApiVersionObject = ConvertApiVersion(env, packageModule.apiVersion); - RETURN_NULL_IF_NULL(aApiVersionObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APIVERSION, aApiVersionObject)); + ani_object apiVersion = ConvertApiVersion(env, packageModule.apiVersion); + RETURN_NULL_IF_NULL(apiVersion); // deviceTypes: Array - ani_ref aDeviceTypes = ConvertAniArrayString(env, packageModule.deviceType); - RETURN_NULL_IF_NULL(aDeviceTypes); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DEVICETYPES, aDeviceTypes)); + ani_ref deviceTypes = ConvertAniArrayString(env, packageModule.deviceType); + RETURN_NULL_IF_NULL(deviceTypes); // distro: ModuleDistroInfo - ani_object aModuleDistroInfoObject = ConvertModuleDistro(env, packageModule.distro); - RETURN_NULL_IF_NULL(aModuleDistroInfoObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DISTRO, aModuleDistroInfoObject)); + ani_object distro = ConvertModuleDistro(env, packageModule.distro); + RETURN_NULL_IF_NULL(distro); // abilities: Array - ani_object aModuleAbilityInfoObject = ConvertAniArray(env, packageModule.abilities, ConvertModuleAbilityInfo); - RETURN_NULL_IF_NULL(aModuleAbilityInfoObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ABILITIES, aModuleAbilityInfoObject)); + ani_object abilities = ConvertAniArray(env, packageModule.abilities, ConvertModuleAbilityInfo); + RETURN_NULL_IF_NULL(abilities); // extensionAbilities: Array - ani_object aExtensionAbilityObject = + ani_object extensionAbilities = ConvertAniArray(env, packageModule.extensionAbilities, ConvertExtensionAbilities); - RETURN_NULL_IF_NULL(aExtensionAbilityObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_EXTENSIONABILITIES, aExtensionAbilityObject)); - - return object; + RETURN_NULL_IF_NULL(extensionAbilities); + + ani_value args[] = { + { .r = mainAbility }, + { .r = apiVersion }, + { .r = deviceTypes }, + { .r = distro }, + { .r = abilities }, + { .r = extensionAbilities }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // mainAbility: string + .AddClass(CLASSNAME_API_VERSION) // apiVersion: ApiVersion + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // deviceTypes: Array + .AddClass(CLASSNAME_MODULE_DISTRO_INFO) // distro: ModuleDistroInfo + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // abilities: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // extensionAbilities: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_MODULE_CONFIG_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertSummary(ani_env* env, const Summary& summary, bool withApp) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_PACKAGE_SUMMARY_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - + // app: BundleConfigInfo + ani_object app = nullptr; if (withApp) { - // app: BundleConfigInfo - ani_object aBundleConfigInfoObject = ConvertPackageApp(env, summary.app); - RETURN_NULL_IF_NULL(aBundleConfigInfoObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APP, aBundleConfigInfoObject)); + app = ConvertPackageApp(env, summary.app); + RETURN_NULL_IF_NULL(app); } // modules: Array - ani_object aModuleConfigInfoObject = ConvertAniArray(env, summary.modules, ConvertPackageModule); - RETURN_NULL_IF_NULL(aModuleConfigInfoObject); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULES, aModuleConfigInfoObject)); - - return object; + ani_object modules = ConvertAniArray(env, summary.modules, ConvertPackageModule); + RETURN_NULL_IF_NULL(modules); + + ani_value args[] = { + { .r = modules }, + { .r = app }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // modules: Array + .BuildSignatureDescriptor(); + static const std::string ctorSigWithApp = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // modules: Array + .AddClass(CLASSNAME_BUNDLE_CONFIG_INFO) // app: BundleConfigInfo + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_PACKAGE_SUMMARY_INNER, withApp ? ctorSigWithApp : ctorSig, args); } ani_object CommonFunAni::ConvertPackages(ani_env* env, const Packages& packages) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_PACKAGE_CONFIG_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - ani_string string = nullptr; - // deviceTypes: Array - ani_ref aDeviceTypes = ConvertAniArrayString(env, packages.deviceType); - RETURN_NULL_IF_NULL(aDeviceTypes); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DEVICETYPES, aDeviceTypes)); + ani_ref deviceTypes = ConvertAniArrayString(env, packages.deviceType); + RETURN_NULL_IF_NULL(deviceTypes); // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, packages.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, packages.name, name)); // moduleType: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, packages.moduleType, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULETYPE, string)); - - // deliveryWithInstall: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_DELIVERYWITHINSTALL, BoolToAniBoolean(packages.deliveryWithInstall))); - - return object; + ani_string moduleType = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, packages.moduleType, moduleType)); + + ani_value args[] = { + { .r = deviceTypes }, + { .r = name }, + { .r = moduleType }, + { .z = BoolToAniBoolean(packages.deliveryWithInstall) }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // deviceTypes: Array + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleType: string + .AddBoolean() // deliveryWithInstall: boolean + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_PACKAGE_CONFIG_INNER, ctorSig, args); } ani_object CommonFunAni::ConvertBundlePackInfo(ani_env* env, const BundlePackInfo& bundlePackInfo, const uint32_t flag) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLE_PACK_INFO_INNER); - RETURN_NULL_IF_NULL(cls); - - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); - - // packages: Array - ani_object aPackageConfigObject = ConvertAniArray(env, bundlePackInfo.packages, ConvertPackages); - RETURN_NULL_IF_NULL(aPackageConfigObject); - if (flag & BundlePackFlag::GET_PACKAGES) { - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PACKAGES, aPackageConfigObject)); - return object; - } + // packages: Array + ani_object packages = ConvertAniArray(env, bundlePackInfo.packages, ConvertPackages); + RETURN_NULL_IF_NULL(packages); - // summary: PackageSummary - ani_object aPackageSummaryObject = ConvertSummary(env, bundlePackInfo.summary, true); - RETURN_NULL_IF_NULL(aPackageSummaryObject); + ani_value args[] = { + { .r = packages }, + }; + static const std::string ctorSigPackages = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // packages: Array + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_PACK_INFO_INNER, ctorSigPackages, args); + } if (flag & BundlePackFlag::GET_BUNDLE_SUMMARY) { - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SUMMARY, aPackageSummaryObject)); - return object; + // summary: PackageSummary + ani_object summary = ConvertSummary(env, bundlePackInfo.summary, true); + RETURN_NULL_IF_NULL(summary); + + ani_value args[] = { + { .r = summary }, + }; + static const std::string ctorSigBundleSummary = SignatureBuilder() + .AddClass(CLASSNAME_PACKAGE_SUMMARY) // summary: PackageSummary + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_PACK_INFO_INNER, ctorSigBundleSummary, args); } if (flag & BundlePackFlag::GET_MODULE_SUMMARY) { - ani_object aPackageSummaryWithoutApp = ConvertSummary(env, bundlePackInfo.summary, false); - RETURN_NULL_IF_NULL(aPackageSummaryWithoutApp); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SUMMARY, aPackageSummaryWithoutApp)); - return object; + // summary: PackageSummary + ani_object summary = ConvertSummary(env, bundlePackInfo.summary, false); + RETURN_NULL_IF_NULL(summary); + + ani_value args[] = { + { .r = summary }, + }; + static const std::string ctorSigModuleSummary = SignatureBuilder() + .AddClass(CLASSNAME_PACKAGE_SUMMARY) // summary: PackageSummary + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_PACK_INFO_INNER, ctorSigModuleSummary, args); } - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PACKAGES, aPackageConfigObject)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SUMMARY, aPackageSummaryObject)); + // packages: Array + ani_object packages = ConvertAniArray(env, bundlePackInfo.packages, ConvertPackages); + RETURN_NULL_IF_NULL(packages); - return object; + // summary: PackageSummary + ani_object summary = ConvertSummary(env, bundlePackInfo.summary, true); + RETURN_NULL_IF_NULL(summary); + + ani_value args[] = { + { .r = packages }, + { .r = summary }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // packages: Array + .AddClass(CLASSNAME_PACKAGE_SUMMARY) // summary: PackageSummary + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_PACK_INFO_INNER, ctorSig, args); } ani_object CommonFunAni::CreateDispatchInfo( @@ -1997,49 +2558,109 @@ ani_object CommonFunAni::CreateDispatchInfo( { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_DISPATCH_INFO_INNER); - RETURN_NULL_IF_NULL(cls); + // version: string + ani_string aniVersion = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, version, aniVersion)); - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); + // dispatchAPIVersion: string + ani_string aniDispatchAPIVersion = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, dispatchAPIVersion, aniDispatchAPIVersion)); + + ani_value args[] = { + { .r = aniVersion }, + { .r = aniDispatchAPIVersion }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // version: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // dispatchAPIVersion: string + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_DISPATCH_INFO_INNER, ctorSig, args); +} - ani_string string = nullptr; +ani_object CommonFunAni::ConvertDynamicIconInfo(ani_env* env, const DynamicIconInfo& dynamicIconInfo) +{ + RETURN_NULL_IF_NULL(env); - // version: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, version, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSION, string)); + // bundleName: string + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, dynamicIconInfo.bundleName, bundleName)); - // dispatchAPIVersion: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, dispatchAPIVersion, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DISPATCHAPIVERSION, string)); + // moduleName: string + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, dynamicIconInfo.moduleName, moduleName)); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .i = dynamicIconInfo.userId }, + { .i = dynamicIconInfo.appIndex }, + }; + static const std::string ctorSig = SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddInt() // userId: int + .AddInt() // appIndex: int + .BuildSignatureDescriptor(); + return CreateNewObjectByClassV2(env, CLASSNAME_DYNAMIC_ICON_INFO_INNER, ctorSig, args); +} - return object; +bool CommonFunAni::ParseBundleOptions(ani_env* env, ani_object object, int32_t& appIndex, int32_t& userId) +{ + RETURN_FALSE_IF_NULL(env); + RETURN_FALSE_IF_NULL(object); + + ani_int intValue = 0; + bool isDefault = true; + + // userId?: int + if (CallGetterOptional(env, object, PROPERTYNAME_USER_ID, &intValue)) { + if (intValue < 0) { + intValue = Constants::INVALID_USERID; + } + userId = intValue; + isDefault = false; + } + + // appIndex?: int + if (CallGetterOptional(env, object, PROPERTYNAME_APP_INDEX, &intValue)) { + appIndex = intValue; + isDefault = false; + } + + return isDefault; } ani_object CommonFunAni::ConvertWantInfo(ani_env* env, const Want& want) { RETURN_NULL_IF_NULL(env); + ani_class cls = CreateClassByName(env, CLASSNAME_WANT); RETURN_NULL_IF_NULL(cls); - ani_object object = CreateNewObjectByClass(env, cls); + + ani_object object = CreateNewObjectByClass(env, CLASSNAME_WANT, cls); RETURN_NULL_IF_NULL(object); + // bundleName?: string ani_string string = nullptr; if (StringToAniStr(env, want.GetElement().GetBundleName(), string)) { - RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_BUNDLE_NAME, string)); } + // abilityName?: string if (StringToAniStr(env, want.GetElement().GetAbilityName(), string)) { - RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_ABILITYNAME, string)); + RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_ABILITY_NAME, string)); } + // deviceId?: string if (StringToAniStr(env, want.GetElement().GetDeviceID(), string)) { - RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_DEVICEID, string)); + RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_DEVICE_ID, string)); } + // action?: string if (StringToAniStr(env, want.GetAction(), string)) { RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_ACTION, string)); } + // entities?: Array auto entities = want.GetEntities(); if (entities.size() > 0) { @@ -2047,10 +2668,12 @@ ani_object CommonFunAni::ConvertWantInfo(ani_env* env, const Want& want) RETURN_NULL_IF_NULL(aEntities); RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_ENTITIES, aEntities)); } + // moduleName?: string if (StringToAniStr(env, want.GetElement().GetModuleName(), string)) { - RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_MODULENAME, string)); + RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_MODULE_NAME, string)); } + return object; } @@ -2068,16 +2691,16 @@ bool CommonFunAni::ParseShortcutInfo(ani_env* env, ani_object object, ShortcutIn shortcutInfo.id = AniStrToString(env, string); // bundleName: string - RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLENAME, &string)); + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLE_NAME, &string)); shortcutInfo.bundleName = AniStrToString(env, string); // moduleName?: string - if (CallGetterOptional(env, object, PROPERTYNAME_MODULENAME, &string)) { + if (CallGetterOptional(env, object, PROPERTYNAME_MODULE_NAME, &string)) { shortcutInfo.moduleName = AniStrToString(env, string); } // hostAbility?: string - if (CallGetterOptional(env, object, PROPERTYNAME_HOSTABILITY, &string)) { + if (CallGetterOptional(env, object, PROPERTYNAME_HOST_ABILITY, &string)) { shortcutInfo.hostAbility = AniStrToString(env, string); } @@ -2086,8 +2709,8 @@ bool CommonFunAni::ParseShortcutInfo(ani_env* env, ani_object object, ShortcutIn shortcutInfo.icon = AniStrToString(env, string); } - // iconId?: number - if (CallGetterOptional(env, object, PROPERTYNAME_ICONID, &uintValue)) { + // iconId?: long + if (CallGetterOptional(env, object, PROPERTYNAME_ICON_ID, &uintValue)) { shortcutInfo.iconId = uintValue; } @@ -2096,8 +2719,8 @@ bool CommonFunAni::ParseShortcutInfo(ani_env* env, ani_object object, ShortcutIn shortcutInfo.label = AniStrToString(env, string); } - // labelId?: number - if (CallGetterOptional(env, object, PROPERTYNAME_LABELID, &uintValue)) { + // labelId?: long + if (CallGetterOptional(env, object, PROPERTYNAME_LABEL_ID, &uintValue)) { shortcutInfo.labelId = uintValue; } @@ -2107,12 +2730,12 @@ bool CommonFunAni::ParseShortcutInfo(ani_env* env, ani_object object, ShortcutIn RETURN_FALSE_IF_FALSE(ParseAniArray(env, array, shortcutInfo.intents, ParseShortcutIntent)); } - // appIndex: number - RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_APPINDEX, &intValue)); + // appIndex: int + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_APP_INDEX, &intValue)); shortcutInfo.appIndex = intValue; - // sourceType: number - RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_SOURCETYPE, &intValue)); + // sourceType: int + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_SOURCE_TYPE, &intValue)); shortcutInfo.sourceType = intValue; ani_boolean boolValue = false; @@ -2132,16 +2755,16 @@ bool CommonFunAni::ParseShortcutIntent(ani_env* env, ani_object object, Shortcut ani_string string = nullptr; // targetBundle: string - RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_TARGETBUNDLE, &string)); + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_TARGET_BUNDLE, &string)); shortcutIntent.targetBundle = AniStrToString(env, string); // targetModule?: string - if (CallGetterOptional(env, object, PROPERTYNAME_TARGETMODULE, &string)) { + if (CallGetterOptional(env, object, PROPERTYNAME_TARGET_MODULE, &string)) { shortcutIntent.targetModule = AniStrToString(env, string); } // targetAbility: string - RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_TARGETABILITY, &string)); + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_TARGET_ABILITY, &string)); shortcutIntent.targetClass = AniStrToString(env, string); // parameters?: Array @@ -2183,12 +2806,12 @@ bool CommonFunAni::ParseKeyValuePair(ani_env* env, ani_object object, std::pair< bool CommonFunAni::ParseHashParams(ani_env* env, ani_object object, std::pair& pair) { - return ParseKeyValuePairWithName(env, object, pair, PROPERTYNAME_MODULENAME, PROPERTYNAME_HASHVALUE); + return ParseKeyValuePairWithName(env, object, pair, PROPERTYNAME_MODULE_NAME, PROPERTYNAME_HASH_VALUE); } bool CommonFunAni::ParsePgoParams(ani_env* env, ani_object object, std::pair& pair) { - return ParseKeyValuePairWithName(env, object, pair, PROPERTYNAME_MODULENAME, PROPERTYNAME_PGOFILEPATH); + return ParseKeyValuePairWithName(env, object, pair, PROPERTYNAME_MODULE_NAME, PROPERTYNAME_PGO_FILE_PATH); } bool CommonFunAni::ParseInstallParam(ani_env* env, ani_object object, InstallParam& installParam) @@ -2198,7 +2821,7 @@ bool CommonFunAni::ParseInstallParam(ani_env* env, ani_object object, InstallPar ani_array array = nullptr; // hashParams? - if (CallGetterOptional(env, object, PROPERTYNAME_HASHPARAMS, &array)) { + if (CallGetterOptional(env, object, PROPERTYNAME_HASH_PARAMS, &array)) { std::vector> hashParams; RETURN_FALSE_IF_FALSE(ParseAniArray(env, array, hashParams, ParseHashParams)); for (const auto& parameter : hashParams) { @@ -2224,7 +2847,7 @@ bool CommonFunAni::ParseInstallParam(ani_env* env, ani_object object, InstallPar } // pgoParams? - if (CallGetterOptional(env, object, PROPERTYNAME_PGOPARAMS, &array)) { + if (CallGetterOptional(env, object, PROPERTYNAME_PGO_PARAMS, &array)) { std::vector> pgoParams; RETURN_FALSE_IF_FALSE(ParseAniArray(env, array, pgoParams, ParsePgoParams)); for (const auto& parameter : pgoParams) { @@ -2237,14 +2860,14 @@ bool CommonFunAni::ParseInstallParam(ani_env* env, ani_object object, InstallPar } ani_int intValue = 0; - // userId?: number - if (CallGetterOptional(env, object, PROPERTYNAME_USERID, &intValue)) { + // userId?: int + if (CallGetterOptional(env, object, PROPERTYNAME_USER_ID, &intValue)) { installParam.userId = intValue; } else { APP_LOGW("Parse userId failed,using default value"); } - // installFlag?: number - if (CallGetterOptional(env, object, PROPERTYNAME_INSTALLFLAG, &intValue)) { + // installFlag?: int + if (CallGetterOptional(env, object, PROPERTYNAME_INSTALL_FLAG, &intValue)) { if ((intValue != static_cast(OHOS::AppExecFwk::InstallFlag::NORMAL)) && (intValue != static_cast(OHOS::AppExecFwk::InstallFlag::REPLACE_EXISTING)) && (intValue != static_cast(OHOS::AppExecFwk::InstallFlag::FREE_INSTALL))) { @@ -2258,35 +2881,36 @@ bool CommonFunAni::ParseInstallParam(ani_env* env, ani_object object, InstallPar ani_boolean boolValue = false; // isKeepData?: boolean - if (CallGetterOptional(env, object, PROPERTYNAME_ISKEEPDATA, &boolValue)) { + if (CallGetterOptional(env, object, PROPERTYNAME_IS_KEEP_DATA, &boolValue)) { installParam.isKeepData = boolValue; } else { APP_LOGW("Parse isKeepData failed,using default value"); } - // crowdtestDeadline?: number - if (CallGetterOptional(env, object, PROPERTYNAME_CROWDTESTDEADLINE, &intValue)) { - installParam.crowdtestDeadline = intValue; + ani_long longValue = 0; + // crowdtestDeadline?: long + if (CallGetterOptional(env, object, PROPERTYNAME_CROWD_TEST_DEADLINE, &longValue)) { + installParam.crowdtestDeadline = longValue; } else { APP_LOGW("Parse crowdtestDeadline failed,using default value"); } // sharedBundleDirPaths?: Array - if (CallGetterOptional(env, object, PROPERTYNAME_SHAREDBUNDLEDIRPATHS, &array)) { + if (CallGetterOptional(env, object, PROPERTYNAME_SHARED_BUNDLE_DIR_PATHS, &array)) { RETURN_FALSE_IF_FALSE(ParseStrArray(env, array, installParam.sharedBundleDirPaths)); } ani_string string = nullptr; // specifiedDistributionType?: string - if (CallGetterOptional(env, object, PROPERTYNAME_SPECIFIEDDISTRIBUTIONTYPE, &string)) { + if (CallGetterOptional(env, object, PROPERTYNAME_SPECIFIED_DISTRIBUTION_TYPE, &string)) { installParam.specifiedDistributionType = AniStrToString(env, string); } else { APP_LOGW("Parse specifiedDistributionType failed,using default value"); } // additionalInfo?: string - if (CallGetterOptional(env, object, PROPERTYNAME_ADDITIONALINFO, &string)) { + if (CallGetterOptional(env, object, PROPERTYNAME_ADDITIONAL_INFO, &string)) { installParam.additionalInfo = AniStrToString(env, string); } else { APP_LOGW("Parse additionalInfo failed,using default value"); @@ -2300,11 +2924,11 @@ bool CommonFunAni::ParseUninstallParam(ani_env* env, ani_object object, Uninstal RETURN_FALSE_IF_NULL(object); ani_string string = nullptr; // bundleName: string - RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLENAME, &string)); + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLE_NAME, &string)); uninstallParam.bundleName = AniStrToString(env, string); ani_int intValue = 0; - // versionCode?: number - if (CallGetterOptional(env, object, PROPERTYNAME_VERSIONCODE, &intValue)) { + // versionCode?: int + if (CallGetterOptional(env, object, PROPERTYNAME_VERSION_CODE, &intValue)) { uninstallParam.versionCode = intValue; } else { APP_LOGW("Parse crowdtestDeadline failed,using default value"); @@ -2318,8 +2942,8 @@ bool CommonFunAni::ParseDestroyAppCloneParam( RETURN_FALSE_IF_NULL(env); RETURN_FALSE_IF_NULL(object); ani_int intValue = 0; - // userId?: number - if (CallGetterOptional(env, object, PROPERTYNAME_USERID, &intValue)) { + // userId?: int + if (CallGetterOptional(env, object, PROPERTYNAME_USER_ID, &intValue)) { destroyAppCloneParam.userId = intValue; } else { destroyAppCloneParam.userId = Constants::UNSPECIFIED_USERID; @@ -2345,8 +2969,8 @@ bool CommonFunAni::ParsePluginParam(ani_env* env, ani_object object, InstallPlug ani_int intValue = 0; ani_array array = nullptr; - // userId?: number - if (CallGetterOptional(env, object, PROPERTYNAME_USERID, &intValue)) { + // userId?: int + if (CallGetterOptional(env, object, PROPERTYNAME_USER_ID, &intValue)) { installPluginParam.userId = intValue; } else { installPluginParam.userId = Constants::UNSPECIFIED_USERID; @@ -2370,16 +2994,16 @@ bool CommonFunAni::ParseCreateAppCloneParam(ani_env* env, ani_object object, int RETURN_FALSE_IF_NULL(env); RETURN_FALSE_IF_NULL(object); ani_int intValue = 0; - // userId?: number - if (CallGetterOptional(env, object, PROPERTYNAME_USERID, &intValue)) { + // userId?: int + if (CallGetterOptional(env, object, PROPERTYNAME_USER_ID, &intValue)) { userId = intValue; } else { userId = Constants::UNSPECIFIED_USERID; APP_LOGW("Parse userId failed,using default value"); } - // appIdx?: number - if (CallGetterOptional(env, object, PROPERTYNAME_APPINDEX, &intValue)) { + // appIdx?: int + if (CallGetterOptional(env, object, PROPERTYNAME_APP_INDEX, &intValue)) { appIdx = intValue; if (appIdx == 0) { APP_LOGI("parse appIndex success, but appIndex is 0, assign a value: %{public}d", ILLEGAL_APP_INDEX); @@ -2399,11 +3023,11 @@ bool CommonFunAni::ParseAbilityInfo(ani_env* env, ani_object object, AbilityInfo ani_string string = nullptr; // bundleName: string - RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLENAME, &string)); + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLE_NAME, &string)); abilityInfo.bundleName = AniStrToString(env, string); // moduleName: string - RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_MODULENAME, &string)); + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_MODULE_NAME, &string)); abilityInfo.moduleName = AniStrToString(env, string); // name: string @@ -2412,5 +3036,33 @@ bool CommonFunAni::ParseAbilityInfo(ani_env* env, ani_object object, AbilityInfo return true; } + +bool CommonFunAni::ParseElementName(ani_env* env, ani_object object, ElementName& elementName) +{ + RETURN_FALSE_IF_NULL(env); + RETURN_FALSE_IF_NULL(object); + + ani_string string = nullptr; + + // deviceId?: string + if (CallGetterOptional(env, object, PROPERTYNAME_DEVICE_ID, &string)) { + elementName.SetDeviceID(AniStrToString(env, string)); + } + + // bundleName: string + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLE_NAME, &string)); + elementName.SetBundleName(AniStrToString(env, string)); + + // moduleName?: string + if (CallGetterOptional(env, object, PROPERTYNAME_MODULE_NAME, &string)) { + elementName.SetModuleName(AniStrToString(env, string)); + } + + // abilityName: string + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_ABILITY_NAME, &string)); + elementName.SetAbilityName(AniStrToString(env, string)); + + return true; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/ani/common/common_fun_ani.h b/interfaces/kits/ani/common/common_fun_ani.h index 1a285eb2b4..cd76505276 100644 --- a/interfaces/kits/ani/common/common_fun_ani.h +++ b/interfaces/kits/ani/common/common_fun_ani.h @@ -34,6 +34,9 @@ namespace OHOS { namespace AppExecFwk { using Want = OHOS::AAFwk::Want; +namespace CommonFunAniNS { +constexpr const char* PROPERTYNAME_UNBOXED = "unboxed"; +} // namespace CommonFunAniNS #define RETURN_IF_NULL(ptr) \ do { \ @@ -77,6 +80,15 @@ using Want = OHOS::AAFwk::Want; return res; \ } \ } while (0) +namespace CommonFunAniNS { +constexpr const char* CLASSNAME_BOOLEAN = "std.core.Boolean"; +constexpr const char* CLASSNAME_INT = "std.core.Int"; +constexpr const char* CLASSNAME_LONG = "std.core.Long"; +constexpr const char* CLASSNAME_DOUBLE = "std.core.Double"; +constexpr const char* CLASSNAME_OBJECT = "std.core.Object"; +constexpr const char* CLASSNAME_ARRAY = "escompat.Array"; +constexpr const char* CLASSNAME_STRING = "std.core.String"; +} // namespace CommonFunAniNS class CommonFunAni { public: // Data conversion. @@ -122,7 +134,7 @@ public: static ani_object ConvertSignatureInfo(ani_env* env, const SignatureInfo& signatureInfo); static ani_object ConvertKeyValuePair( - ani_env* env, const std::pair& item, const char* className); + ani_env* env, const std::pair& item, const std::string& className); static ani_object ConvertDataItem(ani_env* env, const std::pair& item); static ani_object ConvertRouterItem(ani_env* env, const RouterItem& routerItem); @@ -147,12 +159,23 @@ public: return ConvertAbilitySkillInner(env, skill, true); } static ani_object ConvertBundleInfo(ani_env* env, const BundleInfo& bundleInfo, int32_t flags); + static ani_object ConvertDefaultAppAbilityInfo(ani_env* env, const AbilityInfo& abilityInfo); + static ani_object ConvertDefaultAppExtensionInfo(ani_env* env, const ExtensionAbilityInfo& extensionInfo); + static ani_object ConvertDefaultAppHapModuleInfo(ani_env* env, const BundleInfo &bundleInfo); + static ani_object ConvertDefaultAppBundleInfo(ani_env* env, const BundleInfo &bundleInfo); static ani_object ConvertAppCloneIdentity(ani_env* env, const std::string& bundleName, const int32_t appIndex); - - static ani_object ConvertBundleResourceInfo(ani_env* env, const BundleResourceInfo& bundleResInfo); - static ani_object ConvertLauncherAbilityResourceInfo(ani_env* env, - const LauncherAbilityResourceInfo& launcherAbilityResourceInfo); + static ani_object ConvertPermissionDef(ani_env* env, const PermissionDef& permissionDef); + static ani_object ConvertSharedBundleInfo(ani_env* env, const SharedBundleInfo& sharedBundleInfo); + static ani_object ConvertSharedModuleInfo(ani_env* env, const SharedModuleInfo& sharedModuleInfo); + static ani_object ConvertAppProvisionInfo(ani_env* env, const AppProvisionInfo& appProvisionInfo); + static ani_object ConvertValidity(ani_env* env, const Validity& validity); + static ani_object ConvertRecoverableApplicationInfo( + ani_env* env, const RecoverableApplicationInfo& recoverableApplicationInfo); + static ani_object ConvertPreinstalledApplicationInfo( + ani_env* env, const PreinstalledApplicationInfo& reinstalledApplicationInfo); + static ani_object ConvertPluginBundleInfo(ani_env* env, const PluginBundleInfo& pluginBundleInfo); + static ani_object ConvertPluginModuleInfo(ani_env* env, const PluginModuleInfo& pluginModuleInfo); static ani_object ConvertShortcutInfo(ani_env* env, const ShortcutInfo& shortcutInfo); static ani_object ConvertShortcutIntent(ani_env* env, const ShortcutIntent& shortcutIntent); @@ -175,11 +198,14 @@ public: static ani_object ConvertSummary(ani_env* env, const Summary& summary, bool withApp); static ani_object ConvertPackages(ani_env* env, const Packages& packages); static ani_object ConvertBundlePackInfo(ani_env* env, const BundlePackInfo& bundlePackInfo, const uint32_t flag); + static ani_object ConvertDynamicIconInfo(ani_env* env, const DynamicIconInfo& dynamicIconInfo); static ani_object CreateDispatchInfo( ani_env* env, const std::string& version, const std::string& dispatchAPIVersion); + static ani_object ConvertWantInfo(ani_env* env, const Want& want); // Parse from ets to native + static bool ParseBundleOptions(ani_env* env, ani_object object, int32_t& appIndex, int32_t& userId); static bool ParseShortcutInfo(ani_env* env, ani_object object, ShortcutInfo& shortcutInfo); static bool ParseShortcutIntent(ani_env* env, ani_object object, ShortcutIntent& shortcutIntent); static bool ParseKeyValuePair(ani_env* env, ani_object object, std::pair& pair); @@ -187,7 +213,9 @@ public: const char* keyName, const char* valueName); static ani_class CreateClassByName(ani_env* env, const std::string& className); - static ani_object CreateNewObjectByClass(ani_env* env, ani_class cls); + static ani_object CreateNewObjectByClass(ani_env* env, const std::string& className, ani_class cls); + static ani_object CreateNewObjectByClassV2( + ani_env* env, const std::string& className, const std::string& ctorSig, const ani_value* args); static inline ani_object ConvertAniArrayString(ani_env* env, const std::vector& strings) { return ConvertAniArray(env, strings, [](ani_env* env, const std::string& nativeStr) { @@ -217,25 +245,28 @@ public: static bool ParseDestroyAppCloneParam(ani_env* env, ani_object object, DestroyAppCloneParam& destroyAppCloneParam); static bool ParsePluginParam(ani_env* env, ani_object object, InstallPluginParam& installPluginParam); static bool ParseAbilityInfo(ani_env* env, ani_object object, AbilityInfo& abilityInfo); + static bool ParseElementName(ani_env* env, ani_object object, ElementName& elementName); - template - static bool TryCastDoubleTo(const double fromValue, toType* toValue) + template + static bool TryCastTo(const fromType fromValue, toType* toValue) { RETURN_FALSE_IF_NULL(toValue); - if (std::isnan(fromValue)) { - APP_LOGE("value is NaN"); - return false; - } - if (std::isinf(fromValue)) { - APP_LOGE("value is Inf"); - return false; + if constexpr (!std::is_integral_v) { + if (std::isnan(fromValue)) { + APP_LOGE("value is NaN"); + return false; + } + if (std::isinf(fromValue)) { + APP_LOGE("value is Inf"); + return false; + } } - if (fromValue > static_cast(std::numeric_limits::max())) { + if (fromValue > static_cast(std::numeric_limits::max())) { APP_LOGE("value too large"); return false; } - if (fromValue < static_cast(std::numeric_limits::lowest())) { + if (fromValue < static_cast(std::numeric_limits::lowest())) { APP_LOGE("value too small"); return false; } @@ -251,35 +282,20 @@ public: RETURN_NULL_IF_NULL(env); RETURN_NULL_IF_NULL(converter); - ani_class arrayCls = nullptr; - ani_status status = env->FindClass("Lescompat/Array;", &arrayCls); - if (status != ANI_OK) { - APP_LOGE("FindClass failed %{public}d", status); - return nullptr; - } + ani_int length = static_cast(cArray.size()); + ani_value arg = { .i = length }; + ani_object arrayObj = CreateNewObjectByClassV2(env, CommonFunAniNS::CLASSNAME_ARRAY, "i:", &arg); + RETURN_NULL_IF_NULL(arrayObj); - ani_method arrayCtor; - status = env->Class_FindMethod(arrayCls, "", "I:V", &arrayCtor); - if (status != ANI_OK) { - APP_LOGE("Class_FindMethod failed %{public}d", status); - return nullptr; - } - - ani_object arrayObj; - ani_size length = cArray.size(); - status = env->Object_New(arrayCls, arrayCtor, &arrayObj, length); - if (status != ANI_OK) { - APP_LOGE("Object_New failed %{public}d", status); - return nullptr; - } + ani_status status = ANI_OK; if (length > 0) { - for (ani_size i = 0; i < length; ++i) { + for (ani_int i = 0; i < length; ++i) { ani_enum_item item = converter(env, static_cast(cArray[i])); if (item == nullptr) { APP_LOGE("convert failed"); return nullptr; } - status = env->Object_CallMethodByName_Void(arrayObj, "$_set", "ILstd/core/Object;:V", i, item); + status = env->Object_CallMethodByName_Void(arrayObj, "$_set", "iC{std.core.Object}:", i, item); env->Reference_Delete(item); if (status != ANI_OK) { APP_LOGE("Object_CallMethodByName_Void failed %{public}d", status); @@ -298,33 +314,17 @@ public: RETURN_NULL_IF_NULL(env); RETURN_NULL_IF_NULL(converter); - ani_class arrayCls = nullptr; - ani_status status = env->FindClass("Lescompat/Array;", &arrayCls); - if (status != ANI_OK) { - APP_LOGE("FindClass failed %{public}d", status); - return nullptr; - } - - ani_method arrayCtor; - status = env->Class_FindMethod(arrayCls, "", "I:V", &arrayCtor); - if (status != ANI_OK) { - APP_LOGE("Class_FindMethod failed %{public}d", status); - return nullptr; - } - ani_size length = nativeArray.size(); - ani_object arrayObj; - status = env->Object_New(arrayCls, arrayCtor, &arrayObj, length); - if (status != ANI_OK) { - APP_LOGE("Object_New failed %{public}d", status); - return nullptr; - } + ani_value arg = { .i = static_cast(length) }; + ani_object arrayObj = CreateNewObjectByClassV2(env, CommonFunAniNS::CLASSNAME_ARRAY, "i:", &arg); + RETURN_NULL_IF_NULL(arrayObj); - ani_size i = 0; + ani_status status = ANI_OK; + ani_int i = 0; for (const auto& iter : nativeArray) { ani_object item = converter(env, iter, std::forward(args)...); RETURN_NULL_IF_NULL(item); - status = env->Object_CallMethodByName_Void(arrayObj, "$_set", "ILstd/core/Object;:V", i, item); + status = env->Object_CallMethodByName_Void(arrayObj, "$_set", "iC{std.core.Object}:", i, item); env->Reference_Delete(item); if (status != ANI_OK) { APP_LOGE("Object_CallMethodByName_Void failed %{public}d", status); @@ -350,7 +350,7 @@ public: } for (ani_int i = 0; i < static_cast(length); ++i) { ani_ref ref; - status = env->Object_CallMethodByName_Ref(aniArray, "$_get", "I:Lstd/core/Object;", &ref, i); + status = env->Object_CallMethodByName_Ref(aniArray, "$_get", "i:C{std.core.Object}", &ref, i); if (status != ANI_OK) { APP_LOGE("Object_CallMethodByName_Ref failed %{public}d", status); return false; @@ -395,21 +395,41 @@ public: status = env->Object_GetPropertyByName_Ref(object, propertyName, reinterpret_cast(value)); } else if constexpr (std::is_same_v) { status = env->Object_GetPropertyByName_Boolean(object, propertyName, value); - } else if constexpr (std::is_same_v) { - status = env->Object_GetPropertyByName_Char(object, propertyName, value); - } else if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v) { - // uint64_t -> BigInt later + } else if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v) { + ani_int i = 0; + status = env->Object_GetPropertyByName_Int(object, propertyName, &i); + if (status != ANI_OK) { + APP_LOGE("Object_GetPropertyByName %{public}s failed %{public}d", propertyName, status); + return false; + } + if (!TryCastTo(i, value)) { + APP_LOGE("TryCastTo %{public}s failed", propertyName); + return false; + } + return true; + } else if constexpr (std::is_same_v || std::is_same_v) { + ani_long l = 0; + status = env->Object_GetPropertyByName_Long(object, propertyName, &l); + if (status != ANI_OK) { + APP_LOGE("Object_GetPropertyByName %{public}s failed %{public}d", propertyName, status); + return false; + } + if (!TryCastTo(l, value)) { + APP_LOGE("TryCastTo %{public}s failed", propertyName); + return false; + } + return true; + } else if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v) { double d = 0; status = env->Object_GetPropertyByName_Double(object, propertyName, &d); if (status != ANI_OK) { APP_LOGE("Object_GetPropertyByName %{public}s failed %{public}d", propertyName, status); return false; } - if (!TryCastDoubleTo(d, value)) { - APP_LOGE("TryCastDoubleTo %{public}s failed", propertyName); + if (!TryCastTo(d, value)) { + APP_LOGE("TryCastTo %{public}s failed", propertyName); return false; } return true; @@ -455,23 +475,45 @@ public: status = ANI_ERROR; if constexpr (std::is_same_v) { status = env->Object_CallMethodByName_Boolean( - reinterpret_cast(ref), "unboxed", ":Z", value); - } else if constexpr (std::is_same_v) { - status = env->Object_CallMethodByName_Char(reinterpret_cast(ref), "unboxed", ":C", value); - } else if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v || - std::is_same_v || std::is_same_v) { + reinterpret_cast(ref), CommonFunAniNS::PROPERTYNAME_UNBOXED, ":z", value); + } else if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v) { + ani_int i = 0; + status = env->Object_CallMethodByName_Int( + reinterpret_cast(ref), CommonFunAniNS::PROPERTYNAME_UNBOXED, ":i", &i); + if (status != ANI_OK) { + APP_LOGE("Object_CallMethodByName_Int %{public}s failed %{public}d", propertyName, status); + return false; + } + if (!TryCastTo(i, value)) { + APP_LOGE("TryCastTo %{public}s failed", propertyName); + return false; + } + return true; + } else if constexpr (std::is_same_v || std::is_same_v) { + ani_long l = 0; + status = env->Object_CallMethodByName_Long( + reinterpret_cast(ref), CommonFunAniNS::PROPERTYNAME_UNBOXED, ":l", &l); + if (status != ANI_OK) { + APP_LOGE("Object_CallMethodByName_Long %{public}s failed %{public}d", propertyName, status); + return false; + } + if (!TryCastTo(l, value)) { + APP_LOGE("TryCastTo %{public}s failed", propertyName); + return false; + } + return true; + } else if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v) { double d = 0; - status = - env->Object_CallMethodByName_Double(reinterpret_cast(ref), "unboxed", nullptr, &d); + status = env->Object_CallMethodByName_Double( + reinterpret_cast(ref), CommonFunAniNS::PROPERTYNAME_UNBOXED, ":d", &d); if (status != ANI_OK) { - APP_LOGE("Object_GetPropertyByName %{public}s failed %{public}d", propertyName, status); + APP_LOGE("Object_CallMethodByName_Double %{public}s failed %{public}d", propertyName, status); return false; } - *value = static_cast(d); - if (!TryCastDoubleTo(d, value)) { - APP_LOGE("TryCastDoubleTo %{public}s failed", propertyName); + if (!TryCastTo(d, value)) { + APP_LOGE("TryCastTo %{public}s failed", propertyName); return false; } return true; @@ -489,156 +531,185 @@ public: } template - static bool CallSetField(ani_env *env, ani_class cls, ani_object object, const char *name, valueType* value) + static bool CallGetFieldOptional(ani_env *env, ani_object object, const char *name, valueType* value) { RETURN_FALSE_IF_NULL(env); - RETURN_FALSE_IF_NULL(cls); + RETURN_FALSE_IF_NULL(object); - ani_field field = nullptr; - ani_status status = env->Class_FindField(cls, name, &field); + ani_ref ref = nullptr; + ani_status status = env->Object_GetFieldByName_Ref(object, name, &ref); if (status != ANI_OK) { APP_LOGE("Class_FindField %{public}s failed %{public}d", name, status); return false; } - status = env->Object_SetField_Ref(object, field, value); + + ani_boolean isUndefined; + status = env->Reference_IsUndefined(ref, &isUndefined); if (status != ANI_OK) { - APP_LOGE("Object_SetField_Ref %{public}s failed %{public}d", name, status); + APP_LOGE("Reference_IsUndefined %{public}s failed %{public}d", name, status); return false; } + if (isUndefined) { + return false; + } + + if constexpr (std::is_pointer_v && std::is_base_of_v<__ani_ref, std::remove_pointer_t>) { + *value = reinterpret_cast(ref); + } else { + status = ANI_ERROR; + if constexpr (std::is_same_v) { + ani_double d = 0; + status = env->Object_CallMethodByName_Double( + reinterpret_cast(ref), CommonFunAniNS::PROPERTYNAME_UNBOXED, ":d", &d); + if (status != ANI_OK) { + APP_LOGE("Object_CallMethodByName_Double %{public}s failed %{public}d", name, status); + return false; + } + if (!TryCastTo(d, value)) { + APP_LOGE("TryCastTo %{public}s failed", name); + return false; + } + return true; + } else { + APP_LOGE("Object_CallMethodByName %{public}s Unsupported", name); + return false; + } + } + return true; } template - static bool CallSetter(ani_env* env, ani_class cls, ani_object object, const char* propertyName, valueType value) + static bool CallSetField(ani_env *env, ani_class cls, ani_object object, const char *name, valueType* value) { RETURN_FALSE_IF_NULL(env); RETURN_FALSE_IF_NULL(cls); - RETURN_FALSE_IF_NULL(object); - std::string setterName(""); - setterName.append(propertyName); - ani_method setter; - ani_status status = env->Class_FindMethod(cls, setterName.c_str(), nullptr, &setter); + ani_field field = nullptr; + ani_status status = env->Class_FindField(cls, name, &field); if (status != ANI_OK) { - APP_LOGE("Class_FindMethod %{public}s failed %{public}d", propertyName, status); + APP_LOGE("Class_FindField %{public}s failed %{public}d", name, status); return false; } - - if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v || - std::is_same_v || std::is_same_v) { - status = env->Object_CallMethod_Void(object, setter, static_cast(value)); - } else { - status = env->Object_CallMethod_Void(object, setter, value); - } - + status = env->Object_SetField_Ref(object, field, value); if (status != ANI_OK) { - APP_LOGE("Object_CallMethod_Void %{public}s failed %{public}d", propertyName, status); + APP_LOGE("Object_SetField_Ref %{public}s failed %{public}d", name, status); return false; } - return true; } - // sets property to null - static bool CallSetterNull(ani_env* env, ani_class cls, ani_object object, const char* propertyName) + template + static bool CallSetter(ani_env* env, ani_class cls, ani_object object, const char* propertyName, valueType value, + const char* valueClassName = nullptr) { RETURN_FALSE_IF_NULL(env); RETURN_FALSE_IF_NULL(cls); RETURN_FALSE_IF_NULL(object); - ani_ref nullRef = nullptr; - ani_status status = env->GetNull(&nullRef); - if (status != ANI_OK) { - APP_LOGE("GetNull %{public}s failed %{public}d", propertyName, status); + std::string setterSig; + ani_value setterParam { }; + if constexpr (std::is_same_v) { + setterSig = "z:"; + setterParam.z = value; + } else if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v) { + setterSig = "i:"; + setterParam.i = static_cast(value); + } else if constexpr (std::is_same_v || std::is_same_v) { + setterSig = "l:"; + setterParam.l = static_cast(value); + } else if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v) { + setterSig = "d:"; + setterParam.d = static_cast(value); + } else if constexpr (std::is_pointer_v && + std::is_base_of_v<__ani_ref, std::remove_pointer_t>) { + if constexpr (std::is_same_v) { + valueClassName = CommonFunAniNS::CLASSNAME_STRING; + } + if (valueClassName != nullptr) { + setterSig.append("C{"); + setterSig.append(valueClassName); + setterSig.append("}:"); + } + setterParam.r = value; + } else { + APP_LOGE("Classname %{public}s Unsupported", propertyName); return false; } - return CallSetter(env, cls, object, propertyName, nullRef); - } - - // sets optional property to undefined - static bool CallSetterOptionalUndefined(ani_env* env, ani_class cls, ani_object object, const char* propertyName) - { - RETURN_FALSE_IF_NULL(env); - RETURN_FALSE_IF_NULL(cls); - RETURN_FALSE_IF_NULL(object); + std::string setterName(""); + setterName.append(propertyName); + ani_method setter; + ani_status status = + env->Class_FindMethod(cls, setterName.c_str(), setterSig.empty() ? nullptr : setterSig.c_str(), &setter); + if (status != ANI_OK) { + APP_LOGE("Class_FindMethod %{public}s failed %{public}d", propertyName, status); + return false; + } - ani_ref undefined = nullptr; - ani_status status = env->GetUndefined(&undefined); + status = env->Object_CallMethod_Void_A(object, setter, &setterParam); if (status != ANI_OK) { - APP_LOGE("GetUndefined %{public}s failed %{public}d", propertyName, status); + APP_LOGE("Object_CallMethod_Void_A %{public}s failed %{public}d", propertyName, status); return false; } - return CallSetter(env, cls, object, propertyName, undefined); + return true; } template - static bool CallSetterOptional( - ani_env* env, ani_class cls, ani_object object, const char* propertyName, valueType value) + static ani_object BoxValue(ani_env* env, valueType value, const char** pValueClassName = nullptr) { - RETURN_FALSE_IF_NULL(env); - RETURN_FALSE_IF_NULL(cls); - RETURN_FALSE_IF_NULL(object); - - if constexpr (std::is_pointer_v && std::is_base_of_v<__ani_ref, std::remove_pointer_t>) { - return CallSetter(env, cls, object, propertyName, value); - } + RETURN_NULL_IF_NULL(env); const char* valueClassName = nullptr; - const char* ctorSig = nullptr; + std::string ctorSig; + ani_value ctorParam { }; if constexpr (std::is_same_v) { - valueClassName = "Lstd/core/Boolean;"; - ctorSig = "Z:V"; - } else if constexpr (std::is_same_v) { - valueClassName = "Lstd/core/Char;"; - ctorSig = "C:V"; - } else if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v || - std::is_same_v || std::is_same_v) { - valueClassName = "Lstd/core/Double;"; - ctorSig = "D:V"; + valueClassName = CommonFunAniNS::CLASSNAME_BOOLEAN; + ctorSig = "z:"; + ctorParam.z = value; + } else if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v) { + valueClassName = CommonFunAniNS::CLASSNAME_INT; + ctorSig = "i:"; + ctorParam.i = static_cast(value); + } else if constexpr (std::is_same_v || std::is_same_v) { + valueClassName = CommonFunAniNS::CLASSNAME_LONG; + ctorSig = "l:"; + ctorParam.l = static_cast(value); + } else if constexpr (std::is_same_v || std::is_same_v || + std::is_same_v) { + valueClassName = CommonFunAniNS::CLASSNAME_DOUBLE; + ctorSig = "d:"; + ctorParam.d = static_cast(value); } else { - APP_LOGE("Classname %{public}s Unsupported", propertyName); - return false; + APP_LOGE("Type Unsupported"); + return nullptr; } - - ani_class valueClass = nullptr; - ani_status status = env->FindClass(valueClassName, &valueClass); - if (status != ANI_OK) { - APP_LOGE("FindClass %{public}s %{public}s failed %{public}d", propertyName, valueClassName, status); - return false; + if (pValueClassName != nullptr) { + *pValueClassName = valueClassName; } + ani_class valueClass = CreateClassByName(env, valueClassName); + RETURN_NULL_IF_NULL(valueClass); + ani_method ctor = nullptr; - status = env->Class_FindMethod(valueClass, "", ctorSig, &ctor); + ani_status status = env->Class_FindMethod(valueClass, "", ctorSig.c_str(), &ctor); if (status != ANI_OK) { - APP_LOGE("Class_FindMethod %{public}s failed %{public}d", propertyName, status); - return false; + APP_LOGE("Class_FindMethod failed %{public}d", status); + return nullptr; } ani_object valueObj = nullptr; - if constexpr (std::is_same_v || std::is_same_v) { - status = env->Object_New(valueClass, ctor, &valueObj, value); - } else if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v || std::is_same_v || - std::is_same_v) { - status = env->Object_New(valueClass, ctor, &valueObj, static_cast(value)); - } else { - APP_LOGE("Classname %{public}s Unsupported", propertyName); - return false; - } - + status = env->Object_New_A(valueClass, ctor, &valueObj, &ctorParam); if (status != ANI_OK) { - APP_LOGE("Object_New %{public}s failed %{public}d", propertyName, status); - return false; + APP_LOGE("Object_New failed %{public}d", status); + return nullptr; } - return CallSetter(env, cls, object, propertyName, valueObj); + return valueObj; } }; } // namespace AppExecFwk diff --git a/interfaces/kits/ani/common/enum_util.h b/interfaces/kits/ani/common/enum_util.h index b3ebdefc58..b6cfc6e0ca 100644 --- a/interfaces/kits/ani/common/enum_util.h +++ b/interfaces/kits/ani/common/enum_util.h @@ -27,30 +27,38 @@ namespace AppExecFwk { namespace CommonFunAniNS { constexpr int32_t UNSPECIFIED = 255; -constexpr const char* CLASSNAME_BUNDLEMANAGER_BUNDLE_FLAG = "L@ohos/bundle/bundleManager/bundleManager/BundleFlag;"; -constexpr const char* CLASSNAME_BUNDLEMANAGER_BUNDLE_TYPE = "L@ohos/bundle/bundleManager/bundleManager/BundleType;"; -constexpr const char* CLASSNAME_BUNDLEMANAGER_MULTIAPPMODE_TYPE = - "L@ohos/bundle/bundleManager/bundleManager/MultiAppModeType;"; -constexpr const char* CLASSNAME_BUNDLEMANAGER_DISPLAYORIENTATION = - "L@ohos/bundle/bundleManager/bundleManager/DisplayOrientation;"; -constexpr const char* CLASSNAME_BUNDLEMANAGER_LAUNCH_TYPE = "L@ohos/bundle/bundleManager/bundleManager/LaunchType;"; -constexpr const char* CLASSNAME_BUNDLEMANAGER_SUPPORTWINDOWMODE = - "L@ohos/bundle/bundleManager/bundleManager/SupportWindowMode;"; -constexpr const char* CLASSNAME_BUNDLEMANAGER_EXTENSIONABILITY_TYPE = - "L@ohos/bundle/bundleManager/bundleManager/ExtensionAbilityType;"; -constexpr const char* CLASSNAME_BUNDLEMANAGER_MODULE_TYPE = "L@ohos/bundle/bundleManager/bundleManager/ModuleType;"; -constexpr const char* CLASSNAME_BUNDLEMANAGER_PERMISSIONGRANTSTATE = - "L@ohos/bundle/bundleManager/bundleManager/PermissionGrantState;"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_BUNDLE_FLAG = "@ohos.bundle.bundleManager.bundleManager.BundleFlag"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_BUNDLE_TYPE = "@ohos.bundle.bundleManager.bundleManager.BundleType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_MULTI_APP_MODE_TYPE = + "@ohos.bundle.bundleManager.bundleManager.MultiAppModeType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_DISPLAY_ORIENTATION = + "@ohos.bundle.bundleManager.bundleManager.DisplayOrientation"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_LAUNCH_TYPE = "@ohos.bundle.bundleManager.bundleManager.LaunchType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_SUPPORT_WINDOW_MODE = + "@ohos.bundle.bundleManager.bundleManager.SupportWindowMode"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_EXTENSION_ABILITY_TYPE = + "@ohos.bundle.bundleManager.bundleManager.ExtensionAbilityType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_MODULE_TYPE = "@ohos.bundle.bundleManager.bundleManager.ModuleType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_PERMISSION_GRANT_STATE = + "@ohos.bundle.bundleManager.bundleManager.PermissionGrantState"; constexpr const char* CLASSNAME_BUNDLEMANAGER_APPLICATION_FLAG = - "L@ohos/bundle/bundleManager/bundleManager/ApplicationFlag;"; -constexpr const char* CLASSNAME_BUNDLE_DISPLAYORIENTATION = "L@ohos/bundle/bundle/DisplayOrientation;"; -constexpr const char* CLASSNAME_BUNDLE_ABILITY_TYPE = "L@ohos/bundle/bundle/AbilityType;"; -constexpr const char* CLASSNAME_BUNDLE_ABILITYSUB_TYPE = "L@ohos/bundle/bundle/AbilitySubType;"; -constexpr const char* CLASSNAME_BUNDLE_LAUNCHMODE = "L@ohos/bundle/bundle/LaunchMode;"; -constexpr const char* CLASSNAME_ZLIB_COMPRESSLEVEL = "L@ohos/zlib/zlib/CompressLevel;"; -constexpr const char* CLASSNAME_ZLIB_MEMLEVEL = "L@ohos/zlib/zlib/MemLevel;"; -constexpr const char* CLASSNAME_ZLIB_COMPRESSSTRATEGY = "L@ohos/zlib/zlib/CompressStrategy;"; + "@ohos.bundle.bundleManager.bundleManager.ApplicationFlag"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_COMPATIBLE_POLICY = + "@ohos.bundle.bundleManager.bundleManager.CompatiblePolicy"; +constexpr const char* CLASSNAME_BUNDLE_DISPLAY_ORIENTATION = "@ohos.bundle.bundle.DisplayOrientation"; +constexpr const char* CLASSNAME_BUNDLE_ABILITY_TYPE = "@ohos.bundle.bundle.AbilityType"; +constexpr const char* CLASSNAME_BUNDLE_ABILITY_SUB_TYPE = "@ohos.bundle.bundle.AbilitySubType"; +constexpr const char* CLASSNAME_BUNDLE_LAUNCH_MODE = "@ohos.bundle.bundle.LaunchMode"; +constexpr const char* CLASSNAME_ZLIB_COMPRESS_LEVEL = "@ohos.zlib.zlib.CompressLevel"; +constexpr const char* CLASSNAME_ZLIB_MEM_LEVEL = "@ohos.zlib.zlib.MemLevel"; +constexpr const char* CLASSNAME_ZLIB_COMPRESS_STRATEGY = "@ohos.zlib.zlib.CompressStrategy"; constexpr const char* CLASSNAME_ZLIB_PATHSEPARATORSTRATRGY = "L@ohos/zlib/zlib/PathSeparatorStrategy;"; +constexpr const char* CLASSNAME_ZLIB_RETURN_STATUS = "@ohos.zlib.zlib.ReturnStatus"; +constexpr const char* CLASSNAME_APPCONTROL_COMPONENT_TYPE = "@ohos.bundle.appControl.appControl.ComponentType"; +constexpr const char* CLASSNAME_APPCONTROL_DISPOSED_TYPE = "@ohos.bundle.appControl.appControl.DisposedType"; +constexpr const char* CLASSNAME_APPCONTROL_CONTROL_TYPE = "@ohos.bundle.appControl.appControl.ControlType"; +constexpr const char* CLASSNAME_APPCONTROL_UNINSTALL_COMPONENT_TYPE = + "@ohos.bundle.appControl.appControl.UninstallComponentType"; } // namespace CommonFunAniNS class EnumUtils { private: @@ -243,6 +251,27 @@ private: 9, 8, }; + /* zlib.ReturnStatus + enum ReturnStatus { + OK = 0, + STREAM_END = 1, + NEED_DICT = 2, + ERRNO = -1, + STREAM_ERROR = -2, + DATA_ERROR = -3, + MEM_ERROR = -4, + BUF_ERROR = -5 + } */ + static constexpr std::array Array_Zlib_ReturnStatus = { + 0, + 1, + 2, + -1, + -2, + -3, + -4, + -5 + }; public: template @@ -294,7 +323,7 @@ public: } */ static inline ani_enum_item EnumNativeToETS_BundleManager_MultiAppModeType(ani_env* env, const int32_t value) { - return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_MULTIAPPMODE_TYPE, value, 0); + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_MULTI_APP_MODE_TYPE, value, 0); } /* bundleManager.DisplayOrientation @@ -317,7 +346,7 @@ public: } */ static inline ani_enum_item EnumNativeToETS_BundleManager_DisplayOrientation(ani_env* env, const int32_t value) { - return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_DISPLAYORIENTATION, value, 0); + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_DISPLAY_ORIENTATION, value, 0); } /* bundleManager.LaunchType @@ -339,7 +368,7 @@ public: } */ static inline ani_enum_item EnumNativeToETS_BundleManager_SupportWindowMode(ani_env* env, const int32_t value) { - return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_SUPPORTWINDOWMODE, value, 0); + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_SUPPORT_WINDOW_MODE, value, 0); } // bundleManager.ExtensionAbilityType @@ -348,7 +377,7 @@ public: bool isValid = std::find(std::begin(Array_BundleManager_ExtensionAbilityType), std::end(Array_BundleManager_ExtensionAbilityType), value) != std::end(Array_BundleManager_ExtensionAbilityType); - return EnumNativeToETSByTable(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_EXTENSIONABILITY_TYPE, + return EnumNativeToETSByTable(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_EXTENSION_ABILITY_TYPE, isValid ? value : CommonFunAniNS::UNSPECIFIED, Array_BundleManager_ExtensionAbilityType); } @@ -370,7 +399,7 @@ public: } */ static inline ani_enum_item EnumNativeToETS_BundleManager_PermissionGrantState(ani_env* env, const int32_t value) { - return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_PERMISSIONGRANTSTATE, value, -1); + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_PERMISSION_GRANT_STATE, value, -1); } // bundleManager.ApplicationFlag @@ -380,6 +409,15 @@ public: env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_APPLICATION_FLAG, value, Array_BundleManager_ApplicationFlag); } + /* bundleManager.CompatiblePolicy + enum CompatiblePolicy { + BACKWARD_COMPATIBILITY = 1 + } */ + static inline ani_enum_item EnumNativeToETS_BundleManager_CompatiblePolicy(ani_env* env, const int32_t value) + { + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLEMANAGER_COMPATIBLE_POLICY, value, 1); + } + /* bundle.DisplayOrientation enum DisplayOrientation { UNSPECIFIED, @@ -389,7 +427,7 @@ public: } */ static inline ani_enum_item EnumNativeToETS_Bundle_DisplayOrientation(ani_env* env, const int32_t value) { - return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLE_DISPLAYORIENTATION, value, 0); + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLE_DISPLAY_ORIENTATION, value, 0); } /* bundle.AbilityType @@ -411,7 +449,7 @@ public: } */ static inline ani_enum_item EnumNativeToETS_Bundle_AbilitySubType(ani_env* env, const int32_t value) { - return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLE_ABILITYSUB_TYPE, value, 0); + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLE_ABILITY_SUB_TYPE, value, 0); } /* bundle.LaunchMode @@ -421,20 +459,20 @@ public: } */ static inline ani_enum_item EnumNativeToETS_Bundle_LaunchMode(ani_env* env, const int32_t value) { - return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLE_LAUNCHMODE, value, 0); + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_BUNDLE_LAUNCH_MODE, value, 0); } // zlib.CompressLevel static inline ani_enum_item EnumNativeToETS_Zlib_CompressLevel(ani_env* env, const int32_t value) { return EnumNativeToETSByTable( - env, CommonFunAniNS::CLASSNAME_ZLIB_COMPRESSLEVEL, value, Array_Zlib_CompressLevel); + env, CommonFunAniNS::CLASSNAME_ZLIB_COMPRESS_LEVEL, value, Array_Zlib_CompressLevel); } // zlib.MemLevel static inline ani_enum_item EnumNativeToETS_Zlib_MemLevel(ani_env* env, const int32_t value) { - return EnumNativeToETSByTable(env, CommonFunAniNS::CLASSNAME_ZLIB_MEMLEVEL, value, Array_Zlib_MemLevel); + return EnumNativeToETSByTable(env, CommonFunAniNS::CLASSNAME_ZLIB_MEM_LEVEL, value, Array_Zlib_MemLevel); } /* zlib.CompressStrategy @@ -447,7 +485,54 @@ public: } */ static inline ani_enum_item EnumNativeToETS_Zlib_CompressStrategy(ani_env* env, const int32_t value) { - return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_ZLIB_COMPRESSSTRATEGY, value, 0); + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_ZLIB_COMPRESS_STRATEGY, value, 0); + } + + // zlib.ReturnStatus + static inline ani_enum_item EnumNativeToETS_Zlib_ReturnStatus(ani_env* env, const int32_t value) + { + return EnumNativeToETSByTable(env, + CommonFunAniNS::CLASSNAME_ZLIB_RETURN_STATUS, value, Array_Zlib_ReturnStatus); + } + + /* appControl.ComponentType + enum ComponentType { + UI_ABILITY = 1, + UI_EXTENSION = 2 + } */ + static inline ani_enum_item EnumNativeToETS_AppControl_ComponentType(ani_env* env, const int32_t value) + { + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_APPCONTROL_COMPONENT_TYPE, value, 1); + } + + /* appControl.DisposedType + enum DisposedType { + BLOCK_APPLICATION = 1, + BLOCK_ABILITY = 2, + NON_BLOCK = 3 + } */ + static inline ani_enum_item EnumNativeToETS_AppControl_DisposedType(ani_env* env, const int32_t value) + { + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_APPCONTROL_DISPOSED_TYPE, value, 1); + } + + /* appControl.ControlType + enum ControlType { + ALLOWED_LIST = 1, + DISALLOWED_LIST = 2 + } */ + static inline ani_enum_item EnumNativeToETS_AppControl_ControlType(ani_env* env, const int32_t value) + { + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_APPCONTROL_CONTROL_TYPE, value, 1); + } + + /* appControl.UninstallComponentType + enum UninstallComponentType { + EXTENSION = 1, + } */ + static inline ani_enum_item EnumNativeToETS_AppControl_UninstallComponentType(ani_env* env, const int32_t value) + { + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_APPCONTROL_UNINSTALL_COMPONENT_TYPE, value, 1); } /* zlib.PathSeparatorStrategy diff --git a/interfaces/kits/ani/default_app_manager/BUILD.gn b/interfaces/kits/ani/default_app_manager/BUILD.gn new file mode 100644 index 0000000000..7de2fd59d6 --- /dev/null +++ b/interfaces/kits/ani/default_app_manager/BUILD.gn @@ -0,0 +1,98 @@ +# 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/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") + +ohos_shared_library("ani_default_app_manager") { + shlib_type = "ani" + branch_protector_ret = "pac_ret" + + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + integer_overflow = true + ubsan = true + } + + include_dirs = [ + "${inner_api_path}/appexecfwk_core/include", + "${kits_path}/ani/common", + "${kits_path}/js/common", + ] + defines = [ + "APP_LOG_TAG = \"BMS\"", + "LOG_DOMAIN = 0xD001120", + ] + + cflags = [ + "-Os", + "-fstack-protector-strong", + ] + + cflags_cc = [ + "-Os", + "-fstack-protector-strong", + ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + "${kits_path}/ani/common:bms_ani_common", + "${kits_path}/js/common:bundle_napi_common", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + "runtime_core:ani", + "runtime_core:ani_helpers", + "samgr:samgr_proxy", + ] + + if (bundle_framework_default_app) { + sources = [ "ani_default_app_manager.cpp" ] + defines += [ "BUNDLE_FRAMEWORK_DEFAULT_APP" ] + } else { + sources = [ "ani_default_app_manager_unsupported.cpp" ] + } + + if (bundle_framework_graphics) { + defines += [ "BUNDLE_FRAMEWORK_GRAPHICS" ] + } + + subsystem_name = "bundlemanager" + part_name = "bundle_framework" +} + +generate_static_abc("default_app_manager") { + base_url = "./ets" + files = [ "./ets/@ohos.bundle.defaultAppManager.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/default_app_manager.abc" +} + +ohos_prebuilt_etc("default_app_manager_etc") { + source = "$target_out_dir/default_app_manager.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":default_app_manager" ] +} diff --git a/interfaces/kits/ani/default_app_manager/ani_default_app_manager.cpp b/interfaces/kits/ani/default_app_manager/ani_default_app_manager.cpp new file mode 100644 index 0000000000..18ec444a3f --- /dev/null +++ b/interfaces/kits/ani/default_app_manager/ani_default_app_manager.cpp @@ -0,0 +1,225 @@ +/* + * 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 + +#include "app_log_wrapper.h" +#include "bundle_errors.h" +#include "bundle_mgr_interface.h" +#include "business_error_ani.h" +#include "common_func.h" +#include "common_fun_ani.h" +#include "ipc_skeleton.h" +#include "napi_constants.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace OHOS::AAFwk; +namespace { +constexpr const char* NS_NAME_DEFAULTAPPMANAGER = "@ohos.bundle.defaultAppManager.defaultAppManager"; +constexpr int32_t EMPTY_USER_ID = -500; +} // namespace + +static bool ParseType(ani_env *env, ani_string aniType, std::string& result) +{ + if (!CommonFunAni::ParseString(env, aniType, result)) { + APP_LOGE("parse type failed"); + return false; + } + if (TYPE_MAPPING.find(result) != TYPE_MAPPING.end()) { + result = TYPE_MAPPING.at(result); + } + return true; +} + +static ani_boolean AniIsDefaultApplication(ani_env *env, ani_string aniType, ani_boolean aniIsSync) +{ + APP_LOGD("ani IsDefaultApplication called"); + std::string type; + if (!ParseType(env, aniType, type)) { + APP_LOGE("type invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, TYPE_CHECK, TYPE_STRING); + return false; + } + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); + if (defaultAppProxy == nullptr) { + APP_LOGE("defaultAppProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, + isSync ? IS_DEFAULT_APPLICATION_SYNC : IS_DEFAULT_APPLICATION, ""); + return false; + } + + bool isDefaultApp = false; + ErrCode ret = defaultAppProxy->IsDefaultApplication(type, isDefaultApp); + if (ret != ERR_OK) { + APP_LOGE("IsDefaultApplication failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + isSync ? IS_DEFAULT_APPLICATION_SYNC : IS_DEFAULT_APPLICATION, ""); + return false; + } + + return CommonFunAni::BoolToAniBoolean(isDefaultApp); +} + +static ani_object AniGetDefaultApplication(ani_env *env, + ani_string aniType, ani_int aniUserId, ani_boolean aniIsSync) +{ + APP_LOGD("ani GetDefaultApplication called"); + std::string type; + if (!ParseType(env, aniType, type)) { + APP_LOGE("type invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, TYPE_CHECK, TYPE_STRING); + return nullptr; + } + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + } + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); + if (defaultAppProxy == nullptr) { + APP_LOGE("defaultAppProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, + isSync ? GET_DEFAULT_APPLICATION_SYNC : GET_DEFAULT_APPLICATION, + isSync ? "" : Constants::PERMISSION_GET_DEFAULT_APPLICATION); + return nullptr; + } + + BundleInfo bundleInfo; + ErrCode ret = defaultAppProxy->GetDefaultApplication(aniUserId, type, bundleInfo); + if (ret != ERR_OK) { + APP_LOGE("GetDefaultApplication failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + isSync ? GET_DEFAULT_APPLICATION_SYNC : GET_DEFAULT_APPLICATION, + Constants::PERMISSION_GET_DEFAULT_APPLICATION); + return nullptr; + } + + return CommonFunAni::ConvertDefaultAppBundleInfo(env, bundleInfo); +} + +static void AniSetDefaultApplication(ani_env *env, + ani_string aniType, ani_object aniElementName, ani_int aniUserId, ani_boolean aniIsSync) +{ + APP_LOGD("ani SetDefaultApplication called"); + std::string type; + if (!ParseType(env, aniType, type)) { + APP_LOGE("type invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, TYPE_CHECK, TYPE_STRING); + return; + } + ElementName elementName; + if (!CommonFunAni::ParseElementName(env, aniElementName, elementName)) { + APP_LOGE("ParseElementName failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, WANT_CHECK, TYPE_OBJECT); + return; + } + Want want; + want.SetElement(elementName); + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + } + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); + if (defaultAppProxy == nullptr) { + APP_LOGE("defaultAppProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, + isSync ? SET_DEFAULT_APPLICATION_SYNC : SET_DEFAULT_APPLICATION, + isSync ? "" : Constants::PERMISSION_SET_DEFAULT_APPLICATION); + return; + } + + ErrCode ret = defaultAppProxy->SetDefaultApplication(aniUserId, type, want); + if (ret != ERR_OK) { + APP_LOGE("SetDefaultApplication failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + isSync ? SET_DEFAULT_APPLICATION_SYNC : SET_DEFAULT_APPLICATION, + Constants::PERMISSION_SET_DEFAULT_APPLICATION); + } +} + +static void AniResetDefaultApplication(ani_env *env, ani_string aniType, ani_int aniUserId, ani_boolean aniIsSync) +{ + APP_LOGD("ani ResetDefaultApplication called"); + std::string type; + if (!ParseType(env, aniType, type)) { + APP_LOGE("type invalid"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, TYPE_CHECK, TYPE_STRING); + return; + } + if (aniUserId == EMPTY_USER_ID) { + aniUserId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + } + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); + if (defaultAppProxy == nullptr) { + APP_LOGE("defaultAppProxy is null"); + BusinessErrorAni::ThrowCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, + isSync ? RESET_DEFAULT_APPLICATION_SYNC : RESET_DEFAULT_APPLICATION, + isSync ? "" : Constants::PERMISSION_SET_DEFAULT_APPLICATION); + return; + } + + ErrCode ret = defaultAppProxy->ResetDefaultApplication(aniUserId, type); + if (ret != ERR_OK) { + APP_LOGE("ResetDefaultApplication failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + isSync ? RESET_DEFAULT_APPLICATION_SYNC : RESET_DEFAULT_APPLICATION, + Constants::PERMISSION_SET_DEFAULT_APPLICATION); + } +} + +extern "C" { +ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) +{ + APP_LOGI("ANI_Constructor defaultAppManager called"); + ani_env* env; + ani_status status = vm->GetEnv(ANI_VERSION_1, &env); + RETURN_ANI_STATUS_IF_NOT_OK(status, "Unsupported ANI_VERSION_1"); + + arkts::ani_signature::Namespace nsName = arkts::ani_signature::Builder::BuildNamespace(NS_NAME_DEFAULTAPPMANAGER); + ani_namespace kitNs = nullptr; + status = env->FindNamespace(nsName.Descriptor().c_str(), &kitNs); + if (status != ANI_OK) { + APP_LOGE("FindNamespace: %{public}s fail with %{public}d", NS_NAME_DEFAULTAPPMANAGER, status); + return status; + } + + std::array methods = { + ani_native_function { "isDefaultApplicationNative", nullptr, reinterpret_cast(AniIsDefaultApplication) }, + ani_native_function { "getDefaultApplicationNative", nullptr, + reinterpret_cast(AniGetDefaultApplication) }, + ani_native_function { "setDefaultApplicationNative", nullptr, + reinterpret_cast(AniSetDefaultApplication) }, + ani_native_function { "resetDefaultApplicationNative", nullptr, + reinterpret_cast(AniResetDefaultApplication) } + }; + + status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); + if (status != ANI_OK) { + APP_LOGE( + "Namespace_BindNativeFunctions: %{public}s fail with %{public}d", NS_NAME_DEFAULTAPPMANAGER, status); + return status; + } + + *result = ANI_VERSION_1; + + APP_LOGI("ANI_Constructor finished"); + + return ANI_OK; +} +} +} // AppExecFwk +} // OHOS \ No newline at end of file diff --git a/interfaces/kits/ani/default_app_manager/ani_default_app_manager_unsupported.cpp b/interfaces/kits/ani/default_app_manager/ani_default_app_manager_unsupported.cpp new file mode 100644 index 0000000000..2b97d25250 --- /dev/null +++ b/interfaces/kits/ani/default_app_manager/ani_default_app_manager_unsupported.cpp @@ -0,0 +1,107 @@ +/* + * 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 + +#include "app_log_wrapper.h" +#include "bundle_errors.h" +#include "business_error_ani.h" +#include "common_fun_ani.h" +#include "napi_constants.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +constexpr const char* NS_NAME_DEFAULTAPPMANAGER = "@ohos.bundle.defaultAppManager.defaultAppManager"; +} // namespace + +static ani_boolean AniIsDefaultApplication(ani_env *env, ani_string aniType, ani_boolean aniIsSync) +{ + APP_LOGI("SystemCapability.BundleManager.BundleFramework.DefaultApp not supported"); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? IS_DEFAULT_APPLICATION_SYNC : IS_DEFAULT_APPLICATION, ""); + return false; +} + +static ani_object AniGetDefaultApplication(ani_env *env, + ani_string aniType, ani_int aniUserId, ani_boolean aniIsSync) +{ + APP_LOGI("SystemCapability.BundleManager.BundleFramework.DefaultApp not supported"); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? GET_DEFAULT_APPLICATION_SYNC : GET_DEFAULT_APPLICATION, ""); + return nullptr; +} + +static void AniSetDefaultApplication(ani_env *env, + ani_string aniType, ani_object aniElementName, ani_int aniUserId, ani_boolean aniIsSync) +{ + APP_LOGI("SystemCapability.BundleManager.BundleFramework.DefaultApp not supported"); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? SET_DEFAULT_APPLICATION_SYNC : SET_DEFAULT_APPLICATION, ""); +} + +static void AniResetDefaultApplication(ani_env *env, ani_string aniType, ani_int aniUserId, ani_boolean aniIsSync) +{ + APP_LOGI("SystemCapability.BundleManager.BundleFramework.DefaultApp not supported"); + bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, + isSync ? RESET_DEFAULT_APPLICATION_SYNC : RESET_DEFAULT_APPLICATION, ""); +} + +extern "C" { +ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) +{ + APP_LOGI("ANI_Constructor defaultAppManager called"); + ani_env* env; + ani_status status = vm->GetEnv(ANI_VERSION_1, &env); + RETURN_ANI_STATUS_IF_NOT_OK(status, "Unsupported ANI_VERSION_1"); + + arkts::ani_signature::Namespace nsName = + arkts::ani_signature::Builder::BuildNamespace(NS_NAME_DEFAULTAPPMANAGER); + ani_namespace kitNs = nullptr; + status = env->FindNamespace(nsName.Descriptor().c_str(), &kitNs); + if (status != ANI_OK) { + APP_LOGE("FindNamespace: %{public}s fail with %{public}d", NS_NAME_DEFAULTAPPMANAGER, status); + return status; + } + + std::array methods = { + ani_native_function { "isDefaultApplicationNative", nullptr, reinterpret_cast(AniIsDefaultApplication) }, + ani_native_function { "getDefaultApplicationNative", nullptr, + reinterpret_cast(AniGetDefaultApplication) }, + ani_native_function { "setDefaultApplicationNative", nullptr, + reinterpret_cast(AniSetDefaultApplication) }, + ani_native_function { "resetDefaultApplicationNative", nullptr, + reinterpret_cast(AniResetDefaultApplication) } + }; + + status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); + if (status != ANI_OK) { + APP_LOGE( + "Namespace_BindNativeFunctions: %{public}s fail with %{public}d", NS_NAME_DEFAULTAPPMANAGER, status); + return status; + } + + *result = ANI_VERSION_1; + + APP_LOGI("ANI_Constructor finished"); + + return ANI_OK; +} +} +} // AppExecFwk +} // OHOS \ No newline at end of file diff --git a/interfaces/kits/ani/default_app_manager/ets/@ohos.bundle.defaultAppManager.ets b/interfaces/kits/ani/default_app_manager/ets/@ohos.bundle.defaultAppManager.ets new file mode 100644 index 0000000000..6e41c30090 --- /dev/null +++ b/interfaces/kits/ani/default_app_manager/ets/@ohos.bundle.defaultAppManager.ets @@ -0,0 +1,222 @@ +/* + * 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. + */ + +/** + * @file + * @kit AbilityKit + */ + +import { AsyncCallback, BusinessError } from '@ohos.base'; +import { BundleInfo } from 'bundleManager.BundleInfo'; +import { ElementName } from 'bundleManager.ElementName'; + +export default namespace defaultAppManager { + + loadLibraryWithPermissionCheck("ani_default_app_manager.z", "@ohos.bundle.defaultAppManager"); + + const EMPTY_USER_ID: int = -500; + + export enum ApplicationType { + BROWSER = 'Web Browser', + IMAGE = 'Image Gallery', + AUDIO = 'Audio Player', + VIDEO = 'Video Player', + PDF = 'PDF Viewer', + WORD = 'Word Viewer', + EXCEL = 'Excel Viewer', + PPT = 'PPT Viewer', + EMAIL = 'Email' + } + + export native function isDefaultApplicationNative(type: string, isSync: boolean): boolean; + export native function getDefaultApplicationNative(type: string, userId: int, isSync: boolean): BundleInfo; + export native function setDefaultApplicationNative(type: string, elementName: ElementName, userId: int, isSync: boolean): void; + export native function resetDefaultApplicationNative(type: string, userId: int, isSync: boolean): void; + + function isDefaultApplication(type: string, callback: AsyncCallback): void { + let cb = (): boolean => { + return defaultAppManager.isDefaultApplicationNative(type, false); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let result: boolean = e as boolean; + callback(null, result); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + + } + + function isDefaultApplication(type: string): Promise { + let p = new Promise((resolve: (isDefaultApp: boolean) => void, reject: (error: Error) => void) => { + let cb = (): boolean => { + return defaultAppManager.isDefaultApplicationNative(type, false); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let result: boolean = e as boolean; + resolve(result); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function isDefaultApplicationSync(type: string): boolean { + return defaultAppManager.isDefaultApplicationNative(type, true); + } + + function getDefaultApplication(type: string, userId: int, callback: AsyncCallback): void { + let cb = (): BundleInfo => { + return defaultAppManager.getDefaultApplicationNative(type, userId, false); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let result: BundleInfo = e as BundleInfo; + callback(null, result); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getDefaultApplication(type: string, callback: AsyncCallback): void { + let cb = (): BundleInfo => { + return defaultAppManager.getDefaultApplicationNative(type, EMPTY_USER_ID, false); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let result: BundleInfo = e as BundleInfo; + callback(null, result); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function getDefaultApplication(type: string, userId?: int): Promise { + let userIdInfo: int = userId ?? EMPTY_USER_ID; + let p = new Promise((resolve: (bundleInfo: BundleInfo) => void, reject: (error: Error) => void) => { + let cb = (): BundleInfo => { + return defaultAppManager.getDefaultApplicationNative(type, userIdInfo, false); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let result: BundleInfo = e as BundleInfo; + resolve(result); + }, (err: Error): void => { + reject(err as BusinessError); + }); + }); + return p; + } + + function getDefaultApplicationSync(type: string, userId?: int): BundleInfo { + let userIdInfo: int = userId ?? EMPTY_USER_ID; + return defaultAppManager.getDefaultApplicationNative(type, userIdInfo, true); + } + + function setDefaultApplication(type: string, elementName: ElementName, userId: int, callback: AsyncCallback): void { + let cb = (): void => { + return defaultAppManager.setDefaultApplicationNative(type, elementName, userId, false); + }; + let p1 = taskpool.execute(cb); + p1.then(() => { + callback(null, undefined); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function setDefaultApplication(type: string, elementName: ElementName, callback: AsyncCallback): void { + let cb = (): void => { + return defaultAppManager.setDefaultApplicationNative(type, elementName, EMPTY_USER_ID, false); + }; + let p1 = taskpool.execute(cb); + p1.then(() => { + callback(null, undefined); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function setDefaultApplication(type: string, elementName: ElementName, userId?: int): Promise { + let userIdInfo: int = userId ?? EMPTY_USER_ID; + let p = new Promise((resolve: (v: undefined) => void, reject: (error: Error) => void) : void => { + let cb = (): void => { + return defaultAppManager.setDefaultApplicationNative(type, elementName, userIdInfo, false); + }; + let p1 = taskpool.execute(cb); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function setDefaultApplicationSync(type: string, elementName: ElementName, userId?: int): void { + let userIdInfo: int = userId ?? EMPTY_USER_ID; + return defaultAppManager.setDefaultApplicationNative(type, elementName, userIdInfo, true); + } + + function resetDefaultApplication(type: string, userId: int, callback: AsyncCallback): void { + let cb = (): void => { + return defaultAppManager.resetDefaultApplicationNative(type, userId, false); + }; + let p1 = taskpool.execute(cb); + p1.then(() => { + callback(null, undefined); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function resetDefaultApplication(type: string, callback: AsyncCallback): void { + let cb = (): void => { + return defaultAppManager.resetDefaultApplicationNative(type, EMPTY_USER_ID, false); + }; + let p1 = taskpool.execute(cb); + p1.then(() => { + callback(null, undefined); + }, (err: Error): void => { + callback(err as BusinessError, undefined); + }); + } + + function resetDefaultApplication(type: string, userId?: int): Promise { + let userIdInfo: int = userId ?? EMPTY_USER_ID; + let p = new Promise((resolve: (v: undefined) => void, reject: (error: Error) => void) : void => { + let cb = (): void => { + return defaultAppManager.resetDefaultApplicationNative(type, userIdInfo, false); + }; + let p1 = taskpool.execute(cb); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + } + ); + return p; + } + + function resetDefaultApplicationSync(type: string, userId?: int): void { + let userIdInfo: int = userId ?? EMPTY_USER_ID; + return defaultAppManager.resetDefaultApplicationNative(type, userIdInfo, true); + } +} diff --git a/interfaces/kits/ani/freeInstall/BUILD.gn b/interfaces/kits/ani/freeInstall/BUILD.gn index 612db1be36..bbd2d21957 100644 --- a/interfaces/kits/ani/freeInstall/BUILD.gn +++ b/interfaces/kits/ani/freeInstall/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") ohos_shared_library("ani_freeInstall") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { diff --git a/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfo.ets b/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfo.ets index ae19f7b597..8329aef9a0 100644 --- a/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfo.ets +++ b/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfo.ets @@ -68,19 +68,19 @@ export interface AbilityFormInfo { readonly type: string; readonly updateEnabled: boolean; readonly scheduledUpdateTime: string; - readonly updateDuration: number; + readonly updateDuration: int; readonly supportDimensions: Array; readonly defaultDimension: string; } export interface Version { - readonly minCompatibleVersionCode: number; + readonly minCompatibleVersionCode: int; readonly name: string; - readonly code: number; + readonly code: int; } export interface ApiVersion { readonly releaseType: string; - readonly compatible: number; - readonly target: number; + readonly compatible: int; + readonly target: int; } \ No newline at end of file diff --git a/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfoInner.ets b/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfoInner.ets index 213fb78cba..276314cc8c 100644 --- a/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfoInner.ets +++ b/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfoInner.ets @@ -19,6 +19,18 @@ import { BundlePackInfo, PackageConfig, PackageSummary, BundleConfigInfo, Extens export class BundlePackInfoInner implements BundlePackInfo { public readonly packages: Array = new Array; public readonly summary: PackageSummary = new PackageSummaryInner; + + constructor() { } + constructor(packages: Array) { + this.packages = packages; + } + constructor(summary: PackageSummary) { + this.summary = summary; + } + constructor(packages: Array, summary: PackageSummary) { + this.packages = packages; + this.summary = summary; + } } export class PackageConfigInner implements PackageConfig { @@ -26,21 +38,50 @@ export class PackageConfigInner implements PackageConfig { public readonly name: string = ''; public readonly moduleType: string = ''; public readonly deliveryWithInstall: boolean; + + constructor() { } + constructor(deviceTypes: Array, name: string, moduleType: string, deliveryWithInstall: boolean) { + this.deviceTypes = deviceTypes; + this.name = name; + this.moduleType = moduleType; + this.deliveryWithInstall = deliveryWithInstall; + } } export class PackageSummaryInner implements PackageSummary { public readonly app: BundleConfigInfo = new BundleConfigInfoInner; public readonly modules: Array = new Array; + + constructor() { } + constructor(modules: Array) { + this.modules = modules; + } + constructor(modules: Array, app: BundleConfigInfo) { + this.modules = modules; + this.app = app; + } } export class BundleConfigInfoInner implements BundleConfigInfo { public readonly bundleName: string = ''; public readonly version: Version = new VersionInner; + + constructor() { } + constructor(bundleName: string, version: Version) { + this.bundleName = bundleName; + this.version = version; + } } export class ExtensionAbilityInner implements ExtensionAbility { public readonly name: string = ''; public readonly forms: Array = new Array; + + constructor() { } + constructor(name: string, forms: Array) { + this.name = name; + this.forms = forms; + } } export class ModuleConfigInfoInner implements ModuleConfigInfo { @@ -50,6 +91,21 @@ export class ModuleConfigInfoInner implements ModuleConfigInfo { public readonly distro: ModuleDistroInfo = new ModuleDistroInfoInner; public readonly abilities: Array = new Array; public readonly extensionAbilities: Array = new Array; + + constructor() { } + constructor(mainAbility: string, + apiVersion: ApiVersion, + deviceTypes: Array, + distro: ModuleDistroInfo, + abilities: Array, + extensionAbilities: Array) { + this.mainAbility = mainAbility; + this.apiVersion = apiVersion; + this.deviceTypes = deviceTypes; + this.distro = distro; + this.abilities = abilities; + this.extensionAbilities = extensionAbilities; + } } export class ModuleDistroInfoInner implements ModuleDistroInfo { @@ -57,6 +113,14 @@ export class ModuleDistroInfoInner implements ModuleDistroInfo { public readonly installationFree: boolean; public readonly moduleName: string = ''; public readonly moduleType: string = ''; + + constructor() { } + constructor(deliveryWithInstall: boolean, installationFree: boolean, moduleName: string, moduleType: string) { + this.deliveryWithInstall = deliveryWithInstall; + this.installationFree = installationFree; + this.moduleName = moduleName; + this.moduleType = moduleType; + } } export class ModuleAbilityInfoInner implements ModuleAbilityInfo { @@ -64,6 +128,14 @@ export class ModuleAbilityInfoInner implements ModuleAbilityInfo { public readonly label: string = ''; public readonly exported: boolean; public readonly forms: Array = new Array; + + constructor() { } + constructor(name: string, label: string, exported: boolean, forms: Array) { + this.name = name; + this.label = label; + this.exported = exported; + this.forms = forms; + } } export class AbilityFormInfoInner implements AbilityFormInfo { @@ -71,19 +143,50 @@ export class AbilityFormInfoInner implements AbilityFormInfo { public readonly type: string = ''; public readonly updateEnabled: boolean; public readonly scheduledUpdateTime: string = ''; - public readonly updateDuration: number; + public readonly updateDuration: int; public readonly supportDimensions: Array = new Array; public readonly defaultDimension: string = ''; + + constructor() { } + constructor(name: string, + type: string, + updateEnabled: boolean, + scheduledUpdateTime: string, + updateDuration: int, + supportDimensions: Array, + defaultDimension: string) { + this.name = name; + this.type = type; + this.updateEnabled = updateEnabled; + this.scheduledUpdateTime = scheduledUpdateTime; + this.updateDuration = updateDuration; + this.supportDimensions = supportDimensions; + this.defaultDimension = defaultDimension; + } } export class VersionInner implements Version { - public readonly minCompatibleVersionCode: number; + public readonly minCompatibleVersionCode: int; public readonly name: string = ''; - public readonly code: number; + public readonly code: int; + + constructor() { } + constructor(minCompatibleVersionCode: int, name: string, code: int) { + this.minCompatibleVersionCode = minCompatibleVersionCode; + this.name = name; + this.code = code; + } } export class ApiVersionInner implements ApiVersion { public readonly releaseType: string = ''; - public readonly compatible: number; - public readonly target: number; + public readonly compatible: int; + public readonly target: int; + + constructor() { } + constructor(releaseType: string, compatible: int, target: int) { + this.releaseType = releaseType; + this.compatible = compatible; + this.target = target; + } } \ No newline at end of file diff --git a/interfaces/kits/ani/freeInstall/ets/bundleManager/DispatchInfoInner.ets b/interfaces/kits/ani/freeInstall/ets/bundleManager/DispatchInfoInner.ets index 5b881a8f86..06a585ea48 100644 --- a/interfaces/kits/ani/freeInstall/ets/bundleManager/DispatchInfoInner.ets +++ b/interfaces/kits/ani/freeInstall/ets/bundleManager/DispatchInfoInner.ets @@ -18,4 +18,10 @@ import { DispatchInfo } from 'bundleManager.DispatchInfo'; export class DispatchInfoInner implements DispatchInfo { public readonly version: string = ''; public readonly dispatchAPIVersion: string = ''; + + constructor() { } + constructor(version: string, dispatchAPIVersion: string) { + this.version = version; + this.dispatchAPIVersion = dispatchAPIVersion; + } } \ No newline at end of file diff --git a/interfaces/kits/ani/launcher_bundle_manager/BUILD.gn b/interfaces/kits/ani/launcher_bundle_manager/BUILD.gn index 304f43e38b..f8863695f8 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/BUILD.gn +++ b/interfaces/kits/ani/launcher_bundle_manager/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") ohos_shared_library("ani_launcher_bundle_manager") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { diff --git a/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager.cpp b/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager.cpp index df1d46e54f..ab4a56428f 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager.cpp +++ b/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager.cpp @@ -91,7 +91,7 @@ static void AniStartShortcut(ani_env *env, ani_object aniShortcutInfo, ani_objec } static ani_object AniGetShortcutInfo(ani_env *env, - ani_string aniBundleName, ani_double aniUserId, ani_boolean aniIsSync) + ani_string aniBundleName, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGD("ani GetShortcutInfo called"); std::string bundleName; @@ -100,12 +100,8 @@ static ani_object AniGetShortcutInfo(ani_env *env, BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } - int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("try cast userId failed"); - } - if (userId == EMPTY_USER_ID) { - userId = Constants::UNSPECIFIED_USERID; + if (aniUserId == EMPTY_USER_ID) { + aniUserId = Constants::UNSPECIFIED_USERID; } bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); auto launcherService = JSLauncherService::GetLauncherService(); @@ -117,7 +113,7 @@ static ani_object AniGetShortcutInfo(ani_env *env, } std::vector shortcutInfos; - ErrCode ret = launcherService->GetShortcutInfoV9(bundleName, shortcutInfos, userId); + ErrCode ret = launcherService->GetShortcutInfoV9(bundleName, shortcutInfos, aniUserId); if (ret != ERR_OK) { APP_LOGE("GetShortcutInfoV9 failed, ret %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), @@ -134,7 +130,7 @@ static ani_object AniGetShortcutInfo(ani_env *env, } static ani_object AniGetLauncherAbilityInfo(ani_env *env, - ani_string aniBundleName, ani_double aniUserId, ani_boolean aniIsSync) + ani_string aniBundleName, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGD("ani GetLauncherAbilityInfo called"); std::string bundleName; @@ -143,12 +139,6 @@ static ani_object AniGetLauncherAbilityInfo(ani_env *env, BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } - int32_t userId = Constants::UNSPECIFIED_USERID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGE("try cast userId failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); - return nullptr; - } bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); auto launcherService = JSLauncherService::GetLauncherService(); @@ -163,13 +153,13 @@ static ani_object AniGetLauncherAbilityInfo(ani_env *env, std::vector launcherAbilityInfos; ErrCode ret = ERR_OK; if (isSync) { - ret = launcherService->GetLauncherAbilityInfoSync(bundleName, userId, launcherAbilityInfos); + ret = launcherService->GetLauncherAbilityInfoSync(bundleName, aniUserId, launcherAbilityInfos); } else { - ret = launcherService->GetLauncherAbilityByBundleName(bundleName, userId, launcherAbilityInfos); + ret = launcherService->GetLauncherAbilityByBundleName(bundleName, aniUserId, launcherAbilityInfos); } if (ret != ERR_OK) { APP_LOGE("GetLauncherAbilityInfo failed ret:%{public}d, bundleName:%{public}s, userId:%{public}d", - ret, bundleName.c_str(), userId); + ret, bundleName.c_str(), aniUserId); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), isSync ? GET_LAUNCHER_ABILITY_INFO_SYNC : GET_LAUNCHER_ABILITY_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); @@ -185,16 +175,9 @@ static ani_object AniGetLauncherAbilityInfo(ani_env *env, return launcherAbilityInfosObject; } -static ani_object AniGetAllLauncherAbilityInfo(ani_env *env, ani_double aniUserId) +static ani_object AniGetAllLauncherAbilityInfo(ani_env *env, ani_int aniUserId) { APP_LOGD("ani GetAllLauncherAbilityInfo called"); - int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGE("try cast userId failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); - return nullptr; - } - auto launcherService = JSLauncherService::GetLauncherService(); if (launcherService == nullptr) { APP_LOGE("launcherService is nullptr"); @@ -204,9 +187,9 @@ static ani_object AniGetAllLauncherAbilityInfo(ani_env *env, ani_double aniUserI } std::vector launcherAbilityInfos; - ErrCode ret = launcherService->GetAllLauncherAbility(userId, launcherAbilityInfos); + ErrCode ret = launcherService->GetAllLauncherAbility(aniUserId, launcherAbilityInfos); if (ret != ERR_OK) { - APP_LOGE("GetAllLauncherAbility failed ret:%{public}d,userId:%{public}d", ret, userId); + APP_LOGE("GetAllLauncherAbility failed ret:%{public}d,userId:%{public}d", ret, aniUserId); BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), GET_ALL_LAUNCHER_ABILITY_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); return nullptr; @@ -221,6 +204,104 @@ static ani_object AniGetAllLauncherAbilityInfo(ani_env *env, ani_double aniUserI return launcherAbilityInfosObject; } +static ani_object GetShortcutInfoByAppIndex(ani_env* env, ani_string aniBundleName, ani_int aniAppIndex) +{ + APP_LOGD("ani GetShortcutInfoByAppIndex called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("parse bundleName failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + if (aniAppIndex < Constants::MAIN_APP_INDEX || aniAppIndex > Constants::CLONE_APP_INDEX_MAX) { + APP_LOGE("appIndex: %{public}d not in valid range", aniAppIndex); + BusinessErrorAni::ThrowCommonError(env, ERROR_INVALID_APPINDEX, APP_INDEX, TYPE_NUMBER); + return nullptr; + } + auto launcherService = JSLauncherService::GetLauncherService(); + if (launcherService == nullptr) { + APP_LOGE("launcherService is nullptr"); + BusinessErrorAni::ThrowCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, GET_SHORTCUT_INFO_BY_APPINDEX, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + std::vector shortcutInfos; + ErrCode ret = launcherService->GetShortcutInfoByAppIndex(bundleName, aniAppIndex, shortcutInfos); + if (ret != ERR_OK) { + APP_LOGE("GetShortcutInfoByAppIndex failed, ret %{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), GET_SHORTCUT_INFO_BY_APPINDEX, + Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + ani_object shortcutInfosObject = + CommonFunAni::ConvertAniArray(env, shortcutInfos, CommonFunAni::ConvertShortcutInfo); + if (shortcutInfosObject == nullptr) { + APP_LOGE("nullptr shortcutInfosObject"); + return nullptr; + } + return shortcutInfosObject; +} + +static ErrCode InnerStartShortcutWithReason(const OHOS::AppExecFwk::ShortcutInfo &shortcutInfo, + std::string &startReason, const OHOS::AAFwk::StartOptions &startOptions) +{ + if (shortcutInfo.intents.empty()) { + APP_LOGW("intents is empty"); + return ERR_BUNDLE_MANAGER_START_SHORTCUT_FAILED; + } + AAFwk::Want want; + ElementName element; + element.SetBundleName(shortcutInfo.intents[0].targetBundle); + element.SetModuleName(shortcutInfo.intents[0].targetModule); + element.SetAbilityName(shortcutInfo.intents[0].targetClass); + want.SetElement(element); + for (const auto &item : shortcutInfo.intents[0].parameters) { + want.SetParam(item.first, item.second); + } + want.SetParam(AAFwk::Want::PARM_LAUNCH_REASON_MESSAGE, startReason); + want.SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, shortcutInfo.appIndex); + auto res = AAFwk::AbilityManagerClient::GetInstance()->StartShortcut(want, startOptions); + auto it = START_SHORTCUT_RES_MAP.find(res); + if (it == START_SHORTCUT_RES_MAP.end()) { + APP_LOGE("call AbilityManagerClient StartShortcut failed, res : %{public}d", res); + return ERR_BUNDLE_MANAGER_START_SHORTCUT_FAILED; + } + return it->second; +} + +static void StartShortcutWithReasonNative( + ani_env* env, ani_object aniShortcutInfo, ani_string aniStartReason, ani_object aniStartOptions) +{ + APP_LOGD("ani StartShortcutWithReason called"); + ShortcutInfo shortcutInfo; + if (!CommonFunAni::ParseShortcutInfo(env, aniShortcutInfo, shortcutInfo)) { + APP_LOGE("parse shortcutInfo failed"); + BusinessErrorAni::ThrowError(env, ERR_BUNDLE_MANAGER_START_SHORTCUT_FAILED, PARSE_SHORTCUT_INFO_FAILED); + return; + } + std::string reasonMessage; + if (!CommonFunAni::ParseString(env, aniStartReason, reasonMessage)) { + APP_LOGE("parse reasonMessage failed"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_REASON_MESSAGE); + return; + } + StartOptions startOptions; + if (aniStartOptions != nullptr) { + if (!UnwrapStartOptions(env, aniStartOptions, startOptions)) { + APP_LOGE("ParseStartOptions error"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_START_OPTIONS_FAILED); + return; + } + } + ErrCode result = InnerStartShortcutWithReason(shortcutInfo, reasonMessage, startOptions); + if (result != ERR_OK) { + APP_LOGE("StartShortcutWithReason failed, result: %{public}d", result); + BusinessErrorAni::ThrowCommonError( + env, CommonFunc::ConvertErrCode(result), START_SHORTCUT_WITH_REASON, Constants::PERMISSION_START_SHORTCUT); + } +} + extern "C" { ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) { @@ -244,6 +325,10 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) reinterpret_cast(AniGetLauncherAbilityInfo) }, ani_native_function { "getAllLauncherAbilityInfoNative", nullptr, reinterpret_cast(AniGetAllLauncherAbilityInfo) }, + ani_native_function { "getShortcutInfoByAppIndex", nullptr, + reinterpret_cast(GetShortcutInfoByAppIndex) }, + ani_native_function { "startShortcutWithReasonNative", nullptr, + reinterpret_cast(StartShortcutWithReasonNative) }, }; status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); diff --git a/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager_unsupported.cpp b/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager_unsupported.cpp index f8380a0d8f..7b854800d8 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager_unsupported.cpp +++ b/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager_unsupported.cpp @@ -34,7 +34,7 @@ static void AniStartShortcut(ani_env *env, ani_object aniShortcutInfo, ani_objec } static ani_object AniGetShortcutInfo(ani_env *env, - ani_string aniBundleName, ani_double aniUserId, ani_boolean aniIsSync) + ani_string aniBundleName, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGI("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); @@ -44,7 +44,7 @@ static ani_object AniGetShortcutInfo(ani_env *env, } static ani_object AniGetLauncherAbilityInfo(ani_env *env, - ani_string aniBundleName, ani_double aniUserId, ani_boolean aniIsSync) + ani_string aniBundleName, ani_int aniUserId, ani_boolean aniIsSync) { APP_LOGI("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); @@ -53,13 +53,27 @@ static ani_object AniGetLauncherAbilityInfo(ani_env *env, return nullptr; } -static ani_object AniGetAllLauncherAbilityInfo(ani_env *env, ani_double aniUserId) +static ani_object AniGetAllLauncherAbilityInfo(ani_env *env, ani_int aniUserId) { APP_LOGI("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_ALL_LAUNCHER_ABILITY_INFO, ""); return nullptr; } +static ani_object GetShortcutInfoByAppIndex(ani_env* env, ani_string aniBundleName, ani_int aniAppIndex) +{ + APP_LOGI("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_SHORTCUT_INFO_BY_APPINDEX, ""); + return nullptr; +} + +static void StartShortcutWithReasonNative( + ani_env* env, ani_object aniShortcutInfo, ani_string aniStartReason, ani_object aniStartOptions) +{ + APP_LOGI("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, START_SHORTCUT_WITH_REASON, ""); +} + extern "C" { ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) { @@ -83,6 +97,10 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) reinterpret_cast(AniGetLauncherAbilityInfo) }, ani_native_function { "getAllLauncherAbilityInfoNative", nullptr, reinterpret_cast(AniGetAllLauncherAbilityInfo) }, + ani_native_function { "getShortcutInfoByAppIndex", nullptr, + reinterpret_cast(GetShortcutInfoByAppIndex) }, + ani_native_function { "startShortcutWithReasonNative", nullptr, + reinterpret_cast(StartShortcutWithReasonNative) }, }; status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/@ohos.bundle.launcherBundleManager.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/@ohos.bundle.launcherBundleManager.ets index 64a434a220..dc4ff96034 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/ets/@ohos.bundle.launcherBundleManager.ets +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/@ohos.bundle.launcherBundleManager.ets @@ -21,12 +21,14 @@ import StartOptions from '@ohos.app.ability.StartOptions'; export default namespace launcherBundleManager { loadLibraryWithPermissionCheck("ani_launcher_bundle_manager.z", "@ohos.bundle.launcherBundleManager"); - const EMPTY_USER_ID: number = -500; + const EMPTY_USER_ID: int = -500; export native function startShortcutNative(shortcutInfo: ShortcutInfo, options: StartOptions): void; - export native function getShortcutInfoNative(bundleName: string, userId: number, isSync: boolean): Array; - export native function getLauncherAbilityInfoNative(bundleName: string, userId: number, isSync: boolean): Array; - export native function getAllLauncherAbilityInfoNative(userId: number): Array; + export native function getShortcutInfoNative(bundleName: string, userId: int, isSync: boolean): Array; + export native function getLauncherAbilityInfoNative(bundleName: string, userId: int, isSync: boolean): Array; + export native function getAllLauncherAbilityInfoNative(userId: int): Array; + export native function getShortcutInfoByAppIndex(bundleName: string, appIndex: int): Array; + export native function startShortcutWithReasonNative(shortcutInfo: ShortcutInfo, startReason: string, options: StartOptions): void; function startShortcut(shortcutInfo: ShortcutInfo, options?: StartOptions): Promise { let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void): void => { @@ -51,7 +53,7 @@ export default namespace launcherBundleManager { return launcherBundleManager.getShortcutInfoNative(bundleName, EMPTY_USER_ID, true); } - function getShortcutInfoSync(bundleName: string, userId: number): Array { + function getShortcutInfoSync(bundleName: string, userId: int): Array { return launcherBundleManager.getShortcutInfoNative(bundleName, userId, true); } @@ -84,7 +86,7 @@ export default namespace launcherBundleManager { return p; } - function getLauncherAbilityInfo(bundleName: string, userId: number, callback: AsyncCallback, void>): void { + function getLauncherAbilityInfo(bundleName: string, userId: int, callback: AsyncCallback, void>): void { let cb = (): (Array) => { return launcherBundleManager.getLauncherAbilityInfoNative(bundleName, userId, false); }; @@ -97,7 +99,7 @@ export default namespace launcherBundleManager { }); } - function getLauncherAbilityInfo(bundleName: string, userId: number): Promise> { + function getLauncherAbilityInfo(bundleName: string, userId: int): Promise> { let p = new Promise>((resolve: (arrLauncherAbilityInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return launcherBundleManager.getLauncherAbilityInfoNative(bundleName, userId, false); @@ -113,11 +115,11 @@ export default namespace launcherBundleManager { return p; } - function getLauncherAbilityInfoSync(bundleName: string, userId: number): Array { + function getLauncherAbilityInfoSync(bundleName: string, userId: int): Array { return launcherBundleManager.getLauncherAbilityInfoNative(bundleName, userId, true); } - function getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback, void>): void { + function getAllLauncherAbilityInfo(userId: int, callback: AsyncCallback, void>): void { let cb = (): (Array) => { return launcherBundleManager.getAllLauncherAbilityInfoNative(userId); }; @@ -130,7 +132,7 @@ export default namespace launcherBundleManager { }); } - function getAllLauncherAbilityInfo(userId: number): Promise>{ + function getAllLauncherAbilityInfo(userId: int): Promise>{ let p = new Promise>((resolve: (arrLauncherAbilityInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return launcherBundleManager.getAllLauncherAbilityInfoNative(userId); @@ -146,6 +148,25 @@ export default namespace launcherBundleManager { return p; } + function startShortcutWithReason(shortcutInfo: ShortcutInfo, startReason: string, options?: StartOptions): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: BusinessError) => void): void => { + let startOptions : StartOptions = {}; + if (options != undefined) { + startOptions = options; + } + let cb = (): NullishType => { + launcherBundleManager.startShortcutWithReasonNative(shortcutInfo, startReason, startOptions); + } + let p1 = taskpool.execute(cb); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + }); + return p; + } + export type ShortcutInfo = _ShortcutInfo; export type ShortcutWant = _ShortcutWant; export type ParameterItem = _ParameterItem; diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementNameInner.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementNameInner.ets index c230ec268c..97280b5768 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementNameInner.ets +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementNameInner.ets @@ -22,4 +22,19 @@ export class ElementNameInner implements ElementName { abilityName: string = ""; uri?: string | undefined; shortName?: string | undefined; + + constructor() { } + constructor(bundleName: string, + abilityName: string, + deviceId?: string, + moduleName?: string, + uri?: string, + shortName?: string) { + this.deviceId = deviceId; + this.bundleName = bundleName; + this.moduleName = moduleName; + this.abilityName = abilityName; + this.uri = uri; + this.shortName = shortName; + } } \ No newline at end of file diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfo.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfo.ets index ebfd76b8c8..ef83807a72 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfo.ets +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfo.ets @@ -19,8 +19,8 @@ import { ElementName } from 'bundleManager.ElementName'; export interface LauncherAbilityInfo { readonly applicationInfo: ApplicationInfo; readonly elementName: ElementName; - readonly labelId: number; - readonly iconId: number; - readonly userId: number; - readonly installTime: number; + readonly labelId: long; + readonly iconId: long; + readonly userId: int; + readonly installTime: long; } \ No newline at end of file diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfoInner.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfoInner.ets index 04382de4fe..ae32bfa7a2 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfoInner.ets +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfoInner.ets @@ -21,8 +21,23 @@ import { LauncherAbilityInfo } from 'bundleManager.LauncherAbilityInfo'; export class LauncherAbilityInfoInner implements LauncherAbilityInfo { readonly applicationInfo: ApplicationInfo = new ApplicationInfoInner; readonly elementName: ElementName = new ElementNameInner; - readonly labelId: number; - readonly iconId: number; - readonly userId: number; - readonly installTime: number; + readonly labelId: long; + readonly iconId: long; + readonly userId: int; + readonly installTime: long; + + constructor() { } + constructor(applicationInfo: ApplicationInfo, + elementName: ElementName, + labelId: long, + iconId: long, + userId: int, + installTime: long) { + this.applicationInfo = applicationInfo; + this.elementName = elementName; + this.labelId = labelId; + this.iconId = iconId; + this.userId = userId; + this.installTime = installTime; + } } \ No newline at end of file diff --git a/interfaces/kits/ani/overlay/BUILD.gn b/interfaces/kits/ani/overlay/BUILD.gn index 5d55589ed4..b813bc1287 100644 --- a/interfaces/kits/ani/overlay/BUILD.gn +++ b/interfaces/kits/ani/overlay/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") ohos_shared_library("ani_overlay") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { diff --git a/interfaces/kits/ani/overlay/ets/@ohos.bundle.overlay.ets b/interfaces/kits/ani/overlay/ets/@ohos.bundle.overlay.ets index dbfc5b64e5..743a65b8a0 100644 --- a/interfaces/kits/ani/overlay/ets/@ohos.bundle.overlay.ets +++ b/interfaces/kits/ani/overlay/ets/@ohos.bundle.overlay.ets @@ -25,6 +25,20 @@ export default namespace overlay { loadLibraryWithPermissionCheck("ani_overlay.z", "@ohos.bundle.overlay"); + const ERROR_PARAM_CHECK_ERROR: int = 401; + const PARAM_MODULENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. The type of moduleName must be string."; + const PARAM_BUNDLENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. The type of bundleName must be string."; + const PARAM_TARGET_MODULENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. The type of targetModuleName must be string."; + const PARAM_TARGET_BUNDLENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. The type of targetBundleName must be string."; + + function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'Error'; + err.message = message; + return err; + } + export native function setOverlayEnabledNative(moduleName: string, isEnabled: boolean): void; export native function setOverlayEnabledByBundleNameNative(bundleName: string, moduleName: string, isEnabled: boolean): void; export native function getOverlayModuleInfoNative(moduleName: string): OverlayModuleInfo; @@ -33,6 +47,9 @@ export default namespace overlay { export native function getTargetOverlayModuleInfosByBundleNameNative(targetBundleName: string, moduleName: string): Array; function setOverlayEnabled(moduleName: string, isEnabled: boolean, callback: AsyncCallback): void { + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let cb = (): void => { return overlay.setOverlayEnabledNative(moduleName, isEnabled); }; @@ -45,6 +62,9 @@ export default namespace overlay { } function setOverlayEnabled(moduleName: string, isEnabled: boolean): Promise { + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void) : void => { let cb = (): void => { return overlay.setOverlayEnabledNative(moduleName, isEnabled); @@ -61,6 +81,12 @@ export default namespace overlay { } function setOverlayEnabledByBundleName(bundleName: string, moduleName: string, isEnabled: boolean, callback: AsyncCallback): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let cb = (): void => { return overlay.setOverlayEnabledByBundleNameNative(bundleName, moduleName, isEnabled); }; @@ -73,6 +99,12 @@ export default namespace overlay { } function setOverlayEnabledByBundleName(bundleName: string, moduleName: string, isEnabled: boolean): Promise { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void) : void => { let cb = (): void => { return overlay.setOverlayEnabledByBundleNameNative(bundleName, moduleName, isEnabled); @@ -89,6 +121,9 @@ export default namespace overlay { } function getOverlayModuleInfo(moduleName: string, callback: AsyncCallback): void { + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let cb = (): OverlayModuleInfo => { return overlay.getOverlayModuleInfoNative(moduleName); }; @@ -102,6 +137,9 @@ export default namespace overlay { } function getOverlayModuleInfo(moduleName: string): Promise { + if (moduleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + } let p = new Promise((resolve: (overlayModuleInfo: OverlayModuleInfo) => void, reject: (error: BusinessError) => void) => { let cb = (): OverlayModuleInfo => { return overlay.getOverlayModuleInfoNative(moduleName); @@ -118,6 +156,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfos(targetModuleName: string, callback: AsyncCallback>): void { + if (targetModuleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_MODULENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getTargetOverlayModuleInfosNative(targetModuleName); }; @@ -131,6 +172,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfos(targetModuleName: string): Promise> { + if (targetModuleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_MODULENAME_EMPTY_ERROR); + } let p = new Promise>((resolve: (arrOverlayModuleInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return overlay.getTargetOverlayModuleInfosNative(targetModuleName); @@ -147,6 +191,9 @@ export default namespace overlay { } function getOverlayModuleInfoByBundleName(bundleName: string, callback: AsyncCallback>): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getOverlayModuleInfoByBundleNameNative(bundleName, ''); }; @@ -160,6 +207,9 @@ export default namespace overlay { } function getOverlayModuleInfoByBundleName(bundleName: string, moduleName: string, callback: AsyncCallback>): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getOverlayModuleInfoByBundleNameNative(bundleName, moduleName); }; @@ -173,6 +223,9 @@ export default namespace overlay { } function getOverlayModuleInfoByBundleName(bundleName: string, moduleName?: string): Promise> { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + } let moduleNameInfo: string = moduleName ?? ''; let p = new Promise>((resolve: (arrOverlayModuleInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { @@ -190,6 +243,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfosByBundleName(targetBundleName: string, callback: AsyncCallback>): void { + if (targetBundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_BUNDLENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getTargetOverlayModuleInfosByBundleNameNative(targetBundleName, ''); }; @@ -203,6 +259,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfosByBundleName(targetBundleName: string, moduleName: string, callback: AsyncCallback>): void { + if (targetBundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_BUNDLENAME_EMPTY_ERROR); + } let cb = (): (Array) => { return overlay.getTargetOverlayModuleInfosByBundleNameNative(targetBundleName, moduleName); }; @@ -216,6 +275,9 @@ export default namespace overlay { } function getTargetOverlayModuleInfosByBundleName(targetBundleName: string, moduleName?: string): Promise> { + if (targetBundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TARGET_BUNDLENAME_EMPTY_ERROR); + } let moduleNameInfo: string = moduleName ?? ''; let p = new Promise>((resolve: (arrOverlayModuleInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { diff --git a/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfo.ets b/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfo.ets index 5e1c5d7a8d..bf763a8938 100644 --- a/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfo.ets +++ b/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfo.ets @@ -22,6 +22,6 @@ export interface OverlayModuleInfo { readonly bundleName: string; readonly moduleName: string; readonly targetModuleName: string; - readonly priority: number; - readonly state: number; + readonly priority: int; + readonly state: int; } diff --git a/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfoInner.ets b/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfoInner.ets index 60bcaa36c3..cd56a0531a 100644 --- a/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfoInner.ets +++ b/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfoInner.ets @@ -24,6 +24,19 @@ export class OverlayModuleInfoInner implements OverlayModuleInfo { public readonly bundleName: string = ''; public readonly moduleName: string = ''; public readonly targetModuleName: string = ''; - public readonly priority: number; - public readonly state: number; + public readonly priority: int; + public readonly state: int; + + constructor() { } + constructor(bundleName: string, + moduleName: string, + targetModuleName: string, + priority: int, + state: int) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.targetModuleName = targetModuleName; + this.priority = priority; + this.state = state; + } } diff --git a/interfaces/kits/ani/resource_manager/BUILD.gn b/interfaces/kits/ani/resource_manager/BUILD.gn index b7f5e6ca78..47e5a44f93 100644 --- a/interfaces/kits/ani/resource_manager/BUILD.gn +++ b/interfaces/kits/ani/resource_manager/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") ohos_shared_library("ani_bundle_res_manager") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { @@ -36,7 +37,10 @@ ohos_shared_library("ani_bundle_res_manager") { ] if (bundle_framework_bundle_resource) { - sources = [ "ani_resource_manager.cpp" ] + sources = [ + "ani_resource_manager.cpp", + "ani_resource_manager_common.cpp", + ] } else { sources = [ "ani_resource_manager_unsupport.cpp" ] } diff --git a/interfaces/kits/ani/resource_manager/ani_resource_manager.cpp b/interfaces/kits/ani/resource_manager/ani_resource_manager.cpp index d1b01a91fd..2a8a280e24 100644 --- a/interfaces/kits/ani/resource_manager/ani_resource_manager.cpp +++ b/interfaces/kits/ani/resource_manager/ani_resource_manager.cpp @@ -14,6 +14,7 @@ */ #include +#include "ani_resource_manager_common.h" #include "app_log_wrapper.h" #include "bundle_errors.h" #include "bundle_resource_info.h" @@ -28,14 +29,14 @@ namespace OHOS { namespace AppExecFwk { namespace { -constexpr int32_t INVALID_INT = -500; +constexpr int32_t INVALID_VALUE = -500; constexpr int32_t DEFAULT_RES_FLAG = 1; constexpr int32_t DEFAULT_IDX = 0; constexpr const char* NS_NAME_RESOURCEMANAGER = "@ohos.bundle.bundleResourceManager.bundleResourceManager"; } static ani_object AniGetBundleResourceInfo(ani_env* env, ani_string aniBundleName, - ani_double aniResFlag, ani_double aniAppIndex) + ani_int aniResFlag, ani_int aniAppIndex) { APP_LOGD("ani GetBundleResourceInfo called"); std::string bundleName; @@ -44,29 +45,18 @@ static ani_object AniGetBundleResourceInfo(ani_env* env, ani_string aniBundleNam BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } - int32_t resFlag = 0; - if (!CommonFunAni::TryCastDoubleTo(aniResFlag, &resFlag)) { - APP_LOGE("Cast aniResFlag failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, RESOURCE_FLAGS, TYPE_NUMBER); - return nullptr; - } - int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { - APP_LOGE("Cast aniAppIndex failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return nullptr; - } - if (resFlag == INVALID_INT) { - resFlag = DEFAULT_RES_FLAG; + if (aniResFlag == INVALID_VALUE) { + aniResFlag = DEFAULT_RES_FLAG; } - if (appIndex == INVALID_INT) { - appIndex = DEFAULT_IDX; + if (aniAppIndex == INVALID_VALUE) { + aniAppIndex = DEFAULT_IDX; } BundleResourceInfo bundleResInfo; - int32_t ret = ResourceHelper::InnerGetBundleResourceInfo(bundleName, resFlag, appIndex, bundleResInfo); + int32_t ret = ResourceHelper::InnerGetBundleResourceInfo( + bundleName, static_cast(aniResFlag), aniAppIndex, bundleResInfo); if (ret != ERR_OK) { APP_LOGE("GetBundleResourceInfo failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError( @@ -74,11 +64,11 @@ static ani_object AniGetBundleResourceInfo(ani_env* env, ani_string aniBundleNam return nullptr; } - return CommonFunAni::ConvertBundleResourceInfo(env, bundleResInfo); + return AniResourceManagerCommon::ConvertBundleResourceInfo(env, bundleResInfo); } static ani_object AniGetLauncherAbilityResourceInfo(ani_env* env, ani_string aniBundleName, - ani_double aniResFlag, ani_double aniAppIndex) + ani_int aniResFlag, ani_int aniAppIndex) { APP_LOGD("ani GetLauncherAbilityResourceInfo called"); std::string bundleName; @@ -87,30 +77,18 @@ static ani_object AniGetLauncherAbilityResourceInfo(ani_env* env, ani_string ani BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } - int32_t resFlag = 0; - if (!CommonFunAni::TryCastDoubleTo(aniResFlag, &resFlag)) { - APP_LOGE("Cast aniResFlag failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, RESOURCE_FLAGS, TYPE_NUMBER); - return nullptr; - } - int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { - APP_LOGE("Cast aniAppIndex failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); - return nullptr; - } - if (resFlag == INVALID_INT) { - resFlag = DEFAULT_RES_FLAG; + if (aniResFlag == INVALID_VALUE) { + aniResFlag = DEFAULT_RES_FLAG; } - if (appIndex == INVALID_INT) { - appIndex = DEFAULT_IDX; + if (aniAppIndex == INVALID_VALUE) { + aniAppIndex = DEFAULT_IDX; } std::vector launcherAbilityResourceInfos; int32_t ret = ResourceHelper::InnerGetLauncherAbilityResourceInfo( - bundleName, resFlag, appIndex, launcherAbilityResourceInfos); + bundleName, static_cast(aniResFlag), aniAppIndex, launcherAbilityResourceInfos); if (ret != ERR_OK) { APP_LOGE("GetLauncherAbilityResourceInfo failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, ret, @@ -119,7 +97,7 @@ static ani_object AniGetLauncherAbilityResourceInfo(ani_env* env, ani_string ani } ani_object launcherAbilityResourceInfosObject = CommonFunAni::ConvertAniArray( - env, launcherAbilityResourceInfos, CommonFunAni::ConvertLauncherAbilityResourceInfo); + env, launcherAbilityResourceInfos, AniResourceManagerCommon::ConvertLauncherAbilityResourceInfo); if (launcherAbilityResourceInfosObject == nullptr) { APP_LOGE("nullptr launcherAbilityResourceInfosObject"); } @@ -127,18 +105,12 @@ static ani_object AniGetLauncherAbilityResourceInfo(ani_env* env, ani_string ani return launcherAbilityResourceInfosObject; } -static ani_object AniGetAllBundleResourceInfo(ani_env* env, ani_double aniResFlag) +static ani_object AniGetAllBundleResourceInfo(ani_env* env, ani_int aniResFlag) { APP_LOGD("ani GetAllBundleResourceInfo called"); - int32_t resFlag = 0; - if (!CommonFunAni::TryCastDoubleTo(aniResFlag, &resFlag)) { - APP_LOGE("Cast aniResFlag failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, RESOURCE_FLAGS, TYPE_NUMBER); - return nullptr; - } std::vector bundleResourceInfos; - int32_t ret = ResourceHelper::InnerGetAllBundleResourceInfo(resFlag, bundleResourceInfos); + int32_t ret = ResourceHelper::InnerGetAllBundleResourceInfo(static_cast(aniResFlag), bundleResourceInfos); if (ret != ERR_OK) { APP_LOGE("GetLauncherAbilityResourceInfo failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, ret, GET_ALL_BUNDLE_RESOURCE_INFO, PERMISSION_GET_ALL_BUNDLE_RESOURCES); @@ -146,7 +118,7 @@ static ani_object AniGetAllBundleResourceInfo(ani_env* env, ani_double aniResFla } ani_object bundleResourceInfosObject = CommonFunAni::ConvertAniArray( - env, bundleResourceInfos, CommonFunAni::ConvertBundleResourceInfo); + env, bundleResourceInfos, AniResourceManagerCommon::ConvertBundleResourceInfo); if (bundleResourceInfosObject == nullptr) { APP_LOGE("nullptr bundleResourceInfosObject"); } @@ -154,18 +126,13 @@ static ani_object AniGetAllBundleResourceInfo(ani_env* env, ani_double aniResFla return bundleResourceInfosObject; } -static ani_object AniGetAllLauncherAbilityResourceInfo(ani_env* env, ani_double aniResFlag) +static ani_object AniGetAllLauncherAbilityResourceInfo(ani_env* env, ani_int aniResFlag) { APP_LOGD("ani GetAllLauncherAbilityResourceInfo called"); - int32_t resFlag = 0; - if (!CommonFunAni::TryCastDoubleTo(aniResFlag, &resFlag)) { - APP_LOGE("Cast aniResFlag failed"); - BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, RESOURCE_FLAGS, TYPE_NUMBER); - return nullptr; - } std::vector launcherAbilityResourceInfos; - int32_t ret = ResourceHelper::InnerGetAllLauncherAbilityResourceInfo(resFlag, launcherAbilityResourceInfos); + int32_t ret = ResourceHelper::InnerGetAllLauncherAbilityResourceInfo( + static_cast(aniResFlag), launcherAbilityResourceInfos); if (ret != ERR_OK) { APP_LOGE("GetLauncherAbilityResourceInfo failed ret: %{public}d", ret); BusinessErrorAni::ThrowCommonError(env, ret, @@ -174,7 +141,7 @@ static ani_object AniGetAllLauncherAbilityResourceInfo(ani_env* env, ani_double } ani_object launcherAbilityResourceInfosObject = CommonFunAni::ConvertAniArray( - env, launcherAbilityResourceInfos, CommonFunAni::ConvertLauncherAbilityResourceInfo); + env, launcherAbilityResourceInfos, AniResourceManagerCommon::ConvertLauncherAbilityResourceInfo); if (launcherAbilityResourceInfosObject == nullptr) { APP_LOGE("nullptr launcherAbilityResourceInfosObject"); } @@ -182,6 +149,52 @@ static ani_object AniGetAllLauncherAbilityResourceInfo(ani_env* env, ani_double return launcherAbilityResourceInfosObject; } +static ani_object GetExtensionAbilityResourceInfoNative(ani_env* env, ani_string aniBundleName, + ani_enum_item aniExtensionAbilityType, ani_int aniResourceFlags, ani_int aniAppIndex) +{ + APP_LOGD("ani GetExtensionAbilityResourceInfo called"); + std::string bundleName; + if (!CommonFunAni::ParseString(env, aniBundleName, bundleName)) { + APP_LOGE("parse bundleName failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); + return nullptr; + } + if (bundleName.empty()) { + APP_LOGE("bundleName empty"); + BusinessErrorAni::ThrowCommonError( + env, ERROR_BUNDLE_NOT_EXIST, GET_EXTENSION_ABILITY_RESOURCE_INFO, PERMISSION_GET_BUNDLE_RESOURCES); + return nullptr; + } + ExtensionAbilityType extensionAbilityType = ExtensionAbilityType::UNSPECIFIED; + if (!EnumUtils::EnumETSToNative(env, aniExtensionAbilityType, extensionAbilityType)) { + APP_LOGE("Parse extensionAbilityType failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, EXTENSION_ABILITY_TYPE, TYPE_NUMBER); + return nullptr; + } + if (aniResourceFlags <= 0) { + aniResourceFlags = static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL); + } + if (aniAppIndex == INVALID_VALUE) { + aniAppIndex = DEFAULT_IDX; + } + + std::vector extensionAbilityResourceInfos; + ErrCode ret = ResourceHelper::InnerGetExtensionAbilityResourceInfo( + bundleName, extensionAbilityType, aniResourceFlags, aniAppIndex, extensionAbilityResourceInfos); + if (ret != ERR_OK) { + APP_LOGE("QueryExtensionAbilityInfo failed ret: %{public}d", ret); + BusinessErrorAni::ThrowCommonError( + env, ret, GET_EXTENSION_ABILITY_RESOURCE_INFO, PERMISSION_GET_BUNDLE_RESOURCES); + return nullptr; + } + ani_object launcherAbilityResourceInfosObject = CommonFunAni::ConvertAniArray( + env, extensionAbilityResourceInfos, AniResourceManagerCommon::ConvertLauncherAbilityResourceInfo); + if (launcherAbilityResourceInfosObject == nullptr) { + APP_LOGE("nullptr launcherAbilityResourceInfosObject"); + } + return launcherAbilityResourceInfosObject; +} + extern "C" { ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) { @@ -206,7 +219,9 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) ani_native_function { "getAllBundleResourceInfoNative", nullptr, reinterpret_cast(AniGetAllBundleResourceInfo) }, ani_native_function { "getAllLauncherAbilityResourceInfoNative", nullptr, - reinterpret_cast(AniGetAllLauncherAbilityResourceInfo) } + reinterpret_cast(AniGetAllLauncherAbilityResourceInfo) }, + ani_native_function { "getExtensionAbilityResourceInfoNative", nullptr, + reinterpret_cast(GetExtensionAbilityResourceInfoNative) } }; status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); diff --git a/interfaces/kits/ani/resource_manager/ani_resource_manager_common.cpp b/interfaces/kits/ani/resource_manager/ani_resource_manager_common.cpp new file mode 100644 index 0000000000..6dfaeac37a --- /dev/null +++ b/interfaces/kits/ani/resource_manager/ani_resource_manager_common.cpp @@ -0,0 +1,107 @@ +/* + * 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 + +#include "ani_resource_manager_common.h" +#include "common_fun_ani.h" + +namespace OHOS { +namespace AppExecFwk { + +namespace { +constexpr const char* CLASSNAME_BUNDLE_RES_INFO_INNER = + "bundleManager.BundleResourceInfoInner.BundleResourceInfoInner"; +constexpr const char* CLASSNAME_LAUNCHER_ABILITY_RESOURCE_INFO_INNER = + "bundleManager.LauncherAbilityResourceInfoInner.LauncherAbilityResourceInfoInner"; +} + +ani_object AniResourceManagerCommon::ConvertBundleResourceInfo(ani_env* env, const BundleResourceInfo& bundleResInfo) +{ + RETURN_NULL_IF_NULL(env); + + // bundleName: string + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, bundleResInfo.bundleName, bundleName)); + + // icon: string + ani_string icon = nullptr; + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, bundleResInfo.icon, icon)); + + // label: string + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, bundleResInfo.label, label)); + + ani_value args[] = { + { .r = bundleName }, + { .r = icon }, + { .r = label }, + { .i = bundleResInfo.appIndex }, + }; + static const std::string ctorSig = + arkts::ani_signature::SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // icon: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label: string + .AddInt() // appIndex: int + .BuildSignatureDescriptor(); + return CommonFunAni::CreateNewObjectByClassV2(env, CLASSNAME_BUNDLE_RES_INFO_INNER, ctorSig, args); +} + +ani_object AniResourceManagerCommon::ConvertLauncherAbilityResourceInfo(ani_env* env, + const LauncherAbilityResourceInfo& launcherAbilityResourceInfo) +{ + RETURN_NULL_IF_NULL(env); + + // bundleName: string + ani_string bundleName = nullptr; + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.bundleName, bundleName)); + + // moduleName: string + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.moduleName, moduleName)); + + // abilityName: string + ani_string abilityName = nullptr; + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.abilityName, abilityName)); + + // icon: string + ani_string icon = nullptr; + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.icon, icon)); + + // label: string + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.label, label)); + + ani_value args[] = { + { .r = bundleName }, + { .r = moduleName }, + { .r = abilityName }, + { .r = icon }, + { .r = label }, + { .i = launcherAbilityResourceInfo.appIndex }, + }; + static const std::string ctorSig = + arkts::ani_signature::SignatureBuilder() + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // abilityName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // icon: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // label: string + .AddInt() // appIndex: int + .BuildSignatureDescriptor(); + return CommonFunAni::CreateNewObjectByClassV2(env, CLASSNAME_LAUNCHER_ABILITY_RESOURCE_INFO_INNER, ctorSig, args); +} +} // AppExecFwk +} // OHOS \ No newline at end of file diff --git a/interfaces/kits/ani/resource_manager/ani_resource_manager_common.h b/interfaces/kits/ani/resource_manager/ani_resource_manager_common.h new file mode 100644 index 0000000000..a8fceada4b --- /dev/null +++ b/interfaces/kits/ani/resource_manager/ani_resource_manager_common.h @@ -0,0 +1,33 @@ +/* + * 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 FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INTERFACE_KITS_ANI_RESOURCE_MANAGER_CONVERT_H +#define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INTERFACE_KITS_ANI_RESOURCE_MANAGER_CONVERT_H + +#include + +#include "bundle_mgr_interface.h" + +namespace OHOS { +namespace AppExecFwk { +class AniResourceManagerCommon { +public: + static ani_object ConvertBundleResourceInfo(ani_env* env, const BundleResourceInfo& bundleResInfo); + static ani_object ConvertLauncherAbilityResourceInfo( + ani_env* env, const LauncherAbilityResourceInfo& launcherAbilityResInfo); +}; +} +} +#endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INTERFACE_KITS_ANI_RESOURCE_MANAGER_CONVERT_H \ No newline at end of file diff --git a/interfaces/kits/ani/resource_manager/ani_resource_manager_unsupport.cpp b/interfaces/kits/ani/resource_manager/ani_resource_manager_unsupport.cpp index b14747b1c7..a57ff20aed 100644 --- a/interfaces/kits/ani/resource_manager/ani_resource_manager_unsupport.cpp +++ b/interfaces/kits/ani/resource_manager/ani_resource_manager_unsupport.cpp @@ -27,7 +27,7 @@ constexpr const char* NS_NAME_RESOURCEMANAGER = "@ohos.bundle.bundleResourceMana } static ani_object AniGetBundleResourceInfo(ani_env* env, ani_string aniBundleName, - ani_double aniResFlag, ani_double aniAppIndex) + ani_long aniResFlag, ani_int aniAppIndex) { APP_LOGI("SystemCapability.BundleManager.BundleFramework.Resource not supported"); BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_BUNDLE_RESOURCE_INFO, ""); @@ -35,27 +35,35 @@ static ani_object AniGetBundleResourceInfo(ani_env* env, ani_string aniBundleNam } static ani_object AniGetLauncherAbilityResourceInfo(ani_env* env, ani_string aniBundleName, - ani_double aniResFlag, ani_double aniAppIndex) + ani_long aniResFlag, ani_int aniAppIndex) { APP_LOGI("SystemCapability.BundleManager.BundleFramework.Resource not supported"); BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_LAUNCHER_ABILITY_RESOURCE_INFO, ""); return nullptr; } -static ani_object AniGetAllBundleResourceInfo(ani_env* env, ani_double aniResFlag) +static ani_object AniGetAllBundleResourceInfo(ani_env* env, ani_long aniResFlag) { APP_LOGI("SystemCapability.BundleManager.BundleFramework.Resource not supported"); BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_ALL_BUNDLE_RESOURCE_INFO, ""); return nullptr; } -static ani_object AniGetAllLauncherAbilityResourceInfo(ani_env* env, ani_double aniResFlag) +static ani_object AniGetAllLauncherAbilityResourceInfo(ani_env* env, ani_long aniResFlag) { APP_LOGI("SystemCapability.BundleManager.BundleFramework.Resource not supported"); BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_ALL_LAUNCHER_ABILITY_RESOURCE_INFO, ""); return nullptr; } +static ani_object GetExtensionAbilityResourceInfoNative(ani_env* env, ani_string aniBundleName, + ani_enum_item aniExtensionAbilityType, ani_int aniResourceFlags, ani_int aniAppIndex) +{ + APP_LOGI("SystemCapability.BundleManager.BundleFramework.Resource not supported"); + BusinessErrorAni::ThrowCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_EXTENSION_ABILITY_RESOURCE_INFO, ""); + return nullptr; +} + extern "C" { ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) { @@ -80,7 +88,9 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) ani_native_function { "getAllBundleResourceInfoNative", nullptr, reinterpret_cast(AniGetAllBundleResourceInfo) }, ani_native_function { "getAllLauncherAbilityResourceInfoNative", nullptr, - reinterpret_cast(AniGetAllLauncherAbilityResourceInfo) } + reinterpret_cast(AniGetAllLauncherAbilityResourceInfo) }, + ani_native_function { "getExtensionAbilityResourceInfoNative", nullptr, + reinterpret_cast(GetExtensionAbilityResourceInfoNative) } }; status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); diff --git a/interfaces/kits/ani/resource_manager/ets/@ohos.bundle.bundleResourceManager.ets b/interfaces/kits/ani/resource_manager/ets/@ohos.bundle.bundleResourceManager.ets index 652144da09..8a22d743ee 100644 --- a/interfaces/kits/ani/resource_manager/ets/@ohos.bundle.bundleResourceManager.ets +++ b/interfaces/kits/ani/resource_manager/ets/@ohos.bundle.bundleResourceManager.ets @@ -21,12 +21,13 @@ import { AsyncCallback, BusinessError } from '@ohos.base'; import { BundleResourceInfo } from 'bundleManager.BundleResourceInfo'; import { LauncherAbilityResourceInfo } from 'bundleManager.LauncherAbilityResourceInfo'; +import bundleManager from '@ohos.bundle.bundleManager'; export default namespace bundleResourceManager { loadLibraryWithPermissionCheck("ani_bundle_res_manager.z", "@ohos.bundle.bundleResourceManager"); - const INVALID_INT: number = -500; + const INVALID_VALUE: int = -500; enum ResourceFlag { GET_RESOURCE_INFO_ALL = 0x00000001, @@ -37,38 +38,44 @@ export default namespace bundleResourceManager { GET_RESOURCE_INFO_ONLY_WITH_MAIN_ABILITY = 0x00000020 } - export native function getBundleResourceInfoNative(bundleName: string, resourceFlags: number, appIndex: number): BundleResourceInfo; - export native function getLauncherAbilityResourceInfoNative(bundleName: string, resourceFlags: number, appIndex: number): Array; - export native function getAllBundleResourceInfoNative(resourceFlags: number): Array; - export native function getAllLauncherAbilityResourceInfoNative(resourceFlags: number): Array; + export native function getBundleResourceInfoNative(bundleName: string, resourceFlags: int, appIndex: int): BundleResourceInfo; + export native function getLauncherAbilityResourceInfoNative(bundleName: string, resourceFlags: int, appIndex: int): Array; + export native function getAllBundleResourceInfoNative(resourceFlags: int): Array; + export native function getAllLauncherAbilityResourceInfoNative(resourceFlags: int): Array; + export native function getExtensionAbilityResourceInfoNative(bundleName: string, extensionAbilityType: bundleManager.ExtensionAbilityType, resourceFlags: int, appIndex: int): Array; - function getBundleResourceInfo(bundleName: string, resourceFlags?: number): BundleResourceInfo + function getBundleResourceInfo(bundleName: string, resourceFlags?: int): BundleResourceInfo { - let resFlag = resourceFlags ?? INVALID_INT; - return bundleResourceManager.getBundleResourceInfoNative(bundleName, resFlag, INVALID_INT); + let resFlag = resourceFlags ?? INVALID_VALUE; + return bundleResourceManager.getBundleResourceInfoNative(bundleName, resFlag, INVALID_VALUE); } - function getBundleResourceInfo(bundleName: string, resourceFlags?: number, appIndex?: number): BundleResourceInfo + function getBundleResourceInfo(bundleName: string, resourceFlags?: int, appIndex?: int): BundleResourceInfo { - let resFlag = resourceFlags ?? INVALID_INT; - let appIdx = appIndex ?? INVALID_INT; + let resFlag = resourceFlags ?? INVALID_VALUE; + let appIdx = appIndex ?? INVALID_VALUE; return bundleResourceManager.getBundleResourceInfoNative(bundleName, resFlag, appIdx); } - function getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: number): Array + function getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: int): Array { - let resFlag = resourceFlags ?? INVALID_INT; - return bundleResourceManager.getLauncherAbilityResourceInfoNative(bundleName, resFlag, INVALID_INT); + let resFlag = resourceFlags ?? INVALID_VALUE; + return bundleResourceManager.getLauncherAbilityResourceInfoNative(bundleName, resFlag, INVALID_VALUE); } - function getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: number, appIndex?: number): Array + function getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: int, appIndex?: int): Array { - let resFlag = resourceFlags ?? INVALID_INT; - let appIdx = appIndex ?? INVALID_INT; + let resFlag = resourceFlags ?? INVALID_VALUE; + let appIdx = appIndex ?? INVALID_VALUE; return bundleResourceManager.getLauncherAbilityResourceInfoNative(bundleName, resFlag, appIdx); } - function getAllBundleResourceInfo(resourceFlags: number, callback: AsyncCallback>): void { + function getExtensionAbilityResourceInfo(bundleName: string, extensionAbilityType: bundleManager.ExtensionAbilityType, resourceFlags: int, appIndex?: int): Array { + let appIdx = appIndex ?? INVALID_VALUE; + return getExtensionAbilityResourceInfoNative(bundleName, extensionAbilityType, resourceFlags, appIdx); + } + + function getAllBundleResourceInfo(resourceFlags: int, callback: AsyncCallback>): void { let cb = (): (Array) => { return bundleResourceManager.getAllBundleResourceInfoNative(resourceFlags); }; @@ -81,7 +88,7 @@ export default namespace bundleResourceManager { }); } - function getAllBundleResourceInfo(resourceFlags: number): Promise> { + function getAllBundleResourceInfo(resourceFlags: int): Promise> { let p = new Promise>((resolve: (arrBundleResourceInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return bundleResourceManager.getAllBundleResourceInfoNative(resourceFlags); @@ -97,7 +104,7 @@ export default namespace bundleResourceManager { return p; } - function getAllLauncherAbilityResourceInfo(resourceFlags: number, callback: AsyncCallback>): void { + function getAllLauncherAbilityResourceInfo(resourceFlags: int, callback: AsyncCallback>): void { let cb = (): (Array) => { return bundleResourceManager.getAllLauncherAbilityResourceInfoNative(resourceFlags); }; @@ -110,7 +117,7 @@ export default namespace bundleResourceManager { }); } - function getAllLauncherAbilityResourceInfo(resourceFlags: number): Promise> { + function getAllLauncherAbilityResourceInfo(resourceFlags: int): Promise> { let p = new Promise>((resolve: (arrLauncherAbilityResourceInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return bundleResourceManager.getAllLauncherAbilityResourceInfoNative(resourceFlags); diff --git a/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfo.ets b/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfo.ets index 1cf0f5cd31..256975f8a6 100644 --- a/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfo.ets +++ b/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfo.ets @@ -17,5 +17,5 @@ export interface BundleResourceInfo { readonly bundleName: string; readonly icon: string; readonly label: string; - readonly appIndex: number; + readonly appIndex: int; } \ No newline at end of file diff --git a/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfoInner.ets b/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfoInner.ets index a54fdcd2bc..87157c3735 100644 --- a/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfoInner.ets +++ b/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfoInner.ets @@ -19,5 +19,16 @@ export class BundleResourceInfoInner implements BundleResourceInfo { readonly bundleName: string = ''; readonly icon: string = ''; readonly label: string = ''; - readonly appIndex: number; + readonly appIndex: int; + + constructor() { } + constructor(bundleName: string, + icon: string, + label: string, + appIndex: int) { + this.bundleName = bundleName; + this.icon = icon; + this.label = label; + this.appIndex = appIndex; + } } diff --git a/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfo.ets b/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfo.ets index 9f90522b84..f383bf23fd 100644 --- a/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfo.ets +++ b/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfo.ets @@ -13,16 +13,11 @@ * limitations under the License. */ -/** - * @file - * @kit AbilityKit - */ - export interface LauncherAbilityResourceInfo { readonly bundleName: string; readonly moduleName: string; readonly abilityName: string; readonly icon: string; readonly label: string; - readonly appIndex: number; + readonly appIndex: int; } diff --git a/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfoInner.ets b/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfoInner.ets index c2dfb19591..e7e32b91ce 100644 --- a/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfoInner.ets +++ b/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfoInner.ets @@ -13,11 +13,6 @@ * limitations under the License. */ -/** - * @file - * @kit AbilityKit - */ - import { LauncherAbilityResourceInfo } from 'bundleManager.LauncherAbilityResourceInfo'; export class LauncherAbilityResourceInfoInner implements LauncherAbilityResourceInfo { @@ -26,5 +21,20 @@ export class LauncherAbilityResourceInfoInner implements LauncherAbilityResource readonly abilityName: string = ''; readonly icon: string = ''; readonly label: string = ''; - readonly appIndex: number; + readonly appIndex: int; + + constructor() { } + constructor(bundleName: string, + moduleName: string, + abilityName: string, + icon: string, + label: string, + appIndex: int) { + this.bundleName = bundleName; + this.moduleName = moduleName; + this.abilityName = abilityName; + this.icon = icon; + this.label = label; + this.appIndex = appIndex; + } } diff --git a/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp b/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp index 12d2c9af19..2554df07f8 100644 --- a/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp +++ b/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp @@ -30,22 +30,14 @@ namespace { constexpr const char* NS_NAME_SHORTCUTMANAGER = "@ohos.bundle.shortcutManager.shortcutManager"; } -static void AniAddDesktopShortcutInfo(ani_env* env, ani_object info, ani_double aniUserId) +static void AniAddDesktopShortcutInfo(ani_env* env, ani_object info, ani_int aniUserId) { APP_LOGD("ani AddDesktopShortcutInfo called"); - int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGE("Cast aniUserId failed"); - BusinessErrorAni::ThrowCommonError( - env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); - return; - } - ShortcutInfo shortcutInfo; if (!CommonFunAni::ParseShortcutInfo(env, info, shortcutInfo) || !CommonFunc::CheckShortcutInfo(shortcutInfo)) { BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, INVALID_SHORTCUT_INFO_ERROR); - APP_LOGE("Parse shortcutInfo err. userId:%{public}d", userId); + APP_LOGE("Parse shortcutInfo err. userId:%{public}d", aniUserId); return; } @@ -55,29 +47,21 @@ static void AniAddDesktopShortcutInfo(ani_env* env, ani_object info, ani_double BusinessErrorAni::ThrowError(env, ERR_APPEXECFWK_SERVICE_NOT_READY, ADD_DESKTOP_SHORTCUT_INFO); return; } - ErrCode ret = iBundleMgr->AddDesktopShortcutInfo(shortcutInfo, userId); + ErrCode ret = iBundleMgr->AddDesktopShortcutInfo(shortcutInfo, aniUserId); if (ret != ERR_OK) { - APP_LOGE("AddDesktopShortcutInfo failed ret:%{public}d,userId:%{public}d", ret, userId); + APP_LOGE("AddDesktopShortcutInfo failed ret:%{public}d,userId:%{public}d", ret, aniUserId); BusinessErrorAni::ThrowCommonError( env, CommonFunc::ConvertErrCode(ret), ADD_DESKTOP_SHORTCUT_INFO, Constants::PERMISSION_MANAGER_SHORTCUT); } } -static void AniDeleteDesktopShortcutInfo(ani_env* env, ani_object info, ani_double aniUserId) +static void AniDeleteDesktopShortcutInfo(ani_env* env, ani_object info, ani_int aniUserId) { APP_LOGD("ani DeleteDesktopShortcutInfo called"); - int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGE("Cast aniUserId failed"); - BusinessErrorAni::ThrowCommonError( - env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); - return; - } - ShortcutInfo shortcutInfo; if (!CommonFunAni::ParseShortcutInfo(env, info, shortcutInfo) || !CommonFunc::CheckShortcutInfo(shortcutInfo)) { - APP_LOGE("Parse shortcutInfo failed. userId:%{public}d", userId); + APP_LOGE("Parse shortcutInfo err. userId:%{public}d", aniUserId); BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, INVALID_SHORTCUT_INFO_ERROR); return; } @@ -88,26 +72,18 @@ static void AniDeleteDesktopShortcutInfo(ani_env* env, ani_object info, ani_doub BusinessErrorAni::ThrowError(env, ERR_APPEXECFWK_SERVICE_NOT_READY, DELETE_DESKTOP_SHORTCUT_INFO); return; } - ErrCode ret = iBundleMgr->DeleteDesktopShortcutInfo(shortcutInfo, userId); + ErrCode ret = iBundleMgr->DeleteDesktopShortcutInfo(shortcutInfo, aniUserId); if (ret != ERR_OK) { - APP_LOGE("DeleteDesktopShortcutInfo failed ret:%{public}d,userId:%{public}d", ret, userId); + APP_LOGE("DeleteDesktopShortcutInfo failed ret:%{public}d,userId:%{public}d", ret, aniUserId); BusinessErrorAni::ThrowCommonError( env, CommonFunc::ConvertErrCode(ret), DELETE_DESKTOP_SHORTCUT_INFO, Constants::PERMISSION_MANAGER_SHORTCUT); } } -static ani_ref AniGetAllDesktopShortcutInfo(ani_env* env, ani_double aniUserId) +static ani_ref AniGetAllDesktopShortcutInfo(ani_env* env, ani_int aniUserId) { APP_LOGD("ani GetAllDesktopShortcutInfo called"); - int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGE("Cast aniUserId failed"); - BusinessErrorAni::ThrowCommonError( - env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); - return nullptr; - } - std::vector shortcutInfos; auto iBundleMgr = CommonFunc::GetBundleMgr(); if (iBundleMgr == nullptr) { @@ -115,9 +91,9 @@ static ani_ref AniGetAllDesktopShortcutInfo(ani_env* env, ani_double aniUserId) BusinessErrorAni::ThrowError(env, ERR_APPEXECFWK_SERVICE_NOT_READY, GET_ALL_DESKTOP_SHORTCUT_INFO); return nullptr; } - ErrCode ret = iBundleMgr->GetAllDesktopShortcutInfo(userId, shortcutInfos); + ErrCode ret = iBundleMgr->GetAllDesktopShortcutInfo(aniUserId, shortcutInfos); if (ret != ERR_OK) { - APP_LOGE("GetAllDesktopShortcutInfo failed ret:%{public}d,userId:%{public}d", ret, userId); + APP_LOGE("GetAllDesktopShortcutInfo failed ret:%{public}d,userId:%{public}d", ret, aniUserId); BusinessErrorAni::ThrowCommonError( env, CommonFunc::ConvertErrCode(ret), GET_ALL_DESKTOP_SHORTCUT_INFO, Constants::PERMISSION_MANAGER_SHORTCUT); @@ -131,6 +107,57 @@ static ani_ref AniGetAllDesktopShortcutInfo(ani_env* env, ani_double aniUserId) return shortcutInfosRef; } +static void SetShortcutVisibleForSelfNative(ani_env* env, ani_string aniId, ani_boolean aniVisible) +{ + APP_LOGD("ani SetShortcutVisibleForSelf called"); + std::string shortcutId; + if (!CommonFunAni::ParseString(env, aniId, shortcutId)) { + APP_LOGE("parse shortcutId failed"); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, SHORTCUT_ID, TYPE_STRING); + return; + } + bool visible = CommonFunAni::AniBooleanToBool(aniVisible); + + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("Can not get iBundleMgr"); + BusinessErrorAni::ThrowCommonError( + env, CommonFunc::ConvertErrCode(ERR_APPEXECFWK_SERVICE_NOT_READY), SET_SHORTCUT_VISIBLE, ""); + return; + } + ErrCode ret = iBundleMgr->SetShortcutVisibleForSelf(shortcutId, visible); + if (ret != ERR_OK) { + APP_LOGE("SetShortcutVisibleForSelf failed ret:%{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), SET_SHORTCUT_VISIBLE, ""); + } +} + +static ani_object GetAllShortcutInfoForSelfNative(ani_env* env) +{ + APP_LOGD("ani GetAllShortcutInfoForSelf called"); + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("Can not get iBundleMgr"); + BusinessErrorAni::ThrowCommonError( + env, CommonFunc::ConvertErrCode(ERR_APPEXECFWK_NULL_PTR), GET_ALL_SHORTCUT_INFO_FOR_SELF, ""); + return nullptr; + } + std::vector shortcutInfos; + ErrCode ret = iBundleMgr->GetAllShortcutInfoForSelf(shortcutInfos); + if (ret != ERR_OK) { + APP_LOGE("GetAllShortcutInfoForSelf failed ret:%{public}d", ret); + BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), GET_ALL_SHORTCUT_INFO_FOR_SELF, ""); + return nullptr; + } + ani_object shortcutInfosObject = + CommonFunAni::ConvertAniArray(env, shortcutInfos, CommonFunAni::ConvertShortcutInfo); + if (shortcutInfosObject == nullptr) { + APP_LOGE("nullptr shortcutInfosRef"); + } + + return shortcutInfosObject; +} + extern "C" { ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) { @@ -154,6 +181,10 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) reinterpret_cast(AniDeleteDesktopShortcutInfo) }, ani_native_function { "getAllDesktopShortcutInfoNative", nullptr, reinterpret_cast(AniGetAllDesktopShortcutInfo) }, + ani_native_function { "setShortcutVisibleForSelfNative", nullptr, + reinterpret_cast(SetShortcutVisibleForSelfNative) }, + ani_native_function { "getAllShortcutInfoForSelfNative", nullptr, + reinterpret_cast(GetAllShortcutInfoForSelfNative) }, }; status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); diff --git a/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets b/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets index 7215ab5a77..2ce2347378 100644 --- a/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets +++ b/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets @@ -20,18 +20,36 @@ namespace shortcutManager { loadLibraryWithPermissionCheck("ani_shortcut_manager.z", "@ohos.bundle.shortcutManager"); - export native function addDesktopShortcutInfoNative(shortcutInfo: ShortcutInfo, userId: number): void; - export native function deleteDesktopShortcutInfoNative(shortcutInfo: ShortcutInfo, userId: number): void; - export native function getAllDesktopShortcutInfoNative(userId: number): Array; + function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'Error'; + err.message = message; + return err; + } + + const ERROR_SOURCETYPE : int = -1; + const MAIN_APP_INDEX: int = 0; + const ERROR_PARAM_CHECK_ERROR: int = 401; + const INVALID_SHORTCUT_INFO_ERROR: string = "invalid ShortcutInfo: parameter type error, or appIndex is less than 0"; - function addDesktopShortcutInfo(shortcutInfo: ShortcutInfo, userId: number): Promise { - let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void): void => { + export native function addDesktopShortcutInfoNative(shortcutInfo: ShortcutInfo, userId: int): void; + export native function deleteDesktopShortcutInfoNative(shortcutInfo: ShortcutInfo, userId: int): void; + export native function getAllDesktopShortcutInfoNative(userId: int): Array; + export native function setShortcutVisibleForSelfNative(id: string, visible: boolean): void; + export native function getAllShortcutInfoForSelfNative(): Array; + + function addDesktopShortcutInfo(shortcutInfo: ShortcutInfo, userId: int): Promise { + if (shortcutInfo.appIndex < MAIN_APP_INDEX || shortcutInfo.sourceType === ERROR_SOURCETYPE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, INVALID_SHORTCUT_INFO_ERROR); + } + let p = new Promise((resolve: (v: PromiseLike) => void, reject: (error: BusinessError) => void): void => { let cb = (): NullishType => { return shortcutManager.addDesktopShortcutInfoNative(shortcutInfo, userId); } let p1 = taskpool.execute(cb); p1.then((): void => { - resolve(undefined); + resolve(Promise.resolve()); }, (err: Error): void => { reject(err as BusinessError); }); @@ -39,14 +57,17 @@ namespace shortcutManager { return p; } - function deleteDesktopShortcutInfo(shortcutInfo: ShortcutInfo, userId: number): Promise { - let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void): void => { + function deleteDesktopShortcutInfo(shortcutInfo: ShortcutInfo, userId: int): Promise { + if (shortcutInfo.appIndex < MAIN_APP_INDEX || shortcutInfo.sourceType === ERROR_SOURCETYPE) { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, INVALID_SHORTCUT_INFO_ERROR); + } + let p = new Promise((resolve: (v: PromiseLike) => void, reject: (error: BusinessError) => void): void => { let cb = (): NullishType => { return shortcutManager.deleteDesktopShortcutInfoNative(shortcutInfo, userId) } let p1 = taskpool.execute(cb); p1.then((): void => { - resolve(undefined); + resolve(Promise.resolve()); }, (err: Error): void => { reject(err as BusinessError); }); @@ -54,7 +75,7 @@ namespace shortcutManager { return p; } - function getAllDesktopShortcutInfo(userId: number): Promise> { + function getAllDesktopShortcutInfo(userId: int): Promise> { let p = new Promise>((resolve: (arrShortcutInfo: Array) => void, reject: (error: BusinessError) => void) => { let cb = (): (Array) => { return shortcutManager.getAllDesktopShortcutInfoNative(userId); @@ -70,6 +91,37 @@ namespace shortcutManager { return p; } + function setShortcutVisibleForSelf(id: string, visible: boolean): Promise { + let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void): void => { + let cb = (): NullishType => { + return shortcutManager.setShortcutVisibleForSelfNative(id, visible); + } + let p1 = taskpool.execute(cb); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + }); + return p; + } + + function getAllShortcutInfoForSelf(): Promise> { + let p = new Promise>((resolve: (arrShortcutInfo: Array) => void, reject: (error: BusinessError) => void) => { + let cb = (): (Array) => { + return shortcutManager.getAllShortcutInfoForSelfNative(); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let result: Array = e as Array; + resolve(result); + }, (err: Error): void => { + reject(err as BusinessError); + }); + }); + return p; + } + export type ShortcutInfo = _ShortcutInfo; export type ShortcutWant = _ShortcutWant; export type ParameterItem = _ParameterItem; diff --git a/interfaces/kits/ani/shortcut_manager/ets/bundleManager/ShortcutInfo.ets b/interfaces/kits/ani/shortcut_manager/ets/bundleManager/ShortcutInfo.ets index b73302a42a..69b564af92 100644 --- a/interfaces/kits/ani/shortcut_manager/ets/bundleManager/ShortcutInfo.ets +++ b/interfaces/kits/ani/shortcut_manager/ets/bundleManager/ShortcutInfo.ets @@ -19,12 +19,12 @@ export interface ShortcutInfo { moduleName?: string; hostAbility?: string; icon?: string; - iconId?: number; + iconId?: long; label?: string; - labelId?: number; + labelId?: long; wants?: Array; - appIndex: number; - sourceType: number; + appIndex: int; + sourceType: int; visible?: boolean; } @@ -46,13 +46,40 @@ export class ShortcutInfoInner implements ShortcutInfo { moduleName?: string | undefined; hostAbility?: string | undefined; icon?: string | undefined; - iconId?: number | undefined; + iconId?: long | undefined; label?: string | undefined; - labelId?: number | undefined; + labelId?: long | undefined; wants?: Array | undefined; - appIndex: number; - sourceType: number; + appIndex: int; + sourceType: int; public visible?: boolean | undefined; + + constructor() { } + constructor(id: string, + bundleName: string, + appIndex: int, + sourceType: int, + moduleName?: string, + hostAbility?: string, + icon?: string, + iconId?: long, + label?: string, + labelId?: long, + wants?: Array, + visible?: boolean) { + this.id = id; + this.bundleName = bundleName; + this.appIndex = appIndex; + this.sourceType = sourceType; + this.moduleName = moduleName; + this.hostAbility = hostAbility; + this.icon = icon; + this.iconId = iconId; + this.label = label; + this.labelId = labelId; + this.wants = wants; + this.visible = visible; + } } class ShortcutWantInner implements ShortcutWant { @@ -60,9 +87,25 @@ class ShortcutWantInner implements ShortcutWant { targetModule?: string | undefined; targetAbility: string = ""; parameters?: Array | undefined; + + constructor() { } + constructor(targetBundle: string, + targetAbility: string, + targetModule?: string, + parameters?: Array) { + this.targetBundle = targetBundle; + this.targetAbility = targetAbility; + this.targetModule = targetModule; + this.parameters = parameters; + } } class ParameterItemInner implements ParameterItem { key: string = ""; value: string = ""; + constructor() { } + constructor(key: string, value: string) { + this.key = key; + this.value = value; + } } diff --git a/interfaces/kits/ani/zlib/BUILD.gn b/interfaces/kits/ani/zlib/BUILD.gn index 75fd490c43..ddfc06df87 100644 --- a/interfaces/kits/ani/zlib/BUILD.gn +++ b/interfaces/kits/ani/zlib/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos.gni") import("//foundation/bundlemanager/bundle_framework/appexecfwk.gni") ohos_shared_library("ani_zlib") { + shlib_type = "ani" branch_protector_ret = "pac_ret" sanitize = { @@ -43,11 +44,11 @@ ohos_shared_library("ani_zlib") { sources = [ "${kits_path}/js/zip/src/file_path.cpp", + "${kits_path}/js/zip/src/zip.cpp", "${kits_path}/js/zip/src/zip_internal.cpp", "${kits_path}/js/zip/src/zip_reader.cpp", "${kits_path}/js/zip/src/zip_utils.cpp", "${kits_path}/js/zip/src/zip_writer.cpp", - "${kits_path}/js/zip/src/zip.cpp", "ani_zlib.cpp", ] diff --git a/interfaces/kits/ani/zlib/ani_zlib.cpp b/interfaces/kits/ani/zlib/ani_zlib.cpp index a02c3cccde..98611388d7 100644 --- a/interfaces/kits/ani/zlib/ani_zlib.cpp +++ b/interfaces/kits/ani/zlib/ani_zlib.cpp @@ -356,7 +356,7 @@ static ani_object CreateChecksumSync(ani_env* env) Type checksumType = Builder::BuildClass({ zlibNS.Name(), TYPE_NAME_CHECKSUMINTERNAL }); ani_class clsChecksum = CommonFunAni::CreateClassByName(env, checksumType.Descriptor()); RETURN_NULL_IF_NULL(clsChecksum); - ani_object objChecksum = CommonFunAni::CreateNewObjectByClass(env, clsChecksum); + ani_object objChecksum = CommonFunAni::CreateNewObjectByClass(env, checksumType.Descriptor(), clsChecksum); return objChecksum; } @@ -365,7 +365,7 @@ static ani_double Adler32( { int64_t adler = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAdler, &adler)) { + if (!CommonFunAni::TryCastTo(aniAdler, &adler)) { APP_LOGE("Cast aniAdler failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_ADLER, TYPE_NUMBER); return 0; @@ -400,19 +400,19 @@ static ani_double Adler32Combine(ani_env* env, int64_t adler2 = 0; int64_t len2 = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAdler1, &adler1)) { + if (!CommonFunAni::TryCastTo(aniAdler1, &adler1)) { APP_LOGE("Cast aniAdler1 failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_ADLER1, TYPE_NUMBER); return 0; } - if (!CommonFunAni::TryCastDoubleTo(aniAdler2, &adler2)) { + if (!CommonFunAni::TryCastTo(aniAdler2, &adler2)) { APP_LOGE("Cast aniAdler2 failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_ADLER2, TYPE_NUMBER); return 0; } - if (!CommonFunAni::TryCastDoubleTo(aniLen2, &len2) || len2 < 0) { + if (!CommonFunAni::TryCastTo(aniLen2, &len2) || len2 < 0) { APP_LOGE("Cast aniLen2 failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_LEN2, TYPE_NUMBER); return 0; @@ -429,7 +429,7 @@ static ani_double Crc32(ani_env* env, [[maybe_unused]] ani_object checksumObj, a { int64_t crc = 0; - if (!CommonFunAni::TryCastDoubleTo(aniCrc, &crc)) { + if (!CommonFunAni::TryCastTo(aniCrc, &crc)) { APP_LOGE("Cast aniCrc failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_CRC, TYPE_NUMBER); return 0; @@ -464,19 +464,19 @@ static ani_double Crc32Combine(ani_env* env, int64_t crc2 = 0; int64_t len2 = 0; - if (!CommonFunAni::TryCastDoubleTo(aniCrc1, &crc1)) { + if (!CommonFunAni::TryCastTo(aniCrc1, &crc1)) { APP_LOGE("Cast aniCrc1 failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_CRC1, TYPE_NUMBER); return 0; } - if (!CommonFunAni::TryCastDoubleTo(aniCrc2, &crc2)) { + if (!CommonFunAni::TryCastTo(aniCrc2, &crc2)) { APP_LOGE("Cast aniCrc2 failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_CRC2, TYPE_NUMBER); return 0; } - if (!CommonFunAni::TryCastDoubleTo(aniLen2, &len2) || len2 < 0) { + if (!CommonFunAni::TryCastTo(aniLen2, &len2) || len2 < 0) { APP_LOGE("Cast aniLen2 failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_LEN2, TYPE_NUMBER); return 0; @@ -493,7 +493,7 @@ static ani_double Crc64(ani_env* env, [[maybe_unused]] ani_object checksumObj, a { uint64_t crc = 0; - if (!CommonFunAni::TryCastDoubleTo(aniCrc, &crc)) { + if (!CommonFunAni::TryCastTo(aniCrc, &crc)) { APP_LOGE("Cast aniCrc failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_CRC, TYPE_NUMBER); return 0; -- Gitee