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 std::atomic<bool> SystemProperties::layoutTraceEnable_(false);
44 std::atomic<bool> SystemProperties::traceInputEventEnable_(false);
45 std::atomic<bool> SystemProperties::stateManagerEnable_(false);
46 bool SystemProperties::buildTraceEnable_ = false;
47 bool SystemProperties::syncDebugTraceEnable_ = false;
48 bool SystemProperties::measureDebugTraceEnable_ = false;
49 bool SystemProperties::safeAreaDebugTraceEnable_ = false;
50 bool SystemProperties::pixelRoundEnable_ = true;
51 bool SystemProperties::textTraceEnable_ = false;
52 bool SystemProperties::syntaxTraceEnable_ = false;
53 bool SystemProperties::accessTraceEnable_ = false;
54 bool SystemProperties::vsyncModeTraceEnable_ = false;
55 bool SystemProperties::accessibilityEnabled_ = false;
56 bool SystemProperties::isRound_ = false;
57 bool SystemProperties::isDeviceAccess_ = false;
58 int32_t SystemProperties::deviceWidth_ = 0;
59 int32_t SystemProperties::deviceHeight_ = 0;
60 int32_t SystemProperties::devicePhysicalWidth_ = 0;
61 int32_t SystemProperties::devicePhysicalHeight_ = 0;
62 double SystemProperties::resolution_ = 1.0;
63 DeviceType SystemProperties::deviceType_ { DeviceType::PHONE };
64 DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
65 std::string SystemProperties::brand_ = UNDEFINED_PARAM;
66 std::string SystemProperties::manufacturer_ = UNDEFINED_PARAM;
67 std::string SystemProperties::model_ = UNDEFINED_PARAM;
68 std::string SystemProperties::product_ = UNDEFINED_PARAM;
69 std::string SystemProperties::apiVersion_ = "9";
70 std::string SystemProperties::releaseType_ = UNDEFINED_PARAM;
71 std::string SystemProperties::paramDeviceType_ = UNDEFINED_PARAM;
72 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
73 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
74 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
75 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
76 bool SystemProperties::unZipHap_ = true;
77 bool SystemProperties::windowAnimationEnabled_ = false;
78 bool SystemProperties::debugEnabled_ = false;
79 DebugFlags SystemProperties::debugFlags_ = 0;
80 bool SystemProperties::layoutDetectEnabled_ = false;
81 std::atomic<bool> SystemProperties::debugBoundaryEnabled_(false);
82 bool SystemProperties::debugAutoUIEnabled_ = false;
83 bool SystemProperties::debugOffsetLogEnabled_ = false;
84 bool SystemProperties::downloadByNetworkEnabled_ = false;
85 bool SystemProperties::recycleImageEnabled_ = false;
86 bool SystemProperties::gpuUploadEnabled_ = false;
87 bool SystemProperties::isHookModeEnabled_ = false;
88 bool SystemProperties::astcEnabled_ = false;
89 int SystemProperties::astcMax_ = 0;
90 int SystemProperties::astcPsnr_ = 0;
91 bool SystemProperties::imageFileCacheConvertAstc_ = false;
92 int32_t SystemProperties::imageFileCacheConvertAstcThreshold_ = 2;
93 bool SystemProperties::extSurfaceEnabled_ = false;
94 uint32_t SystemProperties::dumpFrameCount_ = 0;
95 bool SystemProperties::resourceDecoupling_ = true;
96 #ifndef ENABLE_ROSEN_BACKEND
97 bool SystemProperties::rosenBackendEnabled_ = false;
98 #else
99 bool SystemProperties::rosenBackendEnabled_ = true;
100 #endif
101 bool SystemProperties::enableScrollableItemPool_ = false;
102 bool SystemProperties::navigationBlurEnabled_ = true;
103 bool SystemProperties::gridCacheEnabled_ = false;
104 bool SystemProperties::sideBarContainerBlurEnable_ = false;
105 std::atomic<bool> SystemProperties::acePerformanceMonitorEnable_(false);
106 std::atomic<bool> SystemProperties::asyncInitializeEnabled_(true);
107 std::atomic<bool> SystemProperties::focusCanBeActive_(true);
108 bool SystemProperties::aceCommercialLogEnable_ = false;
109 std::pair<float, float> SystemProperties::brightUpPercent_ = {};
110 bool SystemProperties::faultInjectEnabled_ = false;
111 bool SystemProperties::imageFrameworkEnable_ = false;
112 float SystemProperties::pageCount_ = 1.0f;
113 float SystemProperties::dragStartDampingRatio_ = 0.2f;
114 float SystemProperties::dragStartPanDisThreshold_ = 10.0f;
115 uint32_t SystemProperties::canvasDebugMode_ = 0;
116 double SystemProperties::scrollableDistance_ = 0.0;
117 bool SystemProperties::taskPriorityAdjustmentEnable_ = false;
118 int32_t SystemProperties::dragDropFrameworkStatus_ = 0;
119 int32_t SystemProperties::touchAccelarate_ = 0;
120
IsOpIncEnable()121 bool SystemProperties::IsOpIncEnable()
122 {
123 return false;
124 }
125
InitDeviceType(DeviceType type)126 void SystemProperties::InitDeviceType(DeviceType type)
127 {
128 // Properties: "phone", "tv", "tablet", "watch", "car"
129 if (type == DeviceType::TV) {
130 deviceType_ = DeviceType::TV;
131 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TV;
132 } else if (type == DeviceType::WATCH) {
133 deviceType_ = DeviceType::WATCH;
134 paramDeviceType_ = PROPERTY_DEVICE_TYPE_WEARABLE;
135 } else if (type == DeviceType::CAR) {
136 deviceType_ = DeviceType::CAR;
137 paramDeviceType_ = PROPERTY_DEVICE_TYPE_CAR;
138 } else if (type == DeviceType::TABLET) {
139 deviceType_ = DeviceType::TABLET;
140 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TABLET;
141 } else if (type == DeviceType::TWO_IN_ONE) {
142 deviceType_ = DeviceType::TWO_IN_ONE;
143 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TWO_IN_ONE;
144 } else {
145 deviceType_ = DeviceType::PHONE;
146 paramDeviceType_ = PROPERTY_DEVICE_TYPE_PHONE;
147 }
148 }
149
GetDeviceType()150 DeviceType SystemProperties::GetDeviceType()
151 {
152 return deviceType_;
153 }
154
IsSyscapExist(const char * cap)155 bool SystemProperties::IsSyscapExist(const char* cap)
156 {
157 return false;
158 }
159
InitDeviceTypeBySystemProperty()160 void SystemProperties::InitDeviceTypeBySystemProperty()
161 {
162 deviceType_ = DeviceType::PHONE;
163 }
164
InitDeviceInfo(int32_t deviceWidth,int32_t deviceHeight,int32_t orientation,double resolution,bool isRound)165 void SystemProperties::InitDeviceInfo(
166 int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
167 {
168 // SetDeviceOrientation should be eralier than deviceWidth/deviceHeight init.
169 if (orientation == ORIENTATION_PORTRAIT) {
170 orientation_ = DeviceOrientation::PORTRAIT;
171 } else if (orientation == ORIENTATION_LANDSCAPE) {
172 orientation_ = DeviceOrientation::LANDSCAPE;
173 } else {
174 LOGW("SetDeviceOrientation, undefined orientation");
175 }
176
177 isRound_ = isRound;
178 resolution_ = resolution;
179 deviceWidth_ = deviceWidth;
180 deviceHeight_ = deviceHeight;
181 if (isRound_) {
182 screenShape_ = ScreenShape::ROUND;
183 } else {
184 screenShape_ = ScreenShape::NOT_ROUND;
185 }
186 }
187
SetDeviceOrientation(int32_t orientation)188 void SystemProperties::SetDeviceOrientation(int32_t orientation)
189 {
190 if (orientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
191 Swap(deviceWidth_, deviceHeight_);
192 orientation_ = DeviceOrientation::PORTRAIT;
193 } else if (orientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
194 Swap(deviceWidth_, deviceHeight_);
195 orientation_ = DeviceOrientation::LANDSCAPE;
196 } else {
197 LOGI("SetDeviceOrientation, no change info: %{public}d", orientation);
198 }
199 }
200
GetFontWeightScale()201 float SystemProperties::GetFontWeightScale()
202 {
203 return 1.0f;
204 }
205
InitMccMnc(int32_t mcc,int32_t mnc)206 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
207 {
208 mcc_ = mcc;
209 mnc_ = mnc;
210 }
211
IsScoringEnabled(const std::string & name)212 bool SystemProperties::IsScoringEnabled(const std::string& name)
213 {
214 return false;
215 }
216
GetDebugEnabled()217 bool SystemProperties::GetDebugEnabled()
218 {
219 return debugEnabled_;
220 }
221
GetLayoutDetectEnabled()222 bool SystemProperties::GetLayoutDetectEnabled()
223 {
224 return layoutDetectEnabled_;
225 }
226
GetLanguage()227 std::string SystemProperties::GetLanguage()
228 {
229 return UNDEFINED_PARAM;
230 }
231
GetRegion()232 std::string SystemProperties::GetRegion()
233 {
234 return UNDEFINED_PARAM;
235 }
236
GetPartialUpdatePkg()237 std::string SystemProperties::GetPartialUpdatePkg()
238 {
239 return {};
240 }
241
GetNewPipePkg()242 std::string SystemProperties::GetNewPipePkg()
243 {
244 return {};
245 }
246
GetSvgMode()247 int32_t SystemProperties::GetSvgMode()
248 {
249 return 1;
250 }
251
GetIsUseMemoryMonitor()252 bool SystemProperties::GetIsUseMemoryMonitor()
253 {
254 return false;
255 }
256
IsFormAnimationLimited()257 bool SystemProperties::IsFormAnimationLimited()
258 {
259 return true;
260 }
261
GetDebugPixelMapSaveEnabled()262 bool SystemProperties::GetDebugPixelMapSaveEnabled()
263 {
264 return false;
265 }
266
GetResourceDecoupling()267 bool SystemProperties::GetResourceDecoupling()
268 {
269 return true;
270 }
271
GetTitleStyleEnabled()272 bool SystemProperties::GetTitleStyleEnabled()
273 {
274 return false;
275 }
276
GetJankFrameThreshold()277 int32_t SystemProperties::GetJankFrameThreshold()
278 {
279 return 0;
280 }
281
GetCustomTitleFilePath()282 std::string SystemProperties::GetCustomTitleFilePath()
283 {
284 return UNDEFINED_PARAM;
285 }
286
Is24HourClock()287 bool SystemProperties::Is24HourClock()
288 {
289 return false;
290 }
291
GetDisplaySyncSkipEnabled()292 bool SystemProperties::GetDisplaySyncSkipEnabled()
293 {
294 return true;
295 }
296
GetNavigationBlurEnabled()297 bool SystemProperties::GetNavigationBlurEnabled()
298 {
299 return navigationBlurEnabled_;
300 }
301
GetGridCacheEnabled()302 bool SystemProperties::GetGridCacheEnabled()
303 {
304 return gridCacheEnabled_;
305 }
306
GetGridIrregularLayoutEnabled()307 bool SystemProperties::GetGridIrregularLayoutEnabled()
308 {
309 return false;
310 }
311
WaterFlowUseSegmentedLayout()312 bool SystemProperties::WaterFlowUseSegmentedLayout()
313 {
314 return false;
315 }
316
GetSideBarContainerBlurEnable()317 bool SystemProperties::GetSideBarContainerBlurEnable()
318 {
319 return sideBarContainerBlurEnable_;
320 }
321
GetDefaultResolution()322 float SystemProperties::GetDefaultResolution()
323 {
324 return 1.0f;
325 }
326
GetAtomicServiceBundleName()327 std::string SystemProperties::GetAtomicServiceBundleName()
328 {
329 return UNDEFINED_PARAM;
330 }
331
GetDragStartDampingRatio()332 float SystemProperties::GetDragStartDampingRatio()
333 {
334 return dragStartDampingRatio_;
335 }
336
GetDragStartPanDistanceThreshold()337 float SystemProperties::GetDragStartPanDistanceThreshold()
338 {
339 return dragStartPanDisThreshold_;
340 }
341
IsSmallFoldProduct()342 bool SystemProperties::IsSmallFoldProduct()
343 {
344 return false;
345 }
346
IsBigFoldProduct()347 bool SystemProperties::IsBigFoldProduct()
348 {
349 return false;
350 }
351
GetDebugInspectorId()352 std::string SystemProperties::GetDebugInspectorId()
353 {
354 return UNDEFINED_PARAM;
355 }
356
GetSrollableVelocityScale()357 double SystemProperties::GetSrollableVelocityScale()
358 {
359 return 0.0;
360 }
361
GetSrollableFriction()362 double SystemProperties::GetSrollableFriction()
363 {
364 return 0.0;
365 }
366
GetScrollableDistance()367 double SystemProperties::GetScrollableDistance()
368 {
369 return scrollableDistance_;
370 }
371
IsNeedResampleTouchPoints()372 bool SystemProperties::IsNeedResampleTouchPoints()
373 {
374 return true;
375 }
376
IsNeedSymbol()377 bool SystemProperties::IsNeedSymbol()
378 {
379 return true;
380 }
381
GetDragDropFrameworkStatus()382 int32_t SystemProperties::GetDragDropFrameworkStatus()
383 {
384 return dragDropFrameworkStatus_;
385 }
386
GetTouchAccelarate()387 int32_t SystemProperties::GetTouchAccelarate()
388 {
389 return touchAccelarate_;
390 }
391
GetContainerDeleteFlag()392 bool SystemProperties::GetContainerDeleteFlag()
393 {
394 return true;
395 }
396
IsSuperFoldDisplayDevice()397 bool SystemProperties::IsSuperFoldDisplayDevice()
398 {
399 return false;
400 }
401 } // namespace OHOS::Ace
402