【问题标题】:UsbDevice getProductId & getVendorID Android 5.1UsbDevice getProductId & getVendorID Android 5.1
【发布时间】:2017-01-27 16:18:26
【问题描述】:

我有一个与 USB 闪存驱动器交互的 Android 应用。它被过滤为仅适用于我公司的 USB 驱动器,并按 PID/VID 过滤它们。我通过使用 Android UsbDevice 方法 getProductId() 和 getVendorId() 获取 PID/VID。

一个示例组合是 PID:1812 VID:7055 (Hex-PID:0714 VID:1B8F)

我有一个正在测试的 Galaxy Note 4 设备,它为具有 PID:1812 VID:7055 的闪存驱动器返回 PID:37028 和 VID:1748。

我已经在其他几款使用同一个 USB 驱动器的移动设备上进行了测试,包括几部三星 Galaxy 手机。我以前从未遇到过这个问题,我不知道为什么这个特定的设备会返回这个值。任何人都可以在这里提供任何见解吗?

--更新--

我现在在 Droid Turbo 上得到了相同的行为。这两款设备都运行 Android 5.1.1,但仍然无法解释错误的 PID/VID。

【问题讨论】:

标签: java android usb galaxy


【解决方案1】:

getVendorID()getProductID() 的源代码在https://android.googlesource.com/platform/frameworks/base/+/c6f23e8521dedac7a07119031913235be3ca37c3/core/java/android/hardware/usb/UsbDevice.java 中,它使用本机 C 代码 (JNI) 从内核模块(usb_storage 用于大容量存储)或 USB 主机控制器获取数据

原生函数:

private native boolean native_open(String deviceName, FileDescriptor pfd);
private native void native_close();
private native int native_get_fd();
private native boolean native_claim_interface(int interfaceID, boolean force);
private native boolean native_release_interface(int interfaceID);
private native int native_control_request(int requestType, int request, int value,
        int index, byte[] buffer, int length, int timeout);
private native int native_bulk_request(int endpoint, byte[] buffer, int length, int timeout);
private native UsbRequest native_request_wait();
private native String native_get_serial();
private static native int native_get_device_id(String name);
private static native String native_get_device_name(int id); 

也许这是在 Galaxy Note 4 硬件上实现的有点错误

如果它总是返回 same VID 和 PID,你只有一个小问题/没问题...

【讨论】:

    猜你喜欢
    • 2013-07-23
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    相关资源
    最近更新 更多