• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 }  // namespace AmsConfig
38 
39 enum class SatrtUiMode { STATUSBAR = 1, NAVIGATIONBAR = 2, STARTUIBOTH = 3 };
40 
41 class AmsConfigurationParameter final {
42 public:
43     AmsConfigurationParameter() = default;
44     ~AmsConfigurationParameter() = default;
45     /**
46      * return true : ams no config file
47      * return false : ams have config file
48      */
49     bool NonConfigFile() const;
50     /**
51      * Get profile information
52      */
53     void Parse();
54 
55     /**
56      * Get the save time of the current content
57      */
58     int GetMissionSaveTime() const;
59 
60     /**
61      * Get current system direction parameters, Temporary method.
62      */
63     std::string GetOrientation() const;
64 
65     /**
66      * Get the max number of restart.
67      */
68     int GetMaxRestartNum(bool isRootLauncher) const;
69 
70     /**
71      * Get the interval time after restart out of the max number of restart.
72      */
73     int GetRestartIntervalTime() const;
74 
75     /**
76      * get the application not response process timeout time.
77      */
78     int GetANRTimeOutTime() const;
79 
80     /**
81      * get ability manager service not response process timeout time.
82      */
83     int GetAMSTimeOutTime() const;
84 
85     /**
86      * get device type.
87      */
88     std::string GetDeviceType() const;
89 
90     /**
91      * get boot animation stared timout time.
92      */
93     int GetBootAnimationTimeoutTime() const;
94 
95     enum { READ_OK = 0, READ_FAIL = 1, READ_JSON_FAIL = 2 };
96 
97 private:
98     /**
99      * Read the configuration file of ams
100      *
101      */
102     int LoadAmsConfiguration(const std::string &filePath);
103     int LoadAppConfigurationForStartUpService(nlohmann::json& Object);
104     int LoadAppConfigurationForMemoryThreshold(nlohmann::json& Object);
105     int LoadSystemConfiguration(nlohmann::json& Object);
106 
107 private:
108     bool nonConfigFile_ {false};
109     int maxRootLauncherRestartNum_ = 0;
110     int maxResidentRestartNum_ = 0;
111     int restartIntervalTime_ {120000};
112     std::string orientation_ {""};
113     int missionSaveTime_ {12 * 60 * 60 * 1000};
114     int anrTime_ {5000};
115     int amsTime_ {5000};
116     int bootAnimationTime_ {5};
117     std::string deviceType_ {""};
118 };
119 }  // namespace AAFwk
120 }  // namespace OHOS
121 #endif  // OHOS_ABILITY_RUNTIME_AMS_CONFIGURATION_PARAMETER_H
122