package M4;

import android.content.SharedPreferences;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes.dex */
public final class o {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Date f4283e = new Date(-1);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final Date f4284f = new Date(-1);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final SharedPreferences f4285a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f4286b = new Object();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object f4287c = new Object();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Object f4288d = new Object();

    public o(SharedPreferences sharedPreferences) {
        this.f4285a = sharedPreferences;
    }

    public final n a() {
        n nVar;
        synchronized (this.f4287c) {
            int i = this.f4285a.getInt("num_failed_fetches", 0);
            Date date = new Date(this.f4285a.getLong("backoff_end_time_in_millis", -1L));
            nVar = new n();
            nVar.f4281a = i;
            nVar.f4282b = date;
        }
        return nVar;
    }

    public final HashMap b() {
        try {
            JSONObject jSONObject = new JSONObject(this.f4285a.getString("customSignals", "{}"));
            HashMap map = new HashMap();
            Iterator<String> itKeys = jSONObject.keys();
            while (itKeys.hasNext()) {
                String next = itKeys.next();
                map.put(next, jSONObject.optString(next));
            }
            return map;
        } catch (JSONException unused) {
            return new HashMap();
        }
    }

    public final n c() {
        n nVar;
        synchronized (this.f4288d) {
            int i = this.f4285a.getInt("num_failed_realtime_streams", 0);
            Date date = new Date(this.f4285a.getLong("realtime_backoff_end_time_in_millis", -1L));
            nVar = new n();
            nVar.f4281a = i;
            nVar.f4282b = date;
        }
        return nVar;
    }

    public final void d(int i, Date date) {
        synchronized (this.f4287c) {
            this.f4285a.edit().putInt("num_failed_fetches", i).putLong("backoff_end_time_in_millis", date.getTime()).apply();
        }
    }

    public final void e(String str) {
        synchronized (this.f4286b) {
            this.f4285a.edit().putString("last_fetch_etag", str).apply();
        }
    }

    public final void f(int i, Date date) {
        synchronized (this.f4288d) {
            this.f4285a.edit().putInt("num_failed_realtime_streams", i).putLong("realtime_backoff_end_time_in_millis", date.getTime()).apply();
        }
    }

    public final void g() {
        synchronized (this.f4286b) {
            this.f4285a.edit().putInt("last_fetch_status", 1).apply();
        }
    }

    public final void h() {
        synchronized (this.f4286b) {
            this.f4285a.edit().putInt("last_fetch_status", 2).apply();
        }
    }
}
