package com.seewo.vcommons.data;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import java.util.HashSet;
import java.util.Set;

/* JADX INFO: compiled from: PreferencesUtils.java */
/* JADX INFO: loaded from: classes.dex */
public class c {
    private static UserContentResolver a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final Uri f2892b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final Set<String> f2893c;

    static {
        new Gson();
        f2892b = Uri.parse("content://com.seewo.osservice.provider.VCommonContentProvider/key");
        HashSet hashSet = new HashSet(5);
        f2893c = hashSet;
        hashSet.add("FC86WHD-SW-C3-20P,4608-2693");
        f2893c.add("FC75WHD-SW-C3-20P,4608-9C3F");
        f2893c.add("FC70WHD-SW-C3-20P,4608-1478");
        f2893c.add("FC65WHD-SW-A3-20P,4608-BA4E");
        f2893c.add("FC55WHD-SW-A3-20P,4608-D1AC");
    }

    public static boolean a(Context context, String str, boolean z) {
        String strF = f(context, str);
        return TextUtils.isEmpty(strF) ? z : "true".equals(strF);
    }

    public static long b(Context context, String str, long j2) {
        String strF = f(context, str);
        if (TextUtils.isEmpty(strF)) {
            return j2;
        }
        try {
            return Long.parseLong(strF);
        } catch (Exception e2) {
            Log.e("PreferencesUtils", "Exception", e2);
            return j2;
        }
    }

    public static String c(Context context) {
        return f(context, "KEY_PLATFORM_DEVICE_ID");
    }

    public static String d(Context context) {
        return f(context, "KEY_PLATFORM_VERSION");
    }

    private static String e(ContentResolver contentResolver, String str) {
        String string = "";
        Cursor cursorQuery = null;
        try {
            try {
                cursorQuery = contentResolver.query(f2892b, new String[]{str}, null, null, null);
                if (cursorQuery != null && cursorQuery.moveToFirst()) {
                    string = cursorQuery.getString(0);
                }
            } catch (Exception e2) {
                Log.e("PreferencesUtils", "Preferences#getString error, maybe URI is wrong.", e2);
                if (cursorQuery != null) {
                }
            }
            return string;
        } finally {
            if (cursorQuery != null) {
                cursorQuery.close();
            }
        }
    }

    public static String f(Context context, String str) {
        return e(context.getContentResolver(), str);
    }

    public static String g(Context context, String str, String str2) {
        String strF = f(context, str);
        return TextUtils.isEmpty(strF) ? str2 : strF;
    }

    public static String h(Context context, String str, int i2) {
        if (Build.VERSION.SDK_INT < 25) {
            return e(context.getContentResolver(), str);
        }
        UserContentResolver userContentResolver = a;
        if (userContentResolver == null) {
            a = new UserContentResolver(context, i2);
        } else {
            userContentResolver.setUserId(i2);
        }
        return e(a, str);
    }

    public static String i(Context context, String str, String str2, int i2) {
        String strH = h(context, str, i2);
        return TextUtils.isEmpty(strH) ? str2 : strH;
    }

    public static boolean j(Context context) {
        return a(context, "auto_ota_update_state", false);
    }

    public static boolean k(Context context) {
        return a(context, "auto_update", false);
    }

    public static boolean l(Context context, String str, boolean z) {
        return o(context, str, z ? "true" : "false");
    }

    public static boolean m(Context context, String str, long j2) {
        return o(context, str, String.valueOf(j2));
    }

    private static boolean n(ContentResolver contentResolver, String str, String str2) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("key", str);
        contentValues.put("value", str2);
        try {
            return contentResolver.update(f2892b, contentValues, null, null) > 0;
        } catch (Exception e2) {
            Log.e("PreferencesUtils", "Preferences#putString error, maybe URI is wrong.", e2);
            return false;
        }
    }

    public static boolean o(Context context, String str, String str2) {
        return n(context.getContentResolver(), str, str2);
    }

    public static boolean p(Context context, String str, String str2, int i2) {
        if (Build.VERSION.SDK_INT < 25) {
            return n(context.getContentResolver(), str, str2);
        }
        UserContentResolver userContentResolver = a;
        if (userContentResolver == null) {
            a = new UserContentResolver(context, i2);
        } else {
            userContentResolver.setUserId(i2);
        }
        return n(a, str, str2);
    }

    public static void q(Context context, boolean z) {
        l(context, "auto_update", z);
    }

    public static void r(Context context, String str) {
        o(context, "KEY_PLATFORM_DEVICE_ID", str);
    }

    public static void s(Context context, String str) {
        o(context, "KEY_PLATFORM_VERSION", str);
    }

    public static void t(Context context, boolean z) {
        l(context, "KEY_RESET_WALLPAPER_FOR_OTA", z);
    }
}
