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