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 IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = ""); 57 bool IsAllowNativeChildProcess(const std::string &appIdentifier); 58 int32_t GetLimitMaximumExtensionsPerProc(); 59 int32_t GetLimitMaximumExtensionsPerDevice(); 60 std::string GetCacheExtensionTypeList(); 61 bool IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName); 62 int32_t MaxChildProcess(); 63 64 private: 65 void LoadResidentProcessInExtremeMemory(); 66 void LoadAllowNativeChildProcessApps(); 67 void LoadStartAbilityWithoutCallerToken(); 68 AppUtils(); 69 volatile bool isSceneBoard_ = false; 70 volatile DeviceConfiguration<bool> isInheritWindowSplitScreenMode_ = {false, true}; 71 volatile DeviceConfiguration<bool> isSupportAncoApp_ = {false, false}; 72 volatile DeviceConfiguration<int32_t> timeoutUnitTimeRatio_ = {false, 1}; 73 volatile DeviceConfiguration<bool> isSelectorDialogDefaultPossion_ = {false, true}; 74 volatile DeviceConfiguration<bool> isStartSpecifiedProcess_ = {false, false}; 75 volatile DeviceConfiguration<bool> isUseMultiRenderProcess_ = {false, true}; 76 volatile DeviceConfiguration<bool> isLimitMaximumOfRenderProcess_ = {false, true}; 77 volatile DeviceConfiguration<bool> isGrantPersistUriPermission_ = {false, false}; 78 volatile DeviceConfiguration<bool> isStartOptionsWithAnimation_ = {false, false}; 79 volatile DeviceConfiguration<bool> isMultiProcessModel_ = {false, false}; 80 volatile DeviceConfiguration<bool> isStartOptionsWithProcessOptions_ = {false, false}; 81 volatile DeviceConfiguration<bool> enableMoveUIAbilityToBackgroundApi_ = {false, true}; 82 volatile DeviceConfiguration<bool> isLaunchEmbededUIAbility_ = {false, false}; 83 volatile DeviceConfiguration<bool> isSupportNativeChildProcess_ = {false, false}; 84 DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 85 residentProcessInExtremeMemory_ = {false, {}}; 86 std::mutex residentProcessInExtremeMemoryMutex_; 87 DeviceConfiguration<std::vector<std::string>> 88 allowStartNativeProcessApps_ = {false, {}}; 89 volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerProc_ = {false, DEFAULT_MAX_EXT_PER_PROC}; 90 volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerDevice_ = {false, DEFAULT_MAX_EXT_PER_DEV}; 91 DeviceConfiguration<std::vector<std::pair<std::string, std::string>>> 92 startAbilityWithoutCallerToken_ = {false, {}}; 93 std::mutex startAbilityWithoutCallerTokenMutex_; 94 volatile DeviceConfiguration<int32_t> maxChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS}; 95 DISALLOW_COPY_AND_MOVE(AppUtils); 96 }; 97 } // namespace AAFwk 98 } // namespace OHOS 99 #endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H 100