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