• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 #endif
66 
SetWifiDisabled(MessageParcel & data)67 int32_t WifiManagerProxy::SetWifiDisabled(MessageParcel &data)
68 {
69     EDMLOGD("WifiManagerProxy::SetWifiDisabled.");
70     return EnterpriseDeviceMgrProxy::GetInstance()->SetPolicyDisabled(data, EdmInterfaceCode::DISABLE_WIFI);
71 }
72 
IsWifiDisabled(MessageParcel & data,bool & result)73 int32_t WifiManagerProxy::IsWifiDisabled(MessageParcel &data, bool &result)
74 {
75     EDMLOGD("WifiManagerProxy::IsWifiDisabled");
76     return EnterpriseDeviceMgrProxy::GetInstance()->IsPolicyDisabled(data, EdmInterfaceCode::DISABLE_WIFI, result);
77 }
78 } // namespace EDM
79 } // namespace OHOS
80