1 /* 2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_APP_UTILS_H 17 #define OHOS_ABILITY_RUNTIME_APP_UTILS_H 18 19 #include <mutex> 20 #include <string> 21 22 #include "nocopyable.h" 23 24 namespace OHOS { 25 namespace AAFwk { 26 constexpr const int32_t DEFAULT_MAX_EXT_PER_PROC = 10; 27 constexpr const int32_t DEFAULT_MAX_EXT_PER_DEV = 100; 28 constexpr const int32_t DEFAULT_INVALID_VALUE = -1; 29 constexpr const int32_t DEFAULT_MAX_CHILD_PROCESS = 0; 30 template<typename T> 31 class DeviceConfiguration { 32 public: 33 bool isLoaded = false; 34 T value; 35 }; 36 37 /** 38 * @class AppUtils 39 * provides app utils. 40 */ 41 class AppUtils { 42 public: 43 /** 44 * GetInstance, get an instance of AppUtils. 45 * 46 * @return An instance of AppUtils. 47 */ 48 static AppUtils &GetInstance(); 49 50 static void ForbidStartCallback(const char *key, const char *, void *); 51 52 /** 53 * AppUtils, destructor. 54 * 55 */ 56 ~AppUtils(); 57 58 /** 59 * IsLauncher, check if it is a launcher. 60 * 61 * @param bundleName The bundle name. 62 * @return Whether it is a launcher. 63 */ 64 bool IsLauncher(const std::string &bundleName) const; 65 66 /** 67 * IsLauncherAbility, check if it is a launcher ability. 68 * 69 * @param abilityName The ability name. 70 * @return Whether it is a launcher ability. 71 */ 72 bool IsLauncherAbility(const std::string &abilityName) const; 73 74 /** 75 * IsInheritWindowSplitScreenMode, check if it is inherit window split screen mode. 76 * 77 * @return Whether it is inherit window split screen mode. 78 */ 79 bool IsInheritWindowSplitScreenMode(); 80 81 /** 82 * IsSupportAncoApp, check if it supports anco app. 83 * 84 * @return Whether it supports anco app. 85 */ 86 bool IsSupportAncoApp(); 87 88 /** 89 * GetTimeoutUnitTimeRatio, get timeout unit time ratio. 90 * 91 * @return Timeout unit time ratio. 92 */ 93 int32_t GetTimeoutUnitTimeRatio(); 94 95 /** 96 * IsSelectorDialogDefaultPossion, check if selector dialog is on the default position. 97 * 98 * @return Whether selector dialog is on the default position. 99 */ 100 bool IsSelectorDialogDefaultPossion(); 101 102 /** 103 * IsStartSpecifiedProcess, check whether or not to start specified process. 104 * 105 * @return Whether or not to start specified process. 106 */ 107 bool IsStartSpecifiedProcess(); 108 109 /** 110 * IsUseMultiRenderProcess, check whether uses multi-render process. 111 * 112 * @return Whether uses multi-render process. 113 */ 114 bool IsUseMultiRenderProcess(); 115 116 /** 117 * IsLimitMaximumOfRenderProcess, check limit maximum of render process. 118 * 119 * @return Whether limit maximum of render process. 120 */ 121 bool IsLimitMaximumOfRenderProcess(); 122 123 /** 124 * IsGrantPersistUriPermission, check whether to grant persist uri permission. 125 * 126 * @return Whether to grant persist uri permission. 127 */ 128 bool IsGrantPersistUriPermission(); 129 130 /** 131 * IsSupportGrantUriPermission, check whether to grant temp uri permission, default true. 132 * 133 * @return Whether to grant temp uri permission. 134 */ 135 bool IsSupportGrantUriPermission(); 136 137 /** 138 * IsStartOptionsWithAnimation, check whether the start options have animation. 139 * 140 * @return Whether the start options have animation. 141 */ 142 bool IsStartOptionsWithAnimation(); 143 144 /** 145 * IsSupportStartAbilities, check whether the StartUIAbilities API is supported. 146 * 147 * @return Whether the StartUIAbilities API is supported. 148 */ 149 bool IsSupportStartAbilities(); 150 151 /** 152 * IsStartOptionsWithAnimation, check whether it is a multi-process model. 153 * 154 * @return Whether it is a multi-process model. 155 */ 156 bool IsMultiProcessModel(); 157 158 /** 159 * Allow starting child process in pc-type app 160 * 161 * @return allow or not allow 162 */ 163 bool AllowChildProcessInMultiProcessFeatureApp(); 164 165 /** 166 * IsStartOptionsWithProcessOptions, check whether the start options have process options. 167 * 168 * @return Whether the start options have process options. 169 */ 170 bool IsStartOptionsWithProcessOptions(); 171 172 /** 173 * EnableMoveUIAbilityToBackgroundApi, enable move ui-ability to background api. 174 * 175 * @return Whether the enable move ui-ability to background api is successful. 176 */ 177 bool EnableMoveUIAbilityToBackgroundApi(); 178 179 /** 180 * IsLaunchEmbededUIAbility, check if it is to launch embedded ui-ability. 181 * 182 * @return Whether it is to launch embedded ui-ability. 183 */ 184 bool IsLaunchEmbededUIAbility(); 185 186 /** 187 * IsSupportNativeChildProcess, check if it supports native child process. 188 * 189 * @return Whether it supports native child process. 190 */ 191 bool IsSupportNativeChildProcess(); 192 193 /** 194 * IsSupportMultiInstance, check if it supports multi-instance. 195 * 196 * @return Whether it supports multi-instance. 197 */ 198 bool IsSupportMultiInstance(); 199 200 /** 201 * IsAllowResidentInExtremeMemory, check if it allows resident in extrem low memory. 202 * 203 * @param bundleName The bundle name. 204 * @param abilityName The ability name. 205 * @return Whether it allows resident in extrem low memory. 206 */ 207 bool IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = ""); 208 209 /** 210 * IsAllowNativeChildProcess, check if it allows native child process. 211 * 212 * @param appIdentifier The app identifier. 213 * @return Whether it allows native child process. 214 */ 215 bool IsAllowNativeChildProcess(const std::string &appIdentifier); 216 217 /** 218 * GetLimitMaximumExtensionsPerProc, get limit max extensions per proc. 219 * 220 * @return Limit max extensions per proc. 221 */ 222 int32_t GetLimitMaximumExtensionsPerProc(); 223 224 /** 225 * IsBigMemoryUnrelatedKeepAliveProc, check if it refuses resident in memory quick kill.<unnamed> 226 * 227 * @param bundleName The bundle name. 228 */ 229 bool IsBigMemoryUnrelatedKeepAliveProc(const std::string &bundleName); 230 231 /** 232 * IsRequireBigMemoryProcess, check if it requires big memory. 233 * 234 * @param bundleName The bundle name. 235 */ 236 bool IsRequireBigMemoryProcess(const std::string &bundleName); 237 238 /** 239 * GetLimitMaximumExtensionsPerDevice, get limit max extensions per device. 240 * 241 * @return Limit max extensions per device. 242 */ 243 int32_t GetLimitMaximumExtensionsPerDevice(); 244 245 /** 246 * GetCacheExtensionTypeList, get cache extension type list. 247 * 248 * @return Cache extension type list. 249 */ 250 std::string GetCacheExtensionTypeList(); 251 252 /** 253 * IsSystemReasonMessage, get param of anco app identifier. 254 * 255 * @return identifiers. 256 */ 257 std::string GetAncoAppIdentifiers(); 258 259 /** 260 * IsAllowStartAbilityWithoutCallerToken, check if it allows start ability without caller token. 261 * 262 * @param bundleName The bundle name. 263 * @param abilityName The ability name. 264 * @return Whether it allows start ability without caller token. 265 */ 266 bool IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName); 267 268 /** 269 * GetBrokerDelegateBundleName, get broker delegate bundle name. 270 * 271 * @return Broker delegate bundle name. 272 */ 273 std::string GetBrokerDelegateBundleName(); 274 275 /** 276 * GetCollaboratorBrokerUID, get collaborator broker id. 277 * 278 * @return Collaborator broker id. 279 */ 280 int32_t GetCollaboratorBrokerUID(); 281 282 /** 283 * GetCollaboratorBrokerReserveUID, get collaborator broker reserve uid. 284 * 285 * @return Collaborator broker reserve uid. 286 */ 287 int32_t GetCollaboratorBrokerReserveUID(); 288 289 /** 290 * MaxChildProcess, get max child process. 291 * 292 * @return Max child process. 293 */ 294 int32_t MaxChildProcess(); 295 296 /** 297 * MaxMultiProcessFeatureChildProcess, get max child process of multi process feature app. 298 * 299 * @return Max child process count. 300 */ 301 int32_t MaxMultiProcessFeatureChildProcess(); 302 303 /** 304 * GetMigrateClientBundleName, get migrate client bundle name. 305 * 306 * @return Migrate client bundle name. 307 */ 308 std::string GetMigrateClientBundleName(); 309 310 /** 311 * IsConnectSupportCrossUser, check if it support cross-user. 312 * 313 * @return Whether it supports cross-user. 314 */ 315 bool IsConnectSupportCrossUser(); 316 317 /** 318 * IsSupportAppServiceExtension, check if it support app service extension. 319 * 320 * @return Whether it supports app service extension. 321 */ 322 bool IsSupportAppServiceExtension(); 323 324 /** 325 * IsPrepareTerminateEnabled, check if it supports prepare terminate. 326 * 327 * @return Whether it supports prepare terminate. 328 */ 329 bool IsPrepareTerminateEnabled(); 330 331 /** 332 * IsCacheExtensionAbilityByList, check if it allows cache extension ability by list. 333 * 334 * @param bundleName The bundle name. 335 * @param abilityName The ability name. 336 * @return Whether it allows cache extensionability. 337 */ 338 bool IsCacheExtensionAbilityByList(const std::string& bundleName, const std::string& abilityName); 339 340 /** 341 * IsSystemReasonMessage, check if it supports launch reason message. 342 * 343 * @param reasonMessage The launch reason message. 344 * @return Whether it supports launch reason message. 345 */ 346 bool IsSystemReasonMessage(const std::string &reasonMessage); 347 348 bool InResidentWhiteList(const std::string &bundleName); 349 350 const std::vector<std::string> &GetResidentWhiteList(); 351 352 bool InOnNewProcessEnableList(const std::string &bundleName); 353 354 bool IsPreloadApplicationEnabled(); 355 356 bool IsForbidStart(); 357 358 private: 359 /** 360 * LoadResidentProcessInExtremeMemory, load resident process in extreme low memory. 361 * 362 */ 363 void LoadResidentProcessInExtremeMemory(); 364 365 /** 366 * LoadAllowNativeChildProcessApps, load allow native child process apps. 367 * 368 */ 369 void LoadAllowNativeChildProcessApps(); 370 371 /** 372 * LoadStartAbilityWithoutCallerToken, load start ability without caller token. 373 * 374 */ 375 void LoadStartAbilityWithoutCallerToken(); 376 377 /** 378 * IsCacheAbilityEnabled, check cache ability parameter switch. 379 * 380 */ 381 bool IsCacheAbilityEnabled(); 382 383 /** 384 * LoadCacheAbilityList, load cache ability list from file. 385 * 386 */ 387 void LoadCacheAbilityList(); 388 389 /** 390 * LoadProcessProhibitedFromRestarting, load process prohibited in big memory. 391 * 392 */ 393 void LoadProcessProhibitedFromRestarting(); 394 395 /** 396 * LoadRequireBigMemoryApp, load app name that require big memory. 397 * 398 */ 399 void LoadRequireBigMemoryApp(); 400 401 /** 402 * LoadResidentWhiteList, load resident white list. 403 * 404 */ 405 void LoadResidentWhiteList(); 406 407 /** 408 * LoadOnNewProcessEnableList, load on new process enable list. 409 * 410 */ 411 void LoadOnNewProcessEnableList(); 412 413 /** 414 * AppUtils, private constructor. 415 * 416 */ 417 AppUtils(); 418 419 volatile bool isSceneBoard_ = false; 420 volatile DeviceConfiguration<bool> isInheritWindowSplitScreenMode_ = {false, true}; 421 volatile DeviceConfiguration<bool> isSupportAncoApp_ = {false, false}; 422 volatile DeviceConfiguration<int32_t> timeoutUnitTimeRatio_ = {false, 1}; 423 volatile DeviceConfiguration<bool> isSelectorDialogDefaultPossion_ = {false, true}; 424 volatile DeviceConfiguration<bool> isStartSpecifiedProcess_ = {false, false}; 425 volatile DeviceConfiguration<bool> isUseMultiRenderProcess_ = {false, true}; 426 volatile DeviceConfiguration<bool> isLimitMaximumOfRenderProcess_ = {false, true}; 427 volatile DeviceConfiguration<bool> isGrantPersistUriPermission_ = {false, false}; 428 volatile DeviceConfiguration<bool> isStartOptionsWithAnimation_ = {false, false}; 429 volatile DeviceConfiguration<bool> isMultiProcessModel_ = {false, false}; 430 volatile DeviceConfiguration<bool> allowChildProcessInMultiProcessFeatureApp_ = {false, false}; 431 volatile DeviceConfiguration<bool> isStartOptionsWithProcessOptions_ = {false, false}; 432 volatile DeviceConfiguration<bool> enableMoveUIAbilityToBackgroundApi_ = {false, true}; 433 volatile DeviceConfiguration<bool> isLaunchEmbededUIAbility_ = {false, false}; 434 volatile DeviceConfiguration<bool> isSupportNativeChildProcess_ = {false, false}; 435 volatile DeviceConfiguration<bool> isSupportMultiInstance_ = {false, false}; 436 std::mutex isConnectSupportCrossUserMutex_; 437 volatile DeviceConfiguration<bool> isConnectSupportCrossUser_ = {false, false}; 438 volatile DeviceConfiguration<bool> isSupportAppServiceExtension_ = {false, false}; 439 volatile DeviceConfiguration<bool> isGrantTempUriPermission_ = {false, true}; 440 volatile DeviceConfiguration<bool> isSupportStartAbilities_ = {false, false}; 441 volatile DeviceConfiguration<bool> isPreloadApplicationEnabled_ = {false, false}; 442 volatile DeviceConfiguration<bool> isForbidStart_ = {true, false}; 443 DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 444 residentProcessInExtremeMemory_ = {false, {}}; 445 std::mutex residentProcessInExtremeMemoryMutex_; 446 DeviceConfiguration<std::vector<std::string>> processProhibitedFromRestarting_ = {false, {}}; 447 std::mutex processProhibitedFromRestartingMutex_; 448 DeviceConfiguration<std::vector<std::string>> requireBigMemoryApp_ = {false, {}}; 449 std::mutex requireBigMemoryAppMutex_; 450 DeviceConfiguration<std::vector<std::string>> 451 allowStartNativeProcessApps_ = {false, {}}; 452 volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerProc_ = {false, DEFAULT_MAX_EXT_PER_PROC}; 453 volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerDevice_ = {false, DEFAULT_MAX_EXT_PER_DEV}; 454 DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 455 startAbilityWithoutCallerToken_ = {false, {}}; 456 std::mutex startAbilityWithoutCallerTokenMutex_; 457 DeviceConfiguration<std::string> brokerDelegateBundleName_ = {false, ""}; 458 volatile DeviceConfiguration<int32_t> collaboratorBrokerUid_ = {false, DEFAULT_INVALID_VALUE}; 459 volatile DeviceConfiguration<int32_t> collaboratorBrokerReserveUid_ = {false, DEFAULT_INVALID_VALUE}; 460 volatile DeviceConfiguration<int32_t> maxChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS}; 461 volatile DeviceConfiguration<int32_t> maxMultiProcessFeatureChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS}; 462 DeviceConfiguration<std::string> migrateClientBundleName_ = {true, "com.huwei.hmos.migratecilent"}; 463 std::mutex cacheAbilityListMutex_; 464 DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 465 cacheAbilityList_ = {false, {}}; 466 DeviceConfiguration<std::vector<std::string>> residentWhiteList_ = {false, {}}; 467 std::mutex residentWhiteListMutex_; 468 DeviceConfiguration<std::vector<std::string>> onNewProcessEnableList_ = {false, {}}; 469 std::mutex onNewProcessEnableListMutex_; 470 DISALLOW_COPY_AND_MOVE(AppUtils); 471 }; 472 } // namespace AAFwk 473 } // namespace OHOS 474 #endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H 475