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