导航菜单

页面标题

页面副标题

Tasker v6.5.11 - USBHandler.java 源代码

正在查看: Tasker v6.5.11 应用的 USBHandler.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package net.dinglisch.android.taskerm;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.text.TextUtils;
import java.io.File;
import java.util.Map;
import java.util.Set;

public class USBHandler extends Activity {
    private static final String[] r;
    private static final com.joaomgcd.taskerm.util.c3[] s;
    private static final int[] i = {65520, 254, 1, 10, 2, 13, 11, 65522, 65521, 3, 8, 239, 0, 5, 7, 6, 255, 14, 224};
    private static final String[] q = {"subsystem", "power", "driver", "usb_device", "ep_", "statistics"};
    private static int[] t = {2131891126, 2131891016, 2131891017, 2131891018, 2131891019, 2131891020, 2131891021, 2131891022, 2131891023, 2131891024, 2131891025, 2131891033, 2131891026, 2131891027, 2131891028, 2131891029, 2131891030, 2131891031, 2131891032};
    private static long u = 0;

    class a extends com.joaomgcd.taskerm.util.c3 {
        final Context d;

        public a(String str, String str2, int i) {
            super("USBFileObserver", str, str2);
            this.d = i;
        }

        @Override
        public void b(int i, String str) {
            if (i != 32768) {
                long currentTimeMillis = System.currentTimeMillis();
                if (currentTimeMillis - USBHandler.u > 1500) {
                    Intent intent = new Intent(this.d, (Class<?>) ReceiverStaticInternal.class);
                    intent.setAction(i == 512 ? "android.hardware.usb.action.USB_DEVICE_DETACHED" : "android.hardware.usb.action.USB_DEVICE_ATTACHED");
                    MonitorService.B9(this.d, intent, -1);
                    USBHandler.u = currentTimeMillis;
                }
            }
        }
    }

    static {
        String[] strArr = {"/storage/emulated", "/dev/input", "/sys/bus/usb/devices", "/dev/usb", "/dev/bus/usb"};
        r = strArr;
        s = new com.joaomgcd.taskerm.util.c3[strArr.length];
    }

    private static void c(Set<Integer> set, File file, int i2, String str) {
        set.add(Integer.valueOf(i2));
        r7.f("USBHandler", "addDevice: " + str + " from: " + file + ": added " + i2);
    }

    public static int d(int i2) {
        int i3 = 0;
        while (true) {
            int[] iArr = i;
            if (i3 >= iArr.length) {
                r7.G("USBHandler", "cti: unknown device class: " + i2);
                return 239;
            }
            if (iArr[i3] == i2) {
                return i3;
            }
            i3++;
        }
    }

    public static String[] e(Resources resources) {
        return vh.s(resources, t);
    }

    public static void f(Context context, Set<Integer> set) {
        g(context, set);
        h(set);
        set.remove(9);
    }

    public static void g(Context context, Set<Integer> set) {
        UsbManager usbManager = (UsbManager) oi.d(context, "usb", "USBHandler", "gcca");
        if (usbManager == null) {
            return;
        }
        for (UsbDevice usbDevice : usbManager.getDeviceList().values()) {
            int deviceClass = usbDevice.getDeviceClass();
            r7.f("USBHandler", "gca: dclass: " + deviceClass);
            c(set, null, deviceClass, "gca");
            for (int i2 = 0; i2 < usbDevice.getInterfaceCount(); i2++) {
                int interfaceClass = usbDevice.getInterface(i2).getInterfaceClass();
                r7.f("USBHandler", "gca: iface " + i2 + " class " + interfaceClass);
                c(set, null, interfaceClass, "gca");
            }
        }
    }

    public static void h(Set<Integer> set) {
        File file = new File("/sys/bus/usb/devices");
        if (file.exists()) {
            i(file, set, 0);
        } else {
            r7.f("USBHandler", "no dir: /sys/bus/usb/devices");
        }
    }

