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 RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_OBSERVER_MANAGER_H 17 #define RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_OBSERVER_MANAGER_H 18 19 #include <memory> 20 #include "account_observer.h" 21 #include "app_state_observer.h" 22 #include "if_system_ability_manager.h" 23 #include "system_ability_status_change_stub.h" 24 #include "singleton.h" 25 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE 26 #include "audio_observer.h" 27 #endif 28 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE 29 #include "hisysevent_observer.h" 30 #endif 31 #include "connection_subscriber.h" 32 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE 33 #include "device_movement_observer.h" 34 #endif 35 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE 36 #include "sched_telephony_observer.h" 37 #endif 38 #ifdef MMI_ENABLE 39 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE 40 #include "mmi_observer.h" 41 #endif 42 #endif 43 #ifdef RESSCHED_MULTIMEDIA_AV_SESSION_ENABLE 44 #include "av_session_state_listener.h" 45 #endif 46 #include "fold_display_mode_observer.h" 47 #ifdef RESOURCE_REQUEST_REQUEST 48 #include "download_upload_observer.h" 49 #endif 50 #include "window_state_observer.h" 51 #ifdef CONFIG_BGTASK_MGR 52 #include "background_task_observer.h" 53 #endif 54 55 namespace OHOS { 56 namespace ResourceSchedule { 57 using ReportFunc = bool (*)(); 58 class ObserverManager : public DelayedSingleton<ObserverManager>, 59 public std::enable_shared_from_this<ObserverManager> { 60 public: ObserverManager()61 ObserverManager() {} ~ObserverManager()62 ~ObserverManager() {} 63 void Init(); 64 void Disable(); 65 66 private: 67 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 68 public: SystemAbilityStatusChangeListener()69 SystemAbilityStatusChangeListener() {}; 70 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 71 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 72 }; 73 74 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE 75 void InitHiSysEventObserver(); 76 void DisableHiSysEventObserver(); 77 #ifdef MMI_ENABLE 78 void GetAllMmiStatusData(); 79 #endif 80 #endif 81 #ifdef MMI_ENABLE 82 void InitMMiEventObserver(); 83 void DisableMMiEventObserver(); 84 #endif 85 void InitTelephonyObserver(); 86 void DisableTelephonyObserver(); 87 void InitAudioObserver(); 88 void DisableAudioObserver(); 89 void InitDeviceMovementObserver(); 90 void DisableDeviceMovementObserver(); 91 void InitDisplayModeObserver(); 92 void DisableDisplayModeObserver(); 93 void InitDisplayOrientationObserver(); 94 void DisableDisplayOrientationObserver(); 95 void InitSysAbilityListener(); 96 void AddItemToSysAbilityListener(int32_t systemAbilityId, sptr<ISystemAbilityManager>& systemAbilityManager); 97 void InitObserverCbMap(); 98 void InitRemoveObserverCbMap(); 99 void InitConnectionSubscriber(); 100 void DisableConnectionSubscriber(); 101 void GetReportFunc(); 102 void InitDataShareObserver(); 103 void DisableDataShareObserver(); 104 void InitAccountObserver(); 105 void DisableAccountObserver(); 106 void InitWindowStateObserver(); 107 void DisableWindowStateObserver(); 108 void SubscribeWindowModeChange(); 109 void SubscribePipChange(); 110 void UnsubscribeWindowModeChange(); 111 void UnsubscribePipChange(); 112 bool InitWindowStyleObserver(); 113 bool DisableWindowStyleObserver(); 114 void SubscribeAppState(); 115 void UnsubscribeAppState(); 116 #ifdef CONFIG_BGTASK_MGR 117 void InitBackgroundTask(); 118 void DisableBackgroundTask(); 119 #endif 120 #ifdef RESOURCE_REQUEST_REQUEST 121 void InitDownloadUploadObserver(); 122 void DisableDownloadUploadObserver(); 123 #endif 124 125 #ifdef RESSCHED_MULTIMEDIA_AV_SESSION_ENABLE 126 void InitAVSessionStateChangeListener(); 127 void DisableAVSessionStateChangeListener(); 128 std::shared_ptr<AvSessionStateListener> avSessionStateListener_ = nullptr; 129 #endif 130 131 pid_t pid_ = -1; 132 std::map<int32_t, std::function<void()>> handleObserverMap_; 133 std::map<int32_t, std::function<void()>> removeObserverMap_; 134 #ifdef RESOURCE_SCHEDULE_SERVICE_WITH_APP_NAP_ENABLE 135 std::shared_ptr<HiviewDFX::HiSysEventListener> hiSysEventObserver_ = nullptr; 136 #ifdef MMI_ENABLE 137 std::shared_ptr<MmiObserver> mmiEventObserver_ = nullptr; 138 #endif 139 #endif 140 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE 141 int32_t slotId_ = 0; 142 sptr<SchedTelephonyObserver> telephonyObserver_ = nullptr; 143 #endif 144 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE 145 std::shared_ptr<AudioObserver> audioObserver_ = nullptr; 146 #endif 147 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE 148 sptr<DeviceMovementObserver> deviceMovementObserver_ = nullptr; 149 #endif 150 sptr<SystemAbilityStatusChangeListener> sysAbilityListener_ = nullptr; 151 std::shared_ptr<ConnectionSubscriber> connectionSubscriber_ = nullptr; 152 sptr<FoldDisplayModeObserver> foldDisplayModeObserver_ = nullptr; 153 sptr<FoldDisplayOrientationObserver> foldDisplayOrientationObserver_ = nullptr; 154 #ifdef RESOURCE_REQUEST_REQUEST 155 std::shared_ptr<DownLoadUploadObserver> downLoadUploadObserver_ = nullptr; 156 #endif 157 std::shared_ptr<AccountObserver> accountObserver_ = nullptr; 158 sptr<PiPStateObserver> pipStateObserver_ = nullptr; 159 sptr<WindowStateObserver> windowStateObserver_ = nullptr; 160 sptr<WindowVisibilityObserver> windowVisibilityObserver_ = nullptr; 161 sptr<WindowDrawingContentObserver> windowDrawingContentObserver_ = nullptr; 162 sptr<WindowModeObserver> windowModeObserver_ = nullptr; 163 sptr<WindowStyleObserver> windowStyleObserver_ = nullptr; 164 sptr<RmsApplicationStateObserver> appStateObserver_ = nullptr; 165 #ifdef CONFIG_BGTASK_MGR 166 bool isBgtaskSubscribed_ {false}; 167 std::shared_ptr<BackgroundTaskObserver> backgroundTaskObserver_ = nullptr; 168 #endif 169 bool isNeedReport_ = true; 170 int32_t powerKeySubscribeId_ = -1; 171 }; 172 } // namespace ResourceSchedule 173 } // namespace OHOS 174 #endif // RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_OBSERVER_MANAGER_H 175