Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 386dda70 authored by Riley Jones's avatar Riley Jones Committed by Android (Google) Code Review
Browse files

Merge "Adjust edit shortcuts page to display button & gesture" into main

parents 58e38224 1e80db4e
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.Activity.RESULT_CANCELED;
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE;
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
import static android.provider.Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED;
import static android.provider.Settings.Secure.ACCESSIBILITY_GESTURE_TARGETS;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED;
import static android.provider.Settings.Secure.ACCESSIBILITY_QS_TARGETS;
import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
@@ -93,7 +94,8 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment {
            Settings.Secure.getUriFor(ACCESSIBILITY_BUTTON_MODE);
    private static final Uri BUTTON_SHORTCUT_SETTING =
            Settings.Secure.getUriFor(ACCESSIBILITY_BUTTON_TARGETS);

    private static final Uri GESTURE_SHORTCUT_SETTING =
            Settings.Secure.getUriFor(ACCESSIBILITY_GESTURE_TARGETS);
    private static final Uri TRIPLE_TAP_SHORTCUT_SETTING =
            Settings.Secure.getUriFor(ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
    private static final Uri TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING =
@@ -107,6 +109,7 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment {
            VOLUME_KEYS_SHORTCUT_SETTING,
            BUTTON_SHORTCUT_MODE_SETTING,
            BUTTON_SHORTCUT_SETTING,
            GESTURE_SHORTCUT_SETTING,
            TRIPLE_TAP_SHORTCUT_SETTING,
            TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING,
            QUICK_SETTINGS_SHORTCUT_SETTING,
@@ -173,6 +176,8 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment {
                } else if (BUTTON_SHORTCUT_MODE_SETTING.equals(uri)
                        || BUTTON_SHORTCUT_SETTING.equals(uri)) {
                    refreshSoftwareShortcutControllers();
                } else if (GESTURE_SHORTCUT_SETTING.equals(uri)) {
                    refreshPreferenceController(GestureShortcutOptionController.class);
                } else if (TRIPLE_TAP_SHORTCUT_SETTING.equals(uri)) {
                    refreshPreferenceController(TripleTapShortcutOptionController.class);
                } else if (TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING.equals(uri)) {
+8 −1
Original line number Diff line number Diff line
@@ -50,8 +50,15 @@ public class FloatingButtonShortcutOptionController

    @Override
    protected boolean isShortcutAvailable() {
        if (android.provider.Flags.a11yStandaloneGestureEnabled()) {
            // FAB should be available when in gesture navigation mode,
            // or if we're in the FAB button mode while in navbar navigation mode.
            return AccessibilityUtil.isGestureNavigateEnabled(mContext)
                    || AccessibilityUtil.isFloatingMenuEnabled(mContext);
        } else {
            return AccessibilityUtil.isFloatingMenuEnabled(mContext);
        }
    }

    @Nullable
    @Override
+18 −6
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.accessibility.shortcuts;

import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.GESTURE;

import android.content.Context;
import android.text.SpannableStringBuilder;

@@ -51,11 +53,22 @@ public class GestureShortcutOptionController extends SoftwareShortcutOptionPrefe
        }
    }

    @Override
    protected int getShortcutType() {
        return android.provider.Flags.a11yStandaloneGestureEnabled()
                ? GESTURE : super.getShortcutType();
    }

    @Override
    protected boolean isShortcutAvailable() {
        if (android.provider.Flags.a11yStandaloneGestureEnabled()) {
            return !isInSetupWizard()
                && !AccessibilityUtil.isFloatingMenuEnabled(mContext)
                    && AccessibilityUtil.isGestureNavigateEnabled(mContext);
        } else {
            return !isInSetupWizard()
                    && AccessibilityUtil.isGestureNavigateEnabled(mContext)
                    && !AccessibilityUtil.isFloatingMenuEnabled(mContext);
        }
    }

    @Override
@@ -68,9 +81,8 @@ public class GestureShortcutOptionController extends SoftwareShortcutOptionPrefe

        final SpannableStringBuilder sb = new SpannableStringBuilder();
        sb.append(instruction);
        if (!isInSetupWizard()) {
            sb.append("\n\n");
            sb.append(getCustomizeAccessibilityButtonLink());
        if (!isInSetupWizard() && !android.provider.Flags.a11yStandaloneGestureEnabled()) {
            sb.append("\n\n").append(getCustomizeAccessibilityButtonLink());
        }

        return sb;
+24 −13
Original line number Diff line number Diff line
@@ -16,37 +16,46 @@

package com.android.settings.accessibility.shortcuts;

import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_GESTURE;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.spy;

import android.content.ComponentName;
import android.content.Context;
import android.provider.Settings;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Flags;

import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;

import com.android.settings.R;
import com.android.settings.testutils.AccessibilityTestUtils;
import com.android.settings.testutils.shadow.SettingsShadowResources;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.util.Set;

/**
 * Tests for {@link FloatingButtonShortcutOptionController}
 */
@Config(shadows = SettingsShadowResources.class)
@RunWith(RobolectricTestRunner.class)
public class FloatingButtonShortcutOptionControllerTest {
    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    private static final String PREF_KEY = "prefKey";
    private static final String TARGET =
            new ComponentName("FakePackage", "FakeClass").flattenToString();
    private final Context mContext = ApplicationProvider.getApplicationContext();
    private final Context mContext = spy(ApplicationProvider.getApplicationContext());
    private FloatingButtonShortcutOptionController mController;
    private ShortcutOptionPreference mShortcutOptionPreference;

@@ -61,7 +70,6 @@ public class FloatingButtonShortcutOptionControllerTest {
        mShortcutOptionPreference.setKey(PREF_KEY);
        mPreferenceScreen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
        mPreferenceScreen.addPreference(mShortcutOptionPreference);
        setFloatingButtonEnabled(true);
    }

    @Test
@@ -95,23 +103,26 @@ public class FloatingButtonShortcutOptionControllerTest {

    @Test
    public void isShortcutAvailable_floatingMenuEnabled_returnTrue() {
        setFloatingButtonEnabled(true);
        AccessibilityTestUtils.setSoftwareShortcutMode(
                mContext, /* gestureNavEnabled= */ false, /* floatingButtonEnabled= */ true);

        assertThat(mController.isShortcutAvailable()).isTrue();
    }

    @Test
    public void isShortcutAvailable_floatingMenuDisabled_returnFalse() {
        setFloatingButtonEnabled(false);
        AccessibilityTestUtils.setSoftwareShortcutMode(
                mContext, /* gestureNavEnabled= */ false, /* floatingButtonEnabled= */ false);

        assertThat(mController.isShortcutAvailable()).isFalse();
    }

    private void setFloatingButtonEnabled(boolean enable) {
        int mode = enable
                ? ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU : ACCESSIBILITY_BUTTON_MODE_GESTURE;
    @Test
    @EnableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void isShortcutAvailable_gestureNavigationMode_returnsTrue() {
        AccessibilityTestUtils.setSoftwareShortcutMode(
                mContext, /* gestureNavEnabled= */ true, /* floatingButtonEnabled= */ false);

        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_MODE, mode);
        assertThat(mController.isShortcutAvailable()).isTrue();
    }
}
+44 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.accessibility.shortcuts;

import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.GESTURE;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE;
import static com.android.settings.testutils.AccessibilityTestUtils.setupMockAccessibilityManager;

import static com.google.common.truth.Truth.assertThat;
@@ -25,6 +27,10 @@ import static org.mockito.Mockito.when;

import android.content.ComponentName;
import android.content.Context;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Flags;
import android.view.accessibility.AccessibilityManager;

import androidx.preference.PreferenceManager;
@@ -37,6 +43,7 @@ import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.utils.StringUtil;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -50,6 +57,8 @@ import java.util.Set;
@Config(shadows = SettingsShadowResources.class)
@RunWith(RobolectricTestRunner.class)
public class GestureShortcutOptionControllerTest {
    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
    private static final String PREF_KEY = "prefKey";
    private static final String TARGET =
            new ComponentName("FakePackage", "FakeClass").flattenToString();
@@ -136,6 +145,18 @@ public class GestureShortcutOptionControllerTest {
        assertThat(mController.getSummary().toString()).isEqualTo(expected);
    }

    @Test
    @EnableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void getSummary_standaloneGestureFlagOn_verifyNoCustomizeA11yButtonTest() {
        enableTouchExploration(true);
        String expected = StringUtil.getIcuPluralsString(
                mContext,
                /* count= */ 3,
                R.string.accessibility_shortcut_edit_dialog_summary_gesture);

        assertThat(mController.getSummary().toString()).isEqualTo(expected);
    }

    @Test
    public void isShortcutAvailable_inSuw_returnFalse() {
        mController.setInSetupWizard(true);
@@ -144,6 +165,7 @@ public class GestureShortcutOptionControllerTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    public void isShortcutAvailable_notInSuwUseGestureNavSystemUseFab_returnFalse() {
        mController.setInSetupWizard(false);
        AccessibilityTestUtils.setSoftwareShortcutMode(
@@ -179,6 +201,28 @@ public class GestureShortcutOptionControllerTest {
        assertThat(mController.isShortcutAvailable()).isFalse();
    }

    @EnableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    @Test
    public void isShortcutAvailable_floatingMenuEnabled_gestureNavEnabled_returnsTrue() {
        mController.setInSetupWizard(false);
        AccessibilityTestUtils.setSoftwareShortcutMode(
                mContext, /* gestureNavEnabled= */ true, /* floatingButtonEnabled= */ true);

        assertThat(mController.isShortcutAvailable()).isTrue();
    }

    @EnableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    @Test
    public void getShortcutType_gesture() {
        assertThat(mController.getShortcutType()).isEqualTo(GESTURE);
    }

    @DisableFlags(Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED)
    @Test
    public void getShortcutType_software() {
        assertThat(mController.getShortcutType()).isEqualTo(SOFTWARE);
    }

    private void enableTouchExploration(boolean enable) {
        AccessibilityManager am = setupMockAccessibilityManager(mContext);
        when(am.isTouchExplorationEnabled()).thenReturn(enable);
Loading