1 /*
2 * Copyright (c) 2022-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 "device_info_proxy.h"
17
18 #include "edm_constants.h"
19 #include "edm_log.h"
20 #include "func_code.h"
21
22 namespace OHOS {
23 namespace EDM {
24 std::shared_ptr<DeviceInfoProxy> DeviceInfoProxy::instance_ = nullptr;
25 std::once_flag DeviceInfoProxy::flag_;
26 const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr";
27
DeviceInfoProxy()28 DeviceInfoProxy::DeviceInfoProxy() {}
29
~DeviceInfoProxy()30 DeviceInfoProxy::~DeviceInfoProxy() {}
31
GetDeviceInfoProxy()32 std::shared_ptr<DeviceInfoProxy> DeviceInfoProxy::GetDeviceInfoProxy()
33 {
34 std::call_once(flag_, []() {
35 if (instance_ == nullptr) {
36 instance_ = std::make_shared<DeviceInfoProxy>();
37 }
38 });
39 return instance_;
40 }
41
GetDeviceSerial(MessageParcel & data,std::string & info)42 int32_t DeviceInfoProxy::GetDeviceSerial(MessageParcel &data, std::string &info)
43 {
44 return GetDeviceInfo(data, EdmConstants::DeviceInfo::DEVICE_SERIAL, EdmInterfaceCode::GET_DEVICE_INFO, info);
45 }
46
GetDisplayVersion(MessageParcel & data,std::string & info)47 int32_t DeviceInfoProxy::GetDisplayVersion(MessageParcel &data, std::string &info)
48 {
49 return GetDeviceInfo(data, "", EdmInterfaceCode::GET_DISPLAY_VERSION, info);
50 }
51
GetDeviceName(MessageParcel & data,std::string & info)52 int32_t DeviceInfoProxy::GetDeviceName(MessageParcel &data, std::string &info)
53 {
54 return GetDeviceInfo(data, EdmConstants::DeviceInfo::DEVICE_NAME, EdmInterfaceCode::GET_DEVICE_INFO, info);
55 }
56
GetDeviceInfo(MessageParcel & data,const std::string & label,int policyCode,std::string & info)57 int32_t DeviceInfoProxy::GetDeviceInfo(MessageParcel &data, const std::string &label, int policyCode, std::string &info)
58 {
59 EDMLOGD("DeviceInfoProxy::GetDeviceInfo %{public}d", policyCode);
60 MessageParcel reply;
61 // The synchronous interface requires the label
62 if (!label.empty()) {
63 data.WriteString(label);
64 }
65 EnterpriseDeviceMgrProxy::GetInstance()->GetPolicy(policyCode, data, reply);
66 int32_t ret = ERR_INVALID_VALUE;
67 bool blRes = reply.ReadInt32(ret) && (ret == ERR_OK);
68 if (!blRes) {
69 EDMLOGW("EnterpriseDeviceMgrProxy:GetPolicy fail. %{public}d", ret);
70 return ret;
71 }
72 reply.ReadString(info);
73 return ERR_OK;
74 }
75 } // namespace EDM
76 } // namespace OHOS
77