• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "base/utils/system_properties.h"
17 
18 #include <memory>
19 #include <mutex>
20 #include <shared_mutex>
21 #include <string>
22 #include <unistd.h>
23 
24 #include "dm_common.h"
25 
26 #include "display_manager.h"
27 #include "locale_config.h"
28 #include "parameter.h"
29 #include "parameters.h"
30 
31 #include "base/log/log.h"
32 #include "base/utils/utils.h"
33 #include "core/common/ace_application_info.h"
34 #ifdef OHOS_STANDARD_SYSTEM
35 #include "systemcapability.h"
36 #endif
37 
38 namespace OHOS::Ace {
39 namespace {
40 constexpr char PROPERTY_DEVICE_TYPE[] = "const.product.devicetype";
41 constexpr char PROPERTY_DEVICE_TYPE_DEFAULT[] = "default";
42 constexpr char PROPERTY_DEVICE_TYPE_TV[] = "tv";
43 constexpr char PROPERTY_DEVICE_TYPE_TABLET[] = "tablet";
44 constexpr char PROPERTY_DEVICE_TYPE_TWOINONE[] = "2in1";
45 constexpr char PROPERTY_DEVICE_TYPE_WATCH[] = "watch";
46 constexpr char PROPERTY_DEVICE_TYPE_CAR[] = "car";
47 constexpr char ENABLE_DEBUG_AUTOUI_KEY[] = "persist.ace.debug.autoui.enabled";
48 constexpr char ENABLE_DEBUG_BOUNDARY_KEY[] = "persist.ace.debug.boundary.enabled";
49 constexpr char ENABLE_DOWNLOAD_BY_NETSTACK_KEY[] = "persist.ace.download.netstack.enabled";
50 constexpr char ANIMATION_SCALE_KEY[] = "persist.sys.arkui.animationscale";
51 constexpr char CUSTOM_TITLE_KEY[] = "persist.sys.arkui.customtitle";
52 constexpr int32_t ORIENTATION_PORTRAIT = 0;
53 constexpr int32_t ORIENTATION_LANDSCAPE = 1;
54 constexpr int DEFAULT_THRESHOLD_JANK = 15;
55 constexpr float DEFAULT_ANIMATION_SCALE = 1.0f;
56 float animationScale_ = DEFAULT_ANIMATION_SCALE;
57 std::shared_mutex mutex_;
58 #ifdef ENABLE_ROSEN_BACKEND
59 constexpr char DISABLE_ROSEN_FILE_PATH[] = "/etc/disablerosen";
60 constexpr char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_animation";
61 #endif
62 
63 using RsOrientation = Rosen::DisplayOrientation;
64 
Swap(int32_t & deviceWidth,int32_t & deviceHeight)65 void Swap(int32_t& deviceWidth, int32_t& deviceHeight)
66 {
67     int32_t temp = deviceWidth;
68     deviceWidth = deviceHeight;
69     deviceHeight = temp;
70 }
71 
IsDebugAutoUIEnabled()72 bool IsDebugAutoUIEnabled()
73 {
74     return (system::GetParameter(ENABLE_DEBUG_AUTOUI_KEY, "false") == "true");
75 }
76 
IsDebugBoundaryEnabled()77 bool IsDebugBoundaryEnabled()
78 {
79     return system::GetParameter(ENABLE_DEBUG_BOUNDARY_KEY, "false") == "true";
80 }
81 
IsDownloadByNetworkDisabled()82 bool IsDownloadByNetworkDisabled()
83 {
84     return system::GetParameter(ENABLE_DOWNLOAD_BY_NETSTACK_KEY, "true") == "true";
85 }
86 
IsTraceEnabled()87 bool IsTraceEnabled()
88 {
89     return (system::GetParameter("persist.ace.trace.enabled", "1") == "1");
90 }
91 
IsSvgTraceEnabled()92 bool IsSvgTraceEnabled()
93 {
94     return (system::GetParameter("persist.ace.trace.svg.enabled", "0") == "1");
95 }
96 
IsLayoutTraceEnabled()97 bool IsLayoutTraceEnabled()
98 {
99     return (system::GetParameter("persist.ace.trace.layout.enabled", "false") == "true");
100 }
101 
IsBuildTraceEnabled()102 bool IsBuildTraceEnabled()
103 {
104     return (system::GetParameter("persist.ace.trace.build.enabled", "false") == "true");
105 }
106 
IsDeveloperModeOn()107 bool IsDeveloperModeOn()
108 {
109     return (system::GetParameter("const.security.developermode.state", "false") == "true");
110 }
111 
IsHookModeEnabled()112 bool IsHookModeEnabled()
113 {
114 #ifdef PREVIEW
115     return false;
116 #endif
117     const int bufferLen = 128;
118     char paramOutBuf[bufferLen] = { 0 };
119     constexpr char hook_mode[] = "startup:";
120     int ret = GetParameter("persist.libc.hook_mode", "", paramOutBuf, bufferLen);
121     if (ret <= 0 || strncmp(paramOutBuf, hook_mode, strlen(hook_mode)) != 0) {
122         return false;
123     }
124     return true;
125 }
126 
IsRosenBackendEnabled()127 bool IsRosenBackendEnabled()
128 {
129 #ifdef PREVIEW
130     return false;
131 #endif
132 #ifdef ENABLE_ROSEN_BACKEND
133     if (system::GetParameter("persist.ace.rosen.backend.enabled", "0") == "1") {
134         return true;
135     }
136     if (system::GetParameter("persist.ace.rosen.backend.enabled", "0") == "2") {
137         return false;
138     }
139     if (access(DISABLE_ROSEN_FILE_PATH, F_OK) == 0) {
140         return false;
141     }
142     return true;
143 #else
144     return false;
145 #endif
146 }
147 
IsWindowAnimationEnabled()148 bool IsWindowAnimationEnabled()
149 {
150 #ifdef PREVIEW
151     return false;
152 #endif
153 #ifdef ENABLE_ROSEN_BACKEND
154     if (access(DISABLE_WINDOW_ANIMATION_PATH, F_OK) == 0) {
155         return false;
156     }
157     return true;
158 #else
159     return false;
160 #endif
161 }
162 
IsAccessibilityEnabled()163 bool IsAccessibilityEnabled()
164 {
165     return (system::GetParameter("persist.ace.testmode.enabled", "0") == "1" ||
166             system::GetParameter("debug.ace.testmode.enabled", "0") == "1");
167 }
168 
IsDebugEnabled()169 bool IsDebugEnabled()
170 {
171     return (system::GetParameter("persist.ace.debug.enabled", "0") == "1");
172 }
173 
IsNavigationBlurEnabled()174 bool IsNavigationBlurEnabled()
175 {
176     return (system::GetParameter("persist.ace.navigation.blur.enabled", "0") == "1");
177 }
178 
IsGridCacheEnabled()179 bool IsGridCacheEnabled()
180 {
181     return (system::GetParameter("persist.ace.grid.cache.enabled", "0") == "1");
182 }
183 
IsSideBarContainerBlurEnable()184 bool IsSideBarContainerBlurEnable()
185 {
186     return (system::GetParameter("persist.ace.sidebar.blur.enabled", "0") == "1");
187 }
188 
IsGpuUploadEnabled()189 bool IsGpuUploadEnabled()
190 {
191     return (system::GetParameter("persist.ace.gpuupload.enabled", "0") == "1" ||
192             system::GetParameter("debug.ace.gpuupload.enabled", "0") == "1");
193 }
194 
OnAnimationScaleChanged(const char * key,const char * value,void * context)195 void OnAnimationScaleChanged(const char* key, const char* value, void* context)
196 {
197     CHECK_NULL_VOID(key);
198     if (strcmp(key, ANIMATION_SCALE_KEY) != 0) {
199         LOGE("AnimationScale key not matched. key: %{public}s", key);
200         return;
201     }
202     std::unique_lock<std::shared_mutex> lock(mutex_);
203     if (value == nullptr) {
204         LOGW("AnimationScale changes with null value, use default. key: %{public}s", key);
205         animationScale_ = DEFAULT_ANIMATION_SCALE;
206         return;
207     }
208     auto animationScale = std::atof(value);
209     if (animationScale < 0.0f) {
210         LOGE("AnimationScale changes with invalid value: %{public}s. ignore", value);
211         return;
212     }
213     LOGI("AnimationScale: %{public}f -> %{public}f", animationScale_, animationScale);
214     animationScale_ = animationScale;
215 }
216 
GetSysDumpFrameCount()217 uint32_t GetSysDumpFrameCount()
218 {
219     return system::GetUintParameter<uint32_t>("persist.ace.framedumpcount", 10);
220 }
221 
GetAstcEnabled()222 bool GetAstcEnabled()
223 {
224     return system::GetParameter("persist.astc.enable", "true") == "true";
225 }
226 
GetAstcMaxErrorProp()227 int32_t GetAstcMaxErrorProp()
228 {
229     return system::GetIntParameter<int>("persist.astc.max", 50000);
230 }
231 
GetAstcPsnrProp()232 int32_t GetAstcPsnrProp()
233 {
234     return system::GetIntParameter<int>("persist.astc.psnr", 0);
235 }
236 
IsUseMemoryMonitor()237 bool IsUseMemoryMonitor()
238 {
239     return (system::GetParameter("persist.ace.memorymonitor.enabled", "0") == "1");
240 }
241 
IsExtSurfaceEnabled()242 bool IsExtSurfaceEnabled()
243 {
244 #ifdef EXT_SURFACE_ENABLE
245     return true;
246 #else
247     return false;
248 #endif
249 }
250 
IsEnableScrollableItemPool()251 bool IsEnableScrollableItemPool()
252 {
253     return system::GetBoolParameter("persist.ace.scrollablepool.enabled", false);
254 }
255 
IsResourceDecoupling()256 bool IsResourceDecoupling()
257 {
258     return system::GetBoolParameter("persist.sys.arkui.resource.decoupling", true);
259 }
260 } // namespace
261 
262 bool SystemProperties::traceEnabled_ = IsTraceEnabled();
263 bool SystemProperties::svgTraceEnable_ = IsSvgTraceEnabled();
264 bool SystemProperties::layoutTraceEnable_ = IsLayoutTraceEnabled() && IsDeveloperModeOn();
265 bool SystemProperties::buildTraceEnable_ = IsBuildTraceEnabled() && IsDeveloperModeOn();
266 bool SystemProperties::accessibilityEnabled_ = IsAccessibilityEnabled();
267 bool SystemProperties::isRound_ = false;
268 bool SystemProperties::isDeviceAccess_ = false;
269 ACE_WEAK_SYM int32_t SystemProperties::deviceWidth_ = 0;
270 ACE_WEAK_SYM int32_t SystemProperties::deviceHeight_ = 0;
271 ACE_WEAK_SYM int32_t SystemProperties::devicePhysicalWidth_ = 0;
272 ACE_WEAK_SYM int32_t SystemProperties::devicePhysicalHeight_ = 0;
273 ACE_WEAK_SYM double SystemProperties::resolution_ = 1.0;
274 ACE_WEAK_SYM DeviceType SystemProperties::deviceType_ { DeviceType::UNKNOWN };
275 ACE_WEAK_SYM DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
276 std::string SystemProperties::brand_ = INVALID_PARAM;
277 std::string SystemProperties::manufacturer_ = INVALID_PARAM;
278 std::string SystemProperties::model_ = INVALID_PARAM;
279 std::string SystemProperties::product_ = INVALID_PARAM;
280 std::string SystemProperties::apiVersion_ = INVALID_PARAM;
281 std::string SystemProperties::releaseType_ = INVALID_PARAM;
282 std::string SystemProperties::paramDeviceType_ = INVALID_PARAM;
283 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
284 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
285 ACE_WEAK_SYM ColorMode SystemProperties::colorMode_ { ColorMode::LIGHT };
286 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
287 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
288 bool SystemProperties::unZipHap_ = true;
289 ACE_WEAK_SYM bool SystemProperties::rosenBackendEnabled_ = IsRosenBackendEnabled();
290 ACE_WEAK_SYM bool SystemProperties::isHookModeEnabled_ = IsHookModeEnabled();
291 bool SystemProperties::debugBoundaryEnabled_ = IsDebugBoundaryEnabled();
292 bool SystemProperties::debugAutoUIEnabled_ = IsDebugAutoUIEnabled();
293 bool SystemProperties::downloadByNetworkEnabled_ = IsDownloadByNetworkDisabled();
294 ACE_WEAK_SYM bool SystemProperties::windowAnimationEnabled_ = IsWindowAnimationEnabled();
295 ACE_WEAK_SYM bool SystemProperties::debugEnabled_ = IsDebugEnabled();
296 bool SystemProperties::gpuUploadEnabled_ = IsGpuUploadEnabled();
297 bool SystemProperties::astcEnabled_ = GetAstcEnabled();
298 int32_t SystemProperties::astcMax_ = GetAstcMaxErrorProp();
299 int32_t SystemProperties::astcPsnr_ = GetAstcPsnrProp();
300 ACE_WEAK_SYM bool SystemProperties::extSurfaceEnabled_ = IsExtSurfaceEnabled();
301 ACE_WEAK_SYM uint32_t SystemProperties::dumpFrameCount_ = GetSysDumpFrameCount();
302 bool SystemProperties::enableScrollableItemPool_ = IsEnableScrollableItemPool();
303 bool SystemProperties::resourceDecoupling_ = IsResourceDecoupling();
304 bool SystemProperties::navigationBlurEnabled_ = IsNavigationBlurEnabled();
305 bool SystemProperties::gridCacheEnabled_ = IsGridCacheEnabled();
306 bool SystemProperties::sideBarContainerBlurEnable_ = IsSideBarContainerBlurEnable();
307 
IsSyscapExist(const char * cap)308 bool SystemProperties::IsSyscapExist(const char* cap)
309 {
310 #ifdef OHOS_STANDARD_SYSTEM
311     return HasSystemCapability(cap);
312 #else
313     return false;
314 #endif
315 }
316 
InitDeviceType(DeviceType)317 void SystemProperties::InitDeviceType(DeviceType)
318 {
319     // Do nothing, no need to store type here, use system property at 'GetDeviceType' instead.
320 }
321 
GetArkProperties()322 int SystemProperties::GetArkProperties()
323 {
324     return system::GetIntParameter<int>("persist.ark.properties", -1);
325 }
326 
GetArkBundleName()327 std::string SystemProperties::GetArkBundleName()
328 {
329     return system::GetParameter("persist.ark.arkbundlename", "");
330 }
331 
GetGcThreadNum()332 size_t SystemProperties::GetGcThreadNum()
333 {
334     size_t defaultGcThreadNums = 7;
335     return system::GetUintParameter<size_t>("persist.ark.gcthreads", defaultGcThreadNums);
336 }
337 
GetLongPauseTime()338 size_t SystemProperties::GetLongPauseTime()
339 {
340     size_t defaultLongPauseTime = 40; // 40ms
341     return system::GetUintParameter<size_t>("persist.ark.longpausetime", defaultLongPauseTime);
342 }
343 
GetAsmInterpreterEnabled()344 bool SystemProperties::GetAsmInterpreterEnabled()
345 {
346     return system::GetParameter("persist.ark.asminterpreter", "true") == "true";
347 }
348 
GetAsmOpcodeDisableRange()349 std::string SystemProperties::GetAsmOpcodeDisableRange()
350 {
351     return system::GetParameter("persist.ark.asmopcodedisablerange", "");
352 }
353 
IsScoringEnabled(const std::string & name)354 bool SystemProperties::IsScoringEnabled(const std::string& name)
355 {
356     if (name.empty()) {
357         return false;
358     }
359     std::string filePath = "/etc/" + name;
360     if (access(filePath.c_str(), F_OK) == 0) {
361         return true;
362     }
363     std::string prop = system::GetParameter("persist.ace.trace.scoringtool", "");
364     return prop == name;
365 }
366 
GetDeviceType()367 ACE_WEAK_SYM DeviceType SystemProperties::GetDeviceType()
368 {
369     InitDeviceTypeBySystemProperty();
370     return deviceType_;
371 }
372 
InitDeviceTypeBySystemProperty()373 void SystemProperties::InitDeviceTypeBySystemProperty()
374 {
375     if (deviceType_ != DeviceType::UNKNOWN) {
376         return;
377     }
378 
379     auto deviceProp = system::GetParameter(PROPERTY_DEVICE_TYPE, PROPERTY_DEVICE_TYPE_DEFAULT);
380     // Properties: "default", "tv", "tablet", "watch", "car"
381     if (deviceProp == PROPERTY_DEVICE_TYPE_TV) {
382         deviceType_ = DeviceType::TV;
383     } else if (deviceProp == PROPERTY_DEVICE_TYPE_CAR) {
384         deviceType_ = DeviceType::CAR;
385     } else if (deviceProp == PROPERTY_DEVICE_TYPE_WATCH) {
386         deviceType_ = DeviceType::WATCH;
387     } else if (deviceProp == PROPERTY_DEVICE_TYPE_TABLET) {
388         deviceType_ = DeviceType::TABLET;
389     } else if (deviceProp == PROPERTY_DEVICE_TYPE_TWOINONE) {
390         deviceType_ = DeviceType::TWO_IN_ONE;
391     } else {
392         deviceType_ = DeviceType::PHONE;
393     }
394 }
395 
InitDeviceInfo(int32_t deviceWidth,int32_t deviceHeight,int32_t orientation,double resolution,bool isRound)396 void SystemProperties::InitDeviceInfo(
397     int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
398 {
399     // SetDeviceOrientation should be earlier than deviceWidth/deviceHeight init.
400     SetDeviceOrientation(orientation);
401 
402     isRound_ = isRound;
403     resolution_ = resolution;
404     deviceWidth_ = deviceWidth;
405     deviceHeight_ = deviceHeight;
406     brand_ = ::GetBrand();
407     manufacturer_ = ::GetManufacture();
408     model_ = ::GetProductModel();
409     product_ = ::GetMarketName();
410     apiVersion_ = std::to_string(::GetSdkApiVersion());
411     releaseType_ = ::GetOsReleaseType();
412     paramDeviceType_ = ::GetDeviceType();
413 
414     debugEnabled_ = IsDebugEnabled();
415     traceEnabled_ = IsTraceEnabled();
416     svgTraceEnable_ = IsSvgTraceEnabled();
417     layoutTraceEnable_ = IsLayoutTraceEnabled() && IsDeveloperModeOn();
418     buildTraceEnable_ = IsBuildTraceEnabled() && IsDeveloperModeOn();
419     accessibilityEnabled_ = IsAccessibilityEnabled();
420     rosenBackendEnabled_ = IsRosenBackendEnabled();
421     isHookModeEnabled_ = IsHookModeEnabled();
422     debugBoundaryEnabled_ = system::GetParameter(ENABLE_DEBUG_BOUNDARY_KEY, "false") == "true";
423     debugAutoUIEnabled_ = system::GetParameter(ENABLE_DEBUG_AUTOUI_KEY, "false") == "true";
424 
425     downloadByNetworkEnabled_ = system::GetParameter(ENABLE_DOWNLOAD_BY_NETSTACK_KEY, "true") == "true";
426     animationScale_ = std::atof(system::GetParameter(ANIMATION_SCALE_KEY, "1").c_str());
427     WatchParameter(ANIMATION_SCALE_KEY, OnAnimationScaleChanged, nullptr);
428     resourceDecoupling_ = IsResourceDecoupling();
429 
430     navigationBlurEnabled_ = IsNavigationBlurEnabled();
431     gridCacheEnabled_ = IsGridCacheEnabled();
432     sideBarContainerBlurEnable_ = IsSideBarContainerBlurEnable();
433 
434     if (isRound_) {
435         screenShape_ = ScreenShape::ROUND;
436     } else {
437         screenShape_ = ScreenShape::NOT_ROUND;
438     }
439 
440     InitDeviceTypeBySystemProperty();
441 }
442 
SetDeviceOrientation(int32_t orientation)443 ACE_WEAK_SYM void SystemProperties::SetDeviceOrientation(int32_t orientation)
444 {
445     int32_t newOrientation = ((orientation == static_cast<int32_t>(RsOrientation::LANDSCAPE)) ||
446                                  (orientation == static_cast<int32_t>(RsOrientation::LANDSCAPE_INVERTED)))
447                                  ? ORIENTATION_LANDSCAPE
448                                  : ORIENTATION_PORTRAIT;
449     if (newOrientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
450         Swap(deviceWidth_, deviceHeight_);
451         orientation_ = DeviceOrientation::PORTRAIT;
452     } else if (newOrientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
453         Swap(deviceWidth_, deviceHeight_);
454         orientation_ = DeviceOrientation::LANDSCAPE;
455     }
456 }
457 
GetFontWeightScale()458 ACE_WEAK_SYM float SystemProperties::GetFontWeightScale()
459 {
460     // Default value of font weight scale is 1.0.
461     std::string prop =
462         "persist.sys.font_wght_scale_for_user" + std::to_string(AceApplicationInfo::GetInstance().GetUserId());
463     return std::stof(system::GetParameter(prop, "1.0"));
464 }
465 
InitMccMnc(int32_t mcc,int32_t mnc)466 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
467 {
468     mcc_ = mcc;
469     mnc_ = mnc;
470 }
471 
GetDebugEnabled()472 ACE_WEAK_SYM bool SystemProperties::GetDebugEnabled()
473 {
474     return debugEnabled_;
475 }
476 
GetLanguage()477 std::string SystemProperties::GetLanguage()
478 {
479     return system::GetParameter("const.global.language", INVALID_PARAM);
480 }
481 
GetRegion()482 std::string SystemProperties::GetRegion()
483 {
484     return system::GetParameter("const.global.region", INVALID_PARAM);
485 }
486 
GetNewPipePkg()487 std::string SystemProperties::GetNewPipePkg()
488 {
489     return system::GetParameter("persist.ace.newpipe.pkgname", "");
490 }
491 
GetAnimationScale()492 ACE_WEAK_SYM float SystemProperties::GetAnimationScale()
493 {
494     std::shared_lock<std::shared_mutex> lock(mutex_);
495     return animationScale_;
496 }
497 
GetPartialUpdatePkg()498 std::string SystemProperties::GetPartialUpdatePkg()
499 {
500     return system::GetParameter("persist.ace.partial.pkgname", "");
501 }
502 
GetSvgMode()503 int32_t SystemProperties::GetSvgMode()
504 {
505 #ifdef NG_BUILD
506     // disable ace svg before updated to new pipeline
507     return system::GetIntParameter<int>("persist.ace.svg.mode", 0);
508 #else
509     return system::GetIntParameter<int>("persist.ace.svg.mode", 1);
510 #endif
511 }
512 
GetAllowWindowOpenMethodEnabled()513 bool SystemProperties::GetAllowWindowOpenMethodEnabled()
514 {
515     return system::GetBoolParameter("persist.web.allowWindowOpenMethod.enabled", false);
516 }
517 
GetImageFrameworkEnabled()518 bool SystemProperties::GetImageFrameworkEnabled()
519 {
520     return system::GetBoolParameter("persist.ace.image.framework.enabled", true);
521 }
522 
GetDebugPixelMapSaveEnabled()523 bool SystemProperties::GetDebugPixelMapSaveEnabled()
524 {
525     return system::GetBoolParameter("persist.ace.save.pixelmap.enabled", false);
526 }
527 
GetIsUseMemoryMonitor()528 ACE_WEAK_SYM bool SystemProperties::GetIsUseMemoryMonitor()
529 {
530     static bool isUseMemoryMonitor = IsUseMemoryMonitor();
531     return isUseMemoryMonitor;
532 }
533 
IsFormAnimationLimited()534 bool SystemProperties::IsFormAnimationLimited()
535 {
536     return system::GetBoolParameter("persist.sys.arkui.formAnimationLimit", true);
537 }
538 
GetResourceDecoupling()539 bool SystemProperties::GetResourceDecoupling()
540 {
541     return resourceDecoupling_;
542 }
543 
GetTitleStyleEnabled()544 bool SystemProperties::GetTitleStyleEnabled()
545 {
546     return system::GetBoolParameter("persist.ace.title.style.enabled", false);
547 }
548 
GetJankFrameThreshold()549 int32_t SystemProperties::GetJankFrameThreshold()
550 {
551     return system::GetIntParameter<int>("persist.sys.arkui.perf.threshold", DEFAULT_THRESHOLD_JANK);
552 }
553 
GetCustomTitleFilePath()554 ACE_WEAK_SYM std::string SystemProperties::GetCustomTitleFilePath()
555 {
556     return system::GetParameter(CUSTOM_TITLE_KEY, "");
557 }
558 
Is24HourClock()559 ACE_WEAK_SYM bool SystemProperties::Is24HourClock()
560 {
561     return Global::I18n::LocaleConfig::Is24HourClock();
562 }
563 
GetRtlEnabled()564 std::optional<bool> SystemProperties::GetRtlEnabled()
565 {
566     const std::string emptyParam("none");
567     auto ret = system::GetParameter("debug.ace.rtl.enabled", emptyParam);
568     if (ret == emptyParam) {
569         return std::nullopt;
570     } else {
571         return (ret == "true") ? true : false;
572     }
573 }
574 
GetDisplaySyncSkipEnabled()575 bool SystemProperties::GetDisplaySyncSkipEnabled()
576 {
577     return system::GetBoolParameter("debug.ace.displaySyncSkip.enabled", true);
578 }
579 
GetNavigationBlurEnabled()580 bool SystemProperties::GetNavigationBlurEnabled()
581 {
582     return navigationBlurEnabled_;
583 }
584 
GetGridCacheEnabled()585 bool SystemProperties::GetGridCacheEnabled()
586 {
587     return gridCacheEnabled_;
588 }
589 
GetSideBarContainerBlurEnable()590 bool SystemProperties::GetSideBarContainerBlurEnable()
591 {
592     return sideBarContainerBlurEnable_;
593 }
594 
AddWatchSystemParameter(void * context)595 void SystemProperties::AddWatchSystemParameter(void *context)
596 {
597     WatchParameter("persist.ace.trace.layout.enabled", EnableSystemParameterCallback, context);
598     WatchParameter("const.security.developermode.state", EnableSystemParameterCallback, context);
599 }
600 
EnableSystemParameterCallback(const char * key,const char * value,void * context)601 void SystemProperties::EnableSystemParameterCallback(const char *key, const char *value, void *context)
602 {
603     if (context == nullptr) {
604         LOGE("context is nullprt");
605     }
606 
607     if (strcmp(key, "persist.ace.trace.layout.enabled") == 0) {
608         if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
609             layoutTraceEnable_ = strcmp(value, "true") == 0 && IsDeveloperModeOn();
610         }
611         return ;
612     }
613 
614     if (strcmp(key, "const.security.developermode.state") == 0) {
615         if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
616             layoutTraceEnable_ = strcmp(value, "true") == 0 && IsLayoutTraceEnabled();
617         }
618         return ;
619     }
620     LOGE("key %{public}s or value %{public}s mismatch", key, value);
621 }
622 
RemoveWatchSystemParameter(void * context)623 void SystemProperties::RemoveWatchSystemParameter(void *context)
624 {
625     RemoveParameterWatcher("persist.ace.trace.layout.enabled", nullptr, context);
626     RemoveParameterWatcher("const.security.developermode.state", nullptr, context);
627 }
628 
GetDefaultResolution()629 float SystemProperties::GetDefaultResolution()
630 {
631     float density = 1.0f;
632     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
633     if (defaultDisplay) {
634         density = defaultDisplay->GetVirtualPixelRatio();
635     }
636     return density;
637 }
638 } // namespace OHOS::Ace
639