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
33namespace OHOS::Ace {
34namespace {
35constexpr char PROPERTY_DEVICE_TYPE[] = "const.product.devicetype";
36constexpr char PROPERTY_NEED_AVOID_WINDOW[] = "const.window.need_avoid_window";
37constexpr char PROPERTY_DEVICE_TYPE_DEFAULT[] = "default";
38constexpr char PROPERTY_DEVICE_TYPE_TV[] = "tv";
39constexpr char PROPERTY_DEVICE_TYPE_TABLET[] = "tablet";
40constexpr char PROPERTY_DEVICE_TYPE_TWOINONE[] = "2in1";
41constexpr char PROPERTY_DEVICE_TYPE_WATCH[] = "watch";
42constexpr char PROPERTY_DEVICE_TYPE_CAR[] = "car";
43constexpr char PROPERTY_DEVICE_TYPE_WEARABLE[] = "wearable";
44constexpr char PROPERTY_FOLD_TYPE[] = "const.window.foldscreen.type";
45constexpr char ENABLE_DEBUG_AUTOUI_KEY[] = "persist.ace.debug.autoui.enabled";
46constexpr char ENABLE_DEBUG_BOUNDARY_KEY[] = "persist.ace.debug.boundary.enabled";
47constexpr char ENABLE_DOWNLOAD_BY_NETSTACK_KEY[] = "persist.ace.download.netstack.enabled";
48constexpr char ENABLE_DEBUG_OFFSET_LOG_KEY[] = "persist.ace.scrollable.log.enabled";
49constexpr char ANIMATION_SCALE_KEY[] = "persist.sys.arkui.animationscale";
50constexpr char CUSTOM_TITLE_KEY[] = "persist.sys.arkui.customtitle";
51constexpr char DISTRIBUTE_ENGINE_BUNDLE_NAME[] = "atomic.service.distribute.engine.bundle.name";
52constexpr char IS_OPINC_ENABLE[] = "persist.ddgr.opinctype";
53constexpr int32_t ORIENTATION_PORTRAIT = 0;
54constexpr int32_t ORIENTATION_LANDSCAPE = 1;
55constexpr int DEFAULT_THRESHOLD_JANK = 15;
56constexpr float DEFAULT_ANIMATION_SCALE = 1.0f;
57float animationScale_ = DEFAULT_ANIMATION_SCALE;
58constexpr int32_t DEFAULT_DRAG_START_DAMPING_RATIO = 20;
59constexpr int32_t DEFAULT_DRAG_START_PAN_DISTANCE_THRESHOLD_IN_VP = 10;
60std::shared_mutex mutex_;
61const std::regex FOLD_TYPE_REGEX("^(\\d+)(,\\d+){3,}$");
62#ifdef ENABLE_ROSEN_BACKEND
63constexpr char DISABLE_ROSEN_FILE_PATH[] = "/etc/disablerosen";
64constexpr char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_animation";
65#endif
66constexpr int32_t CONVERT_ASTC_THRESHOLD = 2;
67
68bool IsOpIncEnabled()
69{
70    return (system::GetParameter(IS_OPINC_ENABLE, "2") == "2");
71}
72
73void Swap(int32_t& deviceWidth, int32_t& deviceHeight)
74{
75    int32_t temp = deviceWidth;
76    deviceWidth = deviceHeight;
77    deviceHeight = temp;
78}
79
80bool IsDebugAutoUIEnabled()
81{
82    return (system::GetParameter(ENABLE_DEBUG_AUTOUI_KEY, "false") == "true");
83}
84
85bool IsDebugOffsetLogEnabled()
86{
87    return (system::GetParameter(ENABLE_DEBUG_OFFSET_LOG_KEY, "false") == "true");
88}
89
90bool IsDebugBoundaryEnabled()
91{
92    return system::GetParameter(ENABLE_DEBUG_BOUNDARY_KEY, "false") == "true";
93}
94
95bool IsDownloadByNetworkDisabled()
96{
97    return system::GetParameter(ENABLE_DOWNLOAD_BY_NETSTACK_KEY, "true") == "true";
98}
99
100bool IsSvgTraceEnabled()
101{
102    return (system::GetParameter("persist.ace.trace.svg.enabled", "0") == "1");
103}
104
105bool IsLayoutTraceEnabled()
106{
107    return (system::GetParameter("persist.ace.trace.layout.enabled", "false") == "true");
108}
109
110bool IsTextTraceEnabled()
111{
112    return (system::GetParameter("persist.ace.trace.text.enabled", "false") == "true");
113}
114
115bool IsSyntaxTraceEnabled()
116{
117    return (system::GetParameter("persist.ace.trace.syntax.enabled", "false") == "true");
118}
119
120bool IsAccessTraceEnabled()
121{
122    return (system::GetParameter("persist.ace.trace.access.enabled", "false") == "true");
123}
124
125bool IsTraceInputEventEnabled()
126{
127    return (system::GetParameter("persist.ace.trace.inputevent.enabled", "false") == "true");
128}
129
130bool IsStateManagerEnable()
131{
132    return (system::GetParameter("persist.ace.debug.statemgr.enabled", "false") == "true");
133}
134
135bool IsBuildTraceEnabled()
136{
137    return (system::GetParameter("persist.ace.trace.build.enabled", "false") == "true");
138}
139
140bool IsSyncDebugTraceEnabled()
141{
142    return (system::GetParameter("persist.ace.trace.sync.debug.enabled", "false") == "true");
143}
144
145bool IsDeveloperModeOn()
146{
147    return (system::GetParameter("const.security.developermode.state", "false") == "true");
148}
149
150bool IsWindowRectResizeEnabled()
151{
152    return (system::GetParameter("persist.ace.windowresize.enabled", "true") == "true");
153}
154
155bool 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
170bool 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
191bool 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
206bool IsAccessibilityEnabled()
207{
208    return (system::GetParameter("persist.ace.testmode.enabled", "0") == "1" ||
209            system::GetParameter("debug.ace.testmode.enabled", "0") == "1");
210}
211
212bool IsDebugEnabled()
213{
214    return (system::GetParameter("persist.ace.debug.enabled", "0") == "1");
215}
216
217bool IsLayoutDetectEnabled()
218{
219    return (system::GetParameter("persist.ace.layoutdetect.enabled", "0") == "1");
220}
221
222bool IsNavigationBlurEnabled()
223{
224    return (system::GetParameter("persist.ace.navigation.blur.enabled", "0") == "1");
225}
226
227bool IsGridCacheEnabled()
228{
229    return (system::GetParameter("persist.ace.grid.cache.enabled", "1") == "1");
230}
231
232bool IsSideBarContainerBlurEnable()
233{
234    return (system::GetParameter("persist.ace.sidebar.blur.enabled", "0") == "1");
235}
236
237bool IsGpuUploadEnabled()
238{
239    return (system::GetParameter("persist.ace.gpuupload.enabled", "0") == "1" ||
240            system::GetParameter("debug.ace.gpuupload.enabled", "0") == "1");
241}
242
243bool IsImageFrameworkEnabled()
244{
245    return system::GetBoolParameter("persist.ace.image.framework.enabled", true);
246}
247
248void 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
270uint32_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
276bool GetAstcEnabled()
277{
278    return system::GetParameter("persist.astc.enable", "true") == "true";
279}
280
281int32_t GetAstcMaxErrorProp()
282{
283    return system::GetIntParameter<int>("persist.astc.max", 50000); // 50000: Anomaly threshold of astc.
284}
285
286int32_t GetAstcPsnrProp()
287{
288    return system::GetIntParameter<int>("persist.astc.psnr", 0);
289}
290
291bool GetImageFileCacheConvertToAstcEnabled()
292{
293    return system::GetParameter("persist.image.filecache.astc.enable", "false") == "true";
294}
295
296int32_t GetImageFileCacheConvertAstcThresholdProp()
297{
298    return system::GetIntParameter<int>("persist.image.filecache.astc.threshold", CONVERT_ASTC_THRESHOLD);
299}
300
301bool IsUseMemoryMonitor()
302{
303    return (system::GetParameter("persist.ace.memorymonitor.enabled", "0") == "1");
304}
305
306bool IsExtSurfaceEnabled()
307{
308#ifdef EXT_SURFACE_ENABLE
309    return true;
310#else
311    return false;
312#endif
313}
314
315bool IsEnableScrollableItemPool()
316{
317    return system::GetBoolParameter("persist.ace.scrollablepool.enabled", false);
318}
319
320bool IsResourceDecoupling()
321{
322    return system::GetBoolParameter("persist.sys.arkui.resource.decoupling", true);
323}
324
325bool IsAcePerformanceMonitorEnabled()
326{
327    return system::GetBoolParameter("persist.ace.performance.monitor.enabled", false);
328}
329
330bool IsAceCommercialLogEnable()
331{
332    return system::GetParameter("const.logsystem.versiontype", "commercial") == "commercial";
333}
334} // namespace
335
336float ReadDragStartDampingRatio()
337{
338    return system::GetIntParameter("debug.ace.drag.damping.ratio", DEFAULT_DRAG_START_DAMPING_RATIO) / 100.0f;
339}
340
341float ReadDragStartPanDistanceThreshold()
342{
343    return system::GetIntParameter("debug.ace.drag.pan.threshold",
344        DEFAULT_DRAG_START_PAN_DISTANCE_THRESHOLD_IN_VP) * 1.0f;
345}
346
347uint32_t ReadCanvasDebugMode()
348{
349    return system::GetUintParameter("persist.ace.canvas.debug.mode", 0u);
350}
351
352bool IsFaultInjectEnabled()
353{
354    return (system::GetParameter("persist.ace.fault.inject.enabled", "false") == "true");
355}
356
357std::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
366bool SystemProperties::svgTraceEnable_ = IsSvgTraceEnabled();
367bool SystemProperties::developerModeOn_ = IsDeveloperModeOn();
368std::atomic<bool> SystemProperties::layoutTraceEnable_(IsLayoutTraceEnabled() && developerModeOn_);
369bool SystemProperties::imageFrameworkEnable_ = IsImageFrameworkEnabled();
370std::atomic<bool> SystemProperties::traceInputEventEnable_(IsTraceInputEventEnabled() && developerModeOn_);
371std::atomic<bool> SystemProperties::stateManagerEnable_(IsStateManagerEnable());
372bool SystemProperties::buildTraceEnable_ = IsBuildTraceEnabled() && developerModeOn_;
373bool SystemProperties::syncDebugTraceEnable_ = IsSyncDebugTraceEnabled();
374bool SystemProperties::pixelRoundEnable_ = IsPixelRoundEnabled();
375bool SystemProperties::textTraceEnable_ = IsTextTraceEnabled();
376bool SystemProperties::syntaxTraceEnable_ = IsSyntaxTraceEnabled();
377bool SystemProperties::accessTraceEnable_ = IsAccessTraceEnabled();
378bool SystemProperties::accessibilityEnabled_ = IsAccessibilityEnabled();
379bool SystemProperties::isRound_ = false;
380bool SystemProperties::isDeviceAccess_ = false;
381ACE_WEAK_SYM int32_t SystemProperties::deviceWidth_ = 0;
382ACE_WEAK_SYM int32_t SystemProperties::deviceHeight_ = 0;
383ACE_WEAK_SYM int32_t SystemProperties::devicePhysicalWidth_ = 0;
384ACE_WEAK_SYM int32_t SystemProperties::devicePhysicalHeight_ = 0;
385ACE_WEAK_SYM double SystemProperties::resolution_ = 1.0;
386ACE_WEAK_SYM DeviceType SystemProperties::deviceType_ { DeviceType::UNKNOWN };
387ACE_WEAK_SYM FoldScreenType SystemProperties::foldScreenType_ { FoldScreenType::UNKNOWN };
388ACE_WEAK_SYM bool SystemProperties::needAvoidWindow_ { false };
389ACE_WEAK_SYM DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
390std::string SystemProperties::brand_ = INVALID_PARAM;
391std::string SystemProperties::manufacturer_ = INVALID_PARAM;
392std::string SystemProperties::model_ = INVALID_PARAM;
393std::string SystemProperties::product_ = INVALID_PARAM;
394std::string SystemProperties::apiVersion_ = INVALID_PARAM;
395std::string SystemProperties::releaseType_ = INVALID_PARAM;
396std::string SystemProperties::paramDeviceType_ = INVALID_PARAM;
397int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
398int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
399ACE_WEAK_SYM ColorMode SystemProperties::colorMode_ { ColorMode::LIGHT };
400ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
401LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
402bool SystemProperties::unZipHap_ = true;
403ACE_WEAK_SYM bool SystemProperties::rosenBackendEnabled_ = IsRosenBackendEnabled();
404ACE_WEAK_SYM bool SystemProperties::isHookModeEnabled_ = IsHookModeEnabled();
405std::atomic<bool> SystemProperties::debugBoundaryEnabled_(IsDebugBoundaryEnabled() && developerModeOn_);
406bool SystemProperties::debugAutoUIEnabled_ = IsDebugAutoUIEnabled();
407bool SystemProperties::downloadByNetworkEnabled_ = IsDownloadByNetworkDisabled();
408bool SystemProperties::debugOffsetLogEnabled_ = IsDebugOffsetLogEnabled();
409ACE_WEAK_SYM bool SystemProperties::windowAnimationEnabled_ = IsWindowAnimationEnabled();
410ACE_WEAK_SYM bool SystemProperties::debugEnabled_ = IsDebugEnabled();
411ACE_WEAK_SYM bool SystemProperties::layoutDetectEnabled_ = IsLayoutDetectEnabled();
412bool SystemProperties::gpuUploadEnabled_ = IsGpuUploadEnabled();
413bool SystemProperties::astcEnabled_ = GetAstcEnabled();
414int32_t SystemProperties::astcMax_ = GetAstcMaxErrorProp();
415int32_t SystemProperties::astcPsnr_ = GetAstcPsnrProp();
416bool SystemProperties::imageFileCacheConvertAstc_ = GetImageFileCacheConvertToAstcEnabled();
417int32_t SystemProperties::imageFileCacheConvertAstcThreshold_ = GetImageFileCacheConvertAstcThresholdProp();
418ACE_WEAK_SYM bool SystemProperties::extSurfaceEnabled_ = IsExtSurfaceEnabled();
419ACE_WEAK_SYM uint32_t SystemProperties::dumpFrameCount_ = GetSysDumpFrameCount();
420ACE_WEAK_SYM bool SystemProperties::windowRectResizeEnabled_ = IsWindowRectResizeEnabled();
421bool SystemProperties::enableScrollableItemPool_ = IsEnableScrollableItemPool();
422bool SystemProperties::resourceDecoupling_ = IsResourceDecoupling();
423bool SystemProperties::navigationBlurEnabled_ = IsNavigationBlurEnabled();
424bool SystemProperties::gridCacheEnabled_ = IsGridCacheEnabled();
425std::pair<float, float> SystemProperties::brightUpPercent_ = GetPercent();
426bool SystemProperties::sideBarContainerBlurEnable_ = IsSideBarContainerBlurEnable();
427std::atomic<bool> SystemProperties::acePerformanceMonitorEnable_(IsAcePerformanceMonitorEnabled());
428bool SystemProperties::aceCommercialLogEnable_ = IsAceCommercialLogEnable();
429bool SystemProperties::faultInjectEnabled_  = IsFaultInjectEnabled();
430bool SystemProperties::opincEnabled_ = IsOpIncEnabled();
431float SystemProperties::dragStartDampingRatio_ = ReadDragStartDampingRatio();
432float SystemProperties::dragStartPanDisThreshold_ = ReadDragStartPanDistanceThreshold();
433uint32_t SystemProperties::canvasDebugMode_ = ReadCanvasDebugMode();
434float SystemProperties::fontScale_ = 1.0;
435float SystemProperties::fontWeightScale_ = 1.0;
436bool SystemProperties::IsOpIncEnable()
437{
438    return opincEnabled_;
439}
440
441bool SystemProperties::IsSyscapExist(const char* cap)
442{
443#ifdef OHOS_STANDARD_SYSTEM
444    return HasSystemCapability(cap);
445#else
446    return false;
447#endif
448}
449
450void SystemProperties::InitDeviceType(DeviceType)
451{
452    // Do nothing, no need to store type here, use system property at 'GetDeviceType' instead.
453}
454
455int SystemProperties::GetArkProperties()
456{
457    return system::GetIntParameter<int>("persist.ark.properties", -1);
458}
459
460std::string SystemProperties::GetMemConfigProperty()
461{
462    return system::GetParameter("persist.ark.mem_config_property", "");
463}
464
465std::string SystemProperties::GetArkBundleName()
466{
467    return system::GetParameter("persist.ark.arkbundlename", "");
468}
469
470size_t SystemProperties::GetGcThreadNum()
471{
472    size_t defaultGcThreadNums = 7;
473    return system::GetUintParameter<size_t>("persist.ark.gcthreads", defaultGcThreadNums);
474}
475
476size_t SystemProperties::GetLongPauseTime()
477{
478    size_t defaultLongPauseTime = 40; // 40ms
479    return system::GetUintParameter<size_t>("persist.ark.longpausetime", defaultLongPauseTime);
480}
481
482bool SystemProperties::GetAsmInterpreterEnabled()
483{
484    return system::GetParameter("persist.ark.asminterpreter", "true") == "true";
485}
486
487std::string SystemProperties::GetAsmOpcodeDisableRange()
488{
489    return system::GetParameter("persist.ark.asmopcodedisablerange", "");
490}
491
492bool 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
505ACE_WEAK_SYM DeviceType SystemProperties::GetDeviceType()
506{
507    InitDeviceTypeBySystemProperty();
508    return deviceType_;
509}
510
511ACE_WEAK_SYM bool SystemProperties::GetNeedAvoidWindow()
512{
513    return needAvoidWindow_;
514}
515
516void 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
541void 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
592ACE_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
604ACE_WEAK_SYM float SystemProperties::GetFontWeightScale()
605{
606    // Default value of font weight scale is 1.0.
607    return fontWeightScale_;
608}
609
610ACE_WEAK_SYM float SystemProperties::GetFontScale()
611{
612    // Default value of font size scale is 1.0.
613    return fontScale_;
614}
615
616void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
617{
618    mcc_ = mcc;
619    mnc_ = mnc;
620}
621
622ACE_WEAK_SYM bool SystemProperties::GetDebugEnabled()
623{
624    return debugEnabled_;
625}
626
627ACE_WEAK_SYM bool SystemProperties::GetLayoutDetectEnabled()
628{
629    return layoutDetectEnabled_;
630}
631
632std::string SystemProperties::GetLanguage()
633{
634    return system::GetParameter("const.global.language", INVALID_PARAM);
635}
636
637std::string SystemProperties::GetRegion()
638{
639    return system::GetParameter("const.global.region", INVALID_PARAM);
640}
641
642std::string SystemProperties::GetNewPipePkg()
643{
644    return system::GetParameter("persist.ace.newpipe.pkgname", "");
645}
646
647ACE_WEAK_SYM float SystemProperties::GetAnimationScale()
648{
649    std::shared_lock<std::shared_mutex> lock(mutex_);
650    return animationScale_;
651}
652
653std::string SystemProperties::GetPartialUpdatePkg()
654{
655    return system::GetParameter("persist.ace.partial.pkgname", "");
656}
657
658int32_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
668bool SystemProperties::GetAllowWindowOpenMethodEnabled()
669{
670    return system::GetBoolParameter("persist.web.allowWindowOpenMethod.enabled", false);
671}
672
673bool SystemProperties::GetDebugPixelMapSaveEnabled()
674{
675    return system::GetBoolParameter("persist.ace.save.pixelmap.enabled", false);
676}
677
678bool SystemProperties::IsPixelRoundEnabled()
679{
680    return system::GetBoolParameter("ace.debug.pixelround.enabled", true);
681}
682
683ACE_WEAK_SYM bool SystemProperties::GetIsUseMemoryMonitor()
684{
685    static bool isUseMemoryMonitor = IsUseMemoryMonitor();
686    return isUseMemoryMonitor;
687}
688
689bool SystemProperties::IsFormAnimationLimited()
690{
691    return system::GetBoolParameter("persist.sys.arkui.formAnimationLimit", true);
692}
693
694bool SystemProperties::GetResourceDecoupling()
695{
696    return resourceDecoupling_;
697}
698
699bool SystemProperties::GetTitleStyleEnabled()
700{
701    return system::GetBoolParameter("persist.ace.title.style.enabled", false);
702}
703
704int32_t SystemProperties::GetJankFrameThreshold()
705{
706    return system::GetIntParameter<int>("persist.sys.arkui.perf.threshold", DEFAULT_THRESHOLD_JANK);
707}
708
709ACE_WEAK_SYM std::string SystemProperties::GetCustomTitleFilePath()
710{
711    return system::GetParameter(CUSTOM_TITLE_KEY, "");
712}
713
714ACE_WEAK_SYM bool SystemProperties::Is24HourClock()
715{
716    return Global::I18n::LocaleConfig::Is24HourClock();
717}
718
719std::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
730bool SystemProperties::GetDisplaySyncSkipEnabled()
731{
732    return system::GetBoolParameter("debug.ace.displaySyncSkip.enabled", true);
733}
734
735bool SystemProperties::GetNavigationBlurEnabled()
736{
737    return navigationBlurEnabled_;
738}
739
740bool SystemProperties::GetGridCacheEnabled()
741{
742    return gridCacheEnabled_;
743}
744
745bool SystemProperties::GetGridIrregularLayoutEnabled()
746{
747    return system::GetBoolParameter("persist.ace.grid.irregular.enabled", false);
748}
749
750bool SystemProperties::WaterFlowUseSegmentedLayout()
751{
752    return system::GetBoolParameter("persist.ace.water.flow.segmented", false);
753}
754
755bool SystemProperties::GetSideBarContainerBlurEnable()
756{
757    return sideBarContainerBlurEnable_;
758}
759
760void SystemProperties::AddWatchSystemParameter(const char* key, void* context, EnableSystemParameterCallback callback)
761{
762    WatchParameter(key, callback, context);
763}
764
765ACE_WEAK_SYM bool SystemProperties::GetWindowRectResizeEnabled()
766{
767    return windowRectResizeEnabled_;
768}
769
770void SystemProperties::RemoveWatchSystemParameter(
771    const char* key, void* context, EnableSystemParameterCallback callback)
772{
773    RemoveParameterWatcher(key, callback, context);
774}
775
776void 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
783void 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
790void 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
798void 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
805void 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
814void 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
822float 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
832void SystemProperties::SetLayoutTraceEnabled(bool layoutTraceEnable)
833{
834    layoutTraceEnable_.store(layoutTraceEnable && developerModeOn_);
835}
836
837void SystemProperties::SetInputEventTraceEnabled(bool inputEventTraceEnable)
838{
839    traceInputEventEnable_.store(inputEventTraceEnable && developerModeOn_);
840}
841
842void SystemProperties::SetSecurityDevelopermodeLayoutTraceEnabled(bool layoutTraceEnable)
843{
844    layoutTraceEnable_.store(layoutTraceEnable && IsLayoutTraceEnabled());
845}
846
847void SystemProperties::SetDebugBoundaryEnabled(bool debugBoundaryEnabled)
848{
849    debugBoundaryEnabled_.store(debugBoundaryEnabled && developerModeOn_);
850}
851
852void SystemProperties::SetPerformanceMonitorEnabled(bool performanceMonitorEnable)
853{
854    acePerformanceMonitorEnable_.store(performanceMonitorEnable);
855}
856
857std::string SystemProperties::GetAtomicServiceBundleName()
858{
859    return system::GetParameter(DISTRIBUTE_ENGINE_BUNDLE_NAME, "");
860}
861
862float SystemProperties::GetDragStartDampingRatio()
863{
864    return dragStartDampingRatio_;
865}
866
867float SystemProperties::GetDragStartPanDistanceThreshold()
868{
869    return dragStartPanDisThreshold_;
870}
871
872ACE_WEAK_SYM bool SystemProperties::IsSmallFoldProduct()
873{
874    InitFoldScreenTypeBySystemProperty();
875    return foldScreenType_ == FoldScreenType::SMALL_FOLDER;
876}
877
878void 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
893std::string SystemProperties::GetWebDebugRenderMode()
894{
895    return OHOS::system::GetParameter("web.debug.renderMode", "");
896}
897
898std::string SystemProperties::GetDebugInspectorId()
899{
900    return system::GetParameter("ace.debug.inspectorId", INVALID_PARAM);
901}
902
903double SystemProperties::GetSrollableVelocityScale()
904{
905    auto ret = system::GetParameter("persist.scrollable.velocityScale", "");
906    return StringUtils::StringToDouble(ret);
907}
908
909double SystemProperties::GetSrollableFriction()
910{
911    auto ret = system::GetParameter("persist.scrollable.friction", "");
912    return StringUtils::StringToDouble(ret);
913}
914} // namespace OHOS::Ace
915