Merge "Handle the case where null is returned for USB_STATE intent."

This commit is contained in:
Yasuhiro Matsuda
2015-08-26 09:36:41 +00:00
committed by Android (Google) Code Review

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;
}
}
}