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* SUPPORT_BACK_TO_CALLER = "supportBackToCaller"; 52 constexpr const char* SUPPORT_SCB_CRASH_REBOOT = "supportSCBCrashReboot"; 53 constexpr const char* RESIDENT_WHITE_LIST = "normal_resident_apps"; 54 } // namespace AmsConfig 55 56 enum class SatrtUiMode { STATUSBAR = 1, NAVIGATIONBAR = 2, STARTUIBOTH = 3 }; 57 58 enum class JsonValueType { 59 NULLABLE, 60 BOOLEAN, 61 NUMBER, 62 OBJECT, 63 ARRAY, 64 STRING 65 }; 66 67 class AmsConfigurationParameter final { 68 public: 69 enum { READ_OK = 0, READ_FAIL = 1, READ_JSON_FAIL = 2 }; 70 71 static AmsConfigurationParameter &GetInstance(); 72 /** 73 * return true : ams no config file 74 * return false : ams have config file 75 */ 76 bool NonConfigFile() const; 77 /** 78 * Get profile information 79 */ 80 void Parse(); 81 82 /** 83 * Get the save time of the current content 84 */ 85 int GetMissionSaveTime() const; 86 87 /** 88 * Get current system direction parameters, Temporary method. 89 */ 90 std::string GetOrientation() const; 91 92 /** 93 * Get the max number of restart. 94 */ 95 int GetMaxRestartNum(bool isRootLauncher) const; 96 97 /** 98 * Get the interval time after restart out of the max number of restart. 99 */ 100 int GetRestartIntervalTime() const; 101 102 /** 103 * get the application not response process timeout time. 104 */ 105 int GetANRTimeOutTime() const; 106 107 /** 108 * get ability manager service not response process timeout time. 109 */ 110 int GetAMSTimeOutTime() const; 111 112 /** 113 * get boot animation stared timout time. 114 */ 115 int GetBootAnimationTimeoutTime() const; 116 117 /** 118 * get the application cold start timeout time. 119 */ 120 int GetAppStartTimeoutTime() const; 121 122 bool IsSupportBackToCaller() const; 123 124 bool IsSupportSCBCrashReboot() const; 125 126 /** 127 * set picker json object. 128 */ 129 void SetPickerJsonObject(nlohmann::json jsonObject); 130 131 /** 132 * get picker json object. 133 */ 134 nlohmann::json GetPickerJsonObject() const; 135 136 int MultiUserType() const; 137 138 const std::map<std::string, std::string>& GetPickerMap() const; 139 140 bool InResidentWhiteList(const std::string &bundleName) const; 141 const std::vector<std::string> &GetResidentWhiteList() const; 142 143 private: 144 AmsConfigurationParameter(); 145 ~AmsConfigurationParameter() = default; 146 DISALLOW_COPY_AND_MOVE(AmsConfigurationParameter); 147 /** 148 * Read the configuration file of ams 149 * 150 */ 151 int LoadAmsConfiguration(const std::string &filePath); 152 int LoadAppConfigurationForStartUpService(nlohmann::json& Object); 153 int LoadAppConfigurationForMemoryThreshold(nlohmann::json& Object); 154 int LoadSystemConfiguration(nlohmann::json& Object); 155 void LoadPickerConfiguration(nlohmann::json& Object); 156 bool CheckServiceConfigEnable(nlohmann::json& Object, const std::string &configName, JsonValueType type); 157 void UpdateStartUpServiceConfigInteger(nlohmann::json& Object, const std::string &configName, int32_t &value); 158 void UpdateStartUpServiceConfigString(nlohmann::json& Object, const std::string &configName, std::string &value); 159 void UpdatePickerConfigurationString(nlohmann::json& Object, const std::string &configName, std::string &value); 160 void LoadUIExtensionPickerConfig(const std::string &filePath); 161 int32_t LoadBackToCallerConfig(nlohmann::json& Object); 162 int32_t LoadSupportSCBCrashRebootConfig(nlohmann::json& Object); 163 void LoadResidentWhiteListConfig(nlohmann::json& Object); 164 165 private: 166 bool nonConfigFile_ {false}; 167 int maxRootLauncherRestartNum_ = 0; 168 int maxResidentRestartNum_ = 0; 169 int restartIntervalTime_ {120000}; 170 std::string orientation_ {""}; 171 int missionSaveTime_ {12 * 60 * 60 * 1000}; 172 int anrTime_ {5000}; 173 int amsTime_ {5000}; 174 int bootAnimationTime_ {5}; 175 int timeoutUnitTime_ {1000}; 176 std::string bundleName_ {""}; 177 std::string abilityName_ {""}; 178 std::string pickerType_ {""}; 179 nlohmann::json pickerJsonObject_ = nlohmann::json::object(); 180 std::map<std::string, std::string> picker_; 181 int multiUserType_ {0}; 182 bool supportBackToCaller_ {true}; 183 bool supportSceneboardCrashReboot_{true}; 184 std::vector<std::string> residentWhiteList_; 185 }; 186 } // namespace AAFwk 187 } // namespace OHOS 188 #endif // OHOS_ABILITY_RUNTIME_AMS_CONFIGURATION_PARAMETER_H 189