package x4;

import android.content.SharedPreferences;
import android.util.Log;
import androidx.room.x;
import com.google.android.gms.common.internal.w;
import com.google.android.gms.internal.atv_ads_framework.d1;
import com.google.android.gms.internal.measurement.n3;
import com.google.android.gms.internal.measurement.u3;
import com.google.android.gms.internal.measurement.w3;
import com.google.android.gms.measurement.internal.g4;
import com.google.android.gms.measurement.internal.y0;
import com.google.android.gms.measurement.internal.z;
import com.google.android.gms.measurement.internal.z3;
import com.google.android.gms.measurement.internal.zznt;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import xyz.stream.utils.a0;

/* JADX INFO: loaded from: classes.dex */
public final class d implements d5.c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public long f34720a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Object f34721b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Object f34722c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Object f34723d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Object f34724e;

    public d(z3 z3Var) {
        this.f34721b = z3Var;
    }

    public final synchronized e a() {
        try {
            if (((e) this.f34721b) == null) {
                this.f34721b = e.H((File) this.f34723d, this.f34720a);
            }
        } catch (Throwable th) {
            throw th;
        }
        return (e) this.f34721b;
    }

    public final g4 b() {
        long j10 = this.f34720a;
        u3 u3Var = (u3) this.f34723d;
        String str = (String) this.f34722c;
        Map map = (Map) this.f34724e;
        zznt zzntVar = (zznt) this.f34721b;
        g4 g4Var = new g4();
        g4Var.f21641a = j10;
        g4Var.f21642b = u3Var;
        g4Var.f21643c = str;
        g4Var.f21644d = map;
        g4Var.f21645e = zzntVar;
        return g4Var;
    }

    public final void c(w3 w3Var) {
        w.checkNotNull(w3Var);
        this.f34722c = w3Var;
    }

    public final boolean d(long j10, n3 n3Var) {
        w.checkNotNull(n3Var);
        if (((List) this.f34724e) == null) {
            this.f34724e = new ArrayList();
        }
        if (((List) this.f34723d) == null) {
            this.f34723d = new ArrayList();
        }
        if (!((List) this.f34724e).isEmpty() && ((((n3) ((List) this.f34724e).get(0)).B() / 1000) / 60) / 60 != ((n3Var.B() / 1000) / 60) / 60) {
            return false;
        }
        long jA = this.f34720a + ((long) n3Var.a(null));
        ((z3) this.f34721b).M();
        if (jA >= Math.max(0, ((Integer) z.f22042j.a(null)).intValue())) {
            return false;
        }
        this.f34720a = jA;
        ((List) this.f34724e).add(n3Var);
        ((List) this.f34723d).add(Long.valueOf(j10));
        int size = ((List) this.f34724e).size();
        ((z3) this.f34721b).M();
        return size < Math.max(1, ((Integer) z.f22045k.a(null)).intValue());
    }

    public final void e() {
        ((y0) this.f34721b).w();
        ((i8.d) ((y0) this.f34721b).zzb()).getClass();
        long jCurrentTimeMillis = System.currentTimeMillis();
        SharedPreferences.Editor editorEdit = ((y0) this.f34721b).F().edit();
        editorEdit.remove((String) this.f34723d);
        editorEdit.remove((String) this.f34724e);
        editorEdit.putLong((String) this.f34722c, jCurrentTimeMillis);
        editorEdit.apply();
    }

    @Override // d5.c
    public final void f(a5.h hVar, d5.b bVar) {
        d5.d dVar;
        e eVarA;
        boolean z10;
        String strI = ((d1) this.f34722c).i(hVar);
        xyz.stream.utils.f fVar = (xyz.stream.utils.f) this.f34724e;
        synchronized (fVar) {
            dVar = (d5.d) ((Map) fVar.f36132b).get(strI);
            if (dVar == null) {
                a0 a0Var = (a0) fVar.f36133c;
                synchronized (((Queue) a0Var.f36098a)) {
                    dVar = (d5.d) ((Queue) a0Var.f36098a).poll();
                }
                if (dVar == null) {
                    dVar = new d5.d();
                }
                ((Map) fVar.f36132b).put(strI, dVar);
            }
            dVar.f24986b++;
        }
        dVar.f24985a.lock();
        try {
            if (Log.isLoggable("DiskLruCacheWrapper", 2)) {
                Objects.toString(hVar);
            }
            try {
                eVarA = a();
            } catch (IOException unused) {
            }
            if (eVarA.x(strI) != null) {
                return;
            }
            x xVarM = eVarA.m(strI);
            if (xVarM == null) {
                throw new IllegalStateException("Had two simultaneous puts for: ".concat(strI));
            }
            try {
                if (bVar.a(xVarM.d())) {
                    e.e((e) xVarM.f4198d, xVarM, true);
                    xVarM.f4196b = true;
                }
                if (!z10) {
                    xVarM.c();
                }
            } finally {
                if (!xVarM.f4196b) {
                    try {
                        xVarM.c();
                    } catch (IOException unused2) {
                    }
                }
            }
        } finally {
            ((xyz.stream.utils.f) this.f34724e).w(strI);
        }
    }

    @Override // d5.c
    public final File get(a5.h hVar) {
        String strI = ((d1) this.f34722c).i(hVar);
        if (Log.isLoggable("DiskLruCacheWrapper", 2)) {
            Objects.toString(hVar);
        }
        try {
            d dVarX = a().x(strI);
            if (dVarX != null) {
                return ((File[]) dVarX.f34724e)[0];
            }
            return null;
        } catch (IOException unused) {
            return null;
        }
    }
}
