package com.seewo.ota.data;

import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.seewo.aidl.model.OTAScheduleTaskGroup;
import com.seewo.ota.util.m;
import com.seewo.ota.v.s.s.r0;
import com.seewo.vcommons.data.d;
import java.lang.reflect.Type;
import java.util.List;

/* JADX INFO: compiled from: PreferenceUtil.java */
/* JADX INFO: loaded from: classes.dex */
public class a {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static volatile a f2114c;
    private SharedPreferences a = b.i().a().getSharedPreferences("ota_config", 0);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private Gson f2115b = new Gson();

    /* JADX INFO: renamed from: com.seewo.ota.data.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: PreferenceUtil.java */
    class C0054a extends TypeToken<List<OTAScheduleTaskGroup>> {
        C0054a(a aVar) {
        }
    }

    private a() {
    }

    public static a g() {
        if (f2114c == null) {
            synchronized (a.class) {
                if (f2114c == null) {
                    f2114c = new a();
                }
            }
        }
        return f2114c;
    }

    private String n(r0 r0Var) {
        return "Count_Error_" + d.h() + "_" + r0Var.getName();
    }

    private String p(r0 r0Var) {
        return "Count_Failed_" + d.h() + "_" + r0Var.getName();
    }

    public void A(r0 r0Var) {
        Log.d(r0Var.getName(), "resetUpdateFailedCountOfDeviceUpdate: task = " + r0Var.getName());
        this.a.edit().putInt(p(r0Var), 0).commit();
    }

    public void B() {
        this.a.edit().putBoolean("device_post_account", true).apply();
    }

    public boolean C(boolean z, int i2) {
        return this.a.edit().putBoolean("KEY_CAMERA_UPDATE_STATUS" + d.h() + i2, z).commit();
    }

    public void D(Long l) {
        this.a.edit().putLong("local_update_device_delay_day", l.longValue()).commit();
    }

    public void E(String str, long j2) {
        this.a.edit().putLong("KEY_DEVICE_FILE_DOWNLOAD_LENGTH" + str, j2).commit();
    }

    public void F(String str, String str2) {
        this.a.edit().putString("KEY_DEVICE_FILE_DOWNLOAD_URL" + str, str2).commit();
    }

    public void G(boolean z) {
        this.a.edit().putBoolean("isFixedRemind", z).apply();
    }

    public void H(boolean z) {
        this.a.edit().putBoolean("isRemindUpdateLater", z).apply();
    }

    public void I(Long l) {
        this.a.edit().putLong("LAST_SYSTEM_VERSION", l.longValue()).commit();
    }

    public void J(long j2) {
        Log.d("PreferenceUtil", "setNextRemindUpdateTime:" + j2);
        this.a.edit().putLong("nextRemindUpdateTime", j2).apply();
    }

    public void K(long j2) {
        this.a.edit().putLong("next_schedule_time", j2).commit();
    }

    public void L(List<OTAScheduleTaskGroup> list) {
        this.a.edit().putString("schedule_task_list", this.f2115b.toJson(list)).commit();
    }

    public void M(boolean z) {
        this.a.edit().putBoolean("KEY_OTA_SCHEDULER_UPDATE_FINISH_AND_NEED_POWER_OFF", z).apply();
    }

    public void N(r0 r0Var) {
        Log.d(r0Var.getName(), "setSystemVersionOfDeviceUpdate: task = " + r0Var.getName() + ",  currentSystemVersion :" + d.h());
        SharedPreferences.Editor editorEdit = this.a.edit();
        StringBuilder sb = new StringBuilder();
        sb.append("Version_");
        sb.append(r0Var.getName());
        editorEdit.putString(sb.toString(), d.h()).commit();
    }

    public void O(int i2) {
        this.a.edit().putInt("device_update_counts", i2).apply();
    }

    public void P(r0 r0Var) {
        int iO = o(r0Var) + 1;
        Log.d(r0Var.getName(), "setUpdateErrorCountOfDeviceUpdate: task = " + r0Var.getName() + ",  count :" + iO);
        this.a.edit().putInt(n(r0Var), iO).commit();
    }

    public void Q(r0 r0Var) {
        int iQ = q(r0Var) + 1;
        Log.d(r0Var.getName(), "setUpdateFailedCountOfDeviceUpdate: task = " + r0Var.getName() + ",  count :" + iQ);
        this.a.edit().putInt(p(r0Var), iQ).commit();
    }

    public void R(String str, long j2) {
        this.a.edit().putLong(str, j2).commit();
    }

