Show QS shortcut option if the a11y feature provides a tile.
Bug: 314852953 Test: atest com.android.settings.accessibility Test: atest com.android.settings.accessibility.shortcuts Test: manual Flag: ACONFIG android.view.accessibility.a11y_qs_shortcut STAGING Change-Id: Id7a6b3adfd4c4f3cb2b9f7fe15269b57a3d00543
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
<drawable name="a11y_captioning_banner" product="default">@drawable/accessibility_captioning_banner</drawable>
|
<drawable name="a11y_captioning_banner" product="default">@drawable/accessibility_captioning_banner</drawable>
|
||||||
<drawable name="a11y_captioning_banner" product="tablet">@drawable/accessibility_captioning_banner_tablet</drawable>
|
<drawable name="a11y_captioning_banner" product="tablet">@drawable/accessibility_captioning_banner_tablet</drawable>
|
||||||
|
|
||||||
|
<drawable name="a11y_shortcut_type_quick_settings" product="default">@drawable/accessibility_shortcut_type_quick_settings</drawable>
|
||||||
|
|
||||||
<drawable name="a11y_shortcut_type_hardware" product="default">@drawable/accessibility_shortcut_type_hardware</drawable>
|
<drawable name="a11y_shortcut_type_hardware" product="default">@drawable/accessibility_shortcut_type_hardware</drawable>
|
||||||
<drawable name="a11y_shortcut_type_hardware" product="tablet">@drawable/accessibility_shortcut_type_hardware_tablet</drawable>
|
<drawable name="a11y_shortcut_type_hardware" product="tablet">@drawable/accessibility_shortcut_type_hardware_tablet</drawable>
|
||||||
|
|
||||||
|
56
res/drawable/accessibility_shortcut_type_quick_settings.xml
Normal file
56
res/drawable/accessibility_shortcut_type_quick_settings.xml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~
|
||||||
|
~ Copyright 2024 The Android Open Source Project
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
~
|
||||||
|
~
|
||||||
|
-->
|
||||||
|
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="312dp"
|
||||||
|
android:height="130dp"
|
||||||
|
android:viewportWidth="312"
|
||||||
|
android:viewportHeight="130">
|
||||||
|
<group>
|
||||||
|
<clip-path
|
||||||
|
android:pathData="M24,0L288,0A24,24 0,0 1,312 24L312,106A24,24 0,0 1,288 130L24,130A24,24 0,0 1,0 106L0,24A24,24 0,0 1,24 0z"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M24,0L288,0A24,24 0,0 1,312 24L312,106A24,24 0,0 1,288 130L24,130A24,24 0,0 1,0 106L0,24A24,24 0,0 1,24 0z"
|
||||||
|
android:fillColor="#ffffff"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M209,139.62H210V138.62V32C210,24.82 204.18,19 197,19H115C107.82,19 102,24.82 102,32V138.62V139.62H103H209Z"
|
||||||
|
android:strokeWidth="2"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeColor="#6D6D6D"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M103,32C103,25.37 108.37,20 115,20H197C203.63,20 209,25.37 209,32V91.93H103V32Z"
|
||||||
|
android:fillColor="#484848"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M113.31,38.93L149.48,38.93A4,4 0,0 1,153.48 42.93L153.48,52.6A4,4 0,0 1,149.48 56.6L113.31,56.6A4,4 0,0 1,109.31 52.6L109.31,42.93A4,4 0,0 1,113.31 38.93z"
|
||||||
|
android:fillColor="#69B2C9"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M113.31,61.64L149.48,61.64A4,4 0,0 1,153.48 65.64L153.48,75.31A4,4 0,0 1,149.48 79.31L113.31,79.31A4,4 0,0 1,109.31 75.31L109.31,65.64A4,4 0,0 1,113.31 61.64z"
|
||||||
|
android:fillColor="#646464"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M162.52,38.93L198.69,38.93A4,4 0,0 1,202.69 42.93L202.69,52.6A4,4 0,0 1,198.69 56.6L162.52,56.6A4,4 0,0 1,158.52 52.6L158.52,42.93A4,4 0,0 1,162.52 38.93z"
|
||||||
|
android:fillColor="#646464"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M162.52,61.64L198.69,61.64A4,4 0,0 1,202.69 65.64L202.69,75.31A4,4 0,0 1,198.69 79.31L162.52,79.31A4,4 0,0 1,158.52 75.31L158.52,65.64A4,4 0,0 1,162.52 61.64z"
|
||||||
|
android:fillColor="#646464"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -22,6 +22,7 @@
|
|||||||
<string name="accessibility_shortcut_nav_button_pref" translatable="false">shortcut_nav_button_pref</string>
|
<string name="accessibility_shortcut_nav_button_pref" translatable="false">shortcut_nav_button_pref</string>
|
||||||
<string name="accessibility_shortcut_fab_pref" translatable="false">shortcut_fab_pref</string>
|
<string name="accessibility_shortcut_fab_pref" translatable="false">shortcut_fab_pref</string>
|
||||||
<string name="accessibility_shortcut_triple_tap_pref" translatable="false">shortcut_triple_tap_pref</string>
|
<string name="accessibility_shortcut_triple_tap_pref" translatable="false">shortcut_triple_tap_pref</string>
|
||||||
<string name="accessibility_shortcut_two_fingers_double_tap_pref" translatable="false">shortcut_two_fingers_double_tap_pref</string>
|
<string name="accessibility_shortcut_two_finger_double_tap_pref" translatable="false">shortcut_two_finger_double_tap_pref</string>
|
||||||
|
<string name="accessibility_shortcut_quick_settings_pref" translatable="false">shortcut_quick_settings_pref</string>
|
||||||
<string name="accessibility_shortcuts_advanced_collapsed" translatable="false">advanced_shortcuts_collapsed</string>
|
<string name="accessibility_shortcuts_advanced_collapsed" translatable="false">advanced_shortcuts_collapsed</string>
|
||||||
</resources>
|
</resources>
|
@@ -4835,6 +4835,8 @@
|
|||||||
<string name="accessibility_tutorial_dialog_title_triple">Triple tap screen to open</string>
|
<string name="accessibility_tutorial_dialog_title_triple">Triple tap screen to open</string>
|
||||||
<!-- Title for the accessibility tutorial dialog in accessibility service with two finger double tap. [CHAR LIMIT=100] -->
|
<!-- Title for the accessibility tutorial dialog in accessibility service with two finger double tap. [CHAR LIMIT=100] -->
|
||||||
<string name="accessibility_tutorial_dialog_title_two_finger_double">Two finger double tap screen to open</string>
|
<string name="accessibility_tutorial_dialog_title_two_finger_double">Two finger double tap screen to open</string>
|
||||||
|
<!-- Title for the accessibility tutorial dialog in accessibility service with quick setting shortcut. [CHAR LIMIT=100] -->
|
||||||
|
<string name="accessibility_tutorial_dialog_title_quick_setting">Quick Settings shortcut</string>
|
||||||
<!-- Title for the accessibility tutorial dialog in accessibility service with gesture. [CHAR LIMIT=50] -->
|
<!-- Title for the accessibility tutorial dialog in accessibility service with gesture. [CHAR LIMIT=50] -->
|
||||||
<string name="accessibility_tutorial_dialog_title_gesture">Use gesture to open</string>
|
<string name="accessibility_tutorial_dialog_title_gesture">Use gesture to open</string>
|
||||||
<!-- Title for the accessibility tutorial dialog in gesture navigation settings. [CHAR LIMIT=50] -->
|
<!-- Title for the accessibility tutorial dialog in gesture navigation settings. [CHAR LIMIT=50] -->
|
||||||
@@ -4849,6 +4851,8 @@
|
|||||||
<string name="accessibility_tutorial_dialog_message_triple">To start and stop magnification, triple-tap anywhere on your screen.</string>
|
<string name="accessibility_tutorial_dialog_message_triple">To start and stop magnification, triple-tap anywhere on your screen.</string>
|
||||||
<!-- Instruction for the accessibility tutorial dialog in accessibility service with two finger double tap. [CHAR LIMIT=100] -->
|
<!-- Instruction for the accessibility tutorial dialog in accessibility service with two finger double tap. [CHAR LIMIT=100] -->
|
||||||
<string name="accessibility_tutorial_dialog_message_two_finger_triple">To start and stop magnification, double-tap anywhere on your screen with two fingers.</string>
|
<string name="accessibility_tutorial_dialog_message_two_finger_triple">To start and stop magnification, double-tap anywhere on your screen with two fingers.</string>
|
||||||
|
<!-- Instruction for the accessibility tutorial dialog in accessibility service with triple tap. [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="accessibility_tutorial_dialog_message_quick_setting">To use this feature, swipe down from the top of your screen.</string>
|
||||||
<!-- Message for the accessibility tutorial dialog when user enables an accessibility service while using gesture navigation and touch exploration is not enabled. [CHAR LIMIT=NONE] -->
|
<!-- Message for the accessibility tutorial dialog when user enables an accessibility service while using gesture navigation and touch exploration is not enabled. [CHAR LIMIT=NONE] -->
|
||||||
<string name="accessibility_tutorial_dialog_message_gesture">To use this feature, swipe up from the bottom of the screen with 2 fingers.\n\nTo switch between features, swipe up with 2 fingers and hold.</string>
|
<string name="accessibility_tutorial_dialog_message_gesture">To use this feature, swipe up from the bottom of the screen with 2 fingers.\n\nTo switch between features, swipe up with 2 fingers and hold.</string>
|
||||||
<!-- Message for the accessibility tutorial dialog when user enables an accessibility service while using gesture navigation and touch exploration is enabled. [CHAR LIMIT=NONE] -->
|
<!-- Message for the accessibility tutorial dialog when user enables an accessibility service while using gesture navigation and touch exploration is enabled. [CHAR LIMIT=NONE] -->
|
||||||
@@ -4863,10 +4867,10 @@
|
|||||||
<string name="accessibility_tutorial_dialog_link_button">Button settings</string>
|
<string name="accessibility_tutorial_dialog_link_button">Button settings</string>
|
||||||
<!-- Title for accessibility shortcut preference for accessibility apps. [CHAR LIMIT=40] -->
|
<!-- Title for accessibility shortcut preference for accessibility apps. [CHAR LIMIT=40] -->
|
||||||
<string name="accessibility_shortcut_title"><xliff:g id="service" example="Select to Speak">%1$s</xliff:g> shortcut</string>
|
<string name="accessibility_shortcut_title"><xliff:g id="service" example="Select to Speak">%1$s</xliff:g> shortcut</string>
|
||||||
<!-- Title for software shortcut in accessibility edit shortcut dialog. [CHAR LIMIT=NONE] -->
|
<!-- Shown as one of the item in the chosen accessibility shortcut types list presented as a label next to the shortcut toggle. [CHAR LIMIT=NONE] -->
|
||||||
<string name="accessibility_shortcut_edit_summary_software">Accessibility button</string>
|
<string name="accessibility_shortcut_edit_summary_software">accessibility button</string>
|
||||||
<!-- Title for software shortcut gesture in accessibility edit shortcut dialog. [CHAR LIMIT=NONE] -->
|
<!-- Shown as one of the item in the chosen accessibility shortcut types list presented as a label next to the shortcut toggle. [CHAR LIMIT=NONE] -->
|
||||||
<string name="accessibility_shortcut_edit_summary_software_gesture">Accessibility gesture</string>
|
<string name="accessibility_shortcut_edit_summary_software_gesture">accessibility gesture</string>
|
||||||
<!-- Title for software shortcut in gesture mode in accessibility edit shortcut dialog while using gesture navigation is enabled. [CHAR LIMIT=NONE] -->
|
<!-- Title for software shortcut in gesture mode in accessibility edit shortcut dialog while using gesture navigation is enabled. [CHAR LIMIT=NONE] -->
|
||||||
<string name="accessibility_shortcut_edit_dialog_title_software_gesture">Swipe up with 2 fingers</string>
|
<string name="accessibility_shortcut_edit_dialog_title_software_gesture">Swipe up with 2 fingers</string>
|
||||||
<!-- Title for software shortcut in gesture mode in accessibility edit shortcut dialog while using gesture navigation and touch exploration are enabled. [CHAR LIMIT=NONE] -->
|
<!-- Title for software shortcut in gesture mode in accessibility edit shortcut dialog while using gesture navigation and touch exploration are enabled. [CHAR LIMIT=NONE] -->
|
||||||
@@ -4885,6 +4889,12 @@
|
|||||||
<string name="accessibility_shortcut_edit_dialog_summary_software_floating"><annotation id="link">More options</annotation></string>
|
<string name="accessibility_shortcut_edit_dialog_summary_software_floating"><annotation id="link">More options</annotation></string>
|
||||||
<!-- Footer to show help link content description. [CHAR LIMIT=NONE] -->
|
<!-- Footer to show help link content description. [CHAR LIMIT=NONE] -->
|
||||||
<string name="footer_learn_more_content_description">Learn more about <xliff:g id="service" example="Select to Speak">%1$s</xliff:g></string>
|
<string name="footer_learn_more_content_description">Learn more about <xliff:g id="service" example="Select to Speak">%1$s</xliff:g></string>
|
||||||
|
<!-- Title for quick settings shortcut option in accessibility edit shortcut dialog. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="accessibility_shortcut_edit_dialog_title_quick_settings">Quick Settings</string>
|
||||||
|
<!-- Summary for quick settings shortcut option in accessibility edit shortcut dialog. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="accessibility_shortcut_edit_dialog_summary_quick_settings">Swipe down from the top of your screen</string>
|
||||||
|
<!-- Shown as one of the item in the chosen accessibility shortcut types list presented as a label next to the shortcut toggle. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="accessibility_feature_shortcut_setting_summary_quick_settings">Quick Settings</string>
|
||||||
<!-- Title for hardware shortcut in accessibility edit shortcut dialog. [CHAR LIMIT=NONE] -->
|
<!-- Title for hardware shortcut in accessibility edit shortcut dialog. [CHAR LIMIT=NONE] -->
|
||||||
<string name="accessibility_shortcut_edit_dialog_title_hardware">Hold volume keys</string>
|
<string name="accessibility_shortcut_edit_dialog_title_hardware">Hold volume keys</string>
|
||||||
<!-- Part of list to compose user's accessibility shortcut list. [CHAR LIMIT=NONE] -->
|
<!-- Part of list to compose user's accessibility shortcut list. [CHAR LIMIT=NONE] -->
|
||||||
|
@@ -25,6 +25,14 @@
|
|||||||
settings:allowDividerAbove="false"
|
settings:allowDividerAbove="false"
|
||||||
settings:allowDividerBelow="false"/>
|
settings:allowDividerBelow="false"/>
|
||||||
|
|
||||||
|
<com.android.settings.accessibility.shortcuts.ShortcutOptionPreference
|
||||||
|
android:key="@string/accessibility_shortcut_quick_settings_pref"
|
||||||
|
android:persistent="false"
|
||||||
|
android:selectable="true"
|
||||||
|
settings:allowDividerAbove="false"
|
||||||
|
settings:allowDividerBelow="false"
|
||||||
|
settings:controller="com.android.settings.accessibility.shortcuts.QuickSettingsShortcutOptionController" />
|
||||||
|
|
||||||
<com.android.settings.accessibility.shortcuts.ShortcutOptionPreference
|
<com.android.settings.accessibility.shortcuts.ShortcutOptionPreference
|
||||||
android:key="@string/accessibility_shortcut_fab_pref"
|
android:key="@string/accessibility_shortcut_fab_pref"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
@@ -58,12 +66,12 @@
|
|||||||
settings:controller="com.android.settings.accessibility.shortcuts.VolumeKeysShortcutOptionController" />
|
settings:controller="com.android.settings.accessibility.shortcuts.VolumeKeysShortcutOptionController" />
|
||||||
|
|
||||||
<com.android.settings.accessibility.shortcuts.ShortcutOptionPreference
|
<com.android.settings.accessibility.shortcuts.ShortcutOptionPreference
|
||||||
android:key="@string/accessibility_shortcut_two_fingers_double_tap_pref"
|
android:key="@string/accessibility_shortcut_two_finger_double_tap_pref"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:selectable="true"
|
android:selectable="true"
|
||||||
settings:allowDividerAbove="false"
|
settings:allowDividerAbove="false"
|
||||||
settings:allowDividerBelow="false"
|
settings:allowDividerBelow="false"
|
||||||
settings:controller="com.android.settings.accessibility.shortcuts.TwoFingersDoubleTapShortcutOptionController" />
|
settings:controller="com.android.settings.accessibility.shortcuts.TwoFingerDoubleTapShortcutOptionController" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:icon="@drawable/ic_keyboard_arrow_down"
|
android:icon="@drawable/ic_keyboard_arrow_down"
|
||||||
|
@@ -414,7 +414,7 @@ public final class AccessibilityGestureNavigationTutorial {
|
|||||||
|
|
||||||
private static TutorialPage createTwoFingerTripleTapTutorialPage(@NonNull Context context) {
|
private static TutorialPage createTwoFingerTripleTapTutorialPage(@NonNull Context context) {
|
||||||
// TODO(b/308088945): Update tutorial string and image when UX provides them
|
// TODO(b/308088945): Update tutorial string and image when UX provides them
|
||||||
final int type = UserShortcutType.TWOFINGERTRIPLETAP;
|
final int type = UserShortcutType.TWOFINGER_DOUBLETAP;
|
||||||
final CharSequence title =
|
final CharSequence title =
|
||||||
context.getText(R.string.accessibility_tutorial_dialog_title_two_finger_double);
|
context.getText(R.string.accessibility_tutorial_dialog_title_two_finger_double);
|
||||||
final View image =
|
final View image =
|
||||||
@@ -429,10 +429,32 @@ public final class AccessibilityGestureNavigationTutorial {
|
|||||||
return new TutorialPage(type, title, image, indicatorIcon, instruction);
|
return new TutorialPage(type, title, image, indicatorIcon, instruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static TutorialPage createQuickSettingTutorialPage(@NonNull Context context) {
|
||||||
|
final int type = UserShortcutType.QUICK_SETTINGS;
|
||||||
|
final CharSequence title =
|
||||||
|
context.getText(R.string.accessibility_tutorial_dialog_title_quick_setting);
|
||||||
|
final View image =
|
||||||
|
createIllustrationView(context,
|
||||||
|
R.drawable.a11y_shortcut_type_quick_settings);
|
||||||
|
final CharSequence instruction =
|
||||||
|
context.getText(R.string.accessibility_tutorial_dialog_message_quick_setting);
|
||||||
|
final ImageView indicatorIcon =
|
||||||
|
createImageView(context, R.drawable.ic_accessibility_page_indicator);
|
||||||
|
indicatorIcon.setEnabled(false);
|
||||||
|
|
||||||
|
return new TutorialPage(type, title, image, indicatorIcon, instruction);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static List<TutorialPage> createShortcutTutorialPages(@NonNull Context context,
|
static List<TutorialPage> createShortcutTutorialPages(@NonNull Context context,
|
||||||
int shortcutTypes) {
|
int shortcutTypes) {
|
||||||
final List<TutorialPage> tutorialPages = new ArrayList<>();
|
final List<TutorialPage> tutorialPages = new ArrayList<>();
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
if ((shortcutTypes & UserShortcutType.QUICK_SETTINGS)
|
||||||
|
== UserShortcutType.QUICK_SETTINGS) {
|
||||||
|
tutorialPages.add(createQuickSettingTutorialPage(context));
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
tutorialPages.add(createSoftwareTutorialPage(context));
|
tutorialPages.add(createSoftwareTutorialPage(context));
|
||||||
}
|
}
|
||||||
@@ -446,8 +468,8 @@ public final class AccessibilityGestureNavigationTutorial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if ((shortcutTypes & UserShortcutType.TWOFINGERTRIPLETAP)
|
if ((shortcutTypes & UserShortcutType.TWOFINGER_DOUBLETAP)
|
||||||
== UserShortcutType.TWOFINGERTRIPLETAP) {
|
== UserShortcutType.TWOFINGER_DOUBLETAP) {
|
||||||
tutorialPages.add(createTwoFingerTripleTapTutorialPage(context));
|
tutorialPages.add(createTwoFingerTripleTapTutorialPage(context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -452,7 +452,13 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
|
|||||||
getComponentName().flattenToString());
|
getComponentName().flattenToString());
|
||||||
|
|
||||||
final List<CharSequence> list = new ArrayList<>();
|
final List<CharSequence> list = new ArrayList<>();
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
if (hasShortcutType(shortcutTypes, AccessibilityUtil.UserShortcutType.QUICK_SETTINGS)) {
|
||||||
|
final CharSequence qsTitle = context.getText(
|
||||||
|
R.string.accessibility_feature_shortcut_setting_summary_quick_settings);
|
||||||
|
list.add(qsTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (hasShortcutType(shortcutTypes, AccessibilityUtil.UserShortcutType.SOFTWARE)) {
|
if (hasShortcutType(shortcutTypes, AccessibilityUtil.UserShortcutType.SOFTWARE)) {
|
||||||
list.add(getSoftwareShortcutTypeSummary(context));
|
list.add(getSoftwareShortcutTypeSummary(context));
|
||||||
}
|
}
|
||||||
@@ -538,6 +544,10 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showQuickSettingsTooltipIfNeeded() {
|
private void showQuickSettingsTooltipIfNeeded() {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
// Don't show Quick Settings tooltip
|
||||||
|
return;
|
||||||
|
}
|
||||||
final ComponentName tileComponentName = getTileComponentName();
|
final ComponentName tileComponentName = getTileComponentName();
|
||||||
if (tileComponentName == null) {
|
if (tileComponentName == null) {
|
||||||
// Returns if no tile service assigned.
|
// Returns if no tile service assigned.
|
||||||
|
@@ -28,6 +28,7 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.Insets;
|
import android.graphics.Insets;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
@@ -40,8 +41,11 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
/** Provides utility methods to accessibility settings only. */
|
/** Provides utility methods to accessibility settings only. */
|
||||||
@@ -87,6 +91,10 @@ public final class AccessibilityUtil {
|
|||||||
* choose accessibility shortcut as preferred shortcut.
|
* choose accessibility shortcut as preferred shortcut.
|
||||||
* {@code TRIPLETAP} for displaying specifying magnification to be toggled via quickly
|
* {@code TRIPLETAP} for displaying specifying magnification to be toggled via quickly
|
||||||
* tapping screen 3 times as preferred shortcut.
|
* tapping screen 3 times as preferred shortcut.
|
||||||
|
* {@code TWOFINGER_DOUBLETAP} for displaying specifying magnification to be toggled via
|
||||||
|
* quickly tapping screen 2 times with two fingers as preferred shortcut.
|
||||||
|
* {@code QUICK_SETTINGS} for displaying specifying the accessibility services or features which
|
||||||
|
* choose Quick Settings as preferred shortcut.
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef({
|
@IntDef({
|
||||||
@@ -94,16 +102,18 @@ public final class AccessibilityUtil {
|
|||||||
UserShortcutType.SOFTWARE,
|
UserShortcutType.SOFTWARE,
|
||||||
UserShortcutType.HARDWARE,
|
UserShortcutType.HARDWARE,
|
||||||
UserShortcutType.TRIPLETAP,
|
UserShortcutType.TRIPLETAP,
|
||||||
UserShortcutType.TWOFINGERTRIPLETAP,
|
UserShortcutType.TWOFINGER_DOUBLETAP,
|
||||||
|
UserShortcutType.QUICK_SETTINGS,
|
||||||
})
|
})
|
||||||
|
|
||||||
/** Denotes the user shortcut type. */
|
/** Denotes the user shortcut type. */
|
||||||
public @interface UserShortcutType {
|
public @interface UserShortcutType {
|
||||||
int EMPTY = 0;
|
int EMPTY = 0;
|
||||||
int SOFTWARE = 1; // 1 << 0
|
int SOFTWARE = 1;
|
||||||
int HARDWARE = 2; // 1 << 1
|
int HARDWARE = 1 << 1;
|
||||||
int TRIPLETAP = 4; // 1 << 2
|
int TRIPLETAP = 1 << 2;
|
||||||
int TWOFINGERTRIPLETAP = 8; // 1 << 3
|
int TWOFINGER_DOUBLETAP = 1 << 3;
|
||||||
|
int QUICK_SETTINGS = 1 << 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,6 +216,20 @@ public final class AccessibilityUtil {
|
|||||||
*/
|
*/
|
||||||
static void optInAllValuesToSettings(Context context, int shortcutTypes,
|
static void optInAllValuesToSettings(Context context, int shortcutTypes,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
|
||||||
|
if (a11yManager != null) {
|
||||||
|
a11yManager.enableShortcutsForTargets(
|
||||||
|
/* enable= */ true,
|
||||||
|
shortcutTypes,
|
||||||
|
Set.of(componentName.flattenToString()),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
optInValueToSettings(context, UserShortcutType.SOFTWARE, componentName);
|
optInValueToSettings(context, UserShortcutType.SOFTWARE, componentName);
|
||||||
}
|
}
|
||||||
@@ -224,6 +248,19 @@ public final class AccessibilityUtil {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static void optInValueToSettings(Context context, @UserShortcutType int shortcutType,
|
static void optInValueToSettings(Context context, @UserShortcutType int shortcutType,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
|
||||||
|
if (a11yManager != null) {
|
||||||
|
a11yManager.enableShortcutsForTargets(
|
||||||
|
/* enable= */ true,
|
||||||
|
shortcutType,
|
||||||
|
Set.of(componentName.flattenToString()),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final String targetKey = convertKeyFromSettings(shortcutType);
|
final String targetKey = convertKeyFromSettings(shortcutType);
|
||||||
final String targetString = Settings.Secure.getString(context.getContentResolver(),
|
final String targetString = Settings.Secure.getString(context.getContentResolver(),
|
||||||
targetKey);
|
targetKey);
|
||||||
@@ -251,6 +288,19 @@ public final class AccessibilityUtil {
|
|||||||
*/
|
*/
|
||||||
static void optOutAllValuesFromSettings(Context context, int shortcutTypes,
|
static void optOutAllValuesFromSettings(Context context, int shortcutTypes,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
|
||||||
|
if (a11yManager != null) {
|
||||||
|
a11yManager.enableShortcutsForTargets(
|
||||||
|
/* enable= */ false,
|
||||||
|
shortcutTypes,
|
||||||
|
Set.of(componentName.flattenToString()),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||||
optOutValueFromSettings(context, UserShortcutType.SOFTWARE, componentName);
|
optOutValueFromSettings(context, UserShortcutType.SOFTWARE, componentName);
|
||||||
}
|
}
|
||||||
@@ -269,6 +319,19 @@ public final class AccessibilityUtil {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static void optOutValueFromSettings(Context context, @UserShortcutType int shortcutType,
|
static void optOutValueFromSettings(Context context, @UserShortcutType int shortcutType,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
|
||||||
|
if (a11yManager != null) {
|
||||||
|
a11yManager.enableShortcutsForTargets(
|
||||||
|
/* enable= */ false,
|
||||||
|
shortcutType,
|
||||||
|
Set.of(componentName.flattenToString()),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
||||||
final String targetKey = convertKeyFromSettings(shortcutType);
|
final String targetKey = convertKeyFromSettings(shortcutType);
|
||||||
final String targetString = Settings.Secure.getString(context.getContentResolver(),
|
final String targetString = Settings.Secure.getString(context.getContentResolver(),
|
||||||
@@ -307,6 +370,14 @@ public final class AccessibilityUtil {
|
|||||||
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
|
if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
|
||||||
exist |= hasValueInSettings(context, UserShortcutType.HARDWARE, componentName);
|
exist |= hasValueInSettings(context, UserShortcutType.HARDWARE, componentName);
|
||||||
}
|
}
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
if ((shortcutTypes & UserShortcutType.QUICK_SETTINGS)
|
||||||
|
== UserShortcutType.QUICK_SETTINGS) {
|
||||||
|
exist |= hasValueInSettings(context, UserShortcutType.QUICK_SETTINGS,
|
||||||
|
componentName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return exist;
|
return exist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +392,12 @@ public final class AccessibilityUtil {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static boolean hasValueInSettings(Context context, @UserShortcutType int shortcutType,
|
static boolean hasValueInSettings(Context context, @UserShortcutType int shortcutType,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
return ShortcutUtils.getShortcutTargetsFromSettings(
|
||||||
|
context, shortcutType, UserHandle.myUserId()
|
||||||
|
).contains(componentName.flattenToString());
|
||||||
|
}
|
||||||
|
|
||||||
final String targetKey = convertKeyFromSettings(shortcutType);
|
final String targetKey = convertKeyFromSettings(shortcutType);
|
||||||
final String targetString = Settings.Secure.getString(context.getContentResolver(),
|
final String targetString = Settings.Secure.getString(context.getContentResolver(),
|
||||||
targetKey);
|
targetKey);
|
||||||
@@ -357,6 +434,12 @@ public final class AccessibilityUtil {
|
|||||||
if (hasValuesInSettings(context, UserShortcutType.HARDWARE, componentName)) {
|
if (hasValuesInSettings(context, UserShortcutType.HARDWARE, componentName)) {
|
||||||
shortcutTypes |= UserShortcutType.HARDWARE;
|
shortcutTypes |= UserShortcutType.HARDWARE;
|
||||||
}
|
}
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
if (hasValuesInSettings(context, UserShortcutType.QUICK_SETTINGS, componentName)) {
|
||||||
|
shortcutTypes |= UserShortcutType.QUICK_SETTINGS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return shortcutTypes;
|
return shortcutTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,6 +450,10 @@ public final class AccessibilityUtil {
|
|||||||
* @return Mapping key in Settings.
|
* @return Mapping key in Settings.
|
||||||
*/
|
*/
|
||||||
static String convertKeyFromSettings(@UserShortcutType int shortcutType) {
|
static String convertKeyFromSettings(@UserShortcutType int shortcutType) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
return ShortcutUtils.convertToKey(shortcutType);
|
||||||
|
}
|
||||||
|
|
||||||
switch (shortcutType) {
|
switch (shortcutType) {
|
||||||
case UserShortcutType.SOFTWARE:
|
case UserShortcutType.SOFTWARE:
|
||||||
return Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
return Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
||||||
|
@@ -21,8 +21,10 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.internal.accessibility.common.ShortcutConstants;
|
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||||
import com.android.internal.accessibility.util.ShortcutUtils;
|
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||||
@@ -98,6 +100,11 @@ public final class PreferredShortcuts {
|
|||||||
@NonNull Context context, @NonNull Set<String> components) {
|
@NonNull Context context, @NonNull Set<String> components) {
|
||||||
final Map<Integer, Set<String>> shortcutTypeToTargets = new ArrayMap<>();
|
final Map<Integer, Set<String>> shortcutTypeToTargets = new ArrayMap<>();
|
||||||
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
|
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
|
||||||
|
if (!Flags.a11yQsShortcut()
|
||||||
|
&& shortcutType == ShortcutConstants.UserShortcutType.QUICK_SETTINGS) {
|
||||||
|
// Skip saving quick setting as preferred shortcut option when flag is not enabled
|
||||||
|
continue;
|
||||||
|
}
|
||||||
shortcutTypeToTargets.put(
|
shortcutTypeToTargets.put(
|
||||||
shortcutType,
|
shortcutType,
|
||||||
ShortcutUtils.getShortcutTargetsFromSettings(
|
ShortcutUtils.getShortcutTargetsFromSettings(
|
||||||
@@ -138,6 +145,11 @@ public final class PreferredShortcuts {
|
|||||||
return context.getSharedPreferences(ACCESSIBILITY_PERF, Context.MODE_PRIVATE);
|
return context.getSharedPreferences(ACCESSIBILITY_PERF, Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||||
|
static void clearPreferredShortcuts(Context context) {
|
||||||
|
getSharedPreferences(context).edit().clear().apply();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default shortcut types for the given accessibility feature.
|
* Returns the default shortcut types for the given accessibility feature.
|
||||||
*/
|
*/
|
||||||
|
@@ -711,6 +711,13 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
|
|||||||
mComponentName.flattenToString());
|
mComponentName.flattenToString());
|
||||||
|
|
||||||
final List<CharSequence> list = new ArrayList<>();
|
final List<CharSequence> list = new ArrayList<>();
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
if (hasShortcutType(shortcutTypes, UserShortcutType.QUICK_SETTINGS)) {
|
||||||
|
final CharSequence qsTitle = context.getText(
|
||||||
|
R.string.accessibility_feature_shortcut_setting_summary_quick_settings);
|
||||||
|
list.add(qsTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
|
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
|
||||||
list.add(getSoftwareShortcutTypeSummary(context));
|
list.add(getSoftwareShortcutTypeSummary(context));
|
||||||
}
|
}
|
||||||
@@ -906,6 +913,10 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showQuickSettingsTooltipIfNeeded() {
|
private void showQuickSettingsTooltipIfNeeded() {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
// Don't show Quick Settings tooltip
|
||||||
|
return;
|
||||||
|
}
|
||||||
final ComponentName tileComponentName = getTileComponentName();
|
final ComponentName tileComponentName = getTileComponentName();
|
||||||
if (tileComponentName == null) {
|
if (tileComponentName == null) {
|
||||||
// Returns if no tile service assigned.
|
// Returns if no tile service assigned.
|
||||||
|
@@ -33,6 +33,7 @@ import android.icu.text.CaseMap;
|
|||||||
import android.icu.text.MessageFormat;
|
import android.icu.text.MessageFormat;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -65,6 +66,7 @@ import com.google.android.setupcompat.util.WizardManagerHelper;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -357,7 +359,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
}
|
}
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (mTwoFingerTripleTapTypeCheckBox.isChecked()) {
|
if (mTwoFingerTripleTapTypeCheckBox.isChecked()) {
|
||||||
value |= UserShortcutType.TWOFINGERTRIPLETAP;
|
value |= UserShortcutType.TWOFINGER_DOUBLETAP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@@ -419,7 +421,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
hasShortcutType(value, UserShortcutType.TRIPLETAP));
|
hasShortcutType(value, UserShortcutType.TRIPLETAP));
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
mTwoFingerTripleTapTypeCheckBox.setChecked(
|
mTwoFingerTripleTapTypeCheckBox.setChecked(
|
||||||
hasShortcutType(value, UserShortcutType.TWOFINGERTRIPLETAP));
|
hasShortcutType(value, UserShortcutType.TWOFINGER_DOUBLETAP));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,6 +485,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
MAGNIFICATION_CONTROLLER_NAME);
|
MAGNIFICATION_CONTROLLER_NAME);
|
||||||
|
|
||||||
final List<CharSequence> list = new ArrayList<>();
|
final List<CharSequence> list = new ArrayList<>();
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
if (hasShortcutType(shortcutTypes, UserShortcutType.QUICK_SETTINGS)) {
|
||||||
|
final CharSequence qsTitle = context.getText(
|
||||||
|
R.string.accessibility_feature_shortcut_setting_summary_quick_settings);
|
||||||
|
list.add(qsTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
|
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
|
||||||
list.add(getSoftwareShortcutTypeSummary(context));
|
list.add(getSoftwareShortcutTypeSummary(context));
|
||||||
}
|
}
|
||||||
@@ -497,7 +506,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
list.add(tripleTapTitle);
|
list.add(tripleTapTitle);
|
||||||
}
|
}
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (hasShortcutType(shortcutTypes, UserShortcutType.TWOFINGERTRIPLETAP)) {
|
if (hasShortcutType(shortcutTypes, UserShortcutType.TWOFINGER_DOUBLETAP)) {
|
||||||
final CharSequence twoFingerTripleTapTitle = context.getText(
|
final CharSequence twoFingerTripleTapTitle = context.getText(
|
||||||
R.string.accessibility_shortcut_two_finger_double_tap_keyword);
|
R.string.accessibility_shortcut_two_finger_double_tap_keyword);
|
||||||
list.add(twoFingerTripleTapTitle);
|
list.add(twoFingerTripleTapTitle);
|
||||||
@@ -678,15 +687,34 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
optInMagnificationValueToSettings(context, UserShortcutType.TRIPLETAP);
|
optInMagnificationValueToSettings(context, UserShortcutType.TRIPLETAP);
|
||||||
}
|
}
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (((shortcutTypes & UserShortcutType.TWOFINGERTRIPLETAP)
|
if (((shortcutTypes & UserShortcutType.TWOFINGER_DOUBLETAP)
|
||||||
== UserShortcutType.TWOFINGERTRIPLETAP)) {
|
== UserShortcutType.TWOFINGER_DOUBLETAP)) {
|
||||||
optInMagnificationValueToSettings(context, UserShortcutType.TWOFINGERTRIPLETAP);
|
optInMagnificationValueToSettings(context, UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
if (((shortcutTypes & UserShortcutType.QUICK_SETTINGS)
|
||||||
|
== UserShortcutType.QUICK_SETTINGS)) {
|
||||||
|
optInMagnificationValueToSettings(context, UserShortcutType.QUICK_SETTINGS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void optInMagnificationValueToSettings(Context context,
|
private static void optInMagnificationValueToSettings(
|
||||||
@UserShortcutType int shortcutType) {
|
Context context, @UserShortcutType int shortcutType) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
|
||||||
|
if (a11yManager != null) {
|
||||||
|
a11yManager.enableShortcutsForTargets(
|
||||||
|
/* enable= */ true,
|
||||||
|
shortcutType,
|
||||||
|
Set.of(MAGNIFICATION_CONTROLLER_NAME),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (shortcutType == UserShortcutType.TRIPLETAP) {
|
if (shortcutType == UserShortcutType.TRIPLETAP) {
|
||||||
Settings.Secure.putInt(context.getContentResolver(),
|
Settings.Secure.putInt(context.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
|
||||||
@@ -694,8 +722,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (shortcutType == UserShortcutType.TWOFINGERTRIPLETAP) {
|
if (shortcutType == UserShortcutType.TWOFINGER_DOUBLETAP) {
|
||||||
Settings.Secure.putInt(context.getContentResolver(),
|
Settings.Secure.putInt(
|
||||||
|
context.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
||||||
ON);
|
ON);
|
||||||
return;
|
return;
|
||||||
@@ -743,15 +772,34 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
optOutMagnificationValueFromSettings(context, UserShortcutType.TRIPLETAP);
|
optOutMagnificationValueFromSettings(context, UserShortcutType.TRIPLETAP);
|
||||||
}
|
}
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (((shortcutTypes & UserShortcutType.TWOFINGERTRIPLETAP)
|
if (((shortcutTypes & UserShortcutType.TWOFINGER_DOUBLETAP)
|
||||||
== UserShortcutType.TWOFINGERTRIPLETAP)) {
|
== UserShortcutType.TWOFINGER_DOUBLETAP)) {
|
||||||
optOutMagnificationValueFromSettings(context, UserShortcutType.TWOFINGERTRIPLETAP);
|
optOutMagnificationValueFromSettings(context, UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
if (((shortcutTypes & UserShortcutType.QUICK_SETTINGS)
|
||||||
|
== UserShortcutType.QUICK_SETTINGS)) {
|
||||||
|
optOutMagnificationValueFromSettings(context, UserShortcutType.QUICK_SETTINGS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void optOutMagnificationValueFromSettings(Context context,
|
private static void optOutMagnificationValueFromSettings(Context context,
|
||||||
@UserShortcutType int shortcutType) {
|
@UserShortcutType int shortcutType) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
|
||||||
|
if (a11yManager != null) {
|
||||||
|
a11yManager.enableShortcutsForTargets(
|
||||||
|
/* enable= */ false,
|
||||||
|
shortcutType,
|
||||||
|
Set.of(MAGNIFICATION_CONTROLLER_NAME),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (shortcutType == UserShortcutType.TRIPLETAP) {
|
if (shortcutType == UserShortcutType.TRIPLETAP) {
|
||||||
Settings.Secure.putInt(context.getContentResolver(),
|
Settings.Secure.putInt(context.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
|
||||||
@@ -759,8 +807,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (shortcutType == UserShortcutType.TWOFINGERTRIPLETAP) {
|
if (shortcutType == UserShortcutType.TWOFINGER_DOUBLETAP) {
|
||||||
Settings.Secure.putInt(context.getContentResolver(),
|
Settings.Secure.putInt(
|
||||||
|
context.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
||||||
OFF);
|
OFF);
|
||||||
return;
|
return;
|
||||||
@@ -803,10 +852,10 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
exist |= hasMagnificationValueInSettings(context, UserShortcutType.TRIPLETAP);
|
exist |= hasMagnificationValueInSettings(context, UserShortcutType.TRIPLETAP);
|
||||||
}
|
}
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (((shortcutTypes & UserShortcutType.TWOFINGERTRIPLETAP)
|
if (((shortcutTypes & UserShortcutType.TWOFINGER_DOUBLETAP)
|
||||||
== UserShortcutType.TWOFINGERTRIPLETAP)) {
|
== UserShortcutType.TWOFINGER_DOUBLETAP)) {
|
||||||
exist |= hasMagnificationValueInSettings(context,
|
exist |= hasMagnificationValueInSettings(context,
|
||||||
UserShortcutType.TWOFINGERTRIPLETAP);
|
UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return exist;
|
return exist;
|
||||||
@@ -820,7 +869,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (shortcutType == UserShortcutType.TWOFINGERTRIPLETAP) {
|
if (shortcutType == UserShortcutType.TWOFINGER_DOUBLETAP) {
|
||||||
return Settings.Secure.getInt(context.getContentResolver(),
|
return Settings.Secure.getInt(context.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
||||||
OFF) == ON;
|
OFF) == ON;
|
||||||
@@ -857,8 +906,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
shortcutTypes |= UserShortcutType.TRIPLETAP;
|
shortcutTypes |= UserShortcutType.TRIPLETAP;
|
||||||
}
|
}
|
||||||
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
|
||||||
if (hasMagnificationValuesInSettings(context, UserShortcutType.TWOFINGERTRIPLETAP)) {
|
if (hasMagnificationValuesInSettings(context, UserShortcutType.TWOFINGER_DOUBLETAP)) {
|
||||||
shortcutTypes |= UserShortcutType.TWOFINGERTRIPLETAP;
|
shortcutTypes |= UserShortcutType.TWOFINGER_DOUBLETAP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shortcutTypes;
|
return shortcutTypes;
|
||||||
|
@@ -21,6 +21,7 @@ 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_BUTTON_TARGETS;
|
||||||
import static android.provider.Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED;
|
import static android.provider.Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED;
|
||||||
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED;
|
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;
|
import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
||||||
|
|
||||||
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_COMPONENT_NAME;
|
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_COMPONENT_NAME;
|
||||||
@@ -98,6 +99,9 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment {
|
|||||||
private static final Uri TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING =
|
private static final Uri TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING =
|
||||||
Settings.Secure.getUriFor(ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED);
|
Settings.Secure.getUriFor(ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED);
|
||||||
|
|
||||||
|
private static final Uri QUICK_SETTINGS_SHORTCUT_SETTING =
|
||||||
|
Settings.Secure.getUriFor(ACCESSIBILITY_QS_TARGETS);
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final Uri[] SHORTCUT_SETTINGS = {
|
static final Uri[] SHORTCUT_SETTINGS = {
|
||||||
VOLUME_KEYS_SHORTCUT_SETTING,
|
VOLUME_KEYS_SHORTCUT_SETTING,
|
||||||
@@ -105,6 +109,7 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment {
|
|||||||
BUTTON_SHORTCUT_SETTING,
|
BUTTON_SHORTCUT_SETTING,
|
||||||
TRIPLE_TAP_SHORTCUT_SETTING,
|
TRIPLE_TAP_SHORTCUT_SETTING,
|
||||||
TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING,
|
TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING,
|
||||||
|
QUICK_SETTINGS_SHORTCUT_SETTING,
|
||||||
};
|
};
|
||||||
|
|
||||||
private Set<String> mShortcutTargets;
|
private Set<String> mShortcutTargets;
|
||||||
@@ -171,7 +176,9 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment {
|
|||||||
} else if (TRIPLE_TAP_SHORTCUT_SETTING.equals(uri)) {
|
} else if (TRIPLE_TAP_SHORTCUT_SETTING.equals(uri)) {
|
||||||
refreshPreferenceController(TripleTapShortcutOptionController.class);
|
refreshPreferenceController(TripleTapShortcutOptionController.class);
|
||||||
} else if (TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING.equals(uri)) {
|
} else if (TWO_FINGERS_DOUBLE_TAP_SHORTCUT_SETTING.equals(uri)) {
|
||||||
refreshPreferenceController(TwoFingersDoubleTapShortcutOptionController.class);
|
refreshPreferenceController(TwoFingerDoubleTapShortcutOptionController.class);
|
||||||
|
} else if (QUICK_SETTINGS_SHORTCUT_SETTING.equals(uri)) {
|
||||||
|
refreshPreferenceController(QuickSettingsShortcutOptionController.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferredShortcuts.updatePreferredShortcutsFromSettings(
|
PreferredShortcuts.updatePreferredShortcutsFromSettings(
|
||||||
|
@@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.accessibility.shortcuts;
|
||||||
|
|
||||||
|
import static com.android.internal.accessibility.common.ShortcutConstants.AccessibilityFragmentType.INVISIBLE_TOGGLE;
|
||||||
|
|
||||||
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.service.quicksettings.TileService;
|
||||||
|
import android.util.ArraySet;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||||
|
import com.android.internal.accessibility.util.AccessibilityUtils;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A controller handles displaying the quick settings shortcut option preference and
|
||||||
|
* configuring the shortcut.
|
||||||
|
*/
|
||||||
|
public class QuickSettingsShortcutOptionController extends ShortcutOptionPreferenceController {
|
||||||
|
public QuickSettingsShortcutOptionController(
|
||||||
|
@NonNull Context context, @NonNull String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ShortcutConstants.UserShortcutType
|
||||||
|
@Override
|
||||||
|
protected int getShortcutType() {
|
||||||
|
return ShortcutConstants.UserShortcutType.QUICK_SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
final Preference preference = screen.findPreference(getPreferenceKey());
|
||||||
|
if (preference instanceof ShortcutOptionPreference shortcutOptionPreference) {
|
||||||
|
shortcutOptionPreference.setTitle(
|
||||||
|
R.string.accessibility_shortcut_edit_dialog_title_quick_settings);
|
||||||
|
shortcutOptionPreference.setSummary(
|
||||||
|
R.string.accessibility_shortcut_edit_dialog_summary_quick_settings);
|
||||||
|
shortcutOptionPreference.setIntroImageResId(
|
||||||
|
R.drawable.a11y_shortcut_type_quick_settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isShortcutAvailable() {
|
||||||
|
return Flags.a11yQsShortcut()
|
||||||
|
&& TileService.isQuickSettingsSupported()
|
||||||
|
&& allTargetsHasQsTile()
|
||||||
|
&& allTargetsHasValidQsTileUseCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean allTargetsHasQsTile() {
|
||||||
|
AccessibilityManager accessibilityManager = mContext.getSystemService(
|
||||||
|
AccessibilityManager.class);
|
||||||
|
if (accessibilityManager == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<ComponentName, ComponentName> a11yFeatureToTileMap =
|
||||||
|
accessibilityManager.getA11yFeatureToTileMap(UserHandle.myUserId());
|
||||||
|
if (a11yFeatureToTileMap.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String target : getShortcutTargets()) {
|
||||||
|
ComponentName targetComponentName = ComponentName.unflattenFromString(target);
|
||||||
|
if (!a11yFeatureToTileMap.containsKey(targetComponentName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if all targets have valid QS Tile shortcut use case.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Note: We don't want to promote the qs option in the edit shortcuts screen for
|
||||||
|
* a standard AccessibilityService, because the Tile is provided by the owner of the
|
||||||
|
* AccessibilityService, and they don't have control to enable the A11yService themselves
|
||||||
|
* which makes the TileService not acting as the other a11y shortcut like FAB where the user
|
||||||
|
* can turn on/off the feature by toggling the shortcut.
|
||||||
|
*
|
||||||
|
* A standard AccessibilityService normally won't create a TileService because the
|
||||||
|
* above mentioned reason. In any case where the standard AccessibilityService provides a tile,
|
||||||
|
* we'll hide it from the Setting's UI.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
private boolean allTargetsHasValidQsTileUseCase() {
|
||||||
|
AccessibilityManager accessibilityManager = mContext.getSystemService(
|
||||||
|
AccessibilityManager.class);
|
||||||
|
if (accessibilityManager == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AccessibilityServiceInfo> installedServices =
|
||||||
|
accessibilityManager.getInstalledAccessibilityServiceList();
|
||||||
|
final Set<String> standardA11yServices = new ArraySet<>();
|
||||||
|
for (AccessibilityServiceInfo serviceInfo : installedServices) {
|
||||||
|
if (AccessibilityUtils.getAccessibilityServiceFragmentType(serviceInfo)
|
||||||
|
!= INVISIBLE_TOGGLE) {
|
||||||
|
standardA11yServices.add(serviceInfo.getComponentName().flattenToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String target : getShortcutTargets()) {
|
||||||
|
if (standardA11yServices.contains(target)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -18,6 +18,8 @@ package com.android.settings.accessibility.shortcuts;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -116,6 +118,16 @@ public abstract class ShortcutOptionPreferenceController extends BasePreferenceC
|
|||||||
Set<String> shortcutTargets = getShortcutTargets();
|
Set<String> shortcutTargets = getShortcutTargets();
|
||||||
@ShortcutConstants.UserShortcutType int shortcutType = getShortcutType();
|
@ShortcutConstants.UserShortcutType int shortcutType = getShortcutType();
|
||||||
|
|
||||||
|
if (Flags.a11yQsShortcut()) {
|
||||||
|
AccessibilityManager a11yManager = mContext.getSystemService(
|
||||||
|
AccessibilityManager.class);
|
||||||
|
if (a11yManager != null) {
|
||||||
|
a11yManager.enableShortcutsForTargets(enable, shortcutType, shortcutTargets,
|
||||||
|
UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
for (String target : shortcutTargets) {
|
for (String target : shortcutTargets) {
|
||||||
ShortcutUtils.optInValueToSettings(mContext, shortcutType, target);
|
ShortcutUtils.optInValueToSettings(mContext, shortcutType, target);
|
||||||
|
@@ -21,6 +21,7 @@ import static com.android.internal.accessibility.AccessibilityShortcutController
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import com.android.internal.accessibility.common.ShortcutConstants;
|
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -65,6 +66,9 @@ public abstract class SoftwareShortcutOptionPreferenceController
|
|||||||
@Override
|
@Override
|
||||||
protected void enableShortcutForTargets(boolean enable) {
|
protected void enableShortcutForTargets(boolean enable) {
|
||||||
super.enableShortcutForTargets(enable);
|
super.enableShortcutForTargets(enable);
|
||||||
|
if (Flags.a11yQsShortcut()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
// Update the A11y FAB size to large when the Magnification shortcut is enabled
|
// Update the A11y FAB size to large when the Magnification shortcut is enabled
|
||||||
|
@@ -21,6 +21,7 @@ import static com.android.internal.accessibility.AccessibilityShortcutController
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.icu.text.MessageFormat;
|
import android.icu.text.MessageFormat;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -105,6 +106,11 @@ public class TripleTapShortcutOptionController extends ShortcutOptionPreferenceC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enableShortcutForTargets(boolean enable) {
|
protected void enableShortcutForTargets(boolean enable) {
|
||||||
|
if (Flags.a11yQsShortcut()) {
|
||||||
|
super.enableShortcutForTargets(enable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
mContext.getContentResolver(),
|
mContext.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
||||||
|
@@ -36,17 +36,17 @@ import java.util.Set;
|
|||||||
* A controller handles displaying the two fingers double tap shortcut option preference and
|
* A controller handles displaying the two fingers double tap shortcut option preference and
|
||||||
* configuring the shortcut.
|
* configuring the shortcut.
|
||||||
*/
|
*/
|
||||||
public class TwoFingersDoubleTapShortcutOptionController
|
public class TwoFingerDoubleTapShortcutOptionController
|
||||||
extends ShortcutOptionPreferenceController {
|
extends ShortcutOptionPreferenceController {
|
||||||
|
|
||||||
public TwoFingersDoubleTapShortcutOptionController(Context context, String preferenceKey) {
|
public TwoFingerDoubleTapShortcutOptionController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ShortcutConstants.UserShortcutType
|
@ShortcutConstants.UserShortcutType
|
||||||
@Override
|
@Override
|
||||||
protected int getShortcutType() {
|
protected int getShortcutType() {
|
||||||
return ShortcutConstants.UserShortcutType.TRIPLETAP;
|
return ShortcutConstants.UserShortcutType.TWOFINGER_DOUBLETAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,6 +90,10 @@ public class TwoFingersDoubleTapShortcutOptionController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enableShortcutForTargets(boolean enable) {
|
protected void enableShortcutForTargets(boolean enable) {
|
||||||
|
if (android.view.accessibility.Flags.a11yQsShortcut()) {
|
||||||
|
super.enableShortcutForTargets(enable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
mContext.getContentResolver(),
|
mContext.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.accessibility.shortcuts;
|
package com.android.settings.accessibility.shortcuts;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -64,6 +65,10 @@ public class VolumeKeysShortcutOptionController extends ShortcutOptionPreference
|
|||||||
@Override
|
@Override
|
||||||
protected void enableShortcutForTargets(boolean enable) {
|
protected void enableShortcutForTargets(boolean enable) {
|
||||||
super.enableShortcutForTargets(enable);
|
super.enableShortcutForTargets(enable);
|
||||||
|
if (Flags.a11yQsShortcut()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
AccessibilityUtil.skipVolumeShortcutDialogTimeoutRestriction(mContext);
|
AccessibilityUtil.skipVolumeShortcutDialogTimeoutRestriction(mContext);
|
||||||
}
|
}
|
||||||
|
@@ -98,7 +98,20 @@ public final class AccessibilityGestureNavigationTutorialTest {
|
|||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void createTutorialPages_turnOnTwoFingerTripleTapShortcut_hasOnePage() {
|
public void createTutorialPages_turnOnTwoFingerTripleTapShortcut_hasOnePage() {
|
||||||
mShortcutTypes |= UserShortcutType.TWOFINGERTRIPLETAP;
|
mShortcutTypes |= UserShortcutType.TWOFINGER_DOUBLETAP;
|
||||||
|
|
||||||
|
final AlertDialog alertDialog =
|
||||||
|
createAccessibilityTutorialDialog(mContext, mShortcutTypes);
|
||||||
|
|
||||||
|
assertThat(createShortcutTutorialPages(mContext,
|
||||||
|
mShortcutTypes)).hasSize(/* expectedSize= */ 1);
|
||||||
|
assertThat(alertDialog).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void createTutorialPages_turnOnQuickSettingShortcut_hasOnePage() {
|
||||||
|
mShortcutTypes |= UserShortcutType.QUICK_SETTINGS;
|
||||||
|
|
||||||
final AlertDialog alertDialog =
|
final AlertDialog alertDialog =
|
||||||
createAccessibilityTutorialDialog(mContext, mShortcutTypes);
|
createAccessibilityTutorialDialog(mContext, mShortcutTypes);
|
||||||
|
@@ -28,15 +28,24 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Application;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.icu.text.CaseMap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.annotations.EnableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -46,9 +55,14 @@ import androidx.preference.PreferenceManager;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsActivity;
|
||||||
|
import com.android.settings.SubSettings;
|
||||||
|
import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment;
|
||||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
@@ -60,13 +74,14 @@ import org.robolectric.annotation.Config;
|
|||||||
import org.robolectric.shadow.api.Shadow;
|
import org.robolectric.shadow.api.Shadow;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/** Tests for {@link AccessibilityShortcutPreferenceFragment} */
|
/** Tests for {@link AccessibilityShortcutPreferenceFragment} */
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
com.android.settings.testutils.shadow.ShadowFragment.class,
|
com.android.settings.testutils.shadow.ShadowFragment.class,
|
||||||
})
|
})
|
||||||
public class AccessibilityShortcutPreferenceFragmentTest {
|
public class AccessibilityShortcutPreferenceFragmentTest {
|
||||||
|
|
||||||
private static final String PLACEHOLDER_PACKAGE_NAME = "com.placeholder.example";
|
private static final String PLACEHOLDER_PACKAGE_NAME = "com.placeholder.example";
|
||||||
private static final String PLACEHOLDER_CLASS_NAME = PLACEHOLDER_PACKAGE_NAME + ".placeholder";
|
private static final String PLACEHOLDER_CLASS_NAME = PLACEHOLDER_PACKAGE_NAME + ".placeholder";
|
||||||
private static final String PLACEHOLDER_TILE_CLASS_NAME =
|
private static final String PLACEHOLDER_TILE_CLASS_NAME =
|
||||||
@@ -83,7 +98,8 @@ public class AccessibilityShortcutPreferenceFragmentTest {
|
|||||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
||||||
private static final String HARDWARE_SHORTCUT_KEY =
|
private static final String HARDWARE_SHORTCUT_KEY =
|
||||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
private TestAccessibilityShortcutPreferenceFragment mFragment;
|
private TestAccessibilityShortcutPreferenceFragment mFragment;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
private Context mContext = ApplicationProvider.getApplicationContext();
|
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
@@ -206,6 +222,7 @@ public class AccessibilityShortcutPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void restoreValueFromSavedInstanceState_showTooltipView() {
|
public void restoreValueFromSavedInstanceState_showTooltipView() {
|
||||||
mContext.setTheme(androidx.appcompat.R.style.Theme_AppCompat);
|
mContext.setTheme(androidx.appcompat.R.style.Theme_AppCompat);
|
||||||
@@ -222,6 +239,15 @@ public class AccessibilityShortcutPreferenceFragmentTest {
|
|||||||
assertThat(getLatestPopupWindow().isShowing()).isTrue();
|
assertThat(getLatestPopupWindow().isShowing()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
@Config(shadows = ShadowFragment.class)
|
||||||
|
public void showQuickSettingsTooltipIfNeeded_qsFlagOn_dontShowTooltipView() {
|
||||||
|
mFragment.showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||||
|
|
||||||
|
assertThat(getLatestPopupWindow()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void showGeneralCategory_shouldInitCategory() {
|
public void showGeneralCategory_shouldInitCategory() {
|
||||||
@@ -238,6 +264,50 @@ public class AccessibilityShortcutPreferenceFragmentTest {
|
|||||||
assertThat(mFragment.getGeneralCategoryDescription(null)).isNotNull();
|
assertThat(mFragment.getGeneralCategoryDescription(null)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(com.android.settings.accessibility.Flags.FLAG_EDIT_SHORTCUTS_IN_FULL_SCREEN)
|
||||||
|
public void onSettingsClicked_editShortcutsFullScreenFlagOn_showFullScreenEditShortcutScreen() {
|
||||||
|
Activity activity = Robolectric.setupActivity(FragmentActivity.class);
|
||||||
|
when(mFragment.getContext()).thenReturn(activity);
|
||||||
|
Context context = mFragment.getContext();
|
||||||
|
final ShortcutPreference shortcutPreference =
|
||||||
|
new ShortcutPreference(context, /* attrs= */ null);
|
||||||
|
|
||||||
|
mFragment.onSettingsClicked(shortcutPreference);
|
||||||
|
|
||||||
|
Intent intent = shadowOf(
|
||||||
|
(Application) context.getApplicationContext()).getNextStartedActivity();
|
||||||
|
assertThat(intent).isNotNull();
|
||||||
|
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||||
|
assertThat(intent.getComponent()).isEqualTo(
|
||||||
|
new ComponentName(context, SubSettings.class));
|
||||||
|
assertThat(intent.getExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||||
|
.isEqualTo(EditShortcutsPreferenceFragment.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void getShortcutTypeSummary_shortcutSummaryIsCorrectlySet() {
|
||||||
|
final PreferredShortcut userPreferredShortcut = new PreferredShortcut(
|
||||||
|
PLACEHOLDER_COMPONENT_NAME.flattenToString(),
|
||||||
|
UserShortcutType.HARDWARE | UserShortcutType.QUICK_SETTINGS);
|
||||||
|
putUserShortcutTypeIntoSharedPreference(mContext, userPreferredShortcut);
|
||||||
|
final ShortcutPreference shortcutPreference =
|
||||||
|
new ShortcutPreference(mContext, /* attrs= */ null);
|
||||||
|
shortcutPreference.setChecked(true);
|
||||||
|
shortcutPreference.setSettingsEditable(true);
|
||||||
|
mFragment.mShortcutPreference = shortcutPreference;
|
||||||
|
String expected = CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(),
|
||||||
|
/* iter= */ null,
|
||||||
|
mContext.getString(
|
||||||
|
R.string.accessibility_feature_shortcut_setting_summary_quick_settings)
|
||||||
|
+ ", "
|
||||||
|
+ mContext.getString(R.string.accessibility_shortcut_hardware_keyword));
|
||||||
|
|
||||||
|
String summary = mFragment.getShortcutTypeSummary(mContext).toString();
|
||||||
|
assertThat(summary).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
private void callEmptyOnClicked(DialogInterface dialog, int which) {}
|
private void callEmptyOnClicked(DialogInterface dialog, int which) {}
|
||||||
|
|
||||||
private void putStringIntoSettings(String key, String componentName) {
|
private void putStringIntoSettings(String key, String componentName) {
|
||||||
|
@@ -18,6 +18,10 @@ package com.android.settings.accessibility;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -25,20 +29,30 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.annotations.EnableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||||
|
import com.android.settings.testutils.AccessibilityTestUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -55,14 +69,18 @@ public final class AccessibilityUtilTest {
|
|||||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
||||||
private static final String HARDWARE_SHORTCUT_KEY =
|
private static final String HARDWARE_SHORTCUT_KEY =
|
||||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
||||||
|
private static final String QUICK_SETTINGS_SHORTCUT_KEY =
|
||||||
|
Settings.Secure.ACCESSIBILITY_QS_TARGETS;
|
||||||
|
|
||||||
private static final String PLACEHOLDER_SETTING_FEATURE = "placeholderSettingFeature";
|
private static final String PLACEHOLDER_SETTING_FEATURE = "placeholderSettingFeature";
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -151,11 +169,12 @@ public final class AccessibilityUtilTest {
|
|||||||
public void getUserShortcutTypeFromSettings_putOneValue_hasValue() {
|
public void getUserShortcutTypeFromSettings_putOneValue_hasValue() {
|
||||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
final int shortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
final int shortcutTypes = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||||
MOCK_COMPONENT_NAME);
|
MOCK_COMPONENT_NAME);
|
||||||
|
|
||||||
assertThat(
|
assertThat(shortcutTypes).isEqualTo(
|
||||||
(shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE).isTrue();
|
UserShortcutType.SOFTWARE
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -163,16 +182,34 @@ public final class AccessibilityUtilTest {
|
|||||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
setShortcut(UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
|
setShortcut(UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
final int shortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
final int shortcutTypes = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||||
MOCK_COMPONENT_NAME);
|
MOCK_COMPONENT_NAME);
|
||||||
|
|
||||||
assertThat(
|
assertThat(shortcutTypes).isEqualTo(
|
||||||
(shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE).isTrue();
|
UserShortcutType.SOFTWARE
|
||||||
assertThat(
|
| UserShortcutType.HARDWARE
|
||||||
(shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE).isTrue();
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void getUserShortcutTypeFromSettings_threeShortcutTypesChosen() {
|
||||||
|
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
setShortcut(UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
setShortcut(UserShortcutType.QUICK_SETTINGS, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
|
final int shortcutTypes = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||||
|
MOCK_COMPONENT_NAME);
|
||||||
|
|
||||||
|
assertThat(shortcutTypes).isEqualTo(
|
||||||
|
UserShortcutType.SOFTWARE
|
||||||
|
| UserShortcutType.HARDWARE
|
||||||
|
| UserShortcutType.QUICK_SETTINGS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optInAllValuesToSettings_optInValue_haveMatchString() {
|
public void optInAllValuesToSettings_optInValue_haveMatchString() {
|
||||||
clearShortcuts();
|
clearShortcuts();
|
||||||
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE;
|
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE;
|
||||||
@@ -187,6 +224,24 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void optInAllValuesToSettings_optInValue_callsA11yManager() {
|
||||||
|
AccessibilityManager a11yManager =
|
||||||
|
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
|
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE
|
||||||
|
| UserShortcutType.QUICK_SETTINGS;
|
||||||
|
|
||||||
|
AccessibilityUtil.optInAllValuesToSettings(mContext, shortcutTypes, MOCK_COMPONENT_NAME);
|
||||||
|
|
||||||
|
verify(a11yManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true, shortcutTypes,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verifyNoMoreInteractions(a11yManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optInValueToSettings_optInValue_haveMatchString() {
|
public void optInValueToSettings_optInValue_haveMatchString() {
|
||||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
@@ -199,6 +254,23 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void optInValueToSettings_optInValue_callsA11yManager() {
|
||||||
|
AccessibilityManager a11yManager =
|
||||||
|
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
|
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME2.flattenToString());
|
||||||
|
|
||||||
|
AccessibilityUtil.optInValueToSettings(
|
||||||
|
mContext, UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME2);
|
||||||
|
|
||||||
|
verify(a11yManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true, UserShortcutType.HARDWARE,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verifyNoMoreInteractions(a11yManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optInValueToSettings_optInTwoValues_haveMatchString() {
|
public void optInValueToSettings_optInTwoValues_haveMatchString() {
|
||||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
@@ -213,6 +285,7 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optOutAllValuesToSettings_optOutValue_emptyString() {
|
public void optOutAllValuesToSettings_optOutValue_emptyString() {
|
||||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
setShortcut(UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
|
setShortcut(UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
@@ -227,6 +300,27 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void optOutAllValuesToSettings_optOutValue_callsA1yManager() {
|
||||||
|
AccessibilityManager a11yManager =
|
||||||
|
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
|
int shortcutTypes =
|
||||||
|
UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE
|
||||||
|
| UserShortcutType.QUICK_SETTINGS;
|
||||||
|
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
|
AccessibilityUtil.optOutAllValuesFromSettings(mContext, shortcutTypes,
|
||||||
|
MOCK_COMPONENT_NAME);
|
||||||
|
|
||||||
|
verify(a11yManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false,
|
||||||
|
shortcutTypes,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verifyNoMoreInteractions(a11yManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optOutValueFromSettings_optOutValue_emptyString() {
|
public void optOutValueFromSettings_optOutValue_emptyString() {
|
||||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
@@ -237,6 +331,7 @@ public final class AccessibilityUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optOutValueFromSettings_optOutValue_haveMatchString() {
|
public void optOutValueFromSettings_optOutValue_haveMatchString() {
|
||||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString(),
|
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString(),
|
||||||
MOCK_COMPONENT_NAME2.flattenToString());
|
MOCK_COMPONENT_NAME2.flattenToString());
|
||||||
@@ -248,6 +343,55 @@ public final class AccessibilityUtilTest {
|
|||||||
MOCK_COMPONENT_NAME.flattenToString());
|
MOCK_COMPONENT_NAME.flattenToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void optOutValueFromSettings_optOutValue_callsA11yManager() {
|
||||||
|
AccessibilityManager a11yManager =
|
||||||
|
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
|
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
|
AccessibilityUtil.optOutValueFromSettings(
|
||||||
|
mContext, UserShortcutType.QUICK_SETTINGS, MOCK_COMPONENT_NAME);
|
||||||
|
|
||||||
|
verify(a11yManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false, UserShortcutType.QUICK_SETTINGS,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verifyNoMoreInteractions(a11yManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convertKeyFromSettings_shortcutTypeSoftware() {
|
||||||
|
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.SOFTWARE))
|
||||||
|
.isEqualTo(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convertKeyFromSettings_shortcutTypeHardware() {
|
||||||
|
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.HARDWARE))
|
||||||
|
.isEqualTo(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convertKeyFromSettings_shortcutTypeTripleTap() {
|
||||||
|
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.TRIPLETAP))
|
||||||
|
.isEqualTo(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void convertKeyFromSettings_shortcutTypeMultiFingersMultiTap() {
|
||||||
|
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.TWOFINGER_DOUBLETAP))
|
||||||
|
.isEqualTo(
|
||||||
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void convertKeyFromSettings_shortcutTypeQuickSettings() {
|
||||||
|
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.QUICK_SETTINGS))
|
||||||
|
.isEqualTo(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
|
||||||
|
}
|
||||||
|
|
||||||
private AccessibilityServiceInfo getMockAccessibilityServiceInfo() {
|
private AccessibilityServiceInfo getMockAccessibilityServiceInfo() {
|
||||||
final ApplicationInfo applicationInfo = new ApplicationInfo();
|
final ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||||
final ServiceInfo serviceInfo = new ServiceInfo();
|
final ServiceInfo serviceInfo = new ServiceInfo();
|
||||||
@@ -287,12 +431,12 @@ public final class AccessibilityUtilTest {
|
|||||||
shortcutComponents.add(componentName);
|
shortcutComponents.add(componentName);
|
||||||
}
|
}
|
||||||
Settings.Secure.putString(mContext.getContentResolver(),
|
Settings.Secure.putString(mContext.getContentResolver(),
|
||||||
shortcutType == UserShortcutType.SOFTWARE ? SOFTWARE_SHORTCUT_KEY
|
ShortcutUtils.convertToKey(shortcutType), shortcutComponents.toString());
|
||||||
: HARDWARE_SHORTCUT_KEY, shortcutComponents.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearShortcuts() {
|
private void clearShortcuts() {
|
||||||
Settings.Secure.putString(mContext.getContentResolver(), SOFTWARE_SHORTCUT_KEY, "");
|
Settings.Secure.putString(mContext.getContentResolver(), SOFTWARE_SHORTCUT_KEY, "");
|
||||||
Settings.Secure.putString(mContext.getContentResolver(), HARDWARE_SHORTCUT_KEY, "");
|
Settings.Secure.putString(mContext.getContentResolver(), HARDWARE_SHORTCUT_KEY, "");
|
||||||
|
Settings.Secure.putString(mContext.getContentResolver(), QUICK_SETTINGS_SHORTCUT_KEY, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,10 +31,13 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
@@ -49,6 +52,7 @@ import com.android.settings.testutils.shadow.ShadowFragment;
|
|||||||
import com.android.settings.widget.SettingsMainSwitchPreference;
|
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
@@ -65,6 +69,8 @@ import java.util.List;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public class ToggleColorInversionPreferenceFragmentTest {
|
public class ToggleColorInversionPreferenceFragmentTest {
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
private TestToggleColorInversionPreferenceFragment mFragment;
|
private TestToggleColorInversionPreferenceFragment mFragment;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@@ -131,6 +137,7 @@ public class ToggleColorInversionPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void onPreferenceToggled_colorCorrectDisabled_shouldReturnTrueAndShowTooltipView() {
|
public void onPreferenceToggled_colorCorrectDisabled_shouldReturnTrueAndShowTooltipView() {
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, OFF);
|
Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, OFF);
|
||||||
|
@@ -35,10 +35,13 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
@@ -54,6 +57,7 @@ import com.android.settings.widget.SettingsMainSwitchPreference;
|
|||||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
@@ -70,6 +74,8 @@ import java.util.List;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public class ToggleDaltonizerPreferenceFragmentTest {
|
public class ToggleDaltonizerPreferenceFragmentTest {
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
private TestToggleDaltonizerPreferenceFragment mFragment;
|
private TestToggleDaltonizerPreferenceFragment mFragment;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@@ -154,6 +160,7 @@ public class ToggleDaltonizerPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void onPreferenceToggled_colorCorrectDisabled_shouldReturnTrueAndShowTooltipView() {
|
public void onPreferenceToggled_colorCorrectDisabled_shouldReturnTrueAndShowTooltipView() {
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, OFF);
|
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, OFF);
|
||||||
|
@@ -34,10 +34,11 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.icu.text.CaseMap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
import android.platform.test.annotations.DisableFlags;
|
||||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -76,6 +77,8 @@ import org.robolectric.annotation.LooperMode;
|
|||||||
import org.robolectric.shadow.api.Shadow;
|
import org.robolectric.shadow.api.Shadow;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/** Tests for {@link ToggleFeaturePreferenceFragment} */
|
/** Tests for {@link ToggleFeaturePreferenceFragment} */
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@LooperMode(LooperMode.Mode.LEGACY)
|
@LooperMode(LooperMode.Mode.LEGACY)
|
||||||
@@ -83,9 +86,8 @@ import org.robolectric.shadows.ShadowApplication;
|
|||||||
ShadowFragment.class,
|
ShadowFragment.class,
|
||||||
})
|
})
|
||||||
public class ToggleFeaturePreferenceFragmentTest {
|
public class ToggleFeaturePreferenceFragmentTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
private static final String PLACEHOLDER_PACKAGE_NAME = "com.placeholder.example";
|
private static final String PLACEHOLDER_PACKAGE_NAME = "com.placeholder.example";
|
||||||
private static final String PLACEHOLDER_CLASS_NAME = PLACEHOLDER_PACKAGE_NAME + ".placeholder";
|
private static final String PLACEHOLDER_CLASS_NAME = PLACEHOLDER_PACKAGE_NAME + ".placeholder";
|
||||||
@@ -295,6 +297,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void onPreferenceToggledOnEnabledService_showTooltipView() {
|
public void onPreferenceToggledOnEnabledService_showTooltipView() {
|
||||||
mFragment.onPreferenceToggled(
|
mFragment.onPreferenceToggled(
|
||||||
@@ -304,7 +307,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(com.android.settings.accessibility.Flags.FLAG_REMOVE_QS_TOOLTIP_IN_SUW)
|
@EnableFlags(com.android.settings.accessibility.Flags.FLAG_REMOVE_QS_TOOLTIP_IN_SUW)
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void onPreferenceToggledOnEnabledService_inSuw_toolTipViewShouldNotShow() {
|
public void onPreferenceToggledOnEnabledService_inSuw_toolTipViewShouldNotShow() {
|
||||||
Intent suwIntent = new Intent();
|
Intent suwIntent = new Intent();
|
||||||
@@ -318,6 +321,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() {
|
public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() {
|
||||||
mFragment.onPreferenceToggled(
|
mFragment.onPreferenceToggled(
|
||||||
@@ -348,7 +352,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
@EnableFlags(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
||||||
public void createAppInfoPreference_withValidComponentName() {
|
public void createAppInfoPreference_withValidComponentName() {
|
||||||
when(mPackageManager.isPackageAvailable(PLACEHOLDER_PACKAGE_NAME)).thenReturn(true);
|
when(mPackageManager.isPackageAvailable(PLACEHOLDER_PACKAGE_NAME)).thenReturn(true);
|
||||||
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||||
@@ -363,7 +367,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
@EnableFlags(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
||||||
public void createAppInfoPreference_noComponentName_shouldBeNull() {
|
public void createAppInfoPreference_noComponentName_shouldBeNull() {
|
||||||
mFragment.mComponentName = null;
|
mFragment.mComponentName = null;
|
||||||
|
|
||||||
@@ -373,7 +377,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
@EnableFlags(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
||||||
public void createAppInfoPreference_withUnavailablePackage_shouldBeNull() {
|
public void createAppInfoPreference_withUnavailablePackage_shouldBeNull() {
|
||||||
when(mPackageManager.isPackageAvailable(PLACEHOLDER_PACKAGE_NAME)).thenReturn(false);
|
when(mPackageManager.isPackageAvailable(PLACEHOLDER_PACKAGE_NAME)).thenReturn(false);
|
||||||
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||||
@@ -384,7 +388,7 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
@EnableFlags(Flags.FLAG_ACCESSIBILITY_SHOW_APP_INFO_BUTTON)
|
||||||
public void createAppInfoPreference_inSetupWizard_shouldBeNull() {
|
public void createAppInfoPreference_inSetupWizard_shouldBeNull() {
|
||||||
when(mFragment.isAnySetupWizard()).thenReturn(true);
|
when(mFragment.isAnySetupWizard()).thenReturn(true);
|
||||||
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||||
@@ -421,6 +425,40 @@ public class ToggleFeaturePreferenceFragmentTest {
|
|||||||
.isEqualTo(PLACEHOLDER_COMPONENT_NAME.flattenToString());
|
.isEqualTo(PLACEHOLDER_COMPONENT_NAME.flattenToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
@Config(shadows = ShadowFragment.class)
|
||||||
|
public void showQuickSettingsTooltipIfNeeded_qsFlagOn_dontShowTooltipView() {
|
||||||
|
mFragment.showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||||
|
|
||||||
|
assertThat(getLatestPopupWindow()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void getShortcutTypeSummary_shortcutSummaryIsCorrectlySet() {
|
||||||
|
final PreferredShortcut userPreferredShortcut = new PreferredShortcut(
|
||||||
|
PLACEHOLDER_COMPONENT_NAME.flattenToString(),
|
||||||
|
UserShortcutType.HARDWARE | UserShortcutType.QUICK_SETTINGS);
|
||||||
|
putUserShortcutTypeIntoSharedPreference(mContext, userPreferredShortcut);
|
||||||
|
final ShortcutPreference shortcutPreference =
|
||||||
|
new ShortcutPreference(mContext, /* attrs= */ null);
|
||||||
|
shortcutPreference.setChecked(true);
|
||||||
|
shortcutPreference.setSettingsEditable(true);
|
||||||
|
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
|
||||||
|
mFragment.mShortcutPreference = shortcutPreference;
|
||||||
|
String expected = CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(),
|
||||||
|
/* iter= */ null,
|
||||||
|
mContext.getString(
|
||||||
|
R.string.accessibility_feature_shortcut_setting_summary_quick_settings)
|
||||||
|
+ ", "
|
||||||
|
+ mContext.getString(R.string.accessibility_shortcut_hardware_keyword));
|
||||||
|
|
||||||
|
String summary = mFragment.getShortcutTypeSummary(mContext).toString();
|
||||||
|
|
||||||
|
assertThat(summary).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
private void putSecureStringIntoSettings(String key, String componentName) {
|
private void putSecureStringIntoSettings(String key, String componentName) {
|
||||||
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
|
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
@@ -39,13 +40,16 @@ import android.content.DialogInterface;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
|
import android.icu.text.CaseMap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
import android.os.UserHandle;
|
||||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
import android.platform.test.annotations.DisableFlags;
|
||||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -57,6 +61,7 @@ import com.android.settings.DialogCreatable;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
|
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
|
||||||
|
import com.android.settings.testutils.AccessibilityTestUtils;
|
||||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||||
import com.android.settings.testutils.shadow.ShadowStorageManager;
|
import com.android.settings.testutils.shadow.ShadowStorageManager;
|
||||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||||
@@ -80,6 +85,8 @@ import org.robolectric.util.ReflectionHelpers;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/** Tests for {@link ToggleScreenMagnificationPreferenceFragment}. */
|
/** Tests for {@link ToggleScreenMagnificationPreferenceFragment}. */
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -92,7 +99,7 @@ import java.util.List;
|
|||||||
public class ToggleScreenMagnificationPreferenceFragmentTest {
|
public class ToggleScreenMagnificationPreferenceFragmentTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
private static final String PLACEHOLDER_PACKAGE_NAME = "com.mock.example";
|
private static final String PLACEHOLDER_PACKAGE_NAME = "com.mock.example";
|
||||||
private static final String PLACEHOLDER_CLASS_NAME =
|
private static final String PLACEHOLDER_CLASS_NAME =
|
||||||
@@ -122,13 +129,15 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
|
|
||||||
private FragmentController<ToggleScreenMagnificationPreferenceFragment> mFragController;
|
private FragmentController<ToggleScreenMagnificationPreferenceFragment> mFragController;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private AccessibilityManager mAccessibilityManager;
|
||||||
private Resources mSpyResources;
|
private Resources mSpyResources;
|
||||||
private ShadowPackageManager mShadowPackageManager;
|
private ShadowPackageManager mShadowPackageManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUpTestFragment() {
|
public void setUpTestFragment() {
|
||||||
|
|
||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mAccessibilityManager = AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
|
|
||||||
// Set up the fragment that support window magnification feature
|
// Set up the fragment that support window magnification feature
|
||||||
mSpyResources = spy(mContext.getResources());
|
mSpyResources = spy(mContext.getResources());
|
||||||
@@ -319,26 +328,27 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void hasMagnificationValuesInSettings_twoFingerTripleTapIsOn_isTrue() {
|
public void hasMagnificationValuesInSettings_twoFingerTripleTapIsOn_isTrue() {
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
|
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
|
||||||
|
|
||||||
assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings(
|
assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings(
|
||||||
mContext, UserShortcutType.TWOFINGERTRIPLETAP)).isTrue();
|
mContext, UserShortcutType.TWOFINGER_DOUBLETAP)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void hasMagnificationValuesInSettings_twoFingerTripleTapIsOff_isFalse() {
|
public void hasMagnificationValuesInSettings_twoFingerTripleTapIsOff_isFalse() {
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF);
|
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF);
|
||||||
|
|
||||||
assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings(
|
assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings(
|
||||||
mContext, UserShortcutType.TWOFINGERTRIPLETAP)).isFalse();
|
mContext, UserShortcutType.TWOFINGER_DOUBLETAP)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optInAllValuesToSettings_optInValue_haveMatchString() {
|
public void optInAllValuesToSettings_optInValue_haveMatchString() {
|
||||||
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.TRIPLETAP;
|
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.TRIPLETAP;
|
||||||
|
|
||||||
@@ -351,9 +361,36 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void optInAllValuesToSettings_optInValue_callA11yManager() {
|
||||||
|
int shortcutTypes =
|
||||||
|
UserShortcutType.SOFTWARE | UserShortcutType.TRIPLETAP | UserShortcutType.HARDWARE
|
||||||
|
| UserShortcutType.QUICK_SETTINGS;
|
||||||
|
Set<String> shortcutTargets = Set.of(MAGNIFICATION_CONTROLLER_NAME);
|
||||||
|
|
||||||
|
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
|
||||||
|
shortcutTypes);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true, UserShortcutType.SOFTWARE,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true, UserShortcutType.HARDWARE,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true, UserShortcutType.QUICK_SETTINGS,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true, UserShortcutType.TRIPLETAP,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optInAllValuesToSettings_twoFingerTripleTap_haveMatchString() {
|
public void optInAllValuesToSettings_twoFingerTripleTap_haveMatchString() {
|
||||||
int shortcutTypes = UserShortcutType.TWOFINGERTRIPLETAP;
|
int shortcutTypes = UserShortcutType.TWOFINGER_DOUBLETAP;
|
||||||
|
|
||||||
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
|
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
|
||||||
shortcutTypes);
|
shortcutTypes);
|
||||||
@@ -363,6 +400,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optInAllValuesToSettings_existOtherValue_optInValue_haveMatchString() {
|
public void optInAllValuesToSettings_existOtherValue_optInValue_haveMatchString() {
|
||||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, PLACEHOLDER_COMPONENT_NAME.flattenToString());
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, PLACEHOLDER_COMPONENT_NAME.flattenToString());
|
||||||
|
|
||||||
@@ -374,6 +412,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optInAllValuesToSettings_software_sizeValueIsNull_putLargeSizeValue() {
|
public void optInAllValuesToSettings_software_sizeValueIsNull_putLargeSizeValue() {
|
||||||
ShadowSettings.ShadowSecure.reset();
|
ShadowSettings.ShadowSecure.reset();
|
||||||
|
|
||||||
@@ -441,6 +480,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optOutAllValuesToSettings_optOutValue_emptyString() {
|
public void optOutAllValuesToSettings_optOutValue_emptyString() {
|
||||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
||||||
putStringIntoSettings(HARDWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
putStringIntoSettings(HARDWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
||||||
@@ -457,19 +497,46 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void optOutAllValuesToSettings_optOutValue_callA11yManager() {
|
||||||
|
Set<String> shortcutTargets = Set.of(MAGNIFICATION_CONTROLLER_NAME);
|
||||||
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
||||||
|
putStringIntoSettings(HARDWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
||||||
|
setMagnificationTripleTapEnabled(/* enabled= */ true);
|
||||||
|
int shortcutTypes =
|
||||||
|
UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP;
|
||||||
|
|
||||||
|
ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings(
|
||||||
|
mContext, shortcutTypes);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false, UserShortcutType.SOFTWARE,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false, UserShortcutType.HARDWARE,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false, UserShortcutType.TRIPLETAP,
|
||||||
|
shortcutTargets, UserHandle.myUserId());
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optOutAllValuesToSettings_twoFingerTripleTap_settingsValueIsOff() {
|
public void optOutAllValuesToSettings_twoFingerTripleTap_settingsValueIsOff() {
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
|
TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
|
||||||
|
|
||||||
ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings(
|
ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings(
|
||||||
mContext, UserShortcutType.TWOFINGERTRIPLETAP);
|
mContext, UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
|
|
||||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON)).isEqualTo(OFF);
|
TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON)).isEqualTo(OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void optOutValueFromSettings_existOtherValue_optOutValue_haveMatchString() {
|
public void optOutValueFromSettings_existOtherValue_optOutValue_haveMatchString() {
|
||||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY,
|
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY,
|
||||||
PLACEHOLDER_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME);
|
PLACEHOLDER_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME);
|
||||||
@@ -526,7 +593,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void updateShortcutPreferenceData_hasTwoFingerTripleTapInSettings_assignToVariable() {
|
public void updateShortcutPreferenceData_hasTwoFingerTripleTapInSettings_assignToVariable() {
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
|
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
|
||||||
@@ -536,14 +603,14 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
|
|
||||||
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
|
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
|
||||||
MAGNIFICATION_CONTROLLER_NAME);
|
MAGNIFICATION_CONTROLLER_NAME);
|
||||||
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
|
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void updateShortcutPreferenceData_hasTwoFingerTripleTapInSharedPref_assignToVariable() {
|
public void updateShortcutPreferenceData_hasTwoFingerTripleTapInSharedPref_assignToVariable() {
|
||||||
final PreferredShortcut tripleTapShortcut = new PreferredShortcut(
|
final PreferredShortcut tripleTapShortcut = new PreferredShortcut(
|
||||||
MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.TWOFINGERTRIPLETAP);
|
MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
putUserShortcutTypeIntoSharedPreference(mContext, tripleTapShortcut);
|
putUserShortcutTypeIntoSharedPreference(mContext, tripleTapShortcut);
|
||||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||||
|
|
||||||
@@ -551,7 +618,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
|
|
||||||
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
|
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
|
||||||
MAGNIFICATION_CONTROLLER_NAME);
|
MAGNIFICATION_CONTROLLER_NAME);
|
||||||
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
|
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -590,7 +657,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void setupMagnificationEditShortcutDialog_twoFingerTripleTapOn_checkboxIsSavedValue() {
|
public void setupMagnificationEditShortcutDialog_twoFingerTripleTapOn_checkboxIsSavedValue() {
|
||||||
ToggleScreenMagnificationPreferenceFragment fragment =
|
ToggleScreenMagnificationPreferenceFragment fragment =
|
||||||
mFragController.create(R.id.main_content, /* bundle= */
|
mFragController.create(R.id.main_content, /* bundle= */
|
||||||
@@ -598,7 +665,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
final ShortcutPreference shortcutPreference = new ShortcutPreference(mContext, /* attrs= */
|
final ShortcutPreference shortcutPreference = new ShortcutPreference(mContext, /* attrs= */
|
||||||
null);
|
null);
|
||||||
final PreferredShortcut twoFingerTripleTapShortcut = new PreferredShortcut(
|
final PreferredShortcut twoFingerTripleTapShortcut = new PreferredShortcut(
|
||||||
MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.TWOFINGERTRIPLETAP);
|
MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
fragment.mShortcutPreference = shortcutPreference;
|
fragment.mShortcutPreference = shortcutPreference;
|
||||||
|
|
||||||
PreferredShortcuts.saveUserShortcutType(mContext, twoFingerTripleTapShortcut);
|
PreferredShortcuts.saveUserShortcutType(mContext, twoFingerTripleTapShortcut);
|
||||||
@@ -607,7 +674,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
createEditShortcutDialog(fragment.getActivity()));
|
createEditShortcutDialog(fragment.getActivity()));
|
||||||
|
|
||||||
final int checkboxValue = fragment.getShortcutTypeCheckBoxValue();
|
final int checkboxValue = fragment.getShortcutTypeCheckBoxValue();
|
||||||
assertThat(checkboxValue).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
|
assertThat(checkboxValue).isEqualTo(UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -632,10 +699,10 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void restoreValueFromSavedInstanceState_twoFingerTripleTap_assignToVariable() {
|
public void restoreValueFromSavedInstanceState_twoFingerTripleTap_assignToVariable() {
|
||||||
final Bundle fragmentState =
|
final Bundle fragmentState =
|
||||||
createFragmentSavedInstanceState(UserShortcutType.TWOFINGERTRIPLETAP);
|
createFragmentSavedInstanceState(UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
ToggleScreenMagnificationPreferenceFragment fragment = mFragController.get();
|
ToggleScreenMagnificationPreferenceFragment fragment = mFragController.get();
|
||||||
// Had to use reflection to pass the savedInstanceState when launching the fragment
|
// Had to use reflection to pass the savedInstanceState when launching the fragment
|
||||||
ReflectionHelpers.setField(fragment, "mSavedFragmentState", fragmentState);
|
ReflectionHelpers.setField(fragment, "mSavedFragmentState", fragmentState);
|
||||||
@@ -649,8 +716,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
|
|
||||||
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
|
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
|
||||||
MAGNIFICATION_CONTROLLER_NAME);
|
MAGNIFICATION_CONTROLLER_NAME);
|
||||||
assertThat(value).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
|
assertThat(value).isEqualTo(UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
|
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGER_DOUBLETAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -789,7 +856,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void getSummary_magnificationGestureEnabled_returnShortcutOnWithSummary() {
|
public void getSummary_magnificationGestureEnabled_returnShortcutOnWithSummary() {
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
|
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
|
||||||
@@ -803,7 +870,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void getSummary_magnificationGestureDisabled_returnShortcutOffWithSummary() {
|
public void getSummary_magnificationGestureDisabled_returnShortcutOffWithSummary() {
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF);
|
mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF);
|
||||||
@@ -817,6 +884,33 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
|||||||
mContext.getText(R.string.magnification_feature_summary)));
|
mContext.getText(R.string.magnification_feature_summary)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void getShortcutTypeSummary_shortcutSummaryIsCorrectlySet() {
|
||||||
|
final PreferredShortcut userPreferredShortcut = new PreferredShortcut(
|
||||||
|
MAGNIFICATION_CONTROLLER_NAME,
|
||||||
|
UserShortcutType.HARDWARE | UserShortcutType.QUICK_SETTINGS);
|
||||||
|
putUserShortcutTypeIntoSharedPreference(mContext, userPreferredShortcut);
|
||||||
|
final ShortcutPreference shortcutPreference =
|
||||||
|
new ShortcutPreference(mContext, /* attrs= */ null);
|
||||||
|
shortcutPreference.setChecked(true);
|
||||||
|
shortcutPreference.setSettingsEditable(true);
|
||||||
|
ToggleScreenMagnificationPreferenceFragment fragment =
|
||||||
|
mFragController.create(R.id.main_content, /* bundle= */
|
||||||
|
null).start().resume().get();
|
||||||
|
fragment.mShortcutPreference = shortcutPreference;
|
||||||
|
String expected = CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(),
|
||||||
|
/* iter= */ null,
|
||||||
|
mContext.getString(
|
||||||
|
R.string.accessibility_feature_shortcut_setting_summary_quick_settings)
|
||||||
|
+ ", "
|
||||||
|
+ mContext.getString(R.string.accessibility_shortcut_hardware_keyword));
|
||||||
|
|
||||||
|
String summary = fragment.getShortcutTypeSummary(mContext).toString();
|
||||||
|
|
||||||
|
assertThat(summary).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
private void putStringIntoSettings(String key, String componentName) {
|
private void putStringIntoSettings(String key, String componentName) {
|
||||||
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
|
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
|
||||||
}
|
}
|
||||||
|
@@ -86,7 +86,10 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* Tests for {@link EditShortcutsPreferenceFragment}
|
* Tests for {@link EditShortcutsPreferenceFragment}
|
||||||
*/
|
*/
|
||||||
@Config(shadows = SettingsShadowResources.class)
|
@Config(shadows = {
|
||||||
|
SettingsShadowResources.class,
|
||||||
|
com.android.settings.testutils.shadow.ShadowAccessibilityManager.class
|
||||||
|
})
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class EditShortcutsPreferenceFragmentTest {
|
public class EditShortcutsPreferenceFragmentTest {
|
||||||
private static final int METRICS_CATEGORY = 123;
|
private static final int METRICS_CATEGORY = 123;
|
||||||
@@ -99,7 +102,8 @@ public class EditShortcutsPreferenceFragmentTest {
|
|||||||
@Rule
|
@Rule
|
||||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
private FragmentActivity mActivity;
|
private FragmentActivity mActivity;
|
||||||
private FragmentScenario<EditShortcutsPreferenceFragment> mFragmentScenario;
|
private FragmentScenario<EditShortcutsPreferenceFragment> mFragmentScenario;
|
||||||
|
|
||||||
@@ -291,7 +295,7 @@ public class EditShortcutsPreferenceFragmentTest {
|
|||||||
mFragmentScenario.onFragment(fragment -> {
|
mFragmentScenario.onFragment(fragment -> {
|
||||||
TwoStatePreference preference = fragment.findPreference(
|
TwoStatePreference preference = fragment.findPreference(
|
||||||
mContext.getString(
|
mContext.getString(
|
||||||
R.string.accessibility_shortcut_two_fingers_double_tap_pref));
|
R.string.accessibility_shortcut_two_finger_double_tap_pref));
|
||||||
assertThat(preference.isChecked()).isTrue();
|
assertThat(preference.isChecked()).isTrue();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -476,7 +480,26 @@ public class EditShortcutsPreferenceFragmentTest {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onQuickSettingsShortcutSettingChanged_preferredShortcutsUpdated() {
|
||||||
|
mFragmentScenario = createFragScenario(/* isInSuw= */ false);
|
||||||
|
mFragmentScenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
int currentPreferredShortcut =
|
||||||
|
PreferredShortcuts.retrieveUserShortcutType(mContext, TARGET);
|
||||||
|
assertThat(currentPreferredShortcut
|
||||||
|
& ShortcutConstants.UserShortcutType.QUICK_SETTINGS).isEqualTo(0);
|
||||||
|
|
||||||
|
ShortcutUtils.optInValueToSettings(
|
||||||
|
mContext, ShortcutConstants.UserShortcutType.QUICK_SETTINGS, TARGET);
|
||||||
|
|
||||||
|
// Calls onFragment so that the change to Setting is notified to its observer
|
||||||
|
mFragmentScenario.onFragment(fragment ->
|
||||||
|
assertThat(
|
||||||
|
PreferredShortcuts.retrieveUserShortcutType(
|
||||||
|
mContext, TARGET)
|
||||||
|
).isEqualTo(ShortcutConstants.UserShortcutType.QUICK_SETTINGS)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private void assertLaunchSubSettingWithCurrentTargetComponents(
|
private void assertLaunchSubSettingWithCurrentTargetComponents(
|
||||||
String componentName, boolean isInSuw) {
|
String componentName, boolean isInSuw) {
|
||||||
|
@@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility.shortcuts;
|
package com.android.settings.accessibility.shortcuts;
|
||||||
|
|
||||||
|
import static com.android.settings.testutils.AccessibilityTestUtils.setupMockAccessibilityManager;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -148,8 +149,7 @@ public class GestureShortcutOptionControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enableTouchExploration(boolean enable) {
|
private void enableTouchExploration(boolean enable) {
|
||||||
AccessibilityManager am = mock(AccessibilityManager.class);
|
AccessibilityManager am = setupMockAccessibilityManager(mContext);
|
||||||
when(mContext.getSystemService(AccessibilityManager.class)).thenReturn(am);
|
|
||||||
when(am.isTouchExplorationEnabled()).thenReturn(enable);
|
when(am.isTouchExplorationEnabled()).thenReturn(enable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,180 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.accessibility.shortcuts;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.annotations.EnableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||||
|
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||||
|
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 java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link QuickSettingsShortcutOptionController}
|
||||||
|
*/
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class QuickSettingsShortcutOptionControllerTest {
|
||||||
|
private static final String PREF_KEY = "prefKey";
|
||||||
|
private static final ComponentName TARGET = new ComponentName("FakePackage", "FakeClass");
|
||||||
|
private static final String TARGET_FLATTEN = TARGET.flattenToString();
|
||||||
|
private static final ComponentName TARGET_TILE =
|
||||||
|
new ComponentName("FakePackage", "FakeTileClass");
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
|
private final Context mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
private QuickSettingsShortcutOptionController mController;
|
||||||
|
private ShortcutOptionPreference mShortcutOptionPreference;
|
||||||
|
private AccessibilityManager mAccessibilityManager;
|
||||||
|
|
||||||
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
SettingsShadowResources.overrideResource(
|
||||||
|
com.android.internal.R.bool.config_quickSettingsSupported, true);
|
||||||
|
mAccessibilityManager = AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
|
mController = new QuickSettingsShortcutOptionController(
|
||||||
|
mContext, PREF_KEY);
|
||||||
|
mController.setShortcutTargets(Set.of(TARGET_FLATTEN));
|
||||||
|
mShortcutOptionPreference = new ShortcutOptionPreference(mContext);
|
||||||
|
mShortcutOptionPreference.setKey(PREF_KEY);
|
||||||
|
mPreferenceScreen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
|
||||||
|
mPreferenceScreen.addPreference(mShortcutOptionPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_verifyScreenTextSet() {
|
||||||
|
mController.displayPreference(mPreferenceScreen);
|
||||||
|
|
||||||
|
assertThat(mShortcutOptionPreference.getTitle().toString()).isEqualTo(
|
||||||
|
mContext.getString(
|
||||||
|
R.string.accessibility_shortcut_edit_dialog_title_quick_settings));
|
||||||
|
assertThat(mShortcutOptionPreference.getSummary().toString()).isEqualTo(
|
||||||
|
mContext.getString(
|
||||||
|
R.string.accessibility_shortcut_edit_dialog_summary_quick_settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void isShortcutAvailable_a11yQsShortcutFlagDisabled_returnsFalse() {
|
||||||
|
assertThat(mController.isShortcutAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void isShortcutAvailable_qsNotSupported_returnsFalse() {
|
||||||
|
SettingsShadowResources.overrideResource(
|
||||||
|
com.android.internal.R.bool.config_quickSettingsSupported, false);
|
||||||
|
|
||||||
|
assertThat(mController.isShortcutAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void isShortcutAvailable_qsTileProvided_returnsTrue() {
|
||||||
|
when(mAccessibilityManager.getA11yFeatureToTileMap(UserHandle.myUserId()))
|
||||||
|
.thenReturn(Map.of(TARGET, TARGET_TILE));
|
||||||
|
|
||||||
|
assertThat(mController.isShortcutAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void isShortcutAvailable_qsTileNotProvided_returnsFalse() {
|
||||||
|
when(mAccessibilityManager.getA11yFeatureToTileMap(UserHandle.myUserId()))
|
||||||
|
.thenReturn(Collections.emptyMap());
|
||||||
|
|
||||||
|
assertThat(mController.isShortcutAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void isShortcutAvailable_qsTileProvided_invalidUseCase_returnFalse() {
|
||||||
|
AccessibilityServiceInfo mockStandardA11yService =
|
||||||
|
AccessibilityTestUtils.createAccessibilityServiceInfo(
|
||||||
|
mContext, TARGET, /* isAlwaysOnService= */ false);
|
||||||
|
when(mAccessibilityManager.getA11yFeatureToTileMap(UserHandle.myUserId()))
|
||||||
|
.thenReturn(Map.of(TARGET, TARGET_TILE));
|
||||||
|
// setup target as a standard a11y service
|
||||||
|
when(mAccessibilityManager.getInstalledAccessibilityServiceList())
|
||||||
|
.thenReturn(List.of(mockStandardA11yService));
|
||||||
|
|
||||||
|
assertThat(mController.isShortcutAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void isShortcutAvailable_qsTileProvided_validUseCase_returnTrue() {
|
||||||
|
AccessibilityServiceInfo mockAlwaysOnA11yService =
|
||||||
|
AccessibilityTestUtils.createAccessibilityServiceInfo(
|
||||||
|
mContext, TARGET, /* isAlwaysOnService= */ true);
|
||||||
|
when(mAccessibilityManager.getA11yFeatureToTileMap(UserHandle.myUserId()))
|
||||||
|
.thenReturn(Map.of(TARGET, TARGET_TILE));
|
||||||
|
// setup target as a always-on a11y service
|
||||||
|
when(mAccessibilityManager.getInstalledAccessibilityServiceList())
|
||||||
|
.thenReturn(List.of(mockAlwaysOnA11yService));
|
||||||
|
|
||||||
|
|
||||||
|
assertThat(mController.isShortcutAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChecked_targetUseQsShortcut_returnTrue() {
|
||||||
|
ShortcutUtils.optInValueToSettings(
|
||||||
|
mContext, ShortcutConstants.UserShortcutType.QUICK_SETTINGS, TARGET_FLATTEN);
|
||||||
|
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChecked_targetNotUseQsShortcut_returnFalse() {
|
||||||
|
ShortcutUtils.optOutValueFromSettings(
|
||||||
|
mContext, ShortcutConstants.UserShortcutType.QUICK_SETTINGS, TARGET_FLATTEN);
|
||||||
|
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
@@ -22,6 +22,8 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
@@ -30,14 +32,15 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.os.UserHandle;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.platform.test.annotations.DisableFlags;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.os.Build;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
@@ -48,18 +51,18 @@ import com.android.settings.SettingsActivity;
|
|||||||
import com.android.settings.SubSettings;
|
import com.android.settings.SubSettings;
|
||||||
import com.android.settings.accessibility.AccessibilityButtonFragment;
|
import com.android.settings.accessibility.AccessibilityButtonFragment;
|
||||||
import com.android.settings.accessibility.FloatingMenuSizePreferenceController;
|
import com.android.settings.accessibility.FloatingMenuSizePreferenceController;
|
||||||
|
import com.android.settings.testutils.AccessibilityTestUtils;
|
||||||
import com.android.settings.utils.AnnotationSpan;
|
import com.android.settings.utils.AnnotationSpan;
|
||||||
import com.android.settingslib.accessibility.AccessibilityUtils;
|
import com.android.settingslib.accessibility.AccessibilityUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.Shadows;
|
import org.robolectric.Shadows;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -77,18 +80,23 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
new ComponentName("FakePackage", "StandardA11yService");
|
new ComponentName("FakePackage", "StandardA11yService");
|
||||||
private static final String SOFTWARE_SHORTCUT_SETTING_NAME =
|
private static final String SOFTWARE_SHORTCUT_SETTING_NAME =
|
||||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private AccessibilityManager mAccessibilityManager;
|
||||||
private TestSoftwareShortcutOptionPreferenceController mController;
|
private TestSoftwareShortcutOptionPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = spy(Robolectric.buildActivity(FragmentActivity.class).get());
|
mContext = spy(Robolectric.buildActivity(FragmentActivity.class).get());
|
||||||
|
mAccessibilityManager = AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
|
|
||||||
AccessibilityServiceInfo mAlwaysOnServiceInfo = createAccessibilityServiceInfo(
|
AccessibilityServiceInfo mAlwaysOnServiceInfo =
|
||||||
TARGET_ALWAYS_ON_A11Y_SERVICE, /* isAlwaysOnService= */ true);
|
AccessibilityTestUtils.createAccessibilityServiceInfo(
|
||||||
AccessibilityServiceInfo mStandardServiceInfo = createAccessibilityServiceInfo(
|
mContext, TARGET_ALWAYS_ON_A11Y_SERVICE, /* isAlwaysOnService= */ true);
|
||||||
TARGET_STANDARD_A11Y_SERVICE, /* isAlwaysOnService= */ false);
|
AccessibilityServiceInfo mStandardServiceInfo =
|
||||||
|
AccessibilityTestUtils.createAccessibilityServiceInfo(
|
||||||
|
mContext, TARGET_STANDARD_A11Y_SERVICE, /* isAlwaysOnService= */ false);
|
||||||
AccessibilityManager am = mock(AccessibilityManager.class);
|
AccessibilityManager am = mock(AccessibilityManager.class);
|
||||||
when(mContext.getSystemService(Context.ACCESSIBILITY_SERVICE)).thenReturn(am);
|
when(mContext.getSystemService(Context.ACCESSIBILITY_SERVICE)).thenReturn(am);
|
||||||
when(am.getInstalledAccessibilityServiceList()).thenReturn(
|
when(am.getInstalledAccessibilityServiceList()).thenReturn(
|
||||||
@@ -170,6 +178,7 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_enableShortcut_shortcutTurnedOn() {
|
public void enableShortcutForTargets_enableShortcut_shortcutTurnedOn() {
|
||||||
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
|
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
|
||||||
mController.setShortcutTargets(Set.of(target));
|
mController.setShortcutTargets(Set.of(target));
|
||||||
@@ -185,6 +194,27 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void enableShortcutForTargets_enableShortcut_callA11yManager() {
|
||||||
|
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
|
||||||
|
mController.setShortcutTargets(Set.of(target));
|
||||||
|
assertThat(ShortcutUtils.isComponentIdExistingInSettings(
|
||||||
|
mContext, ShortcutConstants.UserShortcutType.SOFTWARE, target
|
||||||
|
)).isFalse();
|
||||||
|
|
||||||
|
mController.enableShortcutForTargets(true);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true,
|
||||||
|
ShortcutConstants.UserShortcutType.SOFTWARE,
|
||||||
|
Set.of(target),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_disableShortcut_shortcutTurnedOff() {
|
public void enableShortcutForTargets_disableShortcut_shortcutTurnedOff() {
|
||||||
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
|
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
|
||||||
ShortcutUtils.optInValueToSettings(
|
ShortcutUtils.optInValueToSettings(
|
||||||
@@ -202,6 +232,29 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void enableShortcutForTargets_disableShortcut_callA11yManager() {
|
||||||
|
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
|
||||||
|
ShortcutUtils.optInValueToSettings(
|
||||||
|
mContext, ShortcutConstants.UserShortcutType.SOFTWARE, target);
|
||||||
|
assertThat(ShortcutUtils.isComponentIdExistingInSettings(
|
||||||
|
mContext, ShortcutConstants.UserShortcutType.SOFTWARE, target
|
||||||
|
)).isTrue();
|
||||||
|
mController.setShortcutTargets(Set.of(target));
|
||||||
|
|
||||||
|
mController.enableShortcutForTargets(false);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false,
|
||||||
|
ShortcutConstants.UserShortcutType.SOFTWARE,
|
||||||
|
Set.of(target),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_enableShortcutWithMagnification_menuSizeIncreased() {
|
public void enableShortcutForTargets_enableShortcutWithMagnification_menuSizeIncreased() {
|
||||||
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
|
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
|
||||||
|
|
||||||
@@ -216,6 +269,7 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_enableShortcutWithMagnification_userConfigureSmallMenuSize_menuSizeNotChanged() {
|
public void enableShortcutForTargets_enableShortcutWithMagnification_userConfigureSmallMenuSize_menuSizeNotChanged() {
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
|
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
|
||||||
@@ -233,6 +287,7 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_enableAlwaysOnServiceShortcut_turnsOnAlwaysOnService() {
|
public void enableShortcutForTargets_enableAlwaysOnServiceShortcut_turnsOnAlwaysOnService() {
|
||||||
mController.setShortcutTargets(
|
mController.setShortcutTargets(
|
||||||
Set.of(TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString()));
|
Set.of(TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString()));
|
||||||
@@ -244,6 +299,7 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_disableAlwaysOnServiceShortcut_turnsOffAlwaysOnService() {
|
public void enableShortcutForTargets_disableAlwaysOnServiceShortcut_turnsOffAlwaysOnService() {
|
||||||
mController.setShortcutTargets(
|
mController.setShortcutTargets(
|
||||||
Set.of(TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString()));
|
Set.of(TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString()));
|
||||||
@@ -255,6 +311,7 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_enableStandardServiceShortcut_wontTurnOnService() {
|
public void enableShortcutForTargets_enableStandardServiceShortcut_wontTurnOnService() {
|
||||||
mController.setShortcutTargets(
|
mController.setShortcutTargets(
|
||||||
Set.of(TARGET_STANDARD_A11Y_SERVICE.flattenToString()));
|
Set.of(TARGET_STANDARD_A11Y_SERVICE.flattenToString()));
|
||||||
@@ -266,6 +323,7 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_disableStandardServiceShortcutWithServiceOn_wontTurnOffService() {
|
public void enableShortcutForTargets_disableStandardServiceShortcutWithServiceOn_wontTurnOffService() {
|
||||||
mController.setShortcutTargets(
|
mController.setShortcutTargets(
|
||||||
Set.of(TARGET_STANDARD_A11Y_SERVICE.flattenToString()));
|
Set.of(TARGET_STANDARD_A11Y_SERVICE.flattenToString()));
|
||||||
@@ -288,32 +346,6 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
|
|||||||
assertThat(intent.getExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(page);
|
assertThat(intent.getExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccessibilityServiceInfo createAccessibilityServiceInfo(
|
|
||||||
ComponentName componentName, boolean isAlwaysOnService) {
|
|
||||||
final ApplicationInfo applicationInfo = new ApplicationInfo();
|
|
||||||
applicationInfo.targetSdkVersion = Build.VERSION_CODES.R;
|
|
||||||
final ServiceInfo serviceInfo = new ServiceInfo();
|
|
||||||
applicationInfo.packageName = componentName.getPackageName();
|
|
||||||
serviceInfo.packageName = componentName.getPackageName();
|
|
||||||
serviceInfo.name = componentName.getClassName();
|
|
||||||
serviceInfo.applicationInfo = applicationInfo;
|
|
||||||
|
|
||||||
final ResolveInfo resolveInfo = new ResolveInfo();
|
|
||||||
resolveInfo.serviceInfo = serviceInfo;
|
|
||||||
try {
|
|
||||||
final AccessibilityServiceInfo info = new AccessibilityServiceInfo(resolveInfo,
|
|
||||||
mContext);
|
|
||||||
info.setComponentName(componentName);
|
|
||||||
if (isAlwaysOnService) {
|
|
||||||
info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON;
|
|
||||||
}
|
|
||||||
return info;
|
|
||||||
} catch (XmlPullParserException | IOException e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class TestSoftwareShortcutOptionPreferenceController
|
private static class TestSoftwareShortcutOptionPreferenceController
|
||||||
extends SoftwareShortcutOptionPreferenceController {
|
extends SoftwareShortcutOptionPreferenceController {
|
||||||
|
|
||||||
|
@@ -21,19 +21,32 @@ import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_U
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.icu.text.MessageFormat;
|
import android.icu.text.MessageFormat;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.annotations.EnableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.accessibility.AccessibilityUtil;
|
import com.android.settings.accessibility.AccessibilityUtil;
|
||||||
|
import com.android.settings.testutils.AccessibilityTestUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
@@ -50,13 +63,17 @@ public class TripleTapShortcutOptionControllerTest {
|
|||||||
"com.android.server.accessibility.MagnificationController";
|
"com.android.server.accessibility.MagnificationController";
|
||||||
private static final String TARGET_FAKE =
|
private static final String TARGET_FAKE =
|
||||||
new ComponentName("FakePackage", "FakeClass").flattenToString();
|
new ComponentName("FakePackage", "FakeClass").flattenToString();
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
private final Context mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
private TripleTapShortcutOptionController mController;
|
private TripleTapShortcutOptionController mController;
|
||||||
private ShortcutOptionPreference mShortcutOptionPreference;
|
private ShortcutOptionPreference mShortcutOptionPreference;
|
||||||
|
private AccessibilityManager mAccessibilityManager;
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
mAccessibilityManager = AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
mController = new TripleTapShortcutOptionController(mContext, PREF_KEY);
|
mController = new TripleTapShortcutOptionController(mContext, PREF_KEY);
|
||||||
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
|
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
|
||||||
mShortcutOptionPreference = new ShortcutOptionPreference(mContext);
|
mShortcutOptionPreference = new ShortcutOptionPreference(mContext);
|
||||||
@@ -147,19 +164,26 @@ public class TripleTapShortcutOptionControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_tripleTapConfigured_returnTrue() {
|
public void isChecked_tripleTapConfigured_returnTrue() {
|
||||||
mController.enableShortcutForTargets(true);
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
||||||
|
AccessibilityUtil.State.ON);
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
assertThat(mController.isChecked()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_tripleTapNotConfigured_returnFalse() {
|
public void isChecked_tripleTapNotConfigured_returnFalse() {
|
||||||
mController.enableShortcutForTargets(false);
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
||||||
|
AccessibilityUtil.State.OFF);
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
assertThat(mController.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_enableShortcut_settingUpdated() {
|
public void enableShortcutForTargets_enableShortcut_settingUpdated() {
|
||||||
mController.enableShortcutForTargets(true);
|
mController.enableShortcutForTargets(true);
|
||||||
|
|
||||||
@@ -172,6 +196,21 @@ public class TripleTapShortcutOptionControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void enableShortcutForTargets_enableShortcut_callA11yManager() {
|
||||||
|
mController.enableShortcutForTargets(true);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true,
|
||||||
|
ShortcutConstants.UserShortcutType.TRIPLETAP,
|
||||||
|
Set.of(TARGET_MAGNIFICATION),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_disableShortcut_settingUpdated() {
|
public void enableShortcutForTargets_disableShortcut_settingUpdated() {
|
||||||
mController.enableShortcutForTargets(false);
|
mController.enableShortcutForTargets(false);
|
||||||
|
|
||||||
@@ -182,4 +221,18 @@ public class TripleTapShortcutOptionControllerTest {
|
|||||||
AccessibilityUtil.State.OFF)
|
AccessibilityUtil.State.OFF)
|
||||||
).isEqualTo(AccessibilityUtil.State.OFF);
|
).isEqualTo(AccessibilityUtil.State.OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void enableShortcutForTargets_disableShortcut_callA11yManager() {
|
||||||
|
mController.enableShortcutForTargets(false);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false,
|
||||||
|
ShortcutConstants.UserShortcutType.TRIPLETAP,
|
||||||
|
Set.of(TARGET_MAGNIFICATION),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,22 +18,29 @@ package com.android.settings.accessibility.shortcuts;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.icu.text.MessageFormat;
|
import android.icu.text.MessageFormat;
|
||||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
import android.os.UserHandle;
|
||||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
import android.platform.test.annotations.DisableFlags;
|
||||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||||
import com.android.server.accessibility.Flags;
|
import com.android.server.accessibility.Flags;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.accessibility.AccessibilityUtil;
|
import com.android.settings.accessibility.AccessibilityUtil;
|
||||||
|
import com.android.settings.testutils.AccessibilityTestUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -44,26 +51,28 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link TwoFingersDoubleTapShortcutOptionController}
|
* Tests for {@link TwoFingerDoubleTapShortcutOptionController}
|
||||||
*/
|
*/
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class TwoFingersDoubleTapShortcutOptionControllerTest {
|
public class TwoFingerDoubleTapShortcutOptionControllerTest {
|
||||||
private static final String PREF_KEY = "prefKey";
|
private static final String PREF_KEY = "prefKey";
|
||||||
private static final String TARGET_MAGNIFICATION =
|
private static final String TARGET_MAGNIFICATION =
|
||||||
"com.android.server.accessibility.MagnificationController";
|
"com.android.server.accessibility.MagnificationController";
|
||||||
private static final String TARGET_FAKE =
|
private static final String TARGET_FAKE =
|
||||||
new ComponentName("FakePackage", "FakeClass").flattenToString();
|
new ComponentName("FakePackage", "FakeClass").flattenToString();
|
||||||
@Rule
|
@Rule
|
||||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
private TwoFingersDoubleTapShortcutOptionController mController;
|
private AccessibilityManager mAccessibilityManager;
|
||||||
|
private TwoFingerDoubleTapShortcutOptionController mController;
|
||||||
private ShortcutOptionPreference mShortcutOptionPreference;
|
private ShortcutOptionPreference mShortcutOptionPreference;
|
||||||
|
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mController = new TwoFingersDoubleTapShortcutOptionController(mContext, PREF_KEY);
|
mAccessibilityManager = AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
|
mController = new TwoFingerDoubleTapShortcutOptionController(mContext, PREF_KEY);
|
||||||
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
|
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
|
||||||
mShortcutOptionPreference = new ShortcutOptionPreference(mContext);
|
mShortcutOptionPreference = new ShortcutOptionPreference(mContext);
|
||||||
mShortcutOptionPreference.setKey(PREF_KEY);
|
mShortcutOptionPreference.setKey(PREF_KEY);
|
||||||
@@ -84,30 +93,30 @@ public class TwoFingersDoubleTapShortcutOptionControllerTest {
|
|||||||
2));
|
2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresFlagsDisabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void isShortcutAvailable_featureFlagTurnedOff_returnFalse() {
|
public void isShortcutAvailable_featureFlagTurnedOff_returnFalse() {
|
||||||
assertThat(mController.isShortcutAvailable()).isFalse();
|
assertThat(mController.isShortcutAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void isShortcutAvailable_multipleTargets_returnFalse() {
|
public void isShortcutAvailable_multipleTargets_returnFalse() {
|
||||||
mController.setShortcutTargets(Set.of(TARGET_FAKE, TARGET_MAGNIFICATION));
|
mController.setShortcutTargets(Set.of(TARGET_FAKE, TARGET_MAGNIFICATION));
|
||||||
|
|
||||||
assertThat(mController.isShortcutAvailable()).isFalse();
|
assertThat(mController.isShortcutAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void isShortcutAvailable_magnificationTargetOnly_returnTrue() {
|
public void isShortcutAvailable_magnificationTargetOnly_returnTrue() {
|
||||||
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
|
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
|
||||||
|
|
||||||
assertThat(mController.isShortcutAvailable()).isTrue();
|
assertThat(mController.isShortcutAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
|
||||||
public void isShortcutAvailable_nonMagnificationTarget_returnFalse() {
|
public void isShortcutAvailable_nonMagnificationTarget_returnFalse() {
|
||||||
mController.setShortcutTargets(Set.of(TARGET_FAKE));
|
mController.setShortcutTargets(Set.of(TARGET_FAKE));
|
||||||
|
|
||||||
@@ -116,19 +125,26 @@ public class TwoFingersDoubleTapShortcutOptionControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_twoFingersDoubleTapConfigured_returnTrue() {
|
public void isChecked_twoFingersDoubleTapConfigured_returnTrue() {
|
||||||
mController.enableShortcutForTargets(true);
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
||||||
|
AccessibilityUtil.State.ON);
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
assertThat(mController.isChecked()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_twoFingersDoubleTapNotConfigured_returnFalse() {
|
public void isChecked_twoFingersDoubleTapNotConfigured_returnFalse() {
|
||||||
mController.enableShortcutForTargets(false);
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
||||||
|
AccessibilityUtil.State.OFF);
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
assertThat(mController.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_enableShortcut_settingUpdated() {
|
public void enableShortcutForTargets_enableShortcut_settingUpdated() {
|
||||||
mController.enableShortcutForTargets(true);
|
mController.enableShortcutForTargets(true);
|
||||||
|
|
||||||
@@ -141,6 +157,21 @@ public class TwoFingersDoubleTapShortcutOptionControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void enableShortcutForTargets_enableShortcut_callA11yManager() {
|
||||||
|
mController.enableShortcutForTargets(true);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true,
|
||||||
|
ShortcutConstants.UserShortcutType.TWOFINGER_DOUBLETAP,
|
||||||
|
Set.of(TARGET_MAGNIFICATION),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_disableShortcut_settingUpdated() {
|
public void enableShortcutForTargets_disableShortcut_settingUpdated() {
|
||||||
mController.enableShortcutForTargets(false);
|
mController.enableShortcutForTargets(false);
|
||||||
|
|
||||||
@@ -151,4 +182,18 @@ public class TwoFingersDoubleTapShortcutOptionControllerTest {
|
|||||||
AccessibilityUtil.State.OFF)
|
AccessibilityUtil.State.OFF)
|
||||||
).isEqualTo(AccessibilityUtil.State.OFF);
|
).isEqualTo(AccessibilityUtil.State.OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void enableShortcutForTargets_disableShortcut_callA11yManager() {
|
||||||
|
mController.enableShortcutForTargets(false);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false,
|
||||||
|
ShortcutConstants.UserShortcutType.TWOFINGER_DOUBLETAP,
|
||||||
|
Set.of(TARGET_MAGNIFICATION),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -18,8 +18,18 @@ package com.android.settings.accessibility.shortcuts;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.annotations.EnableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -28,8 +38,10 @@ import androidx.test.core.app.ApplicationProvider;
|
|||||||
import com.android.internal.accessibility.common.ShortcutConstants;
|
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||||
import com.android.internal.accessibility.util.ShortcutUtils;
|
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.testutils.AccessibilityTestUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
@@ -45,7 +57,11 @@ public class VolumeKeysShortcutOptionControllerTest {
|
|||||||
private static final String PREF_KEY = "prefKey";
|
private static final String PREF_KEY = "prefKey";
|
||||||
private static final String TARGET =
|
private static final String TARGET =
|
||||||
new ComponentName("FakePackage", "FakeClass").flattenToString();
|
new ComponentName("FakePackage", "FakeClass").flattenToString();
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
|
private final Context mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
private AccessibilityManager mAccessibilityManager;
|
||||||
private VolumeKeysShortcutOptionController mController;
|
private VolumeKeysShortcutOptionController mController;
|
||||||
private ShortcutOptionPreference mShortcutOptionPreference;
|
private ShortcutOptionPreference mShortcutOptionPreference;
|
||||||
|
|
||||||
@@ -53,6 +69,7 @@ public class VolumeKeysShortcutOptionControllerTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
mAccessibilityManager = AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||||
mController = new VolumeKeysShortcutOptionController(
|
mController = new VolumeKeysShortcutOptionController(
|
||||||
mContext, PREF_KEY);
|
mContext, PREF_KEY);
|
||||||
mController.setShortcutTargets(Set.of(TARGET));
|
mController.setShortcutTargets(Set.of(TARGET));
|
||||||
@@ -94,6 +111,7 @@ public class VolumeKeysShortcutOptionControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_enableVolumeKeysShortcut_shortcutSet() {
|
public void enableShortcutForTargets_enableVolumeKeysShortcut_shortcutSet() {
|
||||||
mController.enableShortcutForTargets(true);
|
mController.enableShortcutForTargets(true);
|
||||||
|
|
||||||
@@ -103,6 +121,21 @@ public class VolumeKeysShortcutOptionControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void enableShortcutForTargets_enableVolumeKeysShortcut_callA11yManager() {
|
||||||
|
mController.enableShortcutForTargets(true);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ true,
|
||||||
|
ShortcutConstants.UserShortcutType.HARDWARE,
|
||||||
|
Set.of(TARGET),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
public void enableShortcutForTargets_disableVolumeKeysShortcut_shortcutNotSet() {
|
public void enableShortcutForTargets_disableVolumeKeysShortcut_shortcutNotSet() {
|
||||||
mController.enableShortcutForTargets(false);
|
mController.enableShortcutForTargets(false);
|
||||||
|
|
||||||
@@ -110,4 +143,18 @@ public class VolumeKeysShortcutOptionControllerTest {
|
|||||||
ShortcutUtils.isComponentIdExistingInSettings(
|
ShortcutUtils.isComponentIdExistingInSettings(
|
||||||
mContext, ShortcutConstants.UserShortcutType.HARDWARE, TARGET)).isFalse();
|
mContext, ShortcutConstants.UserShortcutType.HARDWARE, TARGET)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void enableShortcutForTargets_disableVolumeKeysShortcut_callA11yManager() {
|
||||||
|
mController.enableShortcutForTargets(false);
|
||||||
|
|
||||||
|
verify(mAccessibilityManager).enableShortcutsForTargets(
|
||||||
|
/* enable= */ false,
|
||||||
|
ShortcutConstants.UserShortcutType.HARDWARE,
|
||||||
|
Set.of(TARGET),
|
||||||
|
UserHandle.myUserId()
|
||||||
|
);
|
||||||
|
verifyNoMoreInteractions(mAccessibilityManager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,11 +20,25 @@ import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATIN
|
|||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.os.Build;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for common methods used in the accessibility feature related tests
|
* Utility class for common methods used in the accessibility feature related tests
|
||||||
*/
|
*/
|
||||||
@@ -47,4 +61,39 @@ public class AccessibilityTestUtils {
|
|||||||
NAV_BAR_MODE_3BUTTON);
|
NAV_BAR_MODE_3BUTTON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a mock {@link AccessibilityManager}
|
||||||
|
*/
|
||||||
|
public static AccessibilityManager setupMockAccessibilityManager(Context mockContext) {
|
||||||
|
AccessibilityManager am = mock(AccessibilityManager.class);
|
||||||
|
when(mockContext.getSystemService(AccessibilityManager.class)).thenReturn(am);
|
||||||
|
return am;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccessibilityServiceInfo createAccessibilityServiceInfo(
|
||||||
|
Context context, ComponentName componentName, boolean isAlwaysOnService) {
|
||||||
|
final ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||||
|
applicationInfo.targetSdkVersion = Build.VERSION_CODES.R;
|
||||||
|
final ServiceInfo serviceInfo = new ServiceInfo();
|
||||||
|
applicationInfo.packageName = componentName.getPackageName();
|
||||||
|
serviceInfo.packageName = componentName.getPackageName();
|
||||||
|
serviceInfo.name = componentName.getClassName();
|
||||||
|
serviceInfo.applicationInfo = applicationInfo;
|
||||||
|
|
||||||
|
final ResolveInfo resolveInfo = new ResolveInfo();
|
||||||
|
resolveInfo.serviceInfo = serviceInfo;
|
||||||
|
try {
|
||||||
|
final AccessibilityServiceInfo info = new AccessibilityServiceInfo(resolveInfo,
|
||||||
|
context);
|
||||||
|
info.setComponentName(componentName);
|
||||||
|
if (isAlwaysOnService) {
|
||||||
|
info.flags |= AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON;
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
} catch (XmlPullParserException | IOException e) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.testutils.shadow;
|
||||||
|
|
||||||
|
import android.annotation.UserIdInt;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shadow of {@link AccessibilityManager} with the hidden methods
|
||||||
|
*/
|
||||||
|
@Implements(AccessibilityManager.class)
|
||||||
|
public class ShadowAccessibilityManager extends org.robolectric.shadows.ShadowAccessibilityManager {
|
||||||
|
/**
|
||||||
|
* Implements a hidden method {@link AccessibilityManager.getA11yFeatureToTileMap} and returns
|
||||||
|
* an empty map.
|
||||||
|
*/
|
||||||
|
@Implementation
|
||||||
|
public Map<ComponentName, ComponentName> getA11yFeatureToTileMap(@UserIdInt int userId) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
}
|
@@ -25,16 +25,22 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
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.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.internal.accessibility.common.ShortcutConstants;
|
import com.android.internal.accessibility.common.ShortcutConstants;
|
||||||
|
import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType;
|
||||||
import com.android.internal.accessibility.util.ShortcutUtils;
|
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@@ -54,7 +60,8 @@ public class PreferredShortcutsTest {
|
|||||||
CLASS_NAME_2);
|
CLASS_NAME_2);
|
||||||
private static final ContentResolver sContentResolver =
|
private static final ContentResolver sContentResolver =
|
||||||
ApplicationProvider.getApplicationContext().getContentResolver();
|
ApplicationProvider.getApplicationContext().getContentResolver();
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -166,11 +173,48 @@ public class PreferredShortcutsTest {
|
|||||||
.isEqualTo(target2ShortcutTypes);
|
.isEqualTo(target2ShortcutTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void updatePreferredShortcutFromSettings_colorInversionWithQsAndSoftwareShortcut_preferredShortcutsMatches() {
|
||||||
|
String target = COLOR_INVERSION_COMPONENT_NAME.flattenToString();
|
||||||
|
Settings.Secure.putString(sContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, target);
|
||||||
|
Settings.Secure.putString(sContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_QS_TARGETS, target);
|
||||||
|
|
||||||
|
PreferredShortcuts.updatePreferredShortcutsFromSettings(mContext, Set.of(target));
|
||||||
|
|
||||||
|
int savedPreferredShortcut = PreferredShortcuts.retrieveUserShortcutType(
|
||||||
|
mContext, target);
|
||||||
|
assertThat(savedPreferredShortcut).isEqualTo(
|
||||||
|
UserShortcutType.SOFTWARE | UserShortcutType.QUICK_SETTINGS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||||
|
public void updatePreferredShortcutFromSettings_colorInversionWithQsAndHardwareShortcut_qsShortcutNotSaved() {
|
||||||
|
String target = COLOR_INVERSION_COMPONENT_NAME.flattenToString();
|
||||||
|
Settings.Secure.putString(sContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, target);
|
||||||
|
Settings.Secure.putString(sContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_QS_TARGETS, target);
|
||||||
|
assertThat(!android.view.accessibility.Flags.a11yQsShortcut()).isTrue();
|
||||||
|
|
||||||
|
PreferredShortcuts.updatePreferredShortcutsFromSettings(mContext, Set.of(target));
|
||||||
|
|
||||||
|
int savedPreferredShortcut = PreferredShortcuts.retrieveUserShortcutType(
|
||||||
|
mContext, target);
|
||||||
|
assertThat(savedPreferredShortcut).isEqualTo(UserShortcutType.HARDWARE);
|
||||||
|
}
|
||||||
|
|
||||||
private static void clearShortcuts() {
|
private static void clearShortcuts() {
|
||||||
Settings.Secure.putString(sContentResolver,
|
Settings.Secure.putString(sContentResolver,
|
||||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "");
|
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "");
|
||||||
Settings.Secure.putString(sContentResolver,
|
Settings.Secure.putString(sContentResolver,
|
||||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, "");
|
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, "");
|
||||||
|
Settings.Secure.putString(sContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_QS_TARGETS, "");
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
sContentResolver,
|
sContentResolver,
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
|
||||||
@@ -179,5 +223,7 @@ public class PreferredShortcutsTest {
|
|||||||
sContentResolver,
|
sContentResolver,
|
||||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
|
||||||
AccessibilityUtil.State.OFF);
|
AccessibilityUtil.State.OFF);
|
||||||
|
|
||||||
|
PreferredShortcuts.clearPreferredShortcuts(ApplicationProvider.getApplicationContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user