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 #ifndef FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_DEATH_RECIPIENT_H 17 #define FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_DEATH_RECIPIENT_H 18 19 #include "ffrt.h" 20 #include <memory> 21 #include <mutex> 22 #include <singleton.h> 23 24 #include "system_ability_status_change_stub.h" 25 26 namespace OHOS { 27 namespace EventFwk { 28 class CommonEventDeathRecipient : public DelayedSingleton<CommonEventDeathRecipient> { 29 public: 30 CommonEventDeathRecipient() = default; 31 ~CommonEventDeathRecipient(); 32 33 void SubscribeSAManager(); 34 private: 35 class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 36 public: 37 SystemAbilityStatusChangeListener(); 38 ~SystemAbilityStatusChangeListener() = default; 39 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 40 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 41 private: 42 bool isSAOffline_ = false; 43 ffrt::mutex mutex_; 44 std::shared_ptr<ffrt::queue> queue_ = nullptr; 45 }; 46 47 ffrt::mutex listenerMutex_; 48 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 49 }; 50 } // namespace EventFwk 51 } // namespace OHOS 52 53 #endif // FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_DEATH_RECIPIENT_H 54