1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#include "app_utils.h" 17eace7efcSopenharmony_ci#include "json_utils.h" 18eace7efcSopenharmony_ci#include "hilog_tag_wrapper.h" 19eace7efcSopenharmony_ci#include "nlohmann/json.hpp" 20eace7efcSopenharmony_ci#include "parameters.h" 21eace7efcSopenharmony_ci#ifdef SUPPORT_GRAPHICS 22eace7efcSopenharmony_ci#include "scene_board_judgement.h" 23eace7efcSopenharmony_ci#endif // SUPPORT_GRAPHICS 24eace7efcSopenharmony_ci 25eace7efcSopenharmony_ci 26eace7efcSopenharmony_cinamespace OHOS { 27eace7efcSopenharmony_cinamespace AAFwk { 28eace7efcSopenharmony_cinamespace { 29eace7efcSopenharmony_ciconstexpr const char* BUNDLE_NAME_LAUNCHER = "com.ohos.launcher"; 30eace7efcSopenharmony_ciconstexpr const char* BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; 31eace7efcSopenharmony_ciconstexpr const char* LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility"; 32eace7efcSopenharmony_ciconstexpr const char* SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility"; 33eace7efcSopenharmony_ciconstexpr const char* INHERIT_WINDOW_SPLIT_SCREEN_MODE = "persist.sys.abilityms.inherit_window_split_screen_mode"; 34eace7efcSopenharmony_ciconstexpr const char* SUPPORT_ANCO_APP = "persist.sys.abilityms.support_anco_app"; 35eace7efcSopenharmony_ciconstexpr const char* TIMEOUT_UNIT_TIME_RATIO = "persist.sys.abilityms.timeout_unit_time_ratio"; 36eace7efcSopenharmony_ciconstexpr const char* SELECTOR_DIALOG_POSSION = "persist.sys.abilityms.selector_dialog_possion"; 37eace7efcSopenharmony_ciconstexpr const char* START_SPECIFIED_PROCESS = "persist.sys.abilityms.start_specified_process"; 38eace7efcSopenharmony_ciconstexpr const char* USE_MULTI_RENDER_PROCESS = "persist.sys.abilityms.use_multi_render_process"; 39eace7efcSopenharmony_ciconstexpr const char* LIMIT_MAXIMUM_OF_RENDER_PROCESS = "persist.sys.abilityms.limit_maximum_of_render_process"; 40eace7efcSopenharmony_ciconstexpr const char* GRANT_PERSIST_URI_PERMISSION = "persist.sys.abilityms.grant_persist_uri_permission"; 41eace7efcSopenharmony_ciconstexpr const char* START_OPTIONS_WITH_ANIMATION = "persist.sys.abilityms.start_options_with_animation"; 42eace7efcSopenharmony_ciconstexpr const char* MULTI_PROCESS_MODEL = "persist.sys.abilityms.multi_process_model"; 43eace7efcSopenharmony_ciconstexpr const char* START_OPTIONS_WITH_PROCESS_OPTION = "persist.sys.abilityms.start_options_with_process_option"; 44eace7efcSopenharmony_ciconstexpr const char* MOVE_UI_ABILITY_TO_BACKGROUND_API_ENABLE = 45eace7efcSopenharmony_ci "persist.sys.abilityms.move_ui_ability_to_background_api_enable"; 46eace7efcSopenharmony_ciconstexpr const char* CONFIG_PATH = "/etc/ability_runtime/resident_process_in_extreme_memory.json"; 47eace7efcSopenharmony_ciconstexpr const char* RESIDENT_PROCESS_IN_EXTREME_MEMORY = "residentProcessInExtremeMemory"; 48eace7efcSopenharmony_ciconstexpr const char* BUNDLE_NAME = "bundleName"; 49eace7efcSopenharmony_ciconstexpr const char* ABILITY_NAME = "abilityName"; 50eace7efcSopenharmony_ciconstexpr const char* KEY_IDENTIFIER = "identifier"; 51eace7efcSopenharmony_ciconstexpr const char* ALLOW_NATIVE_CHILD_PROCESS_APPS_CONFIG_PATH = 52eace7efcSopenharmony_ci "/etc/ability_runtime/allow_native_child_process_apps.json"; 53eace7efcSopenharmony_ciconstexpr const char* KEY_ALLOW_NATIVE_CHILD_PROCESS_APPS = "allowNativeChildProcessApps"; 54eace7efcSopenharmony_ciconstexpr const char* LAUNCH_EMBEDED_UI_ABILITY = "const.abilityms.launch_embeded_ui_ability"; 55eace7efcSopenharmony_ciconst std::string SUPPROT_NATIVE_CHILD_PROCESS = "persist.sys.abilityms.start_native_child_process"; 56eace7efcSopenharmony_ciconst std::string LIMIT_MAXIMUM_EXTENSIONS_OF_PER_PROCESS = 57eace7efcSopenharmony_ci "const.sys.abilityms.limit_maximum_extensions_of_per_process"; 58eace7efcSopenharmony_ciconst std::string LIMIT_MAXIMUM_EXTENSIONS_OF_PER_DEVICE = 59eace7efcSopenharmony_ci "const.sys.abilityms.limit_maximum_extensions_of_per_device"; 60eace7efcSopenharmony_ciconst std::string CACHE_EXTENSION_TYPES = "const.sys.abilityms.cache_extension"; 61eace7efcSopenharmony_ciconstexpr const char* START_ABILITY_WITHOUT_CALLERTOKEN = "/system/etc/start_ability_without_caller_token.json"; 62eace7efcSopenharmony_ciconstexpr const char* START_ABILITY_WITHOUT_CALLERTOKEN_PATH = 63eace7efcSopenharmony_ci "/etc/ability_runtime/start_ability_without_caller_token.json"; 64eace7efcSopenharmony_ciconstexpr const char* START_ABILITY_WITHOUT_CALLERTOKEN_TITLE = "startAbilityWithoutCallerToken"; 65eace7efcSopenharmony_ciconstexpr const char* BROKER_DELEGATE_BUNDLE_NAME = "const.sys.abilityms.broker_delegate_bundle_name"; 66eace7efcSopenharmony_ciconstexpr const char* COLLABORATOR_BROKER_UID = "const.sys.abilityms.collaborator_broker_uid"; 67eace7efcSopenharmony_ciconstexpr const char* COLLABORATOR_BROKER_RESERVE_UID = "const.sys.abilityms.collaborator_broker_reserve_uid"; 68eace7efcSopenharmony_ciconstexpr const char* MAX_CHILD_PROCESS = "const.max_native_child_process"; 69eace7efcSopenharmony_ciconstexpr const char* SUPPORT_MULTI_INSTANCE = "const.abilityms.support_multi_instance"; 70eace7efcSopenharmony_ciconstexpr const char* MIGRATE_CLIENT_BUNDLE_NAME = "const.sys.abilityms.migrate_client_bundle_name"; 71eace7efcSopenharmony_ci} 72eace7efcSopenharmony_ci 73eace7efcSopenharmony_ciAppUtils::~AppUtils() {} 74eace7efcSopenharmony_ci 75eace7efcSopenharmony_ciAppUtils::AppUtils() 76eace7efcSopenharmony_ci{ 77eace7efcSopenharmony_ci #ifdef SUPPORT_GRAPHICS 78eace7efcSopenharmony_ci if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { 79eace7efcSopenharmony_ci isSceneBoard_ = true; 80eace7efcSopenharmony_ci } 81eace7efcSopenharmony_ci #endif // SUPPORT_GRAPHICS 82eace7efcSopenharmony_ci} 83eace7efcSopenharmony_ci 84eace7efcSopenharmony_ciAppUtils &AppUtils::GetInstance() 85eace7efcSopenharmony_ci{ 86eace7efcSopenharmony_ci static AppUtils utils; 87eace7efcSopenharmony_ci return utils; 88eace7efcSopenharmony_ci} 89eace7efcSopenharmony_ci 90eace7efcSopenharmony_cibool AppUtils::IsLauncher(const std::string &bundleName) const 91eace7efcSopenharmony_ci{ 92eace7efcSopenharmony_ci if (isSceneBoard_) { 93eace7efcSopenharmony_ci return bundleName == BUNDLE_NAME_SCENEBOARD; 94eace7efcSopenharmony_ci } 95eace7efcSopenharmony_ci 96eace7efcSopenharmony_ci return bundleName == BUNDLE_NAME_LAUNCHER; 97eace7efcSopenharmony_ci} 98eace7efcSopenharmony_ci 99eace7efcSopenharmony_cibool AppUtils::IsLauncherAbility(const std::string &abilityName) const 100eace7efcSopenharmony_ci{ 101eace7efcSopenharmony_ci if (isSceneBoard_) { 102eace7efcSopenharmony_ci return abilityName == SCENEBOARD_ABILITY_NAME; 103eace7efcSopenharmony_ci } 104eace7efcSopenharmony_ci 105eace7efcSopenharmony_ci return abilityName == LAUNCHER_ABILITY_NAME; 106eace7efcSopenharmony_ci} 107eace7efcSopenharmony_ci 108eace7efcSopenharmony_cibool AppUtils::IsInheritWindowSplitScreenMode() 109eace7efcSopenharmony_ci{ 110eace7efcSopenharmony_ci if (!isInheritWindowSplitScreenMode_.isLoaded) { 111eace7efcSopenharmony_ci isInheritWindowSplitScreenMode_.value = system::GetBoolParameter(INHERIT_WINDOW_SPLIT_SCREEN_MODE, true); 112eace7efcSopenharmony_ci isInheritWindowSplitScreenMode_.isLoaded = true; 113eace7efcSopenharmony_ci } 114eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isInheritWindowSplitScreenMode_.value); 115eace7efcSopenharmony_ci return isInheritWindowSplitScreenMode_.value; 116eace7efcSopenharmony_ci} 117eace7efcSopenharmony_ci 118eace7efcSopenharmony_cibool AppUtils::IsSupportAncoApp() 119eace7efcSopenharmony_ci{ 120eace7efcSopenharmony_ci if (!isSupportAncoApp_.isLoaded) { 121eace7efcSopenharmony_ci isSupportAncoApp_.value = system::GetBoolParameter(SUPPORT_ANCO_APP, false); 122eace7efcSopenharmony_ci isSupportAncoApp_.isLoaded = true; 123eace7efcSopenharmony_ci } 124eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSupportAncoApp_.value); 125eace7efcSopenharmony_ci return isSupportAncoApp_.value; 126eace7efcSopenharmony_ci} 127eace7efcSopenharmony_ci 128eace7efcSopenharmony_ciint32_t AppUtils::GetTimeoutUnitTimeRatio() 129eace7efcSopenharmony_ci{ 130eace7efcSopenharmony_ci if (!timeoutUnitTimeRatio_.isLoaded) { 131eace7efcSopenharmony_ci timeoutUnitTimeRatio_.value = system::GetIntParameter<int32_t>(TIMEOUT_UNIT_TIME_RATIO, 1); 132eace7efcSopenharmony_ci timeoutUnitTimeRatio_.isLoaded = true; 133eace7efcSopenharmony_ci } 134eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", timeoutUnitTimeRatio_.value); 135eace7efcSopenharmony_ci return timeoutUnitTimeRatio_.value; 136eace7efcSopenharmony_ci} 137eace7efcSopenharmony_ci 138eace7efcSopenharmony_cibool AppUtils::IsSelectorDialogDefaultPossion() 139eace7efcSopenharmony_ci{ 140eace7efcSopenharmony_ci if (!isSelectorDialogDefaultPossion_.isLoaded) { 141eace7efcSopenharmony_ci isSelectorDialogDefaultPossion_.value = system::GetBoolParameter(SELECTOR_DIALOG_POSSION, true); 142eace7efcSopenharmony_ci isSelectorDialogDefaultPossion_.isLoaded = true; 143eace7efcSopenharmony_ci } 144eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSelectorDialogDefaultPossion_.value); 145eace7efcSopenharmony_ci return isSelectorDialogDefaultPossion_.value; 146eace7efcSopenharmony_ci} 147eace7efcSopenharmony_ci 148eace7efcSopenharmony_cibool AppUtils::IsStartSpecifiedProcess() 149eace7efcSopenharmony_ci{ 150eace7efcSopenharmony_ci if (!isStartSpecifiedProcess_.isLoaded) { 151eace7efcSopenharmony_ci isStartSpecifiedProcess_.value = system::GetBoolParameter(START_SPECIFIED_PROCESS, false); 152eace7efcSopenharmony_ci isStartSpecifiedProcess_.isLoaded = true; 153eace7efcSopenharmony_ci } 154eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isStartSpecifiedProcess_.value); 155eace7efcSopenharmony_ci return isStartSpecifiedProcess_.value; 156eace7efcSopenharmony_ci} 157eace7efcSopenharmony_ci 158eace7efcSopenharmony_cibool AppUtils::IsUseMultiRenderProcess() 159eace7efcSopenharmony_ci{ 160eace7efcSopenharmony_ci if (!isUseMultiRenderProcess_.isLoaded) { 161eace7efcSopenharmony_ci isUseMultiRenderProcess_.value = system::GetBoolParameter(USE_MULTI_RENDER_PROCESS, true); 162eace7efcSopenharmony_ci isUseMultiRenderProcess_.isLoaded = true; 163eace7efcSopenharmony_ci } 164eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isUseMultiRenderProcess_.value); 165eace7efcSopenharmony_ci return isUseMultiRenderProcess_.value; 166eace7efcSopenharmony_ci} 167eace7efcSopenharmony_ci 168eace7efcSopenharmony_cibool AppUtils::IsLimitMaximumOfRenderProcess() 169eace7efcSopenharmony_ci{ 170eace7efcSopenharmony_ci if (!isLimitMaximumOfRenderProcess_.isLoaded) { 171eace7efcSopenharmony_ci isLimitMaximumOfRenderProcess_.value = system::GetBoolParameter(LIMIT_MAXIMUM_OF_RENDER_PROCESS, true); 172eace7efcSopenharmony_ci isLimitMaximumOfRenderProcess_.isLoaded = true; 173eace7efcSopenharmony_ci } 174eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isLimitMaximumOfRenderProcess_.value); 175eace7efcSopenharmony_ci return isLimitMaximumOfRenderProcess_.value; 176eace7efcSopenharmony_ci} 177eace7efcSopenharmony_ci 178eace7efcSopenharmony_cibool AppUtils::IsGrantPersistUriPermission() 179eace7efcSopenharmony_ci{ 180eace7efcSopenharmony_ci if (!isGrantPersistUriPermission_.isLoaded) { 181eace7efcSopenharmony_ci isGrantPersistUriPermission_.value = system::GetBoolParameter(GRANT_PERSIST_URI_PERMISSION, false); 182eace7efcSopenharmony_ci isGrantPersistUriPermission_.isLoaded = true; 183eace7efcSopenharmony_ci } 184eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isGrantPersistUriPermission_.value); 185eace7efcSopenharmony_ci return isGrantPersistUriPermission_.value; 186eace7efcSopenharmony_ci} 187eace7efcSopenharmony_ci 188eace7efcSopenharmony_cibool AppUtils::IsStartOptionsWithAnimation() 189eace7efcSopenharmony_ci{ 190eace7efcSopenharmony_ci if (!isStartOptionsWithAnimation_.isLoaded) { 191eace7efcSopenharmony_ci isStartOptionsWithAnimation_.value = system::GetBoolParameter(START_OPTIONS_WITH_ANIMATION, false); 192eace7efcSopenharmony_ci isStartOptionsWithAnimation_.isLoaded = true; 193eace7efcSopenharmony_ci } 194eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isStartOptionsWithAnimation_.value); 195eace7efcSopenharmony_ci return isStartOptionsWithAnimation_.value; 196eace7efcSopenharmony_ci} 197eace7efcSopenharmony_ci 198eace7efcSopenharmony_cibool AppUtils::IsMultiProcessModel() 199eace7efcSopenharmony_ci{ 200eace7efcSopenharmony_ci if (!isMultiProcessModel_.isLoaded) { 201eace7efcSopenharmony_ci isMultiProcessModel_.value = system::GetBoolParameter(MULTI_PROCESS_MODEL, false); 202eace7efcSopenharmony_ci isMultiProcessModel_.isLoaded = true; 203eace7efcSopenharmony_ci } 204eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isMultiProcessModel_.value); 205eace7efcSopenharmony_ci return isMultiProcessModel_.value; 206eace7efcSopenharmony_ci} 207eace7efcSopenharmony_ci 208eace7efcSopenharmony_cibool AppUtils::IsStartOptionsWithProcessOptions() 209eace7efcSopenharmony_ci{ 210eace7efcSopenharmony_ci if (!isStartOptionsWithProcessOptions_.isLoaded) { 211eace7efcSopenharmony_ci isStartOptionsWithProcessOptions_.value = system::GetBoolParameter(START_OPTIONS_WITH_PROCESS_OPTION, false); 212eace7efcSopenharmony_ci isStartOptionsWithProcessOptions_.isLoaded = true; 213eace7efcSopenharmony_ci } 214eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isStartOptionsWithProcessOptions_.value); 215eace7efcSopenharmony_ci return isStartOptionsWithProcessOptions_.value; 216eace7efcSopenharmony_ci} 217eace7efcSopenharmony_ci 218eace7efcSopenharmony_cibool AppUtils::EnableMoveUIAbilityToBackgroundApi() 219eace7efcSopenharmony_ci{ 220eace7efcSopenharmony_ci if (!enableMoveUIAbilityToBackgroundApi_.isLoaded) { 221eace7efcSopenharmony_ci enableMoveUIAbilityToBackgroundApi_.value = 222eace7efcSopenharmony_ci system::GetBoolParameter(MOVE_UI_ABILITY_TO_BACKGROUND_API_ENABLE, true); 223eace7efcSopenharmony_ci enableMoveUIAbilityToBackgroundApi_.isLoaded = true; 224eace7efcSopenharmony_ci } 225eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", enableMoveUIAbilityToBackgroundApi_.value); 226eace7efcSopenharmony_ci return enableMoveUIAbilityToBackgroundApi_.value; 227eace7efcSopenharmony_ci} 228eace7efcSopenharmony_ci 229eace7efcSopenharmony_cibool AppUtils::IsLaunchEmbededUIAbility() 230eace7efcSopenharmony_ci{ 231eace7efcSopenharmony_ci if (!isLaunchEmbededUIAbility_.isLoaded) { 232eace7efcSopenharmony_ci isLaunchEmbededUIAbility_.value = system::GetBoolParameter(LAUNCH_EMBEDED_UI_ABILITY, false); 233eace7efcSopenharmony_ci isLaunchEmbededUIAbility_.isLoaded = true; 234eace7efcSopenharmony_ci } 235eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isLaunchEmbededUIAbility_.value); 236eace7efcSopenharmony_ci return isLaunchEmbededUIAbility_.value; 237eace7efcSopenharmony_ci} 238eace7efcSopenharmony_ci 239eace7efcSopenharmony_cibool AppUtils::IsSupportNativeChildProcess() 240eace7efcSopenharmony_ci{ 241eace7efcSopenharmony_ci if (!isSupportNativeChildProcess_.isLoaded) { 242eace7efcSopenharmony_ci isSupportNativeChildProcess_.value = system::GetBoolParameter(SUPPROT_NATIVE_CHILD_PROCESS, false); 243eace7efcSopenharmony_ci isSupportNativeChildProcess_.isLoaded = true; 244eace7efcSopenharmony_ci } 245eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSupportNativeChildProcess_.value); 246eace7efcSopenharmony_ci return isSupportNativeChildProcess_.value; 247eace7efcSopenharmony_ci} 248eace7efcSopenharmony_ci 249eace7efcSopenharmony_cibool AppUtils::IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName) 250eace7efcSopenharmony_ci{ 251eace7efcSopenharmony_ci std::lock_guard lock(residentProcessInExtremeMemoryMutex_); 252eace7efcSopenharmony_ci if (!residentProcessInExtremeMemory_.isLoaded) { 253eace7efcSopenharmony_ci LoadResidentProcessInExtremeMemory(); 254eace7efcSopenharmony_ci residentProcessInExtremeMemory_.isLoaded = true; 255eace7efcSopenharmony_ci } 256eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSupportNativeChildProcess_.value); 257eace7efcSopenharmony_ci for (auto &element : residentProcessInExtremeMemory_.value) { 258eace7efcSopenharmony_ci if (bundleName == element.first && 259eace7efcSopenharmony_ci (abilityName == "" || abilityName == element.second)) { 260eace7efcSopenharmony_ci return true; 261eace7efcSopenharmony_ci } 262eace7efcSopenharmony_ci } 263eace7efcSopenharmony_ci return false; 264eace7efcSopenharmony_ci} 265eace7efcSopenharmony_ci 266eace7efcSopenharmony_civoid AppUtils::LoadResidentProcessInExtremeMemory() 267eace7efcSopenharmony_ci{ 268eace7efcSopenharmony_ci nlohmann::json object; 269eace7efcSopenharmony_ci if (!JsonUtils::GetInstance().LoadConfiguration(CONFIG_PATH, object)) { 270eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "resident process failed"); 271eace7efcSopenharmony_ci return; 272eace7efcSopenharmony_ci } 273eace7efcSopenharmony_ci if (!object.contains(RESIDENT_PROCESS_IN_EXTREME_MEMORY)) { 274eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "resident process invalid"); 275eace7efcSopenharmony_ci return; 276eace7efcSopenharmony_ci } 277eace7efcSopenharmony_ci 278eace7efcSopenharmony_ci for (auto &item : object.at(RESIDENT_PROCESS_IN_EXTREME_MEMORY).items()) { 279eace7efcSopenharmony_ci const nlohmann::json& jsonObject = item.value(); 280eace7efcSopenharmony_ci if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { 281eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "load bundleName failed"); 282eace7efcSopenharmony_ci return; 283eace7efcSopenharmony_ci } 284eace7efcSopenharmony_ci if (!jsonObject.contains(ABILITY_NAME) || !jsonObject.at(ABILITY_NAME).is_string()) { 285eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "load abilityName failed"); 286eace7efcSopenharmony_ci return; 287eace7efcSopenharmony_ci } 288eace7efcSopenharmony_ci std::string bundleName = jsonObject.at(BUNDLE_NAME).get<std::string>(); 289eace7efcSopenharmony_ci std::string abilityName = jsonObject.at(ABILITY_NAME).get<std::string>(); 290eace7efcSopenharmony_ci residentProcessInExtremeMemory_.value.emplace_back(std::make_pair(bundleName, abilityName)); 291eace7efcSopenharmony_ci } 292eace7efcSopenharmony_ci} 293eace7efcSopenharmony_ci 294eace7efcSopenharmony_cibool AppUtils::IsAllowNativeChildProcess(const std::string &appIdentifier) 295eace7efcSopenharmony_ci{ 296eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "appId:%{private}s", appIdentifier.c_str()); 297eace7efcSopenharmony_ci if (!allowStartNativeProcessApps_.isLoaded) { 298eace7efcSopenharmony_ci LoadAllowNativeChildProcessApps(); 299eace7efcSopenharmony_ci allowStartNativeProcessApps_.isLoaded = true; 300eace7efcSopenharmony_ci } 301eace7efcSopenharmony_ci auto &apps = allowStartNativeProcessApps_.value; 302eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}zu", apps.size()); 303eace7efcSopenharmony_ci return std::find(apps.begin(), apps.end(), appIdentifier) != apps.end(); 304eace7efcSopenharmony_ci} 305eace7efcSopenharmony_ci 306eace7efcSopenharmony_civoid AppUtils::LoadAllowNativeChildProcessApps() 307eace7efcSopenharmony_ci{ 308eace7efcSopenharmony_ci nlohmann::json object; 309eace7efcSopenharmony_ci if (!JsonUtils::GetInstance().LoadConfiguration(ALLOW_NATIVE_CHILD_PROCESS_APPS_CONFIG_PATH, object)) { 310eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "load child process config failed"); 311eace7efcSopenharmony_ci return; 312eace7efcSopenharmony_ci } 313eace7efcSopenharmony_ci if (!object.contains(KEY_ALLOW_NATIVE_CHILD_PROCESS_APPS)) { 314eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "get key invalid"); 315eace7efcSopenharmony_ci return; 316eace7efcSopenharmony_ci } 317eace7efcSopenharmony_ci 318eace7efcSopenharmony_ci for (auto &item : object.at(KEY_ALLOW_NATIVE_CHILD_PROCESS_APPS).items()) { 319eace7efcSopenharmony_ci const nlohmann::json& jsonObject = item.value(); 320eace7efcSopenharmony_ci if (!jsonObject.contains(KEY_IDENTIFIER) || !jsonObject.at(KEY_IDENTIFIER).is_string()) { 321eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "load identifier failed"); 322eace7efcSopenharmony_ci return; 323eace7efcSopenharmony_ci } 324eace7efcSopenharmony_ci std::string identifier = jsonObject.at(KEY_IDENTIFIER).get<std::string>(); 325eace7efcSopenharmony_ci allowStartNativeProcessApps_.value.emplace_back(identifier); 326eace7efcSopenharmony_ci } 327eace7efcSopenharmony_ci} 328eace7efcSopenharmony_ci 329eace7efcSopenharmony_ciint32_t AppUtils::GetLimitMaximumExtensionsPerProc() 330eace7efcSopenharmony_ci{ 331eace7efcSopenharmony_ci if (!limitMaximumExtensionsPerProc_.isLoaded) { 332eace7efcSopenharmony_ci limitMaximumExtensionsPerProc_.value = 333eace7efcSopenharmony_ci system::GetIntParameter<int32_t>(LIMIT_MAXIMUM_EXTENSIONS_OF_PER_PROCESS, DEFAULT_MAX_EXT_PER_PROC); 334eace7efcSopenharmony_ci limitMaximumExtensionsPerProc_.isLoaded = true; 335eace7efcSopenharmony_ci } 336eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "limitMaximumExtensionsPerProc: %{public}d", limitMaximumExtensionsPerProc_.value); 337eace7efcSopenharmony_ci return limitMaximumExtensionsPerProc_.value; 338eace7efcSopenharmony_ci} 339eace7efcSopenharmony_ci 340eace7efcSopenharmony_ciint32_t AppUtils::GetLimitMaximumExtensionsPerDevice() 341eace7efcSopenharmony_ci{ 342eace7efcSopenharmony_ci if (!limitMaximumExtensionsPerDevice_.isLoaded) { 343eace7efcSopenharmony_ci limitMaximumExtensionsPerDevice_.value = 344eace7efcSopenharmony_ci system::GetIntParameter<int32_t>(LIMIT_MAXIMUM_EXTENSIONS_OF_PER_DEVICE, DEFAULT_MAX_EXT_PER_DEV); 345eace7efcSopenharmony_ci limitMaximumExtensionsPerDevice_.isLoaded = true; 346eace7efcSopenharmony_ci } 347eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "limitMaximumExtensionsPerDevice: %{public}d", limitMaximumExtensionsPerDevice_.value); 348eace7efcSopenharmony_ci return limitMaximumExtensionsPerDevice_.value; 349eace7efcSopenharmony_ci} 350eace7efcSopenharmony_ci 351eace7efcSopenharmony_cistd::string AppUtils::GetCacheExtensionTypeList() 352eace7efcSopenharmony_ci{ 353eace7efcSopenharmony_ci std::string cacheExtAbilityTypeList = system::GetParameter(CACHE_EXTENSION_TYPES, "260"); 354eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "cacheExtAbilityTypeList is %{public}s", cacheExtAbilityTypeList.c_str()); 355eace7efcSopenharmony_ci return cacheExtAbilityTypeList; 356eace7efcSopenharmony_ci} 357eace7efcSopenharmony_ci 358eace7efcSopenharmony_cibool AppUtils::IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName) 359eace7efcSopenharmony_ci{ 360eace7efcSopenharmony_ci std::lock_guard lock(startAbilityWithoutCallerTokenMutex_); 361eace7efcSopenharmony_ci if (!startAbilityWithoutCallerToken_.isLoaded) { 362eace7efcSopenharmony_ci LoadStartAbilityWithoutCallerToken(); 363eace7efcSopenharmony_ci startAbilityWithoutCallerToken_.isLoaded = true; 364eace7efcSopenharmony_ci } 365eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "isLoaded: %{public}d", startAbilityWithoutCallerToken_.isLoaded); 366eace7efcSopenharmony_ci for (auto &element : startAbilityWithoutCallerToken_.value) { 367eace7efcSopenharmony_ci if (bundleName == element.first && abilityName == element.second) { 368eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::DEFAULT, "call"); 369eace7efcSopenharmony_ci return true; 370eace7efcSopenharmony_ci } 371eace7efcSopenharmony_ci } 372eace7efcSopenharmony_ci return false; 373eace7efcSopenharmony_ci} 374eace7efcSopenharmony_ci 375eace7efcSopenharmony_civoid AppUtils::LoadStartAbilityWithoutCallerToken() 376eace7efcSopenharmony_ci{ 377eace7efcSopenharmony_ci nlohmann::json object; 378eace7efcSopenharmony_ci if (!JsonUtils::GetInstance().LoadConfiguration( 379eace7efcSopenharmony_ci START_ABILITY_WITHOUT_CALLERTOKEN_PATH, object, START_ABILITY_WITHOUT_CALLERTOKEN)) { 380eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DEFAULT, "token list failed"); 381eace7efcSopenharmony_ci return; 382eace7efcSopenharmony_ci } 383eace7efcSopenharmony_ci if (!object.contains(START_ABILITY_WITHOUT_CALLERTOKEN_TITLE)) { 384eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DEFAULT, "token config invalid"); 385eace7efcSopenharmony_ci return; 386eace7efcSopenharmony_ci } 387eace7efcSopenharmony_ci 388eace7efcSopenharmony_ci for (auto &item : object.at(START_ABILITY_WITHOUT_CALLERTOKEN_TITLE).items()) { 389eace7efcSopenharmony_ci const nlohmann::json& jsonObject = item.value(); 390eace7efcSopenharmony_ci if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { 391eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DEFAULT, "load bundleName failed"); 392eace7efcSopenharmony_ci return; 393eace7efcSopenharmony_ci } 394eace7efcSopenharmony_ci if (!jsonObject.contains(ABILITY_NAME) || !jsonObject.at(ABILITY_NAME).is_string()) { 395eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::DEFAULT, "load abilityName failed"); 396eace7efcSopenharmony_ci return; 397eace7efcSopenharmony_ci } 398eace7efcSopenharmony_ci std::string bundleName = jsonObject.at(BUNDLE_NAME).get<std::string>(); 399eace7efcSopenharmony_ci std::string abilityName = jsonObject.at(ABILITY_NAME).get<std::string>(); 400eace7efcSopenharmony_ci startAbilityWithoutCallerToken_.value.emplace_back(std::make_pair(bundleName, abilityName)); 401eace7efcSopenharmony_ci } 402eace7efcSopenharmony_ci} 403eace7efcSopenharmony_ci 404eace7efcSopenharmony_cistd::string AppUtils::GetBrokerDelegateBundleName() 405eace7efcSopenharmony_ci{ 406eace7efcSopenharmony_ci if (!brokerDelegateBundleName_.isLoaded) { 407eace7efcSopenharmony_ci brokerDelegateBundleName_.value = system::GetParameter(BROKER_DELEGATE_BUNDLE_NAME, ""); 408eace7efcSopenharmony_ci brokerDelegateBundleName_.isLoaded = true; 409eace7efcSopenharmony_ci } 410eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "shellAssistantBundleName_ is %{public}s", brokerDelegateBundleName_.value.c_str()); 411eace7efcSopenharmony_ci return brokerDelegateBundleName_.value; 412eace7efcSopenharmony_ci} 413eace7efcSopenharmony_ci 414eace7efcSopenharmony_ciint32_t AppUtils::GetCollaboratorBrokerUID() 415eace7efcSopenharmony_ci{ 416eace7efcSopenharmony_ci if (!collaboratorBrokerUid_.isLoaded) { 417eace7efcSopenharmony_ci collaboratorBrokerUid_.value = system::GetIntParameter(COLLABORATOR_BROKER_UID, DEFAULT_INVALID_VALUE); 418eace7efcSopenharmony_ci collaboratorBrokerUid_.isLoaded = true; 419eace7efcSopenharmony_ci } 420eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "collaboratorBrokerUid_ is %{public}d", collaboratorBrokerUid_.value); 421eace7efcSopenharmony_ci return collaboratorBrokerUid_.value; 422eace7efcSopenharmony_ci} 423eace7efcSopenharmony_ci 424eace7efcSopenharmony_ciint32_t AppUtils::GetCollaboratorBrokerReserveUID() 425eace7efcSopenharmony_ci{ 426eace7efcSopenharmony_ci if (!collaboratorBrokerReserveUid_.isLoaded) { 427eace7efcSopenharmony_ci collaboratorBrokerReserveUid_.value = system::GetIntParameter(COLLABORATOR_BROKER_RESERVE_UID, 428eace7efcSopenharmony_ci DEFAULT_INVALID_VALUE); 429eace7efcSopenharmony_ci collaboratorBrokerReserveUid_.isLoaded = true; 430eace7efcSopenharmony_ci } 431eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "collaboratorBrokerReserveUid_ is %{public}d", collaboratorBrokerReserveUid_.value); 432eace7efcSopenharmony_ci return collaboratorBrokerReserveUid_.value; 433eace7efcSopenharmony_ci} 434eace7efcSopenharmony_ci 435eace7efcSopenharmony_ciint32_t AppUtils::MaxChildProcess() 436eace7efcSopenharmony_ci{ 437eace7efcSopenharmony_ci if (!maxChildProcess_.isLoaded) { 438eace7efcSopenharmony_ci maxChildProcess_.value = 439eace7efcSopenharmony_ci system::GetIntParameter<int32_t>(MAX_CHILD_PROCESS, DEFAULT_MAX_CHILD_PROCESS); 440eace7efcSopenharmony_ci maxChildProcess_.isLoaded = true; 441eace7efcSopenharmony_ci } 442eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "MaxChildProcess: %{public}d", maxChildProcess_.value); 443eace7efcSopenharmony_ci return maxChildProcess_.value; 444eace7efcSopenharmony_ci} 445eace7efcSopenharmony_ci 446eace7efcSopenharmony_cibool AppUtils::IsSupportMultiInstance() 447eace7efcSopenharmony_ci{ 448eace7efcSopenharmony_ci if (!isSupportMultiInstance_.isLoaded) { 449eace7efcSopenharmony_ci isSupportMultiInstance_.value = system::GetBoolParameter(SUPPORT_MULTI_INSTANCE, false); 450eace7efcSopenharmony_ci isSupportMultiInstance_.isLoaded = true; 451eace7efcSopenharmony_ci } 452eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSupportMultiInstance_.value); 453eace7efcSopenharmony_ci return isSupportMultiInstance_.value; 454eace7efcSopenharmony_ci} 455eace7efcSopenharmony_ci 456eace7efcSopenharmony_cistd::string AppUtils::GetMigrateClientBundleName() 457eace7efcSopenharmony_ci{ 458eace7efcSopenharmony_ci if (!migrateClientBundleName_.isLoaded) { 459eace7efcSopenharmony_ci migrateClientBundleName_.value = system::GetParameter(MIGRATE_CLIENT_BUNDLE_NAME, ""); 460eace7efcSopenharmony_ci migrateClientBundleName_.isLoaded = true; 461eace7efcSopenharmony_ci } 462eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::DEFAULT, "migrateClientBundleName_ is %{public}s", migrateClientBundleName_.value.c_str()); 463eace7efcSopenharmony_ci return migrateClientBundleName_.value; 464eace7efcSopenharmony_ci} 465eace7efcSopenharmony_ci} // namespace AAFwk 466eace7efcSopenharmony_ci} // namespace OHOS 467