package o;

import java.util.ArrayList;
import java.util.concurrent.RejectedExecutionException;
import java.util.logging.Level;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Tc0 {
    public final Uc0 a;
    public final String b;
    public boolean c;
    public Oc0 d;
    public final ArrayList e = new ArrayList();
    public boolean f;

    public Tc0(Uc0 uc0, String str) {
        this.a = uc0;
        this.b = str;
    }

    public final void a() {
        byte[] bArr = AbstractC2264qi0.a;
        synchronized (this.a) {
            if (b()) {
                this.a.d(this);
            }
        }
    }

    public final boolean b() {
        Oc0 oc0 = this.d;
        if (oc0 != null && oc0.b) {
            this.f = true;
        }
        ArrayList arrayList = this.e;
        boolean z = false;
        for (int size = arrayList.size() - 1; -1 < size; size--) {
            if (((Oc0) arrayList.get(size)).b) {
                Oc0 oc02 = (Oc0) arrayList.get(size);
                BP bp = Uc0.h;
                if (Uc0.j.isLoggable(Level.FINE)) {
                    AbstractC0662Zn.d(oc02, this, "canceled");
                }
                arrayList.remove(size);
                z = true;
            }
        }
        return z;
    }

    public final void c(Oc0 oc0, long j) {
        synchronized (this.a) {
            if (!this.c) {
                if (d(oc0, j, false)) {
                    this.a.d(this);
                }
            } else if (oc0.b) {
                BP bp = Uc0.h;
                if (Uc0.j.isLoggable(Level.FINE)) {
                    AbstractC0662Zn.d(oc0, this, "schedule canceled (queue is shutdown)");
                }
            } else {
                BP bp2 = Uc0.h;
                if (Uc0.j.isLoggable(Level.FINE)) {
                    AbstractC0662Zn.d(oc0, this, "schedule failed (queue is shutdown)");
                }
                throw new RejectedExecutionException();
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:18:0x0042  */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0066  */
    /* JADX WARN: Removed duplicated region for block: B:30:0x007c  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0085 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:38:0x0079 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean d(o.Oc0 r11, long r12, boolean r14) {
        /*
            r10 = this;
            o.Tc0 r0 = r11.c
            if (r0 != r10) goto L5
            goto L9
        L5:
            if (r0 != 0) goto L88
            r11.c = r10
        L9:
            long r0 = java.lang.System.nanoTime()
            long r2 = r0 + r12
            java.util.ArrayList r4 = r10.e
            int r5 = r4.indexOf(r11)
            r6 = -1
            r7 = 0
            if (r5 == r6) goto L34
            long r8 = r11.d
            int r8 = (r8 > r2 ? 1 : (r8 == r2 ? 0 : -1))
            if (r8 > 0) goto L31
            o.BP r12 = o.Uc0.h
            java.util.logging.Logger r12 = o.Uc0.j
            java.util.logging.Level r13 = java.util.logging.Level.FINE
            boolean r12 = r12.isLoggable(r13)
            if (r12 == 0) goto L87
            java.lang.String r12 = "already scheduled"
            o.AbstractC0662Zn.d(r11, r10, r12)
            return r7
        L31:
            r4.remove(r5)
        L34:
            r11.d = r2
            o.BP r5 = o.Uc0.h
            java.util.logging.Logger r5 = o.Uc0.j
            java.util.logging.Level r8 = java.util.logging.Level.FINE
            boolean r5 = r5.isLoggable(r8)
            if (r5 == 0) goto L5e
            if (r14 == 0) goto L50
            long r2 = r2 - r0
            java.lang.String r14 = o.AbstractC0662Zn.s(r2)
            java.lang.String r2 = "run again after "
            java.lang.String r14 = r2.concat(r14)
            goto L5b
        L50:
            long r2 = r2 - r0
            java.lang.String r14 = o.AbstractC0662Zn.s(r2)
            java.lang.String r2 = "scheduled after "
            java.lang.String r14 = r2.concat(r14)
        L5b:
            o.AbstractC0662Zn.d(r11, r10, r14)
        L5e:
            int r14 = r4.size()
            r2 = r7
            r3 = r2
        L64:
            if (r3 >= r14) goto L79
            java.lang.Object r5 = r4.get(r3)
            int r3 = r3 + 1
            o.Oc0 r5 = (o.Oc0) r5
            long r8 = r5.d
            long r8 = r8 - r0
            int r5 = (r8 > r12 ? 1 : (r8 == r12 ? 0 : -1))
            if (r5 <= 0) goto L76
            goto L7a
        L76:
            int r2 = r2 + 1
            goto L64
        L79:
            r2 = r6
        L7a:
            if (r2 != r6) goto L80
            int r2 = r4.size()
        L80:
            r4.add(r2, r11)
            if (r2 != 0) goto L87
            r11 = 1
            return r11
        L87:
            return r7
        L88:
            java.lang.IllegalStateException r11 = new java.lang.IllegalStateException
            java.lang.String r12 = "task is in multiple queues"
            r11.<init>(r12)
            throw r11
        */
        throw new UnsupportedOperationException("Method not decompiled: o.Tc0.d(o.Oc0, long, boolean):boolean");
    }

    public final void e() {
        byte[] bArr = AbstractC2264qi0.a;
        synchronized (this.a) {
            this.c = true;
            if (b()) {
                this.a.d(this);
            }
        }
    }

    public final String toString() {
        return this.b;
    }
}
