• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 <memory>
17 
18 #include "device_manager_ipc_interface_code.h"
19 #include "device_manager_service.h"
20 #include "dm_constants.h"
21 #include "dm_device_info.h"
22 #include "dm_log.h"
23 #include "dm_subscribe_info.h"
24 #include "dm_publish_info.h"
25 #include "ipc_cmd_register.h"
26 #include "ipc_def.h"
27 #include "ipc_notify_auth_result_req.h"
28 #include "ipc_notify_credential_req.h"
29 #include "ipc_notify_device_found_req.h"
30 #include "ipc_notify_device_discovery_req.h"
31 #include "ipc_notify_device_state_req.h"
32 #include "ipc_notify_discover_result_req.h"
33 #include "ipc_notify_publish_result_req.h"
34 #include "ipc_notify_verify_auth_result_req.h"
35 #include "ipc_server_stub.h"
36 
37 namespace OHOS {
38 namespace DistributedHardware {
ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)39 ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
40 {
41     if (pBaseReq == nullptr) {
42         return ERR_DM_FAILED;
43     }
44 
45     std::shared_ptr<IpcNotifyDeviceStateReq> pReq = std::static_pointer_cast<IpcNotifyDeviceStateReq>(pBaseReq);
46     std::string pkgName = pReq->GetPkgName();
47     int32_t deviceState = pReq->GetDeviceState();
48     DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
49     DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo();
50     if (!data.WriteString(pkgName)) {
51         LOGE("write pkgName failed");
52         return ERR_DM_IPC_WRITE_FAILED;
53     }
54     if (!data.WriteInt32(deviceState)) {
55         LOGE("write state failed");
56         return ERR_DM_IPC_WRITE_FAILED;
57     }
58     if (!data.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) {
59         LOGE("write deviceInfo failed");
60         return ERR_DM_IPC_WRITE_FAILED;
61     }
62     if (!data.WriteRawData(&deviceBasicInfo, sizeof(DmDeviceBasicInfo))) {
63         LOGE("write deviceBasicInfo failed");
64         return ERR_DM_IPC_WRITE_FAILED;
65     }
66     return DM_OK;
67 }
68 
ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)69 ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
70 {
71     if (pBaseRsp == nullptr) {
72         LOGE("pBaseRsp is null");
73         return ERR_DM_FAILED;
74     }
75     pBaseRsp->SetErrCode(reply.ReadInt32());
76     return DM_OK;
77 }
78 
ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)79 ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
80 {
81     if (pBaseReq == nullptr) {
82         return ERR_DM_FAILED;
83     }
84 
85     std::shared_ptr<IpcNotifyDeviceFoundReq> pReq = std::static_pointer_cast<IpcNotifyDeviceFoundReq>(pBaseReq);
86     std::string pkgName = pReq->GetPkgName();
87     uint16_t subscribeId = pReq->GetSubscribeId();
88     DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
89     if (!data.WriteString(pkgName)) {
90         LOGE("write pkgName failed");
91         return ERR_DM_IPC_WRITE_FAILED;
92     }
93     if (!data.WriteInt16((int16_t)subscribeId)) {
94         LOGE("write subscribeId failed");
95         return ERR_DM_IPC_WRITE_FAILED;
96     }
97     if (!data.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) {
98         LOGE("write deviceInfo failed");
99         return ERR_DM_IPC_WRITE_FAILED;
100     }
101     return DM_OK;
102 }
103 
ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)104 ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
105 {
106     if (pBaseRsp == nullptr) {
107         LOGE("pBaseRsp is null");
108         return ERR_DM_FAILED;
109     }
110     pBaseRsp->SetErrCode(reply.ReadInt32());
111     return DM_OK;
112 }
113 
ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)114 ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
115 {
116     if (pBaseReq == nullptr) {
117         return ERR_DM_FAILED;
118     }
119 
120     std::shared_ptr<IpcNotifyDeviceDiscoveryReq> pReq = std::static_pointer_cast<IpcNotifyDeviceDiscoveryReq>(pBaseReq);
121     std::string pkgName = pReq->GetPkgName();
122     uint16_t subscribeId = pReq->GetSubscribeId();
123     DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo();
124     if (!data.WriteString(pkgName)) {
125         LOGE("write pkgName failed");
126         return ERR_DM_IPC_WRITE_FAILED;
127     }
128     if (!data.WriteInt16((int16_t)subscribeId)) {
129         LOGE("write subscribeId failed");
130         return ERR_DM_IPC_WRITE_FAILED;
131     }
132     if (!data.WriteRawData(&deviceBasicInfo, sizeof(DmDeviceBasicInfo))) {
133         LOGE("write deviceBasicInfo failed");
134         return ERR_DM_IPC_WRITE_FAILED;
135     }
136     return DM_OK;
137 }
138 
ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)139 ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
140 {
141     if (pBaseRsp == nullptr) {
142         LOGE("pBaseRsp is null");
143         return ERR_DM_FAILED;
144     }
145     pBaseRsp->SetErrCode(reply.ReadInt32());
146     return DM_OK;
147 }
148 
ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)149 ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
150 {
151     if (pBaseReq == nullptr) {
152         return ERR_DM_FAILED;
153     }
154     std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::static_pointer_cast<IpcNotifyDiscoverResultReq>(pBaseReq);
155     std::string pkgName = pReq->GetPkgName();
156     uint16_t subscribeId = pReq->GetSubscribeId();
157     int32_t result = pReq->GetResult();
158     if (!data.WriteString(pkgName)) {
159         LOGE("write pkgName failed");
160         return ERR_DM_IPC_WRITE_FAILED;
161     }
162     if (!data.WriteInt16((int16_t)subscribeId)) {
163         LOGE("write subscribeId failed");
164         return ERR_DM_IPC_WRITE_FAILED;
165     }
166     if (!data.WriteInt32(result)) {
167         LOGE("write result failed");
168         return ERR_DM_IPC_WRITE_FAILED;
169     }
170     return DM_OK;
171 }
172 
ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)173 ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
174 {
175     if (pBaseRsp == nullptr) {
176         LOGE("pBaseRsp is null");
177         return ERR_DM_FAILED;
178     }
179     pBaseRsp->SetErrCode(reply.ReadInt32());
180     return DM_OK;
181 }
182 
ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)183 ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
184 {
185     if (pBaseReq == nullptr) {
186         return ERR_DM_FAILED;
187     }
188     std::shared_ptr<IpcNotifyPublishResultReq> pReq = std::static_pointer_cast<IpcNotifyPublishResultReq>(pBaseReq);
189     std::string pkgName = pReq->GetPkgName();
190     int32_t publishId = pReq->GetPublishId();
191     int32_t result = pReq->GetResult();
192     if (!data.WriteString(pkgName)) {
193         LOGE("write pkgName failed");
194         return ERR_DM_IPC_WRITE_FAILED;
195     }
196     if (!data.WriteInt32(publishId)) {
197         LOGE("write publishId failed");
198         return ERR_DM_IPC_WRITE_FAILED;
199     }
200     if (!data.WriteInt32(result)) {
201         LOGE("write result failed");
202         return ERR_DM_IPC_WRITE_FAILED;
203     }
204     return DM_OK;
205 }
206 
ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)207 ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
208 {
209     if (pBaseRsp == nullptr) {
210         LOGE("pBaseRsp is null");
211         return ERR_DM_FAILED;
212     }
213     pBaseRsp->SetErrCode(reply.ReadInt32());
214     return DM_OK;
215 }
216 
ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)217 ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
218 {
219     if (pBaseReq == nullptr) {
220         return ERR_DM_FAILED;
221     }
222     std::shared_ptr<IpcNotifyAuthResultReq> pReq = std::static_pointer_cast<IpcNotifyAuthResultReq>(pBaseReq);
223 
224     std::string pkgName = pReq->GetPkgName();
225     std::string deviceId = pReq->GetDeviceId();
226     std::string token = pReq->GetPinToken();
227     int32_t status = pReq->GetStatus();
228     int32_t reason = pReq->GetReason();
229     if (!data.WriteString(pkgName)) {
230         LOGE("write pkgName failed");
231         return ERR_DM_IPC_WRITE_FAILED;
232     }
233     if (!data.WriteString(deviceId)) {
234         LOGE("write deviceId failed");
235         return ERR_DM_IPC_WRITE_FAILED;
236     }
237     if (!data.WriteString(token)) {
238         LOGE("write token failed");
239         return ERR_DM_IPC_WRITE_FAILED;
240     }
241     if (!data.WriteInt32(status)) {
242         LOGE("write status failed");
243         return ERR_DM_IPC_WRITE_FAILED;
244     }
245     if (!data.WriteInt32(reason)) {
246         LOGE("write reason failed");
247         return ERR_DM_IPC_WRITE_FAILED;
248     }
249     return DM_OK;
250 }
251 
ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)252 ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
253 {
254     if (pBaseRsp == nullptr) {
255         LOGE("pBaseRsp is null");
256         return ERR_DM_FAILED;
257     }
258     pBaseRsp->SetErrCode(reply.ReadInt32());
259     return DM_OK;
260 }
261 
ON_IPC_SET_REQUEST(SERVER_VERIFY_AUTH_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)262 ON_IPC_SET_REQUEST(SERVER_VERIFY_AUTH_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
263 {
264     if (pBaseReq == nullptr) {
265         return ERR_DM_FAILED;
266     }
267     std::shared_ptr<IpcNotifyVerifyAuthResultReq> pReq =
268         std::static_pointer_cast<IpcNotifyVerifyAuthResultReq>(pBaseReq);
269 
270     std::string pkgName = pReq->GetPkgName();
271     std::string deviceId = pReq->GetDeviceId();
272     int32_t result = pReq->GetResult();
273     int32_t flag = pReq->GetFlag();
274     if (!data.WriteString(pkgName)) {
275         LOGE("write pkgName failed");
276         return ERR_DM_IPC_WRITE_FAILED;
277     }
278     if (!data.WriteString(deviceId)) {
279         LOGE("write deviceId failed");
280         return ERR_DM_IPC_WRITE_FAILED;
281     }
282     if (!data.WriteInt32(result)) {
283         LOGE("write result failed");
284         return ERR_DM_IPC_WRITE_FAILED;
285     }
286     if (!data.WriteInt32(flag)) {
287         LOGE("write flag failed");
288         return ERR_DM_IPC_WRITE_FAILED;
289     }
290     return DM_OK;
291 }
292 
ON_IPC_READ_RESPONSE(SERVER_VERIFY_AUTH_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)293 ON_IPC_READ_RESPONSE(SERVER_VERIFY_AUTH_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
294 {
295     if (pBaseRsp == nullptr) {
296         LOGE("pBaseRsp is null");
297         return ERR_DM_FAILED;
298     }
299     pBaseRsp->SetErrCode(reply.ReadInt32());
300     return DM_OK;
301 }
302 
ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)303 ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
304 {
305     if (pBaseReq == nullptr) {
306         return ERR_DM_FAILED;
307     }
308 
309     std::shared_ptr<IpcNotifyDMFAResultReq> pReq = std::static_pointer_cast<IpcNotifyDMFAResultReq>(pBaseReq);
310 
311     std::string packagname = pReq->GetPkgName();
312     std::string paramJson = pReq->GetJsonParam();
313     if (!data.WriteString(packagname)) {
314         LOGE("write pkgName failed");
315         return ERR_DM_IPC_WRITE_FAILED;
316     }
317     if (!data.WriteString(paramJson)) {
318         LOGE("write paramJson failed");
319         return ERR_DM_IPC_WRITE_FAILED;
320     }
321     return DM_OK;
322 }
323 
ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)324 ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
325 {
326     if (pBaseRsp == nullptr) {
327         LOGE("pBaseRsp is null");
328         return ERR_DM_FAILED;
329     }
330     pBaseRsp->SetErrCode(reply.ReadInt32());
331     return DM_OK;
332 }
333 
ON_IPC_CMD(GET_TRUST_DEVICE_LIST,MessageParcel & data,MessageParcel & reply)334 ON_IPC_CMD(GET_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply)
335 {
336     std::string pkgName = data.ReadString();
337     std::string extra = data.ReadString();
338     bool isRefresh = data.ReadBool();
339     DeviceManagerService::GetInstance().ShiftLNNGear(pkgName, pkgName, isRefresh);
340     std::vector<DmDeviceInfo> deviceList;
341     int32_t result = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
342     int32_t infoNum = (int32_t)(deviceList.size());
343     DmDeviceInfo deviceInfo;
344     if (!reply.WriteInt32(infoNum)) {
345         LOGE("write infoNum failed");
346         return ERR_DM_IPC_WRITE_FAILED;
347     }
348     if (!deviceList.empty()) {
349         for (; !deviceList.empty();) {
350             deviceInfo = deviceList.back();
351             deviceList.pop_back();
352 
353             if (!reply.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) {
354                 LOGE("write subscribeInfo failed");
355                 return ERR_DM_IPC_WRITE_FAILED;
356             }
357         }
358     }
359     if (!reply.WriteInt32(result)) {
360         LOGE("write result failed");
361         return ERR_DM_IPC_WRITE_FAILED;
362     }
363     return DM_OK;
364 }
365 
ON_IPC_CMD(GET_AVAILABLE_DEVICE_LIST,MessageParcel & data,MessageParcel & reply)366 ON_IPC_CMD(GET_AVAILABLE_DEVICE_LIST, MessageParcel &data, MessageParcel &reply)
367 {
368     std::string pkgName = data.ReadString();
369     std::vector<DmDeviceBasicInfo> deviceList;
370     int32_t result = DeviceManagerService::GetInstance().GetAvailableDeviceList(pkgName, deviceList);
371     int32_t infoNum = (int32_t)(deviceList.size());
372     DmDeviceBasicInfo deviceBasicInfo;
373     if (!reply.WriteInt32(infoNum)) {
374         LOGE("write infoNum failed");
375         return ERR_DM_IPC_WRITE_FAILED;
376     }
377     if (!deviceList.empty()) {
378         for (; !deviceList.empty();) {
379             deviceBasicInfo = deviceList.back();
380             deviceList.pop_back();
381 
382             if (!reply.WriteRawData(&deviceBasicInfo, sizeof(DmDeviceBasicInfo))) {
383                 LOGE("write subscribeInfo failed");
384                 return ERR_DM_IPC_WRITE_FAILED;
385             }
386         }
387     }
388     if (!reply.WriteInt32(result)) {
389         LOGE("write result failed");
390         return ERR_DM_IPC_WRITE_FAILED;
391     }
392     return DM_OK;
393 }
394 
ON_IPC_CMD(CHECK_API_ACCESS_PERMISSION,MessageParcel & data,MessageParcel & reply)395 ON_IPC_CMD(CHECK_API_ACCESS_PERMISSION, MessageParcel &data, MessageParcel &reply)
396 {
397     int32_t result = DeviceManagerService::GetInstance().CheckApiPermission();
398     if (!reply.WriteInt32(result)) {
399         LOGE("write result failed");
400         return ERR_DM_IPC_WRITE_FAILED;
401     }
402     return DM_OK;
403 }
404 
ON_IPC_CMD(CHECK_API_ACCESS_NEWPERMISSION,MessageParcel & data,MessageParcel & reply)405 ON_IPC_CMD(CHECK_API_ACCESS_NEWPERMISSION, MessageParcel &data, MessageParcel &reply)
406 {
407     int32_t result = DeviceManagerService::GetInstance().CheckNewApiPermission();
408     if (!reply.WriteInt32(result)) {
409         LOGE("write result failed");
410         return ERR_DM_IPC_WRITE_FAILED;
411     }
412     return DM_OK;
413 }
414 
ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & data,MessageParcel & reply)415 ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply)
416 {
417     std::string pkgName = data.ReadString();
418     sptr<IRemoteObject> listener = data.ReadRemoteObject();
419     DeviceManagerService::GetInstance().RegisterDeviceManagerListener(pkgName);
420     int32_t result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
421     if (!reply.WriteInt32(result)) {
422         LOGE("write result failed");
423         return ERR_DM_IPC_WRITE_FAILED;
424     }
425     return DM_OK;
426 }
427 
ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & data,MessageParcel & reply)428 ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply)
429 {
430     std::string pkgName = data.ReadString();
431     DeviceManagerService::GetInstance().UnRegisterDeviceManagerListener(pkgName);
432     int32_t result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
433     if (!reply.WriteInt32(result)) {
434         LOGE("write result failed");
435         return ERR_DM_IPC_WRITE_FAILED;
436     }
437     return DM_OK;
438 }
439 
ON_IPC_CMD(START_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)440 ON_IPC_CMD(START_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
441 {
442     std::string pkgName = data.ReadString();
443     std::string extra = data.ReadString();
444     DmSubscribeInfo *subscribeInfo =
445         static_cast<DmSubscribeInfo *>(const_cast<void *>(data.ReadRawData(sizeof(DmSubscribeInfo))));
446     int32_t result = ERR_DM_POINT_NULL;
447 
448     if (subscribeInfo != nullptr) {
449         result = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, *subscribeInfo, extra);
450     }
451     if (!reply.WriteInt32(result)) {
452         LOGE("write result failed");
453         return ERR_DM_IPC_WRITE_FAILED;
454     }
455     return DM_OK;
456 }
457 
ON_IPC_CMD(START_DEVICE_DISCOVERY,MessageParcel & data,MessageParcel & reply)458 ON_IPC_CMD(START_DEVICE_DISCOVERY, MessageParcel &data, MessageParcel &reply)
459 {
460     std::string pkgName = data.ReadString();
461     std::string filterOption = data.ReadString();
462     uint16_t subscribeId = data.ReadUint16();
463     int32_t result = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeId, filterOption);
464     if (!reply.WriteInt32(result)) {
465         LOGE("write result failed");
466         return ERR_DM_IPC_WRITE_FAILED;
467     }
468     return DM_OK;
469 }
470 
ON_IPC_CMD(STOP_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)471 ON_IPC_CMD(STOP_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
472 {
473     std::string pkgName = data.ReadString();
474     uint16_t subscribeId = static_cast<uint16_t>(data.ReadInt32());
475     int32_t result = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId);
476     if (!reply.WriteInt32(result)) {
477         LOGE("write result failed");
478         return ERR_DM_IPC_WRITE_FAILED;
479     }
480     return DM_OK;
481 }
482 
ON_IPC_CMD(PUBLISH_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)483 ON_IPC_CMD(PUBLISH_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
484 {
485     std::string pkgName = data.ReadString();
486     DmPublishInfo *publishInfo =
487         static_cast<DmPublishInfo *>(const_cast<void *>(data.ReadRawData(sizeof(DmPublishInfo))));
488     int32_t result = ERR_DM_POINT_NULL;
489 
490     if (publishInfo != nullptr) {
491         result = DeviceManagerService::GetInstance().PublishDeviceDiscovery(pkgName, *publishInfo);
492     }
493     if (!reply.WriteInt32(result)) {
494         LOGE("write result failed");
495         return ERR_DM_IPC_WRITE_FAILED;
496     }
497     return DM_OK;
498 }
499 
ON_IPC_CMD(UNPUBLISH_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)500 ON_IPC_CMD(UNPUBLISH_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
501 {
502     std::string pkgName = data.ReadString();
503     int32_t publishId = data.ReadInt32();
504     int32_t result = DeviceManagerService::GetInstance().UnPublishDeviceDiscovery(pkgName, publishId);
505     if (!reply.WriteInt32(result)) {
506         LOGE("write result failed");
507         return ERR_DM_IPC_WRITE_FAILED;
508     }
509     return DM_OK;
510 }
511 
ON_IPC_CMD(AUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)512 ON_IPC_CMD(AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
513 {
514     std::string pkgName = data.ReadString();
515     std::string extra = data.ReadString();
516     std::string deviceId = data.ReadString();
517     int32_t authType = data.ReadInt32();
518 
519     int32_t result = DM_OK;
520     result = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
521     if (!reply.WriteInt32(result)) {
522         LOGE("write result failed");
523         return ERR_DM_IPC_WRITE_FAILED;
524     }
525     return DM_OK;
526 }
527 
ON_IPC_CMD(UNAUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)528 ON_IPC_CMD(UNAUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
529 {
530     std::string pkgName = data.ReadString();
531     std::string deviceId = data.ReadString();
532     int32_t result = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
533     if (!reply.WriteInt32(result)) {
534         LOGE("write result failed");
535         return ERR_DM_IPC_WRITE_FAILED;
536     }
537     return DM_OK;
538 }
539 
ON_IPC_CMD(VERIFY_AUTHENTICATION,MessageParcel & data,MessageParcel & reply)540 ON_IPC_CMD(VERIFY_AUTHENTICATION, MessageParcel &data, MessageParcel &reply)
541 {
542     std::string authPara = data.ReadString();
543     int32_t result = DeviceManagerService::GetInstance().VerifyAuthentication(authPara);
544     if (!reply.WriteInt32(result)) {
545         LOGE("write result failed");
546         return ERR_DM_IPC_WRITE_FAILED;
547     }
548     return DM_OK;
549 }
550 
ON_IPC_CMD(GET_DEVICE_INFO,MessageParcel & data,MessageParcel & reply)551 ON_IPC_CMD(GET_DEVICE_INFO, MessageParcel &data, MessageParcel &reply)
552 {
553     std::string networkId = data.ReadString();
554     DmDeviceInfo deviceInfo;
555     int32_t result = DeviceManagerService::GetInstance().GetDeviceInfo(networkId, deviceInfo);
556 
557     if (!reply.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) {
558         LOGE("write deviceInfo failed");
559         return ERR_DM_IPC_WRITE_FAILED;
560     }
561 
562     if (!reply.WriteInt32(result)) {
563         LOGE("write result failed");
564         return ERR_DM_IPC_WRITE_FAILED;
565     }
566     return DM_OK;
567 }
568 
ON_IPC_CMD(GET_LOCAL_DEVICE_INFO,MessageParcel & data,MessageParcel & reply)569 ON_IPC_CMD(GET_LOCAL_DEVICE_INFO, MessageParcel &data, MessageParcel &reply)
570 {
571     (void)data;
572     DmDeviceInfo localDeviceInfo;
573     int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceInfo(localDeviceInfo);
574 
575     if (!reply.WriteRawData(&localDeviceInfo, sizeof(DmDeviceInfo))) {
576         LOGE("write localDeviceInfo failed");
577     }
578 
579     if (!reply.WriteInt32(result)) {
580         LOGE("write result failed");
581         return ERR_DM_IPC_WRITE_FAILED;
582     }
583     return DM_OK;
584 }
585 
ON_IPC_CMD(GET_LOCAL_DEVICE_NETWORKID,MessageParcel & data,MessageParcel & reply)586 ON_IPC_CMD(GET_LOCAL_DEVICE_NETWORKID, MessageParcel &data, MessageParcel &reply)
587 {
588     std::string networkId = "";
589     int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceNetworkId(networkId);
590     if (!reply.WriteString(networkId)) {
591         LOGE("write LocalDeviceNetworkId failed");
592     }
593     if (!reply.WriteInt32(result)) {
594         LOGE("write result failed");
595         return ERR_DM_IPC_WRITE_FAILED;
596     }
597     return DM_OK;
598 }
599 
ON_IPC_CMD(GET_LOCAL_DEVICEID,MessageParcel & data,MessageParcel & reply)600 ON_IPC_CMD(GET_LOCAL_DEVICEID, MessageParcel &data, MessageParcel &reply)
601 {
602     std::string pkgName = data.ReadString();
603     std::string deviceId = "";
604     int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceId(pkgName, deviceId);
605     if (!reply.WriteString(deviceId)) {
606         LOGE("write GetLocalDeviceId failed");
607     }
608     if (!reply.WriteInt32(result)) {
609         LOGE("write result failed");
610         return ERR_DM_IPC_WRITE_FAILED;
611     }
612     return DM_OK;
613 }
614 
ON_IPC_CMD(GET_LOCAL_DEVICE_NAME,MessageParcel & data,MessageParcel & reply)615 ON_IPC_CMD(GET_LOCAL_DEVICE_NAME, MessageParcel &data, MessageParcel &reply)
616 {
617     std::string deviceName = "";
618     int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceName(deviceName);
619     if (!reply.WriteString(deviceName)) {
620         LOGE("write GetLocalDeviceName failed");
621     }
622     if (!reply.WriteInt32(result)) {
623         LOGE("write result failed");
624         return ERR_DM_IPC_WRITE_FAILED;
625     }
626     return DM_OK;
627 }
628 
ON_IPC_CMD(GET_LOCAL_DEVICE_TYPE,MessageParcel & data,MessageParcel & reply)629 ON_IPC_CMD(GET_LOCAL_DEVICE_TYPE, MessageParcel &data, MessageParcel &reply)
630 {
631     int32_t deviceType = 0;
632     int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceType(deviceType);
633     if (!reply.WriteInt32(deviceType)) {
634         LOGE("write GetLocalDeviceName failed");
635     }
636     if (!reply.WriteInt32(result)) {
637         LOGE("write result failed");
638         return ERR_DM_IPC_WRITE_FAILED;
639     }
640     return DM_OK;
641 }
642 
ON_IPC_CMD(GET_UDID_BY_NETWORK,MessageParcel & data,MessageParcel & reply)643 ON_IPC_CMD(GET_UDID_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
644 {
645     std::string pkgName = data.ReadString();
646     std::string netWorkId = data.ReadString();
647     std::string udid;
648     int32_t result = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid);
649 
650     if (!reply.WriteInt32(result)) {
651         LOGE("write result failed");
652         return ERR_DM_IPC_WRITE_FAILED;
653     }
654     if (!reply.WriteString(udid)) {
655         LOGE("write result failed");
656         return ERR_DM_IPC_WRITE_FAILED;
657     }
658     return DM_OK;
659 }
660 
ON_IPC_CMD(GET_UUID_BY_NETWORK,MessageParcel & data,MessageParcel & reply)661 ON_IPC_CMD(GET_UUID_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
662 {
663     std::string pkgName = data.ReadString();
664     std::string netWorkId = data.ReadString();
665     std::string uuid;
666     int32_t result = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid);
667 
668     if (!reply.WriteInt32(result)) {
669         LOGE("write result failed");
670         return ERR_DM_IPC_WRITE_FAILED;
671     }
672     if (!reply.WriteString(uuid)) {
673         LOGE("write result failed");
674         return ERR_DM_IPC_WRITE_FAILED;
675     }
676     return DM_OK;
677 }
678 
ON_IPC_CMD(SERVER_GET_DMFA_INFO,MessageParcel & data,MessageParcel & reply)679 ON_IPC_CMD(SERVER_GET_DMFA_INFO, MessageParcel &data, MessageParcel &reply)
680 {
681     std::string packName = data.ReadString();
682     DmAuthParam authParam;
683     if (DeviceManagerService::GetInstance().GetFaParam(packName, authParam) != DM_OK) {
684         LOGE("ipc read fa parm failed");
685         return ERR_DM_IPC_READ_FAILED;
686     }
687     int32_t appIconLen = authParam.imageinfo.GetAppIconLen();
688     int32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen();
689 
690     reply.WriteInt32(authParam.direction);
691     reply.WriteInt32(authParam.authType);
692     reply.WriteString(authParam.authToken);
693     reply.WriteString(authParam.packageName);
694     reply.WriteString(authParam.appName);
695     reply.WriteString(authParam.appDescription);
696     reply.WriteInt32(authParam.business);
697     reply.WriteInt32(authParam.pincode);
698     reply.WriteInt32(appIconLen);
699     reply.WriteInt32(appThumbnailLen);
700 
701     if (appIconLen > 0 && authParam.imageinfo.GetAppIcon() != nullptr) {
702         if (!reply.WriteRawData(authParam.imageinfo.GetAppIcon(), appIconLen)) {
703             LOGE("write appIcon failed");
704             return ERR_DM_IPC_WRITE_FAILED;
705         }
706     }
707     if (appThumbnailLen > 0 && authParam.imageinfo.GetAppThumbnail() != nullptr) {
708         if (!reply.WriteRawData(authParam.imageinfo.GetAppThumbnail(), appThumbnailLen)) {
709             LOGE("write appThumbnail failed");
710             return ERR_DM_IPC_WRITE_FAILED;
711         }
712     }
713     return DM_OK;
714 }
715 
ON_IPC_CMD(SERVER_USER_AUTH_OPERATION,MessageParcel & data,MessageParcel & reply)716 ON_IPC_CMD(SERVER_USER_AUTH_OPERATION, MessageParcel &data, MessageParcel &reply)
717 {
718     std::string packageName = data.ReadString();
719     int32_t action = data.ReadInt32();
720     std::string params = data.ReadString();
721     int result = DeviceManagerService::GetInstance().SetUserOperation(packageName, action, params);
722     if (!reply.WriteInt32(result)) {
723         return ERR_DM_IPC_WRITE_FAILED;
724     }
725     return result;
726 }
727 
ON_IPC_CMD(REGISTER_DEV_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)728 ON_IPC_CMD(REGISTER_DEV_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
729 {
730     std::string packageName = data.ReadString();
731     std::string extra = data.ReadString();
732     int result = DeviceManagerService::GetInstance().RegisterDevStateCallback(packageName, extra);
733     if (!reply.WriteInt32(result)) {
734         LOGE("write result failed");
735         return ERR_DM_IPC_WRITE_FAILED;
736     }
737     return result;
738 }
739 
ON_IPC_CMD(UNREGISTER_DEV_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)740 ON_IPC_CMD(UNREGISTER_DEV_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
741 {
742     std::string packageName = data.ReadString();
743     std::string extra = data.ReadString();
744     int result = DeviceManagerService::GetInstance().UnRegisterDevStateCallback(packageName, extra);
745     if (!reply.WriteInt32(result)) {
746         LOGE("write result failed");
747         return ERR_DM_IPC_WRITE_FAILED;
748     }
749     return result;
750 }
751 
ON_IPC_CMD(REQUEST_CREDENTIAL,MessageParcel & data,MessageParcel & reply)752 ON_IPC_CMD(REQUEST_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
753 {
754     std::string packageName = data.ReadString();
755     std::string reqJsonStr = data.ReadString();
756     std::string returnJsonStr;
757     int32_t ret = DeviceManagerService::GetInstance().RequestCredential(reqJsonStr, returnJsonStr);
758     if (!reply.WriteInt32(ret)) {
759         LOGE("write ret failed");
760         return ERR_DM_IPC_WRITE_FAILED;
761     }
762     if (ret == DM_OK && !returnJsonStr.empty()) {
763         if (!reply.WriteString(returnJsonStr))
764         {
765             LOGE("write returnJsonStr failed");
766             return ERR_DM_IPC_WRITE_FAILED;
767         }
768     }
769     return DM_OK;
770 }
771 
ON_IPC_CMD(IMPORT_CREDENTIAL,MessageParcel & data,MessageParcel & reply)772 ON_IPC_CMD(IMPORT_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
773 {
774     std::string packageName = data.ReadString();
775     std::string credentialInfo = data.ReadString();
776     int32_t ret = DeviceManagerService::GetInstance().ImportCredential(packageName, credentialInfo);
777     if (!reply.WriteInt32(ret)) {
778         LOGE("write ret failed");
779         return ERR_DM_IPC_WRITE_FAILED;
780     }
781     return DM_OK;
782 }
783 
ON_IPC_CMD(DELETE_CREDENTIAL,MessageParcel & data,MessageParcel & reply)784 ON_IPC_CMD(DELETE_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
785 {
786     std::string packageName = data.ReadString();
787     std::string deleteInfo = data.ReadString();
788     int32_t ret = DeviceManagerService::GetInstance().DeleteCredential(packageName, deleteInfo);
789     if (!reply.WriteInt32(ret)) {
790         LOGE("write ret failed");
791         return ERR_DM_IPC_WRITE_FAILED;
792     }
793     return DM_OK;
794 }
795 
ON_IPC_CMD(REGISTER_CREDENTIAL_CALLBACK,MessageParcel & data,MessageParcel & reply)796 ON_IPC_CMD(REGISTER_CREDENTIAL_CALLBACK, MessageParcel &data, MessageParcel &reply)
797 {
798     std::string packageName = data.ReadString();
799     int result = DeviceManagerService::GetInstance().RegisterCredentialCallback(packageName);
800     if (!reply.WriteInt32(result)) {
801         LOGE("write result failed");
802         return ERR_DM_IPC_WRITE_FAILED;
803     }
804     return result;
805 }
806 
ON_IPC_CMD(UNREGISTER_CREDENTIAL_CALLBACK,MessageParcel & data,MessageParcel & reply)807 ON_IPC_CMD(UNREGISTER_CREDENTIAL_CALLBACK, MessageParcel &data, MessageParcel &reply)
808 {
809     std::string packageName = data.ReadString();
810     int result = DeviceManagerService::GetInstance().UnRegisterCredentialCallback(packageName);
811     if (!reply.WriteInt32(result)) {
812         LOGE("write result failed");
813         return ERR_DM_IPC_WRITE_FAILED;
814     }
815     return result;
816 }
817 
ON_IPC_CMD(NOTIFY_EVENT,MessageParcel & data,MessageParcel & reply)818 ON_IPC_CMD(NOTIFY_EVENT, MessageParcel &data, MessageParcel &reply)
819 {
820     std::string pkgName = data.ReadString();
821     int32_t eventId = data.ReadInt32();
822     std::string event = data.ReadString();
823     int32_t result = DeviceManagerService::GetInstance().NotifyEvent(pkgName, eventId, event);
824     if (!reply.WriteInt32(result)) {
825         LOGE("write result failed");
826         return ERR_DM_IPC_WRITE_FAILED;
827     }
828     return DM_OK;
829 }
830 
ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)831 ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
832 {
833     if (pBaseReq == nullptr) {
834         return ERR_DM_FAILED;
835     }
836     std::shared_ptr<IpcNotifyCredentialReq> pReq = std::static_pointer_cast<IpcNotifyCredentialReq>(pBaseReq);
837     std::string pkgName = pReq->GetPkgName();
838     int32_t action = pReq->GetCredentialAction();
839     std::string credentialResult = pReq->GetCredentialResult();
840     if (!data.WriteString(pkgName)) {
841         LOGE("write pkgName failed");
842         return ERR_DM_IPC_WRITE_FAILED;
843     }
844     if (!data.WriteInt32(action)) {
845         LOGE("write action failed");
846         return ERR_DM_IPC_WRITE_FAILED;
847     }
848     if (!data.WriteString(credentialResult)) {
849         LOGE("write credentialResult failed");
850         return ERR_DM_IPC_WRITE_FAILED;
851     }
852 
853     return DM_OK;
854 }
855 
ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)856 ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
857 {
858     if (pBaseRsp == nullptr) {
859         LOGE("pBaseRsp is null");
860         return ERR_DM_FAILED;
861     }
862     pBaseRsp->SetErrCode(reply.ReadInt32());
863     return DM_OK;
864 }
865 
866 
ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID,MessageParcel & data,MessageParcel & reply)867 ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &data, MessageParcel &reply)
868 {
869     std::string pkgName = data.ReadString();
870     std::string networkId = data.ReadString();
871     std::string uuid;
872 
873     int32_t result = DeviceManagerService::GetInstance().GetEncryptedUuidByNetworkId(pkgName, networkId, uuid);
874     if (!reply.WriteInt32(result)) {
875         LOGE("write result failed");
876         return ERR_DM_IPC_WRITE_FAILED;
877     }
878     if (!reply.WriteString(uuid)) {
879         LOGE("write uuid failed");
880         return ERR_DM_IPC_WRITE_FAILED;
881     }
882     return DM_OK;
883 }
884 
ON_IPC_CMD(GENERATE_ENCRYPTED_UUID,MessageParcel & data,MessageParcel & reply)885 ON_IPC_CMD(GENERATE_ENCRYPTED_UUID, MessageParcel &data, MessageParcel &reply)
886 {
887     std::string pkgName = data.ReadString();
888     std::string uuid = data.ReadString();
889     std::string appId = data.ReadString();
890     std::string encryptedUuid;
891 
892     int32_t result = DeviceManagerService::GetInstance().GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid);
893     if (!reply.WriteInt32(result)) {
894         LOGE("write result failed");
895         return ERR_DM_IPC_WRITE_FAILED;
896     }
897     if (!reply.WriteString(encryptedUuid)) {
898         LOGE("write encryptedUuid failed");
899         return ERR_DM_IPC_WRITE_FAILED;
900     }
901     return DM_OK;
902 }
903 
ON_IPC_CMD(BIND_DEVICE,MessageParcel & data,MessageParcel & reply)904 ON_IPC_CMD(BIND_DEVICE, MessageParcel &data, MessageParcel &reply)
905 {
906     std::string pkgName = data.ReadString();
907     std::string bindParam = data.ReadString();
908     std::string deviceId = data.ReadString();
909     int32_t bindType = data.ReadInt32();
910     int32_t result = DM_OK;
911     result = DeviceManagerService::GetInstance().BindDevice(pkgName, bindType, deviceId, bindParam);
912     if (!reply.WriteInt32(result)) {
913         LOGE("write result failed");
914         return ERR_DM_IPC_WRITE_FAILED;
915     }
916     return DM_OK;
917 }
918 
ON_IPC_CMD(UNBIND_DEVICE,MessageParcel & data,MessageParcel & reply)919 ON_IPC_CMD(UNBIND_DEVICE, MessageParcel &data, MessageParcel &reply)
920 {
921     std::string pkgName = data.ReadString();
922     std::string deviceId = data.ReadString();
923     int32_t result = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId);
924     if (!reply.WriteInt32(result)) {
925         LOGE("write result failed");
926         return ERR_DM_IPC_WRITE_FAILED;
927     }
928     return DM_OK;
929 }
930 
ON_IPC_CMD(GET_NETWORKTYPE_BY_NETWORK,MessageParcel & data,MessageParcel & reply)931 ON_IPC_CMD(GET_NETWORKTYPE_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
932 {
933     std::string pkgName = data.ReadString();
934     std::string netWorkId = data.ReadString();
935     int32_t networkType = -1;
936     int32_t result = DeviceManagerService::GetInstance().GetNetworkTypeByNetworkId(pkgName, netWorkId, networkType);
937     if (!reply.WriteInt32(result)) {
938         LOGE("write result failed");
939         return ERR_DM_IPC_WRITE_FAILED;
940     }
941     if (!reply.WriteInt32(networkType)) {
942         LOGE("write result failed");
943         return ERR_DM_IPC_WRITE_FAILED;
944     }
945     return DM_OK;
946 }
947 
ON_IPC_CMD(REGISTER_UI_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)948 ON_IPC_CMD(REGISTER_UI_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
949 {
950     std::string pkgName = data.ReadString();
951     int32_t result = DeviceManagerService::GetInstance().RegisterUiStateCallback(pkgName);
952     if (!reply.WriteInt32(result)) {
953         LOGE("write result failed");
954         return ERR_DM_IPC_WRITE_FAILED;
955     }
956     return DM_OK;
957 }
958 
ON_IPC_CMD(UNREGISTER_UI_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)959 ON_IPC_CMD(UNREGISTER_UI_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
960 {
961     std::string pkgName = data.ReadString();
962     int32_t result = DeviceManagerService::GetInstance().UnRegisterUiStateCallback(pkgName);
963     if (!reply.WriteInt32(result)) {
964         LOGE("write result failed");
965         return ERR_DM_IPC_WRITE_FAILED;
966     }
967     return DM_OK;
968 }
969 } // namespace DistributedHardware
970 } // namespace OHOS
971