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

import android.content.Context;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.HandlerThread;
import android.os.Parcel;
import java.util.concurrent.LinkedBlockingQueue;

/* JADX INFO: loaded from: classes2.dex */
public final class jh1 implements 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 final wh1 f12864a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f12865b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f12866c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final zzbch f12867d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final LinkedBlockingQueue f12868e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final HandlerThread f12869f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final ch1 f12870g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final long f12871h;

    public jh1(Context context, zzbch zzbchVar, String str, String str2, ch1 ch1Var) {
        this.f12865b = str;
        this.f12867d = zzbchVar;
        this.f12866c = str2;
        this.f12870g = ch1Var;
        HandlerThread handlerThread = new HandlerThread("GassDGClient");
        this.f12869f = handlerThread;
        handlerThread.start();
        this.f12871h = System.currentTimeMillis();
        wh1 wh1Var = new wh1(context, handlerThread.getLooper(), this, this, 19621000);
        this.f12864a = wh1Var;
        this.f12868e = new LinkedBlockingQueue();
        wh1Var.checkAvailabilityAndConnect();
    }

    public final void a() {
        wh1 wh1Var = this.f12864a;
        if (wh1Var != null) {
            if (wh1Var.isConnected() || wh1Var.isConnecting()) {
                wh1Var.disconnect();
            }
        }
    }

    public final void b(int i10, long j10, Exception exc) {
        ch1 ch1Var = this.f12870g;
        if (ch1Var != null) {
            ch1Var.c(i10, System.currentTimeMillis() - j10, exc);
        }
    }

    @Override // com.google.android.gms.common.internal.b
    public final void onConnected(Bundle bundle) {
        zh1 zh1VarC;
        long j10 = this.f12871h;
        HandlerThread handlerThread = this.f12869f;
        try {
            zh1VarC = this.f12864a.c();
        } catch (DeadObjectException | IllegalStateException unused) {
            zh1VarC = null;
        }
        if (zh1VarC != null) {
            try {
                di1 di1Var = new di1(1, 1, this.f12867d.zza(), this.f12865b, this.f12866c);
                Parcel parcelO = zh1VarC.O();
                aj.b(parcelO, di1Var);
                Parcel parcelB0 = zh1VarC.B0(3, parcelO);
                ei1 ei1Var = (ei1) aj.a(parcelB0, ei1.CREATOR);
                parcelB0.recycle();
                b(5011, j10, null);
                this.f12868e.put(ei1Var);
            } finally {
                try {
                } finally {
                }
            }
        }
    }

    @Override // com.google.android.gms.common.internal.c
    public final void onConnectionFailed(e8.b bVar) {
        try {
            b(4012, this.f12871h, null);
            this.f12868e.put(new ei1());
        } catch (InterruptedException unused) {
        }
    }

    @Override // com.google.android.gms.common.internal.b
    public final void onConnectionSuspended(int i10) {
        try {
            b(4011, this.f12871h, null);
            this.f12868e.put(new ei1());
        } catch (InterruptedException unused) {
        }
    }
}
