1 /* 2 * Copyright (c) 2021-2022 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_AMS_CONFIGURATION_PARAMETER_H 17 #define OHOS_ABILITY_RUNTIME_AMS_CONFIGURATION_PARAMETER_H 18 19 #include <fstream> 20 #include <map> 21 #include <nlohmann/json.hpp> 22 #include "nocopyable.h" 23 #include "parameters.h" 24 25 namespace OHOS { 26 namespace AAFwk { 27 namespace AmsConfig { 28 constexpr const char* AMS_CONFIG_FILE_PATH = "/system/etc/ams_service_config.json"; 29 constexpr const char* PICKER_CONFIG_FILE_PATH_DEFAULT = "/system/etc/uiextension_picker_config.json"; 30 constexpr const char* PICKER_CONFIG_FILE_PATH = "/etc/uiextension_picker_config.json"; 31 constexpr const char* SERVICE_ITEM_AMS = "service_startup_config"; 32 constexpr const char* MISSION_SAVE_TIME = "mission_save_time"; 33 constexpr const char* APP_NOT_RESPONSE_PROCESS_TIMEOUT_TIME = "app_not_response_process_timeout_time"; 34 constexpr const char* AMS_TIMEOUT_TIME = "ams_timeout_time"; 35 constexpr const char* DEVICE_TYPE = "device_type"; 36 constexpr const char* SYSTEM_CONFIGURATION = "system_configuration"; 37 constexpr const char* SYSTEM_ORIENTATION = "system_orientation"; 38 constexpr const char* ROOT_LAUNCHER_RESTART_MAX = "root_launcher_restart_max"; 39 constexpr const char* RESIDENT_RESTART_MAX = "resident_restart_max"; 40 constexpr const char* RESTART_INTERVAL_TIME = "restart_interval_time"; 41 constexpr const char* BOOT_ANIMATION_TIMEOUT_TIME = "boot_animation_timeout_time"; 42 constexpr const char* TIMEOUT_UNIT_TIME = "timeout_unit_time"; 43 constexpr const char* ABILITY_NAME = "ability_name"; 44 constexpr const char* BUNDLE_NAME = "bundle_name"; 45 constexpr const char* PICKER_CONFIGURATION = "picker_configuration"; 46 constexpr const char* PICKER_TYPE = "picker_type"; 47 constexpr const char* UIEATENSION = "uiextension"; 48 constexpr const char* UIEATENSION_TYPE = "type"; 49 constexpr const char* UIEATENSION_TYPE_PICKER = "typePicker"; 50 constexpr const char* MULTI_USER_TYPE = "multiUserType"; 51 constexpr const char* CUSTOM_SANDBOX_FEATURE = "support_custom_sandbox"; 52 constexpr const char* SUPPORT_BACK_TO_CALLER = "supportBackToCaller"; 53 constexpr const char* SUPPORT_SCB_CRASH_REBOOT = "supportSCBCrashReboot"; 54 constexpr const char* RESIDENT_WHITE_LIST = "normal_resident_apps"; 55 constexpr const char* SUPPORT_AA_KILL_WITH_REASON = "supportAAKillWithReason"; 56 } // namespace AmsConfig 57 58 enum class SatrtUiMode { STATUSBAR = 1, NAVIGATIONBAR = 2, STARTUIBOTH = 3 }; 59 60 enum class JsonValueType { 61 NULLABLE, 62 BOOLEAN, 63 NUMBER, 64 OBJECT, 65 ARRAY, 66 STRING 67 }; 68 69 class AmsConfigurationParameter final { 70 public: 71 enum { READ_OK = 0, READ_FAIL = 1, READ_JSON_FAIL = 2 }; 72 73 static AmsConfigurationParameter &GetInstance(); 74 /** 75 * return true : ams no config file 76 * return false : ams have config file 77 */ 78 bool NonConfigFile() const; 79 /** 80 * Get profile information 81 */ 82 void Parse(); 83 84 /** 85 * Get the save time of the current content 86 */ 87 int GetMissionSaveTime() const; 88 89 /** 90 * Get current system direction parameters, Temporary method. 91 */ 92 std::string GetOrientation() const; 93 94 /** 95 * Get the max number of restart. 96 */ 97 int GetMaxRestartNum(bool isRootLauncher) const; 98 99 /** 100 * Get the interval time after restart out of the max number of restart. 101 */ 102 int GetRestartIntervalTime() const; 103 104 /** 105 * get the application not response process timeout time. 106 */ 107 int GetANRTimeOutTime() const; 108 109 /** 110 * get ability manager service not response process timeout time. 111 */ 112 int GetAMSTimeOutTime() const; 113 114 /** 115 * get boot animation stared timout time. 116 */ 117 int GetBootAnimationTimeoutTime() const; 118 119 /** 120 * get the application cold start timeout time. 121 */ 122 int GetAppStartTimeoutTime() const; 123 124 bool IsSupportBackToCaller() const; 125 126 bool IsSupportSCBCrashReboot() const; 127 128 bool IsSupportAAKillWithReason() const; 129 130 /** 131 * set picker json object. 132 */ 133 void SetPickerJsonObject(nlohmann::json jsonObject); 134 135 /** 136 * get picker json object. 137 */ 138 nlohmann::json GetPickerJsonObject() const; 139 140 int MultiUserType() const; 141 142 int CustomSandbox() const; 143 144 const std::map<std::string, std::string>& GetPickerMap() const; 145 146 bool InResidentWhiteList(const std::string &bundleName) const; 147 const std::vector<std::string> &GetResidentWhiteList() const; 148 149 private: 150 AmsConfigurationParameter(); 151 ~AmsConfigurationParameter() = default; 152 DISALLOW_COPY_AND_MOVE(AmsConfigurationParameter); 153 /** 154 * Read the configuration file of ams 155 * 156 */ 157 int LoadAmsConfiguration(const std::string &filePath); 158 int LoadAppConfigurationForStartUpService(nlohmann::json& Object); 159 int LoadAppConfigurationForMemoryThreshold(nlohmann::json& Object); 160 int LoadSystemConfiguration(nlohmann::json& Object); 161 void LoadPickerConfiguration(nlohmann::json& Object); 162 bool CheckServiceConfigEnable(nlohmann::json& Object, const std::string &configName, JsonValueType type); 163 void UpdateStartUpServiceConfigInteger(nlohmann::json& Object, const std::string &configName, int32_t &value); 164 void UpdateStartUpServiceConfigString(nlohmann::json& Object, const std::string &configName, std::string &value); 165 void UpdatePickerConfigurationString(nlohmann::json& Object, const std::string &configName, std::string &value); 166 void LoadUIExtensionPickerConfig(const std::string &filePath); 167 int32_t LoadBackToCallerConfig(nlohmann::json& Object); 168 int32_t LoadSupportAAKillWithReasonConfig(nlohmann::json& Object); 169 int32_t LoadSupportSCBCrashRebootConfig(nlohmann::json& Object); 170 void LoadResidentWhiteListConfig(nlohmann::json& Object); 171 172 private: 173 bool nonConfigFile_ {false}; 174 bool supportBackToCaller_ {true}; 175 bool supportSceneboardCrashReboot_{true}; 176 bool supportAAKillWithReason_{false}; 177 178 int maxRootLauncherRestartNum_ = 0; 179 int maxResidentRestartNum_ = 0; 180 int restartIntervalTime_ {120000}; 181 int missionSaveTime_ {12 * 60 * 60 * 1000}; 182 int anrTime_ {5000}; 183 int amsTime_ {5000}; 184 int bootAnimationTime_ {5}; 185 int timeoutUnitTime_ {1000}; 186 int multiUserType_ {0}; 187 int supportCustomSandbox_{0}; 188 189 std::vector<std::string> residentWhiteList_; 190 std::string orientation_ {""}; 191 std::string bundleName_ {""}; 192 std::string abilityName_ {""}; 193 std::string pickerType_ {""}; 194 std::map<std::string, std::string> picker_; 195 nlohmann::json pickerJsonObject_ = nlohmann::json::object(); 196 }; 197 } // namespace AAFwk 198 } // namespace OHOS 199 #endif // OHOS_ABILITY_RUNTIME_AMS_CONFIGURATION_PARAMETER_H 200