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