diff --git a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp index 91394a81d5ec24122412405d429c00b506c37613..b99cf7b733dcbb70858c1ecb8aef119da81ecbb4 100644 --- a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp +++ b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp @@ -79,8 +79,7 @@ static void CheckInfoCache(ani_env* env, const ANIQuery& query, return; } - uint32_t explicitQueryResultLen = 1; - if (infos.size() != explicitQueryResultLen || infos[0].uid != IPCSkeleton::GetCallingUid()) { + if (infos.size() != EXPLICIT_QUERY_RESULT_LEN || infos[0].uid != IPCSkeleton::GetCallingUid()) { return; } 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 e02f57bb25dd74a3dff377c7d9e5e51ee1e22448..df1d46e54f11ba017b414c76242ba4e1cc9ccbbf 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 @@ -34,7 +34,6 @@ namespace OHOS { namespace AppExecFwk { namespace { constexpr int32_t EMPTY_USER_ID = -500; -constexpr const char* PARSE_SHORTCUT_INFO = "parse ShortcutInfo failed"; constexpr const char* NS_NAME_LAUNCHERMANAGER = "@ohos.bundle.launcherBundleManager.launcherBundleManager"; const std::map START_SHORTCUT_RES_MAP = { @@ -50,7 +49,7 @@ static void AniStartShortcut(ani_env *env, ani_object aniShortcutInfo, ani_objec ShortcutInfo shortcutInfo; if (!CommonFunAni::ParseShortcutInfo(env, aniShortcutInfo, shortcutInfo)) { APP_LOGE("parse shortcutInfo failed"); - BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_SHORTCUT_INFO); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_SHORTCUT_INFO_FAILED); return; } if (shortcutInfo.intents.empty()) { @@ -77,7 +76,7 @@ static void AniStartShortcut(ani_env *env, ani_object aniShortcutInfo, ani_objec if (aniStartOptions != nullptr) { if (!UnwrapStartOptions(env, aniStartOptions, startOptions)) { APP_LOGE("ParseStartOptions error"); - BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_START_OPTIONS); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_START_OPTIONS_FAILED); return; } } @@ -103,7 +102,7 @@ static ani_object AniGetShortcutInfo(ani_env *env, } int32_t userId = EMPTY_USER_ID; if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { - APP_LOGW("try cast userId falied"); + APP_LOGW("try cast userId failed"); } if (userId == EMPTY_USER_ID) { userId = Constants::UNSPECIFIED_USERID; diff --git a/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp b/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp index 2ebcca46e717289c6bf2ef4b1de676a8e457ccab..2d1d6fe0570dd1ddf0481965010576072876d7f1 100644 --- a/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp +++ b/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp @@ -27,7 +27,6 @@ namespace OHOS { namespace AppExecFwk { namespace { -constexpr const char* PARSE_SHORTCUT_INFO = "ParseShortCutInfo"; constexpr const char* NS_NAME_SHORTCUTMANAGER = "@ohos.bundle.shortcutManager.shortcutManager"; } @@ -45,7 +44,7 @@ static void AniAddDesktopShortcutInfo(ani_env* env, ani_object info, ani_double ShortcutInfo shortcutInfo; if (!CommonFunAni::ParseShortcutInfo(env, info, shortcutInfo) || !CommonFunc::CheckShortcutInfo(shortcutInfo)) { - BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_SHORTCUT_INFO); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, INVALID_SHORTCUT_INFO_ERROR); APP_LOGE("Parse shortcutInfo err. userId:%{public}d", userId); return; } @@ -79,7 +78,7 @@ static void AniDeleteDesktopShortcutInfo(ani_env* env, ani_object info, ani_doub if (!CommonFunAni::ParseShortcutInfo(env, info, shortcutInfo) || !CommonFunc::CheckShortcutInfo(shortcutInfo)) { APP_LOGE("Parse shortcutInfo err. userId:%{public}d", userId); - BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_SHORTCUT_INFO); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, INVALID_SHORTCUT_INFO_ERROR); return; } diff --git a/interfaces/kits/js/app_control/js_app_control.cpp b/interfaces/kits/js/app_control/js_app_control.cpp index 0411d6966f9c6e5df4a1963411af47887dae0535..ed19ba3f783d9f5fee271a24b4f0db6774c78844 100644 --- a/interfaces/kits/js/app_control/js_app_control.cpp +++ b/interfaces/kits/js/app_control/js_app_control.cpp @@ -34,46 +34,12 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::AAFwk; namespace { -const char* TYPE_WANT = "want"; -const char* PERMISSION_DISPOSED_STATUS = "ohos.permission.MANAGE_DISPOSED_APP_STATUS"; -const char* SET_DISPOSED_STATUS = "SetDisposedStatus"; -const char* GET_DISPOSED_STATUS = "GetDisposedStatus"; -const char* DELETE_DISPOSED_STATUS = "DeleteDisposedStatus"; -const char* SET_DISPOSED_STATUS_SYNC = "SetDisposedStatusSync"; -const char* DELETE_DISPOSED_STATUS_SYNC = "DeleteDisposedStatusSync"; -const char* GET_DISPOSED_STATUS_SYNC = "GetDisposedStatusSync"; -const char* APP_ID = "appId"; -const char* APP_IDENTIFIER = "appIdentifier"; -const char* DISPOSED_WANT = "disposedWant"; -const char* DISPOSED_RULE = "disposedRule"; -const char* DISPOSED_RULE_TYPE = "DisposedRule"; -const char* UNINSTALL_DISPOSED_RULE = "uninstallDisposedRule"; -const char* UNINSTALL_DISPOSED_RULE_TYPE = "UninstallDisposedRule"; -const char* SET_UNINSTALL_DISPOSED_RULE = "SetUninstallDisposedRule"; -const char* DELETE_UNINSTALL_DISPOSED_RULE = "DeleteUninstallDisposedRule"; -const char* GET_UNINSTALL_DISPOSED_RULE = "GetUninstallDisposedRule"; -const char* SET_DISPOSED_RULES = "SetDisposedRules"; const char* PARAM_LENGTH_ERROR = "parameter length invalid"; const int16_t MAX_VECTOR_NUM = 1000; } -static OHOS::sptr GetAppControlProxy() -{ - auto bundleMgr = CommonFunc::GetBundleMgr(); - if (bundleMgr == nullptr) { - APP_LOGE("CommonFunc::GetBundleMgr failed"); - return nullptr; - } - auto appControlProxy = bundleMgr->GetAppControlProxy(); - if (appControlProxy == nullptr) { - APP_LOGE("GetAppControlProxy failed"); - return nullptr; - } - return appControlProxy; -} - static ErrCode InnerGetDisposedStatus(napi_env, const std::string& appId, Want& disposedWant) { - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null"); return ERROR_SYSTEM_ABILITY_NOT_FOUND; @@ -84,7 +50,7 @@ static ErrCode InnerGetDisposedStatus(napi_env, const std::string& appId, Want& static ErrCode InnerSetDisposedStatus(napi_env, const std::string& appId, Want& disposedWant) { - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null"); return ERROR_SYSTEM_ABILITY_NOT_FOUND; @@ -95,7 +61,7 @@ static ErrCode InnerSetDisposedStatus(napi_env, const std::string& appId, Want& static ErrCode InnerDeleteDisposedStatus(napi_env, const std::string& appId) { - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null"); return ERROR_SYSTEM_ABILITY_NOT_FOUND; @@ -215,7 +181,7 @@ napi_value SetDisposedStatusSync(napi_env env, napi_callback_info info) BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, DISPOSED_WANT, TYPE_WANT); return nRet; } - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, @@ -322,7 +288,7 @@ static napi_value InnerDeleteDisposedStatusSync(napi_env env, std::string &appId napi_throw(env, businessError); return nullptr; } - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, @@ -480,7 +446,7 @@ napi_value GetDisposedStatusSync(napi_env env, napi_callback_info info) napi_throw(env, businessError); return nullptr; } - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, @@ -714,7 +680,7 @@ static napi_value InnerGetDisposedRule(napi_env env, std::string &appId, int32_t napi_throw(env, businessError); return nullptr; } - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, @@ -777,7 +743,7 @@ static napi_value InnerSetDisposedRule(napi_env env, std::string &appId, Dispose { napi_value nRet; napi_get_undefined(env, &nRet); - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null."); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, @@ -861,7 +827,7 @@ napi_value SetDisposedRules(napi_env env, napi_callback_info info) BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_TYPE_CHECK_ERROR); return nRet; } - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("AppControlProxy is null"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, @@ -945,7 +911,7 @@ static napi_value InnerGetUninstallDisposedRule(napi_env env, std::string &appId napi_throw(env, businessError); return nullptr; } - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("null appControlProxy"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, @@ -1006,7 +972,7 @@ static napi_value InnerSetUninstallDisposedRule(napi_env env, std::string &appId { napi_value nRet; napi_get_undefined(env, &nRet); - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("null appControlProxy"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, @@ -1084,7 +1050,7 @@ static napi_value InnerDeleteUninstallDisposedRule(napi_env env, std::string &ap napi_throw(env, businessError); return nullptr; } - auto appControlProxy = GetAppControlProxy(); + auto appControlProxy = CommonFunc::GetAppControlProxy(); if (appControlProxy == nullptr) { APP_LOGE("null appControlProxy"); napi_value error = BusinessError::CreateCommonError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, diff --git a/interfaces/kits/js/bundle_manager/BUILD.gn b/interfaces/kits/js/bundle_manager/BUILD.gn index 257bd1ee257e0a7312b80a47b0c8e849c87ef7ee..a719a32bd3141503b63d58ad6b8ed1af71e2db91 100644 --- a/interfaces/kits/js/bundle_manager/BUILD.gn +++ b/interfaces/kits/js/bundle_manager/BUILD.gn @@ -27,7 +27,10 @@ ohos_shared_library("bundle_manager_common") { } include_dirs = [ "${kits_path}/js/common" ] - sources = [ "bundle_manager_helper.cpp" ] + sources = [ + "bundle_manager_helper.cpp", + "clean_cache_callback.cpp", + ] cflags = [ "-Os", @@ -85,7 +88,6 @@ ohos_shared_library("bundlemanager") { sources = [ "bundle_manager.cpp", "bundle_manager_sync.cpp", - "clean_cache_callback.cpp", "native_module.cpp", ] diff --git a/interfaces/kits/js/bundle_manager/bundle_manager.cpp b/interfaces/kits/js/bundle_manager/bundle_manager.cpp index d4537ce7831bae636a0eb858fd0e84e0f1bf01c9..15ae2d815f7dc3df1d528741f0e781a13a94b4e5 100644 --- a/interfaces/kits/js/bundle_manager/bundle_manager.cpp +++ b/interfaces/kits/js/bundle_manager/bundle_manager.cpp @@ -44,64 +44,14 @@ namespace OHOS { namespace AppExecFwk { namespace { constexpr const char* IS_ENABLE = "isEnable"; -constexpr const char* PROFILE_TYPE = "profileType"; constexpr const char* STRING_TYPE = "napi_string"; -constexpr const char* VERIFY_ABC = "VerifyAbc"; -constexpr const char* DELETE_ABC = "DeleteAbc"; -constexpr const char* ERR_MSG_LAUNCH_WANT_INVALID = "The launch want is not found."; -constexpr const char* ADDITIONAL_INFO = "additionalInfo"; -constexpr const char* LINK = "link"; -constexpr const char* DEVELOPER_ID = "developerId"; -constexpr const char* APP_DISTRIBUTION_TYPE = "appDistributionType"; -constexpr const char* APP_DISTRIBUTION_TYPE_ENUM = "AppDistributionType"; constexpr const char* ICON_ID = "iconId"; constexpr const char* LABEL_ID = "labelId"; constexpr const char* STATE = "state"; -constexpr const char* SOURCE_PATHS = "sourcePaths"; -constexpr const char* DESTINATION_PATH = "destinationPath"; -constexpr const char* HOST_BUNDLE_NAME = "hostBundleName"; -constexpr const char* URI = "uri"; -const std::string GET_BUNDLE_ARCHIVE_INFO = "GetBundleArchiveInfo"; -const std::string GET_ALL_BUNDLE_CACHE_SIZE = "getAllBundleCacheSize"; -const std::string CLEAN_ALL_BUNDLE_CACHE = "cleanAllBundleCache"; -const std::string GET_PERMISSION_DEF = "GetPermissionDef"; -const std::string PERMISSION_NAME = "permissionName"; const std::string PARAM_TYPE_CHECK_ERROR_WITH_POS = "param type check error, error position : "; -const std::string GET_ALL_SHARED_BUNDLE_INFO = "GetAllSharedBundleInfo"; -const std::string GET_SHARED_BUNDLE_INFO = "GetSharedBundleInfo"; -const std::string GET_EXT_RESOURCE = "GetExtResource"; -const std::string DISABLE_DYNAMIC_ICON = "DisableDynamicIcon"; -const std::string GET_ALL_DYNAMIC_ICON = "GetAllDynamicIconInfo"; -const std::string GET_DYNAMIC_ICON_INFO = "GetDynamicIconInfo"; -const std::string GET_APP_PROVISION_INFO = "GetAppProvisionInfo"; -const std::string RESOURCE_NAME_OF_GET_ADDITIONAL_INFO = "GetAdditionalInfo"; -const std::string GET_JSON_PROFILE = "GetJsonProfile"; -const std::string GET_RECOVERABLE_APPLICATION_INFO = "GetRecoverableApplicationInfo"; -const std::string RESOURCE_NAME_OF_SET_ADDITIONAL_INFO = "SetAdditionalInfo"; -const std::string CAN_OPEN_LINK = "CanOpenLink"; -const std::string GET_ALL_PREINSTALLED_APP_INFOS = "GetAllPreinstalledApplicationInfos"; -const std::string GET_ALL_BUNDLE_INFO_BY_DEVELOPER_ID = "GetAllBundleInfoByDeveloperId"; -const std::string GET_DEVELOPER_IDS = "GetDeveloperIds"; -const std::string SWITCH_UNINSTALL_STATE = "SwitchUninstallState"; -const std::string GET_ALL_APP_CLONE_BUNDLE_INFO = "GetAllAppCloneBundleInfo"; -const std::string GET_ALL_PLUGIN_INFO = "GetAllPluginInfo"; -const std::string MIGRATE_DATA = "MigrateData"; -const std::string GET_ABILITY_INFOS = "GetAbilityInfos"; -const std::string GET_ABILITYINFO_PERMISSIONS = "ohos.permission.GET_ABILITY_INFO"; -constexpr int32_t ENUM_ONE = 1; -constexpr int32_t ENUM_TWO = 2; -constexpr int32_t ENUM_THREE = 3; -constexpr int32_t ENUM_FOUR = 4; -constexpr int32_t ENUM_FIVE = 5; -constexpr int32_t ENUM_SIX = 6; -constexpr int32_t ENUM_SEVEN = 7; constexpr const char* UNSPECIFIED = "UNSPECIFIED"; constexpr const char* MULTI_INSTANCE = "MULTI_INSTANCE"; constexpr const char* APP_CLONE = "APP_CLONE"; -constexpr const char* BUNDLE_GET_ALL_DYNAMIC_PERMISSIONS = - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; -constexpr const char* BUNDLE_ENABLE_AND_DISABLE_ALL_DYNAMIC_PERMISSIONS = - "ohos.permission.ACCESS_DYNAMIC_ICON and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; } // namespace using namespace OHOS::AAFwk; static std::shared_ptr g_clearCacheListener; @@ -183,18 +133,6 @@ void RegisterClearCacheListener() (void)EventFwk::CommonEventManager::SubscribeCommonEvent(g_clearCacheListener); } -static ErrCode InnerGetBundleArchiveInfo(std::string &hapFilePath, int32_t flags, BundleInfo &bundleInfo) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("iBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetBundleArchiveInfoV9(hapFilePath, flags, bundleInfo); - APP_LOGD("GetBundleArchiveInfoV9 ErrCode : %{public}d", ret); - return CommonFunc::ConvertErrCode(ret); -} - void GetBundleArchiveInfoExec(napi_env env, void *data) { GetBundleArchiveInfoCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -202,7 +140,7 @@ void GetBundleArchiveInfoExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerGetBundleArchiveInfo( + asyncCallbackInfo->err = BundleManagerHelper::InnerGetBundleArchiveInfo( asyncCallbackInfo->hapFilePath, asyncCallbackInfo->flags, asyncCallbackInfo->bundleInfo); } @@ -1117,18 +1055,6 @@ napi_value QueryAbilityInfos(napi_env env, napi_callback_info info) return promise; } -static ErrCode InnerGetAllPluginInfo(std::string &hostBundleName, int32_t userId, - std::vector &pluginBundleInfos) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("iBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetAllPluginInfo(hostBundleName, userId, pluginBundleInfos); - return CommonFunc::ConvertErrCode(ret); -} - void GetAllPluginInfoExec(napi_env env, void *data) { PluginCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -1136,7 +1062,7 @@ void GetAllPluginInfoExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerGetAllPluginInfo(asyncCallbackInfo->hostBundleName, + asyncCallbackInfo->err = BundleManagerHelper::InnerGetAllPluginInfo(asyncCallbackInfo->hostBundleName, asyncCallbackInfo->userId, asyncCallbackInfo->pluginBundleInfos); } @@ -2244,27 +2170,6 @@ napi_value IsAbilityEnabled(napi_env env, napi_callback_info info) return promise; } -static ErrCode InnerCleanBundleCacheCallback( - const std::string &bundleName, int32_t appIndex, const OHOS::sptr cleanCacheCallback) -{ - if (cleanCacheCallback == nullptr) { - APP_LOGE("callback nullptr"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("can not get iBundleMgr"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; - ErrCode result = iBundleMgr->CleanBundleCacheFiles(bundleName, cleanCacheCallback, userId, appIndex); - if (result != ERR_OK) { - APP_LOGE("call error, bundleName is %{public}s, userId is %{public}d, appIndex is %{public}d", - bundleName.c_str(), userId, appIndex); - } - return CommonFunc::ConvertErrCode(result); -} - void CleanBundleCacheFilesExec(napi_env env, void *data) { CleanBundleCacheCallbackInfo* asyncCallbackInfo = reinterpret_cast(data); @@ -2275,7 +2180,7 @@ void CleanBundleCacheFilesExec(napi_env env, void *data) if (asyncCallbackInfo->cleanCacheCallback == nullptr) { asyncCallbackInfo->cleanCacheCallback = new (std::nothrow) CleanCacheCallback(); } - asyncCallbackInfo->err = InnerCleanBundleCacheCallback( + asyncCallbackInfo->err = BundleManagerHelper::InnerCleanBundleCacheCallback( asyncCallbackInfo->bundleName, asyncCallbackInfo->appIndex, asyncCallbackInfo->cleanCacheCallback); if ((asyncCallbackInfo->err == NO_ERROR) && (asyncCallbackInfo->cleanCacheCallback != nullptr)) { // wait for OnCleanCacheFinished @@ -2301,7 +2206,7 @@ void CleanBundleCacheFilesComplete(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[0])); } else { result[0] = BusinessError::CreateCommonError(env, asyncCallbackInfo->err, - "CleanBundleCacheFiles", Constants::PERMISSION_REMOVECACHEFILE); + CLEAN_BUNDLE_CACHE_FILES, Constants::PERMISSION_REMOVECACHEFILE); } CommonFunc::NapiReturnDeferred(env, asyncCallbackInfo, result, ARGS_SIZE_ONE); } @@ -2367,15 +2272,6 @@ napi_value CleanBundleCacheFiles(napi_env env, napi_callback_info info) return promise; } -ErrCode InnerVerify(const std::vector &abcPaths, bool flag) -{ - ErrCode ret = VerifyManagerClient::GetInstance().Verify(abcPaths); - if (ret == ERR_OK && flag) { - VerifyManagerClient::GetInstance().RemoveFiles(abcPaths); - } - return CommonFunc::ConvertErrCode(ret); -} - void VerifyExec(napi_env env, void *data) { VerifyCallbackInfo* asyncCallbackInfo = reinterpret_cast(data); @@ -2384,7 +2280,7 @@ void VerifyExec(napi_env env, void *data) return; } - asyncCallbackInfo->err = InnerVerify(asyncCallbackInfo->abcPaths, asyncCallbackInfo->flag); + asyncCallbackInfo->err = BundleManagerHelper::InnerVerify(asyncCallbackInfo->abcPaths, asyncCallbackInfo->flag); } void VerifyComplete(napi_env env, napi_status status, void *data) @@ -2453,23 +2349,6 @@ napi_value VerifyAbc(napi_env env, napi_callback_info info) return promise; } -ErrCode InnerGetExtResource( - const std::string &bundleName, std::vector &moduleNames) -{ - auto extResourceManager = CommonFunc::GetExtendResourceManager(); - if (extResourceManager == nullptr) { - APP_LOGE("extResourceManager is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - - ErrCode ret = extResourceManager->GetExtResource(bundleName, moduleNames); - if (ret != ERR_OK) { - APP_LOGE("GetExtResource failed"); - } - - return CommonFunc::ConvertErrCode(ret); -} - void GetExtResourceExec(napi_env env, void *data) { DynamicIconCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -2477,7 +2356,7 @@ void GetExtResourceExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerGetExtResource( + asyncCallbackInfo->err = BundleManagerHelper::InnerGetExtResource( asyncCallbackInfo->bundleName, asyncCallbackInfo->moduleNames); } @@ -2551,27 +2430,6 @@ napi_value GetExtResource(napi_env env, napi_callback_info info) return promise; } -ErrCode InnerEnableDynamicIcon( - const std::string &bundleName, const std::string &moduleName, const BundleOption &option) -{ - auto extResourceManager = CommonFunc::GetExtendResourceManager(); - if (extResourceManager == nullptr) { - APP_LOGE("extResourceManager is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = ERR_OK; - if (option.isDefault) { - ret = extResourceManager->EnableDynamicIcon(bundleName, moduleName); - } else { - ret = extResourceManager->EnableDynamicIcon(bundleName, moduleName, option.userId, option.appIndex); - } - if (ret != ERR_OK) { - APP_LOGE("EnableDynamicIcon failed"); - } - - return CommonFunc::ConvertErrCode(ret); -} - void EnableDynamicIconExec(napi_env env, void *data) { DynamicIconCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -2579,8 +2437,9 @@ void EnableDynamicIconExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerEnableDynamicIcon( - asyncCallbackInfo->bundleName, asyncCallbackInfo->moduleName, asyncCallbackInfo->option); + asyncCallbackInfo->err = BundleManagerHelper::InnerEnableDynamicIcon( + asyncCallbackInfo->bundleName, asyncCallbackInfo->moduleName, + asyncCallbackInfo->option.appIndex, asyncCallbackInfo->option.userId, asyncCallbackInfo->option.isDefault); } void EnableDynamicIconComplete(napi_env env, napi_status status, void *data) @@ -2650,27 +2509,6 @@ napi_value EnableDynamicIcon(napi_env env, napi_callback_info info) return promise; } -ErrCode InnerDisableDynamicIcon(const std::string &bundleName, const BundleOption &option) -{ - auto extResourceManager = CommonFunc::GetExtendResourceManager(); - if (extResourceManager == nullptr) { - APP_LOGE("extResourceManager is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - - ErrCode ret = ERR_OK; - if (option.isDefault) { - ret = extResourceManager->DisableDynamicIcon(bundleName); - } else { - ret = extResourceManager->DisableDynamicIcon(bundleName, option.userId, option.appIndex); - } - if (ret != ERR_OK) { - APP_LOGE("DisableDynamicIcon failed"); - } - - return CommonFunc::ConvertErrCode(ret); -} - void DisableDynamicIconExec(napi_env env, void *data) { DynamicIconCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -2678,7 +2516,8 @@ void DisableDynamicIconExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerDisableDynamicIcon(asyncCallbackInfo->bundleName, asyncCallbackInfo->option); + asyncCallbackInfo->err = BundleManagerHelper::InnerDisableDynamicIcon(asyncCallbackInfo->bundleName, + asyncCallbackInfo->option.appIndex, asyncCallbackInfo->option.userId, asyncCallbackInfo->option.isDefault); } void DisableDynamicIconComplete(napi_env env, napi_status status, void *data) @@ -2801,19 +2640,6 @@ napi_value GetDynamicIcon(napi_env env, napi_callback_info info) return promise; } -ErrCode InnerDeleteAbc(const std::string &path) -{ - ErrCode ret = AppExecFwk::VerifyManagerClient::GetInstance().DeleteAbc(path); - if (ret == ERR_APPEXECFWK_NULL_PTR) { - APP_LOGE("VerifyAbc failed due to iBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - if (ret != ERR_OK) { - APP_LOGE("DeleteAbc failed"); - } - return CommonFunc::ConvertErrCode(ret); -} - void DeleteAbcExec(napi_env env, void *data) { VerifyCallbackInfo* asyncCallbackInfo = reinterpret_cast(data); @@ -2822,7 +2648,7 @@ void DeleteAbcExec(napi_env env, void *data) return; } - asyncCallbackInfo->err = InnerDeleteAbc(asyncCallbackInfo->deletePath); + asyncCallbackInfo->err = BundleManagerHelper::InnerDeleteAbc(asyncCallbackInfo->deletePath); } void DeleteAbcComplete(napi_env env, napi_status status, void *data) @@ -2986,128 +2812,10 @@ napi_value GetLaunchWantForBundle(napi_env env, napi_callback_info info) return promise; } -ErrCode GetAbilityFromBundleInfo(const BundleInfo& bundleInfo, const std::string& abilityName, - const std::string& moduleName, AbilityInfo& targetAbilityInfo) -{ - bool ifExists = false; - for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) { - for (const auto& abilityInfo : hapModuleInfo.abilityInfos) { - if (abilityInfo.name == abilityName && abilityInfo.moduleName == moduleName) { - if (!abilityInfo.enabled) { - APP_LOGI("ability disabled"); - return ERR_BUNDLE_MANAGER_ABILITY_DISABLED; - } - ifExists = true; - targetAbilityInfo = abilityInfo; - break; - } - } - if (ifExists) { - break; - } - } - if (!ifExists) { - APP_LOGE("ability not exist"); - return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; - } - return ERR_OK; -} - -ErrCode GetExtensionFromBundleInfo(const BundleInfo& bundleInfo, const std::string& abilityName, - const std::string& moduleName, ExtensionAbilityInfo& targetExtensionInfo) -{ - bool ifExists = false; - for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) { - for (const auto& extensionInfo : hapModuleInfo.extensionInfos) { - if (extensionInfo.name == abilityName && extensionInfo.moduleName == moduleName) { - ifExists = true; - targetExtensionInfo = extensionInfo; - break; - } - if (!extensionInfo.enabled) { - APP_LOGI("extension disabled"); - return ERR_BUNDLE_MANAGER_ABILITY_DISABLED; - } - } - if (ifExists) { - break; - } - } - if (!ifExists) { - APP_LOGE("ability not exist"); - return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; - } - return ERR_OK; -} - static ErrCode InnerGetProfile(GetProfileCallbackInfo &info) { - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("can not get iBundleMgr"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - - if (info.abilityName.empty()) { - APP_LOGE("InnerGetProfile failed due to empty abilityName"); - return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; - } - - if (info.moduleName.empty()) { - APP_LOGE("InnerGetProfile failed due to empty moduleName"); - return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST; - } - auto baseFlag = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA) + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE); - ErrCode result; - BundleMgrClient client; - BundleInfo bundleInfo; - if (info.type == AbilityProfileType::ABILITY_PROFILE) { - auto getAbilityFlag = baseFlag + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY); - result = iBundleMgr->GetBundleInfoForSelf(getAbilityFlag, bundleInfo); - if (result != ERR_OK) { - APP_LOGE("GetBundleInfoForSelf failed"); - return result; - } - AbilityInfo targetAbilityInfo; - result = GetAbilityFromBundleInfo( - bundleInfo, info.abilityName, info.moduleName, targetAbilityInfo); - if (result != ERR_OK) { - return result; - } - if (!client.GetProfileFromAbility(targetAbilityInfo, info.metadataName, info.profileVec)) { - APP_LOGE("GetProfileFromExtension failed"); - return ERR_BUNDLE_MANAGER_PROFILE_NOT_EXIST; - } - return ERR_OK; - } - - if (info.type == AbilityProfileType::EXTENSION_PROFILE) { - auto getExtensionFlag = baseFlag + - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY); - result = iBundleMgr->GetBundleInfoForSelf(getExtensionFlag, bundleInfo); - if (result != ERR_OK) { - APP_LOGE("GetBundleInfoForSelf failed"); - return result; - } - - ExtensionAbilityInfo targetExtensionInfo; - result = GetExtensionFromBundleInfo( - bundleInfo, info.abilityName, info.moduleName, targetExtensionInfo); - if (result != ERR_OK) { - return result; - } - if (!client.GetProfileFromExtension(targetExtensionInfo, info.metadataName, info.profileVec)) { - APP_LOGE("GetProfileFromExtension failed"); - return ERR_BUNDLE_MANAGER_PROFILE_NOT_EXIST; - } - return ERR_OK; - } - - APP_LOGE("InnerGetProfile failed due to type is invalid"); - return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; + return BundleManagerHelper::CommonInnerGetProfile(info.moduleName, info.abilityName, info.metadataName, + info.type == AbilityProfileType::EXTENSION_PROFILE, info.profileVec); } void GetProfileExec(napi_env env, void *data) @@ -3600,17 +3308,6 @@ void CreateAppDistributionTypeObject(napi_env env, napi_value value) NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "NONE", nNone)); } -static ErrCode InnerGetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("can not get iBundleMgr"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetPermissionDef(permissionName, permissionDef); - return CommonFunc::ConvertErrCode(ret); -} - void GetPermissionDefExec(napi_env env, void *data) { AsyncPermissionDefineCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -3619,7 +3316,7 @@ void GetPermissionDefExec(napi_env env, void *data) return; } if (asyncCallbackInfo->err == NO_ERROR) { - asyncCallbackInfo->err = InnerGetPermissionDef(asyncCallbackInfo->permissionName, + asyncCallbackInfo->err = BundleManagerHelper::InnerGetPermissionDef(asyncCallbackInfo->permissionName, asyncCallbackInfo->permissionDef); } } @@ -4299,17 +3996,6 @@ napi_value GetBundleInfoForSelf(napi_env env, napi_callback_info info) return promise; } -static ErrCode InnerGetAllSharedBundleInfo(std::vector &sharedBundles) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("iBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetAllSharedBundleInfo(sharedBundles); - return CommonFunc::ConvertErrCode(ret); -} - void GetAllSharedBundleInfoExec(napi_env env, void *data) { SharedBundleCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -4317,7 +4003,7 @@ void GetAllSharedBundleInfoExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerGetAllSharedBundleInfo(asyncCallbackInfo->sharedBundles); + asyncCallbackInfo->err = BundleManagerHelper::InnerGetAllSharedBundleInfo(asyncCallbackInfo->sharedBundles); } void GetAllSharedBundleInfoComplete(napi_env env, napi_status status, void *data) @@ -4382,18 +4068,6 @@ napi_value GetAllSharedBundleInfo(napi_env env, napi_callback_info info) return promise; } -static ErrCode InnerGetSharedBundleInfo(const std::string &bundleName, const std::string &moduleName, - std::vector &sharedBundles) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("iBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetSharedBundleInfo(bundleName, moduleName, sharedBundles); - return CommonFunc::ConvertErrCode(ret); -} - void GetSharedBundleInfoExec(napi_env env, void *data) { SharedBundleCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -4401,8 +4075,8 @@ void GetSharedBundleInfoExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerGetSharedBundleInfo(asyncCallbackInfo->bundleName, asyncCallbackInfo->moduleName, - asyncCallbackInfo->sharedBundles); + asyncCallbackInfo->err = BundleManagerHelper::InnerGetSharedBundleInfo( + asyncCallbackInfo->bundleName, asyncCallbackInfo->moduleName, asyncCallbackInfo->sharedBundles); } void GetSharedBundleInfoComplete(napi_env env, napi_status status, void *data) @@ -4671,18 +4345,6 @@ void CreateProfileTypeObject(napi_env env, napi_value value) NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, value, "INTENT_PROFILE", nIntentProfile)); } -ErrCode InnerGetAppProvisionInfo( - const std::string &bundleName, int32_t userId, AppProvisionInfo &appProvisionInfo) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("iBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetAppProvisionInfo(bundleName, userId, appProvisionInfo); - return CommonFunc::ConvertErrCode(ret); -} - void GetAppProvisionInfoExec(napi_env env, void *data) { AppProvisionInfoCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -4691,7 +4353,7 @@ void GetAppProvisionInfoExec(napi_env env, void *data) return; } if (asyncCallbackInfo->err == NO_ERROR) { - asyncCallbackInfo->err = InnerGetAppProvisionInfo( + asyncCallbackInfo->err = BundleManagerHelper::InnerGetAppProvisionInfo( asyncCallbackInfo->bundleName, asyncCallbackInfo->userId, asyncCallbackInfo->appProvisionInfo); } } @@ -4997,17 +4659,6 @@ napi_value GetJsonProfile(napi_env env, napi_callback_info info) return nProfile; } -static ErrCode InnerGetRecoverableApplicationInfo(std::vector &recoverableApplications) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("iBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetRecoverableApplicationInfo(recoverableApplications); - return CommonFunc::ConvertErrCode(ret); -} - void GetRecoverableApplicationInfoExec(napi_env env, void *data) { RecoverableApplicationCallbackInfo *asyncCallbackInfo = @@ -5015,7 +4666,8 @@ void GetRecoverableApplicationInfoExec(napi_env env, void *data) if (asyncCallbackInfo == nullptr) { return; } - asyncCallbackInfo->err = InnerGetRecoverableApplicationInfo(asyncCallbackInfo->recoverableApplicationInfos); + asyncCallbackInfo->err = + BundleManagerHelper::InnerGetRecoverableApplicationInfo(asyncCallbackInfo->recoverableApplicationInfos); } void GetRecoverableApplicationInfoExecComplete(napi_env env, napi_status status, void *data) @@ -5230,18 +4882,6 @@ void GetAllPreinstalledApplicationInfosComplete(napi_env env, napi_status status env, asyncCallbackInfo, result, ARGS_SIZE_TWO); } -static ErrCode InnerGetAllPreinstalledApplicationInfos( - std::vector &preinstalledApplicationInfos) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("IBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetAllPreinstalledApplicationInfos(preinstalledApplicationInfos); - return CommonFunc::ConvertErrCode(ret); -} - void GetAllPreinstalledApplicationInfosExec(napi_env env, void *data) { PreinstalledApplicationInfosCallbackInfo *asyncCallbackInfo = @@ -5250,7 +4890,8 @@ void GetAllPreinstalledApplicationInfosExec(napi_env env, void *data) APP_LOGE("AsyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerGetAllPreinstalledApplicationInfos(asyncCallbackInfo->preinstalledApplicationInfos); + asyncCallbackInfo->err = + BundleManagerHelper::InnerGetAllPreinstalledApplicationInfos(asyncCallbackInfo->preinstalledApplicationInfos); } napi_value GetAllPreinstalledApplicationInfos(napi_env env, napi_callback_info info) @@ -5516,46 +5157,6 @@ napi_value GetAppCloneBundleInfo(napi_env env, napi_callback_info info) return promise; } -static ErrCode InnerGetAllAppCloneBundleInfo(const std::string &bundleName, int32_t bundleFlags, - int32_t userId, std::vector &bundleInfos) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("can not get iBundleMgr"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - BundleInfo bundleInfoMain; - ErrCode ret = iBundleMgr->GetCloneBundleInfo(bundleName, bundleFlags, 0, bundleInfoMain, userId); - APP_LOGD("GetMainBundleInfo appIndex = 0, ret=%{public}d", ret); - if (ret == ERR_OK) { - bundleInfos.emplace_back(bundleInfoMain); - } - if (ret != ERR_OK && ret != ERR_BUNDLE_MANAGER_APPLICATION_DISABLED && - ret != ERR_BUNDLE_MANAGER_BUNDLE_DISABLED) { - return CommonFunc::ConvertErrCode(ret); - } - // handle clone apps - std::vector appIndexes; - ErrCode getCloneIndexesRet = iBundleMgr->GetCloneAppIndexes(bundleName, appIndexes, userId); - if (getCloneIndexesRet != ERR_OK) { - if (ret == ERR_OK) { - return SUCCESS; - } - return CommonFunc::ConvertErrCode(ret); - } - for (int32_t appIndex : appIndexes) { - BundleInfo bundleInfo; - ret = iBundleMgr->GetCloneBundleInfo(bundleName, bundleFlags, appIndex, bundleInfo, userId); - if (ret == ERR_OK) { - bundleInfos.emplace_back(bundleInfo); - } - } - if (bundleInfos.empty()) { - return ERROR_BUNDLE_IS_DISABLED; - } - return SUCCESS; -} - void GetAllAppCloneBundleInfoExec(napi_env env, void *data) { CloneAppBundleInfosCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -5567,9 +5168,8 @@ void GetAllAppCloneBundleInfoExec(napi_env env, void *data) asyncCallbackInfo->bundleName.c_str(), asyncCallbackInfo->bundleFlags, asyncCallbackInfo->userId); - asyncCallbackInfo->err = - InnerGetAllAppCloneBundleInfo(asyncCallbackInfo->bundleName, asyncCallbackInfo->bundleFlags, - asyncCallbackInfo->userId, asyncCallbackInfo->bundleInfos); + asyncCallbackInfo->err = BundleManagerHelper::InnerGetAllAppCloneBundleInfo(asyncCallbackInfo->bundleName, + asyncCallbackInfo->bundleFlags, asyncCallbackInfo->userId, asyncCallbackInfo->bundleInfos); } static void CloneAppBundleInfos( @@ -5736,21 +5336,6 @@ napi_value MigrateData(napi_env env, napi_callback_info info) return promise; } -ErrCode InnerGetAllDynamicIconInfo(const int32_t userId, std::vector &dynamicIconInfos) -{ - auto extResourceManager = CommonFunc::GetExtendResourceManager(); - if (extResourceManager == nullptr) { - APP_LOGE("extResourceManager is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = extResourceManager->GetAllDynamicIconInfo(userId, dynamicIconInfos); - if (ret != ERR_OK) { - APP_LOGE_NOFUNC("GetDynamicIcon failed %{public}d", ret); - } - - return CommonFunc::ConvertErrCode(ret); -} - void GetAllDynamicIconInfoExec(napi_env env, void *data) { DynamicIconInfoCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -5758,7 +5343,7 @@ void GetAllDynamicIconInfoExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerGetAllDynamicIconInfo( + asyncCallbackInfo->err = BundleManagerHelper::InnerGetAllDynamicIconInfo( asyncCallbackInfo->userId, asyncCallbackInfo->dynamicIconInfos); } @@ -5818,21 +5403,6 @@ napi_value GetAllDynamicIconInfo(napi_env env, napi_callback_info info) return promise; } -ErrCode InnerGetDynamicIconInfo(const std::string &bundleName, std::vector &dynamicIconInfos) -{ - auto extResourceManager = CommonFunc::GetExtendResourceManager(); - if (extResourceManager == nullptr) { - APP_LOGE("extResourceManager is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = extResourceManager->GetDynamicIconInfo(bundleName, dynamicIconInfos); - if (ret != ERR_OK) { - APP_LOGE_NOFUNC("-n %{public}s GetDynamicIcon failed %{public}d", bundleName.c_str(), ret); - } - - return CommonFunc::ConvertErrCode(ret); -} - void GetDynamicIconInfoExec(napi_env env, void *data) { DynamicIconInfoCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -5840,7 +5410,7 @@ void GetDynamicIconInfoExec(napi_env env, void *data) APP_LOGE("asyncCallbackInfo is null"); return; } - asyncCallbackInfo->err = InnerGetDynamicIconInfo( + asyncCallbackInfo->err = BundleManagerHelper::InnerGetDynamicIconInfo( asyncCallbackInfo->bundleName, asyncCallbackInfo->dynamicIconInfos); } @@ -5896,19 +5466,6 @@ napi_value GetDynamicIconInfo(napi_env env, napi_callback_info info) return promise; } -static ErrCode InnerGetAbilityInfos(const std::string &uri, - uint32_t flags, std::vector &abilityInfos) -{ - auto iBundleMgr = CommonFunc::GetBundleMgr(); - if (iBundleMgr == nullptr) { - APP_LOGE("iBundleMgr is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = iBundleMgr->GetAbilityInfos(uri, flags, abilityInfos); - APP_LOGD("GetAbilityInfos ErrCode : %{public}d", ret); - return CommonFunc::ConvertErrCode(ret); -} - void GetAbilityInfosExec(napi_env env, void *data) { GetAbilityCallbackInfo *asyncCallbackInfo = reinterpret_cast(data); @@ -5927,8 +5484,8 @@ void GetAbilityInfosExec(napi_env env, void *data) return; } } - asyncCallbackInfo->err = InnerGetAbilityInfos(asyncCallbackInfo->uri, asyncCallbackInfo->flags, - asyncCallbackInfo->abilityInfos); + asyncCallbackInfo->err = BundleManagerHelper::InnerGetAbilityInfos( + asyncCallbackInfo->uri, asyncCallbackInfo->flags, asyncCallbackInfo->abilityInfos); } void GetAbilityInfosComplete(napi_env env, napi_status status, void *data) diff --git a/interfaces/kits/js/bundle_manager/bundle_manager_helper.cpp b/interfaces/kits/js/bundle_manager/bundle_manager_helper.cpp index eef818995fdab74442112359b70d0cc19bfce4f1..5fde1aa69dfcdf4d2ede0ec35295b354a91864e7 100644 --- a/interfaces/kits/js/bundle_manager/bundle_manager_helper.cpp +++ b/interfaces/kits/js/bundle_manager/bundle_manager_helper.cpp @@ -16,11 +16,14 @@ #include "bundle_manager_helper.h" #include "app_log_wrapper.h" +#include "bundle_mgr_client.h" #include "bundle_mgr_interface.h" #include "bundle_mgr_proxy.h" #include "bundle_errors.h" #include "business_error.h" #include "common_func.h" +#include "ipc_skeleton.h" +#include "verify_manager_client.h" namespace OHOS { namespace AppExecFwk { @@ -100,17 +103,22 @@ ErrCode BundleManagerHelper::InnerSetApplicationEnabled(const std::string& bundl return CommonFunc::ConvertErrCode(ret); } -ErrCode BundleManagerHelper::InnerEnableDynamicIcon(const std::string& bundleName, const std::string& moduleName) +ErrCode BundleManagerHelper::InnerEnableDynamicIcon( + const std::string& bundleName, const std::string& moduleName, int32_t appIndex, int32_t userId, bool isDefault) { auto extResourceManager = CommonFunc::GetExtendResourceManager(); if (extResourceManager == nullptr) { APP_LOGE("extResourceManager is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; } - - ErrCode ret = extResourceManager->EnableDynamicIcon(bundleName, moduleName); + ErrCode ret = ERR_OK; + if (isDefault) { + ret = extResourceManager->EnableDynamicIcon(bundleName, moduleName); + } else { + ret = extResourceManager->EnableDynamicIcon(bundleName, moduleName, userId, appIndex); + } if (ret != ERR_OK) { - APP_LOGE("EnableDynamicIcon failed"); + APP_LOGE("EnableDynamicIcon failed %{public}d", ret); } return CommonFunc::ConvertErrCode(ret); @@ -127,5 +135,394 @@ ErrCode BundleManagerHelper::InnerGetAppCloneIdentity(int32_t uid, std::string& APP_LOGD("GetNameAndIndexForUid ErrCode : %{public}d", ret); return CommonFunc::ConvertErrCode(ret); } + +ErrCode BundleManagerHelper::InnerGetBundleArchiveInfo(std::string& hapFilePath, int32_t flags, BundleInfo& bundleInfo) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("iBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetBundleArchiveInfoV9(hapFilePath, flags, bundleInfo); + APP_LOGD("GetBundleArchiveInfoV9 ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::GetAbilityFromBundleInfo(const BundleInfo& bundleInfo, const std::string& abilityName, + const std::string& moduleName, AbilityInfo& targetAbilityInfo) +{ + bool ifExists = false; + for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) { + for (const auto& abilityInfo : hapModuleInfo.abilityInfos) { + if (abilityInfo.name == abilityName && abilityInfo.moduleName == moduleName) { + if (!abilityInfo.enabled) { + APP_LOGI("ability disabled"); + return ERR_BUNDLE_MANAGER_ABILITY_DISABLED; + } + ifExists = true; + targetAbilityInfo = abilityInfo; + break; + } + } + if (ifExists) { + break; + } + } + if (!ifExists) { + APP_LOGE("ability not exist"); + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; + } + return ERR_OK; +} + +ErrCode BundleManagerHelper::GetExtensionFromBundleInfo(const BundleInfo& bundleInfo, const std::string& abilityName, + const std::string& moduleName, ExtensionAbilityInfo& targetExtensionInfo) +{ + bool ifExists = false; + for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) { + for (const auto& extensionInfo : hapModuleInfo.extensionInfos) { + if (extensionInfo.name == abilityName && extensionInfo.moduleName == moduleName) { + ifExists = true; + targetExtensionInfo = extensionInfo; + break; + } + if (!extensionInfo.enabled) { + APP_LOGI("extension disabled"); + return ERR_BUNDLE_MANAGER_ABILITY_DISABLED; + } + } + if (ifExists) { + break; + } + } + if (!ifExists) { + APP_LOGE("ability not exist"); + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; + } + return ERR_OK; +} + +ErrCode BundleManagerHelper::CommonInnerGetProfile(const std::string& moduleName, const std::string& abilityName, + const std::string& metadataName, bool isExtensionProfile, std::vector& profileVec) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("can not get iBundleMgr"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + + if (abilityName.empty()) { + APP_LOGE("InnerGetProfile failed due to empty abilityName"); + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; + } + + if (moduleName.empty()) { + APP_LOGE("InnerGetProfile failed due to empty moduleName"); + return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST; + } + auto baseFlag = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA) + + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE); + ErrCode result; + BundleMgrClient client; + BundleInfo bundleInfo; + if (!isExtensionProfile) { + auto getAbilityFlag = baseFlag + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY); + result = iBundleMgr->GetBundleInfoForSelf(getAbilityFlag, bundleInfo); + if (result != ERR_OK) { + APP_LOGE("GetBundleInfoForSelf failed"); + return result; + } + AbilityInfo targetAbilityInfo; + result = GetAbilityFromBundleInfo(bundleInfo, abilityName, moduleName, targetAbilityInfo); + if (result != ERR_OK) { + return result; + } + if (!client.GetProfileFromAbility(targetAbilityInfo, metadataName, profileVec)) { + APP_LOGE("GetProfileFromExtension failed"); + return ERR_BUNDLE_MANAGER_PROFILE_NOT_EXIST; + } + return ERR_OK; + } else { + auto getExtensionFlag = + baseFlag + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY); + result = iBundleMgr->GetBundleInfoForSelf(getExtensionFlag, bundleInfo); + if (result != ERR_OK) { + APP_LOGE("GetBundleInfoForSelf failed"); + return result; + } + + ExtensionAbilityInfo targetExtensionInfo; + result = GetExtensionFromBundleInfo(bundleInfo, abilityName, moduleName, targetExtensionInfo); + if (result != ERR_OK) { + return result; + } + if (!client.GetProfileFromExtension(targetExtensionInfo, metadataName, profileVec)) { + APP_LOGE("GetProfileFromExtension failed"); + return ERR_BUNDLE_MANAGER_PROFILE_NOT_EXIST; + } + return ERR_OK; + } + + APP_LOGE("InnerGetProfile failed due to type is invalid"); + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; +} + +ErrCode BundleManagerHelper::InnerGetPermissionDef(const std::string& permissionName, PermissionDef& permissionDef) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("can not get iBundleMgr"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetPermissionDef(permissionName, permissionDef); + APP_LOGD("GetPermissionDef ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerCleanBundleCacheCallback( + const std::string &bundleName, int32_t appIndex, const OHOS::sptr cleanCacheCallback) +{ + if (cleanCacheCallback == nullptr) { + APP_LOGE("callback nullptr"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("can not get iBundleMgr"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + int32_t userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE; + ErrCode result = iBundleMgr->CleanBundleCacheFiles(bundleName, cleanCacheCallback, userId, appIndex); + if (result != ERR_OK) { + APP_LOGE("call error, bundleName is %{public}s, userId is %{public}d, appIndex is %{public}d", + bundleName.c_str(), userId, appIndex); + } + return CommonFunc::ConvertErrCode(result); +} + +ErrCode BundleManagerHelper::InnerGetAppProvisionInfo( + const std::string& bundleName, int32_t userId, AppProvisionInfo& appProvisionInfo) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("iBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetAppProvisionInfo(bundleName, userId, appProvisionInfo); + APP_LOGD("GetAppProvisionInfo ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetAllPreinstalledApplicationInfos( + std::vector& preinstalledApplicationInfos) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("IBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetAllPreinstalledApplicationInfos(preinstalledApplicationInfos); + APP_LOGD("GetAllPreinstalledApplicationInfos ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetAllAppCloneBundleInfo( + const std::string& bundleName, int32_t bundleFlags, int32_t userId, std::vector& bundleInfos) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("can not get iBundleMgr"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + BundleInfo bundleInfoMain; + ErrCode ret = iBundleMgr->GetCloneBundleInfo(bundleName, bundleFlags, 0, bundleInfoMain, userId); + APP_LOGD("GetMainBundleInfo appIndex = 0, ret=%{public}d", ret); + if (ret == ERR_OK) { + bundleInfos.emplace_back(bundleInfoMain); + } + if (ret != ERR_OK && ret != ERR_BUNDLE_MANAGER_APPLICATION_DISABLED && ret != ERR_BUNDLE_MANAGER_BUNDLE_DISABLED) { + return CommonFunc::ConvertErrCode(ret); + } + // handle clone apps + std::vector appIndexes; + ErrCode getCloneIndexesRet = iBundleMgr->GetCloneAppIndexes(bundleName, appIndexes, userId); + if (getCloneIndexesRet != ERR_OK) { + if (ret == ERR_OK) { + return SUCCESS; + } + return CommonFunc::ConvertErrCode(ret); + } + for (int32_t appIndex : appIndexes) { + BundleInfo bundleInfo; + ret = iBundleMgr->GetCloneBundleInfo(bundleName, bundleFlags, appIndex, bundleInfo, userId); + if (ret == ERR_OK) { + bundleInfos.emplace_back(bundleInfo); + } + } + if (bundleInfos.empty()) { + return ERROR_BUNDLE_IS_DISABLED; + } + return SUCCESS; +} + +ErrCode BundleManagerHelper::InnerGetAllSharedBundleInfo(std::vector& sharedBundles) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("iBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetAllSharedBundleInfo(sharedBundles); + APP_LOGD("GetAllSharedBundleInfo ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetSharedBundleInfo( + const std::string& bundleName, const std::string& moduleName, std::vector& sharedBundles) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("iBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetSharedBundleInfo(bundleName, moduleName, sharedBundles); + APP_LOGD("GetSharedBundleInfo ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetExtResource(const std::string& bundleName, std::vector& moduleNames) +{ + auto extResourceManager = CommonFunc::GetExtendResourceManager(); + if (extResourceManager == nullptr) { + APP_LOGE("extResourceManager is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + + ErrCode ret = extResourceManager->GetExtResource(bundleName, moduleNames); + if (ret != ERR_OK) { + APP_LOGE("GetExtResource failed"); + } + APP_LOGD("GetExtResource ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerDisableDynamicIcon( + const std::string& bundleName, int32_t appIndex, int32_t userId, bool isDefault) +{ + auto extResourceManager = CommonFunc::GetExtendResourceManager(); + if (extResourceManager == nullptr) { + APP_LOGE("extResourceManager is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + + ErrCode ret = ERR_OK; + if (isDefault) { + ret = extResourceManager->DisableDynamicIcon(bundleName); + } else { + ret = extResourceManager->DisableDynamicIcon(bundleName, userId, appIndex); + } + if (ret != ERR_OK) { + APP_LOGE("DisableDynamicIcon failed %{public}d", ret); + } + + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetDynamicIconInfo( + const std::string& bundleName, std::vector& dynamicIconInfos) +{ + auto extResourceManager = CommonFunc::GetExtendResourceManager(); + if (extResourceManager == nullptr) { + APP_LOGE("extResourceManager is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = extResourceManager->GetDynamicIconInfo(bundleName, dynamicIconInfos); + if (ret != ERR_OK) { + APP_LOGE_NOFUNC("-n %{public}s GetDynamicIcon failed %{public}d", bundleName.c_str(), ret); + } + + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetAllDynamicIconInfo( + const int32_t userId, std::vector& dynamicIconInfos) +{ + auto extResourceManager = CommonFunc::GetExtendResourceManager(); + if (extResourceManager == nullptr) { + APP_LOGE("extResourceManager is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = extResourceManager->GetAllDynamicIconInfo(userId, dynamicIconInfos); + if (ret != ERR_OK) { + APP_LOGE_NOFUNC("GetDynamicIcon failed %{public}d", ret); + } + + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerVerify(const std::vector& abcPaths, bool flag) +{ + ErrCode ret = VerifyManagerClient::GetInstance().Verify(abcPaths); + if (ret == ERR_OK && flag) { + VerifyManagerClient::GetInstance().RemoveFiles(abcPaths); + } + if (ret != ERR_OK) { + APP_LOGE("VerifyAbc %{public}d", ret); + } + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerDeleteAbc(const std::string& path) +{ + ErrCode ret = VerifyManagerClient::GetInstance().DeleteAbc(path); + if (ret == ERR_APPEXECFWK_NULL_PTR) { + APP_LOGE("VerifyAbc failed due to iBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + if (ret != ERR_OK) { + APP_LOGE("DeleteAbc %{public}d", ret); + } + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetRecoverableApplicationInfo( + std::vector& recoverableApplications) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("iBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetRecoverableApplicationInfo(recoverableApplications); + APP_LOGD("GetRecoverableApplicationInfo ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetAllPluginInfo( + std::string& hostBundleName, int32_t userId, std::vector& pluginBundleInfos) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("iBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetAllPluginInfo(hostBundleName, userId, pluginBundleInfos); + APP_LOGD("GetAllPluginInfo ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} + +ErrCode BundleManagerHelper::InnerGetAbilityInfos( + const std::string& uri, uint32_t flags, std::vector& abilityInfos) +{ + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("iBundleMgr is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = iBundleMgr->GetAbilityInfos(uri, flags, abilityInfos); + APP_LOGD("GetAbilityInfos ErrCode : %{public}d", ret); + return CommonFunc::ConvertErrCode(ret); +} } // AppExecFwk } // OHOS \ No newline at end of file diff --git a/interfaces/kits/js/bundle_manager/bundle_manager_helper.h b/interfaces/kits/js/bundle_manager/bundle_manager_helper.h index db070857e453dfb10b651006fab5a16e90e2a491..d8aff70f2e42ff4a6f871485704fae3377b8c831 100644 --- a/interfaces/kits/js/bundle_manager/bundle_manager_helper.h +++ b/interfaces/kits/js/bundle_manager/bundle_manager_helper.h @@ -19,6 +19,7 @@ #include "bundle_errors.h" #include "bundle_mgr_interface.h" #include "bundle_mgr_proxy.h" +#include "clean_cache_callback.h" #include "common_func.h" namespace OHOS { @@ -31,8 +32,40 @@ public: static ErrCode InnerIsAbilityEnabled(const AbilityInfo& abilityInfo, bool& isEnable, int32_t appIndex); static ErrCode InnerSetAbilityEnabled(const AbilityInfo& abilityInfo, bool& isEnable, int32_t appIndex); static ErrCode InnerSetApplicationEnabled(const std::string& bundleName, bool& isEnable, int32_t appIndex); - static ErrCode InnerEnableDynamicIcon(const std::string& bundleName, const std::string& moduleName); + static ErrCode InnerEnableDynamicIcon( + const std::string& bundleName, const std::string& moduleName, int32_t appIndex, int32_t userId, bool isDefault); static ErrCode InnerGetAppCloneIdentity(int32_t uid, std::string& bundleName, int32_t& appIndex); + static ErrCode InnerGetBundleArchiveInfo(std::string& hapFilePath, int32_t flags, BundleInfo& bundleInfo); + static ErrCode GetAbilityFromBundleInfo(const BundleInfo& bundleInfo, const std::string& abilityName, + const std::string& moduleName, AbilityInfo& targetAbilityInfo); + static ErrCode GetExtensionFromBundleInfo(const BundleInfo& bundleInfo, const std::string& abilityName, + const std::string& moduleName, ExtensionAbilityInfo& targetExtensionInfo); + static ErrCode CommonInnerGetProfile(const std::string& moduleName, const std::string& abilityName, + const std::string& metadataName, bool isExtensionProfile, std::vector& profileVec); + static ErrCode InnerGetPermissionDef(const std::string& permissionName, PermissionDef& permissionDef); + static ErrCode InnerCleanBundleCacheCallback( + const std::string &bundleName, int32_t appIndex, const OHOS::sptr cleanCacheCallback); + static ErrCode InnerGetAppProvisionInfo( + const std::string& bundleName, int32_t userId, AppProvisionInfo& appProvisionInfo); + static ErrCode InnerGetAllPreinstalledApplicationInfos( + std::vector& preinstalledApplicationInfos); + static ErrCode InnerGetAllAppCloneBundleInfo( + const std::string& bundleName, int32_t bundleFlags, int32_t userId, std::vector& bundleInfos); + static ErrCode InnerGetAllSharedBundleInfo(std::vector& sharedBundles); + static ErrCode InnerGetSharedBundleInfo( + const std::string& bundleName, const std::string& moduleName, std::vector& sharedBundles); + static ErrCode InnerGetExtResource(const std::string& bundleName, std::vector& moduleNames); + static ErrCode InnerDisableDynamicIcon( + const std::string& bundleName, int32_t appIndex, int32_t userId, bool isDefault); + static ErrCode InnerGetDynamicIconInfo( + const std::string& bundleName, std::vector& dynamicIconInfos); + static ErrCode InnerGetAllDynamicIconInfo(const int32_t userId, std::vector& dynamicIconInfos); + static ErrCode InnerVerify(const std::vector& abcPaths, bool flag); + static ErrCode InnerDeleteAbc(const std::string& path); + static ErrCode InnerGetRecoverableApplicationInfo(std::vector& recoverableApplications); + static ErrCode InnerGetAllPluginInfo( + std::string& hostBundleName, int32_t userId, std::vector& pluginBundleInfos); + static ErrCode InnerGetAbilityInfos(const std::string& uri, uint32_t flags, std::vector& abilityInfos); }; } // AppExecFwk } // OHOS diff --git a/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp b/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp index 0edd5a1606bc6d56e300515ebec1c04c9b7cd3ee..517af18469d6f3abd4582103aa84cf91e3feefb4 100644 --- a/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp +++ b/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp @@ -32,21 +32,7 @@ namespace OHOS { namespace AppExecFwk { constexpr const char* IS_ENABLE = "isEnable"; -constexpr const char* HAP_FILE_PATH = "hapFilePath"; -constexpr const char* SANDBOX_DATA_DIR = "sandboxDataDir"; constexpr const char* EXTENSIONABILITY_TYPE = "extensionAbilityType"; -const char* GET_BUNDLE_ARCHIVE_INFO_SYNC = "GetBundleArchiveInfoSync"; -const char* GET_PROFILE_BY_EXTENSION_ABILITY_SYNC = "GetProfileByExtensionAbilitySync"; -const char* GET_PROFILE_BY_ABILITY_SYNC = "GetProfileByAbilitySync"; -const char* GET_PERMISSION_DEF_SYNC = "GetPermissionDefSync"; -const char* GET_APP_PROVISION_INFO_SYNC = "GetAppProvisionInfoSync"; -const char* GET_SIGNATURE_INFO_SYNC = "GetSignatureInfoSync"; -const char* GET_SANDBOX_DATA_DIR_SYNC = "GetSandboxDataDirSync"; -const char* GET_SIGNATURE_INFO_PERMISSIONS = "ohos.permission.GET_SIGNATURE_INFO"; -const char* PERMISSION_NAME = "permissionName"; -const std::string ATOMIC_SERVICE_DIR_PREFIX = "+auid-"; -const std::string CLONE_APP_DIR_PREFIX = "+clone-"; -const std::string PLUS = "+"; bool ParseWantWithParameter(napi_env env, napi_value args, Want &want) { napi_valuetype valueType; @@ -1041,46 +1027,6 @@ napi_value GetSandboxDataDirSync(napi_env env, napi_callback_info info) return nSandboxDataDir; } -void GetBundleNameAndIndexBySandboxDataDir( - const std::string &keyName, std::string &bundleName, int32_t &appIndex) -{ - bundleName = keyName; - appIndex = 0; - bool isApp = true; - // for clone bundle name - auto pos = keyName.find(CLONE_APP_DIR_PREFIX); - if (pos == std::string::npos || pos != 0) { - //for atomic service - pos = keyName.find(ATOMIC_SERVICE_DIR_PREFIX); - if (pos == std::string::npos || pos != 0) { - return; - } - isApp = false; - } - - size_t indexBegin = 0; - if (isApp) { - indexBegin = pos + CLONE_APP_DIR_PREFIX.size(); - } else { - indexBegin = pos + ATOMIC_SERVICE_DIR_PREFIX.size(); - } - - auto plus = keyName.find(PLUS, indexBegin); - if ((plus == std::string::npos) || (plus <= indexBegin)) { - return; - } - - if (isApp) { - std::string index = keyName.substr(indexBegin, plus - indexBegin); - if (!OHOS::StrToInt(index, appIndex)) { - appIndex = 0; - return; - } - } - - bundleName = keyName.substr(plus + PLUS.size()); -} - napi_value GetAppCloneIdentityBySandboxDataDirSync(napi_env env, napi_callback_info info) { APP_LOGD("NAPI GetAppCloneIdentityBySandboxDataDirSync called"); @@ -1097,7 +1043,7 @@ napi_value GetAppCloneIdentityBySandboxDataDirSync(napi_env env, napi_callback_i } std::string bundleName; int32_t appIndex; - GetBundleNameAndIndexBySandboxDataDir(sandboxDataDir, bundleName, appIndex); + CommonFunc::GetBundleNameAndIndexBySandboxDataDir(sandboxDataDir, bundleName, appIndex); napi_value nAppCloneIdentity = nullptr; NAPI_CALL(env, napi_create_object(env, &nAppCloneIdentity)); diff --git a/interfaces/kits/js/bundle_resource/bundle_resource.cpp b/interfaces/kits/js/bundle_resource/bundle_resource.cpp index 1e050529e2da2e1534a631989f71dd8f3b0a1cb3..8082edce7d18043f985184b7ca177e5631dd1e8d 100644 --- a/interfaces/kits/js/bundle_resource/bundle_resource.cpp +++ b/interfaces/kits/js/bundle_resource/bundle_resource.cpp @@ -37,7 +37,6 @@ namespace { constexpr const char* LABEL = "label"; constexpr const char* ICON = "icon"; constexpr const char* DRAWABLE_DESCRIPTOR = "drawableDescriptor"; -constexpr const char* GET_EXTENSION_ABILITY_RESOURCE_INFO = "GetExtensionAbilityResourceInfo"; constexpr const char* GET_RESOURCE_INFO_ALL = "GET_RESOURCE_INFO_ALL"; constexpr const char* GET_RESOURCE_INFO_WITH_LABEL = "GET_RESOURCE_INFO_WITH_LABEL"; constexpr const char* GET_RESOURCE_INFO_WITH_ICON = "GET_RESOURCE_INFO_WITH_ICON"; @@ -440,24 +439,6 @@ void CreateBundleResourceFlagObject(napi_env env, napi_value value) GET_RESOURCE_INFO_ONLY_WITH_MAIN_ABILITY, nGetMainAbility)); } -static ErrCode InnerGetExtensionAbilityResourceInfo( - const std::string &bundleName, ExtensionAbilityType extensionAbilityType, uint32_t flags, int32_t appIndex, - std::vector &extensionAbilityResourceInfos) -{ - APP_LOGD("InnerGetExtensionAbilityResourceInfo start"); - auto bundleResourceProxy = ResourceHelper::GetBundleResourceMgr(); - if (bundleResourceProxy == nullptr) { - APP_LOGE("bundleResourceProxy is null"); - return ERROR_BUNDLE_SERVICE_EXCEPTION; - } - ErrCode ret = bundleResourceProxy->GetExtensionAbilityResourceInfo(bundleName, extensionAbilityType, - flags, extensionAbilityResourceInfos, appIndex); - if (ret != ERR_OK) { - APP_LOGE("failed, bundleName is %{public}s, errCode: %{public}d", bundleName.c_str(), ret); - } - return CommonFunc::ConvertErrCode(ret); -} - napi_value GetExtensionAbilityResourceInfo(napi_env env, napi_callback_info info) { APP_LOGD("GetExtensionAbilityResourceInfo start"); @@ -502,7 +483,7 @@ napi_value GetExtensionAbilityResourceInfo(napi_env env, napi_callback_info info } } std::vector entensionAbilityResourceInfos; - auto ret = InnerGetExtensionAbilityResourceInfo(bundleName, + auto ret = ResourceHelper::InnerGetExtensionAbilityResourceInfo(bundleName, static_cast(extensionAbilityType), flags, appIndex, entensionAbilityResourceInfos); if (ret != ERR_OK) { napi_value businessError = BusinessError::CreateCommonError( diff --git a/interfaces/kits/js/bundle_resource/resource_helper.cpp b/interfaces/kits/js/bundle_resource/resource_helper.cpp index 4b3936fdc16ffe488ccc0357ed72c6154455480b..69bf6246ea38a1bf3c5489a6e9f353451775cb1d 100644 --- a/interfaces/kits/js/bundle_resource/resource_helper.cpp +++ b/interfaces/kits/js/bundle_resource/resource_helper.cpp @@ -123,5 +123,23 @@ ErrCode ResourceHelper::InnerGetAllLauncherAbilityResourceInfo(uint32_t flags, } return CommonFunc::ConvertErrCode(ret); } + +ErrCode ResourceHelper::InnerGetExtensionAbilityResourceInfo(const std::string& bundleName, + ExtensionAbilityType extensionAbilityType, uint32_t flags, int32_t appIndex, + std::vector& extensionAbilityResourceInfos) +{ + APP_LOGD("InnerGetExtensionAbilityResourceInfo start"); + auto bundleResourceProxy = ResourceHelper::GetBundleResourceMgr(); + if (bundleResourceProxy == nullptr) { + APP_LOGE("bundleResourceProxy is null"); + return ERROR_BUNDLE_SERVICE_EXCEPTION; + } + ErrCode ret = bundleResourceProxy->GetExtensionAbilityResourceInfo( + bundleName, extensionAbilityType, flags, extensionAbilityResourceInfos, appIndex); + if (ret != ERR_OK) { + APP_LOGE("failed, bundleName is %{public}s, errCode: %{public}d", bundleName.c_str(), ret); + } + return CommonFunc::ConvertErrCode(ret); +} } // AppExecFwk } // OHOS \ No newline at end of file diff --git a/interfaces/kits/js/bundle_resource/resource_helper.h b/interfaces/kits/js/bundle_resource/resource_helper.h index 80db457c62ed833842e958244424863376797f02..b18752b29c02a130c6354bca4d4ed40c02060062 100644 --- a/interfaces/kits/js/bundle_resource/resource_helper.h +++ b/interfaces/kits/js/bundle_resource/resource_helper.h @@ -33,6 +33,9 @@ public: static ErrCode InnerGetAllBundleResourceInfo(uint32_t flags, std::vector &bundleResourceInfos); static ErrCode InnerGetAllLauncherAbilityResourceInfo(uint32_t flags, std::vector &launcherAbilityResourceInfos); + static ErrCode InnerGetExtensionAbilityResourceInfo(const std::string& bundleName, + ExtensionAbilityType extensionAbilityType, uint32_t flags, int32_t appIndex, + std::vector& extensionAbilityResourceInfos); private: class BundleResourceMgrDeathRecipient : public IRemoteObject::DeathRecipient { diff --git a/interfaces/kits/js/bundlemgr/bundle_mgr.cpp b/interfaces/kits/js/bundlemgr/bundle_mgr.cpp index 002f72e84a00861bb2a14752ab0cb2023ba59356..fa55ca85bbe8ee61a71e38292cf5f76910abdf29 100644 --- a/interfaces/kits/js/bundlemgr/bundle_mgr.cpp +++ b/interfaces/kits/js/bundlemgr/bundle_mgr.cpp @@ -101,11 +101,9 @@ enum class InstallErrorCode : uint8_t { const char* IS_SET_APPLICATION_ENABLED = "IsSetApplicationEnabled"; const char* IS_ABILITY_ENABLED = "IsAbilityEnabled"; -const char* GET_BUNDLE_ARCHIVE_INFO = "GetBundleArchiveInfo"; const char* GET_ABILITY_ICON = "GetAbilityIcon"; constexpr const char* NAPI_GET_APPLICATION_INFO = "GetApplicationInfo"; const char* GET_ALL_BUNDLE_INFO = "GetAllBundleInfo"; -const char* GET_PERMISSION_DEF = "GetPermissionDef"; const char* QUERY_ABILITY_BY_WANT = "queryAbilityByWant"; const char* TYPE_MISMATCH = "type misMatch"; diff --git a/interfaces/kits/js/common/common_func.cpp b/interfaces/kits/js/common/common_func.cpp index d96992478cc1ac0abc29670f492cca78ca401ca5..388356a7b836228db3875ac5746a20b74db1c5ac 100644 --- a/interfaces/kits/js/common/common_func.cpp +++ b/interfaces/kits/js/common/common_func.cpp @@ -74,6 +74,9 @@ constexpr const char* CODE_PATH = "codePath"; const std::string PATH_PREFIX = "/data/app/el1/bundle/public"; const std::string CODE_PATH_PREFIX = "/data/storage/el1/bundle/"; const std::string CONTEXT_DATA_STORAGE_BUNDLE("/data/storage/el1/bundle/"); +const std::string ATOMIC_SERVICE_DIR_PREFIX = "+auid-"; +const std::string CLONE_APP_DIR_PREFIX = "+clone-"; +const std::string PLUS = "+"; constexpr const char* SYSTEM_APP = "systemApp"; constexpr const char* BUNDLE_TYPE = "bundleType"; constexpr const char* CODE_PATHS = "codePaths"; @@ -2776,6 +2779,46 @@ std::string CommonFunc::GetCloneBundleIdKey(const std::string& bundleName, const return std::to_string(appIndex) + CLONE_BUNDLE_PREFIX + bundleName; } +void CommonFunc::GetBundleNameAndIndexBySandboxDataDir( + const std::string& keyName, std::string& bundleName, int32_t& appIndex) +{ + bundleName = keyName; + appIndex = 0; + bool isApp = true; + // for clone bundle name + auto pos = keyName.find(CLONE_APP_DIR_PREFIX); + if (pos == std::string::npos || pos != 0) { + // for atomic service + pos = keyName.find(ATOMIC_SERVICE_DIR_PREFIX); + if (pos == std::string::npos || pos != 0) { + return; + } + isApp = false; + } + + size_t indexBegin = 0; + if (isApp) { + indexBegin = pos + CLONE_APP_DIR_PREFIX.size(); + } else { + indexBegin = pos + ATOMIC_SERVICE_DIR_PREFIX.size(); + } + + auto plus = keyName.find(PLUS, indexBegin); + if ((plus == std::string::npos) || (plus <= indexBegin)) { + return; + } + + if (isApp) { + std::string index = keyName.substr(indexBegin, plus - indexBegin); + if (!OHOS::StrToInt(index, appIndex)) { + appIndex = 0; + return; + } + } + + bundleName = keyName.substr(plus + PLUS.size()); +} + OHOS::sptr CommonFunc::GetOverlayMgrProxy() { auto bundleMgr = GetBundleMgr(); @@ -2790,5 +2833,35 @@ OHOS::sptr CommonFunc::GetOverlayMgrProxy() } return overlayMgrProxy; } + +OHOS::sptr CommonFunc::GetAppControlProxy() +{ + auto bundleMgr = GetBundleMgr(); + if (bundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + return nullptr; + } + auto appControlProxy = bundleMgr->GetAppControlProxy(); + if (appControlProxy == nullptr) { + APP_LOGE("GetAppControlProxy failed"); + return nullptr; + } + return appControlProxy; +} + +OHOS::sptr CommonFunc::GetDefaultAppProxy() +{ + auto bundleMgr = GetBundleMgr(); + if (bundleMgr == nullptr) { + APP_LOGE("GetBundleMgr failed"); + return nullptr; + } + auto defaultAppProxy = bundleMgr->GetDefaultAppProxy(); + if (defaultAppProxy == nullptr) { + APP_LOGE("GetDefaultAppProxy failed"); + return nullptr; + } + return defaultAppProxy; +} } // AppExecFwk } // OHOS diff --git a/interfaces/kits/js/common/common_func.h b/interfaces/kits/js/common/common_func.h index 3ae658ddefef4a5d433baec095e4dba01bfd9c7b..a1f067f341f1a923e55ed01a0ab0cd5e4b619519 100644 --- a/interfaces/kits/js/common/common_func.h +++ b/interfaces/kits/js/common/common_func.h @@ -204,8 +204,15 @@ static void GetBundleNameAndIndexByName(const std::string& keyName, std::string& static std::string GetCloneBundleIdKey(const std::string& bundleName, const int32_t appIndex); +static void GetBundleNameAndIndexBySandboxDataDir( + const std::string& keyName, std::string& bundleName, int32_t& appIndex); + static OHOS::sptr GetOverlayMgrProxy(); +static OHOS::sptr GetAppControlProxy(); + +static OHOS::sptr GetDefaultAppProxy(); + class BundleMgrCommonDeathRecipient : public IRemoteObject::DeathRecipient { void OnRemoteDied([[maybe_unused]] const wptr& remote) override; }; diff --git a/interfaces/kits/js/common/napi_constants.h b/interfaces/kits/js/common/napi_constants.h index 46268f79f54e2c3348d6d9b5bdfc0232066a5cb3..9fe7101bbab7beae109f9b5182af85ba3e7d6cbf 100644 --- a/interfaces/kits/js/common/napi_constants.h +++ b/interfaces/kits/js/common/napi_constants.h @@ -34,8 +34,19 @@ constexpr size_t ARGS_POS_FOUR = 4; constexpr size_t NAPI_RETURN_ONE = 1; constexpr size_t CALLBACK_PARAM_SIZE = 2; +constexpr int32_t GET_REMOTE_ABILITY_INFO_MAX_SIZE = 10; + constexpr int32_t SPECIFIED_DISTRIBUTION_TYPE_MAX_SIZE = 128; constexpr int32_t ADDITIONAL_INFO_MAX_SIZE = 3000; +constexpr uint32_t EXPLICIT_QUERY_RESULT_LEN = 1; + +constexpr int32_t ENUM_ONE = 1; +constexpr int32_t ENUM_TWO = 2; +constexpr int32_t ENUM_THREE = 3; +constexpr int32_t ENUM_FOUR = 4; +constexpr int32_t ENUM_FIVE = 5; +constexpr int32_t ENUM_SIX = 6; +constexpr int32_t ENUM_SEVEN = 7; constexpr const char* TYPE_NUMBER = "number"; constexpr const char* TYPE_STRING = "string"; @@ -70,7 +81,7 @@ constexpr const char* ABILITY_INFO = "abilityInfo"; constexpr const char* LINK_FEATURE = "linkFeature"; constexpr const char* EXTENSION_TYPE_NAME = "extensionTypeName"; constexpr const char* EXTENSION_ABILITY_TYPE = "extensionAbilityType"; -constexpr const char* PARAM_EXTENSION_ABILITY_TYPE_EMPTY_ERROR = +constexpr const char* PARAM_EXTENSION_ABILITY_TYPE_EMPTY_ERROR = "BusinessError 401: Parameter error.Parameter extensionAbilityType is empty."; constexpr const char* INVALID_WANT_ERROR = "implicit query condition, at least one query param(action, entities, uri, type, or linkFeature) non-empty."; @@ -99,17 +110,78 @@ constexpr const char* GET_BUNDLE_NAME_BY_UID_SYNC = "GetBundleNameByUidSync"; constexpr const char* QUERY_EXTENSION_INFOS = "QueryExtensionInfos"; constexpr const char* SET_ABILITY_ENABLED = "SetAbilityEnabled"; constexpr const char* SET_APPLICATION_ENABLED = "SetApplicationEnabled"; +constexpr const char* HAP_FILE_PATH = "hapFilePath"; +constexpr const char* PERMISSION_NAME = "permissionName"; +constexpr const char* PROFILE_TYPE = "profileType"; +constexpr const char* ADDITIONAL_INFO = "additionalInfo"; +constexpr const char* DEVELOPER_ID = "developerId"; +constexpr const char* APP_DISTRIBUTION_TYPE = "appDistributionType"; +constexpr const char* APP_DISTRIBUTION_TYPE_ENUM = "AppDistributionType"; +constexpr const char* HOST_BUNDLE_NAME = "hostBundleName"; +constexpr const char* SOURCE_PATHS = "sourcePaths"; +constexpr const char* DESTINATION_PATH = "destinationPath"; +constexpr const char* LINK = "link"; +constexpr const char* URI = "uri"; +constexpr const char* SANDBOX_DATA_DIR = "sandboxDataDir"; +constexpr const char* ERR_MSG_LAUNCH_WANT_INVALID = "The launch want is not found."; +constexpr const char* PARAM_BUNDLENAME_EMPTY_ERROR = + "BusinessError 401: Parameter error. parameter bundleName is empty"; +constexpr const char* GET_SIGNATURE_INFO_PERMISSIONS = "ohos.permission.GET_SIGNATURE_INFO"; +constexpr const char* PARAM_DEVELOPER_ID_EMPTY_ERROR = + "BusinessError 401: Parameter error. parameter developerId is empty"; +constexpr const char* BUNDLE_ENABLE_AND_DISABLE_ALL_DYNAMIC_PERMISSIONS = + "ohos.permission.ACCESS_DYNAMIC_ICON and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; +constexpr const char* BUNDLE_GET_ALL_DYNAMIC_PERMISSIONS = + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; +constexpr const char* GET_ABILITYINFO_PERMISSIONS = "ohos.permission.GET_ABILITY_INFO"; +constexpr const char* GET_BUNDLE_ARCHIVE_INFO = "GetBundleArchiveInfo"; +constexpr const char* GET_PERMISSION_DEF = "GetPermissionDef"; +constexpr const char* CLEAN_BUNDLE_CACHE_FILES = "cleanBundleCacheFiles"; +constexpr const char* GET_ALL_BUNDLE_CACHE_SIZE = "getAllBundleCacheSize"; +constexpr const char* CLEAN_ALL_BUNDLE_CACHE = "cleanAllBundleCache"; +constexpr const char* GET_APP_PROVISION_INFO = "GetAppProvisionInfo"; +constexpr const char* CAN_OPEN_LINK = "CanOpenLink"; +constexpr const char* GET_ALL_PREINSTALLED_APP_INFOS = "GetAllPreinstalledApplicationInfos"; +constexpr const char* GET_ALL_BUNDLE_INFO_BY_DEVELOPER_ID = "GetAllBundleInfoByDeveloperId"; +constexpr const char* SWITCH_UNINSTALL_STATE = "SwitchUninstallState"; +constexpr const char* GET_SIGNATURE_INFO_SYNC = "GetSignatureInfo"; +constexpr const char* GET_ALL_APP_CLONE_BUNDLE_INFO = "GetAllAppCloneBundleInfo"; +constexpr const char* GET_BUNDLE_ARCHIVE_INFO_SYNC = "GetBundleArchiveInfoSync"; +constexpr const char* GET_PROFILE_BY_EXTENSION_ABILITY_SYNC = "GetProfileByExtensionAbilitySync"; +constexpr const char* GET_PROFILE_BY_ABILITY_SYNC = "GetProfileByAbilitySync"; +constexpr const char* GET_PERMISSION_DEF_SYNC = "GetPermissionDefSync"; +constexpr const char* GET_APP_PROVISION_INFO_SYNC = "GetAppProvisionInfoSync"; +constexpr const char* GET_ALL_SHARED_BUNDLE_INFO = "GetAllSharedBundleInfo"; +constexpr const char* GET_SHARED_BUNDLE_INFO = "GetSharedBundleInfo"; +constexpr const char* GET_JSON_PROFILE = "GetJsonProfile"; +constexpr const char* RESOURCE_NAME_OF_GET_ADDITIONAL_INFO = "GetAdditionalInfo"; +constexpr const char* GET_EXT_RESOURCE = "GetExtResource"; +constexpr const char* DISABLE_DYNAMIC_ICON = "DisableDynamicIcon"; +constexpr const char* VERIFY_ABC = "VerifyAbc"; +constexpr const char* DELETE_ABC = "DeleteAbc"; +constexpr const char* GET_RECOVERABLE_APPLICATION_INFO = "GetRecoverableApplicationInfo"; +constexpr const char* RESOURCE_NAME_OF_SET_ADDITIONAL_INFO = "SetAdditionalInfo"; +constexpr const char* GET_DEVELOPER_IDS = "GetDeveloperIds"; +constexpr const char* GET_ALL_PLUGIN_INFO = "GetAllPluginInfo"; +constexpr const char* MIGRATE_DATA = "MigrateData"; +constexpr const char* GET_ALL_DYNAMIC_ICON = "GetAllDynamicIconInfo"; +constexpr const char* GET_SANDBOX_DATA_DIR_SYNC = "GetSandboxDataDirSync"; +constexpr const char* GET_ABILITY_INFOS = "GetAbilityInfos"; +constexpr const char* GET_DYNAMIC_ICON_INFO = "GetDynamicIconInfo"; -//launcher_bundle_manager +// launcher_bundle_manager constexpr const char* GET_SHORTCUT_INFO = "GetShortcutInfo"; constexpr const char* GET_SHORTCUT_INFO_SYNC = "GetShortcutInfoSync"; constexpr const char* GET_SHORTCUT_INFO_BY_APPINDEX = "GetShortcutInfoByAppIndex"; constexpr const char* ERROR_EMPTY_WANT = "want in ShortcutInfo cannot be empty"; -constexpr const char* PARSE_START_OPTIONS = "parse StartOptions failed"; +constexpr const char* PARSE_SHORTCUT_INFO_FAILED = "parse ShortcutInfo failed"; +constexpr const char* PARSE_START_OPTIONS_FAILED = "parse StartOptions failed"; constexpr const char* START_SHORTCUT = "StartShortcut"; constexpr const char* GET_LAUNCHER_ABILITY_INFO = "GetLauncherAbilityInfo"; constexpr const char* GET_LAUNCHER_ABILITY_INFO_SYNC = "GetLauncherAbilityInfoSync"; constexpr const char* GET_ALL_LAUNCHER_ABILITY_INFO = "GetAllLauncherAbilityInfo"; +constexpr const char* PARSE_REASON_MESSAGE = "parse ReasonMessage failed"; +constexpr const char* START_SHORTCUT_WITH_REASON = "StartShortcutWithReason"; // resource_manager constexpr const char* PERMISSION_GET_BUNDLE_RESOURCES = "ohos.permission.GET_BUNDLE_RESOURCES"; @@ -120,11 +192,17 @@ constexpr const char* PERMISSION_GET_ALL_BUNDLE_RESOURCES = constexpr const char* GET_LAUNCHER_ABILITY_RESOURCE_INFO = "GetLauncherAbilityResourceInfo"; constexpr const char* GET_ALL_BUNDLE_RESOURCE_INFO = "GetAllBundleResourceInfo"; constexpr const char* GET_ALL_LAUNCHER_ABILITY_RESOURCE_INFO = "GetAllLauncherAbilityResourceInfo"; +constexpr const char* GET_EXTENSION_ABILITY_RESOURCE_INFO = "GetExtensionAbilityResourceInfo"; -//shortcut_manager +// shortcut_manager constexpr const char* ADD_DESKTOP_SHORTCUT_INFO = "AddDesktopShortcutInfo"; constexpr const char* DELETE_DESKTOP_SHORTCUT_INFO = "DeleteDesktopShortcutInfo"; constexpr const char* GET_ALL_DESKTOP_SHORTCUT_INFO = "GetAllDesktopShortcutInfo"; +constexpr const char* SET_SHORTCUT_VISIBLE = "SetShortcutVisibleForSelf"; +constexpr const char* GET_ALL_SHORTCUT_INFO_FOR_SELF = "GetAllShortcutInfoForSelf"; +constexpr const char* SHORTCUT_ID = "shortcutId"; +constexpr const char* INVALID_SHORTCUT_INFO_ERROR = + "invalid ShortcutInfo: parameter type error, or appIndex is less than 0"; // free_install constexpr const char* RESOURCE_NAME_OF_IS_HAP_MODULE_REMOVABLE = "isHapModuleRemovable"; @@ -177,6 +255,55 @@ constexpr const char* INSTALL_PREEXISTING_APP = "installPreexistingApp"; constexpr const char* INSTALL_PLUGIN = "InstallPlugin"; constexpr const char* UNINSTALL_PLUGIN = "UninstallPlugin"; constexpr const char* PLUGIN_BUNDLE_NAME = "pluginBundleName"; + +// app_control +constexpr const char* TYPE_WANT = "want"; +constexpr const char* PERMISSION_DISPOSED_STATUS = "ohos.permission.MANAGE_DISPOSED_APP_STATUS"; +constexpr const char* SET_DISPOSED_STATUS = "SetDisposedStatus"; +constexpr const char* GET_DISPOSED_STATUS = "GetDisposedStatus"; +constexpr const char* DELETE_DISPOSED_STATUS = "DeleteDisposedStatus"; +constexpr const char* SET_DISPOSED_STATUS_SYNC = "SetDisposedStatusSync"; +constexpr const char* DELETE_DISPOSED_STATUS_SYNC = "DeleteDisposedStatusSync"; +constexpr const char* GET_DISPOSED_STATUS_SYNC = "GetDisposedStatusSync"; +constexpr const char* APP_ID = "appId"; +constexpr const char* APP_IDENTIFIER = "appIdentifier"; +constexpr const char* DISPOSED_WANT = "disposedWant"; +constexpr const char* DISPOSED_RULE = "disposedRule"; +constexpr const char* DISPOSED_RULE_TYPE = "DisposedRule"; +constexpr const char* UNINSTALL_DISPOSED_RULE = "uninstallDisposedRule"; +constexpr const char* UNINSTALL_DISPOSED_RULE_TYPE = "UninstallDisposedRule"; +constexpr const char* SET_UNINSTALL_DISPOSED_RULE = "SetUninstallDisposedRule"; +constexpr const char* DELETE_UNINSTALL_DISPOSED_RULE = "DeleteUninstallDisposedRule"; +constexpr const char* GET_UNINSTALL_DISPOSED_RULE = "GetUninstallDisposedRule"; +constexpr const char* SET_DISPOSED_RULES = "SetDisposedRules"; + +// default_app_manager +const std::unordered_map TYPE_MAPPING = { + {"Web Browser", "BROWSER"}, + {"Image Gallery", "IMAGE"}, + {"Audio Player", "AUDIO"}, + {"Video Player", "VIDEO"}, + {"PDF Viewer", "PDF"}, + {"Word Viewer", "WORD"}, + {"Excel Viewer", "EXCEL"}, + {"PPT Viewer", "PPT"}, + {"Email", "EMAIL"} +}; +constexpr const char* IS_DEFAULT_APPLICATION = "IsDefaultApplication"; +constexpr const char* IS_DEFAULT_APPLICATION_SYNC = "IsDefaultApplicationSync"; +constexpr const char* GET_DEFAULT_APPLICATION = "GetDefaultApplication"; +constexpr const char* GET_DEFAULT_APPLICATION_SYNC = "GetDefaultApplicationSync"; +constexpr const char* SET_DEFAULT_APPLICATION = "SetDefaultApplication"; +constexpr const char* SET_DEFAULT_APPLICATION_SYNC = "SetDefaultApplicationSync"; +constexpr const char* RESET_DEFAULT_APPLICATION = "ResetDefaultApplication"; +constexpr const char* RESET_DEFAULT_APPLICATION_SYNC = "ResetDefaultApplicationSync"; +constexpr const char* TYPE_CHECK = "type"; +constexpr const char* WANT_CHECK = "want"; + +// distributed_bundle_manager +constexpr const char* RESOURCE_NAME_GET_REMOTE_ABILITY_INFO = "GetRemoteAbilityInfo"; +constexpr const char* PARAMETER_ELEMENT_NAME = "elementName"; +constexpr const char* PARAMETER_LOCALE = "locale"; } } } diff --git a/interfaces/kits/js/default_app/js_default_app.cpp b/interfaces/kits/js/default_app/js_default_app.cpp index 6b3bad90f2954a7f94109377f09fae596ce072d1..2f4f50667fb63dcaf64ec831b332424260ab1029 100644 --- a/interfaces/kits/js/default_app/js_default_app.cpp +++ b/interfaces/kits/js/default_app/js_default_app.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -36,31 +36,9 @@ using namespace OHOS::AAFwk; namespace { constexpr int32_t NAPI_RETURN_ZERO = 0; -const char* IS_DEFAULT_APPLICATION = "IsDefaultApplication"; -const char* IS_DEFAULT_APPLICATION_SYNC = "IsDefaultApplicationSync"; -const char* GET_DEFAULT_APPLICATION = "GetDefaultApplication"; -const char* GET_DEFAULT_APPLICATION_SYNC = "GetDefaultApplicationSync"; -const char* SET_DEFAULT_APPLICATION = "SetDefaultApplication"; -const char* SET_DEFAULT_APPLICATION_SYNC = "SetDefaultApplicationSync"; -const char* RESET_DEFAULT_APPLICATION = "ResetDefaultApplication"; -const char* RESET_DEFAULT_APPLICATION_SYNC = "ResetDefaultApplicationSync"; const char* PARAM_TYPE_CHECK_ERROR_WITH_POS = "param type check error, error position : "; -const char* TYPE_CHECK = "type"; -const char* WANT_CHECK = "want"; } -static const std::unordered_map TYPE_MAPPING = { - {"Web Browser", "BROWSER"}, - {"Image Gallery", "IMAGE"}, - {"Audio Player", "AUDIO"}, - {"Video Player", "VIDEO"}, - {"PDF Viewer", "PDF"}, - {"Word Viewer", "WORD"}, - {"Excel Viewer", "EXCEL"}, - {"PPT Viewer", "PPT"}, - {"Email", "EMAIL"} -}; - static bool ParseType(napi_env env, napi_value value, std::string& result) { napi_valuetype valueType = napi_undefined; @@ -86,31 +64,6 @@ static bool ParseType(napi_env env, napi_value value, std::string& result) return true; } -static OHOS::sptr GetDefaultAppProxy() -{ - auto systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (systemAbilityManager == nullptr) { - APP_LOGE("systemAbilityManager is null"); - return nullptr; - } - auto bundleMgrSa = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (bundleMgrSa == nullptr) { - APP_LOGE("bundleMgrSa is null"); - return nullptr; - } - auto bundleMgr = OHOS::iface_cast(bundleMgrSa); - if (bundleMgr == nullptr) { - APP_LOGE("iface_cast failed"); - return nullptr; - } - auto defaultAppProxy = bundleMgr->GetDefaultAppProxy(); - if (defaultAppProxy == nullptr) { - APP_LOGE("GetDefaultAppProxy failed"); - return nullptr; - } - return defaultAppProxy; -} - static void ConvertAbilityInfo(napi_env env, napi_value objAbilityInfo, const AbilityInfo &abilityInfo) { APP_LOGD("begin to ConvertAbilityInfo"); @@ -233,7 +186,7 @@ static ErrCode InnerIsDefaultApplication(DefaultAppCallbackInfo *info) APP_LOGE("info is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; } - auto defaultAppProxy = GetDefaultAppProxy(); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); if (defaultAppProxy == nullptr) { APP_LOGE("defaultAppProxy is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; @@ -352,7 +305,7 @@ napi_value IsDefaultApplicationSync(napi_env env, napi_callback_info info) return nRet; } - auto defaultAppProxy = GetDefaultAppProxy(); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); if (defaultAppProxy == nullptr) { napi_value error = BusinessError::CreateCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, IS_DEFAULT_APPLICATION_SYNC); @@ -380,7 +333,7 @@ static ErrCode InnerGetDefaultApplication(DefaultAppCallbackInfo *info) APP_LOGE("info is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; } - auto defaultAppProxy = GetDefaultAppProxy(); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); if (defaultAppProxy == nullptr) { APP_LOGE("defaultAppProxy is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; @@ -511,7 +464,7 @@ napi_value GetDefaultApplicationSync(napi_env env, napi_callback_info info) return nullptr; } - auto defaultAppProxy = GetDefaultAppProxy(); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); if (defaultAppProxy == nullptr) { napi_value error = BusinessError::CreateCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, GET_DEFAULT_APPLICATION_SYNC); @@ -543,7 +496,7 @@ static ErrCode InnerSetDefaultApplication(const DefaultAppCallbackInfo *info) APP_LOGE("info is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; } - auto defaultAppProxy = GetDefaultAppProxy(); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); if (defaultAppProxy == nullptr) { APP_LOGE("defaultAppProxy is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; @@ -687,7 +640,7 @@ napi_value SetDefaultApplicationSync(napi_env env, napi_callback_info info) if (ParamsProcessSetDefaultApplicationSync(env, info, type, want, userId) != ERR_OK) { return nRet; } - auto defaultAppProxy = GetDefaultAppProxy(); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); if (defaultAppProxy == nullptr) { napi_value error = BusinessError::CreateCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, SET_DEFAULT_APPLICATION_SYNC); @@ -716,7 +669,7 @@ static ErrCode InnerResetDefaultApplication(const DefaultAppCallbackInfo *info) APP_LOGE("info is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; } - auto defaultAppProxy = GetDefaultAppProxy(); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); if (defaultAppProxy == nullptr) { APP_LOGE("defaultAppProxy is null"); return ERROR_BUNDLE_SERVICE_EXCEPTION; @@ -847,7 +800,7 @@ napi_value ResetDefaultApplicationSync(napi_env env, napi_callback_info info) return nRet; } - auto defaultAppProxy = GetDefaultAppProxy(); + auto defaultAppProxy = CommonFunc::GetDefaultAppProxy(); if (defaultAppProxy == nullptr) { napi_value error = BusinessError::CreateCommonError(env, ERROR_BUNDLE_SERVICE_EXCEPTION, RESET_DEFAULT_APPLICATION_SYNC); diff --git a/interfaces/kits/js/installer/installer.cpp b/interfaces/kits/js/installer/installer.cpp index a5163fd34739272a6fd49a7febabf7ad2b9e736d..e953cd074f8d64cfb6802841aad3e4f3d251cbc9 100644 --- a/interfaces/kits/js/installer/installer.cpp +++ b/interfaces/kits/js/installer/installer.cpp @@ -50,7 +50,6 @@ const char* HASH_PARAMS = "hashParams"; const char* VERSION_CODE = "versionCode"; const char* SHARED_BUNDLE_DIR_PATHS = "sharedBundleDirPaths"; const char* SPECIFIED_DISTRIBUTION_TYPE = "specifiedDistributionType"; -const char* ADDITIONAL_INFO = "additionalInfo"; const char* VERIFY_CODE_PARAM = "verifyCodeParams"; const char* SIGNATURE_FILE_PATH = "signatureFilePath"; const char* PGO_PARAM = "pgoParams"; diff --git a/interfaces/kits/js/launcher_bundle_manager/launcher_bundle_manager.cpp b/interfaces/kits/js/launcher_bundle_manager/launcher_bundle_manager.cpp index c569b63615ea090a6e2b75a9df10a4a380dee96d..c3d6d2b00f082344551049a523f9f43b4c762d79 100644 --- a/interfaces/kits/js/launcher_bundle_manager/launcher_bundle_manager.cpp +++ b/interfaces/kits/js/launcher_bundle_manager/launcher_bundle_manager.cpp @@ -32,9 +32,6 @@ namespace OHOS { namespace AppExecFwk { namespace { -constexpr const char* PARSE_SHORTCUT_INFO = "parse ShortcutInfo failed"; -constexpr const char* PARSE_REASON_MESSAGE = "parse ReasonMessage failed"; -constexpr const char* START_SHORTCUT_WITH_REASON = "StartShortcutWithReason"; const std::map START_SHORTCUT_RES_MAP = { {ERR_OK, ERR_OK}, @@ -525,7 +522,7 @@ napi_value StartShortcut(napi_env env, napi_callback_info info) NAPI_CALL(env, napi_typeof(env, args[i], &valueType)); if (i == ARGS_POS_ZERO) { if (!CommonFunc::ParseShortCutInfo(env, args[ARGS_POS_ZERO], asyncCallbackInfo->shortcutInfo)) { - BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_SHORTCUT_INFO); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_SHORTCUT_INFO_FAILED); return nullptr; } if (asyncCallbackInfo->shortcutInfo.intents.empty()) { @@ -535,7 +532,7 @@ napi_value StartShortcut(napi_env env, napi_callback_info info) } else if (i == ARGS_POS_ONE) { if ((valueType == napi_object) && (!AppExecFwk::UnwrapStartOptions(env, args[ARGS_POS_ONE], asyncCallbackInfo->startOptions))) { - BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_START_OPTIONS); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_START_OPTIONS_FAILED); return nullptr; } } else { @@ -633,7 +630,7 @@ napi_value StartShortcutWithReason(napi_env env, napi_callback_info info) NAPI_CALL(env, napi_typeof(env, args[i], &valueType)); if (i == ARGS_POS_ZERO) { if (!CommonFunc::ParseShortCutInfo(env, args[ARGS_POS_ZERO], asyncCallbackInfo->shortcutInfo)) { - BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_SHORTCUT_INFO); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_SHORTCUT_INFO_FAILED); return nullptr; } } else if (i == ARGS_POS_ONE) { @@ -644,7 +641,7 @@ napi_value StartShortcutWithReason(napi_env env, napi_callback_info info) } else if (i == ARGS_POS_TWO) { if ((valueType == napi_object) && (!AppExecFwk::UnwrapStartOptions(env, args[ARGS_POS_TWO], asyncCallbackInfo->startOptions))) { - BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_START_OPTIONS); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARSE_START_OPTIONS_FAILED); return nullptr; } } else { diff --git a/interfaces/kits/js/shortcut_manager/shortcut_manager.cpp b/interfaces/kits/js/shortcut_manager/shortcut_manager.cpp index c1eded829419e3cca758a1d538e76196e4e43a13..1a74eabdb80796752147fa550bbe9b744bb0659a 100644 --- a/interfaces/kits/js/shortcut_manager/shortcut_manager.cpp +++ b/interfaces/kits/js/shortcut_manager/shortcut_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -29,12 +29,6 @@ namespace OHOS { namespace AppExecFwk { -namespace { -constexpr const char* INVALID_SHORTCUT_INFO_ERROR = - "invalid ShortcutInfo: parameter type error, or appIndex is less than 0"; -constexpr const char* SET_SHORTCUT_VISIBLE = "SetShortcutVisibleForSelf"; -constexpr const char* GET_ALL_SHORTCUT_INFO_FOR_SELF = "GetAllShortcutInfoForSelf"; -} static ErrCode InnerAddDesktopShortcutInfo(const OHOS::AppExecFwk::ShortcutInfo &shortcutInfo, int32_t userId) { auto iBundleMgr = CommonFunc::GetBundleMgr();