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