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