package android.support.v4.media;

import android.content.ComponentName;
import android.content.Context;
import android.media.browse.MediaBrowser;
import android.media.browse.MediaBrowser.ConnectionCallback;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Messenger;
import android.os.RemoteException;
import android.support.v4.app.e;
import android.support.v4.media.MediaBrowserCompat.b;
import android.support.v4.media.MediaBrowserCompat.b.a;
import android.support.v4.media.MediaBrowserCompat.d;
import android.support.v4.media.MediaBrowserCompat.i;
import android.support.v4.media.MediaBrowserCompat.j;
import android.support.v4.media.MediaBrowserCompat.k;
import android.support.v4.media.session.MediaSessionCompat.Token;

class MediaBrowserCompat$e implements a, d, i {
    protected final Object HQ;
    protected final Bundle HR;
    protected final MediaBrowserCompat.a HS = new MediaBrowserCompat.a(this);
    private final android.support.v4.f.a<String, k> HT = new android.support.v4.f.a();
    protected int HU;
    protected j HV;
    protected Messenger HW;
    private Token HX;
    final Context mContext;

    MediaBrowserCompat$e(Context context, ComponentName componentName, b bVar) {
        this.mContext = context;
        Bundle bundle = new Bundle();
        bundle.putInt("extra_client_version", 1);
        this.HR = new Bundle(bundle);
        bVar.HN = this;
        this.HQ = new MediaBrowser(context, componentName, (ConnectionCallback) bVar.HM, this.HR);
    }

    public final void connect() {
        ((MediaBrowser) this.HQ).connect();
    }

    public final void disconnect() {
        if (!(this.HV == null || this.HW == null)) {
            try {
                this.HV.a(7, null, this.HW);
            } catch (RemoteException e) {
            }
        }
        ((MediaBrowser) this.HQ).disconnect();
    }

    public final Token dH() {
        if (this.HX == null) {
            this.HX = Token.z(((MediaBrowser) this.HQ).getSessionToken());
        }
        return this.HX;
    }

    public final void onConnected() {
        Bundle extras = ((MediaBrowser) this.HQ).getExtras();
        if (extras != null) {
            this.HU = extras.getInt("extra_service_version", 0);
            IBinder c = e.c(extras, "extra_messenger");
            if (c != null) {
                this.HV = new j(c, this.HR);
                this.HW = new Messenger(this.HS);
                this.HS.a(this.HW);
                try {
                    j jVar = this.HV;
                    Messenger messenger = this.HW;
                    Bundle bundle = new Bundle();
                    bundle.putBundle("data_root_hints", jVar.HR);
                    jVar.a(6, bundle, messenger);
                } catch (RemoteException e) {
                }
            }
            android.support.v4.media.session.b d = android.support.v4.media.session.b.a.d(e.c(extras, "extra_session_binder"));
            if (d != null) {
                this.HX = Token.a(((MediaBrowser) this.HQ).getSessionToken(), d);
            }
        }
    }

    public final void onConnectionSuspended() {
        this.HV = null;
        this.HW = null;
        this.HX = null;
        this.HS.a(null);
    }

    public final void a(Messenger messenger, String str, Token token, Bundle bundle) {
    }

    public final void b(Messenger messenger) {
    }

    public final void a(Messenger messenger, String str, Bundle bundle) {
        if (this.HW == messenger) {
            k kVar = (k) this.HT.get(str);
            if (kVar == null) {
                boolean z = MediaBrowserCompat.DEBUG;
            } else {
                kVar.c(this.mContext, bundle);
            }
        }
    }
}
