• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void NotifyLowpowerActionByCallback(const std::string& module, uint32_t action);
51 
52 private:
53     void NotifyIdleModeByCallback(bool napped, bool sleeping);
54     void NotifyIdleModeByCommonEvent(bool napped, bool sleeping);
55     void NotifyAllowChangedByCallback(int32_t uid, const std::string& name, uint32_t allowType, bool added);
56     std::list<sptr<IStandbyServiceSubscriber>>::iterator FindSubcriberObject(sptr<IRemoteObject>& proxy);
57     void NotifyPowerOnRegister(const sptr<IStandbyServiceSubscriber>& subscriber);
58     void NotifyLowpowerActionOnRegister(const sptr<IStandbyServiceSubscriber>& subscriber);
59     void UpdateCallBackMap(std::mutex& moduleLock, std::unordered_map<std::string, uint32_t>& callBackMap,
60         const std::string& module, uint32_t value);
61 
62 private:
63     StandbyStateSubscriber(const StandbyStateSubscriber&) = delete;
64     StandbyStateSubscriber& operator= (const StandbyStateSubscriber&) = delete;
65     StandbyStateSubscriber(StandbyStateSubscriber&&) = delete;
66     StandbyStateSubscriber& operator= (StandbyStateSubscriber&&) = delete;
67     std::mutex subscriberLock_ {};
68     std::mutex modulePowerLock_ {};
69     std::mutex moduleActionLock_ {};
70     std::list<sptr<IStandbyServiceSubscriber>> subscriberList_ {};
71     sptr<SubscriberDeathRecipient> deathRecipient_ {nullptr};
72     std::shared_ptr<IStateManagerAdapter> standbyStateManager_ {nullptr};
73     std::unordered_map<std::string, uint32_t> modulePowerMap_;
74     std::unordered_map<std::string, uint32_t> moduleActionMap_;
75     int32_t curDate_;
76 };
77 
78 class SubscriberDeathRecipient final : public IRemoteObject::DeathRecipient {
79 public:
80     DISALLOW_COPY_AND_MOVE(SubscriberDeathRecipient);
81     explicit SubscriberDeathRecipient();
82     ~SubscriberDeathRecipient() override;
83     void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
84 };
85 }  // namespace DevStandbyMgr
86 }  // namespace OHOS
87 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_NOTIFICATION_INCLUDE_NOTIFICATION_HELPER_H
88