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* SUPPORT_AA_KILL_WITH_REASON = "supportAAKillWithReason"; 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 bool IsSupportAAKillWithReason() const; 127 128 /** 129 * set picker json object. 130 */ 131 void SetPickerJsonObject(nlohmann::json jsonObject); 132 133 /** 134 * get picker json object. 135 */ 136 nlohmann::json GetPickerJsonObject() const; 137 138 int MultiUserType() const; 139 140 const std::map<std::string, std::string>& GetPickerMap() const; 141 142 private: 143 AmsConfigurationParameter(); 144 ~AmsConfigurationParameter() = default; 145 DISALLOW_COPY_AND_MOVE(AmsConfigurationParameter); 146 /** 147 * Read the configuration file of ams 148 * 149 */ 150 int LoadAmsConfiguration(const std::string &filePath); 151 int LoadAppConfigurationForStartUpService(nlohmann::json& Object); 152 int LoadAppConfigurationForMemoryThreshold(nlohmann::json& Object); 153 int LoadSystemConfiguration(nlohmann::json& Object); 154 void LoadPickerConfiguration(nlohmann::json& Object); 155 bool CheckServiceConfigEnable(nlohmann::json& Object, const std::string &configName, JsonValueType type); 156 void UpdateStartUpServiceConfigInteger(nlohmann::json& Object, const std::string &configName, int32_t &value); 157 void UpdateStartUpServiceConfigString(nlohmann::json& Object, const std::string &configName, std::string &value); 158 void UpdatePickerConfigurationString(nlohmann::json& Object, const std::string &configName, std::string &value); 159 void LoadUIExtensionPickerConfig(const std::string &filePath); 160 int32_t LoadBackToCallerConfig(nlohmann::json& Object); 161 int32_t LoadSupportAAKillWithReasonConfig(nlohmann::json& Object); 162 int32_t LoadSupportSCBCrashRebootConfig(nlohmann::json& Object); 163 164 private: 165 bool nonConfigFile_ {false}; 166 bool supportBackToCaller_ {true}; 167 bool supportSceneboardCrashReboot_{true}; 168 bool supportAAKillWithReason_{false}; 169 170 int maxRootLauncherRestartNum_ = 0; 171 int maxResidentRestartNum_ = 0; 172 int restartIntervalTime_ {120000}; 173 int missionSaveTime_ {12 * 60 * 60 * 1000}; 174 int anrTime_ {5000}; 175 int amsTime_ {5000}; 176 int bootAnimationTime_ {5}; 177 int timeoutUnitTime_ {1000}; 178 int multiUserType_ {0}; 179 180 std::string orientation_ {""}; 181 std::string bundleName_ {""}; 182 std::string abilityName_ {""}; 183 std::string pickerType_ {""}; 184 std::map<std::string, std::string> picker_; 185 nlohmann::json pickerJsonObject_ = nlohmann::json::object(); 186 }; 187 } // namespace AAFwk 188 } // namespace OHOS 189 #endif // OHOS_ABILITY_RUNTIME_AMS_CONFIGURATION_PARAMETER_H 190