• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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_device_profile_info.h"
22 #include "dm_log.h"
23 #include "ipc_acl_profile_req.h"
24 #include "ipc_authenticate_device_req.h"
25 #include "ipc_bind_device_req.h"
26 #include "ipc_bind_target_req.h"
27 #include "ipc_check_access_control.h"
28 #include "ipc_cmd_register.h"
29 #include "ipc_common_param_req.h"
30 #include "ipc_create_pin_holder_req.h"
31 #include "ipc_destroy_pin_holder_req.h"
32 #include "ipc_def.h"
33 #include "ipc_export_auth_code_rsp.h"
34 #include "ipc_generate_encrypted_uuid_req.h"
35 #include "ipc_get_anony_local_udid_rsp.h"
36 #include "ipc_get_device_icon_info_req.h"
37 #include "ipc_get_device_info_rsp.h"
38 #include "ipc_get_device_network_id_list_req.h"
39 #include "ipc_get_device_network_id_list_rsp.h"
40 #include "ipc_get_device_profile_info_list_req.h"
41 #include "ipc_get_device_screen_status_req.h"
42 #include "ipc_get_device_screen_status_rsp.h"
43 #include "ipc_get_encrypted_uuid_req.h"
44 #include "ipc_get_info_by_network_rsp.h"
45 #include "ipc_get_info_by_network_req.h"
46 #include "ipc_get_local_device_info_rsp.h"
47 #include "ipc_get_local_display_device_name_req.h"
48 #include "ipc_get_local_display_device_name_rsp.h"
49 #include "ipc_get_localserviceinfo_rsp.h"
50 #include "ipc_get_trustdevice_req.h"
51 #include "ipc_get_trustdevice_rsp.h"
52 #include "ipc_import_auth_code_req.h"
53 #include "ipc_model_codec.h"
54 #include "ipc_notify_event_req.h"
55 #include "ipc_put_device_profile_info_list_req.h"
56 #include "ipc_register_listener_req.h"
57 #include "ipc_register_serviceinfo_req.h"
58 #include "ipc_req.h"
59 #include "ipc_rsp.h"
60 #include "ipc_set_credential_req.h"
61 #include "ipc_set_credential_rsp.h"
62 #include "ipc_set_local_device_name_req.h"
63 #include "ipc_set_remote_device_name_req.h"
64 #include "ipc_set_useroperation_req.h"
65 #include "ipc_sync_callback_req.h"
66 #include "ipc_permission_req.h"
67 #include "ipc_publish_req.h"
68 #include "ipc_unbind_device_req.h"
69 #include "ipc_unpublish_req.h"
70 #include "ipc_unauthenticate_device_req.h"
71 #include "securec.h"
72 namespace OHOS { class IRemoteObject; }
73 
74 namespace OHOS {
75 namespace DistributedHardware {
76 namespace {
77 const int32_t DM_MAX_TRUST_DEVICE_NUM = 200;
78 }
79 
ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)80 ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
81 {
82     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
83     std::shared_ptr<IpcRegisterListenerReq> pReq = std::static_pointer_cast<IpcRegisterListenerReq>(pBaseReq);
84     std::string pkgName = pReq->GetPkgName();
85     sptr<IRemoteObject> listener = pReq->GetListener();
86     if (!data.WriteString(pkgName)) {
87         LOGE("write pkgName failed");
88         return ERR_DM_IPC_WRITE_FAILED;
89     }
90     if (!data.WriteRemoteObject(listener)) {
91         LOGE("write listener failed");
92         return ERR_DM_IPC_WRITE_FAILED;
93     }
94     return DM_OK;
95 }
96 
ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)97 ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
98 {
99     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
100     pBaseRsp->SetErrCode(reply.ReadInt32());
101     return DM_OK;
102 }
103 
ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)104 ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
105 {
106     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
107     std::string pkgName = pBaseReq->GetPkgName();
108     if (!data.WriteString(pkgName)) {
109         LOGE("write papam failed");
110         return ERR_DM_IPC_WRITE_FAILED;
111     }
112     return DM_OK;
113 }
114 
ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)115 ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
116 {
117     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
118     pBaseRsp->SetErrCode(reply.ReadInt32());
119     return DM_OK;
120 }
121 
ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)122 ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
123 {
124     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
125     std::shared_ptr<IpcGetTrustDeviceReq> pReq = std::static_pointer_cast<IpcGetTrustDeviceReq>(pBaseReq);
126     std::string pkgName = pReq->GetPkgName();
127     std::string extra = pReq->GetExtra();
128     bool isRefresh = pReq->GetRefresh();
129     if (!data.WriteString(pkgName)) {
130         LOGE("write pkg failed");
131         return ERR_DM_IPC_WRITE_FAILED;
132     }
133     if (!data.WriteString(extra)) {
134         LOGE("write extra failed");
135         return ERR_DM_IPC_WRITE_FAILED;
136     }
137     if (!data.WriteBool(isRefresh)) {
138         LOGE("write isRefresh failed");
139         return ERR_DM_IPC_WRITE_FAILED;
140     }
141     return DM_OK;
142 }
143 
ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)144 ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
145 {
146     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
147     std::shared_ptr<IpcGetTrustDeviceRsp> pRsp = std::static_pointer_cast<IpcGetTrustDeviceRsp>(pBaseRsp);
148     int32_t deviceNum = reply.ReadInt32();
149     if (deviceNum > 0 && deviceNum <= DM_MAX_TRUST_DEVICE_NUM) {
150         std::vector<DmDeviceInfo> deviceInfoVec;
151         for (int32_t i = 0; i < deviceNum; ++i) {
152             DmDeviceInfo deviceInfo;
153             IpcModelCodec::DecodeDmDeviceInfo(reply, deviceInfo);
154             deviceInfoVec.emplace_back(deviceInfo);
155         }
156         pRsp->SetDeviceVec(deviceInfoVec);
157     }
158     pRsp->SetErrCode(reply.ReadInt32());
159     return DM_OK;
160 }
161 
ON_IPC_SET_REQUEST(GET_DEVICE_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)162 ON_IPC_SET_REQUEST(GET_DEVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
163 {
164     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
165     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
166     std::string networkId = pReq->GetNetWorkId();
167     if (!data.WriteString(networkId)) {
168         return ERR_DM_IPC_WRITE_FAILED;
169     }
170     return DM_OK;
171 }
172 
ON_IPC_SET_REQUEST(GET_ALL_TRUST_DEVICE_LIST,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)173 ON_IPC_SET_REQUEST(GET_ALL_TRUST_DEVICE_LIST, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
174 {
175     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
176     std::shared_ptr<IpcGetTrustDeviceReq> pReq = std::static_pointer_cast<IpcGetTrustDeviceReq>(pBaseReq);
177     std::string pkgName = pReq->GetPkgName();
178     std::string extra = pReq->GetExtra();
179     if (!data.WriteString(pkgName)) {
180         LOGE("write pkg failed");
181         return ERR_DM_IPC_WRITE_FAILED;
182     }
183     if (!data.WriteString(extra)) {
184         LOGE("write extra failed");
185         return ERR_DM_IPC_WRITE_FAILED;
186     }
187     return DM_OK;
188 }
189 
ON_IPC_READ_RESPONSE(GET_ALL_TRUST_DEVICE_LIST,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)190 ON_IPC_READ_RESPONSE(GET_ALL_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
191 {
192     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
193     std::shared_ptr<IpcGetTrustDeviceRsp> pRsp = std::static_pointer_cast<IpcGetTrustDeviceRsp>(pBaseRsp);
194     int32_t deviceNum = reply.ReadInt32();
195     if (deviceNum > 0 && deviceNum <= DM_MAX_TRUST_DEVICE_NUM) {
196         std::vector<DmDeviceInfo> deviceInfoVec;
197         for (int32_t i = 0; i < deviceNum; ++i) {
198             DmDeviceInfo deviceInfo;
199             IpcModelCodec::DecodeDmDeviceInfo(reply, deviceInfo);
200             deviceInfoVec.emplace_back(deviceInfo);
201         }
202         pRsp->SetDeviceVec(deviceInfoVec);
203     }
204     pRsp->SetErrCode(reply.ReadInt32());
205     return DM_OK;
206 }
207 
ON_IPC_READ_RESPONSE(GET_DEVICE_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)208 ON_IPC_READ_RESPONSE(GET_DEVICE_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
209 {
210     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
211     std::shared_ptr<IpcGetDeviceInfoRsp> pRsp = std::static_pointer_cast<IpcGetDeviceInfoRsp>(pBaseRsp);
212     DmDeviceInfo deviceInfo;
213     IpcModelCodec::DecodeDmDeviceInfo(reply, deviceInfo);
214     pRsp->SetDeviceInfo(deviceInfo);
215     pRsp->SetErrCode(reply.ReadInt32());
216     return DM_OK;
217 }
218 
ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)219 ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
220 {
221     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
222     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
223     std::string pkgName = pReq->GetPkgName();
224     if (!data.WriteString(pkgName)) {
225         return ERR_DM_IPC_WRITE_FAILED;
226     }
227     return DM_OK;
228 }
229 
ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)230 ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
231 {
232     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
233     std::shared_ptr<IpcGetLocalDeviceInfoRsp> pRsp = std::static_pointer_cast<IpcGetLocalDeviceInfoRsp>(pBaseRsp);
234     DmDeviceInfo localDeviceInfo;
235     IpcModelCodec::DecodeDmDeviceInfo(reply, localDeviceInfo);
236     pRsp->SetLocalDeviceInfo(localDeviceInfo);
237     pRsp->SetErrCode(reply.ReadInt32());
238     return DM_OK;
239 }
240 
ON_IPC_SET_REQUEST(GET_UDID_BY_NETWORK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)241 ON_IPC_SET_REQUEST(GET_UDID_BY_NETWORK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
242 {
243     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
244     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
245     std::string pkgName = pReq->GetPkgName();
246     std::string netWorkId = pReq->GetNetWorkId();
247     if (!data.WriteString(pkgName)) {
248         return ERR_DM_IPC_WRITE_FAILED;
249     }
250     if (!data.WriteString(netWorkId)) {
251         return ERR_DM_IPC_WRITE_FAILED;
252     }
253     return DM_OK;
254 }
255 
ON_IPC_READ_RESPONSE(GET_UDID_BY_NETWORK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)256 ON_IPC_READ_RESPONSE(GET_UDID_BY_NETWORK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
257 {
258     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
259     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
260     pRsp->SetErrCode(reply.ReadInt32());
261     pRsp->SetUdid(reply.ReadString());
262     return DM_OK;
263 }
264 
ON_IPC_SET_REQUEST(GET_UUID_BY_NETWORK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)265 ON_IPC_SET_REQUEST(GET_UUID_BY_NETWORK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
266 {
267     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
268     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
269     std::string pkgName = pReq->GetPkgName();
270     std::string netWorkId = pReq->GetNetWorkId();
271     if (!data.WriteString(pkgName)) {
272         return ERR_DM_IPC_WRITE_FAILED;
273     }
274     if (!data.WriteString(netWorkId)) {
275         return ERR_DM_IPC_WRITE_FAILED;
276     }
277     return DM_OK;
278 }
279 
ON_IPC_READ_RESPONSE(GET_UUID_BY_NETWORK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)280 ON_IPC_READ_RESPONSE(GET_UUID_BY_NETWORK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
281 {
282     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
283     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
284     pRsp->SetErrCode(reply.ReadInt32());
285     pRsp->SetUuid(reply.ReadString());
286     return DM_OK;
287 }
288 
ON_IPC_SET_REQUEST(PUBLISH_DEVICE_DISCOVER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)289 ON_IPC_SET_REQUEST(PUBLISH_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
290 {
291     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
292     std::shared_ptr<IpcPublishReq> pReq = std::static_pointer_cast<IpcPublishReq>(pBaseReq);
293     std::string pkgName = pReq->GetPkgName();
294     const DmPublishInfo dmPublishInfo = pReq->GetPublishInfo();
295     if (!data.WriteString(pkgName)) {
296         LOGE("write pkgName failed");
297         return ERR_DM_IPC_WRITE_FAILED;
298     }
299     if (!data.WriteRawData(&dmPublishInfo, sizeof(DmPublishInfo))) {
300         LOGE("write dmPublishInfo failed");
301         return ERR_DM_IPC_WRITE_FAILED;
302     }
303     return DM_OK;
304 }
305 
ON_IPC_READ_RESPONSE(PUBLISH_DEVICE_DISCOVER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)306 ON_IPC_READ_RESPONSE(PUBLISH_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
307 {
308     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
309     pBaseRsp->SetErrCode(reply.ReadInt32());
310     return DM_OK;
311 }
312 
ON_IPC_SET_REQUEST(UNPUBLISH_DEVICE_DISCOVER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)313 ON_IPC_SET_REQUEST(UNPUBLISH_DEVICE_DISCOVER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
314 {
315     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
316     std::shared_ptr<IpcUnPublishReq> pReq = std::static_pointer_cast<IpcUnPublishReq>(pBaseReq);
317     std::string pkgName = pReq->GetPkgName();
318     int32_t publishId = pReq->GetPublishId();
319     if (!data.WriteString(pkgName)) {
320         LOGE("write pkgName failed");
321         return ERR_DM_IPC_WRITE_FAILED;
322     }
323     if (!data.WriteInt32(publishId)) {
324         LOGE("write publishId failed");
325         return ERR_DM_IPC_WRITE_FAILED;
326     }
327     return DM_OK;
328 }
329 
ON_IPC_READ_RESPONSE(UNPUBLISH_DEVICE_DISCOVER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)330 ON_IPC_READ_RESPONSE(UNPUBLISH_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
331 {
332     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
333     pBaseRsp->SetErrCode(reply.ReadInt32());
334     return DM_OK;
335 }
336 
ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)337 ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
338 {
339     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
340     std::shared_ptr<IpcAuthenticateDeviceReq> pReq = std::static_pointer_cast<IpcAuthenticateDeviceReq>(pBaseReq);
341     std::string pkgName = pReq->GetPkgName();
342     std::string extra = pReq->GetExtra();
343     int32_t authType = pReq->GetAuthType();
344     DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
345     std::string deviceId = deviceInfo.deviceId;
346 
347     if (!data.WriteString(pkgName)) {
348         LOGE("write pkgName failed");
349         return ERR_DM_IPC_WRITE_FAILED;
350     }
351     if (!data.WriteString(extra)) {
352         LOGE("write extra failed");
353         return ERR_DM_IPC_WRITE_FAILED;
354     }
355     if (!data.WriteString(deviceId)) {
356         LOGE("write deviceId failed");
357         return ERR_DM_IPC_WRITE_FAILED;
358     }
359     if (!data.WriteInt32(authType)) {
360         LOGE("write pkgName failed");
361         return ERR_DM_IPC_WRITE_FAILED;
362     }
363     return DM_OK;
364 }
365 
ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)366 ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
367 {
368     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
369     pBaseRsp->SetErrCode(reply.ReadInt32());
370     return DM_OK;
371 }
372 
ON_IPC_SET_REQUEST(UNAUTHENTICATE_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)373 ON_IPC_SET_REQUEST(UNAUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
374 {
375     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
376     std::shared_ptr<IpcUnAuthenticateDeviceReq> pReq = std::static_pointer_cast<IpcUnAuthenticateDeviceReq>(pBaseReq);
377     std::string pkgName = pReq->GetPkgName();
378     DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
379     std::string networkId = deviceInfo.networkId;
380     if (!data.WriteString(pkgName)) {
381         LOGE("write pkgName failed");
382         return ERR_DM_IPC_WRITE_FAILED;
383     }
384     if (!data.WriteString(networkId)) {
385         LOGE("write extra failed");
386         return ERR_DM_IPC_WRITE_FAILED;
387     }
388     return DM_OK;
389 }
390 
ON_IPC_READ_RESPONSE(UNAUTHENTICATE_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)391 ON_IPC_READ_RESPONSE(UNAUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
392 {
393     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
394     pBaseRsp->SetErrCode(reply.ReadInt32());
395     return DM_OK;
396 }
397 
ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)398 ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
399 {
400     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
401     std::shared_ptr<IpcGetOperationReq> pReq = std::static_pointer_cast<IpcGetOperationReq>(pBaseReq);
402     std::string pkgName = pReq->GetPkgName();
403     int32_t action = pReq->GetOperation();
404     std::string params = pReq->GetParams();
405 
406     if (!data.WriteString(pkgName)) {
407         LOGE("write pkgName failed");
408         return ERR_DM_IPC_WRITE_FAILED;
409     }
410     if (!data.WriteInt32(action)) {
411         LOGE("write action failed");
412         return ERR_DM_IPC_WRITE_FAILED;
413     }
414     if (!data.WriteString(params)) {
415         LOGE("write params failed");
416         return ERR_DM_IPC_WRITE_FAILED;
417     }
418 
419     return DM_OK;
420 }
421 
ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)422 ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
423 {
424     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
425     pBaseRsp->SetErrCode(reply.ReadInt32());
426     return DM_OK;
427 }
428 
ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY,MessageParcel & data,MessageParcel & reply)429 ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply)
430 {
431     std::string pkgName = data.ReadString();
432     DmDeviceState deviceState = static_cast<DmDeviceState>(data.ReadInt32());
433     DmDeviceInfo dmDeviceInfo;
434     IpcModelCodec::DecodeDmDeviceInfo(data, dmDeviceInfo);
435 
436     DmDeviceBasicInfo dmDeviceBasicInfo;
437     IpcModelCodec::DecodeDmDeviceBasicInfo(data, dmDeviceBasicInfo);
438     switch (deviceState) {
439         case DEVICE_STATE_ONLINE:
440             DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceInfo);
441             DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceBasicInfo);
442             break;
443         case DEVICE_STATE_OFFLINE:
444             DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceInfo);
445             DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceBasicInfo);
446             break;
447         case DEVICE_INFO_CHANGED:
448             DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceInfo);
449             DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceBasicInfo);
450             break;
451         case DEVICE_INFO_READY:
452             DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceInfo);
453             DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceBasicInfo);
454             break;
455         default:
456             LOGE("unknown device state:%{public}d", deviceState);
457             break;
458     }
459     reply.WriteInt32(DM_OK);
460     return DM_OK;
461 }
462 
ON_IPC_CMD(SERVER_DEVICE_FOUND,MessageParcel & data,MessageParcel & reply)463 ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply)
464 {
465     std::string pkgName = data.ReadString();
466     int16_t subscribeId = data.ReadInt16();
467     DmDeviceInfo dmDeviceInfo;
468     IpcModelCodec::DecodeDmDeviceInfo(data, dmDeviceInfo);
469     DmDeviceBasicInfo devBasicInfo;
470     IpcModelCodec::DecodeDmDeviceBasicInfo(data, devBasicInfo);
471     DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceInfo);
472     DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, devBasicInfo);
473     reply.WriteInt32(DM_OK);
474     return DM_OK;
475 }
476 
ON_IPC_CMD(SERVER_DEVICE_DISCOVERY,MessageParcel & data,MessageParcel & reply)477 ON_IPC_CMD(SERVER_DEVICE_DISCOVERY, MessageParcel &data, MessageParcel &reply)
478 {
479     std::string pkgName = data.ReadString();
480     int16_t subscribeId = data.ReadInt16();
481     DmDeviceBasicInfo dmDeviceBasicInfo;
482     IpcModelCodec::DecodeDmDeviceBasicInfo(data, dmDeviceBasicInfo);
483     DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceBasicInfo);
484     reply.WriteInt32(DM_OK);
485     return DM_OK;
486 }
487 
ON_IPC_CMD(SERVER_DISCOVER_FINISH,MessageParcel & data,MessageParcel & reply)488 ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply)
489 {
490     std::string pkgName = data.ReadString();
491     int16_t subscribeId = data.ReadInt16();
492     int32_t failedReason = data.ReadInt32();
493 
494     if (failedReason == DM_OK) {
495         DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId);
496     } else {
497         DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason);
498     }
499     reply.WriteInt32(DM_OK);
500     return DM_OK;
501 }
502 
ON_IPC_CMD(SERVER_PUBLISH_FINISH,MessageParcel & data,MessageParcel & reply)503 ON_IPC_CMD(SERVER_PUBLISH_FINISH, MessageParcel &data, MessageParcel &reply)
504 {
505     std::string pkgName = data.ReadString();
506     int32_t publishId = data.ReadInt32();
507     int32_t publishResult = data.ReadInt32();
508 
509     DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, publishResult);
510     if (!reply.WriteInt32(DM_OK)) {
511         LOGE("write return failed");
512         return ERR_DM_IPC_WRITE_FAILED;
513     }
514     return DM_OK;
515 }
516 
ON_IPC_CMD(SERVER_AUTH_RESULT,MessageParcel & data,MessageParcel & reply)517 ON_IPC_CMD(SERVER_AUTH_RESULT, MessageParcel &data, MessageParcel &reply)
518 {
519     std::string pkgName = data.ReadString();
520     std::string deviceId = data.ReadString();
521     std::string token = data.ReadString();
522     int32_t status = data.ReadInt32();
523     int32_t reason = data.ReadInt32();
524     DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, (uint32_t)status, reason);
525     reply.WriteInt32(DM_OK);
526     return DM_OK;
527 }
528 
ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY,MessageParcel & data,MessageParcel & reply)529 ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, MessageParcel &data, MessageParcel &reply)
530 {
531     std::string packagename = data.ReadString();
532     std::string paramJson = data.ReadString();
533     DeviceManagerNotify::GetInstance().OnUiCall(packagename, paramJson);
534     if (!reply.WriteInt32(DM_OK)) {
535         LOGE("write return failed");
536         return ERR_DM_IPC_WRITE_FAILED;
537     }
538     return DM_OK;
539 }
540 
ON_IPC_SET_REQUEST(REQUEST_CREDENTIAL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)541 ON_IPC_SET_REQUEST(REQUEST_CREDENTIAL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
542 {
543     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
544     std::shared_ptr<IpcSetCredentialReq> pReq = std::static_pointer_cast<IpcSetCredentialReq>(pBaseReq);
545     std::string pkgName = pReq->GetPkgName();
546     std::string requestJsonStr = pReq->GetCredentialParam();
547 
548     if (!data.WriteString(pkgName)) {
549         LOGE("write pkg failed.");
550         return ERR_DM_IPC_WRITE_FAILED;
551     }
552     if (!data.WriteString(requestJsonStr)) {
553         LOGE("write requestJsonStr failed.");
554         return ERR_DM_IPC_WRITE_FAILED;
555     }
556     return DM_OK;
557 }
558 
ON_IPC_READ_RESPONSE(REQUEST_CREDENTIAL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)559 ON_IPC_READ_RESPONSE(REQUEST_CREDENTIAL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
560 {
561     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
562     std::shared_ptr<IpcSetCredentialRsp> pRsp = std::static_pointer_cast<IpcSetCredentialRsp>(pBaseRsp);
563     pRsp->SetErrCode(reply.ReadInt32());
564     if (pRsp->GetErrCode() == DM_OK) {
565         std::string returnJsonStr = reply.ReadString();
566         pRsp->SetCredentialResult(returnJsonStr);
567     }
568     return DM_OK;
569 }
570 
ON_IPC_SET_REQUEST(SERVER_GET_DMFA_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)571 ON_IPC_SET_REQUEST(SERVER_GET_DMFA_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
572 {
573     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
574     std::shared_ptr<IpcSetCredentialReq> pReq = std::static_pointer_cast<IpcSetCredentialReq>(pBaseReq);
575     std::string pkgName = pReq->GetPkgName();
576     std::string reqJsonStr = pReq->GetCredentialParam();
577     if (!data.WriteString(pkgName)) {
578         LOGE("write pkg failed.");
579         return ERR_DM_IPC_WRITE_FAILED;
580     }
581     if (!data.WriteString(reqJsonStr)) {
582         LOGE("write returnJsonStr failed.");
583         return ERR_DM_IPC_WRITE_FAILED;
584     }
585     return DM_OK;
586 }
587 
ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)588 ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
589 {
590     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
591     std::shared_ptr<IpcSetCredentialRsp> pRsp = std::static_pointer_cast<IpcSetCredentialRsp>(pBaseRsp);
592     pRsp->SetErrCode(reply.ReadInt32());
593     if (pRsp->GetErrCode() == DM_OK) {
594         std::string returnJsonStr = reply.ReadString();
595         pRsp->SetCredentialResult(returnJsonStr);
596     }
597     return DM_OK;
598 }
599 
ON_IPC_SET_REQUEST(IMPORT_CREDENTIAL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)600 ON_IPC_SET_REQUEST(IMPORT_CREDENTIAL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
601 {
602     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
603     std::shared_ptr<IpcSetCredentialReq> pReq = std::static_pointer_cast<IpcSetCredentialReq>(pBaseReq);
604     std::string pkgName = pReq->GetPkgName();
605     std::string credentialInfo = pReq->GetCredentialParam();
606     if (!data.WriteString(pkgName)) {
607         LOGE("write pkg failed.");
608         return ERR_DM_IPC_WRITE_FAILED;
609     }
610     if (!data.WriteString(credentialInfo)) {
611         LOGE("write credentialInfo failed.");
612         return ERR_DM_IPC_WRITE_FAILED;
613     }
614     return DM_OK;
615 }
616 
ON_IPC_READ_RESPONSE(IMPORT_CREDENTIAL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)617 ON_IPC_READ_RESPONSE(IMPORT_CREDENTIAL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
618 {
619     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
620     std::string outParaStr = reply.ReadString();
621     std::map<std::string, std::string> outputResult;
622     ParseMapFromJsonString(outParaStr, outputResult);
623     if (outputResult[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
624         pBaseRsp->SetErrCode(reply.ReadInt32());
625     }
626     if (outputResult[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
627         std::shared_ptr<IpcSetCredentialRsp> pRsp = std::static_pointer_cast<IpcSetCredentialRsp>(pBaseRsp);
628         pRsp->SetErrCode(reply.ReadInt32());
629         if (pRsp->GetErrCode() == DM_OK) {
630             pRsp->SetCredentialResult(outputResult[DM_CREDENTIAL_RETURNJSONSTR]);
631         }
632     }
633     return DM_OK;
634 }
635 
ON_IPC_SET_REQUEST(DELETE_CREDENTIAL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)636 ON_IPC_SET_REQUEST(DELETE_CREDENTIAL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
637 {
638     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
639     std::shared_ptr<IpcSetCredentialReq> pReq = std::static_pointer_cast<IpcSetCredentialReq>(pBaseReq);
640     std::string pkgName = pReq->GetPkgName();
641     std::string deleteInfo = pReq->GetCredentialParam();
642 
643     if (!data.WriteString(pkgName)) {
644         LOGE("write pkg failed.");
645         return ERR_DM_IPC_WRITE_FAILED;
646     }
647     if (!data.WriteString(deleteInfo)) {
648         LOGE("write deleteInfo failed.");
649         return ERR_DM_IPC_WRITE_FAILED;
650     }
651     return DM_OK;
652 }
653 
ON_IPC_READ_RESPONSE(DELETE_CREDENTIAL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)654 ON_IPC_READ_RESPONSE(DELETE_CREDENTIAL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
655 {
656     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
657     std::string outParaStr = reply.ReadString();
658     std::map<std::string, std::string> outputResult;
659     ParseMapFromJsonString(outParaStr, outputResult);
660     if (outputResult[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
661         pBaseRsp->SetErrCode(reply.ReadInt32());
662     }
663     if (outputResult[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
664         std::shared_ptr<IpcSetCredentialRsp> pRsp = std::static_pointer_cast<IpcSetCredentialRsp>(pBaseRsp);
665         pRsp->SetErrCode(reply.ReadInt32());
666         if (pRsp->GetErrCode() == DM_OK) {
667             pRsp->SetCredentialResult(outputResult[DM_CREDENTIAL_RETURNJSONSTR]);
668         }
669     }
670     return DM_OK;
671 }
672 
ON_IPC_SET_REQUEST(REGISTER_CREDENTIAL_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)673 ON_IPC_SET_REQUEST(REGISTER_CREDENTIAL_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
674 {
675     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
676     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
677     std::string pkgName = pReq->GetPkgName();
678 
679     if (!data.WriteString(pkgName)) {
680         LOGE("write pkgName failed");
681         return ERR_DM_IPC_WRITE_FAILED;
682     }
683 
684     return DM_OK;
685 }
686 
ON_IPC_READ_RESPONSE(REGISTER_CREDENTIAL_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)687 ON_IPC_READ_RESPONSE(REGISTER_CREDENTIAL_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
688 {
689     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
690     pBaseRsp->SetErrCode(reply.ReadInt32());
691     return DM_OK;
692 }
693 
ON_IPC_SET_REQUEST(UNREGISTER_CREDENTIAL_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)694 ON_IPC_SET_REQUEST(UNREGISTER_CREDENTIAL_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
695 {
696     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
697     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
698     std::string pkgName = pReq->GetPkgName();
699 
700     if (!data.WriteString(pkgName)) {
701         LOGE("write pkgName failed");
702         return ERR_DM_IPC_WRITE_FAILED;
703     }
704 
705     return DM_OK;
706 }
707 
ON_IPC_READ_RESPONSE(UNREGISTER_CREDENTIAL_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)708 ON_IPC_READ_RESPONSE(UNREGISTER_CREDENTIAL_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
709 {
710     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
711     pBaseRsp->SetErrCode(reply.ReadInt32());
712     return DM_OK;
713 }
714 
ON_IPC_CMD(SERVER_CREDENTIAL_RESULT,MessageParcel & data,MessageParcel & reply)715 ON_IPC_CMD(SERVER_CREDENTIAL_RESULT, MessageParcel &data, MessageParcel &reply)
716 {
717     std::string pkgName = data.ReadString();
718     int32_t action = data.ReadInt32();
719     std::string credentialResult = data.ReadString();
720 
721     DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult);
722     reply.WriteInt32(DM_OK);
723     return DM_OK;
724 }
725 
ON_IPC_SET_REQUEST(NOTIFY_EVENT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)726 ON_IPC_SET_REQUEST(NOTIFY_EVENT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
727 {
728     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
729     std::shared_ptr<IpcNotifyEventReq> pReq = std::static_pointer_cast<IpcNotifyEventReq>(pBaseReq);
730     std::string pkgName = pReq->GetPkgName();
731     int32_t eventId = pReq->GetEventId();
732     std::string event = pReq->GetEvent();
733     if (!data.WriteString(pkgName)) {
734         LOGE("write pkgName failed");
735         return ERR_DM_IPC_WRITE_FAILED;
736     }
737     if (!data.WriteInt32(eventId)) {
738         LOGE("write eventId failed");
739         return ERR_DM_IPC_WRITE_FAILED;
740     }
741     if (!data.WriteString(event)) {
742         LOGE("write event failed");
743         return ERR_DM_IPC_WRITE_FAILED;
744     }
745     return DM_OK;
746 }
747 
ON_IPC_READ_RESPONSE(NOTIFY_EVENT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)748 ON_IPC_READ_RESPONSE(NOTIFY_EVENT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
749 {
750     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
751     pBaseRsp->SetErrCode(reply.ReadInt32());
752     return DM_OK;
753 }
754 
ON_IPC_SET_REQUEST(GET_ENCRYPTED_UUID_BY_NETWOEKID,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)755 ON_IPC_SET_REQUEST(GET_ENCRYPTED_UUID_BY_NETWOEKID, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
756 {
757     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
758     std::shared_ptr<IpcGetEncryptedUuidReq> pReq = std::static_pointer_cast<IpcGetEncryptedUuidReq>(pBaseReq);
759     std::string pkgName = pReq->GetPkgName();
760     std::string netWorkId = pReq->GetNetworkId();
761     if (!data.WriteString(pkgName)) {
762         LOGE("write pkgName failed");
763         return ERR_DM_IPC_WRITE_FAILED;
764     }
765     if (!data.WriteString(netWorkId)) {
766         LOGE("write netWorkId failed");
767         return ERR_DM_IPC_WRITE_FAILED;
768     }
769     return DM_OK;
770 }
771 
ON_IPC_READ_RESPONSE(GET_ENCRYPTED_UUID_BY_NETWOEKID,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)772 ON_IPC_READ_RESPONSE(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
773 {
774     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
775     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
776     pRsp->SetErrCode(reply.ReadInt32());
777     pRsp->SetUuid(reply.ReadString());
778     return DM_OK;
779 }
780 
ON_IPC_SET_REQUEST(GENERATE_ENCRYPTED_UUID,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)781 ON_IPC_SET_REQUEST(GENERATE_ENCRYPTED_UUID, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
782 {
783     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
784     std::shared_ptr<IpcGenerateEncryptedUuidReq> pReq = std::static_pointer_cast<IpcGenerateEncryptedUuidReq>(pBaseReq);
785     std::string pkgName = pReq->GetPkgName();
786     std::string uuid = pReq->GetUuid();
787     std::string appId = pReq->GetAppId();
788     if (!data.WriteString(pkgName)) {
789         LOGE("write pkgName failed");
790         return ERR_DM_IPC_WRITE_FAILED;
791     }
792     if (!data.WriteString(uuid)) {
793         LOGE("write uuid failed");
794         return ERR_DM_IPC_WRITE_FAILED;
795     }
796     if (!data.WriteString(appId)) {
797         LOGE("write appId failed");
798         return ERR_DM_IPC_WRITE_FAILED;
799     }
800     return DM_OK;
801 }
802 
ON_IPC_READ_RESPONSE(GENERATE_ENCRYPTED_UUID,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)803 ON_IPC_READ_RESPONSE(GENERATE_ENCRYPTED_UUID, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
804 {
805     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
806     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
807     pRsp->SetErrCode(reply.ReadInt32());
808     pRsp->SetUuid(reply.ReadString());
809     return DM_OK;
810 }
811 
ON_IPC_SET_REQUEST(BIND_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)812 ON_IPC_SET_REQUEST(BIND_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
813 {
814     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
815     std::shared_ptr<IpcBindDeviceReq> pReq = std::static_pointer_cast<IpcBindDeviceReq>(pBaseReq);
816     std::string pkgName = pReq->GetPkgName();
817     std::string bindParam = pReq->GetBindParam();
818     int32_t bindType = pReq->GetBindType();
819     std::string deviceId = pReq->GetDeviceId();
820 
821     if (!data.WriteString(pkgName)) {
822         LOGE("write pkgName failed");
823         return ERR_DM_IPC_WRITE_FAILED;
824     }
825     if (!data.WriteString(bindParam)) {
826         LOGE("write bindParam failed");
827         return ERR_DM_IPC_WRITE_FAILED;
828     }
829     if (!data.WriteString(deviceId)) {
830         LOGE("write deviceId failed");
831         return ERR_DM_IPC_WRITE_FAILED;
832     }
833     if (!data.WriteInt32(bindType)) {
834         LOGE("write bindType failed");
835         return ERR_DM_IPC_WRITE_FAILED;
836     }
837     return DM_OK;
838 }
839 
ON_IPC_READ_RESPONSE(BIND_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)840 ON_IPC_READ_RESPONSE(BIND_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
841 {
842     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
843     pBaseRsp->SetErrCode(reply.ReadInt32());
844     return DM_OK;
845 }
846 
ON_IPC_SET_REQUEST(UNBIND_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)847 ON_IPC_SET_REQUEST(UNBIND_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
848 {
849     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
850     std::shared_ptr<IpcUnBindDeviceReq> pReq = std::static_pointer_cast<IpcUnBindDeviceReq>(pBaseReq);
851     std::string pkgName = pReq->GetPkgName();
852     std::string deviceId = pReq->GetDeviceId();
853     std::string extra = pReq->GetExtraInfo();
854 
855     if (!data.WriteString(pkgName)) {
856         LOGE("write pkgName failed");
857         return ERR_DM_IPC_WRITE_FAILED;
858     }
859     if (!data.WriteString(deviceId)) {
860         LOGE("write deviceId failed");
861         return ERR_DM_IPC_WRITE_FAILED;
862     }
863     if (!data.WriteString(extra)) {
864         LOGE("write extra failed");
865     }
866     return DM_OK;
867 }
868 
ON_IPC_READ_RESPONSE(UNBIND_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)869 ON_IPC_READ_RESPONSE(UNBIND_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
870 {
871     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
872     pBaseRsp->SetErrCode(reply.ReadInt32());
873     return DM_OK;
874 }
875 
ON_IPC_SET_REQUEST(GET_NETWORKTYPE_BY_NETWORK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)876 ON_IPC_SET_REQUEST(GET_NETWORKTYPE_BY_NETWORK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
877 {
878     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
879     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
880     std::string pkgName = pReq->GetPkgName();
881     std::string netWorkId = pReq->GetNetWorkId();
882     if (!data.WriteString(pkgName)) {
883         return ERR_DM_IPC_WRITE_FAILED;
884     }
885     if (!data.WriteString(netWorkId)) {
886         return ERR_DM_IPC_WRITE_FAILED;
887     }
888     return DM_OK;
889 }
890 
ON_IPC_READ_RESPONSE(GET_NETWORKTYPE_BY_NETWORK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)891 ON_IPC_READ_RESPONSE(GET_NETWORKTYPE_BY_NETWORK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
892 {
893     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
894     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
895     pRsp->SetErrCode(reply.ReadInt32());
896     pRsp->SetNetworkType(reply.ReadInt32());
897     return DM_OK;
898 }
899 
ON_IPC_SET_REQUEST(REGISTER_UI_STATE_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)900 ON_IPC_SET_REQUEST(REGISTER_UI_STATE_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
901 {
902     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
903     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
904     std::string pkgName = pReq->GetPkgName();
905     if (!data.WriteString(pkgName)) {
906         return ERR_DM_IPC_WRITE_FAILED;
907     }
908     return DM_OK;
909 }
910 
ON_IPC_READ_RESPONSE(REGISTER_UI_STATE_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)911 ON_IPC_READ_RESPONSE(REGISTER_UI_STATE_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
912 {
913     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
914     pBaseRsp->SetErrCode(reply.ReadInt32());
915     return DM_OK;
916 }
917 
ON_IPC_SET_REQUEST(UNREGISTER_UI_STATE_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)918 ON_IPC_SET_REQUEST(UNREGISTER_UI_STATE_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
919 {
920     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
921     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
922     std::string pkgName = pReq->GetPkgName();
923     if (!data.WriteString(pkgName)) {
924         return ERR_DM_IPC_WRITE_FAILED;
925     }
926     return DM_OK;
927 }
928 
ON_IPC_READ_RESPONSE(UNREGISTER_UI_STATE_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)929 ON_IPC_READ_RESPONSE(UNREGISTER_UI_STATE_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
930 {
931     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
932     pBaseRsp->SetErrCode(reply.ReadInt32());
933     return DM_OK;
934 }
935 
ON_IPC_SET_REQUEST(IMPORT_AUTH_CODE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)936 ON_IPC_SET_REQUEST(IMPORT_AUTH_CODE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
937 {
938     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
939     std::shared_ptr<IpcImportAuthCodeReq> pReq = std::static_pointer_cast<IpcImportAuthCodeReq>(pBaseReq);
940     std::string pkgName = pReq->GetPkgName();
941     std::string authCode = pReq->GetAuthCode();
942     if (!data.WriteString(pkgName)) {
943         return ERR_DM_IPC_WRITE_FAILED;
944     }
945     if (!data.WriteString(authCode)) {
946         return ERR_DM_IPC_WRITE_FAILED;
947     }
948     return DM_OK;
949 }
950 
ON_IPC_READ_RESPONSE(IMPORT_AUTH_CODE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)951 ON_IPC_READ_RESPONSE(IMPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
952 {
953     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
954     std::shared_ptr<IpcRsp> pRsp = std::static_pointer_cast<IpcRsp>(pBaseRsp);
955     pRsp->SetErrCode(reply.ReadInt32());
956     return DM_OK;
957 }
958 
ON_IPC_SET_REQUEST(EXPORT_AUTH_CODE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)959 ON_IPC_SET_REQUEST(EXPORT_AUTH_CODE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
960 {
961     LOGI("send export auth code request!");
962     return DM_OK;
963 }
964 
ON_IPC_READ_RESPONSE(EXPORT_AUTH_CODE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)965 ON_IPC_READ_RESPONSE(EXPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
966 {
967     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
968     std::shared_ptr<IpcExportAuthCodeRsp> pRsp = std::static_pointer_cast<IpcExportAuthCodeRsp>(pBaseRsp);
969     CHECK_NULL_RETURN(pRsp, ERR_DM_FAILED);
970     std::string authCode = reply.ReadString();
971     pRsp->SetAuthCode(authCode);
972     pRsp->SetErrCode(reply.ReadInt32());
973     return DM_OK;
974 }
975 
ON_IPC_SET_REQUEST(REGISTER_DISCOVERY_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)976 ON_IPC_SET_REQUEST(REGISTER_DISCOVERY_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
977 {
978     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
979     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
980     std::string pkgName = pReq->GetPkgName();
981     std::string discParaStr = pReq->GetFirstParam();
982     std::string filterOpStr = pReq->GetSecondParam();
983     if (!data.WriteString(pkgName)) {
984         LOGE("write pkgName failed");
985         return ERR_DM_IPC_WRITE_FAILED;
986     }
987     if (!data.WriteString(discParaStr)) {
988         LOGE("write discovery parameter failed");
989         return ERR_DM_IPC_WRITE_FAILED;
990     }
991     if (!data.WriteString(filterOpStr)) {
992         LOGE("write filter option parameter failed");
993         return ERR_DM_IPC_WRITE_FAILED;
994     }
995     return DM_OK;
996 }
997 
ON_IPC_READ_RESPONSE(REGISTER_DISCOVERY_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)998 ON_IPC_READ_RESPONSE(REGISTER_DISCOVERY_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
999 {
1000     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1001     pBaseRsp->SetErrCode(reply.ReadInt32());
1002     return DM_OK;
1003 }
1004 
ON_IPC_SET_REQUEST(UNREGISTER_DISCOVERY_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1005 ON_IPC_SET_REQUEST(UNREGISTER_DISCOVERY_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1006 {
1007     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1008     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1009     std::string pkgName = pReq->GetPkgName();
1010     std::string extraParaStr = pReq->GetFirstParam();
1011     if (!data.WriteString(pkgName)) {
1012         LOGE("write pkgName failed");
1013         return ERR_DM_IPC_WRITE_FAILED;
1014     }
1015     if (!data.WriteString(extraParaStr)) {
1016         LOGE("write extra parameter failed");
1017         return ERR_DM_IPC_WRITE_FAILED;
1018     }
1019     return DM_OK;
1020 }
1021 
ON_IPC_READ_RESPONSE(UNREGISTER_DISCOVERY_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1022 ON_IPC_READ_RESPONSE(UNREGISTER_DISCOVERY_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1023 {
1024     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1025     pBaseRsp->SetErrCode(reply.ReadInt32());
1026     return DM_OK;
1027 }
1028 
ON_IPC_SET_REQUEST(START_DISCOVERING,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1029 ON_IPC_SET_REQUEST(START_DISCOVERING, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1030 {
1031     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1032     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1033     std::string pkgName = pReq->GetPkgName();
1034     std::string discParaStr = pReq->GetFirstParam();
1035     std::string filterOpStr = pReq->GetSecondParam();
1036     if (!data.WriteString(pkgName)) {
1037         LOGE("write pkgName failed");
1038         return ERR_DM_IPC_WRITE_FAILED;
1039     }
1040     if (!data.WriteString(discParaStr)) {
1041         LOGE("write discovery parameter failed");
1042         return ERR_DM_IPC_WRITE_FAILED;
1043     }
1044     if (!data.WriteString(filterOpStr)) {
1045         LOGE("write filter option parameter failed");
1046         return ERR_DM_IPC_WRITE_FAILED;
1047     }
1048     return DM_OK;
1049 }
1050 
ON_IPC_READ_RESPONSE(START_DISCOVERING,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1051 ON_IPC_READ_RESPONSE(START_DISCOVERING, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1052 {
1053     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1054     pBaseRsp->SetErrCode(reply.ReadInt32());
1055     return DM_OK;
1056 }
1057 
ON_IPC_SET_REQUEST(STOP_DISCOVERING,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1058 ON_IPC_SET_REQUEST(STOP_DISCOVERING, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1059 {
1060     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1061     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1062     std::string pkgName = pReq->GetPkgName();
1063     std::string discParaStr = pReq->GetFirstParam();
1064     if (!data.WriteString(pkgName)) {
1065         LOGE("write pkgName failed");
1066         return ERR_DM_IPC_WRITE_FAILED;
1067     }
1068     if (!data.WriteString(discParaStr)) {
1069         LOGE("write discovery parameter failed");
1070         return ERR_DM_IPC_WRITE_FAILED;
1071     }
1072     return DM_OK;
1073 }
1074 
ON_IPC_READ_RESPONSE(STOP_DISCOVERING,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1075 ON_IPC_READ_RESPONSE(STOP_DISCOVERING, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1076 {
1077     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1078     pBaseRsp->SetErrCode(reply.ReadInt32());
1079     return DM_OK;
1080 }
1081 
ON_IPC_SET_REQUEST(START_ADVERTISING,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1082 ON_IPC_SET_REQUEST(START_ADVERTISING, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1083 {
1084     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1085     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1086     std::string pkgName = pReq->GetPkgName();
1087     std::string adverParaStr = pReq->GetFirstParam();
1088     if (!data.WriteString(pkgName)) {
1089         LOGE("write pkgName failed");
1090         return ERR_DM_IPC_WRITE_FAILED;
1091     }
1092     if (!data.WriteString(adverParaStr)) {
1093         LOGE("write advertising parameter failed");
1094         return ERR_DM_IPC_WRITE_FAILED;
1095     }
1096     return DM_OK;
1097 }
1098 
ON_IPC_READ_RESPONSE(START_ADVERTISING,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1099 ON_IPC_READ_RESPONSE(START_ADVERTISING, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1100 {
1101     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1102     pBaseRsp->SetErrCode(reply.ReadInt32());
1103     return DM_OK;
1104 }
1105 
ON_IPC_SET_REQUEST(STOP_ADVERTISING,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1106 ON_IPC_SET_REQUEST(STOP_ADVERTISING, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1107 {
1108     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1109     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1110     std::string pkgName = pReq->GetPkgName();
1111     std::string adverParaStr = pReq->GetFirstParam();
1112     if (!data.WriteString(pkgName)) {
1113         LOGE("write pkgName failed");
1114         return ERR_DM_IPC_WRITE_FAILED;
1115     }
1116     if (!data.WriteString(adverParaStr)) {
1117         LOGE("write advertising parameter failed");
1118         return ERR_DM_IPC_WRITE_FAILED;
1119     }
1120     return DM_OK;
1121 }
1122 
ON_IPC_READ_RESPONSE(STOP_ADVERTISING,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1123 ON_IPC_READ_RESPONSE(STOP_ADVERTISING, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1124 {
1125     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1126     pBaseRsp->SetErrCode(reply.ReadInt32());
1127     return DM_OK;
1128 }
1129 
ON_IPC_SET_REQUEST(BIND_TARGET,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1130 ON_IPC_SET_REQUEST(BIND_TARGET, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1131 {
1132     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1133     std::shared_ptr<IpcBindTargetReq> pReq = std::static_pointer_cast<IpcBindTargetReq>(pBaseReq);
1134     std::string pkgName = pReq->GetPkgName();
1135     PeerTargetId targetId = pReq->GetPeerTargetId();
1136     std::string bindParam = pReq->GetBindParam();
1137 
1138     if (!data.WriteString(pkgName)) {
1139         LOGE("write pkgName failed");
1140         return ERR_DM_IPC_WRITE_FAILED;
1141     }
1142     if (!IpcModelCodec::EncodePeerTargetId(targetId, data)) {
1143         LOGE("write peer target id failed");
1144         return ERR_DM_IPC_WRITE_FAILED;
1145     }
1146     if (!data.WriteString(bindParam)) {
1147         LOGE("write bind parameter string failed");
1148         return ERR_DM_IPC_WRITE_FAILED;
1149     }
1150     return DM_OK;
1151 }
1152 
ON_IPC_READ_RESPONSE(BIND_TARGET,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1153 ON_IPC_READ_RESPONSE(BIND_TARGET, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1154 {
1155     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1156     pBaseRsp->SetErrCode(reply.ReadInt32());
1157     return DM_OK;
1158 }
1159 
ON_IPC_SET_REQUEST(UNBIND_TARGET,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1160 ON_IPC_SET_REQUEST(UNBIND_TARGET, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1161 {
1162     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1163     std::shared_ptr<IpcBindTargetReq> pReq = std::static_pointer_cast<IpcBindTargetReq>(pBaseReq);
1164     std::string pkgName = pReq->GetPkgName();
1165     PeerTargetId targetId = pReq->GetPeerTargetId();
1166     std::string unbindParam = pReq->GetBindParam();
1167 
1168     if (!data.WriteString(pkgName)) {
1169         LOGE("write pkgName failed");
1170         return ERR_DM_IPC_WRITE_FAILED;
1171     }
1172     if (!IpcModelCodec::EncodePeerTargetId(targetId, data)) {
1173         LOGE("write peer target id failed");
1174         return ERR_DM_IPC_WRITE_FAILED;
1175     }
1176     if (!data.WriteString(unbindParam)) {
1177         LOGE("write unbind parameter string failed");
1178         return ERR_DM_IPC_WRITE_FAILED;
1179     }
1180     return DM_OK;
1181 }
1182 
ON_IPC_READ_RESPONSE(UNBIND_TARGET,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1183 ON_IPC_READ_RESPONSE(UNBIND_TARGET, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1184 {
1185     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1186     pBaseRsp->SetErrCode(reply.ReadInt32());
1187     return DM_OK;
1188 }
1189 
ON_IPC_CMD(BIND_TARGET_RESULT,MessageParcel & data,MessageParcel & reply)1190 ON_IPC_CMD(BIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply)
1191 {
1192     std::string pkgName = data.ReadString();
1193     PeerTargetId targetId;
1194     IpcModelCodec::DecodePeerTargetId(data, targetId);
1195     int32_t result = data.ReadInt32();
1196     int32_t status = data.ReadInt32();
1197     std::string content = data.ReadString();
1198 
1199     DeviceManagerNotify::GetInstance().OnBindResult(pkgName, targetId, result, status, content);
1200     reply.WriteInt32(DM_OK);
1201     return DM_OK;
1202 }
1203 
ON_IPC_CMD(UNBIND_TARGET_RESULT,MessageParcel & data,MessageParcel & reply)1204 ON_IPC_CMD(UNBIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply)
1205 {
1206     std::string pkgName = data.ReadString();
1207     PeerTargetId targetId;
1208     IpcModelCodec::DecodePeerTargetId(data, targetId);
1209     int32_t result = data.ReadInt32();
1210     std::string content = data.ReadString();
1211 
1212     DeviceManagerNotify::GetInstance().OnUnbindResult(pkgName, targetId, result, content);
1213     reply.WriteInt32(DM_OK);
1214     return DM_OK;
1215 }
1216 
ON_IPC_SET_REQUEST(REGISTER_PIN_HOLDER_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1217 ON_IPC_SET_REQUEST(REGISTER_PIN_HOLDER_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1218 {
1219     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1220     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
1221     std::string pkgName = pReq->GetPkgName();
1222     if (!data.WriteString(pkgName)) {
1223         return ERR_DM_IPC_WRITE_FAILED;
1224     }
1225     return DM_OK;
1226 }
1227 
ON_IPC_READ_RESPONSE(REGISTER_PIN_HOLDER_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1228 ON_IPC_READ_RESPONSE(REGISTER_PIN_HOLDER_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1229 {
1230     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1231     std::shared_ptr<IpcRsp> pRsp = std::static_pointer_cast<IpcRsp>(pBaseRsp);
1232     pRsp->SetErrCode(reply.ReadInt32());
1233     return DM_OK;
1234 }
1235 
ON_IPC_SET_REQUEST(CREATE_PIN_HOLDER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1236 ON_IPC_SET_REQUEST(CREATE_PIN_HOLDER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1237 {
1238     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1239     std::shared_ptr<IpcCreatePinHolderReq> pReq = std::static_pointer_cast<IpcCreatePinHolderReq>(pBaseReq);
1240     std::string pkgName = pReq->GetPkgName();
1241     PeerTargetId targetId = pReq->GetPeerTargetId();
1242     std::string payload = pReq->GetPayload();
1243     int32_t pinType = pReq->GetPinType();
1244     if (!data.WriteString(pkgName)) {
1245         return ERR_DM_IPC_WRITE_FAILED;
1246     }
1247     if (!IpcModelCodec::EncodePeerTargetId(targetId, data)) {
1248         LOGE("write peer target id failed");
1249         return ERR_DM_IPC_WRITE_FAILED;
1250     }
1251     if (!data.WriteString(payload)) {
1252         return ERR_DM_IPC_WRITE_FAILED;
1253     }
1254     if (!data.WriteInt32(pinType)) {
1255         return ERR_DM_IPC_WRITE_FAILED;
1256     }
1257     return DM_OK;
1258 }
1259 
ON_IPC_READ_RESPONSE(CREATE_PIN_HOLDER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1260 ON_IPC_READ_RESPONSE(CREATE_PIN_HOLDER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1261 {
1262     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1263     std::shared_ptr<IpcRsp> pRsp = std::static_pointer_cast<IpcRsp>(pBaseRsp);
1264     pRsp->SetErrCode(reply.ReadInt32());
1265     return DM_OK;
1266 }
1267 
ON_IPC_SET_REQUEST(DESTROY_PIN_HOLDER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1268 ON_IPC_SET_REQUEST(DESTROY_PIN_HOLDER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1269 {
1270     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1271     std::shared_ptr<IpcDestroyPinHolderReq> pReq = std::static_pointer_cast<IpcDestroyPinHolderReq>(pBaseReq);
1272     std::string pkgName = pReq->GetPkgName();
1273     PeerTargetId targetId = pReq->GetPeerTargetId();
1274     int32_t pinType = pReq->GetPinType();
1275     std::string payload = pReq->GetPayload();
1276     if (!data.WriteString(pkgName)) {
1277         return ERR_DM_IPC_WRITE_FAILED;
1278     }
1279     if (!IpcModelCodec::EncodePeerTargetId(targetId, data)) {
1280         LOGE("write peer target id failed");
1281         return ERR_DM_IPC_WRITE_FAILED;
1282     }
1283     if (!data.WriteInt32(pinType)) {
1284         return ERR_DM_IPC_WRITE_FAILED;
1285     }
1286     if (!data.WriteString(payload)) {
1287         return ERR_DM_IPC_WRITE_FAILED;
1288     }
1289     return DM_OK;
1290 }
1291 
ON_IPC_READ_RESPONSE(DESTROY_PIN_HOLDER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1292 ON_IPC_READ_RESPONSE(DESTROY_PIN_HOLDER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1293 {
1294     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1295     std::shared_ptr<IpcRsp> pRsp = std::static_pointer_cast<IpcRsp>(pBaseRsp);
1296     pRsp->SetErrCode(reply.ReadInt32());
1297     return DM_OK;
1298 }
1299 
ON_IPC_SET_REQUEST(SET_DN_POLICY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1300 ON_IPC_SET_REQUEST(SET_DN_POLICY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1301 {
1302     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1303     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1304     std::string pkgName = pReq->GetPkgName();
1305     std::string policy = pReq->GetFirstParam();
1306     if (!data.WriteString(pkgName)) {
1307         LOGE("write pkgName failed");
1308         return ERR_DM_IPC_WRITE_FAILED;
1309     }
1310     if (!data.WriteString(policy)) {
1311         LOGE("write setDnPolicy parameter failed");
1312         return ERR_DM_IPC_WRITE_FAILED;
1313     }
1314     return DM_OK;
1315 }
1316 
ON_IPC_READ_RESPONSE(SET_DN_POLICY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1317 ON_IPC_READ_RESPONSE(SET_DN_POLICY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1318 {
1319     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1320     pBaseRsp->SetErrCode(reply.ReadInt32());
1321     return DM_OK;
1322 }
1323 
ON_IPC_SET_REQUEST(STOP_AUTHENTICATE_DEVICE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1324 ON_IPC_SET_REQUEST(STOP_AUTHENTICATE_DEVICE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1325 {
1326     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1327     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1328     std::string pkgName = pReq->GetPkgName();
1329     if (!data.WriteString(pkgName)) {
1330         LOGE("write pkgName failed");
1331         return ERR_DM_IPC_WRITE_FAILED;
1332     }
1333     return DM_OK;
1334 }
1335 
ON_IPC_READ_RESPONSE(STOP_AUTHENTICATE_DEVICE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1336 ON_IPC_READ_RESPONSE(STOP_AUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1337 {
1338     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1339     pBaseRsp->SetErrCode(reply.ReadInt32());
1340     return DM_OK;
1341 }
1342 
ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER,MessageParcel & data,MessageParcel & reply)1343 ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER, MessageParcel &data, MessageParcel &reply)
1344 {
1345     std::string pkgName = data.ReadString();
1346     std::string deviceId = data.ReadString();
1347     DmPinType pinType = static_cast<DmPinType>(data.ReadInt32());
1348     std::string payload = data.ReadString();
1349 
1350     DeviceManagerNotify::GetInstance().OnPinHolderCreate(pkgName, deviceId, pinType, payload);
1351     reply.WriteInt32(DM_OK);
1352     return DM_OK;
1353 }
1354 
ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER,MessageParcel & data,MessageParcel & reply)1355 ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER, MessageParcel &data, MessageParcel &reply)
1356 {
1357     std::string pkgName = data.ReadString();
1358     DmPinType pinType = static_cast<DmPinType>(data.ReadInt32());
1359     std::string payload = data.ReadString();
1360 
1361     DeviceManagerNotify::GetInstance().OnPinHolderDestroy(pkgName, pinType, payload);
1362     reply.WriteInt32(DM_OK);
1363     return DM_OK;
1364 }
1365 
ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER_RESULT,MessageParcel & data,MessageParcel & reply)1366 ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER_RESULT, MessageParcel &data, MessageParcel &reply)
1367 {
1368     std::string pkgName = data.ReadString();
1369     int32_t result = data.ReadInt32();
1370 
1371     DeviceManagerNotify::GetInstance().OnCreateResult(pkgName, result);
1372     reply.WriteInt32(DM_OK);
1373     return DM_OK;
1374 }
1375 
ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER_RESULT,MessageParcel & data,MessageParcel & reply)1376 ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &data, MessageParcel &reply)
1377 {
1378     std::string pkgName = data.ReadString();
1379     int32_t result = data.ReadInt32();
1380 
1381     DeviceManagerNotify::GetInstance().OnDestroyResult(pkgName, result);
1382     reply.WriteInt32(DM_OK);
1383     return DM_OK;
1384 }
1385 
ON_IPC_SET_REQUEST(DP_ACL_ADD,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1386 ON_IPC_SET_REQUEST(DP_ACL_ADD, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1387 {
1388     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1389     std::shared_ptr<IpcAclProfileReq> pReq = std::static_pointer_cast<IpcAclProfileReq>(pBaseReq);
1390     std::string udid = pReq->GetStr();
1391     if (!data.WriteString(udid)) {
1392         LOGE("write udid failed");
1393         return ERR_DM_IPC_WRITE_FAILED;
1394     }
1395     return DM_OK;
1396 }
1397 
ON_IPC_READ_RESPONSE(DP_ACL_ADD,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1398 ON_IPC_READ_RESPONSE(DP_ACL_ADD, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1399 {
1400     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1401     pBaseRsp->SetErrCode(reply.ReadInt32());
1402     return DM_OK;
1403 }
1404 
ON_IPC_SET_REQUEST(GET_SECURITY_LEVEL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1405 ON_IPC_SET_REQUEST(GET_SECURITY_LEVEL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1406 {
1407     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1408     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
1409     std::string pkgName = pReq->GetPkgName();
1410     std::string networkId = pReq->GetNetWorkId();
1411     if (!data.WriteString(pkgName)) {
1412         return ERR_DM_IPC_WRITE_FAILED;
1413     }
1414     if (!data.WriteString(networkId)) {
1415         return ERR_DM_IPC_WRITE_FAILED;
1416     }
1417     return DM_OK;
1418 }
1419 
ON_IPC_READ_RESPONSE(GET_SECURITY_LEVEL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1420 ON_IPC_READ_RESPONSE(GET_SECURITY_LEVEL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1421 {
1422     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1423     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
1424     pRsp->SetErrCode(reply.ReadInt32());
1425     pRsp->SetSecurityLevel(reply.ReadInt32());
1426     return DM_OK;
1427 }
1428 
ON_IPC_CMD(SERVER_ON_PIN_HOLDER_EVENT,MessageParcel & data,MessageParcel & reply)1429 ON_IPC_CMD(SERVER_ON_PIN_HOLDER_EVENT, MessageParcel &data, MessageParcel &reply)
1430 {
1431     std::string pkgName = data.ReadString();
1432     int32_t result = data.ReadInt32();
1433     DmPinHolderEvent pinHolderEvent = static_cast<DmPinHolderEvent>(data.ReadInt32());
1434     std::string content = data.ReadString();
1435 
1436     DeviceManagerNotify::GetInstance().OnPinHolderEvent(pkgName, pinHolderEvent, result, content);
1437     reply.WriteInt32(DM_OK);
1438     return DM_OK;
1439 }
1440 
ON_IPC_SET_REQUEST(IS_SAME_ACCOUNT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1441 ON_IPC_SET_REQUEST(IS_SAME_ACCOUNT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1442 {
1443     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1444     std::shared_ptr<IpcAclProfileReq> pReq = std::static_pointer_cast<IpcAclProfileReq>(pBaseReq);
1445     std::string netWorkId = pReq->GetStr();
1446     if (!data.WriteString(netWorkId)) {
1447         LOGE("write netWorkId failed");
1448         return ERR_DM_IPC_WRITE_FAILED;
1449     }
1450     return DM_OK;
1451 }
1452 
ON_IPC_READ_RESPONSE(IS_SAME_ACCOUNT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1453 ON_IPC_READ_RESPONSE(IS_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1454 {
1455     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1456     pBaseRsp->SetErrCode(reply.ReadInt32());
1457     return DM_OK;
1458 }
1459 
ON_IPC_SET_REQUEST(CHECK_API_PERMISSION,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1460 ON_IPC_SET_REQUEST(CHECK_API_PERMISSION, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1461 {
1462     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1463     std::shared_ptr<IpcPermissionReq> pReq = std::static_pointer_cast<IpcPermissionReq>(pBaseReq);
1464     if (!data.WriteInt32(pReq->GetPermissionLevel())) {
1465         LOGE("write permissionLevel failed");
1466         return ERR_DM_IPC_WRITE_FAILED;
1467     }
1468     return DM_OK;
1469 }
1470 
ON_IPC_READ_RESPONSE(CHECK_API_PERMISSION,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1471 ON_IPC_READ_RESPONSE(CHECK_API_PERMISSION, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1472 {
1473     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1474     pBaseRsp->SetErrCode(reply.ReadInt32());
1475     return DM_OK;
1476 }
1477 
ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1478 ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1479 {
1480     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1481     std::shared_ptr<IpcCheckAcl> pReq = std::static_pointer_cast<IpcCheckAcl>(pBaseReq);
1482     DmAccessCaller caller = pReq->GetAccessCaller();
1483     DmAccessCallee callee = pReq->GetAccessCallee();
1484     if (!IpcModelCodec::EncodeDmAccessCaller(caller, data)) {
1485         LOGE("write caller failed");
1486         return ERR_DM_IPC_WRITE_FAILED;
1487     }
1488     if (!IpcModelCodec::EncodeDmAccessCallee(callee, data)) {
1489         LOGE("write caller failed");
1490         return ERR_DM_IPC_WRITE_FAILED;
1491     }
1492     return DM_OK;
1493 }
1494 
ON_IPC_READ_RESPONSE(CHECK_ACCESS_CONTROL,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1495 ON_IPC_READ_RESPONSE(CHECK_ACCESS_CONTROL, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1496 {
1497     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1498     pBaseRsp->SetErrCode(reply.ReadInt32());
1499     return DM_OK;
1500 }
1501 
ON_IPC_SET_REQUEST(CHECK_SAME_ACCOUNT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1502 ON_IPC_SET_REQUEST(CHECK_SAME_ACCOUNT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1503 {
1504     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1505     std::shared_ptr<IpcCheckAcl> pReq = std::static_pointer_cast<IpcCheckAcl>(pBaseReq);
1506     DmAccessCaller caller = pReq->GetAccessCaller();
1507     DmAccessCallee callee = pReq->GetAccessCallee();
1508     if (!IpcModelCodec::EncodeDmAccessCaller(caller, data)) {
1509         LOGE("write caller failed");
1510         return ERR_DM_IPC_WRITE_FAILED;
1511     }
1512     if (!IpcModelCodec::EncodeDmAccessCallee(callee, data)) {
1513         LOGE("write caller failed");
1514         return ERR_DM_IPC_WRITE_FAILED;
1515     }
1516     return DM_OK;
1517 }
1518 
ON_IPC_READ_RESPONSE(CHECK_SAME_ACCOUNT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1519 ON_IPC_READ_RESPONSE(CHECK_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1520 {
1521     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1522     pBaseRsp->SetErrCode(reply.ReadInt32());
1523     return DM_OK;
1524 }
1525 
ON_IPC_SET_REQUEST(SHIFT_LNN_GEAR,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1526 ON_IPC_SET_REQUEST(SHIFT_LNN_GEAR, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1527 {
1528     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1529     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
1530     std::string pkgName = pReq->GetPkgName();
1531     if (!data.WriteString(pkgName)) {
1532         LOGE("write pkgName failed");
1533         return ERR_DM_IPC_WRITE_FAILED;
1534     }
1535     return DM_OK;
1536 }
1537 
ON_IPC_READ_RESPONSE(SHIFT_LNN_GEAR,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1538 ON_IPC_READ_RESPONSE(SHIFT_LNN_GEAR, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1539 {
1540     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1541     pBaseRsp->SetErrCode(reply.ReadInt32());
1542     return DM_OK;
1543 }
1544 
ON_IPC_CMD(REMOTE_DEVICE_TRUST_CHANGE,MessageParcel & data,MessageParcel & reply)1545 ON_IPC_CMD(REMOTE_DEVICE_TRUST_CHANGE, MessageParcel &data, MessageParcel &reply)
1546 {
1547     std::string pkgName = data.ReadString();
1548     std::string udid = data.ReadString();
1549     int32_t authForm = data.ReadInt32();
1550     std::string uuid = data.ReadString();
1551     DeviceManagerNotify::GetInstance().OnDeviceTrustChange(pkgName, udid, uuid, authForm);
1552     reply.WriteInt32(DM_OK);
1553     return DM_OK;
1554 }
1555 
ON_IPC_CMD(SERVER_DEVICE_SCREEN_STATE_NOTIFY,MessageParcel & data,MessageParcel & reply)1556 ON_IPC_CMD(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply)
1557 {
1558     std::string pkgName = data.ReadString();
1559     DmDeviceInfo dmDeviceInfo;
1560     IpcModelCodec::DecodeDmDeviceInfo(data, dmDeviceInfo);
1561     DeviceManagerNotify::GetInstance().OnDeviceScreenStatus(pkgName, dmDeviceInfo);
1562 
1563     reply.WriteInt32(DM_OK);
1564     return DM_OK;
1565 }
1566 
ON_IPC_SET_REQUEST(GET_DEVICE_SCREEN_STATUS,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1567 ON_IPC_SET_REQUEST(GET_DEVICE_SCREEN_STATUS, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1568 {
1569     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1570     std::shared_ptr<IpcGetDeviceScreenStatusReq> pReq = std::static_pointer_cast<IpcGetDeviceScreenStatusReq>(pBaseReq);
1571     std::string pkgName = pReq->GetPkgName();
1572     std::string networkId = pReq->GetNetWorkId();
1573     if (!data.WriteString(pkgName)) {
1574         return ERR_DM_IPC_WRITE_FAILED;
1575     }
1576     if (!data.WriteString(networkId)) {
1577         return ERR_DM_IPC_WRITE_FAILED;
1578     }
1579     return DM_OK;
1580 }
1581 
ON_IPC_READ_RESPONSE(GET_DEVICE_SCREEN_STATUS,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1582 ON_IPC_READ_RESPONSE(GET_DEVICE_SCREEN_STATUS, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1583 {
1584     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1585     std::shared_ptr<IpcGetDeviceScreenStatusRsp> pRsp = std::static_pointer_cast<IpcGetDeviceScreenStatusRsp>(pBaseRsp);
1586     pRsp->SetErrCode(reply.ReadInt32());
1587     pRsp->SetScreenStatus(reply.ReadInt32());
1588     return DM_OK;
1589 }
1590 
ON_IPC_SET_REQUEST(GET_ANONY_LOCAL_UDID,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1591 ON_IPC_SET_REQUEST(GET_ANONY_LOCAL_UDID, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1592 {
1593     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1594     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
1595     std::string pkgName = pReq->GetPkgName();
1596     if (!data.WriteString(pkgName)) {
1597         return ERR_DM_IPC_WRITE_FAILED;
1598     }
1599     return DM_OK;
1600 }
1601 
ON_IPC_READ_RESPONSE(GET_ANONY_LOCAL_UDID,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1602 ON_IPC_READ_RESPONSE(GET_ANONY_LOCAL_UDID, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1603 {
1604     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1605     std::shared_ptr<IpcGetAnonyLocalUdidRsp> pRsp = std::static_pointer_cast<IpcGetAnonyLocalUdidRsp>(pBaseRsp);
1606     pRsp->SetErrCode(reply.ReadInt32());
1607     pRsp->SetAnonyUdid(reply.ReadString());
1608     return DM_OK;
1609 }
1610 
ON_IPC_SET_REQUEST(GET_NETWORKID_BY_UDID,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1611 ON_IPC_SET_REQUEST(GET_NETWORKID_BY_UDID, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1612 {
1613     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1614     std::shared_ptr<IpcGetInfoByNetWorkReq> pReq = std::static_pointer_cast<IpcGetInfoByNetWorkReq>(pBaseReq);
1615     std::string pkgName = pReq->GetPkgName();
1616     std::string udid = pReq->GetUdid();
1617     if (!data.WriteString(pkgName)) {
1618         return ERR_DM_IPC_WRITE_FAILED;
1619     }
1620     if (!data.WriteString(udid)) {
1621         return ERR_DM_IPC_WRITE_FAILED;
1622     }
1623     return DM_OK;
1624 }
1625 
ON_IPC_READ_RESPONSE(GET_NETWORKID_BY_UDID,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1626 ON_IPC_READ_RESPONSE(GET_NETWORKID_BY_UDID, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1627 {
1628     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1629     std::shared_ptr<IpcGetInfoByNetWorkRsp> pRsp = std::static_pointer_cast<IpcGetInfoByNetWorkRsp>(pBaseRsp);
1630     pRsp->SetErrCode(reply.ReadInt32());
1631     pRsp->SetNetWorkId(reply.ReadString());
1632     return DM_OK;
1633 }
1634 
ON_IPC_CMD(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY,MessageParcel & data,MessageParcel & reply)1635 ON_IPC_CMD(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, MessageParcel &data, MessageParcel &reply)
1636 {
1637     std::string pkgName = data.ReadString();
1638     std::string deviceList = data.ReadString();
1639     uint16_t deviceTypeId = data.ReadUint16();
1640     int32_t errCode = data.ReadInt32();
1641     DeviceManagerNotify::GetInstance().OnCredentialAuthStatus(pkgName, deviceList, deviceTypeId, errCode);
1642 
1643     reply.WriteInt32(DM_OK);
1644     return DM_OK;
1645 }
1646 
ON_IPC_CMD(SINK_BIND_TARGET_RESULT,MessageParcel & data,MessageParcel & reply)1647 ON_IPC_CMD(SINK_BIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply)
1648 {
1649     std::string pkgName = data.ReadString();
1650     PeerTargetId targetId;
1651     IpcModelCodec::DecodePeerTargetId(data, targetId);
1652     int32_t result = data.ReadInt32();
1653     int32_t status = data.ReadInt32();
1654     std::string content = data.ReadString();
1655 
1656     DeviceManagerNotify::GetInstance().OnSinkBindResult(pkgName, targetId, result, status, content);
1657     reply.WriteInt32(DM_OK);
1658     return DM_OK;
1659 }
1660 
ON_IPC_SET_REQUEST(REGISTER_DEV_STATE_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1661 ON_IPC_SET_REQUEST(REGISTER_DEV_STATE_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1662 {
1663     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1664     std::shared_ptr<IpcReq> pReq = std::static_pointer_cast<IpcReq>(pBaseReq);
1665     std::string pkgName = pReq->GetPkgName();
1666     if (!data.WriteString(pkgName)) {
1667         return ERR_DM_IPC_WRITE_FAILED;
1668     }
1669     return DM_OK;
1670 }
1671 
ON_IPC_READ_RESPONSE(REGISTER_DEV_STATE_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1672 ON_IPC_READ_RESPONSE(REGISTER_DEV_STATE_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1673 {
1674     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1675     pBaseRsp->SetErrCode(reply.ReadInt32());
1676     return DM_OK;
1677 }
1678 
ON_IPC_SET_REQUEST(SYNC_CALLBACK,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1679 ON_IPC_SET_REQUEST(SYNC_CALLBACK, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1680 {
1681     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1682     std::shared_ptr<IpcSyncCallbackReq> pReq = std::static_pointer_cast<IpcSyncCallbackReq>(pBaseReq);
1683     std::string pkgName = pReq->GetPkgName();
1684     if (!data.WriteString(pkgName)) {
1685         LOGE("write pkgName failed");
1686         return ERR_DM_IPC_WRITE_FAILED;
1687     }
1688     if (!data.WriteInt32(pReq->GetDmCommonNotifyEvent())) {
1689         LOGE("write notify event failed");
1690         return ERR_DM_IPC_WRITE_FAILED;
1691     }
1692     return DM_OK;
1693 }
1694 
ON_IPC_READ_RESPONSE(SYNC_CALLBACK,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1695 ON_IPC_READ_RESPONSE(SYNC_CALLBACK, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1696 {
1697     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1698     pBaseRsp->SetErrCode(reply.ReadInt32());
1699     return DM_OK;
1700 }
ON_IPC_SET_REQUEST(REG_AUTHENTICATION_TYPE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1701 ON_IPC_SET_REQUEST(REG_AUTHENTICATION_TYPE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1702 {
1703     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1704     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1705     std::string pkgName = pReq->GetPkgName();
1706     std::string authTypeStr = pReq->GetFirstParam();
1707     if (!data.WriteString(pkgName)) {
1708         LOGE("write pkgName failed");
1709         return ERR_DM_IPC_WRITE_FAILED;
1710     }
1711     if (!data.WriteString(authTypeStr)) {
1712         LOGE("write authTypeStr parameter failed");
1713         return ERR_DM_IPC_WRITE_FAILED;
1714     }
1715     return DM_OK;
1716 }
1717 
ON_IPC_READ_RESPONSE(REG_AUTHENTICATION_TYPE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1718 ON_IPC_READ_RESPONSE(REG_AUTHENTICATION_TYPE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1719 {
1720     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1721     pBaseRsp->SetErrCode(reply.ReadInt32());
1722     return DM_OK;
1723 }
1724 
ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1725 ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1726 {
1727     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1728     std::shared_ptr<IpcGetDeviceProfileInfoListReq> pReq =
1729         std::static_pointer_cast<IpcGetDeviceProfileInfoListReq>(pBaseReq);
1730     std::string pkgName = pReq->GetPkgName();
1731     if (!data.WriteString(pkgName)) {
1732         LOGE("write pkgName failed");
1733         return ERR_DM_IPC_WRITE_FAILED;
1734     }
1735     if (!IpcModelCodec::EncodeDmDeviceProfileInfoFilterOptions(pReq->GetFilterOptions(), data)) {
1736         LOGE("write filterOptions failed");
1737         return ERR_DM_IPC_WRITE_FAILED;
1738     }
1739     return DM_OK;
1740 }
1741 
ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1742 ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1743 {
1744     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1745     pBaseRsp->SetErrCode(reply.ReadInt32());
1746     return DM_OK;
1747 }
1748 
ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST_RESULT,MessageParcel & data,MessageParcel & reply)1749 ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &data, MessageParcel &reply)
1750 {
1751     std::string pkgName = data.ReadString();
1752     int32_t code = data.ReadInt32();
1753     int32_t deviceNum = data.ReadInt32();
1754     std::vector<DmDeviceProfileInfo> deviceProfileInfos;
1755     if (deviceNum > 0 && deviceNum <= MAX_DEVICE_PROFILE_SIZE) {
1756         for (int32_t i = 0; i < deviceNum; ++i) {
1757             DmDeviceProfileInfo deviceInfo;
1758             IpcModelCodec::DecodeDmDeviceProfileInfo(data, deviceInfo);
1759             deviceProfileInfos.emplace_back(deviceInfo);
1760         }
1761     }
1762 
1763     DeviceManagerNotify::GetInstance().OnGetDeviceProfileInfoListResult(pkgName, deviceProfileInfos, code);
1764     reply.WriteInt32(DM_OK);
1765     return DM_OK;
1766 }
1767 
ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1768 ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1769 {
1770     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1771     std::shared_ptr<IpcGetDeviceIconInfoReq> pReq = std::static_pointer_cast<IpcGetDeviceIconInfoReq>(pBaseReq);
1772     std::string pkgName = pReq->GetPkgName();
1773     if (!data.WriteString(pkgName)) {
1774         LOGE("write pkgName failed");
1775         return ERR_DM_IPC_WRITE_FAILED;
1776     }
1777     if (!IpcModelCodec::EncodeDmDeviceIconInfoFilterOptions(pReq->GetFilterOptions(), data)) {
1778         LOGE("write filterOptions failed");
1779         return ERR_DM_IPC_WRITE_FAILED;
1780     }
1781     return DM_OK;
1782 }
1783 
ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1784 ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1785 {
1786     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1787     pBaseRsp->SetErrCode(reply.ReadInt32());
1788     return DM_OK;
1789 }
1790 
ON_IPC_CMD(GET_DEVICE_ICON_INFO_RESULT,MessageParcel & data,MessageParcel & reply)1791 ON_IPC_CMD(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &data, MessageParcel &reply)
1792 {
1793     std::string pkgName = data.ReadString();
1794     int32_t code = data.ReadInt32();
1795     DmDeviceIconInfo deviceIconInfo;
1796     IpcModelCodec::DecodeDmDeviceIconInfo(data, deviceIconInfo);
1797     DeviceManagerNotify::GetInstance().OnGetDeviceIconInfoResult(pkgName, deviceIconInfo, code);
1798     reply.WriteInt32(DM_OK);
1799     return DM_OK;
1800 }
1801 
ON_IPC_SET_REQUEST(PUT_DEVICE_PROFILE_INFO_LIST,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1802 ON_IPC_SET_REQUEST(PUT_DEVICE_PROFILE_INFO_LIST, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1803 {
1804     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1805     std::shared_ptr<IpcPutDeviceProfileInfoListReq> pReq =
1806         std::static_pointer_cast<IpcPutDeviceProfileInfoListReq>(pBaseReq);
1807     std::string pkgName = pReq->GetPkgName();
1808     if (!data.WriteString(pkgName)) {
1809         LOGE("write pkgName failed");
1810         return ERR_DM_IPC_WRITE_FAILED;
1811     }
1812     std::vector<DmDeviceProfileInfo> deviceProfileInfos = pReq->GetDeviceProfileInfoList();
1813     if (!data.WriteInt32((int32_t)deviceProfileInfos.size())) {
1814         LOGE("write device list size failed");
1815         return ERR_DM_IPC_WRITE_FAILED;
1816     }
1817     for (const auto &devInfo : deviceProfileInfos) {
1818         if (!IpcModelCodec::EncodeDmDeviceProfileInfo(devInfo, data)) {
1819             LOGE("write dm device profile info failed");
1820             return ERR_DM_IPC_WRITE_FAILED;
1821         }
1822     }
1823     return DM_OK;
1824 }
1825 
ON_IPC_READ_RESPONSE(PUT_DEVICE_PROFILE_INFO_LIST,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1826 ON_IPC_READ_RESPONSE(PUT_DEVICE_PROFILE_INFO_LIST, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1827 {
1828     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1829     pBaseRsp->SetErrCode(reply.ReadInt32());
1830     return DM_OK;
1831 }
1832 
ON_IPC_SET_REQUEST(GET_LOCAL_DISPLAY_DEVICE_NAME,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1833 ON_IPC_SET_REQUEST(GET_LOCAL_DISPLAY_DEVICE_NAME, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1834 {
1835     CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1836     std::shared_ptr<IpcGetLocalDisplayDeviceNameReq> pReq =
1837         std::static_pointer_cast<IpcGetLocalDisplayDeviceNameReq>(pBaseReq);
1838     std::string pkgName = pReq->GetPkgName();
1839     if (!data.WriteString(pkgName)) {
1840         LOGE("write pkgName failed");
1841         return ERR_DM_IPC_WRITE_FAILED;
1842     }
1843     if (!data.WriteInt32(pReq->GetMaxNameLength())) {
1844         LOGE("write maxNameLength failed");
1845         return ERR_DM_IPC_WRITE_FAILED;
1846     }
1847     return DM_OK;
1848 }
1849 
ON_IPC_READ_RESPONSE(GET_LOCAL_DISPLAY_DEVICE_NAME,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1850 ON_IPC_READ_RESPONSE(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1851 {
1852     CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1853     std::shared_ptr<IpcGetLocalDisplayDeviceNameRsp> pRsp =
1854         std::static_pointer_cast<IpcGetLocalDisplayDeviceNameRsp>(pBaseRsp);
1855     pRsp->SetErrCode(reply.ReadInt32());
1856     pRsp->SetDisplayName(reply.ReadString());
1857     return DM_OK;
1858 }
1859 
ON_IPC_SET_REQUEST(REG_LOCALSERVICE_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1860 ON_IPC_SET_REQUEST(REG_LOCALSERVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1861 {
1862     if (pBaseReq == nullptr) {
1863         LOGE("pBaseReq is null");
1864         return ERR_DM_FAILED;
1865     }
1866     std::shared_ptr<IpcRegServiceInfoReq> pReq = std::static_pointer_cast<IpcRegServiceInfoReq>(pBaseReq);
1867     const DMLocalServiceInfo& info = pReq->GetLocalServiceInfo();
1868     if (!IpcModelCodec::EncodeLocalServiceInfo(info, data)) {
1869         LOGE("EncodeLocalServiceInfo failed");
1870         return ERR_DM_IPC_WRITE_FAILED;
1871     }
1872     return DM_OK;
1873 }
1874 
ON_IPC_READ_RESPONSE(REG_LOCALSERVICE_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1875 ON_IPC_READ_RESPONSE(REG_LOCALSERVICE_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1876 {
1877     if (pBaseRsp == nullptr) {
1878         LOGE("pBaseRsp is null");
1879         return ERR_DM_FAILED;
1880     }
1881     pBaseRsp->SetErrCode(reply.ReadInt32());
1882     return DM_OK;
1883 }
1884 
ON_IPC_SET_REQUEST(UNREG_LOCALSERVICE_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1885 ON_IPC_SET_REQUEST(UNREG_LOCALSERVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1886 {
1887     if (pBaseReq == nullptr) {
1888         LOGE("pBaseReq is null");
1889         return ERR_DM_FAILED;
1890     }
1891     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1892     std::string bundleName = pReq->GetFirstParam();
1893     int64_t pinExchangeType = pReq->GetInt32Param();
1894     if (!data.WriteString(bundleName)) {
1895         return ERR_DM_IPC_WRITE_FAILED;
1896     }
1897     if (!data.WriteInt32(pinExchangeType)) {
1898         return ERR_DM_IPC_WRITE_FAILED;
1899     }
1900     return DM_OK;
1901 }
1902 
ON_IPC_READ_RESPONSE(UNREG_LOCALSERVICE_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1903 ON_IPC_READ_RESPONSE(UNREG_LOCALSERVICE_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1904 {
1905     if (pBaseRsp == nullptr) {
1906         LOGE("pBaseRsp is null");
1907         return ERR_DM_FAILED;
1908     }
1909     pBaseRsp->SetErrCode(reply.ReadInt32());
1910     return DM_OK;
1911 }
1912 
ON_IPC_SET_REQUEST(UPDATE_LOCALSERVICE_INFO,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1913 ON_IPC_SET_REQUEST(UPDATE_LOCALSERVICE_INFO, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1914 {
1915     if (pBaseReq == nullptr) {
1916         LOGE("pBaseReq is null");
1917         return ERR_DM_FAILED;
1918     }
1919     std::shared_ptr<IpcRegServiceInfoReq> pReq = std::static_pointer_cast<IpcRegServiceInfoReq>(pBaseReq);
1920     const DMLocalServiceInfo& info = pReq->GetLocalServiceInfo();
1921     if (!IpcModelCodec::EncodeLocalServiceInfo(info, data)) {
1922         LOGE("EncodeLocalServiceInfo failed");
1923         return ERR_DM_IPC_WRITE_FAILED;
1924     }
1925     return DM_OK;
1926 }
1927 
ON_IPC_READ_RESPONSE(UPDATE_LOCALSERVICE_INFO,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1928 ON_IPC_READ_RESPONSE(UPDATE_LOCALSERVICE_INFO, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1929 {
1930     if (pBaseRsp == nullptr) {
1931         LOGE("pBaseRsp is null");
1932         return ERR_DM_FAILED;
1933     }
1934     pBaseRsp->SetErrCode(reply.ReadInt32());
1935     return DM_OK;
1936 }
1937 
ON_IPC_SET_REQUEST(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1938 ON_IPC_SET_REQUEST(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, std::shared_ptr<IpcReq> pBaseReq,
1939     MessageParcel &data)
1940 {
1941     if (pBaseReq == nullptr) {
1942         LOGE("pBaseReq is null");
1943         return ERR_DM_FAILED;
1944     }
1945     std::shared_ptr<IpcCommonParamReq> pReq = std::static_pointer_cast<IpcCommonParamReq>(pBaseReq);
1946     std::string bundleName = pReq->GetFirstParam();
1947     int32_t pinExchangeType = pReq->GetInt32Param();
1948     if (!data.WriteString(bundleName)) {
1949         return ERR_DM_IPC_WRITE_FAILED;
1950     }
1951     if (!data.WriteInt32(pinExchangeType)) {
1952         return ERR_DM_IPC_WRITE_FAILED;
1953     }
1954     return DM_OK;
1955 }
1956 
ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1957 ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, MessageParcel &reply,
1958     std::shared_ptr<IpcRsp> pBaseRsp)
1959 {
1960     if (pBaseRsp == nullptr) {
1961         LOGE("pBaseRsp is null");
1962         return ERR_DM_FAILED;
1963     }
1964     pBaseRsp->SetErrCode(reply.ReadInt32());
1965     if (pBaseRsp->GetErrCode() == DM_OK) {
1966         std::shared_ptr<IpcGetLocalServiceInfoRsp> pRsp =
1967             std::static_pointer_cast<IpcGetLocalServiceInfoRsp>(pBaseRsp);
1968         DMLocalServiceInfo info;
1969         bool ret = IpcModelCodec::DecodeLocalServiceInfo(reply, info);
1970         if (!ret) {
1971             LOGE("DecodeLocalServiceInfo failed");
1972             pBaseRsp->SetErrCode(ERR_DM_IPC_READ_FAILED);
1973         }
1974         pRsp->SetLocalServiceInfo(info);
1975     }
1976     return DM_OK;
1977 }
1978 
ON_IPC_SET_REQUEST(SET_LOCAL_DEVICE_NAME,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1979 ON_IPC_SET_REQUEST(SET_LOCAL_DEVICE_NAME, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1980 {
1981     if (pBaseReq == nullptr) {
1982         LOGE("pBaseReq is null");
1983         return ERR_DM_FAILED;
1984     }
1985     std::shared_ptr<IpcSetLocalDeviceNameReq> pReq = std::static_pointer_cast<IpcSetLocalDeviceNameReq>(pBaseReq);
1986     std::string pkgName = pReq->GetPkgName();
1987     if (!data.WriteString(pkgName)) {
1988         LOGE("write pkgName failed");
1989         return ERR_DM_IPC_WRITE_FAILED;
1990     }
1991     std::string deviceName = pReq->GetDeviceName();
1992     if (!data.WriteString(deviceName)) {
1993         LOGE("write deviceName failed");
1994         return ERR_DM_IPC_WRITE_FAILED;
1995     }
1996     return DM_OK;
1997 }
1998 
ON_IPC_READ_RESPONSE(SET_LOCAL_DEVICE_NAME,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1999 ON_IPC_READ_RESPONSE(SET_LOCAL_DEVICE_NAME, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
2000 {
2001     if (pBaseRsp == nullptr) {
2002         LOGE("pBaseRsp is null");
2003         return ERR_DM_FAILED;
2004     }
2005     pBaseRsp->SetErrCode(reply.ReadInt32());
2006     return DM_OK;
2007 }
2008 
ON_IPC_CMD(SET_LOCAL_DEVICE_NAME_RESULT,MessageParcel & data,MessageParcel & reply)2009 ON_IPC_CMD(SET_LOCAL_DEVICE_NAME_RESULT, MessageParcel &data, MessageParcel &reply)
2010 {
2011     std::string pkgName = data.ReadString();
2012     int32_t code = data.ReadInt32();
2013     DeviceManagerNotify::GetInstance().OnSetLocalDeviceNameResult(pkgName, code);
2014     reply.WriteInt32(DM_OK);
2015     return DM_OK;
2016 }
2017 
ON_IPC_READ_RESPONSE(SET_REMOTE_DEVICE_NAME,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)2018 ON_IPC_READ_RESPONSE(SET_REMOTE_DEVICE_NAME, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
2019 {
2020     if (pBaseRsp == nullptr) {
2021         LOGE("pBaseRsp is null");
2022         return ERR_DM_FAILED;
2023     }
2024     pBaseRsp->SetErrCode(reply.ReadInt32());
2025     return DM_OK;
2026 }
2027 
ON_IPC_SET_REQUEST(SET_REMOTE_DEVICE_NAME,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)2028 ON_IPC_SET_REQUEST(SET_REMOTE_DEVICE_NAME, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
2029 {
2030     if (pBaseReq == nullptr) {
2031         LOGE("pBaseReq is null");
2032         return ERR_DM_FAILED;
2033     }
2034     std::shared_ptr<IpcSetRemoteDeviceNameReq> pReq = std::static_pointer_cast<IpcSetRemoteDeviceNameReq>(pBaseReq);
2035     std::string pkgName = pReq->GetPkgName();
2036     if (!data.WriteString(pkgName)) {
2037         LOGE("write pkgName failed");
2038         return ERR_DM_IPC_WRITE_FAILED;
2039     }
2040     std::string deviceId = pReq->GetDeviceId();
2041     if (!data.WriteString(deviceId)) {
2042         LOGE("write deviceId failed");
2043         return ERR_DM_IPC_WRITE_FAILED;
2044     }
2045     std::string deviceName = pReq->GetDeviceName();
2046     if (!data.WriteString(deviceName)) {
2047         LOGE("write deviceName failed");
2048         return ERR_DM_IPC_WRITE_FAILED;
2049     }
2050     return DM_OK;
2051 }
2052 
ON_IPC_CMD(SET_REMOTE_DEVICE_NAME_RESULT,MessageParcel & data,MessageParcel & reply)2053 ON_IPC_CMD(SET_REMOTE_DEVICE_NAME_RESULT, MessageParcel &data, MessageParcel &reply)
2054 {
2055     std::string pkgName = data.ReadString();
2056     std::string deviceId = data.ReadString();
2057     int32_t code = data.ReadInt32();
2058     DeviceManagerNotify::GetInstance().OnSetRemoteDeviceNameResult(pkgName, deviceId, code);
2059     reply.WriteInt32(DM_OK);
2060     return DM_OK;
2061 }
2062 
ON_IPC_READ_RESPONSE(RESTORE_LOCAL_DEVICE_NAME,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)2063 ON_IPC_READ_RESPONSE(RESTORE_LOCAL_DEVICE_NAME, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
2064 {
2065     if (pBaseRsp == nullptr) {
2066         LOGE("pBaseRsp is null");
2067         return ERR_DM_FAILED;
2068     }
2069     pBaseRsp->SetErrCode(reply.ReadInt32());
2070     return DM_OK;
2071 }
2072 
ON_IPC_SET_REQUEST(RESTORE_LOCAL_DEVICE_NAME,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)2073 ON_IPC_SET_REQUEST(RESTORE_LOCAL_DEVICE_NAME, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
2074 {
2075     if (pBaseReq == nullptr) {
2076         LOGE("pBaseReq is null");
2077         return ERR_DM_FAILED;
2078     }
2079     std::string pkgName = pBaseReq->GetPkgName();
2080     if (!data.WriteString(pkgName)) {
2081         LOGE("write pkgName failed");
2082         return ERR_DM_IPC_WRITE_FAILED;
2083     }
2084     return DM_OK;
2085 }
2086 
ON_IPC_SET_REQUEST(GET_DEVICE_NETWORK_ID_LIST,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)2087 ON_IPC_SET_REQUEST(GET_DEVICE_NETWORK_ID_LIST, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
2088 {
2089     if (pBaseReq == nullptr) {
2090         LOGE("pBaseReq is null");
2091         return ERR_DM_FAILED;
2092     }
2093     std::shared_ptr<IpcGetDeviceNetworkIdListReq> pReq =
2094         std::static_pointer_cast<IpcGetDeviceNetworkIdListReq>(pBaseReq);
2095     if (!data.WriteString(pReq->GetPkgName())) {
2096         LOGE("write pkgName failed");
2097         return ERR_DM_IPC_WRITE_FAILED;
2098     }
2099     if (!IpcModelCodec::EncodeNetworkIdQueryFilter(pReq->GetQueryFilter(), data)) {
2100         LOGE("write query filter failed");
2101         return ERR_DM_IPC_WRITE_FAILED;
2102     }
2103     return DM_OK;
2104 }
2105 
ON_IPC_READ_RESPONSE(GET_DEVICE_NETWORK_ID_LIST,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)2106 ON_IPC_READ_RESPONSE(GET_DEVICE_NETWORK_ID_LIST, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
2107 {
2108     if (pBaseRsp == nullptr) {
2109         LOGE("pBaseRsp is null");
2110         return ERR_DM_FAILED;
2111     }
2112     pBaseRsp->SetErrCode(reply.ReadInt32());
2113     if (pBaseRsp->GetErrCode() == DM_OK) {
2114         std::shared_ptr<IpcGetDeviceNetworkIdListRsp> pRsp =
2115             std::static_pointer_cast<IpcGetDeviceNetworkIdListRsp>(pBaseRsp);
2116         std::vector<std::string> networkIds;
2117         bool ret = IpcModelCodec::DecodeStringVector(reply, networkIds);
2118         if (!ret) {
2119             LOGE("DecodeLocalServiceInfo failed");
2120             pBaseRsp->SetErrCode(ERR_DM_IPC_READ_FAILED);
2121         }
2122         pRsp->SetNetworkIds(networkIds);
2123     }
2124     return DM_OK;
2125 }
2126 } // namespace DistributedHardware
2127 } // namespace OHOS
2128