• 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 #include "nocopyable.h"
22 
23 namespace OHOS {
24 namespace AAFwk {
25 namespace AmsConfig {
26 constexpr const char* AMS_CONFIG_FILE_PATH = "/system/etc/ams_service_config.json";
27 constexpr const char* SERVICE_ITEM_AMS = "service_startup_config";
28 constexpr const char* MISSION_SAVE_TIME = "mission_save_time";
29 constexpr const char* APP_NOT_RESPONSE_PROCESS_TIMEOUT_TIME = "app_not_response_process_timeout_time";
30 constexpr const char* AMS_TIMEOUT_TIME = "ams_timeout_time";
31 constexpr const char* DEVICE_TYPE = "device_type";
32 constexpr const char* SYSTEM_CONFIGURATION = "system_configuration";
33 constexpr const char* SYSTEM_ORIENTATION = "system_orientation";
34 constexpr const char* ROOT_LAUNCHER_RESTART_MAX = "root_launcher_restart_max";
35 constexpr const char* RESIDENT_RESTART_MAX = "resident_restart_max";
36 constexpr const char* RESTART_INTERVAL_TIME = "restart_interval_time";
37 constexpr const char* BOOT_ANIMATION_TIMEOUT_TIME = "boot_animation_timeout_time";
38 constexpr const char* TIMEOUT_UNIT_TIME = "timeout_unit_time";
39 }  // namespace AmsConfig
40 
41 enum class SatrtUiMode { STATUSBAR = 1, NAVIGATIONBAR = 2, STARTUIBOTH = 3 };
42 
43 class AmsConfigurationParameter final {
44 public:
45     static AmsConfigurationParameter &GetInstance();
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     /**
97      * get the application cold start timeout time.
98      */
99     int GetAppStartTimeoutTime() const;
100 
101     enum { READ_OK = 0, READ_FAIL = 1, READ_JSON_FAIL = 2 };
102 
103 private:
104     AmsConfigurationParameter() = default;
105     ~AmsConfigurationParameter() = default;
106     DISALLOW_COPY_AND_MOVE(AmsConfigurationParameter);
107     /**
108      * Read the configuration file of ams
109      *
110      */
111     int LoadAmsConfiguration(const std::string &filePath);
112     int LoadAppConfigurationForStartUpService(nlohmann::json& Object);
113     int LoadAppConfigurationForMemoryThreshold(nlohmann::json& Object);
114     int LoadSystemConfiguration(nlohmann::json& Object);
115 
116 private:
117     bool nonConfigFile_ {false};
118     int maxRootLauncherRestartNum_ = 0;
119     int maxResidentRestartNum_ = 0;
120     int restartIntervalTime_ {120000};
121     std::string orientation_ {""};
122     int missionSaveTime_ {12 * 60 * 60 * 1000};
123     int anrTime_ {5000};
124     int amsTime_ {5000};
125     int bootAnimationTime_ {5};
126     std::string deviceType_ {""};
127     int timeoutUnitTime_ {1000};
128 };
129 }  // namespace AAFwk
130 }  // namespace OHOS
131 #endif  // OHOS_ABILITY_RUNTIME_AMS_CONFIGURATION_PARAMETER_H
132