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