Fix UsbDeviceManager null object reference

STORAGE_SERVICE is not ready or not available to use.
UsbDeviceManager will get null value and cause null object
reference exception. Check return value before use.

Test: No exception when start USBService
Change-Id: Icdbc532894d3ca1548f327d9f63d495baa549c68
This commit is contained in:
Eddie Hung
2018-09-26 13:30:13 +08:00
committed by Isaac Lee
parent bc5c593e2e
commit ab87b44dca

View File

@@ -539,7 +539,8 @@ public class UsbDeviceManager implements ActivityManagerInternal.ScreenObserver
// We do not show the USB notification if the primary volume supports mass storage.
// The legacy mass storage UI will be used instead.
final StorageManager storageManager = StorageManager.from(mContext);
final StorageVolume primary = storageManager.getPrimaryVolume();
final StorageVolume primary =
storageManager != null ? storageManager.getPrimaryVolume() : null;
boolean massStorageSupported = primary != null && primary.allowMassStorage();
mUseUsbNotification = !massStorageSupported && mContext.getResources().getBoolean(