summaryrefslogtreecommitdiffstats
path: root/v4/api21/android
diff options
context:
space:
mode:
authorSungsoo Lim <sungsoo@google.com>2015-10-24 00:25:29 +0900
committerSungsoo Lim <sungsoo@google.com>2015-10-26 09:29:57 +0900
commit9703a1e215168b6b580430ec490ca616b6490c80 (patch)
tree9ab675e6d4291c0bb5cdd57e533589de8e9f4c98 /v4/api21/android
parent3da6accc0234bcbd06373b716645dfd738ddeba7 (diff)
downloadandroid_frameworks_support-9703a1e215168b6b580430ec490ca616b6490c80.tar.gz
android_frameworks_support-9703a1e215168b6b580430ec490ca616b6490c80.tar.bz2
android_frameworks_support-9703a1e215168b6b580430ec490ca616b6490c80.zip
Revert "Revert "Allow MediaBrowser be connect to MediaBrowserServiceCompat""
- This reverts commit 493571364635be0190cea8ee230a601070391e6f. - Also fix the build issue. Change-Id: Ifc58b98cdc71aad59cfeaf4708cefd879bb0d1be
Diffstat (limited to 'v4/api21/android')
-rw-r--r--v4/api21/android/content/pm/ParceledListSlice.java70
-rw-r--r--v4/api21/android/service/media/IMediaBrowserService.java65
-rw-r--r--v4/api21/android/service/media/IMediaBrowserServiceCallbacks.java38
-rw-r--r--v4/api21/android/support/v4/media/MediaBrowserServiceCompatApi21.java149
4 files changed, 322 insertions, 0 deletions
diff --git a/v4/api21/android/content/pm/ParceledListSlice.java b/v4/api21/android/content/pm/ParceledListSlice.java
new file mode 100644
index 0000000000..b5183c0b94
--- /dev/null
+++ b/v4/api21/android/content/pm/ParceledListSlice.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2015 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 android.content.pm;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.List;
+
+/**
+ * A dummy implementation for overriding a hidden framework class, ParceledListSlice.
+ * When there are duplicated signatures between app and framework code, the framework code will be
+ * run.
+ * @hide
+ */
+public class ParceledListSlice<T extends Parcelable> implements Parcelable {
+ public ParceledListSlice(List<T> list) {
+ }
+
+ @SuppressWarnings("unchecked")
+ private ParceledListSlice(Parcel p, ClassLoader loader) {
+ }
+
+ private static void verifySameType(final Class<?> expected, final Class<?> actual) {
+ }
+
+ public List<T> getList() {
+ return null;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ }
+
+ @SuppressWarnings("unchecked")
+ public static final Parcelable.ClassLoaderCreator<ParceledListSlice> CREATOR =
+ new Parcelable.ClassLoaderCreator<ParceledListSlice>() {
+ public ParceledListSlice createFromParcel(Parcel in) {
+ return null;
+ }
+
+ @Override
+ public ParceledListSlice createFromParcel(Parcel in, ClassLoader loader) {
+ return null;
+ }
+
+ public ParceledListSlice[] newArray(int size) {
+ return null;
+ }
+ };
+}
diff --git a/v4/api21/android/service/media/IMediaBrowserService.java b/v4/api21/android/service/media/IMediaBrowserService.java
new file mode 100644
index 0000000000..086dc9cc0d
--- /dev/null
+++ b/v4/api21/android/service/media/IMediaBrowserService.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 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 android.service.media;
+
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.IInterface;
+import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.ResultReceiver;
+
+/**
+ * A dummy implementation for overriding a hidden framework class, IMediaBrowserService.
+ * When there are duplicated signatures between app and framework code, the framework code will be
+ * run.
+ * TODO: Consider using aidl instead of this.
+ * @hide
+ */
+public interface IMediaBrowserService extends IInterface {
+
+ public static abstract class Stub extends Binder
+ implements IMediaBrowserService {
+ public Stub() {
+ }
+
+ public static IMediaBrowserService asInterface(IBinder obj) {
+ return null;
+ }
+
+ @Override
+ public IBinder asBinder() {
+ return null;
+ }
+
+ @Override
+ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+ throws android.os.RemoteException {
+ return false;
+ }
+ }
+
+ public void connect(String pkg, Bundle rootHints, IMediaBrowserServiceCallbacks callbacks)
+ throws android.os.RemoteException;
+ public void disconnect(IMediaBrowserServiceCallbacks callbacks) throws RemoteException;
+ public void addSubscription(String uri, IMediaBrowserServiceCallbacks callbacks)
+ throws RemoteException;
+ public void removeSubscription(String uri, IMediaBrowserServiceCallbacks callbacks)
+ throws RemoteException;
+ public void getMediaItem(String uri, ResultReceiver cb) throws android.os.RemoteException;
+}
diff --git a/v4/api21/android/service/media/IMediaBrowserServiceCallbacks.java b/v4/api21/android/service/media/IMediaBrowserServiceCallbacks.java
new file mode 100644
index 0000000000..4bea5d9bdc
--- /dev/null
+++ b/v4/api21/android/service/media/IMediaBrowserServiceCallbacks.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2015 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 android.service.media;
+
+import android.content.pm.ParceledListSlice;
+import android.media.session.MediaSession;
+import android.os.Bundle;
+import android.os.IInterface;
+import android.os.RemoteException;
+
+/**
+ * A dummy implementation for overriding a hidden framework class, IMediaBrowserServiceCallbacks.
+ * When there are duplicated signatures between app and framework code, the framework code will be
+ * run.
+ * TODO: Consider using aidl instead of this.
+ * @hide
+ */
+public interface IMediaBrowserServiceCallbacks extends IInterface {
+ public void onConnect(String root, MediaSession.Token session, Bundle extras)
+ throws RemoteException;
+ public void onConnectFailed() throws RemoteException;
+ public void onLoadChildren(String mediaId, ParceledListSlice list) throws RemoteException;
+}
+
diff --git a/v4/api21/android/support/v4/media/MediaBrowserServiceCompatApi21.java b/v4/api21/android/support/v4/media/MediaBrowserServiceCompatApi21.java
new file mode 100644
index 0000000000..e2f517f370
--- /dev/null
+++ b/v4/api21/android/support/v4/media/MediaBrowserServiceCompatApi21.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2015 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 android.support.v4.media;
+
+import android.content.Intent;
+import android.content.pm.ParceledListSlice;
+import android.media.browse.MediaBrowser;
+import android.media.session.MediaSession;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.ResultReceiver;
+import android.service.media.IMediaBrowserService;
+import android.service.media.IMediaBrowserServiceCallbacks;
+import android.service.media.MediaBrowserService;
+
+import java.util.ArrayList;
+import java.util.List;
+
+class MediaBrowserServiceCompatApi21 {
+
+ public static Object createService() {
+ return new MediaBrowserServiceStub();
+ }
+
+ public static void onCreate(Object serviceObj, ServiceStub stub) {
+ ((MediaBrowserServiceStub) serviceObj).onCreate(stub);
+ }
+
+ public static IBinder onBind(Object serviceObj, Intent intent) {
+ return ((MediaBrowserServiceStub) serviceObj).onBind(intent);
+ }
+
+ public interface ServiceStub {
+ void connect(final String pkg, final Bundle rootHints, final ServiceCallbacks callbacks);
+ void disconnect(final ServiceCallbacks callbacks);
+ void addSubscription(final String id, final ServiceCallbacks callbacks);
+ void removeSubscription(final String id, final ServiceCallbacks callbacks);
+ void getMediaItem(final String mediaId, final ResultReceiver receiver);
+ }
+
+ public interface ServiceCallbacks {
+ IBinder asBinder();
+ void onConnect(String root, Object session, Bundle extras) throws RemoteException;
+ void onConnectFailed() throws RemoteException;
+ void onLoadChildren(String mediaId, List<Parcel> list) throws RemoteException;
+ }
+
+ public static class ServiceCallbacksApi21 implements ServiceCallbacks {
+ private final IMediaBrowserServiceCallbacks mCallbacks;
+
+ ServiceCallbacksApi21(IMediaBrowserServiceCallbacks callbacks) {
+ mCallbacks = callbacks;
+ }
+
+ public IBinder asBinder() {
+ return mCallbacks.asBinder();
+ }
+
+ public void onConnect(String root, Object session, Bundle extras) throws RemoteException {
+ mCallbacks.onConnect(root, (MediaSession.Token) session, extras);
+ }
+
+ public void onConnectFailed() throws RemoteException {
+ mCallbacks.onConnectFailed();
+ }
+
+ public void onLoadChildren(String mediaId, List<Parcel> list) throws RemoteException {
+ List<MediaBrowser.MediaItem> itemList = null;
+ if (list != null) {
+ itemList = new ArrayList<>();
+ for (Parcel parcel : list) {
+ parcel.setDataPosition(0);
+ itemList.add(MediaBrowser.MediaItem.CREATOR.createFromParcel(parcel));
+ parcel.recycle();
+ }
+ }
+ final ParceledListSlice<MediaBrowser.MediaItem> pls = new ParceledListSlice(itemList);
+ mCallbacks.onLoadChildren(mediaId, pls);
+ }
+ }
+
+ private static class MediaBrowserServiceStub {
+ ServiceBinderProxy mBinder;
+
+ public void onCreate(ServiceStub stub) {
+ mBinder = new ServiceBinderProxy(stub);
+ }
+
+ public IBinder onBind(Intent intent) {
+ if (MediaBrowserService.SERVICE_INTERFACE.equals(intent.getAction())) {
+ return mBinder;
+ }
+ return null;
+ }
+
+ private static class ServiceBinderProxy extends IMediaBrowserService.Stub {
+ private final ServiceStub mServiceStub;
+
+ ServiceBinderProxy(ServiceStub stub) {
+ mServiceStub = stub;
+ }
+
+ @Override
+ public void connect(final String pkg, final Bundle rootHints,
+ final IMediaBrowserServiceCallbacks callbacks) {
+ mServiceStub.connect(pkg, rootHints, new ServiceCallbacksApi21(callbacks));
+ }
+
+ @Override
+ public void disconnect(final IMediaBrowserServiceCallbacks callbacks) {
+ mServiceStub.disconnect(new ServiceCallbacksApi21(callbacks));
+ }
+
+
+ @Override
+ public void addSubscription(final String id,
+ final IMediaBrowserServiceCallbacks callbacks) {
+ mServiceStub.addSubscription(id, new ServiceCallbacksApi21(callbacks));
+ }
+
+ @Override
+ public void removeSubscription(final String id,
+ final IMediaBrowserServiceCallbacks callbacks) {
+ mServiceStub.removeSubscription(id, new ServiceCallbacksApi21(callbacks));
+ }
+
+ @Override
+ public void getMediaItem(final String mediaId, final ResultReceiver receiver) {
+ mServiceStub.getMediaItem(mediaId, receiver);
+ }
+ }
+ }
+}