1 /*
2 * Copyright (c) 2023-2024 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 "is_wifi_active_plugin.h"
17
18 #include <system_ability_definition.h>
19
20 #include "bool_serializer.h"
21 #include "edm_constants.h"
22 #include "edm_ipc_interface_code.h"
23 #include "wifi_device.h"
24 #include "plugin_manager.h"
25
26 namespace OHOS {
27 namespace EDM {
28 const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(IsWifiActivePlugin::GetPlugin());
29
InitPlugin(std::shared_ptr<IPluginTemplate<IsWifiActivePlugin,bool>> ptr)30 void IsWifiActivePlugin::InitPlugin(std::shared_ptr<IPluginTemplate<IsWifiActivePlugin, bool>> ptr)
31 {
32 EDMLOGI("IsWifiActivePlugin InitPlugin...");
33 std::map<std::string, std::string> perms;
34 perms.insert(std::make_pair(EdmConstants::PERMISSION_TAG_VERSION_11, "ohos.permission.ENTERPRISE_SET_WIFI"));
35 perms.insert(std::make_pair(EdmConstants::PERMISSION_TAG_VERSION_12, "ohos.permission.ENTERPRISE_MANAGE_WIFI"));
36 IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(perms,
37 IPlugin::PermissionType::SUPER_DEVICE_ADMIN, IPlugin::ApiType::PUBLIC);
38 ptr->InitAttribute(EdmInterfaceCode::IS_WIFI_ACTIVE, "is_wifi_active", config, false);
39 ptr->SetSerializer(BoolSerializer::GetInstance());
40 }
41
OnGetPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)42 ErrCode IsWifiActivePlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
43 int32_t userId)
44 {
45 EDMLOGD("IsWifiActivePlugin OnGetPolicy.");
46 bool isActive = false;
47 ErrCode ret = Wifi::WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID)->IsWifiActive(isActive);
48 if (ret != ERR_OK) {
49 reply.WriteInt32(EdmReturnErrCode::SYSTEM_ABNORMALLY);
50 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
51 }
52 reply.WriteInt32(ERR_OK);
53 reply.WriteBool(isActive);
54 return ERR_OK;
55 }
56 } // namespace EDM
57 } // namespace OHOS
58