导航菜单

页面标题

页面副标题

六分钟步行测试管理软件 v1.1.0.2112120029 - UsbIntentReceiverKt.java 源代码

正在查看: 六分钟步行测试管理软件 v1.1.0.2112120029 应用的 UsbIntentReceiverKt.java JAVA 源代码文件

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


package cn.neoprint.padmonitor.app;

import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbManager;
import android.os.Build;
import cn.neoprint.padmonitor.R;
import cn.neoprint.padmonitor.extendfun.ToastExtKt;
import com.github.mjdev.libaums.UsbMassStorageDevice;
import com.github.mjdev.libaums.fs.FileSystem;
import com.github.mjdev.libaums.fs.UsbFile;
import com.github.mjdev.libaums.partition.Partition;
import com.sayeasytech.base.log.KLog;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;

@Metadata(d1 = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\u0018\u0000 \u00102\u00020\u0001:\u0001\u0010B\u0005¢\u0006\u0002\u0010\u0002J\n\u0010\u0005\u001a\u0004\u0018\u00010\u0006H\u0002J\u0018\u0010\u0007\u001a\u00020\b2\u0006\u0010\t\u001a\u00020\n2\u0006\u0010\u000b\u001a\u00020\fH\u0016J\u0010\u0010\r\u001a\u00020\b2\u0006\u0010\u000e\u001a\u00020\u0006H\u0002J\u0010\u0010\u000f\u001a\u00020\b2\u0006\u0010\t\u001a\u00020\nH\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082D¢\u0006\u0002\n\u0000¨\u0006\u0011"}, d2 = {"Lcn/neoprint/padmonitor/app/UsbIntentReceiverKt;", "Landroid/content/BroadcastReceiver;", "()V", "TAG", "", "getTopUsb", "Lcom/github/mjdev/libaums/UsbMassStorageDevice;", "onReceive", "", "context", "Landroid/content/Context;", "intent", "Landroid/content/Intent;", "prepareDevice", "device", "readUsbDeviceList", "Companion", "app_release"}, k = 1, mv = {1, 7, 1}, xi = 48)
public final class UsbIntentReceiverKt extends BroadcastReceiver {
    private static final String ACTION_USB_PERMISSION = "com.sayeasytech.base.USB_PERMISSION";

    public static final Companion INSTANCE = new Companion(null);
    private static UsbMassStorageDevice[] mStorageDevices;
    public static UsbFile mUsbPath;
    private final String TAG = "UsbIntentReceiver";

    @Metadata(d1 = {"\u0000$\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u0011\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0000\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R$\u0010\u0005\u001a\n\u0012\u0004\u0012\u00020\u0007\u0018\u00010\u0006X\u0086\u000e¢\u0006\u0010\n\u0002\u0010\f\u001a\u0004\b\b\u0010\t\"\u0004\b\n\u0010\u000bR\u0014\u0010\r\u001a\u0004\u0018\u00010\u000e8\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000¨\u0006\u000f"}, d2 = {"Lcn/neoprint/padmonitor/app/UsbIntentReceiverKt$Companion;", "", "()V", "ACTION_USB_PERMISSION", "", "mStorageDevices", "", "Lcom/github/mjdev/libaums/UsbMassStorageDevice;", "getMStorageDevices", "()[Lcom/github/mjdev/libaums/UsbMassStorageDevice;", "setMStorageDevices", "([Lcom/github/mjdev/libaums/UsbMassStorageDevice;)V", "[Lcom/github/mjdev/libaums/UsbMassStorageDevice;", "mUsbPath", "Lcom/github/mjdev/libaums/fs/UsbFile;", "app_release"}, k = 1, mv = {1, 7, 1}, xi = 48)
    public static final class Companion {
        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }

        public final UsbMassStorageDevice[] getMStorageDevices() {
            return UsbIntentReceiverKt.mStorageDevices;
        }

        public final void setMStorageDevices(UsbMassStorageDevice[] usbMassStorageDeviceArr) {
            UsbIntentReceiverKt.mStorageDevices = usbMassStorageDeviceArr;
        }
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Intrinsics.checkNotNullParameter(context, "context");
        Intrinsics.checkNotNullParameter(intent, "intent");
        String action = intent.getAction();
        if (action != null) {
            int hashCode = action.hashCode();
            if (hashCode == -2114103349) {
                if (action.equals("android.hardware.usb.action.USB_DEVICE_ATTACHED")) {
                    KLog.d(this.TAG, "USB device attached");
                    readUsbDeviceList(context);
                    return;
                }
                return;
            }
            if (hashCode == -1608292967) {
                if (action.equals("android.hardware.usb.action.USB_DEVICE_DETACHED")) {
                    KLog.d(this.TAG, "USB device detached");
                    mUsbPath = null;
                    return;
                }
                return;
            }
            if (hashCode == -396591121 && action.equals(ACTION_USB_PERMISSION)) {
                KLog.d(this.TAG, "got USB device permission");
                UsbMassStorageDevice topUsb = getTopUsb();
                if (topUsb != null) {
                    prepareDevice(topUsb);
                }
            }
        }
    }

    private final void readUsbDeviceList(Context context) {
        PendingIntent broadcast;
        UsbMassStorageDevice[] massStorageDevices = UsbMassStorageDevice.Companion.getMassStorageDevices(context);
        mStorageDevices = massStorageDevices;
        boolean z = true;
        if (massStorageDevices != null) {
            if (!(massStorageDevices.length == 0)) {
                z = false;
            }
        }
        if (z) {
            return;
        }
        String str = this.TAG;
        StringBuilder append = new StringBuilder().append("readUsbDeviceList, mStorageDevices.length=");
        UsbMassStorageDevice[] usbMassStorageDeviceArr = mStorageDevices;
        Intrinsics.checkNotNull(usbMassStorageDeviceArr);
        KLog.i(str, append.append(usbMassStorageDeviceArr.length).toString());
        Object systemService = context.getSystemService("usb");
        Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.hardware.usb.UsbManager");
        UsbManager usbManager = (UsbManager) systemService;
        Intent intent = new Intent(ACTION_USB_PERMISSION);
        intent.setPackage(context.getPackageName());
        if (Build.VERSION.SDK_INT >= 31) {
            broadcast = PendingIntent.getBroadcast(context, 0, intent, 67108864);
            Intrinsics.checkNotNullExpressionValue(broadcast, "{\n            PendingInt…FLAG_IMMUTABLE)\n        }");
        } else {
            broadcast = PendingIntent.getBroadcast(context, 0, intent, 134217728);
            Intrinsics.checkNotNullExpressionValue(broadcast, "{\n            //PendingI…T\n            )\n        }");
        }
        UsbMassStorageDevice[] usbMassStorageDeviceArr2 = mStorageDevices;
        Intrinsics.checkNotNull(usbMassStorageDeviceArr2);
        for (UsbMassStorageDevice usbMassStorageDevice : usbMassStorageDeviceArr2) {
            if (usbManager.hasPermission(usbMassStorageDevice.getUsbDevice())) {
                KLog.i(this.TAG, "已经获取到Usb访问权限,直接读取设备");
                prepareDevice(usbMassStorageDevice);
            } else {
                KLog.e("申请权限:" + usbMassStorageDevice.getUsbDevice().getDeviceName());
                usbManager.requestPermission(usbMassStorageDevice.getUsbDevice(), broadcast);
            }
        }
    }

    private final UsbMassStorageDevice getTopUsb() {
        UsbMassStorageDevice[] usbMassStorageDeviceArr = mStorageDevices;
        boolean z = true;
        if (usbMassStorageDeviceArr != null) {
            if (!(usbMassStorageDeviceArr.length == 0)) {
                z = false;
            }
        }
        if (z) {
            return null;
        }
        Intrinsics.checkNotNull(usbMassStorageDeviceArr);
        return usbMassStorageDeviceArr[0];
    }

    private final void prepareDevice(UsbMassStorageDevice device) {
        try {
            mUsbPath = null;
            device.init();
            Partition partition = (Partition) device.getPartitions().get(0);
            KLog.i(this.TAG, "partion=" + partition);
            FileSystem fileSystem = partition.getFileSystem();
            KLog.d(this.TAG, "Capacity: " + fileSystem.getCapacity());
            KLog.d(this.TAG, "Occupied Space: " + fileSystem.getOccupiedSpace());
            KLog.d(this.TAG, "Free Space: " + fileSystem.getFreeSpace());
            KLog.d(this.TAG, "Chunk size: " + fileSystem.getChunkSize());
            mUsbPath = fileSystem.getRootDirectory();
            ToastExtKt.showToast$default(AppKt.INSTANCE.getContext(), R.string.usb_storage_is_ready, 0, 2, (Object) null);
        } catch (Exception e) {
            KLog.e(this.TAG, "read usb device error.:" + e);
            ToastExtKt.showToast$default(AppKt.INSTANCE.getContext(), R.string.can_not_get_usb_storage_info, 0, 2, (Object) null);
        }
    }
}