Loading services/audioflinger/PlaybackTracks.h +2 −2 Original line number Diff line number Diff line Loading @@ -62,8 +62,8 @@ private: wp<IAfThreadBase> mThread; std::atomic_bool mHasOpPlayAudio; const AttributionSourceState mAttributionSource; const int32_t mUsage; // on purpose not audio_usage_t because always checked in appOps as int32_t const int32_t mUsage; // on purpose not audio_usage_t because always checked in appOps as // int32_t const int mId; // for logging purposes only const uid_t mUid; const String16 mPackageName; Loading services/audioflinger/Tracks.cpp +20 −26 Original line number Diff line number Diff line Loading @@ -568,9 +568,7 @@ sp<OpPlayAudioMonitor> OpPlayAudioMonitor::createIfNeeded( getPackagesForUid(uid, packages); if (isServiceUid(uid)) { if (packages.isEmpty()) { ALOGD("OpPlayAudio: not muting track:%d usage:%d for service UID %d", id, attr.usage, ALOGW("OpPlayAudio: not muting track:%d usage:%d for service UID %d", id, attr.usage, uid); return nullptr; } Loading @@ -594,7 +592,6 @@ OpPlayAudioMonitor::OpPlayAudioMonitor(IAfThreadBase* thread, audio_usage_t usage, int id, uid_t uid) : mThread(wp<IAfThreadBase>::fromExisting(thread)), mHasOpPlayAudio(true), mAttributionSource(attributionSource), mUsage((int32_t)usage), mId(id), mUid(uid), Loading @@ -614,10 +611,11 @@ void OpPlayAudioMonitor::onFirstRef() // 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()) { if (mPackageName.size()) { mOpCallback = new PlayAudioOpCallback(this); mAppOpsManager.startWatchingMode(AppOpsManager::OP_PLAY_AUDIO, mPackageName, mOpCallback); mAppOpsManager.startWatchingMode(AppOpsManager::OP_PLAY_AUDIO, mPackageName, mOpCallback); } else { ALOGW("Skipping OpPlayAudioMonitor due to null package name"); } } Loading @@ -628,16 +626,16 @@ bool 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 OpPlayAudioMonitor::checkPlayAudioForUsage(bool doBroadcast) { const bool hasAppOps = mAttributionSource.packageName.has_value() && mAppOpsManager.checkAudioOpNoThrow( AppOpsManager::OP_PLAY_AUDIO, mUsage, mUid, mPackageName) == AppOpsManager::MODE_ALLOWED; void OpPlayAudioMonitor::checkPlayAudioForUsage(bool doBroadcast) { const bool hasAppOps = mPackageName.size() && mAppOpsManager.checkAudioOpNoThrow(AppOpsManager::OP_PLAY_AUDIO, mUsage, mUid, mPackageName) == AppOpsManager::MODE_ALLOWED; 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 " : ""); ALOGI("OpPlayAudio: track:%d package:%s usage:%d %smuted", mId, String8(mPackageName).string(), mUsage, hasAppOps ? "not " : ""); if (doBroadcast) { auto thread = mThread.promote(); if (thread != nullptr && thread->type() == IAfThreadBase::OFFLOAD) { Loading @@ -655,11 +653,11 @@ OpPlayAudioMonitor::PlayAudioOpCallback::PlayAudioOpCallback( void OpPlayAudioMonitor::PlayAudioOpCallback::opChanged(int32_t op, const String16& packageName) { // we only have uid, so we need to check all package names anyway UNUSED(packageName); if (op != AppOpsManager::OP_PLAY_AUDIO) { return; } ALOGI("%s OP_PLAY_AUDIO callback received for %s", __func__, String8(packageName).string()); sp<OpPlayAudioMonitor> monitor = mMonitor.promote(); if (monitor != NULL) { monitor->checkPlayAudioForUsage(/*doBroadcast=*/true); Loading Loading @@ -1640,22 +1638,18 @@ void Track::processMuteEvent_l(const sp< if (mMuteEventExtras == nullptr) { mMuteEventExtras = std::make_unique<os::PersistableBundle>(); } mMuteEventExtras->putInt(String16(kExtraPlayerEventMuteKey), static_cast<int>(muteState)); mMuteEventExtras->putInt(String16(kExtraPlayerEventMuteKey), static_cast<int>(muteState)); result = audioManager->portEvent(mPortId, PLAYER_UPDATE_MUTED, mMuteEventExtras); result = audioManager->portEvent(mPortId, PLAYER_UPDATE_MUTED, mMuteEventExtras); } if (result == OK) { ALOGI("%s(%d): processed mute state for port ID %d from %d to %d", __func__, id(), mPortId, int(muteState), int(mMuteState)); mMuteState = muteState; } else { ALOGW("%s(%d): cannot process mute state for port ID %d, status error %d", __func__, id(), mPortId, result); ALOGW("%s(%d): cannot process mute state for port ID %d, status error %d", __func__, id(), mPortId, result); } } Loading Loading
services/audioflinger/PlaybackTracks.h +2 −2 Original line number Diff line number Diff line Loading @@ -62,8 +62,8 @@ private: wp<IAfThreadBase> mThread; std::atomic_bool mHasOpPlayAudio; const AttributionSourceState mAttributionSource; const int32_t mUsage; // on purpose not audio_usage_t because always checked in appOps as int32_t const int32_t mUsage; // on purpose not audio_usage_t because always checked in appOps as // int32_t const int mId; // for logging purposes only const uid_t mUid; const String16 mPackageName; Loading
services/audioflinger/Tracks.cpp +20 −26 Original line number Diff line number Diff line Loading @@ -568,9 +568,7 @@ sp<OpPlayAudioMonitor> OpPlayAudioMonitor::createIfNeeded( getPackagesForUid(uid, packages); if (isServiceUid(uid)) { if (packages.isEmpty()) { ALOGD("OpPlayAudio: not muting track:%d usage:%d for service UID %d", id, attr.usage, ALOGW("OpPlayAudio: not muting track:%d usage:%d for service UID %d", id, attr.usage, uid); return nullptr; } Loading @@ -594,7 +592,6 @@ OpPlayAudioMonitor::OpPlayAudioMonitor(IAfThreadBase* thread, audio_usage_t usage, int id, uid_t uid) : mThread(wp<IAfThreadBase>::fromExisting(thread)), mHasOpPlayAudio(true), mAttributionSource(attributionSource), mUsage((int32_t)usage), mId(id), mUid(uid), Loading @@ -614,10 +611,11 @@ void OpPlayAudioMonitor::onFirstRef() // 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()) { if (mPackageName.size()) { mOpCallback = new PlayAudioOpCallback(this); mAppOpsManager.startWatchingMode(AppOpsManager::OP_PLAY_AUDIO, mPackageName, mOpCallback); mAppOpsManager.startWatchingMode(AppOpsManager::OP_PLAY_AUDIO, mPackageName, mOpCallback); } else { ALOGW("Skipping OpPlayAudioMonitor due to null package name"); } } Loading @@ -628,16 +626,16 @@ bool 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 OpPlayAudioMonitor::checkPlayAudioForUsage(bool doBroadcast) { const bool hasAppOps = mAttributionSource.packageName.has_value() && mAppOpsManager.checkAudioOpNoThrow( AppOpsManager::OP_PLAY_AUDIO, mUsage, mUid, mPackageName) == AppOpsManager::MODE_ALLOWED; void OpPlayAudioMonitor::checkPlayAudioForUsage(bool doBroadcast) { const bool hasAppOps = mPackageName.size() && mAppOpsManager.checkAudioOpNoThrow(AppOpsManager::OP_PLAY_AUDIO, mUsage, mUid, mPackageName) == AppOpsManager::MODE_ALLOWED; 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 " : ""); ALOGI("OpPlayAudio: track:%d package:%s usage:%d %smuted", mId, String8(mPackageName).string(), mUsage, hasAppOps ? "not " : ""); if (doBroadcast) { auto thread = mThread.promote(); if (thread != nullptr && thread->type() == IAfThreadBase::OFFLOAD) { Loading @@ -655,11 +653,11 @@ OpPlayAudioMonitor::PlayAudioOpCallback::PlayAudioOpCallback( void OpPlayAudioMonitor::PlayAudioOpCallback::opChanged(int32_t op, const String16& packageName) { // we only have uid, so we need to check all package names anyway UNUSED(packageName); if (op != AppOpsManager::OP_PLAY_AUDIO) { return; } ALOGI("%s OP_PLAY_AUDIO callback received for %s", __func__, String8(packageName).string()); sp<OpPlayAudioMonitor> monitor = mMonitor.promote(); if (monitor != NULL) { monitor->checkPlayAudioForUsage(/*doBroadcast=*/true); Loading Loading @@ -1640,22 +1638,18 @@ void Track::processMuteEvent_l(const sp< if (mMuteEventExtras == nullptr) { mMuteEventExtras = std::make_unique<os::PersistableBundle>(); } mMuteEventExtras->putInt(String16(kExtraPlayerEventMuteKey), static_cast<int>(muteState)); mMuteEventExtras->putInt(String16(kExtraPlayerEventMuteKey), static_cast<int>(muteState)); result = audioManager->portEvent(mPortId, PLAYER_UPDATE_MUTED, mMuteEventExtras); result = audioManager->portEvent(mPortId, PLAYER_UPDATE_MUTED, mMuteEventExtras); } if (result == OK) { ALOGI("%s(%d): processed mute state for port ID %d from %d to %d", __func__, id(), mPortId, int(muteState), int(mMuteState)); mMuteState = muteState; } else { ALOGW("%s(%d): cannot process mute state for port ID %d, status error %d", __func__, id(), mPortId, result); ALOGW("%s(%d): cannot process mute state for port ID %d, status error %d", __func__, id(), mPortId, result); } } Loading