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 "if_system_ability_manager.h" 20 #include "system_ability_status_change_stub.h" 21 #include "single_instance.h" 22 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE 23 #include "audio_observer.h" 24 #endif 25 #include "hisysevent_observer.h" 26 #include "connection_subscriber.h" 27 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE 28 #include "device_movement_observer.h" 29 #endif 30 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE 31 #include "sched_telephony_observer.h" 32 #endif 33 #include "mmi_observer.h" 34 #ifdef RESSCHED_MULTIMEDIA_AV_SESSION_ENABLE 35 #include "av_session_state_listener.h" 36 #endif 37 38 namespace OHOS { 39 namespace ResourceSchedule { 40 using ReportFunc = bool (*)(); 41 class ObserverManager { 42 DECLARE_SINGLE_INSTANCE_BASE(ObserverManager); 43 44 public: ObserverManager()45 ObserverManager() {} ~ObserverManager()46 ~ObserverManager() {} 47 void Init(); 48 void Disable(); 49 50 private: 51 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 52 public: SystemAbilityStatusChangeListener()53 SystemAbilityStatusChangeListener() {}; 54 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 55 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 56 }; 57 58 void InitHiSysEventObserver(); 59 void DisableHiSysEventObserver(); 60 void InitTelephonyObserver(); 61 void DisableTelephonyObserver(); 62 void InitAudioObserver(); 63 void DisableAudioObserver(); 64 void InitDeviceMovementObserver(); 65 void DisableDeviceMovementObserver(); 66 void InitMMiEventObserver(); 67 void DisableMMiEventObserver(); 68 void InitSysAbilityListener(); 69 void AddItemToSysAbilityListener(int32_t systemAbilityId, sptr<ISystemAbilityManager>& systemAbilityManager); 70 void GetAllMmiStatusData(); 71 void InitObserverCbMap(); 72 void InitConnectionSubscriber(); 73 void DisableConnectionSubscriber(); 74 void GetReportFunc(); 75 #ifdef RESSCHED_MULTIMEDIA_AV_SESSION_ENABLE 76 void InitAVSessionStateChangeListener(); 77 void DisableAVSessionStateChangeListener(); 78 std::shared_ptr<AvSessionStateListener> avSessionStateListener_ = nullptr; 79 #endif 80 81 pid_t pid_ = -1; 82 std::map<int32_t, std::function<void(ObserverManager *)>> handleObserverMap_; 83 std::map<int32_t, std::function<void(ObserverManager *)>> removeObserverMap_; 84 std::shared_ptr<HiviewDFX::HiSysEventListener> hiSysEventObserver_ = nullptr; 85 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE 86 int32_t slotId_ = 0; 87 sptr<SchedTelephonyObserver> telephonyObserver_ = nullptr; 88 #endif 89 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE 90 std::shared_ptr<AudioObserver> audioObserver_ = nullptr; 91 #endif 92 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE 93 sptr<DeviceMovementObserver> deviceMovementObserver_ = nullptr; 94 #endif 95 sptr<SystemAbilityStatusChangeListener> sysAbilityListener_ = nullptr; 96 std::shared_ptr<MmiObserver> mmiEventObserver_ = nullptr; 97 std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> mmiStatusData_; 98 std::shared_ptr<ConnectionSubscriber> connectionSubscriber_ = nullptr; 99 ReportFunc reportFunc_ = nullptr; 100 bool isNeedReport_ = true; 101 }; 102 } // namespace ResourceSchedule 103 } // namespace OHOS 104 #endif // RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_OBSERVER_MANAGER_H 105