1 /*
2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "base/utils/system_properties.h"
17
18 #include <regex>
19
20 #include "display_info.h"
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
30 #ifdef OHOS_STANDARD_SYSTEM
31 #include "systemcapability.h"
32 #endif
33
34 namespace OHOS::Ace {
35 namespace {
36 constexpr char PROPERTY_DEVICE_TYPE[] = "const.product.devicetype";
37 constexpr char PROPERTY_NEED_AVOID_WINDOW[] = "const.window.need_avoid_window";
38 constexpr char PROPERTY_DEVICE_TYPE_DEFAULT[] = "default";
39 constexpr char PROPERTY_DEVICE_TYPE_TV[] = "tv";
40 constexpr char PROPERTY_DEVICE_TYPE_TABLET[] = "tablet";
41 constexpr char PROPERTY_DEVICE_TYPE_TWOINONE[] = "2in1";
42 constexpr char PROPERTY_DEVICE_TYPE_WATCH[] = "watch";
43 constexpr char PROPERTY_DEVICE_TYPE_CAR[] = "car";
44 constexpr char PROPERTY_DEVICE_TYPE_WEARABLE[] = "wearable";
45 constexpr char PROPERTY_FOLD_TYPE[] = "const.window.foldscreen.type";
46 constexpr char ENABLE_DEBUG_AUTOUI_KEY[] = "persist.ace.debug.autoui.enabled";
47 constexpr char ENABLE_DEBUG_BOUNDARY_KEY[] = "persist.ace.debug.boundary.enabled";
48 constexpr char ENABLE_DOWNLOAD_BY_NETSTACK_KEY[] = "persist.ace.download.netstack.enabled";
49 constexpr char ENABLE_RECYCLE_IMAGE_KEY[] = "persist.ace.recycle.image.enabled";
50 constexpr char ENABLE_DEBUG_OFFSET_LOG_KEY[] = "persist.ace.scrollable.log.enabled";
51 constexpr char ANIMATION_SCALE_KEY[] = "persist.sys.arkui.animationscale";
52 constexpr char CUSTOM_TITLE_KEY[] = "persist.sys.arkui.customtitle";
53 constexpr char DISTRIBUTE_ENGINE_BUNDLE_NAME[] = "atomic.service.distribute.engine.bundle.name";
54 constexpr char IS_OPINC_ENABLE[] = "persist.ddgr.opinctype";
55 constexpr char LAYOUT_BREAKPOINT[] = "const.arkui.layoutbreakpoint";
56 constexpr char LAYOUT_BREAKPOINT_DEFAULT[] = "320,600,1000,1440;0.8,1.2;";
57 enum class LayoutBreakPointPart : uint32_t { WIDTH_PART = 0, HEIGHT_PART };
58 constexpr int32_t ORIENTATION_PORTRAIT = 0;
59 constexpr int32_t ORIENTATION_LANDSCAPE = 1;
60 constexpr int DEFAULT_THRESHOLD_JANK = 15;
61 constexpr float DEFAULT_ANIMATION_SCALE = 1.0f;
62 float animationScale_ = DEFAULT_ANIMATION_SCALE;
63 constexpr int32_t DEFAULT_DRAG_START_DAMPING_RATIO = 20;
64 constexpr int32_t DEFAULT_DRAG_START_PAN_DISTANCE_THRESHOLD_IN_VP = 10;
65 constexpr int32_t DEFAULT_FORM_SHARED_IMAGE_CACHE_THRESHOLD = 20;
66 constexpr int32_t DEFAULT_VELOCITY_TRACKER_POINT_NUMBER = 20;
67 constexpr bool DEFAULT_IS_VELOCITY_WITHIN_TIME_WINDOW = true;
68 constexpr bool DEFAULT_IS_VELOCITY_WITHOUT_UP_POINT = true;
69 std::shared_mutex mutex_;
70 const std::regex FOLD_TYPE_REGEX("^(\\d+)(,\\d+){3,}$");
71 #ifdef ENABLE_ROSEN_BACKEND
72 constexpr char DISABLE_ROSEN_FILE_PATH[] = "/etc/disablerosen";
73 constexpr char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_animation";
74 #endif
75 constexpr int32_t CONVERT_ASTC_THRESHOLD = 2;
76 constexpr int32_t FOLD_TYPE_TWO = 2;
77 constexpr int32_t FOLD_TYPE_FOUR = 4;
78 constexpr float DEFAULT_SCROLL_COEFFICEIENT = 2.0f;
79
IsOpIncEnabled()80 bool IsOpIncEnabled()
81 {
82 return (system::GetParameter(IS_OPINC_ENABLE, "2") == "2");
83 }
84
Swap(int32_t & deviceWidth,int32_t & deviceHeight)85 void Swap(int32_t& deviceWidth, int32_t& deviceHeight)
86 {
87 int32_t temp = deviceWidth;
88 deviceWidth = deviceHeight;
89 deviceHeight = temp;
90 }
91
IsDebugAutoUIEnabled()92 bool IsDebugAutoUIEnabled()
93 {
94 return (system::GetParameter(ENABLE_DEBUG_AUTOUI_KEY, "false") == "true");
95 }
96
IsDebugOffsetLogEnabled()97 bool IsDebugOffsetLogEnabled()
98 {
99 return (system::GetParameter(ENABLE_DEBUG_OFFSET_LOG_KEY, "false") == "true");
100 }
101
IsDebugBoundaryEnabled()102 bool IsDebugBoundaryEnabled()
103 {
104 return system::GetParameter(ENABLE_DEBUG_BOUNDARY_KEY, "false") == "true";
105 }
106
IsDownloadByNetworkDisabled()107 bool IsDownloadByNetworkDisabled()
108 {
109 return system::GetParameter(ENABLE_DOWNLOAD_BY_NETSTACK_KEY, "true") == "true";
110 }
111
IsRecycleImageEnabled()112 bool IsRecycleImageEnabled()
113 {
114 return system::GetParameter(ENABLE_RECYCLE_IMAGE_KEY, "true") == "true";
115 }
116
IsSvgTraceEnabled()117 bool IsSvgTraceEnabled()
118 {
119 return (system::GetParameter("persist.ace.trace.svg.enabled", "0") == "1");
120 }
121
IsLayoutTraceEnabled()122 bool IsLayoutTraceEnabled()
123 {
124 return (system::GetParameter("persist.ace.trace.layout.enabled", "false") == "true");
125 }
126
IsTextTraceEnabled()127 bool IsTextTraceEnabled()
128 {
129 return (system::GetParameter("persist.ace.trace.text.enabled", "false") == "true");
130 }
131
IsSyntaxTraceEnabled()132 bool IsSyntaxTraceEnabled()
133 {
134 return (system::GetParameter("persist.ace.trace.syntax.enabled", "false") == "true");
135 }
136
IsAccessTraceEnabled()137 bool IsAccessTraceEnabled()
138 {
139 return (system::GetParameter("persist.ace.trace.access.enabled", "false") == "true");
140 }
141
IsTraceInputEventEnabled()142 bool IsTraceInputEventEnabled()
143 {
144 return (system::GetParameter("persist.ace.trace.inputevent.enabled", "false") == "true");
145 }
146
IsStateManagerEnable()147 bool IsStateManagerEnable()
148 {
149 return (system::GetParameter("persist.ace.debug.statemgr.enabled", "false") == "true");
150 }
151
IsBuildTraceEnabled()152 bool IsBuildTraceEnabled()
153 {
154 return (system::GetParameter("persist.ace.trace.build.enabled", "false") == "true");
155 }
156
IsDynamicDetectionTraceEnabled()157 bool IsDynamicDetectionTraceEnabled()
158 {
159 return (system::GetParameter("persist.ace.trace.dynamicdetection.enabled", "false") == "true");
160 }
161
IsSyncDebugTraceEnabled()162 bool IsSyncDebugTraceEnabled()
163 {
164 return (system::GetParameter("persist.ace.trace.sync.debug.enabled", "false") == "true");
165 }
166
IsMeasureDebugTraceEnabled()167 bool IsMeasureDebugTraceEnabled()
168 {
169 return (system::GetParameter("persist.ace.trace.measure.debug.enabled", "false") == "true");
170 }
171
IsSafeAreaDebugTraceEnabled()172 bool IsSafeAreaDebugTraceEnabled()
173 {
174 return (system::GetParameter("persist.ace.trace.safeArea.debug.enabled", "false") == "true");
175 }
176
IsVsyncModeDebugTraceEnabled()177 bool IsVsyncModeDebugTraceEnabled()
178 {
179 return system::GetBoolParameter("persist.ace.trace.vsyncMode.debug.enabled", false);
180 }
181
IsDeveloperModeOn()182 bool IsDeveloperModeOn()
183 {
184 return (system::GetParameter("const.security.developermode.state", "false") == "true");
185 }
186
IsWindowRectResizeEnabled()187 bool IsWindowRectResizeEnabled()
188 {
189 return (system::GetParameter("persist.ace.windowresize.enabled", "true") == "true");
190 }
191
IsFocusCanBeActive()192 bool IsFocusCanBeActive()
193 {
194 return system::GetParameter("persist.gesture.smart_gesture_enable", "1") != "0";
195 }
196
IsCacheNavigationNodeEnable()197 bool IsCacheNavigationNodeEnable()
198 {
199 return system::GetParameter("persist.ace.navigation.groupnode.cached", "true") == "true";
200 }
201
IsHookModeEnabled()202 bool IsHookModeEnabled()
203 {
204 #ifdef PREVIEW
205 return false;
206 #endif
207 const int bufferLen = 128;
208 char paramOutBuf[bufferLen] = { 0 };
209 constexpr char hook_mode[] = "startup:";
210 int ret = GetParameter("persist.libc.hook_mode", "", paramOutBuf, bufferLen);
211 if (ret <= 0 || strncmp(paramOutBuf, hook_mode, strlen(hook_mode)) != 0) {
212 return false;
213 }
214 return true;
215 }
216
IsRosenBackendEnabled()217 bool IsRosenBackendEnabled()
218 {
219 #ifdef PREVIEW
220 return false;
221 #endif
222 #ifdef ENABLE_ROSEN_BACKEND
223 if (system::GetParameter("persist.ace.rosen.backend.enabled", "0") == "1") {
224 return true;
225 }
226 if (system::GetParameter("persist.ace.rosen.backend.enabled", "0") == "2") {
227 return false;
228 }
229 if (access(DISABLE_ROSEN_FILE_PATH, F_OK) == 0) {
230 return false;
231 }
232 return true;
233 #else
234 return false;
235 #endif
236 }
237
IsWindowAnimationEnabled()238 bool IsWindowAnimationEnabled()
239 {
240 #ifdef PREVIEW
241 return false;
242 #endif
243 #ifdef ENABLE_ROSEN_BACKEND
244 if (access(DISABLE_WINDOW_ANIMATION_PATH, F_OK) == 0) {
245 return false;
246 }
247 return true;
248 #else
249 return false;
250 #endif
251 }
252
IsAccessibilityEnabled()253 bool IsAccessibilityEnabled()
254 {
255 return (system::GetParameter("persist.ace.testmode.enabled", "0") == "1" ||
256 system::GetParameter("debug.ace.testmode.enabled", "0") == "1");
257 }
258
IsDebugEnabled()259 bool IsDebugEnabled()
260 {
261 return (system::GetParameter("persist.ace.debug.enabled", "0") == "1");
262 }
263
IsMouseTransformEnable()264 bool IsMouseTransformEnable()
265 {
266 return (system::GetParameter("persist.ace.event.transform.enable", "1") == "1");
267 }
268
ReadScrollCoefficients()269 float ReadScrollCoefficients()
270 {
271 auto ret = system::GetParameter("persist.ace.scroll.coefficeient", "2.0");
272 if (StringUtils::IsNumber(ret)) {
273 return StringUtils::StringToFloat(ret);
274 }
275 return DEFAULT_SCROLL_COEFFICEIENT;
276 }
277
GetDebugFlags()278 int64_t GetDebugFlags()
279 {
280 return system::GetIntParameter<int64_t>("persist.ace.debug.flags", 0);
281 }
282
IsContainerDeleteFlag()283 bool IsContainerDeleteFlag()
284 {
285 return (system::GetParameter("persist.container.delete", "true") == "true");
286 }
287
IsMultiInstanceEnabled()288 bool IsMultiInstanceEnabled()
289 {
290 return (system::GetParameter("persist.rosen.rsclientmultiinstance.enabled", "0") != "0");
291 }
292
IsLayoutDetectEnabled()293 bool IsLayoutDetectEnabled()
294 {
295 return (system::GetParameter("persist.ace.layoutdetect.enabled", "0") == "1");
296 }
297
IsConfigChangePerform()298 bool IsConfigChangePerform()
299 {
300 return system::GetBoolParameter("persist.sys.arkui.configchangeperform", false);
301 }
302
IsNavigationBlurEnabled()303 bool IsNavigationBlurEnabled()
304 {
305 return (system::GetParameter("persist.ace.navigation.blur.enabled", "0") == "1");
306 }
307
IsForceSplitIgnoreOrientationEnabled()308 bool IsForceSplitIgnoreOrientationEnabled()
309 {
310 return (system::GetParameter("persist.ace.navigation.ignoreorientation.enabled", "0") == "1");
311 }
312
IsArkUIHookEnabled()313 std::optional<bool> IsArkUIHookEnabled()
314 {
315 auto enabledValue = system::GetParameter("persist.ace.arkuihook.enabled", "NA");
316 if (enabledValue == "true") {
317 return true;
318 } else if (enabledValue == "false") {
319 return false;
320 } else {
321 return std::nullopt;
322 }
323 }
324
IsGridCacheEnabled()325 bool IsGridCacheEnabled()
326 {
327 return (system::GetParameter("persist.ace.grid.cache.enabled", "1") == "1");
328 }
329
IsGridIrregularLayoutEnabled()330 bool IsGridIrregularLayoutEnabled()
331 {
332 return (system::GetParameter("persist.ace.grid.irregular.enabled", "false") == "true");
333 }
334
IsSideBarContainerBlurEnable()335 bool IsSideBarContainerBlurEnable()
336 {
337 return (system::GetParameter("persist.ace.sidebar.blur.enabled", "0") == "1");
338 }
339
IsGpuUploadEnabled()340 bool IsGpuUploadEnabled()
341 {
342 return (system::GetParameter("persist.ace.gpuupload.enabled", "0") == "1" ||
343 system::GetParameter("debug.ace.gpuupload.enabled", "0") == "1");
344 }
345
IsImageFrameworkEnabled()346 bool IsImageFrameworkEnabled()
347 {
348 return system::GetBoolParameter("persist.ace.image.framework.enabled", true);
349 }
350
OnAnimationScaleChanged(const char * key,const char * value,void * context)351 void OnAnimationScaleChanged(const char* key, const char* value, void* context)
352 {
353 CHECK_NULL_VOID(key);
354 if (strcmp(key, ANIMATION_SCALE_KEY) != 0) {
355 LOGE("AnimationScale key not matched. key: %{public}s", key);
356 return;
357 }
358 std::unique_lock<std::shared_mutex> lock(mutex_);
359 if (value == nullptr) {
360 LOGW("AnimationScale changes with null value, use default. key: %{public}s", key);
361 animationScale_ = DEFAULT_ANIMATION_SCALE;
362 return;
363 }
364 auto animationScale = std::atof(value);
365 if (animationScale < 0.0f) {
366 LOGE("AnimationScale changes with invalid value: %{public}s. ignore", value);
367 return;
368 }
369 LOGI("AnimationScale: %{public}f -> %{public}f", animationScale_, animationScale);
370 animationScale_ = animationScale;
371 }
372
GetSysDumpFrameCount()373 uint32_t GetSysDumpFrameCount()
374 {
375 return system::GetUintParameter<uint32_t>(
376 "persist.ace.framedumpcount", 10); // 10: Pipeline dump of the last 10 frames' task.
377 }
378
GetAstcEnabled()379 bool GetAstcEnabled()
380 {
381 return system::GetParameter("persist.astc.enable", "true") == "true";
382 }
383
GetAstcMaxErrorProp()384 int32_t GetAstcMaxErrorProp()
385 {
386 return system::GetIntParameter<int>("persist.astc.max", 50000); // 50000: Anomaly threshold of astc.
387 }
388
GetAstcPsnrProp()389 int32_t GetAstcPsnrProp()
390 {
391 return system::GetIntParameter<int>("persist.astc.psnr", 0);
392 }
393
GetImageFileCacheConvertToAstcEnabled()394 bool GetImageFileCacheConvertToAstcEnabled()
395 {
396 return system::GetParameter("persist.image.filecache.astc.enable", "false") == "true";
397 }
398
GetImageFileCacheConvertAstcThresholdProp()399 int32_t GetImageFileCacheConvertAstcThresholdProp()
400 {
401 return system::GetIntParameter<int>("persist.image.filecache.astc.threshold", CONVERT_ASTC_THRESHOLD);
402 }
403
IsUseMemoryMonitor()404 bool IsUseMemoryMonitor()
405 {
406 return (system::GetParameter("persist.ace.memorymonitor.enabled", "0") == "1");
407 }
408
IsExtSurfaceEnabled()409 bool IsExtSurfaceEnabled()
410 {
411 #ifdef EXT_SURFACE_ENABLE
412 return true;
413 #else
414 return false;
415 #endif
416 }
417
IsEnableScrollableItemPool()418 bool IsEnableScrollableItemPool()
419 {
420 return system::GetBoolParameter("persist.ace.scrollablepool.enabled", false);
421 }
422
IsResourceDecoupling()423 bool IsResourceDecoupling()
424 {
425 return system::GetBoolParameter("persist.sys.arkui.resource.decoupling", true);
426 }
427
IsAcePerformanceMonitorEnabled()428 bool IsAcePerformanceMonitorEnabled()
429 {
430 return system::GetBoolParameter("persist.ace.performance.monitor.enabled", false);
431 }
432
IsAceCommercialLogEnable()433 bool IsAceCommercialLogEnable()
434 {
435 return system::GetParameter("const.logsystem.versiontype", "commercial") == "commercial";
436 }
437
ReadVelocityTrackerPointNumber()438 int32_t ReadVelocityTrackerPointNumber()
439 {
440 return system::GetIntParameter("persist.sys.arkui.velocitytracker.pointnum", DEFAULT_VELOCITY_TRACKER_POINT_NUMBER);
441 }
442
ReadIsVelocityWithinTimeWindow()443 bool ReadIsVelocityWithinTimeWindow()
444 {
445 return system::GetBoolParameter(
446 "persist.sys.arkui.velocitytracker.withintimewindow", DEFAULT_IS_VELOCITY_WITHIN_TIME_WINDOW);
447 }
448
ReadIsVelocityWithoutUpPoint()449 bool ReadIsVelocityWithoutUpPoint()
450 {
451 return system::GetBoolParameter(
452 "persist.sys.arkui.velocitytracker.withoutuppoint", DEFAULT_IS_VELOCITY_WITHOUT_UP_POINT);
453 }
454
IsPrebuildInMultiFrameEnabled()455 bool IsPrebuildInMultiFrameEnabled()
456 {
457 return system::GetBoolParameter("persist.ace.prebuild_in_multi_frame.enabled", false);
458 }
459 } // namespace
460
ReadDragStartDampingRatio()461 float ReadDragStartDampingRatio()
462 {
463 return system::GetIntParameter("debug.ace.drag.damping.ratio", DEFAULT_DRAG_START_DAMPING_RATIO) / 100.0f;
464 }
465
ReadDragStartPanDistanceThreshold()466 float ReadDragStartPanDistanceThreshold()
467 {
468 return system::GetIntParameter("debug.ace.drag.pan.threshold",
469 DEFAULT_DRAG_START_PAN_DISTANCE_THRESHOLD_IN_VP) * 1.0f;
470 }
471
ReadCanvasDebugMode()472 uint32_t ReadCanvasDebugMode()
473 {
474 return system::GetUintParameter("persist.ace.canvas.debug.mode", 0u);
475 }
476
IsFaultInjectEnabled()477 bool IsFaultInjectEnabled()
478 {
479 return (system::GetParameter("persist.ace.fault.inject.enabled", "false") == "true");
480 }
481
ReadScrollableDistance()482 double ReadScrollableDistance()
483 {
484 auto ret = system::GetParameter("persist.scrollable.distance", "");
485 return StringUtils::StringToDouble(ret);
486 }
487
GetPercent()488 std::pair<float, float> GetPercent()
489 {
490 std::vector<double> result;
491 StringUtils::StringSplitter(
492 system::GetParameter("const.ace.darkModeAppBGColorBrightness", "0.10,0.05"), ',', result);
493 std::pair<float, float> percent(result.front(), result.back());
494 return percent;
495 }
496
GetPageCountProp()497 int32_t GetPageCountProp()
498 {
499 float pageCount = std::atof(system::GetParameter("persist.ace.cachedcount.page_count", "1.0").c_str());
500 return pageCount > 0.0f ? pageCount : 0.0f;
501 }
502
IsTaskPriorityAdjustmentEnable()503 bool IsTaskPriorityAdjustmentEnable()
504 {
505 int32_t appVsyncPriority = system::GetIntParameter("const.graphic.app_vsync_priority", -1);
506 bool isArkUIEnable = system::GetBoolParameter("persist.sys.arkui.task_priority.enabled", false);
507 return appVsyncPriority != -1 && isArkUIEnable;
508 }
509
ReadDragDropFrameworkStatus()510 int32_t ReadDragDropFrameworkStatus()
511 {
512 return system::GetIntParameter("debug.ace.drag.drop.framework.status", 0);
513 }
514
ReadTouchAccelarateMode()515 int32_t ReadTouchAccelarateMode()
516 {
517 return system::GetIntParameter("debug.ace.touch.accelarate", 0);
518 }
519
IsAscending(const std::vector<double> & nums)520 bool IsAscending(const std::vector<double>& nums)
521 {
522 for (size_t i = 1; i < nums.size(); ++i) {
523 if (nums[i] < nums[i - 1]) {
524 return false;
525 }
526 }
527 return true;
528 }
529
ParseBreakPoints(const std::string & input,const size_t expectedCount,std::vector<double> & breakpointsVec)530 bool ParseBreakPoints(const std::string& input, const size_t expectedCount, std::vector<double>& breakpointsVec)
531 {
532 std::vector<std::string> numStrVec;
533 StringUtils::StringSplitter(input, ',', numStrVec);
534 if (numStrVec.size() != expectedCount) {
535 return false;
536 }
537 for (const std::string& numStr : numStrVec) {
538 std::string s = StringUtils::TrimStr(numStr);
539 if (!StringUtils::IsFloat(s)) {
540 return false;
541 }
542 double num = StringUtils::StringToDouble(s);
543 if (LessOrEqual(num, 0)) {
544 return false;
545 }
546 breakpointsVec.push_back(num);
547 }
548 return IsAscending(breakpointsVec);
549 }
550
ParseWidthBreakPoints(const std::string & input,std::vector<double> & breakpointsVec)551 bool ParseWidthBreakPoints(const std::string& input, std::vector<double>& breakpointsVec)
552 {
553 // 4 means that there are exactly 4 layout break points in the horizontal direction
554 return ParseBreakPoints(input, 4, breakpointsVec);
555 }
556
ParseHeightBreakPoints(const std::string & input,std::vector<double> & breakpointsVec)557 bool ParseHeightBreakPoints(const std::string& input, std::vector<double>& breakpointsVec)
558 {
559 // 2 means that there are exactly 2 layout break points in the vertical direction
560 return ParseBreakPoints(input, 2, breakpointsVec);
561 }
562
GetLayoutBreakpoints(WidthLayoutBreakPoint & widthLayoutBreakpoints,HeightLayoutBreakPoint & heightLayoutBreakpoints)563 void GetLayoutBreakpoints(WidthLayoutBreakPoint& widthLayoutBreakpoints,
564 HeightLayoutBreakPoint& heightLayoutBreakpoints)
565 {
566 auto param = StringUtils::TrimStr(system::GetParameter(LAYOUT_BREAKPOINT, LAYOUT_BREAKPOINT_DEFAULT));
567 if (param == LAYOUT_BREAKPOINT_DEFAULT) {
568 return;
569 }
570
571 std::vector<std::string> parts;
572 StringUtils::StringSplitter(param, ';', parts);
573 // 2 means that "const.arkui.layoutbreakpoint" must have exactly two parts
574 if (parts.size() != 2) {
575 return;
576 }
577 bool parseRet = false;
578 std::vector<double> widthLayoutBreakpointsVec;
579 if (ParseWidthBreakPoints(parts[static_cast<uint32_t>(LayoutBreakPointPart::WIDTH_PART)],
580 widthLayoutBreakpointsVec)) {
581 widthLayoutBreakpoints = WidthLayoutBreakPoint(widthLayoutBreakpointsVec[0],
582 widthLayoutBreakpointsVec[1], widthLayoutBreakpointsVec[2], widthLayoutBreakpointsVec[3]);
583 parseRet = true;
584 }
585
586 std::vector<double> heightLayoutBreakpointsVec;
587 if (parseRet && ParseHeightBreakPoints(parts[static_cast<uint32_t>(LayoutBreakPointPart::HEIGHT_PART)],
588 heightLayoutBreakpointsVec)) {
589 heightLayoutBreakpoints = HeightLayoutBreakPoint(heightLayoutBreakpointsVec[0], heightLayoutBreakpointsVec[1]);
590 } else {
591 widthLayoutBreakpoints = WidthLayoutBreakPoint();
592 }
593 }
594
InitSysBrand()595 std::string InitSysBrand()
596 {
597 const char* res = ::GetBrand();
598 if (res) {
599 return std::string(res);
600 }
601 return SystemProperties::INVALID_PARAM;
602 }
603
InitSysManufacture()604 std::string InitSysManufacture()
605 {
606 const char* res = ::GetManufacture();
607 if (res) {
608 return std::string(res);
609 }
610 return SystemProperties::INVALID_PARAM;
611 }
612
InitSysProductModel()613 std::string InitSysProductModel()
614 {
615 const char* res = ::GetProductModel();
616 if (res) {
617 return std::string(res);
618 }
619 return SystemProperties::INVALID_PARAM;
620 }
621
InitSysMarketName()622 std::string InitSysMarketName()
623 {
624 const char* res = ::GetMarketName();
625 if (res) {
626 return std::string(res);
627 }
628 return SystemProperties::INVALID_PARAM;
629 }
630
InitSysSdkApiVersion()631 std::string InitSysSdkApiVersion()
632 {
633 return std::to_string(::GetSdkApiVersion());
634 }
635
InitSysOsReleaseType()636 std::string InitSysOsReleaseType()
637 {
638 const char* res = ::GetOsReleaseType();
639 if (res) {
640 return std::string(res);
641 }
642 return SystemProperties::INVALID_PARAM;
643 }
644
InitSysDeviceType()645 std::string InitSysDeviceType()
646 {
647 const char* res = ::GetDeviceType();
648 if (res) {
649 return std::string(res);
650 }
651 return SystemProperties::INVALID_PARAM;
652 }
653
654 bool SystemProperties::svgTraceEnable_ = IsSvgTraceEnabled();
655 bool SystemProperties::developerModeOn_ = IsDeveloperModeOn();
656 std::atomic<bool> SystemProperties::layoutTraceEnable_(IsLayoutTraceEnabled() && developerModeOn_);
657 bool SystemProperties::imageFrameworkEnable_ = IsImageFrameworkEnabled();
658 std::atomic<bool> SystemProperties::traceInputEventEnable_(IsTraceInputEventEnabled() && developerModeOn_);
659 std::atomic<bool> SystemProperties::stateManagerEnable_(IsStateManagerEnable());
660 bool SystemProperties::buildTraceEnable_ = IsBuildTraceEnabled() && developerModeOn_;
661 bool SystemProperties::dynamicDetectionTraceEnable_ = IsDynamicDetectionTraceEnabled();
662 bool SystemProperties::cacheNavigationNodeEnable_ = IsCacheNavigationNodeEnable();
663 bool SystemProperties::syncDebugTraceEnable_ = IsSyncDebugTraceEnabled();
664 bool SystemProperties::measureDebugTraceEnable_ = IsMeasureDebugTraceEnabled();
665 bool SystemProperties::safeAreaDebugTraceEnable_ = IsSafeAreaDebugTraceEnabled();
666 bool SystemProperties::pixelRoundEnable_ = IsPixelRoundEnabled();
667 bool SystemProperties::textTraceEnable_ = IsTextTraceEnabled();
668 bool SystemProperties::syntaxTraceEnable_ = IsSyntaxTraceEnabled();
669 bool SystemProperties::accessTraceEnable_ = IsAccessTraceEnabled();
670 bool SystemProperties::vsyncModeTraceEnable_ = IsVsyncModeDebugTraceEnabled();
671 bool SystemProperties::accessibilityEnabled_ = IsAccessibilityEnabled();
672 bool SystemProperties::isRound_ = false;
673 bool SystemProperties::isDeviceAccess_ = false;
674 ACE_WEAK_SYM int32_t SystemProperties::deviceWidth_ = 0;
675 ACE_WEAK_SYM int32_t SystemProperties::deviceHeight_ = 0;
676 ACE_WEAK_SYM int32_t SystemProperties::devicePhysicalWidth_ = 0;
677 ACE_WEAK_SYM int32_t SystemProperties::devicePhysicalHeight_ = 0;
678 ACE_WEAK_SYM double SystemProperties::resolution_ = 1.0;
679 ACE_WEAK_SYM DeviceType SystemProperties::deviceType_ { DeviceType::UNKNOWN };
680 ACE_WEAK_SYM FoldScreenType SystemProperties::foldScreenType_ { FoldScreenType::UNKNOWN };
681 ACE_WEAK_SYM bool SystemProperties::needAvoidWindow_ { false };
682 ACE_WEAK_SYM DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
683 std::string SystemProperties::brand_ = InitSysBrand();
684 std::string SystemProperties::manufacturer_ = InitSysManufacture();
685 std::string SystemProperties::model_ = InitSysProductModel();
686 std::string SystemProperties::product_ = InitSysMarketName();
687 std::string SystemProperties::apiVersion_ = InitSysSdkApiVersion();
688 std::string SystemProperties::releaseType_ = InitSysOsReleaseType();
689 std::string SystemProperties::paramDeviceType_ = InitSysDeviceType();
690 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
691 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
692 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
693 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
694 bool SystemProperties::unZipHap_ = true;
695 ACE_WEAK_SYM bool SystemProperties::rosenBackendEnabled_ = IsRosenBackendEnabled();
696 ACE_WEAK_SYM bool SystemProperties::isHookModeEnabled_ = IsHookModeEnabled();
697 std::atomic<bool> SystemProperties::debugBoundaryEnabled_(IsDebugBoundaryEnabled() && developerModeOn_);
698 bool SystemProperties::debugAutoUIEnabled_ = IsDebugAutoUIEnabled();
699 bool SystemProperties::downloadByNetworkEnabled_ = IsDownloadByNetworkDisabled();
700 bool SystemProperties::recycleImageEnabled_ = IsRecycleImageEnabled();
701 bool SystemProperties::debugOffsetLogEnabled_ = IsDebugOffsetLogEnabled();
702 ACE_WEAK_SYM bool SystemProperties::windowAnimationEnabled_ = IsWindowAnimationEnabled();
703 ACE_WEAK_SYM bool SystemProperties::debugEnabled_ = IsDebugEnabled();
704 std::string SystemProperties::configDeviceType_ = "";
705 ACE_WEAK_SYM bool SystemProperties::transformEnabled_ = IsMouseTransformEnable();
706 float SystemProperties::scrollCoefficients_ = ReadScrollCoefficients();
707 ACE_WEAK_SYM DebugFlags SystemProperties::debugFlags_ = GetDebugFlags();
708 ACE_WEAK_SYM bool SystemProperties::containerDeleteFlag_ = IsContainerDeleteFlag();
709 ACE_WEAK_SYM bool SystemProperties::multiInstanceEnabled_ = IsMultiInstanceEnabled();
710 ACE_WEAK_SYM bool SystemProperties::layoutDetectEnabled_ = IsLayoutDetectEnabled();
711 bool SystemProperties::gpuUploadEnabled_ = IsGpuUploadEnabled();
712 bool SystemProperties::astcEnabled_ = GetAstcEnabled();
713 int32_t SystemProperties::astcMax_ = GetAstcMaxErrorProp();
714 int32_t SystemProperties::astcPsnr_ = GetAstcPsnrProp();
715 bool SystemProperties::imageFileCacheConvertAstc_ = GetImageFileCacheConvertToAstcEnabled();
716 int32_t SystemProperties::imageFileCacheConvertAstcThreshold_ = GetImageFileCacheConvertAstcThresholdProp();
717 ACE_WEAK_SYM bool SystemProperties::extSurfaceEnabled_ = IsExtSurfaceEnabled();
718 ACE_WEAK_SYM uint32_t SystemProperties::dumpFrameCount_ = GetSysDumpFrameCount();
719 ACE_WEAK_SYM bool SystemProperties::windowRectResizeEnabled_ = IsWindowRectResizeEnabled();
720 bool SystemProperties::enableScrollableItemPool_ = IsEnableScrollableItemPool();
721 bool SystemProperties::resourceDecoupling_ = IsResourceDecoupling();
722 bool SystemProperties::configChangePerform_ = IsConfigChangePerform();
723 bool SystemProperties::navigationBlurEnabled_ = IsNavigationBlurEnabled();
724 bool SystemProperties::forceSplitIgnoreOrientationEnabled_ = IsForceSplitIgnoreOrientationEnabled();
725 std::optional<bool> SystemProperties::arkUIHookEnabled_ = IsArkUIHookEnabled();
726 bool SystemProperties::gridCacheEnabled_ = IsGridCacheEnabled();
727 bool SystemProperties::gridIrregularLayoutEnable_ = IsGridIrregularLayoutEnabled();
728 std::pair<float, float> SystemProperties::brightUpPercent_ = GetPercent();
729 float SystemProperties::pageCount_ = GetPageCountProp();
730 bool SystemProperties::sideBarContainerBlurEnable_ = IsSideBarContainerBlurEnable();
731 std::atomic<bool> SystemProperties::acePerformanceMonitorEnable_(IsAcePerformanceMonitorEnabled());
732 std::atomic<bool> SystemProperties::focusCanBeActive_(IsFocusCanBeActive());
733 bool SystemProperties::aceCommercialLogEnable_ = IsAceCommercialLogEnable();
734 bool SystemProperties::faultInjectEnabled_ = IsFaultInjectEnabled();
735 bool SystemProperties::opincEnabled_ = IsOpIncEnabled();
736 float SystemProperties::dragStartDampingRatio_ = ReadDragStartDampingRatio();
737 float SystemProperties::dragStartPanDisThreshold_ = ReadDragStartPanDistanceThreshold();
738 uint32_t SystemProperties::canvasDebugMode_ = ReadCanvasDebugMode();
739 float SystemProperties::fontScale_ = 1.0;
740 float SystemProperties::fontWeightScale_ = 1.0;
741 double SystemProperties::scrollableDistance_ = ReadScrollableDistance();
742 bool SystemProperties::taskPriorityAdjustmentEnable_ = IsTaskPriorityAdjustmentEnable();
743 int32_t SystemProperties::dragDropFrameworkStatus_ = ReadDragDropFrameworkStatus();
744 int32_t SystemProperties::touchAccelarate_ = ReadTouchAccelarateMode();
745 bool SystemProperties::pageTransitionFrzEnabled_ = false;
746 bool SystemProperties::softPagetransition_ = false;
747 bool SystemProperties::formSkeletonBlurEnabled_ = true;
748 int32_t SystemProperties::formSharedImageCacheThreshold_ = DEFAULT_FORM_SHARED_IMAGE_CACHE_THRESHOLD;
749 WidthLayoutBreakPoint SystemProperties::widthLayoutBreakpoints_ = WidthLayoutBreakPoint();
750 HeightLayoutBreakPoint SystemProperties::heightLayoutBreakpoints_ = HeightLayoutBreakPoint();
751 bool SystemProperties::syncLoadEnabled_ = true;
752 bool SystemProperties::whiteBlockEnabled_ = false;
753 int32_t SystemProperties::previewStatus_ = 0;
754 int32_t SystemProperties::velocityTrackerPointNumber_ = ReadVelocityTrackerPointNumber();
755 bool SystemProperties::isVelocityWithinTimeWindow_ = ReadIsVelocityWithinTimeWindow();
756 bool SystemProperties::isVelocityWithoutUpPoint_ = ReadIsVelocityWithoutUpPoint();
757 bool SystemProperties::prebuildInMultiFrameEnabled_ = IsPrebuildInMultiFrameEnabled();
758
IsOpIncEnable()759 bool SystemProperties::IsOpIncEnable()
760 {
761 return opincEnabled_;
762 }
763
IsSyscapExist(const char * cap)764 bool SystemProperties::IsSyscapExist(const char* cap)
765 {
766 #ifdef OHOS_STANDARD_SYSTEM
767 return HasSystemCapability(cap);
768 #else
769 return false;
770 #endif
771 }
772
IsApiVersionGreaterOrEqual(int majorVersion,int minorVersion,int patchVersion)773 bool SystemProperties::IsApiVersionGreaterOrEqual(int majorVersion, int minorVersion, int patchVersion)
774 {
775 #ifdef OHOS_STANDARD_SYSTEM
776 return CheckApiVersionGreaterOrEqual(majorVersion, minorVersion, patchVersion);
777 #else
778 return false;
779 #endif
780 }
781
InitDeviceType(DeviceType)782 void SystemProperties::InitDeviceType(DeviceType)
783 {
784 // Do nothing, no need to store type here, use system property at 'GetDeviceType' instead.
785 }
786
GetArkProperties()787 int SystemProperties::GetArkProperties()
788 {
789 return system::GetIntParameter<int>("persist.ark.properties", -1);
790 }
791
GetMemConfigProperty()792 std::string SystemProperties::GetMemConfigProperty()
793 {
794 return system::GetParameter("persist.ark.mem_config_property", "");
795 }
796
GetArkBundleName()797 std::string SystemProperties::GetArkBundleName()
798 {
799 return system::GetParameter("persist.ark.arkbundlename", "");
800 }
801
GetGcThreadNum()802 size_t SystemProperties::GetGcThreadNum()
803 {
804 size_t defaultGcThreadNums = 7;
805 return system::GetUintParameter<size_t>("persist.ark.gcthreads", defaultGcThreadNums);
806 }
807
GetLongPauseTime()808 size_t SystemProperties::GetLongPauseTime()
809 {
810 size_t defaultLongPauseTime = 40; // 40ms
811 return system::GetUintParameter<size_t>("persist.ark.longpausetime", defaultLongPauseTime);
812 }
813
GetAsmInterpreterEnabled()814 bool SystemProperties::GetAsmInterpreterEnabled()
815 {
816 return system::GetParameter("persist.ark.asminterpreter", "true") == "true";
817 }
818
GetAsmOpcodeDisableRange()819 std::string SystemProperties::GetAsmOpcodeDisableRange()
820 {
821 return system::GetParameter("persist.ark.asmopcodedisablerange", "");
822 }
823
IsScoringEnabled(const std::string & name)824 bool SystemProperties::IsScoringEnabled(const std::string& name)
825 {
826 if (name.empty()) {
827 return false;
828 }
829 std::string filePath = "/etc/" + name;
830 if (access(filePath.c_str(), F_OK) == 0) {
831 return true;
832 }
833 std::string prop = system::GetParameter("persist.ace.trace.scoringtool", "");
834 return prop == name;
835 }
836
GetDeviceType()837 ACE_WEAK_SYM DeviceType SystemProperties::GetDeviceType()
838 {
839 InitDeviceTypeBySystemProperty();
840 return deviceType_;
841 }
842
GetNeedAvoidWindow()843 ACE_WEAK_SYM bool SystemProperties::GetNeedAvoidWindow()
844 {
845 return needAvoidWindow_;
846 }
847
InitDeviceTypeBySystemProperty()848 void SystemProperties::InitDeviceTypeBySystemProperty()
849 {
850 if (deviceType_ != DeviceType::UNKNOWN) {
851 return;
852 }
853
854 auto deviceProp = system::GetParameter(PROPERTY_DEVICE_TYPE, PROPERTY_DEVICE_TYPE_DEFAULT);
855 // Properties: "default", "tv", "tablet", "watch", "car"
856 if (deviceProp == PROPERTY_DEVICE_TYPE_TV) {
857 deviceType_ = DeviceType::TV;
858 } else if (deviceProp == PROPERTY_DEVICE_TYPE_CAR) {
859 deviceType_ = DeviceType::CAR;
860 } else if (deviceProp == PROPERTY_DEVICE_TYPE_WATCH) {
861 deviceType_ = DeviceType::WATCH;
862 } else if (deviceProp == PROPERTY_DEVICE_TYPE_TABLET) {
863 deviceType_ = DeviceType::TABLET;
864 } else if (deviceProp == PROPERTY_DEVICE_TYPE_TWOINONE) {
865 deviceType_ = DeviceType::TWO_IN_ONE;
866 } else if (deviceProp == PROPERTY_DEVICE_TYPE_WEARABLE) {
867 deviceType_ = DeviceType::WEARABLE;
868 } else {
869 deviceType_ = DeviceType::PHONE;
870 }
871 }
872
InitDeviceInfo(int32_t deviceWidth,int32_t deviceHeight,int32_t orientation,double resolution,bool isRound)873 void SystemProperties::InitDeviceInfo(
874 int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
875 {
876 // SetDeviceOrientation should be earlier than deviceWidth/deviceHeight init.
877 SetDeviceOrientation(orientation);
878 isRound_ = isRound;
879 resolution_ = resolution;
880 deviceWidth_ = deviceWidth;
881 deviceHeight_ = deviceHeight;
882 needAvoidWindow_ = system::GetBoolParameter(PROPERTY_NEED_AVOID_WINDOW, false);
883 debugEnabled_ = IsDebugEnabled();
884 transformEnabled_ = IsMouseTransformEnable();
885 debugFlags_ = GetDebugFlags();
886 layoutDetectEnabled_ = IsLayoutDetectEnabled();
887 multiInstanceEnabled_ = IsMultiInstanceEnabled();
888 svgTraceEnable_ = IsSvgTraceEnabled();
889 layoutTraceEnable_.store(IsLayoutTraceEnabled() && developerModeOn_);
890 traceInputEventEnable_.store(IsTraceInputEventEnabled() && developerModeOn_);
891 stateManagerEnable_.store(IsStateManagerEnable());
892 buildTraceEnable_ = IsBuildTraceEnabled() && developerModeOn_;
893 dynamicDetectionTraceEnable_ = IsDynamicDetectionTraceEnabled();
894 syncDebugTraceEnable_ = IsSyncDebugTraceEnabled();
895 measureDebugTraceEnable_ = IsMeasureDebugTraceEnabled();
896 safeAreaDebugTraceEnable_ = IsSafeAreaDebugTraceEnabled();
897 vsyncModeTraceEnable_ = IsVsyncModeDebugTraceEnabled();
898 pixelRoundEnable_ = IsPixelRoundEnabled();
899 accessibilityEnabled_ = IsAccessibilityEnabled();
900 canvasDebugMode_ = ReadCanvasDebugMode();
901 isHookModeEnabled_ = IsHookModeEnabled();
902 debugAutoUIEnabled_ = system::GetParameter(ENABLE_DEBUG_AUTOUI_KEY, "false") == "true";
903 debugOffsetLogEnabled_ = system::GetParameter(ENABLE_DEBUG_OFFSET_LOG_KEY, "false") == "true";
904 downloadByNetworkEnabled_ = system::GetParameter(ENABLE_DOWNLOAD_BY_NETSTACK_KEY, "true") == "true";
905 recycleImageEnabled_ = system::GetParameter(ENABLE_RECYCLE_IMAGE_KEY, "true") == "true";
906 animationScale_ = std::atof(system::GetParameter(ANIMATION_SCALE_KEY, "1").c_str());
907 pageTransitionFrzEnabled_ = system::GetBoolParameter("const.arkui.pagetransitionfreeze", false);
908 softPagetransition_ = system::GetBoolParameter("const.arkui.softPagetransition", false);
909 WatchParameter(ANIMATION_SCALE_KEY, OnAnimationScaleChanged, nullptr);
910 resourceDecoupling_ = IsResourceDecoupling();
911 configChangePerform_ = IsConfigChangePerform();
912 navigationBlurEnabled_ = IsNavigationBlurEnabled();
913 forceSplitIgnoreOrientationEnabled_ = IsForceSplitIgnoreOrientationEnabled();
914 arkUIHookEnabled_ = IsArkUIHookEnabled();
915 gridCacheEnabled_ = IsGridCacheEnabled();
916 gridIrregularLayoutEnable_ = IsGridIrregularLayoutEnabled();
917 sideBarContainerBlurEnable_ = IsSideBarContainerBlurEnable();
918 acePerformanceMonitorEnable_.store(IsAcePerformanceMonitorEnabled());
919 faultInjectEnabled_ = IsFaultInjectEnabled();
920 windowRectResizeEnabled_ = IsWindowRectResizeEnabled();
921 taskPriorityAdjustmentEnable_ = IsTaskPriorityAdjustmentEnable();
922 formSkeletonBlurEnabled_ = system::GetBoolParameter("const.form.skeleton_view.blur_style_enable", true);
923 formSharedImageCacheThreshold_ =
924 system::GetIntParameter("const.form.shared_image.cache_threshold", DEFAULT_FORM_SHARED_IMAGE_CACHE_THRESHOLD);
925 syncLoadEnabled_ = system::GetBoolParameter("persist.ace.scrollable.syncload.enable", false);
926 whiteBlockEnabled_ = system::GetParameter("persist.resourceschedule.whiteblock", "0") == "1";
927 previewStatus_ = system::GetIntParameter<int32_t>("const.arkui.previewStatus", 0);
928 if (isRound_) {
929 screenShape_ = ScreenShape::ROUND;
930 } else {
931 screenShape_ = ScreenShape::NOT_ROUND;
932 }
933 InitDeviceTypeBySystemProperty();
934 GetLayoutBreakpoints(widthLayoutBreakpoints_, heightLayoutBreakpoints_);
935 }
936
SetDeviceOrientation(int32_t orientation)937 ACE_WEAK_SYM void SystemProperties::SetDeviceOrientation(int32_t orientation)
938 {
939 auto newOrientation = static_cast<int32_t>(WindowUtils::GetDeviceOrientation(orientation));
940 if (newOrientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
941 Swap(deviceWidth_, deviceHeight_);
942 orientation_ = DeviceOrientation::PORTRAIT;
943 } else if (newOrientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
944 Swap(deviceWidth_, deviceHeight_);
945 orientation_ = DeviceOrientation::LANDSCAPE;
946 }
947 }
948
GetFontWeightScale()949 ACE_WEAK_SYM float SystemProperties::GetFontWeightScale()
950 {
951 // Default value of font weight scale is 1.0.
952 return fontWeightScale_;
953 }
954
GetFontScale()955 ACE_WEAK_SYM float SystemProperties::GetFontScale()
956 {
957 // Default value of font size scale is 1.0.
958 return fontScale_;
959 }
960
GetContainerDeleteFlag()961 bool SystemProperties::GetContainerDeleteFlag()
962 {
963 return containerDeleteFlag_;
964 }
965
InitMccMnc(int32_t mcc,int32_t mnc)966 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
967 {
968 mcc_ = mcc;
969 mnc_ = mnc;
970 }
971
GetDebugEnabled()972 ACE_WEAK_SYM bool SystemProperties::GetDebugEnabled()
973 {
974 return debugEnabled_;
975 }
976
GetLayoutDetectEnabled()977 ACE_WEAK_SYM bool SystemProperties::GetLayoutDetectEnabled()
978 {
979 return layoutDetectEnabled_;
980 }
981
GetMultiInstanceEnabled()982 ACE_WEAK_SYM bool SystemProperties::GetMultiInstanceEnabled()
983 {
984 return multiInstanceEnabled_;
985 }
986
SetMultiInstanceEnabled(bool enabled)987 ACE_WEAK_SYM void SystemProperties::SetMultiInstanceEnabled(bool enabled)
988 {
989 multiInstanceEnabled_ = enabled;
990 }
991
GetLanguage()992 std::string SystemProperties::GetLanguage()
993 {
994 return system::GetParameter("const.global.language", INVALID_PARAM);
995 }
996
GetRegion()997 std::string SystemProperties::GetRegion()
998 {
999 return system::GetParameter("const.global.region", INVALID_PARAM);
1000 }
1001
GetNewPipePkg()1002 std::string SystemProperties::GetNewPipePkg()
1003 {
1004 return system::GetParameter("persist.ace.newpipe.pkgname", "");
1005 }
1006
GetAnimationScale()1007 ACE_WEAK_SYM float SystemProperties::GetAnimationScale()
1008 {
1009 std::shared_lock<std::shared_mutex> lock(mutex_);
1010 return animationScale_;
1011 }
1012
GetPartialUpdatePkg()1013 std::string SystemProperties::GetPartialUpdatePkg()
1014 {
1015 return system::GetParameter("persist.ace.partial.pkgname", "");
1016 }
1017
GetSvgMode()1018 int32_t SystemProperties::GetSvgMode()
1019 {
1020 #ifdef NG_BUILD
1021 // disable ace svg before updated to new pipeline
1022 return system::GetIntParameter<int>("persist.ace.svg.mode", 0);
1023 #else
1024 return system::GetIntParameter<int>("persist.ace.svg.mode", 1);
1025 #endif
1026 }
1027
GetAllowWindowOpenMethodEnabled()1028 bool SystemProperties::GetAllowWindowOpenMethodEnabled()
1029 {
1030 return system::GetBoolParameter("persist.web.allowWindowOpenMethod.enabled", false);
1031 }
1032
GetDebugPixelMapSaveEnabled()1033 bool SystemProperties::GetDebugPixelMapSaveEnabled()
1034 {
1035 return system::GetBoolParameter("persist.ace.save.pixelmap.enabled", false);
1036 }
1037
IsPixelRoundEnabled()1038 bool SystemProperties::IsPixelRoundEnabled()
1039 {
1040 return system::GetBoolParameter("ace.debug.pixelround.enabled", true);
1041 }
1042
GetIsUseMemoryMonitor()1043 ACE_WEAK_SYM bool SystemProperties::GetIsUseMemoryMonitor()
1044 {
1045 static bool isUseMemoryMonitor = IsUseMemoryMonitor();
1046 return isUseMemoryMonitor;
1047 }
1048
IsFormAnimationLimited()1049 bool SystemProperties::IsFormAnimationLimited()
1050 {
1051 return system::GetBoolParameter("persist.sys.arkui.formAnimationLimit", true);
1052 }
1053
GetResourceDecoupling()1054 bool SystemProperties::GetResourceDecoupling()
1055 {
1056 return resourceDecoupling_;
1057 }
1058
ConfigChangePerform()1059 bool SystemProperties::ConfigChangePerform()
1060 {
1061 return configChangePerform_;
1062 }
1063
SetConfigChangePerform()1064 void SystemProperties::SetConfigChangePerform()
1065 {
1066 configChangePerform_ = true;
1067 }
1068
GetTitleStyleEnabled()1069 bool SystemProperties::GetTitleStyleEnabled()
1070 {
1071 return system::GetBoolParameter("persist.ace.title.style.enabled", false);
1072 }
1073
GetJankFrameThreshold()1074 int32_t SystemProperties::GetJankFrameThreshold()
1075 {
1076 return system::GetIntParameter<int>("persist.sys.arkui.perf.threshold", DEFAULT_THRESHOLD_JANK);
1077 }
1078
GetCustomTitleFilePath()1079 ACE_WEAK_SYM std::string SystemProperties::GetCustomTitleFilePath()
1080 {
1081 return system::GetParameter(CUSTOM_TITLE_KEY, "");
1082 }
1083
Is24HourClock()1084 ACE_WEAK_SYM bool SystemProperties::Is24HourClock()
1085 {
1086 return Global::I18n::LocaleConfig::Is24HourClock();
1087 }
1088
GetRtlEnabled()1089 std::optional<bool> SystemProperties::GetRtlEnabled()
1090 {
1091 const std::string emptyParam("none");
1092 auto ret = system::GetParameter("debug.ace.rtl.enabled", emptyParam);
1093 if (ret == emptyParam) {
1094 return std::nullopt;
1095 } else {
1096 return (ret == "true") ? true : false;
1097 }
1098 }
1099
GetDisplaySyncSkipEnabled()1100 bool SystemProperties::GetDisplaySyncSkipEnabled()
1101 {
1102 return system::GetBoolParameter("debug.ace.displaySyncSkip.enabled", true);
1103 }
1104
GetNavigationBlurEnabled()1105 bool SystemProperties::GetNavigationBlurEnabled()
1106 {
1107 return navigationBlurEnabled_;
1108 }
1109
GetForceSplitIgnoreOrientationEnabled()1110 bool SystemProperties::GetForceSplitIgnoreOrientationEnabled()
1111 {
1112 return forceSplitIgnoreOrientationEnabled_;
1113 }
1114
GetArkUIHookEnabled()1115 std::optional<bool> SystemProperties::GetArkUIHookEnabled()
1116 {
1117 return arkUIHookEnabled_;
1118 }
1119
GetCacheNavigationNodeEnable()1120 bool SystemProperties::GetCacheNavigationNodeEnable()
1121 {
1122 return cacheNavigationNodeEnable_;
1123 }
1124
GetGridCacheEnabled()1125 bool SystemProperties::GetGridCacheEnabled()
1126 {
1127 return gridCacheEnabled_;
1128 }
1129
GetGridIrregularLayoutEnabled()1130 bool SystemProperties::GetGridIrregularLayoutEnabled()
1131 {
1132 return gridIrregularLayoutEnable_;
1133 }
1134
WaterFlowUseSegmentedLayout()1135 bool SystemProperties::WaterFlowUseSegmentedLayout()
1136 {
1137 return system::GetBoolParameter("persist.ace.water.flow.segmented", false);
1138 }
1139
GetSideBarContainerBlurEnable()1140 bool SystemProperties::GetSideBarContainerBlurEnable()
1141 {
1142 return sideBarContainerBlurEnable_;
1143 }
1144
AddWatchSystemParameter(const char * key,void * context,EnableSystemParameterCallback callback)1145 void SystemProperties::AddWatchSystemParameter(const char* key, void* context, EnableSystemParameterCallback callback)
1146 {
1147 WatchParameter(key, callback, context);
1148 }
1149
GetWindowRectResizeEnabled()1150 ACE_WEAK_SYM bool SystemProperties::GetWindowRectResizeEnabled()
1151 {
1152 return windowRectResizeEnabled_;
1153 }
1154
RemoveWatchSystemParameter(const char * key,void * context,EnableSystemParameterCallback callback)1155 void SystemProperties::RemoveWatchSystemParameter(
1156 const char* key, void* context, EnableSystemParameterCallback callback)
1157 {
1158 RemoveParameterWatcher(key, callback, context);
1159 }
1160
EnableSystemParameterTraceLayoutCallback(const char * key,const char * value,void * context)1161 void SystemProperties::EnableSystemParameterTraceLayoutCallback(const char* key, const char* value, void* context)
1162 {
1163 if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
1164 SetLayoutTraceEnabled(strcmp(value, "true") == 0);
1165 }
1166 }
1167
EnableSystemParameterTraceInputEventCallback(const char * key,const char * value,void * context)1168 void SystemProperties::EnableSystemParameterTraceInputEventCallback(const char* key, const char* value, void* context)
1169 {
1170 if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
1171 SetInputEventTraceEnabled(strcmp(value, "true") == 0);
1172 }
1173 }
1174
EnableSystemParameterSecurityDevelopermodeCallback(const char * key,const char * value,void * context)1175 void SystemProperties::EnableSystemParameterSecurityDevelopermodeCallback(
1176 const char* key, const char* value, void* context)
1177 {
1178 if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
1179 SetSecurityDevelopermodeLayoutTraceEnabled(strcmp(value, "true") == 0);
1180 }
1181 }
1182
EnableSystemParameterDebugStatemgrCallback(const char * key,const char * value,void * context)1183 void SystemProperties::EnableSystemParameterDebugStatemgrCallback(const char* key, const char* value, void* context)
1184 {
1185 if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
1186 SetStateManagerEnabled(strcmp(value, "true") == 0);
1187 }
1188 }
1189
EnableSystemParameterDebugBoundaryCallback(const char * key,const char * value,void * context)1190 void SystemProperties::EnableSystemParameterDebugBoundaryCallback(const char* key, const char* value, void* context)
1191 {
1192 bool isDebugBoundary = strcmp(value, "true") == 0;
1193 SetDebugBoundaryEnabled(isDebugBoundary);
1194 auto container = reinterpret_cast<Platform::AceContainer*>(context);
1195 CHECK_NULL_VOID(container);
1196 container->RenderLayoutBoundary(isDebugBoundary);
1197 }
1198
EnableSystemParameterPerformanceMonitorCallback(const char * key,const char * value,void * context)1199 void SystemProperties::EnableSystemParameterPerformanceMonitorCallback(const char* key, const char* value,
1200 void* context)
1201 {
1202 if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) {
1203 SetPerformanceMonitorEnabled(strcmp(value, "true") == 0);
1204 }
1205 }
1206
OnFocusActiveChanged(const char * key,const char * value,void * context)1207 void SystemProperties::OnFocusActiveChanged(const char* key, const char* value, void* context)
1208 {
1209 bool focusCanBeActive = true;
1210 if (value && strcmp(value, "0") == 0) {
1211 focusCanBeActive = false;
1212 }
1213 if (focusCanBeActive != focusCanBeActive_) {
1214 SetFocusCanBeActive(focusCanBeActive);
1215 if (!focusCanBeActive) {
1216 auto container = reinterpret_cast<Platform::AceContainer*>(context);
1217 CHECK_NULL_VOID(container);
1218 ContainerScope scope(container->GetInstanceId());
1219 container->SetIsFocusActive(focusCanBeActive);
1220 }
1221 LOGI("focusCanBeActive turns to %{public}d", focusCanBeActive);
1222 }
1223 return;
1224 }
1225
GetDefaultResolution()1226 float SystemProperties::GetDefaultResolution()
1227 {
1228 // always return density of main screen, don't use this interface unless you need density when no window exists
1229 float density = 1.0f;
1230 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
1231 CHECK_NULL_RETURN(defaultDisplay, density);
1232 auto displayInfo = defaultDisplay->GetDisplayInfoWithCache();
1233 CHECK_NULL_RETURN(displayInfo, density);
1234 density = displayInfo->GetVirtualPixelRatio();
1235 return density;
1236 }
1237
SetLayoutTraceEnabled(bool layoutTraceEnable)1238 void SystemProperties::SetLayoutTraceEnabled(bool layoutTraceEnable)
1239 {
1240 layoutTraceEnable_.store(layoutTraceEnable && developerModeOn_);
1241 }
1242
SetInputEventTraceEnabled(bool inputEventTraceEnable)1243 void SystemProperties::SetInputEventTraceEnabled(bool inputEventTraceEnable)
1244 {
1245 traceInputEventEnable_.store(inputEventTraceEnable && developerModeOn_);
1246 }
1247
SetSecurityDevelopermodeLayoutTraceEnabled(bool layoutTraceEnable)1248 void SystemProperties::SetSecurityDevelopermodeLayoutTraceEnabled(bool layoutTraceEnable)
1249 {
1250 layoutTraceEnable_.store(layoutTraceEnable && IsLayoutTraceEnabled());
1251 }
1252
SetDebugBoundaryEnabled(bool debugBoundaryEnabled)1253 void SystemProperties::SetDebugBoundaryEnabled(bool debugBoundaryEnabled)
1254 {
1255 debugBoundaryEnabled_.store(debugBoundaryEnabled && developerModeOn_);
1256 }
1257
SetPerformanceMonitorEnabled(bool performanceMonitorEnable)1258 void SystemProperties::SetPerformanceMonitorEnabled(bool performanceMonitorEnable)
1259 {
1260 acePerformanceMonitorEnable_.store(performanceMonitorEnable);
1261 }
1262
SetFocusCanBeActive(bool focusCanBeActive)1263 void SystemProperties::SetFocusCanBeActive(bool focusCanBeActive)
1264 {
1265 focusCanBeActive_.store(focusCanBeActive);
1266 }
1267
GetAtomicServiceBundleName()1268 std::string SystemProperties::GetAtomicServiceBundleName()
1269 {
1270 return system::GetParameter(DISTRIBUTE_ENGINE_BUNDLE_NAME, "");
1271 }
1272
GetDragStartDampingRatio()1273 float SystemProperties::GetDragStartDampingRatio()
1274 {
1275 return dragStartDampingRatio_;
1276 }
1277
GetDragStartPanDistanceThreshold()1278 float SystemProperties::GetDragStartPanDistanceThreshold()
1279 {
1280 return dragStartPanDisThreshold_;
1281 }
1282
GetVelocityTrackerPointNumber()1283 int32_t SystemProperties::GetVelocityTrackerPointNumber()
1284 {
1285 return velocityTrackerPointNumber_;
1286 }
1287
IsVelocityWithinTimeWindow()1288 bool SystemProperties::IsVelocityWithinTimeWindow()
1289 {
1290 return isVelocityWithinTimeWindow_;
1291 }
1292
IsVelocityWithoutUpPoint()1293 bool SystemProperties::IsVelocityWithoutUpPoint()
1294 {
1295 return isVelocityWithoutUpPoint_;
1296 }
1297
IsSmallFoldProduct()1298 ACE_WEAK_SYM bool SystemProperties::IsSmallFoldProduct()
1299 {
1300 InitFoldScreenTypeBySystemProperty();
1301 return foldScreenType_ == FoldScreenType::SMALL_FOLDER;
1302 }
1303
IsBigFoldProduct()1304 ACE_WEAK_SYM bool SystemProperties::IsBigFoldProduct()
1305 {
1306 InitFoldScreenTypeBySystemProperty();
1307 return foldScreenType_ == FoldScreenType::BIG_FOLDER;
1308 }
1309
InitFoldScreenTypeBySystemProperty()1310 void SystemProperties::InitFoldScreenTypeBySystemProperty()
1311 {
1312 if (foldScreenType_ != FoldScreenType::UNKNOWN) {
1313 return;
1314 }
1315
1316 auto foldTypeProp = system::GetParameter(PROPERTY_FOLD_TYPE, "0,0,0,0");
1317 if (std::regex_match(foldTypeProp, FOLD_TYPE_REGEX)) {
1318 auto index = foldTypeProp.find_first_of(',');
1319 auto foldScreenTypeStr = foldTypeProp.substr(0, index);
1320 auto type = StringUtils::StringToInt(foldScreenTypeStr);
1321 if (type == FOLD_TYPE_FOUR) {
1322 type = FOLD_TYPE_TWO;
1323 }
1324 foldScreenType_ = static_cast<FoldScreenType>(type);
1325 }
1326 }
1327
GetWebDebugRenderMode()1328 std::string SystemProperties::GetWebDebugRenderMode()
1329 {
1330 return OHOS::system::GetParameter("web.debug.renderMode", "");
1331 }
1332
GetDebugInspectorId()1333 std::string SystemProperties::GetDebugInspectorId()
1334 {
1335 return system::GetParameter("ace.debug.inspectorId", INVALID_PARAM);
1336 }
1337
GetSrollableVelocityScale()1338 double SystemProperties::GetSrollableVelocityScale()
1339 {
1340 auto ret = system::GetParameter("persist.scrollable.velocityScale", "");
1341 return StringUtils::StringToDouble(ret);
1342 }
1343
GetSrollableFriction()1344 double SystemProperties::GetSrollableFriction()
1345 {
1346 auto ret = system::GetParameter("persist.scrollable.friction", "");
1347 return StringUtils::StringToDouble(ret);
1348 }
1349
GetScrollableDistance()1350 double SystemProperties::GetScrollableDistance()
1351 {
1352 return scrollableDistance_;
1353 }
1354
GetScrollCoefficients()1355 ACE_WEAK_SYM float SystemProperties::GetScrollCoefficients()
1356 {
1357 return scrollCoefficients_;
1358 }
1359
GetTransformEnabled()1360 ACE_WEAK_SYM bool SystemProperties::GetTransformEnabled()
1361 {
1362 return transformEnabled_;
1363 }
1364
GetWebDebugMaximizeResizeOptimize()1365 bool SystemProperties::GetWebDebugMaximizeResizeOptimize()
1366 {
1367 return system::GetBoolParameter("web.debug.maximize_resize_optimize", true);
1368 }
1369
IsNeedResampleTouchPoints()1370 bool SystemProperties::IsNeedResampleTouchPoints()
1371 {
1372 return true;
1373 }
1374
IsNeedSymbol()1375 bool SystemProperties::IsNeedSymbol()
1376 {
1377 return true;
1378 }
1379
GetDragDropFrameworkStatus()1380 int32_t SystemProperties::GetDragDropFrameworkStatus()
1381 {
1382 return dragDropFrameworkStatus_;
1383 }
1384
GetTouchAccelarate()1385 int32_t SystemProperties::GetTouchAccelarate()
1386 {
1387 return touchAccelarate_;
1388 }
1389
IsSuperFoldDisplayDevice()1390 bool SystemProperties::IsSuperFoldDisplayDevice()
1391 {
1392 InitFoldScreenTypeBySystemProperty();
1393 return foldScreenType_ == FoldScreenType::SUPER_FOLDER;
1394 }
1395
IsPageTransitionFreeze()1396 bool SystemProperties::IsPageTransitionFreeze()
1397 {
1398 return pageTransitionFrzEnabled_;
1399 }
1400
IsSoftPageTransition()1401 bool SystemProperties::IsSoftPageTransition()
1402 {
1403 return softPagetransition_;
1404 }
1405
IsFormSkeletonBlurEnabled()1406 bool SystemProperties::IsFormSkeletonBlurEnabled()
1407 {
1408 return formSkeletonBlurEnabled_;
1409 }
1410
getFormSharedImageCacheThreshold()1411 int32_t SystemProperties::getFormSharedImageCacheThreshold()
1412 {
1413 return formSharedImageCacheThreshold_;
1414 }
1415
IsWhiteBlockEnabled()1416 bool SystemProperties::IsWhiteBlockEnabled()
1417 {
1418 return whiteBlockEnabled_;
1419 }
1420
IsWhiteBlockIdleChange()1421 bool SystemProperties::IsWhiteBlockIdleChange()
1422 {
1423 return OHOS::system::GetParameter("persist.resourceschedule.whiteblock.idle", "0") == "1";
1424 }
1425
GetWhiteBlockIndexValue()1426 int32_t SystemProperties::GetWhiteBlockIndexValue()
1427 {
1428 auto ret = OHOS::system::GetParameter("persist.resourceschedule.whiteblock.index", "0");
1429 return StringUtils::StringToInt(ret);
1430 }
1431
GetWhiteBlockCacheCountValue()1432 int32_t SystemProperties::GetWhiteBlockCacheCountValue()
1433 {
1434 auto ret = OHOS::system::GetParameter("persist.resourceschedule.whiteblock.cachedcount", "0");
1435 return StringUtils::StringToInt(ret);
1436 }
1437
GetPreviewStatus()1438 int32_t SystemProperties::GetPreviewStatus()
1439 {
1440 return previewStatus_;
1441 }
1442 } // namespace OHOS::Ace
1443