• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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     InitNewRdbIpcInterface();
55     InitNewKVIpcInterface();
56     InitAclAndSubscribe();
57 }
58 
InitAclAndSubscribe()59 void DistributedDeviceProfileStub::InitAclAndSubscribe()
60 {
61     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE));
62     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE));
63     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE));
64     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE));
65     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE));
66     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE));
67     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE));
68     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE));
69     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE));
70     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS));
71     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE));
72     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH));
73     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE));
74     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH));
75     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED));
76     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED));
77     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES));
78     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH));
79     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILES));
80     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH));
81     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_ICON_INFOS));
82     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH));
83     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH));
84     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::PUT_SESSION_KEY));
85     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::GET_SESSION_KEY));
86     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::UPDATE_SESSION_KEY));
87     aclAndSubscribeFuncs_.emplace_back(static_cast<uint32_t>(DPInterfaceCode::DELETE_SESSION_KEY));
88 }
89 
NotifyAclEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)90 int32_t DistributedDeviceProfileStub::NotifyAclEventInner(uint32_t code, MessageParcel& data,
91     MessageParcel& reply, MessageOption& option)
92 {
93     switch (code) {
94         case static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE):
95             return PutAccessControlProfileInner(data, reply);
96         case static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE):
97             return UpdateAccessControlProfileInner(data, reply);
98         case static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE):
99             return GetTrustDeviceProfileInner(data, reply);
100         case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE):
101             return GetAllTrustDeviceProfileInner(data, reply);
102         case static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE):
103             return GetAccessControlProfileInner(data, reply);
104         case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE):
105             return GetAllAccessControlProfileInner(data, reply);
106         case static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE):
107             return DeleteAccessControlProfileInner(data, reply);
108         case static_cast<uint32_t>(DPInterfaceCode::PUT_SESSION_KEY):
109             return PutSessionKeyInner(data, reply);
110         case static_cast<uint32_t>(DPInterfaceCode::GET_SESSION_KEY):
111             return GetSessionKeyInner(data, reply);
112         case static_cast<uint32_t>(DPInterfaceCode::UPDATE_SESSION_KEY):
113             return UpdateSessionKeyInner(data, reply);
114         case static_cast<uint32_t>(DPInterfaceCode::DELETE_SESSION_KEY):
115             return DeleteSessionKeyInner(data, reply);
116         default:
117             return NotifyProfileDataEventInner(code, data, reply, option);
118     }
119 }
120 
NotifyProfileDataEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)121 int32_t DistributedDeviceProfileStub::NotifyProfileDataEventInner(uint32_t code, MessageParcel& data,
122     MessageParcel& reply, MessageOption& option)
123 {
124     switch (code) {
125         case static_cast<uint32_t>(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH):
126             return PutDeviceProfileBatchInner(data, reply);
127         case static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILES):
128             return GetDeviceProfilesInner(data, reply);
129         case static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_ICON_INFOS):
130             return GetDeviceIconInfosInner(data, reply);
131         case static_cast<uint32_t>(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH):
132             return PutDeviceIconInfoBatchInner(data, reply);
133         case static_cast<uint32_t>(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH):
134             return PutProductInfoBatchInner(data, reply);
135         case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE):
136             return SubscribeDeviceProfileInner(data, reply);
137         case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE):
138             return UnSubscribeDeviceProfileInner(data, reply);
139         case static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS):
140             return SendSubscribeInfosInner(data, reply);
141         case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE):
142             return PutServiceProfileInner(data, reply);
143         case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH):
144             return PutServiceProfileBatchInner(data, reply);
145         case static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE):
146             return PutCharacteristicProfileInner(data, reply);
147         case static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH):
148             return PutCharacteristicProfileBatchInner(data, reply);
149         case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED):
150             return SubscribeDeviceProfileInitedInner(data, reply);
151         case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED):
152             return UnSubscribeDeviceProfileInitedInner(data, reply);
153         case static_cast<uint32_t>(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES):
154             return PutAllTrustedDevicesInner(data, reply);
155         case static_cast<uint32_t>(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH):
156             return DeleteDeviceProfileBatchInner(data, reply);
157         default:
158             HILOGW("unknown request code, please check, code = %{public}u", code);
159             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
160     }
161 }
162 
NotifyOldEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)163 int32_t DistributedDeviceProfileStub::NotifyOldEventInner(uint32_t code, MessageParcel& data,
164     MessageParcel& reply, MessageOption& option)
165 {
166     switch (code) {
167         case static_cast<uint32_t>(IDeviceProfileInterfaceCode::PUT_DEVICE_PROFILE):
168             return PutDeviceProfileInner(data, reply);
169         case static_cast<uint32_t>(IDeviceProfileInterfaceCode::DELETE_DEVICE_PROFILE):
170             return DeleteDeviceProfileInner(data, reply);
171         case static_cast<uint32_t>(IDeviceProfileInterfaceCode::GET_DEVICE_PROFILE):
172             return GetDeviceProfileInner(data, reply);
173         case static_cast<uint32_t>(IDeviceProfileInterfaceCode::SUBSCRIBE_PROFILE_EVENT):
174             return SubscribeProfileEventInner(data, reply);
175         case static_cast<uint32_t>(IDeviceProfileInterfaceCode::UNSUBSCRIBE_PROFILE_EVENT):
176             return UnsubscribeProfileEventInner(data, reply);
177         case static_cast<uint32_t>(IDeviceProfileInterfaceCode::SYNC_DEVICE_PROFILE):
178             return SyncDeviceProfileInner(data, reply);
179         default:
180             return NotifyNewEventInner(code, data, reply, option);
181     }
182 }
183 
NotifyNewEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)184 int32_t DistributedDeviceProfileStub::NotifyNewEventInner(uint32_t code, MessageParcel& data,
185     MessageParcel& reply, MessageOption& option)
186 {
187     switch (code) {
188         case static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILE_NEW):
189             return GetDeviceProfileNewInner(data, reply);
190         case static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_PROFILE):
191             return GetServiceProfileInner(data, reply);
192         case static_cast<uint32_t>(DPInterfaceCode::GET_CHAR_PROFILE):
193             return GetCharacteristicProfileInner(data, reply);
194         case static_cast<uint32_t>(DPInterfaceCode::DEL_SERVICE_PROFILE):
195             return DeleteServiceProfileInner(data, reply);
196         case static_cast<uint32_t>(DPInterfaceCode::DEL_CHAR_PROFILE):
197             return DeleteCharacteristicProfileInner(data, reply);
198         case static_cast<uint32_t>(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW):
199             return SyncDeviceProfileNewInner(data, reply);
200         case static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE):
201             return PutServiceInfoProfileInner(data, reply);
202         case static_cast<uint32_t>(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE):
203             return DeleteServiceInfoProfileInner(data, reply);
204         case static_cast<uint32_t>(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE):
205             return UpdateServiceInfoProfileInner(data, reply);
206         case static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY):
207             return GetServiceInfoProfileByUniqueKeyInner(data, reply);
208         case static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID):
209             return GetServiceInfoProfileListByTokenIdInner(data, reply);
210         case static_cast<uint32_t>(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST):
211             return GetAllServiceInfoProfileListInner(data, reply);
212         case static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME):
213             return GetServiceInfoProfileListByBundleNameInner(data, reply);
214         case static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID):
215             return SubscribePinCodeInvalidInner(data, reply);
216         case static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID):
217             return UnSubscribePinCodeInvalidInner(data, reply);
218         default:
219             return NotifyLocalServiceEventInner(code, data, reply, option);
220     }
221 }
222 
NotifyLocalServiceEventInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)223 int32_t DistributedDeviceProfileStub::NotifyLocalServiceEventInner(uint32_t code, MessageParcel& data,
224     MessageParcel& reply, MessageOption& option)
225 {
226     switch (code) {
227         case static_cast<uint32_t>(DPInterfaceCode::PUT_LOCAL_SERVICE_INFO):
228             return PutLocalServiceInfoInner(data, reply);
229         case static_cast<uint32_t>(DPInterfaceCode::UPDATA_LOCAL_SERVICE_INFO):
230             return UpdateLocalServiceInfoInner(data, reply);
231         case static_cast<uint32_t>(DPInterfaceCode::GET_LOCAL_SERVICE_INFO_BY_BINDLE_AND_PINTYPE):
232             return GetLocalServiceInfoByBundleAndPinTypeInner(data, reply);
233         case static_cast<uint32_t>(DPInterfaceCode::DELETE_LOCAL_SERVICE_INFO):
234             return DeleteLocalServiceInfoInner(data, reply);
235         default:
236             HILOGW("unknown request code, please check, code = %{public}u", code);
237             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
238     }
239 }
240 
EnforceInterfaceToken(MessageParcel & data)241 bool DistributedDeviceProfileStub::EnforceInterfaceToken(MessageParcel& data)
242 {
243     return data.ReadInterfaceToken() == IDistributedDeviceProfile::GetDescriptor();
244 }
245 
InitNewRdbIpcInterface()246 void DistributedDeviceProfileStub::InitNewRdbIpcInterface()
247 {
248     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE)] =
249         &DistributedDeviceProfileStub::PutAccessControlProfileInner;
250     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE)] =
251         &DistributedDeviceProfileStub::UpdateAccessControlProfileInner;
252     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE)] =
253         &DistributedDeviceProfileStub::GetTrustDeviceProfileInner;
254     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE)] =
255         &DistributedDeviceProfileStub::GetAllTrustDeviceProfileInner;
256     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE)] =
257         &DistributedDeviceProfileStub::GetAccessControlProfileInner;
258     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE)] =
259         &DistributedDeviceProfileStub::GetAllAccessControlProfileInner;
260     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE)] =
261         &DistributedDeviceProfileStub::DeleteAccessControlProfileInner;
262     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_SESSION_KEY)] =
263         &DistributedDeviceProfileStub::PutSessionKeyInner;
264     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_SESSION_KEY)] =
265         &DistributedDeviceProfileStub::GetSessionKeyInner;
266     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::UPDATE_SESSION_KEY)] =
267         &DistributedDeviceProfileStub::UpdateSessionKeyInner;
268     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DELETE_SESSION_KEY)] =
269         &DistributedDeviceProfileStub::DeleteSessionKeyInner;
270 }
271 
InitNewKVIpcInterface()272 void DistributedDeviceProfileStub::InitNewKVIpcInterface()
273 {
274     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE)] =
275         &DistributedDeviceProfileStub::PutServiceProfileInner;
276     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH)] =
277         &DistributedDeviceProfileStub::PutServiceProfileBatchInner;
278     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE)] =
279         &DistributedDeviceProfileStub::PutCharacteristicProfileInner;
280     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH)] =
281         &DistributedDeviceProfileStub::PutCharacteristicProfileBatchInner;
282     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILE_NEW)] =
283         &DistributedDeviceProfileStub::GetDeviceProfileNewInner;
284     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_PROFILE)] =
285         &DistributedDeviceProfileStub::GetServiceProfileInner;
286     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::GET_CHAR_PROFILE)] =
287         &DistributedDeviceProfileStub::GetCharacteristicProfileInner;
288     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DEL_SERVICE_PROFILE)] =
289         &DistributedDeviceProfileStub::DeleteServiceProfileInner;
290     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::DEL_CHAR_PROFILE)] =
291         &DistributedDeviceProfileStub::DeleteCharacteristicProfileInner;
292     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE)] =
293         &DistributedDeviceProfileStub::SubscribeDeviceProfileInner;
294     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE)] =
295         &DistributedDeviceProfileStub::UnSubscribeDeviceProfileInner;
296     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS)] =
297         &DistributedDeviceProfileStub::SendSubscribeInfosInner;
298     funcsMap_[static_cast<uint32_t>(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW)] =
299         &DistributedDeviceProfileStub::SyncDeviceProfileNewInner;
300 }
301 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)302 int32_t DistributedDeviceProfileStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
303     MessageParcel& reply, MessageOption& option)
304 {
305     HILOGI("code = %{public}u, CallingPid = %{public}u", code, IPCSkeleton::GetCallingPid());
306     DelayUnloadTask();
307     if (!EnforceInterfaceToken(data)) {
308         HILOGE("check interface token failed");
309         return ERR_DP_INTERFACE_CHECK_FAILED;
310     }
311     if (!AuthorityManager::GetInstance().CheckCallerTrust()) {
312         HILOGE("caller is not trusted");
313         return ERR_DP_PERMISSION_DENIED;
314     }
315     if (std::find(aclAndSubscribeFuncs_.begin(), aclAndSubscribeFuncs_.end(), code) !=
316         aclAndSubscribeFuncs_.end()) {
317         int32_t ret = NotifyAclEventInner(code, data, reply, option);
318         return ret;
319     }
320     if (!DistributedDeviceProfileServiceNew::GetInstance().IsInited()) {
321         HILOGE("DP not finish init");
322         return ERR_DP_LOAD_SERVICE_ERR;
323     }
324     int32_t ret = NotifyOldEventInner(code, data, reply, option);
325     return ret;
326 }
327 
PutDeviceProfileInner(MessageParcel & data,MessageParcel & reply)328 int32_t DistributedDeviceProfileStub::PutDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
329 {
330     HILOGI("called");
331     ServiceCharacteristicProfile profile;
332     if (!profile.Unmarshalling(data)) {
333         return ERR_NULL_OBJECT;
334     }
335     return PutDeviceProfile(profile);
336 }
337 
GetDeviceProfileInner(MessageParcel & data,MessageParcel & reply)338 int32_t DistributedDeviceProfileStub::GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
339 {
340     HILOGI("called");
341     std::string udid;
342     std::string serviceId;
343     ServiceCharacteristicProfile profile;
344     PARCEL_READ_HELPER(data, String, udid);
345     PARCEL_READ_HELPER(data, String, serviceId);
346     int32_t ret = GetDeviceProfile(udid, serviceId, profile);
347     if (!reply.WriteInt32(ret)) {
348         HILOGE("WriteInt32 failed");
349         return ERR_FLATTEN_OBJECT;
350     }
351     if (!profile.Marshalling(reply)) {
352         HILOGE("marshall profile failed");
353         return ERR_FLATTEN_OBJECT;
354     }
355     return ERR_NONE;
356 }
357 
DeleteDeviceProfileInner(MessageParcel & data,MessageParcel & reply)358 int32_t DistributedDeviceProfileStub::DeleteDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
359 {
360     HILOGI("called");
361     return DeleteDeviceProfile(data.ReadString());
362 }
363 
SubscribeProfileEventInner(MessageParcel & data,MessageParcel & reply)364 int32_t DistributedDeviceProfileStub::SubscribeProfileEventInner(MessageParcel& data, MessageParcel& reply)
365 {
366     HILOGI("called");
367     uint32_t numSubscribeInfos = data.ReadUint32();
368     if (numSubscribeInfos == 0 || numSubscribeInfos > MAX_EVENT_LEN) {
369         return ERR_DP_INVALID_PARAMS;
370     }
371 
372     std::list<SubscribeInfo> subscribeInfos;
373     for (uint32_t i = 0; i < numSubscribeInfos; i++) {
374         SubscribeInfo subscribeInfo;
375         if (!subscribeInfo.Unmarshalling(data)) {
376             return ERR_NULL_OBJECT;
377         }
378         HILOGD("profile event = %{public}u", static_cast<uint32_t>(subscribeInfo.profileEvent));
379         subscribeInfos.emplace_back(std::move(subscribeInfo));
380     }
381     sptr<IRemoteObject> eventNotifier = data.ReadRemoteObject();
382     std::list<ProfileEvent> failedEvents;
383 
384     int32_t errCode = SubscribeProfileEvents(subscribeInfos, eventNotifier, failedEvents);
385     HILOGI("errCode = %{public}d", errCode);
386     if (!reply.WriteInt32(errCode)) {
387         return ERR_FLATTEN_OBJECT;
388     }
389     if ((errCode != ERR_OK) && !DeviceProfileUtils::WriteProfileEvents(failedEvents, reply)) {
390         HILOGE("write profile events failed");
391         return ERR_FLATTEN_OBJECT;
392     }
393     return ERR_NONE;
394 }
395 
UnsubscribeProfileEventInner(MessageParcel & data,MessageParcel & reply)396 int32_t DistributedDeviceProfileStub::UnsubscribeProfileEventInner(MessageParcel& data, MessageParcel& reply)
397 {
398     HILOGI("called");
399     uint32_t numEvents = data.ReadUint32();
400     if (numEvents == 0 || numEvents > MAX_EVENT_LEN) {
401         return ERR_DP_INVALID_PARAMS;
402     }
403 
404     std::list<ProfileEvent> profileEvents;
405     for (uint32_t i = 0; i < numEvents; i++) {
406         ProfileEvent profileEvent = static_cast<ProfileEvent>(data.ReadUint32());
407         if (profileEvent >= EVENT_PROFILE_END || profileEvent == EVENT_UNKNOWN) {
408             return ERR_DP_INVALID_PARAMS;
409         }
410         profileEvents.emplace_back(profileEvent);
411     }
412     sptr<IRemoteObject> eventNotifier = data.ReadRemoteObject();
413     std::list<ProfileEvent> failedEvents;
414 
415     int32_t errCode = UnsubscribeProfileEvents(profileEvents, eventNotifier, failedEvents);
416     HILOGI("errCode = %{public}d", errCode);
417     if (!reply.WriteInt32(errCode)) {
418         return ERR_FLATTEN_OBJECT;
419     }
420     if ((errCode != ERR_OK) && !DeviceProfileUtils::WriteProfileEvents(failedEvents, reply)) {
421         HILOGE("write profile events failed");
422         return ERR_FLATTEN_OBJECT;
423     }
424     return ERR_NONE;
425 }
426 
SyncDeviceProfileInner(MessageParcel & data,MessageParcel & reply)427 int32_t DistributedDeviceProfileStub::SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
428 {
429     SyncOptions syncOption;
430     if (!syncOption.Unmarshalling(data)) {
431         HILOGD("unmarshalling failed");
432         return ERR_NULL_OBJECT;
433     }
434 
435     sptr<IRemoteObject> eventNotifier = data.ReadRemoteObject();
436     return SyncDeviceProfile(syncOption, eventNotifier);
437 }
438 
PutAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)439 int32_t DistributedDeviceProfileStub::PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
440 {
441     HILOGI("called");
442     AccessControlProfile accessControlProfile;
443     if (!accessControlProfile.UnMarshalling(data)) {
444         HILOGE("read parcel fail!");
445         return DP_READ_PARCEL_FAIL;
446     }
447     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutAccessControlProfile(accessControlProfile);
448     if (!reply.WriteInt32(ret)) {
449         HILOGE("Write reply failed");
450         return DP_WRITE_PARCEL_FAIL;
451     }
452     return DP_SUCCESS;
453 }
454 
UpdateAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)455 int32_t DistributedDeviceProfileStub::UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
456 {
457     HILOGI("called");
458     AccessControlProfile accessControlProfile;
459     if (!accessControlProfile.UnMarshalling(data)) {
460         HILOGE("read parcel fail!");
461         return DP_READ_PARCEL_FAIL;
462     }
463     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateAccessControlProfile(accessControlProfile);
464     if (!reply.WriteInt32(ret)) {
465         HILOGE("Write reply failed");
466         return ERR_FLATTEN_OBJECT;
467     }
468     return DP_SUCCESS;
469 }
470 
GetTrustDeviceProfileInner(MessageParcel & data,MessageParcel & reply)471 int32_t DistributedDeviceProfileStub::GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
472 {
473     HILOGI("called");
474     std::string deviceId;
475     READ_HELPER(data, String, deviceId);
476     TrustDeviceProfile trustDeviceProfile;
477     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetTrustDeviceProfile(deviceId, trustDeviceProfile);
478     if (!reply.WriteInt32(ret)) {
479         HILOGE("Write reply failed");
480         return ERR_FLATTEN_OBJECT;
481     }
482     if (!trustDeviceProfile.Marshalling(reply)) {
483         HILOGE("write parcel fail!");
484         return DP_WRITE_PARCEL_FAIL;
485     }
486     return DP_SUCCESS;
487 }
488 
PutProductInfoBatchInner(MessageParcel & data,MessageParcel & reply)489 int32_t DistributedDeviceProfileStub::PutProductInfoBatchInner(MessageParcel& data, MessageParcel& reply)
490 {
491     std::vector<ProductInfo> productInfos;
492     if (!IpcUtils::UnMarshalling(data, productInfos)) {
493         HILOGE("read parcel fail!");
494         return DP_READ_PARCEL_FAIL;
495     }
496     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutProductInfoBatch(productInfos);
497     if (!reply.WriteInt32(ret)) {
498         HILOGE("Write reply failed");
499         return ERR_FLATTEN_OBJECT;
500     }
501     return DP_SUCCESS;
502 }
503 
PutDeviceIconInfoBatchInner(MessageParcel & data,MessageParcel & reply)504 int32_t DistributedDeviceProfileStub::PutDeviceIconInfoBatchInner(MessageParcel& data, MessageParcel& reply)
505 {
506     std::vector<DeviceIconInfo> deviceIconInfos;
507     if (!IpcUtils::UnMarshalling(data, deviceIconInfos)) {
508         HILOGE("read parcel fail!");
509         return DP_READ_PARCEL_FAIL;
510     }
511     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutDeviceIconInfoBatch(deviceIconInfos);
512     if (!reply.WriteInt32(ret)) {
513         HILOGE("Write reply failed");
514         return ERR_FLATTEN_OBJECT;
515     }
516     return DP_SUCCESS;
517 }
518 
GetDeviceIconInfosInner(MessageParcel & data,MessageParcel & reply)519 int32_t DistributedDeviceProfileStub::GetDeviceIconInfosInner(MessageParcel& data, MessageParcel& reply)
520 {
521     DeviceIconInfoFilterOptions filterOptions;
522     std::vector<DeviceIconInfo> deviceIconInfos;
523     if (!filterOptions.UnMarshalling(data)) {
524         HILOGE("read parcel fail!");
525         return DP_READ_PARCEL_FAIL;
526     }
527     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetDeviceIconInfos(filterOptions,
528         deviceIconInfos);
529     if (!reply.WriteInt32(ret)) {
530         HILOGE("Write reply failed");
531         return ERR_FLATTEN_OBJECT;
532     }
533     if (!IpcUtils::Marshalling(reply, deviceIconInfos)) {
534         HILOGE("Write parcel fail!");
535         return DP_READ_PARCEL_FAIL;
536     }
537     return DP_SUCCESS;
538 }
539 
PutServiceInfoProfileInner(MessageParcel & data,MessageParcel & reply)540 int32_t DistributedDeviceProfileStub::PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply)
541 {
542     HILOGI("called");
543     ServiceInfoProfile serviceInfoProfile;
544     if (!serviceInfoProfile.UnMarshalling(data)) {
545         HILOGE("read parcel fail!");
546         return DP_READ_PARCEL_FAIL;
547     }
548     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceInfoProfile(serviceInfoProfile);
549     if (!reply.WriteInt32(ret)) {
550         HILOGE("Write reply failed");
551         return DP_WRITE_PARCEL_FAIL;
552     }
553     return DP_SUCCESS;
554 }
555 
DeleteServiceInfoProfileInner(MessageParcel & data,MessageParcel & reply)556 int32_t DistributedDeviceProfileStub::DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply)
557 {
558     HILOGI("called");
559     ServiceInfoUniqueKey key;
560     if (!key.UnMarshalling(data)) {
561         HILOGE("read parcel fail!");
562         return DP_READ_PARCEL_FAIL;
563     }
564     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteServiceInfoProfile(key);
565     if (!reply.WriteInt32(ret)) {
566         HILOGE("Write reply failed");
567         return DP_WRITE_PARCEL_FAIL;
568     }
569     return DP_SUCCESS;
570 }
571 
UpdateServiceInfoProfileInner(MessageParcel & data,MessageParcel & reply)572 int32_t DistributedDeviceProfileStub::UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply)
573 {
574     HILOGI("called");
575     ServiceInfoProfile serviceInfoProfile;
576     if (!serviceInfoProfile.UnMarshalling(data)) {
577         HILOGE("read parcel fail!");
578         return DP_READ_PARCEL_FAIL;
579     }
580     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile);
581     if (!reply.WriteInt32(ret)) {
582         HILOGE("Write reply failed");
583         return DP_WRITE_PARCEL_FAIL;
584     }
585     return DP_SUCCESS;
586 }
587 
GetServiceInfoProfileByUniqueKeyInner(MessageParcel & data,MessageParcel & reply)588 int32_t DistributedDeviceProfileStub::GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, MessageParcel& reply)
589 {
590     ServiceInfoUniqueKey key;
591     ServiceInfoProfile serviceInfoProfile;
592     if (!key.UnMarshalling(data)) {
593         HILOGE("read parcel fail!");
594         return DP_READ_PARCEL_FAIL;
595     }
596     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileByUniqueKey(key,
597         serviceInfoProfile);
598     if (!reply.WriteInt32(ret)) {
599         HILOGE("Write reply failed");
600         return ERR_FLATTEN_OBJECT;
601     }
602     if (!serviceInfoProfile.Marshalling(reply)) {
603         HILOGE("write parcel fail!");
604         return DP_READ_PARCEL_FAIL;
605     }
606     return DP_SUCCESS;
607 }
608 
GetServiceInfoProfileListByTokenIdInner(MessageParcel & data,MessageParcel & reply)609 int32_t DistributedDeviceProfileStub::GetServiceInfoProfileListByTokenIdInner(MessageParcel& data,
610     MessageParcel& reply)
611 {
612     ServiceInfoUniqueKey key;
613     std::vector<ServiceInfoProfile> serviceInfoProfiles;
614     if (!key.UnMarshalling(data)) {
615         HILOGE("read parcel fail!");
616         return DP_READ_PARCEL_FAIL;
617     }
618     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileListByTokenId(key,
619         serviceInfoProfiles);
620     if (!reply.WriteInt32(ret)) {
621         HILOGE("Write reply failed");
622         return ERR_FLATTEN_OBJECT;
623     }
624 
625     if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) {
626         HILOGE("Write parcel fail!");
627         return DP_READ_PARCEL_FAIL;
628     }
629     return DP_SUCCESS;
630 }
631 
GetAllServiceInfoProfileListInner(MessageParcel & data,MessageParcel & reply)632 int32_t DistributedDeviceProfileStub::GetAllServiceInfoProfileListInner(MessageParcel& data,
633     MessageParcel& reply)
634 {
635     std::vector<ServiceInfoProfile> serviceInfoProfiles;
636     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles);
637     if (!reply.WriteInt32(ret)) {
638         HILOGE("Write reply failed");
639         return ERR_FLATTEN_OBJECT;
640     }
641 
642     if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) {
643         HILOGE("Write parcel fail!");
644         return DP_READ_PARCEL_FAIL;
645     }
646     return DP_SUCCESS;
647 }
648 
GetServiceInfoProfileListByBundleNameInner(MessageParcel & data,MessageParcel & reply)649 int32_t DistributedDeviceProfileStub::GetServiceInfoProfileListByBundleNameInner(MessageParcel& data,
650     MessageParcel& reply)
651 {
652     ServiceInfoUniqueKey key;
653     std::vector<ServiceInfoProfile> serviceInfoProfiles;
654     if (!key.UnMarshalling(data)) {
655         HILOGE("read parcel fail!");
656         return DP_READ_PARCEL_FAIL;
657     }
658     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileListByBundleName(key,
659         serviceInfoProfiles);
660     if (!reply.WriteInt32(ret)) {
661         HILOGE("Write reply failed");
662         return ERR_FLATTEN_OBJECT;
663     }
664 
665     if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) {
666         HILOGE("Write parcel fail!");
667         return DP_READ_PARCEL_FAIL;
668     }
669     return DP_SUCCESS;
670 }
671 
DeleteDeviceProfileBatchInner(MessageParcel & data,MessageParcel & reply)672 int32_t DistributedDeviceProfileStub::DeleteDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply)
673 {
674     std::vector<OHOS::DistributedDeviceProfile::DeviceProfile> deviceProfiles;
675     if (!IpcUtils::UnMarshalling(data, deviceProfiles)) {
676         HILOGE("Write parcel fail!");
677         return DP_READ_PARCEL_FAIL;
678     }
679     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteDeviceProfileBatch(deviceProfiles);
680     if (!reply.WriteInt32(ret)) {
681         HILOGE("Write reply failed");
682         return ERR_FLATTEN_OBJECT;
683     }
684     return DP_SUCCESS;
685 }
686 
GetAllTrustDeviceProfileInner(MessageParcel & data,MessageParcel & reply)687 int32_t DistributedDeviceProfileStub::GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
688 {
689     HILOGI("called");
690     std::vector<TrustDeviceProfile> trustDeviceProfiles;
691     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllTrustDeviceProfile(trustDeviceProfiles);
692     if (!reply.WriteInt32(ret)) {
693         HILOGE("Write reply failed");
694         return ERR_FLATTEN_OBJECT;
695     }
696     if (!IpcUtils::Marshalling(reply, trustDeviceProfiles)) {
697         HILOGE("read parcel fail!");
698         return DP_READ_PARCEL_FAIL;
699     }
700     return DP_SUCCESS;
701 }
702 
GetAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)703 int32_t DistributedDeviceProfileStub::GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
704 {
705     HILOGI("called");
706     std::map<std::string, std::string> queryParams;
707     if (!IpcUtils::UnMarshalling(data, queryParams)) {
708         HILOGE("read parcel fail!");
709         return DP_READ_PARCEL_FAIL;
710     }
711     std::vector<AccessControlProfile> accessControlProfiles;
712     int32_t ret =
713         DistributedDeviceProfileServiceNew::GetInstance().GetAccessControlProfile(queryParams, accessControlProfiles);
714     if (!reply.WriteInt32(ret)) {
715         HILOGE("Write reply failed");
716         return ERR_FLATTEN_OBJECT;
717     }
718     if (!IpcUtils::Marshalling(reply, accessControlProfiles)) {
719         HILOGE("write parcel fail!");
720         return DP_WRITE_PARCEL_FAIL;
721     }
722     return DP_SUCCESS;
723 }
724 
GetAllAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)725 int32_t DistributedDeviceProfileStub::GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
726 {
727     HILOGI("called");
728     std::vector<AccessControlProfile> accessControlProfiles;
729     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllAccessControlProfile(accessControlProfiles);
730     if (!reply.WriteInt32(ret)) {
731         HILOGE("Write reply failed");
732         return ERR_FLATTEN_OBJECT;
733     }
734     if (!IpcUtils::Marshalling(reply, accessControlProfiles)) {
735         HILOGE("write parcel fail!");
736         return DP_WRITE_PARCEL_FAIL;
737     }
738     return DP_SUCCESS;
739 }
740 
DeleteAccessControlProfileInner(MessageParcel & data,MessageParcel & reply)741 int32_t DistributedDeviceProfileStub::DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply)
742 {
743     HILOGI("called");
744     int32_t accessControlId;
745     READ_HELPER(data, Int32, accessControlId);
746     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteAccessControlProfile(accessControlId);
747     if (!reply.WriteInt32(ret)) {
748         HILOGE("Write reply failed");
749         return ERR_FLATTEN_OBJECT;
750     }
751     return DP_SUCCESS;
752 }
753 
PutSessionKeyInner(MessageParcel & data,MessageParcel & reply)754 int32_t DistributedDeviceProfileStub::PutSessionKeyInner(MessageParcel& data, MessageParcel& reply)
755 {
756     HILOGI("called");
757     uint32_t userId = 0;
758     std::vector<uint8_t> sessionKey;
759     int32_t sessionKeyId = 0;
760     READ_HELPER(data, Uint32, userId);
761     if (!IpcUtils::UnMarshalling(data, sessionKey)) {
762         HILOGE("dp ipc write parcel fail");
763         return DP_WRITE_PARCEL_FAIL;
764     }
765     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutSessionKey(userId, sessionKey, sessionKeyId);
766     if (!reply.WriteInt32(ret)) {
767         HILOGE("Write reply failed");
768         return DP_WRITE_PARCEL_FAIL;
769     }
770     WRITE_HELPER(reply, Int32, sessionKeyId);
771     return DP_SUCCESS;
772 }
773 
GetSessionKeyInner(MessageParcel & data,MessageParcel & reply)774 int32_t DistributedDeviceProfileStub::GetSessionKeyInner(MessageParcel& data, MessageParcel& reply)
775 {
776     HILOGI("called");
777     uint32_t userId = 0;
778     int32_t sessionKeyId = 0;
779     std::vector<uint8_t> sessionKey;
780     READ_HELPER(data, Uint32, userId);
781     READ_HELPER(data, Int32, sessionKeyId);
782     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetSessionKey(userId, sessionKeyId, sessionKey);
783     if (!reply.WriteInt32(ret)) {
784         HILOGE("Write reply failed");
785         return DP_WRITE_PARCEL_FAIL;
786     }
787     if (!IpcUtils::Marshalling(reply, sessionKey)) {
788         HILOGE("dp ipc write parcel fail");
789         return DP_WRITE_PARCEL_FAIL;
790     }
791     return DP_SUCCESS;
792 }
793 
UpdateSessionKeyInner(MessageParcel & data,MessageParcel & reply)794 int32_t DistributedDeviceProfileStub::UpdateSessionKeyInner(MessageParcel& data, MessageParcel& reply)
795 {
796     HILOGI("called");
797     uint32_t userId = 0;
798     std::vector<uint8_t> sessionKey;
799     int32_t sessionKeyId = 0;
800     READ_HELPER(data, Uint32, userId);
801     READ_HELPER(data, Int32, sessionKeyId);
802     if (!IpcUtils::UnMarshalling(data, sessionKey)) {
803         HILOGE("dp ipc write parcel fail");
804         return DP_WRITE_PARCEL_FAIL;
805     }
806     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateSessionKey(userId, sessionKeyId, sessionKey);
807     if (!reply.WriteInt32(ret)) {
808         HILOGE("Write reply failed");
809         return DP_WRITE_PARCEL_FAIL;
810     }
811     return DP_SUCCESS;
812 }
813 
DeleteSessionKeyInner(MessageParcel & data,MessageParcel & reply)814 int32_t DistributedDeviceProfileStub::DeleteSessionKeyInner(MessageParcel& data, MessageParcel& reply)
815 {
816     HILOGI("called");
817     uint32_t userId = 0;
818     int32_t sessionKeyId = 0;
819     READ_HELPER(data, Uint32, userId);
820     READ_HELPER(data, Int32, sessionKeyId);
821     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteSessionKey(userId, sessionKeyId);
822     if (!reply.WriteInt32(ret)) {
823         HILOGE("Write reply failed");
824         return DP_WRITE_PARCEL_FAIL;
825     }
826     return DP_SUCCESS;
827 }
828 
PutDeviceProfileBatchInner(MessageParcel & data,MessageParcel & reply)829 int32_t DistributedDeviceProfileStub::PutDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply)
830 {
831     std::vector<OHOS::DistributedDeviceProfile::DeviceProfile> deviceProfiles;
832     if (!IpcUtils::UnMarshalling(data, deviceProfiles)) {
833         HILOGE("read parcel fail!");
834         return DP_READ_PARCEL_FAIL;
835     }
836     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutDeviceProfileBatch(deviceProfiles);
837     if (!reply.WriteInt32(ret)) {
838         HILOGE("Write reply failed");
839         return ERR_FLATTEN_OBJECT;
840     }
841     return DP_SUCCESS;
842 }
843 
PutServiceProfileInner(MessageParcel & data,MessageParcel & reply)844 int32_t DistributedDeviceProfileStub::PutServiceProfileInner(MessageParcel& data, MessageParcel& reply)
845 {
846     HILOGI("called");
847     ServiceProfile serviceProfile;
848     if (!serviceProfile.UnMarshalling(data)) {
849         HILOGE("read parcel fail!");
850         return DP_READ_PARCEL_FAIL;
851     }
852     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceProfile(serviceProfile);
853     if (!reply.WriteInt32(ret)) {
854         HILOGE("Write reply failed");
855         return ERR_FLATTEN_OBJECT;
856     }
857     return DP_SUCCESS;
858 }
859 
PutServiceProfileBatchInner(MessageParcel & data,MessageParcel & reply)860 int32_t DistributedDeviceProfileStub::PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply)
861 {
862     std::vector<ServiceProfile> serviceProfiles;
863     if (!IpcUtils::UnMarshalling(data, serviceProfiles)) {
864         HILOGE("read parcel fail!");
865         return DP_READ_PARCEL_FAIL;
866     }
867     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceProfileBatch(serviceProfiles);
868     if (!reply.WriteInt32(ret)) {
869         HILOGE("Write reply failed");
870         return ERR_FLATTEN_OBJECT;
871     }
872     return DP_SUCCESS;
873 }
874 
PutCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)875 int32_t DistributedDeviceProfileStub::PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
876 {
877     CharacteristicProfile charProfile;
878     if (!charProfile.UnMarshalling(data)) {
879         HILOGE("read parcel fail!");
880         return DP_READ_PARCEL_FAIL;
881     }
882     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutCharacteristicProfile(charProfile);
883     if (!reply.WriteInt32(ret)) {
884         HILOGE("Write reply failed");
885         return ERR_FLATTEN_OBJECT;
886     }
887     return DP_SUCCESS;
888 }
889 
PutCharacteristicProfileBatchInner(MessageParcel & data,MessageParcel & reply)890 int32_t DistributedDeviceProfileStub::PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply)
891 {
892     std::vector<CharacteristicProfile> charProfiles;
893     if (!IpcUtils::UnMarshalling(data, charProfiles)) {
894         HILOGE("read parcel fail!");
895         return DP_READ_PARCEL_FAIL;
896     }
897     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutCharacteristicProfileBatch(charProfiles);
898     if (!reply.WriteInt32(ret)) {
899         HILOGE("Write reply failed");
900         return ERR_FLATTEN_OBJECT;
901     }
902     return DP_SUCCESS;
903 }
904 
GetDeviceProfileNewInner(MessageParcel & data,MessageParcel & reply)905 int32_t DistributedDeviceProfileStub::GetDeviceProfileNewInner(MessageParcel& data, MessageParcel& reply)
906 {
907     std::string deviceId;
908     bool isMultiUser = false;
909     int32_t userId = DistributedDeviceProfile::DEFAULT_USER_ID;
910     OHOS::DistributedDeviceProfile::DeviceProfile deviceProfile;
911     READ_HELPER(data, String, deviceId);
912     READ_HELPER(data, Bool, isMultiUser);
913     READ_HELPER(data, Int32, userId);
914     deviceProfile.SetIsMultiUser(isMultiUser);
915     deviceProfile.SetUserId(userId);
916     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetDeviceProfile(deviceId, deviceProfile);
917     if (!reply.WriteInt32(ret)) {
918         HILOGE("Write reply failed");
919         return ERR_FLATTEN_OBJECT;
920     }
921     if (!deviceProfile.Marshalling(reply)) {
922         HILOGE("write parcel fail!");
923         return DP_WRITE_PARCEL_FAIL;
924     }
925     return DP_SUCCESS;
926 }
927 
GetDeviceProfilesInner(MessageParcel & data,MessageParcel & reply)928 int32_t DistributedDeviceProfileStub::GetDeviceProfilesInner(MessageParcel& data, MessageParcel& reply)
929 {
930     DeviceProfileFilterOptions options;
931     std::vector<OHOS::DistributedDeviceProfile::DeviceProfile> deviceProfiles;
932     if (!options.UnMarshalling(data)) {
933         HILOGE("read parcel fail!");
934         return DP_READ_PARCEL_FAIL;
935     }
936     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetDeviceProfiles(options, deviceProfiles);
937     if (!reply.WriteInt32(ret)) {
938         HILOGE("Write reply failed");
939         return ERR_FLATTEN_OBJECT;
940     }
941     if (!IpcUtils::Marshalling(reply, deviceProfiles)) {
942         HILOGE("write parcel fail!");
943         return DP_WRITE_PARCEL_FAIL;
944     }
945     return DP_SUCCESS;
946 }
947 
GetServiceProfileInner(MessageParcel & data,MessageParcel & reply)948 int32_t DistributedDeviceProfileStub::GetServiceProfileInner(MessageParcel& data, MessageParcel& reply)
949 {
950     std::string deviceId;
951     std::string serviceName;
952     ServiceProfile serviceProfile;
953     bool isMultiUser = false;
954     int32_t userId = DistributedDeviceProfile::DEFAULT_USER_ID;
955     READ_HELPER(data, String, deviceId);
956     READ_HELPER(data, String, serviceName);
957     READ_HELPER(data, Bool, isMultiUser);
958     READ_HELPER(data, Int32, userId);
959     serviceProfile.SetIsMultiUser(isMultiUser);
960     serviceProfile.SetUserId(userId);
961     int32_t ret =
962         DistributedDeviceProfileServiceNew::GetInstance().GetServiceProfile(deviceId, serviceName, serviceProfile);
963     if (!reply.WriteInt32(ret)) {
964         HILOGE("Write reply failed");
965         return ERR_FLATTEN_OBJECT;
966     }
967     if (!serviceProfile.Marshalling(reply)) {
968         HILOGE("write parcel fail!");
969         return DP_WRITE_PARCEL_FAIL;
970     }
971     return DP_SUCCESS;
972 }
973 
GetCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)974 int32_t DistributedDeviceProfileStub::GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
975 {
976     std::string deviceId;
977     std::string serviceName;
978     std::string characteristicKey;
979     bool isMultiUser = false;
980     int32_t userId = DistributedDeviceProfile::DEFAULT_USER_ID;
981     READ_HELPER(data, String, deviceId);
982     READ_HELPER(data, String, serviceName);
983     READ_HELPER(data, String, characteristicKey);
984     READ_HELPER(data, Bool, isMultiUser);
985     READ_HELPER(data, Int32, userId);
986     CharacteristicProfile charProfile;
987     charProfile.SetIsMultiUser(isMultiUser);
988     charProfile.SetUserId(userId);
989     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetCharacteristicProfile(deviceId, serviceName,
990         characteristicKey, charProfile);
991     if (!reply.WriteInt32(ret)) {
992         HILOGE("Write reply failed");
993         return ERR_FLATTEN_OBJECT;
994     }
995     if (!charProfile.Marshalling(reply)) {
996         HILOGE("write parcel fail!");
997         return DP_WRITE_PARCEL_FAIL;
998     }
999     return DP_SUCCESS;
1000 }
1001 
DeleteServiceProfileInner(MessageParcel & data,MessageParcel & reply)1002 int32_t DistributedDeviceProfileStub::DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply)
1003 {
1004     std::string deviceId;
1005     std::string serviceName;
1006     bool isMultiUser = false;
1007     int32_t userId = DistributedDeviceProfile::DEFAULT_USER_ID;
1008     READ_HELPER(data, String, deviceId);
1009     READ_HELPER(data, String, serviceName);
1010     READ_HELPER(data, Bool, isMultiUser);
1011     READ_HELPER(data, Int32, userId);
1012     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteServiceProfile(deviceId, serviceName,
1013         isMultiUser, userId);
1014     if (!reply.WriteInt32(ret)) {
1015         HILOGE("Write reply failed");
1016         return ERR_FLATTEN_OBJECT;
1017     }
1018     return DP_SUCCESS;
1019 }
1020 
DeleteCharacteristicProfileInner(MessageParcel & data,MessageParcel & reply)1021 int32_t DistributedDeviceProfileStub::DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply)
1022 {
1023     std::string deviceId;
1024     std::string serviceName;
1025     std::string characteristicKey;
1026     bool isMultiUser = false;
1027     int32_t userId = OHOS::DistributedDeviceProfile::DEFAULT_USER_ID;
1028     READ_HELPER(data, String, deviceId);
1029     READ_HELPER(data, String, serviceName);
1030     READ_HELPER(data, String, characteristicKey);
1031     READ_HELPER(data, Bool, isMultiUser);
1032     READ_HELPER(data, Int32, userId);
1033     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName,
1034         characteristicKey, isMultiUser, userId);
1035     if (!reply.WriteInt32(ret)) {
1036         HILOGE("Write reply failed");
1037         return ERR_FLATTEN_OBJECT;
1038     }
1039     return DP_SUCCESS;
1040 }
1041 
SubscribeDeviceProfileInner(MessageParcel & data,MessageParcel & reply)1042 int32_t DistributedDeviceProfileStub::SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
1043 {
1044     OHOS::DistributedDeviceProfile::SubscribeInfo subscribeInfo;
1045     if (!subscribeInfo.UnMarshalling(data)) {
1046         HILOGE("read parcel fail!");
1047         return DP_READ_PARCEL_FAIL;
1048     }
1049     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfile(subscribeInfo);
1050     if (!reply.WriteInt32(ret)) {
1051         HILOGE("Write reply failed");
1052         return ERR_FLATTEN_OBJECT;
1053     }
1054     return DP_SUCCESS;
1055 }
1056 
UnSubscribeDeviceProfileInner(MessageParcel & data,MessageParcel & reply)1057 int32_t DistributedDeviceProfileStub::UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply)
1058 {
1059     OHOS::DistributedDeviceProfile::SubscribeInfo subscribeInfo;
1060     if (!subscribeInfo.UnMarshalling(data)) {
1061         HILOGE("read parcel fail!");
1062         return DP_READ_PARCEL_FAIL;
1063     }
1064     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfile(subscribeInfo);
1065     if (!reply.WriteInt32(ret)) {
1066         HILOGE("Write reply failed");
1067         return ERR_FLATTEN_OBJECT;
1068     }
1069     return DP_SUCCESS;
1070 }
1071 
SyncDeviceProfileNewInner(MessageParcel & data,MessageParcel & reply)1072 int32_t DistributedDeviceProfileStub::SyncDeviceProfileNewInner(MessageParcel& data, MessageParcel& reply)
1073 {
1074     OHOS::DistributedDeviceProfile::DpSyncOptions syncOptions;
1075     if (!syncOptions.UnMarshalling(data)) {
1076         HILOGE("read parcel fail!");
1077         return DP_READ_PARCEL_FAIL;
1078     }
1079     sptr<IRemoteObject> syncCompletedCallback = data.ReadRemoteObject();
1080     int32_t ret =
1081         DistributedDeviceProfileServiceNew::GetInstance().SyncDeviceProfile(syncOptions, syncCompletedCallback);
1082     if (!reply.WriteInt32(ret)) {
1083         HILOGE("Write reply failed");
1084         return ERR_FLATTEN_OBJECT;
1085     }
1086     return DP_SUCCESS;
1087 }
1088 
SendSubscribeInfosInner(MessageParcel & data,MessageParcel & reply)1089 int32_t DistributedDeviceProfileStub::SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply)
1090 {
1091     std::map<std::string, OHOS::DistributedDeviceProfile::SubscribeInfo> listenerMap;
1092     if (!IpcUtils::UnMarshalling(data, listenerMap)) {
1093         HILOGE("read parcel fail!");
1094         return DP_READ_PARCEL_FAIL;
1095     }
1096     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SendSubscribeInfos(listenerMap);
1097     if (!reply.WriteInt32(ret)) {
1098         HILOGE("Write reply failed");
1099         return ERR_FLATTEN_OBJECT;
1100     }
1101     return DP_SUCCESS;
1102 }
1103 
SubscribeDeviceProfileInitedInner(MessageParcel & data,MessageParcel & reply)1104 int32_t DistributedDeviceProfileStub::SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply)
1105 {
1106     int32_t saId = -1;
1107     READ_HELPER(data, Int32, saId);
1108     sptr<IRemoteObject> dpInitedCallback = data.ReadRemoteObject();
1109     if (dpInitedCallback == nullptr) {
1110         HILOGE("read remoteObject failed!");
1111         return ERR_FLATTEN_OBJECT;
1112     }
1113     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfileInited(saId,
1114         dpInitedCallback);
1115     if (!reply.WriteInt32(ret)) {
1116         HILOGE("Write reply failed");
1117         return ERR_FLATTEN_OBJECT;
1118     }
1119     return DP_SUCCESS;
1120 }
1121 
UnSubscribeDeviceProfileInitedInner(MessageParcel & data,MessageParcel & reply)1122 int32_t DistributedDeviceProfileStub::UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply)
1123 {
1124     int32_t saId = -1;
1125     READ_HELPER(data, Int32, saId);
1126     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfileInited(saId);
1127     if (!reply.WriteInt32(ret)) {
1128         HILOGE("Write reply failed");
1129         return ERR_FLATTEN_OBJECT;
1130     }
1131     return DP_SUCCESS;
1132 }
1133 
SubscribePinCodeInvalidInner(MessageParcel & data,MessageParcel & reply)1134 int32_t DistributedDeviceProfileStub::SubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply)
1135 {
1136     std::string bundleName = "";
1137     int32_t pinExchangeType = DEFAULT_PIN_EXCHANGE_TYPE;
1138     READ_HELPER(data, String, bundleName);
1139     READ_HELPER(data, Int32, pinExchangeType);
1140     sptr<IRemoteObject> pincodeInvalidCallback = data.ReadRemoteObject();
1141     if (pincodeInvalidCallback == nullptr) {
1142         HILOGE("read remoteObject failed!");
1143         return ERR_FLATTEN_OBJECT;
1144     }
1145     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribePinCodeInvalid(bundleName,
1146         pinExchangeType, pincodeInvalidCallback);
1147     if (!reply.WriteInt32(ret)) {
1148         HILOGE("Write reply failed");
1149         return ERR_FLATTEN_OBJECT;
1150     }
1151     return DP_SUCCESS;
1152 }
1153 
UnSubscribePinCodeInvalidInner(MessageParcel & data,MessageParcel & reply)1154 int32_t DistributedDeviceProfileStub::UnSubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply)
1155 {
1156     std::string bundleName = "";
1157     int32_t pinExchangeType = DEFAULT_PIN_EXCHANGE_TYPE;
1158     READ_HELPER(data, String, bundleName);
1159     READ_HELPER(data, Int32, pinExchangeType);
1160     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribePinCodeInvalid(bundleName,
1161         pinExchangeType);
1162     if (!reply.WriteInt32(ret)) {
1163         HILOGE("Write reply failed");
1164         return ERR_FLATTEN_OBJECT;
1165     }
1166     return DP_SUCCESS;
1167 }
1168 
PutAllTrustedDevicesInner(MessageParcel & data,MessageParcel & reply)1169 int32_t DistributedDeviceProfileStub::PutAllTrustedDevicesInner(MessageParcel& data, MessageParcel& reply)
1170 {
1171     std::vector<TrustedDeviceInfo> deviceInfos;
1172     if (!IpcUtils::UnMarshalling(data, deviceInfos)) {
1173         HILOGE("read parcel fail!");
1174         return DP_READ_PARCEL_FAIL;
1175     }
1176     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutAllTrustedDevices(deviceInfos);
1177     if (!reply.WriteInt32(ret)) {
1178         HILOGE("Write reply failed");
1179         return ERR_FLATTEN_OBJECT;
1180     }
1181     return DP_SUCCESS;
1182 }
1183 
PutLocalServiceInfoInner(MessageParcel & data,MessageParcel & reply)1184 int32_t DistributedDeviceProfileStub::PutLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply)
1185 {
1186     HILOGI("called");
1187     LocalServiceInfo localServiceInfo;
1188     if (!localServiceInfo.UnMarshalling(data)) {
1189         HILOGE("read parcel fail!");
1190         return DP_READ_PARCEL_FAIL;
1191     }
1192     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutLocalServiceInfo(localServiceInfo);
1193     if (!reply.WriteInt32(ret)) {
1194         HILOGE("Write reply failed");
1195         return DP_WRITE_PARCEL_FAIL;
1196     }
1197     return DP_SUCCESS;
1198 }
1199 
UpdateLocalServiceInfoInner(MessageParcel & data,MessageParcel & reply)1200 int32_t DistributedDeviceProfileStub::UpdateLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply)
1201 {
1202     HILOGI("called");
1203     LocalServiceInfo localServiceInfo;
1204     if (!localServiceInfo.UnMarshalling(data)) {
1205         HILOGE("read parcel fail!");
1206         return DP_READ_PARCEL_FAIL;
1207     }
1208     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateLocalServiceInfo(localServiceInfo);
1209     if (!reply.WriteInt32(ret)) {
1210         HILOGE("Write reply failed");
1211         return DP_WRITE_PARCEL_FAIL;
1212     }
1213     return DP_SUCCESS;
1214 }
1215 
GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel & data,MessageParcel & reply)1216 int32_t DistributedDeviceProfileStub::GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel& data,
1217     MessageParcel& reply)
1218 {
1219     LocalServiceInfo localServiceInfo;
1220     int32_t pinExchangeType = 0;
1221     std::string bundleName = "";
1222     READ_HELPER(data, String, bundleName);
1223     READ_HELPER(data, Int32, pinExchangeType);
1224     int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetLocalServiceInfoByBundleAndPinType(
1225         bundleName, pinExchangeType, localServiceInfo);
1226     if (!reply.WriteInt32(ret)) {
1227         HILOGE("Write reply failed");
1228         return ERR_FLATTEN_OBJECT;
1229     }
1230     if (!localServiceInfo.Marshalling(reply)) {
1231         HILOGE("write parcel fail!");
1232         return DP_WRITE_PARCEL_FAIL;
1233     }
1234     return DP_SUCCESS;
1235 }
1236 
DeleteLocalServiceInfoInner(MessageParcel & data,MessageParcel & reply)1237 int32_t DistributedDeviceProfileStub::DeleteLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply)
1238 {
1239     int32_t pinExchangeType = 0;
1240     std::string bundleName = "";
1241     READ_HELPER(data, String, bundleName);
1242     READ_HELPER(data, Int32, pinExchangeType);
1243     int32_t ret =
1244         DistributedDeviceProfileServiceNew::GetInstance().DeleteLocalServiceInfo(bundleName, pinExchangeType);
1245     if (!reply.WriteInt32(ret)) {
1246         HILOGE("Write reply failed");
1247         return DP_WRITE_PARCEL_FAIL;
1248     }
1249     return DP_SUCCESS;
1250 }
1251 } // namespace DeviceProfile
1252 } // namespace OHOS
1253