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_manager_ipc_interface_code.h"
17 #include "device_manager_notify.h"
18 #include "dm_anonymous.h"
19 #include "dm_constants.h"
20 #include "dm_device_info.h"
21 #include "dm_log.h"
22 #include "ipc_acl_profile_req.h"
23 #include "ipc_authenticate_device_req.h"
24 #include "ipc_bind_device_req.h"
25 #include "ipc_bind_target_req.h"
26 #include "ipc_check_access_control.h"
27 #include "ipc_cmd_register.h"
28 #include "ipc_common_param_req.h"
29 #include "ipc_create_pin_holder_req.h"
30 #include "ipc_destroy_pin_holder_req.h"
31 #include "ipc_def.h"
32 #include "ipc_export_auth_code_rsp.h"
33 #include "ipc_generate_encrypted_uuid_req.h"
34 #include "ipc_get_device_info_rsp.h"
35 #include "ipc_get_device_screen_status_req.h"
36 #include "ipc_get_device_screen_status_rsp.h"
37 #include "ipc_get_encrypted_uuid_req.h"
38 #include "ipc_get_info_by_network_rsp.h"
39 #include "ipc_get_info_by_network_req.h"
40 #include "ipc_get_local_device_info_rsp.h"
41 #include "ipc_get_trustdevice_req.h"
42 #include "ipc_get_trustdevice_rsp.h"
43 #include "ipc_import_auth_code_req.h"
44 #include "ipc_notify_event_req.h"
45 #include "ipc_register_listener_req.h"
46 #include "ipc_req.h"
47 #include "ipc_rsp.h"
48 #include "ipc_set_credential_req.h"
49 #include "ipc_set_credential_rsp.h"
50 #include "ipc_set_useroperation_req.h"
51 #include "ipc_start_discovery_req.h"
52 #include "ipc_start_discover_req.h"
53 #include "ipc_stop_discovery_req.h"
54 #include "ipc_permission_req.h"
55 #include "ipc_publish_req.h"
56 #include "ipc_unbind_device_req.h"
57 #include "ipc_unpublish_req.h"
58 #include "ipc_unauthenticate_device_req.h"
59 #include "securec.h"
60 namespace OHOS { class IRemoteObject; }
61 
62 namespace OHOS {
63 namespace DistributedHardware {
64 namespace {
65 const int32_t DM_MAX_TRUST_DEVICE_NUM = 200;
66 }
67 
DecodeDmDeviceInfo(MessageParcel & parcel,DmDeviceInfo & devInfo)68 void DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo)
69 {
70     std::string deviceIdStr = parcel.ReadString();
71     if (strcpy_s(devInfo.deviceId, deviceIdStr.size() + 1, deviceIdStr.c_str()) != DM_OK) {
72         LOGE("strcpy_s deviceId failed!");
73     }
74     std::string deviceNameStr = parcel.ReadString();
75     if (strcpy_s(devInfo.deviceName, deviceNameStr.size() + 1, deviceNameStr.c_str()) != DM_OK) {
76         LOGE("strcpy_s deviceName failed!");
77     }
78     devInfo.deviceTypeId = parcel.ReadUint16();
79     std::string networkIdStr = parcel.ReadString();
80     if (strcpy_s(devInfo.networkId, networkIdStr.size() + 1, networkIdStr.c_str()) != DM_OK) {
81         LOGE("strcpy_s networkId failed!");
82     }
83     devInfo.range = parcel.ReadInt32();
84     devInfo.networkType = parcel.ReadInt32();
85     devInfo.authForm = static_cast<DmAuthForm>(parcel.ReadInt32());
86     devInfo.extraData = parcel.ReadString();
87 }
88 
DecodeDmDeviceBasicInfo(MessageParcel & parcel,DmDeviceBasicInfo & devInfo)89 void DecodeDmDeviceBasicInfo(MessageParcel &parcel, DmDeviceBasicInfo &devInfo)
90 {
91     std::string deviceIdStr = parcel.ReadString();
92     if (strcpy_s(devInfo.deviceId, deviceIdStr.size() + 1, deviceIdStr.c_str()) != DM_OK) {
93         LOGE("strcpy_s deviceId failed!");
94     }
95     std::string deviceNameStr = parcel.ReadString();
96     if (strcpy_s(devInfo.deviceName, deviceNameStr.size() + 1, deviceNameStr.c_str()) != DM_OK) {
97         LOGE("strcpy_s deviceName failed!");
98     }
99     devInfo.deviceTypeId = parcel.ReadUint16();
100     std::string networkIdStr = parcel.ReadString();
101     if (strcpy_s(devInfo.networkId, networkIdStr.size() + 1, networkIdStr.c_str()) != DM_OK) {
102         LOGE("strcpy_s networkId failed!");
103     }
104 }
105 
EncodePeerTargetId(const PeerTargetId & targetId,MessageParcel & parcel)106 bool EncodePeerTargetId(const PeerTargetId &targetId, MessageParcel &parcel)
107 {
108     bool bRet = true;
109     bRet = (bRet && parcel.WriteString(targetId.deviceId));
110     bRet = (bRet && parcel.WriteString(targetId.brMac));
111     bRet = (bRet && parcel.WriteString(targetId.bleMac));
112     bRet = (bRet && parcel.WriteString(targetId.wifiIp));
113     bRet = (bRet && parcel.WriteUint16(targetId.wifiPort));
114     return bRet;
115 }
116 
DecodePeerTargetId(MessageParcel & parcel,PeerTargetId & targetId)117 void DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targetId)
118 {
119     targetId.deviceId = parcel.ReadString();
120     targetId.brMac = parcel.ReadString();
121     targetId.bleMac = parcel.ReadString();
122     targetId.wifiIp = parcel.ReadString();
123     targetId.wifiPort = parcel.ReadUint16();
124 }
125 
EncodeDmAccessCaller(const DmAccessCaller & caller,MessageParcel & parcel)126 bool EncodeDmAccessCaller(const DmAccessCaller &caller, MessageParcel &parcel)
127 {
128     bool bRet = true;
129     bRet = (bRet && parcel.WriteString(caller.accountId));
130     bRet = (bRet && parcel.WriteString(caller.pkgName));
131     bRet = (bRet && parcel.WriteString(caller.networkId));
132     bRet = (bRet && parcel.WriteInt32(caller.userId));
133     bRet = (bRet && parcel.WriteUint64(caller.tokenId));
134     bRet = (bRet && parcel.WriteString(caller.extra));
135     return bRet;
136 }
137 
EncodeDmAccessCallee(const DmAccessCallee & callee,MessageParcel & parcel)138 bool EncodeDmAccessCallee(const DmAccessCallee &callee, MessageParcel &parcel)
139 {
140     bool bRet = true;
141     bRet = (bRet && parcel.WriteString(callee.accountId));
142     bRet = (bRet && parcel.WriteString(callee.networkId));
143     bRet = (bRet && parcel.WriteString(callee.peerId));
144     bRet = (bRet && parcel.WriteInt32(callee.userId));
145     bRet = (bRet && parcel.WriteString(callee.extra));
146     return bRet;
147 }
148 
ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)149 ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
150 {
151     std::shared_ptr<IpcRegisterListenerReq> pReq = std::static_pointer_cast<IpcRegisterListenerReq>(pBaseReq);
152     std::string pkgName = pReq->GetPkgName();
153     sptr<IRemoteObject> listener = pReq->GetListener();
154     if (!data.WriteString(pkgName)) {
155         LOGE("write pkgName failed");
156         return ERR_DM_IPC_WRITE_FAILED;
157     }
158     if (!data.WriteRemoteObject(listener)) {
159         LOGE("write listener failed");
160         return ERR_DM_IPC_WRITE_FAILED;
161     }
162     return DM_OK;
163 }
164 
ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)165 ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
166 {
167     if (pBaseRsp == nullptr) {
168         LOGE("pBaseRsp is null");
169         return ERR_DM_FAILED;
170     }
171     pBaseRsp->SetErrCode(reply.ReadInt32());
172     return DM_OK;
173 }
174 
ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)175 ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
176 {
177     std::string pkgName = pBaseReq->GetPkgName();
178     if (!data.WriteString(pkgName)) {
179         LOGE("write papam failed");
180         return ERR_DM_IPC_WRITE_FAILED;
181     }
182     return DM_OK;
183 }
184 
ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)185 ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
186 {
187     pBaseRsp->SetErrCode(reply.ReadInt32());
188     return DM_OK;
189 }
190 
ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)191 ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
192 {
193     std::shared_ptr<IpcGetTrustDeviceReq> pReq = std::static_pointer_cast<IpcGetTrustDeviceReq>(pBaseReq);
194     std::string pkgName = pReq->GetPkgName();
195     std::string extra = pReq->GetExtra();
196     bool isRefresh = pReq->GetRefresh();
197     if (!data.WriteString(pkgName)) {
198         LOGE("write pkg failed");
199         return ERR_DM_IPC_WRITE_FAILED;
200     }
201     if (!data.WriteString(extra)) {
202         LOGE("write extra failed");
203         return ERR_DM_IPC_WRITE_FAILED;
204     }
205     if (!data.WriteBool(isRefresh)) {
206         LOGE("write isRefresh failed");
207         return ERR_DM_IPC_WRITE_FAILED;
208     }
209     return DM_OK;
210 }
211 
ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)212 ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
213 {
214     std::shared_ptr<IpcGetTrustDeviceRsp> pRsp = std::static_pointer_cast<IpcGetTrustDeviceRsp>(pBaseRsp);
215     int32_t deviceNum = reply.ReadInt32();
216     if (deviceNum > 0 && deviceNum <= DM_MAX_TRUST_DEVICE_NUM) {
217         std::vector<DmDeviceInfo> deviceInfoVec;
218         for (int32_t i = 0; i < deviceNum; ++i) {
219             DmDeviceInfo deviceInfo;
220             DecodeDmDeviceInfo(reply, deviceInfo);
221             deviceInfoVec.emplace_back(deviceInfo);
222         }
223         pRsp->SetDeviceVec(deviceInfoVec);
224     }
225     pRsp->SetErrCode(reply.ReadInt32());
226     return DM_OK;
227 }
228 
ON_IPC_SET_REQUEST(GET_DEVICE_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)229 ON_IPC_SET_REQUEST(GET_DEVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
230 {
231     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
232     std::string networkId = pReq->GetNetWorkId();
233     if (!data.WriteString(networkId)) {
234         return ERR_DM_IPC_WRITE_FAILED;
235     }
236     return DM_OK;
237 }
238 
ON_IPC_READ_RESPONSE(GET_DEVICE_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)239 ON_IPC_READ_RESPONSE(GET_DEVICE_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
240 {
241     std::shared_ptr<IpcGetDeviceInfoRsp> pRsp = std::static_pointer_cast<IpcGetDeviceInfoRsp>(pBaseRsp);
242     DmDeviceInfo deviceInfo;
243     DecodeDmDeviceInfo(reply, deviceInfo);
244     pRsp->SetDeviceInfo(deviceInfo);
245     pRsp->SetErrCode(reply.ReadInt32());
246     return DM_OK;
247 }
248 
ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)249 ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
250 {
251     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
252     std::string pkgName = pReq->GetPkgName();
253     if (!data.WriteString(pkgName)) {
254         return ERR_DM_IPC_WRITE_FAILED;
255     }
256     return DM_OK;
257 }
258 
ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)259 ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
260 {
261     std::shared_ptr<IpcGetLocalDeviceInfoRsp> pRsp = std::static_pointer_cast<IpcGetLocalDeviceInfoRsp>(pBaseRsp);
262     DmDeviceInfo localDeviceInfo;
263     DecodeDmDeviceInfo(reply, localDeviceInfo);
264     pRsp->SetLocalDeviceInfo(localDeviceInfo);
265     pRsp->SetErrCode(reply.ReadInt32());
266     return DM_OK;
267 }
268 
ON_IPC_SET_REQUEST(GET_UDID_BY_NETWORK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)269 ON_IPC_SET_REQUEST(GET_UDID_BY_NETWORK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
270 {
271     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
272     std::string pkgName = pReq->GetPkgName();
273     std::string netWorkId = pReq->GetNetWorkId();
274     if (!data.WriteString(pkgName)) {
275         return ERR_DM_IPC_WRITE_FAILED;
276     }
277     if (!data.WriteString(netWorkId)) {
278         return ERR_DM_IPC_WRITE_FAILED;
279     }
280     return DM_OK;
281 }
282 
ON_IPC_READ_RESPONSE(GET_UDID_BY_NETWORK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)283 ON_IPC_READ_RESPONSE(GET_UDID_BY_NETWORK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
284 {
285     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
286     pRsp->SetErrCode(reply.ReadInt32());
287     pRsp->SetUdid(reply.ReadString());
288     return DM_OK;
289 }
290 
ON_IPC_SET_REQUEST(GET_UUID_BY_NETWORK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)291 ON_IPC_SET_REQUEST(GET_UUID_BY_NETWORK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
292 {
293     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
294     std::string pkgName = pReq->GetPkgName();
295     std::string netWorkId = pReq->GetNetWorkId();
296     if (!data.WriteString(pkgName)) {
297         return ERR_DM_IPC_WRITE_FAILED;
298     }
299     if (!data.WriteString(netWorkId)) {
300         return ERR_DM_IPC_WRITE_FAILED;
301     }
302     return DM_OK;
303 }
304 
ON_IPC_READ_RESPONSE(GET_UUID_BY_NETWORK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)305 ON_IPC_READ_RESPONSE(GET_UUID_BY_NETWORK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
306 {
307     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
308     pRsp->SetErrCode(reply.ReadInt32());
309     pRsp->SetUuid(reply.ReadString());
310     return DM_OK;
311 }
312 
ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)313 ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
314 {
315     std::shared_ptr<IpcStartDiscoveryReq> pReq = std::static_pointer_cast<IpcStartDiscoveryReq>(pBaseReq);
316     std::string pkgName = pReq->GetPkgName();
317     std::string extra = pReq->GetExtra();
318     const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo();
319     if (!data.WriteString(pkgName)) {
320         LOGE("write pkgName failed");
321         return ERR_DM_IPC_WRITE_FAILED;
322     }
323     if (!data.WriteString(extra)) {
324         LOGE("write extra failed");
325         return ERR_DM_IPC_WRITE_FAILED;
326     }
327     if (!data.WriteRawData(&dmSubscribeInfo, sizeof(DmSubscribeInfo))) {
328         LOGE("write subscribe info failed");
329         return ERR_DM_IPC_WRITE_FAILED;
330     }
331     return DM_OK;
332 }
333 
ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)334 ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
335 {
336     pBaseRsp->SetErrCode(reply.ReadInt32());
337     return DM_OK;
338 }
339 
ON_IPC_SET_REQUEST(START_DEVICE_DISCOVERY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)340 ON_IPC_SET_REQUEST(START_DEVICE_DISCOVERY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
341 {
342     std::shared_ptr<IpcStartDevDiscoveryByIdReq> pReq = std::static_pointer_cast<IpcStartDevDiscoveryByIdReq>(pBaseReq);
343     std::string pkgName = pReq->GetPkgName();
344     std::string filterOption = pReq->GetFilterOption();
345     const uint16_t subscribeId = pReq->GetSubscribeId();
346     if (!data.WriteString(pkgName)) {
347         LOGE("write pkgName failed");
348         return ERR_DM_IPC_WRITE_FAILED;
349     }
350     if (!data.WriteString(filterOption)) {
351         LOGE("write filterOption failed");
352         return ERR_DM_IPC_WRITE_FAILED;
353     }
354     if (!data.WriteUint16(subscribeId)) {
355         LOGE("write subscribe id failed");
356         return ERR_DM_IPC_WRITE_FAILED;
357     }
358     return DM_OK;
359 }
360 
ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVERY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)361 ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVERY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
362 {
363     pBaseRsp->SetErrCode(reply.ReadInt32());
364     return DM_OK;
365 }
366 
ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)367 ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
368 {
369     std::shared_ptr<IpcStopDiscoveryReq> pReq = std::static_pointer_cast<IpcStopDiscoveryReq>(pBaseReq);
370     std::string pkgName = pReq->GetPkgName();
371     uint16_t subscribeId = pReq->GetSubscribeId();
372     if (!data.WriteString(pkgName)) {
373         LOGE("write pkgName failed");
374         return ERR_DM_IPC_WRITE_FAILED;
375     }
376     if (!data.WriteInt16((int16_t)subscribeId)) {
377         LOGE("write subscribeId failed");
378         return ERR_DM_IPC_WRITE_FAILED;
379     }
380     return DM_OK;
381 }
382 
ON_IPC_READ_RESPONSE(STOP_DEVICE_DISCOVER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)383 ON_IPC_READ_RESPONSE(STOP_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
384 {
385     if (pBaseRsp == nullptr) {
386         LOGE("pBaseRsp is null");
387         return ERR_DM_FAILED;
388     }
389     pBaseRsp->SetErrCode(reply.ReadInt32());
390     return DM_OK;
391 }
392 
ON_IPC_SET_REQUEST(PUBLISH_DEVICE_DISCOVER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)393 ON_IPC_SET_REQUEST(PUBLISH_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
394 {
395     std::shared_ptr<IpcPublishReq> pReq = std::static_pointer_cast<IpcPublishReq>(pBaseReq);
396     std::string pkgName = pReq->GetPkgName();
397     const DmPublishInfo dmPublishInfo = pReq->GetPublishInfo();
398     if (!data.WriteString(pkgName)) {
399         LOGE("write pkgName failed");
400         return ERR_DM_IPC_WRITE_FAILED;
401     }
402     if (!data.WriteRawData(&dmPublishInfo, sizeof(DmPublishInfo))) {
403         LOGE("write dmPublishInfo failed");
404         return ERR_DM_IPC_WRITE_FAILED;
405     }
406     return DM_OK;
407 }
408 
ON_IPC_READ_RESPONSE(PUBLISH_DEVICE_DISCOVER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)409 ON_IPC_READ_RESPONSE(PUBLISH_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
410 {
411     pBaseRsp->SetErrCode(reply.ReadInt32());
412     return DM_OK;
413 }
414 
ON_IPC_SET_REQUEST(UNPUBLISH_DEVICE_DISCOVER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)415 ON_IPC_SET_REQUEST(UNPUBLISH_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
416 {
417     std::shared_ptr<IpcUnPublishReq> pReq = std::static_pointer_cast<IpcUnPublishReq>(pBaseReq);
418     std::string pkgName = pReq->GetPkgName();
419     int32_t publishId = pReq->GetPublishId();
420     if (!data.WriteString(pkgName)) {
421         LOGE("write pkgName failed");
422         return ERR_DM_IPC_WRITE_FAILED;
423     }
424     if (!data.WriteInt32(publishId)) {
425         LOGE("write publishId failed");
426         return ERR_DM_IPC_WRITE_FAILED;
427     }
428     return DM_OK;
429 }
430 
ON_IPC_READ_RESPONSE(UNPUBLISH_DEVICE_DISCOVER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)431 ON_IPC_READ_RESPONSE(UNPUBLISH_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
432 {
433     if (pBaseRsp == nullptr) {
434         LOGE("pBaseRsp is null");
435         return ERR_DM_FAILED;
436     }
437     pBaseRsp->SetErrCode(reply.ReadInt32());
438     return DM_OK;
439 }
440 
ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)441 ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
442 {
443     std::shared_ptr<IpcAuthenticateDeviceReq> pReq = std::static_pointer_cast<IpcAuthenticateDeviceReq>(pBaseReq);
444     std::string pkgName = pReq->GetPkgName();
445     std::string extra = pReq->GetExtra();
446     int32_t authType = pReq->GetAuthType();
447     DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
448     std::string deviceId = deviceInfo.deviceId;
449 
450     if (!data.WriteString(pkgName)) {
451         LOGE("write pkgName failed");
452         return ERR_DM_IPC_WRITE_FAILED;
453     }
454     if (!data.WriteString(extra)) {
455         LOGE("write extra failed");
456         return ERR_DM_IPC_WRITE_FAILED;
457     }
458     if (!data.WriteString(deviceId)) {
459         LOGE("write deviceId failed");
460         return ERR_DM_IPC_WRITE_FAILED;
461     }
462     if (!data.WriteInt32(authType)) {
463         LOGE("write pkgName failed");
464         return ERR_DM_IPC_WRITE_FAILED;
465     }
466     return DM_OK;
467 }
468 
ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)469 ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
470 {
471     if (pBaseRsp == nullptr) {
472         LOGE("pBaseRsp is null");
473         return ERR_DM_FAILED;
474     }
475     pBaseRsp->SetErrCode(reply.ReadInt32());
476     return DM_OK;
477 }
478 
ON_IPC_SET_REQUEST(UNAUTHENTICATE_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)479 ON_IPC_SET_REQUEST(UNAUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
480 {
481     std::shared_ptr<IpcUnAuthenticateDeviceReq> pReq = std::static_pointer_cast<IpcUnAuthenticateDeviceReq>(pBaseReq);
482     std::string pkgName = pReq->GetPkgName();
483     DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
484     std::string networkId = deviceInfo.networkId;
485     if (!data.WriteString(pkgName)) {
486         LOGE("write pkgName failed");
487         return ERR_DM_IPC_WRITE_FAILED;
488     }
489     if (!data.WriteString(networkId)) {
490         LOGE("write extra failed");
491         return ERR_DM_IPC_WRITE_FAILED;
492     }
493     return DM_OK;
494 }
495 
ON_IPC_READ_RESPONSE(UNAUTHENTICATE_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)496 ON_IPC_READ_RESPONSE(UNAUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
497 {
498     pBaseRsp->SetErrCode(reply.ReadInt32());
499     return DM_OK;
500 }
501 
ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)502 ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
503 {
504     std::shared_ptr<IpcGetOperationReq> pReq = std::static_pointer_cast<IpcGetOperationReq>(pBaseReq);
505     std::string pkgName = pReq->GetPkgName();
506     int32_t action = pReq->GetOperation();
507     std::string params = pReq->GetParams();
508 
509     if (!data.WriteString(pkgName)) {
510         LOGE("write pkgName failed");
511         return ERR_DM_IPC_WRITE_FAILED;
512     }
513     if (!data.WriteInt32(action)) {
514         LOGE("write action failed");
515         return ERR_DM_IPC_WRITE_FAILED;
516     }
517     if (!data.WriteString(params)) {
518         LOGE("write params failed");
519         return ERR_DM_IPC_WRITE_FAILED;
520     }
521 
522     return DM_OK;
523 }
524 
ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)525 ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
526 {
527     pBaseRsp->SetErrCode(reply.ReadInt32());
528     return DM_OK;
529 }
530 
ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY,MessageParcel & data,MessageParcel & reply)531 ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply)
532 {
533     std::string pkgName = data.ReadString();
534     DmDeviceState deviceState = static_cast<DmDeviceState>(data.ReadInt32());
535     DmDeviceInfo dmDeviceInfo;
536     DecodeDmDeviceInfo(data, dmDeviceInfo);
537 
538     DmDeviceBasicInfo dmDeviceBasicInfo;
539     size_t deviceBasicSize = sizeof(DmDeviceBasicInfo);
540     void *deviceBasicInfo = static_cast<void *>(const_cast<void *>(data.ReadRawData(deviceBasicSize)));
541     if (deviceBasicInfo != nullptr &&
542         memcpy_s(&dmDeviceBasicInfo, deviceBasicSize, deviceBasicInfo, deviceBasicSize) != 0) {
543         reply.WriteInt32(ERR_DM_IPC_COPY_FAILED);
544         return DM_OK;
545     }
546     switch (deviceState) {
547         case DEVICE_STATE_ONLINE:
548             DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceInfo);
549             DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceBasicInfo);
550             break;
551         case DEVICE_STATE_OFFLINE:
552             DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceInfo);
553             DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceBasicInfo);
554             break;
555         case DEVICE_INFO_CHANGED:
556             DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceInfo);
557             DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceBasicInfo);
558             break;
559         case DEVICE_INFO_READY:
560             DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceInfo);
561             DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceBasicInfo);
562             break;
563         default:
564             LOGE("unknown device state:%{public}d", deviceState);
565             break;
566     }
567     reply.WriteInt32(DM_OK);
568     return DM_OK;
569 }
570 
ON_IPC_CMD(SERVER_DEVICE_FOUND,MessageParcel & data,MessageParcel & reply)571 ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply)
572 {
573     std::string pkgName = data.ReadString();
574     int16_t subscribeId = data.ReadInt16();
575     DmDeviceInfo dmDeviceInfo;
576     DecodeDmDeviceInfo(data, dmDeviceInfo);
577     DmDeviceBasicInfo devBasicInfo;
578     DecodeDmDeviceBasicInfo(data, devBasicInfo);
579     DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceInfo);
580     DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, devBasicInfo);
581     reply.WriteInt32(DM_OK);
582     return DM_OK;
583 }
584 
ON_IPC_CMD(SERVER_DEVICE_DISCOVERY,MessageParcel & data,MessageParcel & reply)585 ON_IPC_CMD(SERVER_DEVICE_DISCOVERY, MessageParcel &data, MessageParcel &reply)
586 {
587     std::string pkgName = data.ReadString();
588     int16_t subscribeId = data.ReadInt16();
589     DmDeviceBasicInfo dmDeviceBasicInfo;
590     size_t deviceSize = sizeof(DmDeviceBasicInfo);
591     void *deviceInfo = static_cast<void *>(const_cast<void *>(data.ReadRawData(deviceSize)));
592     if (deviceInfo != nullptr && memcpy_s(&dmDeviceBasicInfo, deviceSize, deviceInfo, deviceSize) != 0) {
593         reply.WriteInt32(ERR_DM_IPC_COPY_FAILED);
594         return ERR_DM_IPC_COPY_FAILED;
595     }
596     DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceBasicInfo);
597     reply.WriteInt32(DM_OK);
598     return DM_OK;
599 }
600 
ON_IPC_CMD(SERVER_DISCOVER_FINISH,MessageParcel & data,MessageParcel & reply)601 ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply)
602 {
603     std::string pkgName = data.ReadString();
604     int16_t subscribeId = data.ReadInt16();
605     int32_t failedReason = data.ReadInt32();
606 
607     if (failedReason == DM_OK) {
608         DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId);
609     } else {
610         DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason);
611     }
612     reply.WriteInt32(DM_OK);
613     return DM_OK;
614 }
615 
ON_IPC_CMD(SERVER_PUBLISH_FINISH,MessageParcel & data,MessageParcel & reply)616 ON_IPC_CMD(SERVER_PUBLISH_FINISH, MessageParcel &data, MessageParcel &reply)
617 {
618     std::string pkgName = data.ReadString();
619     int32_t publishId = data.ReadInt32();
620     int32_t publishResult = data.ReadInt32();
621 
622     DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, publishResult);
623     if (!reply.WriteInt32(DM_OK)) {
624         LOGE("write return failed");
625         return ERR_DM_IPC_WRITE_FAILED;
626     }
627     return DM_OK;
628 }
629 
ON_IPC_CMD(SERVER_AUTH_RESULT,MessageParcel & data,MessageParcel & reply)630 ON_IPC_CMD(SERVER_AUTH_RESULT, MessageParcel &data, MessageParcel &reply)
631 {
632     std::string pkgName = data.ReadString();
633     std::string deviceId = data.ReadString();
634     std::string token = data.ReadString();
635     int32_t status = data.ReadInt32();
636     int32_t reason = data.ReadInt32();
637     DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, (uint32_t)status, reason);
638     reply.WriteInt32(DM_OK);
639     return DM_OK;
640 }
641 
ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY,MessageParcel & data,MessageParcel & reply)642 ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, MessageParcel &data, MessageParcel &reply)
643 {
644     std::string packagename = data.ReadString();
645     std::string paramJson = data.ReadString();
646     DeviceManagerNotify::GetInstance().OnUiCall(packagename, paramJson);
647     if (!reply.WriteInt32(DM_OK)) {
648         LOGE("write return failed");
649         return ERR_DM_IPC_WRITE_FAILED;
650     }
651     return DM_OK;
652 }
653 
ON_IPC_SET_REQUEST(REQUEST_CREDENTIAL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)654 ON_IPC_SET_REQUEST(REQUEST_CREDENTIAL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
655 {
656     std::shared_ptr<IpcSetCredentialReq> pReq = std::static_pointer_cast<IpcSetCredentialReq>(pBaseReq);
657     std::string pkgName = pReq->GetPkgName();
658     std::string requestJsonStr = pReq->GetCredentialParam();
659 
660     if (!data.WriteString(pkgName)) {
661         LOGE("write pkg failed.");
662         return ERR_DM_IPC_WRITE_FAILED;
663     }
664     if (!data.WriteString(requestJsonStr)) {
665         LOGE("write requestJsonStr failed.");
666         return ERR_DM_IPC_WRITE_FAILED;
667     }
668     return DM_OK;
669 }
670 
ON_IPC_READ_RESPONSE(REQUEST_CREDENTIAL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)671 ON_IPC_READ_RESPONSE(REQUEST_CREDENTIAL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
672 {
673     std::shared_ptr<IpcSetCredentialRsp> pRsp = std::static_pointer_cast<IpcSetCredentialRsp>(pBaseRsp);
674     pRsp->SetErrCode(reply.ReadInt32());
675     if (pRsp->GetErrCode() == DM_OK) {
676         std::string returnJsonStr = reply.ReadString();
677         pRsp->SetCredentialResult(returnJsonStr);
678     }
679     return DM_OK;
680 }
681 
ON_IPC_SET_REQUEST(SERVER_GET_DMFA_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)682 ON_IPC_SET_REQUEST(SERVER_GET_DMFA_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
683 {
684     std::shared_ptr<IpcSetCredentialReq> pReq = std::static_pointer_cast<IpcSetCredentialReq>(pBaseReq);
685     std::string pkgName = pReq->GetPkgName();
686     std::string reqJsonStr = pReq->GetCredentialParam();
687     if (!data.WriteString(pkgName)) {
688         LOGE("write pkg failed.");
689         return ERR_DM_IPC_WRITE_FAILED;
690     }
691     if (!data.WriteString(reqJsonStr)) {
692         LOGE("write returnJsonStr failed.");
693         return ERR_DM_IPC_WRITE_FAILED;
694     }
695     return DM_OK;
696 }
697 
ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)698 ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
699 {
700     std::shared_ptr<IpcSetCredentialRsp> pRsp = std::static_pointer_cast<IpcSetCredentialRsp>(pBaseRsp);
701     pRsp->SetErrCode(reply.ReadInt32());
702     if (pRsp->GetErrCode() == DM_OK) {
703         std::string returnJsonStr = reply.ReadString();
704         pRsp->SetCredentialResult(returnJsonStr);
705     }
706     return DM_OK;
707 }
708 
ON_IPC_SET_REQUEST(IMPORT_CREDENTIAL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)709 ON_IPC_SET_REQUEST(IMPORT_CREDENTIAL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
710 {
711     std::shared_ptr<IpcSetCredentialReq> pReq = std::static_pointer_cast<IpcSetCredentialReq>(pBaseReq);
712     std::string pkgName = pReq->GetPkgName();
713     std::string credentialInfo = pReq->GetCredentialParam();
714     if (!data.WriteString(pkgName)) {
715         LOGE("write pkg failed.");
716         return ERR_DM_IPC_WRITE_FAILED;
717     }
718     if (!data.WriteString(credentialInfo)) {
719         LOGE("write credentialInfo failed.");
720         return ERR_DM_IPC_WRITE_FAILED;
721     }
722     return DM_OK;
723 }
724 
ON_IPC_READ_RESPONSE(IMPORT_CREDENTIAL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)725 ON_IPC_READ_RESPONSE(IMPORT_CREDENTIAL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
726 {
727     std::string outParaStr = reply.ReadString();
728     std::map<std::string, std::string> outputResult;
729     ParseMapFromJsonString(outParaStr, outputResult);
730     if (outputResult[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
731         pBaseRsp->SetErrCode(reply.ReadInt32());
732     }
733     if (outputResult[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
734         std::shared_ptr<IpcSetCredentialRsp> pRsp = std::static_pointer_cast<IpcSetCredentialRsp>(pBaseRsp);
735         pRsp->SetErrCode(reply.ReadInt32());
736         if (pRsp->GetErrCode() == DM_OK) {
737             pRsp->SetCredentialResult(outputResult[DM_CREDENTIAL_RETURNJSONSTR]);
738         }
739     }
740     return DM_OK;
741 }
742 
ON_IPC_SET_REQUEST(DELETE_CREDENTIAL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)743 ON_IPC_SET_REQUEST(DELETE_CREDENTIAL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
744 {
745     std::shared_ptr<IpcSetCredentialReq> pReq = std::static_pointer_cast<IpcSetCredentialReq>(pBaseReq);
746     std::string pkgName = pReq->GetPkgName();
747     std::string deleteInfo = pReq->GetCredentialParam();
748 
749     if (!data.WriteString(pkgName)) {
750         LOGE("write pkg failed.");
751         return ERR_DM_IPC_WRITE_FAILED;
752     }
753     if (!data.WriteString(deleteInfo)) {
754         LOGE("write deleteInfo failed.");
755         return ERR_DM_IPC_WRITE_FAILED;
756     }
757     return DM_OK;
758 }
759 
ON_IPC_READ_RESPONSE(DELETE_CREDENTIAL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)760 ON_IPC_READ_RESPONSE(DELETE_CREDENTIAL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
761 {
762     std::string outParaStr = reply.ReadString();
763     std::map<std::string, std::string> outputResult;
764     ParseMapFromJsonString(outParaStr, outputResult);
765     if (outputResult[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
766         pBaseRsp->SetErrCode(reply.ReadInt32());
767     }
768     if (outputResult[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
769         std::shared_ptr<IpcSetCredentialRsp> pRsp = std::static_pointer_cast<IpcSetCredentialRsp>(pBaseRsp);
770         pRsp->SetErrCode(reply.ReadInt32());
771         if (pRsp->GetErrCode() == DM_OK) {
772             pRsp->SetCredentialResult(outputResult[DM_CREDENTIAL_RETURNJSONSTR]);
773         }
774     }
775     return DM_OK;
776 }
777 
ON_IPC_SET_REQUEST(REGISTER_CREDENTIAL_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)778 ON_IPC_SET_REQUEST(REGISTER_CREDENTIAL_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
779 {
780     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
781     std::string pkgName = pReq->GetPkgName();
782 
783     if (!data.WriteString(pkgName)) {
784         LOGE("write pkgName failed");
785         return ERR_DM_IPC_WRITE_FAILED;
786     }
787 
788     return DM_OK;
789 }
790 
ON_IPC_READ_RESPONSE(REGISTER_CREDENTIAL_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)791 ON_IPC_READ_RESPONSE(REGISTER_CREDENTIAL_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
792 {
793     pBaseRsp->SetErrCode(reply.ReadInt32());
794     return DM_OK;
795 }
796 
ON_IPC_SET_REQUEST(UNREGISTER_CREDENTIAL_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)797 ON_IPC_SET_REQUEST(UNREGISTER_CREDENTIAL_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
798 {
799     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
800     std::string pkgName = pReq->GetPkgName();
801 
802     if (!data.WriteString(pkgName)) {
803         LOGE("write pkgName failed");
804         return ERR_DM_IPC_WRITE_FAILED;
805     }
806 
807     return DM_OK;
808 }
809 
ON_IPC_READ_RESPONSE(UNREGISTER_CREDENTIAL_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)810 ON_IPC_READ_RESPONSE(UNREGISTER_CREDENTIAL_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
811 {
812     pBaseRsp->SetErrCode(reply.ReadInt32());
813     return DM_OK;
814 }
815 
ON_IPC_CMD(SERVER_CREDENTIAL_RESULT,MessageParcel & data,MessageParcel & reply)816 ON_IPC_CMD(SERVER_CREDENTIAL_RESULT, MessageParcel &data, MessageParcel &reply)
817 {
818     std::string pkgName = data.ReadString();
819     int32_t action = data.ReadInt32();
820     std::string credentialResult = data.ReadString();
821 
822     DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult);
823     reply.WriteInt32(DM_OK);
824     return DM_OK;
825 }
826 
ON_IPC_SET_REQUEST(NOTIFY_EVENT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)827 ON_IPC_SET_REQUEST(NOTIFY_EVENT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
828 {
829     std::shared_ptr<IpcNotifyEventReq> pReq = std::static_pointer_cast<IpcNotifyEventReq>(pBaseReq);
830     std::string pkgName = pReq->GetPkgName();
831     int32_t eventId = pReq->GetEventId();
832     std::string event = pReq->GetEvent();
833     if (!data.WriteString(pkgName)) {
834         LOGE("write pkgName failed");
835         return ERR_DM_IPC_WRITE_FAILED;
836     }
837     if (!data.WriteInt32(eventId)) {
838         LOGE("write eventId failed");
839         return ERR_DM_IPC_WRITE_FAILED;
840     }
841     if (!data.WriteString(event)) {
842         LOGE("write event failed");
843         return ERR_DM_IPC_WRITE_FAILED;
844     }
845     return DM_OK;
846 }
847 
ON_IPC_READ_RESPONSE(NOTIFY_EVENT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)848 ON_IPC_READ_RESPONSE(NOTIFY_EVENT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
849 {
850     pBaseRsp->SetErrCode(reply.ReadInt32());
851     return DM_OK;
852 }
853 
ON_IPC_SET_REQUEST(GET_ENCRYPTED_UUID_BY_NETWOEKID,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)854 ON_IPC_SET_REQUEST(GET_ENCRYPTED_UUID_BY_NETWOEKID, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
855 {
856     std::shared_ptr<IpcGetEncryptedUuidReq> pReq = std::static_pointer_cast<IpcGetEncryptedUuidReq>(pBaseReq);
857     std::string pkgName = pReq->GetPkgName();
858     std::string netWorkId = pReq->GetNetworkId();
859     if (!data.WriteString(pkgName)) {
860         LOGE("write pkgName failed");
861         return ERR_DM_IPC_WRITE_FAILED;
862     }
863     if (!data.WriteString(netWorkId)) {
864         LOGE("write netWorkId failed");
865         return ERR_DM_IPC_WRITE_FAILED;
866     }
867     return DM_OK;
868 }
869 
ON_IPC_READ_RESPONSE(GET_ENCRYPTED_UUID_BY_NETWOEKID,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)870 ON_IPC_READ_RESPONSE(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
871 {
872     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
873     pRsp->SetErrCode(reply.ReadInt32());
874     pRsp->SetUuid(reply.ReadString());
875     return DM_OK;
876 }
877 
ON_IPC_SET_REQUEST(GENERATE_ENCRYPTED_UUID,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)878 ON_IPC_SET_REQUEST(GENERATE_ENCRYPTED_UUID, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
879 {
880     std::shared_ptr<IpcGenerateEncryptedUuidReq> pReq = std::static_pointer_cast<IpcGenerateEncryptedUuidReq>(pBaseReq);
881     std::string pkgName = pReq->GetPkgName();
882     std::string uuid = pReq->GetUuid();
883     std::string appId = pReq->GetAppId();
884     if (!data.WriteString(pkgName)) {
885         LOGE("write pkgName failed");
886         return ERR_DM_IPC_WRITE_FAILED;
887     }
888     if (!data.WriteString(uuid)) {
889         LOGE("write uuid failed");
890         return ERR_DM_IPC_WRITE_FAILED;
891     }
892     if (!data.WriteString(appId)) {
893         LOGE("write appId failed");
894         return ERR_DM_IPC_WRITE_FAILED;
895     }
896     return DM_OK;
897 }
898 
ON_IPC_READ_RESPONSE(GENERATE_ENCRYPTED_UUID,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)899 ON_IPC_READ_RESPONSE(GENERATE_ENCRYPTED_UUID, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
900 {
901     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
902     pRsp->SetErrCode(reply.ReadInt32());
903     pRsp->SetUuid(reply.ReadString());
904     return DM_OK;
905 }
906 
ON_IPC_SET_REQUEST(BIND_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)907 ON_IPC_SET_REQUEST(BIND_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
908 {
909     std::shared_ptr<IpcBindDeviceReq> pReq = std::static_pointer_cast<IpcBindDeviceReq>(pBaseReq);
910     std::string pkgName = pReq->GetPkgName();
911     std::string bindParam = pReq->GetBindParam();
912     int32_t bindType = pReq->GetBindType();
913     std::string deviceId = pReq->GetDeviceId();
914 
915     if (!data.WriteString(pkgName)) {
916         LOGE("write pkgName failed");
917         return ERR_DM_IPC_WRITE_FAILED;
918     }
919     if (!data.WriteString(bindParam)) {
920         LOGE("write bindParam failed");
921         return ERR_DM_IPC_WRITE_FAILED;
922     }
923     if (!data.WriteString(deviceId)) {
924         LOGE("write deviceId failed");
925         return ERR_DM_IPC_WRITE_FAILED;
926     }
927     if (!data.WriteInt32(bindType)) {
928         LOGE("write bindType failed");
929         return ERR_DM_IPC_WRITE_FAILED;
930     }
931     return DM_OK;
932 }
933 
ON_IPC_READ_RESPONSE(BIND_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)934 ON_IPC_READ_RESPONSE(BIND_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
935 {
936     if (pBaseRsp == nullptr) {
937         LOGE("pBaseRsp is null");
938         return ERR_DM_FAILED;
939     }
940     pBaseRsp->SetErrCode(reply.ReadInt32());
941     return DM_OK;
942 }
943 
ON_IPC_SET_REQUEST(UNBIND_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)944 ON_IPC_SET_REQUEST(UNBIND_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
945 {
946     std::shared_ptr<IpcUnBindDeviceReq> pReq = std::static_pointer_cast<IpcUnBindDeviceReq>(pBaseReq);
947     std::string pkgName = pReq->GetPkgName();
948     std::string deviceId = pReq->GetDeviceId();
949 
950     if (!data.WriteString(pkgName)) {
951         LOGE("write pkgName failed");
952         return ERR_DM_IPC_WRITE_FAILED;
953     }
954     if (!data.WriteString(deviceId)) {
955         LOGE("write deviceId failed");
956         return ERR_DM_IPC_WRITE_FAILED;
957     }
958     return DM_OK;
959 }
960 
ON_IPC_READ_RESPONSE(UNBIND_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)961 ON_IPC_READ_RESPONSE(UNBIND_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
962 {
963     pBaseRsp->SetErrCode(reply.ReadInt32());
964     return DM_OK;
965 }
966 
ON_IPC_SET_REQUEST(GET_NETWORKTYPE_BY_NETWORK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)967 ON_IPC_SET_REQUEST(GET_NETWORKTYPE_BY_NETWORK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
968 {
969     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
970     std::string pkgName = pReq->GetPkgName();
971     std::string netWorkId = pReq->GetNetWorkId();
972     if (!data.WriteString(pkgName)) {
973         return ERR_DM_IPC_WRITE_FAILED;
974     }
975     if (!data.WriteString(netWorkId)) {
976         return ERR_DM_IPC_WRITE_FAILED;
977     }
978     return DM_OK;
979 }
980 
ON_IPC_READ_RESPONSE(GET_NETWORKTYPE_BY_NETWORK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)981 ON_IPC_READ_RESPONSE(GET_NETWORKTYPE_BY_NETWORK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
982 {
983     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
984     pRsp->SetErrCode(reply.ReadInt32());
985     pRsp->SetNetworkType(reply.ReadInt32());
986     return DM_OK;
987 }
988 
ON_IPC_SET_REQUEST(REGISTER_UI_STATE_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)989 ON_IPC_SET_REQUEST(REGISTER_UI_STATE_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
990 {
991     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
992     std::string pkgName = pReq->GetPkgName();
993     if (!data.WriteString(pkgName)) {
994         return ERR_DM_IPC_WRITE_FAILED;
995     }
996     return DM_OK;
997 }
998 
ON_IPC_READ_RESPONSE(REGISTER_UI_STATE_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)999 ON_IPC_READ_RESPONSE(REGISTER_UI_STATE_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1000 {
1001     pBaseRsp->SetErrCode(reply.ReadInt32());
1002     return DM_OK;
1003 }
1004 
ON_IPC_SET_REQUEST(UNREGISTER_UI_STATE_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1005 ON_IPC_SET_REQUEST(UNREGISTER_UI_STATE_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1006 {
1007     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
1008     std::string pkgName = pReq->GetPkgName();
1009     if (!data.WriteString(pkgName)) {
1010         return ERR_DM_IPC_WRITE_FAILED;
1011     }
1012     return DM_OK;
1013 }
1014 
ON_IPC_READ_RESPONSE(UNREGISTER_UI_STATE_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1015 ON_IPC_READ_RESPONSE(UNREGISTER_UI_STATE_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1016 {
1017     pBaseRsp->SetErrCode(reply.ReadInt32());
1018     return DM_OK;
1019 }
1020 
ON_IPC_SET_REQUEST(IMPORT_AUTH_CODE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1021 ON_IPC_SET_REQUEST(IMPORT_AUTH_CODE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1022 {
1023     std::shared_ptr<IpcImportAuthCodeReq> pReq = std::static_pointer_cast<IpcImportAuthCodeReq>(pBaseReq);
1024     std::string pkgName = pReq->GetPkgName();
1025     std::string authCode = pReq->GetAuthCode();
1026     if (!data.WriteString(pkgName)) {
1027         return ERR_DM_IPC_WRITE_FAILED;
1028     }
1029     if (!data.WriteString(authCode)) {
1030         return ERR_DM_IPC_WRITE_FAILED;
1031     }
1032     return DM_OK;
1033 }
1034 
ON_IPC_READ_RESPONSE(IMPORT_AUTH_CODE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1035 ON_IPC_READ_RESPONSE(IMPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1036 {
1037     std::shared_ptr<IpcRsp> pRsp = std::static_pointer_cast<IpcRsp>(pBaseRsp);
1038     pRsp->SetErrCode(reply.ReadInt32());
1039     return DM_OK;
1040 }
1041 
ON_IPC_SET_REQUEST(EXPORT_AUTH_CODE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1042 ON_IPC_SET_REQUEST(EXPORT_AUTH_CODE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1043 {
1044     LOGI("send export auth code request!");
1045     return DM_OK;
1046 }
1047 
ON_IPC_READ_RESPONSE(EXPORT_AUTH_CODE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1048 ON_IPC_READ_RESPONSE(EXPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1049 {
1050     std::shared_ptr<IpcExportAuthCodeRsp> pRsp = std::static_pointer_cast<IpcExportAuthCodeRsp>(pBaseRsp);
1051     if (pRsp == nullptr) {
1052         LOGE("IpcExportAuthCodeRsp pRsp is null");
1053         return ERR_DM_FAILED;
1054     }
1055     std::string authCode = reply.ReadString();
1056     pRsp->SetAuthCode(authCode);
1057     pRsp->SetErrCode(reply.ReadInt32());
1058     return DM_OK;
1059 }
1060 
ON_IPC_SET_REQUEST(REGISTER_DISCOVERY_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1061 ON_IPC_SET_REQUEST(REGISTER_DISCOVERY_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1062 {
1063     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1064     std::string pkgName = pReq->GetPkgName();
1065     std::string discParaStr = pReq->GetFirstParam();
1066     std::string filterOpStr = pReq->GetSecondParam();
1067     if (!data.WriteString(pkgName)) {
1068         LOGE("write pkgName failed");
1069         return ERR_DM_IPC_WRITE_FAILED;
1070     }
1071     if (!data.WriteString(discParaStr)) {
1072         LOGE("write discovery parameter failed");
1073         return ERR_DM_IPC_WRITE_FAILED;
1074     }
1075     if (!data.WriteString(filterOpStr)) {
1076         LOGE("write filter option parameter failed");
1077         return ERR_DM_IPC_WRITE_FAILED;
1078     }
1079     return DM_OK;
1080 }
1081 
ON_IPC_READ_RESPONSE(REGISTER_DISCOVERY_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1082 ON_IPC_READ_RESPONSE(REGISTER_DISCOVERY_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1083 {
1084     if (pBaseRsp == nullptr) {
1085         LOGE("pBaseRsp is null");
1086         return ERR_DM_FAILED;
1087     }
1088     pBaseRsp->SetErrCode(reply.ReadInt32());
1089     return DM_OK;
1090 }
1091 
ON_IPC_SET_REQUEST(UNREGISTER_DISCOVERY_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1092 ON_IPC_SET_REQUEST(UNREGISTER_DISCOVERY_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1093 {
1094     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1095     std::string pkgName = pReq->GetPkgName();
1096     std::string extraParaStr = pReq->GetFirstParam();
1097     if (!data.WriteString(pkgName)) {
1098         LOGE("write pkgName failed");
1099         return ERR_DM_IPC_WRITE_FAILED;
1100     }
1101     if (!data.WriteString(extraParaStr)) {
1102         LOGE("write extra parameter failed");
1103         return ERR_DM_IPC_WRITE_FAILED;
1104     }
1105     return DM_OK;
1106 }
1107 
ON_IPC_READ_RESPONSE(UNREGISTER_DISCOVERY_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1108 ON_IPC_READ_RESPONSE(UNREGISTER_DISCOVERY_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1109 {
1110     if (pBaseRsp == nullptr) {
1111         LOGE("pBaseRsp is null");
1112         return ERR_DM_FAILED;
1113     }
1114     pBaseRsp->SetErrCode(reply.ReadInt32());
1115     return DM_OK;
1116 }
1117 
ON_IPC_SET_REQUEST(START_DISCOVERING,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1118 ON_IPC_SET_REQUEST(START_DISCOVERING, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1119 {
1120     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1121     std::string pkgName = pReq->GetPkgName();
1122     std::string discParaStr = pReq->GetFirstParam();
1123     std::string filterOpStr = pReq->GetSecondParam();
1124     if (!data.WriteString(pkgName)) {
1125         LOGE("write pkgName failed");
1126         return ERR_DM_IPC_WRITE_FAILED;
1127     }
1128     if (!data.WriteString(discParaStr)) {
1129         LOGE("write discovery parameter failed");
1130         return ERR_DM_IPC_WRITE_FAILED;
1131     }
1132     if (!data.WriteString(filterOpStr)) {
1133         LOGE("write filter option parameter failed");
1134         return ERR_DM_IPC_WRITE_FAILED;
1135     }
1136     return DM_OK;
1137 }
1138 
ON_IPC_READ_RESPONSE(START_DISCOVERING,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1139 ON_IPC_READ_RESPONSE(START_DISCOVERING, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1140 {
1141     if (pBaseRsp == nullptr) {
1142         LOGE("pBaseRsp is null");
1143         return ERR_DM_FAILED;
1144     }
1145     pBaseRsp->SetErrCode(reply.ReadInt32());
1146     return DM_OK;
1147 }
1148 
ON_IPC_SET_REQUEST(STOP_DISCOVERING,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1149 ON_IPC_SET_REQUEST(STOP_DISCOVERING, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1150 {
1151     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1152     std::string pkgName = pReq->GetPkgName();
1153     std::string discParaStr = pReq->GetFirstParam();
1154     if (!data.WriteString(pkgName)) {
1155         LOGE("write pkgName failed");
1156         return ERR_DM_IPC_WRITE_FAILED;
1157     }
1158     if (!data.WriteString(discParaStr)) {
1159         LOGE("write discovery parameter failed");
1160         return ERR_DM_IPC_WRITE_FAILED;
1161     }
1162     return DM_OK;
1163 }
1164 
ON_IPC_READ_RESPONSE(STOP_DISCOVERING,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1165 ON_IPC_READ_RESPONSE(STOP_DISCOVERING, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1166 {
1167     if (pBaseRsp == nullptr) {
1168         LOGE("pBaseRsp is null");
1169         return ERR_DM_FAILED;
1170     }
1171     pBaseRsp->SetErrCode(reply.ReadInt32());
1172     return DM_OK;
1173 }
1174 
ON_IPC_SET_REQUEST(START_ADVERTISING,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1175 ON_IPC_SET_REQUEST(START_ADVERTISING, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1176 {
1177     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1178     std::string pkgName = pReq->GetPkgName();
1179     std::string adverParaStr = pReq->GetFirstParam();
1180     if (!data.WriteString(pkgName)) {
1181         LOGE("write pkgName failed");
1182         return ERR_DM_IPC_WRITE_FAILED;
1183     }
1184     if (!data.WriteString(adverParaStr)) {
1185         LOGE("write advertising parameter failed");
1186         return ERR_DM_IPC_WRITE_FAILED;
1187     }
1188     return DM_OK;
1189 }
1190 
ON_IPC_READ_RESPONSE(START_ADVERTISING,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1191 ON_IPC_READ_RESPONSE(START_ADVERTISING, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1192 {
1193     if (pBaseRsp == nullptr) {
1194         LOGE("pBaseRsp is null");
1195         return ERR_DM_FAILED;
1196     }
1197     pBaseRsp->SetErrCode(reply.ReadInt32());
1198     return DM_OK;
1199 }
1200 
ON_IPC_SET_REQUEST(STOP_ADVERTISING,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1201 ON_IPC_SET_REQUEST(STOP_ADVERTISING, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1202 {
1203     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1204     std::string pkgName = pReq->GetPkgName();
1205     std::string adverParaStr = pReq->GetFirstParam();
1206     if (!data.WriteString(pkgName)) {
1207         LOGE("write pkgName failed");
1208         return ERR_DM_IPC_WRITE_FAILED;
1209     }
1210     if (!data.WriteString(adverParaStr)) {
1211         LOGE("write advertising parameter failed");
1212         return ERR_DM_IPC_WRITE_FAILED;
1213     }
1214     return DM_OK;
1215 }
1216 
ON_IPC_READ_RESPONSE(STOP_ADVERTISING,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1217 ON_IPC_READ_RESPONSE(STOP_ADVERTISING, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1218 {
1219     if (pBaseRsp == nullptr) {
1220         LOGE("pBaseRsp is null");
1221         return ERR_DM_FAILED;
1222     }
1223     pBaseRsp->SetErrCode(reply.ReadInt32());
1224     return DM_OK;
1225 }
1226 
ON_IPC_SET_REQUEST(BIND_TARGET,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1227 ON_IPC_SET_REQUEST(BIND_TARGET, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1228 {
1229     std::shared_ptr<IpcBindTargetReq> pReq = std::static_pointer_cast<IpcBindTargetReq>(pBaseReq);
1230     std::string pkgName = pReq->GetPkgName();
1231     PeerTargetId targetId = pReq->GetPeerTargetId();
1232     std::string bindParam = pReq->GetBindParam();
1233 
1234     if (!data.WriteString(pkgName)) {
1235         LOGE("write pkgName failed");
1236         return ERR_DM_IPC_WRITE_FAILED;
1237     }
1238     if (!EncodePeerTargetId(targetId, data)) {
1239         LOGE("write peer target id failed");
1240         return ERR_DM_IPC_WRITE_FAILED;
1241     }
1242     if (!data.WriteString(bindParam)) {
1243         LOGE("write bind parameter string failed");
1244         return ERR_DM_IPC_WRITE_FAILED;
1245     }
1246     return DM_OK;
1247 }
1248 
ON_IPC_READ_RESPONSE(BIND_TARGET,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1249 ON_IPC_READ_RESPONSE(BIND_TARGET, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1250 {
1251     if (pBaseRsp == nullptr) {
1252         LOGE("pBaseRsp is null");
1253         return ERR_DM_FAILED;
1254     }
1255     pBaseRsp->SetErrCode(reply.ReadInt32());
1256     return DM_OK;
1257 }
1258 
ON_IPC_SET_REQUEST(UNBIND_TARGET,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1259 ON_IPC_SET_REQUEST(UNBIND_TARGET, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1260 {
1261     std::shared_ptr<IpcBindTargetReq> pReq = std::static_pointer_cast<IpcBindTargetReq>(pBaseReq);
1262     std::string pkgName = pReq->GetPkgName();
1263     PeerTargetId targetId = pReq->GetPeerTargetId();
1264     std::string unbindParam = pReq->GetBindParam();
1265 
1266     if (!data.WriteString(pkgName)) {
1267         LOGE("write pkgName failed");
1268         return ERR_DM_IPC_WRITE_FAILED;
1269     }
1270     if (!EncodePeerTargetId(targetId, data)) {
1271         LOGE("write peer target id failed");
1272         return ERR_DM_IPC_WRITE_FAILED;
1273     }
1274     if (!data.WriteString(unbindParam)) {
1275         LOGE("write unbind parameter string failed");
1276         return ERR_DM_IPC_WRITE_FAILED;
1277     }
1278     return DM_OK;
1279 }
1280 
ON_IPC_READ_RESPONSE(UNBIND_TARGET,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1281 ON_IPC_READ_RESPONSE(UNBIND_TARGET, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1282 {
1283     if (pBaseRsp == nullptr) {
1284         LOGE("pBaseRsp is null");
1285         return ERR_DM_FAILED;
1286     }
1287     pBaseRsp->SetErrCode(reply.ReadInt32());
1288     return DM_OK;
1289 }
1290 
ON_IPC_CMD(BIND_TARGET_RESULT,MessageParcel & data,MessageParcel & reply)1291 ON_IPC_CMD(BIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply)
1292 {
1293     std::string pkgName = data.ReadString();
1294     PeerTargetId targetId;
1295     DecodePeerTargetId(data, targetId);
1296     int32_t result = data.ReadInt32();
1297     int32_t status = data.ReadInt32();
1298     std::string content = data.ReadString();
1299 
1300     DeviceManagerNotify::GetInstance().OnBindResult(pkgName, targetId, result, status, content);
1301     reply.WriteInt32(DM_OK);
1302     return DM_OK;
1303 }
1304 
ON_IPC_CMD(UNBIND_TARGET_RESULT,MessageParcel & data,MessageParcel & reply)1305 ON_IPC_CMD(UNBIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply)
1306 {
1307     std::string pkgName = data.ReadString();
1308     PeerTargetId targetId;
1309     DecodePeerTargetId(data, targetId);
1310     int32_t result = data.ReadInt32();
1311     std::string content = data.ReadString();
1312 
1313     DeviceManagerNotify::GetInstance().OnUnbindResult(pkgName, targetId, result, content);
1314     reply.WriteInt32(DM_OK);
1315     return DM_OK;
1316 }
1317 
ON_IPC_SET_REQUEST(REGISTER_PIN_HOLDER_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1318 ON_IPC_SET_REQUEST(REGISTER_PIN_HOLDER_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1319 {
1320     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
1321     std::string pkgName = pReq->GetPkgName();
1322     if (!data.WriteString(pkgName)) {
1323         return ERR_DM_IPC_WRITE_FAILED;
1324     }
1325     return DM_OK;
1326 }
1327 
ON_IPC_READ_RESPONSE(REGISTER_PIN_HOLDER_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1328 ON_IPC_READ_RESPONSE(REGISTER_PIN_HOLDER_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1329 {
1330     std::shared_ptr<IpcRsp> pRsp = std::static_pointer_cast<IpcRsp>(pBaseRsp);
1331     pRsp->SetErrCode(reply.ReadInt32());
1332     return DM_OK;
1333 }
1334 
ON_IPC_SET_REQUEST(CREATE_PIN_HOLDER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1335 ON_IPC_SET_REQUEST(CREATE_PIN_HOLDER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1336 {
1337     std::shared_ptr<IpcCreatePinHolderReq> pReq = std::static_pointer_cast<IpcCreatePinHolderReq>(pBaseReq);
1338     std::string pkgName = pReq->GetPkgName();
1339     PeerTargetId targetId = pReq->GetPeerTargetId();
1340     std::string payload = pReq->GetPayload();
1341     int32_t pinType = pReq->GetPinType();
1342     if (!data.WriteString(pkgName)) {
1343         return ERR_DM_IPC_WRITE_FAILED;
1344     }
1345     if (!EncodePeerTargetId(targetId, data)) {
1346         LOGE("write peer target id failed");
1347         return ERR_DM_IPC_WRITE_FAILED;
1348     }
1349     if (!data.WriteString(payload)) {
1350         return ERR_DM_IPC_WRITE_FAILED;
1351     }
1352     if (!data.WriteInt32(pinType)) {
1353         return ERR_DM_IPC_WRITE_FAILED;
1354     }
1355     return DM_OK;
1356 }
1357 
ON_IPC_READ_RESPONSE(CREATE_PIN_HOLDER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1358 ON_IPC_READ_RESPONSE(CREATE_PIN_HOLDER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1359 {
1360     std::shared_ptr<IpcRsp> pRsp = std::static_pointer_cast<IpcRsp>(pBaseRsp);
1361     pRsp->SetErrCode(reply.ReadInt32());
1362     return DM_OK;
1363 }
1364 
ON_IPC_SET_REQUEST(DESTROY_PIN_HOLDER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1365 ON_IPC_SET_REQUEST(DESTROY_PIN_HOLDER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1366 {
1367     std::shared_ptr<IpcDestroyPinHolderReq> pReq = std::static_pointer_cast<IpcDestroyPinHolderReq>(pBaseReq);
1368     std::string pkgName = pReq->GetPkgName();
1369     PeerTargetId targetId = pReq->GetPeerTargetId();
1370     int32_t pinType = pReq->GetPinType();
1371     std::string payload = pReq->GetPayload();
1372     if (!data.WriteString(pkgName)) {
1373         return ERR_DM_IPC_WRITE_FAILED;
1374     }
1375     if (!EncodePeerTargetId(targetId, data)) {
1376         LOGE("write peer target id failed");
1377         return ERR_DM_IPC_WRITE_FAILED;
1378     }
1379     if (!data.WriteInt32(pinType)) {
1380         return ERR_DM_IPC_WRITE_FAILED;
1381     }
1382     if (!data.WriteString(payload)) {
1383         return ERR_DM_IPC_WRITE_FAILED;
1384     }
1385     return DM_OK;
1386 }
1387 
ON_IPC_READ_RESPONSE(DESTROY_PIN_HOLDER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1388 ON_IPC_READ_RESPONSE(DESTROY_PIN_HOLDER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1389 {
1390     std::shared_ptr<IpcRsp> pRsp = std::static_pointer_cast<IpcRsp>(pBaseRsp);
1391     pRsp->SetErrCode(reply.ReadInt32());
1392     return DM_OK;
1393 }
1394 
ON_IPC_SET_REQUEST(SET_DN_POLICY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1395 ON_IPC_SET_REQUEST(SET_DN_POLICY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1396 {
1397     if (pBaseReq == nullptr) {
1398         LOGE("pBaseRsp is null");
1399         return ERR_DM_FAILED;
1400     }
1401     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1402     std::string pkgName = pReq->GetPkgName();
1403     std::string policy = pReq->GetFirstParam();
1404     if (!data.WriteString(pkgName)) {
1405         LOGE("write pkgName failed");
1406         return ERR_DM_IPC_WRITE_FAILED;
1407     }
1408     if (!data.WriteString(policy)) {
1409         LOGE("write setDnPolicy parameter failed");
1410         return ERR_DM_IPC_WRITE_FAILED;
1411     }
1412     return DM_OK;
1413 }
1414 
ON_IPC_READ_RESPONSE(SET_DN_POLICY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1415 ON_IPC_READ_RESPONSE(SET_DN_POLICY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1416 {
1417     if (pBaseRsp == nullptr) {
1418         LOGE("pBaseRsp is null");
1419         return ERR_DM_FAILED;
1420     }
1421     pBaseRsp->SetErrCode(reply.ReadInt32());
1422     return DM_OK;
1423 }
1424 
ON_IPC_SET_REQUEST(STOP_AUTHENTICATE_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1425 ON_IPC_SET_REQUEST(STOP_AUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1426 {
1427     if (pBaseReq == nullptr) {
1428         LOGE("pBaseRsp is null");
1429         return ERR_DM_FAILED;
1430     }
1431     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1432     std::string pkgName = pReq->GetPkgName();
1433     if (!data.WriteString(pkgName)) {
1434         LOGE("write pkgName failed");
1435         return ERR_DM_IPC_WRITE_FAILED;
1436     }
1437     return DM_OK;
1438 }
1439 
ON_IPC_READ_RESPONSE(STOP_AUTHENTICATE_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1440 ON_IPC_READ_RESPONSE(STOP_AUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1441 {
1442     if (pBaseRsp == nullptr) {
1443         LOGE("pBaseRsp is null");
1444         return ERR_DM_FAILED;
1445     }
1446     pBaseRsp->SetErrCode(reply.ReadInt32());
1447     return DM_OK;
1448 }
1449 
ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER,MessageParcel & data,MessageParcel & reply)1450 ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER, MessageParcel &data, MessageParcel &reply)
1451 {
1452     std::string pkgName = data.ReadString();
1453     std::string deviceId = data.ReadString();
1454     DmPinType pinType = static_cast<DmPinType>(data.ReadInt32());
1455     std::string payload = data.ReadString();
1456 
1457     DeviceManagerNotify::GetInstance().OnPinHolderCreate(pkgName, deviceId, pinType, payload);
1458     reply.WriteInt32(DM_OK);
1459     return DM_OK;
1460 }
1461 
ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER,MessageParcel & data,MessageParcel & reply)1462 ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER, MessageParcel &data, MessageParcel &reply)
1463 {
1464     std::string pkgName = data.ReadString();
1465     DmPinType pinType = static_cast<DmPinType>(data.ReadInt32());
1466     std::string payload = data.ReadString();
1467 
1468     DeviceManagerNotify::GetInstance().OnPinHolderDestroy(pkgName, pinType, payload);
1469     reply.WriteInt32(DM_OK);
1470     return DM_OK;
1471 }
1472 
ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER_RESULT,MessageParcel & data,MessageParcel & reply)1473 ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER_RESULT, MessageParcel &data, MessageParcel &reply)
1474 {
1475     std::string pkgName = data.ReadString();
1476     int32_t result = data.ReadInt32();
1477 
1478     DeviceManagerNotify::GetInstance().OnCreateResult(pkgName, result);
1479     reply.WriteInt32(DM_OK);
1480     return DM_OK;
1481 }
1482 
ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER_RESULT,MessageParcel & data,MessageParcel & reply)1483 ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &data, MessageParcel &reply)
1484 {
1485     std::string pkgName = data.ReadString();
1486     int32_t result = data.ReadInt32();
1487 
1488     DeviceManagerNotify::GetInstance().OnDestroyResult(pkgName, result);
1489     reply.WriteInt32(DM_OK);
1490     return DM_OK;
1491 }
1492 
ON_IPC_SET_REQUEST(DP_ACL_ADD,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1493 ON_IPC_SET_REQUEST(DP_ACL_ADD, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1494 {
1495     std::shared_ptr<IpcAclProfileReq> pReq = std::static_pointer_cast<IpcAclProfileReq>(pBaseReq);
1496     std::string udid = pReq->GetStr();
1497     if (!data.WriteString(udid)) {
1498         LOGE("write udid failed");
1499         return ERR_DM_IPC_WRITE_FAILED;
1500     }
1501     return DM_OK;
1502 }
1503 
ON_IPC_READ_RESPONSE(DP_ACL_ADD,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1504 ON_IPC_READ_RESPONSE(DP_ACL_ADD, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1505 {
1506     if (pBaseRsp == nullptr) {
1507         LOGE("pBaseRsp is null");
1508         return ERR_DM_FAILED;
1509     }
1510     pBaseRsp->SetErrCode(reply.ReadInt32());
1511     return DM_OK;
1512 }
1513 
ON_IPC_SET_REQUEST(GET_SECURITY_LEVEL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1514 ON_IPC_SET_REQUEST(GET_SECURITY_LEVEL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1515 {
1516     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
1517     std::string pkgName = pReq->GetPkgName();
1518     std::string networkId = pReq->GetNetWorkId();
1519     if (!data.WriteString(pkgName)) {
1520         return ERR_DM_IPC_WRITE_FAILED;
1521     }
1522     if (!data.WriteString(networkId)) {
1523         return ERR_DM_IPC_WRITE_FAILED;
1524     }
1525     return DM_OK;
1526 }
1527 
ON_IPC_READ_RESPONSE(GET_SECURITY_LEVEL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1528 ON_IPC_READ_RESPONSE(GET_SECURITY_LEVEL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1529 {
1530     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
1531     pRsp->SetErrCode(reply.ReadInt32());
1532     pRsp->SetSecurityLevel(reply.ReadInt32());
1533     return DM_OK;
1534 }
1535 
ON_IPC_CMD(SERVER_ON_PIN_HOLDER_EVENT,MessageParcel & data,MessageParcel & reply)1536 ON_IPC_CMD(SERVER_ON_PIN_HOLDER_EVENT, MessageParcel &data, MessageParcel &reply)
1537 {
1538     std::string pkgName = data.ReadString();
1539     int32_t result = data.ReadInt32();
1540     DmPinHolderEvent pinHolderEvent = static_cast<DmPinHolderEvent>(data.ReadInt32());
1541     std::string content = data.ReadString();
1542 
1543     DeviceManagerNotify::GetInstance().OnPinHolderEvent(pkgName, pinHolderEvent, result, content);
1544     reply.WriteInt32(DM_OK);
1545     return DM_OK;
1546 }
1547 
ON_IPC_SET_REQUEST(IS_SAME_ACCOUNT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1548 ON_IPC_SET_REQUEST(IS_SAME_ACCOUNT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1549 {
1550     std::shared_ptr<IpcAclProfileReq> pReq = std::static_pointer_cast<IpcAclProfileReq>(pBaseReq);
1551     std::string netWorkId = pReq->GetStr();
1552     if (!data.WriteString(netWorkId)) {
1553         LOGE("write netWorkId failed");
1554         return ERR_DM_IPC_WRITE_FAILED;
1555     }
1556     return DM_OK;
1557 }
1558 
ON_IPC_READ_RESPONSE(IS_SAME_ACCOUNT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1559 ON_IPC_READ_RESPONSE(IS_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1560 {
1561     if (pBaseRsp == nullptr) {
1562         LOGE("pBaseRsp is null");
1563         return ERR_DM_FAILED;
1564     }
1565     pBaseRsp->SetErrCode(reply.ReadInt32());
1566     return DM_OK;
1567 }
1568 
ON_IPC_SET_REQUEST(CHECK_API_PERMISSION,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1569 ON_IPC_SET_REQUEST(CHECK_API_PERMISSION, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1570 {
1571     if (pBaseReq == nullptr) {
1572         LOGE("pBaseReq is nullptr");
1573         return ERR_DM_FAILED;
1574     }
1575     std::shared_ptr<IpcPermissionReq> pReq = std::static_pointer_cast<IpcPermissionReq>(pBaseReq);
1576     if (!data.WriteInt32(pReq->GetPermissionLevel())) {
1577         LOGE("write permissionLevel failed");
1578         return ERR_DM_IPC_WRITE_FAILED;
1579     }
1580     return DM_OK;
1581 }
1582 
ON_IPC_READ_RESPONSE(CHECK_API_PERMISSION,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1583 ON_IPC_READ_RESPONSE(CHECK_API_PERMISSION, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1584 {
1585     if (pBaseRsp == nullptr) {
1586         LOGE("pBaseRsp is nullptr");
1587         return ERR_DM_FAILED;
1588     }
1589     pBaseRsp->SetErrCode(reply.ReadInt32());
1590     return DM_OK;
1591 }
1592 
ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1593 ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1594 {
1595     std::shared_ptr<IpcCheckAcl> pReq = std::static_pointer_cast<IpcCheckAcl>(pBaseReq);
1596     DmAccessCaller caller = pReq->GetAccessCaller();
1597     DmAccessCallee callee = pReq->GetAccessCallee();
1598     if (!EncodeDmAccessCaller(caller, data)) {
1599         LOGE("write caller failed");
1600         return ERR_DM_IPC_WRITE_FAILED;
1601     }
1602     if (!EncodeDmAccessCallee(callee, data)) {
1603         LOGE("write caller failed");
1604         return ERR_DM_IPC_WRITE_FAILED;
1605     }
1606     return DM_OK;
1607 }
1608 
ON_IPC_READ_RESPONSE(CHECK_ACCESS_CONTROL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1609 ON_IPC_READ_RESPONSE(CHECK_ACCESS_CONTROL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1610 {
1611     if (pBaseRsp == nullptr) {
1612         LOGE("pBaseRsp is null");
1613         return ERR_DM_FAILED;
1614     }
1615     pBaseRsp->SetErrCode(reply.ReadInt32());
1616     return DM_OK;
1617 }
1618 
ON_IPC_SET_REQUEST(CHECK_SAME_ACCOUNT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1619 ON_IPC_SET_REQUEST(CHECK_SAME_ACCOUNT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1620 {
1621     std::shared_ptr<IpcCheckAcl> pReq = std::static_pointer_cast<IpcCheckAcl>(pBaseReq);
1622     DmAccessCaller caller = pReq->GetAccessCaller();
1623     DmAccessCallee callee = pReq->GetAccessCallee();
1624     if (!EncodeDmAccessCaller(caller, data)) {
1625         LOGE("write caller failed");
1626         return ERR_DM_IPC_WRITE_FAILED;
1627     }
1628     if (!EncodeDmAccessCallee(callee, data)) {
1629         LOGE("write caller failed");
1630         return ERR_DM_IPC_WRITE_FAILED;
1631     }
1632     return DM_OK;
1633 }
1634 
ON_IPC_READ_RESPONSE(CHECK_SAME_ACCOUNT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1635 ON_IPC_READ_RESPONSE(CHECK_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1636 {
1637     if (pBaseRsp == nullptr) {
1638         LOGE("pBaseRsp is null");
1639         return ERR_DM_FAILED;
1640     }
1641     pBaseRsp->SetErrCode(reply.ReadInt32());
1642     return DM_OK;
1643 }
1644 
ON_IPC_SET_REQUEST(SHIFT_LNN_GEAR,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1645 ON_IPC_SET_REQUEST(SHIFT_LNN_GEAR, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1646 {
1647     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
1648     std::string pkgName = pReq->GetPkgName();
1649     if (!data.WriteString(pkgName)) {
1650         LOGE("write pkgName failed");
1651         return ERR_DM_IPC_WRITE_FAILED;
1652     }
1653     return DM_OK;
1654 }
1655 
ON_IPC_READ_RESPONSE(SHIFT_LNN_GEAR,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1656 ON_IPC_READ_RESPONSE(SHIFT_LNN_GEAR, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1657 {
1658     if (pBaseRsp == nullptr) {
1659         LOGE("pBaseRsp is null");
1660         return ERR_DM_FAILED;
1661     }
1662     pBaseRsp->SetErrCode(reply.ReadInt32());
1663     return DM_OK;
1664 }
1665 
ON_IPC_SET_REQUEST(GET_NETWORKID_BY_UDID,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1666 ON_IPC_SET_REQUEST(GET_NETWORKID_BY_UDID, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1667 {
1668     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
1669     std::string pkgName = pReq->GetPkgName();
1670     std::string udid = pReq->GetUdid();
1671     if (!data.WriteString(pkgName)) {
1672         return ERR_DM_IPC_WRITE_FAILED;
1673     }
1674     if (!data.WriteString(udid)) {
1675         return ERR_DM_IPC_WRITE_FAILED;
1676     }
1677     return DM_OK;
1678 }
1679 
ON_IPC_READ_RESPONSE(GET_NETWORKID_BY_UDID,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1680 ON_IPC_READ_RESPONSE(GET_NETWORKID_BY_UDID, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1681 {
1682     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
1683     pRsp->SetErrCode(reply.ReadInt32());
1684     pRsp->SetNetWorkId(reply.ReadString());
1685     return DM_OK;
1686 }
1687 
ON_IPC_CMD(SERVER_DEVICE_SCREEN_STATE_NOTIFY,MessageParcel & data,MessageParcel & reply)1688 ON_IPC_CMD(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply)
1689 {
1690     std::string pkgName = data.ReadString();
1691     DmDeviceInfo dmDeviceInfo;
1692     DecodeDmDeviceInfo(data, dmDeviceInfo);
1693     DeviceManagerNotify::GetInstance().OnDeviceScreenStatus(pkgName, dmDeviceInfo);
1694 
1695     reply.WriteInt32(DM_OK);
1696     return DM_OK;
1697 }
1698 
ON_IPC_SET_REQUEST(GET_DEVICE_SCREEN_STATUS,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1699 ON_IPC_SET_REQUEST(GET_DEVICE_SCREEN_STATUS, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1700 {
1701     std::shared_ptr<IpcGetDeviceScreenStatusReq> pReq = std::static_pointer_cast<IpcGetDeviceScreenStatusReq>(pBaseReq);
1702     std::string pkgName = pReq->GetPkgName();
1703     std::string networkId = pReq->GetNetWorkId();
1704     if (!data.WriteString(pkgName)) {
1705         return ERR_DM_IPC_WRITE_FAILED;
1706     }
1707     if (!data.WriteString(networkId)) {
1708         return ERR_DM_IPC_WRITE_FAILED;
1709     }
1710     return DM_OK;
1711 }
1712 
ON_IPC_READ_RESPONSE(GET_DEVICE_SCREEN_STATUS,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1713 ON_IPC_READ_RESPONSE(GET_DEVICE_SCREEN_STATUS, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1714 {
1715     std::shared_ptr<IpcGetDeviceScreenStatusRsp> pRsp = std::static_pointer_cast<IpcGetDeviceScreenStatusRsp>(pBaseRsp);
1716     pRsp->SetErrCode(reply.ReadInt32());
1717     pRsp->SetScreenStatus(reply.ReadInt32());
1718     return DM_OK;
1719 }
1720 
ON_IPC_CMD(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY,MessageParcel & data,MessageParcel & reply)1721 ON_IPC_CMD(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, MessageParcel &data, MessageParcel &reply)
1722 {
1723     std::string pkgName = data.ReadString();
1724     std::string proofInfo = data.ReadString();
1725     uint16_t deviceTypeId = data.ReadUint16();
1726     int32_t errCode = data.ReadInt32();
1727     DeviceManagerNotify::GetInstance().OnCredentialAuthStatus(pkgName, proofInfo, deviceTypeId, errCode);
1728 
1729     reply.WriteInt32(DM_OK);
1730     return DM_OK;
1731 }
1732 } // namespace DistributedHardware
1733 } // namespace OHOS