Revert "Allow MediaBrowser be connect to MediaBrowserServiceCompat"

This reverts commit 6a4150834d679d66abef50aff74d30ae2e846a32.

Change-Id: Ia50b8f070ae97024ee9e64ed27ef61eabe155f3f
diff --git a/v4/Android.mk b/v4/Android.mk
index 740e92b..2050725 100644
--- a/v4/Android.mk
+++ b/v4/Android.mk
@@ -168,7 +168,6 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := android-support-v4-api21
 LOCAL_SDK_VERSION := 21
-LOCAL_AIDL_INCLUDES := frameworks/support/v4/api21
 LOCAL_SRC_FILES := $(call all-java-files-under, api21)
 LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4-api20
 include $(BUILD_STATIC_JAVA_LIBRARY)
@@ -202,7 +201,7 @@
 LOCAL_AIDL_INCLUDES := frameworks/support/v4/java
 LOCAL_SRC_FILES := $(call all-java-files-under, java) \
     $(call all-Iaidl-files-under, java)
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4-api23
+LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4-api23
 include $(BUILD_STATIC_JAVA_LIBRARY)
 
 # API Check
diff --git a/v4/api21/android/content/pm/ParceledListSlice.java b/v4/api21/android/content/pm/ParceledListSlice.java
deleted file mode 100644
index b5183c0..0000000
--- a/v4/api21/android/content/pm/ParceledListSlice.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 086dc9c..0000000
--- a/v4/api21/android/service/media/IMediaBrowserService.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 4bea5d9..0000000
--- a/v4/api21/android/service/media/IMediaBrowserServiceCallbacks.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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
deleted file mode 100644
index e2f517f..0000000
--- a/v4/api21/android/support/v4/media/MediaBrowserServiceCompatApi21.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * 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);
-            }
-        }
-    }
-}
diff --git a/v4/java/android/support/v4/media/IMediaBrowserServiceCompat.aidl b/v4/java/android/support/v4/media/IMediaBrowserServiceCompat.aidl
index 96155cd..05012b6 100644
--- a/v4/java/android/support/v4/media/IMediaBrowserServiceCompat.aidl
+++ b/v4/java/android/support/v4/media/IMediaBrowserServiceCompat.aidl
@@ -1,18 +1,18 @@
 /*
- * Copyright 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.
- */
+** Copyright 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;
 
@@ -34,4 +34,4 @@
     void addSubscription(String uri, IMediaBrowserServiceCompatCallbacks callbacks);
     void removeSubscription(String uri, IMediaBrowserServiceCompatCallbacks callbacks);
     void getMediaItem(String uri, in ResultReceiver cb);
-}
+}
\ No newline at end of file
diff --git a/v4/java/android/support/v4/media/IMediaBrowserServiceCompatCallbacks.aidl b/v4/java/android/support/v4/media/IMediaBrowserServiceCompatCallbacks.aidl
index d2c7fd9..d191123 100644
--- a/v4/java/android/support/v4/media/IMediaBrowserServiceCompatCallbacks.aidl
+++ b/v4/java/android/support/v4/media/IMediaBrowserServiceCompatCallbacks.aidl
@@ -1,18 +1,18 @@
 /*
- * Copyright 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.
- */
+** Copyright 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;
 
diff --git a/v4/java/android/support/v4/media/MediaBrowserServiceCompat.java b/v4/java/android/support/v4/media/MediaBrowserServiceCompat.java
index 5d5f1f7..d8cd79e 100644
--- a/v4/java/android/support/v4/media/MediaBrowserServiceCompat.java
+++ b/v4/java/android/support/v4/media/MediaBrowserServiceCompat.java
@@ -20,14 +20,14 @@
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.os.Binder;
-import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
-import android.os.Parcel;
 import android.os.RemoteException;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
+import android.support.v4.media.IMediaBrowserServiceCompat;
+import android.support.v4.media.IMediaBrowserServiceCompatCallbacks;
 import android.support.v4.media.session.MediaSessionCompat;
 import android.support.v4.os.ResultReceiver;
 import android.support.v4.util.ArrayMap;
@@ -36,7 +36,6 @@
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
-import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 
@@ -56,7 +55,7 @@
  * &lt;service android:name=".MyMediaBrowserServiceCompat"
  *          android:label="&#64;string/service_name" >
  *     &lt;intent-filter>
- *         &lt;action android:name="android.media.browse.MediaBrowserService" />
+ *         &lt;action android:name="android.media.browse.MediaBrowserServiceCompat" />
  *     &lt;/intent-filter>
  * &lt;/service>
  * </pre>
@@ -66,12 +65,10 @@
     private static final String TAG = "MediaBrowserServiceCompat";
     private static final boolean DBG = false;
 
-    private MediaBrowserServiceImpl mImpl;
-
     /**
      * The {@link Intent} that must be declared as handled by the service.
      */
