• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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_log.h"
19 #include "func_code.h"
20 #include "message_parcel_utils.h"
21 
22 namespace OHOS {
23 namespace EDM {
24 std::shared_ptr<WifiManagerProxy> WifiManagerProxy::instance_ = nullptr;
25 std::once_flag WifiManagerProxy::flag_;
26 const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr";
27 
WifiManagerProxy()28 WifiManagerProxy::WifiManagerProxy() {}
29 
~WifiManagerProxy()30 WifiManagerProxy::~WifiManagerProxy() {}
31 
GetWifiManagerProxy()32 std::shared_ptr<WifiManagerProxy> WifiManagerProxy::GetWifiManagerProxy()
33 {
34     std::call_once(flag_, []() {
35         if (instance_ == nullptr) {
36             instance_ = std::make_shared<WifiManagerProxy>();
37         }
38     });
39     return instance_;
40 }
41 
IsWifiActive(MessageParcel & data,bool & result)42 int32_t WifiManagerProxy::IsWifiActive(MessageParcel &data, bool &result)
43 {
44     EDMLOGD("WifiManagerProxy::IsWifiActive");
45     auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
46     MessageParcel reply;
47     proxy->GetPolicy(EdmInterfaceCode::IS_WIFI_ACTIVE, data, reply);
48     int32_t ret = ERR_INVALID_VALUE;
49     bool blRes = reply.ReadInt32(ret) && (ret == ERR_OK);
50     if (!blRes) {
51         EDMLOGW("EnterpriseDeviceMgrProxy:GetPolicy fail. %{public}d", ret);
52         return ret;
53     }
54     reply.ReadBool(result);
55     return ERR_OK;
56 }
57 #ifdef WIFI_EDM_ENABLE
SetWifiProfile(MessageParcel & data)58 int32_t WifiManagerProxy::SetWifiProfile(MessageParcel &data)
59 {
60     EDMLOGD("WifiManagerProxy::SetWifiProfile");
61     auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
62     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_WIFI_PROFILE);
63     return proxy->HandleDevicePolicy(funcCode, data);
64 }
65 
AddOrRemoveWifiList(MessageParcel & data,FuncOperateType operateType,EdmInterfaceCode code)66 int32_t WifiManagerProxy::AddOrRemoveWifiList(MessageParcel &data, FuncOperateType operateType, EdmInterfaceCode code)
67 {
68     EDMLOGD("WifiManagerProxy::AddOrRemoveWifiList");
69     auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
70     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)operateType, code);
71     return proxy->HandleDevicePolicy(funcCode, data);
72 }
73 
GetWifiList(MessageParcel & data,std::vector<WifiId> & result,EdmInterfaceCode policyCode)74 int32_t WifiManagerProxy::GetWifiList(MessageParcel &data, std::vector<WifiId> &result, EdmInterfaceCode policyCode)
75 {
76     EDMLOGI("WifiManagerProxy::GetWifiList is %{public}d", policyCode);
77     auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
78     MessageParcel reply;
79     proxy->GetPolicy(policyCode, data, reply);
80     int32_t ret = ERR_INVALID_VALUE;
81     bool blRes = reply.ReadInt32(ret) && (ret == ERR_OK);
82     if (!blRes) {
83         EDMLOGD("WifiManagerProxy:GetWifiList fail. %{public}d", ret);
84         return ret;
85     }
86     uint32_t size = reply.ReadUint32();
87     if (size > EdmConstants::WIFI_LIST_MAX_SIZE) {
88         EDMLOGE("WifiManagerProxy:GetWifiList size=[%{public}u] is too large", size);
89         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
90     }
91     EDMLOGI("WifiManagerProxy:GetWifiList return size:%{public}u", size);
92     for (uint32_t i = 0; i < size; i++) {
93         WifiId wifiId;
94         if (!WifiId::Unmarshalling(reply, wifiId)) {
95             EDMLOGE("EnterpriseDeviceMgrProxy::GetEnterpriseInfo read parcel fail");
96             return EdmReturnErrCode::SYSTEM_ABNORMALLY;
97         }
98         result.emplace_back(wifiId);
99     }
100     return ERR_OK;
101 }
102 #endif
103 
SetWifiDisabled(MessageParcel & data)104 int32_t WifiManagerProxy::SetWifiDisabled(MessageParcel &data)
105 {
106     EDMLOGD("WifiManagerProxy::SetWifiDisabled.");
107     return EnterpriseDeviceMgrProxy::GetInstance()->SetPolicyDisabled(data, EdmInterfaceCode::DISABLE_WIFI);
108 }
109 
IsWifiDisabled(MessageParcel & data,bool & result)110 int32_t WifiManagerProxy::IsWifiDisabled(MessageParcel &data, bool &result)
111 {
112     EDMLOGD("WifiManagerProxy::IsWifiDisabled");
113     return EnterpriseDeviceMgrProxy::GetInstance()->IsPolicyDisabled(data, EdmInterfaceCode::DISABLE_WIFI, result);
114 }
115 
TurnOnWifi(MessageParcel & data)116 int32_t WifiManagerProxy::TurnOnWifi(MessageParcel &data)
117 {
118     EDMLOGI("WifiManagerProxy::TurnOnWifi");
119     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SWITCH_WIFI);
120     return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data);
121 }
122 
TurnOffWifi(MessageParcel & data)123 int32_t WifiManagerProxy::TurnOffWifi(MessageParcel &data)
124 {
125     EDMLOGI("WifiManagerProxy::TurnOffWifi");
126     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::REMOVE, EdmInterfaceCode::SWITCH_WIFI);
127     return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data);
128 }
129 } // namespace EDM
130 } // namespace OHOS
131