Fix potential NPE in NotificationRecord's KeyguardManager call

Fix: 288118117
Test: manual
Change-Id: I42396c914ee38f00dd122492ba332c095bbfd817
This commit is contained in:
Abhijoy Saha
2023-06-23 14:32:55 -07:00
parent c163059eb9
commit c1b21100e8

View File

@@ -103,7 +103,7 @@ public final class NotificationRecord {
final int mTargetSdkVersion;
final int mOriginalFlags;
private final Context mContext;
private final KeyguardManager mKeyguardManager;
private KeyguardManager mKeyguardManager;
private final PowerManager mPowerManager;
NotificationUsageStats.SingleNotificationStats stats;
boolean isCanceled;
@@ -1625,10 +1625,21 @@ public final class NotificationRecord {
}
boolean isLocked() {
return mKeyguardManager.isKeyguardLocked()
return getKeyguardManager().isKeyguardLocked()
|| !mPowerManager.isInteractive(); // Unlocked AOD
}
/**
* For some early {@link NotificationRecord}, {@link KeyguardManager} can be {@code null} in
* the constructor. Retrieve it again if it is null.
*/
private KeyguardManager getKeyguardManager() {
if (mKeyguardManager == null) {
mKeyguardManager = mContext.getSystemService(KeyguardManager.class);
}
return mKeyguardManager;
}
@VisibleForTesting
static final class Light {
public final int color;