• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 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 class MemMgrEventCenter {
38     DECLARE_SINGLE_INSTANCE_BASE(MemMgrEventCenter);
39 
40 public:
41     ~MemMgrEventCenter();
42     bool Init();
43     void RetryRegisterEventObserver(int32_t systemAbilityId);
44     void Dump(int fd);
45     void RemoveEventObserver(int32_t systemAbilityId);
46 private:
47     MemMgrEventCenter();
48     bool CreateRegisterHandler();
49     void UnregisterEventObserver();
50     bool RegisterEventObserver();
51     void RegisterBgTaskObserver();
52     void RegisterAccountObserver();
53     void RegisterExtConnObserver();
54     void RegisterAppStateObserver();
55     void RegisterCommonEventObserver();
56     void RegisterMemoryPressureObserver();
57     int regAccountObsRetry_ = 0;
58     int regAppStatusObsRetry_ = 0;
59     std::unique_ptr<AppExecFwk::AppMgrClient> appMgrClient_;
60     std::shared_ptr<AppExecFwk::EventHandler> regObsHandler_;
61     std::shared_ptr<ExtensionConnectionObserver> extConnObserver_;
62     std::shared_ptr<AccountObserver> accountObserver_;
63     std::shared_ptr<CommonEventObserver> commonEventObserver_;
64 #ifdef CONFIG_BGTASK_MGR
65     std::shared_ptr<BgTaskObserver> bgTaskObserver_;
66 #endif
67     std::shared_ptr<MemoryPressureObserver> memoryPressureObserver_;
68     sptr<AppStateObserver> appStateObserver_;
69 };
70 } // namespace Memory
71 } // namespace OHOS
72 #endif // OHOS_MEMORY_MEMMGR_EVENT_CENTER_H
73