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