1 /*
2 * Copyright (c) 2021 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 #include "device_info_proxy.h"
16
17 #include "beget_ext.h"
18 #include "idevice_info.h"
19 #include "parcel.h"
20 #include "string_ex.h"
21 #include "sysparam_errno.h"
22 #include "deviceinfoservice_ipc_interface_code.h"
23
24 namespace OHOS {
25 namespace device_info {
DeviceInfoSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int32_t DeviceInfoProxy::DeviceInfoSendRequest(uint32_t code,
27 MessageParcel &data, MessageParcel &reply, MessageOption &option)
28 {
29 #ifdef STARTUP_INIT_TEST
30 int ret = 0;
31 #else
32 int ret = SYSPARAM_SYSTEM_ERROR;
33 #endif
34 auto remote = Remote();
35 if (remote != nullptr) {
36 ret = remote->SendRequest(code, data, reply, option);
37 }
38 return ret;
39 }
40
GetUdid(std::string & result)41 int32_t DeviceInfoProxy::GetUdid(std::string& result)
42 {
43 MessageParcel data;
44 MessageParcel reply;
45 MessageOption option { MessageOption::TF_SYNC };
46 data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor());
47 int32_t ret = DeviceInfoSendRequest(static_cast<uint32_t> (DeviceInfoInterfaceCode::COMMAND_GET_UDID),
48 data, reply, option);
49 DINFO_CHECK(ret == ERR_NONE, return ret, "getUdid failed, error code is %d", ret);
50 result = Str16ToStr8(reply.ReadString16());
51 return ERR_OK;
52 }
53
GetSerialID(std::string & result)54 int32_t DeviceInfoProxy::GetSerialID(std::string& result)
55 {
56 MessageParcel data;
57 MessageParcel reply;
58 MessageOption option { MessageOption::TF_SYNC };
59
60 data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor());
61 int32_t ret = DeviceInfoSendRequest(static_cast<uint32_t> (DeviceInfoInterfaceCode::COMMAND_GET_SERIAL_ID),
62 data, reply, option);
63 DINFO_CHECK(ret == ERR_NONE, return ret, "GetSerial failed, error code is %d", ret);
64 result = Str16ToStr8(reply.ReadString16());
65 return ERR_OK;
66 }
67 } // namespace device_info
68 } // namespace OHOS
69