• 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 
16 #include "base/utils/system_properties.h"
17 
18 #include "base/log/log.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 
23 constexpr int32_t ORIENTATION_PORTRAIT = 0;
24 constexpr int32_t ORIENTATION_LANDSCAPE = 1;
25 const char PROPERTY_DEVICE_TYPE_PHONE[] = "phone";
26 const char PROPERTY_DEVICE_TYPE_TV[] = "tv";
27 const char PROPERTY_DEVICE_TYPE_TABLET[] = "tablet";
28 const char PROPERTY_DEVICE_TYPE_WEARABLE[] = "wearable";
29 const char PROPERTY_DEVICE_TYPE_CAR[] = "car";
30 
31 static constexpr char UNDEFINED_PARAM[] = "undefined parameter";
32 
Swap(int32_t & deviceWidth,int32_t & deviceHeight)33 void Swap(int32_t& deviceWidth, int32_t& deviceHeight)
34 {
35     int32_t temp = deviceWidth;
36     deviceWidth = deviceHeight;
37     deviceHeight = temp;
38 }
39 
40 } // namespace
41 
InitDeviceType(DeviceType type)42 void SystemProperties::InitDeviceType(DeviceType type)
43 {
44     // Properties: "phone", "tv", "tablet", "watch", "car"
45     if (type == DeviceType::TV) {
46         deviceType_ = DeviceType::TV;
47         paramDeviceType_ = PROPERTY_DEVICE_TYPE_TV;
48     } else if (type == DeviceType::WATCH) {
49         deviceType_ = DeviceType::WATCH;
50         paramDeviceType_ = PROPERTY_DEVICE_TYPE_WEARABLE;
51     } else if (type == DeviceType::CAR) {
52         deviceType_ = DeviceType::CAR;
53         paramDeviceType_ = PROPERTY_DEVICE_TYPE_CAR;
54     } else if (type == DeviceType::TABLET) {
55         deviceType_ = DeviceType::TABLET;
56         paramDeviceType_ = PROPERTY_DEVICE_TYPE_TABLET;
57     } else {
58         deviceType_ = DeviceType::PHONE;
59         paramDeviceType_ = PROPERTY_DEVICE_TYPE_PHONE;
60     }
61 }
62 
63 bool SystemProperties::traceEnabled_ = false;
64 bool SystemProperties::svgTraceEnable_ = false;
65 bool SystemProperties::accessibilityEnabled_ = false;
66 bool SystemProperties::isRound_ = false;
67 bool SystemProperties::isDeviceAccess_ = false;
68 int32_t SystemProperties::deviceWidth_ = 0;
69 int32_t SystemProperties::deviceHeight_ = 0;
70 double SystemProperties::resolution_ = 1.0;
71 DeviceType SystemProperties::deviceType_ { DeviceType::PHONE };
72 DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
73 std::string SystemProperties::brand_ = UNDEFINED_PARAM;
74 std::string SystemProperties::manufacturer_ = UNDEFINED_PARAM;
75 std::string SystemProperties::model_ = UNDEFINED_PARAM;
76 std::string SystemProperties::product_ = UNDEFINED_PARAM;
77 std::string SystemProperties::apiVersion_ = "9";
78 std::string SystemProperties::releaseType_ = UNDEFINED_PARAM;
79 std::string SystemProperties::paramDeviceType_ = UNDEFINED_PARAM;
80 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
81 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
82 ColorMode SystemProperties::colorMode_ = ColorMode::LIGHT;
83 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
84 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
85 bool SystemProperties::unZipHap_ = true;
86 #ifndef ENABLE_ROSEN_BACKEND
87 bool SystemProperties::rosenBackendEnabled_ = false;
88 #else
89 bool SystemProperties::rosenBackendEnabled_ = true;
90 #endif
91 bool SystemProperties::windowAnimationEnabled_ = false;
92 bool SystemProperties::debugBoundaryEnabled_ = false;
93 bool SystemProperties::gpuUploadEnabled_ = false;
94 bool SystemProperties::isHookModeEnabled_ = false;
95 bool SystemProperties::astcEnabled_ = false;
96 int SystemProperties::astcMax_ = 0;
97 int SystemProperties::astcPsnr_ = 0;
98 bool SystemProperties::extSurfaceEnabled_ = false;
99 
GetDeviceType()100 DeviceType SystemProperties::GetDeviceType()
101 {
102     return deviceType_;
103 }
104 
IsSyscapExist(const char * cap)105 bool SystemProperties::IsSyscapExist(const char* cap)
106 {
107     return false;
108 }
109 
InitDeviceTypeBySystemProperty()110 void SystemProperties::InitDeviceTypeBySystemProperty()
111 {
112     deviceType_ = DeviceType::PHONE;
113 }
114 
InitDeviceInfo(int32_t deviceWidth,int32_t deviceHeight,int32_t orientation,double resolution,bool isRound)115 void SystemProperties::InitDeviceInfo(
116     int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
117 {
118     // SetDeviceOrientation should be eralier than deviceWidth/deviceHeight init.
119     if (orientation == ORIENTATION_PORTRAIT) {
120         orientation_ = DeviceOrientation::PORTRAIT;
121     } else if (orientation == ORIENTATION_LANDSCAPE) {
122         orientation_ = DeviceOrientation::LANDSCAPE;
123     } else {
124         LOGW("SetDeviceOrientation, undefined orientation");
125     }
126 
127     isRound_ = isRound;
128     resolution_ = resolution;
129     deviceWidth_ = deviceWidth;
130     deviceHeight_ = deviceHeight;
131     if (isRound_) {
132         screenShape_ = ScreenShape::ROUND;
133     } else {
134         screenShape_ = ScreenShape::NOT_ROUND;
135     }
136 }
137 
SetDeviceOrientation(int32_t orientation)138 void SystemProperties::SetDeviceOrientation(int32_t orientation)
139 {
140     if (orientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
141         Swap(deviceWidth_, deviceHeight_);
142         orientation_ = DeviceOrientation::PORTRAIT;
143     } else if (orientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
144         Swap(deviceWidth_, deviceHeight_);
145         orientation_ = DeviceOrientation::LANDSCAPE;
146     } else {
147         LOGI("SetDeviceOrientation, no change info: %{public}d", orientation);
148     }
149 }
150 
GetFontWeightScale()151 float SystemProperties::GetFontWeightScale()
152 {
153     return 1.0f;
154 }
155 
InitMccMnc(int32_t mcc,int32_t mnc)156 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
157 {
158     mcc_ = mcc;
159     mnc_ = mnc;
160 }
161 
IsScoringEnabled(const std::string & name)162 bool SystemProperties::IsScoringEnabled(const std::string& name)
163 {
164     return false;
165 }
166 
GetDebugEnabled()167 bool SystemProperties::GetDebugEnabled()
168 {
169     return false;
170 }
171 
GetLanguage()172 std::string SystemProperties::GetLanguage()
173 {
174     return UNDEFINED_PARAM;
175 }
176 
GetRegion()177 std::string SystemProperties::GetRegion()
178 {
179     return UNDEFINED_PARAM;
180 }
181 
GetPartialUpdatePkg()182 std::string SystemProperties::GetPartialUpdatePkg()
183 {
184     // TODO: add support for pc preview.
185     return "";
186 }
187 
GetNewPipePkg()188 std::string SystemProperties::GetNewPipePkg()
189 {
190     // TODO: add support for pc preview.
191     return "";
192 }
193 
GetSvgMode()194 int32_t SystemProperties::GetSvgMode()
195 {
196     return 1;
197 }
198 
199 } // namespace OHOS::Ace
200