OSDN Git Service

Fix the finding logic of MediaButtonSession
authorSungsoo <sungsoo@google.com>
Fri, 9 Jun 2017 03:59:47 +0000 (12:59 +0900)
committerSungsoo <sungsoo@google.com>
Fri, 9 Jun 2017 04:55:48 +0000 (13:55 +0900)
When we find a media button session with the given UID, we should
ignore the sessions whose playback state is not set.

Bug: 62373831
Test: passed CtsMediaTestCases
Change-Id: I484c888c5bdbceb85dd4524c1353906efc0c4f02

services/core/java/com/android/server/media/MediaSessionRecord.java
services/core/java/com/android/server/media/MediaSessionStack.java

index a275f49..89e1050 100644 (file)
@@ -320,6 +320,15 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
     }
 
     /**
+     * Get the playback state.
+     *
+     * @return The current playback state.
+     */
+    public PlaybackState getPlaybackState() {
+        return mPlaybackState;
+    }
+
+    /**
      * Check if the session is currently performing playback.
      *
      * @return True if the session is performing playback, false otherwise.
index f474769..8431311 100644 (file)
@@ -153,7 +153,7 @@ class MediaSessionStack {
             mCachedVolumeDefault = null;
         }
 
-        // In most cases, playback state isn't needed for finding media buttion session,
+        // In most cases, playback state isn't needed for finding media button session,
         // but we only use it as a hint if an app has multiple local media sessions.
         // In that case, we pick the media session whose PlaybackState matches
         // the audio playback configuration.
@@ -204,8 +204,9 @@ class MediaSessionStack {
 
     /**
      * Find the media button session with the given {@param uid}.
-     * If the app has multiple media sessions, the media session matches the audio playback state
-     * becomes the media button session.
+     * If the app has multiple media sessions, the media session whose playback state is not null
+     * and matches the audio playback state becomes the media button session. Otherwise the top
+     * priority session becomes the media button session.
      *
      * @return The media button session. Returns {@code null} if the app doesn't have a media
      *   session.
@@ -214,7 +215,7 @@ class MediaSessionStack {
         MediaSessionRecord mediaButtonSession = null;
         for (MediaSessionRecord session : mSessions) {
             if (uid == session.getUid()) {
-                if (session.isPlaybackActive() ==
+                if (session.getPlaybackState() != null && session.isPlaybackActive() ==
                         mAudioPlaybackMonitor.isPlaybackActive(session.getUid())) {
                     // If there's a media session whose PlaybackState matches
                     // the audio playback state, return it immediately.