Loading services/audioflinger/PlaybackTracks.h +1 −1 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ private: sp<PlayAudioOpCallback> mOpCallback; // called by PlayAudioOpCallback when OP_PLAY_AUDIO is updated in AppOp callback void checkPlayAudioForUsage(); void checkPlayAudioForUsage(bool doBroadcast); wp<AudioFlinger::ThreadBase> mThread; std::atomic_bool mHasOpPlayAudio; Loading services/audioflinger/Tracks.cpp +12 −8 Original line number Diff line number Diff line Loading @@ -564,7 +564,9 @@ AudioFlinger::PlaybackThread::OpPlayAudioMonitor::~OpPlayAudioMonitor() void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::onFirstRef() { checkPlayAudioForUsage(); // make sure not to broadcast the initial state since it is not needed and could // cause a deadlock since this method can be called with the mThread->mLock held checkPlayAudioForUsage(/*doBroadcast=*/false); if (mAttributionSource.packageName.has_value()) { mOpCallback = new PlayAudioOpCallback(this); mAppOpsManager.startWatchingMode(AppOpsManager::OP_PLAY_AUDIO, Loading @@ -579,7 +581,7 @@ bool AudioFlinger::PlaybackThread::OpPlayAudioMonitor::hasOpPlayAudio() const { // Note this method is never called (and never to be) for audio server / patch record track // - not called from constructor due to check on UID, // - not called from PlayAudioOpCallback because the callback is not installed in this case void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::checkPlayAudioForUsage() void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::checkPlayAudioForUsage(bool doBroadcast) { const bool hasAppOps = mAttributionSource.packageName.has_value() && mAppOpsManager.checkAudioOpNoThrow( Loading @@ -589,6 +591,7 @@ void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::checkPlayAudioForUsage() bool shouldChange = !hasAppOps; // check if we need to update. if (mHasOpPlayAudio.compare_exchange_strong(shouldChange, hasAppOps)) { ALOGD("OpPlayAudio: track:%d usage:%d %smuted", mId, mUsage, hasAppOps ? "not " : ""); if (doBroadcast) { auto thread = mThread.promote(); if (thread != nullptr && thread->type() == AudioFlinger::ThreadBase::OFFLOAD) { // Wake up Thread if offloaded, otherwise it may be several seconds for update. Loading @@ -597,6 +600,7 @@ void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::checkPlayAudioForUsage() } } } } AudioFlinger::PlaybackThread::OpPlayAudioMonitor::PlayAudioOpCallback::PlayAudioOpCallback( const wp<OpPlayAudioMonitor>& monitor) : mMonitor(monitor) Loading @@ -611,7 +615,7 @@ void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::PlayAudioOpCallback::opCh } sp<OpPlayAudioMonitor> monitor = mMonitor.promote(); if (monitor != NULL) { monitor->checkPlayAudioForUsage(); monitor->checkPlayAudioForUsage(/*doBroadcast=*/true); } } Loading Loading
services/audioflinger/PlaybackTracks.h +1 −1 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ private: sp<PlayAudioOpCallback> mOpCallback; // called by PlayAudioOpCallback when OP_PLAY_AUDIO is updated in AppOp callback void checkPlayAudioForUsage(); void checkPlayAudioForUsage(bool doBroadcast); wp<AudioFlinger::ThreadBase> mThread; std::atomic_bool mHasOpPlayAudio; Loading
services/audioflinger/Tracks.cpp +12 −8 Original line number Diff line number Diff line Loading @@ -564,7 +564,9 @@ AudioFlinger::PlaybackThread::OpPlayAudioMonitor::~OpPlayAudioMonitor() void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::onFirstRef() { checkPlayAudioForUsage(); // make sure not to broadcast the initial state since it is not needed and could // cause a deadlock since this method can be called with the mThread->mLock held checkPlayAudioForUsage(/*doBroadcast=*/false); if (mAttributionSource.packageName.has_value()) { mOpCallback = new PlayAudioOpCallback(this); mAppOpsManager.startWatchingMode(AppOpsManager::OP_PLAY_AUDIO, Loading @@ -579,7 +581,7 @@ bool AudioFlinger::PlaybackThread::OpPlayAudioMonitor::hasOpPlayAudio() const { // Note this method is never called (and never to be) for audio server / patch record track // - not called from constructor due to check on UID, // - not called from PlayAudioOpCallback because the callback is not installed in this case void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::checkPlayAudioForUsage() void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::checkPlayAudioForUsage(bool doBroadcast) { const bool hasAppOps = mAttributionSource.packageName.has_value() && mAppOpsManager.checkAudioOpNoThrow( Loading @@ -589,6 +591,7 @@ void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::checkPlayAudioForUsage() bool shouldChange = !hasAppOps; // check if we need to update. if (mHasOpPlayAudio.compare_exchange_strong(shouldChange, hasAppOps)) { ALOGD("OpPlayAudio: track:%d usage:%d %smuted", mId, mUsage, hasAppOps ? "not " : ""); if (doBroadcast) { auto thread = mThread.promote(); if (thread != nullptr && thread->type() == AudioFlinger::ThreadBase::OFFLOAD) { // Wake up Thread if offloaded, otherwise it may be several seconds for update. Loading @@ -597,6 +600,7 @@ void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::checkPlayAudioForUsage() } } } } AudioFlinger::PlaybackThread::OpPlayAudioMonitor::PlayAudioOpCallback::PlayAudioOpCallback( const wp<OpPlayAudioMonitor>& monitor) : mMonitor(monitor) Loading @@ -611,7 +615,7 @@ void AudioFlinger::PlaybackThread::OpPlayAudioMonitor::PlayAudioOpCallback::opCh } sp<OpPlayAudioMonitor> monitor = mMonitor.promote(); if (monitor != NULL) { monitor->checkPlayAudioForUsage(); monitor->checkPlayAudioForUsage(/*doBroadcast=*/true); } } Loading