• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 #include "parameter_ex.h"
16 #include <cstdint>
17 
18 #include "parameter.h"
19 #include "parameters.h"
20 #include "sysversion.h"
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 namespace Parameter {
25 namespace {
26 constexpr char DEFAULT_DES[] = "unknown";
27 }
GetString(const std::string & key,const std::string & defaultValue)28 std::string GetString(const std::string& key, const std::string& defaultValue)
29 {
30     return OHOS::system::GetParameter(key, defaultValue);
31 }
32 
GetInteger(const std::string & key,const int64_t defaultValue)33 int64_t GetInteger(const std::string& key, const int64_t defaultValue)
34 {
35     return OHOS::system::GetIntParameter(key, defaultValue);
36 }
37 
GetUnsignedInteger(const std::string & key,const uint64_t defaultValue)38 uint64_t GetUnsignedInteger(const std::string& key, const uint64_t defaultValue)
39 {
40     return OHOS::system::GetUintParameter(key, defaultValue);
41 }
42 
GetBoolean(const std::string & key,const bool defaultValue)43 bool GetBoolean(const std::string& key, const bool defaultValue)
44 {
45     return OHOS::system::GetBoolParameter(key, defaultValue);
46 }
47 
SetProperty(const std::string & key,const std::string & defaultValue)48 bool SetProperty(const std::string& key, const std::string& defaultValue)
49 {
50     return OHOS::system::SetParameter(key, defaultValue);
51 }
52 
WaitParamSync(const char * key,const char * value,int timeout)53 int WaitParamSync(const char *key, const char *value, int timeout)
54 {
55     return WaitParameter(key, value, timeout);
56 }
57 
WatchParamChange(const char * keyPrefix,ParameterChgPtr callback,void * context)58 int WatchParamChange(const char *keyPrefix, ParameterChgPtr callback, void *context)
59 {
60     return WatchParameter(keyPrefix, callback, context);
61 }
62 
GetDisplayVersionStr()63 std::string GetDisplayVersionStr()
64 {
65     static std::string displayedVersionStr = std::string(GetDisplayVersion());
66     return displayedVersionStr;
67 }
68 
IsBetaVersion()69 bool IsBetaVersion()
70 {
71     static bool isBetaVersion = GetString(KEY_HIVIEW_VERSION_TYPE, "unknown").find("beta") != std::string::npos;
72     return isBetaVersion;
73 }
74 
IsDeveloperMode()75 bool IsDeveloperMode()
76 {
77     return GetBoolean(KEY_DEVELOPER_MODE_STATE, false);
78 }
79 
IsLeakStateMode()80 bool IsLeakStateMode()
81 {
82     auto leakState = OHOS::system::GetParameter(KEY_LEAKDECTOR_MODE_STATE, "unknown");
83     return (leakState.find("enable") != std::string::npos);
84 }
85 
IsUCollectionSwitchOn()86 bool IsUCollectionSwitchOn()
87 {
88     std::string ucollectionState = GetString(HIVIEW_UCOLLECTION_STATE, "false");
89     return ucollectionState == "true";
90 }
91 
IsTestAppTraceOn()92 bool IsTestAppTraceOn()
93 {
94     std::string appTraceState = GetString(HIVIEW_UCOLLECTION_TEST_APP_TRACE_STATE, "false");
95     return appTraceState == "true";
96 }
97 
IsTraceCollectionSwitchOn()98 bool IsTraceCollectionSwitchOn()
99 {
100     std::string traceCollectionState = GetString(DEVELOP_HIVIEW_TRACE_RECORDER, "false");
101     return traceCollectionState == "true";
102 }
103 
IsLaboratoryMode()104 bool IsLaboratoryMode()
105 {
106     std::string laboratoryState = GetString(KEY_LABORATORY_MODE_STATE, "");
107     return laboratoryState == "reliability";
108 }
109 
GetDeviceTypeStr()110 std::string GetDeviceTypeStr()
111 {
112     static std::string deviceType = OHOS::system::GetDeviceType();
113     return deviceType;
114 }
115 
GetBrandStr()116 std::string GetBrandStr()
117 {
118     static std::string brandStr = std::string(GetBrand());
119     return brandStr;
120 }
121 
GetManufactureStr()122 std::string GetManufactureStr()
123 {
124     static std::string manufactureStr = std::string(GetManufacture());
125     return manufactureStr;
126 }
127 
GetMarketNameStr()128 std::string GetMarketNameStr()
129 {
130     static std::string marketNameStr = std::string(GetMarketName());
131     return marketNameStr;
132 }
133 
GetDeviceModelStr()134 std::string GetDeviceModelStr()
135 {
136     std::string displayedVersionStr = std::string(GetDisplayVersion());
137     auto pos = displayedVersionStr.find(' ');
138     if (pos == displayedVersionStr.npos) {
139         return DEFAULT_DES;
140     }
141     return displayedVersionStr.substr(0, pos);
142 }
143 
GetSysVersionStr()144 std::string GetSysVersionStr()
145 {
146     std::string displayedVersionStr = Parameter::GetDisplayVersionStr();
147     auto pos = displayedVersionStr.find(' ');
148     if (pos == displayedVersionStr.npos) {
149         return displayedVersionStr;
150     }
151     return displayedVersionStr.substr(pos + 1, displayedVersionStr.size());
152 }
153 
GetDistributionOsVersionStr()154 std::string GetDistributionOsVersionStr()
155 {
156     static std::string osVersion = std::string(GetDistributionOSVersion());
157     return osVersion;
158 }
159 
GetProductModelStr()160 std::string GetProductModelStr()
161 {
162     static std::string productModelStr = std::string(GetProductModel());
163     return productModelStr;
164 }
165 
GetSysVersionDetailsStr()166 std::string GetSysVersionDetailsStr()
167 {
168     std::string sysVersionDetails = std::to_string(GetMajorVersion());
169     sysVersionDetails += ".";
170     sysVersionDetails += std::to_string(GetSeniorVersion());
171     sysVersionDetails += ".";
172     sysVersionDetails += std::to_string(GetFeatureVersion());
173     return sysVersionDetails;
174 }
175 
GetVersionStr()176 std::string GetVersionStr()
177 {
178     return IsBetaVersion() ? "Beta" : "Commercial";
179 }
180 
GetRegionCode()181 int32_t GetRegionCode()
182 {
183     constexpr int32_t defaultCode = 156;
184     return defaultCode;
185 }
186 } // namespace Parameter
187 } // namespace HiviewDFX
188 } // namespace OHOS
189