From ecb58cbbc59aaa20793184f98008b11d53054cf5 Mon Sep 17 00:00:00 2001 From: Jason Chang Date: Tue, 20 Apr 2021 21:03:22 +0800 Subject: [PATCH] (2/n) Stop user from enabling OHM setting if user is using 3-button mode Return One-Handed mode getAvailabilityStatus to UNSUPPORTED_ON_DEVICE when SystemNavigationMode is 3-button. Bug: 184903678 Test: manual Test: manual verified on Settings > System > Gesture page Test: make RunSettingsRoboTests ROBOTEST_FILTER= "com.android.settings.gestures .OneHandedEnablePreferenceControllerTest" Test: make RunSettingsRoboTests ROBOTEST_FILTER= "com.android.settings.gestures .SwipeBottomToNotificationPreferenceControllerTest" Change-Id: I454dabb5cc267d544732fa5079f3146154d0568c --- .../OneHandedEnablePreferenceController.java | 6 ++--- .../gestures/OneHandedSettingsUtils.java | 22 ++++++++++++++++ ...tomToNotificationPreferenceController.java | 3 ++- ...eHandedEnablePreferenceControllerTest.java | 26 +++++++++++++++++++ ...oNotificationPreferenceControllerTest.java | 26 +++++++++++++++++++ 5 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/gestures/OneHandedEnablePreferenceController.java b/src/com/android/settings/gestures/OneHandedEnablePreferenceController.java index 75018970449..1e9c240115b 100644 --- a/src/com/android/settings/gestures/OneHandedEnablePreferenceController.java +++ b/src/com/android/settings/gestures/OneHandedEnablePreferenceController.java @@ -19,7 +19,6 @@ package com.android.settings.gestures; import android.content.Context; import com.android.settings.R; -import com.android.settings.core.BasePreferenceController; import com.android.settings.widget.SettingsMainSwitchPreferenceController; /** @@ -33,9 +32,8 @@ public class OneHandedEnablePreferenceController extends SettingsMainSwitchPrefe @Override public int getAvailabilityStatus() { - return OneHandedSettingsUtils.isSupportOneHandedMode() - ? BasePreferenceController.AVAILABLE - : BasePreferenceController.UNSUPPORTED_ON_DEVICE; + return OneHandedSettingsUtils.isFeatureAvailable(mContext) + ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override diff --git a/src/com/android/settings/gestures/OneHandedSettingsUtils.java b/src/com/android/settings/gestures/OneHandedSettingsUtils.java index 5de02dba1f1..21998a6e215 100644 --- a/src/com/android/settings/gestures/OneHandedSettingsUtils.java +++ b/src/com/android/settings/gestures/OneHandedSettingsUtils.java @@ -176,6 +176,28 @@ public class OneHandedSettingsUtils { sCurrentUserId); } + /** + * Get NavigationBar mode flag from Settings provider. + * @param context App context + * @return Navigation bar mode: + * 0 = 3 button + * 1 = 2 button + * 2 = fully gestural + */ + public static int getNavigationBarMode(Context context) { + return Settings.Secure.getIntForUser(context.getContentResolver(), + Settings.Secure.NAVIGATION_MODE, 2 /* fully gestural */, sCurrentUserId); + } + + /** + * + * @param context App context + * @return Support One-Handed mode feature or not. + */ + public static boolean isFeatureAvailable(Context context) { + return isSupportOneHandedMode() && getNavigationBarMode(context) != 0; + } + /** * Registers callback for observing Settings.Secure.ONE_HANDED_MODE_ENABLED state. * @param callback for state changes diff --git a/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceController.java b/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceController.java index 320d006ac7e..ec81482dd68 100644 --- a/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceController.java +++ b/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceController.java @@ -33,7 +33,8 @@ public class SwipeBottomToNotificationPreferenceController extends TogglePrefere @Override public int getAvailabilityStatus() { - return OneHandedSettingsUtils.isSupportOneHandedMode() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return OneHandedSettingsUtils.isFeatureAvailable(mContext) + ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override diff --git a/tests/robotests/src/com/android/settings/gestures/OneHandedEnablePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/OneHandedEnablePreferenceControllerTest.java index ac2beb351cb..e5b86880faa 100644 --- a/tests/robotests/src/com/android/settings/gestures/OneHandedEnablePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/OneHandedEnablePreferenceControllerTest.java @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.os.SystemProperties; import android.os.UserHandle; +import android.provider.Settings; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; @@ -60,6 +61,7 @@ public class OneHandedEnablePreferenceControllerTest { @Test public void getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); + setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.AVAILABLE); @@ -68,6 +70,16 @@ public class OneHandedEnablePreferenceControllerTest { @Test public void getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldUnsupported() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); + setNavigationBarMode(mContext, "2" /* fully gestural */); + + assertThat(mController.getAvailabilityStatus()) + .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); + } + + @Test + public void getAvailabilityStatus_set3ButtonModeProperty_shouldUnsupported() { + SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); + setNavigationBarMode(mContext, "0" /* 3-button */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); @@ -88,4 +100,18 @@ public class OneHandedEnablePreferenceControllerTest { assertThat(mController.getSummary()) .isEqualTo(mContext.getText(R.string.switch_off_text)); } + + /** + * Set NavigationBar mode flag to Settings provider. + * @param context App context + * @param value Navigation bar mode: + * 0 = 3 button + * 1 = 2 button + * 2 = fully gestural + * @return true if the value was set, false on database errors. + */ + private boolean setNavigationBarMode(Context context, String value) { + return Settings.Secure.putStringForUser(context.getContentResolver(), + Settings.Secure.NAVIGATION_MODE, value, UserHandle.myUserId()); + } } diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceControllerTest.java index 9f76800faa7..8f50006674c 100644 --- a/tests/robotests/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceControllerTest.java @@ -22,6 +22,7 @@ import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.os.SystemProperties; +import android.os.UserHandle; import android.provider.Settings; import com.android.settings.R; @@ -69,6 +70,7 @@ public class SwipeBottomToNotificationPreferenceControllerTest { @Test public void getAvailabilityStatus_oneHandedUnsupported_returnsUnsupport() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); + setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()).isEqualTo( BasePreferenceController.UNSUPPORTED_ON_DEVICE); @@ -77,10 +79,20 @@ public class SwipeBottomToNotificationPreferenceControllerTest { @Test public void getAvailabilityStatus_oneHandedSupported_returnsAvailable() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); + setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } + @Test + public void getAvailabilityStatus_set3ButtonModeProperty_returnsUnsupport() { + SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); + setNavigationBarMode(mContext, "0" /* 3-button */); + + assertThat(mController.getAvailabilityStatus()) + .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); + } + @Test public void getSummary_gestureEnabled_returnsOnSummary() { mController.setChecked(true); @@ -105,4 +117,18 @@ public class SwipeBottomToNotificationPreferenceControllerTest { assertThat(mController.isChecked()).isFalse(); } + + /** + * Set NavigationBar mode flag to Settings provider. + * @param context App context + * @param value Navigation bar mode: + * 0 = 3 button + * 1 = 2 button + * 2 = fully gestural + * @return true if the value was set, false on database errors. + */ + private boolean setNavigationBarMode(Context context, String value) { + return Settings.Secure.putStringForUser(context.getContentResolver(), + Settings.Secure.NAVIGATION_MODE, value, UserHandle.myUserId()); + } }