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 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 23 #include "audio_observer.h" 24 #include "camera_observer.h" 25 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE 26 #include "device_movement_observer.h" 27 #endif 28 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE 29 #include "sched_telephony_observer.h" 30 #endif 31 32 namespace OHOS { 33 namespace ResourceSchedule { 34 class ObserverManager { 35 DECLARE_SINGLE_INSTANCE_BASE(ObserverManager); 36 37 public: ObserverManager()38 ObserverManager() {} ~ObserverManager()39 ~ObserverManager() {} 40 void Init(); 41 void Disable(); 42 43 private: 44 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 45 public: SystemAbilityStatusChangeListener()46 SystemAbilityStatusChangeListener() {}; 47 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 48 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 49 }; 50 51 void InitCameraObserver(); 52 void DisableCameraObserver(); 53 void InitTelephonyObserver(); 54 void DisableTelephonyObserver(); 55 void InitAudioObserver(); 56 void DisableAudioObserver(); 57 void InitDeviceMovementObserver(); 58 void DisableDeviceMovementObserver(); 59 void InitSysAbilityListener(); 60 void AddItemToSysAbilityListener(int32_t systemAbilityId, sptr<ISystemAbilityManager>& systemAbilityManager); 61 62 pid_t pid_ = -1; 63 std::map<int32_t, std::function<void(ObserverManager *)>> handleObserverMap_; 64 std::map<int32_t, std::function<void(ObserverManager *)>> removeObserverMap_; 65 std::shared_ptr<HiviewDFX::HiSysEventListener> cameraObserver_ = nullptr; 66 #ifdef RESSCHED_TELEPHONY_STATE_REGISTRY_ENABLE 67 int32_t slotId_ = 0; 68 sptr<SchedTelephonyObserver> telephonyObserver_ = nullptr; 69 #endif 70 std::shared_ptr<AudioObserver> audioObserver_ = nullptr; 71 #ifdef DEVICE_MOVEMENT_PERCEPTION_ENABLE 72 sptr<DeviceMovementObserver> deviceMovementObserver_ = nullptr; 73 #endif 74 sptr<SystemAbilityStatusChangeListener> sysAbilityListener_ = nullptr; 75 }; 76 } // namespace ResourceSchedule 77 } // namespace OHOS 78 #endif // RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_OBSERVER_MANAGER_H 79