Loading packages/MediaComponents/src/com/android/media/MediaController2Impl.java +29 −2 Original line number Diff line number Diff line Loading @@ -39,8 +39,10 @@ import android.media.update.MediaController2Provider; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; import android.os.Process; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.UserHandle; import android.support.annotation.GuardedBy; import android.util.Log; Loading Loading @@ -125,6 +127,24 @@ public class MediaController2Impl implements MediaController2Provider { connectToSession(SessionToken2Impl.from(mToken).getSessionBinder()); } else { // Session service if (Process.myUid() == Process.SYSTEM_UID) { // It's system server (MediaSessionService) that wants to monitor session. // Don't bind if able.. IMediaSession2 binder = SessionToken2Impl.from(mToken).getSessionBinder(); if (binder != null) { // Use binder in the session token instead of bind by its own. // Otherwise server will holds the binding to the service *forever* and service // will never stop. mServiceConnection = null; connectToSession(SessionToken2Impl.from(mToken).getSessionBinder()); return; } else if (DEBUG) { // Should happen only when system server wants to dispatch media key events to // a dead service. Log.d(TAG, "System server binds to a session service. Should unbind" + " immediately after the use."); } } mServiceConnection = new SessionServiceConnection(); connectToService(); } Loading @@ -150,8 +170,15 @@ public class MediaController2Impl implements MediaController2Provider { // If a service wants to keep running, it should be either foreground service or // bounded service. But there had been request for the feature for system apps // and using bindService() will be better fit with it. // TODO(jaewan): Use bindServiceAsUser()?? boolean result = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); boolean result; if (Process.myUid() == Process.SYSTEM_UID) { // Use bindServiceAsUser() for binding from system service to avoid following warning. // ContextImpl: Calling a method in the system process without a qualified user result = mContext.bindServiceAsUser(intent, mServiceConnection, Context.BIND_AUTO_CREATE, UserHandle.getUserHandleForUid(mToken.getUid())); } else { result = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); } if (!result) { Log.w(TAG, "bind to " + mToken + " failed"); } else if (DEBUG) { Loading packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +2 −2 Original line number Diff line number Diff line Loading @@ -149,10 +149,10 @@ public class MediaSession2Impl implements MediaSession2Provider { + " session services define the same id=" + id); } else if (libraryService != null) { mSessionToken = new SessionToken2Impl(context, Process.myUid(), TYPE_LIBRARY_SERVICE, mContext.getPackageName(), libraryService, id, null).getInstance(); mContext.getPackageName(), libraryService, id, mSessionStub).getInstance(); } else if (sessionService != null) { mSessionToken = new SessionToken2Impl(context, Process.myUid(), TYPE_SESSION_SERVICE, mContext.getPackageName(), sessionService, id, null).getInstance(); mContext.getPackageName(), sessionService, id, mSessionStub).getInstance(); } else { mSessionToken = new SessionToken2Impl(context, Process.myUid(), TYPE_SESSION, mContext.getPackageName(), null, id, mSessionStub).getInstance(); Loading packages/MediaComponents/test/src/android/media/MediaController2Test.java +0 −2 Original line number Diff line number Diff line Loading @@ -744,13 +744,11 @@ public class MediaController2Test extends MediaSession2TestBase { testControllerAfterSessionIsGone(id); } @Ignore @Test public void testClose_sessionService() throws InterruptedException { testCloseFromService(MockMediaSessionService2.ID); } @Ignore @Test public void testClose_libraryService() throws InterruptedException { testCloseFromService(MockMediaLibraryService2.ID); Loading Loading
packages/MediaComponents/src/com/android/media/MediaController2Impl.java +29 −2 Original line number Diff line number Diff line Loading @@ -39,8 +39,10 @@ import android.media.update.MediaController2Provider; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; import android.os.Process; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.UserHandle; import android.support.annotation.GuardedBy; import android.util.Log; Loading Loading @@ -125,6 +127,24 @@ public class MediaController2Impl implements MediaController2Provider { connectToSession(SessionToken2Impl.from(mToken).getSessionBinder()); } else { // Session service if (Process.myUid() == Process.SYSTEM_UID) { // It's system server (MediaSessionService) that wants to monitor session. // Don't bind if able.. IMediaSession2 binder = SessionToken2Impl.from(mToken).getSessionBinder(); if (binder != null) { // Use binder in the session token instead of bind by its own. // Otherwise server will holds the binding to the service *forever* and service // will never stop. mServiceConnection = null; connectToSession(SessionToken2Impl.from(mToken).getSessionBinder()); return; } else if (DEBUG) { // Should happen only when system server wants to dispatch media key events to // a dead service. Log.d(TAG, "System server binds to a session service. Should unbind" + " immediately after the use."); } } mServiceConnection = new SessionServiceConnection(); connectToService(); } Loading @@ -150,8 +170,15 @@ public class MediaController2Impl implements MediaController2Provider { // If a service wants to keep running, it should be either foreground service or // bounded service. But there had been request for the feature for system apps // and using bindService() will be better fit with it. // TODO(jaewan): Use bindServiceAsUser()?? boolean result = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); boolean result; if (Process.myUid() == Process.SYSTEM_UID) { // Use bindServiceAsUser() for binding from system service to avoid following warning. // ContextImpl: Calling a method in the system process without a qualified user result = mContext.bindServiceAsUser(intent, mServiceConnection, Context.BIND_AUTO_CREATE, UserHandle.getUserHandleForUid(mToken.getUid())); } else { result = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); } if (!result) { Log.w(TAG, "bind to " + mToken + " failed"); } else if (DEBUG) { Loading
packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +2 −2 Original line number Diff line number Diff line Loading @@ -149,10 +149,10 @@ public class MediaSession2Impl implements MediaSession2Provider { + " session services define the same id=" + id); } else if (libraryService != null) { mSessionToken = new SessionToken2Impl(context, Process.myUid(), TYPE_LIBRARY_SERVICE, mContext.getPackageName(), libraryService, id, null).getInstance(); mContext.getPackageName(), libraryService, id, mSessionStub).getInstance(); } else if (sessionService != null) { mSessionToken = new SessionToken2Impl(context, Process.myUid(), TYPE_SESSION_SERVICE, mContext.getPackageName(), sessionService, id, null).getInstance(); mContext.getPackageName(), sessionService, id, mSessionStub).getInstance(); } else { mSessionToken = new SessionToken2Impl(context, Process.myUid(), TYPE_SESSION, mContext.getPackageName(), null, id, mSessionStub).getInstance(); Loading
packages/MediaComponents/test/src/android/media/MediaController2Test.java +0 −2 Original line number Diff line number Diff line Loading @@ -744,13 +744,11 @@ public class MediaController2Test extends MediaSession2TestBase { testControllerAfterSessionIsGone(id); } @Ignore @Test public void testClose_sessionService() throws InterruptedException { testCloseFromService(MockMediaSessionService2.ID); } @Ignore @Test public void testClose_libraryService() throws InterruptedException { testCloseFromService(MockMediaLibraryService2.ID); Loading