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