-    public static final String SERVICE_INTERFACE = "android.media.browse.MediaBrowserService";
+    public static final String SERVICE_INTERFACE = "android.media.browse.MediaBrowserServiceCompat";
 
     /**
      * A key for passing the MediaItem to the ResultReceiver in getItem.
@@ -82,54 +79,16 @@
 
     private final ArrayMap<IBinder, ConnectionRecord> mConnections = new ArrayMap();
     private final Handler mHandler = new Handler();
+    private ServiceBinder mBinder;
     MediaSessionCompat.Token mSession;
 
-    interface MediaBrowserServiceImpl {
-        public void onCreate();
-        IBinder onBind(Intent intent);
-    }
-
-    class MediaBrowserServiceImplBase implements MediaBrowserServiceImpl {
-        private ServiceBinderCompat mBinder;
-
-        @Override
-        public void onCreate() {
-            mBinder = new ServiceBinderCompat(new ServiceStub());
-        }
-
-        @Override
-        public IBinder onBind(Intent intent) {
-            // STOPSHIP: Use messenger or version management for further extension
-            if (SERVICE_INTERFACE.equals(intent.getAction())) {
-                return mBinder;
-            }
-            return null;
-        }
-    }
-
-    class MediaBrowserServiceImplApi21 implements MediaBrowserServiceImpl {
-        private Object mServiceObj;
-
-        @Override
-        public void onCreate() {
-            mServiceObj = MediaBrowserServiceCompatApi21.createService();
-            MediaBrowserServiceCompatApi21.onCreate(mServiceObj,
-                    new ServiceStubApi21(new ServiceStub()));
-        }
-
-        @Override
-        public IBinder onBind(Intent intent) {
-            return MediaBrowserServiceCompatApi21.onBind(mServiceObj, intent);
-        }
-    }
-
     /**
      * All the info about a connection.
      */
     private class ConnectionRecord {
         String pkg;
         Bundle rootHints;
-        ServiceCallbacks callbacks;
+        IMediaBrowserServiceCompatCallbacks callbacks;
         BrowserRoot root;
         HashSet<String> subscriptions = new HashSet();
     }
@@ -147,7 +106,7 @@
      * @see MediaBrowserServiceCompat#onLoadChildren
      * @see MediaBrowserServiceCompat#onLoadItem
      */
-    public static class Result<T> {
+    public class Result<T> {
         private Object mDebug;
         private boolean mDetachCalled;
         private boolean mSendResultCalled;
@@ -195,9 +154,10 @@
         }
     }
 
-    private class ServiceStub {
+    private class ServiceBinder extends IMediaBrowserServiceCompat.Stub {
+        @Override
         public void connect(final String pkg, final Bundle rootHints,
-                final ServiceCallbacks callbacks) {
+                final IMediaBrowserServiceCompatCallbacks callbacks) {
 
             final int uid = Binder.getCallingUid();
             if (!isValidPackage(pkg, uid)) {
@@ -206,84 +166,89 @@
             }
 
             mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    final IBinder b = callbacks.asBinder();
+                    @Override
+                    public void run() {
+                        final IBinder b = callbacks.asBinder();
 
-                    // Clear out the old subscriptions.  We are getting new ones.
-                    mConnections.remove(b);
+                        // Clear out the old subscriptions.  We are getting new ones.
+                        mConnections.remove(b);
 
-                    final ConnectionRecord connection = new ConnectionRecord();
-                    connection.pkg = pkg;
-                    connection.rootHints = rootHints;
-                    connection.callbacks = callbacks;
+                        final ConnectionRecord connection = new ConnectionRecord();
+                        connection.pkg = pkg;
+                        connection.rootHints = rootHints;
+                        connection.callbacks = callbacks;
 
-                    connection.root =
-                            MediaBrowserServiceCompat.this.onGetRoot(pkg, uid, rootHints);
+                        connection.root =
+                                MediaBrowserServiceCompat.this.onGetRoot(pkg, uid, rootHints);
 
-                    // If they didn't return something, don't allow this client.
-                    if (connection.root == null) {
-                        Log.i(TAG, "No root for client " + pkg + " from service "
-                                + getClass().getName());
-                        try {
-                            callbacks.onConnectFailed();
-                        } catch (RemoteException ex) {
-                            Log.w(TAG, "Calling onConnectFailed() failed. Ignoring. "
-                                    + "pkg=" + pkg);
-                        }
-                    } else {
-                        try {
-                            mConnections.put(b, connection);
-                            if (mSession != null) {
-                                callbacks.onConnect(connection.root.getRootId(),
-                                        mSession, connection.root.getExtras());
+                        // If they didn't return something, don't allow this client.
+                        if (connection.root == null) {
+                            Log.i(TAG, "No root for client " + pkg + " from service "
+                                    + getClass().getName());
+                            try {
+                                callbacks.onConnectFailed();
+                            } catch (RemoteException ex) {
+                                Log.w(TAG, "Calling onConnectFailed() failed. Ignoring. "
+                                        + "pkg=" + pkg);
                             }
-                        } catch (RemoteException ex) {
-                            Log.w(TAG, "Calling onConnect() failed. Dropping client. "
-                                    + "pkg=" + pkg);
-                            mConnections.remove(b);
+                        } else {
+                            try {
+                                mConnections.put(b, connection);
+                                if (mSession != null) {
+                                    callbacks.onConnect(connection.root.getRootId(),
+                                            mSession, connection.root.getExtras());
+                                }
+                            } catch (RemoteException ex) {
+                                Log.w(TAG, "Calling onConnect() failed. Dropping client. "
+                                        + "pkg=" + pkg);
+                                mConnections.remove(b);
+                            }
                         }
                     }
-                }
-            });
+                });
         }
 
