summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jean-Michel Trivi <jmtrivi@google.com> 2022-07-11 01:45:39 +0000
committer Jean-Michel Trivi <jmtrivi@google.com> 2022-12-05 23:30:44 +0000
commitdec1a1b6b7f780528516e777b24ce1639293c27c (patch)
tree829b66502dba43eafb068c0f88d930c626131d0f
parent2591d9de4e5eaea8d0466a062be17b087ffe858a (diff)
AudioService: do not log sound effects in audio dumpsys
"audio" dumpsys captures the logs from PlaybackActivityMonitor. This includes the activity of the SoundPool in AudioService which handles the sounds effects for the UI, such as touchsounds. But with touchsounds enabled, too many important player logs are lost as UI playback events fill the rolling window of logs. The fix consists in SoundEffectsHelper giving a handle of the PlayerBase used for effect playback to AudioService, which then tells PlaybackActivityMonitor to not log playback events for this player. Bug: 236983951 Test: with touch sounds enabled, verify events absent from dumpsys audio Change-Id: I6fb0289ef3b72e4dd505f9114dd59da174f53238
-rw-r--r--services/core/java/com/android/server/audio/AudioService.java22
-rw-r--r--services/core/java/com/android/server/audio/PlaybackActivityMonitor.java42
-rw-r--r--services/core/java/com/android/server/audio/SoundEffectsHelper.java8
3 files changed, 64 insertions, 8 deletions
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 8aa898edff9a..008d0f170883 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -257,6 +257,9 @@ public class AudioService extends IAudioService.Stub
/** Debug communication route */
protected static final boolean DEBUG_COMM_RTE = false;
+ /** Debug log sound fx (touchsounds...) in dumpsys */
+ protected static final boolean DEBUG_LOG_SOUND_FX = false;
+
/** How long to delay before persisting a change in volume/ringer mode. */
private static final int PERSIST_DELAY = 500;
@@ -378,6 +381,7 @@ public class AudioService extends IAudioService.Stub
private static final int MSG_ROTATION_UPDATE = 48;
private static final int MSG_FOLD_UPDATE = 49;
private static final int MSG_RESET_SPATIALIZER = 50;
+ private static final int MSG_NO_LOG_FOR_PLAYER_I = 51;
// start of messages handled under wakelock
// these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(),
@@ -1016,7 +1020,7 @@ public class AudioService extends IAudioService.Stub
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
mAudioEventWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "handleAudioEvent");
- mSfxHelper = new SoundEffectsHelper(mContext);
+ mSfxHelper = new SoundEffectsHelper(mContext, playerBase -> ignorePlayerLogs(playerBase));
final boolean headTrackingDefault = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_spatial_audio_head_tracking_enabled_default);
@@ -1500,6 +1504,18 @@ public class AudioService extends IAudioService.Stub
}
//-----------------------------------------------------------------
+ // Communicate to PlayackActivityMonitor whether to log or not
+ // the sound FX activity (useful for removing touch sounds in the activity logs)
+ void ignorePlayerLogs(@NonNull PlayerBase playerToIgnore) {
+ if (DEBUG_LOG_SOUND_FX) {
+ return;
+ }
+ sendMsg(mAudioHandler, MSG_NO_LOG_FOR_PLAYER_I, SENDMSG_REPLACE,
+ /*arg1, piid of the player*/ playerToIgnore.getPlayerIId(),
+ /*arg2 ignored*/ 0, /*obj ignored*/ null, /*delay*/ 0);
+ }
+
+ //-----------------------------------------------------------------
// monitoring requests for volume range initialization
@Override // AudioSystemAdapter.OnVolRangeInitRequestListener
public void onVolumeRangeInitRequestFromNative() {
@@ -8721,6 +8737,10 @@ public class AudioService extends IAudioService.Stub
// fold parameter format: "device_folded=x" where x is one of on, off
mAudioSystem.setParameters((String) msg.obj);
break;
+
+ case MSG_NO_LOG_FOR_PLAYER_I:
+ mPlaybackMonitor.ignorePlayerIId(msg.arg1);
+ break;
}
}
}
diff --git a/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java b/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
index 0bc4b20b4643..226d239307cf 100644
--- a/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
+++ b/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
@@ -191,6 +191,18 @@ public final class PlaybackActivityMonitor
}
//=================================================================
+ // Player to ignore (only handling single player, designed for ignoring
+ // in the logs one specific player such as the touch sounds player)
+ @GuardedBy("mPlayerLock")
+ private ArrayList<Integer> mDoNotLogPiidList = new ArrayList<>();
+
+ /*package*/ void ignorePlayerIId(int doNotLogPiid) {
+ synchronized (mPlayerLock) {
+ mDoNotLogPiidList.add(doNotLogPiid);
+ }
+ }
+
+ //=================================================================
// Track players and their states
// methods playerAttributes, playerEvent, releasePlayer are all oneway calls
// into AudioService. They trigger synchronous dispatchPlaybackChange() which updates
@@ -314,14 +326,18 @@ public final class PlaybackActivityMonitor
Log.v(TAG, TextUtils.formatSimple("playerEvent(piid=%d, event=%s, eventValue=%d)",
piid, AudioPlaybackConfiguration.playerStateToString(event), eventValue));
}
-
- final boolean change;
+ boolean change;
synchronized(mPlayerLock) {
final AudioPlaybackConfiguration apc = mPlayers.get(new Integer(piid));
if (apc == null) {
return;
}
+ final boolean doNotLog = mDoNotLogPiidList.contains(piid);
+ if (doNotLog && event != AudioPlaybackConfiguration.PLAYER_STATE_RELEASED) {
+ // do not log nor dispatch events for "ignored" players other than the release
+ return;
+ }
sEventLogger.enqueue(new PlayerEvent(piid, event, eventValue));
if (event == AudioPlaybackConfiguration.PLAYER_UPDATE_PORT_ID) {
@@ -338,7 +354,8 @@ public final class PlaybackActivityMonitor
}
}
}
- if (apc.getPlayerType() == AudioPlaybackConfiguration.PLAYER_TYPE_JAM_SOUNDPOOL) {
+ if (apc.getPlayerType() == AudioPlaybackConfiguration.PLAYER_TYPE_JAM_SOUNDPOOL
+ && event != AudioPlaybackConfiguration.PLAYER_STATE_RELEASED) {
// FIXME SoundPool not ready for state reporting
return;
}
@@ -350,9 +367,15 @@ public final class PlaybackActivityMonitor
Log.e(TAG, "Error handling event " + event);
change = false;
}
- if (change && event == AudioPlaybackConfiguration.PLAYER_STATE_STARTED) {
- mDuckingManager.checkDuck(apc);
- mFadingManager.checkFade(apc);
+ if (change) {
+ if (event == AudioPlaybackConfiguration.PLAYER_STATE_STARTED) {
+ mDuckingManager.checkDuck(apc);
+ mFadingManager.checkFade(apc);
+ }
+ if (doNotLog) {
+ // do not dispatch events for "ignored" players
+ change = false;
+ }
}
}
if (change) {
@@ -435,6 +458,10 @@ public final class PlaybackActivityMonitor
mEventHandler.sendMessage(
mEventHandler.obtainMessage(MSG_L_CLEAR_PORTS_FOR_PIID, piid, /*arg2=*/0));
+ if (change && mDoNotLogPiidList.contains(piid)) {
+ // do not dispatch a change for a "do not log" player
+ change = false;
+ }
}
}
if (change) {
@@ -560,6 +587,9 @@ public final class PlaybackActivityMonitor
for (Integer piidInt : piidIntList) {
final AudioPlaybackConfiguration apc = mPlayers.get(piidInt);
if (apc != null) {
+ if (mDoNotLogPiidList.contains(apc.getPlayerInterfaceId())) {
+ pw.print("(not logged)");
+ }
apc.dump(pw);
}
}
diff --git a/services/core/java/com/android/server/audio/SoundEffectsHelper.java b/services/core/java/com/android/server/audio/SoundEffectsHelper.java
index 79b54ebfeb3c..8c4efbae0a7c 100644
--- a/services/core/java/com/android/server/audio/SoundEffectsHelper.java
+++ b/services/core/java/com/android/server/audio/SoundEffectsHelper.java
@@ -25,6 +25,7 @@ import android.media.AudioSystem;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
+import android.media.PlayerBase;
import android.media.SoundPool;
import android.os.Environment;
import android.os.Handler;
@@ -47,6 +48,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.Consumer;
/**
* A helper class for managing sound effects loading / unloading
@@ -109,11 +111,14 @@ class SoundEffectsHelper {
private final int[] mEffects = new int[AudioManager.NUM_SOUND_EFFECTS]; // indexes in mResources
private SoundPool mSoundPool;
private SoundPoolLoader mSoundPoolLoader;
+ /** callback to provide handle to the player of the sound effects */
+ private final Consumer<PlayerBase> mPlayerAvailableCb;
- SoundEffectsHelper(Context context) {
+ SoundEffectsHelper(Context context, Consumer<PlayerBase> playerAvailableCb) {
mContext = context;
mSfxAttenuationDb = mContext.getResources().getInteger(
com.android.internal.R.integer.config_soundEffectVolumeDb);
+ mPlayerAvailableCb = playerAvailableCb;
startWorker();
}
@@ -189,6 +194,7 @@ class SoundEffectsHelper {
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build())
.build();
+ mPlayerAvailableCb.accept(mSoundPool);
loadSoundAssets();
mSoundPoolLoader = new SoundPoolLoader();