From 46f40517beaeeb81bd145393dad68108a9e239ca Mon Sep 17 00:00:00 2001 From: Matthew Fritze Date: Thu, 17 May 2018 11:27:46 -0700 Subject: [PATCH] Fix availability status for AOD gestures Double tap screen to wake and lift to check phone are dependent on AOD - and should return DISABLED DEPENDENT SETTING when AOD is turned on. Test: robotests Change-Id: Ib3f40c38bb210d0f512736746dc45a1b844c6bee Merged-In: Ib246070ee853185459628b2584ddbae72e15a2f8 Fixes: 79779562 --- .../DoubleTapScreenPreferenceController.java | 14 ++++++- .../PickupGesturePreferenceController.java | 14 ++++++- .../DoubleTapScreenPreferenceControllerTest.java | 45 +++++++++++++++------- .../PickupGesturePreferenceControllerTest.java | 45 +++++++++++++++------- 4 files changed, 88 insertions(+), 30 deletions(-) diff --git a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java index 94ef97859a..4dd483a4fe 100644 --- a/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java +++ b/src/com/android/settings/gestures/DoubleTapScreenPreferenceController.java @@ -24,6 +24,7 @@ import android.os.UserHandle; import android.provider.Settings; import android.support.v7.preference.Preference; import android.support.annotation.VisibleForTesting; +import android.text.TextUtils; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.settings.R; @@ -74,7 +75,18 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro if (mAmbientConfig == null) { mAmbientConfig = new AmbientDisplayConfiguration(mContext); } - return mAmbientConfig.pulseOnDoubleTapAvailable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + + // No hardware support for Double Tap + if (!mAmbientConfig.doubleTapSensorAvailable()) { + return UNSUPPORTED_ON_DEVICE; + } + + // Can't change Double Tap when AOD is enabled. + if (!mAmbientConfig.ambientDisplayAvailable()) { + return DISABLED_DEPENDENT_SETTING; + } + + return AVAILABLE; } @Override diff --git a/src/com/android/settings/gestures/PickupGesturePreferenceController.java b/src/com/android/settings/gestures/PickupGesturePreferenceController.java index d50df19e52..d0f247ec14 100644 --- a/src/com/android/settings/gestures/PickupGesturePreferenceController.java +++ b/src/com/android/settings/gestures/PickupGesturePreferenceController.java @@ -25,6 +25,7 @@ import android.content.SharedPreferences; import android.os.UserHandle; import android.provider.Settings; import android.support.annotation.VisibleForTesting; +import android.text.TextUtils; import com.android.internal.hardware.AmbientDisplayConfiguration; import com.android.settings.R; @@ -68,7 +69,18 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll if (mAmbientConfig == null) { mAmbientConfig = new AmbientDisplayConfiguration(mContext); } - return mAmbientConfig.pulseOnPickupAvailable() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + + // No hardware support for Pickup Gesture + if (!mAmbientConfig.dozePulsePickupSensorAvailable()) { + return UNSUPPORTED_ON_DEVICE; + } + + // Can't change Pickup Gesture when AOD is enabled. + if (!mAmbientConfig.ambientDisplayAvailable()) { + return DISABLED_DEPENDENT_SETTING; + } + + return AVAILABLE; } @Override diff --git a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java index cc9347ddff..63a1027615 100644 --- a/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/DoubleTapScreenPreferenceControllerTest.java @@ -16,6 +16,10 @@ package com.android.settings.gestures; +import static com.android.settings.core.BasePreferenceController.AVAILABLE; +import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING; +import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.when; @@ -61,20 +65,6 @@ public class DoubleTapScreenPreferenceControllerTest { } @Test - public void isAvailable_configIsTrue_shouldReturnTrue() { - when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(true); - - assertThat(mController.isAvailable()).isTrue(); - } - - @Test - public void isAvailable_configIsFalse_shouldReturnFalse() { - when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(false); - - assertThat(mController.isAvailable()).isFalse(); - } - - @Test public void testIsChecked_configIsSet_shouldReturnTrue() { // Set the setting to be enabled. when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(true); @@ -162,4 +152,31 @@ public class DoubleTapScreenPreferenceControllerTest { when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(false); assertThat(mController.canHandleClicks()).isTrue(); } + + @Test + public void getAvailabilityStatus_aodNotSupported_UNSUPPORTED_ON_DEVICE() { + when(mAmbientDisplayConfiguration.doubleTapSensorAvailable()).thenReturn(false); + when(mAmbientDisplayConfiguration.ambientDisplayAvailable()).thenReturn(false); + final int availabilityStatus = mController.getAvailabilityStatus(); + + assertThat(availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE); + } + + @Test + public void getAvailabilityStatus_aodOn_DISABLED_DEPENDENT_SETTING() { + when(mAmbientDisplayConfiguration.doubleTapSensorAvailable()).thenReturn(true); + when(mAmbientDisplayConfiguration.ambientDisplayAvailable()).thenReturn(false); + final int availabilityStatus = mController.getAvailabilityStatus(); + + assertThat(availabilityStatus).isEqualTo(DISABLED_DEPENDENT_SETTING); + } + + @Test + public void getAvailabilityStatus_aodSupported_aodOff_AVAILABLE() { + when(mAmbientDisplayConfiguration.doubleTapSensorAvailable()).thenReturn(true); + when(mAmbientDisplayConfiguration.ambientDisplayAvailable()).thenReturn(true); + final int availabilityStatus = mController.getAvailabilityStatus(); + + assertThat(availabilityStatus).isEqualTo(AVAILABLE); + } } diff --git a/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java index 6aa451ce12..98c32ad9ba 100644 --- a/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/PickupGesturePreferenceControllerTest.java @@ -16,6 +16,10 @@ package com.android.settings.gestures; +import static com.android.settings.core.BasePreferenceController.AVAILABLE; +import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING; +import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.doReturn; @@ -62,20 +66,6 @@ public class PickupGesturePreferenceControllerTest { } @Test - public void isAvailable_configIsTrue_shouldReturnTrue() { - when(mAmbientDisplayConfiguration.pulseOnPickupAvailable()).thenReturn(true); - - assertThat(mController.isAvailable()).isTrue(); - } - - @Test - public void isAvailable_configIsFalse_shouldReturnFalse() { - when(mAmbientDisplayConfiguration.pulseOnPickupAvailable()).thenReturn(false); - - assertThat(mController.isAvailable()).isFalse(); - } - - @Test public void testIsChecked_configIsSet_shouldReturnTrue() { // Set the setting to be enabled. when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(true); @@ -153,4 +143,31 @@ public class PickupGesturePreferenceControllerTest { assertThat(PickupGesturePreferenceController.isSuggestionComplete(mContext, prefs)) .isTrue(); } + + @Test + public void getAvailabilityStatus_aodNotSupported_UNSUPPORTED_ON_DEVICE() { + when(mAmbientDisplayConfiguration.dozePulsePickupSensorAvailable()).thenReturn(false); + when(mAmbientDisplayConfiguration.ambientDisplayAvailable()).thenReturn(false); + final int availabilityStatus = mController.getAvailabilityStatus(); + + assertThat(availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE); + } + + @Test + public void getAvailabilityStatus_aodOn_DISABLED_DEPENDENT_SETTING() { + when(mAmbientDisplayConfiguration.dozePulsePickupSensorAvailable()).thenReturn(true); + when(mAmbientDisplayConfiguration.ambientDisplayAvailable()).thenReturn(false); + final int availabilityStatus = mController.getAvailabilityStatus(); + + assertThat(availabilityStatus).isEqualTo(DISABLED_DEPENDENT_SETTING); + } + + @Test + public void getAvailabilityStatus_aodSupported_aodOff_AVAILABLE() { + when(mAmbientDisplayConfiguration.dozePulsePickupSensorAvailable()).thenReturn(true); + when(mAmbientDisplayConfiguration.ambientDisplayAvailable()).thenReturn(true); + final int availabilityStatus = mController.getAvailabilityStatus(); + + assertThat(availabilityStatus).isEqualTo(AVAILABLE); + } } -- 2.11.0