• 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_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      */
GetDevcieOrientation()93     static DeviceOrientation GetDevcieOrientation()
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 
GetRosenBackendEnabled()179     static bool GetRosenBackendEnabled()
180     {
181         return rosenBackendEnabled_;
182     }
183 
GetTraceEnabled()184     static bool GetTraceEnabled()
185     {
186         return traceEnabled_;
187     }
188 
GetAccessibilityEnabled()189     static bool GetAccessibilityEnabled()
190     {
191         return accessibilityEnabled_;
192     }
193 
194     static bool GetDebugEnabled();
195 
196     /*
197      * Set device orientation.
198      */
199     static void SetDeviceOrientation(int32_t orientation);
200 
201     static constexpr char INVALID_PARAM[] = "N/A";
202 
GetMcc()203     static int32_t GetMcc()
204     {
205         return mcc_;
206     }
207 
GetMnc()208     static int32_t GetMnc()
209     {
210         return mnc_;
211     }
212 
SetColorMode(ColorMode colorMode)213     static void SetColorMode(ColorMode colorMode)
214     {
215         if (colorMode_ != colorMode) {
216             colorMode_ = colorMode;
217         }
218     }
219 
GetColorMode()220     static ColorMode GetColorMode()
221     {
222         return colorMode_;
223     }
224 
225     static void InitMccMnc(int32_t mcc, int32_t mnc);
226 
GetScreenShape()227     static ScreenShape GetScreenShape()
228     {
229         return screenShape_;
230     }
231 
232     /*
233      * Change px to vp
234      */
Px2Vp(double pxNum)235     static double Px2Vp(double pxNum)
236     {
237         return pxNum / resolution_;
238     }
239 
Vp2Px(double pxNum)240     static double Vp2Px(double pxNum)
241     {
242         return pxNum * resolution_;
243     }
244 
245     static int GetArkProperties();
246 
247     static bool IsScoringEnabled(const std::string& name);
248 
SetWindowPos(int32_t x,int32_t y)249     static void SetWindowPos(int32_t x, int32_t y)
250     {
251         windowPosX_ = x;
252         windowPosY_ = y;
253     }
254 
GetWindowPosX()255     static int32_t GetWindowPosX()
256     {
257         return windowPosX_;
258     }
259 
GetWindowPosY()260     static int32_t GetWindowPosY()
261     {
262         return windowPosY_;
263     }
264 
IsWindowSizeAnimationEnabled()265     static bool IsWindowSizeAnimationEnabled()
266     {
267         return windowAnimationEnabled_;
268     }
269 
270 private:
271     static bool traceEnabled_;
272     static bool accessibilityEnabled_;
273     static bool isRound_;
274     static int32_t deviceWidth_;
275     static int32_t deviceHeight_;
276     static double resolution_;
277     static DeviceType deviceType_;
278     static DeviceOrientation orientation_;
279     static std::string brand_;
280     static std::string manufacturer_;
281     static std::string model_;
282     static std::string product_;
283     static std::string apiVersion_;
284     static std::string releaseType_;
285     static std::string paramDeviceType_;
286     static int32_t mcc_;
287     static int32_t mnc_;
288     static ColorMode colorMode_;
289     static ScreenShape screenShape_;
290     static LongScreenType LongScreen_;
291     static bool rosenBackendEnabled_;
292     static bool windowAnimationEnabled_;
293     static bool debugEnabled_;
294     static int32_t windowPosX_;
295     static int32_t windowPosY_;
296 };
297 
298 } // namespace OHOS::Ace
299 
300 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_SYSTEM_PROPERTIES_H
301