-        public void disconnect(final ServiceCallbacks callbacks) {
+        @Override
+        public void disconnect(final IMediaBrowserServiceCompatCallbacks callbacks) {
             mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    final IBinder b = callbacks.asBinder();
+                    @Override
+                    public void run() {
+                        final IBinder b = callbacks.asBinder();
 
-                    // Clear out the old subscriptions.  We are getting new ones.
-                    final ConnectionRecord old = mConnections.remove(b);
-                    if (old != null) {
-                        // TODO
+                        // Clear out the old subscriptions.  We are getting new ones.
+                        final ConnectionRecord old = mConnections.remove(b);
+                        if (old != null) {
+                            // TODO
+                        }
                     }
-                }
-            });
+                });
         }
 
 
-        public void addSubscription(final String id, final ServiceCallbacks callbacks) {
+        @Override
+        public void addSubscription(
+                final String id, final IMediaBrowserServiceCompatCallbacks callbacks) {
             mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    final IBinder b = callbacks.asBinder();
+                    @Override
+                    public void run() {
+                        final IBinder b = callbacks.asBinder();
 
-                    // Get the record for the connection
-                    final ConnectionRecord connection = mConnections.get(b);
-                    if (connection == null) {
-                        Log.w(TAG, "addSubscription for callback that isn't registered id="
+                        // Get the record for the connection
+                        final ConnectionRecord connection = mConnections.get(b);
+                        if (connection == null) {
+                            Log.w(TAG, "addSubscription for callback that isn't registered id="
                                 + id);
-                        return;
-                    }
+                            return;
+                        }
 
-                    MediaBrowserServiceCompat.this.addSubscription(id, connection);
-                }
-            });
+                        MediaBrowserServiceCompat.this.addSubscription(id, connection);
+                    }
+                });
         }
 