    public void S(UpdateInfo updateInfo) {
        this.a.edit().putString("KEY_UPDATE_INFO", this.f2115b.toJson(updateInfo)).commit();
    }

    public void T(boolean z) {
        this.a.edit().putBoolean("KEY_UPDATE_SENSOR_BY_DEBUG_MENU", z).commit();
    }

    public void U(String str) {
        this.a.edit().putString("KEY_SENSOR_FILE_PATH", str).commit();
    }

    public <T> void V(String str, List<T> list) {
        String json = this.f2115b.toJson(list);
        this.a.edit().putString("waiting_update_queue_" + str, json).commit();
    }

    public boolean a(r0 r0Var) {
        if (q(r0Var) >= 6) {
            Log.d(r0Var.getName(), "The upgrade of this device(" + r0Var.getName() + ") has failed too many times, do not continue to upgrade该小板升级失败次数太多，不继续尝试升级它");
            return false;
        }
        if ("error".equalsIgnoreCase(r0Var.isInExceptionalState())) {
            if (o(r0Var) >= 6) {
                Log.d(r0Var.getName(), "The current version of the device is error, and the number of failures is too many, do not continue to upgrade该小板当前版本为error次数太多，不继续尝试升级它");
                return false;
            }
            Log.d(r0Var.getName(), "The current version of the device is error, try to upgrade it该小板当前版本为error，尝试升级它");
            P(r0Var);
            return true;
        }
        String strL = l(r0Var);
        if (TextUtils.isEmpty(strL) || !d.h().equals(strL)) {
            return true;
        }
        Log.d(r0Var.getName(), "system version check:display is been update(当前系统版本<" + d.h() + ">已经升级过一次设备<" + r0Var.getName() + ">了，不再需要重复升级)");
        return false;
    }

    public void b() {
        this.a.edit().putString("KEY_UPDATE_INFO", "").commit();
    }

    public void c(String str) {
        this.a.edit().remove("waiting_update_queue_" + str).commit();
    }

    public boolean d(int i2) {
        return this.a.getBoolean("KEY_CAMERA_UPDATE_STATUS" + d.h() + i2, false);
    }

    public Long e() {
        return Long.valueOf(this.a.getLong("local_update_device_delay_day", 0L));
    }

    public String f(String str) {
        return this.a.getString("KEY_DEVICE_FILE_DOWNLOAD_URL" + str, "");
    }

    public Long h() {
        return Long.valueOf(this.a.getLong("LAST_SYSTEM_VERSION", 0L));
    }

    public long i() {
        return this.a.getLong("nextRemindUpdateTime", -1L);
    }

    public long j() {
        return this.a.getLong("next_schedule_time", -1L);
    }

    public List<OTAScheduleTaskGroup> k() {
        return (List) this.f2115b.fromJson(this.a.getString("schedule_task_list", null), new C0054a(this).getType());
    }

    public String l(r0 r0Var) {
        return this.a.getString("Version_" + r0Var.getName(), "");
    }

    public int m() {
        return this.a.getInt("device_update_counts", 0);
    }

    public int o(r0 r0Var) {
        return this.a.getInt(n(r0Var), 0);
    }

    public int q(r0 r0Var) {
        return this.a.getInt(p(r0Var), 0);
    }

    public long r(String str) {
        return this.a.getLong(str, 0L);
    }

    public UpdateInfo s() {
        String string = this.a.getString("KEY_UPDATE_INFO", "");
        if (TextUtils.isEmpty(string)) {
            return null;
        }
        return (UpdateInfo) m.a(this.f2115b, string, UpdateInfo.class);
    }

    public String t() {
        return this.a.getString("KEY_SENSOR_FILE_PATH", "");
    }

    public <T> List<T> u(String str, Type type) {
        String string = this.a.getString("waiting_update_queue_" + str, null);
        if (string == null) {
            return null;
        }
        return (List) this.f2115b.fromJson(string, type);
    }

    public boolean v() {
        return this.a.getBoolean("device_post_account", false);
    }

    public boolean w() {
        return this.a.getBoolean("isFixedRemind", false);
    }

    public boolean x() {
        return this.a.getBoolean("isRemindUpdateLater", false);
    }

    public boolean y() {
        return this.a.getBoolean("KEY_OTA_SCHEDULER_UPDATE_FINISH_AND_NEED_POWER_OFF", false);
    }

    public boolean z() {
        return this.a.getBoolean("KEY_UPDATE_SENSOR_BY_DEBUG_MENU", false);
    }
}
