Add log for OP_PLAY_AUDIO checking
Bug: 292244020
Test: flash and logcat with zen mode on/off
Change-Id: Ice0d4930f92c8420e61d4b8c743c3c31319c3bfd
diff --git a/services/audioflinger/PlaybackTracks.h b/services/audioflinger/PlaybackTracks.h
index 5f54e11..3e5501f 100644
--- a/services/audioflinger/PlaybackTracks.h
+++ b/services/audioflinger/PlaybackTracks.h
@@ -62,8 +62,8 @@
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;
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index ecea9eb..e93046e 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -568,9 +568,7 @@
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;
}
@@ -594,7 +592,6 @@
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),
@@ -614,10 +611,11 @@
// 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");
}
}
@@ -628,16 +626,16 @@
// 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) {
@@ -655,11 +653,11 @@
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);
@@ -1640,22 +1638,18 @@
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);
}
}