OSDN Git Service

MediaSessionService: Clear calling identity for incoming calls from apps
authorJaewan Kim <jaewan@google.com>
Thu, 30 Mar 2017 09:19:17 +0000 (18:19 +0900)
committerJaewan Kim <jaewan@google.com>
Wed, 19 Apr 2017 05:53:32 +0000 (05:53 +0000)
This only clears calling identity if MediaSessionRecord calls
APIs of MediaSessionService.

Bug: 36682559
Test: Run CtsMediaTest (MediaSessionTest and MediaSessionManagerTest)
  and Manual test (Checked that a media app that changes the active
  state and supports cast doesn't crash)
Change-Id: Ia4a441b692ea7da606b1bafbe9a6c3f8fd690518

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

index ee348cf..a275f49 100644 (file)
@@ -751,7 +751,12 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
         @Override
         public void setActive(boolean active) {
             mIsActive = active;
-            mService.updateSession(MediaSessionRecord.this);
+            final long token = Binder.clearCallingIdentity();
+            try {
+                mService.updateSession(MediaSessionRecord.this);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
             mHandler.post(MessageHandler.MSG_UPDATE_SESSION_STATE);
         }
 
@@ -862,7 +867,12 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
                 }
             }
             if (typeChanged) {
-                mService.onSessionPlaybackTypeChanged(MediaSessionRecord.this);
+                final long token = Binder.clearCallingIdentity();
+                try {
+                    mService.onSessionPlaybackTypeChanged(MediaSessionRecord.this);
+                } finally {
+                    Binder.restoreCallingIdentity(token);
+                }
                 mHandler.post(MessageHandler.MSG_UPDATE_VOLUME);
             }
         }
@@ -877,7 +887,12 @@ public class MediaSessionRecord implements IBinder.DeathRecipient {
                 mMaxVolume = max;
             }
             if (typeChanged) {
-                mService.onSessionPlaybackTypeChanged(MediaSessionRecord.this);
+                final long token = Binder.clearCallingIdentity();
+                try {
+                    mService.onSessionPlaybackTypeChanged(MediaSessionRecord.this);
+                } finally {
+                    Binder.restoreCallingIdentity(token);
+                }
                 mHandler.post(MessageHandler.MSG_UPDATE_VOLUME);
             }
         }