• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 OHOS_MEMORY_MEMMGR_EVENT_CENTER_H
17 #define OHOS_MEMORY_MEMMGR_EVENT_CENTER_H
18 
19 #include "single_instance.h"
20 #include "event_handler.h"
21 #include "extension_connection_observer.h"
22 #include "common_event_observer.h"
23 #include "account_observer.h"
24 #include "memory_pressure_observer.h"
25 #ifdef CONFIG_BGTASK_MGR
26 #include "bg_task_observer.h"
27 #endif
28 #include "system_ability_definition.h"
29 #include "app_mgr_interface.h"
30 #include "iservice_registry.h"
31 #include "app_process_data.h"
32 #include "app_mgr_client.h"
33 #include "app_state_observer.h"
34 
35 namespace OHOS {
36 namespace Memory {
37 enum RegisterEvent : int64_t {
38     REG_ALLOBS_EVENT = 0,
39     REG_MEMPRESSOBS_EVENT,
40     REG_APPOBS_EVENT,
41     REG_EXTOBS_EVENT,
42     REG_ACCOUNTOBS_EVENT,
43     REG_COMMONOBS_EVENT,
44     REG_BGTASKOBS_EVENT,
45 };
46 
47 class MemMgrEventCenter {
48     DECLARE_SINGLE_INSTANCE_BASE(MemMgrEventCenter);
49 
50 public:
51     ~MemMgrEventCenter();
52     bool Init();
53     void RetryRegisterEventObserver(int32_t systemAbilityId);
54     void Dump(int fd);
55     void RemoveEventObserver(int32_t systemAbilityId);
56 private:
57     MemMgrEventCenter();
58     bool CreateRegisterHandler();
59     void UnregisterEventObserver();
60     bool RegisterEventObserver();
61     void RegisterBgTaskObserver();
62     void RegisterAccountObserver();
63     void RegisterExtConnObserver();
64     void RegisterAppStateObserver();
65     void RegisterCommonEventObserver();
66     void RegisterMemoryPressureObserver();
67     void HandlerRegisterEvent(int64_t registerEventId);
68     int regAccountObsRetry_ = 0;
69     int regAppStatusObsRetry_ = 0;
70     std::unique_ptr<AppExecFwk::AppMgrClient> appMgrClient_;
71     std::shared_ptr<AppExecFwk::EventHandler> regObsHandler_;
72     std::shared_ptr<ExtensionConnectionObserver> extConnObserver_;
73     std::shared_ptr<AccountObserver> accountObserver_;
74     std::shared_ptr<CommonEventObserver> commonEventObserver_;
75 #ifdef CONFIG_BGTASK_MGR
76     std::shared_ptr<BgTaskObserver> bgTaskObserver_;
77 #endif
78     std::shared_ptr<MemoryPressureObserver> memoryPressureObserver_;
79     sptr<AppStateObserver> appStateObserver_;
80 };
81 } // namespace Memory
82 } // namespace OHOS
83 #endif // OHOS_MEMORY_MEMMGR_EVENT_CENTER_H
84