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 59 private: 60 MemMgrEventCenter(); 61 bool CreateRegisterHandler(); 62 void UnregisterEventObserver(); 63 bool RegisterEventObserver(); 64 void RegisterBgTaskObserver(); 65 void RegisterAccountObserver(); 66 void RegisterExtConnObserver(); 67 void RegisterAppStateObserver(); 68 void RegisterCommonEventObserver(); 69 void RegisterMemoryPressureObserver(); 70 void RegisterKswapdObserver(); 71 void HandlerRegisterEvent(int64_t registerEventId); 72 int regAccountObsRetry_ = 0; 73 int regAppStatusObsRetry_ = 0; 74 std::unique_ptr<AppExecFwk::AppMgrClient> appMgrClient_; 75 std::shared_ptr<AppExecFwk::EventHandler> regObsHandler_; 76 std::shared_ptr<ExtensionConnectionObserver> extConnObserver_; 77 std::shared_ptr<AccountObserver> accountObserver_; 78 std::shared_ptr<CommonEventObserver> commonEventObserver_; 79 #ifdef CONFIG_BGTASK_MGR 80 std::shared_ptr<BgTaskObserver> bgTaskObserver_; 81 #endif 82 std::shared_ptr<MemoryPressureObserver> memoryPressureObserver_; 83 std::shared_ptr<KswapdObserver> kswapdObserver_; 84 sptr<AppStateObserver> appStateObserver_; 85 }; 86 } // namespace Memory 87 } // namespace OHOS 88 #endif // OHOS_MEMORY_MEMMGR_EVENT_CENTER_H 89