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

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes2.dex */
public final class s0 extends HandlerThread implements Handler.Callback {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public fp0 f16269a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Handler f16270b;

    @Nullable
    private Error zzc;

    @Nullable
    private RuntimeException zzd;

    @Nullable
    private t0 zze;

    public final t0 a(int i10) {
        boolean z10;
        start();
        Handler handler = new Handler(getLooper(), this);
        this.f16270b = handler;
        this.f16269a = new fp0(handler, null);
        synchronized (this) {
            z10 = false;
            this.f16270b.obtainMessage(1, i10, 0).sendToTarget();
            while (this.zze == null && this.zzd == null && this.zzc == null) {
                try {
                    wait();
                } catch (InterruptedException unused) {
                    z10 = true;
                }
            }
        }
        if (z10) {
            Thread.currentThread().interrupt();
        }
        RuntimeException runtimeException = this.zzd;
        if (runtimeException != null) {
            throw runtimeException;
        }
        Error error = this.zzc;
        if (error != null) {
            throw error;
        }
        t0 t0Var = this.zze;
        t0Var.getClass();
        return t0Var;
    }

    @Override // android.os.Handler.Callback
    public final boolean handleMessage(Message message) {
        int i10 = message.what;
        try {
            if (i10 == 1) {
                try {
                    try {
                        int i11 = message.arg1;
                        fp0 fp0Var = this.f16269a;
                        fp0Var.getClass();
                        fp0Var.a(i11);
                        this.zze = new t0(this, this.f16269a.c(), i11 != 0);
                        synchronized (this) {
                            notify();
                        }
                    } catch (zzdu e10) {
                        vt0.zzf("PlaceholderSurface", "Failed to initialize placeholder surface", e10);
                        this.zzd = new IllegalStateException(e10);
                        synchronized (this) {
                            notify();
                        }
                    }
                } catch (Error e11) {
                    vt0.zzf("PlaceholderSurface", "Failed to initialize placeholder surface", e11);
                    this.zzc = e11;
                    synchronized (this) {
                        notify();
                    }
                } catch (RuntimeException e12) {
                    vt0.zzf("PlaceholderSurface", "Failed to initialize placeholder surface", e12);
                    this.zzd = e12;
                    synchronized (this) {
                        notify();
                    }
                }
            } else if (i10 == 2) {
                try {
                    fp0 fp0Var2 = this.f16269a;
                    fp0Var2.getClass();
                    fp0Var2.b();
                } finally {
                    try {
                    } finally {
                    }
                }
                return true;
            }
            return true;
        } catch (Throwable th) {
            synchronized (this) {
                notify();
                throw th;
            }
        }
    }
}
