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;

/* JADX INFO: renamed from: ᵢʾʩ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class HandlerC3257 extends Handler implements Runnable {

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public Thread f12391;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final int f12392;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public boolean f12393;

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public final /* synthetic */ ᵣˊˈᵪ f12394;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final long f12395;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final InterfaceC1933 f12396;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public InterfaceC4051 f12397;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public IOException f12398;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public int f12399;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public volatile boolean f12400;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public HandlerC3257(ᵣˊˈᵪ r1, Looper looper, InterfaceC1933 interfaceC1933, InterfaceC4051 interfaceC4051, int i, long j) {
        super(looper);
        this.f12394 = r1;
        this.f12396 = interfaceC1933;
        this.f12397 = interfaceC4051;
        this.f12392 = i;
        this.f12395 = j;
    }

    @Override // android.os.Handler
    public final void handleMessage(Message message) {
        if (this.f12400) {
            return;
        }
        int i = message.what;
        if (i == 1) {
            m7421();
            return;
        }
        if (i == 4) {
            throw ((Error) message.obj);
        }
        this.f12394.ᵔᵖᵹᵫ = null;
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        long j = jElapsedRealtime - this.f12395;
        InterfaceC4051 interfaceC4051 = this.f12397;
        interfaceC4051.getClass();
        if (this.f12393) {
            interfaceC4051.mo5223(this.f12396, jElapsedRealtime, j, false);
            return;
        }
        int i2 = message.what;
        if (i2 == 2) {
            try {
                interfaceC4051.mo5226(this.f12396, jElapsedRealtime, j);
                return;
            } catch (RuntimeException e) {
                ˋˀᵧ.ˋˈ("Unexpected exception handling load completed", e);
                this.f12394.ᵨᵼⁱ = new Loader$UnexpectedLoaderException(e);
                return;
            }
        }
        if (i2 != 3) {
            return;
        }
        IOException iOException = (IOException) message.obj;
        this.f12398 = iOException;
        int i3 = this.f12399 + 1;
        this.f12399 = i3;
        C0655 c0655Mo5228 = interfaceC4051.mo5228(this.f12396, jElapsedRealtime, j, iOException, i3);
        int i4 = c0655Mo5228.f3092;
        if (i4 == 3) {
            this.f12394.ᵨᵼⁱ = this.f12398;
            return;
        }
        if (i4 != 2) {
            if (i4 == 1) {
                this.f12399 = 1;
            }
            long jMin = c0655Mo5228.f3093;
            if (jMin == -9223372036854775807L) {
                jMin = Math.min((this.f12399 - 1) * 1000, 5000);
            }
            ᵣˊˈᵪ r13 = this.f12394;
            ᵻᵪ.ˌᴵ(((HandlerC3257) r13.ᵔᵖᵹᵫ) == null);
            r13.ᵔᵖᵹᵫ = this;
            if (jMin > 0) {
                sendEmptyMessageDelayed(1, jMin);
            } else {
                m7421();
            }
        }
    }

    @Override // java.lang.Runnable
    public final void run() {
        boolean z;
        try {
            synchronized (this) {
                z = this.f12393;
                this.f12391 = Thread.currentThread();
            }
            if (!z) {
                Trace.beginSection("load:".concat(this.f12396.getClass().getSimpleName()));
                try {
                    this.f12396.mo3275();
                    Trace.endSection();
                } catch (Throwable th) {
                    Trace.endSection();
                    throw th;
                }
            }
            synchronized (this) {
                this.f12391 = null;
                Thread.interrupted();
            }
            if (this.f12400) {
                return;
            }
            sendEmptyMessage(2);
        } catch (IOException e) {
            if (this.f12400) {
                return;
            }
            obtainMessage(3, e).sendToTarget();
        } catch (Exception e2) {
            if (this.f12400) {
                return;
            }
            ˋˀᵧ.ˋˈ("Unexpected exception loading stream", e2);
            obtainMessage(3, new Loader$UnexpectedLoaderException(e2)).sendToTarget();
        } catch (OutOfMemoryError e3) {
            if (this.f12400) {
                return;
            }
            ˋˀᵧ.ˋˈ("OutOfMemory error loading stream", e3);
            obtainMessage(3, new Loader$UnexpectedLoaderException(e3)).sendToTarget();
        } catch (Error e4) {
            if (!this.f12400) {
                ˋˀᵧ.ˋˈ("Unexpected error loading stream", e4);
                obtainMessage(4, e4).sendToTarget();
            }
            throw e4;
        }
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final void m7421() {
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        long j = jElapsedRealtime - this.f12395;
        InterfaceC4051 interfaceC4051 = this.f12397;
        interfaceC4051.getClass();
        interfaceC4051.mo5230(this.f12396, jElapsedRealtime, j, this.f12399);
        this.f12398 = null;
        ᵣˊˈᵪ r7 = this.f12394;
        ExecutorC1728 executorC1728 = (ExecutorC1728) r7.ᵜᵪʾ;
        HandlerC3257 handlerC3257 = (HandlerC3257) r7.ᵔᵖᵹᵫ;
        handlerC3257.getClass();
        executorC1728.execute(handlerC3257);
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m7422(boolean z) {
        this.f12400 = z;
        this.f12398 = null;
        if (hasMessages(1)) {
            this.f12393 = true;
            removeMessages(1);
            if (!z) {
                sendEmptyMessage(2);
            }
        } else {
            synchronized (this) {
                try {
                    this.f12393 = true;
                    this.f12396.mo3273();
                    Thread thread = this.f12391;
                    if (thread != null) {
                        thread.interrupt();
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        if (z) {
            this.f12394.ᵔᵖᵹᵫ = null;
            long jElapsedRealtime = SystemClock.elapsedRealtime();
            InterfaceC4051 interfaceC4051 = this.f12397;
            interfaceC4051.getClass();
            interfaceC4051.mo5223(this.f12396, jElapsedRealtime, jElapsedRealtime - this.f12395, true);
            this.f12397 = null;
        }
    }
}
