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 "singleton.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_DELAYED_SINGLETON(StandbyStateSubscriber); 39 40 public: 41 static std::shared_ptr<StandbyStateSubscriber> GetInstance(); 42 ErrCode AddSubscriber(const sptr<IStandbyServiceSubscriber>& subscriber); 43 ErrCode RemoveSubscriber(const sptr<IStandbyServiceSubscriber>& subscriber); 44 void ReportStandbyState(uint32_t curState); 45 void ReportAllowListChanged(int32_t uid, const std::string& name, uint32_t allowType, bool added); 46 void HandleSubscriberDeath(const wptr<IRemoteObject>& remote); 47 void ShellDump(const std::vector<std::string>& argsInStr, std::string& result); 48 void NotifyAllowChangedByCommonEvent(int32_t uid, const std::string& name, uint32_t allowType, bool added); 49 void NotifyPowerOverusedByCallback(const std::string& module, uint32_t level); 50 51 private: 52 void NotifyIdleModeByCallback(bool napped, bool sleeping); 53 void NotifyIdleModeByCommonEvent(bool napped, bool sleeping); 54 void NotifyAllowChangedByCallback(int32_t uid, const std::string& name, uint32_t allowType, bool added); 55 std::list<sptr<IStandbyServiceSubscriber>>::iterator FindSubcriberObject(sptr<IRemoteObject>& proxy); 56 void NotifyPowerOnRegister(const sptr<IStandbyServiceSubscriber>& subscriber); 57 58 private: 59 StandbyStateSubscriber(const StandbyStateSubscriber&) = delete; 60 StandbyStateSubscriber& operator= (const StandbyStateSubscriber&) = delete; 61 StandbyStateSubscriber(StandbyStateSubscriber&&) = delete; 62 StandbyStateSubscriber& operator= (StandbyStateSubscriber&&) = delete; 63 std::mutex subscriberLock_ {}; 64 std::list<sptr<IStandbyServiceSubscriber>> subscriberList_ {}; 65 sptr<SubscriberDeathRecipient> deathRecipient_ {nullptr}; 66 std::shared_ptr<IStateManagerAdapter> standbyStateManager_ {nullptr}; 67 std::unordered_map<std::string, uint32_t> modulePowerMap_; 68 int32_t curDate_; 69 }; 70 71 class SubscriberDeathRecipient final : public IRemoteObject::DeathRecipient { 72 public: 73 DISALLOW_COPY_AND_MOVE(SubscriberDeathRecipient); 74 explicit SubscriberDeathRecipient(); 75 ~SubscriberDeathRecipient() override; 76 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 77 }; 78 } // namespace DevStandbyMgr 79 } // namespace OHOS 80 #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_NOTIFICATION_INCLUDE_NOTIFICATION_HELPER_H 81