1 /*
2 * Copyright (c) 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 "wifi_manager_proxy.h"
17
18 #include "edm_constants.h"
19 #include "edm_log.h"
20 #include "func_code.h"
21 #include "message_parcel_utils.h"
22
23 namespace OHOS {
24 namespace EDM {
25 std::shared_ptr<WifiManagerProxy> WifiManagerProxy::instance_ = nullptr;
26 std::mutex WifiManagerProxy::mutexLock_;
27 const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr";
28
WifiManagerProxy()29 WifiManagerProxy::WifiManagerProxy() {}
30
~WifiManagerProxy()31 WifiManagerProxy::~WifiManagerProxy() {}
32
GetWifiManagerProxy()33 std::shared_ptr<WifiManagerProxy> WifiManagerProxy::GetWifiManagerProxy()
34 {
35 if (instance_ == nullptr) {
36 std::lock_guard<std::mutex> lock(mutexLock_);
37 if (instance_ == nullptr) {
38 std::shared_ptr<WifiManagerProxy> temp = std::make_shared<WifiManagerProxy>();
39 instance_ = temp;
40 }
41 }
42 return instance_;
43 }
44
IsWifiActive(const AppExecFwk::ElementName & admin,bool & result,bool isSync)45 int32_t WifiManagerProxy::IsWifiActive(const AppExecFwk::ElementName &admin, bool &result, bool isSync)
46 {
47 EDMLOGD("WifiManagerProxy::IsWifiActive");
48 auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
49 MessageParcel data;
50 MessageParcel reply;
51 data.WriteInterfaceToken(DESCRIPTOR);
52 data.WriteInt32(WITHOUT_USERID);
53 data.WriteString(isSync ? EdmConstants::PERMISSION_TAG_VERSION_12 : EdmConstants::PERMISSION_TAG_VERSION_11);
54 data.WriteInt32(HAS_ADMIN);
55 data.WriteParcelable(&admin);
56 proxy->GetPolicy(EdmInterfaceCode::IS_WIFI_ACTIVE, data, reply);
57 int32_t ret = ERR_INVALID_VALUE;
58 bool blRes = reply.ReadInt32(ret) && (ret == ERR_OK);
59 if (!blRes) {
60 EDMLOGW("EnterpriseDeviceMgrProxy:GetPolicy fail. %{public}d", ret);
61 return ret;
62 }
63 reply.ReadBool(result);
64 return ERR_OK;
65 }
66 #ifdef WIFI_EDM_ENABLE
SetWifiProfile(const AppExecFwk::ElementName & admin,Wifi::WifiDeviceConfig & config,WifiPassword & pwd,bool isSync)67 int32_t WifiManagerProxy::SetWifiProfile(const AppExecFwk::ElementName &admin, Wifi::WifiDeviceConfig &config,
68 WifiPassword &pwd, bool isSync)
69 {
70 EDMLOGD("WifiManagerProxy::SetWifiProfile");
71 auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
72 MessageParcel data;
73 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_WIFI_PROFILE);
74 data.WriteInterfaceToken(DESCRIPTOR);
75 data.WriteInt32(WITHOUT_USERID);
76 data.WriteParcelable(&admin);
77 data.WriteString(isSync ? EdmConstants::PERMISSION_TAG_VERSION_12 : EdmConstants::PERMISSION_TAG_VERSION_11);
78 MessageParcelUtils::WriteWifiDeviceConfig(config, data, pwd);
79 return proxy->HandleDevicePolicy(funcCode, data);
80 }
81 #endif
82
SetWifiDisabled(const AppExecFwk::ElementName & admin,const bool & isDisabled)83 int32_t WifiManagerProxy::SetWifiDisabled(const AppExecFwk::ElementName &admin, const bool &isDisabled)
84 {
85 EDMLOGD("WifiManagerProxy::SetWifiDisabled. isDisable: %{public}d", isDisabled);
86 return EnterpriseDeviceMgrProxy::GetInstance()->SetPolicyDisabled(admin, isDisabled,
87 EdmInterfaceCode::DISABLE_WIFI, EdmConstants::PERMISSION_TAG_VERSION_11);
88 }
89
IsWifiDisabled(AppExecFwk::ElementName * admin,bool & result)90 int32_t WifiManagerProxy::IsWifiDisabled(AppExecFwk::ElementName *admin, bool &result)
91 {
92 EDMLOGD("WifiManagerProxy::IsWifiDisabled");
93 return EnterpriseDeviceMgrProxy::GetInstance()->IsPolicyDisabled(admin, EdmInterfaceCode::DISABLE_WIFI, result,
94 EdmConstants::PERMISSION_TAG_VERSION_11);
95 }
96 } // namespace EDM
97 } // namespace OHOS
98