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.constants.SeewoConstants;
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;

    public enum ActionMediaDevice {
        OPEN,
        REMOVE,
        CLOSE
    }

    private USBDeviceUtils() {
    }

    public static void setMediaDeviceChannel(Context context, ActionMediaDevice actionMediaDevice) {
        int i;
        if (BoardTypeUtils.is811Machine()) {
            AudioManager audioManager = (AudioManager) context.getSystemService("audio");
            int i2 = AnonymousClass1.$SwitchMap$com$seewo$vcommons$data$USBDeviceUtils$ActionMediaDevice[actionMediaDevice.ordinal()];
            if (i2 != 1) {
                i = 2;
                if (i2 != 2) {
                    i = 0;
                }
            } else {
                i = OPEN_MEDIA_SOUND_DEVICE;
            }
            Reflect.on(audioManager).call("setMediaOutDevice", Integer.valueOf(i));
        }
    }

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

        static {
            int[] iArr = new int[ActionMediaDevice.values().length];
            $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 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 == OPEN_MEDIA_SOUND_DEVICE;
    }

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

    public static Map<String, Object> getLocalWirelessDisplayInfo(Context context) {
        HashMap map = new HashMap();
        Cursor cursorQuery = context.getContentResolver().query(Uri.parse(SeewoConstants.LOCAL_WIRELESS_DISPLAY_INFO_URI), null, null, null, null);
        if (cursorQuery == null) {
            return null;
        }
        while (cursorQuery.moveToNext()) {
            map.put(SeewoConstants.WIRELESS_DISPLAY_NAME_KEY, cursorQuery.getString(cursorQuery.getColumnIndex(SeewoConstants.WIRELESS_DISPLAY_NAME_KEY)));
            map.put(SeewoConstants.WIRELESS_DISPLAY_PID_KEY, Integer.valueOf(cursorQuery.getInt(cursorQuery.getColumnIndex(SeewoConstants.WIRELESS_DISPLAY_PID_KEY))));
            map.put(SeewoConstants.WIRELESS_DISPLAY_VID_KEY, Integer.valueOf(cursorQuery.getInt(cursorQuery.getColumnIndex(SeewoConstants.WIRELESS_DISPLAY_VID_KEY))));
        }
        cursorQuery.close();
        return map;
    }

    public static Map<String, Object> getLocalSmartPenInfo(Context context) {
        HashMap map = new HashMap();
        Cursor cursorQuery = context.getContentResolver().query(Uri.parse(SeewoConstants.LOCAL_SMART_PEN_INFO_URI), null, null, null, null);
        while (cursorQuery.moveToNext()) {
            map.put(SeewoConstants.SMART_PEN_NAME_KEY, cursorQuery.getString(cursorQuery.getColumnIndex(SeewoConstants.SMART_PEN_NAME_KEY)));
            map.put(SeewoConstants.SMART_PEN_PID_KEY, Integer.valueOf(cursorQuery.getInt(cursorQuery.getColumnIndex(SeewoConstants.SMART_PEN_PID_KEY))));
            map.put(SeewoConstants.SMART_PEN_VID_KEY, Integer.valueOf(cursorQuery.getInt(cursorQuery.getColumnIndex(SeewoConstants.SMART_PEN_VID_KEY))));
        }
        cursorQuery.close();
        return map;
    }

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

    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;
    }
}
