diff --git a/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp b/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp index 81b231fcbf076155ad9a2a01bbe07492be7133c8..a47efc92829298ed1883da4cac4c1406ba851b56 100644 --- a/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp +++ b/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp @@ -410,7 +410,7 @@ static void AniDestroyAppClone(ani_env* env, [[maybe_unused]] ani_object install return; } int32_t appIdx = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIdx)) { + if (!CommonFunAni::TryCastTo(aniAppIndex, &appIdx)) { APP_LOGE("Cast appIdx failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); return; @@ -443,7 +443,7 @@ static void AniInstallPreexistingApp(ani_env* env, [[maybe_unused]] ani_object i return; } int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGE("Cast appIdx failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); return; 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 84692d5356e55d7588c76031212467de8e612a11..f6301353d0c1dcf6e66c90c431fa07f1d858786b 100644 --- a/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installer.ets +++ b/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installer.ets @@ -96,7 +96,7 @@ namespace installer { createAppClone(bundleName: string, createAppCloneParam?: CreateAppCloneParam): Promise; - destroyAppClone(bundleName: string, appIndex: number, options?: number | DestroyAppCloneParam): Promise; + destroyAppClone(bundleName: string, appIndex: number, options?: int | DestroyAppCloneParam): Promise; installPreexistingApp(bundleName: string, userId?: number): Promise; @@ -121,11 +121,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 +135,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 4c81093a3943326d7719e34c42507a878cc7e5b9..f742414bd3bebc4cf7d12e5a21c6f310e870ba78 100644 --- a/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets +++ b/interfaces/kits/ani/bundle_installer/ets/@ohos.bundle.installerInner.ets @@ -37,11 +37,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 +51,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,7 +73,7 @@ export class DestroyAppCloneParamInner implements installer.DestroyAppCloneParam } export class PluginParamInner implements installer.PluginParam { - userId?: number; + userId?: int; parameters?: Array; } @@ -333,7 +333,7 @@ export class BundleInstallerInner implements installer.BundleInstaller { return p; } - destroyAppClone(bundleName: string, appIndex: number, options?: number | installer.DestroyAppCloneParam): Promise { + destroyAppClone(bundleName: string, appIndex: number, options?: int | installer.DestroyAppCloneParam): Promise { let defaultParam = new DestroyAppCloneParamInner(); let option = options ?? defaultParam; if (option instanceof installer.DestroyAppCloneParam) { diff --git a/interfaces/kits/ani/bundle_manager/BUILD.gn b/interfaces/kits/ani/bundle_manager/BUILD.gn index 737a910eb53f1f9d3fa85561612728ca91331bf0..7c803fc367f8458e492e2c5045689f2974a9dd2e 100644 --- a/interfaces/kits/ani/bundle_manager/BUILD.gn +++ b/interfaces/kits/ani/bundle_manager/BUILD.gn @@ -66,13 +66,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 +225,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 079974d16dde3185246ba75b7a4985dd23d2c8a2..766cbbbe4f6ce4c477c635a672681bd857832772 100644 --- a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp +++ b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp @@ -177,7 +177,7 @@ static ani_object GetBundleInfoForSelfNative(ani_env* env, ani_double aniBundleF { APP_LOGD("ani GetBundleInfoForSelf called"); int32_t bundleFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniBundleFlags, &bundleFlags)) { + if (!CommonFunAni::TryCastTo(aniBundleFlags, &bundleFlags)) { APP_LOGE("Cast aniBundleFlags failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_FLAGS, TYPE_NUMBER); return nullptr; @@ -224,13 +224,13 @@ static ani_object GetBundleInfoNative(ani_env* env, { APP_LOGD("ani GetBundleInfo called"); int32_t bundleFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniBundleFlags, &bundleFlags)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } int32_t callingUid = IPCSkeleton::GetCallingUid(); @@ -289,13 +289,13 @@ static ani_object GetApplicationInfoNative(ani_env* env, { APP_LOGD("ani GetApplicationInfo called"); int32_t applicationFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniApplicationFlags, &applicationFlags)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } std::string bundleName; @@ -351,13 +351,13 @@ static ani_object GetAllBundleInfoNative(ani_env* env, ani_double aniBundleFlags { APP_LOGD("ani GetAllBundleInfo called"); int32_t bundleFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniBundleFlags, &bundleFlags)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } if (userId == EMPTY_USER_ID) { @@ -387,13 +387,13 @@ static ani_object GetAllApplicationInfoNative(ani_env* env, ani_double aniApplic { APP_LOGD("ani GetAllApplicationInfo called"); int32_t applicationFlags = 0; - if (!CommonFunAni::TryCastDoubleTo(aniApplicationFlags, &applicationFlags)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } @@ -432,7 +432,7 @@ static ani_boolean IsApplicationEnabledNative(ani_env* env, return isEnable; } int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { + if (!CommonFunAni::TryCastTo(aniAppIndex, &appIndex)) { APP_LOGE("Cast aniAppIndex failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); return isEnable; @@ -475,12 +475,12 @@ static ani_object QueryAbilityInfoSyncNative(ani_env* env, BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, INVALID_WANT_ERROR); return nullptr; } - if (!CommonFunAni::TryCastDoubleTo(aniAbilityFlags, &abilityFlags)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } @@ -521,7 +521,7 @@ static ani_object GetAppCloneIdentityNative(ani_env* env, ani_double aniUid) { APP_LOGD("ani GetAppCloneIdentity called"); int32_t uid = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUid, &uid)) { + if (!CommonFunAni::TryCastTo(aniUid, &uid)) { APP_LOGE("Cast aniUid failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::UID, TYPE_NUMBER); return nullptr; @@ -620,7 +620,7 @@ static ani_object GetLaunchWantForBundleNative(ani_env* env, return nullptr; } int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } if (userId == EMPTY_USER_ID) { @@ -657,19 +657,19 @@ static ani_object GetAppCloneBundleInfoNative(ani_env* env, ani_string aniBundle return nullptr; } int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, use default value"); } if (userId == EMPTY_USER_ID) { @@ -730,7 +730,7 @@ static ani_string GetBundleNameByUidNative(ani_env* env, ani_double aniUserId, a { APP_LOGD("ani GetBundleNameByUid called"); int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGE("Cast userId failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, Constants::UID, TYPE_NUMBER); return nullptr; @@ -790,12 +790,12 @@ static ani_object QueryAbilityInfoWithWantsNative(ani_env* env, BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, INVALID_WANT_ERROR); return nullptr; } - if (!CommonFunAni::TryCastDoubleTo(aniAbilityFlags, &abilityFlags)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } @@ -868,7 +868,7 @@ static ani_boolean IsAbilityEnabledNative(ani_env* env, return isEnable; } int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { + if (!CommonFunAni::TryCastTo(aniAppIndex, &appIndex)) { APP_LOGE("Cast aniAppIndex failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); return isEnable; @@ -894,7 +894,7 @@ static void SetAbilityEnabledNative(ani_env* env, return; } int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { + if (!CommonFunAni::TryCastTo(aniAppIndex, &appIndex)) { APP_LOGE("Cast aniAppIndex failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); return; @@ -921,7 +921,7 @@ static void SetApplicationEnabledNative(ani_env* env, return; } int32_t appIndex = 0; - if (!CommonFunAni::TryCastDoubleTo(aniAppIndex, &appIndex)) { + if (!CommonFunAni::TryCastTo(aniAppIndex, &appIndex)) { APP_LOGE("Cast aniAppIndex failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); return; @@ -967,12 +967,12 @@ static ani_object QueryExtensionAbilityInfoNative(ani_env* env, return nullptr; } } - if (!CommonFunAni::TryCastDoubleTo(aniExtensionAbilityFlags, &flags)) { + if (!CommonFunAni::TryCastTo(aniExtensionAbilityFlags, &flags)) { APP_LOGE("Cast aniExtensionAbilityFlags failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, FLAGS, TYPE_NUMBER); return nullptr; } - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } if (userId == EMPTY_USER_ID) { @@ -1044,12 +1044,12 @@ 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)) { + if (!CommonFunAni::TryCastTo(aniExtensionAbilityFlags, &flags)) { APP_LOGE("Cast aniExtensionAbilityFlags failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, FLAGS, TYPE_NUMBER); return nullptr; } - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("Parse userId failed, set this parameter to the caller userId"); } if (userId == EMPTY_USER_ID) { diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfo.ets index e9f0d462096511c79701d235407b17a6c8318aa7..5bb3c63fdb422ec10f25dc4bc895746c74a086e3 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 fa4f2c7c437ac9bf3c6b299434c59a8ff3c79ff8..04034bef8202bd28f0573e7f0dbcd1f4d082f312 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfoInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AbilityInfoInner.ets @@ -25,33 +25,99 @@ 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; + } } 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 0000000000000000000000000000000000000000..a1606cee0fea1953ccd3e22bef61c8b2e162c627 --- /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 0000000000000000000000000000000000000000..b09c7297e32ae70eb332e13748c351b63c233744 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/AppProvisionInfoInner.ets @@ -0,0 +1,36 @@ +/* + * 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 = ''; +} + +export class ValidityInner implements Validity { + public readonly notBefore: long; + public readonly notAfter: long; +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ApplicationInfo.ets index 3699f46f3d9591d35e4227e563460a73408f4850..fb4788dac9c270627b5db78e3262bc93305f515d 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 82a9b34f358b25d33940f2730e8b5d081f1afd6c..962acd86746a99cd9d86e6dc41b9f32ddfcbe9b8 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,106 @@ 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; } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfo.ets index 63841555ba33a1394a5dc85f99fef57702c05fc7..88b4ac156c05a6d877b964e7dd29134307e8ebb4 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 066a7918489621e0c0494ef3c2075ce90276c8c7..61e91e801247f72c5a0e1741f77deab44c62262a 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfoInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/BundleInfoInner.ets @@ -16,39 +16,90 @@ 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; + } } 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 +107,29 @@ 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 | undefined) { + 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; +} + +export class DynamicIconInfoInner implements DynamicIconInfo { + public readonly bundleName: string = ''; + public readonly moduleName: string = ''; + public readonly userId: int; + public readonly appIndex: int; +} + +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 0e54076f5acb8a422a01f72067ae6dd30f24ca04..87ec0233fda2af261874e805bcc06b1303388711 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 0ed1bc765a8971d9a0220fac84867074df0308c0..c00c5750d93a887565740fe3749d19672775f159 100644 --- a/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfoInner.ets +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/ExtensionAbilityInfoInner.ets @@ -24,19 +24,56 @@ 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; + } } diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfo.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/HapModuleInfo.ets index acf816284373a3a1de99bdca9117c2471ce7e839..edd50608a3527934cf1399dd4f3bf3e5163e76d4 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 4022bb7ffb0dca165b4f8a518b9e2bc639b7e185..00fc9d417fd906b836c6d1b898789bab7700c1f8 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,73 @@ 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; + } } 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 +116,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 8005f976a3de3bb15dc7536885f58482e016a4f8..44f70e8a58c012f798b20af0fb8c9b7fe1a5fb92 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 4fa5d528ec70c3fe235ab90b5e0f85881a0a5b7c..c3e59cea7c9ab51453e27636140194d7ea28da40 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 0000000000000000000000000000000000000000..079933c2450cd08fb2efec204da569488582c771 --- /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 0000000000000000000000000000000000000000..86a6b83553b0a6c57b5a9017c7ced09be6c2d03c --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PermissionDefInner.ets @@ -0,0 +1,23 @@ +/* + * 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; +} \ 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 0000000000000000000000000000000000000000..869773e09867eb1113e2f47fbebd4df62b760b50 --- /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 0000000000000000000000000000000000000000..87fae43b91f459a0866d5e9c1f7796cd1116db6b --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/PluginBundleInfoInner.ets @@ -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. + */ + +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; +} + +export class PluginModuleInfoInner implements PluginModuleInfo { + public readonly moduleName: string = ''; + public readonly descriptionId: long; + public readonly description: string = ''; +} 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 0000000000000000000000000000000000000000..55c7331932e137c061c49b47578324eda18769ac --- /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 0000000000000000000000000000000000000000..43cca25ed3c21d34b5ec2c17eccf0d763d145f46 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/RecoverableApplicationInfoInner.ets @@ -0,0 +1,27 @@ +/* + * 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; +} 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 0000000000000000000000000000000000000000..57362770e70ee5a01a6268e4ccdd01833df1cbfe --- /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 0000000000000000000000000000000000000000..3a5c31ab479b32f78797f1e03e984cf96a3e77c6 --- /dev/null +++ b/interfaces/kits/ani/bundle_manager/ets/bundleManager/SharedBundleInfoInner.ets @@ -0,0 +1,32 @@ +/* + * 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; +} + +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; +} diff --git a/interfaces/kits/ani/bundle_manager/ets/bundleManager/Skill.ets b/interfaces/kits/ani/bundle_manager/ets/bundleManager/Skill.ets index 9fa231ab73a153fbf8940da8fc416f1a338ca72b..21835f1ff398b2b48a0f8aa60e4a9372d9036348 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 0cb6db443e34c8d8e63a3492f86afc15283e183e..4496d46e2b9395d6c03b3253b6223113fff23076 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/ets/@ohos.bundle.bundleMonitor.ets b/interfaces/kits/ani/bundle_monitor/ets/@ohos.bundle.bundleMonitor.ets index 6a4478a39e2a5038bfb0fd8c26cab5ac51c24a76..a3e010edc6493b5cf78ff41638942c6d2ad87f33 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,14 @@ 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; } type BundleChangedEvent = 'add' | 'update' | 'remove'; diff --git a/interfaces/kits/ani/common/BUILD.gn b/interfaces/kits/ani/common/BUILD.gn index 789e9fc86fb959f6c0a741e4c66fd196f9b3547f..febafb002b3ff54ebd6d8306161e7d1dc82b788a 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 7eabdeb7f618b5353da50dd8b95d1d8e04d9dbed..e40645b10e4f1397283bdc18686d35989a629ca4 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 fd2c3e6cb28b7abca0a2ec60aa1a878a8bb2ac14..54d5fd26682bec301f35e186136fdfd798ef0ebc 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 6e3567fb1494a7ba9990ff73056f3042f6f038b6..59b1413ee601f2a8cca54e08a54817a9cc3f944c 100644 --- a/interfaces/kits/ani/common/common_fun_ani.cpp +++ b/interfaces/kits/ani/common/common_fun_ani.cpp @@ -13,180 +13,131 @@ * 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_BUNDLEMANAGER_BUNDLE_TYPE = "@ohos.bundle.bundleManager.bundleManager.BundleType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_MULTIAPPMODE_TYPE = + "@ohos.bundle.bundleManager.bundleManager.MultiAppModeType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_DISPLAYORIENTATION = + "@ohos.bundle.bundleManager.bundleManager.DisplayOrientation"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_LAUNCH_TYPE = "@ohos.bundle.bundleManager.bundleManager.LaunchType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_EXTENSIONABILITY_TYPE = + "@ohos.bundle.bundleManager.bundleManager.ExtensionAbilityType"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_MODULE_TYPE = "@ohos.bundle.bundleManager.bundleManager.ModuleType"; + +constexpr const char* CLASSNAME_ABILITYINFO_INNER = "bundleManager.AbilityInfoInner.AbilityInfoInner"; +constexpr const char* CLASSNAME_EXTENSIONABILITYINFO_INNER = + "bundleManager.ExtensionAbilityInfoInner.ExtensionAbilityInfoInner"; +constexpr const char* CLASSNAME_WINDOWSIZE = "bundleManager.AbilityInfo.WindowSize"; +constexpr const char* CLASSNAME_WINDOWSIZE_INNER = "bundleManager.AbilityInfoInner.WindowSizeInner"; +constexpr const char* CLASSNAME_APPLICATIONINFO = "bundleManager.ApplicationInfo.ApplicationInfo"; +constexpr const char* CLASSNAME_APPLICATIONINFO_INNER = "bundleManager.ApplicationInfoInner.ApplicationInfoInner"; +constexpr const char* CLASSNAME_MODULEMETADATA_INNER = "bundleManager.ApplicationInfoInner.ModuleMetadataInner"; +constexpr const char* CLASSNAME_MULTIAPPMODE = "bundleManager.ApplicationInfo.MultiAppMode"; +constexpr const char* CLASSNAME_MULTIAPPMODE_INNER = "bundleManager.ApplicationInfoInner.MultiAppModeInner"; +constexpr const char* CLASSNAME_BUNDLEINFO_INNER = "bundleManager.BundleInfoInner.BundleInfoInner"; +constexpr const char* CLASSNAME_PERMISSION_INNER = "bundleManager.BundleInfoInner.ReqPermissionDetailInner"; +constexpr const char* CLASSNAME_USEDSCENE = "bundleManager.BundleInfo.UsedScene"; +constexpr const char* CLASSNAME_USEDSCENE_INNER = "bundleManager.BundleInfoInner.UsedSceneInner"; +constexpr const char* CLASSNAME_SIGNATUREINFO = "bundleManager.BundleInfo.SignatureInfo"; +constexpr const char* CLASSNAME_SIGNATUREINFO_INNER = "bundleManager.BundleInfoInner.SignatureInfoInner"; +constexpr const char* CLASSNAME_APPCLONEIDENTITY_INNER = "bundleManager.BundleInfoInner.AppCloneIdentityInner"; +constexpr const char* CLASSNAME_DYNAMICICONINFO_INNER = "bundleManager.BundleInfoInner.DynamicIconInfoInner"; +constexpr const char* CLASSNAME_PERMISSIONDEF_INNER = "bundleManager.PermissionDefInner.PermissionDefInner"; +constexpr const char* CLASSNAME_SHAREDBUNDLEINFO_INNER = "bundleManager.SharedBundleInfoInner.SharedBundleInfoInner"; +constexpr const char* CLASSNAME_SHAREDMODULEINFO_INNER = "bundleManager.SharedBundleInfoInner.SharedModuleInfoInner"; +constexpr const char* CLASSNAME_APPPROVISIONINFO_INNER = "bundleManager.AppProvisionInfoInner.AppProvisionInfoInner"; +constexpr const char* CLASSNAME_VALIDITY_INNER = "bundleManager.AppProvisionInfoInner.ValidityInner"; +constexpr const char* CLASSNAME_RECOVERABLEAPPLICATIONINFO_INNER = + "bundleManager.RecoverableApplicationInfoInner.RecoverableApplicationInfoInner"; +constexpr const char* CLASSNAME_PREINSTALLEDAPPLICATIONINFO_INNER = + "bundleManager.ApplicationInfoInner.PreinstalledApplicationInfoInner"; +constexpr const char* CLASSNAME_PLUGINBUNDLEINFO_INNER = "bundleManager.PluginBundleInfoInner.PluginBundleInfoInner"; +constexpr const char* CLASSNAME_PLUGINMODULEINFO_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_ROUTERITEM_INNER = "bundleManager.HapModuleInfoInner.RouterItemInner"; +constexpr const char* CLASSNAME_PRELOADITEM_INNER = "bundleManager.HapModuleInfoInner.PreloadItemInner"; +constexpr const char* CLASSNAME_DEPENDENCY_INNER = "bundleManager.HapModuleInfoInner.DependencyInner"; +constexpr const char* CLASSNAME_HAPMODULEINFO_INNER = "bundleManager.HapModuleInfoInner.HapModuleInfoInner"; +constexpr const char* CLASSNAME_DATAITEM_INNER = "bundleManager.HapModuleInfoInner.DataItemInner"; +constexpr const char* CLASSNAME_ELEMENTNAME_INNER = "bundleManager.ElementNameInner.ElementNameInner"; +constexpr const char* CLASSNAME_SKILL_INNER = "bundleManager.SkillInner.SkillInner"; +constexpr const char* CLASSNAME_SKILLURI_INNER = "bundleManager.SkillInner.SkillUriInner"; +constexpr const char* CLASSNAME_SHORTCUTINFO_INNER = "bundleManager.ShortcutInfo.ShortcutInfoInner"; +constexpr const char* CLASSNAME_SHORTCUTWANT_INNER = "bundleManager.ShortcutInfo.ShortcutWantInner"; +constexpr const char* CLASSNAME_SHORTCUT_PARAMETERITEM_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_INNER = "bundleManager.BundlePackInfoInner.PackageSummaryInner"; +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_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;"; + "bundleManager.BundlePackInfoInner.ModuleAbilityInfoInner"; +constexpr const char* CLASSNAME_ABILITY_FORM_INFO_INNER = "bundleManager.BundlePackInfoInner.AbilityFormInfoInner"; +constexpr const char* CLASSNAME_VERSION_INNER = "bundleManager.BundlePackInfoInner.VersionInner"; +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_MOUDLE_INFO_INNER = - "LbundleManager/OverlayModuleInfoInner/OverlayModuleInfoInner;"; -constexpr const char* CLASSNAME_WANT = "L@ohos/app/ability/Want/Want;"; + "bundleManager.OverlayModuleInfoInner.OverlayModuleInfoInner"; +constexpr const char* CLASSNAME_WANT = "@ohos.app.ability.Want.Want"; 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_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_LABEL = "label"; constexpr const char* PROPERTYNAME_LABELID = "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_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_ENTITIES = "entities"; -constexpr const char* PROPERTYNAME_URIS = "uris"; -constexpr const char* PROPERTYNAME_DOMAINVERIFY = "domainVerify"; constexpr const char* PROPERTYNAME_HOSTABILITY = "hostAbility"; constexpr const char* PROPERTYNAME_WANTS = "wants"; constexpr const char* PROPERTYNAME_SOURCETYPE = "sourceType"; @@ -229,12 +180,137 @@ 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_PERMISSIONNAME = "permissionName"; +constexpr const char* PROPERTYNAME_GRANTMODE = "grantMode"; +constexpr const char* PROPERTYNAME_COMPATIBLEPOLICY = "compatiblePolicy"; +constexpr const char* PROPERTYNAME_SHAREDMODULEINFO = "sharedModuleInfo"; +constexpr const char* PROPERTYNAME_UUID = "uuid"; +constexpr const char* PROPERTYNAME_NOTBEFORE = "notBefore"; +constexpr const char* PROPERTYNAME_NOTAFTER = "notAfter"; +constexpr const char* PROPERTYNAME_VALIDITY = "validity"; +constexpr const char* PROPERTYNAME_DEVELOPERID = "developerId"; +constexpr const char* PROPERTYNAME_APL = "apl"; +constexpr const char* PROPERTYNAME_ISSUER = "issuer"; +constexpr const char* PROPERTYNAME_ORGANIZATION = "organization"; +constexpr const char* PROPERTYNAME_CODEPATHS = "codePaths"; +constexpr const char* PROPERTYNAME_PLUGINBUNDLENAME = "pluginBundleName"; +constexpr const char* PROPERTYNAME_PLUGINMODULEINFOS = "pluginModuleInfos"; constexpr const char* PROPERTYNAME_VISIBLE = "visible"; constexpr const char* PROPERTYNAME_ACTION = "action"; 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/"; + +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_BUNDLEINFO_INNER, { } }, + { CLASSNAME_APPLICATIONINFO_INNER, { } }, + { CLASSNAME_MODULEMETADATA_INNER, { } }, + { CLASSNAME_METADATA_INNER, { } }, + { CLASSNAME_RESOURCE_INNER, { } }, + { CLASSNAME_MULTIAPPMODE_INNER, { } }, + { CLASSNAME_HAPMODULEINFO_INNER, { } }, + { CLASSNAME_ABILITYINFO_INNER, { } }, + { CLASSNAME_SKILL_INNER, { } }, + { CLASSNAME_WINDOWSIZE_INNER, { } }, + { CLASSNAME_EXTENSIONABILITYINFO_INNER, { } }, + { CLASSNAME_DEPENDENCY_INNER, { } }, + { CLASSNAME_PRELOADITEM_INNER, { } }, + { CLASSNAME_ROUTERITEM_INNER, { } }, + { CLASSNAME_DATAITEM_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, 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 = std::find_if(g_aniClassCache.begin(), g_aniClassCache.end(), [env, cls](const auto& pair) { + ani_boolean equals = ANI_FALSE; + env->Reference_StrictEquals(pair.second.classRef, cls, &equals); + return equals == ANI_TRUE; + }); + 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, ani_class cls, const std::string& ctorSig = Builder::BuildSignatureDescriptor({})) +{ + RETURN_NULL_IF_NULL(env); + RETURN_NULL_IF_NULL(cls); + + ani_method method = GetCacheCtorMethod(env, 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) @@ -255,7 +331,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 ""; } @@ -292,30 +368,48 @@ 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) { RETURN_NULL_IF_NULL(env); + RETURN_NULL_IF_NULL(cls); - ani_method method = nullptr; - ani_status status = env->Class_FindMethod(cls, "", ":V", &method); + ani_method method = GetCtorMethod(env, cls); + RETURN_NULL_IF_NULL(method); + + ani_object object = nullptr; + ani_status status = env->Object_New(cls, method, &object); if (status != ANI_OK) { - APP_LOGE("Class_FindMethod failed %{public}d", status); + APP_LOGE("Object_New failed %{public}d", status); return nullptr; } + return object; +} +ani_object CommonFunAni::CreateNewObjectByClassV2( + ani_env* env, ani_class cls, const std::string& ctorSig, const ani_value* args) +{ + RETURN_NULL_IF_NULL(env); + RETURN_NULL_IF_NULL(cls); + RETURN_NULL_IF_NULL(args); + + ani_method method = GetCtorMethod(env, cls, ctorSig.empty()? nullptr: ctorSig.c_str()); + RETURN_NULL_IF_NULL(method); ani_object object = nullptr; - status = env->Object_New(cls, method, &object); + ani_status status = env->Object_New_A(cls, method, &object, args); if (status != ANI_OK) { - APP_LOGE("Object_New failed %{public}d", status); + APP_LOGE("Object_New_A failed %{public}d", status); return nullptr; } return object; @@ -325,99 +419,162 @@ ani_object CommonFunAni::ConvertBundleInfo(ani_env* env, const BundleInfo& bundl { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLEINFO); + ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLEINFO_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, 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 }, + }; + SignatureBuilder sign {}; + sign.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_APPLICATIONINFO) // appInfo: ApplicationInfo + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // hapModulesInfo: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // reqPermissionDetails: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // permissionGrantStates: Array + .AddClass(CLASSNAME_SIGNATUREINFO) // signatureInfo: SignatureInfo + .AddLong() // installTime: long + .AddLong() // updateTime: long + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // routerMap: Array + .AddInt() // appIndex: int + .AddClass(CommonFunAniNS::CLASSNAME_LONG); // firstInstallTime?: long + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), 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)); + ani_class cls = CreateClassByName(env, CLASSNAME_ABILITYINFO_INNER); + RETURN_NULL_IF_NULL(cls); - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, bundleInfo.appIndex)); + ani_object object = CreateNewObjectByClass(env, cls); + RETURN_NULL_IF_NULL(object); - // firstInstallTime?: number - RETURN_NULL_IF_FALSE( - CallSetterOptional(env, cls, object, PROPERTYNAME_FIRSTINSTALLTIME, bundleInfo.firstInstallTime)); + 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)); + + // moduleName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.moduleName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + + // name: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.name, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + + // label: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.label, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); + + // labelId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, abilityInfo.labelId)); + + // description: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.description, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTION, string)); + + // descriptionId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, abilityInfo.descriptionId)); + + // icon: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, abilityInfo.iconPath, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + + // iconId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, abilityInfo.iconId)); return object; } -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); + ani_class cls = CreateClassByName(env, CLASSNAME_EXTENSIONABILITYINFO_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -425,51 +582,58 @@ ani_object CommonFunAni::ConvertMetadata(ani_env* env, const Metadata& metadata) 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)); + + // moduleName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.moduleName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.name, string)); + RETURN_NULL_IF_FALSE(StringToAniStr(env, extensionInfo.name, string)); RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); - // value: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.value, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VALUE, string)); + // labelId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, extensionInfo.labelId)); - // resource: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.resource, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_RESOURCE, string)); + // descriptionId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, extensionInfo.descriptionId)); - // valueId?: number - RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_VALUEID, metadata.valueId)); + // iconId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, extensionInfo.iconId)); return object; } -ani_object CommonFunAni::ConvertMultiAppMode(ani_env* env, const MultiAppModeData& multiAppMode) +ani_object CommonFunAni::ConvertDefaultAppHapModuleInfo(ani_env* env, const BundleInfo& bundleInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_MULTIAPPMODE); + ani_class cls = CreateClassByName(env, CLASSNAME_HAPMODULEINFO_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); RETURN_NULL_IF_NULL(object); - // maxCount: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAXCOUNT, multiAppMode.maxCount)); + // abilitiesInfo: Array + ani_object aAbilityInfoObject = ConvertAniArray(env, bundleInfo.abilityInfos, ConvertDefaultAppAbilityInfo); + RETURN_NULL_IF_NULL(aAbilityInfoObject); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ABILITIESINFO, aAbilityInfoObject)); - // multiAppModeType: bundleManager.MultiAppModeType - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MULTIAPPMODETYPE, - EnumUtils::EnumNativeToETS_BundleManager_MultiAppModeType( - env, static_cast(multiAppMode.multiAppModeType)))); + // extensionAbilitiesInfo: Array + ani_object aExtensionInfoObject = ConvertAniArray(env, bundleInfo.extensionInfos, ConvertDefaultAppExtensionInfo); + RETURN_NULL_IF_NULL(aExtensionInfoObject); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_EXTENSIONABILITIESINFO, aExtensionInfoObject)); return object; } -ani_object CommonFunAni::ConvertModuleMetaInfosItem( - ani_env* env, const std::pair>& item) +ani_object CommonFunAni::ConvertDefaultAppBundleInfo(ani_env* env, const BundleInfo& bundleInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_MODULEMETADATA); + ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLEINFO_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -477,399 +641,514 @@ ani_object CommonFunAni::ConvertModuleMetaInfosItem( 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)); + // name: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleInfo.name, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); - // 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)); + // hapModulesInfo: Array + std::vector bundleInfos = { bundleInfo }; + ani_object aHapModuleInfosObject = ConvertAniArray(env, bundleInfos, ConvertDefaultAppHapModuleInfo); + RETURN_NULL_IF_NULL(aHapModuleInfosObject); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_HAPMODULESINFO, aHapModuleInfosObject)); return object; } -ani_object CommonFunAni::ConvertApplicationInfo(ani_env* env, const ApplicationInfo& appInfo) +ani_object CommonFunAni::ConvertMetadata(ani_env* env, const Metadata& metadata) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_APPLICATIONINFO); + ani_class cls = CreateClassByName(env, CLASSNAME_METADATA_INNER); RETURN_NULL_IF_NULL(cls); - ani_object object = CreateNewObjectByClass(env, cls); - RETURN_NULL_IF_NULL(object); + // name: string + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.name, name)); - ani_string string = nullptr; + // value: string + ani_string value = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, metadata.value, value)); - // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.name, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + // 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 }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // value: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // resource: string + .AddClass(CommonFunAniNS::CLASSNAME_LONG); // valueId?: long + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); +} - // description: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.description, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTION, string)); +ani_object CommonFunAni::ConvertMultiAppMode(ani_env* env, const MultiAppModeData& multiAppMode) +{ + RETURN_NULL_IF_NULL(env); - // descriptionId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, appInfo.descriptionId)); + ani_class cls = CreateClassByName(env, CLASSNAME_MULTIAPPMODE_INNER); + RETURN_NULL_IF_NULL(cls); - // enabled: boolean - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ENABLED, BoolToAniBoolean(appInfo.enabled))); + ani_value args[] = { + { .r = EnumUtils::EnumNativeToETS_BundleManager_MultiAppModeType( + env, static_cast(multiAppMode.multiAppModeType)) }, + { .i = multiAppMode.maxCount }, + }; + SignatureBuilder sign {}; + sign.AddClass(CLASSNAME_BUNDLEMANAGER_MULTIAPPMODE_TYPE) // multiAppModeType: bundleManager.MultiAppModeType + .AddInt(); // maxCount: int + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); +} - // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.label, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); +ani_object CommonFunAni::ConvertModuleMetaInfosItem( + ani_env* env, const std::pair>& item) +{ + RETURN_NULL_IF_NULL(env); - // labelId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, appInfo.labelId)); + ani_class cls = CreateClassByName(env, CLASSNAME_MODULEMETADATA_INNER); + RETURN_NULL_IF_NULL(cls); - // icon: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.iconPath, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + // moduleName: string + ani_string moduleName = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, item.first, moduleName)); - // iconId: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, appInfo.iconId)); + // metadata: Array + ani_object metadata = ConvertAniArray(env, item.second, ConvertMetadata); + RETURN_NULL_IF_NULL(metadata); + + ani_value args[] = { + { .r = moduleName }, + { .r = metadata }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY); // metadata: Array + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); +} + +ani_object CommonFunAni::ConvertApplicationInfo(ani_env* env, const ApplicationInfo& appInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_APPLICATIONINFO_INNER); + RETURN_NULL_IF_NULL(cls); + + // name: string + ani_string name = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.name, name)); + + // description: string + ani_string description = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.description, description)); + + // label: string + ani_string label = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, appInfo.label, label)); + + // icon: string + 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 }, + }; + SignatureBuilder sign {}; + sign.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(CLASSNAME_BUNDLEMANAGER_BUNDLE_TYPE) // bundleType: bundleManager.BundleType + .AddBoolean() // debug: boolean + .AddBoolean() // dataUnclearable: boolean + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // nativeLibraryPath: string + .AddClass(CLASSNAME_MULTIAPPMODE) // 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 + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertAbilityInfo(ani_env* env, const AbilityInfo& abilityInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_ABILITYINFO); + ani_class cls = CreateClassByName(env, CLASSNAME_ABILITYINFO_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, 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) }, + }; + SignatureBuilder sign {}; + sign.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(CLASSNAME_BUNDLEMANAGER_DISPLAYORIENTATION) // orientation: bundleManager.DisplayOrientation + .AddClass(CLASSNAME_BUNDLEMANAGER_LAUNCH_TYPE) // launchType: bundleManager.LaunchType + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // permissions: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // deviceTypes: Array + .AddClass(CLASSNAME_APPLICATIONINFO) // applicationInfo: ApplicationInfo + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // metadata: Array + .AddBoolean() // enabled: boolean + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // supportWindowModes: Array + .AddClass(CLASSNAME_WINDOWSIZE) // windowSize: WindowSize + .AddBoolean() // excludeFromDock: boolean + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // skills: Array + .AddInt() // appIndex: int + .AddLong(); // orientationId: long + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertWindowSize(ani_env* env, const AbilityInfo& abilityInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_WINDOWSIZE); + ani_class cls = CreateClassByName(env, CLASSNAME_WINDOWSIZE_INNER); 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) }, + }; + SignatureBuilder sign {}; + sign.AddDouble() // maxWindowRatio: double + .AddDouble() // minWindowRatio: double + .AddLong() // maxWindowWidth: long + .AddLong() // minWindowWidth: long + .AddLong() // maxWindowHeight: long + .AddLong(); // minWindowHeight: long + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertExtensionInfo(ani_env* env, const ExtensionAbilityInfo& extensionInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_EXTENSIONABILITYINFO); + ani_class cls = CreateClassByName(env, CLASSNAME_EXTENSIONABILITYINFO_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, 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 }, + }; + SignatureBuilder sign {}; + sign.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(CLASSNAME_BUNDLEMANAGER_EXTENSIONABILITY_TYPE) // extensionAbilityType + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // extensionAbilityTypeName: string + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // permissions: Array + .AddClass(CLASSNAME_APPLICATIONINFO) // 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 + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), 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); @@ -886,7 +1165,7 @@ ani_object CommonFunAni::ConvertResource(ani_env* env, const Resource& resource) RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, 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; } @@ -895,40 +1174,50 @@ ani_object CommonFunAni::ConvertSignatureInfo(ani_env* env, const SignatureInfo& { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SIGNATUREINFO); + ani_class cls = CreateClassByName(env, CLASSNAME_SIGNATUREINFO_INNER); 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 }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_STRING) // appId: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // fingerprint: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // appIdentifier: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING); // certificate?: string + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), 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); + ani_class cls = CreateClassByName(env, className); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -947,80 +1236,117 @@ ani_object CommonFunAni::ConvertKeyValuePair( return object; } +ani_object CommonFunAni::ConvertKeyValuePairV2( + ani_env* env, const std::pair& item, const std::string& className) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, className); + RETURN_NULL_IF_NULL(cls); + + // key: string + ani_string key = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, item.first, key)); + + // value: string + ani_string value = nullptr; + RETURN_NULL_IF_FALSE(StringToAniStr(env, item.second, value)); + + ani_value args[] = { + { .r = key }, + { .r = value }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_STRING) // key: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING); // value: string + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); +} + inline ani_object CommonFunAni::ConvertDataItem(ani_env* env, const std::pair& item) { - return ConvertKeyValuePair(env, item, CLASSNAME_DATAITEM); + return ConvertKeyValuePairV2(env, item, CLASSNAME_DATAITEM_INNER); } ani_object CommonFunAni::ConvertRouterItem(ani_env* env, const RouterItem& routerItem) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_ROUTERITEM); + ani_class cls = CreateClassByName(env, CLASSNAME_ROUTERITEM_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, 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 }, + }; + SignatureBuilder sign {}; + sign.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 + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertRequestPermission(ani_env* env, const RequestPermission& requestPermission) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_PERMISSION); + ani_class cls = CreateClassByName(env, CLASSNAME_PERMISSION_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, 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 }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_STRING) // name: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // reason: string + .AddLong() // reasonId: long + .AddClass(CLASSNAME_USEDSCENE); // usedScene: UsedScene + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertRequestPermissionUsedScene( @@ -1028,193 +1354,211 @@ ani_object CommonFunAni::ConvertRequestPermissionUsedScene( { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_USEDSCENE); + ani_class cls = CreateClassByName(env, CLASSNAME_USEDSCENE_INNER); 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 }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // abilities: Array + .AddClass(CommonFunAniNS::CLASSNAME_STRING); // when: string + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertPreloadItem(ani_env* env, const PreloadItem& preloadItem) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_PRELOADITEM); + ani_class cls = CreateClassByName(env, CLASSNAME_PRELOADITEM_INNER); 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 }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_STRING); // moduleName: string + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertDependency(ani_env* env, const Dependency& dependency) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_DEPENDENCY); + ani_class cls = CreateClassByName(env, CLASSNAME_DEPENDENCY_INNER); 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) }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_STRING) // moduleName: string + .AddClass(CommonFunAniNS::CLASSNAME_STRING) // bundleName: string + .AddLong(); // versionCode: long + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertHapModuleInfo(ani_env* env, const HapModuleInfo& hapModuleInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_HAPMODULEINFO); + ani_class cls = CreateClassByName(env, CLASSNAME_HAPMODULEINFO_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, 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)); - - // 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)); + ani_object metadata = ConvertAniArray(env, hapModuleInfo.metadata, ConvertMetadata); + RETURN_NULL_IF_NULL(metadata); - // installationFree: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_INSTALLATIONFREE, BoolToAniBoolean(hapModuleInfo.installationFree))); + // deviceTypes: Array + 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 }, + }; + SignatureBuilder sign {}; + sign.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(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 + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); } ani_object CommonFunAni::ConvertElementName(ani_env* env, const ElementName& elementName) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_ELEMENTNAME); + ani_class cls = CreateClassByName(env, CLASSNAME_ELEMENTNAME_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -1257,105 +1601,166 @@ ani_object CommonFunAni::ConvertAbilitySkillUriInner(ani_env* env, const SkillUr { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SKILLURI); + ani_class cls = CreateClassByName(env, CLASSNAME_SKILLURI_INNER); 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)); + 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 }, + }; + SignatureBuilder sign {}; + sign.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 + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); +} + +ani_object CommonFunAni::ConvertAbilitySkillInner(ani_env* env, const Skill& skill, bool isExtension) +{ + RETURN_NULL_IF_NULL(env); - // maxFileSupported: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MAXFILESUPPORTED, skillUri.maxFileSupported)); + ani_class cls = CreateClassByName(env, CLASSNAME_SKILL_INNER); + RETURN_NULL_IF_NULL(cls); - if (!isExtension) { - // linkFeature: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, skillUri.linkFeature, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LINKFEATURE, string)); - } + // actions: Array + ani_object actions = ConvertAniArrayString(env, skill.actions); + RETURN_NULL_IF_NULL(actions); + + // entities: Array + ani_object entities = ConvertAniArrayString(env, skill.entities); + RETURN_NULL_IF_NULL(entities); + + // uris: Array + ani_object uris = + ConvertAniArray(env, skill.uris, isExtension ? ConvertExtensionAbilitySkillUri : ConvertAbilitySkillUri); + RETURN_NULL_IF_NULL(uris); + + ani_value args[] = { + { .r = actions }, + { .r = entities }, + { .r = uris }, + { .z = BoolToAniBoolean(isExtension? false: skill.domainVerify) }, + }; + SignatureBuilder sign {}; + sign.AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // actions: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // entities: Array + .AddClass(CommonFunAniNS::CLASSNAME_ARRAY) // uris: Array + .AddBoolean(); // domainVerify: boolean + return CreateNewObjectByClassV2(env, cls, sign.BuildSignatureDescriptor(), args); +} + +ani_object CommonFunAni::ConvertAppCloneIdentity(ani_env* env, const std::string& bundleName, const int32_t appIndex) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_APPCLONEIDENTITY_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, bundleName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + + // appIndex: int + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, appIndex)); return object; } -ani_object CommonFunAni::ConvertAbilitySkillInner(ani_env* env, const Skill& skill, bool isExtension) +ani_object CommonFunAni::ConvertPermissionDef(ani_env* env, const PermissionDef& permissionDef) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SKILL); + ani_class cls = CreateClassByName(env, CLASSNAME_PERMISSIONDEF_INNER); 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_string string = nullptr; - // 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)); + // permissionName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, permissionDef.permissionName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PERMISSIONNAME, string)); - // uris: Array - ani_object aSkillUri = - ConvertAniArray(env, skill.uris, isExtension ? ConvertExtensionAbilitySkillUri : ConvertAbilitySkillUri); - RETURN_NULL_IF_NULL(aSkillUri); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_URIS, aSkillUri)); + // grantMode: int + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_GRANTMODE, permissionDef.grantMode)); - if (!isExtension) { - // domainVerify: boolean - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_DOMAINVERIFY, BoolToAniBoolean(skill.domainVerify))); - } + // labelId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, permissionDef.labelId)); + + // descriptionId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, permissionDef.descriptionId)); return object; } -ani_object CommonFunAni::ConvertAppCloneIdentity(ani_env* env, const std::string& bundleName, const int32_t appIndex) +ani_object CommonFunAni::ConvertSharedBundleInfo(ani_env* env, const SharedBundleInfo& sharedBundleInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_APPCLONEIDENTITY); + ani_class cls = CreateClassByName(env, CLASSNAME_SHAREDBUNDLEINFO_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -1364,20 +1769,144 @@ ani_object CommonFunAni::ConvertAppCloneIdentity(ani_env* env, const std::string ani_string string = nullptr; // name: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + RETURN_NULL_IF_FALSE(StringToAniStr(env, sharedBundleInfo.name, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, appIndex)); + // bundleType: bundleManager.CompatiblePolicy + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_COMPATIBLEPOLICY, + EnumUtils::EnumNativeToETS_BundleManager_CompatiblePolicy( + env, static_cast(CompatiblePolicy::BACKWARD_COMPATIBILITY)))); + + // sharedModuleInfo: Array + ani_object aSharedModuleInfosObject = + ConvertAniArray(env, sharedBundleInfo.sharedModuleInfos, ConvertSharedModuleInfo); + RETURN_NULL_IF_NULL(aSharedModuleInfosObject); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SHAREDMODULEINFO, aSharedModuleInfosObject)); + + return object; +} + +ani_object CommonFunAni::ConvertSharedModuleInfo(ani_env* env, const SharedModuleInfo& sharedModuleInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_SHAREDMODULEINFO_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, sharedModuleInfo.name, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NAME, string)); + + // versionCode: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONCODE, sharedModuleInfo.versionCode)); + + // versionName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, sharedModuleInfo.versionName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONNAME, string)); + + // description: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, sharedModuleInfo.description, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTION, string)); + + // descriptionId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, sharedModuleInfo.descriptionId)); + + return object; +} + +ani_object CommonFunAni::ConvertAppProvisionInfo(ani_env* env, const AppProvisionInfo& appProvisionInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_APPPROVISIONINFO_INNER); + RETURN_NULL_IF_NULL(cls); + + ani_object object = CreateNewObjectByClass(env, cls); + RETURN_NULL_IF_NULL(object); + + ani_string string = nullptr; + + // versionCode: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONCODE, appProvisionInfo.versionCode)); + + // versionName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.versionName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONNAME, string)); + + // uuid: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.uuid, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_UUID, string)); + + // type: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.type, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TYPE, string)); + + // appDistributionType: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.appDistributionType, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPDISTRIBUTIONTYPE, string)); + + // validity: Validity + ani_object aniValidityObject = ConvertValidity(env, appProvisionInfo.validity); + RETURN_NULL_IF_NULL(aniValidityObject); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VALIDITY, aniValidityObject)); + + // developerId: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.developerId, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DEVELOPERID, string)); + + // certificate: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.certificate, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_CERTIFICATE, string)); + + // apl: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.apl, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APL, string)); + + // issuer: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.issuer, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ISSUER, string)); + + // appIdentifier: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.appIdentifier, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPIDENTIFIER, string)); + + // organization: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, appProvisionInfo.organization, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ORGANIZATION, string)); + + return object; +} + +ani_object CommonFunAni::ConvertValidity(ani_env* env, const Validity& validity) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_VALIDITY_INNER); + RETURN_NULL_IF_NULL(cls); + + ani_object object = CreateNewObjectByClass(env, cls); + RETURN_NULL_IF_NULL(object); + + // notBefore: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NOTBEFORE, validity.notBefore)); + + // notAfter: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_NOTAFTER, validity.notAfter)); return object; } -ani_object CommonFunAni::ConvertBundleResourceInfo(ani_env* env, const BundleResourceInfo& bundleResInfo) +ani_object CommonFunAni::ConvertRecoverableApplicationInfo( + ani_env* env, const RecoverableApplicationInfo& recoverableApplicationInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_BUNDLERESINFO); + ani_class cls = CreateClassByName(env, CLASSNAME_RECOVERABLEAPPLICATIONINFO_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -1386,31 +1915,42 @@ ani_object CommonFunAni::ConvertBundleResourceInfo(ani_env* env, const BundleRes ani_string string = nullptr; // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleResInfo.bundleName, string)); + RETURN_NULL_IF_FALSE(StringToAniStr(env, recoverableApplicationInfo.bundleName, string)); RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); - // icon: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleResInfo.icon, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + // moduleName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, recoverableApplicationInfo.moduleName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); - // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleResInfo.label, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); + // labelId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, recoverableApplicationInfo.labelId)); + + // iconId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, recoverableApplicationInfo.iconId)); + + // systemApp: boolean + RETURN_NULL_IF_FALSE( + CallSetter(env, cls, object, PROPERTYNAME_SYSTEMAPP, BoolToAniBoolean(recoverableApplicationInfo.systemApp))); - // drawableDecriptor: drawableDecriptor + // bundleType: bundleManager.BundleType + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLETYPE, + EnumUtils::EnumNativeToETS_BundleManager_BundleType( + env, static_cast(recoverableApplicationInfo.bundleType)))); - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, bundleResInfo.appIndex)); + // codePaths: Array + ani_ref aCodePaths = ConvertAniArrayString(env, recoverableApplicationInfo.codePaths); + RETURN_NULL_IF_NULL(aCodePaths); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_CODEPATHS, aCodePaths)); return object; } -ani_object CommonFunAni::ConvertLauncherAbilityResourceInfo( - ani_env* env, const LauncherAbilityResourceInfo& launcherAbilityResourceInfo) +ani_object CommonFunAni::ConvertPreinstalledApplicationInfo( + ani_env* env, const PreinstalledApplicationInfo& reinstalledApplicationInfo) { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_LAUNCHER_ABILITY_RESOURCE_INFO_INNER); + ani_class cls = CreateClassByName(env, CLASSNAME_PREINSTALLEDAPPLICATIONINFO_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -1419,29 +1959,90 @@ ani_object CommonFunAni::ConvertLauncherAbilityResourceInfo( ani_string string = nullptr; // bundleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.bundleName, string)); + RETURN_NULL_IF_FALSE(StringToAniStr(env, reinstalledApplicationInfo.bundleName, string)); RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); // moduleName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.moduleName, string)); + RETURN_NULL_IF_FALSE(StringToAniStr(env, reinstalledApplicationInfo.moduleName, string)); RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); - // abilityName: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.abilityName, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ABILITYNAME, string)); + // iconId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, reinstalledApplicationInfo.iconId)); - // icon: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.icon, string)); - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + // labelId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, reinstalledApplicationInfo.labelId)); + + return object; +} + +ani_object CommonFunAni::ConvertPluginBundleInfo(ani_env* env, const PluginBundleInfo& pluginBundleInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_PLUGINBUNDLEINFO_INNER); + RETURN_NULL_IF_NULL(cls); + + ani_object object = CreateNewObjectByClass(env, cls); + RETURN_NULL_IF_NULL(object); + + ani_string string = nullptr; // label: string - RETURN_NULL_IF_FALSE(StringToAniStr(env, launcherAbilityResourceInfo.label, string)); + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginBundleInfo.label, string)); RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); - // drawableDescriptor: DrawableDescriptor; + // labelId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, pluginBundleInfo.labelId)); + + // icon: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginBundleInfo.icon, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + + // iconId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, pluginBundleInfo.iconId)); + + // pluginBundleName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginBundleInfo.pluginBundleName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PLUGINBUNDLENAME, string)); + + // versionCode: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONCODE, pluginBundleInfo.versionCode)); + + // versionName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginBundleInfo.versionName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_VERSIONNAME, string)); + + // pluginModuleInfos: Array + ani_object apluginModuleInfosObject = + ConvertAniArray(env, pluginBundleInfo.pluginModuleInfos, ConvertPluginModuleInfo); + RETURN_NULL_IF_NULL(apluginModuleInfosObject); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PLUGINMODULEINFOS, apluginModuleInfosObject)); + + return object; +} + +ani_object CommonFunAni::ConvertPluginModuleInfo(ani_env* env, const PluginModuleInfo& pluginModuleInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_PLUGINMODULEINFO_INNER); + 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, pluginModuleInfo.moduleName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + + // descriptionId: long + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTIONID, pluginModuleInfo.descriptionId)); - // appIndex: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, launcherAbilityResourceInfo.appIndex)); + // description: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, pluginModuleInfo.description, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_DESCRIPTION, string)); return object; } @@ -1450,7 +2051,7 @@ ani_object CommonFunAni::ConvertShortcutInfo(ani_env* env, const ShortcutInfo& s { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SHORTCUTINFO); + ani_class cls = CreateClassByName(env, CLASSNAME_SHORTCUTINFO_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -1481,7 +2082,7 @@ ani_object CommonFunAni::ConvertShortcutInfo(ani_env* env, const ShortcutInfo& s RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_ICON, string)); } - // iconId?: number + // iconId?: long RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_ICONID, shortcutInfo.iconId)); // label?: string @@ -1489,7 +2090,7 @@ ani_object CommonFunAni::ConvertShortcutInfo(ani_env* env, const ShortcutInfo& s RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_LABEL, string)); } - // labelId?: number + // labelId?: long RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_LABELID, shortcutInfo.labelId)); // wants?: Array @@ -1497,10 +2098,10 @@ ani_object CommonFunAni::ConvertShortcutInfo(ani_env* env, const ShortcutInfo& s RETURN_NULL_IF_NULL(aShortcutWantObject); RETURN_NULL_IF_FALSE(CallSetterOptional(env, cls, object, PROPERTYNAME_WANTS, aShortcutWantObject)); - // appIndex: number + // appIndex: int RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, shortcutInfo.appIndex)); - // sourceType: number + // sourceType: int RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_SOURCETYPE, shortcutInfo.sourceType)); // visible?: boolean @@ -1514,7 +2115,7 @@ ani_object CommonFunAni::ConvertShortcutIntent(ani_env* env, const ShortcutInten { RETURN_NULL_IF_NULL(env); - ani_class cls = CreateClassByName(env, CLASSNAME_SHORTCUTWANT); + ani_class cls = CreateClassByName(env, CLASSNAME_SHORTCUTWANT_INNER); RETURN_NULL_IF_NULL(cls); ani_object object = CreateNewObjectByClass(env, cls); @@ -1546,7 +2147,7 @@ ani_object CommonFunAni::ConvertShortcutIntent(ani_env* env, const ShortcutInten 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_PARAMETERITEM_INNER); } ani_object CommonFunAni::ConvertLauncherAbilityInfo(ani_env* env, const LauncherAbilityInfo& launcherAbility) @@ -1569,16 +2170,16 @@ ani_object CommonFunAni::ConvertLauncherAbilityInfo(ani_env* env, const Launcher RETURN_NULL_IF_NULL(aElementNameObject); RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ELEMENTNAME, aElementNameObject)); - // labelId: number + // labelId: long RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, launcherAbility.labelId)); - // iconId: number + // iconId: long RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, launcherAbility.iconId)); - // userId: number + // userId: int RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_USERID, launcherAbility.userId)); - // installTime: number + // installTime: long RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_INSTALLTIME, launcherAbility.installTime)); return object; @@ -1608,10 +2209,10 @@ ani_object CommonFunAni::ConvertOverlayModuleInfo(ani_env* env, const OverlayMod RETURN_NULL_IF_FALSE(StringToAniStr(env, overlayModuleInfo.targetModuleName, string)); RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TARGETMOUDLENAME, string)); - // priority: number + // priority: int RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_PRIORITY, overlayModuleInfo.priority)); - // state: number + // state: int RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_STATE, overlayModuleInfo.state)); return object; @@ -1634,10 +2235,10 @@ ani_object CommonFunAni::CreateBundleChangedInfo( RETURN_NULL_IF_FALSE(StringToAniStr(env, bundleName, string)); RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); - // userId: number + // userId: int RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_USERID, userId)); - // appIndex: number + // appIndex: int RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, appIndex)); return object; @@ -1655,16 +2256,16 @@ ani_object CommonFunAni::ConvertVersion(ani_env* env, const Version& version) ani_string string = nullptr; - // minCompatibleVersionCode: number - RETURN_NULL_IF_FALSE( - CallSetter(env, cls, object, PROPERTYNAME_MINCOMPATIBLEVERSIONCODE, version.minCompatibleVersionCode)); + // minCompatibleVersionCode: int + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MINCOMPATIBLEVERSIONCODE, + static_cast(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)); + // code: int + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_CODE, static_cast(version.code))); return object; } @@ -1721,8 +2322,9 @@ ani_object CommonFunAni::ConvertAbilityFormInfo(ani_env* env, const AbilityFormI 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)); + // updateDuration: int + RETURN_NULL_IF_FALSE(CallSetter( + env, cls, object, PROPERTYNAME_UPDATEDURATION, static_cast(abilityFormInfo.updateDuration))); // supportDimensions: Array ani_ref aSupportDimensions = ConvertAniArrayString(env, abilityFormInfo.supportDimensions); @@ -1815,11 +2417,12 @@ ani_object CommonFunAni::ConvertApiVersion(ani_env* env, const ApiVersion& apiVe 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)); + // compatible: int + RETURN_NULL_IF_FALSE( + CallSetter(env, cls, object, PROPERTYNAME_COMPATIBLE, static_cast(apiVersion.compatible))); - // target: number - RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TARGET, apiVersion.target)); + // target: int + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_TARGET, static_cast(apiVersion.target))); return object; } @@ -2015,30 +2618,92 @@ ani_object CommonFunAni::CreateDispatchInfo( return object; } +ani_object CommonFunAni::ConvertDynamicIconInfo(ani_env* env, const DynamicIconInfo& dynamicIconInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_DYNAMICICONINFO_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, dynamicIconInfo.bundleName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + + // moduleName: string + RETURN_NULL_IF_FALSE(StringToAniStr(env, dynamicIconInfo.moduleName, string)); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + + // userId: int + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_USERID, dynamicIconInfo.userId)); + + // appIndex: int + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, dynamicIconInfo.appIndex)); + + 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_USERID, &intValue)) { + if (intValue < 0) { + intValue = Constants::INVALID_USERID; + } + userId = intValue; + isDefault = false; + } + + // appIndex?: int + if (CallGetterOptional(env, object, PROPERTYNAME_APPINDEX, &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); 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)); } + // abilityName?: string if (StringToAniStr(env, want.GetElement().GetAbilityName(), string)) { RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_ABILITYNAME, string)); } + // deviceId?: string if (StringToAniStr(env, want.GetElement().GetDeviceID(), string)) { RETURN_NULL_IF_FALSE(CallSetField(env, cls, object, PROPERTYNAME_DEVICEID, 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) { @@ -2046,10 +2711,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 object; } @@ -2085,7 +2752,7 @@ bool CommonFunAni::ParseShortcutInfo(ani_env* env, ani_object object, ShortcutIn shortcutInfo.icon = AniStrToString(env, string); } - // iconId?: number + // iconId?: long if (CallGetterOptional(env, object, PROPERTYNAME_ICONID, &uintValue)) { shortcutInfo.iconId = uintValue; } @@ -2095,7 +2762,7 @@ bool CommonFunAni::ParseShortcutInfo(ani_env* env, ani_object object, ShortcutIn shortcutInfo.label = AniStrToString(env, string); } - // labelId?: number + // labelId?: long if (CallGetterOptional(env, object, PROPERTYNAME_LABELID, &uintValue)) { shortcutInfo.labelId = uintValue; } @@ -2106,11 +2773,11 @@ bool CommonFunAni::ParseShortcutInfo(ani_env* env, ani_object object, ShortcutIn RETURN_FALSE_IF_FALSE(ParseAniArray(env, array, shortcutInfo.intents, ParseShortcutIntent)); } - // appIndex: number + // appIndex: int RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_APPINDEX, &intValue)); shortcutInfo.appIndex = intValue; - // sourceType: number + // sourceType: int RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_SOURCETYPE, &intValue)); shortcutInfo.sourceType = intValue; @@ -2236,13 +2903,13 @@ bool CommonFunAni::ParseInstallParam(ani_env* env, ani_object object, InstallPar } ani_int intValue = 0; - // userId?: number + // userId?: int if (CallGetterOptional(env, object, PROPERTYNAME_USERID, &intValue)) { installParam.userId = intValue; } else { APP_LOGW("Parse userId failed,using default value"); } - // installFlag?: number + // installFlag?: int if (CallGetterOptional(env, object, PROPERTYNAME_INSTALLFLAG, &intValue)) { if ((intValue != static_cast(OHOS::AppExecFwk::InstallFlag::NORMAL)) && (intValue != static_cast(OHOS::AppExecFwk::InstallFlag::REPLACE_EXISTING)) && @@ -2263,9 +2930,10 @@ bool CommonFunAni::ParseInstallParam(ani_env* env, ani_object object, InstallPar 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_CROWDTESTDEADLINE, &longValue)) { + installParam.crowdtestDeadline = longValue; } else { APP_LOGW("Parse crowdtestDeadline failed,using default value"); } @@ -2302,7 +2970,7 @@ bool CommonFunAni::ParseUninstallParam(ani_env* env, ani_object object, Uninstal RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLENAME, &string)); uninstallParam.bundleName = AniStrToString(env, string); ani_int intValue = 0; - // versionCode?: number + // versionCode?: int if (CallGetterOptional(env, object, PROPERTYNAME_VERSIONCODE, &intValue)) { uninstallParam.versionCode = intValue; } else { @@ -2317,7 +2985,7 @@ bool CommonFunAni::ParseDestroyAppCloneParam( RETURN_FALSE_IF_NULL(env); RETURN_FALSE_IF_NULL(object); ani_int intValue = 0; - // userId?: number + // userId?: int if (CallGetterOptional(env, object, PROPERTYNAME_USERID, &intValue)) { destroyAppCloneParam.userId = intValue; } else { @@ -2344,7 +3012,7 @@ bool CommonFunAni::ParsePluginParam(ani_env* env, ani_object object, InstallPlug ani_int intValue = 0; ani_array array = nullptr; - // userId?: number + // userId?: int if (CallGetterOptional(env, object, PROPERTYNAME_USERID, &intValue)) { installPluginParam.userId = intValue; } else { @@ -2369,7 +3037,7 @@ 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 + // userId?: int if (CallGetterOptional(env, object, PROPERTYNAME_USERID, &intValue)) { userId = intValue; } else { @@ -2377,7 +3045,7 @@ bool CommonFunAni::ParseCreateAppCloneParam(ani_env* env, ani_object object, int APP_LOGW("Parse userId failed,using default value"); } - // appIdx?: number + // appIdx?: int if (CallGetterOptional(env, object, PROPERTYNAME_APPINDEX, &intValue)) { appIdx = intValue; } else { @@ -2407,5 +3075,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_DEVICEID, &string)) { + elementName.SetDeviceID(AniStrToString(env, string)); + } + + // bundleName: string + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_BUNDLENAME, &string)); + elementName.SetBundleName(AniStrToString(env, string)); + + // moduleName?: string + if (CallGetterOptional(env, object, PROPERTYNAME_MODULENAME, &string)) { + elementName.SetModuleName(AniStrToString(env, string)); + } + + // abilityName: string + RETURN_FALSE_IF_FALSE(CallGetter(env, object, PROPERTYNAME_ABILITYNAME, &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 1a285eb2b4a25ed53574ea8ef347237be9fd5a40..47735a5e2c61136a57004c3e0822ff9480275f29 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,14 @@ 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_ARRAY = "escompat.Array"; +constexpr const char* CLASSNAME_STRING = "std.core.String"; +} // namespace CommonFunAniNS class CommonFunAni { public: // Data conversion. @@ -122,7 +133,9 @@ 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 ConvertKeyValuePairV2( + 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 +160,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 +199,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); @@ -188,6 +215,8 @@ public: static ani_class CreateClassByName(ani_env* env, const std::string& className); static ani_object CreateNewObjectByClass(ani_env* env, ani_class cls); + static ani_object CreateNewObjectByClassV2( + ani_env* env, ani_class cls, 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 +246,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,27 +283,15 @@ 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_class arrayCls = CreateClassByName(env, CommonFunAniNS::CLASSNAME_ARRAY); + RETURN_NULL_IF_NULL(arrayCls); - 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_value arg = { .i = static_cast(length) }; + ani_object arrayObj = CreateNewObjectByClassV2(env, arrayCls, "i:", &arg); + RETURN_NULL_IF_NULL(arrayObj); + + ani_status status = ANI_OK; if (length > 0) { for (ani_size i = 0; i < length; ++i) { ani_enum_item item = converter(env, static_cast(cArray[i])); @@ -279,7 +299,7 @@ public: 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 +318,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_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_class arrayCls = CreateClassByName(env, CommonFunAniNS::CLASSNAME_ARRAY); + RETURN_NULL_IF_NULL(arrayCls); 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, arrayCls, "i:", &arg); + RETURN_NULL_IF_NULL(arrayObj); + ani_status status = ANI_OK; ani_size 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 +357,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 +402,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 +482,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; @@ -488,6 +537,55 @@ public: return true; } + template + static bool CallGetFieldOptional(ani_env *env, ani_object object, const char *name, valueType* value) + { + RETURN_FALSE_IF_NULL(env); + RETURN_FALSE_IF_NULL(object); + + 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; + } + + ani_boolean isUndefined; + status = env->Reference_IsUndefined(ref, &isUndefined); + if (status != ANI_OK) { + 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_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", name, status); + return false; + } + if (!TryCastTo(i, 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 CallSetField(ani_env *env, ani_class cls, ani_object object, const char *name, valueType* value) { @@ -509,32 +607,58 @@ public: } template - static bool CallSetter(ani_env* env, ani_class cls, ani_object object, const char* propertyName, valueType value) + 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); + 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; + } + std::string setterName(""); setterName.append(propertyName); ani_method setter; - ani_status status = env->Class_FindMethod(cls, setterName.c_str(), nullptr, &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; } - 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_CallMethod_Void_A(object, setter, &setterParam); if (status != ANI_OK) { - APP_LOGE("Object_CallMethod_Void %{public}s failed %{public}d", propertyName, status); + APP_LOGE("Object_CallMethod_Void_A %{public}s failed %{public}d", propertyName, status); return false; } @@ -542,7 +666,8 @@ public: } // sets property to null - static bool CallSetterNull(ani_env* env, ani_class cls, ani_object object, const char* propertyName) + static bool CallSetterNull(ani_env* env, ani_class cls, ani_object object, const char* propertyName, + const char* valueClassName = nullptr) { RETURN_FALSE_IF_NULL(env); RETURN_FALSE_IF_NULL(cls); @@ -555,11 +680,12 @@ public: return false; } - return CallSetter(env, cls, object, propertyName, nullRef); + return CallSetter(env, cls, object, propertyName, nullRef, valueClassName); } // sets optional property to undefined - static bool CallSetterOptionalUndefined(ani_env* env, ani_class cls, ani_object object, const char* propertyName) + static bool CallSetterOptionalUndefined(ani_env* env, ani_class cls, ani_object object, const char* propertyName, + const char* valueClassName = nullptr) { RETURN_FALSE_IF_NULL(env); RETURN_FALSE_IF_NULL(cls); @@ -572,73 +698,79 @@ public: return false; } - return CallSetter(env, cls, object, propertyName, undefined); + return CallSetter(env, cls, object, propertyName, undefined, valueClassName); } 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 failed %{public}d", status); + return nullptr; } - if (status != ANI_OK) { - APP_LOGE("Object_New %{public}s failed %{public}d", propertyName, status); - return false; + return valueObj; + } + + template + static bool CallSetterOptional(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); + + if constexpr (std::is_pointer_v && std::is_base_of_v<__ani_ref, std::remove_pointer_t>) { + return CallSetter(env, cls, object, propertyName, value, valueClassName); } - return CallSetter(env, cls, object, propertyName, valueObj); + ani_object valueObj = BoxValue(env, value, &valueClassName); + RETURN_FALSE_IF_NULL(valueObj); + + return CallSetter(env, cls, object, propertyName, valueObj, valueClassName); } }; } // namespace AppExecFwk diff --git a/interfaces/kits/ani/common/enum_util.h b/interfaces/kits/ani/common/enum_util.h index 2f7021b86f3140f88f15756c4ca7caec330900c7..f742d556acbbce839b75a8a75e206b21529d8104 100644 --- a/interfaces/kits/ani/common/enum_util.h +++ b/interfaces/kits/ani/common/enum_util.h @@ -43,6 +43,8 @@ constexpr const char* CLASSNAME_BUNDLEMANAGER_PERMISSIONGRANTSTATE = "L@ohos/bundle/bundleManager/bundleManager/PermissionGrantState;"; constexpr const char* CLASSNAME_BUNDLEMANAGER_APPLICATION_FLAG = "L@ohos/bundle/bundleManager/bundleManager/ApplicationFlag;"; +constexpr const char* CLASSNAME_BUNDLEMANAGER_COMPATIBLEPOLICY = + "L@ohos/bundle/bundleManager/bundleManager/CompatiblePolicy;"; 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;"; @@ -51,6 +53,12 @@ constexpr const char* CLASSNAME_ZLIB_COMPRESSLEVEL = "L@ohos/zlib/zlib/CompressL constexpr const char* CLASSNAME_ZLIB_MEMLEVEL = "L@ohos/zlib/zlib/MemLevel;"; constexpr const char* CLASSNAME_ZLIB_COMPRESSSTRATEGY = "L@ohos/zlib/zlib/CompressStrategy;"; constexpr const char* CLASSNAME_ZLIB_PATHSEPARATORSTRATRGY = "L@ohos/zlib/zlib/PathSeparatorStrategy;"; +constexpr const char* CLASSNAME_ZLIB_RETURNSTATUS = "L@ohos/zlib/zlib/ReturnStatus;"; +constexpr const char* CLASSNAME_APPCONTROL_COMPONENTTYPE = "L@ohos/bundle/appControl/appControl/ComponentType;"; +constexpr const char* CLASSNAME_APPCONTROL_DISPOSEDTYPE = "L@ohos/bundle/appControl/appControl/DisposedType;"; +constexpr const char* CLASSNAME_APPCONTROL_CONTROLTYPE = "L@ohos/bundle/appControl/appControl/ControlType;"; +constexpr const char* CLASSNAME_APPCONTROL_UNINSTALLCOMPONENTTYPE = + "L@ohos/bundle/appControl/appControl/UninstallComponentType;"; } // namespace CommonFunAniNS class EnumUtils { private: @@ -378,6 +386,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_COMPATIBLEPOLICY, value, 1); + } + /* bundle.DisplayOrientation enum DisplayOrientation { UNSPECIFIED, @@ -448,6 +465,57 @@ public: return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_ZLIB_COMPRESSSTRATEGY, value, 0); } + // zlib.ReturnStatus + // enum ReturnStatus { + // OK = 0, + // STREAM_END = 1, + // NEED_DICT = 2, + // } + static inline ani_enum_item EnumNativeToETS_Zlib_ReturnStatus(ani_env* env, const int32_t value) + { + return EnumNativeToETSByOffset(env, CommonFunAniNS::CLASSNAME_ZLIB_RETURNSTATUS, value, 0); + } + + // 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_COMPONENTTYPE, 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_DISPOSEDTYPE, 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_CONTROLTYPE, 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_UNINSTALLCOMPONENTTYPE, value, 1); + } + /* zlib.PathSeparatorStrategy enum PathSeparatorStrategy { PATH_SEPARATOR_STRATEGY_DEFAULT = 0, diff --git a/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfo.ets b/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfo.ets index ae19f7b59727543650c8cc33eea552d2766a7a6b..8329aef9a06d21135ec13a5d42640177323570e7 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 213fb78cba9a4445e670cd170277cc3ea73b82c5..3a0c42cae2334a99d2d74a097890a49c5a25f0a7 100644 --- a/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfoInner.ets +++ b/interfaces/kits/ani/freeInstall/ets/bundleManager/BundlePackInfoInner.ets @@ -71,19 +71,19 @@ 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 = ''; } 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; } 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; } \ No newline at end of file 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 df1d46e54f11ba017b414c76242ba4e1cc9ccbbf..e0534aa5173a5f42b072378bb80627d9f46b2556 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 @@ -101,7 +101,7 @@ static ani_object AniGetShortcutInfo(ani_env *env, return nullptr; } int32_t userId = EMPTY_USER_ID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGW("try cast userId failed"); } if (userId == EMPTY_USER_ID) { @@ -144,7 +144,7 @@ static ani_object AniGetLauncherAbilityInfo(ani_env *env, return nullptr; } int32_t userId = Constants::UNSPECIFIED_USERID; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGE("try cast userId failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); return nullptr; @@ -189,7 +189,7 @@ static ani_object AniGetAllLauncherAbilityInfo(ani_env *env, ani_double aniUserI { APP_LOGD("ani GetAllLauncherAbilityInfo called"); int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGE("try cast userId failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); return nullptr; 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 ebfd76b8c82a2f498283f3f009d6be69b622254b..ef83807a723ec487233edbb7b9f3d6df0e36061f 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 04382de4fed9ebb76dbafd9af97fb2c4de25e0c2..304fca3ed4b90a682d1a7a4fb19d8f13dbca6870 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,8 @@ 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; } \ No newline at end of file diff --git a/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfo.ets b/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfo.ets index 5e1c5d7a8d20a684f53f62bb48bdda863fe29637..bf763a8938e9bf21b7f037d61addf6820772e98e 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 60bcaa36c3155bedeabfb993a358d651cd821d58..72ef0f9d75ae42a6fd9aefab90d241e14041d35a 100644 --- a/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfoInner.ets +++ b/interfaces/kits/ani/overlay/ets/bundleManager/OverlayModuleInfoInner.ets @@ -24,6 +24,6 @@ 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; } diff --git a/interfaces/kits/ani/resource_manager/BUILD.gn b/interfaces/kits/ani/resource_manager/BUILD.gn index b7f5e6ca7854def90a472414cf0fb83ff760ed10..8300187f4e7e3627c8617321fa66a13eef067ba0 100644 --- a/interfaces/kits/ani/resource_manager/BUILD.gn +++ b/interfaces/kits/ani/resource_manager/BUILD.gn @@ -36,7 +36,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 d1b01a91fd87364798ba00f78283f1583fda15b9..a33ebc634d3128bc085d8f8fb7ee416140b097ff 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" @@ -45,13 +46,13 @@ static ani_object AniGetBundleResourceInfo(ani_env* env, ani_string aniBundleNam return nullptr; } int32_t resFlag = 0; - if (!CommonFunAni::TryCastDoubleTo(aniResFlag, &resFlag)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniAppIndex, &appIndex)) { APP_LOGE("Cast aniAppIndex failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); return nullptr; @@ -74,7 +75,7 @@ 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, @@ -88,13 +89,13 @@ static ani_object AniGetLauncherAbilityResourceInfo(ani_env* env, ani_string ani return nullptr; } int32_t resFlag = 0; - if (!CommonFunAni::TryCastDoubleTo(aniResFlag, &resFlag)) { + if (!CommonFunAni::TryCastTo(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)) { + if (!CommonFunAni::TryCastTo(aniAppIndex, &appIndex)) { APP_LOGE("Cast aniAppIndex failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER); return nullptr; @@ -119,7 +120,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"); } @@ -131,7 +132,7 @@ static ani_object AniGetAllBundleResourceInfo(ani_env* env, ani_double aniResFla { APP_LOGD("ani GetAllBundleResourceInfo called"); int32_t resFlag = 0; - if (!CommonFunAni::TryCastDoubleTo(aniResFlag, &resFlag)) { + if (!CommonFunAni::TryCastTo(aniResFlag, &resFlag)) { APP_LOGE("Cast aniResFlag failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, RESOURCE_FLAGS, TYPE_NUMBER); return nullptr; @@ -146,7 +147,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"); } @@ -158,7 +159,7 @@ static ani_object AniGetAllLauncherAbilityResourceInfo(ani_env* env, ani_double { APP_LOGD("ani GetAllLauncherAbilityResourceInfo called"); int32_t resFlag = 0; - if (!CommonFunAni::TryCastDoubleTo(aniResFlag, &resFlag)) { + if (!CommonFunAni::TryCastTo(aniResFlag, &resFlag)) { APP_LOGE("Cast aniResFlag failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, RESOURCE_FLAGS, TYPE_NUMBER); return nullptr; @@ -174,7 +175,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"); } 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 0000000000000000000000000000000000000000..9af1883477ef1805cfb299b9a592b8cf0b134265 --- /dev/null +++ b/interfaces/kits/ani/resource_manager/ani_resource_manager_common.cpp @@ -0,0 +1,104 @@ +/* + * 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 "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"; +constexpr const char* PROPERTYNAME_BUNDLENAME = "bundleName"; +constexpr const char* PROPERTYNAME_MODULENAME = "moduleName"; +constexpr const char* PROPERTYNAME_ABILITYNAME = "abilityName"; +constexpr const char* PROPERTYNAME_ICON = "icon"; +constexpr const char* PROPERTYNAME_LABEL = "label"; +constexpr const char* PROPERTYNAME_APPINDEX = "appIndex"; +} + +ani_object AniResourceManagerCommon::ConvertBundleResourceInfo(ani_env* env, const BundleResourceInfo& bundleResInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CommonFunAni::CreateClassByName(env, CLASSNAME_BUNDLE_RES_INFO_INNER); + RETURN_NULL_IF_NULL(cls); + + ani_object object = CommonFunAni::CreateNewObjectByClass(env, cls); + RETURN_NULL_IF_NULL(object); + + ani_string string = nullptr; + + // bundleName: string + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, bundleResInfo.bundleName, string)); + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + + // icon: string + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, bundleResInfo.icon, string)); + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + + // label: string + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, bundleResInfo.label, string)); + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); + + // appIndex: number + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, bundleResInfo.appIndex)); + + return object; +} + +ani_object AniResourceManagerCommon::ConvertLauncherAbilityResourceInfo(ani_env* env, + const LauncherAbilityResourceInfo& launcherAbilityResourceInfo) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CommonFunAni::CreateClassByName(env, CLASSNAME_LAUNCHER_ABILITY_RESOURCE_INFO_INNER); + RETURN_NULL_IF_NULL(cls); + + ani_object object = CommonFunAni::CreateNewObjectByClass(env, cls); + RETURN_NULL_IF_NULL(object); + + ani_string string = nullptr; + + // bundleName: string + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.bundleName, string)); + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_BUNDLENAME, string)); + + // moduleName: string + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.moduleName, string)); + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_MODULENAME, string)); + + // abilityName: string + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.abilityName, string)); + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_ABILITYNAME, string)); + + // icon: string + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.icon, string)); + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_ICON, string)); + + // label: string + RETURN_NULL_IF_FALSE(CommonFunAni::StringToAniStr(env, launcherAbilityResourceInfo.label, string)); + RETURN_NULL_IF_FALSE(CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_LABEL, string)); + + // appIndex: number + RETURN_NULL_IF_FALSE( + CommonFunAni::CallSetter(env, cls, object, PROPERTYNAME_APPINDEX, launcherAbilityResourceInfo.appIndex)); + + return object; +} +} // 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 0000000000000000000000000000000000000000..a8fceada4beab62e88f88bac89387f86e5c18a3a --- /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/ets/bundleManager/BundleResourceInfo.ets b/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfo.ets index 1cf0f5cd31b2a2ef49e6f9b144a1374e2fceeac9..256975f8a69467a87c911b66e22de3f6cc680088 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 a54fdcd2bcc181d0007d91989c26cec9f758e28c..5723e115a111c361734551bb2ee3dcb9895c4251 100644 --- a/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfoInner.ets +++ b/interfaces/kits/ani/resource_manager/ets/bundleManager/BundleResourceInfoInner.ets @@ -19,5 +19,5 @@ export class BundleResourceInfoInner implements BundleResourceInfo { readonly bundleName: string = ''; readonly icon: string = ''; readonly label: string = ''; - readonly appIndex: number; + readonly appIndex: int; } diff --git a/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfo.ets b/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfo.ets index 9f90522b84c1147aaf6645ffc2e30598827a067e..81726c4487cd660b998db821c801be410bd06207 100644 --- a/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfo.ets +++ b/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfo.ets @@ -24,5 +24,5 @@ export interface LauncherAbilityResourceInfo { 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 c2dfb19591768ac25c1c5842125709282dd3a818..df4398f5f5fda699fd8abd518069844a3edcb016 100644 --- a/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfoInner.ets +++ b/interfaces/kits/ani/resource_manager/ets/bundleManager/LauncherAbilityResourceInfoInner.ets @@ -26,5 +26,5 @@ export class LauncherAbilityResourceInfoInner implements LauncherAbilityResource readonly abilityName: string = ''; readonly icon: string = ''; readonly label: string = ''; - readonly appIndex: number; + readonly appIndex: int; } diff --git a/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp b/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp index 12d2c9af1922db73283e417460b1d038e5e4fecd..6b21196350ed7d13dcaa3344cc348207ed6b912b 100644 --- a/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp +++ b/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp @@ -34,7 +34,7 @@ static void AniAddDesktopShortcutInfo(ani_env* env, ani_object info, ani_double { APP_LOGD("ani AddDesktopShortcutInfo called"); int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGE("Cast aniUserId failed"); BusinessErrorAni::ThrowCommonError( env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); @@ -67,7 +67,7 @@ static void AniDeleteDesktopShortcutInfo(ani_env* env, ani_object info, ani_doub { APP_LOGD("ani DeleteDesktopShortcutInfo called"); int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGE("Cast aniUserId failed"); BusinessErrorAni::ThrowCommonError( env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); @@ -101,7 +101,7 @@ static ani_ref AniGetAllDesktopShortcutInfo(ani_env* env, ani_double aniUserId) { APP_LOGD("ani GetAllDesktopShortcutInfo called"); int32_t userId = 0; - if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + if (!CommonFunAni::TryCastTo(aniUserId, &userId)) { APP_LOGE("Cast aniUserId failed"); BusinessErrorAni::ThrowCommonError( env, ERROR_PARAM_CHECK_ERROR, USER_ID, TYPE_NUMBER); diff --git a/interfaces/kits/ani/shortcut_manager/ets/bundleManager/ShortcutInfo.ets b/interfaces/kits/ani/shortcut_manager/ets/bundleManager/ShortcutInfo.ets index b73302a42a120b0c70ebddff3b1f1940096ec2fc..9895ccda3b29a7382f509cb0bd6e90735185e163 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,12 +46,12 @@ 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; } diff --git a/interfaces/kits/ani/zlib/ani_zlib.cpp b/interfaces/kits/ani/zlib/ani_zlib.cpp index aa0c0870aa62f69250db644b1bf1382802a34cc2..de86d983514926592bd8ce344b8f96386f9f9d61 100644 --- a/interfaces/kits/ani/zlib/ani_zlib.cpp +++ b/interfaces/kits/ani/zlib/ani_zlib.cpp @@ -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; @@ -402,19 +402,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)) { + if (!CommonFunAni::TryCastTo(aniLen2, &len2)) { APP_LOGE("Cast aniLen2 failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_LEN2, TYPE_NUMBER); return 0; @@ -431,7 +431,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; @@ -468,19 +468,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)) { + if (!CommonFunAni::TryCastTo(aniLen2, &len2)) { APP_LOGE("Cast aniLen2 failed"); BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, PARAM_NAME_LEN2, TYPE_NUMBER); return 0; @@ -497,7 +497,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;