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
GetLTPOConfig(const std::string & settingName)207 std::vector<FrameRateSetting> ArkSystemPropertiesAdapterWrapper::GetLTPOConfig(const std::string& settingName)
208 {
209 if (!ctocpp_) {
210 return {};
211 }
212 ArkWebString ark_setting_name = ArkWebStringClassToStruct(settingName);
213 ArkFrameRateSettingAdapterVector ark_vector = ctocpp_->GetLTPOConfig(ark_setting_name);
214 std::vector<FrameRateSetting> result {};
215
216 for (int i = 0; i < ark_vector.size; i++) {
217 result.emplace_back(FrameRateSetting {
218 ark_vector.value[i].min_, ark_vector.value[i].max_, ark_vector.value[i].preferredFrameRate_ });
219 }
220 ArkWebStringStructRelease(ark_setting_name);
221 SAFE_FREE(ark_vector.value, ark_vector.ark_web_mem_free_func);
222
223 return result;
224 }
225
GetOOPGPUStatus()226 std::string ArkSystemPropertiesAdapterWrapper::GetOOPGPUStatus()
227 {
228 ArkWebString str = ctocpp_->GetOOPGPUStatus();
229 std::string result = ArkWebStringStructToClass(str);
230 ArkWebStringStructRelease(str);
231 return result;
232 }
233 } // namespace OHOS::ArkWeb
234