1 /* 2 * Copyright (c) 2023 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_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_NOTIFICATION_INCLUDE_NOTIFICATION_HELPER_H 17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_NOTIFICATION_INCLUDE_NOTIFICATION_HELPER_H 18 19 #include <list> 20 #include <map> 21 #include <memory> 22 #include <algorithm> 23 24 #include "singleton.h" 25 #include "iremote_object.h" 26 27 #include "allow_type.h" 28 #include "single_instance.h" 29 #include "standby_service_errors.h" 30 #include "istandby_service_subscriber.h" 31 #include "standby_state.h" 32 #include "istate_manager_adapter.h" 33 34 namespace OHOS { 35 namespace DevStandbyMgr { 36 class SubscriberDeathRecipient; 37 class StandbyStateSubscriber : public std::enable_shared_from_this<StandbyStateSubscriber> { 38 DECLARE_SINGLE_INSTANCE(StandbyStateSubscriber); 39 40 public: 41 ErrCode AddSubscriber(const sptr<IStandbyServiceSubscriber>& subscriber); 42 ErrCode RemoveSubscriber(const sptr<IStandbyServiceSubscriber>& subscriber); 43 void ReportStandbyState(uint32_t curState); 44 void ReportAllowListChanged(int32_t uid, const std::string& name, uint32_t allowType, bool added); 45 void HandleSubscriberDeath(const wptr<IRemoteObject>& remote); 46 void ShellDump(const std::vector<std::string>& argsInStr, std::string& result); 47 void NotifyAllowChangedByCommonEvent(int32_t uid, const std::string& name, uint32_t allowType, bool added); 48 49 private: 50 void NotifyIdleModeByCallback(bool napped, bool sleeping); 51 void NotifyIdleModeByCommonEvent(bool napped, bool sleeping); 52 void NotifyAllowChangedByCallback(int32_t uid, const std::string& name, uint32_t allowType, bool added); 53 std::list<sptr<IStandbyServiceSubscriber>>::iterator FindSubcriberObject(sptr<IRemoteObject>& proxy); 54 55 private: 56 std::mutex subscriberLock_ {}; 57 std::list<sptr<IStandbyServiceSubscriber>> subscriberList_ {}; 58 sptr<SubscriberDeathRecipient> deathRecipient_ {nullptr}; 59 std::shared_ptr<IStateManagerAdapter> standbyStateManager_ {nullptr}; 60 }; 61 62 class SubscriberDeathRecipient final : public IRemoteObject::DeathRecipient { 63 public: 64 DISALLOW_COPY_AND_MOVE(SubscriberDeathRecipient); 65 explicit SubscriberDeathRecipient(); 66 ~SubscriberDeathRecipient() override; 67 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 68 }; 69 } // namespace DevStandbyMgr 70 } // namespace OHOS 71 #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_NOTIFICATION_INCLUDE_NOTIFICATION_HELPER_H