package com.seewo.libshid.util;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import com.seewo.libmcuservice.constant.IMcuConstants;
import com.seewo.libshid.SeewoPIDVID;
import com.seewo.libshid.devices.DeviceIdent;
import com.seewo.vcommons.data.UserContentResolver;
import com.seewo.vcommons.mstar.MKeyEvent;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;

/* JADX INFO: loaded from: classes.dex */
public class Utils {
    public static final int DEFAULT_SMART_PEN_IDENTIFIER = -1;
    public static final String DEFAULT_SMART_PEN_NAME = "NODEVICE";
    public static final String DEFAULT_USB_DEVICES_NAME = "NODEVICE";
    public static final int DEFAULT_USB_DEVICE_IDENTIFIER = -1;
    public static final String KEY_COMMON_NAME_SUFFIX = "_name";
    public static final String KEY_COMMON_PID_SUFFIX = "_pid";
    public static final String KEY_COMMON_VID_SUFFIX = "_vid";
    public static final String LOCAL_SMART_PEN_INFO_URI = "content://com.seewo.osservice.provider.smartpen/smart_pen";
    public static final String LOCAL_WIRELESS_DISPLAY_INFO_URI = "content://com.seewo.osservice.provider.smartpen/wireless_display";
    public static final String SMART_PEN_NAME_KEY = "smart_pen_name";
    public static final String SMART_PEN_PID_KEY = "smart_pen_pid";
    public static final String SMART_PEN_UNIQUE_KEY_PREFIX = "smart_pen";
    public static final String SMART_PEN_VID_KEY = "smart_pen_vid";
    public static final int SP01_PAIRED_DATA_LENGTH = 64;
    public static final int SP01_READ_BYTE_SIZE = 3;
    public static final int SP03_PAIRED_DATA_LENGTH = 64;
    public static final int SP03_READ_BYTE_SIZE = 5;
    public static final int SP05A_PAIRED_DATA_LENGTH = 8;
    public static final int SP05A_READ_BYTE_SIZE = 8;
    public static final int SP05_PAIRED_DATA_LENGTH = 64;
    public static final int SP05_READ_BYTE_SIZE = 3;
    public static final String USB_DEVICE_URI_PREFIX = "content://com.seewo.osservice.provider.smartpen/";
    public static final String WIRELESS_DISPLAY_NAME_KEY = "wireless_display_name";
    public static final String WIRELESS_DISPLAY_PID_KEY = "wireless_display_pid";
    public static final String WIRELESS_DISPLAY_UNIQUE_KEY_PREFIX = "wireless_display";
    public static final String WIRELESS_DISPLAY_VID_KEY = "wireless_display_vid";

    private Utils() {
    }

    public static int changeByteToInt(byte b2) {
        return b2 & IMcuConstants.DEFAULT_VALUE;
    }

    public static ByteBuffer createSP01PairedData() {
        ByteBuffer byteBufferAllocate = ByteBuffer.allocate(64);
        byteBufferAllocate.put(new byte[]{-4, 8, -67, -24, -41});
        int iChangeByteToInt = 0;
        for (int i2 = 0; i2 < 63; i2++) {
            if (i2 > 4) {
                byteBufferAllocate.put((byte) 0);
            }
            iChangeByteToInt += changeByteToInt(byteBufferAllocate.get(i2));
        }
        byteBufferAllocate.put(63, (byte) ((iChangeByteToInt % MKeyEvent.KEYCODE_EPG) & MKeyEvent.KEYCODE_SLEEP));
        return byteBufferAllocate;
    }

    private static UserContentResolver getCurrentUserContentResolver(Context context) {
        return new UserContentResolver(context, 0);
    }

    public static HashMap<String, Object> getLocalSmartPenInfo(Context context) {
        HashMap<String, Object> map = new HashMap<>();
        Cursor cursorQuery = getCurrentUserContentResolver(context).query(Uri.parse("content://com.seewo.osservice.provider.smartpen/smart_pen"), null, null, null, null);
        if (cursorQuery == null) {
            return null;
        }
        while (cursorQuery.moveToNext()) {
            map.put("smart_pen_name", cursorQuery.getString(cursorQuery.getColumnIndex("smart_pen_name")));
            map.put("smart_pen_pid", Integer.valueOf(cursorQuery.getInt(cursorQuery.getColumnIndex("smart_pen_pid"))));
            map.put("smart_pen_vid", Integer.valueOf(cursorQuery.getInt(cursorQuery.getColumnIndex("smart_pen_vid"))));
        }
        cursorQuery.close();
        return map;
    }

