package defpackage;

import android.content.SharedPreferences;
import android.util.Log;
import j$.util.Objects;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

/* JADX INFO: renamed from: ᵻᵮ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C5227 implements InterfaceC4865, InterfaceC2274 {

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

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public Object f19712;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public long f19713;

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

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

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

    public C5227(long j, C0974 c0974, C5022 c5022, C5179 c5179, C3250 c3250) {
        this.f19711 = 2;
        this.f19713 = j;
        this.f19712 = c0974;
        this.f19714 = c5022;
        this.f19715 = c5179;
        this.f19716 = c3250;
    }

    public C5227(File file) {
        this.f19711 = 0;
        this.f19715 = new ˊˊᵞᵽ(19);
        this.f19714 = file;
        this.f19713 = 262144000L;
        this.f19712 = new C3714(21);
    }

    public C5227(C0252 c0252, C5377 c5377) {
        this.f19711 = 1;
        this.f19712 = c0252;
        this.f19714 = c5377;
        this.f19713 = Long.MIN_VALUE;
        this.f19715 = new CopyOnWriteArrayList();
        this.f19716 = new LinkedBlockingDeque();
    }

    public /* synthetic */ C5227(C2894 c2894) {
        this.f19711 = 4;
        this.f19716 = c2894;
    }

    public /* synthetic */ C5227(C3740 c3740, long j) {
        this.f19711 = 3;
        this.f19716 = c3740;
        ᵘᵞʿⁱ.ˊᵫᵗ("health_monitor");
        ᵘᵞʿⁱ.ᵻˈᵦʼ(j > 0);
        this.f19712 = "health_monitor:start";
        this.f19714 = "health_monitor:count";
        this.f19715 = "health_monitor:value";
        this.f19713 = j;
    }

    @Override // defpackage.InterfaceC4865
    public synchronized void clear() {
        try {
            try {
                C2899 c2899M10791 = m10791();
                c2899M10791.close();
                AbstractC4756.m9935(c2899M10791.f11138);
            } catch (IOException unused) {
                Log.isLoggable("DiskLruCacheWrapper", 5);
            }
        } finally {
            m10795();
        }
    }

    public String toString() {
        switch (this.f19711) {
            case 2:
                return "TreeConnect[" + this.f19713 + "](" + ((C0974) this.f19712) + ")";
            default:
                return super.toString();
        }
    }

    @Override // defpackage.InterfaceC2274
    /* JADX INFO: renamed from: ʽˈˋ */
    public C4013 mo5887() throws IOException {
        C1560 c1560M10792;
        long j;
        C1560 c1560;
        IOException iOException = null;
        while (true) {
            try {
                if (((CopyOnWriteArrayList) this.f19715).isEmpty() && !((C0252) this.f19712).m1468(null)) {
                    throw iOException;
                }
                if (((C0252) this.f19712).f1843.f18172) {
                    throw new IOException("Canceled");
                }
                ᵢʒʡᵟ r2 = ((C5377) this.f19714).f20373;
                long jNanoTime = System.nanoTime();
                long j2 = this.f19713 - jNanoTime;
                if (((CopyOnWriteArrayList) this.f19715).isEmpty() || j2 <= 0) {
                    c1560M10792 = m10792();
                    j = 250000000;
                    this.f19713 = jNanoTime + 250000000;
                } else {
                    j = j2;
                    c1560M10792 = null;
                }
                if (c1560M10792 == null) {
                    TimeUnit timeUnit = TimeUnit.NANOSECONDS;
                    CopyOnWriteArrayList copyOnWriteArrayList = (CopyOnWriteArrayList) this.f19715;
                    if (copyOnWriteArrayList.isEmpty() || (c1560 = (C1560) ((LinkedBlockingDeque) this.f19716).poll(j, timeUnit)) == null) {
                        c1560M10792 = null;
                    } else {
                        copyOnWriteArrayList.remove(c1560.f6255);
                        c1560M10792 = c1560;
                    }
                    if (c1560M10792 == null) {
                    }
                }
                boolean z = false;
                if (c1560M10792.f6253 == null && c1560M10792.f6254 == null) {
                    m10793();
                    if (!c1560M10792.f6255.mo3692()) {
                        c1560M10792 = c1560M10792.f6255.mo3693();
                    }
                    if (c1560M10792.f6253 == null && c1560M10792.f6254 == null) {
                        z = true;
                    }
                    if (z) {
                        return c1560M10792.f6255.mo3691();
                    }
                }
                Throwable th = c1560M10792.f6254;
                if (th != null) {
                    if (!(th instanceof IOException)) {
                        throw th;
                    }
                    if (iOException == null) {
                        iOException = (IOException) th;
                    } else {
                        ᵷˆᵣ.ʽˈˋ(iOException, th);
                    }
                }
                InterfaceC4344 interfaceC4344 = c1560M10792.f6253;
                if (interfaceC4344 != null) {
                    ((C0252) this.f19712).f1836.addFirst(interfaceC4344);
                }
            } finally {
                m10793();
            }
        }
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public void m10790() {
        C3740 c3740 = (C3740) this.f19716;
        c3740.ˈᵲᵢ();
        ((C1103) ((ᵜᵪʾ) c3740).ˌᴵ).f4701.getClass();
        long jCurrentTimeMillis = System.currentTimeMillis();
        SharedPreferences.Editor editorEdit = c3740.m8407().edit();
        editorEdit.remove((String) this.f19714);
        editorEdit.remove((String) this.f19715);
        editorEdit.putLong((String) this.f19712, jCurrentTimeMillis);
        editorEdit.apply();
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public synchronized C2899 m10791() {
        try {
            if (((C2899) this.f19716) == null) {
                this.f19716 = C2899.m6951((File) this.f19714, this.f19713);
            }
        } catch (Throwable th) {
            throw th;
        }
        return (C2899) this.f19716;
    }

    @Override // defpackage.InterfaceC4865
    /* JADX INFO: renamed from: ᵟᵹᵙ */
    public File mo10107(InterfaceC0883 interfaceC0883) {
        String strM8360 = ((C3714) this.f19712).m8360(interfaceC0883);
        if (Log.isLoggable("DiskLruCacheWrapper", 2)) {
            Objects.toString(interfaceC0883);
        }
        try {
            ᵟˑʽ r3 = m10791().m6956(strM8360);
            if (r3 != null) {
                return ((File[]) r3.ˌᴵ)[0];
            }
            return null;
        } catch (IOException unused) {
            Log.isLoggable("DiskLruCacheWrapper", 5);
            return null;
        }
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public C1560 m10792() {
        InterfaceC4344 c3684;
        C0252 c0252 = (C0252) this.f19712;
        if (c0252.m1468(null)) {
            try {
                c3684 = c0252.m1465();
            } catch (Throwable th) {
                c3684 = new C3684(th);
            }
            if (c3684.mo3692()) {
                return new C1560(c3684, (Throwable) null, 6);
            }
            if (c3684 instanceof C3684) {
                return ((C3684) c3684).f14048;
            }
            ((CopyOnWriteArrayList) this.f19715).add(c3684);
            ((C5377) this.f19714).m10966().m10972(new C2966(AbstractC1190.f5067 + " connect " + c0252.f1845.f1327.m4640(), c3684, this), 0L);
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public void m10793() {
        CopyOnWriteArrayList<InterfaceC4344> copyOnWriteArrayList = (CopyOnWriteArrayList) this.f19715;
        for (InterfaceC4344 interfaceC4344 : copyOnWriteArrayList) {
            interfaceC4344.cancel();
            InterfaceC4344 interfaceC4344Mo3690 = interfaceC4344.mo3690();
            if (interfaceC4344Mo3690 != null) {
                ((C0252) this.f19712).f1836.addLast(interfaceC4344Mo3690);
            }
        }
        copyOnWriteArrayList.clear();
    }

    /* JADX WARN: Removed duplicated region for block: B:23:0x009c  */
    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean m10794(long j, C4943 c4943) {
        if (((ArrayList) this.f19715) == null) {
            this.f19715 = new ArrayList();
        }
        if (((ArrayList) this.f19714) == null) {
            this.f19714 = new ArrayList();
        }
        if (((ArrayList) this.f19715).isEmpty() || ((((C4943) ((ArrayList) this.f19715).get(0)).m10277() / 1000) / 60) / 60 == ((c4943.m10277() / 1000) / 60) / 60) {
            long jM9880 = this.f19713 + ((long) c4943.m9880());
            C2894 c2894 = (C2894) this.f19716;
            if (!c2894.m6921().m8314(null, AbstractC3818.f14543)) {
                c2894.m6921();
                if (jM9880 < Math.max(0, ((Integer) AbstractC3818.f14571.m1988(null)).intValue())) {
                }
            } else if (!((ArrayList) this.f19715).isEmpty()) {
                c2894.m6921();
                if (jM9880 < Math.max(0, ((Integer) AbstractC3818.f14571.m1988(null)).intValue())) {
                    this.f19713 = jM9880;
                    ((ArrayList) this.f19715).add(c4943);
                    ((ArrayList) this.f19714).add(Long.valueOf(j));
                    C5090 c5090 = (C5090) this.f19712;
                    if (((ArrayList) this.f19715).size() < Math.max(1, c2894.m6921().m8310(c5090 != null ? c5090.m10481() : null, AbstractC3818.f14579))) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    @Override // defpackage.InterfaceC4865
    /* JADX INFO: renamed from: ᵶᵥᵝ */
    public void mo10108(InterfaceC0883 interfaceC0883, ᵯᵨᵲ r8) {
        C1738 c1738M3713;
        boolean z;
        String strM8360 = ((C3714) this.f19712).m8360(interfaceC0883);
        ˊˊᵞᵽ r2 = (ˊˊᵞᵽ) this.f19715;
        synchronized (r2) {
            try {
                c1738M3713 = (C1738) ((HashMap) r2.ᵜᵪʾ).get(strM8360);
                if (c1738M3713 == null) {
                    c1738M3713 = ((C1227) r2.ᵔᵖᵹᵫ).m3713();
                    ((HashMap) r2.ᵜᵪʾ).put(strM8360, c1738M3713);
                }
                c1738M3713.f6971++;
            } catch (Throwable th) {
                throw th;
            }
        }
        c1738M3713.f6972.lock();
        try {
            if (Log.isLoggable("DiskLruCacheWrapper", 2)) {
                Objects.toString(interfaceC0883);
            }
            try {
                C2899 c2899M10791 = m10791();
                if (c2899M10791.m6956(strM8360) == null) {
                    C0764 c0764M6959 = c2899M10791.m6959(strM8360);
                    if (c0764M6959 == null) {
                        throw new IllegalStateException("Had two simultaneous puts for: ".concat(strM8360));
                    }
                    try {
                        if (((InterfaceC4562) r8.ᵜᵪʾ).mo2774(r8.ᵔᵖᵹᵫ, c0764M6959.m2745(), (C2220) r8.ᵨᵼⁱ)) {
                            C2899.m6950((C2899) c0764M6959.f3429, c0764M6959, true);
                            c0764M6959.f3426 = true;
                        }
                        if (!z) {
                            try {
                                c0764M6959.m2748();
                            } catch (IOException unused) {
                            }
                        }
                    } finally {
                        if (!c0764M6959.f3426) {
                            try {
                                c0764M6959.m2748();
                            } catch (IOException unused2) {
                            }
                        }
                    }
                }
            } catch (IOException unused3) {
                Log.isLoggable("DiskLruCacheWrapper", 5);
            }
        } finally {
            ((ˊˊᵞᵽ) this.f19715).ˑʢ(strM8360);
        }
    }

    @Override // defpackage.InterfaceC2274
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public C0252 mo5888() {
        return (C0252) this.f19712;
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public synchronized void m10795() {
        this.f19716 = null;
    }
}
