From 509670cb0d3d67a2eb807e228334f251b3dbded1 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Wed, 18 Aug 2021 00:22:22 +0000 Subject: [PATCH] LPP will now always launch either GlobalActions or the Assistant. Previously, on devices that default to launching Assistant on long-press power, toggling this checkbox in Settings would switch between that default (launching Assistant) and a no-op. Those devices now toggle between Assistant and GlobalActions (the power menu), just like devices that have the old default behavior of LPP launching GlobalActions. Change-Id: Id36031e70825da195f9c30ce05b3ae3d5e49b5fb Test: make RunSettingsRoboTests \ ROBOTEST_FILTER=LongPressPowerButtonPreferenceControllerTest Bug: 192946325 --- .../LongPressPowerButtonPreferenceController.java | 10 ++++++---- .../LongPressPowerButtonPreferenceControllerTest.java | 9 ++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/gestures/LongPressPowerButtonPreferenceController.java b/src/com/android/settings/gestures/LongPressPowerButtonPreferenceController.java index 3e9c80fecce..a52be15f62e 100644 --- a/src/com/android/settings/gestures/LongPressPowerButtonPreferenceController.java +++ b/src/com/android/settings/gestures/LongPressPowerButtonPreferenceController.java @@ -179,16 +179,18 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo POWER_BUTTON_LONG_PRESS_SETTING, LONG_PRESS_POWER_ASSISTANT_VALUE); } - // We need to determine the right disabled value - we set it to device default - // if it's different than Assist, otherwise we fallback to either global actions or power - // menu. + // We need to determine the right disabled value based on the device default + // for long-press power. + + // If the default is to start the assistant, then the fallback is GlobalActions. final int defaultPowerButtonValue = mContext.getResources().getInteger( POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE); if (defaultPowerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) { return Settings.Global.putInt(mContext.getContentResolver(), - POWER_BUTTON_LONG_PRESS_SETTING, LONG_PRESS_POWER_NO_ACTION); + POWER_BUTTON_LONG_PRESS_SETTING, LONG_PRESS_POWER_GLOBAL_ACTIONS); } + // If the default is something different than Assist, we use that default. return Settings.Global.putInt(mContext.getContentResolver(), POWER_BUTTON_LONG_PRESS_SETTING, defaultPowerButtonValue); } diff --git a/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java index 053fa5a12d7..8ff50abff8f 100644 --- a/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/gestures/LongPressPowerButtonPreferenceControllerTest.java @@ -199,7 +199,7 @@ public class LongPressPowerButtonPreferenceControllerTest { @Test public void preferenceUnchecked_assistDefault_setNoAction() { - // Value out of range chosen deliberately. + // Ensure that the Assistant is the default behavior for LPP. when(mResources.getInteger( com.android.internal.R.integer.config_longPressOnPowerBehavior)) .thenReturn( @@ -209,13 +209,12 @@ public class LongPressPowerButtonPreferenceControllerTest { assertThat(Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo( - LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_NO_ACTION); + LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS); assertThat(Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo( LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION); - verify(mController.mAssistSwitch).setSummary( - getString( - R.string.power_menu_summary_long_press_for_assist_disabled_no_action)); + verify(mController.mAssistSwitch).setSummary(getString( + R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu)); } private String getString(@StringRes int id) {