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.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.seewo.libmcuservice.constant.ITVStateConstants;
import java.util.HashSet;
import java.util.Set;

/* JADX INFO: compiled from: PreferencesUtils.java */
/* JADX INFO: loaded from: classes.dex */
public class c {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final Uri f2546b = Uri.parse("content://com.seewo.osservice.provider.VCommonContentProvider/key");

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

    static {
        HashSet hashSet = new HashSet(5);
        f2547c = 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, String str, boolean z) {
        String strD = d(context, str);
        return TextUtils.isEmpty(strD) ? z : "true".equals(strD);
    }

    public static boolean b(Context context) {
        return a(context, "ethernet_switch_state", true);
    }

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

    public static String e(Context context) {
        return d(context, "usb_path");
    }

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

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

    public static void h(Context context, String str) {
        g(context, "manual_gateway_addr", str);
    }
}
