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;
import tv.danmaku.ijk.media.player.IjkMediaMeta;

/* JADX INFO: loaded from: classes2.dex */
public final class hh1 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 f12167a;

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

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

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

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

    public hh1(Context context, String str, String str2) {
        this.f12168b = str;
        this.f12169c = str2;
        HandlerThread handlerThread = new HandlerThread("GassClient");
        this.f12171e = handlerThread;
        handlerThread.start();
        wh1 wh1Var = new wh1(context, handlerThread.getLooper(), this, this, 9200000);
        this.f12167a = wh1Var;
        this.f12170d = new LinkedBlockingQueue();
        wh1Var.checkAvailabilityAndConnect();
    }

    public static pf b() {
        we weVarD0 = pf.D0();
        weVarD0.h(IjkMediaMeta.AV_CH_TOP_BACK_LEFT);
        return (pf) weVarD0.e();
    }

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

    @Override // com.google.android.gms.common.internal.b
    public final void onConnected(Bundle bundle) {
        zh1 zh1VarC;
        LinkedBlockingQueue linkedBlockingQueue = this.f12170d;
        HandlerThread handlerThread = this.f12171e;
        try {
            zh1VarC = this.f12167a.c();
        } catch (DeadObjectException | IllegalStateException unused) {
            zh1VarC = null;
        }
        if (zh1VarC != null) {
            try {
                try {
                    xh1 xh1Var = new xh1(1, this.f12168b, this.f12169c);
                    Parcel parcelO = zh1VarC.O();
                    aj.b(parcelO, xh1Var);
                    Parcel parcelB0 = zh1VarC.B0(1, parcelO);
                    yh1 yh1Var = (yh1) aj.a(parcelB0, yh1.CREATOR);
                    parcelB0.recycle();
                    if (yh1Var.f18842b == null) {
                        try {
                            byte[] bArr = yh1Var.f18843c;
                            ua2 ua2Var = ua2.f17195b;
                            int i10 = fa2.f11138a;
                            yh1Var.f18842b = pf.C0(bArr, ua2.f17196c);
                            yh1Var.f18843c = null;
                        } catch (zzicg | NullPointerException e10) {
                            throw new IllegalStateException(e10);
                        }
                    }
                    yh1Var.zzb();
                    linkedBlockingQueue.put(yh1Var.f18842b);
                } catch (Throwable unused2) {
                    linkedBlockingQueue.put(b());
                }
            } catch (InterruptedException unused3) {
            } catch (Throwable th) {
                a();
                handlerThread.quit();
                throw th;
            }
            a();
            handlerThread.quit();
        }
    }

    @Override // com.google.android.gms.common.internal.c
    public final void onConnectionFailed(e8.b bVar) {
        try {
            this.f12170d.put(b());
        } catch (InterruptedException unused) {
        }
    }

    @Override // com.google.android.gms.common.internal.b
    public final void onConnectionSuspended(int i10) {
        try {
            this.f12170d.put(b());
        } catch (InterruptedException unused) {
        }
    }
}
