package com.seewo.vcommons.data;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
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;
    private static final Uri b;

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

    /* JADX INFO: compiled from: PreferencesUtils.java */
    public enum a {
        CLOSE,
        NOT_AUTH,
        AUTH
    }

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

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

    public static void B(Context context, int i2) {
        x(context, "AUTO_BLACK_SCREEN", i2, 0);
        com.seewo.hiddenapi.b.c(context, new Intent("com.seewo.action.update_auto_black_screen"), com.seewo.hiddenapi.c.a);
    }

    public static void C(Context context, int i2) {
        x(context, "AUTO_POWER_OFF", i2, 0);
        com.seewo.hiddenapi.b.c(context, new Intent("com.seewo.action.update_auto_power_off"), com.seewo.hiddenapi.c.a);
    }

    public static void D(Context context, boolean z) {
        u(context, "KEY_DISPLAY_POWER_MANAGEMENT", z);
    }

    public static void E(Context context, Integer num) {
        z(context, "KEY_FAKE_POWER_OFF_CHANNEL", num == null ? "" : String.valueOf(num));
    }

    public static void F(Context context, a aVar) {
        z(context, "KEY_LAN_RS232_MODE", aVar.name());
        context.sendBroadcast(new Intent("com.seewo.remote.action. ACTION_UPDATE_LAN_RS232_STATE"));
    }

    public static void G(Context context, int i2) {
        z(context, "MDA_MUTE_STATE", String.valueOf(i2));
    }

    public static void H(Context context, int i2) {
        x(context, "POWER_SAVE_STATE", i2, 0);
    }

    public static void I(Context context, String str) {
        z(context, "sahara_password", str);
    }

    public static void J(Context context, boolean z) {
        v(context, "screen_saver", z, 0);
    }

    public static int a(Context context) {
        return h(context, "AUTO_BLACK_SCREEN", e.c.e.c.a.e() ? 15 : 0, 0);
    }

    public static int b(Context context) {
        return h(context, "AUTO_POWER_OFF", 0, 0);
    }

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

    public static boolean d(Context context, String str, boolean z, int i2) {
        String strN = n(context, str, i2);
        return TextUtils.isEmpty(strN) ? z : "true".equals(strN);
    }

    public static int e(Context context, int i2) {
        return g(context, "KEY_EYE_CARE_MODE", i2);
    }

    public static boolean f(Context context) {
        return c(context, "KEY_FAKE_STANDBY", false);
    }

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

    public static int h(Context context, String str, int i2, int i3) {
        String strN = n(context, str, i3);
        if (TextUtils.isEmpty(strN)) {
            return i2;
        }
        try {
            return Integer.parseInt(strN);
        } catch (Exception e2) {
            Log.e("PreferencesUtils", "Exception", e2);
            return i2;
        }
    }

    public static int i(Context context) {
        String strM = m(context, "MDA_MUTE_STATE");
        if (TextUtils.isEmpty(strM)) {
            return -1;
        }
        try {
            return Integer.valueOf(strM).intValue();
        } catch (NumberFormatException e2) {
            Log.d("PreferencesUtils", "getMDAMuteState convert to integer error", e2);
            return -1;
        }
    }

    public static int j(Context context) {
        return h(context, "POWER_SAVE_STATE", 2, 0);
    }

    public static String k(Context context) {
        return m(context, "sahara_password");
    }

    private static String l(ContentResolver contentResolver, String str) {
        String string = "";
        Cursor cursorQuery = null;
        try {
            try {
                cursorQuery = contentResolver.query(b, 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 m(Context context, String str) {
        return l(context.getContentResolver(), str);
    }

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

    public static String o(Context context) {
        return n(context, "key_touch_check_sum", 0);
    }

    public static boolean p(Context context) {
        return d(context, "KEY_DISPLAY_POWER_MANAGEMENT", false, 0);
    }

    public static boolean q(Context context) {
        return c(context, "KEY_FACTORY_IR_TRABSMIT", false);
    }

    public static boolean r(Context context) {
        return c(context, "pass_through", false);
    }

    public static boolean s(Context context) {
        return d(context, "screen_saver", e.c.e.c.a.a() && e.c.e.f.b.g(), 0);
    }

    public static boolean t(Context context) {
        return d(context, "wifi_ap_support_duplex", false, 0);
    }

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

    public static boolean v(Context context, String str, boolean z, int i2) {
        return A(context, str, z ? "true" : "false", i2);
    }

    public static boolean w(Context context, String str, int i2) {
        return z(context, str, String.valueOf(i2));
    }

    public static boolean x(Context context, String str, int i2, int i3) {
        return A(context, str, String.valueOf(i2), i3);
    }

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

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