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_impl.h"
17 
18 #include "include/nweb_helper.h"
19 
20 #include "base/bridge/ark_web_bridge_macros.h"
21 
22 namespace OHOS::ArkWeb {
23 
ArkSystemPropertiesAdapterImpl(NWeb::SystemPropertiesAdapter & ref)24 ArkSystemPropertiesAdapterImpl::ArkSystemPropertiesAdapterImpl(NWeb::SystemPropertiesAdapter& ref) : real_(ref) {}
25 
GetResourceUseHapPathEnable()26 bool ArkSystemPropertiesAdapterImpl::GetResourceUseHapPathEnable()
27 {
28     return real_.GetResourceUseHapPathEnable();
29 }
30 
GetDeviceInfoProductModel()31 ArkWebString ArkSystemPropertiesAdapterImpl::GetDeviceInfoProductModel()
32 {
33     std::string str = real_.GetDeviceInfoProductModel();
34     return ArkWebStringClassToStruct(str);
35 }
36 
GetDeviceInfoBrand()37 ArkWebString ArkSystemPropertiesAdapterImpl::GetDeviceInfoBrand()
38 {
39     std::string str = real_.GetDeviceInfoBrand();
40     return ArkWebStringClassToStruct(str);
41 }
42 
GetDeviceInfoMajorVersion()43 int32_t ArkSystemPropertiesAdapterImpl::GetDeviceInfoMajorVersion()
44 {
45     return real_.GetDeviceInfoMajorVersion();
46 }
47 
GetProductDeviceType()48 int32_t ArkSystemPropertiesAdapterImpl::GetProductDeviceType()
49 {
50     return (int32_t)real_.GetProductDeviceType();
51 }
52 
GetWebOptimizationValue()53 bool ArkSystemPropertiesAdapterImpl::GetWebOptimizationValue()
54 {
55     return real_.GetWebOptimizationValue();
56 }
57 
IsAdvancedSecurityMode()58 bool ArkSystemPropertiesAdapterImpl::IsAdvancedSecurityMode()
59 {
60     return real_.IsAdvancedSecurityMode();
61 }
62 
GetUserAgentOSName()63 ArkWebString ArkSystemPropertiesAdapterImpl::GetUserAgentOSName()
64 {
65     std::string str = real_.GetUserAgentOSName();
66     return ArkWebStringClassToStruct(str);
67 }
68 
GetUserAgentOSVersion()69 ArkWebString ArkSystemPropertiesAdapterImpl::GetUserAgentOSVersion()
70 {
71     std::string str = real_.GetUserAgentOSVersion();
72     return ArkWebStringClassToStruct(str);
73 }
74 
GetUserAgentBaseOSName()75 ArkWebString ArkSystemPropertiesAdapterImpl::GetUserAgentBaseOSName()
76 {
77     std::string str = real_.GetUserAgentBaseOSName();
78     return ArkWebStringClassToStruct(str);
79 }
80 
GetSoftwareMajorVersion()81 int32_t ArkSystemPropertiesAdapterImpl::GetSoftwareMajorVersion()
82 {
83     return real_.GetSoftwareMajorVersion();
84 }
85 
GetSoftwareSeniorVersion()86 int32_t ArkSystemPropertiesAdapterImpl::GetSoftwareSeniorVersion()
87 {
88     return real_.GetSoftwareSeniorVersion();
89 }
90 
GetNetlogMode()91 ArkWebString ArkSystemPropertiesAdapterImpl::GetNetlogMode()
92 {
93     std::string str = real_.GetNetlogMode();
94     return ArkWebStringClassToStruct(str);
95 }
96 
GetTraceDebugEnable()97 bool ArkSystemPropertiesAdapterImpl::GetTraceDebugEnable()
98 {
99     return real_.GetTraceDebugEnable();
100 }
101 
GetSiteIsolationMode()102 ArkWebString ArkSystemPropertiesAdapterImpl::GetSiteIsolationMode()
103 {
104     std::string str = real_.GetSiteIsolationMode();
105     return ArkWebStringClassToStruct(str);
106 }
107 
GetFlowBufMaxFd()108 int32_t ArkSystemPropertiesAdapterImpl::GetFlowBufMaxFd()
109 {
110     return real_.GetFlowBufMaxFd();
111 }
112 
GetOOPGPUEnable()113 bool ArkSystemPropertiesAdapterImpl::GetOOPGPUEnable()
114 {
115     return real_.GetOOPGPUEnable();
116 }
117 
SetOOPGPUDisable()118 void ArkSystemPropertiesAdapterImpl::SetOOPGPUDisable()
119 {
120     real_.SetOOPGPUDisable();
121 }
122 
AttachSysPropObserver(int32_t key,void * observer)123 void ArkSystemPropertiesAdapterImpl::AttachSysPropObserver(int32_t key, void* observer)
124 {
125     real_.AttachSysPropObserver((NWeb::PropertiesKey)key, (NWeb::SystemPropertiesObserver*)observer);
126 }
127 
DetachSysPropObserver(int32_t key,void * observer)128 void ArkSystemPropertiesAdapterImpl::DetachSysPropObserver(int32_t key, void* observer)
129 {
130     real_.DetachSysPropObserver((NWeb::PropertiesKey)key, (NWeb::SystemPropertiesObserver*)observer);
131 }
132 
GetBoolParameter(ArkWebString key,bool defaultValue)133 bool ArkSystemPropertiesAdapterImpl::GetBoolParameter(ArkWebString key, bool defaultValue)
134 {
135     return real_.GetBoolParameter(ArkWebStringStructToClass(key), defaultValue);
136 }
137 
GetLTPOConfig(const ArkWebString & settingName)138 ArkFrameRateSettingAdapterVector ArkSystemPropertiesAdapterImpl::GetLTPOConfig(const ArkWebString& settingName)
139 {
140     std::vector<NWeb::FrameRateSetting> frameRateSettingVector =
141         real_.GetLTPOConfig(ArkWebStringStructToClass(settingName));
142     ArkFrameRateSettingAdapterVector result = { .size = frameRateSettingVector.size(),
143         .ark_web_mem_free_func = ArkWebMemFree };
144     if (result.size > 0) {
145         result.value = (ArkFrameRateSettingAdapter*)ArkWebMemMalloc(sizeof(ArkFrameRateSettingAdapter) * result.size);
146         if (result.value == nullptr) {
147             result.size = 0;
148             return result;
149         }
150 
151         int count = 0;
152         for (auto it = frameRateSettingVector.begin(); it != frameRateSettingVector.end(); it++) {
153             result.value[count] = { it->min_, it->max_, it->preferredFrameRate_ };
154             count++;
155         }
156     }
157 
158     return result;
159 }
160 
GetOOPGPUStatus()161 ArkWebString ArkSystemPropertiesAdapterImpl::GetOOPGPUStatus()
162 {
163     std::string str = real_.GetOOPGPUStatus();
164     return ArkWebStringClassToStruct(str);
165 }
166 
167 } // namespace OHOS::ArkWeb
168