• 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 "get_all_network_interfaces_plugin.h"
17 
18 #include "array_string_serializer.h"
19 #include "edm_constants.h"
20 #include "edm_ipc_interface_code.h"
21 #include "ethernet_client.h"
22 #include "interface_type.h"
23 #include "iplugin_manager.h"
24 
25 namespace OHOS {
26 namespace EDM {
27 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetAllNetworkInterfacesPlugin::GetPlugin());
28 
InitPlugin(std::shared_ptr<IPluginTemplate<GetAllNetworkInterfacesPlugin,std::vector<std::string>>> ptr)29 void GetAllNetworkInterfacesPlugin::InitPlugin(
30     std::shared_ptr<IPluginTemplate<GetAllNetworkInterfacesPlugin, std::vector<std::string>>> ptr)
31 {
32     EDMLOGI("GetAllNetworkInterfacesPlugin InitPlugin...");
33     std::map<std::string, std::map<IPlugin::PermissionType, std::string>> tagPermissions;
34     std::map<IPlugin::PermissionType, std::string> typePermissionsForTag11;
35     std::map<IPlugin::PermissionType, std::string> typePermissionsForTag12;
36     typePermissionsForTag11.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
37         EdmPermission::PERMISSION_ENTERPRISE_GET_NETWORK_INFO);
38     typePermissionsForTag12.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN,
39         EdmPermission::PERMISSION_ENTERPRISE_MANAGE_NETWORK);
40     tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_11, typePermissionsForTag11);
41     tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_12, typePermissionsForTag12);
42 
43     IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(tagPermissions, IPlugin::ApiType::PUBLIC);
44     ptr->InitAttribute(EdmInterfaceCode::GET_NETWORK_INTERFACES, PolicyName::POLICY_GET_NETWORK_INTERFACES,
45         config, false);
46     ptr->SetSerializer(ArrayStringSerializer::GetInstance());
47 }
48 
OnGetPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)49 ErrCode GetAllNetworkInterfacesPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
50     int32_t userId)
51 {
52     EDMLOGI("GetAllNetworkInterfacesPlugin OnGetPolicy.");
53     std::vector<std::string> interfaces;
54     DelayedSingleton<NetManagerStandard::EthernetClient>::GetInstance()->GetAllActiveIfaces(interfaces);
55     reply.WriteInt32(ERR_OK);
56     reply.WriteStringVector(interfaces);
57     return ERR_OK;
58 }
59 } // namespace EDM
60 } // namespace OHOS
61