package com.seewo.vcommons.data;

import android.content.Context;
import android.database.Cursor;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.media.AudioManager;
import android.net.Uri;
import com.seewo.vcommons.utils.BoardTypeUtils;
import com.seewo.vcommons.utils.RLog;
import com.seewo.vcommons.utils.reflect.Reflect;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public class USBDeviceUtils {
    private static final int CLOSE_MEDIA_SOUND_DEVICE = 2;
    private static final int OPEN_MEDIA_SOUND_DEVICE = 16384;
    private static final int REMOVE_MEDIA_SOUND_DEVICE = 0;

    /* JADX INFO: renamed from: com.seewo.vcommons.data.USBDeviceUtils$1, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        public static final /* synthetic */ int[] $SwitchMap$com$seewo$vcommons$data$USBDeviceUtils$ActionMediaDevice;

        static {
            ActionMediaDevice.values();
            int[] iArr = new int[3];
            $SwitchMap$com$seewo$vcommons$data$USBDeviceUtils$ActionMediaDevice = iArr;
            try {
                iArr[ActionMediaDevice.OPEN.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$seewo$vcommons$data$USBDeviceUtils$ActionMediaDevice[ActionMediaDevice.CLOSE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
        }
    }

    public enum ActionMediaDevice {
        OPEN,
        REMOVE,
        CLOSE
    }

    private USBDeviceUtils() {
    }

    public static Map<String, Object> getLocalSmartPenInfo(Context context) {
        HashMap map = new HashMap();
        Cursor cursorQuery = context.getContentResolver().query(Uri.parse("content://com.seewo.osservice.provider.smartpen/smart_pen"), null, null, null, 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 Map<String, Object> getLocalWirelessDisplayInfo(Context context) {
        HashMap map = new HashMap();
        Cursor cursorQuery = context.getContentResolver().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 List<UsbDevice> getUsbDevices(Context context) {
        UsbManager usbManager = (UsbManager) context.getSystemService("usb");
        if (usbManager == null) {
            return new ArrayList();
        }
        HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
        ArrayList arrayList = new ArrayList();
        Iterator<Map.Entry<String, UsbDevice>> it = deviceList.entrySet().iterator();
        while (it.hasNext()) {
            arrayList.add(it.next().getValue());
        }
        return arrayList;
    }

    public static boolean isInMediaDeviceChannel(Context context) {
        if (!PreferencesUtils.isMediaDeviceEnable(context) || !BoardTypeUtils.is811Machine()) {
            return false;
        }
        int iIntValue = ((Integer) Reflect.on((AudioManager) context.getSystemService("audio")).call("getMediaOutDevice").get()).intValue();
        RLog.d("USBDeviceUtils", "mediaType:" + iIntValue);
        return iIntValue == 16384;
    }

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

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

    public static void setMediaDeviceChannel(Context context, ActionMediaDevice actionMediaDevice) {
        if (BoardTypeUtils.is811Machine()) {
            AudioManager audioManager = (AudioManager) context.getSystemService("audio");
            int iOrdinal = actionMediaDevice.ordinal();
            int i2 = 2;
            if (iOrdinal == 0) {
                i2 = 16384;
            } else if (iOrdinal != 2) {
                i2 = 0;
            }
            Reflect.on(audioManager).call("setMediaOutDevice", Integer.valueOf(i2));
        }
    }
}
