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