1 /*
2 * Copyright (c) 2022-2024 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 #include "xcollie/xcollie.h"
18 #include "xcollie/xcollie_define.h"
19
20 #include "device_manager_ipc_interface_code.h"
21 #include "device_manager_service.h"
22 #include "dm_anonymous.h"
23 #include "dm_constants.h"
24 #include "dm_device_info.h"
25 #include "dm_log.h"
26 #include "dm_subscribe_info.h"
27 #include "dm_publish_info.h"
28 #include "ipc_acl_profile_req.h"
29 #include "ipc_cmd_register.h"
30 #include "ipc_def.h"
31 #include "ipc_create_pin_holder_req.h"
32 #include "ipc_credential_auth_status_req.h"
33 #include "ipc_destroy_pin_holder_req.h"
34 #include "ipc_notify_auth_result_req.h"
35 #include "ipc_notify_bind_result_req.h"
36 #include "ipc_notify_credential_req.h"
37 #include "ipc_notify_device_found_req.h"
38 #include "ipc_notify_device_discovery_req.h"
39 #include "ipc_notify_device_state_req.h"
40 #include "ipc_notify_discover_result_req.h"
41 #include "ipc_notify_publish_result_req.h"
42 #include "ipc_notify_pin_holder_event_req.h"
43 #include "ipc_server_client_proxy.h"
44 #include "ipc_server_stub.h"
45
46 #include "nlohmann/json.hpp"
47
48 namespace OHOS {
49 namespace DistributedHardware {
50 const unsigned int XCOLLIE_TIMEOUT_S = 5;
EncodeDmDeviceInfo(const DmDeviceInfo & devInfo,MessageParcel & parcel)51 bool EncodeDmDeviceInfo(const DmDeviceInfo &devInfo, MessageParcel &parcel)
52 {
53 bool bRet = true;
54 std::string deviceIdStr(devInfo.deviceId);
55 bRet = (bRet && parcel.WriteString(deviceIdStr));
56 std::string deviceNameStr(devInfo.deviceName);
57 bRet = (bRet && parcel.WriteString(deviceNameStr));
58 bRet = (bRet && parcel.WriteUint16(devInfo.deviceTypeId));
59 std::string networkIdStr(devInfo.networkId);
60 bRet = (bRet && parcel.WriteString(networkIdStr));
61 bRet = (bRet && parcel.WriteInt32(devInfo.range));
62 bRet = (bRet && parcel.WriteInt32(devInfo.networkType));
63 bRet = (bRet && parcel.WriteInt32(devInfo.authForm));
64 bRet = (bRet && parcel.WriteString(devInfo.extraData));
65 return bRet;
66 }
67
EncodeDmDeviceBasicInfo(const DmDeviceBasicInfo & devInfo,MessageParcel & parcel)68 bool EncodeDmDeviceBasicInfo(const DmDeviceBasicInfo &devInfo, MessageParcel &parcel)
69 {
70 bool bRet = true;
71 std::string deviceIdStr(devInfo.deviceId);
72 bRet = (bRet && parcel.WriteString(deviceIdStr));
73 std::string deviceNameStr(devInfo.deviceName);
74 bRet = (bRet && parcel.WriteString(deviceNameStr));
75 bRet = (bRet && parcel.WriteUint16(devInfo.deviceTypeId));
76 std::string networkIdStr(devInfo.networkId);
77 bRet = (bRet && parcel.WriteString(networkIdStr));
78 return bRet;
79 }
80
EncodePeerTargetId(const PeerTargetId & targetId,MessageParcel & parcel)81 bool EncodePeerTargetId(const PeerTargetId &targetId, MessageParcel &parcel)
82 {
83 bool bRet = true;
84 bRet = (bRet && parcel.WriteString(targetId.deviceId));
85 bRet = (bRet && parcel.WriteString(targetId.brMac));
86 bRet = (bRet && parcel.WriteString(targetId.bleMac));
87 bRet = (bRet && parcel.WriteString(targetId.wifiIp));
88 bRet = (bRet && parcel.WriteUint16(targetId.wifiPort));
89 return bRet;
90 }
91
DecodePeerTargetId(MessageParcel & parcel,PeerTargetId & targetId)92 void DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targetId)
93 {
94 targetId.deviceId = parcel.ReadString();
95 targetId.brMac = parcel.ReadString();
96 targetId.bleMac = parcel.ReadString();
97 targetId.wifiIp = parcel.ReadString();
98 targetId.wifiPort = parcel.ReadUint16();
99 }
100
DecodeDmAccessCaller(MessageParcel & parcel,DmAccessCaller & caller)101 void DecodeDmAccessCaller(MessageParcel &parcel, DmAccessCaller &caller)
102 {
103 caller.accountId = parcel.ReadString();
104 caller.pkgName = parcel.ReadString();
105 caller.networkId = parcel.ReadString();
106 caller.userId = parcel.ReadInt32();
107 caller.tokenId = parcel.ReadUint64();
108 caller.extra = parcel.ReadString();
109 }
110
DecodeDmAccessCallee(MessageParcel & parcel,DmAccessCallee & callee)111 void DecodeDmAccessCallee(MessageParcel &parcel, DmAccessCallee &callee)
112 {
113 callee.accountId = parcel.ReadString();
114 callee.networkId = parcel.ReadString();
115 callee.peerId = parcel.ReadString();
116 callee.userId = parcel.ReadInt32();
117 callee.extra = parcel.ReadString();
118 }
119
ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)120 ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
121 {
122 if (pBaseReq == nullptr) {
123 return ERR_DM_FAILED;
124 }
125
126 std::shared_ptr<IpcNotifyDeviceStateReq> pReq = std::static_pointer_cast<IpcNotifyDeviceStateReq>(pBaseReq);
127 std::string pkgName = pReq->GetPkgName();
128 int32_t deviceState = pReq->GetDeviceState();
129 DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
130 DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo();
131 if (!data.WriteString(pkgName)) {
132 LOGE("write pkgName failed");
133 return ERR_DM_IPC_WRITE_FAILED;
134 }
135 if (!data.WriteInt32(deviceState)) {
136 LOGE("write state failed");
137 return ERR_DM_IPC_WRITE_FAILED;
138 }
139 if (!EncodeDmDeviceInfo(deviceInfo, data)) {
140 LOGE("write dm device info failed");
141 return ERR_DM_IPC_WRITE_FAILED;
142 }
143 if (!data.WriteRawData(&deviceBasicInfo, sizeof(DmDeviceBasicInfo))) {
144 LOGE("write deviceBasicInfo failed");
145 return ERR_DM_IPC_WRITE_FAILED;
146 }
147 return DM_OK;
148 }
149
ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)150 ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
151 {
152 if (pBaseRsp == nullptr) {
153 LOGE("pBaseRsp is null");
154 return ERR_DM_FAILED;
155 }
156 pBaseRsp->SetErrCode(reply.ReadInt32());
157 return DM_OK;
158 }
159
ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)160 ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
161 {
162 if (pBaseReq == nullptr) {
163 return ERR_DM_FAILED;
164 }
165
166 std::shared_ptr<IpcNotifyDeviceFoundReq> pReq = std::static_pointer_cast<IpcNotifyDeviceFoundReq>(pBaseReq);
167 std::string pkgName = pReq->GetPkgName();
168 uint16_t subscribeId = pReq->GetSubscribeId();
169 DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
170 DmDeviceBasicInfo devBasicInfo = pReq->GetDeviceBasicInfo();
171 if (!data.WriteString(pkgName)) {
172 LOGE("write pkgName failed");
173 return ERR_DM_IPC_WRITE_FAILED;
174 }
175 if (!data.WriteInt16((int16_t)subscribeId)) {
176 LOGE("write subscribeId failed");
177 return ERR_DM_IPC_WRITE_FAILED;
178 }
179 if (!EncodeDmDeviceInfo(deviceInfo, data)) {
180 LOGE("write dm device info failed");
181 return ERR_DM_IPC_WRITE_FAILED;
182 }
183 if (!EncodeDmDeviceBasicInfo(devBasicInfo, data)) {
184 LOGE("write dm device basic info failed");
185 return ERR_DM_IPC_WRITE_FAILED;
186 }
187 return DM_OK;
188 }
189
ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)190 ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
191 {
192 if (pBaseRsp == nullptr) {
193 LOGE("pBaseRsp is null");
194 return ERR_DM_FAILED;
195 }
196 pBaseRsp->SetErrCode(reply.ReadInt32());
197 return DM_OK;
198 }
199
ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)200 ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
201 {
202 if (pBaseReq == nullptr) {
203 return ERR_DM_FAILED;
204 }
205
206 std::shared_ptr<IpcNotifyDeviceDiscoveryReq> pReq = std::static_pointer_cast<IpcNotifyDeviceDiscoveryReq>(pBaseReq);
207 std::string pkgName = pReq->GetPkgName();
208 uint16_t subscribeId = pReq->GetSubscribeId();
209 DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo();
210 if (!data.WriteString(pkgName)) {
211 LOGE("write pkgName failed");
212 return ERR_DM_IPC_WRITE_FAILED;
213 }
214 if (!data.WriteInt16((int16_t)subscribeId)) {
215 LOGE("write subscribeId failed");
216 return ERR_DM_IPC_WRITE_FAILED;
217 }
218 if (!data.WriteRawData(&deviceBasicInfo, sizeof(DmDeviceBasicInfo))) {
219 LOGE("write deviceBasicInfo failed");
220 return ERR_DM_IPC_WRITE_FAILED;
221 }
222 return DM_OK;
223 }
224
ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)225 ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
226 {
227 if (pBaseRsp == nullptr) {
228 LOGE("pBaseRsp is null");
229 return ERR_DM_FAILED;
230 }
231 pBaseRsp->SetErrCode(reply.ReadInt32());
232 return DM_OK;
233 }
234
ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)235 ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
236 {
237 if (pBaseReq == nullptr) {
238 return ERR_DM_FAILED;
239 }
240 std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::static_pointer_cast<IpcNotifyDiscoverResultReq>(pBaseReq);
241 std::string pkgName = pReq->GetPkgName();
242 uint16_t subscribeId = pReq->GetSubscribeId();
243 int32_t result = pReq->GetResult();
244 if (!data.WriteString(pkgName)) {
245 LOGE("write pkgName failed");
246 return ERR_DM_IPC_WRITE_FAILED;
247 }
248 if (!data.WriteInt16((int16_t)subscribeId)) {
249 LOGE("write subscribeId failed");
250 return ERR_DM_IPC_WRITE_FAILED;
251 }
252 if (!data.WriteInt32(result)) {
253 LOGE("write result failed");
254 return ERR_DM_IPC_WRITE_FAILED;
255 }
256 return DM_OK;
257 }
258
ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)259 ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
260 {
261 if (pBaseRsp == nullptr) {
262 LOGE("pBaseRsp is null");
263 return ERR_DM_FAILED;
264 }
265 pBaseRsp->SetErrCode(reply.ReadInt32());
266 return DM_OK;
267 }
268
ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)269 ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
270 {
271 if (pBaseReq == nullptr) {
272 return ERR_DM_FAILED;
273 }
274 std::shared_ptr<IpcNotifyPublishResultReq> pReq = std::static_pointer_cast<IpcNotifyPublishResultReq>(pBaseReq);
275 std::string pkgName = pReq->GetPkgName();
276 int32_t publishId = pReq->GetPublishId();
277 int32_t result = pReq->GetResult();
278 if (!data.WriteString(pkgName)) {
279 LOGE("write pkgName failed");
280 return ERR_DM_IPC_WRITE_FAILED;
281 }
282 if (!data.WriteInt32(publishId)) {
283 LOGE("write publishId failed");
284 return ERR_DM_IPC_WRITE_FAILED;
285 }
286 if (!data.WriteInt32(result)) {
287 LOGE("write result failed");
288 return ERR_DM_IPC_WRITE_FAILED;
289 }
290 return DM_OK;
291 }
292
ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)293 ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH, 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_AUTH_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)303 ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
304 {
305 if (pBaseReq == nullptr) {
306 return ERR_DM_FAILED;
307 }
308 std::shared_ptr<IpcNotifyAuthResultReq> pReq = std::static_pointer_cast<IpcNotifyAuthResultReq>(pBaseReq);
309
310 std::string pkgName = pReq->GetPkgName();
311 std::string deviceId = pReq->GetDeviceId();
312 std::string token = pReq->GetPinToken();
313 int32_t status = pReq->GetStatus();
314 int32_t reason = pReq->GetReason();
315 if (!data.WriteString(pkgName)) {
316 LOGE("write pkgName failed");
317 return ERR_DM_IPC_WRITE_FAILED;
318 }
319 if (!data.WriteString(deviceId)) {
320 LOGE("write deviceId failed");
321 return ERR_DM_IPC_WRITE_FAILED;
322 }
323 if (!data.WriteString(token)) {
324 LOGE("write token failed");
325 return ERR_DM_IPC_WRITE_FAILED;
326 }
327 if (!data.WriteInt32(status)) {
328 LOGE("write status failed");
329 return ERR_DM_IPC_WRITE_FAILED;
330 }
331 if (!data.WriteInt32(reason)) {
332 LOGE("write reason failed");
333 return ERR_DM_IPC_WRITE_FAILED;
334 }
335 return DM_OK;
336 }
337
ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)338 ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
339 {
340 if (pBaseRsp == nullptr) {
341 LOGE("pBaseRsp is null");
342 return ERR_DM_FAILED;
343 }
344 pBaseRsp->SetErrCode(reply.ReadInt32());
345 return DM_OK;
346 }
347
ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)348 ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
349 {
350 if (pBaseReq == nullptr) {
351 return ERR_DM_FAILED;
352 }
353
354 std::shared_ptr<IpcNotifyDMFAResultReq> pReq = std::static_pointer_cast<IpcNotifyDMFAResultReq>(pBaseReq);
355
356 std::string packagname = pReq->GetPkgName();
357 std::string paramJson = pReq->GetJsonParam();
358 if (!data.WriteString(packagname)) {
359 LOGE("write pkgName failed");
360 return ERR_DM_IPC_WRITE_FAILED;
361 }
362 if (!data.WriteString(paramJson)) {
363 LOGE("write paramJson failed");
364 return ERR_DM_IPC_WRITE_FAILED;
365 }
366 return DM_OK;
367 }
368
ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)369 ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
370 {
371 if (pBaseRsp == nullptr) {
372 LOGE("pBaseRsp is null");
373 return ERR_DM_FAILED;
374 }
375 pBaseRsp->SetErrCode(reply.ReadInt32());
376 return DM_OK;
377 }
378
ON_IPC_CMD(GET_TRUST_DEVICE_LIST,MessageParcel & data,MessageParcel & reply)379 ON_IPC_CMD(GET_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply)
380 {
381 std::string pkgName = data.ReadString();
382 std::string extra = data.ReadString();
383 bool isRefresh = data.ReadBool();
384 DeviceManagerService::GetInstance().ShiftLNNGear(pkgName, pkgName, isRefresh, false);
385 std::vector<DmDeviceInfo> deviceList;
386 int32_t result = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
387 if (!reply.WriteInt32((int32_t)deviceList.size())) {
388 LOGE("write device list size failed");
389 return ERR_DM_IPC_WRITE_FAILED;
390 }
391 for (const auto &devInfo : deviceList) {
392 if (!EncodeDmDeviceInfo(devInfo, reply)) {
393 LOGE("write dm device info failed");
394 return ERR_DM_IPC_WRITE_FAILED;
395 }
396 }
397 if (!reply.WriteInt32(result)) {
398 LOGE("write result failed");
399 return ERR_DM_IPC_WRITE_FAILED;
400 }
401 return DM_OK;
402 }
403
ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & data,MessageParcel & reply)404 ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply)
405 {
406 int32_t id = OHOS::HiviewDFX::XCollie::GetInstance().SetTimer("RegisterDeviceManagerListener", XCOLLIE_TIMEOUT_S,
407 nullptr, nullptr, OHOS::HiviewDFX::XCOLLIE_FLAG_LOG | OHOS::HiviewDFX::XCOLLIE_FLAG_RECOVERY);
408 std::string pkgName = data.ReadString();
409 sptr<IRemoteObject> listener = data.ReadRemoteObject();
410 if (listener == nullptr) {
411 LOGE("read remote object failed.");
412 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
413 return ERR_DM_POINT_NULL;
414 }
415 sptr<IpcServerClientProxy> callback(new IpcServerClientProxy(listener));
416 if (callback == nullptr) {
417 LOGE("create ipc server client proxy failed.");
418 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
419 return ERR_DM_POINT_NULL;
420 }
421 DeviceManagerService::GetInstance().RegisterCallerAppId(pkgName);
422 int32_t result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, callback);
423 if (!reply.WriteInt32(result)) {
424 LOGE("write result failed");
425 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
426 return ERR_DM_IPC_WRITE_FAILED;
427 }
428 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
429 return DM_OK;
430 }
431
ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & data,MessageParcel & reply)432 ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply)
433 {
434 std::string pkgName = data.ReadString();
435 DeviceManagerService::GetInstance().UnRegisterCallerAppId(pkgName);
436 int32_t result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
437 if (!reply.WriteInt32(result)) {
438 LOGE("write result failed");
439 return ERR_DM_IPC_WRITE_FAILED;
440 }
441 return DM_OK;
442 }
443
ON_IPC_CMD(START_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)444 ON_IPC_CMD(START_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
445 {
446 std::string pkgName = data.ReadString();
447 std::string extra = data.ReadString();
448 DmSubscribeInfo *subscribeInfo =
449 static_cast<DmSubscribeInfo *>(const_cast<void *>(data.ReadRawData(sizeof(DmSubscribeInfo))));
450 int32_t result = ERR_DM_POINT_NULL;
451
452 if (subscribeInfo != nullptr) {
453 result = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, *subscribeInfo, extra);
454 }
455 if (!reply.WriteInt32(result)) {
456 LOGE("write result failed");
457 return ERR_DM_IPC_WRITE_FAILED;
458 }
459 return DM_OK;
460 }
461
ON_IPC_CMD(START_DEVICE_DISCOVERY,MessageParcel & data,MessageParcel & reply)462 ON_IPC_CMD(START_DEVICE_DISCOVERY, MessageParcel &data, MessageParcel &reply)
463 {
464 std::string pkgName = data.ReadString();
465 std::string filterOption = data.ReadString();
466 uint16_t subscribeId = data.ReadUint16();
467 int32_t result = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeId, filterOption);
468 if (!reply.WriteInt32(result)) {
469 LOGE("write result failed");
470 return ERR_DM_IPC_WRITE_FAILED;
471 }
472 return DM_OK;
473 }
474
ON_IPC_CMD(STOP_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)475 ON_IPC_CMD(STOP_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
476 {
477 std::string pkgName = data.ReadString();
478 uint16_t subscribeId = data.ReadUint16();
479 int32_t result = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId);
480 if (!reply.WriteInt32(result)) {
481 LOGE("write result failed");
482 return ERR_DM_IPC_WRITE_FAILED;
483 }
484 return DM_OK;
485 }
486
ON_IPC_CMD(PUBLISH_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)487 ON_IPC_CMD(PUBLISH_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
488 {
489 std::string pkgName = data.ReadString();
490 DmPublishInfo *publishInfo =
491 static_cast<DmPublishInfo *>(const_cast<void *>(data.ReadRawData(sizeof(DmPublishInfo))));
492 int32_t result = ERR_DM_POINT_NULL;
493
494 if (publishInfo != nullptr) {
495 result = DeviceManagerService::GetInstance().PublishDeviceDiscovery(pkgName, *publishInfo);
496 }
497 if (!reply.WriteInt32(result)) {
498 LOGE("write result failed");
499 return ERR_DM_IPC_WRITE_FAILED;
500 }
501 return DM_OK;
502 }
503
ON_IPC_CMD(UNPUBLISH_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)504 ON_IPC_CMD(UNPUBLISH_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
505 {
506 std::string pkgName = data.ReadString();
507 int32_t publishId = data.ReadInt32();
508 int32_t result = DeviceManagerService::GetInstance().UnPublishDeviceDiscovery(pkgName, publishId);
509 if (!reply.WriteInt32(result)) {
510 LOGE("write result failed");
511 return ERR_DM_IPC_WRITE_FAILED;
512 }
513 return DM_OK;
514 }
515
ON_IPC_CMD(AUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)516 ON_IPC_CMD(AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
517 {
518 std::string pkgName = data.ReadString();
519 std::string extra = data.ReadString();
520 std::string deviceId = data.ReadString();
521 int32_t authType = data.ReadInt32();
522
523 int32_t result = DM_OK;
524 result = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
525 if (!reply.WriteInt32(result)) {
526 LOGE("write result failed");
527 return ERR_DM_IPC_WRITE_FAILED;
528 }
529 return DM_OK;
530 }
531
ON_IPC_CMD(UNAUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)532 ON_IPC_CMD(UNAUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
533 {
534 std::string pkgName = data.ReadString();
535 std::string deviceId = data.ReadString();
536 int32_t result = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
537 if (!reply.WriteInt32(result)) {
538 LOGE("write result failed");
539 return ERR_DM_IPC_WRITE_FAILED;
540 }
541 return DM_OK;
542 }
543
ON_IPC_CMD(GET_DEVICE_INFO,MessageParcel & data,MessageParcel & reply)544 ON_IPC_CMD(GET_DEVICE_INFO, MessageParcel &data, MessageParcel &reply)
545 {
546 std::string networkId = data.ReadString();
547 DmDeviceInfo deviceInfo;
548 int32_t result = DeviceManagerService::GetInstance().GetDeviceInfo(networkId, deviceInfo);
549 if (!EncodeDmDeviceInfo(deviceInfo, reply)) {
550 LOGE("write dm device info failed");
551 return ERR_DM_IPC_WRITE_FAILED;
552 }
553 if (!reply.WriteInt32(result)) {
554 LOGE("write result failed");
555 return ERR_DM_IPC_WRITE_FAILED;
556 }
557 return DM_OK;
558 }
559
ON_IPC_CMD(GET_LOCAL_DEVICE_INFO,MessageParcel & data,MessageParcel & reply)560 ON_IPC_CMD(GET_LOCAL_DEVICE_INFO, MessageParcel &data, MessageParcel &reply)
561 {
562 (void)data;
563 DmDeviceInfo localDeviceInfo;
564 int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceInfo(localDeviceInfo);
565 if (!EncodeDmDeviceInfo(localDeviceInfo, reply)) {
566 LOGE("write dm device info failed");
567 return ERR_DM_IPC_WRITE_FAILED;
568 }
569 if (!reply.WriteInt32(result)) {
570 LOGE("write result failed");
571 return ERR_DM_IPC_WRITE_FAILED;
572 }
573 return DM_OK;
574 }
575
ON_IPC_CMD(GET_UDID_BY_NETWORK,MessageParcel & data,MessageParcel & reply)576 ON_IPC_CMD(GET_UDID_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
577 {
578 std::string pkgName = data.ReadString();
579 std::string netWorkId = data.ReadString();
580 std::string udid;
581 int32_t result = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid);
582
583 if (!reply.WriteInt32(result)) {
584 LOGE("write result failed");
585 return ERR_DM_IPC_WRITE_FAILED;
586 }
587 if (!reply.WriteString(udid)) {
588 LOGE("write result failed");
589 return ERR_DM_IPC_WRITE_FAILED;
590 }
591 return DM_OK;
592 }
593
ON_IPC_CMD(GET_UUID_BY_NETWORK,MessageParcel & data,MessageParcel & reply)594 ON_IPC_CMD(GET_UUID_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
595 {
596 std::string pkgName = data.ReadString();
597 std::string netWorkId = data.ReadString();
598 std::string uuid;
599 int32_t result = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid);
600
601 if (!reply.WriteInt32(result)) {
602 LOGE("write result failed");
603 return ERR_DM_IPC_WRITE_FAILED;
604 }
605 if (!reply.WriteString(uuid)) {
606 LOGE("write result failed");
607 return ERR_DM_IPC_WRITE_FAILED;
608 }
609 return DM_OK;
610 }
611
ON_IPC_CMD(SERVER_USER_AUTH_OPERATION,MessageParcel & data,MessageParcel & reply)612 ON_IPC_CMD(SERVER_USER_AUTH_OPERATION, MessageParcel &data, MessageParcel &reply)
613 {
614 std::string packageName = data.ReadString();
615 int32_t action = data.ReadInt32();
616 std::string params = data.ReadString();
617 int result = DeviceManagerService::GetInstance().SetUserOperation(packageName, action, params);
618 if (!reply.WriteInt32(result)) {
619 return ERR_DM_IPC_WRITE_FAILED;
620 }
621 return result;
622 }
623
ON_IPC_CMD(REQUEST_CREDENTIAL,MessageParcel & data,MessageParcel & reply)624 ON_IPC_CMD(REQUEST_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
625 {
626 std::string packageName = data.ReadString();
627 std::string reqParaStr = data.ReadString();
628 std::map<std::string, std::string> requestParam;
629 ParseMapFromJsonString(reqParaStr, requestParam);
630 std::string returnJsonStr;
631 int32_t ret = ERR_DM_FAILED;
632 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
633 ret = DeviceManagerService::GetInstance().RequestCredential(requestParam[DM_CREDENTIAL_REQJSONSTR],
634 returnJsonStr);
635 }
636 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
637 ret = DeviceManagerService::GetInstance().MineRequestCredential(packageName, returnJsonStr);
638 }
639 if (!reply.WriteInt32(ret)) {
640 LOGE("write ret failed");
641 return ERR_DM_IPC_WRITE_FAILED;
642 }
643 if (ret == DM_OK && !returnJsonStr.empty()) {
644 if (!reply.WriteString(returnJsonStr)) {
645 LOGE("write returnJsonStr failed");
646 return ERR_DM_IPC_WRITE_FAILED;
647 }
648 }
649 return DM_OK;
650 }
651
ON_IPC_CMD(IMPORT_CREDENTIAL,MessageParcel & data,MessageParcel & reply)652 ON_IPC_CMD(IMPORT_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
653 {
654 std::string packageName = data.ReadString();
655 std::string reqParaStr = data.ReadString();
656 std::map<std::string, std::string> requestParam;
657 ParseMapFromJsonString(reqParaStr, requestParam);
658 std::string returnJsonStr;
659 std::map<std::string, std::string> outputResult;
660 int32_t ret = ERR_DM_FAILED;
661 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
662 ret = DeviceManagerService::GetInstance().ImportCredential(packageName, requestParam[DM_CREDENTIAL_REQJSONSTR]);
663 outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH);
664 }
665 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
666 ret = DeviceManagerService::GetInstance().ImportCredential(packageName, requestParam[DM_CREDENTIAL_REQJSONSTR],
667 returnJsonStr);
668 outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE);
669 outputResult.emplace(DM_CREDENTIAL_RETURNJSONSTR, returnJsonStr);
670 }
671 if (!reply.WriteInt32(ret)) {
672 LOGE("write ret failed");
673 return ERR_DM_IPC_WRITE_FAILED;
674 }
675 if (ret == DM_OK && !returnJsonStr.empty()) {
676 std::string outParaStr = ConvertMapToJsonString(outputResult);
677 if (!reply.WriteString(outParaStr)) {
678 LOGE("write returnJsonStr failed");
679 return ERR_DM_IPC_WRITE_FAILED;
680 }
681 }
682 return DM_OK;
683 }
684
ON_IPC_CMD(DELETE_CREDENTIAL,MessageParcel & data,MessageParcel & reply)685 ON_IPC_CMD(DELETE_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
686 {
687 std::string packageName = data.ReadString();
688 std::string reqParaStr = data.ReadString();
689 std::map<std::string, std::string> requestParam;
690 ParseMapFromJsonString(reqParaStr, requestParam);
691 std::map<std::string, std::string> outputResult;
692 std::string returnJsonStr;
693 int32_t ret = ERR_DM_FAILED;
694 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
695 ret = DeviceManagerService::GetInstance().DeleteCredential(packageName, requestParam[DM_CREDENTIAL_REQJSONSTR]);
696 outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH);
697 }
698 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
699 ret = DeviceManagerService::GetInstance().DeleteCredential(packageName, requestParam[DM_CREDENTIAL_REQJSONSTR],
700 returnJsonStr);
701 outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE);
702 outputResult.emplace(DM_CREDENTIAL_RETURNJSONSTR, returnJsonStr);
703 }
704 if (!reply.WriteInt32(ret)) {
705 LOGE("write ret failed");
706 return ERR_DM_IPC_WRITE_FAILED;
707 }
708 if (ret == DM_OK && !returnJsonStr.empty()) {
709 std::string outParaStr = ConvertMapToJsonString(outputResult);
710 if (!reply.WriteString(outParaStr)) {
711 LOGE("write returnJsonStr failed");
712 return ERR_DM_IPC_WRITE_FAILED;
713 }
714 }
715 return DM_OK;
716 }
717
ON_IPC_CMD(SERVER_GET_DMFA_INFO,MessageParcel & data,MessageParcel & reply)718 ON_IPC_CMD(SERVER_GET_DMFA_INFO, MessageParcel &data, MessageParcel &reply)
719 {
720 std::string packageName = data.ReadString();
721 std::string reqJsonStr = data.ReadString();
722 std::string returnJsonStr;
723 int32_t ret = DeviceManagerService::GetInstance().CheckCredential(packageName, reqJsonStr, returnJsonStr);
724 if (!reply.WriteInt32(ret)) {
725 LOGE("write ret failed");
726 return ERR_DM_IPC_WRITE_FAILED;
727 }
728 if (ret == DM_OK && !returnJsonStr.empty()) {
729 if (!reply.WriteString(returnJsonStr)) {
730 LOGE("write returnJsonStr failed");
731 return ERR_DM_IPC_WRITE_FAILED;
732 }
733 }
734 return DM_OK;
735 }
736
ON_IPC_CMD(REGISTER_CREDENTIAL_CALLBACK,MessageParcel & data,MessageParcel & reply)737 ON_IPC_CMD(REGISTER_CREDENTIAL_CALLBACK, MessageParcel &data, MessageParcel &reply)
738 {
739 std::string packageName = data.ReadString();
740 int result = DeviceManagerService::GetInstance().RegisterCredentialCallback(packageName);
741 if (!reply.WriteInt32(result)) {
742 LOGE("write result failed");
743 return ERR_DM_IPC_WRITE_FAILED;
744 }
745 return result;
746 }
747
ON_IPC_CMD(UNREGISTER_CREDENTIAL_CALLBACK,MessageParcel & data,MessageParcel & reply)748 ON_IPC_CMD(UNREGISTER_CREDENTIAL_CALLBACK, MessageParcel &data, MessageParcel &reply)
749 {
750 std::string packageName = data.ReadString();
751 int result = DeviceManagerService::GetInstance().UnRegisterCredentialCallback(packageName);
752 if (!reply.WriteInt32(result)) {
753 LOGE("write result failed");
754 return ERR_DM_IPC_WRITE_FAILED;
755 }
756 return result;
757 }
758
ON_IPC_CMD(NOTIFY_EVENT,MessageParcel & data,MessageParcel & reply)759 ON_IPC_CMD(NOTIFY_EVENT, MessageParcel &data, MessageParcel &reply)
760 {
761 std::string pkgName = data.ReadString();
762 int32_t eventId = data.ReadInt32();
763 std::string event = data.ReadString();
764 int32_t result = DeviceManagerService::GetInstance().NotifyEvent(pkgName, eventId, event);
765 if (!reply.WriteInt32(result)) {
766 LOGE("write result failed");
767 return ERR_DM_IPC_WRITE_FAILED;
768 }
769 return DM_OK;
770 }
771
ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)772 ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
773 {
774 if (pBaseReq == nullptr) {
775 return ERR_DM_FAILED;
776 }
777 std::shared_ptr<IpcNotifyCredentialReq> pReq = std::static_pointer_cast<IpcNotifyCredentialReq>(pBaseReq);
778 std::string pkgName = pReq->GetPkgName();
779 int32_t action = pReq->GetCredentialAction();
780 std::string credentialResult = pReq->GetCredentialResult();
781 if (!data.WriteString(pkgName)) {
782 LOGE("write pkgName failed");
783 return ERR_DM_IPC_WRITE_FAILED;
784 }
785 if (!data.WriteInt32(action)) {
786 LOGE("write action failed");
787 return ERR_DM_IPC_WRITE_FAILED;
788 }
789 if (!data.WriteString(credentialResult)) {
790 LOGE("write credentialResult failed");
791 return ERR_DM_IPC_WRITE_FAILED;
792 }
793
794 return DM_OK;
795 }
796
ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)797 ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
798 {
799 if (pBaseRsp == nullptr) {
800 LOGE("pBaseRsp is null");
801 return ERR_DM_FAILED;
802 }
803 pBaseRsp->SetErrCode(reply.ReadInt32());
804 return DM_OK;
805 }
806
ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID,MessageParcel & data,MessageParcel & reply)807 ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &data, MessageParcel &reply)
808 {
809 std::string pkgName = data.ReadString();
810 std::string networkId = data.ReadString();
811 std::string uuid;
812
813 int32_t result = DeviceManagerService::GetInstance().GetEncryptedUuidByNetworkId(pkgName, networkId, uuid);
814 if (!reply.WriteInt32(result)) {
815 LOGE("write result failed");
816 return ERR_DM_IPC_WRITE_FAILED;
817 }
818 if (!reply.WriteString(uuid)) {
819 LOGE("write uuid failed");
820 return ERR_DM_IPC_WRITE_FAILED;
821 }
822 return DM_OK;
823 }
824
ON_IPC_CMD(GENERATE_ENCRYPTED_UUID,MessageParcel & data,MessageParcel & reply)825 ON_IPC_CMD(GENERATE_ENCRYPTED_UUID, MessageParcel &data, MessageParcel &reply)
826 {
827 std::string pkgName = data.ReadString();
828 std::string uuid = data.ReadString();
829 std::string appId = data.ReadString();
830 std::string encryptedUuid;
831
832 int32_t result = DeviceManagerService::GetInstance().GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid);
833 if (!reply.WriteInt32(result)) {
834 LOGE("write result failed");
835 return ERR_DM_IPC_WRITE_FAILED;
836 }
837 if (!reply.WriteString(encryptedUuid)) {
838 LOGE("write encryptedUuid failed");
839 return ERR_DM_IPC_WRITE_FAILED;
840 }
841 return DM_OK;
842 }
843
ON_IPC_CMD(BIND_DEVICE,MessageParcel & data,MessageParcel & reply)844 ON_IPC_CMD(BIND_DEVICE, MessageParcel &data, MessageParcel &reply)
845 {
846 std::string pkgName = data.ReadString();
847 std::string bindParam = data.ReadString();
848 std::string deviceId = data.ReadString();
849 int32_t bindType = data.ReadInt32();
850 int32_t result = DM_OK;
851 result = DeviceManagerService::GetInstance().BindDevice(pkgName, bindType, deviceId, bindParam);
852 if (!reply.WriteInt32(result)) {
853 LOGE("write result failed");
854 return ERR_DM_IPC_WRITE_FAILED;
855 }
856 return DM_OK;
857 }
858
ON_IPC_CMD(UNBIND_DEVICE,MessageParcel & data,MessageParcel & reply)859 ON_IPC_CMD(UNBIND_DEVICE, MessageParcel &data, MessageParcel &reply)
860 {
861 std::string pkgName = data.ReadString();
862 std::string deviceId = data.ReadString();
863 int32_t result = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId);
864 if (!reply.WriteInt32(result)) {
865 LOGE("write result failed");
866 return ERR_DM_IPC_WRITE_FAILED;
867 }
868 return DM_OK;
869 }
870
ON_IPC_CMD(GET_NETWORKTYPE_BY_NETWORK,MessageParcel & data,MessageParcel & reply)871 ON_IPC_CMD(GET_NETWORKTYPE_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
872 {
873 std::string pkgName = data.ReadString();
874 std::string netWorkId = data.ReadString();
875 int32_t networkType = -1;
876 int32_t result = DeviceManagerService::GetInstance().GetNetworkTypeByNetworkId(pkgName, netWorkId, networkType);
877 if (!reply.WriteInt32(result)) {
878 LOGE("write result failed");
879 return ERR_DM_IPC_WRITE_FAILED;
880 }
881 if (!reply.WriteInt32(networkType)) {
882 LOGE("write result failed");
883 return ERR_DM_IPC_WRITE_FAILED;
884 }
885 return DM_OK;
886 }
887
ON_IPC_CMD(REGISTER_UI_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)888 ON_IPC_CMD(REGISTER_UI_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
889 {
890 std::string pkgName = data.ReadString();
891 int32_t result = DeviceManagerService::GetInstance().RegisterUiStateCallback(pkgName);
892 if (!reply.WriteInt32(result)) {
893 LOGE("write result failed");
894 return ERR_DM_IPC_WRITE_FAILED;
895 }
896 return DM_OK;
897 }
898
ON_IPC_CMD(UNREGISTER_UI_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)899 ON_IPC_CMD(UNREGISTER_UI_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
900 {
901 std::string pkgName = data.ReadString();
902 int32_t result = DeviceManagerService::GetInstance().UnRegisterUiStateCallback(pkgName);
903 if (!reply.WriteInt32(result)) {
904 LOGE("write result failed");
905 return ERR_DM_IPC_WRITE_FAILED;
906 }
907 return DM_OK;
908 }
909
ON_IPC_CMD(IMPORT_AUTH_CODE,MessageParcel & data,MessageParcel & reply)910 ON_IPC_CMD(IMPORT_AUTH_CODE, MessageParcel &data, MessageParcel &reply)
911 {
912 std::string pkgName = data.ReadString();
913 std::string authCode = data.ReadString();
914 int32_t result = DeviceManagerService::GetInstance().ImportAuthCode(pkgName, authCode);
915 if (!reply.WriteInt32(result)) {
916 LOGE("write result failed");
917 return ERR_DM_IPC_WRITE_FAILED;
918 }
919 return DM_OK;
920 }
921
ON_IPC_CMD(EXPORT_AUTH_CODE,MessageParcel & data,MessageParcel & reply)922 ON_IPC_CMD(EXPORT_AUTH_CODE, MessageParcel &data, MessageParcel &reply)
923 {
924 std::string authCode = "";
925 int32_t result = DeviceManagerService::GetInstance().ExportAuthCode(authCode);
926 if (!reply.WriteString(authCode)) {
927 LOGE("write result failed");
928 return ERR_DM_IPC_WRITE_FAILED;
929 }
930 if (!reply.WriteInt32(result)) {
931 LOGE("write result failed");
932 return ERR_DM_IPC_WRITE_FAILED;
933 }
934 return DM_OK;
935 }
936
ON_IPC_CMD(REGISTER_DISCOVERY_CALLBACK,MessageParcel & data,MessageParcel & reply)937 ON_IPC_CMD(REGISTER_DISCOVERY_CALLBACK, MessageParcel &data, MessageParcel &reply)
938 {
939 std::string pkgName = data.ReadString();
940 std::string discParaStr = data.ReadString();
941 std::string filterOpStr = data.ReadString();
942 std::map<std::string, std::string> discoverParam;
943 ParseMapFromJsonString(discParaStr, discoverParam);
944 std::map<std::string, std::string> filterOptions;
945 ParseMapFromJsonString(filterOpStr, filterOptions);
946 int32_t result = DeviceManagerService::GetInstance().EnableDiscoveryListener(pkgName, discoverParam, filterOptions);
947 if (!reply.WriteInt32(result)) {
948 LOGE("write result failed");
949 return ERR_DM_IPC_WRITE_FAILED;
950 }
951 return DM_OK;
952 }
953
ON_IPC_CMD(UNREGISTER_DISCOVERY_CALLBACK,MessageParcel & data,MessageParcel & reply)954 ON_IPC_CMD(UNREGISTER_DISCOVERY_CALLBACK, MessageParcel &data, MessageParcel &reply)
955 {
956 std::string pkgName = data.ReadString();
957 std::string extraParaStr = data.ReadString();
958 std::map<std::string, std::string> extraParam;
959 ParseMapFromJsonString(extraParaStr, extraParam);
960 int32_t result = DeviceManagerService::GetInstance().DisableDiscoveryListener(pkgName, extraParam);
961 if (!reply.WriteInt32(result)) {
962 LOGE("write result failed");
963 return ERR_DM_IPC_WRITE_FAILED;
964 }
965 return DM_OK;
966 }
967
ON_IPC_CMD(START_DISCOVERING,MessageParcel & data,MessageParcel & reply)968 ON_IPC_CMD(START_DISCOVERING, MessageParcel &data, MessageParcel &reply)
969 {
970 std::string pkgName = data.ReadString();
971 std::string discParaStr = data.ReadString();
972 std::string filterOpStr = data.ReadString();
973 std::map<std::string, std::string> discoverParam;
974 ParseMapFromJsonString(discParaStr, discoverParam);
975 std::map<std::string, std::string> filterOptions;
976 ParseMapFromJsonString(filterOpStr, filterOptions);
977 int32_t result = DeviceManagerService::GetInstance().StartDiscovering(pkgName, discoverParam, filterOptions);
978 if (!reply.WriteInt32(result)) {
979 LOGE("write result failed");
980 return ERR_DM_IPC_WRITE_FAILED;
981 }
982 return DM_OK;
983 }
984
ON_IPC_CMD(STOP_DISCOVERING,MessageParcel & data,MessageParcel & reply)985 ON_IPC_CMD(STOP_DISCOVERING, MessageParcel &data, MessageParcel &reply)
986 {
987 std::string pkgName = data.ReadString();
988 std::string discParaStr = data.ReadString();
989 std::map<std::string, std::string> discoverParam;
990 ParseMapFromJsonString(discParaStr, discoverParam);
991 int32_t result = DeviceManagerService::GetInstance().StopDiscovering(pkgName, discoverParam);
992 if (!reply.WriteInt32(result)) {
993 LOGE("write result failed");
994 return ERR_DM_IPC_WRITE_FAILED;
995 }
996 return DM_OK;
997 }
998
ON_IPC_CMD(START_ADVERTISING,MessageParcel & data,MessageParcel & reply)999 ON_IPC_CMD(START_ADVERTISING, MessageParcel &data, MessageParcel &reply)
1000 {
1001 std::string pkgName = data.ReadString();
1002 std::string adverParaStr = data.ReadString();
1003 std::map<std::string, std::string> advertiseParam;
1004 ParseMapFromJsonString(adverParaStr, advertiseParam);
1005 int32_t result = DeviceManagerService::GetInstance().StartAdvertising(pkgName, advertiseParam);
1006 if (!reply.WriteInt32(result)) {
1007 LOGE("write result failed");
1008 return ERR_DM_IPC_WRITE_FAILED;
1009 }
1010 return DM_OK;
1011 }
1012
ON_IPC_CMD(STOP_ADVERTISING,MessageParcel & data,MessageParcel & reply)1013 ON_IPC_CMD(STOP_ADVERTISING, MessageParcel &data, MessageParcel &reply)
1014 {
1015 std::string pkgName = data.ReadString();
1016 std::string adverParaStr = data.ReadString();
1017 std::map<std::string, std::string> advertiseParam;
1018 ParseMapFromJsonString(adverParaStr, advertiseParam);
1019 int32_t result = DeviceManagerService::GetInstance().StopAdvertising(pkgName, advertiseParam);
1020 if (!reply.WriteInt32(result)) {
1021 LOGE("write result failed");
1022 return ERR_DM_IPC_WRITE_FAILED;
1023 }
1024 return DM_OK;
1025 }
1026
ON_IPC_CMD(BIND_TARGET,MessageParcel & data,MessageParcel & reply)1027 ON_IPC_CMD(BIND_TARGET, MessageParcel &data, MessageParcel &reply)
1028 {
1029 std::string pkgName = data.ReadString();
1030 PeerTargetId targetId;
1031 DecodePeerTargetId(data, targetId);
1032 std::string bindParamStr = data.ReadString();
1033 std::map<std::string, std::string> bindParam;
1034 ParseMapFromJsonString(bindParamStr, bindParam);
1035 int32_t result = DeviceManagerService::GetInstance().BindTarget(pkgName, targetId, bindParam);
1036 if (!reply.WriteInt32(result)) {
1037 LOGE("write result failed");
1038 return ERR_DM_IPC_WRITE_FAILED;
1039 }
1040 return DM_OK;
1041 }
1042
ON_IPC_CMD(UNBIND_TARGET,MessageParcel & data,MessageParcel & reply)1043 ON_IPC_CMD(UNBIND_TARGET, MessageParcel &data, MessageParcel &reply)
1044 {
1045 std::string pkgName = data.ReadString();
1046 PeerTargetId targetId;
1047 DecodePeerTargetId(data, targetId);
1048 std::string unbindParamStr = data.ReadString();
1049 std::map<std::string, std::string> unbindParam;
1050 ParseMapFromJsonString(unbindParamStr, unbindParam);
1051 int32_t result = DeviceManagerService::GetInstance().UnbindTarget(pkgName, targetId, unbindParam);
1052 if (!reply.WriteInt32(result)) {
1053 LOGE("write result failed");
1054 return ERR_DM_IPC_WRITE_FAILED;
1055 }
1056 return DM_OK;
1057 }
1058
ON_IPC_SET_REQUEST(BIND_TARGET_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1059 ON_IPC_SET_REQUEST(BIND_TARGET_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1060 {
1061 if (pBaseReq == nullptr) {
1062 return ERR_DM_FAILED;
1063 }
1064 std::shared_ptr<IpcNotifyBindResultReq> pReq = std::static_pointer_cast<IpcNotifyBindResultReq>(pBaseReq);
1065 std::string pkgName = pReq->GetPkgName();
1066 PeerTargetId targetId = pReq->GetPeerTargetId();
1067 int32_t result = pReq->GetResult();
1068 int32_t status = pReq->GetStatus();
1069 std::string content = pReq->GetContent();
1070
1071 if (!data.WriteString(pkgName)) {
1072 LOGE("write bind pkgName failed");
1073 return ERR_DM_IPC_WRITE_FAILED;
1074 }
1075 if (!EncodePeerTargetId(targetId, data)) {
1076 LOGE("write bind peer target id failed");
1077 return ERR_DM_IPC_WRITE_FAILED;
1078 }
1079 if (!data.WriteInt32(result)) {
1080 LOGE("write bind result code failed");
1081 return ERR_DM_IPC_WRITE_FAILED;
1082 }
1083 if (!data.WriteInt32(status)) {
1084 LOGE("write bind result status failed");
1085 return ERR_DM_IPC_WRITE_FAILED;
1086 }
1087 if (!data.WriteString(content)) {
1088 LOGE("write bind result content failed");
1089 return ERR_DM_IPC_WRITE_FAILED;
1090 }
1091 return DM_OK;
1092 }
1093
ON_IPC_READ_RESPONSE(BIND_TARGET_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1094 ON_IPC_READ_RESPONSE(BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1095 {
1096 if (pBaseRsp == nullptr) {
1097 LOGE("pBaseRsp is null");
1098 return ERR_DM_FAILED;
1099 }
1100 pBaseRsp->SetErrCode(reply.ReadInt32());
1101 return DM_OK;
1102 }
1103
ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1104 ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1105 {
1106 if (pBaseReq == nullptr) {
1107 return ERR_DM_FAILED;
1108 }
1109 std::shared_ptr<IpcNotifyBindResultReq> pReq = std::static_pointer_cast<IpcNotifyBindResultReq>(pBaseReq);
1110 std::string pkgName = pReq->GetPkgName();
1111 PeerTargetId targetId = pReq->GetPeerTargetId();
1112 int32_t result = pReq->GetResult();
1113 std::string content = pReq->GetContent();
1114
1115 if (!data.WriteString(pkgName)) {
1116 LOGE("write unbind pkgName failed");
1117 return ERR_DM_IPC_WRITE_FAILED;
1118 }
1119 if (!EncodePeerTargetId(targetId, data)) {
1120 LOGE("write unbind peer target id failed");
1121 return ERR_DM_IPC_WRITE_FAILED;
1122 }
1123 if (!data.WriteInt32(result)) {
1124 LOGE("write unbind result code failed");
1125 return ERR_DM_IPC_WRITE_FAILED;
1126 }
1127 if (!data.WriteString(content)) {
1128 LOGE("write unbind result content failed");
1129 return ERR_DM_IPC_WRITE_FAILED;
1130 }
1131 return DM_OK;
1132 }
1133
ON_IPC_READ_RESPONSE(UNBIND_TARGET_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1134 ON_IPC_READ_RESPONSE(UNBIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1135 {
1136 if (pBaseRsp == nullptr) {
1137 LOGE("pBaseRsp is null");
1138 return ERR_DM_FAILED;
1139 }
1140 pBaseRsp->SetErrCode(reply.ReadInt32());
1141 return DM_OK;
1142 }
1143
ON_IPC_CMD(REGISTER_PIN_HOLDER_CALLBACK,MessageParcel & data,MessageParcel & reply)1144 ON_IPC_CMD(REGISTER_PIN_HOLDER_CALLBACK, MessageParcel &data, MessageParcel &reply)
1145 {
1146 std::string pkgName = data.ReadString();
1147 int32_t result = DeviceManagerService::GetInstance().RegisterPinHolderCallback(pkgName);
1148 if (!reply.WriteInt32(result)) {
1149 LOGE("write result failed");
1150 return ERR_DM_IPC_WRITE_FAILED;
1151 }
1152 return DM_OK;
1153 }
1154
ON_IPC_CMD(CREATE_PIN_HOLDER,MessageParcel & data,MessageParcel & reply)1155 ON_IPC_CMD(CREATE_PIN_HOLDER, MessageParcel &data, MessageParcel &reply)
1156 {
1157 std::string pkgName = data.ReadString();
1158 PeerTargetId targetId;
1159 DecodePeerTargetId(data, targetId);
1160 std::string payload = data.ReadString();
1161 DmPinType pinType = static_cast<DmPinType>(data.ReadInt32());
1162 int32_t result = DeviceManagerService::GetInstance().CreatePinHolder(pkgName, targetId, pinType, payload);
1163 if (!reply.WriteInt32(result)) {
1164 LOGE("write result failed");
1165 return ERR_DM_IPC_WRITE_FAILED;
1166 }
1167 return DM_OK;
1168 }
1169
ON_IPC_CMD(DESTROY_PIN_HOLDER,MessageParcel & data,MessageParcel & reply)1170 ON_IPC_CMD(DESTROY_PIN_HOLDER, MessageParcel &data, MessageParcel &reply)
1171 {
1172 std::string pkgName = data.ReadString();
1173 PeerTargetId targetId;
1174 DecodePeerTargetId(data, targetId);
1175 DmPinType pinType = static_cast<DmPinType>(data.ReadInt32());
1176 std::string payload = data.ReadString();
1177 int32_t result = DeviceManagerService::GetInstance().DestroyPinHolder(pkgName, targetId, pinType, payload);
1178 if (!reply.WriteInt32(result)) {
1179 LOGE("write result failed");
1180 return ERR_DM_IPC_WRITE_FAILED;
1181 }
1182 return DM_OK;
1183 }
1184
ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1185 ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1186 {
1187 if (pBaseReq == nullptr) {
1188 return ERR_DM_FAILED;
1189 }
1190 std::shared_ptr<IpcCreatePinHolderReq> pReq = std::static_pointer_cast<IpcCreatePinHolderReq>(pBaseReq);
1191 std::string pkgName = pReq->GetPkgName();
1192 std::string deviceId = pReq->GetDeviceId();
1193 int32_t pinType = pReq->GetPinType();
1194 std::string payload = pReq->GetPayload();
1195
1196 if (!data.WriteString(pkgName)) {
1197 LOGE("write pkgName failed");
1198 return ERR_DM_IPC_WRITE_FAILED;
1199 }
1200 if (!data.WriteString(deviceId)) {
1201 LOGE("write deviceId failed");
1202 return ERR_DM_IPC_WRITE_FAILED;
1203 }
1204 if (!data.WriteInt32(pinType)) {
1205 LOGE("write pinType failed");
1206 return ERR_DM_IPC_WRITE_FAILED;
1207 }
1208 if (!data.WriteString(payload)) {
1209 LOGE("write payload failed");
1210 return ERR_DM_IPC_WRITE_FAILED;
1211 }
1212 return DM_OK;
1213 }
1214
ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1215 ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1216 {
1217 if (pBaseRsp == nullptr) {
1218 LOGE("pBaseRsp is null");
1219 return ERR_DM_FAILED;
1220 }
1221 pBaseRsp->SetErrCode(reply.ReadInt32());
1222 return DM_OK;
1223 }
1224
ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1225 ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1226 {
1227 if (pBaseReq == nullptr) {
1228 return ERR_DM_FAILED;
1229 }
1230 std::shared_ptr<IpcDestroyPinHolderReq> pReq = std::static_pointer_cast<IpcDestroyPinHolderReq>(pBaseReq);
1231 std::string pkgName = pReq->GetPkgName();
1232 int32_t pinType = pReq->GetPinType();
1233 std::string payload = pReq->GetPayload();
1234
1235 if (!data.WriteString(pkgName)) {
1236 LOGE("write pkgName failed");
1237 return ERR_DM_IPC_WRITE_FAILED;
1238 }
1239 if (!data.WriteInt32(pinType)) {
1240 LOGE("write pinType failed");
1241 return ERR_DM_IPC_WRITE_FAILED;
1242 }
1243 if (!data.WriteString(payload)) {
1244 LOGE("write payload failed");
1245 return ERR_DM_IPC_WRITE_FAILED;
1246 }
1247 return DM_OK;
1248 }
1249
ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1250 ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1251 {
1252 if (pBaseRsp == nullptr) {
1253 LOGE("pBaseRsp is null");
1254 return ERR_DM_FAILED;
1255 }
1256 pBaseRsp->SetErrCode(reply.ReadInt32());
1257 return DM_OK;
1258 }
1259
ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1260 ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1261 {
1262 if (pBaseReq == nullptr) {
1263 return ERR_DM_FAILED;
1264 }
1265 std::shared_ptr<IpcNotifyPublishResultReq> pReq = std::static_pointer_cast<IpcNotifyPublishResultReq>(pBaseReq);
1266 std::string pkgName = pReq->GetPkgName();
1267 int32_t result = pReq->GetResult();
1268
1269 if (!data.WriteString(pkgName)) {
1270 LOGE("write pkgName failed");
1271 return ERR_DM_IPC_WRITE_FAILED;
1272 }
1273 if (!data.WriteInt32(result)) {
1274 LOGE("write result failed");
1275 return ERR_DM_IPC_WRITE_FAILED;
1276 }
1277 return DM_OK;
1278 }
1279
ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1280 ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1281 {
1282 if (pBaseRsp == nullptr) {
1283 LOGE("pBaseRsp is null");
1284 return ERR_DM_FAILED;
1285 }
1286 pBaseRsp->SetErrCode(reply.ReadInt32());
1287 return DM_OK;
1288 }
1289
ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1290 ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1291 {
1292 if (pBaseReq == nullptr) {
1293 return ERR_DM_FAILED;
1294 }
1295 std::shared_ptr<IpcNotifyPublishResultReq> pReq = std::static_pointer_cast<IpcNotifyPublishResultReq>(pBaseReq);
1296 std::string pkgName = pReq->GetPkgName();
1297 int32_t result = pReq->GetResult();
1298
1299 if (!data.WriteString(pkgName)) {
1300 LOGE("write pkgName failed");
1301 return ERR_DM_IPC_WRITE_FAILED;
1302 }
1303 if (!data.WriteInt32(result)) {
1304 LOGE("write result failed");
1305 return ERR_DM_IPC_WRITE_FAILED;
1306 }
1307 return DM_OK;
1308 }
1309
ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1310 ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1311 {
1312 if (pBaseRsp == nullptr) {
1313 LOGE("pBaseRsp is null");
1314 return ERR_DM_FAILED;
1315 }
1316 pBaseRsp->SetErrCode(reply.ReadInt32());
1317 return DM_OK;
1318 }
1319
ON_IPC_CMD(DP_ACL_ADD,MessageParcel & data,MessageParcel & reply)1320 ON_IPC_CMD(DP_ACL_ADD, MessageParcel &data, MessageParcel &reply)
1321 {
1322 std::string udid = data.ReadString();
1323 int32_t result = DeviceManagerService::GetInstance().DpAclAdd(udid);
1324 if (!reply.WriteInt32(result)) {
1325 LOGE("write result failed");
1326 return ERR_DM_IPC_WRITE_FAILED;
1327 }
1328 return DM_OK;
1329 }
1330
ON_IPC_CMD(GET_SECURITY_LEVEL,MessageParcel & data,MessageParcel & reply)1331 ON_IPC_CMD(GET_SECURITY_LEVEL, MessageParcel &data, MessageParcel &reply)
1332 {
1333 std::string pkgName = data.ReadString();
1334 std::string networkId = data.ReadString();
1335 int32_t securityLevel = -1;
1336 int32_t result = DeviceManagerService::GetInstance().GetDeviceSecurityLevel(pkgName, networkId, securityLevel);
1337 if (!reply.WriteInt32(result)) {
1338 return ERR_DM_IPC_WRITE_FAILED;
1339 }
1340 if (!reply.WriteInt32(securityLevel)) {
1341 return ERR_DM_IPC_WRITE_FAILED;
1342 }
1343 return DM_OK;
1344 }
1345
ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1346 ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1347 {
1348 if (pBaseReq == nullptr) {
1349 return ERR_DM_FAILED;
1350 }
1351 std::shared_ptr<IpcNotifyPinHolderEventReq> pReq = std::static_pointer_cast<IpcNotifyPinHolderEventReq>(pBaseReq);
1352 std::string pkgName = pReq->GetPkgName();
1353 int32_t pinHolderEvent = pReq->GetPinHolderEvent();
1354 int32_t result = pReq->GetResult();
1355 std::string content = pReq->GetContent();
1356
1357 if (!data.WriteString(pkgName)) {
1358 LOGE("write pkgName failed");
1359 return ERR_DM_IPC_WRITE_FAILED;
1360 }
1361 if (!data.WriteInt32(result)) {
1362 LOGE("write result failed");
1363 return ERR_DM_IPC_WRITE_FAILED;
1364 }
1365 if (!data.WriteInt32(pinHolderEvent)) {
1366 LOGE("write pinHolderEvent failed");
1367 return ERR_DM_IPC_WRITE_FAILED;
1368 }
1369 if (!data.WriteString(content)) {
1370 LOGE("write content failed");
1371 return ERR_DM_IPC_WRITE_FAILED;
1372 }
1373 return DM_OK;
1374 }
1375
ON_IPC_READ_RESPONSE(SERVER_ON_PIN_HOLDER_EVENT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1376 ON_IPC_READ_RESPONSE(SERVER_ON_PIN_HOLDER_EVENT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1377 {
1378 if (pBaseRsp == nullptr) {
1379 LOGE("pBaseRsp is null");
1380 return ERR_DM_FAILED;
1381 }
1382 pBaseRsp->SetErrCode(reply.ReadInt32());
1383 return DM_OK;
1384 }
1385
ON_IPC_CMD(IS_SAME_ACCOUNT,MessageParcel & data,MessageParcel & reply)1386 ON_IPC_CMD(IS_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply)
1387 {
1388 std::string netWorkId = data.ReadString();
1389 int32_t result = DeviceManagerService::GetInstance().IsSameAccount(netWorkId);
1390 if (!reply.WriteInt32(result)) {
1391 LOGE("write result failed.");
1392 return ERR_DM_IPC_WRITE_FAILED;
1393 }
1394 return DM_OK;
1395 }
1396
ON_IPC_CMD(CHECK_API_PERMISSION,MessageParcel & data,MessageParcel & reply)1397 ON_IPC_CMD(CHECK_API_PERMISSION, MessageParcel &data, MessageParcel &reply)
1398 {
1399 int32_t permissionLevel = data.ReadInt32();
1400 int32_t result = DeviceManagerService::GetInstance().CheckApiPermission(permissionLevel);
1401 if (!reply.WriteInt32(result)) {
1402 LOGE("write result failed");
1403 return ERR_DM_IPC_WRITE_FAILED;
1404 }
1405 return DM_OK;
1406 }
1407
ON_IPC_CMD(CHECK_ACCESS_CONTROL,MessageParcel & data,MessageParcel & reply)1408 ON_IPC_CMD(CHECK_ACCESS_CONTROL, MessageParcel &data, MessageParcel &reply)
1409 {
1410 DmAccessCaller caller;
1411 DmAccessCallee callee;
1412 DecodeDmAccessCaller(data, caller);
1413 DecodeDmAccessCallee(data, callee);
1414 int32_t result = DeviceManagerService::GetInstance().CheckAccessControl(caller, callee);
1415 if (!reply.WriteInt32(result)) {
1416 LOGE("write result failed.");
1417 return ERR_DM_IPC_WRITE_FAILED;
1418 }
1419 return DM_OK;
1420 }
1421
ON_IPC_CMD(CHECK_SAME_ACCOUNT,MessageParcel & data,MessageParcel & reply)1422 ON_IPC_CMD(CHECK_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply)
1423 {
1424 DmAccessCaller caller;
1425 DmAccessCallee callee;
1426 DecodeDmAccessCaller(data, caller);
1427 DecodeDmAccessCallee(data, callee);
1428 int32_t result = DeviceManagerService::GetInstance().CheckIsSameAccount(caller, callee);
1429 if (!reply.WriteInt32(result)) {
1430 LOGE("write result failed.");
1431 return ERR_DM_IPC_WRITE_FAILED;
1432 }
1433 return DM_OK;
1434 }
1435
1436
ON_IPC_CMD(SHIFT_LNN_GEAR,MessageParcel & data,MessageParcel & reply)1437 ON_IPC_CMD(SHIFT_LNN_GEAR, MessageParcel &data, MessageParcel &reply)
1438 {
1439 std::string pkgName = data.ReadString();
1440 int32_t result = DeviceManagerService::GetInstance().ShiftLNNGear(pkgName, pkgName, true, true);
1441 if (!reply.WriteInt32(result)) {
1442 LOGE("write result failed");
1443 return ERR_DM_IPC_WRITE_FAILED;
1444 }
1445 return DM_OK;
1446 }
1447
ON_IPC_CMD(SET_DN_POLICY,MessageParcel & data,MessageParcel & reply)1448 ON_IPC_CMD(SET_DN_POLICY, MessageParcel &data, MessageParcel &reply)
1449 {
1450 std::string pkgName = data.ReadString();
1451 std::string policyStr = data.ReadString();
1452 std::map<std::string, std::string> policy;
1453 ParseMapFromJsonString(policyStr, policy);
1454 int32_t result = DeviceManagerService::GetInstance().SetDnPolicy(pkgName, policy);
1455 if (!reply.WriteInt32(result)) {
1456 LOGE("write result failed");
1457 return ERR_DM_IPC_WRITE_FAILED;
1458 }
1459 return DM_OK;
1460 }
1461
ON_IPC_CMD(STOP_AUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)1462 ON_IPC_CMD(STOP_AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
1463 {
1464 std::string pkgName = data.ReadString();
1465 int32_t result = DeviceManagerService::GetInstance().StopAuthenticateDevice(pkgName);
1466 if (!reply.WriteInt32(result)) {
1467 LOGE("write result failed");
1468 return ERR_DM_IPC_WRITE_FAILED;
1469 }
1470 return DM_OK;
1471 }
1472
ON_IPC_CMD(GET_NETWORKID_BY_UDID,MessageParcel & data,MessageParcel & reply)1473 ON_IPC_CMD(GET_NETWORKID_BY_UDID, MessageParcel &data, MessageParcel &reply)
1474 {
1475 std::string pkgName = data.ReadString();
1476 std::string udid = data.ReadString();
1477 std::string netWorkId;
1478 int32_t result = DeviceManagerService::GetInstance().GetNetworkIdByUdid(pkgName, udid, netWorkId);
1479
1480 if (!reply.WriteInt32(result)) {
1481 LOGE("write result failed");
1482 return ERR_DM_IPC_WRITE_FAILED;
1483 }
1484 if (!reply.WriteString(netWorkId)) {
1485 LOGE("write result failed");
1486 return ERR_DM_IPC_WRITE_FAILED;
1487 }
1488 return DM_OK;
1489 }
1490
ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1491 ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1492 {
1493 if (pBaseReq == nullptr) {
1494 return ERR_DM_FAILED;
1495 }
1496 std::shared_ptr<IpcNotifyDeviceStateReq> pReq = std::static_pointer_cast<IpcNotifyDeviceStateReq>(pBaseReq);
1497 std::string pkgName = pReq->GetPkgName();
1498 DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
1499
1500 if (!data.WriteString(pkgName)) {
1501 LOGE("write pkgName failed");
1502 return ERR_DM_IPC_WRITE_FAILED;
1503 }
1504 if (!EncodeDmDeviceInfo(deviceInfo, data)) {
1505 LOGE("write dm device info failed");
1506 return ERR_DM_IPC_WRITE_FAILED;
1507 }
1508 return DM_OK;
1509 }
1510
ON_IPC_READ_RESPONSE(SERVER_DEVICE_SCREEN_STATE_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1511 ON_IPC_READ_RESPONSE(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1512 {
1513 if (pBaseRsp == nullptr) {
1514 LOGE("pBaseRsp is null");
1515 return ERR_DM_FAILED;
1516 }
1517 pBaseRsp->SetErrCode(reply.ReadInt32());
1518 return DM_OK;
1519 }
1520
ON_IPC_CMD(GET_DEVICE_SCREEN_STATUS,MessageParcel & data,MessageParcel & reply)1521 ON_IPC_CMD(GET_DEVICE_SCREEN_STATUS, MessageParcel &data, MessageParcel &reply)
1522 {
1523 std::string pkgName = data.ReadString();
1524 std::string networkId = data.ReadString();
1525 int32_t screenStatus = -1;
1526 int32_t result = DeviceManagerService::GetInstance().GetDeviceScreenStatus(pkgName, networkId, screenStatus);
1527 if (!reply.WriteInt32(result)) {
1528 return ERR_DM_IPC_WRITE_FAILED;
1529 }
1530 if (!reply.WriteInt32(screenStatus)) {
1531 return ERR_DM_IPC_WRITE_FAILED;
1532 }
1533 return DM_OK;
1534 }
1535
ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1536 ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1537 {
1538 if (pBaseReq == nullptr) {
1539 return ERR_DM_FAILED;
1540 }
1541 std::shared_ptr<IpcNotifyCredentialAuthStatusReq> pReq =
1542 std::static_pointer_cast<IpcNotifyCredentialAuthStatusReq>(pBaseReq);
1543 std::string pkgName = pReq->GetPkgName();
1544 std::string proofInfo = pReq->GetProofInfo();
1545 uint16_t deviceTypeId = pReq->GetDeviceTypeId();
1546 int32_t errCode = pReq->GetErrCode();
1547
1548 if (!data.WriteString(pkgName)) {
1549 LOGE("write pkgName failed");
1550 return ERR_DM_IPC_WRITE_FAILED;
1551 }
1552 if (!data.WriteString(proofInfo)) {
1553 LOGE("write proofInfo failed");
1554 return ERR_DM_IPC_WRITE_FAILED;
1555 }
1556 if (!data.WriteUint16(deviceTypeId)) {
1557 LOGE("write deviceTypeId failed");
1558 return ERR_DM_IPC_WRITE_FAILED;
1559 }
1560 if (!data.WriteInt32(errCode)) {
1561 LOGE("write errCode failed");
1562 return ERR_DM_IPC_WRITE_FAILED;
1563 }
1564 return DM_OK;
1565 }
1566
ON_IPC_READ_RESPONSE(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1567 ON_IPC_READ_RESPONSE(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1568 {
1569 if (pBaseRsp == nullptr) {
1570 LOGE("pBaseRsp is null");
1571 return ERR_DM_FAILED;
1572 }
1573 pBaseRsp->SetErrCode(reply.ReadInt32());
1574 return DM_OK;
1575 }
1576 } // namespace DistributedHardware
1577 } // namespace OHOS