1 /*
2 * Copyright (c) 2021-2025 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 constexpr int32_t DEFAULT_FORM_SHARED_IMAGE_CACHE_THRESHOLD = 20;
31
32 constexpr int32_t DEFAULT_VELOCITY_TRACKER_POINTNUMBER_VALUE = 20;
33
34 static constexpr char UNDEFINED_PARAM[] = "undefined parameter";
35
Swap(int32_t & deviceWidth,int32_t & deviceHeight)36 void Swap(int32_t& deviceWidth, int32_t& deviceHeight)
37 {
38 int32_t temp = deviceWidth;
39 deviceWidth = deviceHeight;
40 deviceHeight = temp;
41 }
42 } // namespace
43
44 bool SystemProperties::svgTraceEnable_ = false;
45 bool SystemProperties::developerModeOn_ = false;
46 std::atomic<bool> SystemProperties::layoutTraceEnable_(false);
47 std::atomic<bool> SystemProperties::traceInputEventEnable_(false);
48 std::atomic<bool> SystemProperties::stateManagerEnable_(false);
49 bool SystemProperties::buildTraceEnable_ = false;
50 bool SystemProperties::dynamicDetectionTraceEnable_ = false;
51 bool SystemProperties::syncDebugTraceEnable_ = false;
52 bool SystemProperties::measureDebugTraceEnable_ = false;
53 bool SystemProperties::safeAreaDebugTraceEnable_ = false;
54 bool SystemProperties::pixelRoundEnable_ = true;
55 bool SystemProperties::textTraceEnable_ = false;
56 bool SystemProperties::syntaxTraceEnable_ = false;
57 bool SystemProperties::accessTraceEnable_ = false;
58 bool SystemProperties::vsyncModeTraceEnable_ = false;
59 bool SystemProperties::accessibilityEnabled_ = false;
60 bool SystemProperties::isRound_ = false;
61 bool SystemProperties::isDeviceAccess_ = false;
62 int32_t SystemProperties::deviceWidth_ = 0;
63 int32_t SystemProperties::deviceHeight_ = 0;
64 int32_t SystemProperties::devicePhysicalWidth_ = 0;
65 int32_t SystemProperties::devicePhysicalHeight_ = 0;
66 double SystemProperties::resolution_ = 1.0;
67 DeviceType SystemProperties::deviceType_ { DeviceType::PHONE };
68 DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
69 std::string SystemProperties::brand_ = UNDEFINED_PARAM;
70 std::string SystemProperties::manufacturer_ = UNDEFINED_PARAM;
71 std::string SystemProperties::model_ = UNDEFINED_PARAM;
72 std::string SystemProperties::product_ = UNDEFINED_PARAM;
73 std::string SystemProperties::apiVersion_ = "9";
74 std::string SystemProperties::releaseType_ = UNDEFINED_PARAM;
75 std::string SystemProperties::paramDeviceType_ = UNDEFINED_PARAM;
76 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
77 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
78 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
79 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
80 bool SystemProperties::unZipHap_ = true;
81 bool SystemProperties::windowAnimationEnabled_ = false;
82 bool SystemProperties::debugEnabled_ = false;
83 DebugFlags SystemProperties::debugFlags_ = 0;
84 bool SystemProperties::layoutDetectEnabled_ = false;
85 std::atomic<bool> SystemProperties::debugBoundaryEnabled_(false);
86 bool SystemProperties::debugAutoUIEnabled_ = false;
87 bool SystemProperties::debugOffsetLogEnabled_ = false;
88 bool SystemProperties::downloadByNetworkEnabled_ = false;
89 bool SystemProperties::recycleImageEnabled_ = false;
90 bool SystemProperties::gpuUploadEnabled_ = false;
91 bool SystemProperties::isHookModeEnabled_ = false;
92 bool SystemProperties::astcEnabled_ = false;
93 int SystemProperties::astcMax_ = 0;
94 int SystemProperties::astcPsnr_ = 0;
95 bool SystemProperties::imageFileCacheConvertAstc_ = false;
96 int32_t SystemProperties::imageFileCacheConvertAstcThreshold_ = 2;
97 bool SystemProperties::extSurfaceEnabled_ = false;
98 uint32_t SystemProperties::dumpFrameCount_ = 0;
99 bool SystemProperties::resourceDecoupling_ = true;
100 #ifndef ENABLE_ROSEN_BACKEND
101 bool SystemProperties::rosenBackendEnabled_ = false;
102 #else
103 bool SystemProperties::rosenBackendEnabled_ = true;
104 #endif
105 bool SystemProperties::enableScrollableItemPool_ = false;
106 bool SystemProperties::navigationBlurEnabled_ = true;
107 bool SystemProperties::forceSplitIgnoreOrientationEnabled_ = false;
108 std::optional<bool> SystemProperties::arkUIHookEnabled_;
109 bool SystemProperties::gridCacheEnabled_ = false;
110 bool SystemProperties::gridIrregularLayoutEnable_ = false;
111 bool SystemProperties::sideBarContainerBlurEnable_ = false;
112 std::atomic<bool> SystemProperties::acePerformanceMonitorEnable_(false);
113 std::atomic<bool> SystemProperties::focusCanBeActive_(true);
114 bool SystemProperties::aceCommercialLogEnable_ = false;
115 std::pair<float, float> SystemProperties::brightUpPercent_ = {};
116 bool SystemProperties::faultInjectEnabled_ = false;
117 bool SystemProperties::imageFrameworkEnable_ = false;
118 float SystemProperties::pageCount_ = 1.0f;
119 float SystemProperties::dragStartDampingRatio_ = 0.2f;
120 float SystemProperties::dragStartPanDisThreshold_ = 10.0f;
121 uint32_t SystemProperties::canvasDebugMode_ = 0;
122 double SystemProperties::scrollableDistance_ = 0.0;
123 bool SystemProperties::taskPriorityAdjustmentEnable_ = false;
124 int32_t SystemProperties::dragDropFrameworkStatus_ = 0;
125 int32_t SystemProperties::touchAccelarate_ = 0;
126 bool SystemProperties::pageTransitionFrzEnabled_ = false;
127 bool SystemProperties::softPagetransition_ = false;
128 bool SystemProperties::formSkeletonBlurEnabled_ = true;
129 int32_t SystemProperties::formSharedImageCacheThreshold_ = DEFAULT_FORM_SHARED_IMAGE_CACHE_THRESHOLD;
130 WidthLayoutBreakPoint SystemProperties::widthLayoutBreakpoints_ = WidthLayoutBreakPoint();
131 HeightLayoutBreakPoint SystemProperties::heightLayoutBreakpoints_ = HeightLayoutBreakPoint();
132 bool SystemProperties::syncLoadEnabled_ = true;
133 int32_t SystemProperties::velocityTrackerPointNumber_ = DEFAULT_VELOCITY_TRACKER_POINTNUMBER_VALUE;
134 bool SystemProperties::isVelocityWithinTimeWindow_ = true;
135 bool SystemProperties::isVelocityWithoutUpPoint_ = true;
136 bool SystemProperties::prebuildInMultiFrameEnabled_ = false;
137
IsOpIncEnable()138 bool SystemProperties::IsOpIncEnable()
139 {
140 return false;
141 }
142
InitDeviceType(DeviceType type)143 void SystemProperties::InitDeviceType(DeviceType type)
144 {
145 // Properties: "phone", "tv", "tablet", "watch", "car"
146 if (type == DeviceType::TV) {
147 deviceType_ = DeviceType::TV;
148 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TV;
149 } else if (type == DeviceType::WATCH) {
150 deviceType_ = DeviceType::WATCH;
151 paramDeviceType_ = PROPERTY_DEVICE_TYPE_WEARABLE;
152 } else if (type == DeviceType::CAR) {
153 deviceType_ = DeviceType::CAR;
154 paramDeviceType_ = PROPERTY_DEVICE_TYPE_CAR;
155 } else if (type == DeviceType::TABLET) {
156 deviceType_ = DeviceType::TABLET;
157 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TABLET;
158 } else if (type == DeviceType::TWO_IN_ONE) {
159 deviceType_ = DeviceType::TWO_IN_ONE;
160 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TWO_IN_ONE;
161 } else {
162 deviceType_ = DeviceType::PHONE;
163 paramDeviceType_ = PROPERTY_DEVICE_TYPE_PHONE;
164 }
165 }
166
GetDeviceType()167 DeviceType SystemProperties::GetDeviceType()
168 {
169 return deviceType_;
170 }
171
IsSyscapExist(const char * cap)172 bool SystemProperties::IsSyscapExist(const char* cap)
173 {
174 return false;
175 }
176
IsApiVersionGreaterOrEqual(int majorVersion,int minorVersion,int patchVersion)177 bool SystemProperties::IsApiVersionGreaterOrEqual(int majorVersion, int minorVersion, int patchVersion)
178 {
179 return false;
180 }
181
InitDeviceTypeBySystemProperty()182 void SystemProperties::InitDeviceTypeBySystemProperty()
183 {
184 deviceType_ = DeviceType::PHONE;
185 }
186
InitDeviceInfo(int32_t deviceWidth,int32_t deviceHeight,int32_t orientation,double resolution,bool isRound)187 void SystemProperties::InitDeviceInfo(
188 int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
189 {
190 // SetDeviceOrientation should be eralier than deviceWidth/deviceHeight init.
191 if (orientation == ORIENTATION_PORTRAIT) {
192 orientation_ = DeviceOrientation::PORTRAIT;
193 } else if (orientation == ORIENTATION_LANDSCAPE) {
194 orientation_ = DeviceOrientation::LANDSCAPE;
195 } else {
196 LOGW("SetDeviceOrientation, undefined orientation");
197 }
198
199 isRound_ = isRound;
200 resolution_ = resolution;
201 deviceWidth_ = deviceWidth;
202 deviceHeight_ = deviceHeight;
203 if (isRound_) {
204 screenShape_ = ScreenShape::ROUND;
205 } else {
206 screenShape_ = ScreenShape::NOT_ROUND;
207 }
208 }
209
SetDeviceOrientation(int32_t orientation)210 void SystemProperties::SetDeviceOrientation(int32_t orientation)
211 {
212 if (orientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
213 Swap(deviceWidth_, deviceHeight_);
214 orientation_ = DeviceOrientation::PORTRAIT;
215 } else if (orientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
216 Swap(deviceWidth_, deviceHeight_);
217 orientation_ = DeviceOrientation::LANDSCAPE;
218 } else {
219 LOGI("SetDeviceOrientation, no change info: %{public}d", orientation);
220 }
221 }
222
GetFontWeightScale()223 float SystemProperties::GetFontWeightScale()
224 {
225 return 1.0f;
226 }
227
InitMccMnc(int32_t mcc,int32_t mnc)228 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
229 {
230 mcc_ = mcc;
231 mnc_ = mnc;
232 }
233
IsScoringEnabled(const std::string & name)234 bool SystemProperties::IsScoringEnabled(const std::string& name)
235 {
236 return false;
237 }
238
GetDebugEnabled()239 bool SystemProperties::GetDebugEnabled()
240 {
241 return debugEnabled_;
242 }
243
GetLayoutDetectEnabled()244 bool SystemProperties::GetLayoutDetectEnabled()
245 {
246 return layoutDetectEnabled_;
247 }
248
GetLanguage()249 std::string SystemProperties::GetLanguage()
250 {
251 return UNDEFINED_PARAM;
252 }
253
GetRegion()254 std::string SystemProperties::GetRegion()
255 {
256 return UNDEFINED_PARAM;
257 }
258
GetPartialUpdatePkg()259 std::string SystemProperties::GetPartialUpdatePkg()
260 {
261 return {};
262 }
263
GetNewPipePkg()264 std::string SystemProperties::GetNewPipePkg()
265 {
266 return {};
267 }
268
GetSvgMode()269 int32_t SystemProperties::GetSvgMode()
270 {
271 return 1;
272 }
273
GetIsUseMemoryMonitor()274 bool SystemProperties::GetIsUseMemoryMonitor()
275 {
276 return false;
277 }
278
IsFormAnimationLimited()279 bool SystemProperties::IsFormAnimationLimited()
280 {
281 return true;
282 }
283
GetDebugPixelMapSaveEnabled()284 bool SystemProperties::GetDebugPixelMapSaveEnabled()
285 {
286 return false;
287 }
288
GetResourceDecoupling()289 bool SystemProperties::GetResourceDecoupling()
290 {
291 return true;
292 }
293
ConfigChangePerform()294 bool SystemProperties::ConfigChangePerform()
295 {
296 return false;
297 }
298
GetTitleStyleEnabled()299 bool SystemProperties::GetTitleStyleEnabled()
300 {
301 return false;
302 }
303
GetJankFrameThreshold()304 int32_t SystemProperties::GetJankFrameThreshold()
305 {
306 return 0;
307 }
308
GetCustomTitleFilePath()309 std::string SystemProperties::GetCustomTitleFilePath()
310 {
311 return UNDEFINED_PARAM;
312 }
313
Is24HourClock()314 bool SystemProperties::Is24HourClock()
315 {
316 return false;
317 }
318
GetDisplaySyncSkipEnabled()319 bool SystemProperties::GetDisplaySyncSkipEnabled()
320 {
321 return true;
322 }
323
GetNavigationBlurEnabled()324 bool SystemProperties::GetNavigationBlurEnabled()
325 {
326 return navigationBlurEnabled_;
327 }
328
GetForceSplitIgnoreOrientationEnabled()329 bool SystemProperties::GetForceSplitIgnoreOrientationEnabled()
330 {
331 return forceSplitIgnoreOrientationEnabled_;
332 }
333
GetArkUIHookEnabled()334 std::optional<bool> SystemProperties::GetArkUIHookEnabled()
335 {
336 return arkUIHookEnabled_;
337 }
338
GetGridCacheEnabled()339 bool SystemProperties::GetGridCacheEnabled()
340 {
341 return gridCacheEnabled_;
342 }
343
GetGridIrregularLayoutEnabled()344 bool SystemProperties::GetGridIrregularLayoutEnabled()
345 {
346 return gridIrregularLayoutEnable_;
347 }
348
WaterFlowUseSegmentedLayout()349 bool SystemProperties::WaterFlowUseSegmentedLayout()
350 {
351 return false;
352 }
353
GetSideBarContainerBlurEnable()354 bool SystemProperties::GetSideBarContainerBlurEnable()
355 {
356 return sideBarContainerBlurEnable_;
357 }
358
GetDefaultResolution()359 float SystemProperties::GetDefaultResolution()
360 {
361 return 1.0f;
362 }
363
GetAtomicServiceBundleName()364 std::string SystemProperties::GetAtomicServiceBundleName()
365 {
366 return UNDEFINED_PARAM;
367 }
368
GetDragStartDampingRatio()369 float SystemProperties::GetDragStartDampingRatio()
370 {
371 return dragStartDampingRatio_;
372 }
373
GetDragStartPanDistanceThreshold()374 float SystemProperties::GetDragStartPanDistanceThreshold()
375 {
376 return dragStartPanDisThreshold_;
377 }
378
GetVelocityTrackerPointNumber()379 int32_t SystemProperties::GetVelocityTrackerPointNumber()
380 {
381 return velocityTrackerPointNumber_;
382 }
383
IsVelocityWithinTimeWindow()384 bool SystemProperties::IsVelocityWithinTimeWindow()
385 {
386 return isVelocityWithinTimeWindow_;
387 }
388
IsVelocityWithoutUpPoint()389 bool SystemProperties::IsVelocityWithoutUpPoint()
390 {
391 return isVelocityWithoutUpPoint_;
392 }
393
IsSmallFoldProduct()394 bool SystemProperties::IsSmallFoldProduct()
395 {
396 return false;
397 }
398
IsBigFoldProduct()399 bool SystemProperties::IsBigFoldProduct()
400 {
401 return false;
402 }
403
GetDebugInspectorId()404 std::string SystemProperties::GetDebugInspectorId()
405 {
406 return UNDEFINED_PARAM;
407 }
408
GetSrollableVelocityScale()409 double SystemProperties::GetSrollableVelocityScale()
410 {
411 return 0.0;
412 }
413
GetSrollableFriction()414 double SystemProperties::GetSrollableFriction()
415 {
416 return 0.0;
417 }
418
GetScrollableDistance()419 double SystemProperties::GetScrollableDistance()
420 {
421 return scrollableDistance_;
422 }
423
IsNeedResampleTouchPoints()424 bool SystemProperties::IsNeedResampleTouchPoints()
425 {
426 return true;
427 }
428
IsNeedSymbol()429 bool SystemProperties::IsNeedSymbol()
430 {
431 return true;
432 }
433
GetDragDropFrameworkStatus()434 int32_t SystemProperties::GetDragDropFrameworkStatus()
435 {
436 return dragDropFrameworkStatus_;
437 }
438
GetTouchAccelarate()439 int32_t SystemProperties::GetTouchAccelarate()
440 {
441 return touchAccelarate_;
442 }
443
GetContainerDeleteFlag()444 bool SystemProperties::GetContainerDeleteFlag()
445 {
446 return true;
447 }
448
IsSuperFoldDisplayDevice()449 bool SystemProperties::IsSuperFoldDisplayDevice()
450 {
451 return false;
452 }
453
IsPageTransitionFreeze()454 bool SystemProperties::IsPageTransitionFreeze()
455 {
456 return pageTransitionFrzEnabled_;
457 }
458
IsSoftPageTransition()459 bool SystemProperties::IsSoftPageTransition()
460 {
461 return softPagetransition_;
462 }
463
IsFormSkeletonBlurEnabled()464 bool SystemProperties::IsFormSkeletonBlurEnabled()
465 {
466 return formSkeletonBlurEnabled_;
467 }
468
GetMultiInstanceEnabled()469 bool SystemProperties::GetMultiInstanceEnabled()
470 {
471 return false;
472 }
473
getFormSharedImageCacheThreshold()474 int32_t SystemProperties::getFormSharedImageCacheThreshold()
475 {
476 return formSharedImageCacheThreshold_;
477 }
478
SetMultiInstanceEnabled(bool enabled)479 void SystemProperties::SetMultiInstanceEnabled(bool enabled)
480 {
481 }
482
IsWhiteBlockEnabled()483 bool SystemProperties::IsWhiteBlockEnabled()
484 {
485 return false;
486 }
487
IsWhiteBlockIdleChange()488 bool SystemProperties::IsWhiteBlockIdleChange()
489 {
490 return false;
491 }
492
GetWhiteBlockIndexValue()493 int32_t SystemProperties::GetWhiteBlockIndexValue()
494 {
495 return 0;
496 }
497
GetWhiteBlockCacheCountValue()498 int32_t SystemProperties::GetWhiteBlockCacheCountValue()
499 {
500 return 0;
501 }
502
GetPreviewStatus()503 int32_t SystemProperties::GetPreviewStatus()
504 {
505 return -1;
506 }
507 } // namespace OHOS::Ace
508