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