Handle the case where null is returned for USB_STATE intent.

USB_STATE is not received if USB_STATE has not changed from
the initial state. This CL adds handling for that case.

BUG: 22163689
Change-Id: I232a558caaac4f4984f7629e2574d478fc7ad432
This commit is contained in:
Yasuhiro Matsuda
2015-08-07 17:49:54 +09:00
parent 2eec566259
commit acb7b31bff

View File

@@ -47,7 +47,8 @@ public class UsbBackend {
public UsbBackend(Context context) {
Intent intent = context.registerReceiver(null,
new IntentFilter(UsbManager.ACTION_USB_STATE));
mIsUnlocked = intent.getBooleanExtra(UsbManager.USB_DATA_UNLOCKED, false);
mIsUnlocked = intent == null ?
false : intent.getBooleanExtra(UsbManager.USB_DATA_UNLOCKED, false);
mUserManager = UserManager.get(context);
mUsbManager = context.getSystemService(UsbManager.class);
@@ -151,4 +152,4 @@ public class UsbBackend {
// No port, support sink modes only.
return (mode & MODE_POWER_MASK) != MODE_POWER_SOURCE;
}
}
}