Loading services/core/java/com/android/server/audio/PlaybackActivityMonitor.java +23 −53 Original line number Diff line number Diff line Loading @@ -235,6 +235,10 @@ public final class PlaybackActivityMonitor public int trackPlayer(PlayerBase.PlayerIdCard pic) { final int newPiid = AudioSystem.newAudioPlayerId(); if (DEBUG) { Log.v(TAG, "trackPlayer() new piid=" + newPiid); } if (newPiid == PLAYER_PIID_INVALID) { Log.w(TAG, "invalid piid assigned from AudioSystem"); return newPiid; } final AudioPlaybackConfiguration apc = new AudioPlaybackConfiguration(pic, newPiid, Binder.getCallingUid(), Binder.getCallingPid()); Loading Loading @@ -365,8 +369,7 @@ public final class PlaybackActivityMonitor sEventLogger.enqueue(new PlayerEvent(piid, event, eventValue)); if (event == AudioPlaybackConfiguration.PLAYER_UPDATE_PORT_ID) { mEventHandler.sendMessage( mEventHandler.obtainMessage(MSG_II_UPDATE_PORT_EVENT, eventValue, piid)); mPortIdToPiid.put(eventValue, piid); return; } else if (event == AudioPlaybackConfiguration.PLAYER_STATE_STARTED) { for (Integer uidInteger: mBannedUids) { Loading Loading @@ -429,16 +432,12 @@ public final class PlaybackActivityMonitor synchronized (mPlayerLock) { int piid = mPortIdToPiid.get(portId, PLAYER_PIID_INVALID); if (piid == PLAYER_PIID_INVALID) { if (DEBUG) { Log.v(TAG, "No piid assigned for invalid/internal port id " + portId); } Log.w(TAG, "No piid assigned for invalid/internal port id " + portId); return; } final AudioPlaybackConfiguration apc = mPlayers.get(piid); if (apc == null) { if (DEBUG) { Log.v(TAG, "No AudioPlaybackConfiguration assigned for piid " + piid); } Log.w(TAG, "No AudioPlaybackConfiguration assigned for piid " + piid); return; } Loading Loading @@ -470,11 +469,18 @@ public final class PlaybackActivityMonitor public void releasePlayer(int piid, int binderUid) { if (DEBUG) { Log.v(TAG, "releasePlayer() for piid=" + piid); } boolean change = false; if (piid == PLAYER_PIID_INVALID) { Log.w(TAG, "Received releasePlayer with invalid piid: " + piid); sEventLogger.enqueue(new EventLogger.StringEvent("releasePlayer with invalid piid:" + piid + ", uid:" + binderUid)); return; } synchronized(mPlayerLock) { final AudioPlaybackConfiguration apc = mPlayers.get(new Integer(piid)); if (checkConfigurationCaller(piid, apc, binderUid)) { sEventLogger.enqueue(new EventLogger.StringEvent( "releasing player piid:" + piid)); "releasing player piid:" + piid + ", uid:" + binderUid)); mPlayers.remove(new Integer(piid)); mDuckingManager.removeReleased(apc); mFadeOutManager.removeReleased(apc); Loading @@ -484,8 +490,10 @@ public final class PlaybackActivityMonitor AudioPlaybackConfiguration.PLAYER_DEVICEID_INVALID); // remove all port ids mapped to the released player mEventHandler.sendMessage( mEventHandler.obtainMessage(MSG_I_CLEAR_PORTS_FOR_PIID, piid, /*arg2=*/0)); int portIdx; while ((portIdx = mPortIdToPiid.indexOfValue(piid)) >= 0) { mPortIdToPiid.removeAt(portIdx); } if (change && mDoNotLogPiidList.contains(piid)) { // do not dispatch a change for a "do not log" player Loading Loading @@ -1608,14 +1616,6 @@ public final class PlaybackActivityMonitor */ private static final int MSG_L_TIMEOUT_MUTE_AWAIT_CONNECTION = 1; /** * assign new port id to piid * args: * msg.arg1: port id * msg.arg2: piid */ private static final int MSG_II_UPDATE_PORT_EVENT = 2; /** * event for player getting muted * args: Loading @@ -1624,14 +1624,7 @@ public final class PlaybackActivityMonitor * msg.obj: extras describing the mute reason * type: PersistableBundle */ private static final int MSG_IIL_UPDATE_PLAYER_MUTED_EVENT = 3; /** * clear all ports assigned to a given piid * args: * msg.arg1: the piid */ private static final int MSG_I_CLEAR_PORTS_FOR_PIID = 4; private static final int MSG_IIL_UPDATE_PLAYER_MUTED_EVENT = 2; /** * event for player reporting playback format and spatialization status Loading @@ -1641,7 +1634,7 @@ public final class PlaybackActivityMonitor * msg.obj: extras describing the sample rate, channel mask, spatialized * type: PersistableBundle */ private static final int MSG_IIL_UPDATE_PLAYER_FORMAT = 5; private static final int MSG_IIL_UPDATE_PLAYER_FORMAT = 3; private void initEventHandler() { mEventThread = new HandlerThread(TAG); Loading @@ -1660,11 +1653,6 @@ public final class PlaybackActivityMonitor mMuteAwaitConnectionTimeoutCb.accept((AudioDeviceAttributes) msg.obj); break; case MSG_II_UPDATE_PORT_EVENT: synchronized (mPlayerLock) { mPortIdToPiid.put(/*portId*/msg.arg1, /*piid*/msg.arg2); } break; case MSG_IIL_UPDATE_PLAYER_MUTED_EVENT: // TODO: replace PersistableBundle with own struct PersistableBundle extras = (PersistableBundle) msg.obj; Loading @@ -1680,10 +1668,7 @@ public final class PlaybackActivityMonitor sEventLogger.enqueue( new PlayerEvent(piid, PLAYER_UPDATE_MUTED, eventValue)); final AudioPlaybackConfiguration apc; synchronized (mPlayerLock) { apc = mPlayers.get(piid); } final AudioPlaybackConfiguration apc = mPlayers.get(piid); if (apc == null || !apc.handleMutedEvent(eventValue)) { break; // do not dispatch } Loading @@ -1691,21 +1676,6 @@ public final class PlaybackActivityMonitor } break; case MSG_I_CLEAR_PORTS_FOR_PIID: int piid = msg.arg1; if (piid == AudioPlaybackConfiguration.PLAYER_PIID_INVALID) { Log.w(TAG, "Received clear ports with invalid piid"); break; } synchronized (mPlayerLock) { int portIdx; while ((portIdx = mPortIdToPiid.indexOfValue(piid)) >= 0) { mPortIdToPiid.removeAt(portIdx); } } break; case MSG_IIL_UPDATE_PLAYER_FORMAT: final PersistableBundle formatExtras = (PersistableBundle) msg.obj; if (formatExtras == null) { Loading Loading
services/core/java/com/android/server/audio/PlaybackActivityMonitor.java +23 −53 Original line number Diff line number Diff line Loading @@ -235,6 +235,10 @@ public final class PlaybackActivityMonitor public int trackPlayer(PlayerBase.PlayerIdCard pic) { final int newPiid = AudioSystem.newAudioPlayerId(); if (DEBUG) { Log.v(TAG, "trackPlayer() new piid=" + newPiid); } if (newPiid == PLAYER_PIID_INVALID) { Log.w(TAG, "invalid piid assigned from AudioSystem"); return newPiid; } final AudioPlaybackConfiguration apc = new AudioPlaybackConfiguration(pic, newPiid, Binder.getCallingUid(), Binder.getCallingPid()); Loading Loading @@ -365,8 +369,7 @@ public final class PlaybackActivityMonitor sEventLogger.enqueue(new PlayerEvent(piid, event, eventValue)); if (event == AudioPlaybackConfiguration.PLAYER_UPDATE_PORT_ID) { mEventHandler.sendMessage( mEventHandler.obtainMessage(MSG_II_UPDATE_PORT_EVENT, eventValue, piid)); mPortIdToPiid.put(eventValue, piid); return; } else if (event == AudioPlaybackConfiguration.PLAYER_STATE_STARTED) { for (Integer uidInteger: mBannedUids) { Loading Loading @@ -429,16 +432,12 @@ public final class PlaybackActivityMonitor synchronized (mPlayerLock) { int piid = mPortIdToPiid.get(portId, PLAYER_PIID_INVALID); if (piid == PLAYER_PIID_INVALID) { if (DEBUG) { Log.v(TAG, "No piid assigned for invalid/internal port id " + portId); } Log.w(TAG, "No piid assigned for invalid/internal port id " + portId); return; } final AudioPlaybackConfiguration apc = mPlayers.get(piid); if (apc == null) { if (DEBUG) { Log.v(TAG, "No AudioPlaybackConfiguration assigned for piid " + piid); } Log.w(TAG, "No AudioPlaybackConfiguration assigned for piid " + piid); return; } Loading Loading @@ -470,11 +469,18 @@ public final class PlaybackActivityMonitor public void releasePlayer(int piid, int binderUid) { if (DEBUG) { Log.v(TAG, "releasePlayer() for piid=" + piid); } boolean change = false; if (piid == PLAYER_PIID_INVALID) { Log.w(TAG, "Received releasePlayer with invalid piid: " + piid); sEventLogger.enqueue(new EventLogger.StringEvent("releasePlayer with invalid piid:" + piid + ", uid:" + binderUid)); return; } synchronized(mPlayerLock) { final AudioPlaybackConfiguration apc = mPlayers.get(new Integer(piid)); if (checkConfigurationCaller(piid, apc, binderUid)) { sEventLogger.enqueue(new EventLogger.StringEvent( "releasing player piid:" + piid)); "releasing player piid:" + piid + ", uid:" + binderUid)); mPlayers.remove(new Integer(piid)); mDuckingManager.removeReleased(apc); mFadeOutManager.removeReleased(apc); Loading @@ -484,8 +490,10 @@ public final class PlaybackActivityMonitor AudioPlaybackConfiguration.PLAYER_DEVICEID_INVALID); // remove all port ids mapped to the released player mEventHandler.sendMessage( mEventHandler.obtainMessage(MSG_I_CLEAR_PORTS_FOR_PIID, piid, /*arg2=*/0)); int portIdx; while ((portIdx = mPortIdToPiid.indexOfValue(piid)) >= 0) { mPortIdToPiid.removeAt(portIdx); } if (change && mDoNotLogPiidList.contains(piid)) { // do not dispatch a change for a "do not log" player Loading Loading @@ -1608,14 +1616,6 @@ public final class PlaybackActivityMonitor */ private static final int MSG_L_TIMEOUT_MUTE_AWAIT_CONNECTION = 1; /** * assign new port id to piid * args: * msg.arg1: port id * msg.arg2: piid */ private static final int MSG_II_UPDATE_PORT_EVENT = 2; /** * event for player getting muted * args: Loading @@ -1624,14 +1624,7 @@ public final class PlaybackActivityMonitor * msg.obj: extras describing the mute reason * type: PersistableBundle */ private static final int MSG_IIL_UPDATE_PLAYER_MUTED_EVENT = 3; /** * clear all ports assigned to a given piid * args: * msg.arg1: the piid */ private static final int MSG_I_CLEAR_PORTS_FOR_PIID = 4; private static final int MSG_IIL_UPDATE_PLAYER_MUTED_EVENT = 2; /** * event for player reporting playback format and spatialization status Loading @@ -1641,7 +1634,7 @@ public final class PlaybackActivityMonitor * msg.obj: extras describing the sample rate, channel mask, spatialized * type: PersistableBundle */ private static final int MSG_IIL_UPDATE_PLAYER_FORMAT = 5; private static final int MSG_IIL_UPDATE_PLAYER_FORMAT = 3; private void initEventHandler() { mEventThread = new HandlerThread(TAG); Loading @@ -1660,11 +1653,6 @@ public final class PlaybackActivityMonitor mMuteAwaitConnectionTimeoutCb.accept((AudioDeviceAttributes) msg.obj); break; case MSG_II_UPDATE_PORT_EVENT: synchronized (mPlayerLock) { mPortIdToPiid.put(/*portId*/msg.arg1, /*piid*/msg.arg2); } break; case MSG_IIL_UPDATE_PLAYER_MUTED_EVENT: // TODO: replace PersistableBundle with own struct PersistableBundle extras = (PersistableBundle) msg.obj; Loading @@ -1680,10 +1668,7 @@ public final class PlaybackActivityMonitor sEventLogger.enqueue( new PlayerEvent(piid, PLAYER_UPDATE_MUTED, eventValue)); final AudioPlaybackConfiguration apc; synchronized (mPlayerLock) { apc = mPlayers.get(piid); } final AudioPlaybackConfiguration apc = mPlayers.get(piid); if (apc == null || !apc.handleMutedEvent(eventValue)) { break; // do not dispatch } Loading @@ -1691,21 +1676,6 @@ public final class PlaybackActivityMonitor } break; case MSG_I_CLEAR_PORTS_FOR_PIID: int piid = msg.arg1; if (piid == AudioPlaybackConfiguration.PLAYER_PIID_INVALID) { Log.w(TAG, "Received clear ports with invalid piid"); break; } synchronized (mPlayerLock) { int portIdx; while ((portIdx = mPortIdToPiid.indexOfValue(piid)) >= 0) { mPortIdToPiid.removeAt(portIdx); } } break; case MSG_IIL_UPDATE_PLAYER_FORMAT: final PersistableBundle formatExtras = (PersistableBundle) msg.obj; if (formatExtras == null) { Loading