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 <memory> 20 #include <optional> 21 #include <string> 22 23 #include "base/utils/device_config.h" 24 #include "base/utils/device_type.h" 25 #include "base/utils/macros.h" 26 27 namespace OHOS::Ace { 28 29 enum class ResolutionType : int32_t { 30 RESOLUTION_NONE = -2, 31 RESOLUTION_ANY = -1, 32 RESOLUTION_LDPI = 120, 33 RESOLUTION_MDPI = 160, 34 RESOLUTION_HDPI = 240, 35 RESOLUTION_XHDPI = 320, 36 RESOLUTION_XXHDPI = 480, 37 RESOLUTION_XXXHDPI = 640, 38 }; 39 40 constexpr int32_t MCC_UNDEFINED = 0; 41 constexpr int32_t MNC_UNDEFINED = 0; 42 43 enum class LongScreenType : int32_t { 44 LONG = 0, 45 NOT_LONG, 46 LONG_SCREEN_UNDEFINED, 47 }; 48 49 enum class ScreenShape : int32_t { 50 ROUND = 0, 51 NOT_ROUND, 52 SCREEN_SHAPE_UNDEFINED, 53 }; 54 55 class ACE_FORCE_EXPORT SystemProperties final { 56 public: 57 /* 58 * Init device type for Ace. 59 */ 60 static void InitDeviceType(DeviceType deviceType); 61 62 /* 63 * Init device info for Ace. 64 */ 65 static void InitDeviceInfo( 66 int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound); 67 68 /* 69 * Init device type according to system property. 70 */ 71 static void InitDeviceTypeBySystemProperty(); 72 73 /* 74 * Get type of current device. 75 */ 76 static DeviceType GetDeviceType(); 77 78 /* 79 * check SystemCapability. 80 */ 81 static bool IsSyscapExist(const char* cap); 82 83 /** 84 * Set type of current device. 85 * @param deviceType 86 */ SetDeviceType(DeviceType deviceType)87 static void SetDeviceType(DeviceType deviceType) 88 { 89 deviceType_ = deviceType; 90 } 91 92 /* 93 * Get current orientation of device. 94 */ GetDeviceOrientation()95 static DeviceOrientation GetDeviceOrientation() 96 { 97 return orientation_; 98 } 99 100 /* 101 * Get width of device. 102 */ GetDeviceWidth()103 static int32_t GetDeviceWidth() 104 { 105 return deviceWidth_; 106 } 107 108 /* 109 * Get height of device. 110 */ GetDeviceHeight()111 static int32_t GetDeviceHeight() 112 { 113 return deviceHeight_; 114 } 115 116 /* 117 * Set physical width of device. 118 */ SetDevicePhysicalWidth(int32_t devicePhysicalWidth)119 static void SetDevicePhysicalWidth(int32_t devicePhysicalWidth) 120 { 121 devicePhysicalWidth_ = devicePhysicalWidth; 122 } 123 124 /* 125 * Set physical height of device. 126 */ SetDevicePhysicalHeight(int32_t devicePhysicalHeight)127 static void SetDevicePhysicalHeight(int32_t devicePhysicalHeight) 128 { 129 devicePhysicalHeight_ = devicePhysicalHeight; 130 } 131 132 /* 133 * Get physical width of device. 134 */ GetDevicePhysicalWidth()135 static int32_t GetDevicePhysicalWidth() 136 { 137 return devicePhysicalWidth_; 138 } 139 140 /* 141 * Get physical height of device. 142 */ GetDevicePhysicalHeight()143 static int32_t GetDevicePhysicalHeight() 144 { 145 return devicePhysicalHeight_; 146 } 147 148 /* 149 * Get wght scale of device. 150 */ 151 static float GetFontWeightScale(); 152 153 /* 154 * Get density of default display. 155 */ GetResolution()156 static double GetResolution() 157 { 158 return resolution_; 159 } 160 161 /* 162 * Set resolution of device. 163 */ SetResolution(double resolution)164 static void SetResolution(double resolution) 165 { 166 resolution_ = resolution; 167 } 168 GetIsScreenRound()169 static bool GetIsScreenRound() 170 { 171 return isRound_; 172 } 173 GetBrand()174 static const std::string& GetBrand() 175 { 176 return brand_; 177 } 178 GetManufacturer()179 static const std::string& GetManufacturer() 180 { 181 return manufacturer_; 182 } 183 GetModel()184 static const std::string& GetModel() 185 { 186 return model_; 187 } 188 GetProduct()189 static const std::string& GetProduct() 190 { 191 return product_; 192 } 193 GetApiVersion()194 static const std::string& GetApiVersion() 195 { 196 return apiVersion_; 197 } 198 GetReleaseType()199 static const std::string& GetReleaseType() 200 { 201 return releaseType_; 202 } 203 GetParamDeviceType()204 static const std::string& GetParamDeviceType() 205 { 206 return paramDeviceType_; 207 } 208 209 static std::string GetLanguage(); 210 211 static std::string GetRegion(); 212 213 static std::string GetNewPipePkg(); 214 215 static float GetAnimationScale(); 216 217 static std::string GetPartialUpdatePkg(); 218 219 static int32_t GetSvgMode(); 220 221 static bool GetImageFrameworkEnabled(); 222 223 static bool GetDebugPixelMapSaveEnabled(); 224 GetRosenBackendEnabled()225 static bool GetRosenBackendEnabled() 226 { 227 return rosenBackendEnabled_; 228 } 229 GetHookModeEnabled()230 static bool GetHookModeEnabled() 231 { 232 return isHookModeEnabled_; 233 } 234 GetDebugBoundaryEnabled()235 static bool GetDebugBoundaryEnabled() 236 { 237 return debugBoundaryEnabled_; 238 } 239 GetDebugAutoUIEnabled()240 static bool GetDebugAutoUIEnabled() 241 { 242 return debugAutoUIEnabled_; 243 } 244 GetDownloadByNetworkEnabled()245 static bool GetDownloadByNetworkEnabled() 246 { 247 return downloadByNetworkEnabled_; 248 } 249 GetTraceEnabled()250 static bool GetTraceEnabled() 251 { 252 return traceEnabled_; 253 } 254 GetSvgTraceEnabled()255 static bool GetSvgTraceEnabled() 256 { 257 return svgTraceEnable_; 258 } 259 GetLayoutTraceEnabled()260 static bool GetLayoutTraceEnabled() 261 { 262 return layoutTraceEnable_; 263 } 264 GetBuildTraceEnabled()265 static bool GetBuildTraceEnabled() 266 { 267 return buildTraceEnable_; 268 } 269 GetAccessibilityEnabled()270 static bool GetAccessibilityEnabled() 271 { 272 return accessibilityEnabled_; 273 } 274 275 static bool GetDebugEnabled(); 276 GetGpuUploadEnabled()277 static bool GetGpuUploadEnabled() 278 { 279 return gpuUploadEnabled_; 280 } 281 282 /* 283 * Set device orientation. 284 */ 285 static void SetDeviceOrientation(int32_t orientation); 286 287 static constexpr char INVALID_PARAM[] = "N/A"; 288 GetMcc()289 static int32_t GetMcc() 290 { 291 return mcc_; 292 } 293 GetMnc()294 static int32_t GetMnc() 295 { 296 return mnc_; 297 } 298 SetColorMode(ColorMode colorMode)299 static void SetColorMode(ColorMode colorMode) 300 { 301 if (colorMode_ != colorMode) { 302 colorMode_ = colorMode; 303 } 304 } 305 GetColorMode()306 static ColorMode GetColorMode() 307 { 308 return colorMode_; 309 } 310 SetDeviceAccess(bool isDeviceAccess)311 static void SetDeviceAccess(bool isDeviceAccess) 312 { 313 isDeviceAccess_ = isDeviceAccess; 314 } 315 GetDeviceAccess()316 static bool GetDeviceAccess() 317 { 318 return isDeviceAccess_; 319 } 320 321 static void InitMccMnc(int32_t mcc, int32_t mnc); 322 GetScreenShape()323 static ScreenShape GetScreenShape() 324 { 325 return screenShape_; 326 } 327 328 static int GetArkProperties(); 329 330 static std::string GetArkBundleName(); 331 332 static size_t GetGcThreadNum(); 333 334 static size_t GetLongPauseTime(); 335 336 static void SetUnZipHap(bool unZipHap = true) 337 { 338 unZipHap_ = unZipHap; 339 } 340 GetUnZipHap()341 static bool GetUnZipHap() 342 { 343 return unZipHap_; 344 } 345 346 static bool GetAsmInterpreterEnabled(); 347 348 static std::string GetAsmOpcodeDisableRange(); 349 350 static bool IsScoringEnabled(const std::string& name); 351 IsWindowSizeAnimationEnabled()352 static bool IsWindowSizeAnimationEnabled() 353 { 354 return windowAnimationEnabled_; 355 } 356 IsAstcEnabled()357 static bool IsAstcEnabled() 358 { 359 return astcEnabled_; 360 } 361 GetAstcMaxError()362 static int32_t GetAstcMaxError() 363 { 364 return astcMax_; 365 } 366 GetAstcPsnr()367 static int32_t GetAstcPsnr() 368 { 369 return astcPsnr_; 370 } 371 SetExtSurfaceEnabled(bool extSurfaceEnabled)372 static void SetExtSurfaceEnabled(bool extSurfaceEnabled) 373 { 374 extSurfaceEnabled_ = extSurfaceEnabled; 375 } 376 GetExtSurfaceEnabled()377 static bool GetExtSurfaceEnabled() 378 { 379 return extSurfaceEnabled_; 380 } 381 382 static bool GetAllowWindowOpenMethodEnabled(); 383 GetDumpFrameCount()384 static uint32_t GetDumpFrameCount() 385 { 386 return dumpFrameCount_; 387 } 388 389 static bool GetIsUseMemoryMonitor(); 390 391 static bool IsFormAnimationLimited(); 392 393 static bool GetResourceDecoupling(); 394 395 static int32_t GetJankFrameThreshold(); 396 397 static bool GetTitleStyleEnabled(); 398 399 static std::string GetCustomTitleFilePath(); 400 401 static bool Is24HourClock(); 402 403 static std::optional<bool> GetRtlEnabled(); 404 GetEnableScrollableItemPool()405 static bool GetEnableScrollableItemPool() 406 { 407 return enableScrollableItemPool_; 408 } 409 410 static bool GetDisplaySyncSkipEnabled(); 411 412 static bool GetNavigationBlurEnabled(); 413 414 static bool GetGridCacheEnabled(); 415 416 static bool GetSideBarContainerBlurEnable(); 417 418 static void AddWatchSystemParameter(void *context); 419 420 static void EnableSystemParameterCallback(const char *key, const char *value, void *context); 421 422 static void RemoveWatchSystemParameter(void *context); 423 424 static float GetDefaultResolution(); 425 426 private: 427 static bool traceEnabled_; 428 static bool svgTraceEnable_; 429 static bool layoutTraceEnable_; 430 static bool buildTraceEnable_; 431 static bool accessibilityEnabled_; 432 static bool isRound_; 433 static bool isDeviceAccess_; 434 static int32_t deviceWidth_; 435 static int32_t deviceHeight_; 436 static int32_t devicePhysicalWidth_; 437 static int32_t devicePhysicalHeight_; 438 static double resolution_; // density of the default display 439 static DeviceType deviceType_; 440 static DeviceOrientation orientation_; 441 static std::string brand_; 442 static std::string manufacturer_; 443 static std::string model_; 444 static std::string product_; 445 static std::string apiVersion_; 446 static std::string releaseType_; 447 static std::string paramDeviceType_; 448 static int32_t mcc_; 449 static int32_t mnc_; 450 static ColorMode colorMode_; 451 static ScreenShape screenShape_; 452 static LongScreenType LongScreen_; 453 static bool unZipHap_; 454 static bool rosenBackendEnabled_; 455 static bool windowAnimationEnabled_; 456 static bool debugEnabled_; 457 static bool debugBoundaryEnabled_; 458 static bool debugAutoUIEnabled_; // for AutoUI Test 459 static bool downloadByNetworkEnabled_; 460 static bool gpuUploadEnabled_; 461 static bool isHookModeEnabled_; 462 static bool astcEnabled_; 463 static int32_t astcMax_; 464 static int32_t astcPsnr_; 465 static bool extSurfaceEnabled_; 466 static uint32_t dumpFrameCount_; 467 static bool resourceDecoupling_; 468 static bool enableScrollableItemPool_; 469 static bool navigationBlurEnabled_; 470 static bool gridCacheEnabled_; 471 static bool sideBarContainerBlurEnable_; 472 }; 473 474 } // namespace OHOS::Ace 475 476 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_SYSTEM_PROPERTIES_H 477