package defpackage;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.os.Trace;
import androidx.media3.exoplayer.upstream.Loader$UnexpectedLoaderException;
import java.io.IOException;

/* renamed from: ᵻʽˏ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class HandlerC5173 extends Handler implements Runnable {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public Thread f19253;

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public final /* synthetic */ ᵧˉʙ f19254;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public volatile boolean f19255;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public boolean f19256;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public int f19257;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final InterfaceC0452 f19258;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public IOException f19259;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final int f19260;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public InterfaceC1426 f19261;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final long f19262;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public HandlerC5173(ᵧˉʙ r1, Looper looper, InterfaceC0452 interfaceC0452, InterfaceC1426 interfaceC1426, int i, long j) {
        super(looper);
        this.f19254 = r1;
        this.f19258 = interfaceC0452;
        this.f19261 = interfaceC1426;
        this.f19260 = i;
        this.f19262 = j;
    }

    @Override // android.os.Handler
    public final void handleMessage(Message message) {
        if (this.f19255) {
            return;
        }
        int i = message.what;
        if (i == 1) {
            m10678();
            return;
        }
        if (i == 4) {
            throw ((Error) message.obj);
        }
        this.f19254.ᵿʗᵝʽ = null;
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        long j = jElapsedRealtime - this.f19262;
        InterfaceC1426 interfaceC1426 = this.f19261;
        interfaceC1426.getClass();
        if (this.f19256) {
            interfaceC1426.mo3514(this.f19258, jElapsedRealtime, j, false);
            return;
        }
        int i2 = message.what;
        if (i2 == 2) {
            try {
                interfaceC1426.mo3512(this.f19258, jElapsedRealtime, j);
                return;
            } catch (RuntimeException e) {
                ᵳʿˉ.ᵸˑ("Unexpected exception handling load completed", e);
                this.f19254.ᵾᵬ = new Loader$UnexpectedLoaderException(e);
                return;
            }
        }
        if (i2 != 3) {
            return;
        }
        IOException iOException = (IOException) message.obj;
        this.f19259 = iOException;
        int i3 = this.f19257 + 1;
        this.f19257 = i3;
        C3160 c3160Mo3510 = interfaceC1426.mo3510(this.f19258, jElapsedRealtime, j, iOException, i3);
        int i4 = c3160Mo3510.f11993;
        if (i4 == 3) {
            this.f19254.ᵾᵬ = this.f19259;
            return;
        }
        if (i4 != 2) {
            if (i4 == 1) {
                this.f19257 = 1;
            }
            long jMin = c3160Mo3510.f11992;
            if (jMin == -9223372036854775807L) {
                jMin = Math.min((this.f19257 - 1) * 1000, 5000);
            }
            ᵧˉʙ r13 = this.f19254;
            ᵛᵾˏ.ᵿʗᵝʽ(((HandlerC5173) r13.ᵿʗᵝʽ) == null);
            r13.ᵿʗᵝʽ = this;
            if (jMin > 0) {
                sendEmptyMessageDelayed(1, jMin);
            } else {
                m10678();
            }
        }
    }

    @Override // java.lang.Runnable
    public final void run() {
        boolean z;
        try {
            synchronized (this) {
                z = this.f19256;
                this.f19253 = Thread.currentThread();
            }
            if (!z) {
                Trace.beginSection("load:".concat(this.f19258.getClass().getSimpleName()));
                try {
                    this.f19258.mo1781();
                    Trace.endSection();
                } catch (Throwable th) {
                    Trace.endSection();
                    throw th;
                }
            }
            synchronized (this) {
                this.f19253 = null;
                Thread.interrupted();
            }
            if (this.f19255) {
                return;
            }
            sendEmptyMessage(2);
        } catch (IOException e) {
            if (this.f19255) {
                return;
            }
            obtainMessage(3, e).sendToTarget();
        } catch (Exception e2) {
            if (this.f19255) {
                return;
            }
            ᵳʿˉ.ᵸˑ("Unexpected exception loading stream", e2);
            obtainMessage(3, new Loader$UnexpectedLoaderException(e2)).sendToTarget();
        } catch (OutOfMemoryError e3) {
            if (this.f19255) {
                return;
            }
            ᵳʿˉ.ᵸˑ("OutOfMemory error loading stream", e3);
            obtainMessage(3, new Loader$UnexpectedLoaderException(e3)).sendToTarget();
        } catch (Error e4) {
            if (!this.f19255) {
                ᵳʿˉ.ᵸˑ("Unexpected error loading stream", e4);
                obtainMessage(4, e4).sendToTarget();
            }
            throw e4;
        }
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m10677(boolean z) {
        this.f19255 = z;
        this.f19259 = null;
        if (hasMessages(1)) {
            this.f19256 = true;
            removeMessages(1);
            if (!z) {
                sendEmptyMessage(2);
            }
        } else {
            synchronized (this) {
                try {
                    this.f19256 = true;
                    this.f19258.mo1782();
                    Thread thread = this.f19253;
                    if (thread != null) {
                        thread.interrupt();
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        if (z) {
            this.f19254.ᵿʗᵝʽ = null;
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            InterfaceC1426 interfaceC1426 = this.f19261;
            interfaceC1426.getClass();
            interfaceC1426.mo3514(this.f19258, jElapsedRealtime, jElapsedRealtime - this.f19262, true);
            this.f19261 = null;
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void m10678() {
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        long j = jElapsedRealtime - this.f19262;
        InterfaceC1426 interfaceC1426 = this.f19261;
        interfaceC1426.getClass();
        interfaceC1426.mo3521(this.f19258, jElapsedRealtime, j, this.f19257);
        this.f19259 = null;
        ᵧˉʙ r7 = this.f19254;
        ExecutorC1049 executorC1049 = (ExecutorC1049) r7.ᵢˇᵭ;
        HandlerC5173 handlerC5173 = (HandlerC5173) r7.ᵿʗᵝʽ;
        handlerC5173.getClass();
        executorC1049.execute(handlerC5173);
    }
}
