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 <nlohmann/json.hpp> 21 22 namespace OHOS { 23 namespace AAFwk { 24 namespace AmsConfig { 25 constexpr const char* AMS_CONFIG_FILE_PATH = "/system/etc/ams_service_config.json"; 26 constexpr const char* SERVICE_ITEM_AMS = "service_startup_config"; 27 constexpr const char* MISSION_SAVE_TIME = "mission_save_time"; 28 constexpr const char* APP_NOT_RESPONSE_PROCESS_TIMEOUT_TIME = "app_not_response_process_timeout_time"; 29 constexpr const char* AMS_TIMEOUT_TIME = "ams_timeout_time"; 30 constexpr const char* DEVICE_TYPE = "device_type"; 31 constexpr const char* SYSTEM_CONFIGURATION = "system_configuration"; 32 constexpr const char* SYSTEM_ORIENTATION = "system_orientation"; 33 constexpr const char* ROOT_LAUNCHER_RESTART_MAX = "root_launcher_restart_max"; 34 constexpr const char* RESIDENT_RESTART_MAX = "resident_restart_max"; 35 constexpr const char* RESTART_INTERVAL_TIME = "restart_interval_time"; 36 constexpr const char* BOOT_ANIMATION_TIMEOUT_TIME = "boot_animation_timeout_time"; 37 constexpr const char* APP_NOT_RESPONSE_HANDLE_TYPE = "anr_handle_type"; 38 } // namespace AmsConfig 39 40 enum class SatrtUiMode { STATUSBAR = 1, NAVIGATIONBAR = 2, STARTUIBOTH = 3 }; 41 42 class AmsConfigurationParameter final { 43 public: 44 AmsConfigurationParameter() = default; 45 ~AmsConfigurationParameter() = default; 46 /** 47 * return true : ams no config file 48 * return false : ams have config file 49 */ 50 bool NonConfigFile() const; 51 /** 52 * Get profile information 53 */ 54 void Parse(); 55 56 /** 57 * Get the save time of the current content 58 */ 59 int GetMissionSaveTime() const; 60 61 /** 62 * Get current system direction parameters, Temporary method. 63 */ 64 std::string GetOrientation() const; 65 66 /** 67 * Get the max number of restart. 68 */ 69 int GetMaxRestartNum(bool isRootLauncher) const; 70 71 /** 72 * Get the interval time after restart out of the max number of restart. 73 */ 74 int GetRestartIntervalTime() const; 75 76 /** 77 * get the application not response process timeout time. 78 */ 79 int GetANRTimeOutTime() const; 80 81 /** 82 * get ability manager service not response process timeout time. 83 */ 84 int GetAMSTimeOutTime() const; 85 86 /** 87 * get device type. 88 */ 89 std::string GetDeviceType() const; 90 91 /** 92 * get boot animation stared timout time. 93 */ 94 int GetBootAnimationTimeoutTime() const; 95 96 int GetAnrHandleType() const; 97 98 enum { READ_OK = 0, READ_FAIL = 1, READ_JSON_FAIL = 2 }; 99 100 private: 101 /** 102 * Read the configuration file of ams 103 * 104 */ 105 int LoadAmsConfiguration(const std::string &filePath); 106 int LoadAppConfigurationForStartUpService(nlohmann::json& Object); 107 int LoadAppConfigurationForMemoryThreshold(nlohmann::json& Object); 108 int LoadSystemConfiguration(nlohmann::json& Object); 109 110 private: 111 bool nonConfigFile_ {false}; 112 int maxRootLauncherRestartNum_ = 0; 113 int maxResidentRestartNum_ = 0; 114 int restartIntervalTime_ {120000}; 115 std::string orientation_ {""}; 116 int missionSaveTime_ {12 * 60 * 60 * 1000}; 117 int anrTime_ {5000}; 118 int amsTime_ {5000}; 119 int bootAnimationTime_ {5}; 120 int anrHandleType_ {0}; 121 std::string deviceType_ {""}; 122 }; 123 } // namespace AAFwk 124 } // namespace OHOS 125 #endif // OHOS_ABILITY_RUNTIME_AMS_CONFIGURATION_PARAMETER_H 126