• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_AAFWK_AMS_CONFIGURATION_PARAMETER_H
17 #define OHOS_AAFWK_AMS_CONFIGURATION_PARAMETER_H
18 
19 #include <fstream>
20 #include <nlohmann/json.hpp>
21 
22 namespace OHOS {
23 namespace AAFwk {
24 namespace AmsConfig {
25 namespace MemThreshold {
26 const std::string HOME_APP("home_application");
27 }
28 const std::string AMS_CONFIG_FILE_PATH {"/system/etc/ams_service_config.json"};
29 const std::string SERVICE_ITEM_AMS {"service_startup_config"};
30 const std::string STARTUP_SETTINGS_DATA {"startup_settings_data"};
31 const std::string STARTUP_SCREEN_LOCK {"startup_screen_lock"};
32 const std::string STARTUP_STATUS_BAR {"startup_system_ui_status_bar"};
33 const std::string STARTUP_NAVIGATION_BAR {"startup_system_ui_navigation_bar"};
34 const std::string STARTUP_PHONE_SERVICE {"startup_phone_service"};
35 const std::string MISSION_SAVE_TIME {"mission_save_time"};
36 const std::string APP_NOT_RESPONSE_PROCESS_TIMEOUT_TIME {"app_not_response_process_timeout_time"};
37 const std::string AMS_TIMEOUT_TIME {"ams_timeout_time"};
38 const std::string SYSTEM_CONFIGURATION {"system_configuration"};
39 const std::string SYSTEM_ORIENTATION {"system_orientation"};
40 const std::string STARTUP_MMS {"startup_mms"};
41 const std::string USE_NEW_MISSION {"use_new_mission"};
42 const std::string ROOT_LAUNCHER_RESTART_MAX {"root_launcher_restart_max"};
43 }  // namespace AmsConfig
44 
45 enum class SatrtUiMode { STATUSBAR = 1, NAVIGATIONBAR = 2, STARTUIBOTH = 3 };
46 
47 class AmsConfigurationParameter final {
48 public:
49     AmsConfigurationParameter() = default;
50     ~AmsConfigurationParameter() = default;
51     /**
52      * return true : ams no config file
53      * return false : ams have config file
54      */
55     bool NonConfigFile() const;
56     /**
57      * return true : ams can start settings data
58      * return false : ams do not start settings data
59      */
60     bool GetStartSettingsDataState() const;
61     /**
62      * return true : ams can start screen lock
63      * return false : ams do not start screen lock
64      */
65     bool GetStartScreenLockState() const;
66     /**
67      * return true : ams can start system ui status bar
68      * return false : ams do not start system ui status bar
69      */
70     bool GetStatusBarState() const;
71     /**
72      * return true : ams can start system ui navigation bar
73      * return false : ams do not start system ui navigation bar
74      */
75     bool GetNavigationBarState() const;
76     /**
77      * return true : ams can start phone service
78      * return false : ams do not start phone service
79      */
80     bool GetPhoneServiceState() const;
81     /**
82      * return true : ams can start mms
83      * return false : ams do not start mms
84      */
85     bool GetStartMmsState() const;
86     /**
87      * Get profile information
88      */
89     void Parse();
90     /**
91      * The low memory threshold under which the system will kill background processes
92      */
93     int GetMemThreshold(const std::string &key);
94     /**
95      * Get the save time of the current content
96      */
97     int GetMissionSaveTime() const;
98     /**
99      * Get current system direction parameters, Temporary method.
100      */
101     std::string GetOrientation() const;
102     /**
103      * check if use new mission.
104      *
105      * return true if use mission list, false if use mission stack.
106      */
107     bool IsUseNewMission() const;
108     /**
109      * Get the max number of restart.
110      */
111     int GetMaxRestartNum() const;
112     /**
113      * get the application not response process timeout time.
114      */
115     int GetANRTimeOutTime() const;
116     /**
117      * get ability manager service not response process timeout time.
118      */
119     int GetAMSTimeOutTime() const;
120 
121     enum { READ_OK = 0, READ_FAIL = 1, READ_JSON_FAIL = 2 };
122 
123 private:
124     /**
125      * Read the configuration file of ams
126      *
127      */
128     int LoadAmsConfiguration(const std::string &filePath);
129     int LoadAppConfigurationForStartUpService(nlohmann::json& Object);
130     int LoadAppConfigurationForMemoryThreshold(nlohmann::json& Object);
131     int LoadSystemConfiguration(nlohmann::json& Object);
132 
133 private:
134     bool nonConfigFile_ {false};
135     bool canStartSettingsData_ {false};
136     bool canStartScreenLock_ {false};
137     bool canStartUiStatusBar_ {false};
138     bool canStartUiNavigationBar_ {false};
139     bool canStartPhoneService_ {false};
140     bool canStartMms {false};
141     bool useNewMission_ {false};
142     int maxRestartNum_ = 0;
143     std::string orientation_ {""};
144     int missionSaveTime_ {12 * 60 * 60 * 1000};
145     int anrTime_ {5000};
146     int amsTime_ {5000};
147     std::map<std::string, std::string> memThreshold_;
148 };
149 }  // namespace AAFwk
150 }  // namespace OHOS
151 #endif  // OHOS_AAFWK_AMS_CONFIGURATION_PARAMETER_H
152