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#ifndef OHOS_ABILITY_RUNTIME_APP_UTILS_H 17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_APP_UTILS_H 18eace7efcSopenharmony_ci 19eace7efcSopenharmony_ci#include <mutex> 20eace7efcSopenharmony_ci#include <string> 21eace7efcSopenharmony_ci 22eace7efcSopenharmony_ci#include "nocopyable.h" 23eace7efcSopenharmony_ci 24eace7efcSopenharmony_cinamespace OHOS { 25eace7efcSopenharmony_cinamespace AAFwk { 26eace7efcSopenharmony_ciconstexpr const int32_t DEFAULT_MAX_EXT_PER_PROC = 10; 27eace7efcSopenharmony_ciconstexpr const int32_t DEFAULT_MAX_EXT_PER_DEV = 100; 28eace7efcSopenharmony_ciconstexpr const int32_t DEFAULT_INVALID_VALUE = -1; 29eace7efcSopenharmony_ciconstexpr const int32_t DEFAULT_MAX_CHILD_PROCESS = 0; 30eace7efcSopenharmony_citemplate<typename T> 31eace7efcSopenharmony_ciclass DeviceConfiguration { 32eace7efcSopenharmony_cipublic: 33eace7efcSopenharmony_ci bool isLoaded = false; 34eace7efcSopenharmony_ci T value; 35eace7efcSopenharmony_ci}; 36eace7efcSopenharmony_ci 37eace7efcSopenharmony_ci/** 38eace7efcSopenharmony_ci * @class AppUtils 39eace7efcSopenharmony_ci * provides app utils. 40eace7efcSopenharmony_ci */ 41eace7efcSopenharmony_ciclass AppUtils { 42eace7efcSopenharmony_cipublic: 43eace7efcSopenharmony_ci /** 44eace7efcSopenharmony_ci * GetInstance, get an instance of AppUtils. 45eace7efcSopenharmony_ci * 46eace7efcSopenharmony_ci * @return An instance of AppUtils. 47eace7efcSopenharmony_ci */ 48eace7efcSopenharmony_ci static AppUtils &GetInstance(); 49eace7efcSopenharmony_ci 50eace7efcSopenharmony_ci /** 51eace7efcSopenharmony_ci * AppUtils, destructor. 52eace7efcSopenharmony_ci * 53eace7efcSopenharmony_ci */ 54eace7efcSopenharmony_ci ~AppUtils(); 55eace7efcSopenharmony_ci 56eace7efcSopenharmony_ci /** 57eace7efcSopenharmony_ci * IsLauncher, check if it is a launcher. 58eace7efcSopenharmony_ci * 59eace7efcSopenharmony_ci * @param bundleName The bundle name. 60eace7efcSopenharmony_ci * @return Whether it is a launcher. 61eace7efcSopenharmony_ci */ 62eace7efcSopenharmony_ci bool IsLauncher(const std::string &bundleName) const; 63eace7efcSopenharmony_ci 64eace7efcSopenharmony_ci /** 65eace7efcSopenharmony_ci * IsLauncherAbility, check if it is a launcher ability. 66eace7efcSopenharmony_ci * 67eace7efcSopenharmony_ci * @param abilityName The ability name. 68eace7efcSopenharmony_ci * @return Whether it is a launcher ability. 69eace7efcSopenharmony_ci */ 70eace7efcSopenharmony_ci bool IsLauncherAbility(const std::string &abilityName) const; 71eace7efcSopenharmony_ci 72eace7efcSopenharmony_ci /** 73eace7efcSopenharmony_ci * IsInheritWindowSplitScreenMode, check if it is inherit window split screen mode. 74eace7efcSopenharmony_ci * 75eace7efcSopenharmony_ci * @return Whether it is inherit window split screen mode. 76eace7efcSopenharmony_ci */ 77eace7efcSopenharmony_ci bool IsInheritWindowSplitScreenMode(); 78eace7efcSopenharmony_ci 79eace7efcSopenharmony_ci /** 80eace7efcSopenharmony_ci * IsSupportAncoApp, check if it supports anco app. 81eace7efcSopenharmony_ci * 82eace7efcSopenharmony_ci * @return Whether it supports anco app. 83eace7efcSopenharmony_ci */ 84eace7efcSopenharmony_ci bool IsSupportAncoApp(); 85eace7efcSopenharmony_ci 86eace7efcSopenharmony_ci /** 87eace7efcSopenharmony_ci * GetTimeoutUnitTimeRatio, get timeout unit time ratio. 88eace7efcSopenharmony_ci * 89eace7efcSopenharmony_ci * @return Timeout unit time ratio. 90eace7efcSopenharmony_ci */ 91eace7efcSopenharmony_ci int32_t GetTimeoutUnitTimeRatio(); 92eace7efcSopenharmony_ci 93eace7efcSopenharmony_ci /** 94eace7efcSopenharmony_ci * IsSelectorDialogDefaultPossion, check if selector dialog is on the default position. 95eace7efcSopenharmony_ci * 96eace7efcSopenharmony_ci * @return Whether selector dialog is on the default position. 97eace7efcSopenharmony_ci */ 98eace7efcSopenharmony_ci bool IsSelectorDialogDefaultPossion(); 99eace7efcSopenharmony_ci 100eace7efcSopenharmony_ci /** 101eace7efcSopenharmony_ci * IsStartSpecifiedProcess, check whether or not to start specified process. 102eace7efcSopenharmony_ci * 103eace7efcSopenharmony_ci * @return Whether or not to start specified process. 104eace7efcSopenharmony_ci */ 105eace7efcSopenharmony_ci bool IsStartSpecifiedProcess(); 106eace7efcSopenharmony_ci 107eace7efcSopenharmony_ci /** 108eace7efcSopenharmony_ci * IsUseMultiRenderProcess, check whether uses multi-render process. 109eace7efcSopenharmony_ci * 110eace7efcSopenharmony_ci * @return Whether uses multi-render process. 111eace7efcSopenharmony_ci */ 112eace7efcSopenharmony_ci bool IsUseMultiRenderProcess(); 113eace7efcSopenharmony_ci 114eace7efcSopenharmony_ci /** 115eace7efcSopenharmony_ci * IsLimitMaximumOfRenderProcess, check limit maximum of render process. 116eace7efcSopenharmony_ci * 117eace7efcSopenharmony_ci * @return Whether limit maximum of render process. 118eace7efcSopenharmony_ci */ 119eace7efcSopenharmony_ci bool IsLimitMaximumOfRenderProcess(); 120eace7efcSopenharmony_ci 121eace7efcSopenharmony_ci /** 122eace7efcSopenharmony_ci * IsGrantPersistUriPermission, check whether to grant persist uri permission. 123eace7efcSopenharmony_ci * 124eace7efcSopenharmony_ci * @return Whether to grant persist uri permission. 125eace7efcSopenharmony_ci */ 126eace7efcSopenharmony_ci bool IsGrantPersistUriPermission(); 127eace7efcSopenharmony_ci 128eace7efcSopenharmony_ci /** 129eace7efcSopenharmony_ci * IsStartOptionsWithAnimation, check whether the start options have animation. 130eace7efcSopenharmony_ci * 131eace7efcSopenharmony_ci * @return Whether the start options have animation. 132eace7efcSopenharmony_ci */ 133eace7efcSopenharmony_ci bool IsStartOptionsWithAnimation(); 134eace7efcSopenharmony_ci 135eace7efcSopenharmony_ci /** 136eace7efcSopenharmony_ci * IsStartOptionsWithAnimation, check whether it is a multi-process model. 137eace7efcSopenharmony_ci * 138eace7efcSopenharmony_ci * @return Whether it is a multi-process model. 139eace7efcSopenharmony_ci */ 140eace7efcSopenharmony_ci bool IsMultiProcessModel(); 141eace7efcSopenharmony_ci 142eace7efcSopenharmony_ci /** 143eace7efcSopenharmony_ci * IsStartOptionsWithProcessOptions, check whether the start options have process options. 144eace7efcSopenharmony_ci * 145eace7efcSopenharmony_ci * @return Whether the start options have process options. 146eace7efcSopenharmony_ci */ 147eace7efcSopenharmony_ci bool IsStartOptionsWithProcessOptions(); 148eace7efcSopenharmony_ci 149eace7efcSopenharmony_ci /** 150eace7efcSopenharmony_ci * EnableMoveUIAbilityToBackgroundApi, enable move ui-ability to background api. 151eace7efcSopenharmony_ci * 152eace7efcSopenharmony_ci * @return Whether the enable move ui-ability to background api is successful. 153eace7efcSopenharmony_ci */ 154eace7efcSopenharmony_ci bool EnableMoveUIAbilityToBackgroundApi(); 155eace7efcSopenharmony_ci 156eace7efcSopenharmony_ci /** 157eace7efcSopenharmony_ci * IsLaunchEmbededUIAbility, check if it is to launch embedded ui-ability. 158eace7efcSopenharmony_ci * 159eace7efcSopenharmony_ci * @return Whether it is to launch embedded ui-ability. 160eace7efcSopenharmony_ci */ 161eace7efcSopenharmony_ci bool IsLaunchEmbededUIAbility(); 162eace7efcSopenharmony_ci 163eace7efcSopenharmony_ci /** 164eace7efcSopenharmony_ci * IsSupportNativeChildProcess, check if it supports native child process. 165eace7efcSopenharmony_ci * 166eace7efcSopenharmony_ci * @return Whether it supports native child process. 167eace7efcSopenharmony_ci */ 168eace7efcSopenharmony_ci bool IsSupportNativeChildProcess(); 169eace7efcSopenharmony_ci 170eace7efcSopenharmony_ci /** 171eace7efcSopenharmony_ci * IsSupportMultiInstance, check if it supports multi-instance. 172eace7efcSopenharmony_ci * 173eace7efcSopenharmony_ci * @return Whether it supports multi-instance. 174eace7efcSopenharmony_ci */ 175eace7efcSopenharmony_ci bool IsSupportMultiInstance(); 176eace7efcSopenharmony_ci 177eace7efcSopenharmony_ci /** 178eace7efcSopenharmony_ci * IsAllowResidentInExtremeMemory, check if it allows resident in extrem low memory. 179eace7efcSopenharmony_ci * 180eace7efcSopenharmony_ci * @param bundleName The bundle name. 181eace7efcSopenharmony_ci * @param abilityName The ability name. 182eace7efcSopenharmony_ci * @return Whether it allows resident in extrem low memory. 183eace7efcSopenharmony_ci */ 184eace7efcSopenharmony_ci bool IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = ""); 185eace7efcSopenharmony_ci 186eace7efcSopenharmony_ci /** 187eace7efcSopenharmony_ci * IsAllowNativeChildProcess, check if it allows native child process. 188eace7efcSopenharmony_ci * 189eace7efcSopenharmony_ci * @param appIdentifier The app identifier. 190eace7efcSopenharmony_ci * @return Whether it allows native child process. 191eace7efcSopenharmony_ci */ 192eace7efcSopenharmony_ci bool IsAllowNativeChildProcess(const std::string &appIdentifier); 193eace7efcSopenharmony_ci 194eace7efcSopenharmony_ci /** 195eace7efcSopenharmony_ci * GetLimitMaximumExtensionsPerProc, get limit max extensions per proc. 196eace7efcSopenharmony_ci * 197eace7efcSopenharmony_ci * @return Limit max extensions per proc. 198eace7efcSopenharmony_ci */ 199eace7efcSopenharmony_ci int32_t GetLimitMaximumExtensionsPerProc(); 200eace7efcSopenharmony_ci 201eace7efcSopenharmony_ci /** 202eace7efcSopenharmony_ci * GetLimitMaximumExtensionsPerDevice, get limit max extensions per device. 203eace7efcSopenharmony_ci * 204eace7efcSopenharmony_ci * @return Limit max extensions per device. 205eace7efcSopenharmony_ci */ 206eace7efcSopenharmony_ci int32_t GetLimitMaximumExtensionsPerDevice(); 207eace7efcSopenharmony_ci 208eace7efcSopenharmony_ci /** 209eace7efcSopenharmony_ci * GetCacheExtensionTypeList, get cache extension type list. 210eace7efcSopenharmony_ci * 211eace7efcSopenharmony_ci * @return Cache extension type list. 212eace7efcSopenharmony_ci */ 213eace7efcSopenharmony_ci std::string GetCacheExtensionTypeList(); 214eace7efcSopenharmony_ci 215eace7efcSopenharmony_ci /** 216eace7efcSopenharmony_ci * IsAllowStartAbilityWithoutCallerToken, check if it allows start ability without caller token. 217eace7efcSopenharmony_ci * 218eace7efcSopenharmony_ci * @param bundleName The bundle name. 219eace7efcSopenharmony_ci * @param abilityName The ability name. 220eace7efcSopenharmony_ci * @return Whether it allows start ability without caller token. 221eace7efcSopenharmony_ci */ 222eace7efcSopenharmony_ci bool IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName); 223eace7efcSopenharmony_ci 224eace7efcSopenharmony_ci /** 225eace7efcSopenharmony_ci * GetBrokerDelegateBundleName, get broker delegate bundle name. 226eace7efcSopenharmony_ci * 227eace7efcSopenharmony_ci * @return Broker delegate bundle name. 228eace7efcSopenharmony_ci */ 229eace7efcSopenharmony_ci std::string GetBrokerDelegateBundleName(); 230eace7efcSopenharmony_ci 231eace7efcSopenharmony_ci /** 232eace7efcSopenharmony_ci * GetCollaboratorBrokerUID, get collaborator broker id. 233eace7efcSopenharmony_ci * 234eace7efcSopenharmony_ci * @return Collaborator broker id. 235eace7efcSopenharmony_ci */ 236eace7efcSopenharmony_ci int32_t GetCollaboratorBrokerUID(); 237eace7efcSopenharmony_ci 238eace7efcSopenharmony_ci /** 239eace7efcSopenharmony_ci * GetCollaboratorBrokerReserveUID, get collaborator broker reserve uid. 240eace7efcSopenharmony_ci * 241eace7efcSopenharmony_ci * @return Collaborator broker reserve uid. 242eace7efcSopenharmony_ci */ 243eace7efcSopenharmony_ci int32_t GetCollaboratorBrokerReserveUID(); 244eace7efcSopenharmony_ci 245eace7efcSopenharmony_ci /** 246eace7efcSopenharmony_ci * MaxChildProcess, get max child process. 247eace7efcSopenharmony_ci * 248eace7efcSopenharmony_ci * @return Max child process. 249eace7efcSopenharmony_ci */ 250eace7efcSopenharmony_ci int32_t MaxChildProcess(); 251eace7efcSopenharmony_ci 252eace7efcSopenharmony_ci /** 253eace7efcSopenharmony_ci * GetMigrateClientBundleName, get migrate client bundle name. 254eace7efcSopenharmony_ci * 255eace7efcSopenharmony_ci * @return Migrate client bundle name. 256eace7efcSopenharmony_ci */ 257eace7efcSopenharmony_ci std::string GetMigrateClientBundleName(); 258eace7efcSopenharmony_ci 259eace7efcSopenharmony_ciprivate: 260eace7efcSopenharmony_ci /** 261eace7efcSopenharmony_ci * LoadResidentProcessInExtremeMemory, load resident process in extreme low memory. 262eace7efcSopenharmony_ci * 263eace7efcSopenharmony_ci */ 264eace7efcSopenharmony_ci void LoadResidentProcessInExtremeMemory(); 265eace7efcSopenharmony_ci 266eace7efcSopenharmony_ci /** 267eace7efcSopenharmony_ci * LoadAllowNativeChildProcessApps, load allow native child process apps. 268eace7efcSopenharmony_ci * 269eace7efcSopenharmony_ci */ 270eace7efcSopenharmony_ci void LoadAllowNativeChildProcessApps(); 271eace7efcSopenharmony_ci 272eace7efcSopenharmony_ci /** 273eace7efcSopenharmony_ci * LoadStartAbilityWithoutCallerToken, load start ability without caller token. 274eace7efcSopenharmony_ci * 275eace7efcSopenharmony_ci */ 276eace7efcSopenharmony_ci void LoadStartAbilityWithoutCallerToken(); 277eace7efcSopenharmony_ci 278eace7efcSopenharmony_ci /** 279eace7efcSopenharmony_ci * AppUtils, private constructor. 280eace7efcSopenharmony_ci * 281eace7efcSopenharmony_ci */ 282eace7efcSopenharmony_ci AppUtils(); 283eace7efcSopenharmony_ci 284eace7efcSopenharmony_ci volatile bool isSceneBoard_ = false; 285eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isInheritWindowSplitScreenMode_ = {false, true}; 286eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isSupportAncoApp_ = {false, false}; 287eace7efcSopenharmony_ci volatile DeviceConfiguration<int32_t> timeoutUnitTimeRatio_ = {false, 1}; 288eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isSelectorDialogDefaultPossion_ = {false, true}; 289eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isStartSpecifiedProcess_ = {false, false}; 290eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isUseMultiRenderProcess_ = {false, true}; 291eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isLimitMaximumOfRenderProcess_ = {false, true}; 292eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isGrantPersistUriPermission_ = {false, false}; 293eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isStartOptionsWithAnimation_ = {false, false}; 294eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isMultiProcessModel_ = {false, false}; 295eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isStartOptionsWithProcessOptions_ = {false, false}; 296eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> enableMoveUIAbilityToBackgroundApi_ = {false, true}; 297eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isLaunchEmbededUIAbility_ = {false, false}; 298eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isSupportNativeChildProcess_ = {false, false}; 299eace7efcSopenharmony_ci volatile DeviceConfiguration<bool> isSupportMultiInstance_ = {false, false}; 300eace7efcSopenharmony_ci DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 301eace7efcSopenharmony_ci residentProcessInExtremeMemory_ = {false, {}}; 302eace7efcSopenharmony_ci std::mutex residentProcessInExtremeMemoryMutex_; 303eace7efcSopenharmony_ci DeviceConfiguration<std::vector<std::string>> 304eace7efcSopenharmony_ci allowStartNativeProcessApps_ = {false, {}}; 305eace7efcSopenharmony_ci volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerProc_ = {false, DEFAULT_MAX_EXT_PER_PROC}; 306eace7efcSopenharmony_ci volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerDevice_ = {false, DEFAULT_MAX_EXT_PER_DEV}; 307eace7efcSopenharmony_ci DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 308eace7efcSopenharmony_ci startAbilityWithoutCallerToken_ = {false, {}}; 309eace7efcSopenharmony_ci std::mutex startAbilityWithoutCallerTokenMutex_; 310eace7efcSopenharmony_ci DeviceConfiguration<std::string> brokerDelegateBundleName_ = {false, ""}; 311eace7efcSopenharmony_ci volatile DeviceConfiguration<int32_t> collaboratorBrokerUid_ = {false, DEFAULT_INVALID_VALUE}; 312eace7efcSopenharmony_ci volatile DeviceConfiguration<int32_t> collaboratorBrokerReserveUid_ = {false, DEFAULT_INVALID_VALUE}; 313eace7efcSopenharmony_ci volatile DeviceConfiguration<int32_t> maxChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS}; 314eace7efcSopenharmony_ci DeviceConfiguration<std::string> migrateClientBundleName_ = {true, "com.huwei.hmos.migratecilent"}; 315eace7efcSopenharmony_ci DISALLOW_COPY_AND_MOVE(AppUtils); 316eace7efcSopenharmony_ci}; 317eace7efcSopenharmony_ci} // namespace AAFwk 318eace7efcSopenharmony_ci} // namespace OHOS 319eace7efcSopenharmony_ci#endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H 320