From d7d1e8063aa692e09850a4b79f4903048b3380cc Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Mon, 9 Jul 2018 16:45:22 -0700 Subject: [PATCH] Fix NPE when querying AmbientDisply through ExternalSeting Bug: 110403709 Test: manual Change-Id: I5c037b010e296cbd011f8c141932e6befd341c99 --- ...playNotificationsPreferenceController.java | 16 ++++++++++----- .../PickupGesturePreferenceController.java | 20 +++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java b/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java index cae56715107..b3c182252f7 100644 --- a/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java +++ b/src/com/android/settings/display/AmbientDisplayNotificationsPreferenceController.java @@ -68,7 +68,7 @@ public class AmbientDisplayNotificationsPreferenceController extends @Override public boolean isChecked() { - return mConfig.pulseOnNotificationEnabled(MY_USER); + return getAmbientConfig().pulseOnNotificationEnabled(MY_USER); } @Override @@ -79,14 +79,20 @@ public class AmbientDisplayNotificationsPreferenceController extends @Override public int getAvailabilityStatus() { - if (mConfig == null) { - mConfig = new AmbientDisplayConfiguration(mContext); - } - return mConfig.pulseOnNotificationAvailable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return getAmbientConfig().pulseOnNotificationAvailable() + ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override public boolean isSliceable() { return TextUtils.equals(getPreferenceKey(), "ambient_display_notification"); } + + private AmbientDisplayConfiguration getAmbientConfig() { + if (mConfig == null) { + mConfig = new AmbientDisplayConfiguration(mContext); + } + + return mConfig; + } } diff --git a/src/com/android/settings/gestures/PickupGesturePreferenceController.java b/src/com/android/settings/gestures/PickupGesturePreferenceController.java index 430361c1707..53a4447cbe0 100644 --- a/src/com/android/settings/gestures/PickupGesturePreferenceController.java +++ b/src/com/android/settings/gestures/PickupGesturePreferenceController.java @@ -62,17 +62,13 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll @Override public int getAvailabilityStatus() { - if (mAmbientConfig == null) { - mAmbientConfig = new AmbientDisplayConfiguration(mContext); - } - // No hardware support for Pickup Gesture - if (!mAmbientConfig.dozePulsePickupSensorAvailable()) { + if (!getAmbientConfig().dozePulsePickupSensorAvailable()) { return UNSUPPORTED_ON_DEVICE; } // Can't change Pickup Gesture when AOD is enabled. - if (!mAmbientConfig.ambientDisplayAvailable()) { + if (!getAmbientConfig().ambientDisplayAvailable()) { return DISABLED_DEPENDENT_SETTING; } @@ -91,7 +87,7 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll @Override public boolean isChecked() { - return mAmbientConfig.pulseOnPickupEnabled(mUserId); + return getAmbientConfig().pulseOnPickupEnabled(mUserId); } @Override @@ -112,6 +108,14 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll @VisibleForTesting boolean pulseOnPickupCanBeModified() { - return mAmbientConfig.pulseOnPickupCanBeModified(mUserId); + return getAmbientConfig().pulseOnPickupCanBeModified(mUserId); + } + + private AmbientDisplayConfiguration getAmbientConfig() { + if (mAmbientConfig == null) { + mAmbientConfig = new AmbientDisplayConfiguration(mContext); + } + + return mAmbientConfig; } }