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 #ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_SYSTEM_PROPERTIES_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_SYSTEM_PROPERTIES_H 18 19 #include <atomic> 20 #include <cstdint> 21 #include <memory> 22 #include <optional> 23 #include <string> 24 25 #include "base/utils/device_config.h" 26 #include "base/utils/device_type.h" 27 #include "base/utils/macros.h" 28 29 namespace OHOS::Ace { 30 31 enum class ResolutionType : int32_t { 32 RESOLUTION_NONE = -2, 33 RESOLUTION_ANY = -1, 34 RESOLUTION_LDPI = 120, 35 RESOLUTION_MDPI = 160, 36 RESOLUTION_HDPI = 240, 37 RESOLUTION_XHDPI = 320, 38 RESOLUTION_XXHDPI = 480, 39 RESOLUTION_XXXHDPI = 640, 40 }; 41 42 enum class FoldScreenType: int32_t { 43 UNKNOWN = 0, 44 BIG_FOLDER = 1, 45 SMALL_FOLDER = 2, 46 OUTER_FOLDER = 3, 47 }; 48 49 constexpr int32_t MCC_UNDEFINED = 0; 50 constexpr int32_t MNC_UNDEFINED = 0; 51 extern const char ENABLE_DEBUG_BOUNDARY_KEY[]; 52 extern const char ENABLE_TRACE_LAYOUT_KEY[]; 53 extern const char ENABLE_TRACE_INPUTEVENT_KEY[]; 54 extern const char ENABLE_SECURITY_DEVELOPERMODE_KEY[]; 55 extern const char ENABLE_DEBUG_STATEMGR_KEY[]; 56 57 enum class LongScreenType : int32_t { 58 LONG = 0, 59 NOT_LONG, 60 LONG_SCREEN_UNDEFINED, 61 }; 62 63 enum class ScreenShape : int32_t { 64 ROUND = 0, 65 NOT_ROUND, 66 SCREEN_SHAPE_UNDEFINED, 67 }; 68 69 class ACE_FORCE_EXPORT SystemProperties final { 70 public: 71 /* 72 * Init device type for Ace. 73 */ 74 static void InitDeviceType(DeviceType deviceType); 75 76 /* 77 * Init device info for Ace. 78 */ 79 static void InitDeviceInfo( 80 int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound); 81 82 /* 83 * Init device type according to system property. 84 */ 85 static void InitDeviceTypeBySystemProperty(); 86 87 /** 88 * Init fold screen type according to system property. 89 */ 90 static void InitFoldScreenTypeBySystemProperty(); 91 92 /* 93 * Get type of current device. 94 */ 95 static DeviceType GetDeviceType(); 96 97 /* 98 * Get if current device need avoid window. 99 */ 100 static bool GetNeedAvoidWindow(); 101 102 /* 103 * check SystemCapability. 104 */ 105 static bool IsSyscapExist(const char* cap); 106 107 /** 108 * Set type of current device. 109 * @param deviceType 110 */ SetDeviceType(DeviceType deviceType)111 static void SetDeviceType(DeviceType deviceType) 112 { 113 deviceType_ = deviceType; 114 } 115 116 /* 117 * Get current orientation of device. 118 */ GetDeviceOrientation()119 static DeviceOrientation GetDeviceOrientation() 120 { 121 return orientation_; 122 } 123 124 /* 125 * Get width of device. 126 */ GetDeviceWidth()127 static int32_t GetDeviceWidth() 128 { 129 return deviceWidth_; 130 } 131 132 /* 133 * Get height of device. 134 */ GetDeviceHeight()135 static int32_t GetDeviceHeight() 136 { 137 return deviceHeight_; 138 } 139 140 /* 141 * Set physical width of device. 142 */ SetDevicePhysicalWidth(int32_t devicePhysicalWidth)143 static void SetDevicePhysicalWidth(int32_t devicePhysicalWidth) 144 { 145 devicePhysicalWidth_ = devicePhysicalWidth; 146 } 147 148 /* 149 * Set physical height of device. 150 */ SetDevicePhysicalHeight(int32_t devicePhysicalHeight)151 static void SetDevicePhysicalHeight(int32_t devicePhysicalHeight) 152 { 153 devicePhysicalHeight_ = devicePhysicalHeight; 154 } 155 156 /* 157 * Get physical width of device. 158 */ GetDevicePhysicalWidth()159 static int32_t GetDevicePhysicalWidth() 160 { 161 return devicePhysicalWidth_; 162 } 163 164 /* 165 * Get physical height of device. 166 */ GetDevicePhysicalHeight()167 static int32_t GetDevicePhysicalHeight() 168 { 169 return devicePhysicalHeight_; 170 } 171 172 /* 173 * Get wght scale of device. 174 */ 175 static float GetFontWeightScale(); 176 SetFontWeightScale(const float fontWeightScale)177 static void SetFontWeightScale(const float fontWeightScale) 178 { 179 if (fontWeightScale_ != fontWeightScale) { 180 fontWeightScale_ = fontWeightScale; 181 } 182 } 183 184 /* 185 * Get size scale of device. 186 */ 187 static float GetFontScale(); 188 SetFontScale(const float fontScale)189 static void SetFontScale(const float fontScale) 190 { 191 if (fontScale != fontScale_) { 192 fontScale_ = fontScale; 193 } 194 } 195 196 /* 197 * Get density of default display. 198 */ GetResolution()199 static double GetResolution() 200 { 201 return resolution_; 202 } 203 204 /* 205 * Set resolution of device. 206 */ SetResolution(double resolution)207 static void SetResolution(double resolution) 208 { 209 resolution_ = resolution; 210 } 211 GetIsScreenRound()212 static bool GetIsScreenRound() 213 { 214 return isRound_; 215 } 216 GetBrand()217 static const std::string& GetBrand() 218 { 219 return brand_; 220 } 221 GetManufacturer()222 static const std::string& GetManufacturer() 223 { 224 return manufacturer_; 225 } 226 GetModel()227 static const std::string& GetModel() 228 { 229 return model_; 230 } 231 GetProduct()232 static const std::string& GetProduct() 233 { 234 return product_; 235 } 236 GetApiVersion()237 static const std::string& GetApiVersion() 238 { 239 return apiVersion_; 240 } 241 GetReleaseType()242 static const std::string& GetReleaseType() 243 { 244 return releaseType_; 245 } 246 GetParamDeviceType()247 static const std::string& GetParamDeviceType() 248 { 249 return paramDeviceType_; 250 } 251 252 static std::string GetLanguage(); 253 254 static std::string GetRegion(); 255 256 static std::string GetNewPipePkg(); 257 258 static float GetAnimationScale(); 259 260 static std::string GetPartialUpdatePkg(); 261 262 static int32_t GetSvgMode(); 263 264 static bool GetDebugPixelMapSaveEnabled(); 265 266 static bool IsPixelRoundEnabled(); 267 GetRosenBackendEnabled()268 static bool GetRosenBackendEnabled() 269 { 270 return rosenBackendEnabled_; 271 } 272 GetHookModeEnabled()273 static bool GetHookModeEnabled() 274 { 275 return isHookModeEnabled_; 276 } 277 GetDeveloperModeOn()278 static bool GetDeveloperModeOn() 279 { 280 return developerModeOn_; 281 } 282 GetDebugBoundaryEnabled()283 static bool GetDebugBoundaryEnabled() 284 { 285 return debugBoundaryEnabled_.load(); 286 } 287 GetDebugOffsetLogEnabled()288 static bool GetDebugOffsetLogEnabled() 289 { 290 return debugOffsetLogEnabled_; 291 } 292 GetDebugAutoUIEnabled()293 static bool GetDebugAutoUIEnabled() 294 { 295 return debugAutoUIEnabled_; 296 } 297 GetDownloadByNetworkEnabled()298 static bool GetDownloadByNetworkEnabled() 299 { 300 return downloadByNetworkEnabled_; 301 } 302 GetSvgTraceEnabled()303 static bool GetSvgTraceEnabled() 304 { 305 return svgTraceEnable_; 306 } 307 GetLayoutTraceEnabled()308 static bool GetLayoutTraceEnabled() 309 { 310 return layoutTraceEnable_.load(); 311 } 312 GetSyncDebugTraceEnabled()313 static bool GetSyncDebugTraceEnabled() 314 { 315 return syncDebugTraceEnable_; 316 } 317 GetPixelRoundEnabled()318 static bool GetPixelRoundEnabled() 319 { 320 return pixelRoundEnable_; 321 } 322 GetTextTraceEnabled()323 static bool GetTextTraceEnabled() 324 { 325 return textTraceEnable_; 326 } 327 GetSyntaxTraceEnabled()328 static bool GetSyntaxTraceEnabled() 329 { 330 return syntaxTraceEnable_; 331 } 332 GetAccessTraceEnabled()333 static bool GetAccessTraceEnabled() 334 { 335 return accessTraceEnable_; 336 } 337 GetTraceInputEventEnabled()338 static bool GetTraceInputEventEnabled() 339 { 340 return traceInputEventEnable_.load(); 341 } 342 GetStateManagerEnabled()343 static bool GetStateManagerEnabled() 344 { 345 return stateManagerEnable_.load(); 346 } 347 SetStateManagerEnabled(bool stateManagerEnable)348 static void SetStateManagerEnabled(bool stateManagerEnable) 349 { 350 stateManagerEnable_.store(stateManagerEnable); 351 } 352 SetFaultInjectEnabled(bool faultInjectEnable)353 static void SetFaultInjectEnabled(bool faultInjectEnable) 354 { 355 faultInjectEnabled_ = faultInjectEnable; 356 } 357 GetFaultInjectEnabled()358 static bool GetFaultInjectEnabled() 359 { 360 return faultInjectEnabled_; 361 } 362 GetBuildTraceEnabled()363 static bool GetBuildTraceEnabled() 364 { 365 return buildTraceEnable_; 366 } 367 GetAccessibilityEnabled()368 static bool GetAccessibilityEnabled() 369 { 370 return accessibilityEnabled_; 371 } 372 GetCanvasDebugMode()373 static uint32_t GetCanvasDebugMode() 374 { 375 return canvasDebugMode_; 376 } 377 378 static bool GetDebugEnabled(); 379 380 static bool GetLayoutDetectEnabled(); 381 GetGpuUploadEnabled()382 static bool GetGpuUploadEnabled() 383 { 384 return gpuUploadEnabled_; 385 } 386 GetImageFrameworkEnabled()387 static bool GetImageFrameworkEnabled() 388 { 389 return imageFrameworkEnable_; 390 } 391 392 /* 393 * Set device orientation. 394 */ 395 static void SetDeviceOrientation(int32_t orientation); 396 397 static constexpr char INVALID_PARAM[] = "N/A"; 398 GetMcc()399 static int32_t GetMcc() 400 { 401 return mcc_; 402 } 403 GetMnc()404 static int32_t GetMnc() 405 { 406 return mnc_; 407 } 408 SetColorMode(ColorMode colorMode)409 static void SetColorMode(ColorMode colorMode) 410 { 411 if (colorMode_ != colorMode) { 412 colorMode_ = colorMode; 413 } 414 } 415 GetColorMode()416 static ColorMode GetColorMode() 417 { 418 return colorMode_; 419 } 420 SetDeviceAccess(bool isDeviceAccess)421 static void SetDeviceAccess(bool isDeviceAccess) 422 { 423 isDeviceAccess_ = isDeviceAccess; 424 } 425 GetDeviceAccess()426 static bool GetDeviceAccess() 427 { 428 return isDeviceAccess_; 429 } 430 431 static void InitMccMnc(int32_t mcc, int32_t mnc); 432 GetScreenShape()433 static ScreenShape GetScreenShape() 434 { 435 return screenShape_; 436 } 437 438 static int GetArkProperties(); 439 440 static std::string GetMemConfigProperty(); 441 442 static std::string GetArkBundleName(); 443 444 static size_t GetGcThreadNum(); 445 446 static size_t GetLongPauseTime(); 447 SetUnZipHap(bool unZipHap = true)448 static void SetUnZipHap(bool unZipHap = true) 449 { 450 unZipHap_ = unZipHap; 451 } 452 GetUnZipHap()453 static bool GetUnZipHap() 454 { 455 return unZipHap_; 456 } 457 458 static bool GetAsmInterpreterEnabled(); 459 460 static std::string GetAsmOpcodeDisableRange(); 461 462 static bool IsScoringEnabled(const std::string& name); 463 IsWindowSizeAnimationEnabled()464 static bool IsWindowSizeAnimationEnabled() 465 { 466 return windowAnimationEnabled_; 467 } 468 IsAstcEnabled()469 static bool IsAstcEnabled() 470 { 471 return astcEnabled_; 472 } 473 474 static bool GetWindowRectResizeEnabled(); 475 GetAstcMaxError()476 static int32_t GetAstcMaxError() 477 { 478 return astcMax_; 479 } 480 GetAstcPsnr()481 static int32_t GetAstcPsnr() 482 { 483 return astcPsnr_; 484 } 485 IsImageFileCacheConvertAstcEnabled()486 static bool IsImageFileCacheConvertAstcEnabled() 487 { 488 return imageFileCacheConvertAstc_; 489 } 490 GetImageFileCacheConvertAstcThreshold()491 static int32_t GetImageFileCacheConvertAstcThreshold() 492 { 493 return imageFileCacheConvertAstcThreshold_; 494 } 495 SetExtSurfaceEnabled(bool extSurfaceEnabled)496 static void SetExtSurfaceEnabled(bool extSurfaceEnabled) 497 { 498 extSurfaceEnabled_ = extSurfaceEnabled; 499 } 500 GetExtSurfaceEnabled()501 static bool GetExtSurfaceEnabled() 502 { 503 return extSurfaceEnabled_; 504 } 505 506 static bool GetAllowWindowOpenMethodEnabled(); 507 GetDumpFrameCount()508 static uint32_t GetDumpFrameCount() 509 { 510 return dumpFrameCount_; 511 } 512 513 static bool GetIsUseMemoryMonitor(); 514 515 static bool IsFormAnimationLimited(); 516 517 static bool GetResourceDecoupling(); 518 519 static int32_t GetJankFrameThreshold(); 520 521 static bool GetTitleStyleEnabled(); 522 523 static std::string GetCustomTitleFilePath(); 524 525 static bool Is24HourClock(); 526 527 static std::optional<bool> GetRtlEnabled(); 528 GetEnableScrollableItemPool()529 static bool GetEnableScrollableItemPool() 530 { 531 return enableScrollableItemPool_; 532 } 533 534 static bool GetDisplaySyncSkipEnabled(); 535 536 static bool GetNavigationBlurEnabled(); 537 538 static bool GetGridCacheEnabled(); 539 540 static bool GetGridIrregularLayoutEnabled(); 541 542 static bool WaterFlowUseSegmentedLayout(); 543 544 static bool GetSideBarContainerBlurEnable(); 545 546 using EnableSystemParameterCallback = void (*)(const char* key, const char* value, void* context); 547 548 static void AddWatchSystemParameter(const char* key, void* context, EnableSystemParameterCallback callback); 549 550 static void RemoveWatchSystemParameter(const char* key, void* context, EnableSystemParameterCallback callback); 551 static void EnableSystemParameterTraceLayoutCallback(const char* key, const char* value, void* context); 552 static void EnableSystemParameterTraceInputEventCallback(const char* key, const char* value, void* context); 553 static void EnableSystemParameterSecurityDevelopermodeCallback(const char* key, const char* value, void* context); 554 static void EnableSystemParameterDebugStatemgrCallback(const char* key, const char* value, void* context); 555 static void EnableSystemParameterDebugBoundaryCallback(const char* key, const char* value, void* context); 556 static void EnableSystemParameterPerformanceMonitorCallback(const char* key, const char* value, void* context); 557 static float GetDefaultResolution(); 558 559 static void SetLayoutTraceEnabled(bool layoutTraceEnable); 560 561 static void SetInputEventTraceEnabled(bool inputEventTraceEnable); 562 563 static void SetSecurityDevelopermodeLayoutTraceEnabled(bool layoutTraceEnable); 564 565 static void SetDebugBoundaryEnabled(bool debugBoundaryEnabled); 566 567 static void SetPerformanceMonitorEnabled(bool performanceMonitorEnable); 568 GetAcePerformanceMonitorEnabled()569 static bool GetAcePerformanceMonitorEnabled() 570 { 571 return acePerformanceMonitorEnable_.load(); 572 } 573 GetAceCommercialLogEnabled()574 static bool GetAceCommercialLogEnabled() 575 { 576 return aceCommercialLogEnable_; 577 } 578 579 static std::string GetAtomicServiceBundleName(); 580 GetDarkModeBrightnessPercent()581 static std::pair<float, float> GetDarkModeBrightnessPercent() 582 { 583 return brightUpPercent_; 584 } 585 586 static bool IsOpIncEnable(); 587 588 static float GetDragStartDampingRatio(); 589 590 static float GetDragStartPanDistanceThreshold(); 591 592 static bool IsSmallFoldProduct(); 593 594 static std::string GetWebDebugRenderMode(); 595 596 static std::string GetDebugInspectorId(); 597 598 static double GetSrollableVelocityScale(); 599 600 static double GetSrollableFriction(); 601 602 private: 603 static bool opincEnabled_; 604 static bool developerModeOn_; 605 static bool svgTraceEnable_; 606 static std::atomic<bool> layoutTraceEnable_; 607 static std::atomic<bool> traceInputEventEnable_; 608 static bool buildTraceEnable_; 609 static bool syncDebugTraceEnable_; 610 static bool pixelRoundEnable_; 611 static bool textTraceEnable_; 612 static bool syntaxTraceEnable_; 613 static bool accessTraceEnable_; 614 static bool accessibilityEnabled_; 615 static uint32_t canvasDebugMode_; 616 static bool isRound_; 617 static bool isDeviceAccess_; 618 static int32_t deviceWidth_; 619 static int32_t deviceHeight_; 620 static int32_t devicePhysicalWidth_; 621 static int32_t devicePhysicalHeight_; 622 static double resolution_; // density of the default display 623 static DeviceType deviceType_; 624 static bool needAvoidWindow_; 625 static DeviceOrientation orientation_; 626 static std::string brand_; 627 static std::string manufacturer_; 628 static std::string model_; 629 static std::string product_; 630 static std::string apiVersion_; 631 static std::string releaseType_; 632 static std::string paramDeviceType_; 633 static int32_t mcc_; 634 static int32_t mnc_; 635 static ColorMode colorMode_; 636 static ScreenShape screenShape_; 637 static LongScreenType LongScreen_; 638 static bool unZipHap_; 639 static bool rosenBackendEnabled_; 640 static bool windowAnimationEnabled_; 641 static bool debugEnabled_; 642 static bool layoutDetectEnabled_; 643 static std::atomic<bool> debugBoundaryEnabled_; 644 static bool debugAutoUIEnabled_; // for AutoUI Test 645 static bool debugOffsetLogEnabled_; 646 static bool downloadByNetworkEnabled_; 647 static bool gpuUploadEnabled_; 648 static bool isHookModeEnabled_; 649 static bool astcEnabled_; 650 static int32_t astcMax_; 651 static int32_t astcPsnr_; 652 static bool imageFileCacheConvertAstc_; 653 static int32_t imageFileCacheConvertAstcThreshold_; 654 static bool extSurfaceEnabled_; 655 static uint32_t dumpFrameCount_; 656 static bool resourceDecoupling_; 657 static bool enableScrollableItemPool_; 658 static bool navigationBlurEnabled_; 659 static bool gridCacheEnabled_; 660 static bool sideBarContainerBlurEnable_; 661 static std::atomic<bool> stateManagerEnable_; 662 static std::atomic<bool> acePerformanceMonitorEnable_; 663 static bool aceCommercialLogEnable_; 664 static bool faultInjectEnabled_; 665 static bool imageFrameworkEnable_; 666 static std::pair<float, float> brightUpPercent_; 667 static float dragStartDampingRatio_; 668 static float dragStartPanDisThreshold_; 669 static float fontScale_; 670 static float fontWeightScale_; 671 static bool windowRectResizeEnabled_; 672 static FoldScreenType foldScreenType_; 673 }; 674 675 } // namespace OHOS::Ace 676 677 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_SYSTEM_PROPERTIES_H 678