1 /*
2  * Copyright (c) 2021-2022 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 "ans_manager_death_recipient.h"
17 
18 #include "ans_log_wrapper.h"
19 #include "ans_notification.h"
20 #include "iservice_registry.h"
21 #include "system_ability_definition.h"
22 
23 namespace OHOS {
24 namespace Notification {
SubscribeSAManager()25 void AnsManagerDeathRecipient::SubscribeSAManager()
26 {
27     std::lock_guard<std::mutex> lock(mutex_);
28     if (statusChangeListener_ != nullptr) {
29         return;
30     }
31     auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
32     statusChangeListener_ = new (std::nothrow) AnsManagerDeathRecipient::SystemAbilityStatusChangeListener();
33     if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
34         ANS_LOGI("GetSystemAbilityManager failed or new SystemAbilityStatusChangeListener failed");
35         statusChangeListener_ = nullptr;
36         return;
37     }
38     int32_t ret = samgrProxy->SubscribeSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID, statusChangeListener_);
39     if (ret != ERR_OK) {
40         ANS_LOGI("SubscribeSystemAbility to sa manager failed");
41         statusChangeListener_ = nullptr;
42     }
43 }
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)44 void AnsManagerDeathRecipient::SystemAbilityStatusChangeListener::OnAddSystemAbility(
45     int32_t systemAbilityId, const std::string& deviceId) {}
46 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)47 void AnsManagerDeathRecipient::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
48     int32_t systemAbilityId, const std::string& deviceId)
49 {
50     ANS_LOGI("Ans manager service died");
51     DelayedSingleton<AnsNotification>::GetInstance()->OnServiceDied();
52 }
53 }  // namespace Notification
54 }  // namespace OHOS