1 /*
2 * Copyright (c) 2021-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 "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 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE)] =
37 &DistributedDeviceProfileStubNew::PutAccessControlProfileInner;
38 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE)] =
39 &DistributedDeviceProfileStubNew::UpdateAccessControlProfileInner;
40 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE)] =
41 &DistributedDeviceProfileStubNew::GetTrustDeviceProfileInner;
42 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE)] =
43 &DistributedDeviceProfileStubNew::GetAllTrustDeviceProfileInner;
44 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE)] =
45 &DistributedDeviceProfileStubNew::GetAccessControlProfileInner;
46 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE)] =
47 &DistributedDeviceProfileStubNew::GetAllAccessControlProfileInner;
48 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE)] =
49 &DistributedDeviceProfileStubNew::DeleteAccessControlProfileInner;
50 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE)] =
51 &DistributedDeviceProfileStubNew::PutServiceProfileInner;
52 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH)] =
53 &DistributedDeviceProfileStubNew::PutServiceProfileBatchInner;
54 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE)] =
55 &DistributedDeviceProfileStubNew::PutCharacteristicProfileInner;
56 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH)] =
57 &DistributedDeviceProfileStubNew::PutCharacteristicProfileBatchInner;
58 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILE_NEW)] =
59 &DistributedDeviceProfileStubNew::GetDeviceProfileInner;
60 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_PROFILE)] =
61 &DistributedDeviceProfileStubNew::GetServiceProfileInner;
62 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_CHAR_PROFILE)] =
63 &DistributedDeviceProfileStubNew::GetCharacteristicProfileInner;
64 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DEL_SERVICE_PROFILE)] =
65 &DistributedDeviceProfileStubNew::DeleteServiceProfileInner;
66 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DEL_CHAR_PROFILE)] =
67 &DistributedDeviceProfileStubNew::DeleteCharacteristicProfileInner;
68 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE)] =
69 &DistributedDeviceProfileStubNew::SubscribeDeviceProfileInner;
70 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE)] =
71 &DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInner;
72 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW)] =
73 &DistributedDeviceProfileStubNew::SyncDeviceProfileInner;
74 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS)] =
75 &DistributedDeviceProfileStubNew::SendSubscribeInfosInner;
76 InitAclAndSubscribe();
77 }
78
InitAclAndSubscribe()79 void DistributedDeviceProfileStubNew::InitAclAndSubscribe()
80 {
81 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE));
82 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE));
83 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE));
84 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE));
85 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE));
86 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE));
87 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE));
88 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE));
89 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE));
90 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS));
91 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE));
92 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH));
93 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE));
94 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH));
95 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED));
96 aclAndSubscribeFuncs_.insert(static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED));
97 }
98
~DistributedDeviceProfileStubNew()99 DistributedDeviceProfileStubNew::~DistributedDeviceProfileStubNew()
100 {
101 HILOGI("destructor!");
102 }
103
IsInterfaceTokenValid(MessageParcel & data)104 bool DistributedDeviceProfileStubNew::IsInterfaceTokenValid(MessageParcel& data)
105 {
106 return data.ReadInterfaceToken() == IDistributedDeviceProfile::GetDescriptor();
107 }
108
109
NotifyAclEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)110 int32_t DistributedDeviceProfileStubNew::NotifyAclEventInner(uint32_t code, MessageParcel& data,
111 MessageParcel& reply, MessageOption& option)
112 {
113 switch (code) {
114 case static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE):
115 return PutAccessControlProfileInner(data, reply);
116 case static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE):
117 return UpdateAccessControlProfileInner(data, reply);
118 case static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE):
119 return GetTrustDeviceProfileInner(data, reply);
120 case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE):
121 return GetAllTrustDeviceProfileInner(data, reply);
122 case static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE):
123 return GetAccessControlProfileInner(data, reply);
124 case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE):
125 return GetAllAccessControlProfileInner(data, reply);
126 case static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE):
127 return DeleteAccessControlProfileInner(data, reply);
128 case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE):
129 return SubscribeDeviceProfileInner(data, reply);
130 case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE):
131 return UnSubscribeDeviceProfileInner(data, reply);
132 case static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS):
133 return SendSubscribeInfosInner(data, reply);
134 case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE):
135 return PutServiceProfileInner(data, reply);
136 case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH):
137 return PutServiceProfileBatchInner(data, reply);
138 case static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE):
139 return PutCharacteristicProfileInner(data, reply);
140 case static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH):
141 return PutCharacteristicProfileBatchInner(data, reply);
142 case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED):
143 return SubscribeDeviceProfileInitedInner(data, reply);
144 case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED):
145 return UnSubscribeDeviceProfileInitedInner(data, reply);
146 default:
147 HILOGE("unknown request code, please check, code = %{public}u", code);
148 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
149 }
150 }
151
NotifyEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)152 int32_t DistributedDeviceProfileStubNew::NotifyEventInner(uint32_t code, MessageParcel& data,
153 MessageParcel& reply, MessageOption& option)
154 {
155 switch (code) {
156 case static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILE_NEW):
157 return GetDeviceProfileInner(data, reply);
158 case static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_PROFILE):
159 return GetServiceProfileInner(data, reply);
160 case static_cast<uint32_t>(DPInterfaceCode::GET_CHAR_PROFILE):
161 return GetCharacteristicProfileInner(data, reply);
162 case static_cast<uint32_t>(DPInterfaceCode::DEL_SERVICE_PROFILE):
163 return DeleteServiceProfileInner(data, reply);
164 case static_cast<uint32_t>(DPInterfaceCode::DEL_CHAR_PROFILE):
165 return DeleteCharacteristicProfileInner(data, reply);
166 case static_cast<uint32_t>(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW):
167 return SyncDeviceProfileInner(data, reply);
168 default:
169 HILOGE("Invalid request code, code = %{public}u", code);
170 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
171 }
172 }
173
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)174 int32_t DistributedDeviceProfileStubNew::OnRemoteRequest(uint32_t code, MessageParcel& data,
175 MessageParcel& reply, MessageOption& option)
176 {
177 HILOGI("code = %{public}u, CallingPid = %{public}u", code, IPCSkeleton::GetCallingPid());
178 DelayUnloadTask();
179 if (!IsInterfaceTokenValid(data)) {
180 HILOGE("check interface token failed");
181 return DP_INTERFACE_CHECK_FAILED;
182 }
183 if (aclAndSubscribeFuncs_.find(code) != aclAndSubscribeFuncs_.end()) {
184 return NotifyAclEventInner(code, data, reply, option);
185 }
186 if (!IsInited()) {
187 HILOGE("DP not finish init");
188 return DP_LOAD_SERVICE_ERR;
189 }
190 int32_t ret = NotifyEventInner(code, data, reply, option);
191 return ret;
192 }
193
PutAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)194 int32_t DistributedDeviceProfileStubNew::PutAccessControlProfileInner(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 = PutAccessControlProfile(accessControlProfile);
203 if (!reply.WriteInt32(ret)) {
204 HILOGE("Write reply failed");
205 return DP_WRITE_PARCEL_FAIL;
206 }
207 return DP_SUCCESS;
208 }
209
UpdateAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)210 int32_t DistributedDeviceProfileStubNew::UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
211 {
212 HILOGI("called");
213 AccessControlProfile accessControlProfile;
214 if (!accessControlProfile.UnMarshalling(data)) {
215 HILOGE("read parcel fail!");
216 return DP_READ_PARCEL_FAIL;
217 }
218 int32_t ret = UpdateAccessControlProfile(accessControlProfile);
219 if (!reply.WriteInt32(ret)) {
220 HILOGE("Write reply failed");
221 return ERR_FLATTEN_OBJECT;
222 }
223 return DP_SUCCESS;
224 }
225
GetTrustDeviceProfileInner(MessageParcel & data,MessageParcel & reply)226 int32_t DistributedDeviceProfileStubNew::GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
227 {
228 HILOGI("called");
229 std::string deviceId;
230 READ_HELPER(data, String, deviceId);
231 TrustDeviceProfile trustDeviceProfile;
232 int32_t ret = GetTrustDeviceProfile(deviceId, trustDeviceProfile);
233 if (!reply.WriteInt32(ret)) {
234 HILOGE("Write reply failed");
235 return ERR_FLATTEN_OBJECT;
236 }
237 if (!trustDeviceProfile.Marshalling(reply)) {
238 HILOGE("write parcel fail!");
239 return DP_WRITE_PARCEL_FAIL;
240 }
241 return DP_SUCCESS;
242 }
243
GetAllTrustDeviceProfileInner(MessageParcel & data,MessageParcel & reply)244 int32_t DistributedDeviceProfileStubNew::GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
245 {
246 HILOGI("called");
247 std::vector<TrustDeviceProfile> trustDeviceProfiles;
248 int32_t ret = GetAllTrustDeviceProfile(trustDeviceProfiles);
249 if (!reply.WriteInt32(ret)) {
250 HILOGE("Write reply failed");
251 return ERR_FLATTEN_OBJECT;
252 }
253 if (!IpcUtils::Marshalling(reply, trustDeviceProfiles)) {
254 HILOGE("read parcel fail!");
255 return DP_READ_PARCEL_FAIL;
256 }
257 return DP_SUCCESS;
258 }
259
GetAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)260 int32_t DistributedDeviceProfileStubNew::GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
261 {
262 HILOGI("called");
263 std::map<std::string, std::string> queryParams;
264 if (!IpcUtils::UnMarshalling(data, queryParams)) {
265 HILOGE("read parcel fail!");
266 return DP_READ_PARCEL_FAIL;
267 }
268 std::vector<AccessControlProfile> accessControlProfiles;
269 int32_t ret = GetAccessControlProfile(queryParams, 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
GetAllAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)281 int32_t DistributedDeviceProfileStubNew::GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
282 {
283 HILOGI("called");
284 std::vector<AccessControlProfile> accessControlProfiles;
285 int32_t ret = GetAllAccessControlProfile(accessControlProfiles);
286 if (!reply.WriteInt32(ret)) {
287 HILOGE("Write reply failed");
288 return ERR_FLATTEN_OBJECT;
289 }
290 if (!IpcUtils::Marshalling(reply, accessControlProfiles)) {
291 HILOGE("write parcel fail!");
292 return DP_WRITE_PARCEL_FAIL;
293 }
294 return DP_SUCCESS;
295 }
296
DeleteAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)297 int32_t DistributedDeviceProfileStubNew::DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
298 {
299 HILOGI("called");
300 int32_t accessControlId;
301 READ_HELPER(data, Int32, accessControlId);
302 int32_t ret = DeleteAccessControlProfile(accessControlId);
303 if (!reply.WriteInt32(ret)) {
304 HILOGE("Write reply failed");
305 return ERR_FLATTEN_OBJECT;
306 }
307 return DP_SUCCESS;
308 }
309
PutServiceProfileInner(MessageParcel & data,MessageParcel & reply)310 int32_t DistributedDeviceProfileStubNew::PutServiceProfileInner(MessageParcel& data, MessageParcel& reply)
311 {
312 HILOGI("called");
313 ServiceProfile serviceProfile;
314 if (!serviceProfile.UnMarshalling(data)) {
315 HILOGE("read parcel fail!");
316 return DP_READ_PARCEL_FAIL;
317 }
318 int32_t ret = PutServiceProfile(serviceProfile);
319 if (!reply.WriteInt32(ret)) {
320 HILOGE("Write reply failed");
321 return ERR_FLATTEN_OBJECT;
322 }
323 return DP_SUCCESS;
324 }
325
PutServiceProfileBatchInner(MessageParcel & data,MessageParcel & reply)326 int32_t DistributedDeviceProfileStubNew::PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply)
327 {
328 std::vector<ServiceProfile> serviceProfiles;
329 if (!IpcUtils::UnMarshalling(data, serviceProfiles)) {
330 HILOGE("read parcel fail!");
331 return DP_READ_PARCEL_FAIL;
332 }
333 int32_t ret = PutServiceProfileBatch(serviceProfiles);
334 if (!reply.WriteInt32(ret)) {
335 HILOGE("Write reply failed");
336 return ERR_FLATTEN_OBJECT;
337 }
338 return DP_SUCCESS;
339 }
340
PutCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)341 int32_t DistributedDeviceProfileStubNew::PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
342 {
343 CharacteristicProfile charProfile;
344 if (!charProfile.UnMarshalling(data)) {
345 HILOGE("read parcel fail!");
346 return DP_READ_PARCEL_FAIL;
347 }
348 int32_t ret = PutCharacteristicProfile(charProfile);
349 if (!reply.WriteInt32(ret)) {
350 HILOGE("Write reply failed");
351 return ERR_FLATTEN_OBJECT;
352 }
353 return DP_SUCCESS;
354 }
355
PutCharacteristicProfileBatchInner(MessageParcel & data,MessageParcel & reply)356 int32_t DistributedDeviceProfileStubNew::PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply)
357 {
358 std::vector<CharacteristicProfile> charProfiles;
359 if (!IpcUtils::UnMarshalling(data, charProfiles)) {
360 HILOGE("read parcel fail!");
361 return DP_READ_PARCEL_FAIL;
362 }
363 int32_t ret = PutCharacteristicProfileBatch(charProfiles);
364 if (!reply.WriteInt32(ret)) {
365 HILOGE("Write reply failed");
366 return ERR_FLATTEN_OBJECT;
367 }
368 return DP_SUCCESS;
369 }
370
GetDeviceProfileInner(MessageParcel & data,MessageParcel & reply)371 int32_t DistributedDeviceProfileStubNew::GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
372 {
373 std::string deviceId;
374 DeviceProfile deviceProfile;
375 READ_HELPER(data, String, deviceId);
376 int32_t ret = GetDeviceProfile(deviceId, deviceProfile);
377 if (!reply.WriteInt32(ret)) {
378 HILOGE("Write reply failed");
379 return ERR_FLATTEN_OBJECT;
380 }
381 if (!deviceProfile.Marshalling(reply)) {
382 HILOGE("write parcel fail!");
383 return DP_WRITE_PARCEL_FAIL;
384 }
385 return DP_SUCCESS;
386 }
387
GetServiceProfileInner(MessageParcel & data,MessageParcel & reply)388 int32_t DistributedDeviceProfileStubNew::GetServiceProfileInner(MessageParcel& data, MessageParcel& reply)
389 {
390 std::string deviceId;
391 std::string serviceName;
392 ServiceProfile serviceProfile;
393 READ_HELPER(data, String, deviceId);
394 READ_HELPER(data, String, serviceName);
395 int32_t ret = GetServiceProfile(deviceId, serviceName, serviceProfile);
396 if (!reply.WriteInt32(ret)) {
397 HILOGE("Write reply failed");
398 return ERR_FLATTEN_OBJECT;
399 }
400 if (!serviceProfile.Marshalling(reply)) {
401 HILOGE("write parcel fail!");
402 return DP_WRITE_PARCEL_FAIL;
403 }
404 return DP_SUCCESS;
405 }
406
GetCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)407 int32_t DistributedDeviceProfileStubNew::GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
408 {
409 std::string deviceId;
410 std::string serviceName;
411 std::string characteristicKey;
412 READ_HELPER(data, String, deviceId);
413 READ_HELPER(data, String, serviceName);
414 READ_HELPER(data, String, characteristicKey);
415 CharacteristicProfile charProfile;
416 int32_t ret = GetCharacteristicProfile(deviceId, serviceName, characteristicKey, charProfile);
417 if (!reply.WriteInt32(ret)) {
418 HILOGE("Write reply failed");
419 return ERR_FLATTEN_OBJECT;
420 }
421 if (!charProfile.Marshalling(reply)) {
422 HILOGE("write parcel fail!");
423 return DP_WRITE_PARCEL_FAIL;
424 }
425 return DP_SUCCESS;
426 }
427
DeleteServiceProfileInner(MessageParcel & data,MessageParcel & reply)428 int32_t DistributedDeviceProfileStubNew::DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply)
429 {
430 std::string deviceId;
431 std::string serviceName;
432 READ_HELPER(data, String, deviceId);
433 READ_HELPER(data, String, serviceName);
434 int32_t ret = DeleteServiceProfile(deviceId, serviceName);
435 if (!reply.WriteInt32(ret)) {
436 HILOGE("Write reply failed");
437 return ERR_FLATTEN_OBJECT;
438 }
439 return DP_SUCCESS;
440 }
441
DeleteCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)442 int32_t DistributedDeviceProfileStubNew::DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
443 {
444 std::string deviceId;
445 std::string serviceName;
446 std::string characteristicKey;
447 READ_HELPER(data, String, deviceId);
448 READ_HELPER(data, String, serviceName);
449 READ_HELPER(data, String, characteristicKey);
450 int32_t ret = DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey);
451 if (!reply.WriteInt32(ret)) {
452 HILOGE("Write reply failed");
453 return ERR_FLATTEN_OBJECT;
454 }
455 return DP_SUCCESS;
456 }
457
SubscribeDeviceProfileInner(MessageParcel & data,MessageParcel & reply)458 int32_t DistributedDeviceProfileStubNew::SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
459 {
460 SubscribeInfo subscribeInfo;
461 if (!subscribeInfo.UnMarshalling(data)) {
462 HILOGE("read parcel fail!");
463 return DP_READ_PARCEL_FAIL;
464 }
465 int32_t ret = SubscribeDeviceProfile(subscribeInfo);
466 if (!reply.WriteInt32(ret)) {
467 HILOGE("Write reply failed");
468 return ERR_FLATTEN_OBJECT;
469 }
470 return DP_SUCCESS;
471 }
472
UnSubscribeDeviceProfileInner(MessageParcel & data,MessageParcel & reply)473 int32_t DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
474 {
475 SubscribeInfo subscribeInfo;
476 if (!subscribeInfo.UnMarshalling(data)) {
477 HILOGE("read parcel fail!");
478 return DP_READ_PARCEL_FAIL;
479 }
480 int32_t ret = UnSubscribeDeviceProfile(subscribeInfo);
481 if (!reply.WriteInt32(ret)) {
482 HILOGE("Write reply failed");
483 return ERR_FLATTEN_OBJECT;
484 }
485 return DP_SUCCESS;
486 }
487
SyncDeviceProfileInner(MessageParcel & data,MessageParcel & reply)488 int32_t DistributedDeviceProfileStubNew::SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
489 {
490 DistributedDeviceProfile::DpSyncOptions syncOptions;
491 if (!syncOptions.UnMarshalling(data)) {
492 HILOGE("read parcel fail!");
493 return DP_READ_PARCEL_FAIL;
494 }
495 sptr<IRemoteObject> syncCompletedCallback = data.ReadRemoteObject();
496 int32_t ret = SyncDeviceProfile(syncOptions, syncCompletedCallback);
497 if (!reply.WriteInt32(ret)) {
498 HILOGE("Write reply failed");
499 return ERR_FLATTEN_OBJECT;
500 }
501 return DP_SUCCESS;
502 }
503
504
SendSubscribeInfosInner(MessageParcel & data,MessageParcel & reply)505 int32_t DistributedDeviceProfileStubNew::SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply)
506 {
507 std::map<std::string, SubscribeInfo> listenerMap;
508 if (!IpcUtils::UnMarshalling(data, listenerMap)) {
509 HILOGE("read parcel fail!");
510 return DP_READ_PARCEL_FAIL;
511 }
512 int32_t ret = SendSubscribeInfos(listenerMap);
513 if (!reply.WriteInt32(ret)) {
514 HILOGE("Write reply failed");
515 return ERR_FLATTEN_OBJECT;
516 }
517 return DP_SUCCESS;
518 }
519
SubscribeDeviceProfileInitedInner(MessageParcel & data,MessageParcel & reply)520 int32_t DistributedDeviceProfileStubNew::SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply)
521 {
522 int32_t saId = -1;
523 READ_HELPER(data, Int32, saId);
524 sptr<IRemoteObject> dpInitedCallback = data.ReadRemoteObject();
525 if (dpInitedCallback == nullptr) {
526 HILOGE("read remoteObject failed!");
527 return ERR_FLATTEN_OBJECT;
528 }
529 int32_t ret = SubscribeDeviceProfileInited(saId, dpInitedCallback);
530 if (!reply.WriteInt32(ret)) {
531 HILOGE("Write reply failed");
532 return ERR_FLATTEN_OBJECT;
533 }
534 return DP_SUCCESS;
535 }
536
UnSubscribeDeviceProfileInitedInner(MessageParcel & data,MessageParcel & reply)537 int32_t DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply)
538 {
539 int32_t saId = -1;
540 READ_HELPER(data, Int32, saId);
541 int32_t ret = UnSubscribeDeviceProfileInited(saId);
542 if (!reply.WriteInt32(ret)) {
543 HILOGE("Write reply failed");
544 return ERR_FLATTEN_OBJECT;
545 }
546 return DP_SUCCESS;
547 }
548 } // namespace DeviceProfile
549 } // namespace OHOS
550