1 /*
2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "distributed_device_profile_stub_new.h"
17
18 #include <string>
19
20 #include "ipc_skeleton.h"
21 #include "ipc_utils.h"
22
23 #include "distributed_device_profile_errors.h"
24 #include "distributed_device_profile_log.h"
25 #include "distributed_device_profile_enums.h"
26 #include "profile_utils.h"
27
28 namespace OHOS {
29 namespace DistributedDeviceProfile {
30 namespace {
31 const std::string TAG = "DistributedDeviceProfileStubNew";
32 }
33
DistributedDeviceProfileStubNew()34 DistributedDeviceProfileStubNew::DistributedDeviceProfileStubNew()
35 {
36 InitAclAndSubscribe();
37 }
38
InitAclAndSubscribe()39 void DistributedDeviceProfileStubNew::InitAclAndSubscribe()
40 {
41 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE));
42 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE));
43 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE));
44 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE));
45 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE));
46 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE));
47 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE));
48 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE));
49 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE));
50 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS));
51 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE));
52 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH));
53 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE));
54 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH));
55 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED));
56 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED));
57 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES));
58 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_SESSION_KEY));
59 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_SESSION_KEY));
60 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::UPDATE_SESSION_KEY));
61 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::DELETE_SESSION_KEY));
62 }
63
~DistributedDeviceProfileStubNew()64 DistributedDeviceProfileStubNew::~DistributedDeviceProfileStubNew()
65 {
66 HILOGI("destructor!");
67 }
68
IsInterfaceTokenValid(MessageParcel & data)69 bool DistributedDeviceProfileStubNew::IsInterfaceTokenValid(MessageParcel& data)
70 {
71 return data.ReadInterfaceToken() == IDistributedDeviceProfile::GetDescriptor();
72 }
73
74
NotifyAclEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)75 int32_t DistributedDeviceProfileStubNew::NotifyAclEventInner(uint32_t code, MessageParcel& data,
76 MessageParcel& reply, MessageOption& option)
77 {
78 switch (code) {
79 case static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE):
80 return PutAccessControlProfileInner(data, reply);
81 case static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE):
82 return UpdateAccessControlProfileInner(data, reply);
83 case static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE):
84 return GetTrustDeviceProfileInner(data, reply);
85 case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE):
86 return GetAllTrustDeviceProfileInner(data, reply);
87 case static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE):
88 return GetAccessControlProfileInner(data, reply);
89 case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE):
90 return GetAllAccessControlProfileInner(data, reply);
91 case static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE):
92 return DeleteAccessControlProfileInner(data, reply);
93 case static_cast<uint32_t>(DPInterfaceCode::PUT_SESSION_KEY):
94 return PutSessionKeyInner(data, reply);
95 case static_cast<uint32_t>(DPInterfaceCode::GET_SESSION_KEY):
96 return GetSessionKeyInner(data, reply);
97 case static_cast<uint32_t>(DPInterfaceCode::UPDATE_SESSION_KEY):
98 return UpdateSessionKeyInner(data, reply);
99 case static_cast<uint32_t>(DPInterfaceCode::DELETE_SESSION_KEY):
100 return DeleteSessionKeyInner(data, reply);
101 default:
102 return NotifyProfileDataEventInner(code, data, reply, option);
103 }
104 }
105
NotifyProfileDataEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)106 int32_t DistributedDeviceProfileStubNew::NotifyProfileDataEventInner(
107 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
108 {
109 switch (code) {
110 case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE):
111 return SubscribeDeviceProfileInner(data, reply);
112 case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE):
113 return UnSubscribeDeviceProfileInner(data, reply);
114 case static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS):
115 return SendSubscribeInfosInner(data, reply);
116 case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE):
117 return PutServiceProfileInner(data, reply);
118 case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH):
119 return PutServiceProfileBatchInner(data, reply);
120 case static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE):
121 return PutCharacteristicProfileInner(data, reply);
122 case static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH):
123 return PutCharacteristicProfileBatchInner(data, reply);
124 case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED):
125 return SubscribeDeviceProfileInitedInner(data, reply);
126 case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED):
127 return UnSubscribeDeviceProfileInitedInner(data, reply);
128 case static_cast<uint32_t>(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES):
129 return PutAllTrustedDevicesInner(data, reply);
130 default:
131 HILOGE("unknown request code, please check, code = %{public}u", code);
132 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
133 }
134 }
135
NotifyEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)136 int32_t DistributedDeviceProfileStubNew::NotifyEventInner(uint32_t code, MessageParcel& data,
137 MessageParcel& reply, MessageOption& option)
138 {
139 switch (code) {
140 case static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILE_NEW):
141 return GetDeviceProfileInner(data, reply);
142 case static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_PROFILE):
143 return GetServiceProfileInner(data, reply);
144 case static_cast<uint32_t>(DPInterfaceCode::GET_CHAR_PROFILE):
145 return GetCharacteristicProfileInner(data, reply);
146 case static_cast<uint32_t>(DPInterfaceCode::DEL_SERVICE_PROFILE):
147 return DeleteServiceProfileInner(data, reply);
148 case static_cast<uint32_t>(DPInterfaceCode::DEL_CHAR_PROFILE):
149 return DeleteCharacteristicProfileInner(data, reply);
150 case static_cast<uint32_t>(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW):
151 return SyncDeviceProfileInner(data, reply);
152 default:
153 HILOGE("Invalid request code, code = %{public}u", code);
154 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
155 }
156 }
157
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)158 int32_t DistributedDeviceProfileStubNew::OnRemoteRequest(uint32_t code, MessageParcel& data,
159 MessageParcel& reply, MessageOption& option)
160 {
161 HILOGI("code = %{public}u, CallingPid = %{public}u", code, IPCSkeleton::GetCallingPid());
162 DelayUnloadTask();
163 if (!IsInterfaceTokenValid(data)) {
164 HILOGE("check interface token failed");
165 return DP_INTERFACE_CHECK_FAILED;
166 }
167 if (aclAndSubscribeFuncs_.find(code) != aclAndSubscribeFuncs_.end()) {
168 return NotifyAclEventInner(code, data, reply, option);
169 }
170 if (!IsInited()) {
171 HILOGE("DP not finish init");
172 return DP_LOAD_SERVICE_ERR;
173 }
174 int32_t ret = NotifyEventInner(code, data, reply, option);
175 return ret;
176 }
177
PutAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)178 int32_t DistributedDeviceProfileStubNew::PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
179 {
180 HILOGI("called");
181 AccessControlProfile accessControlProfile;
182 if (!accessControlProfile.UnMarshalling(data)) {
183 HILOGE("read parcel fail!");
184 return DP_READ_PARCEL_FAIL;
185 }
186 int32_t ret = PutAccessControlProfile(accessControlProfile);
187 if (!reply.WriteInt32(ret)) {
188 HILOGE("Write reply failed");
189 return DP_WRITE_PARCEL_FAIL;
190 }
191 return DP_SUCCESS;
192 }
193
UpdateAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)194 int32_t DistributedDeviceProfileStubNew::UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
195 {
196 HILOGI("called");
197 AccessControlProfile accessControlProfile;
198 if (!accessControlProfile.UnMarshalling(data)) {
199 HILOGE("read parcel fail!");
200 return DP_READ_PARCEL_FAIL;
201 }
202 int32_t ret = UpdateAccessControlProfile(accessControlProfile);
203 if (!reply.WriteInt32(ret)) {
204 HILOGE("Write reply failed");
205 return ERR_FLATTEN_OBJECT;
206 }
207 return DP_SUCCESS;
208 }
209
GetTrustDeviceProfileInner(MessageParcel & data,MessageParcel & reply)210 int32_t DistributedDeviceProfileStubNew::GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
211 {
212 HILOGD("called");
213 std::string deviceId;
214 READ_HELPER(data, String, deviceId);
215 TrustDeviceProfile trustDeviceProfile;
216 int32_t ret = GetTrustDeviceProfile(deviceId, trustDeviceProfile);
217 if (!reply.WriteInt32(ret)) {
218 HILOGE("Write reply failed");
219 return ERR_FLATTEN_OBJECT;
220 }
221 if (!trustDeviceProfile.Marshalling(reply)) {
222 HILOGE("write parcel fail!");
223 return DP_WRITE_PARCEL_FAIL;
224 }
225 return DP_SUCCESS;
226 }
227
GetAllTrustDeviceProfileInner(MessageParcel & data,MessageParcel & reply)228 int32_t DistributedDeviceProfileStubNew::GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
229 {
230 HILOGI("called");
231 std::vector<TrustDeviceProfile> trustDeviceProfiles;
232 int32_t ret = GetAllTrustDeviceProfile(trustDeviceProfiles);
233 if (!reply.WriteInt32(ret)) {
234 HILOGE("Write reply failed");
235 return ERR_FLATTEN_OBJECT;
236 }
237 if (!IpcUtils::Marshalling(reply, trustDeviceProfiles)) {
238 HILOGE("read parcel fail!");
239 return DP_READ_PARCEL_FAIL;
240 }
241 return DP_SUCCESS;
242 }
243
GetAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)244 int32_t DistributedDeviceProfileStubNew::GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
245 {
246 HILOGI("called");
247 std::map<std::string, std::string> queryParams;
248 if (!IpcUtils::UnMarshalling(data, queryParams)) {
249 HILOGE("read parcel fail!");
250 return DP_READ_PARCEL_FAIL;
251 }
252 std::vector<AccessControlProfile> accessControlProfiles;
253 int32_t ret = GetAccessControlProfile(queryParams, accessControlProfiles);
254 if (!reply.WriteInt32(ret)) {
255 HILOGE("Write reply failed");
256 return ERR_FLATTEN_OBJECT;
257 }
258 if (!IpcUtils::Marshalling(reply, accessControlProfiles)) {
259 HILOGE("write parcel fail!");
260 return DP_WRITE_PARCEL_FAIL;
261 }
262 return DP_SUCCESS;
263 }
264
GetAllAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)265 int32_t DistributedDeviceProfileStubNew::GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
266 {
267 HILOGI("called");
268 std::vector<AccessControlProfile> accessControlProfiles;
269 int32_t ret = GetAllAccessControlProfile(accessControlProfiles);
270 if (!reply.WriteInt32(ret)) {
271 HILOGE("Write reply failed");
272 return ERR_FLATTEN_OBJECT;
273 }
274 if (!IpcUtils::Marshalling(reply, accessControlProfiles)) {
275 HILOGE("write parcel fail!");
276 return DP_WRITE_PARCEL_FAIL;
277 }
278 return DP_SUCCESS;
279 }
280
DeleteAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)281 int32_t DistributedDeviceProfileStubNew::DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
282 {
283 HILOGI("called");
284 int32_t accessControlId;
285 READ_HELPER(data, Int32, accessControlId);
286 int32_t ret = DeleteAccessControlProfile(accessControlId);
287 if (!reply.WriteInt32(ret)) {
288 HILOGE("Write reply failed");
289 return ERR_FLATTEN_OBJECT;
290 }
291 return DP_SUCCESS;
292 }
293
PutSessionKeyInner(MessageParcel & data,MessageParcel & reply)294 int32_t DistributedDeviceProfileStubNew::PutSessionKeyInner(MessageParcel& data, MessageParcel& reply)
295 {
296 HILOGI("called");
297 uint32_t userId = 0;
298 std::vector<uint8_t> sessionKey;
299 int32_t sessionKeyId = 0;
300 READ_HELPER(data, Uint32, userId);
301 if (!IpcUtils::UnMarshalling(data, sessionKey)) {
302 HILOGE("dp ipc write parcel fail");
303 return DP_WRITE_PARCEL_FAIL;
304 }
305 int32_t ret = PutSessionKey(userId, sessionKey, sessionKeyId);
306 if (!reply.WriteInt32(ret)) {
307 HILOGE("Write reply failed");
308 return DP_WRITE_PARCEL_FAIL;
309 }
310 WRITE_HELPER(reply, Int32, sessionKeyId);
311 return DP_SUCCESS;
312 }
313
GetSessionKeyInner(MessageParcel & data,MessageParcel & reply)314 int32_t DistributedDeviceProfileStubNew::GetSessionKeyInner(MessageParcel& data, MessageParcel& reply)
315 {
316 HILOGI("called");
317 uint32_t userId = 0;
318 int32_t sessionKeyId = 0;
319 std::vector<uint8_t> sessionKey;
320 READ_HELPER(data, Uint32, userId);
321 READ_HELPER(data, Int32, sessionKeyId);
322 int32_t ret = GetSessionKey(userId, sessionKeyId, sessionKey);
323 if (!reply.WriteInt32(ret)) {
324 HILOGE("Write reply failed");
325 return DP_WRITE_PARCEL_FAIL;
326 }
327 if (!IpcUtils::Marshalling(reply, sessionKey)) {
328 HILOGE("dp ipc write parcel fail");
329 return DP_WRITE_PARCEL_FAIL;
330 }
331 return DP_SUCCESS;
332 }
333
UpdateSessionKeyInner(MessageParcel & data,MessageParcel & reply)334 int32_t DistributedDeviceProfileStubNew::UpdateSessionKeyInner(MessageParcel& data, MessageParcel& reply)
335 {
336 HILOGI("called");
337 uint32_t userId = 0;
338 std::vector<uint8_t> sessionKey;
339 int32_t sessionKeyId = 0;
340 READ_HELPER(data, Uint32, userId);
341 READ_HELPER(data, Int32, sessionKeyId);
342 if (!IpcUtils::UnMarshalling(data, sessionKey)) {
343 HILOGE("dp ipc write parcel fail");
344 return DP_WRITE_PARCEL_FAIL;
345 }
346 int32_t ret = UpdateSessionKey(userId, sessionKeyId, sessionKey);
347 if (!reply.WriteInt32(ret)) {
348 HILOGE("Write reply failed");
349 return DP_WRITE_PARCEL_FAIL;
350 }
351 return DP_SUCCESS;
352 }
353
DeleteSessionKeyInner(MessageParcel & data,MessageParcel & reply)354 int32_t DistributedDeviceProfileStubNew::DeleteSessionKeyInner(MessageParcel& data, MessageParcel& reply)
355 {
356 HILOGI("called");
357 uint32_t userId = 0;
358 int32_t sessionKeyId = 0;
359 READ_HELPER(data, Uint32, userId);
360 READ_HELPER(data, Int32, sessionKeyId);
361 int32_t ret = DeleteSessionKey(userId, sessionKeyId);
362 if (!reply.WriteInt32(ret)) {
363 HILOGE("Write reply failed");
364 return DP_WRITE_PARCEL_FAIL;
365 }
366 return DP_SUCCESS;
367 }
368
PutServiceProfileInner(MessageParcel & data,MessageParcel & reply)369 int32_t DistributedDeviceProfileStubNew::PutServiceProfileInner(MessageParcel& data, MessageParcel& reply)
370 {
371 HILOGI("called");
372 ServiceProfile serviceProfile;
373 if (!serviceProfile.UnMarshalling(data)) {
374 HILOGE("read parcel fail!");
375 return DP_READ_PARCEL_FAIL;
376 }
377 int32_t ret = PutServiceProfile(serviceProfile);
378 if (!reply.WriteInt32(ret)) {
379 HILOGE("Write reply failed");
380 return ERR_FLATTEN_OBJECT;
381 }
382 return DP_SUCCESS;
383 }
384
PutServiceProfileBatchInner(MessageParcel & data,MessageParcel & reply)385 int32_t DistributedDeviceProfileStubNew::PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply)
386 {
387 std::vector<ServiceProfile> serviceProfiles;
388 if (!IpcUtils::UnMarshalling(data, serviceProfiles)) {
389 HILOGE("read parcel fail!");
390 return DP_READ_PARCEL_FAIL;
391 }
392 int32_t ret = PutServiceProfileBatch(serviceProfiles);
393 if (!reply.WriteInt32(ret)) {
394 HILOGE("Write reply failed");
395 return ERR_FLATTEN_OBJECT;
396 }
397 return DP_SUCCESS;
398 }
399
PutCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)400 int32_t DistributedDeviceProfileStubNew::PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
401 {
402 CharacteristicProfile charProfile;
403 if (!charProfile.UnMarshalling(data)) {
404 HILOGE("read parcel fail!");
405 return DP_READ_PARCEL_FAIL;
406 }
407 int32_t ret = PutCharacteristicProfile(charProfile);
408 if (!reply.WriteInt32(ret)) {
409 HILOGE("Write reply failed");
410 return ERR_FLATTEN_OBJECT;
411 }
412 return DP_SUCCESS;
413 }
414
PutCharacteristicProfileBatchInner(MessageParcel & data,MessageParcel & reply)415 int32_t DistributedDeviceProfileStubNew::PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply)
416 {
417 std::vector<CharacteristicProfile> charProfiles;
418 if (!IpcUtils::UnMarshalling(data, charProfiles)) {
419 HILOGE("read parcel fail!");
420 return DP_READ_PARCEL_FAIL;
421 }
422 int32_t ret = PutCharacteristicProfileBatch(charProfiles);
423 if (!reply.WriteInt32(ret)) {
424 HILOGE("Write reply failed");
425 return ERR_FLATTEN_OBJECT;
426 }
427 return DP_SUCCESS;
428 }
429
GetDeviceProfileInner(MessageParcel & data,MessageParcel & reply)430 int32_t DistributedDeviceProfileStubNew::GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
431 {
432 std::string deviceId;
433 bool isMultiUser = false;
434 int32_t userId = DEFAULT_USER_ID;
435 DeviceProfile deviceProfile;
436 READ_HELPER(data, String, deviceId);
437 READ_HELPER(data, Bool, isMultiUser);
438 READ_HELPER(data, Int32, userId);
439 deviceProfile.SetIsMultiUser(isMultiUser);
440 deviceProfile.SetUserId(userId);
441 int32_t ret = GetDeviceProfile(deviceId, deviceProfile);
442 if (!reply.WriteInt32(ret)) {
443 HILOGE("Write reply failed");
444 return ERR_FLATTEN_OBJECT;
445 }
446 if (!deviceProfile.Marshalling(reply)) {
447 HILOGE("write parcel fail!");
448 return DP_WRITE_PARCEL_FAIL;
449 }
450 return DP_SUCCESS;
451 }
452
GetServiceProfileInner(MessageParcel & data,MessageParcel & reply)453 int32_t DistributedDeviceProfileStubNew::GetServiceProfileInner(MessageParcel& data, MessageParcel& reply)
454 {
455 std::string deviceId;
456 std::string serviceName;
457 bool isMultiUser = false;
458 int32_t userId = DEFAULT_USER_ID;
459 ServiceProfile serviceProfile;
460 READ_HELPER(data, String, deviceId);
461 READ_HELPER(data, String, serviceName);
462 READ_HELPER(data, Bool, isMultiUser);
463 READ_HELPER(data, Int32, userId);
464 serviceProfile.SetIsMultiUser(isMultiUser);
465 serviceProfile.SetUserId(userId);
466 int32_t ret = GetServiceProfile(deviceId, serviceName, serviceProfile);
467 if (!reply.WriteInt32(ret)) {
468 HILOGE("Write reply failed");
469 return ERR_FLATTEN_OBJECT;
470 }
471 if (!serviceProfile.Marshalling(reply)) {
472 HILOGE("write parcel fail!");
473 return DP_WRITE_PARCEL_FAIL;
474 }
475 return DP_SUCCESS;
476 }
477
GetCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)478 int32_t DistributedDeviceProfileStubNew::GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
479 {
480 std::string deviceId;
481 std::string serviceName;
482 std::string characteristicKey;
483 bool isMultiUser = false;
484 int32_t userId = DEFAULT_USER_ID;
485 READ_HELPER(data, String, deviceId);
486 READ_HELPER(data, String, serviceName);
487 READ_HELPER(data, String, characteristicKey);
488 READ_HELPER(data, Bool, isMultiUser);
489 READ_HELPER(data, Int32, userId);
490 CharacteristicProfile charProfile;
491 charProfile.SetIsMultiUser(isMultiUser);
492 charProfile.SetUserId(userId);
493 int32_t ret = GetCharacteristicProfile(deviceId, serviceName, characteristicKey, charProfile);
494 if (!reply.WriteInt32(ret)) {
495 HILOGE("Write reply failed");
496 return ERR_FLATTEN_OBJECT;
497 }
498 if (!charProfile.Marshalling(reply)) {
499 HILOGE("write parcel fail!");
500 return DP_WRITE_PARCEL_FAIL;
501 }
502 return DP_SUCCESS;
503 }
504
DeleteServiceProfileInner(MessageParcel & data,MessageParcel & reply)505 int32_t DistributedDeviceProfileStubNew::DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply)
506 {
507 std::string deviceId;
508 std::string serviceName;
509 bool isMultiUser = false;
510 int32_t userId = DEFAULT_USER_ID;
511 READ_HELPER(data, String, deviceId);
512 READ_HELPER(data, String, serviceName);
513 READ_HELPER(data, Bool, isMultiUser);
514 READ_HELPER(data, Int32, userId);
515 int32_t ret = DeleteServiceProfile(deviceId, serviceName, isMultiUser, userId);
516 if (!reply.WriteInt32(ret)) {
517 HILOGE("Write reply failed");
518 return ERR_FLATTEN_OBJECT;
519 }
520 return DP_SUCCESS;
521 }
522
DeleteCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)523 int32_t DistributedDeviceProfileStubNew::DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
524 {
525 std::string deviceId;
526 std::string serviceName;
527 std::string characteristicKey;
528 bool isMultiUser = false;
529 int32_t userId = DEFAULT_USER_ID;
530 READ_HELPER(data, String, deviceId);
531 READ_HELPER(data, String, serviceName);
532 READ_HELPER(data, String, characteristicKey);
533 READ_HELPER(data, Bool, isMultiUser);
534 READ_HELPER(data, Int32, userId);
535 int32_t ret = DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey, isMultiUser, userId);
536 if (!reply.WriteInt32(ret)) {
537 HILOGE("Write reply failed");
538 return ERR_FLATTEN_OBJECT;
539 }
540 return DP_SUCCESS;
541 }
542
SubscribeDeviceProfileInner(MessageParcel & data,MessageParcel & reply)543 int32_t DistributedDeviceProfileStubNew::SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
544 {
545 SubscribeInfo subscribeInfo;
546 if (!subscribeInfo.UnMarshalling(data)) {
547 HILOGE("read parcel fail!");
548 return DP_READ_PARCEL_FAIL;
549 }
550 int32_t ret = SubscribeDeviceProfile(subscribeInfo);
551 if (!reply.WriteInt32(ret)) {
552 HILOGE("Write reply failed");
553 return ERR_FLATTEN_OBJECT;
554 }
555 return DP_SUCCESS;
556 }
557
UnSubscribeDeviceProfileInner(MessageParcel & data,MessageParcel & reply)558 int32_t DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
559 {
560 SubscribeInfo subscribeInfo;
561 if (!subscribeInfo.UnMarshalling(data)) {
562 HILOGE("read parcel fail!");
563 return DP_READ_PARCEL_FAIL;
564 }
565 int32_t ret = UnSubscribeDeviceProfile(subscribeInfo);
566 if (!reply.WriteInt32(ret)) {
567 HILOGE("Write reply failed");
568 return ERR_FLATTEN_OBJECT;
569 }
570 return DP_SUCCESS;
571 }
572
SyncDeviceProfileInner(MessageParcel & data,MessageParcel & reply)573 int32_t DistributedDeviceProfileStubNew::SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
574 {
575 DistributedDeviceProfile::DpSyncOptions syncOptions;
576 if (!syncOptions.UnMarshalling(data)) {
577 HILOGE("read parcel fail!");
578 return DP_READ_PARCEL_FAIL;
579 }
580 sptr<IRemoteObject> syncCompletedCallback = data.ReadRemoteObject();
581 int32_t ret = SyncDeviceProfile(syncOptions, syncCompletedCallback);
582 if (!reply.WriteInt32(ret)) {
583 HILOGE("Write reply failed");
584 return ERR_FLATTEN_OBJECT;
585 }
586 return DP_SUCCESS;
587 }
588
SendSubscribeInfosInner(MessageParcel & data,MessageParcel & reply)589 int32_t DistributedDeviceProfileStubNew::SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply)
590 {
591 std::map<std::string, SubscribeInfo> listenerMap;
592 if (!IpcUtils::UnMarshalling(data, listenerMap)) {
593 HILOGE("read parcel fail!");
594 return DP_READ_PARCEL_FAIL;
595 }
596 int32_t ret = SendSubscribeInfos(listenerMap);
597 if (!reply.WriteInt32(ret)) {
598 HILOGE("Write reply failed");
599 return ERR_FLATTEN_OBJECT;
600 }
601 return DP_SUCCESS;
602 }
603
SubscribeDeviceProfileInitedInner(MessageParcel & data,MessageParcel & reply)604 int32_t DistributedDeviceProfileStubNew::SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply)
605 {
606 int32_t saId = -1;
607 READ_HELPER(data, Int32, saId);
608 sptr<IRemoteObject> dpInitedCallback = data.ReadRemoteObject();
609 if (dpInitedCallback == nullptr) {
610 HILOGE("read remoteObject failed!");
611 return ERR_FLATTEN_OBJECT;
612 }
613 int32_t ret = SubscribeDeviceProfileInited(saId, dpInitedCallback);
614 if (!reply.WriteInt32(ret)) {
615 HILOGE("Write reply failed");
616 return ERR_FLATTEN_OBJECT;
617 }
618 return DP_SUCCESS;
619 }
620
UnSubscribeDeviceProfileInitedInner(MessageParcel & data,MessageParcel & reply)621 int32_t DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply)
622 {
623 int32_t saId = -1;
624 READ_HELPER(data, Int32, saId);
625 int32_t ret = UnSubscribeDeviceProfileInited(saId);
626 if (!reply.WriteInt32(ret)) {
627 HILOGE("Write reply failed");
628 return ERR_FLATTEN_OBJECT;
629 }
630 return DP_SUCCESS;
631 }
632
PutAllTrustedDevicesInner(MessageParcel & data,MessageParcel & reply)633 int32_t DistributedDeviceProfileStubNew::PutAllTrustedDevicesInner(MessageParcel& data, MessageParcel& reply)
634 {
635 std::vector<TrustedDeviceInfo> deviceInfos;
636 if (!IpcUtils::UnMarshalling(data, deviceInfos)) {
637 HILOGE("read parcel fail!");
638 return DP_READ_PARCEL_FAIL;
639 }
640 int32_t ret = PutAllTrustedDevices(deviceInfos);
641 if (!reply.WriteInt32(ret)) {
642 HILOGE("Write reply failed");
643 return ERR_FLATTEN_OBJECT;
644 }
645 return DP_SUCCESS;
646 }
647
PutLocalServiceInfoInner(MessageParcel & data,MessageParcel & reply)648 int32_t DistributedDeviceProfileStubNew::PutLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply)
649 {
650 HILOGI("called");
651 LocalServiceInfo localServiceInfo;
652 if (!localServiceInfo.UnMarshalling(data)) {
653 HILOGE("read parcel fail!");
654 return DP_READ_PARCEL_FAIL;
655 }
656 int32_t ret = PutLocalServiceInfo(localServiceInfo);
657 if (!reply.WriteInt32(ret)) {
658 HILOGE("Write reply failed");
659 return DP_WRITE_PARCEL_FAIL;
660 }
661 return DP_SUCCESS;
662 }
663
UpdateLocalServiceInfoInner(MessageParcel & data,MessageParcel & reply)664 int32_t DistributedDeviceProfileStubNew::UpdateLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply)
665 {
666 HILOGI("called");
667 LocalServiceInfo localServiceInfo;
668 if (!localServiceInfo.UnMarshalling(data)) {
669 HILOGE("read parcel fail!");
670 return DP_READ_PARCEL_FAIL;
671 }
672 int32_t ret = UpdateLocalServiceInfo(localServiceInfo);
673 if (!reply.WriteInt32(ret)) {
674 HILOGE("Write reply failed");
675 return DP_WRITE_PARCEL_FAIL;
676 }
677 return DP_SUCCESS;
678 }
679
GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel & data,MessageParcel & reply)680 int32_t DistributedDeviceProfileStubNew::GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel& data,
681 MessageParcel& reply)
682 {
683 LocalServiceInfo localServiceInfo;
684 int32_t pinExchangeType = 0;
685 std::string bundleName = "";
686 READ_HELPER(data, String, bundleName);
687 READ_HELPER(data, Int32, pinExchangeType);
688 int32_t ret = GetLocalServiceInfoByBundleAndPinType(bundleName, pinExchangeType, localServiceInfo);
689 if (!reply.WriteInt32(ret)) {
690 HILOGE("Write reply failed");
691 return ERR_FLATTEN_OBJECT;
692 }
693 if (!localServiceInfo.Marshalling(reply)) {
694 HILOGE("write parcel fail!");
695 return DP_WRITE_PARCEL_FAIL;
696 }
697 return DP_SUCCESS;
698 }
699
DeleteLocalServiceInfoInner(MessageParcel & data,MessageParcel & reply)700 int32_t DistributedDeviceProfileStubNew::DeleteLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply)
701 {
702 int32_t pinExchangeType = 0;
703 std::string bundleName = "";
704 READ_HELPER(data, String, bundleName);
705 READ_HELPER(data, Int32, pinExchangeType);
706 int32_t ret = DeleteLocalServiceInfo(bundleName, pinExchangeType);
707 if (!reply.WriteInt32(ret)) {
708 HILOGE("Write reply failed");
709 return DP_WRITE_PARCEL_FAIL;
710 }
711 return DP_SUCCESS;
712 }
713 } // namespace DeviceProfile
714 } // namespace OHOS
715