    public static void i(File file, Set<Integer> set, int i2) {
        if (l(file.getName(), q)) {
            return;
        }
        File[] listFiles = file.listFiles();
        if (dq.r(listFiles)) {
            return;
        }
        for (File file2 : listFiles) {
            if (!file2.isDirectory()) {
                String name = file2.getName();
                boolean equals = name.equals("bInterfaceClass");
                if (equals || name.equals("bDeviceClass")) {
                    String X = dq.X(file2);
                    if (!TextUtils.isEmpty(X)) {
                        Integer D1 = dq.D1(X.trim());
                        if (D1 == null) {
                            r7.G("USBHandler", "gccldd: non-integer contents: " + file2);
                        } else if (D1.intValue() == 3 && equals) {
                            int n = n(file);
                            if (n == 2) {
                                c(set, file2, 65521, "gla_mouse");
                            } else if (n == 1) {
                                c(set, file2, 65522, "gla_key");
                            } else {
                                c(set, file2, 3, "gla_hid");
                            }
                        } else if (D1.intValue() != 0) {
                            c(set, file2, D1.intValue(), "gla_default");
                        }
                    }
                }
            } else if (i2 <= 4) {
                i(file2, set, i2 + 1);
            }
        }
    }

    public static UsbDevice j(UsbManager usbManager, int i2, int i3) {
        if (usbManager == null) {
            r7.G("USBHandler", "getDeviceWithClass: no manager ");
            return null;
        }
        for (Map.Entry<String, UsbDevice> entry : usbManager.getDeviceList().entrySet()) {
            String key = entry.getKey();
            UsbDevice value = entry.getValue();
            int deviceClass = value.getDeviceClass();
            int deviceSubclass = value.getDeviceSubclass();
            r7.f("USBHandler", "gdwc: device: " + key + " class " + deviceClass + " sub " + value.getDeviceSubclass());
            if (deviceClass == 0) {
                for (int i4 = 0; i4 < value.getInterfaceCount(); i4++) {
                    UsbInterface usbInterface = value.getInterface(i4);
                    int interfaceClass = usbInterface.getInterfaceClass();
                    int interfaceSubclass = usbInterface.getInterfaceSubclass();
                    r7.f("USBHandler", "gdwc:   test interface " + i4 + " class " + interfaceClass + " sub " + interfaceSubclass);
                    if (interfaceClass == i2 && interfaceSubclass == i3) {
                        r7.f("USBHandler", "gdwc:   match interface");
                        return value;
                    }
                }
            } else if (deviceClass == i2 && deviceSubclass == i3) {
                r7.f("USBHandler", "gdwc: match device");
                return value;
            }
        }
        return null;
    }

    public static UsbManager k(Context context) {
        return (UsbManager) oi.d(context, "usb", "USBHandler", "getMan");
    }

    private static boolean l(String str, String[] strArr) {
        for (String str2 : strArr) {
            if (str.startsWith(str2)) {
                return true;
            }
        }
        return false;
    }

    public static int m(int i2) {
        return i[i2];
    }

    private static int n(File file) {
        String X;
        File file2 = new File(file, "bInterfaceProtocol");
        if (file2.exists() && (X = dq.X(file2)) != null) {
            Integer E3 = dq.E3(X.trim());
            if (E3 != null) {
                return E3.intValue();
            }
            r7.f("USBHandler", "bad protocol file contents " + file + ": " + X);
        }
        return -1;
    }

    public static void o(Context context, boolean z) {
        int i2 = 0;
        int i3 = 0;
        while (true) {
            com.joaomgcd.taskerm.util.c3[] c3VarArr = s;
            if (i3 >= c3VarArr.length) {
                break;
            }
            com.joaomgcd.taskerm.util.c3 c3Var = c3VarArr[i3];
            if (c3Var != null) {
                c3Var.d();
                c3VarArr[i3] = null;
            }
            i3++;
        }
        if (!z) {
            return;
        }
        while (true) {
            String[] strArr = r;
            if (i2 >= strArr.length) {
                return;
            }
            if (new File(strArr[i2]).exists()) {
                r7.f("USBHandler", "add monitor for " + strArr[i2]);
                com.joaomgcd.taskerm.util.c3[] c3VarArr2 = s;
                a aVar = new a(strArr[i2], 768, context);
                c3VarArr2[i2] = aVar;
                aVar.c();
            }
            i2++;
        }
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Intent intent = getIntent();
        String action = intent.getAction();
        if (action.equals("android.hardware.usb.action.USB_DEVICE_ATTACHED")) {
            r7.f("USBHandler", action);
            MonitorService.B9(this, intent, -1);
        } else {
            if (action.equals("android.hardware.usb.action.USB_DEVICE_DETACHED")) {
                MonitorService.B9(this, intent, -1);
                return;
            }
            r7.k("USBHandler", "unexpected action " + action);
        }
    }
}