1 /* 2 * Copyright (c) 2023-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 ST_POWER_STATE_LISTENER_H 17 #define ST_POWER_STATE_LISTENER_H 18 19 #include <iremote_stub.h> 20 #include <audio_interrupt_info.h> 21 22 #include "suspend/isync_sleep_callback.h" 23 #include "suspend/sleep_priority.h" 24 #include "power_mgr_client.h" 25 26 namespace OHOS { 27 namespace AudioStandard { 28 using namespace OHOS::PowerMgr; 29 class AudioPolicyServer; 30 class PowerListerMethods { 31 public: 32 PowerListerMethods() = default; 33 virtual ~PowerListerMethods() = default; 34 static void InitAudioInterruptInfo(AudioInterrupt& audioInterrupt); 35 }; 36 37 class PowerStateListenerStub : public IRemoteStub<ISyncSleepCallback> { 38 public: 39 PowerStateListenerStub() = default; 40 virtual ~PowerStateListenerStub() = default; 41 DISALLOW_COPY_AND_MOVE(PowerStateListenerStub); 42 43 virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, 44 MessageParcel &reply, MessageOption &option) override; 45 46 private: 47 int32_t OnSyncSleepCallbackStub(MessageParcel &data); 48 int32_t OnSyncWakeupCallbackStub(MessageParcel &data); 49 }; 50 51 class PowerStateListener : public PowerStateListenerStub { 52 public: 53 explicit PowerStateListener(const sptr<AudioPolicyServer> audioPolicyServer); ~PowerStateListener()54 virtual ~PowerStateListener() {} 55 void OnSyncSleep(bool OnForceSleep) override; 56 void OnSyncWakeup(bool OnForceSleep) override; 57 58 private: 59 void ControlAudioFocus(bool applyFocus); 60 sptr<AudioPolicyServer> audioPolicyServer_; 61 }; 62 63 class SyncHibernateListenerStub : public IRemoteStub<ISyncHibernateCallback> { 64 public: 65 SyncHibernateListenerStub() = default; 66 virtual ~SyncHibernateListenerStub() = default; 67 DISALLOW_COPY_AND_MOVE(SyncHibernateListenerStub); 68 69 virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, 70 MessageParcel &reply, MessageOption &option) override; 71 72 private: 73 int32_t OnSyncHibernateCallbackStub(); 74 int32_t OnSyncWakeupCallbackStub(); 75 }; 76 77 class SyncHibernateListener : public SyncHibernateListenerStub { 78 public: 79 explicit SyncHibernateListener(const sptr<AudioPolicyServer> audioPolicyServer); ~SyncHibernateListener()80 virtual ~SyncHibernateListener() {} 81 void OnSyncHibernate() override; 82 void OnSyncWakeup() override; 83 84 private: 85 void ControlAudioFocus(bool isHibernate); 86 sptr<AudioPolicyServer> audioPolicyServer_; 87 }; 88 } // namespace AudioStandard 89 } // namespace OHOS 90 91 #endif // ST_POWER_STATE_LISTENER_H 92