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_client.h"
17
18 #include <algorithm>
19 #include <bitset>
20 #include <chrono>
21 #include <functional>
22 #include <new>
23 #include <string>
24 #include <thread>
25 #include <type_traits>
26 #include <unistd.h>
27 #include <utility>
28 #include <profile_utils.h>
29 #include "profile_change_listener_stub.h"
30 #include "device_profile_load_callback.h"
31 #include "distributed_device_profile_errors.h"
32 #include "distributed_device_profile_log.h"
33 #include "dp_radar_helper.h"
34 #include "event_handler.h"
35 #include "event_runner.h"
36 #include "i_distributed_device_profile.h"
37 #include "if_system_ability_manager.h"
38 #include "ipc_skeleton.h"
39 #include "iremote_broker.h"
40 #include "iservice_registry.h"
41 #include "system_ability_definition.h"
42
43 namespace OHOS {
44 namespace DistributedDeviceProfile {
45 using namespace std::chrono_literals;
46
47 namespace {
48 const std::string TAG = "DistributedDeviceProfileClient";
49 constexpr int32_t LOAD_SA_TIMEOUT_MS = 10000;
50 }
51
52 IMPLEMENT_SINGLE_INSTANCE(DistributedDeviceProfileClient);
53
LoadDeviceProfileService()54 sptr<IDistributedDeviceProfile> DistributedDeviceProfileClient::LoadDeviceProfileService()
55 {
56 sptr<DeviceProfileLoadCallback> loadCallback = new DeviceProfileLoadCallback();
57 if (loadCallback == nullptr) {
58 HILOGE("loadCallback is nullptr.");
59 return nullptr;
60 }
61
62 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
63 if (samgrProxy == nullptr) {
64 HILOGE("get samgr failed");
65 return nullptr;
66 }
67
68 int32_t ret = samgrProxy->LoadSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID, loadCallback);
69 int32_t stageRes = (ret == ERR_OK) ?
70 static_cast<int32_t>(StageRes::STAGE_IDLE) : static_cast<int32_t>(StageRes::STAGE_FAIL);
71 DpRadarHelper::GetInstance().ReportLoadDpSa(stageRes);
72 if (ret != ERR_OK) {
73 HILOGE("Failed to Load systemAbility");
74 return nullptr;
75 }
76 {
77 std::unique_lock<std::mutex> lock(serviceLock_);
78 auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(LOAD_SA_TIMEOUT_MS),
79 [this]() { return dpProxy_ != nullptr; });
80 if (waitStatus && dpProxy_ != nullptr) {
81 HILOGE("Get profile Service success!");
82 return dpProxy_;
83 }
84 }
85 return nullptr;
86 }
87
LoadSystemAbilitySuccess(const sptr<IRemoteObject> & remoteObject)88 void DistributedDeviceProfileClient::LoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject)
89 {
90 HILOGI("FinishStartSA");
91 int32_t stageRes = static_cast<int32_t>(StageRes::STAGE_SUCC);
92 DpRadarHelper::GetInstance().ReportLoadDpSaCb(stageRes);
93 std::lock_guard<std::mutex> lock(serviceLock_);
94 if (dpDeathRecipient_ == nullptr) {
95 dpDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new DeviceProfileDeathRecipient);
96 }
97 if (remoteObject != nullptr) {
98 remoteObject->AddDeathRecipient(dpDeathRecipient_);
99 dpProxy_ = iface_cast<IDistributedDeviceProfile>(remoteObject);
100 proxyConVar_.notify_one();
101 DpRadarHelper::GetInstance().SetDeviceProfileInit(true);
102 }
103 }
104
LoadSystemAbilityFail()105 void DistributedDeviceProfileClient::LoadSystemAbilityFail()
106 {
107 int32_t stageRes = static_cast<int32_t>(StageRes::STAGE_FAIL);
108 DpRadarHelper::GetInstance().ReportLoadDpSaCb(stageRes);
109 std::lock_guard<std::mutex> lock(serviceLock_);
110 dpProxy_ = nullptr;
111 }
112
SendSubscribeInfosToService()113 void DistributedDeviceProfileClient::SendSubscribeInfosToService()
114 {
115 auto dpService = GetDeviceProfileService();
116 if (dpService == nullptr) {
117 HILOGE("dpService is nullptr!");
118 return;
119 }
120 {
121 std::lock_guard<std::mutex> lock(serviceLock_);
122 if (subscribeInfos_.empty() || subscribeInfos_.size() > MAX_SUBSCRIBE_INFO_SIZE) {
123 HILOGE("SubscribeInfos size is invalid!size: %{public}zu!", subscribeInfos_.size());
124 return;
125 }
126 dpService->SendSubscribeInfos(subscribeInfos_);
127 }
128 }
129
PutAccessControlProfile(const AccessControlProfile & accessControlProfile)130 int32_t DistributedDeviceProfileClient::PutAccessControlProfile(const AccessControlProfile& accessControlProfile)
131 {
132 auto dpService = GetDeviceProfileService();
133 if (dpService == nullptr) {
134 HILOGE("get dp service failed");
135 return DP_GET_SERVICE_FAILED;
136 }
137 return dpService->PutAccessControlProfile(accessControlProfile);
138 }
139
UpdateAccessControlProfile(const AccessControlProfile & accessControlProfile)140 int32_t DistributedDeviceProfileClient::UpdateAccessControlProfile(const AccessControlProfile& accessControlProfile)
141 {
142 auto dpService = GetDeviceProfileService();
143 if (dpService == nullptr) {
144 HILOGE("get dp service failed");
145 return DP_GET_SERVICE_FAILED;
146 }
147 return dpService->UpdateAccessControlProfile(accessControlProfile);
148 }
149
GetTrustDeviceProfile(const std::string & deviceId,TrustDeviceProfile & trustDeviceProfile)150 int32_t DistributedDeviceProfileClient::GetTrustDeviceProfile(const std::string& deviceId,
151 TrustDeviceProfile& trustDeviceProfile)
152 {
153 auto dpService = GetDeviceProfileService();
154 if (dpService == nullptr) {
155 HILOGE("get dp service failed");
156 return DP_GET_SERVICE_FAILED;
157 }
158 return dpService->GetTrustDeviceProfile(deviceId, trustDeviceProfile);
159 }
160
GetAllTrustDeviceProfile(std::vector<TrustDeviceProfile> & trustDeviceProfiles)161 int32_t DistributedDeviceProfileClient::GetAllTrustDeviceProfile(std::vector<TrustDeviceProfile>& trustDeviceProfiles)
162 {
163 auto dpService = GetDeviceProfileService();
164 if (dpService == nullptr) {
165 HILOGE("get dp service failed");
166 return DP_GET_SERVICE_FAILED;
167 }
168 return dpService->GetAllTrustDeviceProfile(trustDeviceProfiles);
169 }
170
GetAccessControlProfile(std::map<std::string,std::string> params,std::vector<AccessControlProfile> & accessControlProfiles)171 int32_t DistributedDeviceProfileClient::GetAccessControlProfile(std::map<std::string, std::string> params,
172 std::vector<AccessControlProfile>& accessControlProfiles)
173 {
174 auto dpService = GetDeviceProfileService();
175 if (dpService == nullptr) {
176 HILOGE("Get dp service failed");
177 return DP_GET_SERVICE_FAILED;
178 }
179 if (params.empty() || params.size() > MAX_PARAM_SIZE) {
180 HILOGE("Params size is invalid!size: %{public}zu!", params.size());
181 return DP_INVALID_PARAMS;
182 }
183 return dpService->GetAccessControlProfile(params, accessControlProfiles);
184 }
185
GetAllAccessControlProfile(std::vector<AccessControlProfile> & accessControlProfiles)186 int32_t DistributedDeviceProfileClient::GetAllAccessControlProfile(
187 std::vector<AccessControlProfile>& accessControlProfiles)
188 {
189 auto dpService = GetDeviceProfileService();
190 if (dpService == nullptr) {
191 HILOGE("Get dp service failed");
192 return DP_GET_SERVICE_FAILED;
193 }
194 return dpService->GetAllAccessControlProfile(accessControlProfiles);
195 }
196
DeleteAccessControlProfile(int32_t accessControlId)197 int32_t DistributedDeviceProfileClient::DeleteAccessControlProfile(int32_t accessControlId)
198 {
199 auto dpService = GetDeviceProfileService();
200 if (dpService == nullptr) {
201 HILOGE("Get dp service failed");
202 return DP_GET_SERVICE_FAILED;
203 }
204 return dpService->DeleteAccessControlProfile(accessControlId);
205 }
206
PutServiceProfile(const ServiceProfile & serviceProfile)207 int32_t DistributedDeviceProfileClient::PutServiceProfile(const ServiceProfile& serviceProfile)
208 {
209 auto dpService = GetDeviceProfileService();
210 if (dpService == nullptr) {
211 HILOGE("Get dp service failed");
212 return DP_GET_SERVICE_FAILED;
213 }
214 return dpService->PutServiceProfile(serviceProfile);
215 }
216
PutServiceProfileBatch(const std::vector<ServiceProfile> & serviceProfiles)217 int32_t DistributedDeviceProfileClient::PutServiceProfileBatch(const std::vector<ServiceProfile>& serviceProfiles)
218 {
219 auto dpService = GetDeviceProfileService();
220 if (dpService == nullptr) {
221 HILOGE("Get dp service failed");
222 return DP_GET_SERVICE_FAILED;
223 }
224 if (serviceProfiles.empty() || serviceProfiles.size() > MAX_PROFILE_SIZE) {
225 HILOGE("ServiceProfiles size is invalid!size: %{public}zu!", serviceProfiles.size());
226 return DP_INVALID_PARAMS;
227 }
228 return dpService->PutServiceProfileBatch(serviceProfiles);
229 }
230
PutCharacteristicProfile(const CharacteristicProfile & characteristicProfile)231 int32_t DistributedDeviceProfileClient::PutCharacteristicProfile(const CharacteristicProfile& characteristicProfile)
232 {
233 auto dpService = GetDeviceProfileService();
234 if (dpService == nullptr) {
235 HILOGE("Get dp service failed");
236 return DP_GET_SERVICE_FAILED;
237 }
238 return dpService->PutCharacteristicProfile(characteristicProfile);
239 }
240
PutCharacteristicProfileBatch(const std::vector<CharacteristicProfile> & characteristicProfiles)241 int32_t DistributedDeviceProfileClient::PutCharacteristicProfileBatch(
242 const std::vector<CharacteristicProfile>& characteristicProfiles)
243 {
244 auto dpService = GetDeviceProfileService();
245 if (dpService == nullptr) {
246 HILOGE("Get dp service failed");
247 return DP_GET_SERVICE_FAILED;
248 }
249 if (characteristicProfiles.empty() || characteristicProfiles.size() > MAX_PROFILE_SIZE) {
250 HILOGE("ServiceProfiles size is invalid!size: %{public}zu!", characteristicProfiles.size());
251 return DP_INVALID_PARAMS;
252 }
253 return dpService->PutCharacteristicProfileBatch(characteristicProfiles);
254 }
255
GetDeviceProfile(const std::string & deviceId,DeviceProfile & deviceProfile)256 int32_t DistributedDeviceProfileClient::GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile)
257 {
258 auto dpService = GetDeviceProfileService();
259 if (dpService == nullptr) {
260 HILOGE("Get dp service failed");
261 return DP_GET_SERVICE_FAILED;
262 }
263 return dpService->GetDeviceProfile(deviceId, deviceProfile);
264 }
265
GetServiceProfile(const std::string & deviceId,const std::string & serviceName,ServiceProfile & serviceProfile)266 int32_t DistributedDeviceProfileClient::GetServiceProfile(const std::string& deviceId, const std::string& serviceName,
267 ServiceProfile& serviceProfile)
268 {
269 auto dpService = GetDeviceProfileService();
270 if (dpService == nullptr) {
271 HILOGE("Get dp service failed");
272 return DP_GET_SERVICE_FAILED;
273 }
274 return dpService->GetServiceProfile(deviceId, serviceName, serviceProfile);
275 }
276
GetCharacteristicProfile(const std::string & deviceId,const std::string & serviceName,const std::string & characteristicId,CharacteristicProfile & characteristicProfile)277 int32_t DistributedDeviceProfileClient::GetCharacteristicProfile(const std::string& deviceId,
278 const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& characteristicProfile)
279 {
280 auto dpService = GetDeviceProfileService();
281 if (dpService == nullptr) {
282 HILOGE("Get dp service failed");
283 return DP_GET_SERVICE_FAILED;
284 }
285 return dpService->GetCharacteristicProfile(deviceId, serviceName, characteristicId, characteristicProfile);
286 }
287
DeleteServiceProfile(const std::string & deviceId,const std::string & serviceName)288 int32_t DistributedDeviceProfileClient::DeleteServiceProfile(const std::string& deviceId,
289 const std::string& serviceName)
290 {
291 auto dpService = GetDeviceProfileService();
292 if (dpService == nullptr) {
293 HILOGE("Get dp service failed");
294 return DP_GET_SERVICE_FAILED;
295 }
296 return dpService->DeleteServiceProfile(deviceId, serviceName);
297 }
298
DeleteCharacteristicProfile(const std::string & deviceId,const std::string & serviceName,const std::string & characteristicKey)299 int32_t DistributedDeviceProfileClient::DeleteCharacteristicProfile(const std::string& deviceId,
300 const std::string& serviceName, const std::string& characteristicKey)
301 {
302 auto dpService = GetDeviceProfileService();
303 if (dpService == nullptr) {
304 HILOGE("Get dp service failed");
305 return DP_GET_SERVICE_FAILED;
306 }
307 return dpService->DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey);
308 }
309
SubscribeDeviceProfile(const SubscribeInfo & subscribeInfo)310 int32_t DistributedDeviceProfileClient::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo)
311 {
312 SubscribeDeviceProfileSA();
313 auto dpService = GetDeviceProfileService();
314 if (dpService == nullptr) {
315 HILOGE("Get dp service failed");
316 return DP_GET_SERVICE_FAILED;
317 }
318 {
319 std::lock_guard<std::mutex> lock(serviceLock_);
320 if (subscribeInfos_.size() > MAX_LISTENER_SIZE) {
321 HILOGE("ProfileChangeListeners size is invalid!size: %{public}zu!", subscribeInfos_.size());
322 return DP_EXCEED_MAX_SIZE_FAIL;
323 }
324 std::string subscribeTag =
325 subscribeInfo.GetSubscribeKey() + SEPARATOR + std::to_string(subscribeInfo.GetSaId());
326 subscribeInfos_[subscribeTag] = subscribeInfo;
327 HILOGI("subscribeInfos_.size is %{public}zu", subscribeInfos_.size());
328 }
329 return dpService->SubscribeDeviceProfile(subscribeInfo);
330 }
331
UnSubscribeDeviceProfile(const SubscribeInfo & subscribeInfo)332 int32_t DistributedDeviceProfileClient::UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo)
333 {
334 SubscribeDeviceProfileSA();
335 auto dpService = GetDeviceProfileService();
336 if (dpService == nullptr) {
337 HILOGE("Get dp service failed");
338 return DP_GET_SERVICE_FAILED;
339 }
340 {
341 std::lock_guard<std::mutex> lock(serviceLock_);
342 subscribeInfos_.erase(subscribeInfo.GetSubscribeKey() + SEPARATOR + std::to_string(subscribeInfo.GetSaId()));
343 HILOGI("subscribeInfos_.size is %{public}zu", subscribeInfos_.size());
344 }
345 return dpService->UnSubscribeDeviceProfile(subscribeInfo);
346 }
347
SyncDeviceProfile(const DpSyncOptions & syncOptions,sptr<ISyncCompletedCallback> syncCb)348 int32_t DistributedDeviceProfileClient::SyncDeviceProfile(const DpSyncOptions& syncOptions,
349 sptr<ISyncCompletedCallback> syncCb)
350 {
351 auto dpService = GetDeviceProfileService();
352 if (dpService == nullptr) {
353 HILOGE("Get dp service failed");
354 return DP_GET_SERVICE_FAILED;
355 }
356 if (syncCb == nullptr) {
357 HILOGE("SyncCb is nullptr!");
358 return DP_SYNC_DEVICE_FAIL;
359 }
360 sptr<IRemoteObject> syncCompletedCallback = syncCb->AsObject();
361 if (syncCompletedCallback == nullptr) {
362 HILOGE("SyncCb ipc cast fail!");
363 return DP_SYNC_DEVICE_FAIL;
364 }
365 return dpService->SyncDeviceProfile(syncOptions, syncCompletedCallback);
366 }
367
GetDeviceProfileService()368 sptr<IDistributedDeviceProfile> DistributedDeviceProfileClient::GetDeviceProfileService()
369 {
370 {
371 std::lock_guard<std::mutex> lock(serviceLock_);
372 if (dpProxy_ != nullptr) {
373 return dpProxy_;
374 }
375 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
376 if (samgrProxy == nullptr) {
377 HILOGE("get samgr failed");
378 return nullptr;
379 }
380 auto object = samgrProxy->CheckSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID);
381 int32_t stageRes = (object != nullptr) ?
382 static_cast<int32_t>(StageRes::STAGE_SUCC) : static_cast<int32_t>(StageRes::STAGE_FAIL);
383 if (!DpRadarHelper::GetInstance().IsDeviceProfileInit()) {
384 DpRadarHelper::GetInstance().ReportCheckDpSa(stageRes);
385 }
386 if (object != nullptr) {
387 HILOGD("get service succeeded");
388 if (dpDeathRecipient_ == nullptr) {
389 dpDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new DeviceProfileDeathRecipient);
390 }
391 object->AddDeathRecipient(dpDeathRecipient_);
392 dpProxy_ = iface_cast<IDistributedDeviceProfile>(object);
393 return dpProxy_;
394 }
395 }
396
397 HILOGW("remoteObject is null!");
398 if (LoadDeviceProfileService()) {
399 std::lock_guard<std::mutex> lock(serviceLock_);
400 if (dpProxy_ != nullptr) {
401 return dpProxy_;
402 } else {
403 HILOGE("load dp service failed");
404 return nullptr;
405 }
406 }
407 HILOGE("load dp service failed");
408 return nullptr;
409 }
410
OnServiceDied(const sptr<IRemoteObject> & remote)411 void DistributedDeviceProfileClient::OnServiceDied(const sptr<IRemoteObject>& remote)
412 {
413 HILOGI("called");
414 std::lock_guard<std::mutex> lock(serviceLock_);
415 DpRadarHelper::GetInstance().SetDeviceProfileInit(false);
416 dpProxy_ = nullptr;
417 }
418
OnRemoteDied(const wptr<IRemoteObject> & remote)419 void DistributedDeviceProfileClient::DeviceProfileDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
420 {
421 HILOGI("call!");
422 DistributedDeviceProfileClient::GetInstance().OnServiceDied(remote.promote());
423 }
424
SubscribeDeviceProfileSA()425 void DistributedDeviceProfileClient::SubscribeDeviceProfileSA()
426 {
427 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
428 if (samgrProxy == nullptr) {
429 HILOGE("get samgr failed");
430 return;
431 }
432 int32_t ret = DP_SUCCESS;
433 {
434 std::lock_guard<std::mutex> lock(serviceLock_);
435 if (saListenerCallback_ == nullptr) {
436 saListenerCallback_ = sptr<SystemAbilityListener>(new SystemAbilityListener());
437 }
438 ret = samgrProxy->SubscribeSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID, saListenerCallback_);
439 }
440 if (ret != DP_SUCCESS) {
441 HILOGE("subscribe dp sa failed! ret %{public}d.", ret);
442 return;
443 }
444 HILOGD("subscribe dp sa success");
445 }
446
StartThreadSendSubscribeInfos()447 void DistributedDeviceProfileClient::StartThreadSendSubscribeInfos()
448 {
449 HILOGI("Send SubscribeInfos cache in proxy to service!");
450 std::thread(&DistributedDeviceProfileClient::SendSubscribeInfosToService, this).detach();
451 }
452
ReSubscribeDeviceProfileInited()453 void DistributedDeviceProfileClient::ReSubscribeDeviceProfileInited()
454 {
455 if (dpInitedCallback_ == nullptr) {
456 HILOGE("not use Retry subscribe dp inited");
457 return;
458 }
459 auto autoTask = [this] () {
460 int32_t ret = SubscribeDeviceProfileInited(saId_, dpInitedCallback_);
461 if (ret != DP_SUCCESS) {
462 HILOGE("Retry subscribe dp inited failed");
463 } else {
464 HILOGD("Retry subscribe dp inited succeed");
465 }
466 };
467 std::thread(autoTask).detach();
468 }
469
SubscribeDeviceProfileInited(int32_t saId,sptr<IDpInitedCallback> initedCb)470 int32_t DistributedDeviceProfileClient::SubscribeDeviceProfileInited(int32_t saId,
471 sptr<IDpInitedCallback> initedCb)
472 {
473 HILOGI("enter, saId:%{public}d", saId);
474 SubscribeDeviceProfileSA();
475 auto dpService = GetDeviceProfileService();
476 if (dpService == nullptr) {
477 HILOGE("Get dp service failed");
478 return DP_SUBSCRIBE_INITED_FALI;
479 }
480 if (saId <= 0 || saId > MAX_SAID) {
481 HILOGE("saId is invalid, saId:%{public}d", saId);
482 return DP_INVALID_PARAM;
483 }
484 if (initedCb == nullptr) {
485 HILOGE("initedCb is nullptr!");
486 return DP_INVALID_PARAM;
487 }
488 sptr<IRemoteObject> dpInitedCallback = initedCb->AsObject();
489 if (dpInitedCallback == nullptr) {
490 HILOGE("SyncCb ipc cast fail!");
491 return DP_SUBSCRIBE_INITED_FALI;
492 }
493 {
494 std::lock_guard<std::mutex> lock(serviceLock_);
495 int32_t ret = dpService->SubscribeDeviceProfileInited(saId, dpInitedCallback);
496 if (ret != DP_SUCCESS) {
497 HILOGE("Subscribe DP Inited failed!");
498 return ret;
499 }
500 saId_ = saId;
501 dpInitedCallback_ = initedCb;
502 }
503 HILOGD("Subscribe DP Inited succeed!");
504 return DP_SUCCESS;
505 }
506
UnSubscribeDeviceProfileInited(int32_t saId)507 int32_t DistributedDeviceProfileClient::UnSubscribeDeviceProfileInited(int32_t saId)
508 {
509 HILOGI("enter");
510 if (dpInitedCallback_ == nullptr) {
511 HILOGE("not subscribe dp inited, no need unsubscribe dp inited");
512 return DP_SUCCESS;
513 }
514 SubscribeDeviceProfileSA();
515 auto dpService = GetDeviceProfileService();
516 if (dpService == nullptr) {
517 HILOGE("Get dp service failed");
518 return DP_GET_SERVICE_FAILED;
519 }
520 if (saId <= 0 || saId > MAX_SAID) {
521 HILOGE("saId is invalid, saId:%{public}d", saId);
522 return DP_INVALID_PARAM;
523 }
524 {
525 std::lock_guard<std::mutex> lock(serviceLock_);
526 int32_t ret = dpService->UnSubscribeDeviceProfileInited(saId);
527 if (ret != DP_SUCCESS) {
528 HILOGE("Unsubscribe DP Inited failed!");
529 return ret;
530 }
531 dpInitedCallback_ = nullptr;
532 }
533 HILOGD("Unsubscribe DP Inited succeed!");
534 return DP_SUCCESS;
535 }
536
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)537 void DistributedDeviceProfileClient::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId,
538 const std::string &deviceId)
539 {
540 HILOGD("dp sa removed");
541 }
542
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)543 void DistributedDeviceProfileClient::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId,
544 const std::string &deviceId)
545 {
546 HILOGI("dp sa started");
547 DistributedDeviceProfileClient::GetInstance().StartThreadSendSubscribeInfos();
548 DistributedDeviceProfileClient::GetInstance().ReSubscribeDeviceProfileInited();
549 }
550 } // namespace DeviceProfile
551 } // namespace OHOS
552