Check for a null UsbManager object

Apparently this can happen on some (broken?) devices
This commit is contained in:
Cameron Gutman
2023-10-12 00:22:28 -05:00
parent 0168a55596
commit 9915007f30
2 changed files with 10 additions and 8 deletions

View File

@@ -365,13 +365,15 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
// Count all USB devices that match our drivers
if (PreferenceConfiguration.readPreferences(context).usbDriver) {
UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
for (UsbDevice dev : usbManager.getDeviceList().values()) {
// We explicitly check not to claim devices that appear as InputDevices
// otherwise we will double count them.
if (UsbDriverService.shouldClaimDevice(dev, false) &&
!UsbDriverService.isRecognizedInputDevice(dev)) {
LimeLog.info("Counting UsbDevice: "+dev.getDeviceName());
mask |= 1 << count++;
if (usbManager != null) {
for (UsbDevice dev : usbManager.getDeviceList().values()) {
// We explicitly check not to claim devices that appear as InputDevices
// otherwise we will double count them.
if (UsbDriverService.shouldClaimDevice(dev, false) &&
!UsbDriverService.isRecognizedInputDevice(dev)) {
LimeLog.info("Counting UsbDevice: "+dev.getDeviceName());
mask |= 1 << count++;
}
}
}
}

View File

@@ -287,7 +287,7 @@ public class UsbDriverService extends Service implements UsbDriverListener {
}
private void start() {
if (started) {
if (started || usbManager == null) {
return;
}