1 /*
2 * Copyright (c) 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 #include "ohos_adapter/bridge/ark_system_properties_adapter_wrapper.h"
17
18 namespace {
19 constexpr int32_t DEFAULT_INITIAL_CONGESTION_WINDOW_SIZE = 10;
20 }
21
22 namespace OHOS::ArkWeb {
23 using OHOS::NWeb::FrameRateSetting;
ArkSystemPropertiesAdapterWrapper(ArkWebRefPtr<ArkSystemPropertiesAdapter> ref)24 ArkSystemPropertiesAdapterWrapper::ArkSystemPropertiesAdapterWrapper(ArkWebRefPtr<ArkSystemPropertiesAdapter> ref)
25 : ctocpp_(ref)
26 {}
27
GetResourceUseHapPathEnable()28 bool ArkSystemPropertiesAdapterWrapper::GetResourceUseHapPathEnable()
29 {
30 if (!ctocpp_) {
31 return false;
32 }
33 return ctocpp_->GetResourceUseHapPathEnable();
34 }
35
GetDeviceInfoProductModel()36 std::string ArkSystemPropertiesAdapterWrapper::GetDeviceInfoProductModel()
37 {
38 if (!ctocpp_) {
39 return "";
40 }
41 ArkWebString str = ctocpp_->GetDeviceInfoProductModel();
42 std::string result = ArkWebStringStructToClass(str);
43 ArkWebStringStructRelease(str);
44 return result;
45 }
46
GetDeviceInfoBrand()47 std::string ArkSystemPropertiesAdapterWrapper::GetDeviceInfoBrand()
48 {
49 if (!ctocpp_) {
50 return "";
51 }
52 ArkWebString str = ctocpp_->GetDeviceInfoBrand();
53 std::string result = ArkWebStringStructToClass(str);
54 ArkWebStringStructRelease(str);
55 return result;
56 }
57
GetDeviceInfoMajorVersion()58 int32_t ArkSystemPropertiesAdapterWrapper::GetDeviceInfoMajorVersion()
59 {
60 if (!ctocpp_) {
61 return -1;
62 }
63 return ctocpp_->GetDeviceInfoMajorVersion();
64 }
65
GetProductDeviceType()66 OHOS::NWeb::ProductDeviceType ArkSystemPropertiesAdapterWrapper::GetProductDeviceType()
67 {
68 if (!ctocpp_) {
69 return OHOS::NWeb::ProductDeviceType::DEVICE_TYPE_UNKNOWN;
70 }
71 int32_t result = ctocpp_->GetProductDeviceType();
72 return (OHOS::NWeb::ProductDeviceType)result;
73 }
74
GetWebOptimizationValue()75 bool ArkSystemPropertiesAdapterWrapper::GetWebOptimizationValue()
76 {
77 if (!ctocpp_) {
78 return false;
79 }
80 return ctocpp_->GetWebOptimizationValue();
81 }
82
IsAdvancedSecurityMode()83 bool ArkSystemPropertiesAdapterWrapper::IsAdvancedSecurityMode()
84 {
85 if (!ctocpp_) {
86 return false;
87 }
88 return ctocpp_->IsAdvancedSecurityMode();
89 }
90
GetUserAgentOSName()91 std::string ArkSystemPropertiesAdapterWrapper::GetUserAgentOSName()
92 {
93 if (!ctocpp_) {
94 return "";
95 }
96 ArkWebString str = ctocpp_->GetUserAgentOSName();
97 std::string result = ArkWebStringStructToClass(str);
98 ArkWebStringStructRelease(str);
99 return result;
100 }
101
GetUserAgentOSVersion()102 std::string ArkSystemPropertiesAdapterWrapper::GetUserAgentOSVersion()
103 {
104 if (!ctocpp_) {
105 return "";
106 }
107 ArkWebString str = ctocpp_->GetUserAgentOSVersion();
108 std::string result = ArkWebStringStructToClass(str);
109 ArkWebStringStructRelease(str);
110 return result;
111 }
112
GetUserAgentBaseOSName()113 std::string ArkSystemPropertiesAdapterWrapper::GetUserAgentBaseOSName()
114 {
115 if (!ctocpp_) {
116 return "";
117 }
118 ArkWebString str = ctocpp_->GetUserAgentBaseOSName();
119 std::string result = ArkWebStringStructToClass(str);
120 ArkWebStringStructRelease(str);
121 return result;
122 }
123
GetSoftwareMajorVersion()124 int32_t ArkSystemPropertiesAdapterWrapper::GetSoftwareMajorVersion()
125 {
126 if (!ctocpp_) {
127 return -1;
128 }
129 return ctocpp_->GetSoftwareMajorVersion();
130 }
131
GetSoftwareSeniorVersion()132 int32_t ArkSystemPropertiesAdapterWrapper::GetSoftwareSeniorVersion()
133 {
134 if (!ctocpp_) {
135 return -1;
136 }
137 return ctocpp_->GetSoftwareSeniorVersion();
138 }
139
GetNetlogMode()140 std::string ArkSystemPropertiesAdapterWrapper::GetNetlogMode()
141 {
142 if (!ctocpp_) {
143 return "";
144 }
145 ArkWebString str = ctocpp_->GetNetlogMode();
146 std::string result = ArkWebStringStructToClass(str);
147 ArkWebStringStructRelease(str);
148 return result;
149 }
150
GetTraceDebugEnable()151 bool ArkSystemPropertiesAdapterWrapper::GetTraceDebugEnable()
152 {
153 if (!ctocpp_) {
154 return false;
155 }
156 return ctocpp_->GetTraceDebugEnable();
157 }
158
GetSiteIsolationMode()159 std::string ArkSystemPropertiesAdapterWrapper::GetSiteIsolationMode()
160 {
161 ArkWebString str = ctocpp_->GetSiteIsolationMode();
162 std::string result = ArkWebStringStructToClass(str);
163 ArkWebStringStructRelease(str);
164 return result;
165 }
166
GetFlowBufMaxFd()167 int32_t ArkSystemPropertiesAdapterWrapper::GetFlowBufMaxFd()
168 {
169 if (!ctocpp_) {
170 return -1;
171 }
172 return ctocpp_->GetFlowBufMaxFd();
173 }
174
GetOOPGPUEnable()175 bool ArkSystemPropertiesAdapterWrapper::GetOOPGPUEnable()
176 {
177 if (!ctocpp_) {
178 return false;
179 }
180 return ctocpp_->GetOOPGPUEnable();
181 }
182
SetOOPGPUDisable()183 void ArkSystemPropertiesAdapterWrapper::SetOOPGPUDisable()
184 {
185 if (!ctocpp_) {
186 return;
187 }
188 ctocpp_->SetOOPGPUDisable();
189 }
190
AttachSysPropObserver(NWeb::PropertiesKey key,NWeb::SystemPropertiesObserver * observer)191 void ArkSystemPropertiesAdapterWrapper::AttachSysPropObserver(
192 NWeb::PropertiesKey key, NWeb::SystemPropertiesObserver* observer)
193 {
194 ctocpp_->AttachSysPropObserver((int32_t)key, (void*)observer);
195 }
196
DetachSysPropObserver(NWeb::PropertiesKey key,NWeb::SystemPropertiesObserver * observer)197 void ArkSystemPropertiesAdapterWrapper::DetachSysPropObserver(
198 NWeb::PropertiesKey key, NWeb::SystemPropertiesObserver* observer)
199 {
200 ctocpp_->DetachSysPropObserver((int32_t)key, (void*)observer);
201 }
202
GetBoolParameter(const std::string & key,bool defaultValue)203 bool ArkSystemPropertiesAdapterWrapper::GetBoolParameter(const std::string& key, bool defaultValue)
204 {
205 ArkWebString str = ArkWebStringClassToStruct(key);
206 bool result = ctocpp_->GetBoolParameter(str, defaultValue);
207 ArkWebStringStructRelease(str);
208 return result;
209 }
210
211 ARK_WEB_NO_SANITIZE
GetLTPOConfig(const std::string & settingName)212 std::vector<FrameRateSetting> ArkSystemPropertiesAdapterWrapper::GetLTPOConfig(const std::string& settingName)
213 {
214 if (!ctocpp_) {
215 return {};
216 }
217 ArkWebString ark_setting_name = ArkWebStringClassToStruct(settingName);
218 ArkFrameRateSettingAdapterVector ark_vector = ctocpp_->GetLTPOConfig(ark_setting_name);
219 std::vector<FrameRateSetting> result {};
220
221 for (int i = 0; i < ark_vector.size; i++) {
222 result.emplace_back(FrameRateSetting {
223 ark_vector.value[i].min_, ark_vector.value[i].max_, ark_vector.value[i].preferredFrameRate_ });
224 }
225 ArkWebStringStructRelease(ark_setting_name);
226 SAFE_FREE(ark_vector.value, ark_vector.ark_web_mem_free_func);
227
228 return result;
229 }
230
GetOOPGPUStatus()231 std::string ArkSystemPropertiesAdapterWrapper::GetOOPGPUStatus()
232 {
233 if (!ctocpp_) {
234 return "";
235 }
236 ArkWebString str = ctocpp_->GetOOPGPUStatus();
237 std::string result = ArkWebStringStructToClass(str);
238 ArkWebStringStructRelease(str);
239 return result;
240 }
241
IsLTPODynamicApp(const std::string & bundleName)242 bool ArkSystemPropertiesAdapterWrapper::IsLTPODynamicApp(const std::string& bundleName)
243 {
244 ArkWebString ark_bundle_name = ArkWebStringClassToStruct(bundleName);
245 bool result = ctocpp_->IsLTPODynamicApp(ark_bundle_name);
246 ArkWebStringStructRelease(ark_bundle_name);
247 return result;
248 }
249
GetLTPOStrategy()250 int32_t ArkSystemPropertiesAdapterWrapper::GetLTPOStrategy()
251 {
252 int32_t result = ctocpp_->GetLTPOStrategy();
253 return result;
254 }
255
GetVulkanStatus()256 std::string ArkSystemPropertiesAdapterWrapper::GetVulkanStatus()
257 {
258 if (!ctocpp_) {
259 return "";
260 }
261 ArkWebString str = ctocpp_->GetVulkanStatus();
262 std::string result = ArkWebStringStructToClass(str);
263 ArkWebStringStructRelease(str);
264 return result;
265 }
266
GetCompatibleDeviceType()267 std::string ArkSystemPropertiesAdapterWrapper::GetCompatibleDeviceType()
268 {
269 if (!ctocpp_) {
270 return "";
271 }
272 ArkWebString str = ctocpp_->GetCompatibleDeviceType();
273 std::string result = ArkWebStringStructToClass(str);
274 ArkWebStringStructRelease(str);
275 return result;
276 }
277
GetDeviceInfoApiVersion()278 std::string ArkSystemPropertiesAdapterWrapper::GetDeviceInfoApiVersion()
279 {
280 if (!ctocpp_) {
281 return "";
282 }
283 ArkWebString str = ctocpp_->GetDeviceInfoApiVersion();
284 std::string result = ArkWebStringStructToClass(str);
285 ArkWebStringStructRelease(str);
286 return result;
287 }
288
GetPRPPreloadMode()289 std::string ArkSystemPropertiesAdapterWrapper::GetPRPPreloadMode()
290 {
291 if (!ctocpp_) {
292 return "";
293 }
294 ArkWebString str = ctocpp_->GetPRPPreloadMode();
295 std::string result = ArkWebStringStructToClass(str);
296 ArkWebStringStructRelease(str);
297 return result;
298 }
299
GetScrollVelocityScale()300 std::string ArkSystemPropertiesAdapterWrapper::GetScrollVelocityScale()
301 {
302 if (!ctocpp_) {
303 return "";
304 }
305 ArkWebString str = ctocpp_->GetScrollVelocityScale();
306 std::string result = ArkWebStringStructToClass(str);
307 ArkWebStringStructRelease(str);
308 return result;
309 }
310
GetScrollFriction()311 std::string ArkSystemPropertiesAdapterWrapper::GetScrollFriction()
312 {
313 if (!ctocpp_) {
314 return "";
315 }
316 ArkWebString str = ctocpp_->GetScrollFriction();
317 std::string result = ArkWebStringStructToClass(str);
318 ArkWebStringStructRelease(str);
319 return result;
320 }
321
GetBundleName()322 std::string ArkSystemPropertiesAdapterWrapper::GetBundleName()
323 {
324 if (!ctocpp_) {
325 return "";
326 }
327 ArkWebString str = ctocpp_->GetBundleName();
328 std::string result = ArkWebStringStructToClass(str);
329 ArkWebStringStructRelease(str);
330 return result;
331 }
332
GetStringParameter(const std::string & key,const std::string & defaultValue)333 std::string ArkSystemPropertiesAdapterWrapper::GetStringParameter(const std::string& key,
334 const std::string& defaultValue)
335 {
336 if (!ctocpp_) {
337 return "";
338 }
339 ArkWebString str = ArkWebStringClassToStruct(key);
340 ArkWebString value = ArkWebStringClassToStruct(defaultValue);
341 ArkWebString res = ctocpp_->GetStringParameter(str, value);
342 std::string result = ArkWebStringStructToClass(res);
343 ArkWebStringStructRelease(str);
344 ArkWebStringStructRelease(value);
345 ArkWebStringStructRelease(res);
346 return result;
347 }
348
GetInitialCongestionWindowSize()349 int32_t ArkSystemPropertiesAdapterWrapper::GetInitialCongestionWindowSize()
350 {
351 if (!ctocpp_) {
352 return DEFAULT_INITIAL_CONGESTION_WINDOW_SIZE;
353 }
354 return ctocpp_->GetInitialCongestionWindowSize();
355 }
356
GetIntParameter(const std::string & key,int32_t defaultValue)357 int32_t ArkSystemPropertiesAdapterWrapper::GetIntParameter(const std::string& key, int32_t defaultValue)
358 {
359 if (!ctocpp_) {
360 return -1;
361 }
362 ArkWebString str = ArkWebStringClassToStruct(key);
363 int32_t result = ctocpp_->GetIntParameter(str, defaultValue);
364 ArkWebStringStructRelease(str);
365 return result;
366 }
367 } // namespace OHOS::ArkWeb
368