From a31fd420292a12cb7ca14d7518cc6b7d3ca2c296 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Mon, 24 Oct 2022 07:03:21 +0000 Subject: [PATCH] Fix possible NPE in StorageNotification. Because findRecordByUuid() can return null, add a null check to avoid NPE. StorageNotification: Notifying about private volume: VolumeInfo{private}: StorageNotification: type=PRIVATE diskId=null partGuid=null mountFlags=0 mountUserId=-10000 StorageNotification: state=MOUNTED StorageNotification: fsType=null fsUuid=null fsLabel=null StorageNotification: path=/data internalPath=null AndroidRuntime: FATAL EXCEPTION: main AndroidRuntime: Process: com.android.systemui, PID: 5952 AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.storage.VolumeRecord.isSnoozed()' on a null object reference AndroidRuntime: at com.android.systemui.usb.StorageNotification.onVolumeStateChangedInternal(StorageNotification.java:337) AndroidRuntime: at com.android.systemui.usb.StorageNotification.start(StorageNotification.java:114) Bug: 253408750 Test: build, boot Signed-off-by: Jimmy Hu Change-Id: I8859d4d578ca040771bef9cf9870f91fb8d29628 --- .../src/com/android/systemui/usb/StorageNotification.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java index bf706735d5313..3507cb7c40a42 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java +++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java @@ -381,7 +381,7 @@ public class StorageNotification implements CoreStartable { // Don't annoy when user dismissed in past. (But make sure the disk is adoptable; we // used to allow snoozing non-adoptable disks too.) - if (rec.isSnoozed() && disk.isAdoptable()) { + if (rec == null || (rec.isSnoozed() && disk.isAdoptable())) { return null; } if (disk.isAdoptable() && !rec.isInited() && rec.getType() != VolumeInfo.TYPE_PUBLIC