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_service.h"
19 #include "dm_constants.h"
20 #include "dm_device_info.h"
21 #include "dm_log.h"
22 #include "dm_subscribe_info.h"
23 #include "dm_publish_info.h"
24 #include "ipc_cmd_register.h"
25 #include "ipc_def.h"
26 #include "ipc_notify_auth_result_req.h"
27 #include "ipc_notify_credential_req.h"
28 #include "ipc_notify_device_found_req.h"
29 #include "ipc_notify_device_state_req.h"
30 #include "ipc_notify_discover_result_req.h"
31 #include "ipc_notify_publish_result_req.h"
32 #include "ipc_notify_verify_auth_result_req.h"
33 #include "ipc_server_stub.h"
34
35 namespace OHOS {
36 namespace DistributedHardware {
ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)37 ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
38 {
39 if (pBaseReq == nullptr) {
40 return ERR_DM_FAILED;
41 }
42
43 std::shared_ptr<IpcNotifyDeviceStateReq> pReq = std::static_pointer_cast<IpcNotifyDeviceStateReq>(pBaseReq);
44 std::string pkgName = pReq->GetPkgName();
45 int32_t deviceState = pReq->GetDeviceState();
46 DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
47 if (!data.WriteString(pkgName)) {
48 LOGE("write pkgName failed");
49 return ERR_DM_IPC_WRITE_FAILED;
50 }
51 if (!data.WriteInt32(deviceState)) {
52 LOGE("write state failed");
53 return ERR_DM_IPC_WRITE_FAILED;
54 }
55 if (!data.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) {
56 LOGE("write deviceInfo failed");
57 return ERR_DM_IPC_WRITE_FAILED;
58 }
59 return DM_OK;
60 }
61
ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)62 ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
63 {
64 if (pBaseRsp == nullptr) {
65 LOGE("pBaseRsp is null");
66 return ERR_DM_FAILED;
67 }
68 pBaseRsp->SetErrCode(reply.ReadInt32());
69 return DM_OK;
70 }
71
ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)72 ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
73 {
74 if (pBaseReq == nullptr) {
75 return ERR_DM_FAILED;
76 }
77
78 std::shared_ptr<IpcNotifyDeviceFoundReq> pReq = std::static_pointer_cast<IpcNotifyDeviceFoundReq>(pBaseReq);
79 std::string pkgName = pReq->GetPkgName();
80 uint16_t subscribeId = pReq->GetSubscribeId();
81 DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
82 if (!data.WriteString(pkgName)) {
83 LOGE("write pkgName failed");
84 return ERR_DM_IPC_WRITE_FAILED;
85 }
86 if (!data.WriteInt16((int16_t)subscribeId)) {
87 LOGE("write subscribeId failed");
88 return ERR_DM_IPC_WRITE_FAILED;
89 }
90 if (!data.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) {
91 LOGE("write deviceInfo failed");
92 return ERR_DM_IPC_WRITE_FAILED;
93 }
94 return DM_OK;
95 }
96
ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)97 ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
98 {
99 if (pBaseRsp == nullptr) {
100 LOGE("pBaseRsp is null");
101 return ERR_DM_FAILED;
102 }
103 pBaseRsp->SetErrCode(reply.ReadInt32());
104 return DM_OK;
105 }
106
ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)107 ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
108 {
109 if (pBaseReq == nullptr) {
110 return ERR_DM_FAILED;
111 }
112 std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::static_pointer_cast<IpcNotifyDiscoverResultReq>(pBaseReq);
113 std::string pkgName = pReq->GetPkgName();
114 uint16_t subscribeId = pReq->GetSubscribeId();
115 int32_t result = pReq->GetResult();
116 if (!data.WriteString(pkgName)) {
117 LOGE("write pkgName failed");
118 return ERR_DM_IPC_WRITE_FAILED;
119 }
120 if (!data.WriteInt16((int16_t)subscribeId)) {
121 LOGE("write subscribeId failed");
122 return ERR_DM_IPC_WRITE_FAILED;
123 }
124 if (!data.WriteInt32(result)) {
125 LOGE("write result failed");
126 return ERR_DM_IPC_WRITE_FAILED;
127 }
128 return DM_OK;
129 }
130
ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)131 ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
132 {
133 if (pBaseRsp == nullptr) {
134 LOGE("pBaseRsp is null");
135 return ERR_DM_FAILED;
136 }
137 pBaseRsp->SetErrCode(reply.ReadInt32());
138 return DM_OK;
139 }
140
ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)141 ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
142 {
143 if (pBaseReq == nullptr) {
144 return ERR_DM_FAILED;
145 }
146 std::shared_ptr<IpcNotifyPublishResultReq> pReq = std::static_pointer_cast<IpcNotifyPublishResultReq>(pBaseReq);
147 std::string pkgName = pReq->GetPkgName();
148 int32_t publishId = pReq->GetPublishId();
149 int32_t result = pReq->GetResult();
150 if (!data.WriteString(pkgName)) {
151 LOGE("write pkgName failed");
152 return ERR_DM_IPC_WRITE_FAILED;
153 }
154 if (!data.WriteInt32(publishId)) {
155 LOGE("write publishId failed");
156 return ERR_DM_IPC_WRITE_FAILED;
157 }
158 if (!data.WriteInt32(result)) {
159 LOGE("write result failed");
160 return ERR_DM_IPC_WRITE_FAILED;
161 }
162 return DM_OK;
163 }
164
ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)165 ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
166 {
167 if (pBaseRsp == nullptr) {
168 LOGE("pBaseRsp is null");
169 return ERR_DM_FAILED;
170 }
171 pBaseRsp->SetErrCode(reply.ReadInt32());
172 return DM_OK;
173 }
174
ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)175 ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
176 {
177 if (pBaseReq == nullptr) {
178 return ERR_DM_FAILED;
179 }
180 std::shared_ptr<IpcNotifyAuthResultReq> pReq = std::static_pointer_cast<IpcNotifyAuthResultReq>(pBaseReq);
181
182 std::string pkgName = pReq->GetPkgName();
183 std::string deviceId = pReq->GetDeviceId();
184 std::string token = pReq->GetPinToken();
185 int32_t status = pReq->GetStatus();
186 int32_t reason = pReq->GetReason();
187 if (!data.WriteString(pkgName)) {
188 LOGE("write pkgName failed");
189 return ERR_DM_IPC_WRITE_FAILED;
190 }
191 if (!data.WriteString(deviceId)) {
192 LOGE("write deviceId failed");
193 return ERR_DM_IPC_WRITE_FAILED;
194 }
195 if (!data.WriteString(token)) {
196 LOGE("write token failed");
197 return ERR_DM_IPC_WRITE_FAILED;
198 }
199 if (!data.WriteInt32(status)) {
200 LOGE("write status failed");
201 return ERR_DM_IPC_WRITE_FAILED;
202 }
203 if (!data.WriteInt32(reason)) {
204 LOGE("write reason failed");
205 return ERR_DM_IPC_WRITE_FAILED;
206 }
207 return DM_OK;
208 }
209
ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)210 ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
211 {
212 if (pBaseRsp == nullptr) {
213 LOGE("pBaseRsp is null");
214 return ERR_DM_FAILED;
215 }
216 pBaseRsp->SetErrCode(reply.ReadInt32());
217 return DM_OK;
218 }
219
ON_IPC_SET_REQUEST(SERVER_VERIFY_AUTH_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)220 ON_IPC_SET_REQUEST(SERVER_VERIFY_AUTH_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
221 {
222 if (pBaseReq == nullptr) {
223 return ERR_DM_FAILED;
224 }
225 std::shared_ptr<IpcNotifyVerifyAuthResultReq> pReq =
226 std::static_pointer_cast<IpcNotifyVerifyAuthResultReq>(pBaseReq);
227
228 std::string pkgName = pReq->GetPkgName();
229 std::string deviceId = pReq->GetDeviceId();
230 int32_t result = pReq->GetResult();
231 int32_t flag = pReq->GetFlag();
232 if (!data.WriteString(pkgName)) {
233 LOGE("write pkgName failed");
234 return ERR_DM_IPC_WRITE_FAILED;
235 }
236 if (!data.WriteString(deviceId)) {
237 LOGE("write deviceId failed");
238 return ERR_DM_IPC_WRITE_FAILED;
239 }
240 if (!data.WriteInt32(result)) {
241 LOGE("write result failed");
242 return ERR_DM_IPC_WRITE_FAILED;
243 }
244 if (!data.WriteInt32(flag)) {
245 LOGE("write flag failed");
246 return ERR_DM_IPC_WRITE_FAILED;
247 }
248 return DM_OK;
249 }
250
ON_IPC_READ_RESPONSE(SERVER_VERIFY_AUTH_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)251 ON_IPC_READ_RESPONSE(SERVER_VERIFY_AUTH_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
252 {
253 if (pBaseRsp == nullptr) {
254 LOGE("pBaseRsp is null");
255 return ERR_DM_FAILED;
256 }
257 pBaseRsp->SetErrCode(reply.ReadInt32());
258 return DM_OK;
259 }
260
ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)261 ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
262 {
263 if (pBaseReq == nullptr) {
264 return ERR_DM_FAILED;
265 }
266
267 std::shared_ptr<IpcNotifyDMFAResultReq> pReq = std::static_pointer_cast<IpcNotifyDMFAResultReq>(pBaseReq);
268
269 std::string packagname = pReq->GetPkgName();
270 std::string paramJson = pReq->GetJsonParam();
271 if (!data.WriteString(packagname)) {
272 LOGE("write pkgName failed");
273 return ERR_DM_IPC_WRITE_FAILED;
274 }
275 if (!data.WriteString(paramJson)) {
276 LOGE("write paramJson failed");
277 return ERR_DM_IPC_WRITE_FAILED;
278 }
279 return DM_OK;
280 }
281
ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)282 ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
283 {
284 if (pBaseRsp == nullptr) {
285 LOGE("pBaseRsp is null");
286 return ERR_DM_FAILED;
287 }
288 pBaseRsp->SetErrCode(reply.ReadInt32());
289 return DM_OK;
290 }
291
ON_IPC_CMD(GET_TRUST_DEVICE_LIST,MessageParcel & data,MessageParcel & reply)292 ON_IPC_CMD(GET_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply)
293 {
294 std::string pkgName = data.ReadString();
295 std::string extra = data.ReadString();
296 std::vector<DmDeviceInfo> deviceList;
297 int32_t result = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
298 int32_t infoNum =(int32_t)(deviceList.size());
299 DmDeviceInfo deviceInfo;
300 if (!reply.WriteInt32(infoNum)) {
301 LOGE("write infoNum failed");
302 return ERR_DM_IPC_WRITE_FAILED;
303 }
304 if (!deviceList.empty()) {
305 for (; !deviceList.empty();) {
306 deviceInfo = deviceList.back();
307 deviceList.pop_back();
308
309 if (!reply.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) {
310 LOGE("write subscribeInfo failed");
311 return ERR_DM_IPC_WRITE_FAILED;
312 }
313 }
314 }
315 if (!reply.WriteInt32(result)) {
316 LOGE("write result failed");
317 return ERR_DM_IPC_WRITE_FAILED;
318 }
319 return DM_OK;
320 }
321
ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & data,MessageParcel & reply)322 ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply)
323 {
324 std::string pkgName = data.ReadString();
325 sptr<IRemoteObject> listener = data.ReadRemoteObject();
326 int32_t result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
327 if (!reply.WriteInt32(result)) {
328 LOGE("write result failed");
329 return ERR_DM_IPC_WRITE_FAILED;
330 }
331 return DM_OK;
332 }
333
ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & data,MessageParcel & reply)334 ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply)
335 {
336 std::string pkgName = data.ReadString();
337 int32_t result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
338 if (!reply.WriteInt32(result)) {
339 LOGE("write result failed");
340 return ERR_DM_IPC_WRITE_FAILED;
341 }
342 return DM_OK;
343 }
344
ON_IPC_CMD(START_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)345 ON_IPC_CMD(START_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
346 {
347 std::string pkgName = data.ReadString();
348 std::string extra = data.ReadString();
349 DmSubscribeInfo *subscribeInfo = (DmSubscribeInfo *)data.ReadRawData(sizeof(DmSubscribeInfo));
350 int32_t result = ERR_DM_POINT_NULL;
351
352 if (subscribeInfo != nullptr) {
353 result = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, *subscribeInfo, extra);
354 }
355 if (!reply.WriteInt32(result)) {
356 LOGE("write result failed");
357 return ERR_DM_IPC_WRITE_FAILED;
358 }
359 return DM_OK;
360 }
361
ON_IPC_CMD(STOP_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)362 ON_IPC_CMD(STOP_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
363 {
364 std::string pkgName = data.ReadString();
365 uint16_t subscribeId = (uint16_t)(data.ReadInt32());
366 int32_t result = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId);
367 if (!reply.WriteInt32(result)) {
368 LOGE("write result failed");
369 return ERR_DM_IPC_WRITE_FAILED;
370 }
371 return DM_OK;
372 }
373
ON_IPC_CMD(PUBLISH_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)374 ON_IPC_CMD(PUBLISH_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
375 {
376 std::string pkgName = data.ReadString();
377 DmPublishInfo *publishInfo = (DmPublishInfo *)data.ReadRawData(sizeof(DmPublishInfo));
378 int32_t result = ERR_DM_POINT_NULL;
379
380 if (publishInfo != nullptr) {
381 result = DeviceManagerService::GetInstance().PublishDeviceDiscovery(pkgName, *publishInfo);
382 }
383 if (!reply.WriteInt32(result)) {
384 LOGE("write result failed");
385 return ERR_DM_IPC_WRITE_FAILED;
386 }
387 return DM_OK;
388 }
389
ON_IPC_CMD(UNPUBLISH_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)390 ON_IPC_CMD(UNPUBLISH_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
391 {
392 std::string pkgName = data.ReadString();
393 int32_t publishId = data.ReadInt32();
394 int32_t result = DeviceManagerService::GetInstance().UnPublishDeviceDiscovery(pkgName, publishId);
395 if (!reply.WriteInt32(result)) {
396 LOGE("write result failed");
397 return ERR_DM_IPC_WRITE_FAILED;
398 }
399 return DM_OK;
400 }
401
ON_IPC_CMD(AUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)402 ON_IPC_CMD(AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
403 {
404 std::string pkgName = data.ReadString();
405 std::string extra = data.ReadString();
406 std::string deviceId = data.ReadString();
407 int32_t authType = data.ReadInt32();
408 int32_t result = DM_OK;
409 result = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
410 if (!reply.WriteInt32(result)) {
411 LOGE("write result failed");
412 return ERR_DM_IPC_WRITE_FAILED;
413 }
414 return DM_OK;
415 }
416
ON_IPC_CMD(UNAUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)417 ON_IPC_CMD(UNAUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
418 {
419 std::string pkgName = data.ReadString();
420 std::string deviceId = data.ReadString();
421 int32_t result = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
422 if (!reply.WriteInt32(result)) {
423 LOGE("write result failed");
424 return ERR_DM_IPC_WRITE_FAILED;
425 }
426 return DM_OK;
427 }
428
ON_IPC_CMD(VERIFY_AUTHENTICATION,MessageParcel & data,MessageParcel & reply)429 ON_IPC_CMD(VERIFY_AUTHENTICATION, MessageParcel &data, MessageParcel &reply)
430 {
431 std::string authPara = data.ReadString();
432 int32_t result = DeviceManagerService::GetInstance().VerifyAuthentication(authPara);
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(GET_LOCAL_DEVICE_INFO,MessageParcel & data,MessageParcel & reply)440 ON_IPC_CMD(GET_LOCAL_DEVICE_INFO, MessageParcel &data, MessageParcel &reply)
441 {
442 DmDeviceInfo localDeviceInfo;
443 int32_t result = 0;
444 result = DeviceManagerService::GetInstance().GetLocalDeviceInfo(localDeviceInfo);
445
446 if (!reply.WriteRawData(&localDeviceInfo, sizeof(DmDeviceInfo))) {
447 LOGE("write subscribeInfo failed");
448 }
449
450 if (!reply.WriteInt32(result)) {
451 LOGE("write result failed");
452 return ERR_DM_IPC_WRITE_FAILED;
453 }
454 return DM_OK;
455 }
456
ON_IPC_CMD(GET_UDID_BY_NETWORK,MessageParcel & data,MessageParcel & reply)457 ON_IPC_CMD(GET_UDID_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
458 {
459 std::string pkgName = data.ReadString();
460 std::string netWorkId = data.ReadString();
461 std::string udid;
462 int32_t result = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid);
463
464 if (!reply.WriteInt32(result)) {
465 LOGE("write result failed");
466 return ERR_DM_IPC_WRITE_FAILED;
467 }
468 if (!reply.WriteString(udid)) {
469 LOGE("write result failed");
470 return ERR_DM_IPC_WRITE_FAILED;
471 }
472 return DM_OK;
473 }
474
ON_IPC_CMD(GET_UUID_BY_NETWORK,MessageParcel & data,MessageParcel & reply)475 ON_IPC_CMD(GET_UUID_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
476 {
477 std::string pkgName = data.ReadString();
478 std::string netWorkId = data.ReadString();
479 std::string uuid;
480 int32_t result = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid);
481
482 if (!reply.WriteInt32(result)) {
483 LOGE("write result failed");
484 return ERR_DM_IPC_WRITE_FAILED;
485 }
486 if (!reply.WriteString(uuid)) {
487 LOGE("write result failed");
488 return ERR_DM_IPC_WRITE_FAILED;
489 }
490 return DM_OK;
491 }
492
ON_IPC_CMD(SERVER_GET_DMFA_INFO,MessageParcel & data,MessageParcel & reply)493 ON_IPC_CMD(SERVER_GET_DMFA_INFO, MessageParcel &data, MessageParcel &reply)
494 {
495 std::string packName = data.ReadString();
496 DmAuthParam authParam;
497 if (DeviceManagerService::GetInstance().GetFaParam(packName, authParam) != DM_OK) {
498 LOGE("ipc read fa parm failed");
499 return ERR_DM_IPC_READ_FAILED;
500 }
501 int32_t appIconLen = authParam.imageinfo.GetAppIconLen();
502 int32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen();
503
504 reply.WriteInt32(authParam.direction);
505 reply.WriteInt32(authParam.authType);
506 reply.WriteString(authParam.authToken);
507 reply.WriteString(authParam.packageName);
508 reply.WriteString(authParam.appName);
509 reply.WriteString(authParam.appDescription);
510 reply.WriteInt32(authParam.business);
511 reply.WriteInt32(authParam.pincode);
512 reply.WriteInt32(appIconLen);
513 reply.WriteInt32(appThumbnailLen);
514
515 if (appIconLen > 0 && authParam.imageinfo.GetAppIcon() != nullptr) {
516 if (!reply.WriteRawData(authParam.imageinfo.GetAppIcon(), appIconLen)) {
517 LOGE("write appIcon failed");
518 return ERR_DM_IPC_WRITE_FAILED;
519 }
520 }
521 if (appThumbnailLen > 0 && authParam.imageinfo.GetAppThumbnail() != nullptr) {
522 if (!reply.WriteRawData(authParam.imageinfo.GetAppThumbnail(), appThumbnailLen)) {
523 LOGE("write appThumbnail failed");
524 return ERR_DM_IPC_WRITE_FAILED;
525 }
526 }
527 return DM_OK;
528 }
529
ON_IPC_CMD(SERVER_USER_AUTH_OPERATION,MessageParcel & data,MessageParcel & reply)530 ON_IPC_CMD(SERVER_USER_AUTH_OPERATION, MessageParcel &data, MessageParcel &reply)
531 {
532 std::string packageName = data.ReadString();
533 int32_t action = data.ReadInt32();
534 std::string params = data.ReadString();
535 int result = DeviceManagerService::GetInstance().SetUserOperation(packageName, action, params);
536 if (!reply.WriteInt32(result)) {
537 return ERR_DM_IPC_WRITE_FAILED;
538 }
539 return result;
540 }
541
ON_IPC_CMD(REGISTER_DEV_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)542 ON_IPC_CMD(REGISTER_DEV_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
543 {
544 std::string packageName = data.ReadString();
545 std::string extra = data.ReadString();
546 int result = DeviceManagerService::GetInstance().RegisterDevStateCallback(packageName, extra);
547 if (!reply.WriteInt32(result)) {
548 LOGE("write result failed");
549 return ERR_DM_IPC_WRITE_FAILED;
550 }
551 return result;
552 }
553
ON_IPC_CMD(UNREGISTER_DEV_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)554 ON_IPC_CMD(UNREGISTER_DEV_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
555 {
556 std::string packageName = data.ReadString();
557 std::string extra = data.ReadString();
558 int result = DeviceManagerService::GetInstance().UnRegisterDevStateCallback(packageName, extra);
559 if (!reply.WriteInt32(result)) {
560 LOGE("write result failed");
561 return ERR_DM_IPC_WRITE_FAILED;
562 }
563 return result;
564 }
565
ON_IPC_CMD(REQUEST_CREDENTIAL,MessageParcel & data,MessageParcel & reply)566 ON_IPC_CMD(REQUEST_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
567 {
568 std::string packageName = data.ReadString();
569 std::string reqJsonStr = data.ReadString();
570 std::string returnJsonStr;
571 int32_t ret = DeviceManagerService::GetInstance().RequestCredential(reqJsonStr, returnJsonStr);
572 if (!reply.WriteInt32(ret)) {
573 LOGE("write ret failed");
574 return ERR_DM_IPC_WRITE_FAILED;
575 }
576 if (ret == DM_OK && !returnJsonStr.empty()) {
577 if (!reply.WriteString(returnJsonStr))
578 {
579 LOGE("write returnJsonStr failed");
580 return ERR_DM_IPC_WRITE_FAILED;
581 }
582 }
583 return DM_OK;
584 }
585
ON_IPC_CMD(IMPORT_CREDENTIAL,MessageParcel & data,MessageParcel & reply)586 ON_IPC_CMD(IMPORT_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
587 {
588 std::string packageName = data.ReadString();
589 std::string credentialInfo = data.ReadString();
590 int32_t ret = DeviceManagerService::GetInstance().ImportCredential(packageName, credentialInfo);
591 if (!reply.WriteInt32(ret)) {
592 LOGE("write ret failed");
593 return ERR_DM_IPC_WRITE_FAILED;
594 }
595 return DM_OK;
596 }
597
ON_IPC_CMD(DELETE_CREDENTIAL,MessageParcel & data,MessageParcel & reply)598 ON_IPC_CMD(DELETE_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
599 {
600 std::string packageName = data.ReadString();
601 std::string deleteInfo = data.ReadString();
602 int32_t ret = DeviceManagerService::GetInstance().DeleteCredential(packageName, deleteInfo);
603 if (!reply.WriteInt32(ret)) {
604 LOGE("write ret failed");
605 return ERR_DM_IPC_WRITE_FAILED;
606 }
607 return DM_OK;
608 }
609
ON_IPC_CMD(REGISTER_CREDENTIAL_CALLBACK,MessageParcel & data,MessageParcel & reply)610 ON_IPC_CMD(REGISTER_CREDENTIAL_CALLBACK, MessageParcel &data, MessageParcel &reply)
611 {
612 std::string packageName = data.ReadString();
613 int result = DeviceManagerService::GetInstance().RegisterCredentialCallback(packageName);
614 if (!reply.WriteInt32(result)) {
615 LOGE("write result failed");
616 return ERR_DM_IPC_WRITE_FAILED;
617 }
618 return result;
619 }
620
ON_IPC_CMD(UNREGISTER_CREDENTIAL_CALLBACK,MessageParcel & data,MessageParcel & reply)621 ON_IPC_CMD(UNREGISTER_CREDENTIAL_CALLBACK, MessageParcel &data, MessageParcel &reply)
622 {
623 std::string packageName = data.ReadString();
624 int result = DeviceManagerService::GetInstance().UnRegisterCredentialCallback(packageName);
625 if (!reply.WriteInt32(result)) {
626 LOGE("write result failed");
627 return ERR_DM_IPC_WRITE_FAILED;
628 }
629 return result;
630 }
631
ON_IPC_CMD(NOTIFY_EVENT,MessageParcel & data,MessageParcel & reply)632 ON_IPC_CMD(NOTIFY_EVENT, MessageParcel &data, MessageParcel &reply)
633 {
634 std::string pkgName = data.ReadString();
635 int32_t eventId = data.ReadInt32();
636 std::string event = data.ReadString();
637 int32_t result = DeviceManagerService::GetInstance().NotifyEvent(pkgName, eventId, event);
638 if (!reply.WriteInt32(result)) {
639 LOGE("write result failed");
640 return ERR_DM_IPC_WRITE_FAILED;
641 }
642 return DM_OK;
643 }
644
ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)645 ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
646 {
647 if (pBaseReq == nullptr) {
648 return ERR_DM_FAILED;
649 }
650 std::shared_ptr<IpcNotifyCredentialReq> pReq = std::static_pointer_cast<IpcNotifyCredentialReq>(pBaseReq);
651 std::string pkgName = pReq->GetPkgName();
652 int32_t action = pReq->GetCredentialAction();
653 std::string credentialResult = pReq->GetCredentialResult();
654 if (!data.WriteString(pkgName)) {
655 LOGE("write pkgName failed");
656 return ERR_DM_IPC_WRITE_FAILED;
657 }
658 if (!data.WriteInt32(action)) {
659 LOGE("write action failed");
660 return ERR_DM_IPC_WRITE_FAILED;
661 }
662 if (!data.WriteString(credentialResult)) {
663 LOGE("write credentialResult failed");
664 return ERR_DM_IPC_WRITE_FAILED;
665 }
666
667 return DM_OK;
668 }
669
ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)670 ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
671 {
672 if (pBaseRsp == nullptr) {
673 LOGE("pBaseRsp is null");
674 return ERR_DM_FAILED;
675 }
676 pBaseRsp->SetErrCode(reply.ReadInt32());
677 return DM_OK;
678 }
679
680
ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID,MessageParcel & data,MessageParcel & reply)681 ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &data, MessageParcel &reply)
682 {
683 std::string pkgName = data.ReadString();
684 std::string networkId = data.ReadString();
685 std::string uuid;
686
687 int32_t result = DeviceManagerService::GetInstance().GetEncryptedUuidByNetworkId(pkgName, networkId, uuid);
688 if (!reply.WriteInt32(result)) {
689 LOGE("write result failed");
690 return ERR_DM_IPC_WRITE_FAILED;
691 }
692 if (!reply.WriteString(uuid)) {
693 LOGE("write result failed");
694 return ERR_DM_IPC_WRITE_FAILED;
695 }
696 return DM_OK;
697 }
698
ON_IPC_CMD(GENERATE_ENCRYPTED_UUID,MessageParcel & data,MessageParcel & reply)699 ON_IPC_CMD(GENERATE_ENCRYPTED_UUID, MessageParcel &data, MessageParcel &reply)
700 {
701 std::string pkgName = data.ReadString();
702 std::string uuid = data.ReadString();
703 std::string appId = data.ReadString();
704 std::string encryptedUuid;
705
706 int32_t result = DeviceManagerService::GetInstance().GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid);
707 if (!reply.WriteInt32(result)) {
708 LOGE("write result failed");
709 return ERR_DM_IPC_WRITE_FAILED;
710 }
711 if (!reply.WriteString(encryptedUuid)) {
712 LOGE("write result failed");
713 return ERR_DM_IPC_WRITE_FAILED;
714 }
715 return DM_OK;
716 }
717 } // namespace DistributedHardware
718 } // namespace OHOS
719