• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 "device_info_proxy.h"
17 
18 #include "edm_log.h"
19 #include "func_code.h"
20 
21 namespace OHOS {
22 namespace EDM {
23 std::shared_ptr<DeviceInfoProxy> DeviceInfoProxy::instance_ = nullptr;
24 std::mutex DeviceInfoProxy::mutexLock_;
25 const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr";
26 
DeviceInfoProxy()27 DeviceInfoProxy::DeviceInfoProxy() {}
28 
~DeviceInfoProxy()29 DeviceInfoProxy::~DeviceInfoProxy() {}
30 
GetDeviceInfoProxy()31 std::shared_ptr<DeviceInfoProxy> DeviceInfoProxy::GetDeviceInfoProxy()
32 {
33     if (instance_ == nullptr) {
34         std::lock_guard<std::mutex> lock(mutexLock_);
35         if (instance_ == nullptr) {
36             std::shared_ptr<DeviceInfoProxy> temp = std::make_shared<DeviceInfoProxy>();
37             instance_ = temp;
38         }
39     }
40     return instance_;
41 }
42 
GetDeviceSerial(AppExecFwk::ElementName & admin,std::string & info)43 int32_t DeviceInfoProxy::GetDeviceSerial(AppExecFwk::ElementName &admin, std::string &info)
44 {
45     return GetDeviceInfo(admin, info, EdmInterfaceCode::GET_DEVICE_SERIAL);
46 }
47 
GetDisplayVersion(AppExecFwk::ElementName & admin,std::string & info)48 int32_t DeviceInfoProxy::GetDisplayVersion(AppExecFwk::ElementName &admin, std::string &info)
49 {
50     return GetDeviceInfo(admin, info, EdmInterfaceCode::GET_DISPLAY_VERSION);
51 }
52 
GetDeviceName(AppExecFwk::ElementName & admin,std::string & info)53 int32_t DeviceInfoProxy::GetDeviceName(AppExecFwk::ElementName &admin, std::string &info)
54 {
55     return GetDeviceInfo(admin, info, EdmInterfaceCode::GET_DEVICE_NAME);
56 }
57 
GetDeviceInfo(AppExecFwk::ElementName & admin,std::string & info,int policyCode)58 int32_t DeviceInfoProxy::GetDeviceInfo(AppExecFwk::ElementName &admin, std::string &info, int policyCode)
59 {
60     EDMLOGD("DeviceInfoProxy::GetDeviceInfo %{pubilc}d", policyCode);
61     auto proxy = EnterpriseDeviceMgrProxy::GetInstance();
62     if (proxy == nullptr) {
63         EDMLOGE("can not get EnterpriseDeviceMgrProxy");
64         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
65     }
66     MessageParcel data;
67     MessageParcel reply;
68     data.WriteInterfaceToken(DESCRIPTOR);
69     data.WriteInt32(WITHOUT_USERID);
70     data.WriteInt32(HAS_ADMIN);
71     data.WriteParcelable(&admin);
72     proxy->GetPolicy(policyCode, data, reply);
73     int32_t ret = ERR_INVALID_VALUE;
74     bool blRes = reply.ReadInt32(ret) && (ret == ERR_OK);
75     if (!blRes) {
76         EDMLOGW("EnterpriseDeviceMgrProxy:GetPolicy fail. %{public}d", ret);
77         return ret;
78     }
79     reply.ReadString(info);
80     return ERR_OK;
81 }
82 }  // namespace EDM
83 }  // namespace OHOS
84