1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2021-2024 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#ifndef OHOS_ABILITY_RUNTIME_ABILITY_UTIL_H 17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_ABILITY_UTIL_H 18eace7efcSopenharmony_ci 19eace7efcSopenharmony_ci#include <string> 20eace7efcSopenharmony_ci#include <unordered_set> 21eace7efcSopenharmony_ci 22eace7efcSopenharmony_ci#include "ability_config.h" 23eace7efcSopenharmony_ci#include "ability_manager_client.h" 24eace7efcSopenharmony_ci#include "ability_manager_errors.h" 25eace7efcSopenharmony_ci#include "app_jump_control_rule.h" 26eace7efcSopenharmony_ci#include "bundle_mgr_helper.h" 27eace7efcSopenharmony_ci#include "hilog_tag_wrapper.h" 28eace7efcSopenharmony_ci#include "in_process_call_wrapper.h" 29eace7efcSopenharmony_ci#include "ipc_skeleton.h" 30eace7efcSopenharmony_ci#include "permission_verification.h" 31eace7efcSopenharmony_ci#include "sa_mgr_client.h" 32eace7efcSopenharmony_ci#include "system_ability_definition.h" 33eace7efcSopenharmony_ci 34eace7efcSopenharmony_cinamespace OHOS { 35eace7efcSopenharmony_cinamespace AAFwk { 36eace7efcSopenharmony_cinamespace AbilityUtil { 37eace7efcSopenharmony_ciconstexpr const char* SYSTEM_BASIC = "system_basic"; 38eace7efcSopenharmony_ciconstexpr const char* SYSTEM_CORE = "system_core"; 39eace7efcSopenharmony_ciconstexpr const char* DEFAULT_DEVICE_ID = ""; 40eace7efcSopenharmony_ci 41eace7efcSopenharmony_ci#ifdef WITH_DLP 42eace7efcSopenharmony_ciconstexpr const char* DLP_BUNDLE_NAME = "com.ohos.dlpmanager"; 43eace7efcSopenharmony_ciconstexpr const char* DLP_MODULE_NAME = "entry"; 44eace7efcSopenharmony_ciconstexpr const char* DLP_ABILITY_NAME = "ViewAbility"; 45eace7efcSopenharmony_ciconstexpr const char* DLP_PARAMS_SANDBOX = "ohos.dlp.params.sandbox"; 46eace7efcSopenharmony_ciconstexpr const char* DLP_PARAMS_BUNDLE_NAME = "ohos.dlp.params.bundleName"; 47eace7efcSopenharmony_ciconstexpr const char* DLP_PARAMS_MODULE_NAME = "ohos.dlp.params.moduleName"; 48eace7efcSopenharmony_ciconstexpr const char* DLP_PARAMS_ABILITY_NAME = "ohos.dlp.params.abilityName"; 49eace7efcSopenharmony_ci#endif // WITH_DLP 50eace7efcSopenharmony_ciconstexpr const char* MARKET_BUNDLE_NAME = "com.huawei.hmsapp.appgallery"; 51eace7efcSopenharmony_ciconstexpr const char* MARKET_CROWD_TEST_BUNDLE_PARAM = "crowd_test_bundle_name"; 52eace7efcSopenharmony_ciconstexpr const char* BUNDLE_NAME_SELECTOR_DIALOG = "com.ohos.amsdialog"; 53eace7efcSopenharmony_ciconstexpr const char* JUMP_INTERCEPTOR_DIALOG_CALLER_PKG = "interceptor_callerPkg"; 54eace7efcSopenharmony_ci 55eace7efcSopenharmony_ci#define CHECK_POINTER_CONTINUE(object) \ 56eace7efcSopenharmony_ci if (!object) { \ 57eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "nullptr"); \ 58eace7efcSopenharmony_ci continue; \ 59eace7efcSopenharmony_ci } 60eace7efcSopenharmony_ci 61eace7efcSopenharmony_ci#define CHECK_POINTER_IS_NULLPTR(object) \ 62eace7efcSopenharmony_ci if (object == nullptr) { \ 63eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "nullptr"); \ 64eace7efcSopenharmony_ci return; \ 65eace7efcSopenharmony_ci } 66eace7efcSopenharmony_ci 67eace7efcSopenharmony_ci#define CHECK_POINTER(object) \ 68eace7efcSopenharmony_ci if (!object) { \ 69eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "nullptr"); \ 70eace7efcSopenharmony_ci return; \ 71eace7efcSopenharmony_ci } 72eace7efcSopenharmony_ci 73eace7efcSopenharmony_ci#define CHECK_POINTER_LOG(object, log) \ 74eace7efcSopenharmony_ci if (!object) { \ 75eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s:", log); \ 76eace7efcSopenharmony_ci return; \ 77eace7efcSopenharmony_ci } 78eace7efcSopenharmony_ci 79eace7efcSopenharmony_ci#define CHECK_POINTER_TAG_LOG(object, tag, log) \ 80eace7efcSopenharmony_ci if (!object) { \ 81eace7efcSopenharmony_ci TAG_LOGE(tag, "%{public}s:", log); \ 82eace7efcSopenharmony_ci return; \ 83eace7efcSopenharmony_ci } 84eace7efcSopenharmony_ci 85eace7efcSopenharmony_ci#define CHECK_POINTER_AND_RETURN(object, value) \ 86eace7efcSopenharmony_ci if (!object) { \ 87eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "nullptr"); \ 88eace7efcSopenharmony_ci return value; \ 89eace7efcSopenharmony_ci } 90eace7efcSopenharmony_ci 91eace7efcSopenharmony_ci#define CHECK_POINTER_AND_RETURN_LOG(object, value, log) \ 92eace7efcSopenharmony_ci if (!object) { \ 93eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s:", log); \ 94eace7efcSopenharmony_ci return value; \ 95eace7efcSopenharmony_ci } 96eace7efcSopenharmony_ci 97eace7efcSopenharmony_ci#define CHECK_POINTER_RETURN_BOOL(object) \ 98eace7efcSopenharmony_ci if (!object) { \ 99eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "nullptr"); \ 100eace7efcSopenharmony_ci return false; \ 101eace7efcSopenharmony_ci } 102eace7efcSopenharmony_ci 103eace7efcSopenharmony_ci#define CHECK_RET_RETURN_RET(object, log) \ 104eace7efcSopenharmony_ci if (object != ERR_OK) { \ 105eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s, ret : %{public}d", log, object); \ 106eace7efcSopenharmony_ci return object; \ 107eace7efcSopenharmony_ci } 108eace7efcSopenharmony_ci 109eace7efcSopenharmony_ci#define CHECK_TRUE_RETURN_RET(object, value, log) \ 110eace7efcSopenharmony_ci if (object) { \ 111eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", log); \ 112eace7efcSopenharmony_ci return value; \ 113eace7efcSopenharmony_ci } 114eace7efcSopenharmony_ci 115eace7efcSopenharmony_ci[[maybe_unused]] static bool IsSystemDialogAbility(const std::string &bundleName, const std::string &abilityName) 116eace7efcSopenharmony_ci{ 117eace7efcSopenharmony_ci if (abilityName == AbilityConfig::SYSTEM_DIALOG_NAME && bundleName == AbilityConfig::SYSTEM_UI_BUNDLE_NAME) { 118eace7efcSopenharmony_ci return true; 119eace7efcSopenharmony_ci } 120eace7efcSopenharmony_ci 121eace7efcSopenharmony_ci if (abilityName == AbilityConfig::DEVICE_MANAGER_NAME && bundleName == AbilityConfig::DEVICE_MANAGER_BUNDLE_NAME) { 122eace7efcSopenharmony_ci return true; 123eace7efcSopenharmony_ci } 124eace7efcSopenharmony_ci 125eace7efcSopenharmony_ci return false; 126eace7efcSopenharmony_ci} 127eace7efcSopenharmony_ci 128eace7efcSopenharmony_ci[[maybe_unused]] static std::string ConvertBundleNameSingleton(const std::string &bundleName, const std::string &name, 129eace7efcSopenharmony_ci const std::string &moduleName, const int32_t appIndex = 0) 130eace7efcSopenharmony_ci{ 131eace7efcSopenharmony_ci std::string strName; 132eace7efcSopenharmony_ci if (appIndex == 0) { 133eace7efcSopenharmony_ci strName = AbilityConfig::MISSION_NAME_MARK_HEAD + bundleName + 134eace7efcSopenharmony_ci AbilityConfig::MISSION_NAME_SEPARATOR + moduleName + 135eace7efcSopenharmony_ci AbilityConfig::MISSION_NAME_SEPARATOR + name; 136eace7efcSopenharmony_ci } else { 137eace7efcSopenharmony_ci strName = AbilityConfig::MISSION_NAME_MARK_HEAD + bundleName + 138eace7efcSopenharmony_ci AbilityConfig::MISSION_NAME_SEPARATOR + std::to_string(appIndex) + 139eace7efcSopenharmony_ci AbilityConfig::MISSION_NAME_SEPARATOR + moduleName + 140eace7efcSopenharmony_ci AbilityConfig::MISSION_NAME_SEPARATOR + name; 141eace7efcSopenharmony_ci } 142eace7efcSopenharmony_ci 143eace7efcSopenharmony_ci return strName; 144eace7efcSopenharmony_ci} 145eace7efcSopenharmony_ci 146eace7efcSopenharmony_cistatic constexpr int64_t NANOSECONDS = 1000000000; // NANOSECONDS mean 10^9 nano second 147eace7efcSopenharmony_cistatic constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 millias second 148eace7efcSopenharmony_ci[[maybe_unused]] static int64_t SystemTimeMillis() 149eace7efcSopenharmony_ci{ 150eace7efcSopenharmony_ci struct timespec t; 151eace7efcSopenharmony_ci t.tv_sec = 0; 152eace7efcSopenharmony_ci t.tv_nsec = 0; 153eace7efcSopenharmony_ci clock_gettime(CLOCK_MONOTONIC, &t); 154eace7efcSopenharmony_ci return (int64_t)((t.tv_sec) * NANOSECONDS + t.tv_nsec) / MICROSECONDS; 155eace7efcSopenharmony_ci} 156eace7efcSopenharmony_ci 157eace7efcSopenharmony_ci[[maybe_unused]] static int64_t UTCTimeSeconds() 158eace7efcSopenharmony_ci{ 159eace7efcSopenharmony_ci struct timespec t; 160eace7efcSopenharmony_ci t.tv_sec = 0; 161eace7efcSopenharmony_ci t.tv_nsec = 0; 162eace7efcSopenharmony_ci clock_gettime(CLOCK_REALTIME, &t); 163eace7efcSopenharmony_ci return (int64_t)(t.tv_sec); 164eace7efcSopenharmony_ci} 165eace7efcSopenharmony_ci 166eace7efcSopenharmony_ci[[maybe_unused]] static bool IsStartFreeInstall(const Want &want) 167eace7efcSopenharmony_ci{ 168eace7efcSopenharmony_ci auto flags = want.GetFlags(); 169eace7efcSopenharmony_ci if ((flags & Want::FLAG_INSTALL_ON_DEMAND) == Want::FLAG_INSTALL_ON_DEMAND) { 170eace7efcSopenharmony_ci return true; 171eace7efcSopenharmony_ci } 172eace7efcSopenharmony_ci return false; 173eace7efcSopenharmony_ci} 174eace7efcSopenharmony_ci 175eace7efcSopenharmony_ci[[maybe_unused]] static std::shared_ptr<AppExecFwk::BundleMgrHelper> GetBundleManagerHelper() 176eace7efcSopenharmony_ci{ 177eace7efcSopenharmony_ci return DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance(); 178eace7efcSopenharmony_ci} 179eace7efcSopenharmony_ci 180eace7efcSopenharmony_ci[[maybe_unused]] static bool ParseJumpInterceptorWant(Want &targetWant, const std::string callerPkg) 181eace7efcSopenharmony_ci{ 182eace7efcSopenharmony_ci if (callerPkg.empty()) { 183eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "empty callerPkg"); 184eace7efcSopenharmony_ci return false; 185eace7efcSopenharmony_ci } 186eace7efcSopenharmony_ci targetWant.SetParam(JUMP_INTERCEPTOR_DIALOG_CALLER_PKG, callerPkg); 187eace7efcSopenharmony_ci return true; 188eace7efcSopenharmony_ci} 189eace7efcSopenharmony_ci 190eace7efcSopenharmony_ci[[maybe_unused]] static bool CheckJumpInterceptorWant(const Want &targetWant, std::string &callerPkg, 191eace7efcSopenharmony_ci std::string &targetPkg) 192eace7efcSopenharmony_ci{ 193eace7efcSopenharmony_ci if (!targetWant.HasParameter(JUMP_INTERCEPTOR_DIALOG_CALLER_PKG)) { 194eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid interceptor param"); 195eace7efcSopenharmony_ci return false; 196eace7efcSopenharmony_ci } 197eace7efcSopenharmony_ci callerPkg = targetWant.GetStringParam(JUMP_INTERCEPTOR_DIALOG_CALLER_PKG); 198eace7efcSopenharmony_ci targetPkg = targetWant.GetElement().GetBundleName(); 199eace7efcSopenharmony_ci return !callerPkg.empty() && !targetPkg.empty(); 200eace7efcSopenharmony_ci} 201eace7efcSopenharmony_ci 202eace7efcSopenharmony_ci[[maybe_unused]] static bool AddAbilityJumpRuleToBms(const std::string &callerPkg, const std::string &targetPkg, 203eace7efcSopenharmony_ci int32_t userId) 204eace7efcSopenharmony_ci{ 205eace7efcSopenharmony_ci if (callerPkg.empty() || targetPkg.empty()) { 206eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid inputs"); 207eace7efcSopenharmony_ci return false; 208eace7efcSopenharmony_ci } 209eace7efcSopenharmony_ci auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); 210eace7efcSopenharmony_ci if (bundleMgrHelper == nullptr) { 211eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "GetBundleManagerHelper failed"); 212eace7efcSopenharmony_ci return false; 213eace7efcSopenharmony_ci } 214eace7efcSopenharmony_ci auto appControlMgr = bundleMgrHelper->GetAppControlProxy(); 215eace7efcSopenharmony_ci if (appControlMgr == nullptr) { 216eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "Get appControlMgr failed"); 217eace7efcSopenharmony_ci return false; 218eace7efcSopenharmony_ci } 219eace7efcSopenharmony_ci int ret = IN_PROCESS_CALL(appControlMgr->ConfirmAppJumpControlRule(callerPkg, targetPkg, userId)); 220eace7efcSopenharmony_ci return ret == ERR_OK; 221eace7efcSopenharmony_ci} 222eace7efcSopenharmony_ci 223eace7efcSopenharmony_ci#ifdef WITH_DLP 224eace7efcSopenharmony_ci[[maybe_unused]] static bool HandleDlpApp(Want &want) 225eace7efcSopenharmony_ci{ 226eace7efcSopenharmony_ci const std::unordered_set<std::string> whiteListDlpSet = { BUNDLE_NAME_SELECTOR_DIALOG }; 227eace7efcSopenharmony_ci if (whiteListDlpSet.find(want.GetBundle()) != whiteListDlpSet.end()) { 228eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "enter special app"); 229eace7efcSopenharmony_ci return false; 230eace7efcSopenharmony_ci } 231eace7efcSopenharmony_ci 232eace7efcSopenharmony_ci AppExecFwk::ElementName element = want.GetElement(); 233eace7efcSopenharmony_ci if (want.GetBoolParam(DLP_PARAMS_SANDBOX, false) && !element.GetBundleName().empty() && 234eace7efcSopenharmony_ci !element.GetAbilityName().empty()) { 235eace7efcSopenharmony_ci want.SetElementName(DEFAULT_DEVICE_ID, DLP_BUNDLE_NAME, DLP_ABILITY_NAME, DLP_MODULE_NAME); 236eace7efcSopenharmony_ci want.SetParam(DLP_PARAMS_BUNDLE_NAME, element.GetBundleName()); 237eace7efcSopenharmony_ci want.SetParam(DLP_PARAMS_MODULE_NAME, element.GetModuleName()); 238eace7efcSopenharmony_ci want.SetParam(DLP_PARAMS_ABILITY_NAME, element.GetAbilityName()); 239eace7efcSopenharmony_ci want.RemoveParam(DLP_PARAMS_SANDBOX); 240eace7efcSopenharmony_ci return true; 241eace7efcSopenharmony_ci } 242eace7efcSopenharmony_ci 243eace7efcSopenharmony_ci return false; 244eace7efcSopenharmony_ci} 245eace7efcSopenharmony_ci#endif // WITH_DLP 246eace7efcSopenharmony_ci 247eace7efcSopenharmony_ci[[maybe_unused]] static bool IsStartIncludeAtomicService(const Want &want, const int32_t userId) 248eace7efcSopenharmony_ci{ 249eace7efcSopenharmony_ci auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); 250eace7efcSopenharmony_ci if (bundleMgrHelper == nullptr) { 251eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "GetBundleManagerHelper failed"); 252eace7efcSopenharmony_ci return false; 253eace7efcSopenharmony_ci } 254eace7efcSopenharmony_ci 255eace7efcSopenharmony_ci std::string targetBundleName = want.GetBundle(); 256eace7efcSopenharmony_ci AppExecFwk::ApplicationInfo targetAppInfo; 257eace7efcSopenharmony_ci bool getTargetResult = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(targetBundleName, 258eace7efcSopenharmony_ci AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, targetAppInfo)); 259eace7efcSopenharmony_ci if (!getTargetResult) { 260eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "Get targetAppInfo failed"); 261eace7efcSopenharmony_ci return false; 262eace7efcSopenharmony_ci } 263eace7efcSopenharmony_ci if (targetAppInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE) { 264eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "target is atomic service"); 265eace7efcSopenharmony_ci return true; 266eace7efcSopenharmony_ci } 267eace7efcSopenharmony_ci 268eace7efcSopenharmony_ci int callerUid = IPCSkeleton::GetCallingUid(); 269eace7efcSopenharmony_ci std::string callerBundleName; 270eace7efcSopenharmony_ci ErrCode err = IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callerUid, callerBundleName)); 271eace7efcSopenharmony_ci if (err != ERR_OK) { 272eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "Get bms failed"); 273eace7efcSopenharmony_ci return false; 274eace7efcSopenharmony_ci } 275eace7efcSopenharmony_ci AppExecFwk::ApplicationInfo callerAppInfo; 276eace7efcSopenharmony_ci bool getCallerResult = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(callerBundleName, 277eace7efcSopenharmony_ci AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, callerAppInfo)); 278eace7efcSopenharmony_ci if (!getCallerResult) { 279eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "Get callerAppInfo failed"); 280eace7efcSopenharmony_ci return false; 281eace7efcSopenharmony_ci } 282eace7efcSopenharmony_ci if (callerAppInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE) { 283eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "caller is atomic service"); 284eace7efcSopenharmony_ci return true; 285eace7efcSopenharmony_ci } 286eace7efcSopenharmony_ci return false; 287eace7efcSopenharmony_ci} 288eace7efcSopenharmony_ci 289eace7efcSopenharmony_ci[[maybe_unused]] static void RemoveShowModeKey(Want &want) 290eace7efcSopenharmony_ci{ 291eace7efcSopenharmony_ci if (want.HasParameter(AAFwk::SCREEN_MODE_KEY)) { 292eace7efcSopenharmony_ci want.RemoveParam(AAFwk::SCREEN_MODE_KEY); 293eace7efcSopenharmony_ci } 294eace7efcSopenharmony_ci} 295eace7efcSopenharmony_ci 296eace7efcSopenharmony_ci[[maybe_unused]] static bool IsSceneBoard(const std::string &bundleName, const std::string &AbilityName) 297eace7efcSopenharmony_ci{ 298eace7efcSopenharmony_ci return AbilityName == AbilityConfig::SCENEBOARD_ABILITY_NAME && 299eace7efcSopenharmony_ci bundleName == AbilityConfig::SCENEBOARD_BUNDLE_NAME; 300eace7efcSopenharmony_ci} 301eace7efcSopenharmony_ci 302eace7efcSopenharmony_ci[[maybe_unused]] static void RemoveWindowModeKey(Want &want) 303eace7efcSopenharmony_ci{ 304eace7efcSopenharmony_ci if (want.HasParameter(Want::PARAM_RESV_WINDOW_MODE)) { 305eace7efcSopenharmony_ci want.RemoveParam(Want::PARAM_RESV_WINDOW_MODE); 306eace7efcSopenharmony_ci } 307eace7efcSopenharmony_ci} 308eace7efcSopenharmony_ci 309eace7efcSopenharmony_ci[[maybe_unused]] static void RemoveInstanceKey(Want &want) 310eace7efcSopenharmony_ci{ 311eace7efcSopenharmony_ci want.RemoveParam(Want::APP_INSTANCE_KEY); 312eace7efcSopenharmony_ci want.RemoveParam(Want::CREATE_APP_INSTANCE_KEY); 313eace7efcSopenharmony_ci} 314eace7efcSopenharmony_ci 315eace7efcSopenharmony_ci[[maybe_unused]] static void RemoveWantKey(Want &want) 316eace7efcSopenharmony_ci{ 317eace7efcSopenharmony_ci RemoveShowModeKey(want); 318eace7efcSopenharmony_ci RemoveWindowModeKey(want); 319eace7efcSopenharmony_ci} 320eace7efcSopenharmony_ci 321eace7efcSopenharmony_ci[[maybe_unused]] static int32_t CheckInstanceKey(const Want &want) 322eace7efcSopenharmony_ci{ 323eace7efcSopenharmony_ci auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY); 324eace7efcSopenharmony_ci auto isCreating = want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false); 325eace7efcSopenharmony_ci if (!instanceKey.empty() || isCreating) { 326eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "Not support multi-instance"); 327eace7efcSopenharmony_ci return ERR_MULTI_INSTANCE_NOT_SUPPORTED; 328eace7efcSopenharmony_ci } 329eace7efcSopenharmony_ci return ERR_OK; 330eace7efcSopenharmony_ci} 331eace7efcSopenharmony_ci 332eace7efcSopenharmony_ci[[maybe_unused]] static void WantSetParameterWindowMode(Want &want, int32_t windowMode) 333eace7efcSopenharmony_ci{ 334eace7efcSopenharmony_ci want.SetParam(Want::PARAM_RESV_WINDOW_MODE, windowMode); 335eace7efcSopenharmony_ci} 336eace7efcSopenharmony_ci 337eace7efcSopenharmony_ci[[maybe_unused]] static void ProcessWindowMode(Want &want, uint32_t accessTokenId, int32_t windowMode) 338eace7efcSopenharmony_ci{ 339eace7efcSopenharmony_ci if (PermissionVerification::GetInstance()->IsSystemAppCall()) { 340eace7efcSopenharmony_ci want.SetParam(Want::PARAM_RESV_WINDOW_MODE, windowMode); 341eace7efcSopenharmony_ci return; 342eace7efcSopenharmony_ci } 343eace7efcSopenharmony_ci if (IPCSkeleton::GetCallingTokenID() == accessTokenId && ( 344eace7efcSopenharmony_ci windowMode == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY || 345eace7efcSopenharmony_ci windowMode == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY)) { 346eace7efcSopenharmony_ci want.SetParam(Want::PARAM_RESV_WINDOW_MODE, windowMode); 347eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "set windownMode for inner application split-screen mode"); 348eace7efcSopenharmony_ci } else if (windowMode == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FULLSCREEN) { 349eace7efcSopenharmony_ci want.SetParam(Want::PARAM_RESV_WINDOW_MODE, windowMode); 350eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "set windownMode for full screen mode"); 351eace7efcSopenharmony_ci } else { 352eace7efcSopenharmony_ci RemoveWindowModeKey(want); 353eace7efcSopenharmony_ci } 354eace7efcSopenharmony_ci} 355eace7efcSopenharmony_ci 356eace7efcSopenharmony_ci[[maybe_unused]] static int StartAppgallery(const std::string &bundleName, const int requestCode, const int32_t userId, 357eace7efcSopenharmony_ci const std::string &action) 358eace7efcSopenharmony_ci{ 359eace7efcSopenharmony_ci std::string appGalleryBundleName; 360eace7efcSopenharmony_ci auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); 361eace7efcSopenharmony_ci if (bundleMgrHelper == nullptr || !bundleMgrHelper->QueryAppGalleryBundleName(appGalleryBundleName)) { 362eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "GetBundleManagerHelper or QueryAppGalleryBundleName failed"); 363eace7efcSopenharmony_ci appGalleryBundleName = MARKET_BUNDLE_NAME; 364eace7efcSopenharmony_ci } 365eace7efcSopenharmony_ci 366eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "appGalleryBundleName:%{public}s", appGalleryBundleName.c_str()); 367eace7efcSopenharmony_ci 368eace7efcSopenharmony_ci Want want; 369eace7efcSopenharmony_ci want.SetElementName(appGalleryBundleName, ""); 370eace7efcSopenharmony_ci want.SetAction(action); 371eace7efcSopenharmony_ci want.SetParam(MARKET_CROWD_TEST_BUNDLE_PARAM, bundleName); 372eace7efcSopenharmony_ci return AbilityManagerClient::GetInstance()->StartAbility(want, requestCode, userId); 373eace7efcSopenharmony_ci} 374eace7efcSopenharmony_ci 375eace7efcSopenharmony_ciinline ErrCode EdmErrorType(bool isEdm) 376eace7efcSopenharmony_ci{ 377eace7efcSopenharmony_ci if (isEdm) { 378eace7efcSopenharmony_ci return ERR_EDM_APP_CONTROLLED; 379eace7efcSopenharmony_ci } 380eace7efcSopenharmony_ci return ERR_APP_CONTROLLED; 381eace7efcSopenharmony_ci} 382eace7efcSopenharmony_ci} // namespace AbilityUtil 383eace7efcSopenharmony_ci} // namespace AAFwk 384eace7efcSopenharmony_ci} // namespace OHOS 385eace7efcSopenharmony_ci 386eace7efcSopenharmony_ci#endif // OHOS_ABILITY_RUNTIME_ABILITY_UTIL_H 387