package com.ifpdos.debugmenu.action;

import android.content.Context;
import com.cvte.vman.instance.InvokeCmd;
import com.ifpdos.debugmenu.action.base.ItemInfoAction;
import com.seewo.sdk.model.SDKKeyboardCode;
import com.seewo.sdk.util.RLog;
import d.b.a.a.a;
import d.f.a.v0;
import d.i.f.c.c;
import java.io.File;
import java.io.FileInputStream;

/* JADX INFO: loaded from: classes.dex */
public class ShowMicVersionAction extends ItemInfoAction implements v0 {
    private static final int DEV_VENDOR_ID = 8183;
    private static final String HIDRAW_PATH = "/sys/class/hidraw";
    private static final String TAG = "ShowMicVersionAction";
    private String standard_data;
    private static final int[] DEV_PRODUCT_ID_S = {InvokeCmd.CMD_PROJECT_ID_SET_INDEX, InvokeCmd.CMD_PROJECT_ID_GET_INDEX, InvokeCmd.CMD_PROJECT_ID_IS_SUPPORT};
    private static final byte[] CTRL_DEV_REPORT_DESC = {6, -1, -1, 9, 0, -95, 1, -123, 1, SDKKeyboardCode.FUNCTION_KEY_BOARD_R, 0, SDKKeyboardCode.FUNCTION_KEY_BOARD_8, -1, SDKKeyboardCode.FUNCTION_KEY_BOARD_V, 0, 41, -1, -106, -1, 1, 117, 8, SDKKeyboardCode.FUNCTION_KEY_BOARD_VOLUME_MUTE, 2, SDKKeyboardCode.FUNCTION_KEY_BOARD_V, 0, 41, -1, -106, -1, 7, -111, 2, -64};

    public ShowMicVersionAction(Context context) {
        super(context);
        c.l("persist.sys.cape.update", "1");
    }

    private static String getDeviceCtrlPath() {
        File[] fileArrListFiles = new File(HIDRAW_PATH).listFiles();
        if (fileArrListFiles != null && fileArrListFiles.length > 0) {
            int i2 = 0;
            for (int i3 = 0; i3 < fileArrListFiles.length; i3++) {
                if (fileArrListFiles[i3].isDirectory() && isTargetDev(fileArrListFiles[i3].getPath()) != null) {
                    i2++;
                    byte[] reportDescriptor = readReportDescriptor(fileArrListFiles[i3].getPath());
                    if (reportDescriptor == null || reportDescriptor.length <= 0) {
                        if (i2 == 2) {
                            StringBuilder sbB = a.B("/dev/");
                            sbB.append(fileArrListFiles[i3].getName());
                            return sbB.toString();
                        }
                    } else if (isTheSameDesc(reportDescriptor, CTRL_DEV_REPORT_DESC)) {
                        StringBuilder sbB2 = a.B("/dev/");
                        sbB2.append(fileArrListFiles[i3].getName());
                        return sbB2.toString();
                    }
                }
            }
        }
        return null;
    }

