package com.google.android.gms.measurement.internal;

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;

/* JADX INFO: loaded from: classes2.dex */
public final class h3 implements ServiceConnection, com.google.android.gms.common.internal.b, com.google.android.gms.common.internal.c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public volatile boolean f21653a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public volatile n0 f21654b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ a3 f21655c;

    public h3(a3 a3Var) {
        this.f21655c = a3Var;
    }

    @Override // com.google.android.gms.common.internal.b
    public final void onConnected(Bundle bundle) {
        com.google.android.gms.common.internal.w.d("MeasurementServiceConnection.onConnected");
        synchronized (this) {
            try {
                com.google.android.gms.common.internal.w.checkNotNull(this.f21654b);
                this.f21655c.zzl().I(new g3(this, (h0) this.f21654b.getService(), 1));
            } catch (DeadObjectException | IllegalStateException unused) {
                this.f21654b = null;
                this.f21653a = false;
            }
        }
    }

    @Override // com.google.android.gms.common.internal.c
    public final void onConnectionFailed(e8.b bVar) {
        int i10;
        com.google.android.gms.common.internal.w.d("MeasurementServiceConnection.onConnectionFailed");
        p0 p0Var = ((m1) this.f21655c.f31277a).f21757i;
        if (p0Var == null || !p0Var.f21470b) {
            p0Var = null;
        }
        if (p0Var != null) {
            p0Var.f21837i.b(bVar, "Service connection failed");
        }
        synchronized (this) {
            i10 = 0;
            this.f21653a = false;
            this.f21654b = null;
        }
        this.f21655c.zzl().I(new i3(this, i10));
    }

    @Override // com.google.android.gms.common.internal.b
    public final void onConnectionSuspended(int i10) {
        com.google.android.gms.common.internal.w.d("MeasurementServiceConnection.onConnectionSuspended");
        a3 a3Var = this.f21655c;
        a3Var.zzj().f21841m.c("Service connection suspended");
        a3Var.zzl().I(new i3(this, 1));
    }

    @Override // android.content.ServiceConnection
    public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        com.google.android.gms.common.internal.w.d("MeasurementServiceConnection.onServiceConnected");
        synchronized (this) {
            int i10 = 0;
            if (iBinder == null) {
                this.f21653a = false;
                this.f21655c.zzj().f21834f.c("Service connected with null binder");
                return;
            }
            h0 i0Var = 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");
                    i0Var = iInterfaceQueryLocalInterface instanceof h0 ? (h0) iInterfaceQueryLocalInterface : new i0(iBinder);
                    this.f21655c.zzj().f21842n.c("Bound to IMeasurementService interface");
                } else {
                    this.f21655c.zzj().f21834f.b(interfaceDescriptor, "Got binder with a wrong descriptor");
                }
            } catch (RemoteException unused) {
                this.f21655c.zzj().f21834f.c("Service connect failed to get IMeasurementService");
            }
            if (i0Var == null) {
                this.f21653a = false;
                try {
                    h8.a.b().c(this.f21655c.zza(), this.f21655c.f21471c);
                } catch (IllegalArgumentException unused2) {
                }
            } else {
                this.f21655c.zzl().I(new g3(this, i0Var, i10));
            }
        }
    }

    @Override // android.content.ServiceConnection
    public final void onServiceDisconnected(ComponentName componentName) {
        com.google.android.gms.common.internal.w.d("MeasurementServiceConnection.onServiceDisconnected");
        a3 a3Var = this.f21655c;
        a3Var.zzj().f21841m.c("Service disconnected");
        a3Var.zzl().I(new s1(this, componentName, 10));
    }
}
