OSDN Git Service

Make WakeScreen conditionally avaialable
authorLucas Dupin <dupin@google.com>
Wed, 13 Feb 2019 21:08:09 +0000 (13:08 -0800)
committerLucas Dupin <dupin@google.com>
Wed, 13 Feb 2019 21:39:28 +0000 (13:39 -0800)
Also moving the setting closer to 'Always On'

Fixes: 124389844
Test: manual
Test: make RunSettingsRoboTests ROBOTEST_FILTER=WakeScreenGesturePreferenceController
Change-Id: Ic19e01bf4259608dc0430507fbb3ce5ebf6fa456

res/xml/security_lockscreen_settings.xml
src/com/android/settings/gestures/WakeScreenGesturePreferenceController.java
tests/robotests/src/com/android/settings/gestures/WakeScreenGesturePreferenceControllerTest.java

index c5765d3..6833922 100644 (file)
             settings:controller="com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController" />
 
         <Preference
+            android:key="ambient_display_wake_screen"
+            android:title="@string/ambient_display_wake_screen_title"
+            android:fragment="com.android.settings.gestures.WakeScreenGestureSettings"
+            settings:controller="com.android.settings.gestures.WakeScreenGesturePreferenceController" />
+
+        <Preference
             android:key="ambient_display_tap"
             android:title="@string/ambient_display_tap_screen_title"
             android:fragment="com.android.settings.gestures.TapScreenGestureSettings"
             android:fragment="com.android.settings.gestures.PickupGestureSettings"
             settings:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
 
-        <Preference
-            android:key="ambient_display_wake_screen"
-            android:title="@string/ambient_display_wake_screen_title"
-            android:fragment="com.android.settings.gestures.WakeScreenGestureSettings"
-            settings:controller="com.android.settings.gestures.WakeScreenGesturePreferenceController" />
-
         <SwitchPreference
             android:key="ambient_display_notification"
             android:title="@string/doze_title"
index a43fad1..96a3580 100644 (file)
@@ -53,7 +53,18 @@ public class WakeScreenGesturePreferenceController extends GesturePreferenceCont
                 || !mFeatureProvider.isSupported(mContext)) {
             return UNSUPPORTED_ON_DEVICE;
         }
-        return mFeatureProvider.isEnabled(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+
+        if (!mFeatureProvider.isEnabled(mContext)) {
+            return CONDITIONALLY_UNAVAILABLE;
+        }
+
+        return getAmbientConfig().alwaysOnEnabled(mUserId)
+                ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
+    }
+
+    @Override
+    protected boolean canHandleClicks() {
+        return getAmbientConfig().alwaysOnEnabled(mUserId);
     }
 
     @Override
index 6149539..ecda5fd 100644 (file)
 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.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
@@ -77,6 +79,7 @@ public class WakeScreenGesturePreferenceControllerTest {
 
     @Test
     public void getAvailabilityStatus_gestureNotSupported_UNSUPPORTED_ON_DEVICE() {
+        when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
         when(mAmbientDisplayConfiguration.wakeScreenGestureAvailable()).thenReturn(false);
         final int availabilityStatus = mController.getAvailabilityStatus();
 
@@ -85,6 +88,7 @@ public class WakeScreenGesturePreferenceControllerTest {
 
     @Test
     public void getAvailabilityStatus_gestureSupported_AVAILABLE() {
+        when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
         when(mAmbientDisplayConfiguration.wakeScreenGestureAvailable()).thenReturn(true);
         final int availabilityStatus = mController.getAvailabilityStatus();
 
@@ -92,6 +96,25 @@ public class WakeScreenGesturePreferenceControllerTest {
     }
 
     @Test
+    public void getAvailabilityStatus_gestureSupported_DISABLED_DEPENDENT_SETTING() {
+        when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(false);
+        when(mAmbientDisplayConfiguration.wakeScreenGestureAvailable()).thenReturn(true);
+        final int availabilityStatus = mController.getAvailabilityStatus();
+
+        assertThat(availabilityStatus).isEqualTo(DISABLED_DEPENDENT_SETTING);
+    }
+
+    @Test
+    public void canHandleClicks_onlyWhenAlwaysOn() {
+        when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(false);
+        assertThat(mController.canHandleClicks()).isEqualTo(false);
+
+        reset(mAmbientDisplayConfiguration);
+        when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
+        assertThat(mController.canHandleClicks()).isEqualTo(true);
+    }
+
+    @Test
     public void isSliceableCorrectKey_returnsTrue() {
         final WakeScreenGesturePreferenceController controller =
                 new WakeScreenGesturePreferenceController(mContext, "gesture_wake_screen");