    private static String getMicNormal() {
        String micVersion = getMicVersion();
        if (!a.b0("Hid micVersion:", micVersion, TAG, micVersion)) {
            return micVersion;
        }
        String strF = c.f("persist.sys.cape.version", "");
        a.O("PropertiesUtils.getArrayMicVersion:", strF, TAG);
        return strF;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:101:0x0220  */
    /* JADX WARN: Removed duplicated region for block: B:122:0x01a6 A[EDGE_INSN: B:122:0x01a6->B:92:0x01a6 BREAK  A[LOOP:2: B:50:0x00de->B:108:0x023d], SYNTHETIC] */
    /* JADX WARN: Type inference failed for: r2v0, types: [d.d.b.a.b] */
    /* JADX WARN: Type inference failed for: r7v0 */
    /* JADX WARN: Type inference failed for: r7v1, types: [boolean] */
    /* JADX WARN: Type inference failed for: r7v14 */
    /* JADX WARN: Type inference failed for: r7v19 */
    /* JADX WARN: Type inference failed for: r7v2, types: [int] */
    /* JADX WARN: Type inference failed for: r7v6 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static java.lang.String getMicVersion() {
        /*
            Method dump skipped, instruction units count: 587
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ifpdos.debugmenu.action.ShowMicVersionAction.getMicVersion():java.lang.String");
    }

    private static boolean isPidVidMatch(String[] strArr) {
        if (strArr != null && strArr.length >= 3) {
            String str = String.format("%08X", Integer.valueOf(DEV_VENDOR_ID));
            for (int i2 : DEV_PRODUCT_ID_S) {
                String str2 = String.format("%08X", Integer.valueOf(i2));
                if (strArr[1].equals(str) && strArr[2].equals(str2)) {
                    return true;
                }
            }
        }
        return false;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:50:0x0092 A[Catch: IOException -> 0x008e, TryCatch #9 {IOException -> 0x008e, blocks: (B:46:0x008a, B:50:0x0092, B:52:0x0097), top: B:60:0x008a }] */
    /* JADX WARN: Removed duplicated region for block: B:52:0x0097 A[Catch: IOException -> 0x008e, TRY_LEAVE, TryCatch #9 {IOException -> 0x008e, blocks: (B:46:0x008a, B:50:0x0092, B:52:0x0097), top: B:60:0x008a }] */
    /* JADX WARN: Removed duplicated region for block: B:60:0x008a A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Type inference failed for: r7v0, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r7v12 */
    /* JADX WARN: Type inference failed for: r7v13, types: [java.io.InputStreamReader, java.io.Reader] */
    /* JADX WARN: Type inference failed for: r7v2 */
    /* JADX WARN: Type inference failed for: r7v4 */
    /* JADX WARN: Type inference failed for: r7v5, types: [java.io.InputStreamReader] */
    /* JADX WARN: Type inference failed for: r7v7, types: [java.io.InputStreamReader] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static java.lang.String isTargetDev(java.lang.String r7) throws java.lang.Throwable {
        /*
            java.lang.String r0 = "ShowMicVersionAction"
            r1 = 0
            java.io.FileInputStream r2 = new java.io.FileInputStream     // Catch: java.lang.Throwable -> L63 java.io.IOException -> L69
            java.lang.StringBuilder r3 = new java.lang.StringBuilder     // Catch: java.lang.Throwable -> L63 java.io.IOException -> L69
            r3.<init>()     // Catch: java.lang.Throwable -> L63 java.io.IOException -> L69
            r3.append(r7)     // Catch: java.lang.Throwable -> L63 java.io.IOException -> L69
            java.lang.String r7 = "/device/uevent"
            r3.append(r7)     // Catch: java.lang.Throwable -> L63 java.io.IOException -> L69
            java.lang.String r7 = r3.toString()     // Catch: java.lang.Throwable -> L63 java.io.IOException -> L69
            r2.<init>(r7)     // Catch: java.lang.Throwable -> L63 java.io.IOException -> L69
            java.io.InputStreamReader r7 = new java.io.InputStreamReader     // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5f
            r7.<init>(r2)     // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5f
            java.io.BufferedReader r3 = new java.io.BufferedReader     // Catch: java.lang.Throwable -> L54 java.io.IOException -> L59
            r3.<init>(r7)     // Catch: java.lang.Throwable -> L54 java.io.IOException -> L59
        L23:
            java.lang.String r4 = r3.readLine()     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            if (r4 == 0) goto L48
            java.lang.String r5 = "HID_ID="
            boolean r5 = r4.startsWith(r5)     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            if (r5 != 0) goto L32
            goto L23
        L32:
            java.lang.String r5 = ":"
            java.lang.String[] r5 = r4.split(r5)     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            boolean r5 = isPidVidMatch(r5)     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            if (r5 == 0) goto L23
            r3.close()     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            r7.close()     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            r2.close()     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            return r4
        L48:
            r3.close()     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            r7.close()     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            r2.close()     // Catch: java.io.IOException -> L52 java.lang.Throwable -> L87
            goto L86
        L52:
            r4 = move-exception
            goto L6d
        L54:
            r3 = move-exception
            r6 = r3
            r3 = r1
            r1 = r6
            goto L88
        L59:
            r4 = move-exception
            r3 = r1
            goto L6d
        L5c:
            r7 = move-exception
            r3 = r1
            goto L66
        L5f:
            r4 = move-exception
            r7 = r1
            r3 = r7
            goto L6d
        L63:
            r7 = move-exception
            r2 = r1
            r3 = r2
        L66:
            r1 = r7
            r7 = r3
            goto L88
        L69:
            r4 = move-exception
            r7 = r1
            r2 = r7
            r3 = r2
        L6d:
            com.seewo.sdk.util.RLog.e(r0, r4)     // Catch: java.lang.Throwable -> L87
            if (r3 == 0) goto L78
            r3.close()     // Catch: java.io.IOException -> L76
            goto L78
        L76:
            r7 = move-exception
            goto L83
        L78:
            if (r7 == 0) goto L7d
            r7.close()     // Catch: java.io.IOException -> L76
        L7d:
            if (r2 == 0) goto L86
            r2.close()     // Catch: java.io.IOException -> L76
            goto L86
        L83:
            com.seewo.sdk.util.RLog.e(r0, r7)
        L86:
            return r1
        L87:
            r1 = move-exception
        L88:
            if (r3 == 0) goto L90
            r3.close()     // Catch: java.io.IOException -> L8e
            goto L90
        L8e:
            r7 = move-exception
            goto L9b
        L90:
            if (r7 == 0) goto L95
            r7.close()     // Catch: java.io.IOException -> L8e
        L95:
            if (r2 == 0) goto L9e
            r2.close()     // Catch: java.io.IOException -> L8e
            goto L9e
        L9b:
            com.seewo.sdk.util.RLog.e(r0, r7)
        L9e:
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ifpdos.debugmenu.action.ShowMicVersionAction.isTargetDev(java.lang.String):java.lang.String");
    }

    private static boolean isTheSameDesc(byte[] bArr, byte[] bArr2) {
        if (bArr == null || bArr.length < bArr2.length) {
            return false;
        }
        for (int i2 = 0; i2 < bArr2.length; i2++) {
            if (bArr2[i2] != bArr[i2]) {
                return false;
            }
        }
        return true;
    }

    private static byte[] readReportDescriptor(String str) {
        byte[] bArr = new byte[256];
        try {
            StringBuilder sb = new StringBuilder();
            sb.append(str);
            sb.append("/device/report_descriptor");
            return new FileInputStream(sb.toString()).read(bArr) <= 0 ? new byte[0] : bArr;
        } catch (Exception e2) {
            RLog.e(TAG, e2);
            return new byte[0];
        }
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemInfoAction
    public String getValue(Context context) {
        return getMicNormal();
    }

    @Override // d.f.a.v0
    public void setStandData(String str) {
        this.standard_data = str;
    }
}
