package com.tencent.usb;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.util.Log;
import com.cvte.va.sdk.mica.receiver.UsbChangeReceiver;

/* JADX INFO: loaded from: classes.dex */
public class a {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static a f1504c;
    private Context a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private b f1505b;

    /* JADX INFO: renamed from: com.tencent.usb.a$a, reason: collision with other inner class name */
    public interface InterfaceC0014a {
        void onAttach();

        void onDetach(UsbDevice usbDevice);
    }

    public class b extends BroadcastReceiver {
        private InterfaceC0014a a;

        public b(a aVar) {
        }

        public void a(InterfaceC0014a interfaceC0014a) {
            this.a = interfaceC0014a;
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            UsbDevice usbDevice;
            String action = intent.getAction();
            Log.i("USB_DEV", "usb action + " + action);
            usbDevice = (UsbDevice) intent.getParcelableExtra("device");
            action.hashCode();
            switch (action) {
                case "android.hardware.usb.action.USB_DEVICE_ATTACHED":
                    if (usbDevice != null) {
                        StringBuilder sbF = g.a.a.a.a.F("设备连接: ");
                        sbF.append(usbDevice.toString());
                        Log.i("USB_DEV", sbF.toString());
                    }
                    if (this.a != null) {
                        if ((usbDevice.getVendorId() == 10071 && usbDevice.getProductId() == 16388) || ((usbDevice.getVendorId() == 10847 && (usbDevice.getProductId() & 61440) == 8192) || ((usbDevice.getVendorId() == 8183 && usbDevice.getProductId() == 1105) || ((usbDevice.getVendorId() == 6127 && usbDevice.getProductId() == 41088) || ((usbDevice.getVendorId() == 8711 && usbDevice.getProductId() == 8197) || (usbDevice.getVendorId() == 12372 && usbDevice.getProductId() == 34952)))))) {
                            StringBuilder sbF2 = g.a.a.a.a.F("命中连接设备: vid:");
                            sbF2.append(usbDevice.getVendorId());
                            sbF2.append(" pid:");
                            sbF2.append(usbDevice.getProductId());
                            Log.i("USB_DEV", sbF2.toString());
                            this.a.onAttach();
                            break;
                        }
                    }
                    break;
                case "android.hardware.usb.action.USB_DEVICE_DETACHED":
                    if (usbDevice != null) {
                        StringBuilder sbF3 = g.a.a.a.a.F("设备断开: ");
                        sbF3.append(usbDevice.toString());
                        Log.i("USB_DEV", sbF3.toString());
                    }
                    if (this.a != null) {
                        if ((usbDevice.getVendorId() == 10071 && usbDevice.getProductId() == 16388) || ((usbDevice.getVendorId() == 10847 && (usbDevice.getProductId() & 61440) == 8192) || ((usbDevice.getVendorId() == 8183 && usbDevice.getProductId() == 1105) || ((usbDevice.getVendorId() == 6127 && usbDevice.getProductId() == 41088) || ((usbDevice.getVendorId() == 8711 && usbDevice.getProductId() == 8197) || (usbDevice.getVendorId() == 12372 && usbDevice.getProductId() == 34952)))))) {
                            StringBuilder sbF4 = g.a.a.a.a.F("命中断开设备: vid:");
                            sbF4.append(usbDevice.getVendorId());
                            sbF4.append(" pid:");
                            sbF4.append(usbDevice.getProductId());
                            Log.i("USB_DEV", sbF4.toString());
                            this.a.onDetach(usbDevice);
                            break;
                        }
                    }
                    break;
                case "android.hardware.usb.action.USB_STATE":
                    Log.i("USB_DEV", "connected :" + intent.getBooleanExtra("connected", false));
                    Log.i("USB_DEV", "configured :" + intent.getBooleanExtra("configured", false));
                    Log.i("USB_DEV", "func_adb :" + intent.getBooleanExtra("adb", false));
                    Log.i("USB_DEV", "func_rndis :" + intent.getBooleanExtra("rndis", false));
                    Log.i("USB_DEV", "func_mtp :" + intent.getBooleanExtra("mtp", false));
                    Log.i("USB_DEV", "func_ptp :" + intent.getBooleanExtra("ptp", false));
                    Log.i("USB_DEV", "finc_audio_source :" + intent.getBooleanExtra("audio_source", false));
                    Log.i("USB_DEV", "func_midi :" + intent.getBooleanExtra("midi", false));
                    break;
            }
        }
    }

    private a(Context context) {
        this.a = context;
        b(this.a);
    }

    private void a() {
        b bVar = this.f1505b;
        if (bVar != null) {
            this.a.unregisterReceiver(bVar);
        }
    }

    public static void a(Context context) {
        f1504c = new a(context);
    }

    private void b(Context context) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(UsbChangeReceiver.f974b);
        intentFilter.addAction(UsbChangeReceiver.f975c);
        intentFilter.addAction("android.hardware.usb.action.USB_STATE");
        b bVar = new b(this);
        this.f1505b = bVar;
        context.registerReceiver(bVar, intentFilter);
    }

    public static a c() {
        return f1504c;
    }

    public void a(InterfaceC0014a interfaceC0014a) {
        b bVar = this.f1505b;
        if (bVar != null) {
            bVar.a(interfaceC0014a);
        }
    }

    public void b() {
        f1504c = null;
        a();
    }
}
