• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 
21 namespace OHOS {
22 namespace HiviewDFX {
23 namespace Parameter {
GetString(const std::string & key,const std::string & defaultValue)24 std::string GetString(const std::string& key, const std::string& defaultValue)
25 {
26     return OHOS::system::GetParameter(key, defaultValue);
27 }
28 
GetInteger(const std::string & key,const int64_t defaultValue)29 int64_t GetInteger(const std::string& key, const int64_t defaultValue)
30 {
31     return OHOS::system::GetIntParameter(key, defaultValue);
32 }
33 
GetUnsignedInteger(const std::string & key,const uint64_t defaultValue)34 uint64_t GetUnsignedInteger(const std::string& key, const uint64_t defaultValue)
35 {
36     return OHOS::system::GetUintParameter(key, defaultValue);
37 }
38 
GetBoolean(const std::string & key,const bool defaultValue)39 bool GetBoolean(const std::string& key, const bool defaultValue)
40 {
41     return OHOS::system::GetBoolParameter(key, defaultValue);
42 }
43 
SetProperty(const std::string & key,const std::string & defaultValue)44 bool SetProperty(const std::string& key, const std::string& defaultValue)
45 {
46     return OHOS::system::SetParameter(key, defaultValue);
47 }
48 
WaitParamSync(const char * key,const char * value,int timeout)49 int WaitParamSync(const char *key, const char *value, int timeout)
50 {
51     return WaitParameter(key, value, timeout);
52 }
53 
IsBetaVersion()54 bool IsBetaVersion()
55 {
56     auto versionType = GetString(KEY_HIVIEW_VERSION_TYPE, "unknown");
57     return (versionType.find("beta") != std::string::npos);
58 }
59 
GetDeviceType()60 DeviceType GetDeviceType()
61 {
62     std::string deviceType = GetString(KEY_BUILD_CHARACTER, "unknown");
63     if (deviceType == "phone" || deviceType == "default") {
64         return DeviceType::PHONE;
65     } else if (deviceType == "watch") {
66         return DeviceType::WATCH;
67     } else if (deviceType == "tv") {
68         return DeviceType::TV;
69     } else if (deviceType == "car") {
70         return DeviceType::IVI;
71     } else {
72         return DeviceType::UNKNOWN;
73     }
74 }
75 } // namespace Parameter
76 } // namespace HiviewDFX
77 } // namespace OHOS
78