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::traceEnabled_ = false;
42 bool SystemProperties::svgTraceEnable_ = false;
43 bool SystemProperties::accessibilityEnabled_ = false;
44 bool SystemProperties::isRound_ = false;
45 bool SystemProperties::isDeviceAccess_ = false;
46 int32_t SystemProperties::deviceWidth_ = 0;
47 int32_t SystemProperties::deviceHeight_ = 0;
48 double SystemProperties::resolution_ = 1.0;
49 DeviceType SystemProperties::deviceType_ { DeviceType::PHONE };
50 DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT };
51 std::string SystemProperties::brand_ = UNDEFINED_PARAM;
52 std::string SystemProperties::manufacturer_ = UNDEFINED_PARAM;
53 std::string SystemProperties::model_ = UNDEFINED_PARAM;
54 std::string SystemProperties::product_ = UNDEFINED_PARAM;
55 std::string SystemProperties::apiVersion_ = "9";
56 std::string SystemProperties::releaseType_ = UNDEFINED_PARAM;
57 std::string SystemProperties::paramDeviceType_ = UNDEFINED_PARAM;
58 int32_t SystemProperties::mcc_ = MCC_UNDEFINED;
59 int32_t SystemProperties::mnc_ = MNC_UNDEFINED;
60 ColorMode SystemProperties::colorMode_ = ColorMode::LIGHT;
61 ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
62 LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
63 bool SystemProperties::unZipHap_ = true;
64 bool SystemProperties::windowAnimationEnabled_ = false;
65 bool SystemProperties::debugBoundaryEnabled_ = false;
66 bool SystemProperties::gpuUploadEnabled_ = false;
67 bool SystemProperties::isHookModeEnabled_ = false;
68 bool SystemProperties::astcEnabled_ = false;
69 int SystemProperties::astcMax_ = 0;
70 int SystemProperties::astcPsnr_ = 0;
71 bool SystemProperties::extSurfaceEnabled_ = false;
72 uint32_t SystemProperties::dumpFrameCount_ = 0;
73 #ifndef ENABLE_ROSEN_BACKEND
74 bool SystemProperties::rosenBackendEnabled_ = false;
75 #else
76 bool SystemProperties::rosenBackendEnabled_ = true;
77 #endif
78
InitDeviceType(DeviceType type)79 void SystemProperties::InitDeviceType(DeviceType type)
80 {
81 // Properties: "phone", "tv", "tablet", "watch", "car"
82 if (type == DeviceType::TV) {
83 deviceType_ = DeviceType::TV;
84 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TV;
85 } else if (type == DeviceType::WATCH) {
86 deviceType_ = DeviceType::WATCH;
87 paramDeviceType_ = PROPERTY_DEVICE_TYPE_WEARABLE;
88 } else if (type == DeviceType::CAR) {
89 deviceType_ = DeviceType::CAR;
90 paramDeviceType_ = PROPERTY_DEVICE_TYPE_CAR;
91 } else if (type == DeviceType::TABLET) {
92 deviceType_ = DeviceType::TABLET;
93 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TABLET;
94 } else if (type == DeviceType::TWO_IN_ONE) {
95 deviceType_ = DeviceType::TWO_IN_ONE;
96 paramDeviceType_ = PROPERTY_DEVICE_TYPE_TWO_IN_ONE;
97 } else {
98 deviceType_ = DeviceType::PHONE;
99 paramDeviceType_ = PROPERTY_DEVICE_TYPE_PHONE;
100 }
101 }
102
GetDeviceType()103 DeviceType SystemProperties::GetDeviceType()
104 {
105 return deviceType_;
106 }
107
IsSyscapExist(const char * cap)108 bool SystemProperties::IsSyscapExist(const char* cap)
109 {
110 return false;
111 }
112
InitDeviceTypeBySystemProperty()113 void SystemProperties::InitDeviceTypeBySystemProperty()
114 {
115 deviceType_ = DeviceType::PHONE;
116 }
117
InitDeviceInfo(int32_t deviceWidth,int32_t deviceHeight,int32_t orientation,double resolution,bool isRound)118 void SystemProperties::InitDeviceInfo(
119 int32_t deviceWidth, int32_t deviceHeight, int32_t orientation, double resolution, bool isRound)
120 {
121 // SetDeviceOrientation should be eralier than deviceWidth/deviceHeight init.
122 if (orientation == ORIENTATION_PORTRAIT) {
123 orientation_ = DeviceOrientation::PORTRAIT;
124 } else if (orientation == ORIENTATION_LANDSCAPE) {
125 orientation_ = DeviceOrientation::LANDSCAPE;
126 } else {
127 LOGW("SetDeviceOrientation, undefined orientation");
128 }
129
130 isRound_ = isRound;
131 resolution_ = resolution;
132 deviceWidth_ = deviceWidth;
133 deviceHeight_ = deviceHeight;
134 if (isRound_) {
135 screenShape_ = ScreenShape::ROUND;
136 } else {
137 screenShape_ = ScreenShape::NOT_ROUND;
138 }
139 }
140
SetDeviceOrientation(int32_t orientation)141 void SystemProperties::SetDeviceOrientation(int32_t orientation)
142 {
143 if (orientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) {
144 Swap(deviceWidth_, deviceHeight_);
145 orientation_ = DeviceOrientation::PORTRAIT;
146 } else if (orientation == ORIENTATION_LANDSCAPE && orientation_ != DeviceOrientation::LANDSCAPE) {
147 Swap(deviceWidth_, deviceHeight_);
148 orientation_ = DeviceOrientation::LANDSCAPE;
149 } else {
150 LOGI("SetDeviceOrientation, no change info: %{public}d", orientation);
151 }
152 }
153
GetFontWeightScale()154 float SystemProperties::GetFontWeightScale()
155 {
156 return 1.0f;
157 }
158
InitMccMnc(int32_t mcc,int32_t mnc)159 void SystemProperties::InitMccMnc(int32_t mcc, int32_t mnc)
160 {
161 mcc_ = mcc;
162 mnc_ = mnc;
163 }
164
IsScoringEnabled(const std::string & name)165 bool SystemProperties::IsScoringEnabled(const std::string& name)
166 {
167 return false;
168 }
169
GetDebugEnabled()170 bool SystemProperties::GetDebugEnabled()
171 {
172 return false;
173 }
174
GetLanguage()175 std::string SystemProperties::GetLanguage()
176 {
177 return UNDEFINED_PARAM;
178 }
179
GetRegion()180 std::string SystemProperties::GetRegion()
181 {
182 return UNDEFINED_PARAM;
183 }
184
GetPartialUpdatePkg()185 std::string SystemProperties::GetPartialUpdatePkg()
186 {
187 // TODO: add support for pc preview.
188 return {};
189 }
190
GetNewPipePkg()191 std::string SystemProperties::GetNewPipePkg()
192 {
193 // TODO: add support for pc preview.
194 return {};
195 }
196
GetSvgMode()197 int32_t SystemProperties::GetSvgMode()
198 {
199 return 1;
200 }
201
GetIsUseMemoryMonitor()202 bool SystemProperties::GetIsUseMemoryMonitor()
203 {
204 return false;
205 }
206
IsFormAnimationLimited()207 bool SystemProperties::IsFormAnimationLimited()
208 {
209 return true;
210 }
211
GetImageFrameworkEnabled()212 bool SystemProperties::GetImageFrameworkEnabled()
213 {
214 return false;
215 }
216 } // namespace OHOS::Ace
217