• 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::mutex WifiManagerProxy::mutexLock_;
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     if (instance_ == nullptr) {
35         std::lock_guard<std::mutex> lock(mutexLock_);
36         if (instance_ == nullptr) {
37             std::shared_ptr<WifiManagerProxy> temp = std::make_shared<WifiManagerProxy>();
38             instance_ = temp;
39         }
40     }
41     return instance_;
42 }
43 
IsWifiActive(const AppExecFwk::ElementName & admin,bool & result)44 int32_t WifiManagerProxy::IsWifiActive(const AppExecFwk::ElementName &admin, bool &result)
45 {
46     EDMLOGD("WifiManagerProxy::IsWifiActive");
47     auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
48     if (proxy == nullptr) {
49         EDMLOGE("can not get EnterpriseDeviceMgrProxy");
50         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
51     }
52     MessageParcel data;
53     MessageParcel reply;
54     data.WriteInterfaceToken(DESCRIPTOR);
55     data.WriteInt32(WITHOUT_USERID);
56     data.WriteInt32(HAS_ADMIN);
57     data.WriteParcelable(&admin);
58     proxy->GetPolicy(EdmInterfaceCode::IS_WIFI_ACTIVE, data, reply);
59     int32_t ret = ERR_INVALID_VALUE;
60     bool blRes = reply.ReadInt32(ret) && (ret == ERR_OK);
61     if (!blRes) {
62         EDMLOGW("EnterpriseDeviceMgrProxy:GetPolicy fail. %{public}d", ret);
63         return ret;
64     }
65     reply.ReadBool(result);
66     return ERR_OK;
67 }
68 
SetWifiProfile(const AppExecFwk::ElementName & admin,Wifi::WifiDeviceConfig & config)69 int32_t WifiManagerProxy::SetWifiProfile(const AppExecFwk::ElementName &admin, Wifi::WifiDeviceConfig &config)
70 {
71     EDMLOGD("WifiManagerProxy::SetWifiProfile");
72     auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
73     if (proxy == nullptr) {
74         EDMLOGE("can not get EnterpriseDeviceMgrProxy");
75         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
76     }
77     MessageParcel data;
78     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SET_WIFI_PROFILE);
79     data.WriteInterfaceToken(DESCRIPTOR);
80     data.WriteInt32(WITHOUT_USERID);
81     data.WriteParcelable(&admin);
82     MessageParcelUtils::WriteWifiDeviceConfig(config, data);
83     return proxy->HandleDevicePolicy(funcCode, data);
84 }
85 } // namespace EDM
86 } // namespace OHOS
87