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.h"
17
18 #include <string>
19
20 #include "authority_manager.h"
21 #include "deviceprofile_ipc_interface_code.h"
22 #include "device_profile_errors.h"
23 #include "device_profile_log.h"
24 #include "device_profile_storage.h"
25 #include "device_profile_utils.h"
26 #include "ipc_skeleton.h"
27 #include "iprofile_event_notifier.h"
28 #include "parcel_helper.h"
29 #include "distributed_device_profile_service_new.h"
30 #include "distributed_device_profile_errors.h"
31
32 namespace OHOS {
33 namespace DeviceProfile {
34 using namespace OHOS::DistributedDeviceProfile;
35 namespace {
36 const std::string TAG = "DistributedDeviceProfileStub";
37 constexpr uint32_t MAX_EVENT_LEN = 1000000;
38 }
39
DistributedDeviceProfileStub()40 DistributedDeviceProfileStub::DistributedDeviceProfileStub()
41 {
42 funcsMap_[static_cast<uint32_t>(IDeviceProfileInterfaceCode::PUT_DEVICE_PROFILE)] =
43 &DistributedDeviceProfileStub::PutDeviceProfileInner;
44 funcsMap_[static_cast<uint32_t>(IDeviceProfileInterfaceCode::DELETE_DEVICE_PROFILE)] =
45 &DistributedDeviceProfileStub::DeleteDeviceProfileInner;
46 funcsMap_[static_cast<uint32_t>(IDeviceProfileInterfaceCode::GET_DEVICE_PROFILE)] =
47 &DistributedDeviceProfileStub::GetDeviceProfileInner;
48 funcsMap_[static_cast<uint32_t>(IDeviceProfileInterfaceCode::SUBSCRIBE_PROFILE_EVENT)] =
49 &DistributedDeviceProfileStub::SubscribeProfileEventInner;
50 funcsMap_[static_cast<uint32_t>(IDeviceProfileInterfaceCode::UNSUBSCRIBE_PROFILE_EVENT)] =
51 &DistributedDeviceProfileStub::UnsubscribeProfileEventInner;
52 funcsMap_[static_cast<uint32_t>(IDeviceProfileInterfaceCode::SYNC_DEVICE_PROFILE)] =
53 &DistributedDeviceProfileStub::SyncDeviceProfileInner;
54 InitNewIpcInterface();
55 }
56
InitNewIpcInterface()57 void DistributedDeviceProfileStub::InitNewIpcInterface()
58 {
59 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE)] =
60 &DistributedDeviceProfileStub::PutAccessControlProfileInner;
61 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE)] =
62 &DistributedDeviceProfileStub::UpdateAccessControlProfileInner;
63 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE)] =
64 &DistributedDeviceProfileStub::GetTrustDeviceProfileInner;
65 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE)] =
66 &DistributedDeviceProfileStub::GetAllTrustDeviceProfileInner;
67 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE)] =
68 &DistributedDeviceProfileStub::GetAccessControlProfileInner;
69 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE)] =
70 &DistributedDeviceProfileStub::GetAllAccessControlProfileInner;
71 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE)] =
72 &DistributedDeviceProfileStub::DeleteAccessControlProfileInner;
73 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE)] =
74 &DistributedDeviceProfileStub::PutServiceProfileInner;
75 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH)] =
76 &DistributedDeviceProfileStub::PutServiceProfileBatchInner;
77 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE)] =
78 &DistributedDeviceProfileStub::PutCharacteristicProfileInner;
79 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH)] =
80 &DistributedDeviceProfileStub::PutCharacteristicProfileBatchInner;
81 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILE_NEW)] =
82 &DistributedDeviceProfileStub::GetDeviceProfileNewInner;
83 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_PROFILE)] =
84 &DistributedDeviceProfileStub::GetServiceProfileInner;
85 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_CHAR_PROFILE)] =
86 &DistributedDeviceProfileStub::GetCharacteristicProfileInner;
87 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DEL_SERVICE_PROFILE)] =
88 &DistributedDeviceProfileStub::DeleteServiceProfileInner;
89 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DEL_CHAR_PROFILE)] =
90 &DistributedDeviceProfileStub::DeleteCharacteristicProfileInner;
91 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE)] =
92 &DistributedDeviceProfileStub::SubscribeDeviceProfileInner;
93 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE)] =
94 &DistributedDeviceProfileStub::UnSubscribeDeviceProfileInner;
95 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS)] =
96 &DistributedDeviceProfileStub::SendSubscribeInfosInner;
97 funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW)] =
98 &DistributedDeviceProfileStub::SyncDeviceProfileNewInner;
99 InitAclAndSubscribe();
100 }
101
InitAclAndSubscribe()102 void DistributedDeviceProfileStub::InitAclAndSubscribe()
103 {
104 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE));
105 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE));
106 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE));
107 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE));
108 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE));
109 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE));
110 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE));
111 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE));
112 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE));
113 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS));
114 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE));
115 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH));
116 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE));
117 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH));
118 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED));
119 aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED));
120 }
121
NotifyAclEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)122 int32_t DistributedDeviceProfileStub::NotifyAclEventInner(uint32_t code, MessageParcel& data,
123 MessageParcel& reply, MessageOption& option)
124 {
125 switch (code) {
126 case static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE):
127 return PutAccessControlProfileInner(data, reply);
128 case static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE):
129 return UpdateAccessControlProfileInner(data, reply);
130 case static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE):
131 return GetTrustDeviceProfileInner(data, reply);
132 case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE):
133 return GetAllTrustDeviceProfileInner(data, reply);
134 case static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE):
135 return GetAccessControlProfileInner(data, reply);
136 case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE):
137 return GetAllAccessControlProfileInner(data, reply);
138 case static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE):
139 return DeleteAccessControlProfileInner(data, reply);
140 case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE):
141 return SubscribeDeviceProfileInner(data, reply);
142 case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE):
143 return UnSubscribeDeviceProfileInner(data, reply);
144 case static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS):
145 return SendSubscribeInfosInner(data, reply);
146 case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE):
147 return PutServiceProfileInner(data, reply);
148 case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH):
149 return PutServiceProfileBatchInner(data, reply);
150 case static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE):
151 return PutCharacteristicProfileInner(data, reply);
152 case static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH):
153 return PutCharacteristicProfileBatchInner(data, reply);
154 case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED):
155 return SubscribeDeviceProfileInitedInner(data, reply);
156 case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED):
157 return UnSubscribeDeviceProfileInitedInner(data, reply);
158 default:
159 HILOGW("unknown request code, please check, code = %{public}u", code);
160 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
161 }
162 }
163
NotifyOldEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)164 int32_t DistributedDeviceProfileStub::NotifyOldEventInner(uint32_t code, MessageParcel& data,
165 MessageParcel& reply, MessageOption& option)
166 {
167 switch (code) {
168 case static_cast<uint32_t>(IDeviceProfileInterfaceCode::PUT_DEVICE_PROFILE):
169 return PutDeviceProfileInner(data, reply);
170 case static_cast<uint32_t>(IDeviceProfileInterfaceCode::DELETE_DEVICE_PROFILE):
171 return DeleteDeviceProfileInner(data, reply);
172 case static_cast<uint32_t>(IDeviceProfileInterfaceCode::GET_DEVICE_PROFILE):
173 return GetDeviceProfileInner(data, reply);
174 case static_cast<uint32_t>(IDeviceProfileInterfaceCode::SUBSCRIBE_PROFILE_EVENT):
175 return SubscribeProfileEventInner(data, reply);
176 case static_cast<uint32_t>(IDeviceProfileInterfaceCode::UNSUBSCRIBE_PROFILE_EVENT):
177 return UnsubscribeProfileEventInner(data, reply);
178 case static_cast<uint32_t>(IDeviceProfileInterfaceCode::SYNC_DEVICE_PROFILE):
179 return SyncDeviceProfileInner(data, reply);
180 default:
181 return NotifyNewEventInner(code, data, reply, option);
182 }
183 }
184
NotifyNewEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)185 int32_t DistributedDeviceProfileStub::NotifyNewEventInner(uint32_t code, MessageParcel& data,
186 MessageParcel& reply, MessageOption& option)
187 {
188 switch (code) {
189 case static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILE_NEW):
190 return GetDeviceProfileNewInner(data, reply);
191 case static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_PROFILE):
192 return GetServiceProfileInner(data, reply);
193 case static_cast<uint32_t>(DPInterfaceCode::GET_CHAR_PROFILE):
194 return GetCharacteristicProfileInner(data, reply);
195 case static_cast<uint32_t>(DPInterfaceCode::DEL_SERVICE_PROFILE):
196 return DeleteServiceProfileInner(data, reply);
197 case static_cast<uint32_t>(DPInterfaceCode::DEL_CHAR_PROFILE):
198 return DeleteCharacteristicProfileInner(data, reply);
199 case static_cast<uint32_t>(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW):
200 return SyncDeviceProfileNewInner(data, reply);
201 default:
202 HILOGW("unknown request code, please check, code = %{public}u", code);
203 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
204 }
205 }
206
EnforceInterfaceToken(MessageParcel & data)207 bool DistributedDeviceProfileStub::EnforceInterfaceToken(MessageParcel& data)
208 {
209 return data.ReadInterfaceToken() == IDistributedDeviceProfile::GetDescriptor();
210 }
211
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)212 int32_t DistributedDeviceProfileStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
213 MessageParcel& reply, MessageOption& option)
214 {
215 HILOGI("code = %{public}u, CallingPid = %{public}u", code, IPCSkeleton::GetCallingPid());
216 DelayUnloadTask();
217 if (!EnforceInterfaceToken(data)) {
218 HILOGE("check interface token failed");
219 return ERR_DP_INTERFACE_CHECK_FAILED;
220 }
221 if (!AuthorityManager::GetInstance().CheckCallerTrust()) {
222 HILOGE("caller is not trusted");
223 return ERR_DP_PERMISSION_DENIED;
224 }
225 if (std::find(aclAndSubscribeFuncs_.begin(), aclAndSubscribeFuncs_.end(), code) !=
226 aclAndSubscribeFuncs_.end()) {
227 int32_t ret = NotifyAclEventInner(code, data, reply, option);
228 return ret;
229 }
230 if (!DistributedDeviceProfileServiceNew::GetInstance().IsInited()) {
231 HILOGE("DP not finish init");
232 return ERR_DP_LOAD_SERVICE_ERR;
233 }
234 int32_t ret = NotifyOldEventInner(code, data, reply, option);
235 return ret;
236 }
237
PutDeviceProfileInner(MessageParcel & data,MessageParcel & reply)238 int32_t DistributedDeviceProfileStub::PutDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
239 {
240 HILOGI("called");
241 ServiceCharacteristicProfile profile;
242 if (!profile.Unmarshalling(data)) {
243 return ERR_NULL_OBJECT;
244 }
245 return PutDeviceProfile(profile);
246 }
247
GetDeviceProfileInner(MessageParcel & data,MessageParcel & reply)248 int32_t DistributedDeviceProfileStub::GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
249 {
250 HILOGI("called");
251 std::string udid;
252 std::string serviceId;
253 ServiceCharacteristicProfile profile;
254 PARCEL_READ_HELPER(data, String, udid);
255 PARCEL_READ_HELPER(data, String, serviceId);
256 int32_t ret = GetDeviceProfile(udid, serviceId, profile);
257 if (!(reply.WriteInt32(ret) && profile.Marshalling(reply))) {
258 HILOGE("marshall profile failed");
259 return ERR_FLATTEN_OBJECT;
260 }
261 return ERR_NONE;
262 }
263
DeleteDeviceProfileInner(MessageParcel & data,MessageParcel & reply)264 int32_t DistributedDeviceProfileStub::DeleteDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
265 {
266 HILOGI("called");
267 return DeleteDeviceProfile(data.ReadString());
268 }
269
SubscribeProfileEventInner(MessageParcel & data,MessageParcel & reply)270 int32_t DistributedDeviceProfileStub::SubscribeProfileEventInner(MessageParcel& data, MessageParcel& reply)
271 {
272 HILOGI("called");
273 uint32_t numSubscribeInfos = data.ReadUint32();
274 if (numSubscribeInfos == 0 || numSubscribeInfos > MAX_EVENT_LEN) {
275 return ERR_DP_INVALID_PARAMS;
276 }
277
278 std::list<SubscribeInfo> subscribeInfos;
279 for (uint32_t i = 0; i < numSubscribeInfos; i++) {
280 SubscribeInfo subscribeInfo;
281 if (!subscribeInfo.Unmarshalling(data)) {
282 return ERR_NULL_OBJECT;
283 }
284 HILOGD("profile event = %{public}u", static_cast<uint32_t>(subscribeInfo.profileEvent));
285 subscribeInfos.emplace_back(std::move(subscribeInfo));
286 }
287 sptr<IRemoteObject> eventNotifier = data.ReadRemoteObject();
288 std::list<ProfileEvent> failedEvents;
289
290 int32_t errCode = SubscribeProfileEvents(subscribeInfos, eventNotifier, failedEvents);
291 HILOGI("errCode = %{public}d", errCode);
292 if (!reply.WriteInt32(errCode)) {
293 return ERR_FLATTEN_OBJECT;
294 }
295 if ((errCode != ERR_OK) && !DeviceProfileUtils::WriteProfileEvents(failedEvents, reply)) {
296 HILOGE("write profile events failed");
297 return ERR_FLATTEN_OBJECT;
298 }
299 return ERR_NONE;
300 }
301
UnsubscribeProfileEventInner(MessageParcel & data,MessageParcel & reply)302 int32_t DistributedDeviceProfileStub::UnsubscribeProfileEventInner(MessageParcel& data, MessageParcel& reply)
303 {
304 HILOGI("called");
305 uint32_t numEvents = data.ReadUint32();
306 if (numEvents == 0 || numEvents > MAX_EVENT_LEN) {
307 return ERR_DP_INVALID_PARAMS;
308 }
309
310 std::list<ProfileEvent> profileEvents;
311 for (uint32_t i = 0; i < numEvents; i++) {
312 ProfileEvent profileEvent = static_cast<ProfileEvent>(data.ReadUint32());
313 if (profileEvent >= EVENT_PROFILE_END || profileEvent == EVENT_UNKNOWN) {
314 return ERR_DP_INVALID_PARAMS;
315 }
316 profileEvents.emplace_back(profileEvent);
317 }
318 sptr<IRemoteObject> eventNotifier = data.ReadRemoteObject();
319 std::list<ProfileEvent> failedEvents;
320
321 int32_t errCode = UnsubscribeProfileEvents(profileEvents, eventNotifier, failedEvents);
322 HILOGI("errCode = %{public}d", errCode);
323 if (!reply.WriteInt32(errCode)) {
324 return ERR_FLATTEN_OBJECT;
325 }
326 if ((errCode != ERR_OK) && !DeviceProfileUtils::WriteProfileEvents(failedEvents, reply)) {
327 HILOGE("write profile events failed");
328 return ERR_FLATTEN_OBJECT;
329 }
330 return ERR_NONE;
331 }
332
SyncDeviceProfileInner(MessageParcel & data,MessageParcel & reply)333 int32_t DistributedDeviceProfileStub::SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
334 {
335 SyncOptions syncOption;
336 if (!syncOption.Unmarshalling(data)) {
337 HILOGD("unmarshalling failed");
338 return ERR_NULL_OBJECT;
339 }
340
341 sptr<IRemoteObject> eventNotifier = data.ReadRemoteObject();
342 return SyncDeviceProfile(syncOption, eventNotifier);
343 }
344
PutAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)345 int32_t DistributedDeviceProfileStub::PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
346 {
347 HILOGI("called");
348 AccessControlProfile accessControlProfile;
349 if (!accessControlProfile.UnMarshalling(data)) {
350 HILOGE("read parcel fail!");
351 return DP_READ_PARCEL_FAIL;
352 }
353 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutAccessControlProfile(accessControlProfile);
354 if (!reply.WriteInt32(ret)) {
355 HILOGE("Write reply failed");
356 return DP_WRITE_PARCEL_FAIL;
357 }
358 return DP_SUCCESS;
359 }
360
UpdateAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)361 int32_t DistributedDeviceProfileStub::UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
362 {
363 HILOGI("called");
364 AccessControlProfile accessControlProfile;
365 if (!accessControlProfile.UnMarshalling(data)) {
366 HILOGE("read parcel fail!");
367 return DP_READ_PARCEL_FAIL;
368 }
369 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateAccessControlProfile(accessControlProfile);
370 if (!reply.WriteInt32(ret)) {
371 HILOGE("Write reply failed");
372 return ERR_FLATTEN_OBJECT;
373 }
374 return DP_SUCCESS;
375 }
376
GetTrustDeviceProfileInner(MessageParcel & data,MessageParcel & reply)377 int32_t DistributedDeviceProfileStub::GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
378 {
379 HILOGI("called");
380 std::string deviceId;
381 READ_HELPER(data, String, deviceId);
382 TrustDeviceProfile trustDeviceProfile;
383 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetTrustDeviceProfile(deviceId, trustDeviceProfile);
384 if (!reply.WriteInt32(ret)) {
385 HILOGE("Write reply failed");
386 return ERR_FLATTEN_OBJECT;
387 }
388 if (!trustDeviceProfile.Marshalling(reply)) {
389 HILOGE("write parcel fail!");
390 return DP_WRITE_PARCEL_FAIL;
391 }
392 return DP_SUCCESS;
393 }
394
GetAllTrustDeviceProfileInner(MessageParcel & data,MessageParcel & reply)395 int32_t DistributedDeviceProfileStub::GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
396 {
397 HILOGI("called");
398 std::vector<TrustDeviceProfile> trustDeviceProfiles;
399 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllTrustDeviceProfile(trustDeviceProfiles);
400 if (!reply.WriteInt32(ret)) {
401 HILOGE("Write reply failed");
402 return ERR_FLATTEN_OBJECT;
403 }
404 if (!IpcUtils::Marshalling(reply, trustDeviceProfiles)) {
405 HILOGE("read parcel fail!");
406 return DP_READ_PARCEL_FAIL;
407 }
408 return DP_SUCCESS;
409 }
410
GetAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)411 int32_t DistributedDeviceProfileStub::GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
412 {
413 HILOGI("called");
414 std::map<std::string, std::string> queryParams;
415 if (!IpcUtils::UnMarshalling(data, queryParams)) {
416 HILOGE("read parcel fail!");
417 return DP_READ_PARCEL_FAIL;
418 }
419 std::vector<AccessControlProfile> accessControlProfiles;
420 int32_t ret =
421 DistributedDeviceProfileServiceNew::GetInstance().GetAccessControlProfile(queryParams, accessControlProfiles);
422 if (!reply.WriteInt32(ret)) {
423 HILOGE("Write reply failed");
424 return ERR_FLATTEN_OBJECT;
425 }
426 if (!IpcUtils::Marshalling(reply, accessControlProfiles)) {
427 HILOGE("write parcel fail!");
428 return DP_WRITE_PARCEL_FAIL;
429 }
430 return DP_SUCCESS;
431 }
432
GetAllAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)433 int32_t DistributedDeviceProfileStub::GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
434 {
435 HILOGI("called");
436 std::vector<AccessControlProfile> accessControlProfiles;
437 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllAccessControlProfile(accessControlProfiles);
438 if (!reply.WriteInt32(ret)) {
439 HILOGE("Write reply failed");
440 return ERR_FLATTEN_OBJECT;
441 }
442 if (!IpcUtils::Marshalling(reply, accessControlProfiles)) {
443 HILOGE("write parcel fail!");
444 return DP_WRITE_PARCEL_FAIL;
445 }
446 return DP_SUCCESS;
447 }
448
DeleteAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)449 int32_t DistributedDeviceProfileStub::DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
450 {
451 HILOGI("called");
452 int32_t accessControlId;
453 READ_HELPER(data, Int32, accessControlId);
454 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteAccessControlProfile(accessControlId);
455 if (!reply.WriteInt32(ret)) {
456 HILOGE("Write reply failed");
457 return ERR_FLATTEN_OBJECT;
458 }
459 return DP_SUCCESS;
460 }
461
PutServiceProfileInner(MessageParcel & data,MessageParcel & reply)462 int32_t DistributedDeviceProfileStub::PutServiceProfileInner(MessageParcel& data, MessageParcel& reply)
463 {
464 HILOGI("called");
465 ServiceProfile serviceProfile;
466 if (!serviceProfile.UnMarshalling(data)) {
467 HILOGE("read parcel fail!");
468 return DP_READ_PARCEL_FAIL;
469 }
470 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceProfile(serviceProfile);
471 if (!reply.WriteInt32(ret)) {
472 HILOGE("Write reply failed");
473 return ERR_FLATTEN_OBJECT;
474 }
475 return DP_SUCCESS;
476 }
477
PutServiceProfileBatchInner(MessageParcel & data,MessageParcel & reply)478 int32_t DistributedDeviceProfileStub::PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply)
479 {
480 std::vector<ServiceProfile> serviceProfiles;
481 if (!IpcUtils::UnMarshalling(data, serviceProfiles)) {
482 HILOGE("read parcel fail!");
483 return DP_READ_PARCEL_FAIL;
484 }
485 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceProfileBatch(serviceProfiles);
486 if (!reply.WriteInt32(ret)) {
487 HILOGE("Write reply failed");
488 return ERR_FLATTEN_OBJECT;
489 }
490 return DP_SUCCESS;
491 }
492
PutCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)493 int32_t DistributedDeviceProfileStub::PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
494 {
495 CharacteristicProfile charProfile;
496 if (!charProfile.UnMarshalling(data)) {
497 HILOGE("read parcel fail!");
498 return DP_READ_PARCEL_FAIL;
499 }
500 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutCharacteristicProfile(charProfile);
501 if (!reply.WriteInt32(ret)) {
502 HILOGE("Write reply failed");
503 return ERR_FLATTEN_OBJECT;
504 }
505 return DP_SUCCESS;
506 }
507
PutCharacteristicProfileBatchInner(MessageParcel & data,MessageParcel & reply)508 int32_t DistributedDeviceProfileStub::PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply)
509 {
510 std::vector<CharacteristicProfile> charProfiles;
511 if (!IpcUtils::UnMarshalling(data, charProfiles)) {
512 HILOGE("read parcel fail!");
513 return DP_READ_PARCEL_FAIL;
514 }
515 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutCharacteristicProfileBatch(charProfiles);
516 if (!reply.WriteInt32(ret)) {
517 HILOGE("Write reply failed");
518 return ERR_FLATTEN_OBJECT;
519 }
520 return DP_SUCCESS;
521 }
522
GetDeviceProfileNewInner(MessageParcel & data,MessageParcel & reply)523 int32_t DistributedDeviceProfileStub::GetDeviceProfileNewInner(MessageParcel& data, MessageParcel& reply)
524 {
525 std::string deviceId;
526 OHOS::DistributedDeviceProfile::DeviceProfile deviceProfile;
527 READ_HELPER(data, String, deviceId);
528 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetDeviceProfile(deviceId, deviceProfile);
529 if (!reply.WriteInt32(ret)) {
530 HILOGE("Write reply failed");
531 return ERR_FLATTEN_OBJECT;
532 }
533 if (!deviceProfile.Marshalling(reply)) {
534 HILOGE("write parcel fail!");
535 return DP_WRITE_PARCEL_FAIL;
536 }
537 return DP_SUCCESS;
538 }
539
GetServiceProfileInner(MessageParcel & data,MessageParcel & reply)540 int32_t DistributedDeviceProfileStub::GetServiceProfileInner(MessageParcel& data, MessageParcel& reply)
541 {
542 std::string deviceId;
543 std::string serviceName;
544 ServiceProfile serviceProfile;
545 READ_HELPER(data, String, deviceId);
546 READ_HELPER(data, String, serviceName);
547 int32_t ret =
548 DistributedDeviceProfileServiceNew::GetInstance().GetServiceProfile(deviceId, serviceName, serviceProfile);
549 if (!reply.WriteInt32(ret)) {
550 HILOGE("Write reply failed");
551 return ERR_FLATTEN_OBJECT;
552 }
553 if (!serviceProfile.Marshalling(reply)) {
554 HILOGE("write parcel fail!");
555 return DP_WRITE_PARCEL_FAIL;
556 }
557 return DP_SUCCESS;
558 }
559
GetCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)560 int32_t DistributedDeviceProfileStub::GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
561 {
562 std::string deviceId;
563 std::string serviceName;
564 std::string characteristicKey;
565 READ_HELPER(data, String, deviceId);
566 READ_HELPER(data, String, serviceName);
567 READ_HELPER(data, String, characteristicKey);
568 CharacteristicProfile charProfile;
569 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
570 characteristicKey, charProfile);
571 if (!reply.WriteInt32(ret)) {
572 HILOGE("Write reply failed");
573 return ERR_FLATTEN_OBJECT;
574 }
575 if (!charProfile.Marshalling(reply)) {
576 HILOGE("write parcel fail!");
577 return DP_WRITE_PARCEL_FAIL;
578 }
579 return DP_SUCCESS;
580 }
581
DeleteServiceProfileInner(MessageParcel & data,MessageParcel & reply)582 int32_t DistributedDeviceProfileStub::DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply)
583 {
584 std::string deviceId;
585 std::string serviceName;
586 READ_HELPER(data, String, deviceId);
587 READ_HELPER(data, String, serviceName);
588 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteServiceProfile(deviceId, serviceName);
589 if (!reply.WriteInt32(ret)) {
590 HILOGE("Write reply failed");
591 return ERR_FLATTEN_OBJECT;
592 }
593 return DP_SUCCESS;
594 }
595
DeleteCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)596 int32_t DistributedDeviceProfileStub::DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
597 {
598 std::string deviceId;
599 std::string serviceName;
600 std::string characteristicKey;
601 READ_HELPER(data, String, deviceId);
602 READ_HELPER(data, String, serviceName);
603 READ_HELPER(data, String, characteristicKey);
604 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
605 characteristicKey);
606 if (!reply.WriteInt32(ret)) {
607 HILOGE("Write reply failed");
608 return ERR_FLATTEN_OBJECT;
609 }
610 return DP_SUCCESS;
611 }
612
SubscribeDeviceProfileInner(MessageParcel & data,MessageParcel & reply)613 int32_t DistributedDeviceProfileStub::SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
614 {
615 OHOS::DistributedDeviceProfile::SubscribeInfo subscribeInfo;
616 if (!subscribeInfo.UnMarshalling(data)) {
617 HILOGE("read parcel fail!");
618 return DP_READ_PARCEL_FAIL;
619 }
620 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfile(subscribeInfo);
621 if (!reply.WriteInt32(ret)) {
622 HILOGE("Write reply failed");
623 return ERR_FLATTEN_OBJECT;
624 }
625 return DP_SUCCESS;
626 }
627
UnSubscribeDeviceProfileInner(MessageParcel & data,MessageParcel & reply)628 int32_t DistributedDeviceProfileStub::UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
629 {
630 OHOS::DistributedDeviceProfile::SubscribeInfo subscribeInfo;
631 subscribeInfo.UnMarshalling(data);
632 if (!subscribeInfo.UnMarshalling(data)) {
633 HILOGE("read parcel fail!");
634 return DP_READ_PARCEL_FAIL;
635 }
636 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfile(subscribeInfo);
637 if (!reply.WriteInt32(ret)) {
638 HILOGE("Write reply failed");
639 return ERR_FLATTEN_OBJECT;
640 }
641 return DP_SUCCESS;
642 }
643
SyncDeviceProfileNewInner(MessageParcel & data,MessageParcel & reply)644 int32_t DistributedDeviceProfileStub::SyncDeviceProfileNewInner(MessageParcel& data, MessageParcel& reply)
645 {
646 OHOS::DistributedDeviceProfile::DpSyncOptions syncOptions;
647 if (!syncOptions.UnMarshalling(data)) {
648 HILOGE("read parcel fail!");
649 return DP_READ_PARCEL_FAIL;
650 }
651 sptr<IRemoteObject> syncCompletedCallback = data.ReadRemoteObject();
652 int32_t ret =
653 DistributedDeviceProfileServiceNew::GetInstance().SyncDeviceProfile(syncOptions, syncCompletedCallback);
654 if (!reply.WriteInt32(ret)) {
655 HILOGE("Write reply failed");
656 return ERR_FLATTEN_OBJECT;
657 }
658 return DP_SUCCESS;
659 }
660
661
SendSubscribeInfosInner(MessageParcel & data,MessageParcel & reply)662 int32_t DistributedDeviceProfileStub::SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply)
663 {
664 std::map<std::string, OHOS::DistributedDeviceProfile::SubscribeInfo> listenerMap;
665 if (!IpcUtils::UnMarshalling(data, listenerMap)) {
666 HILOGE("read parcel fail!");
667 return DP_READ_PARCEL_FAIL;
668 }
669 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SendSubscribeInfos(listenerMap);
670 if (!reply.WriteInt32(ret)) {
671 HILOGE("Write reply failed");
672 return ERR_FLATTEN_OBJECT;
673 }
674 return DP_SUCCESS;
675 }
676
SubscribeDeviceProfileInitedInner(MessageParcel & data,MessageParcel & reply)677 int32_t DistributedDeviceProfileStub::SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply)
678 {
679 int32_t saId = -1;
680 READ_HELPER(data, Int32, saId);
681 sptr<IRemoteObject> dpInitedCallback = data.ReadRemoteObject();
682 if (dpInitedCallback == nullptr) {
683 HILOGE("read remoteObject failed!");
684 return ERR_FLATTEN_OBJECT;
685 }
686 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfileInited(saId,
687 dpInitedCallback);
688 if (!reply.WriteInt32(ret)) {
689 HILOGE("Write reply failed");
690 return ERR_FLATTEN_OBJECT;
691 }
692 return DP_SUCCESS;
693 }
694
UnSubscribeDeviceProfileInitedInner(MessageParcel & data,MessageParcel & reply)695 int32_t DistributedDeviceProfileStub::UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply)
696 {
697 int32_t saId = -1;
698 READ_HELPER(data, Int32, saId);
699 int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfileInited(saId);
700 if (!reply.WriteInt32(ret)) {
701 HILOGE("Write reply failed");
702 return ERR_FLATTEN_OBJECT;
703 }
704 return DP_SUCCESS;
705 }
706 } // namespace DeviceProfile
707 } // namespace OHOS
708