From b80aee943c5f902ed09584f786a03e57b69acf89 Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Tue, 3 Jul 2018 12:42:33 -0700 Subject: [PATCH] Fix NPE when querying AmbientDisply through ExternalSeting Bug: 110403709 Test: manual Change-Id: Iee9994061c2b5c4bdd7aefe2d25a73e8ed4c9db0 --- ...ntDisplayAlwaysOnPreferenceController.java | 18 ++++++--------- .../DoubleTapScreenPreferenceController.java | 23 ++++++++++--------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java index 0593aa0256b..a3cff3da3d4 100644 --- a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java +++ b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java @@ -43,10 +43,7 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference @Override public int getAvailabilityStatus() { - if (mConfig == null) { - mConfig = new AmbientDisplayConfiguration(mContext); - } - return isAvailable(mConfig) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return isAvailable(getConfig()) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override @@ -56,7 +53,7 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference @Override public boolean isChecked() { - return mConfig.alwaysOnEnabled(MY_USER); + return getConfig().alwaysOnEnabled(MY_USER); } @Override @@ -82,15 +79,14 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference return this; } - public static boolean isAlwaysOnEnabled(AmbientDisplayConfiguration config) { - return config.alwaysOnEnabled(MY_USER); - } - public static boolean isAvailable(AmbientDisplayConfiguration config) { return config.alwaysOnAvailableForUser(MY_USER); } - public static boolean accessibilityInversionEnabled(AmbientDisplayConfiguration config) { - return config.accessibilityInversionEnabled(MY_USER); + private AmbientDisplayConfiguration getConfig() { + if (mConfig == null) { + mConfig = new AmbientDisplayConfiguration(mContext); + } + return mConfig; } } diff --git a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java index 47952291028..04bdedcccef 100644 --- a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java +++ b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java @@ -35,7 +35,6 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro private final int OFF = 0; private static final String PREF_KEY_VIDEO = "gesture_double_tap_screen_video"; - private final String mDoubleTapScreenPrefKey; private final String SECURE_KEY = DOZE_PULSE_ON_DOUBLE_TAP; @@ -46,7 +45,6 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro public DoubleTapScreenPreferenceController(Context context, String key) { super(context, key); mUserId = UserHandle.myUserId(); - mDoubleTapScreenPrefKey = key; } public DoubleTapScreenPreferenceController setConfig(AmbientDisplayConfiguration config) { @@ -67,17 +65,13 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro @Override public int getAvailabilityStatus() { - if (mAmbientConfig == null) { - mAmbientConfig = new AmbientDisplayConfiguration(mContext); - } - // No hardware support for Double Tap - if (!mAmbientConfig.doubleTapSensorAvailable()) { + if (!getAmbientConfig().doubleTapSensorAvailable()) { return UNSUPPORTED_ON_DEVICE; } // Can't change Double Tap when AOD is enabled. - if (!mAmbientConfig.ambientDisplayAvailable()) { + if (!getAmbientConfig().ambientDisplayAvailable()) { return DISABLED_DEPENDENT_SETTING; } @@ -102,11 +96,18 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro @Override public boolean isChecked() { - return mAmbientConfig.pulseOnDoubleTapEnabled(mUserId); + return getAmbientConfig().pulseOnDoubleTapEnabled(mUserId); } @Override protected boolean canHandleClicks() { - return !mAmbientConfig.alwaysOnEnabled(mUserId); + return !getAmbientConfig().alwaysOnEnabled(mUserId); } -} \ No newline at end of file + + private AmbientDisplayConfiguration getAmbientConfig() { + if (mAmbientConfig == null) { + mAmbientConfig = new AmbientDisplayConfiguration(mContext); + } + return mAmbientConfig; + } +}