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