• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
28     statusChangeListener_ = new (std::nothrow) AnsManagerDeathRecipient::SystemAbilityStatusChangeListener();
29     if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
30         ANS_LOGI("GetSystemAbilityManager failed or new SystemAbilityStatusChangeListener failed");
31         statusChangeListener_ = nullptr;
32         return;
33     }
34     int32_t ret = samgrProxy->SubscribeSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID, statusChangeListener_);
35     if (ret != ERR_OK) {
36         ANS_LOGI("SubscribeSystemAbility to sa manager failed");
37         statusChangeListener_ = nullptr;
38     }
39 }
40 
GetIsSubscribeSAManager()41 bool AnsManagerDeathRecipient::GetIsSubscribeSAManager()
42 {
43     return statusChangeListener_ != nullptr;
44 }
45 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)46 void AnsManagerDeathRecipient::SystemAbilityStatusChangeListener::OnAddSystemAbility(
47     int32_t systemAbilityId, const std::string& deviceId)
48 {
49     if (!isSAOffline) {
50         return;
51     }
52     ANS_LOGI("Ans manager service restore, try to reconnect");
53     DelayedSingleton<AnsNotification>::GetInstance()->Reconnect();
54     isSAOffline = false;
55 }
56 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)57 void AnsManagerDeathRecipient::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
58     int32_t systemAbilityId, const std::string& deviceId)
59 {
60     ANS_LOGI("Ans manager service died");
61     DelayedSingleton<AnsNotification>::GetInstance()->ResetAnsManagerProxy();
62     isSAOffline = true;
63 }
64 }  // namespace Notification
65 }  // namespace OHOS
66