package d.i.f.c;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.seewo.vcommons.data.UserContentResolver;
import java.util.HashSet;
import java.util.Set;

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

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

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

    /* JADX INFO: compiled from: PreferencesUtils.java */
    public enum a {
        LAN,
        INTERNET
    }

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

    public static boolean a(Context context) {
        boolean zEquals = "true".equals(f(context, "ap_status", 0));
        StringBuilder sbB = d.b.a.a.a.B("[");
        sbB.append(context.getPackageName());
        sbB.append("] getApStatus: ");
        sbB.append(zEquals);
        Log.d("PreferencesUtils", sbB.toString());
        return zEquals;
    }

    public static boolean b(Context context, String str, boolean z) {
        String strD = d(context.getContentResolver(), str);
        return TextUtils.isEmpty(strD) ? z : "true".equals(strD);
    }

    public static int c(Context context, String str, int i2) {
        String strD = d(context.getContentResolver(), str);
        if (TextUtils.isEmpty(strD)) {
            return i2;
        }
        try {
            return Integer.parseInt(strD);
        } catch (Exception e2) {
            Log.e("PreferencesUtils", "Exception", e2);
            return i2;
        }
    }

    public static String d(ContentResolver contentResolver, String str) {
        String string = "";
        Cursor cursorQuery = null;
        try {
            try {
                cursorQuery = contentResolver.query(f3646b, 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 e(Context context, String str, String str2) {
        String strD = d(context.getContentResolver(), str);
        return TextUtils.isEmpty(strD) ? str2 : strD;
    }

    public static String f(Context context, String str, int i2) {
        UserContentResolver userContentResolver = a;
        if (userContentResolver == null) {
            a = new UserContentResolver(context, i2);
        } else {
            userContentResolver.setUserId(i2);
        }
        return d(a, str);
    }

    public static boolean g(Context context, String str, boolean z) {
        return h(context.getContentResolver(), str, z ? "true" : "false");
    }

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

    public static boolean i(Context context, String str, String str2, int i2) {
        UserContentResolver userContentResolver = a;
        if (userContentResolver == null) {
            a = new UserContentResolver(context, i2);
        } else {
            userContentResolver.setUserId(i2);
        }
        return h(a, str, str2);
    }

    public static void j(Context context, boolean z) {
        i(context, "screen_saver", z ? "true" : "false", 0);
    }
}
