1 /*
2  * Copyright (c) 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 
16 #include "ge_system_properties.h"
17 
18 namespace OHOS {
19 namespace Rosen {
20 
GetEventProperty(const std::string & paraName)21 std::string GESystemProperties::GetEventProperty(const std::string& paraName)
22 {
23 #ifdef GE_OHOS
24     return system::GetParameter(paraName, "0");
25 #else
26     return "";
27 #endif
28 }
29 
GetBoolSystemProperty(const char * name,bool defaultValue)30 bool GESystemProperties::GetBoolSystemProperty(const char* name, bool defaultValue)
31 {
32 #ifdef GE_OHOS
33     static CachedHandle g_Handle = CachedParameterCreate(name, defaultValue ? "1" : "0");
34     int changed = 0;
35     const char* enable = CachedParameterGetChanged(g_Handle, &changed);
36     return ConvertToInt(enable, defaultValue ? 1 : 0) != 0;
37 #else
38     return false;
39 #endif
40 }
41 
ConvertToInt(const char * originValue,int defaultValue)42 int GESystemProperties::ConvertToInt(const char* originValue, int defaultValue)
43 {
44     return originValue == nullptr ? defaultValue : std::atoi(originValue);
45 }
46 
47 } // namespace Rosen
48 } // namespace OHOS
49