package o;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.os.IInterface;
import android.os.RemoteException;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.internal.BaseGmsClient;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.stats.ConnectionTracker;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Qt0 implements ServiceConnection, BaseGmsClient.BaseConnectionCallbacks, BaseGmsClient.BaseOnConnectionFailedListener {
    public volatile boolean a;
    public volatile Gq0 b;
    public final /* synthetic */ Vt0 c;

    public Qt0(Vt0 vt0) {
        this.c = vt0;
    }

    @Override // com.google.android.gms.common.internal.BaseGmsClient.BaseConnectionCallbacks
    public final void onConnected(Bundle bundle) {
        Fr0 fr0 = ((Kr0) this.c.a).g;
        Kr0.l(fr0);
        fr0.x();
        synchronized (this) {
            try {
                Preconditions.checkNotNull(this.b);
                InterfaceC2185pq0 interfaceC2185pq0 = (InterfaceC2185pq0) this.b.getService();
                Fr0 fr02 = ((Kr0) this.c.a).g;
                Kr0.l(fr02);
                fr02.B(new Jt0(this, interfaceC2185pq0, 1));
            } catch (DeadObjectException | IllegalStateException unused) {
                this.b = null;
                this.a = false;
            }
        }
    }

    @Override // com.google.android.gms.common.internal.BaseGmsClient.BaseOnConnectionFailedListener
    public final void onConnectionFailed(ConnectionResult connectionResult) {
        Vt0 vt0 = this.c;
        Fr0 fr0 = ((Kr0) vt0.a).g;
        Kr0.l(fr0);
        fr0.x();
        Nq0 nq0 = ((Kr0) vt0.a).f;
        if (nq0 == null || !nq0.b) {
            nq0 = null;
        }
        if (nq0 != null) {
            nq0.n.c(connectionResult, "Service connection failed");
        }
        synchronized (this) {
            this.a = false;
            this.b = null;
        }
        Fr0 fr02 = ((Kr0) this.c.a).g;
        Kr0.l(fr02);
        fr02.B(new Js0(10, this, connectionResult));
    }

    @Override // com.google.android.gms.common.internal.BaseGmsClient.BaseConnectionCallbacks
    public final void onConnectionSuspended(int i) {
        Kr0 kr0 = (Kr0) this.c.a;
        Fr0 fr0 = kr0.g;
        Kr0.l(fr0);
        fr0.x();
        Nq0 nq0 = kr0.f;
        Kr0.l(nq0);
        nq0.m.b("Service connection suspended");
        Fr0 fr02 = kr0.g;
        Kr0.l(fr02);
        fr02.B(new RunnableC2017o3(28, this));
    }

    @Override // android.content.ServiceConnection
    public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        Fr0 fr0 = ((Kr0) this.c.a).g;
        Kr0.l(fr0);
        fr0.x();
        synchronized (this) {
            if (iBinder == null) {
                this.a = false;
                Nq0 nq0 = ((Kr0) this.c.a).f;
                Kr0.l(nq0);
                nq0.f.b("Service connected with null binder");
                return;
            }
            InterfaceC2185pq0 c1995nq0 = null;
            try {
                String interfaceDescriptor = iBinder.getInterfaceDescriptor();
                if ("com.google.android.gms.measurement.internal.IMeasurementService".equals(interfaceDescriptor)) {
                    IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.measurement.internal.IMeasurementService");
                    c1995nq0 = iInterfaceQueryLocalInterface instanceof InterfaceC2185pq0 ? (InterfaceC2185pq0) iInterfaceQueryLocalInterface : new C1995nq0(iBinder);
                    Nq0 nq02 = ((Kr0) this.c.a).f;
                    Kr0.l(nq02);
                    nq02.n.b("Bound to IMeasurementService interface");
                } else {
                    Nq0 nq03 = ((Kr0) this.c.a).f;
                    Kr0.l(nq03);
                    nq03.f.c(interfaceDescriptor, "Got binder with a wrong descriptor");
                }
            } catch (RemoteException unused) {
                Nq0 nq04 = ((Kr0) this.c.a).f;
                Kr0.l(nq04);
                nq04.f.b("Service connect failed to get IMeasurementService");
            }
            if (c1995nq0 == null) {
                this.a = false;
                try {
                    ConnectionTracker connectionTracker = ConnectionTracker.getInstance();
                    Vt0 vt0 = this.c;
                    connectionTracker.unbindService(((Kr0) vt0.a).a, vt0.c);
                } catch (IllegalArgumentException unused2) {
                }
            } else {
                Fr0 fr02 = ((Kr0) this.c.a).g;
                Kr0.l(fr02);
                fr02.B(new Jt0(this, c1995nq0, 0));
            }
        }
    }

    @Override // android.content.ServiceConnection
    public final void onServiceDisconnected(ComponentName componentName) {
        Kr0 kr0 = (Kr0) this.c.a;
        Fr0 fr0 = kr0.g;
        Kr0.l(fr0);
        fr0.x();
        Nq0 nq0 = kr0.f;
        Kr0.l(nq0);
        nq0.m.b("Service disconnected");
        Fr0 fr02 = kr0.g;
        Kr0.l(fr02);
        fr02.B(new Js0(8, this, componentName));
    }
}
