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_mac_plugin.h"
17
18 #include "edm_constants.h"
19 #include "edm_ipc_interface_code.h"
20 #include "ethernet_client.h"
21 #include "interface_type.h"
22 #include "string_serializer.h"
23 #include "plugin_manager.h"
24
25 namespace OHOS {
26 namespace EDM {
27 const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(GetMacPlugin::GetPlugin());
28
InitPlugin(std::shared_ptr<IPluginTemplate<GetMacPlugin,std::string>> ptr)29 void GetMacPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<GetMacPlugin, std::string>> ptr)
30 {
31 EDMLOGI("GetMacPlugin InitPlugin...");
32 std::map<std::string, std::string> perms;
33 perms.insert(std::make_pair(EdmConstants::PERMISSION_TAG_VERSION_11,
34 "ohos.permission.ENTERPRISE_GET_NETWORK_INFO"));
35 perms.insert(std::make_pair(EdmConstants::PERMISSION_TAG_VERSION_12, "ohos.permission.ENTERPRISE_MANAGE_NETWORK"));
36 IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(perms,
37 IPlugin::PermissionType::SUPER_DEVICE_ADMIN, IPlugin::ApiType::PUBLIC);
38 ptr->InitAttribute(EdmInterfaceCode::GET_MAC, "get_mac", config, false);
39 ptr->SetSerializer(StringSerializer::GetInstance());
40 }
41
OnGetPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)42 ErrCode GetMacPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId)
43 {
44 EDMLOGI("GetMacPlugin OnGetPolicy.");
45 nmd::InterfaceConfigurationParcel config;
46 std::string networkInterface;
47 data.ReadString(networkInterface);
48 DelayedSingleton<NetManagerStandard::EthernetClient>::GetInstance()->GetInterfaceConfig(networkInterface, config);
49 reply.WriteInt32(ERR_OK);
50 reply.WriteString(config.hwAddr);
51 return ERR_OK;
52 }
53 } // namespace EDM
54 } // namespace OHOS
55