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 <shared_mutex>
19 #include <regex>
20 
21 #include "display_manager.h"
22 #include "locale_config.h"
23 #include "parameter.h"
24 #include "parameters.h"
25 
26 #include "adapter/ohos/entrance/ace_container.h"
27 #include "adapter/ohos/osal/window_utils.h"
28 #include "core/common/ace_application_info.h"
29 #ifdef OHOS_STANDARD_SYSTEM
30 #include "systemcapability.h"
31 #endif
32 
33 namespace OHOS::Ace {
34 namespace {
35 constexpr char PROPERTY_DEVICE_TYPE[] = "const.product.devicetype";
36 constexpr char PROPERTY_NEED_AVOID_WINDOW[] = "const.window.need_avoid_window";
37 constexpr char PROPERTY_DEVICE_TYPE_DEFAULT[] = "default";
38 constexpr char PROPERTY_DEVICE_TYPE_TV[] = "tv";
39 constexpr char PROPERTY_DEVICE_TYPE_TABLET[] = "tablet";
40 constexpr char PROPERTY_DEVICE_TYPE_TWOINONE[] = "2in1";
41 constexpr char PROPERTY_DEVICE_TYPE_WATCH[] = "watch";
42 constexpr char PROPERTY_DEVICE_TYPE_CAR[] = "car";
43 constexpr char PROPERTY_DEVICE_TYPE_WEARABLE[] = "wearable";
44 constexpr char PROPERTY_FOLD_TYPE[] = "const.window.foldscreen.type";
45 constexpr char ENABLE_DEBUG_AUTOUI_KEY[] = "persist.ace.debug.autoui.enabled";
46 constexpr char ENABLE_DEBUG_BOUNDARY_KEY[] = "persist.ace.debug.boundary.enabled";
47 constexpr char ENABLE_DOWNLOAD_BY_NETSTACK_KEY[] = "persist.ace.download.netstack.enabled";
48 constexpr char ENABLE_DEBUG_OFFSET_LOG_KEY[] = "persist.ace.scrollable.log.enabled";
49 constexpr char ANIMATION_SCALE_KEY[] = "persist.sys.arkui.animationscale";
50 constexpr char CUSTOM_TITLE_KEY[] = "persist.sys.arkui.customtitle";
51 constexpr char DISTRIBUTE_ENGINE_BUNDLE_NAME[] = "atomic.service.distribute.engine.bundle.name";
52 constexpr char IS_OPINC_ENABLE[] = "persist.ddgr.opinctype";
53 constexpr int32_t ORIENTATION_PORTRAIT = 0;
54 constexpr int32_t ORIENTATION_LANDSCAPE = 1;
55 constexpr int DEFAULT_THRESHOLD_JANK = 15;
56 constexpr float DEFAULT_ANIMATION_SCALE = 1.0f;
57 float animationScale_ = DEFAULT_ANIMATION_SCALE;
58 constexpr int32_t DEFAULT_DRAG_START_DAMPING_RATIO = 20;
59 constexpr int32_t DEFAULT_DRAG_START_PAN_DISTANCE_THRESHOLD_IN_VP = 10;
60 std::shared_mutex mutex_;
61 const std::regex FOLD_TYPE_REGEX("^(\\d+)(,\\d+){3,}$");
62 #ifdef ENABLE_ROSEN_BACKEND
63 constexpr char DISABLE_ROSEN_FILE_PATH[] = "/etc/disablerosen";
64 constexpr char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_animation";
65 #endif
66 constexpr int32_t CONVERT_ASTC_THRESHOLD = 2;
67 
IsOpIncEnabled()68 bool IsOpIncEnabled()
69 {
70     return (system::GetParameter(IS_OPINC_ENABLE, "2") == "2");
71 }
72 
Swap(int32_t& deviceWidth, int32_t& deviceHeight)73 void Swap(int32_t& deviceWidth, int32_t& deviceHeight)
74 {
75     int32_t temp = deviceWidth;
76     deviceWidth = deviceHeight;
77     deviceHeight = temp;
78 }
79 
IsDebugAutoUIEnabled()80 bool IsDebugAutoUIEnabled()
81 {
82     return (system::GetParameter(ENABLE_DEBUG_AUTOUI_KEY, "false") == "true");
83 }
84 
IsDebugOffsetLogEnabled()85 bool IsDebugOffsetLogEnabled()
86 {
87     return (system::GetParameter(ENABLE_DEBUG_OFFSET_LOG_KEY, "false") == "true");
88 }
89 
IsDebugBoundaryEnabled()90 bool IsDebugBoundaryEnabled()
91 {
92     return system::GetParameter(ENABLE_DEBUG_BOUNDARY_KEY, "false") == "true";
93 }
94 
IsDownloadByNetworkDisabled()95 bool IsDownloadByNetworkDisabled()
96 {
97     return system::GetParameter(ENABLE_DOWNLOAD_BY_NETSTACK_KEY, "true") == "true";
98 }
99 
IsSvgTraceEnabled()100 bool IsSvgTraceEnabled()
101 {
102     return (system::GetParameter("persist.ace.trace.svg.enabled", "0") == "1");
103 }
104 
IsLayoutTraceEnabled()105 bool IsLayoutTraceEnabled()
106 {
107     return (system::GetParameter("persist.ace.trace.layout.enabled", "false") == "true");
108 }
109 
IsTextTraceEnabled()110 bool IsTextTraceEnabled()
111 {
112     return (system::GetParameter("persist.ace.trace.text.enabled", "false") == "true");
113 }
114 
IsSyntaxTraceEnabled()115 bool IsSyntaxTraceEnabled()
116 {
117     return (system::GetParameter("persist.ace.trace.syntax.enabled", "false") == "true");
118 }
119 
IsAccessTraceEnabled()120 bool IsAccessTraceEnabled()
121 {
122     return (system::GetParameter("persist.ace.trace.access.enabled", "false") == "true");
123 }
124 
IsTraceInputEventEnabled()125 bool IsTraceInputEventEnabled()
126 {
127     return (system::GetParameter("persist.ace.trace.inputevent.enabled", "false") == "true");
128 }
129 
IsStateManagerEnable()130 bool IsStateManagerEnable()
131 {
132     return (system::GetParameter("persist.ace.debug.statemgr.enabled", "false") == "true");
133 }
134 
IsBuildTraceEnabled()135 bool IsBuildTraceEnabled()
136 {
137     return (system::GetParameter("persist.ace.trace.build.enabled", "false") == "true");
138 }
139 
IsSyncDebugTraceEnabled()140 bool IsSyncDebugTraceEnabled()
141 {
142     return (system::GetParameter("persist.ace.trace.sync.debug.enabled", "false") == "true");
143 }
144 
IsDeveloperModeOn()145 bool IsDeveloperModeOn()
146 {
147     return (system::GetParameter("const.security.developermode.state", "false") == "true");
148 }
149 
IsWindowRectResizeEnabled()150 bool IsWindowRectResizeEnabled()
151 {
152     return (system::GetParameter("persist.ace.windowresize.enabled", "true") == "true");
153 }
154 
IsHookModeEnabled()155 bool IsHookModeEnabled()
156 {
157 #ifdef PREVIEW
158     return false;
159 #endif
160     const int bufferLen = 128;
161     char paramOutBuf[bufferLen] = { 0 };
162     constexpr char hook_mode[] = "startup:";
163     int ret = GetParameter("persist.libc.hook_mode", "", paramOutBuf, bufferLen);
164     if (ret <= 0 || strncmp(paramOutBuf, hook_mode, strlen(hook_mode)) != 0) {
165         return false;
166     }
167     return true;
168 }
169 
IsRosenBackendEnabled()170 bool IsRosenBackendEnabled()
171 {
172 #ifdef PREVIEW
173     return false;
174 #endif
175 #ifdef ENABLE_ROSEN_BACKEND
176     if (system::GetParameter("persist.ace.rosen.backend.enabled", "0") == "1") {
177         return true;
178     }
179     if (system::GetParameter("persist.ace.rosen.backend.enabled", "0") == "2") {
180         return false;
181     }
182     if (access(DISABLE_ROSEN_FILE_PATH, F_OK) == 0) {
183         return false;
184     }
185     return true;
186 #else
187     return false;
188 #endif
189 }
190 
IsWindowAnimationEnabled()191 bool IsWindowAnimationEnabled()
192 {
193 #ifdef PREVIEW
194     return false;
195 #endif
196 #ifdef ENABLE_ROSEN_BACKEND
197     if (access(DISABLE_WINDOW_ANIMATION_PATH, F_OK) == 0) {
198         return false;
199     }
200     return true;
201 #else
202     return false;
203 #endif
204 }
205 
IsAccessibilityEnabled()206 bool IsAccessibilityEnabled()
207 {
208     return (system::GetParameter("persist.ace.testmode.enabled", "0") == "1" ||
209             system::GetParameter("debug.ace.testmode.enabled", "0") == "1");
210 }
211 
IsDebugEnabled()212 bool IsDebugEnabled()
213 {
214     return (system::GetParameter("persist.ace.debug.enabled", "0") == "1");
215 }
216 
IsLayoutDetectEnabled()217 bool IsLayoutDetectEnabled()
218 {
219     return (system::GetParameter("persist.ace.layoutdetect.enabled", "0") == "1");
220 }
221 
IsNavigationBlurEnabled()222 bool IsNavigationBlurEnabled()
223 {
224     return (system::GetParameter("persist.ace.navigation.blur.enabled", "0") == "1");
225 }
226 
IsGridCacheEnabled()227 bool IsGridCacheEnabled()
228 {
229     return (system::GetParameter("persist.ace.grid.cache.enabled", "1") == "1");
230 }
231 
IsSideBarContainerBlurEnable()232 bool IsSideBarContainerBlurEnable()
233 {
234     return (system::GetParameter("persist.ace.sidebar.blur.enabled", "0") == "1");
235 }
236 
IsGpuUploadEnabled()237 bool IsGpuUploadEnabled()
238 {
239     return (system::GetParameter("persist.ace.gpuupload.enabled", "0") == "1" ||
240             system::GetParameter("debug.ace.gpuupload.enabled", "0") == "1");
241 }
242 
IsImageFrameworkEnabled()243 bool IsImageFrameworkEnabled()
244 {
245     return system::GetBoolParameter("persist.ace.image.framework.enabled", true);
246 }
247 
OnAnimationScaleChanged(const char* key, const char* value, void* context)248 void OnAnimationScaleChanged(const char* key, const char* value, void* context)
249 {
250     CHECK_NULL_VOID(key);
251     if (strcmp(key, ANIMATION_SCALE_KEY) != 0) {
252         LOGE("AnimationScale key not matched. key: %{public}s", key);
253         return;
254     }
255     std::unique_lock<std::shared_mutex> lock(mutex_);
256     if (value == nullptr) {
257         LOGW("AnimationScale changes with null value, use default. key: %{public}s", key);
258         animationScale_ = DEFAULT_ANIMATION_SCALE;
259         return;
260     }
261     auto animationScale = std::atof(value);
262     if (animationScale < 0.0f) {
263         LOGE("AnimationScale changes with invalid value: %{public}s. ignore", value);
264         return;
265     }
266     LOGI("AnimationScale: %{public}f -> %{public}f", animationScale_, animationScale);
267     animationScale_ = animationScale;
268 }
269 
GetSysDumpFrameCount()270 uint32_t GetSysDumpFrameCount()
271 {
272     return system::GetUintParameter<uint32_t>(
273         "persist.ace.framedumpcount", 10); // 10: Pipeline dump of the last 10 frames' task.
274 }
275 
GetAstcEnabled()276 bool GetAstcEnabled()
277 {
278     return system::GetParameter("persist.astc.enable", "true") == "true";
279 }
280 
GetAstcMaxErrorProp()281 int32_t GetAstcMaxErrorProp()
282 {
283     return system::GetIntParameter<int>("persist.astc.max", 50000); // 50000: Anomaly threshold of astc.
284 }
285 
GetAstcPsnrProp()286 int32_t GetAstcPsnrProp()
287 {
288     return system::GetIntParameter<int>("persist.astc.psnr", 0);
289 }
290 
GetImageFileCacheConvertToAstcEnabled()291 bool GetImageFileCacheConvertToAstcEnabled()
292 {
293     return system::GetParameter("persist.image.filecache.astc.enable", "false") == "true";
294 }
295 
GetImageFileCacheConvertAstcThresholdProp()296 int32_t GetImageFileCacheConvertAstcThresholdProp()
297 {
298     return system::GetIntParameter<int>("persist.image.filecache.astc.threshold", CONVERT_ASTC_THRESHOLD);
299 }
300 
IsUseMemoryMonitor()301 bool IsUseMemoryMonitor()
302 {
303     return (system::GetParameter("persist.ace.memorymonitor.enabled", "0") == "1");
304 }
305 
IsExtSurfaceEnabled()306 bool IsExtSurfaceEnabled()
307 {
308 #ifdef EXT_SURFACE_ENABLE
309     return true;
310 #else
311     return false;
312 #endif
313 }
314 
IsEnableScrollableItemPool()315 bool IsEnableScrollableItemPool()
316 {
317     return system::GetBoolParameter("persist.ace.scrollablepool.enabled", false);
318 }
319 
IsResourceDecoupling()320 bool IsResourceDecoupling()
321 {
322     return system::GetBoolParameter("persist.sys.arkui.resource.decoupling", true);
323 }
324 
IsAcePerformanceMonitorEnabled()325 bool IsAcePerformanceMonitorEnabled()
326 {
327     return system::GetBoolParameter("persist.ace.performance.monitor.enabled", false);
328 }
329 
IsAceCommercialLogEnable()330 bool IsAceCommercialLogEnable()
331 {
332     return system::GetParameter("const.logsystem.versiontype", "commercial") == "commercial";
333 }
334 } // namespace
335 
ReadDragStartDampingRatio()336 float ReadDragStartDampingRatio()
337 {
338     return system::GetIntParameter("debug.ace.drag.damping.ratio", DEFAULT_DRAG_START_DAMPING_RATIO) / 100.0f;
339 }
340 
ReadDragStartPanDistanceThreshold()341 float ReadDragStartPanDistanceThreshold()
342 {
343     return system::GetIntParameter("debug.ace.drag.pan.threshold",
344         DEFAULT_DRAG_START_PAN_DISTANCE_THRESHOLD_IN_VP) * 1.0f;
345 }
346 
ReadCanvasDebugMode()347 uint32_t ReadCanvasDebugMode()
348 {
349     return system::GetUintParameter("persist.ace.canvas.debug.mode", 0u);
350 }
351 
IsFaultInjectEnabled()352 bool IsFaultInjectEnabled()
353 {
354     return (system::GetParameter("persist.ace.fault.inject.enabled", "false") == "true");
355 }
356 
GetPercent()357 std::pair<float, float> GetPercent()
358 {
359     std::vector<double> result;
360     StringUtils::StringSplitter(
361         system::GetParameter("const.ace.darkModeAppBGColorBrightness", "0.10,0.05"), ',', result);
362     std::pair<float, float> percent(result.front(), result.back());
363     return percent;
364 }
365 
366 bool SystemProperties::svgTraceEnable_ = IsSvgTraceEnabled();
367 bool SystemProperties::developerModeOn_ = IsDeveloperModeOn();
368 std::atomic<bool> SystemProperties::layoutTraceEnable_(IsLayoutTraceEnabled() && developerModeOn_);
369 bool SystemProperties::imageFrameworkEnable_ = IsImageFrameworkEnabled();
370 std::atomic<bool> SystemProperties::traceInputEventEnable_(IsTraceInputEventEnabled() && developerModeOn_);
371 std::atomic<bool> SystemProperties::stateManagerEnable_(IsStateManagerEnable());
372 bool SystemProperties::buildTraceEnable_ = IsBuildTraceEnabled() && developerModeOn_;
373 bool SystemProperties::syncDebugTraceEnable_ = IsSyncDebugTraceEnabled();
374 bool SystemProperties::pixelRoundEnable_ = IsPixelRoundEnabled();
375 bool SystemProperties::textTraceEnable_ = IsTextTraceEnabled();
376 bool SystemProperties::syntaxTraceEnable_ = IsSyntaxTraceEnabled();
377 bool SystemProperties::accessTraceEnable_ = IsAccessTraceEnabled();
378 bool SystemProperties::accessibilityEnabled_ = IsAccessibilityEnabled();
379 bool SystemProperties::isRound_ = false;
380 bool SystemProperties::isDeviceAccess_ = false;
381 ACE_WEAK_SYM int32_t SystemProperties::deviceWidth_ = 0;
382 ACE_WEAK_SYM int32_t SystemProperties::deviceHeight_ = 0;
383 ACE_WEAK_SYM int32_t SystemProperties::devicePhysicalWidth_ = 0;
384 ACE_WEAK_SYM int32_t SystemProperties::devicePhysicalHeight_ = 0;
385 ACE_WEAK_SYM double SystemProperties::resolution_ = 1.0;
386 ACE_WEAK_SYM DeviceType SystemProperties::deviceType_ { DeviceType::UNKNOWN };
387 ACE_WEAK_SYM FoldScreenType SystemProperties::foldScreenType_ { FoldScreenType::UNKNOWN };
388 ACE_WEAK_SYM bool SystemProperties::needAvoidWindow_ { false };
389 ACE_WEAK_SYM DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
390 std::string SystemProperties::brand_ = INVALID_PARAM;
391 std::string SystemProperties::manufacturer_ = INVALID_PARAM;
392 std::string SystemProperties::model_ = INVALID_PARAM;
393 std::string SystemProperties::product_ = INVALID_PARAM;
394 std::string SystemProperties::apiVersion_ = INVALID_PARAM;
395 std::string SystemProperties::releaseType_ = INVALID_PARAM;
396 std::string SystemProperties::paramDeviceType_ = INVALID_PARAM;
397 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
398 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
399 ACE_WEAK_SYM ColorMode SystemProperties::colorMode_ { ColorMode::LIGHT };
400 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
401 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
402 bool SystemProperties::unZipHap_ = true;
403 ACE_WEAK_SYM bool SystemProperties::rosenBackendEnabled_ = IsRosenBackendEnabled();
404 ACE_WEAK_SYM bool SystemProperties::isHookModeEnabled_ = IsHookModeEnabled();
405 std::atomic<bool> SystemProperties::debugBoundaryEnabled_(IsDebugBoundaryEnabled() && developerModeOn_);
406 bool SystemProperties::debugAutoUIEnabled_ = IsDebugAutoUIEnabled();
407 bool SystemProperties::downloadByNetworkEnabled_ = IsDownloadByNetworkDisabled();
408 bool SystemProperties::debugOffsetLogEnabled_ = IsDebugOffsetLogEnabled();
409 ACE_WEAK_SYM bool SystemProperties::windowAnimationEnabled_ = IsWindowAnimationEnabled();
410 ACE_WEAK_SYM bool SystemProperties::debugEnabled_ = IsDebugEnabled();
411 ACE_WEAK_SYM bool SystemProperties::layoutDetectEnabled_ = IsLayoutDetectEnabled();
412 bool SystemProperties::gpuUploadEnabled_ = IsGpuUploadEnabled();
413 bool SystemProperties::astcEnabled_ = GetAstcEnabled();
414 int32_t SystemProperties::astcMax_ = GetAstcMaxErrorProp();
415 int32_t SystemProperties::astcPsnr_ = GetAstcPsnrProp();
416 bool SystemProperties::imageFileCacheConvertAstc_ = GetImageFileCacheConvertToAstcEnabled();
417 int32_t SystemProperties::imageFileCacheConvertAstcThreshold_ = GetImageFileCacheConvertAstcThresholdProp();
418 ACE_WEAK_SYM bool SystemProperties::extSurfaceEnabled_ = IsExtSurfaceEnabled();
419 ACE_WEAK_SYM uint32_t SystemProperties::dumpFrameCount_ = GetSysDumpFrameCount();
420 ACE_WEAK_SYM bool SystemProperties::windowRectResizeEnabled_ = IsWindowRectResizeEnabled();
421 bool SystemProperties::enableScrollableItemPool_ = IsEnableScrollableItemPool();
422 bool SystemProperties::resourceDecoupling_ = IsResourceDecoupling();
423 bool SystemProperties::navigationBlurEnabled_ = IsNavigationBlurEnabled();
424 bool SystemProperties::gridCacheEnabled_ = IsGridCacheEnabled();
425 std::pair<float, float> SystemProperties::brightUpPercent_ = GetPercent();
426 bool SystemProperties::sideBarContainerBlurEnable_ = IsSideBarContainerBlurEnable();
427 std::atomic<bool> SystemProperties::acePerformanceMonitorEnable_(IsAcePerformanceMonitorEnabled());
428 bool SystemProperties::aceCommercialLogEnable_ = IsAceCommercialLogEnable();
429 bool SystemProperties::faultInjectEnabled_  = IsFaultInjectEnabled();
430 bool SystemProperties::opincEnabled_ = IsOpIncEnabled();
431 float SystemProperties::dragStartDampingRatio_ = ReadDragStartDampingRatio();
432 float SystemProperties::dragStartPanDisThreshold_ = ReadDragStartPanDistanceThreshold();
433 uint32_t SystemProperties::canvasDebugMode_ = ReadCanvasDebugMode();
434 float SystemProperties::fontScale_ = 1.0;
435 float SystemProperties::fontWeightScale_ = 1.0;
IsOpIncEnable()436 bool SystemProperties::IsOpIncEnable()
437 {
438     return opincEnabled_;
439 }
440 
IsSyscapExist(const char* cap)441 bool SystemProperties::IsSyscapExist(const char* cap)
442 {
443 #ifdef OHOS_STANDARD_SYSTEM
444     return HasSystemCapability(cap);
445 #else
446     return false;
447 #endif
448 }
449 
InitDeviceType(DeviceType)450 void SystemProperties::InitDeviceType(DeviceType)
451 {
452     // Do nothing, no need to store type here, use system property at 'GetDeviceType' instead.
453 }
454 
GetArkProperties()455 int SystemProperties::GetArkProperties()
456 {
457     return system::GetIntParameter<int>("persist.ark.properties", -1);
458 }
459 
GetMemConfigProperty()460 std::string SystemProperties::GetMemConfigProperty()
461 {
462     return system::GetParameter("persist.ark.mem_config_property", "");
463 }
464 
GetArkBundleName()465 std::string SystemProperties::GetArkBundleName()
466 {
467     return system::GetParameter("persist.ark.arkbundlename", "");
468 }
469 
GetGcThreadNum()470 size_t SystemProperties::GetGcThreadNum()
471 {
472     size_t defaultGcThreadNums = 7;
473     return system::GetUintParameter<size_t>("persist.ark.gcthreads", defaultGcThreadNums);
474 }
475 
GetLongPauseTime()476 size_t SystemProperties::GetLongPauseTime()
477 {
478     size_t defaultLongPauseTime = 40; // 40ms
479     return system::GetUintParameter<size_t>("persist.ark.longpausetime", defaultLongPauseTime);
480 }
481 
GetAsmInterpreterEnabled()482 bool SystemProperties::GetAsmInterpreterEnabled()
483 {
484     return system::GetParameter("persist.ark.asminterpreter", "true") == "true";
485 }
486 
GetAsmOpcodeDisableRange()487 std::string SystemProperties::GetAsmOpcodeDisableRange()
488 {
489     return system::GetParameter("persist.ark.asmopcodedisablerange", "");
490 }
491 
IsScoringEnabled(const std::string& name)492 bool SystemProperties::IsScoringEnabled(const std::string& name)
493 {
494     if (name.empty()) {
495         return false;
496     }
497     std::string filePath = "/etc/" + name;
498     if (access(filePath.c_str(), F_OK) == 0) {
499         return true;
500     }
501     std::string prop = system::GetParameter("persist.ace.trace.scoringtool", "");
502     return prop == name;
503 }
504 
GetDeviceType()505 ACE_WEAK_SYM DeviceType SystemProperties::GetDeviceType()
506 {
507     InitDeviceTypeBySystemProperty();
508     return deviceType_;
509 }
510 
GetNeedAvoidWindow()511 ACE_WEAK_SYM bool SystemProperties::GetNeedAvoidWindow()
512 {
513     return needAvoidWindow_;
514 }
515 
InitDeviceTypeBySystemProperty()516 void SystemProperties::InitDeviceTypeBySystemProperty()
517 {
518     if (deviceType_ != DeviceType::UNKNOWN) {
519         return;
520     }
521 
522     auto deviceProp = system::GetParameter(PROPERTY_DEVICE_TYPE, PROPERTY_DEVICE_TYPE_DEFAULT);
523     // Properties: "default", "tv", "tablet", "watch", "car"
524     if (deviceProp == PROPERTY_DEVICE_TYPE_TV) {
525         deviceType_ = DeviceType::TV;
526     } else if (deviceProp == PROPERTY_DEVICE_TYPE_CAR) {
527         deviceType_ = DeviceType::CAR;
528     } else if (deviceProp == PROPERTY_DEVICE_TYPE_WATCH) {
529         deviceType_ = DeviceType::WATCH;
530     } else if (deviceProp == PROPERTY_DEVICE_TYPE_TABLET) {
531         deviceType_ = DeviceType::TABLET;
532     } else if (deviceProp == PROPERTY_DEVICE_TYPE_TWOINONE) {
533         deviceType_ = DeviceType::TWO_IN_ONE;
534     } else if (deviceProp == PROPERTY_DEVICE_TYPE_WEARABLE) {
535         deviceType_ = DeviceType::WEARABLE;
536     } else {
537         deviceType_ = DeviceType::PHONE;
538     }
539 }
540 
InitDeviceInfo( int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)541 void SystemProperties::InitDeviceInfo(
542     int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
543 {
544     // SetDeviceOrientation should be earlier than deviceWidth/deviceHeight init.
545     SetDeviceOrientation(orientation);
546 
547     isRound_ = isRound;
548     resolution_ = resolution;
549     deviceWidth_ = deviceWidth;
550     deviceHeight_ = deviceHeight;
551     brand_ = ::GetBrand();
552     manufacturer_ = ::GetManufacture();
553     model_ = ::GetProductModel();
554     product_ = ::GetMarketName();
555     apiVersion_ = std::to_string(::GetSdkApiVersion());
556     releaseType_ = ::GetOsReleaseType();
557     paramDeviceType_ = ::GetDeviceType();
558     needAvoidWindow_ = system::GetBoolParameter(PROPERTY_NEED_AVOID_WINDOW, false);
559     debugEnabled_ = IsDebugEnabled();
560     layoutDetectEnabled_ = IsLayoutDetectEnabled();
561     svgTraceEnable_ = IsSvgTraceEnabled();
562     layoutTraceEnable_.store(IsLayoutTraceEnabled() && developerModeOn_);
563     traceInputEventEnable_.store(IsTraceInputEventEnabled() && developerModeOn_);
564     stateManagerEnable_.store(IsStateManagerEnable());
565     buildTraceEnable_ = IsBuildTraceEnabled() && developerModeOn_;
566     syncDebugTraceEnable_ = IsSyncDebugTraceEnabled();
567     pixelRoundEnable_ = IsPixelRoundEnabled();
568     accessibilityEnabled_ = IsAccessibilityEnabled();
569     canvasDebugMode_ = ReadCanvasDebugMode();
570     isHookModeEnabled_ = IsHookModeEnabled();
571     debugAutoUIEnabled_ = system::GetParameter(ENABLE_DEBUG_AUTOUI_KEY, "false") == "true";
572     debugOffsetLogEnabled_ = system::GetParameter(ENABLE_DEBUG_OFFSET_LOG_KEY, "false") == "true";
573     downloadByNetworkEnabled_ = system::GetParameter(ENABLE_DOWNLOAD_BY_NETSTACK_KEY, "true") == "true";
574     animationScale_ = std::atof(system::GetParameter(ANIMATION_SCALE_KEY, "1").c_str());
575     WatchParameter(ANIMATION_SCALE_KEY, OnAnimationScaleChanged, nullptr);
576     resourceDecoupling_ = IsResourceDecoupling();
577     navigationBlurEnabled_ = IsNavigationBlurEnabled();
578     gridCacheEnabled_ = IsGridCacheEnabled();
579     sideBarContainerBlurEnable_ = IsSideBarContainerBlurEnable();
580     acePerformanceMonitorEnable_.store(IsAcePerformanceMonitorEnabled());
581     faultInjectEnabled_  = IsFaultInjectEnabled();
582     windowRectResizeEnabled_ = IsWindowRectResizeEnabled();
583     if (isRound_) {
584         screenShape_ = ScreenShape::ROUND;
585     } else {
586         screenShape_ = ScreenShape::NOT_ROUND;
587     }
588 
589     InitDeviceTypeBySystemProperty();
590 }
591 
SetDeviceOrientation(int32_t orientation)592 ACE_WEAK_SYM void SystemProperties::SetDeviceOrientation(int32_t orientation)
593 {
594     auto newOrientation = static_cast<int32_t>(WindowUtils::GetDeviceOrientation(orientation));
595     if (newOrientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
596         Swap(deviceWidth_, deviceHeight_);
597         orientation_ = DeviceOrientation::PORTRAIT;
598     } else if (newOrientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
599         Swap(deviceWidth_, deviceHeight_);
600         orientation_ = DeviceOrientation::LANDSCAPE;
601     }
602 }
603 
GetFontWeightScale()604 ACE_WEAK_SYM float SystemProperties::GetFontWeightScale()
605 {
606     // Default value of font weight scale is 1.0.
607     return fontWeightScale_;
608 }
609 
GetFontScale()610 ACE_WEAK_SYM float SystemProperties::GetFontScale()
611 {
612     // Default value of font size scale is 1.0.
613     return fontScale_;
614 }
615 
InitMccMnc(int32_t mcc, int32_t mnc)616 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
617 {
618     mcc_ = mcc;
619     mnc_ = mnc;
620 }
621 
GetDebugEnabled()622 ACE_WEAK_SYM bool SystemProperties::GetDebugEnabled()
623 {
624     return debugEnabled_;
625 }
626 
GetLayoutDetectEnabled()627 ACE_WEAK_SYM bool SystemProperties::GetLayoutDetectEnabled()
628 {
629     return layoutDetectEnabled_;
630 }
631 
GetLanguage()632 std::string SystemProperties::GetLanguage()
633 {
634     return system::GetParameter("const.global.language", INVALID_PARAM);
635 }
636 
GetRegion()637 std::string SystemProperties::GetRegion()
638 {
639     return system::GetParameter("const.global.region", INVALID_PARAM);
640 }
641 
GetNewPipePkg()642 std::string SystemProperties::GetNewPipePkg()
643 {
644     return system::GetParameter("persist.ace.newpipe.pkgname", "");
645 }
646 
GetAnimationScale()647 ACE_WEAK_SYM float SystemProperties::GetAnimationScale()
648 {
649     std::shared_lock<std::shared_mutex> lock(mutex_);
650     return animationScale_;
651 }
652 
GetPartialUpdatePkg()653 std::string SystemProperties::GetPartialUpdatePkg()
654 {
655     return system::GetParameter("persist.ace.partial.pkgname", "");
656 }
657 
GetSvgMode()658 int32_t SystemProperties::GetSvgMode()
659 {
660 #ifdef NG_BUILD
661     // disable ace svg before updated to new pipeline
662     return system::GetIntParameter<int>("persist.ace.svg.mode", 0);
663 #else
664     return system::GetIntParameter<int>("persist.ace.svg.mode", 1);
665 #endif
666 }
667 
GetAllowWindowOpenMethodEnabled()668 bool SystemProperties::GetAllowWindowOpenMethodEnabled()
669 {
670     return system::GetBoolParameter("persist.web.allowWindowOpenMethod.enabled", false);
671 }
672 
GetDebugPixelMapSaveEnabled()673 bool SystemProperties::GetDebugPixelMapSaveEnabled()
674 {
675     return system::GetBoolParameter("persist.ace.save.pixelmap.enabled", false);
676 }
677 
IsPixelRoundEnabled()678 bool SystemProperties::IsPixelRoundEnabled()
679 {
680     return system::GetBoolParameter("ace.debug.pixelround.enabled", true);
681 }
682 
GetIsUseMemoryMonitor()683 ACE_WEAK_SYM bool SystemProperties::GetIsUseMemoryMonitor()
684 {
685     static bool isUseMemoryMonitor = IsUseMemoryMonitor();
686     return isUseMemoryMonitor;
687 }
688 
IsFormAnimationLimited()689 bool SystemProperties::IsFormAnimationLimited()
690 {
691     return system::GetBoolParameter("persist.sys.arkui.formAnimationLimit", true);
692 }
693 
GetResourceDecoupling()694 bool SystemProperties::GetResourceDecoupling()
695 {
696     return resourceDecoupling_;
697 }
698 
GetTitleStyleEnabled()699 bool SystemProperties::GetTitleStyleEnabled()
700 {
701     return system::GetBoolParameter("persist.ace.title.style.enabled", false);
702 }
703 
GetJankFrameThreshold()704 int32_t SystemProperties::GetJankFrameThreshold()
705 {
706     return system::GetIntParameter<int>("persist.sys.arkui.perf.threshold", DEFAULT_THRESHOLD_JANK);
707 }
708 
GetCustomTitleFilePath()709 ACE_WEAK_SYM std::string SystemProperties::GetCustomTitleFilePath()
710 {
711     return system::GetParameter(CUSTOM_TITLE_KEY, "");
712 }
713 
Is24HourClock()714 ACE_WEAK_SYM bool SystemProperties::Is24HourClock()
715 {
716     return Global::I18n::LocaleConfig::Is24HourClock();
717 }
718 
GetRtlEnabled()719 std::optional<bool> SystemProperties::GetRtlEnabled()
720 {
721     const std::string emptyParam("none");
722     auto ret = system::GetParameter("debug.ace.rtl.enabled", emptyParam);
723     if (ret == emptyParam) {
724         return std::nullopt;
725     } else {
726         return (ret == "true") ? true : false;
727     }
728 }
729 
GetDisplaySyncSkipEnabled()730 bool SystemProperties::GetDisplaySyncSkipEnabled()
731 {
732     return system::GetBoolParameter("debug.ace.displaySyncSkip.enabled", true);
733 }
734 
GetNavigationBlurEnabled()735 bool SystemProperties::GetNavigationBlurEnabled()
736 {
737     return navigationBlurEnabled_;
738 }
739 
GetGridCacheEnabled()740 bool SystemProperties::GetGridCacheEnabled()
741 {
742     return gridCacheEnabled_;
743 }
744 
GetGridIrregularLayoutEnabled()745 bool SystemProperties::GetGridIrregularLayoutEnabled()
746 {
747     return system::GetBoolParameter("persist.ace.grid.irregular.enabled", false);
748 }
749 
WaterFlowUseSegmentedLayout()750 bool SystemProperties::WaterFlowUseSegmentedLayout()
751 {
752     return system::GetBoolParameter("persist.ace.water.flow.segmented", false);
753 }
754 
GetSideBarContainerBlurEnable()755 bool SystemProperties::GetSideBarContainerBlurEnable()
756 {
757     return sideBarContainerBlurEnable_;
758 }
759 
AddWatchSystemParameter(const char* key, void* context, EnableSystemParameterCallback callback)760 void SystemProperties::AddWatchSystemParameter(const char* key, void* context, EnableSystemParameterCallback callback)
761 {
762     WatchParameter(key, callback, context);
763 }
764 
GetWindowRectResizeEnabled()765 ACE_WEAK_SYM bool SystemProperties::GetWindowRectResizeEnabled()
766 {
767     return windowRectResizeEnabled_;
768 }
769 
RemoveWatchSystemParameter( const char* key, void* context, EnableSystemParameterCallback callback)770 void SystemProperties::RemoveWatchSystemParameter(
771     const char* key, void* context, EnableSystemParameterCallback callback)
772 {
773     RemoveParameterWatcher(key, callback, context);
774 }
775 
EnableSystemParameterTraceLayoutCallback(const char* key, const char* value, void* context)776 void SystemProperties::EnableSystemParameterTraceLayoutCallback(const char* key, const char* value, void* context)
777 {
778     if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
779         SetLayoutTraceEnabled(strcmp(value, "true") == 0);
780     }
781 }
782 
EnableSystemParameterTraceInputEventCallback(const char* key, const char* value, void* context)783 void SystemProperties::EnableSystemParameterTraceInputEventCallback(const char* key, const char* value, void* context)
784 {
785     if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
786         SetInputEventTraceEnabled(strcmp(value, "true") == 0);
787     }
788 }
789 
EnableSystemParameterSecurityDevelopermodeCallback( const char* key, const char* value, void* context)790 void SystemProperties::EnableSystemParameterSecurityDevelopermodeCallback(
791     const char* key, const char* value, void* context)
792 {
793     if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
794         SetSecurityDevelopermodeLayoutTraceEnabled(strcmp(value, "true") == 0);
795     }
796 }
797 
EnableSystemParameterDebugStatemgrCallback(const char* key, const char* value, void* context)798 void SystemProperties::EnableSystemParameterDebugStatemgrCallback(const char* key, const char* value, void* context)
799 {
800     if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
801         SetStateManagerEnabled(strcmp(value, "true") == 0);
802     }
803 }
804 
EnableSystemParameterDebugBoundaryCallback(const char* key, const char* value, void* context)805 void SystemProperties::EnableSystemParameterDebugBoundaryCallback(const char* key, const char* value, void* context)
806 {
807     bool isDebugBoundary = strcmp(value, "true") == 0;
808     SetDebugBoundaryEnabled(isDebugBoundary);
809     auto container = reinterpret_cast<Platform::AceContainer*>(context);
810     CHECK_NULL_VOID(container);
811     container->RenderLayoutBoundary(isDebugBoundary);
812 }
813 
EnableSystemParameterPerformanceMonitorCallback(const char* key, const char* value, void* context)814 void SystemProperties::EnableSystemParameterPerformanceMonitorCallback(const char* key, const char* value,
815     void* context)
816 {
817     if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
818         SetPerformanceMonitorEnabled(strcmp(value, "true") == 0);
819     }
820 }
821 
GetDefaultResolution()822 float SystemProperties::GetDefaultResolution()
823 {
824     float density = 1.0f;
825     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
826     if (defaultDisplay) {
827         density = defaultDisplay->GetVirtualPixelRatio();
828     }
829     return density;
830 }
831 
SetLayoutTraceEnabled(bool layoutTraceEnable)832 void SystemProperties::SetLayoutTraceEnabled(bool layoutTraceEnable)
833 {
834     layoutTraceEnable_.store(layoutTraceEnable && developerModeOn_);
835 }
836 
SetInputEventTraceEnabled(bool inputEventTraceEnable)837 void SystemProperties::SetInputEventTraceEnabled(bool inputEventTraceEnable)
838 {
839     traceInputEventEnable_.store(inputEventTraceEnable && developerModeOn_);
840 }
841 
SetSecurityDevelopermodeLayoutTraceEnabled(bool layoutTraceEnable)842 void SystemProperties::SetSecurityDevelopermodeLayoutTraceEnabled(bool layoutTraceEnable)
843 {
844     layoutTraceEnable_.store(layoutTraceEnable && IsLayoutTraceEnabled());
845 }
846 
SetDebugBoundaryEnabled(bool debugBoundaryEnabled)847 void SystemProperties::SetDebugBoundaryEnabled(bool debugBoundaryEnabled)
848 {
849     debugBoundaryEnabled_.store(debugBoundaryEnabled && developerModeOn_);
850 }
851 
SetPerformanceMonitorEnabled(bool performanceMonitorEnable)852 void SystemProperties::SetPerformanceMonitorEnabled(bool performanceMonitorEnable)
853 {
854     acePerformanceMonitorEnable_.store(performanceMonitorEnable);
855 }
856 
GetAtomicServiceBundleName()857 std::string SystemProperties::GetAtomicServiceBundleName()
858 {
859     return system::GetParameter(DISTRIBUTE_ENGINE_BUNDLE_NAME, "");
860 }
861 
GetDragStartDampingRatio()862 float SystemProperties::GetDragStartDampingRatio()
863 {
864     return dragStartDampingRatio_;
865 }
866 
GetDragStartPanDistanceThreshold()867 float SystemProperties::GetDragStartPanDistanceThreshold()
868 {
869     return dragStartPanDisThreshold_;
870 }
871 
IsSmallFoldProduct()872 ACE_WEAK_SYM bool SystemProperties::IsSmallFoldProduct()
873 {
874     InitFoldScreenTypeBySystemProperty();
875     return foldScreenType_ == FoldScreenType::SMALL_FOLDER;
876 }
877 
InitFoldScreenTypeBySystemProperty()878 void SystemProperties::InitFoldScreenTypeBySystemProperty()
879 {
880     if (foldScreenType_ != FoldScreenType::UNKNOWN) {
881         return;
882     }
883 
884     auto foldTypeProp = system::GetParameter(PROPERTY_FOLD_TYPE, "0,0,0,0");
885     if (std::regex_match(foldTypeProp, FOLD_TYPE_REGEX)) {
886         auto index = foldTypeProp.find_first_of(',');
887         auto foldScreenTypeStr = foldTypeProp.substr(0, index);
888         auto type = std::stoi(foldScreenTypeStr);
889         foldScreenType_ = static_cast<FoldScreenType>(type);
890     }
891 }
892 
GetWebDebugRenderMode()893 std::string SystemProperties::GetWebDebugRenderMode()
894 {
895     return OHOS::system::GetParameter("web.debug.renderMode", "");
896 }
897 
GetDebugInspectorId()898 std::string SystemProperties::GetDebugInspectorId()
899 {
900     return system::GetParameter("ace.debug.inspectorId", INVALID_PARAM);
901 }
902 
GetSrollableVelocityScale()903 double SystemProperties::GetSrollableVelocityScale()
904 {
905     auto ret = system::GetParameter("persist.scrollable.velocityScale", "");
906     return StringUtils::StringToDouble(ret);
907 }
908 
GetSrollableFriction()909 double SystemProperties::GetSrollableFriction()
910 {
911     auto ret = system::GetParameter("persist.scrollable.friction", "");
912     return StringUtils::StringToDouble(ret);
913 }
914 } // namespace OHOS::Ace
915