package I;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.core.location.LocationRequestCompat;
import b0.AbstractC0399d;
import b0.D;
import java.io.IOException;
import n.C0633A;
import n.x;
import n.z;

/* JADX INFO: loaded from: classes.dex */
final class j implements Handler.Callback {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final i f960a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final Handler f961b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private C0633A f962c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private boolean f963d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private f f964e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private IOException f965f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private RuntimeException f966g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private boolean f967h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private long f968i;

    public j(Looper looper, i iVar) {
        this.f961b = new Handler(looper, this);
        this.f960a = iVar;
        a();
    }

    private void d(x xVar) {
        long j2 = xVar.f5847k0;
        boolean z2 = j2 == LocationRequestCompat.PASSIVE_INTERVAL;
        this.f967h = z2;
        if (z2) {
            j2 = 0;
        }
        this.f968i = j2;
    }

    private void e(long j2, C0633A c0633a) {
        g gVarB;
        RuntimeException e2;
        z zVar = null;
        try {
            this.f960a.c(c0633a.f5413f);
            gVarB = this.f960a.b(c0633a.f5409b.array(), 0, c0633a.f5410c);
            e2 = null;
        } catch (RuntimeException e3) {
            e2 = e3;
            gVarB = null;
        } catch (z e4) {
            gVarB = null;
            zVar = e4;
            e2 = null;
        }
        synchronized (this) {
            if (this.f962c == c0633a) {
                this.f964e = new f(gVarB, this.f967h, j2, this.f968i);
                this.f965f = zVar;
                this.f966g = e2;
                this.f963d = false;
            }
        }
    }

    public synchronized void a() {
        this.f962c = new C0633A(1);
        this.f963d = false;
        this.f964e = null;
        this.f965f = null;
        this.f966g = null;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public synchronized f b() {
        try {
            IOException iOException = this.f965f;
            if (iOException != null) {
                throw iOException;
            }
            RuntimeException runtimeException = this.f966g;
            if (runtimeException != null) {
                throw runtimeException;
            }
        } finally {
            this.f964e = null;
            this.f965f = null;
            this.f966g = null;
        }
        return this.f964e;
    }

    public synchronized C0633A c() {
        return this.f962c;
    }

    public synchronized boolean f() {
        return this.f963d;
    }

    public void g(x xVar) {
        this.f961b.obtainMessage(0, xVar).sendToTarget();
    }

    public synchronized void h() {
        AbstractC0399d.e(!this.f963d);
        this.f963d = true;
        this.f964e = null;
        this.f965f = null;
        this.f966g = null;
        this.f961b.obtainMessage(1, D.B(this.f962c.f5412e), D.n(this.f962c.f5412e), this.f962c).sendToTarget();
    }

    @Override // android.os.Handler.Callback
    public boolean handleMessage(Message message) {
        int i2 = message.what;
        if (i2 == 0) {
            d((x) message.obj);
        } else if (i2 == 1) {
            e(D.v(message.arg1, message.arg2), (C0633A) message.obj);
        }
        return true;
    }
}
