Fix NPE when input device is removed during enumeration

This commit is contained in:
Cameron Gutman 2017-10-17 00:07:51 -07:00
parent 40d1436ce3
commit 780a64694d

View File

@ -151,6 +151,10 @@ public class UsbDriverService extends Service implements UsbDriverListener {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
for (int id : InputDevice.getDeviceIds()) { for (int id : InputDevice.getDeviceIds()) {
InputDevice inputDev = InputDevice.getDevice(id); InputDevice inputDev = InputDevice.getDevice(id);
if (inputDev == null) {
// Device was removed while looping
continue;
}
if (inputDev.getVendorId() == device.getVendorId() && if (inputDev.getVendorId() == device.getVendorId() &&
inputDev.getProductId() == device.getProductId()) { inputDev.getProductId() == device.getProductId()) {