package android.support.v4.media; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.BadParcelableException; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; import android.support.v4.media.MediaBrowserCompatApi21; import android.support.v4.media.MediaBrowserCompatApi26; import android.support.v4.media.session.IMediaSession; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.os.ResultReceiver; import android.text.TextUtils; import android.util.Log; import androidx.collection.ArrayMap; import androidx.core.app.BundleCompat; import androidx.media.MediaBrowserCompatUtils; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ public final class MediaBrowserCompat { static final boolean b = Log.isLoggable("MediaBrowserCompat", 3); private final MediaBrowserImpl a; private static class CallbackHandler extends Handler { private final WeakReference a; private WeakReference b; CallbackHandler(MediaBrowserServiceCallbackImpl mediaBrowserServiceCallbackImpl) { this.a = new WeakReference<>(mediaBrowserServiceCallbackImpl); } void a(Messenger messenger) { this.b = new WeakReference<>(messenger); } @Override // android.os.Handler public void handleMessage(Message message) { WeakReference weakReference = this.b; if (weakReference == null || weakReference.get() == null || this.a.get() == null) { return; } Bundle data = message.getData(); MediaSessionCompat.a(data); MediaBrowserServiceCallbackImpl mediaBrowserServiceCallbackImpl = this.a.get(); Messenger messenger = this.b.get(); try { int i = message.what; if (i == 1) { Bundle bundle = data.getBundle("data_root_hints"); MediaSessionCompat.a(bundle); mediaBrowserServiceCallbackImpl.a(messenger, data.getString("data_media_item_id"), (MediaSessionCompat.Token) data.getParcelable("data_media_session_token"), bundle); } else if (i == 2) { mediaBrowserServiceCallbackImpl.a(messenger); } else if (i != 3) { Log.w("MediaBrowserCompat", "Unhandled message: " + message + "\n Client version: 1\n Service version: " + message.arg1); } else { Bundle bundle2 = data.getBundle("data_options"); MediaSessionCompat.a(bundle2); Bundle bundle3 = data.getBundle("data_notify_children_changed_options"); MediaSessionCompat.a(bundle3); mediaBrowserServiceCallbackImpl.a(messenger, data.getString("data_media_item_id"), data.getParcelableArrayList("data_media_item_list"), bundle2, bundle3); } } catch (BadParcelableException unused) { Log.e("MediaBrowserCompat", "Could not unparcel the data."); if (message.what == 1) { mediaBrowserServiceCallbackImpl.a(messenger); } } } } public static class ConnectionCallback { final Object a; ConnectionCallbackInternal b; interface ConnectionCallbackInternal { void b(); void d(); void onConnected(); } private class StubApi21 implements MediaBrowserCompatApi21.ConnectionCallback { StubApi21() { } @Override // android.support.v4.media.MediaBrowserCompatApi21.ConnectionCallback public void b() { ConnectionCallbackInternal connectionCallbackInternal = ConnectionCallback.this.b; if (connectionCallbackInternal != null) { connectionCallbackInternal.b(); } ConnectionCallback.this.c(); } @Override // android.support.v4.media.MediaBrowserCompatApi21.ConnectionCallback public void d() { ConnectionCallbackInternal connectionCallbackInternal = ConnectionCallback.this.b; if (connectionCallbackInternal != null) { connectionCallbackInternal.d(); } ConnectionCallback.this.b(); } @Override // android.support.v4.media.MediaBrowserCompatApi21.ConnectionCallback public void onConnected() { ConnectionCallbackInternal connectionCallbackInternal = ConnectionCallback.this.b; if (connectionCallbackInternal != null) { connectionCallbackInternal.onConnected(); } ConnectionCallback.this.a(); } } public ConnectionCallback() { if (Build.VERSION.SDK_INT >= 21) { this.a = MediaBrowserCompatApi21.a((MediaBrowserCompatApi21.ConnectionCallback) new StubApi21()); } else { this.a = null; } } public void a() { throw null; } void a(ConnectionCallbackInternal connectionCallbackInternal) { this.b = connectionCallbackInternal; } public void b() { throw null; } public void c() { throw null; } } public static abstract class CustomActionCallback { public abstract void a(String str, Bundle bundle, Bundle bundle2); public abstract void b(String str, Bundle bundle, Bundle bundle2); public abstract void c(String str, Bundle bundle, Bundle bundle2); } private static class CustomActionResultReceiver extends ResultReceiver { private final String mAction; private final CustomActionCallback mCallback; private final Bundle mExtras; CustomActionResultReceiver(String str, Bundle bundle, CustomActionCallback customActionCallback, Handler handler) { super(handler); this.mAction = str; this.mExtras = bundle; this.mCallback = customActionCallback; } @Override // android.support.v4.os.ResultReceiver protected void onReceiveResult(int i, Bundle bundle) { if (this.mCallback == null) { return; } MediaSessionCompat.a(bundle); if (i == -1) { this.mCallback.a(this.mAction, this.mExtras, bundle); return; } if (i == 0) { this.mCallback.c(this.mAction, this.mExtras, bundle); return; } if (i == 1) { this.mCallback.b(this.mAction, this.mExtras, bundle); return; } Log.w("MediaBrowserCompat", "Unknown result code: " + i + " (extras=" + this.mExtras + ", resultData=" + bundle + ")"); } } public static abstract class ItemCallback { public abstract void a(MediaItem mediaItem); public abstract void a(String str); } private static class ItemReceiver extends ResultReceiver { private final ItemCallback mCallback; private final String mMediaId; ItemReceiver(String str, ItemCallback itemCallback, Handler handler) { super(handler); this.mMediaId = str; this.mCallback = itemCallback; } @Override // android.support.v4.os.ResultReceiver protected void onReceiveResult(int i, Bundle bundle) { MediaSessionCompat.a(bundle); if (i != 0 || bundle == null || !bundle.containsKey("media_item")) { this.mCallback.a(this.mMediaId); return; } Parcelable parcelable = bundle.getParcelable("media_item"); if (parcelable == null || (parcelable instanceof MediaItem)) { this.mCallback.a((MediaItem) parcelable); } else { this.mCallback.a(this.mMediaId); } } } interface MediaBrowserImpl { void a(); void c(); MediaSessionCompat.Token e(); } static class MediaBrowserImplApi23 extends MediaBrowserImplApi21 { MediaBrowserImplApi23(Context context, ComponentName componentName, ConnectionCallback connectionCallback, Bundle bundle) { super(context, componentName, connectionCallback, bundle); } } static class MediaBrowserImplApi26 extends MediaBrowserImplApi23 { MediaBrowserImplApi26(Context context, ComponentName componentName, ConnectionCallback connectionCallback, Bundle bundle) { super(context, componentName, connectionCallback, bundle); } } interface MediaBrowserServiceCallbackImpl { void a(Messenger messenger); void a(Messenger messenger, String str, MediaSessionCompat.Token token, Bundle bundle); void a(Messenger messenger, String str, List list, Bundle bundle, Bundle bundle2); } public static abstract class SearchCallback { public abstract void a(String str, Bundle bundle); public abstract void a(String str, Bundle bundle, List list); } private static class SearchResultReceiver extends ResultReceiver { private final SearchCallback mCallback; private final Bundle mExtras; private final String mQuery; SearchResultReceiver(String str, Bundle bundle, SearchCallback searchCallback, Handler handler) { super(handler); this.mQuery = str; this.mExtras = bundle; this.mCallback = searchCallback; } @Override // android.support.v4.os.ResultReceiver protected void onReceiveResult(int i, Bundle bundle) { MediaSessionCompat.a(bundle); if (i != 0 || bundle == null || !bundle.containsKey("search_results")) { this.mCallback.a(this.mQuery, this.mExtras); return; } Parcelable[] parcelableArray = bundle.getParcelableArray("search_results"); ArrayList arrayList = null; if (parcelableArray != null) { arrayList = new ArrayList(); for (Parcelable parcelable : parcelableArray) { arrayList.add((MediaItem) parcelable); } } this.mCallback.a(this.mQuery, this.mExtras, arrayList); } } private static class Subscription { private final List a = new ArrayList(); private final List b = new ArrayList(); public List a() { return this.a; } public List b() { return this.b; } public SubscriptionCallback a(Bundle bundle) { for (int i = 0; i < this.b.size(); i++) { if (MediaBrowserCompatUtils.a(this.b.get(i), bundle)) { return this.a.get(i); } } return null; } } public MediaBrowserCompat(Context context, ComponentName componentName, ConnectionCallback connectionCallback, Bundle bundle) { int i = Build.VERSION.SDK_INT; if (i >= 26) { this.a = new MediaBrowserImplApi26(context, componentName, connectionCallback, bundle); return; } if (i >= 23) { this.a = new MediaBrowserImplApi23(context, componentName, connectionCallback, bundle); } else if (i >= 21) { this.a = new MediaBrowserImplApi21(context, componentName, connectionCallback, bundle); } else { this.a = new MediaBrowserImplBase(context, componentName, connectionCallback, bundle); } } public void a() { this.a.c(); } public void b() { this.a.a(); } public MediaSessionCompat.Token c() { return this.a.e(); } static class MediaBrowserImplBase implements MediaBrowserImpl, MediaBrowserServiceCallbackImpl { final Context a; final ComponentName b; final ConnectionCallback c; final Bundle d; final CallbackHandler e = new CallbackHandler(this); private final ArrayMap f = new ArrayMap<>(); int g = 1; MediaServiceConnection h; ServiceBinderWrapper i; Messenger j; private String k; private MediaSessionCompat.Token l; public MediaBrowserImplBase(Context context, ComponentName componentName, ConnectionCallback connectionCallback, Bundle bundle) { if (context == null) { throw new IllegalArgumentException("context must not be null"); } if (componentName == null) { throw new IllegalArgumentException("service component must not be null"); } if (connectionCallback == null) { throw new IllegalArgumentException("connection callback must not be null"); } this.a = context; this.b = componentName; this.c = connectionCallback; this.d = bundle == null ? null : new Bundle(bundle); } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserImpl public void a() { this.g = 0; this.e.post(new Runnable() { // from class: android.support.v4.media.MediaBrowserCompat.MediaBrowserImplBase.2 @Override // java.lang.Runnable public void run() { MediaBrowserImplBase mediaBrowserImplBase = MediaBrowserImplBase.this; Messenger messenger = mediaBrowserImplBase.j; if (messenger != null) { try { mediaBrowserImplBase.i.a(messenger); } catch (RemoteException unused) { Log.w("MediaBrowserCompat", "RemoteException during connect for " + MediaBrowserImplBase.this.b); } } MediaBrowserImplBase mediaBrowserImplBase2 = MediaBrowserImplBase.this; int i = mediaBrowserImplBase2.g; mediaBrowserImplBase2.d(); if (i != 0) { MediaBrowserImplBase.this.g = i; } if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "disconnect..."); MediaBrowserImplBase.this.b(); } } }); } void b() { Log.d("MediaBrowserCompat", "MediaBrowserCompat..."); Log.d("MediaBrowserCompat", " mServiceComponent=" + this.b); Log.d("MediaBrowserCompat", " mCallback=" + this.c); Log.d("MediaBrowserCompat", " mRootHints=" + this.d); Log.d("MediaBrowserCompat", " mState=" + a(this.g)); Log.d("MediaBrowserCompat", " mServiceConnection=" + this.h); Log.d("MediaBrowserCompat", " mServiceBinderWrapper=" + this.i); Log.d("MediaBrowserCompat", " mCallbacksMessenger=" + this.j); Log.d("MediaBrowserCompat", " mRootId=" + this.k); Log.d("MediaBrowserCompat", " mMediaSessionToken=" + this.l); } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserImpl public void c() { int i = this.g; if (i == 0 || i == 1) { this.g = 2; this.e.post(new Runnable() { // from class: android.support.v4.media.MediaBrowserCompat.MediaBrowserImplBase.1 @Override // java.lang.Runnable public void run() { MediaBrowserImplBase mediaBrowserImplBase = MediaBrowserImplBase.this; if (mediaBrowserImplBase.g == 0) { return; } mediaBrowserImplBase.g = 2; if (MediaBrowserCompat.b && mediaBrowserImplBase.h != null) { throw new RuntimeException("mServiceConnection should be null. Instead it is " + MediaBrowserImplBase.this.h); } MediaBrowserImplBase mediaBrowserImplBase2 = MediaBrowserImplBase.this; if (mediaBrowserImplBase2.i != null) { throw new RuntimeException("mServiceBinderWrapper should be null. Instead it is " + MediaBrowserImplBase.this.i); } if (mediaBrowserImplBase2.j != null) { throw new RuntimeException("mCallbacksMessenger should be null. Instead it is " + MediaBrowserImplBase.this.j); } Intent intent = new Intent("android.media.browse.MediaBrowserService"); intent.setComponent(MediaBrowserImplBase.this.b); MediaBrowserImplBase mediaBrowserImplBase3 = MediaBrowserImplBase.this; mediaBrowserImplBase3.h = mediaBrowserImplBase3.new MediaServiceConnection(); boolean z = false; try { z = MediaBrowserImplBase.this.a.bindService(intent, MediaBrowserImplBase.this.h, 1); } catch (Exception unused) { Log.e("MediaBrowserCompat", "Failed binding to service " + MediaBrowserImplBase.this.b); } if (!z) { MediaBrowserImplBase.this.d(); MediaBrowserImplBase.this.c.b(); } if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "connect..."); MediaBrowserImplBase.this.b(); } } }); } else { throw new IllegalStateException("connect() called while neigther disconnecting nor disconnected (state=" + a(this.g) + ")"); } } void d() { MediaServiceConnection mediaServiceConnection = this.h; if (mediaServiceConnection != null) { this.a.unbindService(mediaServiceConnection); } this.g = 1; this.h = null; this.i = null; this.j = null; this.e.a(null); this.k = null; this.l = null; } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserImpl public MediaSessionCompat.Token e() { if (f()) { return this.l; } throw new IllegalStateException("getSessionToken() called while not connected(state=" + this.g + ")"); } public boolean f() { return this.g == 3; } private class MediaServiceConnection implements ServiceConnection { MediaServiceConnection() { } private void a(Runnable runnable) { if (Thread.currentThread() == MediaBrowserImplBase.this.e.getLooper().getThread()) { runnable.run(); } else { MediaBrowserImplBase.this.e.post(runnable); } } @Override // android.content.ServiceConnection public void onServiceConnected(final ComponentName componentName, final IBinder iBinder) { a(new Runnable() { // from class: android.support.v4.media.MediaBrowserCompat.MediaBrowserImplBase.MediaServiceConnection.1 @Override // java.lang.Runnable public void run() { if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "MediaServiceConnection.onServiceConnected name=" + componentName + " binder=" + iBinder); MediaBrowserImplBase.this.b(); } if (MediaServiceConnection.this.a("onServiceConnected")) { MediaBrowserImplBase mediaBrowserImplBase = MediaBrowserImplBase.this; mediaBrowserImplBase.i = new ServiceBinderWrapper(iBinder, mediaBrowserImplBase.d); MediaBrowserImplBase mediaBrowserImplBase2 = MediaBrowserImplBase.this; mediaBrowserImplBase2.j = new Messenger(mediaBrowserImplBase2.e); MediaBrowserImplBase mediaBrowserImplBase3 = MediaBrowserImplBase.this; mediaBrowserImplBase3.e.a(mediaBrowserImplBase3.j); MediaBrowserImplBase.this.g = 2; try { if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "ServiceCallbacks.onConnect..."); MediaBrowserImplBase.this.b(); } MediaBrowserImplBase.this.i.a(MediaBrowserImplBase.this.a, MediaBrowserImplBase.this.j); } catch (RemoteException unused) { Log.w("MediaBrowserCompat", "RemoteException during connect for " + MediaBrowserImplBase.this.b); if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "ServiceCallbacks.onConnect..."); MediaBrowserImplBase.this.b(); } } } } }); } @Override // android.content.ServiceConnection public void onServiceDisconnected(final ComponentName componentName) { a(new Runnable() { // from class: android.support.v4.media.MediaBrowserCompat.MediaBrowserImplBase.MediaServiceConnection.2 @Override // java.lang.Runnable public void run() { if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "MediaServiceConnection.onServiceDisconnected name=" + componentName + " this=" + this + " mServiceConnection=" + MediaBrowserImplBase.this.h); MediaBrowserImplBase.this.b(); } if (MediaServiceConnection.this.a("onServiceDisconnected")) { MediaBrowserImplBase mediaBrowserImplBase = MediaBrowserImplBase.this; mediaBrowserImplBase.i = null; mediaBrowserImplBase.j = null; mediaBrowserImplBase.e.a(null); MediaBrowserImplBase mediaBrowserImplBase2 = MediaBrowserImplBase.this; mediaBrowserImplBase2.g = 4; mediaBrowserImplBase2.c.c(); } } }); } boolean a(String str) { int i; MediaBrowserImplBase mediaBrowserImplBase = MediaBrowserImplBase.this; if (mediaBrowserImplBase.h == this && (i = mediaBrowserImplBase.g) != 0 && i != 1) { return true; } int i2 = MediaBrowserImplBase.this.g; if (i2 == 0 || i2 == 1) { return false; } Log.i("MediaBrowserCompat", str + " for " + MediaBrowserImplBase.this.b + " with mServiceConnection=" + MediaBrowserImplBase.this.h + " this=" + this); return false; } } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserServiceCallbackImpl public void a(Messenger messenger, String str, MediaSessionCompat.Token token, Bundle bundle) { if (a(messenger, "onConnect")) { if (this.g != 2) { Log.w("MediaBrowserCompat", "onConnect from service while mState=" + a(this.g) + "... ignoring"); return; } this.k = str; this.l = token; this.g = 3; if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "ServiceCallbacks.onConnect..."); b(); } this.c.a(); try { for (Map.Entry entry : this.f.entrySet()) { String key = entry.getKey(); Subscription value = entry.getValue(); List a = value.a(); List b = value.b(); for (int i = 0; i < a.size(); i++) { this.i.a(key, a.get(i).a, b.get(i), this.j); } } } catch (RemoteException unused) { Log.d("MediaBrowserCompat", "addSubscription failed with RemoteException."); } } } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserServiceCallbackImpl public void a(Messenger messenger) { Log.e("MediaBrowserCompat", "onConnectFailed for " + this.b); if (a(messenger, "onConnectFailed")) { if (this.g != 2) { Log.w("MediaBrowserCompat", "onConnect from service while mState=" + a(this.g) + "... ignoring"); return; } d(); this.c.b(); } } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserServiceCallbackImpl public void a(Messenger messenger, String str, List list, Bundle bundle, Bundle bundle2) { if (a(messenger, "onLoadChildren")) { if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "onLoadChildren for " + this.b + " id=" + str); } Subscription subscription = this.f.get(str); if (subscription == null) { if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "onLoadChildren for id that isn't subscribed id=" + str); return; } return; } SubscriptionCallback a = subscription.a(bundle); if (a != null) { if (bundle == null) { if (list == null) { a.a(str); return; } else { a.a(str, (List) list); return; } } if (list == null) { a.a(str, bundle); } else { a.a(str, list, bundle); } } } } private static String a(int i) { if (i == 0) { return "CONNECT_STATE_DISCONNECTING"; } if (i == 1) { return "CONNECT_STATE_DISCONNECTED"; } if (i == 2) { return "CONNECT_STATE_CONNECTING"; } if (i == 3) { return "CONNECT_STATE_CONNECTED"; } if (i == 4) { return "CONNECT_STATE_SUSPENDED"; } return "UNKNOWN/" + i; } private boolean a(Messenger messenger, String str) { int i; if (this.j == messenger && (i = this.g) != 0 && i != 1) { return true; } int i2 = this.g; if (i2 == 0 || i2 == 1) { return false; } Log.i("MediaBrowserCompat", str + " for " + this.b + " with mCallbacksMessenger=" + this.j + " this=" + this); return false; } } public static abstract class SubscriptionCallback { final IBinder a = new Binder(); WeakReference b; public SubscriptionCallback() { int i = Build.VERSION.SDK_INT; if (i >= 26) { MediaBrowserCompatApi26.a(new StubApi26()); } else if (i >= 21) { MediaBrowserCompatApi21.a((MediaBrowserCompatApi21.SubscriptionCallback) new StubApi21()); } } public void a(String str) { } public void a(String str, Bundle bundle) { } public void a(String str, List list) { } public void a(String str, List list, Bundle bundle) { } private class StubApi26 extends StubApi21 implements MediaBrowserCompatApi26.SubscriptionCallback { StubApi26() { super(); } @Override // android.support.v4.media.MediaBrowserCompatApi26.SubscriptionCallback public void a(String str, List list, Bundle bundle) { SubscriptionCallback.this.a(str, MediaItem.fromMediaItemList(list), bundle); } @Override // android.support.v4.media.MediaBrowserCompatApi26.SubscriptionCallback public void a(String str, Bundle bundle) { SubscriptionCallback.this.a(str, bundle); } } private class StubApi21 implements MediaBrowserCompatApi21.SubscriptionCallback { StubApi21() { } @Override // android.support.v4.media.MediaBrowserCompatApi21.SubscriptionCallback public void a(String str, List list) { WeakReference weakReference = SubscriptionCallback.this.b; Subscription subscription = weakReference == null ? null : weakReference.get(); if (subscription == null) { SubscriptionCallback.this.a(str, MediaItem.fromMediaItemList(list)); return; } List fromMediaItemList = MediaItem.fromMediaItemList(list); List a = subscription.a(); List b = subscription.b(); for (int i = 0; i < a.size(); i++) { Bundle bundle = b.get(i); if (bundle == null) { SubscriptionCallback.this.a(str, fromMediaItemList); } else { SubscriptionCallback.this.a(str, a(fromMediaItemList, bundle), bundle); } } } @Override // android.support.v4.media.MediaBrowserCompatApi21.SubscriptionCallback public void b(String str) { SubscriptionCallback.this.a(str); } List a(List list, Bundle bundle) { if (list == null) { return null; } int i = bundle.getInt("android.media.browse.extra.PAGE", -1); int i2 = bundle.getInt("android.media.browse.extra.PAGE_SIZE", -1); if (i == -1 && i2 == -1) { return list; } int i3 = i2 * i; int i4 = i3 + i2; if (i >= 0 && i2 >= 1 && i3 < list.size()) { if (i4 > list.size()) { i4 = list.size(); } return list.subList(i3, i4); } return Collections.emptyList(); } } } static class MediaBrowserImplApi21 implements MediaBrowserImpl, MediaBrowserServiceCallbackImpl, ConnectionCallback.ConnectionCallbackInternal { final Context a; protected final Object b; protected final Bundle c; protected final CallbackHandler d = new CallbackHandler(this); private final ArrayMap e = new ArrayMap<>(); protected ServiceBinderWrapper f; protected Messenger g; private MediaSessionCompat.Token h; MediaBrowserImplApi21(Context context, ComponentName componentName, ConnectionCallback connectionCallback, Bundle bundle) { this.a = context; this.c = bundle != null ? new Bundle(bundle) : new Bundle(); this.c.putInt("extra_client_version", 1); connectionCallback.a(this); this.b = MediaBrowserCompatApi21.a(context, componentName, connectionCallback.a, this.c); } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserImpl public void a() { Messenger messenger; ServiceBinderWrapper serviceBinderWrapper = this.f; if (serviceBinderWrapper != null && (messenger = this.g) != null) { try { serviceBinderWrapper.b(messenger); } catch (RemoteException unused) { Log.i("MediaBrowserCompat", "Remote error unregistering client messenger."); } } MediaBrowserCompatApi21.b(this.b); } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserServiceCallbackImpl public void a(Messenger messenger) { } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserServiceCallbackImpl public void a(Messenger messenger, String str, MediaSessionCompat.Token token, Bundle bundle) { } @Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback.ConnectionCallbackInternal public void b() { this.f = null; this.g = null; this.h = null; this.d.a(null); } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserImpl public void c() { MediaBrowserCompatApi21.a(this.b); } @Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback.ConnectionCallbackInternal public void d() { } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserImpl public MediaSessionCompat.Token e() { if (this.h == null) { this.h = MediaSessionCompat.Token.fromToken(MediaBrowserCompatApi21.d(this.b)); } return this.h; } @Override // android.support.v4.media.MediaBrowserCompat.ConnectionCallback.ConnectionCallbackInternal public void onConnected() { Bundle c = MediaBrowserCompatApi21.c(this.b); if (c == null) { return; } c.getInt("extra_service_version", 0); IBinder a = BundleCompat.a(c, "extra_messenger"); if (a != null) { this.f = new ServiceBinderWrapper(a, this.c); this.g = new Messenger(this.d); this.d.a(this.g); try { this.f.b(this.a, this.g); } catch (RemoteException unused) { Log.i("MediaBrowserCompat", "Remote error registering client messenger."); } } IMediaSession a2 = IMediaSession.Stub.a(BundleCompat.a(c, "extra_session_binder")); if (a2 != null) { this.h = MediaSessionCompat.Token.fromToken(MediaBrowserCompatApi21.d(this.b), a2); } } @Override // android.support.v4.media.MediaBrowserCompat.MediaBrowserServiceCallbackImpl public void a(Messenger messenger, String str, List list, Bundle bundle, Bundle bundle2) { if (this.g != messenger) { return; } Subscription subscription = this.e.get(str); if (subscription == null) { if (MediaBrowserCompat.b) { Log.d("MediaBrowserCompat", "onLoadChildren for id that isn't subscribed id=" + str); return; } return; } SubscriptionCallback a = subscription.a(bundle); if (a != null) { if (bundle == null) { if (list == null) { a.a(str); return; } else { a.a(str, (List) list); return; } } if (list == null) { a.a(str, bundle); } else { a.a(str, list, bundle); } } } } private static class ServiceBinderWrapper { private Messenger a; private Bundle b; public ServiceBinderWrapper(IBinder iBinder, Bundle bundle) { this.a = new Messenger(iBinder); this.b = bundle; } void a(Context context, Messenger messenger) throws RemoteException { Bundle bundle = new Bundle(); bundle.putString("data_package_name", context.getPackageName()); bundle.putBundle("data_root_hints", this.b); a(1, bundle, messenger); } void b(Context context, Messenger messenger) throws RemoteException { Bundle bundle = new Bundle(); bundle.putString("data_package_name", context.getPackageName()); bundle.putBundle("data_root_hints", this.b); a(6, bundle, messenger); } void a(Messenger messenger) throws RemoteException { a(2, null, messenger); } void b(Messenger messenger) throws RemoteException { a(7, null, messenger); } void a(String str, IBinder iBinder, Bundle bundle, Messenger messenger) throws RemoteException { Bundle bundle2 = new Bundle(); bundle2.putString("data_media_item_id", str); BundleCompat.a(bundle2, "data_callback_token", iBinder); bundle2.putBundle("data_options", bundle); a(3, bundle2, messenger); } private void a(int i, Bundle bundle, Messenger messenger) throws RemoteException { Message obtain = Message.obtain(); obtain.what = i; obtain.arg1 = 1; obtain.setData(bundle); obtain.replyTo = messenger; this.a.send(obtain); } } public static class MediaItem implements Parcelable { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { // from class: android.support.v4.media.MediaBrowserCompat.MediaItem.1 /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.Creator public MediaItem createFromParcel(Parcel parcel) { return new MediaItem(parcel); } /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.Creator public MediaItem[] newArray(int i) { return new MediaItem[i]; } }; public static final int FLAG_BROWSABLE = 1; public static final int FLAG_PLAYABLE = 2; private final MediaDescriptionCompat mDescription; private final int mFlags; public MediaItem(MediaDescriptionCompat mediaDescriptionCompat, int i) { if (mediaDescriptionCompat == null) { throw new IllegalArgumentException("description cannot be null"); } if (TextUtils.isEmpty(mediaDescriptionCompat.getMediaId())) { throw new IllegalArgumentException("description must have a non-empty media id"); } this.mFlags = i; this.mDescription = mediaDescriptionCompat; } public static MediaItem fromMediaItem(Object obj) { if (obj == null || Build.VERSION.SDK_INT < 21) { return null; } return new MediaItem(MediaDescriptionCompat.fromMediaDescription(MediaBrowserCompatApi21.MediaItem.a(obj)), MediaBrowserCompatApi21.MediaItem.b(obj)); } public static List fromMediaItemList(List list) { if (list == null || Build.VERSION.SDK_INT < 21) { return null; } ArrayList arrayList = new ArrayList(list.size()); Iterator it = list.iterator(); while (it.hasNext()) { arrayList.add(fromMediaItem(it.next())); } return arrayList; } @Override // android.os.Parcelable public int describeContents() { return 0; } public MediaDescriptionCompat getDescription() { return this.mDescription; } public int getFlags() { return this.mFlags; } public String getMediaId() { return this.mDescription.getMediaId(); } public boolean isBrowsable() { return (this.mFlags & 1) != 0; } public boolean isPlayable() { return (this.mFlags & 2) != 0; } public String toString() { return "MediaItem{mFlags=" + this.mFlags + ", mDescription=" + this.mDescription + '}'; } @Override // android.os.Parcelable public void writeToParcel(Parcel parcel, int i) { parcel.writeInt(this.mFlags); this.mDescription.writeToParcel(parcel, i); } MediaItem(Parcel parcel) { this.mFlags = parcel.readInt(); this.mDescription = MediaDescriptionCompat.CREATOR.createFromParcel(parcel); } } }