    public static HashMap<String, Object> getLocalWirelessDisplayInfo(Context context) {
        HashMap<String, Object> map = new HashMap<>();
        Cursor cursorQuery = getCurrentUserContentResolver(context).query(Uri.parse("content://com.seewo.osservice.provider.smartpen/wireless_display"), null, null, null, null);
        if (cursorQuery == null) {
            return null;
        }
        while (cursorQuery.moveToNext()) {
            map.put("wireless_display_name", cursorQuery.getString(cursorQuery.getColumnIndex("wireless_display_name")));
            map.put("wireless_display_pid", Integer.valueOf(cursorQuery.getInt(cursorQuery.getColumnIndex("wireless_display_pid"))));
            map.put("wireless_display_vid", Integer.valueOf(cursorQuery.getInt(cursorQuery.getColumnIndex("wireless_display_vid"))));
        }
        cursorQuery.close();
        return map;
    }

    public static int getWirelessDisplayDeviceCount(Context context) {
        int count = 0;
        if (!isWirelessDisplayEnabled(context)) {
            return 0;
        }
        Cursor cursorQuery = getCurrentUserContentResolver(context).query(Uri.parse("content://com.seewo.osservice.provider.smartpen/wireless_display"), null, null, null, null);
        if (cursorQuery != null && cursorQuery.getCount() != 0) {
            count = cursorQuery.getCount();
        }
        if (cursorQuery != null) {
            cursorQuery.close();
        }
        return count;
    }

    public static boolean is8821auCPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.NP05_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean is8821auDPIDVID(int i2, int i3) {
        return i2 == 18 && i3 == 9732;
    }

    public static boolean isElectricShelfPIDVID(int i2, int i3) {
        return i2 == 57360 && i3 == 6790;
    }

    public static boolean isMachD_LINK_DWA182_REV_D1PIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.WIFI_D_LINK_DWA182_REV_D1_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMachRel8188eusPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.REL8188EUS_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMachRel8188eus_1PIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.REL8188EUS_1_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMachRel8812auPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.REL8812AU_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMachRel8821auPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.REL8821AU_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMachRel8822buPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.REL8822BU_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMachRel8822cuPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.REL8822CU_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMachRtl8192buPIDVID(int i2, int i3) {
        return i2 == 33163 && i3 == 3034;
    }

    public static boolean isMatchMt7632uPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.MT7632U_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMatchRel8188gtvPIDVID(int i2, int i3) {
        return i2 == 396 && i3 == 3034;
    }

    public static boolean isMatchRel8821cuPIDVID(int i2, int i3) {
        return i2 == 51232 && i3 == 3034;
    }

    public static boolean isMatchSeewoSmartPenPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.DEVICE_IDENTS).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMatchWifiPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.HISI_WIFI_DEVICES).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMatchWiredDisplayPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.WIRED_DISPLAY_DEVICE_IDENTS).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isMatchWirelessDisplayPIDVID(int i2, int i3) {
        return Arrays.asList(SeewoPIDVID.WIRLESS_DISPLAY_DEVICE_IDENTS).contains(new DeviceIdent(i2, i3));
    }

    public static boolean isSmartPenEnabled(Context context) {
        HashMap<String, Object> localSmartPenInfo = getLocalSmartPenInfo(context);
        if (localSmartPenInfo == null) {
            return false;
        }
        Object obj = localSmartPenInfo.get("smart_pen_pid");
        Object obj2 = localSmartPenInfo.get("smart_pen_vid");
        if (obj == null || obj2 == null) {
            return false;
        }
        return (((Integer) obj).intValue() == -1 && ((Integer) obj2).intValue() == -1) ? false : true;
    }

    public static boolean isWirelessDisplayEnabled(Context context) {
        HashMap<String, Object> localWirelessDisplayInfo = getLocalWirelessDisplayInfo(context);
        if (localWirelessDisplayInfo == null) {
            return false;
        }
        Object obj = localWirelessDisplayInfo.get("wireless_display_pid");
        Object obj2 = localWirelessDisplayInfo.get("wireless_display_vid");
        if (obj == null || obj2 == null) {
            return false;
        }
        return (((Integer) obj).intValue() == -1 && ((Integer) obj2).intValue() == -1) ? false : true;
    }
}
