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 constexpr int32_t ORIENTATION_PORTRAIT = 0;
23 constexpr int32_t ORIENTATION_LANDSCAPE = 1;
24 constexpr char PROPERTY_DEVICE_TYPE_PHONE[] = "phone";
25 constexpr char PROPERTY_DEVICE_TYPE_TV[] = "tv";
26 constexpr char PROPERTY_DEVICE_TYPE_TABLET[] = "tablet";
27 constexpr char PROPERTY_DEVICE_TYPE_TWO_IN_ONE[] = "2in1";
28 constexpr char PROPERTY_DEVICE_TYPE_WEARABLE[] = "wearable";
29 constexpr 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 } // namespace
40 
41 bool SystemProperties::svgTraceEnable_ = false;
42 bool SystemProperties::developerModeOn_ = false;
43 std::atomic<bool> SystemProperties::layoutTraceEnable_(false);
44 std::atomic<bool> SystemProperties::traceInputEventEnable_(false);
45 std::atomic<bool> SystemProperties::stateManagerEnable_(false);
46 bool SystemProperties::buildTraceEnable_ = false;
47 bool SystemProperties::syncDebugTraceEnable_ = false;
48 bool SystemProperties::pixelRoundEnable_ = true;
49 bool SystemProperties::textTraceEnable_ = false;
50 bool SystemProperties::syntaxTraceEnable_ = false;
51 bool SystemProperties::accessTraceEnable_ = false;
52 bool SystemProperties::accessibilityEnabled_ = false;
53 bool SystemProperties::isRound_ = false;
54 bool SystemProperties::isDeviceAccess_ = false;
55 int32_t SystemProperties::deviceWidth_ = 0;
56 int32_t SystemProperties::deviceHeight_ = 0;
57 int32_t SystemProperties::devicePhysicalWidth_ = 0;
58 int32_t SystemProperties::devicePhysicalHeight_ = 0;
59 double SystemProperties::resolution_ = 1.0;
60 DeviceType SystemProperties::deviceType_ { DeviceType::PHONE };
61 DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
62 std::string SystemProperties::brand_ = UNDEFINED_PARAM;
63 std::string SystemProperties::manufacturer_ = UNDEFINED_PARAM;
64 std::string SystemProperties::model_ = UNDEFINED_PARAM;
65 std::string SystemProperties::product_ = UNDEFINED_PARAM;
66 std::string SystemProperties::apiVersion_ = "9";
67 std::string SystemProperties::releaseType_ = UNDEFINED_PARAM;
68 std::string SystemProperties::paramDeviceType_ = UNDEFINED_PARAM;
69 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
70 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
71 ColorMode SystemProperties::colorMode_ = ColorMode::LIGHT;
72 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
73 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
74 bool SystemProperties::unZipHap_ = true;
75 bool SystemProperties::windowAnimationEnabled_ = false;
76 std::atomic<bool> SystemProperties::debugBoundaryEnabled_(false);
77 bool SystemProperties::debugAutoUIEnabled_ = false;
78 bool SystemProperties::debugOffsetLogEnabled_ = false;
79 bool SystemProperties::downloadByNetworkEnabled_ = false;
80 bool SystemProperties::gpuUploadEnabled_ = false;
81 bool SystemProperties::isHookModeEnabled_ = false;
82 bool SystemProperties::astcEnabled_ = false;
83 int SystemProperties::astcMax_ = 0;
84 int SystemProperties::astcPsnr_ = 0;
85 bool SystemProperties::imageFileCacheConvertAstc_ = false;
86 int32_t SystemProperties::imageFileCacheConvertAstcThreshold_ = 2;
87 bool SystemProperties::extSurfaceEnabled_ = false;
88 uint32_t SystemProperties::dumpFrameCount_ = 0;
89 bool SystemProperties::resourceDecoupling_ = true;
90 #ifndef ENABLE_ROSEN_BACKEND
91 bool SystemProperties::rosenBackendEnabled_ = false;
92 #else
93 bool SystemProperties::rosenBackendEnabled_ = true;
94 #endif
95 bool SystemProperties::enableScrollableItemPool_ = false;
96 bool SystemProperties::navigationBlurEnabled_ = true;
97 bool SystemProperties::gridCacheEnabled_ = false;
98 bool SystemProperties::sideBarContainerBlurEnable_ = false;
99 std::atomic<bool> SystemProperties::acePerformanceMonitorEnable_(false);
100 bool SystemProperties::aceCommercialLogEnable_ = false;
101 std::pair<float, float> SystemProperties::brightUpPercent_ = {};
102 bool SystemProperties::faultInjectEnabled_ = false;
103 bool SystemProperties::imageFrameworkEnable_ = false;
104 float SystemProperties::dragStartDampingRatio_ = 0.2f;
105 float SystemProperties::dragStartPanDisThreshold_ = 10.0f;
106 uint32_t SystemProperties::canvasDebugMode_ = 0;
107 
IsOpIncEnable()108 bool SystemProperties::IsOpIncEnable()
109 {
110     return false;
111 }
112 
InitDeviceType(DeviceType type)113 void SystemProperties::InitDeviceType(DeviceType type)
114 {
115     // Properties: "phone", "tv", "tablet", "watch", "car"
116     if (type == DeviceType::TV) {
117         deviceType_ = DeviceType::TV;
118         paramDeviceType_ = PROPERTY_DEVICE_TYPE_TV;
119     } else if (type == DeviceType::WATCH) {
120         deviceType_ = DeviceType::WATCH;
121         paramDeviceType_ = PROPERTY_DEVICE_TYPE_WEARABLE;
122     } else if (type == DeviceType::CAR) {
123         deviceType_ = DeviceType::CAR;
124         paramDeviceType_ = PROPERTY_DEVICE_TYPE_CAR;
125     } else if (type == DeviceType::TABLET) {
126         deviceType_ = DeviceType::TABLET;
127         paramDeviceType_ = PROPERTY_DEVICE_TYPE_TABLET;
128     } else if (type == DeviceType::TWO_IN_ONE) {
129         deviceType_ = DeviceType::TWO_IN_ONE;
130         paramDeviceType_ = PROPERTY_DEVICE_TYPE_TWO_IN_ONE;
131     } else {
132         deviceType_ = DeviceType::PHONE;
133         paramDeviceType_ = PROPERTY_DEVICE_TYPE_PHONE;
134     }
135 }
136 
GetDeviceType()137 DeviceType SystemProperties::GetDeviceType()
138 {
139     return deviceType_;
140 }
141 
IsSyscapExist(const char* cap)142 bool SystemProperties::IsSyscapExist(const char* cap)
143 {
144     return false;
145 }
146 
InitDeviceTypeBySystemProperty()147 void SystemProperties::InitDeviceTypeBySystemProperty()
148 {
149     deviceType_ = DeviceType::PHONE;
150 }
151 
InitDeviceInfo( int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)152 void SystemProperties::InitDeviceInfo(
153     int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
154 {
155     // SetDeviceOrientation should be eralier than deviceWidth/deviceHeight init.
156     if (orientation == ORIENTATION_PORTRAIT) {
157         orientation_ = DeviceOrientation::PORTRAIT;
158     } else if (orientation == ORIENTATION_LANDSCAPE) {
159         orientation_ = DeviceOrientation::LANDSCAPE;
160     } else {
161         LOGW("SetDeviceOrientation, undefined orientation");
162     }
163 
164     isRound_ = isRound;
165     resolution_ = resolution;
166     deviceWidth_ = deviceWidth;
167     deviceHeight_ = deviceHeight;
168     if (isRound_) {
169         screenShape_ = ScreenShape::ROUND;
170     } else {
171         screenShape_ = ScreenShape::NOT_ROUND;
172     }
173 }
174 
SetDeviceOrientation(int32_t orientation)175 void SystemProperties::SetDeviceOrientation(int32_t orientation)
176 {
177     if (orientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
178         Swap(deviceWidth_, deviceHeight_);
179         orientation_ = DeviceOrientation::PORTRAIT;
180     } else if (orientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
181         Swap(deviceWidth_, deviceHeight_);
182         orientation_ = DeviceOrientation::LANDSCAPE;
183     } else {
184         LOGI("SetDeviceOrientation, no change info: %{public}d", orientation);
185     }
186 }
187 
GetFontWeightScale()188 float SystemProperties::GetFontWeightScale()
189 {
190     return 1.0f;
191 }
192 
InitMccMnc(int32_t mcc, int32_t mnc)193 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
194 {
195     mcc_ = mcc;
196     mnc_ = mnc;
197 }
198 
IsScoringEnabled(const std::string& name)199 bool SystemProperties::IsScoringEnabled(const std::string& name)
200 {
201     return false;
202 }
203 
GetDebugEnabled()204 bool SystemProperties::GetDebugEnabled()
205 {
206     return false;
207 }
208 
GetLayoutDetectEnabled()209 bool SystemProperties::GetLayoutDetectEnabled()
210 {
211     return false;
212 }
213 
GetLanguage()214 std::string SystemProperties::GetLanguage()
215 {
216     return UNDEFINED_PARAM;
217 }
218 
GetRegion()219 std::string SystemProperties::GetRegion()
220 {
221     return UNDEFINED_PARAM;
222 }
223 
GetPartialUpdatePkg()224 std::string SystemProperties::GetPartialUpdatePkg()
225 {
226     return {};
227 }
228 
GetNewPipePkg()229 std::string SystemProperties::GetNewPipePkg()
230 {
231     return {};
232 }
233 
GetSvgMode()234 int32_t SystemProperties::GetSvgMode()
235 {
236     return 1;
237 }
238 
GetIsUseMemoryMonitor()239 bool SystemProperties::GetIsUseMemoryMonitor()
240 {
241     return false;
242 }
243 
IsFormAnimationLimited()244 bool SystemProperties::IsFormAnimationLimited()
245 {
246     return true;
247 }
248 
GetDebugPixelMapSaveEnabled()249 bool SystemProperties::GetDebugPixelMapSaveEnabled()
250 {
251     return false;
252 }
253 
GetResourceDecoupling()254 bool SystemProperties::GetResourceDecoupling()
255 {
256     return true;
257 }
258 
GetTitleStyleEnabled()259 bool SystemProperties::GetTitleStyleEnabled()
260 {
261     return false;
262 }
263 
GetJankFrameThreshold()264 int32_t SystemProperties::GetJankFrameThreshold()
265 {
266     return 0;
267 }
268 
GetCustomTitleFilePath()269 std::string SystemProperties::GetCustomTitleFilePath()
270 {
271     return UNDEFINED_PARAM;
272 }
273 
Is24HourClock()274 bool SystemProperties::Is24HourClock()
275 {
276     return false;
277 }
278 
GetDisplaySyncSkipEnabled()279 bool SystemProperties::GetDisplaySyncSkipEnabled()
280 {
281     return true;
282 }
283 
GetNavigationBlurEnabled()284 bool SystemProperties::GetNavigationBlurEnabled()
285 {
286     return navigationBlurEnabled_;
287 }
288 
GetGridCacheEnabled()289 bool SystemProperties::GetGridCacheEnabled()
290 {
291     return gridCacheEnabled_;
292 }
293 
GetGridIrregularLayoutEnabled()294 bool SystemProperties::GetGridIrregularLayoutEnabled()
295 {
296     return false;
297 }
298 
WaterFlowUseSegmentedLayout()299 bool SystemProperties::WaterFlowUseSegmentedLayout()
300 {
301     return false;
302 }
303 
GetSideBarContainerBlurEnable()304 bool SystemProperties::GetSideBarContainerBlurEnable()
305 {
306     return sideBarContainerBlurEnable_;
307 }
308 
GetDefaultResolution()309 float SystemProperties::GetDefaultResolution()
310 {
311     return 1.0f;
312 }
313 
GetAtomicServiceBundleName()314 std::string SystemProperties::GetAtomicServiceBundleName()
315 {
316     return UNDEFINED_PARAM;
317 }
318 
GetDragStartDampingRatio()319 float SystemProperties::GetDragStartDampingRatio()
320 {
321     return dragStartDampingRatio_;
322 }
323 
GetDragStartPanDistanceThreshold()324 float SystemProperties::GetDragStartPanDistanceThreshold()
325 {
326     return dragStartPanDisThreshold_;
327 }
328 
IsSmallFoldProduct()329 bool SystemProperties::IsSmallFoldProduct()
330 {
331     return false;
332 }
333 
GetDebugInspectorId()334 std::string SystemProperties::GetDebugInspectorId()
335 {
336     return UNDEFINED_PARAM;
337 }
338 
GetSrollableVelocityScale()339 double SystemProperties::GetSrollableVelocityScale()
340 {
341     return 0.0;
342 }
343 
GetSrollableFriction()344 double SystemProperties::GetSrollableFriction()
345 {
346     return 0.0;
347 }
348 } // namespace OHOS::Ace
349