-        public void removeSubscription(final String id, final ServiceCallbacks callbacks) {
+        @Override
+        public void removeSubscription(final String id,
+                final IMediaBrowserServiceCompatCallbacks callbacks) {
             mHandler.post(new Runnable() {
                 @Override
                 public void run() {
@@ -303,6 +268,7 @@
             });
         }
 
+        @Override
         public void getMediaItem(final String mediaId, final ResultReceiver receiver) {
             if (TextUtils.isEmpty(mediaId) || receiver == null) {
                 return;
@@ -317,171 +283,18 @@
         }
     }
 
-    private class ServiceBinderCompat extends IMediaBrowserServiceCompat.Stub {
-        final ServiceStub mServiceStub;
-
-        ServiceBinderCompat(ServiceStub binder) {
-            mServiceStub = binder;
-        }
-
-        @Override
-        public void connect(final String pkg, final Bundle rootHints,
-                final IMediaBrowserServiceCompatCallbacks callbacks) {
-            mServiceStub.connect(pkg, rootHints, new ServiceCallbacksCompat(callbacks));
-        }
-
-        @Override
-        public void disconnect(final IMediaBrowserServiceCompatCallbacks callbacks) {
-            mConnections.get(callbacks.asBinder());
-            mServiceStub.disconnect(new ServiceCallbacksCompat(callbacks));
-        }
-
-
-        @Override
-        public void addSubscription(
-                final String id, final IMediaBrowserServiceCompatCallbacks callbacks) {
-            mServiceStub.addSubscription(id, new ServiceCallbacksCompat(callbacks));
-        }
-
-        @Override
-        public void removeSubscription(final String id,
-                final IMediaBrowserServiceCompatCallbacks callbacks) {
-            mServiceStub.removeSubscription(id, new ServiceCallbacksCompat(callbacks));
-        }
-
-        @Override
-        public void getMediaItem(final String mediaId, final ResultReceiver receiver) {
-            mServiceStub.getMediaItem(mediaId, receiver);
-        }
-    }
-
-    private class ServiceStubApi21 implements MediaBrowserServiceCompatApi21.ServiceStub {
-        final ServiceStub mBinder;
-
-        ServiceStubApi21(ServiceStub binder) {
-            mBinder = binder;
-        }
-
-        @Override
-        public void connect(final String pkg, final Bundle rootHints,
-                final MediaBrowserServiceCompatApi21.ServiceCallbacks callbacks) {
-            mBinder.connect(pkg, rootHints, new ServiceCallbacksApi21(callbacks));
-        }
-
-        @Override
-        public void disconnect(final MediaBrowserServiceCompatApi21.ServiceCallbacks callbacks) {
-            mBinder.disconnect(new ServiceCallbacksApi21(callbacks));
-        }
-
-
-        @Override
-        public void addSubscription(
-                final String id, final MediaBrowserServiceCompatApi21.ServiceCallbacks callbacks) {
-            mBinder.addSubscription(id, new ServiceCallbacksApi21(callbacks));
-        }
-
-        @Override
-        public void removeSubscription(final String id,
-                final MediaBrowserServiceCompatApi21.ServiceCallbacks callbacks) {
-            mBinder.removeSubscription(id, new ServiceCallbacksApi21(callbacks));
-        }
-
-        @Override
-        public void getMediaItem(final String mediaId, final android.os.ResultReceiver receiver) {
-            ResultReceiver receiverCompat = new ResultReceiver(mHandler) {
-                @Override
-                protected void onReceiveResult(int resultCode, Bundle resultData) {
-                    receiver.send(resultCode, resultData);
-                }
-            };
-            mBinder.getMediaItem(mediaId, receiverCompat);
-        }
-    }
-
-    private interface ServiceCallbacks {
-        IBinder asBinder();
-        void onConnect(String root, MediaSessionCompat.Token session, Bundle extras)
-                throws RemoteException;
-        void onConnectFailed() throws RemoteException;
-        void onLoadChildren(String mediaId, List<MediaBrowserCompat.MediaItem> list)
-                throws RemoteException;
-    }
-
-    private class ServiceCallbacksCompat implements ServiceCallbacks {
-        final IMediaBrowserServiceCompatCallbacks mCallbacks;
-
-        ServiceCallbacksCompat(IMediaBrowserServiceCompatCallbacks callbacks) {
-            mCallbacks = callbacks;
-        }
-
-        public IBinder asBinder() {
-            return mCallbacks.asBinder();
-        }
-
-        public void onConnect(String root, MediaSessionCompat.Token session, Bundle extras)
-                throws RemoteException {
-            mCallbacks.onConnect(root, session, extras);
-        }
-
-        public void onConnectFailed() throws RemoteException {
-            mCallbacks.onConnectFailed();
-        }
-
-        public void onLoadChildren(String mediaId, List<MediaBrowserCompat.MediaItem> list)
-                throws RemoteException {
-            mCallbacks.onLoadChildren(mediaId, list);
-        }
-    }
-
-    private class ServiceCallbacksApi21 implements ServiceCallbacks {
-        final MediaBrowserServiceCompatApi21.ServiceCallbacks mCallbacks;
-
-        ServiceCallbacksApi21(MediaBrowserServiceCompatApi21.ServiceCallbacks callbacks) {
-            mCallbacks = callbacks;
-        }
-
-        public IBinder asBinder() {
-            return mCallbacks.asBinder();
-        }
-
-        public void onConnect(String root, MediaSessionCompat.Token session, Bundle extras)
-                throws RemoteException {
-            mCallbacks.onConnect(root, session.getToken(), extras);
-        }
-
-        public void onConnectFailed() throws RemoteException {
-            mCallbacks.onConnectFailed();
-        }
-
-        public void onLoadChildren(String mediaId, List<MediaBrowserCompat.MediaItem> list)
-                throws RemoteException {
-            List<Parcel> parcelList = null;
-            if (list != null) {
-                parcelList = new ArrayList<>();
-                for (MediaBrowserCompat.MediaItem item : list) {
-                    Parcel parcel = Parcel.obtain();
-                    item.writeToParcel(parcel, 0);
-                    parcelList.add(parcel);
-                }
-            }
-            mCallbacks.onLoadChildren(mediaId, parcelList);
-        }
-    }
-
     @Override
     public void onCreate() {
         super.onCreate();
-        if (Build.VERSION.SDK_INT >= 21) {
-            mImpl = new MediaBrowserServiceImplApi21();
-        } else {
-            mImpl = new MediaBrowserServiceImplBase();
-        }
-        mImpl.onCreate();
+        mBinder = new ServiceBinder();
     }
 
     @Override
     public IBinder onBind(Intent intent) {
-        return mImpl.onBind(intent);
+        if (SERVICE_INTERFACE.equals(intent.getAction())) {
+            return mBinder;
+        }
+        return null;
     }
 
     @Override