Loading packages/MediaComponents/src/com/android/media/IMediaController2.aidl +0 −12 Original line number Diff line number Diff line Loading @@ -52,16 +52,4 @@ oneway interface IMediaController2 { void onAllowedCommandsChanged(in Bundle commands); void onCustomCommand(in Bundle command, in Bundle args, in ResultReceiver receiver); ////////////////////////////////////////////////////////////////////////////////////////////// // Browser sepcific ////////////////////////////////////////////////////////////////////////////////////////////// void onGetLibraryRootDone(in Bundle rootHints, String rootMediaId, in Bundle rootExtra); void onGetItemDone(String mediaId, in Bundle result); void onChildrenChanged(String rootMediaId, int itemCount, in Bundle extras); void onGetChildrenDone(String parentId, int page, int pageSize, in List<Bundle> result, in Bundle extras); void onSearchResultChanged(String query, int itemCount, in Bundle extras); void onGetSearchResultDone(String query, int page, int pageSize, in List<Bundle> result, in Bundle extras); } packages/MediaComponents/src/com/android/media/IMediaSession2.aidl +0 −13 Original line number Diff line number Diff line Loading @@ -69,17 +69,4 @@ oneway interface IMediaSession2 { void skipToNextItem(IMediaController2 caller); void setRepeatMode(IMediaController2 caller, int repeatMode); void setShuffleMode(IMediaController2 caller, int shuffleMode); ////////////////////////////////////////////////////////////////////////////////////////////// // library service specific ////////////////////////////////////////////////////////////////////////////////////////////// void getLibraryRoot(IMediaController2 caller, in Bundle rootHints); void getItem(IMediaController2 caller, String mediaId); void getChildren(IMediaController2 caller, String parentId, int page, int pageSize, in Bundle extras); void search(IMediaController2 caller, String query, in Bundle extras); void getSearchResult(IMediaController2 caller, String query, int page, int pageSize, in Bundle extras); void subscribe(IMediaController2 caller, String parentId, in Bundle extras); void unsubscribe(IMediaController2 caller, String parentId); } packages/MediaComponents/src/com/android/media/MediaBrowser2Impl.javadeleted 100644 → 0 +0 −236 Original line number Diff line number Diff line /* * Copyright 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.media; import android.content.Context; import android.media.MediaBrowser2; import android.media.MediaBrowser2.BrowserCallback; import android.media.MediaItem2; import android.media.SessionToken2; import android.media.update.MediaBrowser2Provider; import android.os.Bundle; import android.os.RemoteException; import android.text.TextUtils; import android.util.Log; import java.util.List; import java.util.concurrent.Executor; public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrowser2Provider { private final String TAG = "MediaBrowser2"; private final boolean DEBUG = true; // TODO(jaewan): change. private final MediaBrowser2 mInstance; private final MediaBrowser2.BrowserCallback mCallback; public MediaBrowser2Impl(Context context, MediaBrowser2 instance, SessionToken2 token, Executor executor, BrowserCallback callback) { super(context, instance, token, executor, callback); mInstance = instance; mCallback = callback; } @Override MediaBrowser2 getInstance() { return (MediaBrowser2) super.getInstance(); } @Override public void getLibraryRoot_impl(Bundle rootHints) { final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.getLibraryRoot(getControllerStub(), rootHints); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void subscribe_impl(String parentId, Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.subscribe(getControllerStub(), parentId, extras); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void unsubscribe_impl(String parentId) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.unsubscribe(getControllerStub(), parentId); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void getItem_impl(String mediaId) { if (mediaId == null) { throw new IllegalArgumentException("mediaId shouldn't be null"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.getItem(getControllerStub(), mediaId); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void getChildren_impl(String parentId, int page, int pageSize, Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } if (page < 1 || pageSize < 1) { throw new IllegalArgumentException("Neither page nor pageSize should be less than 1"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.getChildren(getControllerStub(), parentId, page, pageSize, extras); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void search_impl(String query, Bundle extras) { if (TextUtils.isEmpty(query)) { throw new IllegalArgumentException("query shouldn't be empty"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.search(getControllerStub(), query, extras); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void getSearchResult_impl(String query, int page, int pageSize, Bundle extras) { if (TextUtils.isEmpty(query)) { throw new IllegalArgumentException("query shouldn't be empty"); } if (page < 1 || pageSize < 1) { throw new IllegalArgumentException("Neither page nor pageSize should be less than 1"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.getSearchResult(getControllerStub(), query, page, pageSize, extras); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } public void onGetLibraryRootDone( final Bundle rootHints, final String rootMediaId, final Bundle rootExtra) { getCallbackExecutor().execute(() -> { mCallback.onGetLibraryRootDone(getInstance(), rootHints, rootMediaId, rootExtra); }); } public void onGetItemDone(String mediaId, MediaItem2 item) { getCallbackExecutor().execute(() -> { mCallback.onGetItemDone(getInstance(), mediaId, item); }); } public void onGetChildrenDone(String parentId, int page, int pageSize, List<MediaItem2> result, Bundle extras) { getCallbackExecutor().execute(() -> { mCallback.onGetChildrenDone(getInstance(), parentId, page, pageSize, result, extras); }); } public void onSearchResultChanged(String query, int itemCount, Bundle extras) { getCallbackExecutor().execute(() -> { mCallback.onSearchResultChanged(getInstance(), query, itemCount, extras); }); } public void onGetSearchResultDone(String query, int page, int pageSize, List<MediaItem2> result, Bundle extras) { getCallbackExecutor().execute(() -> { mCallback.onGetSearchResultDone(getInstance(), query, page, pageSize, result, extras); }); } public void onChildrenChanged(final String parentId, int itemCount, final Bundle extras) { getCallbackExecutor().execute(() -> { mCallback.onChildrenChanged(getInstance(), parentId, itemCount, extras); }); } } packages/MediaComponents/src/com/android/media/MediaController2Impl.java +0 −59 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ import android.media.MediaMetadata2; import android.media.MediaPlaylistAgent.RepeatMode; import android.media.MediaPlaylistAgent.ShuffleMode; import android.media.MediaSession2.CommandButton; import android.media.MediaSessionService2; import android.media.Rating2; import android.media.SessionCommand2; import android.media.SessionCommandGroup2; Loading Loading @@ -154,64 +153,6 @@ public class MediaController2Impl implements MediaController2Provider { // Session mServiceConnection = null; 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(); } } private void connectToService() { // Service. Needs to get fresh binder whenever connection is needed. SessionToken2Impl impl = SessionToken2Impl.from(mToken); final Intent intent = new Intent(MediaSessionService2.SERVICE_INTERFACE); intent.setClassName(mToken.getPackageName(), impl.getServiceName()); // Use bindService() instead of startForegroundService() to start session service for three // reasons. // 1. Prevent session service owner's stopSelf() from destroying service. // With the startForegroundService(), service's call of stopSelf() will trigger immediate // onDestroy() calls on the main thread even when onConnect() is running in another // thread. // 2. Minimize APIs for developers to take care about. // With bindService(), developers only need to take care about Service.onBind() // but Service.onStartCommand() should be also taken care about with the // startForegroundService(). // 3. Future support for UI-less playback // 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. 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) { Log.d(TAG, "bind to " + mToken + " success"); } } Loading packages/MediaComponents/src/com/android/media/MediaController2Stub.java +0 −148 Original line number Diff line number Diff line Loading @@ -54,14 +54,6 @@ public class MediaController2Stub extends IMediaController2.Stub { return controller; } private MediaBrowser2Impl getBrowser() throws IllegalStateException { final MediaController2Impl controller = getController(); if (controller instanceof MediaBrowser2Impl) { return (MediaBrowser2Impl) controller; } return null; } public void destroy() { mController.clear(); } Loading Loading @@ -327,144 +319,4 @@ public class MediaController2Stub extends IMediaController2.Stub { } controller.onCustomCommand(command, args, receiver); } //////////////////////////////////////////////////////////////////////////////////////////// // MediaBrowser specific //////////////////////////////////////////////////////////////////////////////////////////// @Override public void onGetLibraryRootDone(Bundle rootHints, String rootMediaId, Bundle rootExtra) throws RuntimeException { final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onGetLibraryRootDone(rootHints, rootMediaId, rootExtra); } @Override public void onGetItemDone(String mediaId, Bundle itemBundle) throws RuntimeException { if (mediaId == null) { Log.w(TAG, "onGetItemDone(): Ignoring null mediaId"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onGetItemDone(mediaId, MediaItem2.fromBundle(itemBundle)); } @Override public void onGetChildrenDone(String parentId, int page, int pageSize, List<Bundle> itemBundleList, Bundle extras) throws RuntimeException { if (parentId == null) { Log.w(TAG, "onGetChildrenDone(): Ignoring null parentId"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } List<MediaItem2> result = null; if (itemBundleList != null) { result = new ArrayList<>(); for (Bundle bundle : itemBundleList) { result.add(MediaItem2.fromBundle(bundle)); } } browser.onGetChildrenDone(parentId, page, pageSize, result, extras); } @Override public void onSearchResultChanged(String query, int itemCount, Bundle extras) throws RuntimeException { if (TextUtils.isEmpty(query)) { Log.w(TAG, "onSearchResultChanged(): Ignoring empty query"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onSearchResultChanged(query, itemCount, extras); } @Override public void onGetSearchResultDone(String query, int page, int pageSize, List<Bundle> itemBundleList, Bundle extras) throws RuntimeException { if (TextUtils.isEmpty(query)) { Log.w(TAG, "onGetSearchResultDone(): Ignoring empty query"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } List<MediaItem2> result = null; if (itemBundleList != null) { result = new ArrayList<>(); for (Bundle bundle : itemBundleList) { result.add(MediaItem2.fromBundle(bundle)); } } browser.onGetSearchResultDone(query, page, pageSize, result, extras); } @Override public void onChildrenChanged(String parentId, int itemCount, Bundle extras) { if (parentId == null) { Log.w(TAG, "onChildrenChanged(): Ignoring null parentId"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onChildrenChanged(parentId, itemCount, extras); } } Loading
packages/MediaComponents/src/com/android/media/IMediaController2.aidl +0 −12 Original line number Diff line number Diff line Loading @@ -52,16 +52,4 @@ oneway interface IMediaController2 { void onAllowedCommandsChanged(in Bundle commands); void onCustomCommand(in Bundle command, in Bundle args, in ResultReceiver receiver); ////////////////////////////////////////////////////////////////////////////////////////////// // Browser sepcific ////////////////////////////////////////////////////////////////////////////////////////////// void onGetLibraryRootDone(in Bundle rootHints, String rootMediaId, in Bundle rootExtra); void onGetItemDone(String mediaId, in Bundle result); void onChildrenChanged(String rootMediaId, int itemCount, in Bundle extras); void onGetChildrenDone(String parentId, int page, int pageSize, in List<Bundle> result, in Bundle extras); void onSearchResultChanged(String query, int itemCount, in Bundle extras); void onGetSearchResultDone(String query, int page, int pageSize, in List<Bundle> result, in Bundle extras); }
packages/MediaComponents/src/com/android/media/IMediaSession2.aidl +0 −13 Original line number Diff line number Diff line Loading @@ -69,17 +69,4 @@ oneway interface IMediaSession2 { void skipToNextItem(IMediaController2 caller); void setRepeatMode(IMediaController2 caller, int repeatMode); void setShuffleMode(IMediaController2 caller, int shuffleMode); ////////////////////////////////////////////////////////////////////////////////////////////// // library service specific ////////////////////////////////////////////////////////////////////////////////////////////// void getLibraryRoot(IMediaController2 caller, in Bundle rootHints); void getItem(IMediaController2 caller, String mediaId); void getChildren(IMediaController2 caller, String parentId, int page, int pageSize, in Bundle extras); void search(IMediaController2 caller, String query, in Bundle extras); void getSearchResult(IMediaController2 caller, String query, int page, int pageSize, in Bundle extras); void subscribe(IMediaController2 caller, String parentId, in Bundle extras); void unsubscribe(IMediaController2 caller, String parentId); }
packages/MediaComponents/src/com/android/media/MediaBrowser2Impl.javadeleted 100644 → 0 +0 −236 Original line number Diff line number Diff line /* * Copyright 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.media; import android.content.Context; import android.media.MediaBrowser2; import android.media.MediaBrowser2.BrowserCallback; import android.media.MediaItem2; import android.media.SessionToken2; import android.media.update.MediaBrowser2Provider; import android.os.Bundle; import android.os.RemoteException; import android.text.TextUtils; import android.util.Log; import java.util.List; import java.util.concurrent.Executor; public class MediaBrowser2Impl extends MediaController2Impl implements MediaBrowser2Provider { private final String TAG = "MediaBrowser2"; private final boolean DEBUG = true; // TODO(jaewan): change. private final MediaBrowser2 mInstance; private final MediaBrowser2.BrowserCallback mCallback; public MediaBrowser2Impl(Context context, MediaBrowser2 instance, SessionToken2 token, Executor executor, BrowserCallback callback) { super(context, instance, token, executor, callback); mInstance = instance; mCallback = callback; } @Override MediaBrowser2 getInstance() { return (MediaBrowser2) super.getInstance(); } @Override public void getLibraryRoot_impl(Bundle rootHints) { final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.getLibraryRoot(getControllerStub(), rootHints); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void subscribe_impl(String parentId, Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.subscribe(getControllerStub(), parentId, extras); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void unsubscribe_impl(String parentId) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.unsubscribe(getControllerStub(), parentId); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void getItem_impl(String mediaId) { if (mediaId == null) { throw new IllegalArgumentException("mediaId shouldn't be null"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.getItem(getControllerStub(), mediaId); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void getChildren_impl(String parentId, int page, int pageSize, Bundle extras) { if (parentId == null) { throw new IllegalArgumentException("parentId shouldn't be null"); } if (page < 1 || pageSize < 1) { throw new IllegalArgumentException("Neither page nor pageSize should be less than 1"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.getChildren(getControllerStub(), parentId, page, pageSize, extras); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void search_impl(String query, Bundle extras) { if (TextUtils.isEmpty(query)) { throw new IllegalArgumentException("query shouldn't be empty"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.search(getControllerStub(), query, extras); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } @Override public void getSearchResult_impl(String query, int page, int pageSize, Bundle extras) { if (TextUtils.isEmpty(query)) { throw new IllegalArgumentException("query shouldn't be empty"); } if (page < 1 || pageSize < 1) { throw new IllegalArgumentException("Neither page nor pageSize should be less than 1"); } final IMediaSession2 binder = getSessionBinder(); if (binder != null) { try { binder.getSearchResult(getControllerStub(), query, page, pageSize, extras); } catch (RemoteException e) { // TODO(jaewan): Handle disconnect. if (DEBUG) { Log.w(TAG, "Cannot connect to the service or the session is gone", e); } } } else { Log.w(TAG, "Session isn't active", new IllegalStateException()); } } public void onGetLibraryRootDone( final Bundle rootHints, final String rootMediaId, final Bundle rootExtra) { getCallbackExecutor().execute(() -> { mCallback.onGetLibraryRootDone(getInstance(), rootHints, rootMediaId, rootExtra); }); } public void onGetItemDone(String mediaId, MediaItem2 item) { getCallbackExecutor().execute(() -> { mCallback.onGetItemDone(getInstance(), mediaId, item); }); } public void onGetChildrenDone(String parentId, int page, int pageSize, List<MediaItem2> result, Bundle extras) { getCallbackExecutor().execute(() -> { mCallback.onGetChildrenDone(getInstance(), parentId, page, pageSize, result, extras); }); } public void onSearchResultChanged(String query, int itemCount, Bundle extras) { getCallbackExecutor().execute(() -> { mCallback.onSearchResultChanged(getInstance(), query, itemCount, extras); }); } public void onGetSearchResultDone(String query, int page, int pageSize, List<MediaItem2> result, Bundle extras) { getCallbackExecutor().execute(() -> { mCallback.onGetSearchResultDone(getInstance(), query, page, pageSize, result, extras); }); } public void onChildrenChanged(final String parentId, int itemCount, final Bundle extras) { getCallbackExecutor().execute(() -> { mCallback.onChildrenChanged(getInstance(), parentId, itemCount, extras); }); } }
packages/MediaComponents/src/com/android/media/MediaController2Impl.java +0 −59 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ import android.media.MediaMetadata2; import android.media.MediaPlaylistAgent.RepeatMode; import android.media.MediaPlaylistAgent.ShuffleMode; import android.media.MediaSession2.CommandButton; import android.media.MediaSessionService2; import android.media.Rating2; import android.media.SessionCommand2; import android.media.SessionCommandGroup2; Loading Loading @@ -154,64 +153,6 @@ public class MediaController2Impl implements MediaController2Provider { // Session mServiceConnection = null; 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(); } } private void connectToService() { // Service. Needs to get fresh binder whenever connection is needed. SessionToken2Impl impl = SessionToken2Impl.from(mToken); final Intent intent = new Intent(MediaSessionService2.SERVICE_INTERFACE); intent.setClassName(mToken.getPackageName(), impl.getServiceName()); // Use bindService() instead of startForegroundService() to start session service for three // reasons. // 1. Prevent session service owner's stopSelf() from destroying service. // With the startForegroundService(), service's call of stopSelf() will trigger immediate // onDestroy() calls on the main thread even when onConnect() is running in another // thread. // 2. Minimize APIs for developers to take care about. // With bindService(), developers only need to take care about Service.onBind() // but Service.onStartCommand() should be also taken care about with the // startForegroundService(). // 3. Future support for UI-less playback // 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. 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) { Log.d(TAG, "bind to " + mToken + " success"); } } Loading
packages/MediaComponents/src/com/android/media/MediaController2Stub.java +0 −148 Original line number Diff line number Diff line Loading @@ -54,14 +54,6 @@ public class MediaController2Stub extends IMediaController2.Stub { return controller; } private MediaBrowser2Impl getBrowser() throws IllegalStateException { final MediaController2Impl controller = getController(); if (controller instanceof MediaBrowser2Impl) { return (MediaBrowser2Impl) controller; } return null; } public void destroy() { mController.clear(); } Loading Loading @@ -327,144 +319,4 @@ public class MediaController2Stub extends IMediaController2.Stub { } controller.onCustomCommand(command, args, receiver); } //////////////////////////////////////////////////////////////////////////////////////////// // MediaBrowser specific //////////////////////////////////////////////////////////////////////////////////////////// @Override public void onGetLibraryRootDone(Bundle rootHints, String rootMediaId, Bundle rootExtra) throws RuntimeException { final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onGetLibraryRootDone(rootHints, rootMediaId, rootExtra); } @Override public void onGetItemDone(String mediaId, Bundle itemBundle) throws RuntimeException { if (mediaId == null) { Log.w(TAG, "onGetItemDone(): Ignoring null mediaId"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onGetItemDone(mediaId, MediaItem2.fromBundle(itemBundle)); } @Override public void onGetChildrenDone(String parentId, int page, int pageSize, List<Bundle> itemBundleList, Bundle extras) throws RuntimeException { if (parentId == null) { Log.w(TAG, "onGetChildrenDone(): Ignoring null parentId"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } List<MediaItem2> result = null; if (itemBundleList != null) { result = new ArrayList<>(); for (Bundle bundle : itemBundleList) { result.add(MediaItem2.fromBundle(bundle)); } } browser.onGetChildrenDone(parentId, page, pageSize, result, extras); } @Override public void onSearchResultChanged(String query, int itemCount, Bundle extras) throws RuntimeException { if (TextUtils.isEmpty(query)) { Log.w(TAG, "onSearchResultChanged(): Ignoring empty query"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onSearchResultChanged(query, itemCount, extras); } @Override public void onGetSearchResultDone(String query, int page, int pageSize, List<Bundle> itemBundleList, Bundle extras) throws RuntimeException { if (TextUtils.isEmpty(query)) { Log.w(TAG, "onGetSearchResultDone(): Ignoring empty query"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } List<MediaItem2> result = null; if (itemBundleList != null) { result = new ArrayList<>(); for (Bundle bundle : itemBundleList) { result.add(MediaItem2.fromBundle(bundle)); } } browser.onGetSearchResultDone(query, page, pageSize, result, extras); } @Override public void onChildrenChanged(String parentId, int itemCount, Bundle extras) { if (parentId == null) { Log.w(TAG, "onChildrenChanged(): Ignoring null parentId"); return; } final MediaBrowser2Impl browser; try { browser = getBrowser(); } catch (IllegalStateException e) { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } if (browser == null) { // TODO(jaewan): Revisit here. Could be a bug return; } browser.onChildrenChanged(parentId, itemCount, extras); } }