1 /* 2 * Copyright (c) 2023 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_MAX_CHILD_PROCESS = 0; 29 template<typename T> 30 class DeviceConfiguration { 31 public: 32 bool isLoaded = false; 33 T value; 34 }; 35 36 class AppUtils { 37 public: 38 static AppUtils &GetInstance(); 39 ~AppUtils(); 40 bool IsLauncher(const std::string &bundleName) const; 41 bool IsLauncherAbility(const std::string &abilityName) const; 42 bool IsInheritWindowSplitScreenMode(); 43 bool IsSupportAncoApp(); 44 int32_t GetTimeoutUnitTimeRatio(); 45 bool IsSelectorDialogDefaultPossion(); 46 bool IsStartSpecifiedProcess(); 47 bool IsUseMultiRenderProcess(); 48 bool IsLimitMaximumOfRenderProcess(); 49 bool IsGrantPersistUriPermission(); 50 bool IsStartOptionsWithAnimation(); 51 bool IsMultiProcessModel(); 52 bool IsStartOptionsWithProcessOptions(); 53 bool EnableMoveUIAbilityToBackgroundApi(); 54 bool IsLaunchEmbededUIAbility(); 55 bool IsSupportNativeChildProcess(); 56 bool IsSupportMultiInstance(); 57 bool IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = ""); 58 bool IsAllowNativeChildProcess(const std::string &appIdentifier); 59 int32_t GetLimitMaximumExtensionsPerProc(); 60 int32_t GetLimitMaximumExtensionsPerDevice(); 61 std::string GetCacheExtensionTypeList(); 62 bool IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName); 63 int32_t MaxChildProcess(); 64 65 private: 66 void LoadResidentProcessInExtremeMemory(); 67 void LoadAllowNativeChildProcessApps(); 68 void LoadStartAbilityWithoutCallerToken(); 69 AppUtils(); 70 volatile bool isSceneBoard_ = false; 71 volatile DeviceConfiguration<bool> isInheritWindowSplitScreenMode_ = {false, true}; 72 volatile DeviceConfiguration<bool> isSupportAncoApp_ = {false, false}; 73 volatile DeviceConfiguration<int32_t> timeoutUnitTimeRatio_ = {false, 1}; 74 volatile DeviceConfiguration<bool> isSelectorDialogDefaultPossion_ = {false, true}; 75 volatile DeviceConfiguration<bool> isStartSpecifiedProcess_ = {false, false}; 76 volatile DeviceConfiguration<bool> isUseMultiRenderProcess_ = {false, true}; 77 volatile DeviceConfiguration<bool> isLimitMaximumOfRenderProcess_ = {false, true}; 78 volatile DeviceConfiguration<bool> isGrantPersistUriPermission_ = {false, false}; 79 volatile DeviceConfiguration<bool> isStartOptionsWithAnimation_ = {false, false}; 80 volatile DeviceConfiguration<bool> isMultiProcessModel_ = {false, false}; 81 volatile DeviceConfiguration<bool> isStartOptionsWithProcessOptions_ = {false, false}; 82 volatile DeviceConfiguration<bool> enableMoveUIAbilityToBackgroundApi_ = {false, true}; 83 volatile DeviceConfiguration<bool> isLaunchEmbededUIAbility_ = {false, false}; 84 volatile DeviceConfiguration<bool> isSupportNativeChildProcess_ = {false, false}; 85 volatile DeviceConfiguration<bool> isSupportMultiInstance_ = {false, false}; 86 DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 87 residentProcessInExtremeMemory_ = {false, {}}; 88 std::mutex residentProcessInExtremeMemoryMutex_; 89 DeviceConfiguration<std::vector<std::string>> 90 allowStartNativeProcessApps_ = {false, {}}; 91 volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerProc_ = {false, DEFAULT_MAX_EXT_PER_PROC}; 92 volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerDevice_ = {false, DEFAULT_MAX_EXT_PER_DEV}; 93 DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 94 startAbilityWithoutCallerToken_ = {false, {}}; 95 std::mutex startAbilityWithoutCallerTokenMutex_; 96 volatile DeviceConfiguration<int32_t> maxChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS}; 97 DISALLOW_COPY_AND_MOVE(AppUtils); 98 }; 99 } // namespace AAFwk 100 } // namespace OHOS 101 #endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H 102