From bd26b3a43e57577e430979148b73132f4674f051 Mon Sep 17 00:00:00 2001 From: Vaibhav Devmurari Date: Fri, 19 Jan 2024 14:48:55 +0000 Subject: [PATCH 1/8] Add Slow keys A11Y settings to PK settings page Test: manual Bug: 294546335 Change-Id: I9e20973e648d04b907e4d2225bd49b78e42d2089 --- res/values/strings.xml | 4 ++ res/xml/physical_keyboard_settings.xml | 18 +++++--- .../inputmethod/PhysicalKeyboardFragment.java | 42 ++++++++++++++++++- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 8185828f2b7..8a56f1f087a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4285,6 +4285,10 @@ Bounce keys Enable Bounce keys for physical keyboard accessibility + + Slow keys + + Enable Slow keys for physical keyboard accessibility Sticky keys diff --git a/res/xml/physical_keyboard_settings.xml b/res/xml/physical_keyboard_settings.xml index dc424d19875..b95f23ee763 100644 --- a/res/xml/physical_keyboard_settings.xml +++ b/res/xml/physical_keyboard_settings.xml @@ -43,17 +43,23 @@ android:key="keyboard_a11y_category" android:title="@string/keyboard_a11y_category"> - - + + + + diff --git a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java index 7de505edbca..b06edb2957b 100644 --- a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java +++ b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java @@ -70,6 +70,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment private static final String KEYBOARD_A11Y_CATEGORY = "keyboard_a11y_category"; private static final String SHOW_VIRTUAL_KEYBOARD_SWITCH = "show_virtual_keyboard_switch"; private static final String ACCESSIBILITY_BOUNCE_KEYS = "accessibility_bounce_keys"; + private static final String ACCESSIBILITY_SLOW_KEYS = "accessibility_slow_keys"; private static final String ACCESSIBILITY_STICKY_KEYS = "accessibility_sticky_keys"; private static final String KEYBOARD_SHORTCUTS_HELPER = "keyboard_shortcuts_helper"; private static final String MODIFIER_KEYS_SETTINGS = "modifier_keys_settings"; @@ -78,6 +79,8 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment Secure.SHOW_IME_WITH_HARD_KEYBOARD); private static final Uri sAccessibilityBounceKeysUri = Secure.getUriFor( Secure.ACCESSIBILITY_BOUNCE_KEYS); + private static final Uri sAccessibilitySlowKeysUri = Secure.getUriFor( + Secure.ACCESSIBILITY_SLOW_KEYS); private static final Uri sAccessibilityStickyKeysUri = Secure.getUriFor( Secure.ACCESSIBILITY_STICKY_KEYS); @@ -97,6 +100,8 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment @Nullable private TwoStatePreference mAccessibilityBounceKeys = null; @Nullable + private TwoStatePreference mAccessibilitySlowKeys = null; + @Nullable private TwoStatePreference mAccessibilityStickyKeys = null; @@ -127,6 +132,8 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment mKeyboardA11yCategory = Objects.requireNonNull(findPreference(KEYBOARD_A11Y_CATEGORY)); mAccessibilityBounceKeys = Objects.requireNonNull( mKeyboardA11yCategory.findPreference(ACCESSIBILITY_BOUNCE_KEYS)); + mAccessibilitySlowKeys = Objects.requireNonNull( + mKeyboardA11yCategory.findPreference(ACCESSIBILITY_SLOW_KEYS)); mAccessibilityStickyKeys = Objects.requireNonNull( mKeyboardA11yCategory.findPreference(ACCESSIBILITY_STICKY_KEYS)); @@ -147,6 +154,9 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment if (!InputSettings.isAccessibilityBounceKeysFeatureEnabled()) { mKeyboardA11yCategory.removePreference(mAccessibilityBounceKeys); } + if (!InputSettings.isAccessibilitySlowKeysFeatureFlagEnabled()) { + mKeyboardA11yCategory.removePreference(mAccessibilitySlowKeys); + } if (!InputSettings.isAccessibilityStickyKeysFeatureEnabled()) { mKeyboardA11yCategory.removePreference(mAccessibilityStickyKeys); } @@ -196,6 +206,8 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment mShowVirtualKeyboardSwitchPreferenceChangeListener); Objects.requireNonNull(mAccessibilityBounceKeys).setOnPreferenceChangeListener( mAccessibilityBounceKeysSwitchPreferenceChangeListener); + Objects.requireNonNull(mAccessibilitySlowKeys).setOnPreferenceChangeListener( + mAccessibilitySlowKeysSwitchPreferenceChangeListener); Objects.requireNonNull(mAccessibilityStickyKeys).setOnPreferenceChangeListener( mAccessibilityStickyKeysSwitchPreferenceChangeListener); registerSettingsObserver(); @@ -208,6 +220,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment mIm.unregisterInputDeviceListener(this); Objects.requireNonNull(mShowVirtualKeyboardSwitch).setOnPreferenceChangeListener(null); Objects.requireNonNull(mAccessibilityBounceKeys).setOnPreferenceChangeListener(null); + Objects.requireNonNull(mAccessibilitySlowKeys).setOnPreferenceChangeListener(null); Objects.requireNonNull(mAccessibilityStickyKeys).setOnPreferenceChangeListener(null); unregisterSettingsObserver(); } @@ -315,10 +328,12 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment updateShowVirtualKeyboardSwitch(); if (InputSettings.isAccessibilityBounceKeysFeatureEnabled() - || InputSettings.isAccessibilityStickyKeysFeatureEnabled()) { + || InputSettings.isAccessibilityStickyKeysFeatureEnabled() + || InputSettings.isAccessibilitySlowKeysFeatureFlagEnabled()) { Objects.requireNonNull(mKeyboardA11yCategory).setOrder(2); preferenceScreen.addPreference(mKeyboardA11yCategory); updateAccessibilityBounceKeysSwitch(); + updateAccessibilitySlowKeysSwitch(); updateAccessibilityStickyKeysSwitch(); } } @@ -356,6 +371,13 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment mContentObserver, UserHandle.myUserId()); } + if (InputSettings.isAccessibilitySlowKeysFeatureFlagEnabled()) { + contentResolver.registerContentObserver( + sAccessibilitySlowKeysUri, + false, + mContentObserver, + UserHandle.myUserId()); + } if (InputSettings.isAccessibilityStickyKeysFeatureEnabled()) { contentResolver.registerContentObserver( sAccessibilityStickyKeysUri, @@ -365,6 +387,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment } updateShowVirtualKeyboardSwitch(); updateAccessibilityBounceKeysSwitch(); + updateAccessibilitySlowKeysSwitch(); updateAccessibilityStickyKeysSwitch(); } @@ -385,6 +408,14 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment InputSettings.isAccessibilityBounceKeysEnabled(getContext())); } + private void updateAccessibilitySlowKeysSwitch() { + if (!InputSettings.isAccessibilitySlowKeysFeatureFlagEnabled()) { + return; + } + Objects.requireNonNull(mAccessibilitySlowKeys).setChecked( + InputSettings.isAccessibilitySlowKeysEnabled(getContext())); + } + private void updateAccessibilityStickyKeysSwitch() { if (!InputSettings.isAccessibilityStickyKeysFeatureEnabled()) { return; @@ -413,6 +444,13 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment return true; }; + private final OnPreferenceChangeListener + mAccessibilitySlowKeysSwitchPreferenceChangeListener = (preference, newValue) -> { + InputSettings.setAccessibilitySlowKeysThreshold(getContext(), + ((Boolean) newValue) ? 500 : 0); + return true; + }; + private final OnPreferenceChangeListener mAccessibilityStickyKeysSwitchPreferenceChangeListener = (preference, newValue) -> { InputSettings.setAccessibilityStickyKeysEnabled(getContext(), (Boolean) newValue); @@ -426,6 +464,8 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment updateShowVirtualKeyboardSwitch(); } else if (sAccessibilityBounceKeysUri.equals(uri)) { updateAccessibilityBounceKeysSwitch(); + } else if (sAccessibilitySlowKeysUri.equals(uri)) { + updateAccessibilitySlowKeysSwitch(); } else if (sAccessibilityStickyKeysUri.equals(uri)) { updateAccessibilityStickyKeysSwitch(); } From 4e195505b981f8b2ad9cb72df46c8db4eacaf01c Mon Sep 17 00:00:00 2001 From: Riley Jones Date: Thu, 4 Jan 2024 00:06:18 +0000 Subject: [PATCH 2/8] Created a dedicated activity for EditShortcutsPreferenceFragment. This will allow it to be reached via intent. Test: Send an intent with the ACCESSIBILITY_SHORTCUT_SETTINGS action (make sure the "targets" fragment argument is populated with a string array of shortcut targets) Flag: None (Change adds definitions but no new behavior) Bug: 297583708 Change-Id: Ie0dd4918a4f38c04b781308f170b568af30bb238 --- AndroidManifest.xml | 15 +++++++++++++++ src/com/android/settings/Settings.java | 1 + .../EditShortcutsPreferenceFragment.java | 1 + .../settings/core/gateway/SettingsGateway.java | 2 ++ 4 files changed, 19 insertions(+) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4230b6a37a7..374851ea077 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2262,6 +2262,21 @@ android:value="true" /> + + + + + + + + + Date: Wed, 24 Jan 2024 06:09:11 +0000 Subject: [PATCH 3/8] Update the string for CSIP pairing dialogs Bug: 311226935 Change-Id: Ib85b7d0e78a4745408930f5939fedc9eb98b4063 Test: N/A --- res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 01979b24691..3c3bb521f6c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1743,7 +1743,7 @@ Pair with %1$s? - Add new member to the existing coordinated set + Confirm to add the second piece of your audio device Bluetooth pairing code @@ -1766,7 +1766,7 @@ You may also need to type this passkey on the other device. - Confirm to pair with the coordinated set + Confirm to pair with the audio device Allow access to your contacts and call history From 5ef53eafddb198dd4ee896f6e01d8f7f7fd6be17 Mon Sep 17 00:00:00 2001 From: Angela Wang Date: Wed, 24 Jan 2024 12:44:08 +0000 Subject: [PATCH 4/8] New flag "enable_hearing_aid_preset_control" Bug: 300015207 Test: m Change-Id: I126ef66d9477bbd7eb085e05fa4132c65e885beb --- aconfig/accessibility/accessibility_flags.aconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aconfig/accessibility/accessibility_flags.aconfig b/aconfig/accessibility/accessibility_flags.aconfig index 1c03a270ada..057a71a90ba 100644 --- a/aconfig/accessibility/accessibility_flags.aconfig +++ b/aconfig/accessibility/accessibility_flags.aconfig @@ -9,6 +9,12 @@ flag { bug: "300302098" } +flag { + name: "enable_hearing_aid_preset_control" + namespace: "accessibility" + description: "Allows users to control hearing aid preset in the Bluetooth device details page." + bug: "300015207" +} flag { name: "remove_qs_tooltip_in_suw" From a32d3cb21845efde3857023535cca7a971504450 Mon Sep 17 00:00:00 2001 From: Angela Wang Date: Wed, 24 Jan 2024 17:03:43 +0000 Subject: [PATCH 5/8] New flag "enable_hearing_aid_volume_offset_control" Bug: 301198830 Test: m Change-Id: I3ae8f9458f1f43f844b393d64fe10009e43ee664 --- aconfig/accessibility/accessibility_flags.aconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aconfig/accessibility/accessibility_flags.aconfig b/aconfig/accessibility/accessibility_flags.aconfig index 057a71a90ba..ad770fb512c 100644 --- a/aconfig/accessibility/accessibility_flags.aconfig +++ b/aconfig/accessibility/accessibility_flags.aconfig @@ -16,6 +16,13 @@ flag { bug: "300015207" } +flag { + name: "enable_hearing_aid_volume_offset_control" + namespace: "accessibility" + description: "Allows users to control hearing aid volume offset in the Bluetooth device details page." + bug: "301198830" +} + flag { name: "remove_qs_tooltip_in_suw" namespace: "accessibility" From 46086cbee08579c9c054f01b537329c7bd1a746c Mon Sep 17 00:00:00 2001 From: Fabien Sanglard Date: Wed, 24 Jan 2024 13:46:43 -0800 Subject: [PATCH 6/8] Document "Revoke USB debug authorizations" It is not clear why the button "Revoke USB debugging authorizations" may be missing from the Developer settings. This is only adding a line to explain why we don't display it. Test: NA Bug: NA Change-Id: Ie67e7a8142fc80d35016e0b43febf68d2c0354d1 --- .../settings/development/ClearAdbKeysPreferenceController.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/com/android/settings/development/ClearAdbKeysPreferenceController.java b/src/com/android/settings/development/ClearAdbKeysPreferenceController.java index b39d874432b..69e6c690e6e 100644 --- a/src/com/android/settings/development/ClearAdbKeysPreferenceController.java +++ b/src/com/android/settings/development/ClearAdbKeysPreferenceController.java @@ -52,6 +52,9 @@ public class ClearAdbKeysPreferenceController extends DeveloperOptionsPreference @Override public boolean isAvailable() { + // If the build is insecure (any -user build, 'ro.adb.secure=0'), adbd does not + // requests/store authorizations. There is no need for a "revoke authorizations" + // button. return AdbProperties.secure().orElse(false); } From 37704520779ef7b8df2cc82d0ac0ec0aa7d197a7 Mon Sep 17 00:00:00 2001 From: Massimo Carli Date: Thu, 18 Jan 2024 23:55:17 +0000 Subject: [PATCH 7/8] Use custom default font_scale behing flag When the flag is enabled, we read the default font scale value from the device_font_scale property in Settings. Flag: ACONFIG com.android.window.flags.configurable_font_scale_default DEVELOPMENT Bug: 316160749 Test: atest SettingsRoboTests:FontSizeDataTest Change-Id: I03a5ee9a2bd364dca9c75b131832e5f9e868167a --- .../android/settings/accessibility/FontSizeData.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/accessibility/FontSizeData.java b/src/com/android/settings/accessibility/FontSizeData.java index 1226d25b0e3..096710d89f3 100644 --- a/src/com/android/settings/accessibility/FontSizeData.java +++ b/src/com/android/settings/accessibility/FontSizeData.java @@ -25,6 +25,7 @@ import android.content.res.Resources; import android.provider.Settings; import com.android.settingslib.R; +import com.android.window.flags.Flags; import java.util.Arrays; import java.util.List; @@ -38,12 +39,11 @@ final class FontSizeData extends PreviewSizeData { FontSizeData(Context context) { super(context); - final Resources resources = getContext().getResources(); final ContentResolver resolver = getContext().getContentResolver(); final List strEntryValues = Arrays.asList(resources.getStringArray(R.array.entryvalues_font_size)); - setDefaultValue(FONT_SCALE_DEF_VALUE); + setDefaultValue(getFontScaleDefValue(resolver)); final float currentScale = Settings.System.getFloat(resolver, Settings.System.FONT_SCALE, getDefaultValue()); setInitialIndex(fontSizeValueToIndex(currentScale, strEntryValues.toArray(new String[0]))); @@ -78,4 +78,10 @@ final class FontSizeData extends PreviewSizeData { } return indices.length - 1; } + + private float getFontScaleDefValue(ContentResolver resolver) { + return Flags.configurableFontScaleDefault() ? Settings.System.getFloat(resolver, + Settings.System.DEFAULT_DEVICE_FONT_SCALE, FONT_SCALE_DEF_VALUE) + : FONT_SCALE_DEF_VALUE; + } } From 12b8d82376acf0e8c21caf0de6ca482bac21ac72 Mon Sep 17 00:00:00 2001 From: Yanting Yang Date: Wed, 24 Jan 2024 07:06:12 +0000 Subject: [PATCH 8/8] Support dynamic search index for App pinning Bug: 243899654 Test: manual & m RunSettingsRoboTests Change-Id: I5ae5b604894c53e0e816f7a244104321e22c12de --- .../security/ScreenPinningSettings.java | 41 +++++-- .../security/ScreenPinningSettingsTest.java | 113 ++++++++++++++++++ .../shadow/ShadowLockPatternUtils.java | 10 +- 3 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 tests/robotests/src/com/android/settings/security/ScreenPinningSettingsTest.java diff --git a/src/com/android/settings/security/ScreenPinningSettings.java b/src/com/android/settings/security/ScreenPinningSettings.java index 99d6492d1b9..8690847b4d0 100644 --- a/src/com/android/settings/security/ScreenPinningSettings.java +++ b/src/com/android/settings/security/ScreenPinningSettings.java @@ -22,6 +22,7 @@ import android.app.settings.SettingsEnums; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.res.Resources; import android.icu.text.MessageFormat; import android.os.Bundle; import android.os.UserHandle; @@ -30,6 +31,7 @@ import android.provider.Settings; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; +import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.preference.Preference; import androidx.preference.Preference.OnPreferenceChangeListener; @@ -45,7 +47,11 @@ import com.android.settings.password.ChooseLockSettingsHelper; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.SettingsMainSwitchBar; import com.android.settingslib.search.SearchIndexable; +import com.android.settingslib.search.SearchIndexableRaw; import com.android.settingslib.widget.FooterPreference; + +import java.util.List; + /** * Screen pinning settings. */ @@ -174,9 +180,8 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment } } - private int getCurrentSecurityTitle() { - int quality = mLockPatternUtils.getKeyguardStoredPasswordQuality( - UserHandle.myUserId()); + private static int getCurrentSecurityTitle(LockPatternUtils lockPatternUtils) { + int quality = lockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId()); switch (quality) { case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: @@ -187,7 +192,7 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment case DevicePolicyManager.PASSWORD_QUALITY_MANAGED: return R.string.screen_pinning_unlock_password; case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: - if (mLockPatternUtils.isLockPatternEnabled(UserHandle.myUserId())) { + if (lockPatternUtils.isLockPatternEnabled(UserHandle.myUserId())) { return R.string.screen_pinning_unlock_pattern; } } @@ -232,7 +237,7 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment } }); mUseScreenLock.setChecked(isScreenLockUsed()); - mUseScreenLock.setTitle(getCurrentSecurityTitle()); + mUseScreenLock.setTitle(getCurrentSecurityTitle(mLockPatternUtils)); } else { mFooterPreference.setSummary(getAppPinningContent()); mUseScreenLock.setEnabled(false); @@ -252,8 +257,30 @@ public class ScreenPinningSettings extends SettingsPreferenceFragment } /** - * For search + * For search. + * + * This page only provides an index for the toggle preference of using screen lock for + * unpinning. The preference name will change with various lock configurations. Indexing data + * from XML isn't suitable since it uses a static title by default. So, we skip XML indexing + * by omitting the XML argument in the constructor and use a dynamic index method instead. */ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider(R.xml.screen_pinning_settings); + new BaseSearchIndexProvider() { + + @NonNull + @Override + public List getDynamicRawDataToIndex(@NonNull Context context, + boolean enabled) { + List dynamicRaws = + super.getDynamicRawDataToIndex(context, enabled); + final SearchIndexableRaw raw = new SearchIndexableRaw(context); + final Resources res = context.getResources(); + final LockPatternUtils lockPatternUtils = new LockPatternUtils(context); + raw.key = KEY_USE_SCREEN_LOCK; + raw.title = res.getString(getCurrentSecurityTitle(lockPatternUtils)); + raw.screenTitle = res.getString(R.string.screen_pinning_title); + dynamicRaws.add(raw); + return dynamicRaws; + } + }; } diff --git a/tests/robotests/src/com/android/settings/security/ScreenPinningSettingsTest.java b/tests/robotests/src/com/android/settings/security/ScreenPinningSettingsTest.java new file mode 100644 index 00000000000..045ef65b634 --- /dev/null +++ b/tests/robotests/src/com/android/settings/security/ScreenPinningSettingsTest.java @@ -0,0 +1,113 @@ +/* + * 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.security; + +import static com.google.common.truth.Truth.assertThat; + +import android.app.admin.DevicePolicyManager; +import android.content.Context; +import android.os.UserHandle; + +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settings.testutils.shadow.ShadowLockPatternUtils; +import com.android.settingslib.search.SearchIndexableRaw; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +@Config(shadows = ShadowLockPatternUtils.class) +public class ScreenPinningSettingsTest { + + private Context mContext; + + @Before + public void setUp() { + mContext = ApplicationProvider.getApplicationContext(); + } + + @After + public void tearDown() { + ShadowLockPatternUtils.reset(); + } + + @Test + public void getDynamicRawDataToIndex_numericPassword_shouldIndexUnlockPinTitle() { + ShadowLockPatternUtils.setKeyguardStoredPasswordQuality( + DevicePolicyManager.PASSWORD_QUALITY_NUMERIC); + + final List indexRaws = + ScreenPinningSettings.SEARCH_INDEX_DATA_PROVIDER.getDynamicRawDataToIndex( + mContext, /* enabled= */ true); + + assertThat(indexRaws.size()).isEqualTo(1); + assertThat(indexRaws.get(0).title).isEqualTo( + mContext.getString(R.string.screen_pinning_unlock_pin)); + } + + @Test + public void getDynamicRawDataToIndex_alphabeticPassword_shouldIndexUnlockPasswordTitle() { + ShadowLockPatternUtils.setKeyguardStoredPasswordQuality( + DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC); + + final List indexRaws = + ScreenPinningSettings.SEARCH_INDEX_DATA_PROVIDER.getDynamicRawDataToIndex( + mContext, /* enabled= */ true); + + assertThat(indexRaws.size()).isEqualTo(1); + assertThat(indexRaws.get(0).title).isEqualTo( + mContext.getString(R.string.screen_pinning_unlock_password)); + } + + @Test + public void getDynamicRawDataToIndex_patternPassword_shouldIndexUnlockPatternTitle() { + ShadowLockPatternUtils.setKeyguardStoredPasswordQuality( + DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); + ShadowLockPatternUtils.setIsLockPatternEnabled( + UserHandle.myUserId(), /* isLockPatternEnabled= */ true); + + final List indexRaws = + ScreenPinningSettings.SEARCH_INDEX_DATA_PROVIDER.getDynamicRawDataToIndex( + mContext, /* enabled= */ true); + + assertThat(indexRaws.size()).isEqualTo(1); + assertThat(indexRaws.get(0).title).isEqualTo( + mContext.getString(R.string.screen_pinning_unlock_pattern)); + } + + @Test + public void getDynamicRawDataToIndex_nonePassword_shouldIndexUnlockNoneTitle() { + ShadowLockPatternUtils.setKeyguardStoredPasswordQuality( + DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); + + final List indexRaws = + ScreenPinningSettings.SEARCH_INDEX_DATA_PROVIDER.getDynamicRawDataToIndex( + mContext, /* enabled= */ true); + + assertThat(indexRaws.size()).isEqualTo(1); + assertThat(indexRaws.get(0).title).isEqualTo( + mContext.getString(R.string.screen_pinning_unlock_none)); + } +} diff --git a/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java index 0474f52117f..efea6fdeaaa 100644 --- a/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java +++ b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java @@ -50,6 +50,7 @@ public class ShadowLockPatternUtils { private static Map sUserToVisiblePatternEnabledMap = new HashMap<>(); private static Map sUserToBiometricAllowedMap = new HashMap<>(); private static Map sUserToLockPatternEnabledMap = new HashMap<>(); + private static Map sKeyguardStoredPasswordQualityMap = new HashMap<>(); private static boolean sIsUserOwnsFrpCredential; @@ -66,6 +67,7 @@ public class ShadowLockPatternUtils { sUserToLockPatternEnabledMap.clear(); sDeviceEncryptionEnabled = false; sIsUserOwnsFrpCredential = false; + sKeyguardStoredPasswordQualityMap.clear(); } @Implementation @@ -97,7 +99,7 @@ public class ShadowLockPatternUtils { @Implementation protected int getKeyguardStoredPasswordQuality(int userHandle) { - return 1; + return sKeyguardStoredPasswordQualityMap.getOrDefault(userHandle, /* defaultValue= */ 1); } @Implementation @@ -171,7 +173,7 @@ public class ShadowLockPatternUtils { @Implementation public boolean isLockPatternEnabled(int userId) { - return sUserToBiometricAllowedMap.getOrDefault(userId, false); + return sUserToLockPatternEnabledMap.getOrDefault(userId, false); } public static void setIsLockPatternEnabled(int userId, boolean isLockPatternEnabled) { @@ -238,4 +240,8 @@ public class ShadowLockPatternUtils { public boolean isSeparateProfileChallengeEnabled(int userHandle) { return false; } + + public static void setKeyguardStoredPasswordQuality(int quality) { + sKeyguardStoredPasswordQualityMap.put(UserHandle.myUserId(), quality); + } }