package o;

import android.content.Context;
import android.os.Build;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class PE {
    public static final C1770lY b = new C1770lY("fire-global");
    public static final C1770lY c = new C1770lY("fire-count");
    public static final C1770lY d = new C1770lY("last-used-date");
    public final OI a;

    public PE(Context context, String str) {
        this.a = new OI(context, AbstractC2462sn.u("FirebaseHeartBeat", str));
    }

    public final synchronized ArrayList a() {
        try {
            ArrayList arrayList = new ArrayList();
            String strB = b(System.currentTimeMillis());
            OI oi = this.a;
            oi.getClass();
            for (Map.Entry entry : ((Map) AbstractC1692kh0.M(C0281Kv.l, new NI(oi, null, 0))).entrySet()) {
                if (entry.getValue() instanceof Set) {
                    HashSet hashSet = new HashSet((Set) entry.getValue());
                    hashSet.remove(strB);
                    if (!hashSet.isEmpty()) {
                        arrayList.add(new C0468Sb(((C1770lY) entry.getKey()).a, new ArrayList(hashSet)));
                    }
                }
            }
            long jCurrentTimeMillis = System.currentTimeMillis();
            synchronized (this) {
                this.a.a(new X3(2, jCurrentTimeMillis));
            }
            return arrayList;
        } catch (Throwable th) {
            throw th;
        }
        return arrayList;
    }

    public final synchronized String b(long j) {
        if (Build.VERSION.SDK_INT < 26) {
            return new SimpleDateFormat("yyyy-MM-dd", Locale.UK).format(new Date(j));
        }
        Instant instant = new Date(j).toInstant();
        ZoneOffset unused = ZoneOffset.UTC;
        LocalDateTime localDateTime = instant.atOffset(ZoneOffset.UTC).toLocalDateTime();
        DateTimeFormatter unused2 = DateTimeFormatter.ISO_LOCAL_DATE;
        return localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE);
    }

    public final synchronized C1770lY c(VQ vq, String str) {
        for (Map.Entry entry : vq.a().entrySet()) {
            if (entry.getValue() instanceof Set) {
                Iterator it = ((Set) entry.getValue()).iterator();
                while (it.hasNext()) {
                    if (str.equals((String) it.next())) {
                        return new C1770lY(((C1770lY) entry.getKey()).a);
                    }
                }
            }
        }
        return null;
    }

    public final synchronized void d(VQ vq, String str) {
        C1770lY c1770lYC = c(vq, str);
        if (c1770lYC == null) {
            return;
        }
        Object hashSet = new HashSet();
        Object objC = vq.c(c1770lYC);
        if (objC != null) {
            hashSet = objC;
        }
        HashSet hashSet2 = new HashSet((Collection) hashSet);
        hashSet2.remove(str);
        if (hashSet2.isEmpty()) {
            vq.b();
            vq.a.remove(c1770lYC);
        } else {
            vq.d(c1770lYC, hashSet2);
        }
    }

    public final synchronized boolean e(long j) {
        InterfaceC0220Im interfaceC0220Im;
        C0281Kv c0281Kv;
        long jLongValue;
        OI oi = this.a;
        oi.getClass();
        interfaceC0220Im = null;
        NI ni = new NI(oi, interfaceC0220Im, 1);
        c0281Kv = C0281Kv.l;
        jLongValue = ((Long) AbstractC1692kh0.M(c0281Kv, ni)).longValue();
        synchronized (this) {
        }
        if (b(jLongValue).equals(b(j))) {
            return false;
        }
        OI oi2 = this.a;
        Long lValueOf = Long.valueOf(j);
        oi2.getClass();
        return true;
    }
}
