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 #include "base/utils/system_properties.h"
17 
18 #include "base/log/log.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 constexpr int32_t ORIENTATION_PORTRAIT = 0;
23 constexpr int32_t ORIENTATION_LANDSCAPE = 1;
24 constexpr char PROPERTY_DEVICE_TYPE_PHONE[] = "phone";
25 constexpr char PROPERTY_DEVICE_TYPE_TV[] = "tv";
26 constexpr char PROPERTY_DEVICE_TYPE_TABLET[] = "tablet";
27 constexpr char PROPERTY_DEVICE_TYPE_TWO_IN_ONE[] = "2in1";
28 constexpr char PROPERTY_DEVICE_TYPE_WEARABLE[] = "wearable";
29 constexpr char PROPERTY_DEVICE_TYPE_CAR[] = "car";
30 
31 static constexpr char UNDEFINED_PARAM[] = "undefined parameter";
32 
Swap(int32_t & deviceWidth,int32_t & deviceHeight)33 void Swap(int32_t& deviceWidth, int32_t& deviceHeight)
34 {
35     int32_t temp = deviceWidth;
36     deviceWidth = deviceHeight;
37     deviceHeight = temp;
38 }
39 } // namespace
40 
41 bool SystemProperties::svgTraceEnable_ = false;
42 bool SystemProperties::developerModeOn_ = false;
43 bool SystemProperties::layoutTraceEnable_ = false;
44 bool SystemProperties::traceInputEventEnable_ = false;
45 bool SystemProperties::stateManagerEnable_ = false;
46 bool SystemProperties::buildTraceEnable_ = false;
47 bool SystemProperties::syncDebugTraceEnable_ = false;
48 bool SystemProperties::pixelRoundEnable_ = true;
49 bool SystemProperties::textTraceEnable_ = false;
50 bool SystemProperties::syntaxTraceEnable_ = false;
51 bool SystemProperties::accessTraceEnable_ = false;
52 bool SystemProperties::accessibilityEnabled_ = false;
53 bool SystemProperties::isRound_ = false;
54 bool SystemProperties::isDeviceAccess_ = false;
55 int32_t SystemProperties::deviceWidth_ = 0;
56 int32_t SystemProperties::deviceHeight_ = 0;
57 int32_t SystemProperties::devicePhysicalWidth_ = 0;
58 int32_t SystemProperties::devicePhysicalHeight_ = 0;
59 double SystemProperties::resolution_ = 1.0;
60 DeviceType SystemProperties::deviceType_ { DeviceType::PHONE };
61 DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
62 std::string SystemProperties::brand_ = UNDEFINED_PARAM;
63 std::string SystemProperties::manufacturer_ = UNDEFINED_PARAM;
64 std::string SystemProperties::model_ = UNDEFINED_PARAM;
65 std::string SystemProperties::product_ = UNDEFINED_PARAM;
66 std::string SystemProperties::apiVersion_ = "9";
67 std::string SystemProperties::releaseType_ = UNDEFINED_PARAM;
68 std::string SystemProperties::paramDeviceType_ = UNDEFINED_PARAM;
69 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
70 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
71 ColorMode SystemProperties::colorMode_ = ColorMode::LIGHT;
72 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
73 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
74 bool SystemProperties::unZipHap_ = true;
75 bool SystemProperties::windowAnimationEnabled_ = false;
76 bool SystemProperties::debugBoundaryEnabled_ = false;
77 bool SystemProperties::debugAutoUIEnabled_ = false;
78 bool SystemProperties::debugOffsetLogEnabled_ = false;
79 bool SystemProperties::downloadByNetworkEnabled_ = false;
80 bool SystemProperties::gpuUploadEnabled_ = false;
81 bool SystemProperties::isHookModeEnabled_ = false;
82 bool SystemProperties::astcEnabled_ = false;
83 int SystemProperties::astcMax_ = 0;
84 int SystemProperties::astcPsnr_ = 0;
85 bool SystemProperties::imageFileCacheConvertAstc_ = false;
86 int32_t SystemProperties::imageFileCacheConvertAstcThreshold_ = 2;
87 bool SystemProperties::extSurfaceEnabled_ = false;
88 uint32_t SystemProperties::dumpFrameCount_ = 0;
89 bool SystemProperties::resourceDecoupling_ = true;
90 #ifndef ENABLE_ROSEN_BACKEND
91 bool SystemProperties::rosenBackendEnabled_ = false;
92 #else
93 bool SystemProperties::rosenBackendEnabled_ = true;
94 #endif
95 bool SystemProperties::enableScrollableItemPool_ = false;
96 bool SystemProperties::navigationBlurEnabled_ = true;
97 bool SystemProperties::sideBarContainerBlurEnable_ = false;
98 bool SystemProperties::gridCacheEnabled_ = false;
99 bool SystemProperties::acePerformanceMonitorEnable_ = false;
100 bool SystemProperties::aceCommercialLogEnable_ = false;
101 std::pair<float, float> SystemProperties::brightUpPercent_ = {};
102 bool SystemProperties::faultInjectEnabled_ = false;
103 bool SystemProperties::imageFrameworkEnable_ = false;
104 float SystemProperties::pageCount_ = 1.0f;
105 float SystemProperties::dragStartDampingRatio_ = 0.2f;
106 float SystemProperties::dragStartPanDisThreshold_ = 10.0f;
107 uint32_t SystemProperties::canvasDebugMode_ = 0;
108 
IsOpIncEnable()109 bool SystemProperties::IsOpIncEnable()
110 {
111     return false;
112 }
113 
InitDeviceType(DeviceType type)114 void SystemProperties::InitDeviceType(DeviceType type)
115 {
116     // Properties: "phone", "tv", "tablet", "watch", "car"
117     if (type == DeviceType::TV) {
118         deviceType_ = DeviceType::TV;
119         paramDeviceType_ = PROPERTY_DEVICE_TYPE_TV;
120     } else if (type == DeviceType::WATCH) {
121         deviceType_ = DeviceType::WATCH;
122         paramDeviceType_ = PROPERTY_DEVICE_TYPE_WEARABLE;
123     } else if (type == DeviceType::CAR) {
124         deviceType_ = DeviceType::CAR;
125         paramDeviceType_ = PROPERTY_DEVICE_TYPE_CAR;
126     } else if (type == DeviceType::TABLET) {
127         deviceType_ = DeviceType::TABLET;
128         paramDeviceType_ = PROPERTY_DEVICE_TYPE_TABLET;
129     } else if (type == DeviceType::TWO_IN_ONE) {
130         deviceType_ = DeviceType::TWO_IN_ONE;
131         paramDeviceType_ = PROPERTY_DEVICE_TYPE_TWO_IN_ONE;
132     } else {
133         deviceType_ = DeviceType::PHONE;
134         paramDeviceType_ = PROPERTY_DEVICE_TYPE_PHONE;
135     }
136 }
137 
GetDeviceType()138 DeviceType SystemProperties::GetDeviceType()
139 {
140     return deviceType_;
141 }
142 
IsSyscapExist(const char * cap)143 bool SystemProperties::IsSyscapExist(const char* cap)
144 {
145     return false;
146 }
147 
InitDeviceTypeBySystemProperty()148 void SystemProperties::InitDeviceTypeBySystemProperty()
149 {
150     deviceType_ = DeviceType::PHONE;
151 }
152 
InitDeviceInfo(int32_t deviceWidth,int32_t deviceHeight,int32_t orientation,double resolution,bool isRound)153 void SystemProperties::InitDeviceInfo(
154     int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
155 {
156     // SetDeviceOrientation should be eralier than deviceWidth/deviceHeight init.
157     if (orientation == ORIENTATION_PORTRAIT) {
158         orientation_ = DeviceOrientation::PORTRAIT;
159     } else if (orientation == ORIENTATION_LANDSCAPE) {
160         orientation_ = DeviceOrientation::LANDSCAPE;
161     } else {
162         LOGW("SetDeviceOrientation, undefined orientation");
163     }
164 
165     isRound_ = isRound;
166     resolution_ = resolution;
167     deviceWidth_ = deviceWidth;
168     deviceHeight_ = deviceHeight;
169     if (isRound_) {
170         screenShape_ = ScreenShape::ROUND;
171     } else {
172         screenShape_ = ScreenShape::NOT_ROUND;
173     }
174 }
175 
SetDeviceOrientation(int32_t orientation)176 void SystemProperties::SetDeviceOrientation(int32_t orientation)
177 {
178     if (orientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
179         Swap(deviceWidth_, deviceHeight_);
180         orientation_ = DeviceOrientation::PORTRAIT;
181     } else if (orientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
182         Swap(deviceWidth_, deviceHeight_);
183         orientation_ = DeviceOrientation::LANDSCAPE;
184     } else {
185         LOGI("SetDeviceOrientation, no change info: %{public}d", orientation);
186     }
187 }
188 
GetFontWeightScale()189 float SystemProperties::GetFontWeightScale()
190 {
191     return 1.0f;
192 }
193 
InitMccMnc(int32_t mcc,int32_t mnc)194 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
195 {
196     mcc_ = mcc;
197     mnc_ = mnc;
198 }
199 
IsScoringEnabled(const std::string & name)200 bool SystemProperties::IsScoringEnabled(const std::string& name)
201 {
202     return false;
203 }
204 
GetDebugEnabled()205 bool SystemProperties::GetDebugEnabled()
206 {
207     return false;
208 }
209 
GetLayoutDetectEnabled()210 bool SystemProperties::GetLayoutDetectEnabled()
211 {
212     return false;
213 }
214 
GetLanguage()215 std::string SystemProperties::GetLanguage()
216 {
217     return UNDEFINED_PARAM;
218 }
219 
GetRegion()220 std::string SystemProperties::GetRegion()
221 {
222     return UNDEFINED_PARAM;
223 }
224 
GetPartialUpdatePkg()225 std::string SystemProperties::GetPartialUpdatePkg()
226 {
227     return {};
228 }
229 
GetNewPipePkg()230 std::string SystemProperties::GetNewPipePkg()
231 {
232     return {};
233 }
234 
GetSvgMode()235 int32_t SystemProperties::GetSvgMode()
236 {
237     return 1;
238 }
239 
GetIsUseMemoryMonitor()240 bool SystemProperties::GetIsUseMemoryMonitor()
241 {
242     return false;
243 }
244 
IsFormAnimationLimited()245 bool SystemProperties::IsFormAnimationLimited()
246 {
247     return true;
248 }
249 
GetDebugPixelMapSaveEnabled()250 bool SystemProperties::GetDebugPixelMapSaveEnabled()
251 {
252     return false;
253 }
254 
GetResourceDecoupling()255 bool SystemProperties::GetResourceDecoupling()
256 {
257     return true;
258 }
259 
GetTitleStyleEnabled()260 bool SystemProperties::GetTitleStyleEnabled()
261 {
262     return false;
263 }
264 
GetJankFrameThreshold()265 int32_t SystemProperties::GetJankFrameThreshold()
266 {
267     return 0;
268 }
269 
Is24HourClock()270 bool SystemProperties::Is24HourClock()
271 {
272     return false;
273 }
274 
GetCustomTitleFilePath()275 std::string SystemProperties::GetCustomTitleFilePath()
276 {
277     return UNDEFINED_PARAM;
278 }
279 
GetDisplaySyncSkipEnabled()280 bool SystemProperties::GetDisplaySyncSkipEnabled()
281 {
282     return true;
283 }
284 
GetNavigationBlurEnabled()285 bool SystemProperties::GetNavigationBlurEnabled()
286 {
287     return navigationBlurEnabled_;
288 }
289 
GetSideBarContainerBlurEnable()290 bool SystemProperties::GetSideBarContainerBlurEnable()
291 {
292     return sideBarContainerBlurEnable_;
293 }
294 
WaterFlowUseSegmentedLayout()295 bool SystemProperties::WaterFlowUseSegmentedLayout()
296 {
297     return false;
298 }
299 
GetGridIrregularLayoutEnabled()300 bool SystemProperties::GetGridIrregularLayoutEnabled()
301 {
302     return false;
303 }
304 
GetGridCacheEnabled()305 bool SystemProperties::GetGridCacheEnabled()
306 {
307     return gridCacheEnabled_;
308 }
309 
GetDefaultResolution()310 float SystemProperties::GetDefaultResolution()
311 {
312     return 1.0f;
313 }
314 
GetAtomicServiceBundleName()315 std::string SystemProperties::GetAtomicServiceBundleName()
316 {
317     return UNDEFINED_PARAM;
318 }
319 
GetDragStartDampingRatio()320 float SystemProperties::GetDragStartDampingRatio()
321 {
322     return dragStartDampingRatio_;
323 }
324 
GetDragStartPanDistanceThreshold()325 float SystemProperties::GetDragStartPanDistanceThreshold()
326 {
327     return dragStartPanDisThreshold_;
328 }
329 
IsSmallFoldProduct()330 bool SystemProperties::IsSmallFoldProduct()
331 {
332     return false;
333 }
334 
IsNeedResampleTouchPoints()335 bool SystemProperties::IsNeedResampleTouchPoints()
336 {
337     return true;
338 }
339 } // namespace OHOS::Ace
340