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