From 38ed880811b4d24cdc6b1f9a59661fef33ab0bdf Mon Sep 17 00:00:00 2001 From: Chun-Ku Lin Date: Wed, 15 Jan 2025 23:29:51 +0000 Subject: [PATCH 01/14] Partial flag clean up: Remove large mouse pointer in A11y Setting screen Customization on mouse pointer has been moved to other screen, which is released in 24Q4. Cleaning up the reference in a11y settings earlier for cleaner ColorAndMotionScreen catalyst migration. Bug: 346358375 Flag: EXEMPT partial clan up on android.view.flags.enable_vector_cursor_a11y_settings Test: build succeed Change-Id: Ie5c22f6cd1a55102240a86e13f17591e29ddbbf8 --- res/values/strings.xml | 4 - res/xml/accessibility_color_and_motion.xml | 7 -- .../accessibility/ColorAndMotionFragment.java | 7 -- .../LargePointerIconPreferenceController.java | 60 --------- ...gePointerIconPreferenceControllerTest.java | 114 ------------------ 5 files changed, 192 deletions(-) delete mode 100644 src/com/android/settings/accessibility/LargePointerIconPreferenceController.java delete mode 100644 tests/unit/src/com/android/settings/accessibility/LargePointerIconPreferenceControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 9842843c9cd..bbba1cf6e17 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5500,10 +5500,6 @@ screen magnification on app transitions Power button ends call - - Large mouse pointer - - Make the mouse pointer more noticeable Make more apps dark diff --git a/res/xml/accessibility_color_and_motion.xml b/res/xml/accessibility_color_and_motion.xml index 9cc8f8b9bc7..1c27aaa5b81 100644 --- a/res/xml/accessibility_color_and_motion.xml +++ b/res/xml/accessibility_color_and_motion.xml @@ -58,13 +58,6 @@ android:title="@string/accessibility_disable_animations" settings:controller="com.android.settings.accessibility.DisableAnimationsPreferenceController"/> - - mShortcutFeatureKeys = new ArrayList<>(); @@ -116,9 +114,6 @@ public class ColorAndMotionFragment extends DashboardFragment { // Disable animation. mToggleDisableAnimationsPreference = findPreference(RemoveAnimationsPreference.KEY); - - // Large pointer icon. - mToggleLargePointerIconPreference = findPreference(TOGGLE_LARGE_POINTER_ICON); } /** @@ -134,10 +129,8 @@ public class ColorAndMotionFragment extends DashboardFragment { // hardware-accelerated color transform. getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen); getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference); - getPreferenceScreen().removePreference(mToggleLargePointerIconPreference); experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen); experimentalCategory.addPreference(mToggleDisableAnimationsPreference); - experimentalCategory.addPreference(mToggleLargePointerIconPreference); } } diff --git a/src/com/android/settings/accessibility/LargePointerIconPreferenceController.java b/src/com/android/settings/accessibility/LargePointerIconPreferenceController.java deleted file mode 100644 index 0f1d44d81d5..00000000000 --- a/src/com/android/settings/accessibility/LargePointerIconPreferenceController.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2019 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; - -import android.content.Context; -import android.provider.Settings; - -import androidx.annotation.VisibleForTesting; - -import com.android.settings.R; -import com.android.settings.core.TogglePreferenceController; - -public class LargePointerIconPreferenceController extends TogglePreferenceController { - - @VisibleForTesting - static final int ON = 1; - @VisibleForTesting - static final int OFF = 0; - - public LargePointerIconPreferenceController(Context context, String preferenceKey) { - super(context, preferenceKey); - } - - @Override - public boolean isChecked() { - return Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, OFF) != OFF; - } - - @Override - public boolean setChecked(boolean isChecked) { - return Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, isChecked ? ON : OFF); - } - - @Override - public int getAvailabilityStatus() { - return android.view.flags.Flags.enableVectorCursorA11ySettings() ? CONDITIONALLY_UNAVAILABLE - : AVAILABLE; - } - - @Override - public int getSliceHighlightMenuRes() { - return R.string.menu_key_accessibility; - } -} diff --git a/tests/unit/src/com/android/settings/accessibility/LargePointerIconPreferenceControllerTest.java b/tests/unit/src/com/android/settings/accessibility/LargePointerIconPreferenceControllerTest.java deleted file mode 100644 index fbc1a199d66..00000000000 --- a/tests/unit/src/com/android/settings/accessibility/LargePointerIconPreferenceControllerTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2020 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; - -import static android.view.flags.Flags.FLAG_ENABLE_VECTOR_CURSOR_A11Y_SETTINGS; - -import static com.android.settings.accessibility.LargePointerIconPreferenceController.OFF; -import static com.android.settings.accessibility.LargePointerIconPreferenceController.ON; - -import static com.google.common.truth.Truth.assertThat; - -import android.content.Context; -import android.platform.test.annotations.RequiresFlagsDisabled; -import android.platform.test.annotations.RequiresFlagsEnabled; -import android.platform.test.flag.junit.CheckFlagsRule; -import android.platform.test.flag.junit.DeviceFlagsValueProvider; -import android.provider.Settings; - -import androidx.preference.SwitchPreference; -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import com.android.settings.core.BasePreferenceController; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(AndroidJUnit4.class) -public class LargePointerIconPreferenceControllerTest { - - @Rule - public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); - - private static final int UNKNOWN = -1; - - private Context mContext; - private SwitchPreference mPreference; - private LargePointerIconPreferenceController mController; - - @Before - public void setUp() { - mContext = ApplicationProvider.getApplicationContext(); - mPreference = new SwitchPreference(mContext); - mController = new LargePointerIconPreferenceController(mContext, "large_pointer"); - } - - @Test - @RequiresFlagsDisabled(FLAG_ENABLE_VECTOR_CURSOR_A11Y_SETTINGS) - public void getAvailabilityStatus_shouldReturnAvailable() { - assertThat(mController.getAvailabilityStatus()) - .isEqualTo(BasePreferenceController.AVAILABLE); - } - - @Test - @RequiresFlagsEnabled(FLAG_ENABLE_VECTOR_CURSOR_A11Y_SETTINGS) - public void getAvailabilityStatus_shouldReturnConditionallyUnavailable() { - assertThat(mController.getAvailabilityStatus()) - .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE); - } - - @Test - public void isChecked_enabledLargePointer_shouldReturnTrue() { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, ON); - - mController.updateState(mPreference); - - assertThat(mController.isChecked()).isTrue(); - assertThat(mPreference.isChecked()).isTrue(); - } - - @Test - public void isChecked_disabledLargePointer_shouldReturnFalse() { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, OFF); - - mController.updateState(mPreference); - - assertThat(mController.isChecked()).isFalse(); - assertThat(mPreference.isChecked()).isFalse(); - } - - @Test - public void setChecked_enabled_shouldEnableLargePointer() { - mController.setChecked(true); - - assertThat(Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, UNKNOWN)).isEqualTo(ON); - } - - @Test - public void setChecked_disabled_shouldDisableLargePointer() { - mController.setChecked(false); - - assertThat(Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, UNKNOWN)).isEqualTo(OFF); - } -} From 1337a88d112b005f897b3745b5475cf7d4764db7 Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Fri, 17 Jan 2025 12:32:05 +0900 Subject: [PATCH 02/14] Revert "Replace system_ext container with system" This reverts commit 6e1b274f03cab386f39c7d7c0b0487b4dcad6af3. A system partition cannot have the aconfigs of other partitions. Revive the system_ext container for system_ext aconfigs. Bug: 385213580 Test: "adb shell aflags list" must not be changed. Flag: EXEMPT refactor Change-Id: I8f52d5f86e6ffaccd624846fbe1ba0a8fc842af6 --- aconfig/Android.bp | 12 ++++++------ aconfig/accessibility/accessibility_flags.aconfig | 2 +- aconfig/catalyst/about_phone.aconfig | 2 +- aconfig/catalyst/accessibility.aconfig | 2 +- aconfig/catalyst/battery.aconfig | 2 +- aconfig/catalyst/connected_devices.aconfig | 2 +- aconfig/catalyst/display.aconfig | 2 +- aconfig/catalyst/location.aconfig | 2 +- aconfig/catalyst/lockscreen.aconfig | 2 +- aconfig/catalyst/network_and_internet.aconfig | 2 +- aconfig/catalyst/sound_screen.aconfig | 2 +- aconfig/catalyst/system.aconfig | 2 +- .../settings_core_flag_declarations.aconfig | 2 +- .../factory_reset_flag_declarations.aconfig | 2 +- .../settings_keyboard_layout_picker_features.aconfig | 2 +- .../settings_physical_keyboard_a11y_features.aconfig | 2 +- .../settings_mediadrm_flag_declarations.aconfig | 2 +- ...gs_accessibility_flag_declarations_legacy.aconfig | 2 +- ...gs_biometrics_framework_flag_declarations.aconfig | 2 +- ...tings_biometrics_integration_declarations.aconfig | 2 +- aconfig/settings_bluetooth_declarations.aconfig | 2 +- ...ettings_connecteddevice_flag_declarations.aconfig | 2 +- ...ontacts_default_account_flag_declarations.aconfig | 2 +- aconfig/settings_datetime_flag_declarations.aconfig | 2 +- .../settings_development_flag_declarations.aconfig | 2 +- .../settings_device_diagnostics_declarations.aconfig | 2 +- aconfig/settings_display_flag_declarations.aconfig | 2 +- .../settings_experience_flag_declarations.aconfig | 2 +- aconfig/settings_flag_declarations.aconfig | 2 +- .../settings_globalintl_flag_declarations.aconfig | 2 +- .../settings_notification_flag_declarations.aconfig | 2 +- ...s_onboarding_experience_flag_declarations.aconfig | 2 +- ...gs_perform_backup_tasks_flag_declarations.aconfig | 2 +- aconfig/settings_security_flag_declarations.aconfig | 2 +- aconfig/settings_telephony_flag_declarations.aconfig | 2 +- .../settings_threadnetwork_flag_declarations.aconfig | 2 +- ...s_voice_activation_apps_flag_declarations.aconfig | 2 +- aconfig/settings_wifi_flag_declarations.aconfig | 2 +- 38 files changed, 43 insertions(+), 43 deletions(-) diff --git a/aconfig/Android.bp b/aconfig/Android.bp index 6d62dcf9397..cdc84353b3b 100644 --- a/aconfig/Android.bp +++ b/aconfig/Android.bp @@ -6,7 +6,7 @@ package { aconfig_declarations { name: "aconfig_settings_flags", package: "com.android.settings.flags", - container: "system", + container: "system_ext", srcs: [ "*.aconfig", "catalyst/*.aconfig", @@ -21,7 +21,7 @@ java_aconfig_library { aconfig_declarations { name: "factory_reset_flags", package: "com.android.settings.factory_reset", - container: "system", + container: "system_ext", srcs: ["factory_reset/*.aconfig"], } @@ -33,7 +33,7 @@ java_aconfig_library { aconfig_declarations { name: "media_drm_flags", package: "com.android.settings.media_drm", - container: "system", + container: "system_ext", srcs: ["media_drm/*.aconfig"], } @@ -45,7 +45,7 @@ java_aconfig_library { aconfig_declarations { name: "accessibility_flags", package: "com.android.settings.accessibility", - container: "system", + container: "system_ext", srcs: ["accessibility/*.aconfig"], } @@ -57,7 +57,7 @@ java_aconfig_library { aconfig_declarations { name: "development_settings_flags", package: "com.android.settings.development", - container: "system", + container: "system_ext", srcs: [ "development/**/*.aconfig", ], @@ -71,7 +71,7 @@ java_aconfig_library { aconfig_declarations { name: "keyboard_flags", package: "com.android.settings.keyboard", - container: "system", + container: "system_ext", srcs: ["keyboard/*.aconfig"], } diff --git a/aconfig/accessibility/accessibility_flags.aconfig b/aconfig/accessibility/accessibility_flags.aconfig index f7ef9d5af46..2e98766dfe0 100644 --- a/aconfig/accessibility/accessibility_flags.aconfig +++ b/aconfig/accessibility/accessibility_flags.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.accessibility" -container: "system" +container: "system_ext" # NOTE: Keep alphabetized to help limit merge conflicts from multiple simultaneous editors. diff --git a/aconfig/catalyst/about_phone.aconfig b/aconfig/catalyst/about_phone.aconfig index 8ecde46eae5..d0564de2e58 100644 --- a/aconfig/catalyst/about_phone.aconfig +++ b/aconfig/catalyst/about_phone.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_legal_information" diff --git a/aconfig/catalyst/accessibility.aconfig b/aconfig/catalyst/accessibility.aconfig index 783706709a1..fe0d7a5347b 100644 --- a/aconfig/catalyst/accessibility.aconfig +++ b/aconfig/catalyst/accessibility.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_accessibility_color_and_motion" diff --git a/aconfig/catalyst/battery.aconfig b/aconfig/catalyst/battery.aconfig index cec40f3746b..7c152d9175c 100644 --- a/aconfig/catalyst/battery.aconfig +++ b/aconfig/catalyst/battery.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_power_usage_summary_screen" diff --git a/aconfig/catalyst/connected_devices.aconfig b/aconfig/catalyst/connected_devices.aconfig index 7a335fa4675..5b7a70bdbf0 100644 --- a/aconfig/catalyst/connected_devices.aconfig +++ b/aconfig/catalyst/connected_devices.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_bluetooth_switchbar_screen" diff --git a/aconfig/catalyst/display.aconfig b/aconfig/catalyst/display.aconfig index 9485e70fc1d..11c1d3a592c 100644 --- a/aconfig/catalyst/display.aconfig +++ b/aconfig/catalyst/display.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_display_settings_screen" diff --git a/aconfig/catalyst/location.aconfig b/aconfig/catalyst/location.aconfig index c656bf3ea58..24f2c538d8a 100644 --- a/aconfig/catalyst/location.aconfig +++ b/aconfig/catalyst/location.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_location_settings" diff --git a/aconfig/catalyst/lockscreen.aconfig b/aconfig/catalyst/lockscreen.aconfig index 9a84f66af15..280171af32d 100644 --- a/aconfig/catalyst/lockscreen.aconfig +++ b/aconfig/catalyst/lockscreen.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_lockscreen_from_display_settings" diff --git a/aconfig/catalyst/network_and_internet.aconfig b/aconfig/catalyst/network_and_internet.aconfig index aa26ce42be6..e39b182bdee 100644 --- a/aconfig/catalyst/network_and_internet.aconfig +++ b/aconfig/catalyst/network_and_internet.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_network_provider_and_internet_screen" diff --git a/aconfig/catalyst/sound_screen.aconfig b/aconfig/catalyst/sound_screen.aconfig index ac7f8bc1b80..1eacc3a7b3e 100644 --- a/aconfig/catalyst/sound_screen.aconfig +++ b/aconfig/catalyst/sound_screen.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_sound_screen" diff --git a/aconfig/catalyst/system.aconfig b/aconfig/catalyst/system.aconfig index f87ff44a909..4cd1cd90bae 100644 --- a/aconfig/catalyst/system.aconfig +++ b/aconfig/catalyst/system.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "catalyst_language_setting" diff --git a/aconfig/development/settings_core_flag_declarations.aconfig b/aconfig/development/settings_core_flag_declarations.aconfig index b73b0268009..45768f461dc 100644 --- a/aconfig/development/settings_core_flag_declarations.aconfig +++ b/aconfig/development/settings_core_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.development" -container: "system" +container: "system_ext" flag { name: "deprecate_list_activity" diff --git a/aconfig/factory_reset/factory_reset_flag_declarations.aconfig b/aconfig/factory_reset/factory_reset_flag_declarations.aconfig index 7feebf54dcc..dc7d8d4e42a 100644 --- a/aconfig/factory_reset/factory_reset_flag_declarations.aconfig +++ b/aconfig/factory_reset/factory_reset_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.factory_reset" -container: "system" +container: "system_ext" flag { name: "enable_factory_reset_wizard" diff --git a/aconfig/keyboard/settings_keyboard_layout_picker_features.aconfig b/aconfig/keyboard/settings_keyboard_layout_picker_features.aconfig index 18684ab7344..79e9ddc27c9 100644 --- a/aconfig/keyboard/settings_keyboard_layout_picker_features.aconfig +++ b/aconfig/keyboard/settings_keyboard_layout_picker_features.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.keyboard" -container: "system" +container: "system_ext" flag { name: "keyboard_layout_picker_activity_enabled" diff --git a/aconfig/keyboard/settings_physical_keyboard_a11y_features.aconfig b/aconfig/keyboard/settings_physical_keyboard_a11y_features.aconfig index 00c0b183759..ca5cb8d7739 100644 --- a/aconfig/keyboard/settings_physical_keyboard_a11y_features.aconfig +++ b/aconfig/keyboard/settings_physical_keyboard_a11y_features.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.keyboard" -container: "system" +container: "system_ext" flag { name: "keyboard_and_touchpad_a11y_new_page_enabled" diff --git a/aconfig/media_drm/settings_mediadrm_flag_declarations.aconfig b/aconfig/media_drm/settings_mediadrm_flag_declarations.aconfig index 3969b2919de..10579ebd3dd 100644 --- a/aconfig/media_drm/settings_mediadrm_flag_declarations.aconfig +++ b/aconfig/media_drm/settings_mediadrm_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.media_drm" -container: "system" +container: "system_ext" flag { name: "force_l3_enabled" diff --git a/aconfig/settings_accessibility_flag_declarations_legacy.aconfig b/aconfig/settings_accessibility_flag_declarations_legacy.aconfig index 6e02bfe20eb..d0e5850ddc3 100644 --- a/aconfig/settings_accessibility_flag_declarations_legacy.aconfig +++ b/aconfig/settings_accessibility_flag_declarations_legacy.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" # NOTE: Don't add new accessibility flags here, since the package name doesn't follow # the best practice for setting's feature flag go/settings-trunk-stable diff --git a/aconfig/settings_biometrics_framework_flag_declarations.aconfig b/aconfig/settings_biometrics_framework_flag_declarations.aconfig index 820786eec68..e81c68e6aa0 100644 --- a/aconfig/settings_biometrics_framework_flag_declarations.aconfig +++ b/aconfig/settings_biometrics_framework_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "biometric_settings_provider" diff --git a/aconfig/settings_biometrics_integration_declarations.aconfig b/aconfig/settings_biometrics_integration_declarations.aconfig index cc756c6d587..48bf293fa1b 100644 --- a/aconfig/settings_biometrics_integration_declarations.aconfig +++ b/aconfig/settings_biometrics_integration_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "sfps_enroll_refinement" diff --git a/aconfig/settings_bluetooth_declarations.aconfig b/aconfig/settings_bluetooth_declarations.aconfig index bdd317ee82a..45ea2dc5103 100644 --- a/aconfig/settings_bluetooth_declarations.aconfig +++ b/aconfig/settings_bluetooth_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "enable_offload_bluetooth_operations_to_background_thread" diff --git a/aconfig/settings_connecteddevice_flag_declarations.aconfig b/aconfig/settings_connecteddevice_flag_declarations.aconfig index eede0931b97..f10c019a459 100644 --- a/aconfig/settings_connecteddevice_flag_declarations.aconfig +++ b/aconfig/settings_connecteddevice_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "rotation_connected_display_setting" diff --git a/aconfig/settings_contacts_default_account_flag_declarations.aconfig b/aconfig/settings_contacts_default_account_flag_declarations.aconfig index eb877af4ad9..621714d9830 100644 --- a/aconfig/settings_contacts_default_account_flag_declarations.aconfig +++ b/aconfig/settings_contacts_default_account_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "enable_contacts_default_account_in_settings" diff --git a/aconfig/settings_datetime_flag_declarations.aconfig b/aconfig/settings_datetime_flag_declarations.aconfig index 995124339db..305a55dff1e 100644 --- a/aconfig/settings_datetime_flag_declarations.aconfig +++ b/aconfig/settings_datetime_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "datetime_feedback" diff --git a/aconfig/settings_development_flag_declarations.aconfig b/aconfig/settings_development_flag_declarations.aconfig index f2452e55ec0..cdce6e7437c 100644 --- a/aconfig/settings_development_flag_declarations.aconfig +++ b/aconfig/settings_development_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" # NOTE: Keep alphabetized to help limit merge conflicts from multiple simultaneous editors. diff --git a/aconfig/settings_device_diagnostics_declarations.aconfig b/aconfig/settings_device_diagnostics_declarations.aconfig index 7423f2bc00a..90a12dbb9ab 100644 --- a/aconfig/settings_device_diagnostics_declarations.aconfig +++ b/aconfig/settings_device_diagnostics_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "enable_device_diagnostics_in_settings" diff --git a/aconfig/settings_display_flag_declarations.aconfig b/aconfig/settings_display_flag_declarations.aconfig index 9fe587b0162..52b9603e051 100644 --- a/aconfig/settings_display_flag_declarations.aconfig +++ b/aconfig/settings_display_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "protect_screen_timeout_with_auth" diff --git a/aconfig/settings_experience_flag_declarations.aconfig b/aconfig/settings_experience_flag_declarations.aconfig index ae3af2441cc..2d32ffaa2c7 100644 --- a/aconfig/settings_experience_flag_declarations.aconfig +++ b/aconfig/settings_experience_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "new_apn_page_enabled" diff --git a/aconfig/settings_flag_declarations.aconfig b/aconfig/settings_flag_declarations.aconfig index b57a69d9469..2971d22b5de 100644 --- a/aconfig/settings_flag_declarations.aconfig +++ b/aconfig/settings_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "show_factory_reset_cancel_button" diff --git a/aconfig/settings_globalintl_flag_declarations.aconfig b/aconfig/settings_globalintl_flag_declarations.aconfig index 6cfd140b66f..2e3aab560b3 100644 --- a/aconfig/settings_globalintl_flag_declarations.aconfig +++ b/aconfig/settings_globalintl_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "terms_of_address_enabled" diff --git a/aconfig/settings_notification_flag_declarations.aconfig b/aconfig/settings_notification_flag_declarations.aconfig index bdb65738827..f2ef4287f41 100644 --- a/aconfig/settings_notification_flag_declarations.aconfig +++ b/aconfig/settings_notification_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "dedupe_dnd_settings_channels" diff --git a/aconfig/settings_onboarding_experience_flag_declarations.aconfig b/aconfig/settings_onboarding_experience_flag_declarations.aconfig index 8d58d40a66c..830c1017741 100644 --- a/aconfig/settings_onboarding_experience_flag_declarations.aconfig +++ b/aconfig/settings_onboarding_experience_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "enable_sound_backup" diff --git a/aconfig/settings_perform_backup_tasks_flag_declarations.aconfig b/aconfig/settings_perform_backup_tasks_flag_declarations.aconfig index 86bae9d84ad..dcb876b52f7 100644 --- a/aconfig/settings_perform_backup_tasks_flag_declarations.aconfig +++ b/aconfig/settings_perform_backup_tasks_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "enable_perform_backup_tasks_in_settings" diff --git a/aconfig/settings_security_flag_declarations.aconfig b/aconfig/settings_security_flag_declarations.aconfig index 3684212f87c..e27f835aea8 100644 --- a/aconfig/settings_security_flag_declarations.aconfig +++ b/aconfig/settings_security_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "protect_lock_after_timeout_with_auth" diff --git a/aconfig/settings_telephony_flag_declarations.aconfig b/aconfig/settings_telephony_flag_declarations.aconfig index 5919e535b8c..3543e60c002 100644 --- a/aconfig/settings_telephony_flag_declarations.aconfig +++ b/aconfig/settings_telephony_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "remove_key_hide_enable_2g" diff --git a/aconfig/settings_threadnetwork_flag_declarations.aconfig b/aconfig/settings_threadnetwork_flag_declarations.aconfig index e5448a91eb4..99664678137 100644 --- a/aconfig/settings_threadnetwork_flag_declarations.aconfig +++ b/aconfig/settings_threadnetwork_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "thread_settings_enabled" diff --git a/aconfig/settings_voice_activation_apps_flag_declarations.aconfig b/aconfig/settings_voice_activation_apps_flag_declarations.aconfig index d72e67fb687..9ca3525b1e5 100644 --- a/aconfig/settings_voice_activation_apps_flag_declarations.aconfig +++ b/aconfig/settings_voice_activation_apps_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" flag { name: "enable_voice_activation_apps_in_settings" diff --git a/aconfig/settings_wifi_flag_declarations.aconfig b/aconfig/settings_wifi_flag_declarations.aconfig index 67ed9437a9a..cb8007f2e93 100644 --- a/aconfig/settings_wifi_flag_declarations.aconfig +++ b/aconfig/settings_wifi_flag_declarations.aconfig @@ -1,5 +1,5 @@ package: "com.android.settings.flags" -container: "system" +container: "system_ext" # NOTE: Keep alphabetized to help limit merge conflicts from multiple simultaneous editors. From d77fd9689e9341e0efa2b9721f7ae533cfca9ea1 Mon Sep 17 00:00:00 2001 From: Yiyi Shen Date: Fri, 17 Jan 2025 17:51:47 +0800 Subject: [PATCH 03/14] [Audiosharing] Avoid popup dialog when broadcast start in SysUI Test: atest Bug: 305620450 Flag: com.android.settingslib.flags.enable_le_audio_sharing Change-Id: I447aeb7e9646a5f9278fd2def8a2a9e6a59ac47e --- .../AudioSharingSwitchBarController.java | 18 +++++++--------- .../AudioSharingSwitchBarControllerTest.java | 21 ++++++------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java index 7ca3256b849..44921153ce6 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java @@ -128,6 +128,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController // join the audio sharing, we will wait for the process complete for this list of sinks and then // popup audio sharing dialog with options to pair new device. private CopyOnWriteArrayList mSinksToWaitFor = new CopyOnWriteArrayList<>(); + private AtomicBoolean mStartingSharing = new AtomicBoolean(false); private AtomicBoolean mStoppingSharing = new AtomicBoolean(false); @VisibleForTesting @@ -160,6 +161,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController @Override public void onBroadcastStartFailed(int reason) { Log.d(TAG, "onBroadcastStartFailed(), reason = " + reason); + mStartingSharing.compareAndSet(true, false); updateSwitch(); showErrorDialog(); mMetricsFeatureProvider.action( @@ -177,16 +179,8 @@ public class AudioSharingSwitchBarController extends BasePreferenceController + broadcastId + ", metadata = " + metadata.getBroadcastName()); - if (mAssistant == null - || mAssistant.getAllConnectedDevices().stream() - .anyMatch( - device -> BluetoothUtils - .hasActiveLocalBroadcastSourceForBtDevice( - device, mBtManager))) { - Log.d( - TAG, - "Skip handleOnBroadcastReady: null assistant or " - + "sink has active local source."); + if (!mStartingSharing.compareAndSet(true, false)) { + Log.d(TAG, "Skip handleOnBroadcastReady, not in starting process"); return; } handleOnBroadcastReady(); @@ -213,6 +207,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController @Override public void onBroadcastStopFailed(int reason) { Log.d(TAG, "onBroadcastStopFailed(), reason = " + reason); + mStoppingSharing.compareAndSet(true, false); updateSwitch(); mMetricsFeatureProvider.action( mContext, @@ -565,6 +560,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController mDeviceItemsForSharing.remove(0); } if (mBroadcast != null) { + mStartingSharing.set(true); mBroadcast.startPrivateBroadcast(); mSinksInAdding.clear(); AudioSharingUtils.postOnMainThread(mContext, @@ -583,7 +579,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController int broadcastId = mBroadcast.getLatestBroadcastId(); if (broadcastId != -1) { mBroadcast.stopBroadcast(broadcastId); - mStoppingSharing.compareAndSet(false, true); + mStoppingSharing.set(true); mSinksInAdding.clear(); mSinksToWaitFor.clear(); } diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java index 7851b2b38f8..dea98233609 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java @@ -515,23 +515,14 @@ public class AudioSharingSwitchBarControllerTest { } @Test - public void onBroadcastMetadataChanged_hasLocalSource_noDialog() { + public void onBroadcastMetadataChanged_notTriggeredHere_noDialog() { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true); when(mBtnView.isEnabled()).thenReturn(true); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice2, mDevice1)); - when(mState.getBroadcastId()).thenReturn(1); - when(mBroadcast.getLatestBroadcastId()).thenReturn(1); - when(mAssistant.getAllSources(mDevice2)).thenReturn(ImmutableList.of(mState)); + when(mAssistant.getAllSources(any(BluetoothDevice.class))).thenReturn(ImmutableList.of()); when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(mMetadata); doNothing().when(mBroadcast).startPrivateBroadcast(); - mController.onCheckedChanged(mBtnView, /* isChecked= */ true); - shadowOf(Looper.getMainLooper()).idle(); - - verify(mBroadcast).startPrivateBroadcast(); - List childFragments = mParentFragment.getChildFragmentManager().getFragments(); - assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly( - AudioSharingProgressDialogFragment.class.getName()); mController.mBroadcastCallback.onBroadcastMetadataChanged(/* reason= */ 1, mMetadata); shadowOf(Looper.getMainLooper()).idle(); @@ -540,7 +531,7 @@ public class AudioSharingSwitchBarControllerTest { verify(mFeatureFactory.metricsFeatureProvider, never()) .action(any(Context.class), eq(SettingsEnums.ACTION_AUTO_JOIN_AUDIO_SHARING)); - childFragments = mParentFragment.getChildFragmentManager().getFragments(); + List childFragments = mParentFragment.getChildFragmentManager().getFragments(); // No audio sharing dialog. assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).doesNotContain( AudioSharingDialogFragment.class.getName()); @@ -613,7 +604,7 @@ public class AudioSharingSwitchBarControllerTest { } @Test - public void onBroadcastMetadataChanged_oneActiveOnConnected_showJoinAudioSharingDialog() { + public void onBroadcastMetadataChanged_oneActiveOneConnected_showJoinAudioSharingDialog() { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true); when(mBtnView.isEnabled()).thenReturn(true); @@ -681,7 +672,7 @@ public class AudioSharingSwitchBarControllerTest { } @Test - public void onBroadcastMetadataChanged_oneActiveOnConnected_clickShareBtnOnDialog_addSource() { + public void onBroadcastMetadataChanged_oneActiveOneConnected_clickShareBtnOnDialog_addSource() { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true); when(mBtnView.isEnabled()).thenReturn(true); @@ -722,7 +713,7 @@ public class AudioSharingSwitchBarControllerTest { } @Test - public void onBroadcastMetadataChanged_oneActiveOnConnected_clickCancelBtnOnDialog_doNothing() { + public void onBroadcastMetadataChanged_oneActiveOneConnected_clickCancelBtnOnDlg_doNothing() { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true); when(mBtnView.isEnabled()).thenReturn(true); From 5ace2018cc7821e3e49cf533cda0fc9ee3f1fe51 Mon Sep 17 00:00:00 2001 From: Vincent Wang Date: Mon, 13 Jan 2025 08:33:24 +0000 Subject: [PATCH 04/14] Determine if devices support screen off unlock from config Bug: 389002332 Flag: android.hardware.biometrics.screen_off_unlock_udfps Test: 1. Build pass 2. Check screen off unlcok is enabled on usudfps & udfps devices 3. Enable screen off unlock on usudfps devices by default 4. Disable screen off unlock on udfps devices by default Change-Id: I81c419f51a808a5e51d9bb92f19553cdf9e9c2f8 --- .../fingerprint/FingerprintSettings.java | 21 +++++++------------ ...eenOffUnlockUdfpsPreferenceController.java | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java index e618ae358b3..6d0169568b9 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java @@ -623,15 +623,10 @@ public class FingerprintSettings extends SubSettings { return false; } - private boolean isUltrasnoicUdfps() { - mFingerprintManager = Utils.getFingerprintManagerOrNull(getActivity()); - if (mFingerprintManager != null) { - mSensorProperties = mFingerprintManager.getSensorPropertiesInternal(); - for (FingerprintSensorPropertiesInternal prop : mSensorProperties) { - if (prop.isUltrasonicUdfps()) { - return true; - } - } + private boolean isScreenOffUnlcokSupported() { + if (isUdfps()) { + return getContext().getResources().getBoolean( + com.android.internal.R.bool.config_screen_off_udfps_enabled); } return false; } @@ -678,7 +673,7 @@ public class FingerprintSettings extends SubSettings { // This needs to be after setting ids, otherwise // |mRequireScreenOnToAuthPreferenceController.isChecked| is always checking the primary // user instead of the user with |mUserId|. - if (isSfps() || (screenOffUnlockUdfps() && isUltrasnoicUdfps())) { + if (isSfps() || (screenOffUnlockUdfps() && isScreenOffUnlcokSupported())) { scrollToPreference(fpPrefKey); addFingerprintUnlockCategory(); } @@ -778,7 +773,7 @@ public class FingerprintSettings extends SubSettings { restToUnlockPreference.getOnPreferenceChangeListener()); } setupFingerprintUnlockCategoryPreferencesForScreenOnToAuth(); - } else if (screenOffUnlockUdfps() && isUltrasnoicUdfps()) { + } else if (screenOffUnlockUdfps() && isScreenOffUnlcokSupported()) { setupFingerprintUnlockCategoryPreferencesForScreenOffUnlock(); } updateFingerprintUnlockCategoryVisibility(); @@ -846,7 +841,7 @@ public class FingerprintSettings extends SubSettings { private void updatePreferencesAfterFingerprintRemoved() { updateAddPreference(); - if (isSfps() || (screenOffUnlockUdfps() && isUltrasnoicUdfps())) { + if (isSfps() || (screenOffUnlockUdfps() && isScreenOffUnlcokSupported())) { updateFingerprintUnlockCategoryVisibility(); } updatePreferences(); @@ -1119,7 +1114,7 @@ public class FingerprintSettings extends SubSettings { } } - } else if (screenOffUnlockUdfps() && isUltrasnoicUdfps()) { + } else if (screenOffUnlockUdfps() && isScreenOffUnlcokSupported()) { for (AbstractPreferenceController controller : controllers) { if (controller.getPreferenceKey() == KEY_FINGERPRINT_UNLOCK_CATEGORY) { mFingerprintUnlockCategoryPreferenceController = diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsScreenOffUnlockUdfpsPreferenceController.java b/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsScreenOffUnlockUdfpsPreferenceController.java index 5c32d90ba7e..b09c6382ebf 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsScreenOffUnlockUdfpsPreferenceController.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsScreenOffUnlockUdfpsPreferenceController.java @@ -59,7 +59,7 @@ public class FingerprintSettingsScreenOffUnlockUdfpsPreferenceController return false; } final boolean defEnabled = mContext.getResources().getBoolean( - com.android.internal.R.bool.config_screen_off_udfps_enabled); + com.android.internal.R.bool.config_screen_off_udfps_default_on); final int value = Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.SCREEN_OFF_UNLOCK_UDFPS_ENABLED, From 5a8e10bbe3ecc795336696398f23042931d5144b Mon Sep 17 00:00:00 2001 From: Yiyi Shen Date: Mon, 20 Jan 2025 18:16:55 +0800 Subject: [PATCH 05/14] [Audiosharing] Move entry preference out of group category Test: atest Bug: 305620450 Flag: com.android.settingslib.flags.enable_le_audio_sharing Change-Id: I0573c9c35c05ca7915f94e6f67064cc5b3d79fec --- res/xml/connected_devices.xml | 15 ++- ...udioSharingDevicePreferenceController.java | 18 +-- .../AudioSharingPreferenceController.java | 60 ++++++++- ...SharingDevicePreferenceControllerTest.java | 15 +-- .../AudioSharingPreferenceControllerTest.java | 127 +++++++++++++++++- 5 files changed, 187 insertions(+), 48 deletions(-) diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml index 05bf925e56d..e8c169ce92c 100644 --- a/res/xml/connected_devices.xml +++ b/res/xml/connected_devices.xml @@ -30,13 +30,6 @@ android:key="audio_sharing_device_list" android:title="@string/audio_sharing_device_group_title" settings:controller="com.android.settings.connecteddevice.audiosharing.AudioSharingDevicePreferenceController"> - + + BluetoothUtils.isBroadcasting(mBtManager) + ? mContext.getString(R.string.audio_sharing_summary_on) + : mContext.getString(R.string.audio_sharing_summary_off); + default -> ""; + }; } @Override public void onBluetoothStateChanged(@AdapterState int bluetoothState) { - refreshSummary(); + refreshPreference(); + } + + private void refreshPreference() { + switch (getPreferenceKey()) { + // Audio sharing entrance on Connected devices page has no summary, but its visibility + // will change based on audio sharing state + case CONNECTED_DEVICES_PREF_KEY -> updateVisibility(); + // Audio sharing entrance on Connection preferences page always show up, but its summary + // will change based on audio sharing state + case CONNECTION_PREFERENCES_PREF_KEY -> refreshSummary(); + } + } + + private void updateVisibility() { + if (mPreference == null) { + return; + } + switch (getPreferenceKey()) { + case CONNECTED_DEVICES_PREF_KEY -> { + var unused = + ThreadUtils.postOnBackgroundThread( + () -> { + boolean visible = BluetoothUtils.isBroadcasting(mBtManager); + AudioSharingUtils.postOnMainThread( + mContext, + () -> { + // Check nullability to pass NullAway check + if (mPreference != null) { + mPreference.setVisible(visible); + } + }); + }); + } + } } private void refreshSummary() { diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceControllerTest.java index a49d0c13890..1913debc5af 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceControllerTest.java @@ -117,8 +117,6 @@ import java.util.concurrent.Executor; }) public class AudioSharingDevicePreferenceControllerTest { private static final String KEY = "audio_sharing_device_list"; - private static final String KEY_AUDIO_SHARING_SETTINGS = - "connected_device_audio_sharing_settings"; private static final String TEST_DEVICE_NAME = "test"; @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @@ -151,7 +149,6 @@ public class AudioSharingDevicePreferenceControllerTest { private Lifecycle mLifecycle; private LifecycleOwner mLifecycleOwner; private PreferenceCategory mPreferenceGroup; - private Preference mAudioSharingPreference; private FakeFeatureFactory mFeatureFactory; private AudioManager mAudioManager; @@ -189,10 +186,6 @@ public class AudioSharingDevicePreferenceControllerTest { when(mScreen.getContext()).thenReturn(mContext); mPreferenceGroup = spy(new PreferenceCategory(mContext)); doReturn(mPreferenceManager).when(mPreferenceGroup).getPreferenceManager(); - mAudioSharingPreference = new Preference(mContext); - mPreferenceGroup.addPreference(mAudioSharingPreference); - when(mPreferenceGroup.findPreference(KEY_AUDIO_SHARING_SETTINGS)) - .thenReturn(mAudioSharingPreference); when(mScreen.findPreference(KEY)).thenReturn(mPreferenceGroup); mController = new AudioSharingDevicePreferenceController(mContext); mController.init(mFragment); @@ -260,7 +253,6 @@ public class AudioSharingDevicePreferenceControllerTest { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.displayPreference(mScreen); assertThat(mPreferenceGroup.isVisible()).isFalse(); - assertThat(mAudioSharingPreference.isVisible()).isFalse(); verify(mBluetoothDeviceUpdater, never()).forceUpdate(); } @@ -269,7 +261,6 @@ public class AudioSharingDevicePreferenceControllerTest { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.displayPreference(mScreen); assertThat(mPreferenceGroup.isVisible()).isFalse(); - assertThat(mAudioSharingPreference.isVisible()).isFalse(); verify(mBluetoothDeviceUpdater).setPrefContext(mContext); verify(mBluetoothDeviceUpdater).forceUpdate(); } @@ -299,8 +290,7 @@ public class AudioSharingDevicePreferenceControllerTest { shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreferenceGroup.isVisible()).isTrue(); - assertThat(mAudioSharingPreference.isVisible()).isTrue(); - assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(2); + assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); } @Test @@ -312,8 +302,7 @@ public class AudioSharingDevicePreferenceControllerTest { shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreferenceGroup.isVisible()).isFalse(); - assertThat(mAudioSharingPreference.isVisible()).isFalse(); - assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(1); + assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0); } @Test diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPreferenceControllerTest.java index d9c883e5b1f..cdf21db9de2 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPreferenceControllerTest.java @@ -25,8 +25,10 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.robolectric.Shadows.shadowOf; @@ -77,7 +79,8 @@ import org.robolectric.shadow.api.Shadow; ShadowThreadUtils.class }) public class AudioSharingPreferenceControllerTest { - private static final String PREF_KEY = "audio_sharing_settings"; + private static final String PREF_KEY1 = "audio_sharing_settings"; + private static final String PREF_KEY2 = "connected_device_audio_sharing_settings"; @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @@ -110,9 +113,6 @@ public class AudioSharingPreferenceControllerTest { when(localBluetoothManager.getEventManager()).thenReturn(mBtEventManager); when(localBluetoothManager.getProfileManager()).thenReturn(mLocalBtProfileManager); when(mLocalBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast); - mController = new AudioSharingPreferenceController(mContext, PREF_KEY); - mPreference = spy(new Preference(mContext)); - when(mScreen.findPreference(PREF_KEY)).thenReturn(mPreference); } @After @@ -124,6 +124,7 @@ public class AudioSharingPreferenceControllerTest { @Test public void onStart_flagOn_registerCallback() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); + setupControllerWithKey(PREF_KEY1); mController.onStart(mLifecycleOwner); verify(mBtEventManager).registerCallback(mController); verify(mBroadcast).registerServiceCallBack(any(), any(BluetoothLeBroadcast.Callback.class)); @@ -132,6 +133,7 @@ public class AudioSharingPreferenceControllerTest { @Test public void onStart_flagOff_skipRegisterCallback() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); + setupControllerWithKey(PREF_KEY1); mController.onStart(mLifecycleOwner); verify(mBtEventManager, never()).registerCallback(mController); verify(mBroadcast, never()) @@ -141,6 +143,7 @@ public class AudioSharingPreferenceControllerTest { @Test public void onStop_flagOn_unregisterCallback() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); + setupControllerWithKey(PREF_KEY1); mController.onStop(mLifecycleOwner); verify(mBtEventManager).unregisterCallback(mController); verify(mBroadcast).unregisterServiceCallBack(any(BluetoothLeBroadcast.Callback.class)); @@ -149,6 +152,7 @@ public class AudioSharingPreferenceControllerTest { @Test public void onStop_flagOff_skipUnregisterCallback() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); + setupControllerWithKey(PREF_KEY1); mController.onStop(mLifecycleOwner); verify(mBtEventManager, never()).unregisterCallback(mController); verify(mBroadcast, never()) @@ -158,65 +162,147 @@ public class AudioSharingPreferenceControllerTest { @Test public void getAvailabilityStatus_flagOn() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); + setupControllerWithKey(PREF_KEY1); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test public void getAvailabilityStatus_flagOff() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); + setupControllerWithKey(PREF_KEY1); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } @Test - public void getSummary_broadcastOn() { + public void getSummary_connectionPreference_broadcastOn() { when(mBroadcast.isEnabled(any())).thenReturn(true); + setupControllerWithKey(PREF_KEY1); assertThat(mController.getSummary().toString()) .isEqualTo(mContext.getString(R.string.audio_sharing_summary_on)); } @Test - public void getSummary_broadcastOff() { + public void getSummary_connectionPreference_broadcastOff() { when(mBroadcast.isEnabled(any())).thenReturn(false); + setupControllerWithKey(PREF_KEY1); assertThat(mController.getSummary().toString()) .isEqualTo(mContext.getString(R.string.audio_sharing_summary_off)); } + @Test + public void getSummary_connectedDevices_broadcastOn() { + when(mBroadcast.isEnabled(any())).thenReturn(true); + setupControllerWithKey(PREF_KEY2); + assertThat(mController.getSummary().toString()).isEmpty(); + } + + @Test + public void getSummary_connectedDevices_broadcastOff() { + when(mBroadcast.isEnabled(any())).thenReturn(false); + setupControllerWithKey(PREF_KEY2); + assertThat(mController.getSummary().toString()).isEmpty(); + } + @Test public void onBluetoothStateChanged_refreshSummary() { + setupControllerWithKey(PREF_KEY1); + mController.updateState(mPreference); mController.displayPreference(mScreen); + shadowOf(Looper.getMainLooper()).idle(); + assertThat(mPreference.getSummary().toString()) + .isEqualTo(mContext.getString(R.string.audio_sharing_summary_off)); + assertThat(mPreference.isVisible()).isTrue(); + when(mBroadcast.isEnabled(any())).thenReturn(true); mController.onBluetoothStateChanged(STATE_ON); shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreference.getSummary().toString()) .isEqualTo(mContext.getString(R.string.audio_sharing_summary_on)); + assertThat(mPreference.isVisible()).isTrue(); when(mBroadcast.isEnabled(any())).thenReturn(false); mController.onBluetoothStateChanged(STATE_OFF); shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreference.getSummary().toString()) .isEqualTo(mContext.getString(R.string.audio_sharing_summary_off)); + assertThat(mPreference.isVisible()).isTrue(); + } + + @Test + public void onBluetoothStateChanged_refreshVisibility() { + setupControllerWithKey(PREF_KEY2); + mController.updateState(mPreference); + mController.displayPreference(mScreen); + shadowOf(Looper.getMainLooper()).idle(); + assertThat(mPreference.getSummary().toString()).isEmpty(); + assertThat(mPreference.isVisible()).isFalse(); + + when(mBroadcast.isEnabled(any())).thenReturn(true); + mController.onBluetoothStateChanged(STATE_ON); + shadowOf(Looper.getMainLooper()).idle(); + assertThat(mPreference.getSummary().toString()).isEmpty(); + assertThat(mPreference.isVisible()).isTrue(); + + when(mBroadcast.isEnabled(any())).thenReturn(false); + mController.onBluetoothStateChanged(STATE_OFF); + shadowOf(Looper.getMainLooper()).idle(); + assertThat(mPreference.getSummary().toString()).isEmpty(); + assertThat(mPreference.isVisible()).isFalse(); } @Test public void testBluetoothLeBroadcastCallbacks_refreshSummary() { + setupControllerWithKey(PREF_KEY1); + mController.updateState(mPreference); mController.displayPreference(mScreen); + shadowOf(Looper.getMainLooper()).idle(); + assertThat(mPreference.getSummary().toString()) + .isEqualTo(mContext.getString(R.string.audio_sharing_summary_off)); + assertThat(mPreference.isVisible()).isTrue(); when(mBroadcast.isEnabled(any())).thenReturn(true); mController.mBroadcastCallback.onBroadcastStarted(/* reason= */ 1, /* broadcastId= */ 1); shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreference.getSummary().toString()) .isEqualTo(mContext.getString(R.string.audio_sharing_summary_on)); + assertThat(mPreference.isVisible()).isTrue(); when(mBroadcast.isEnabled(any())).thenReturn(false); mController.mBroadcastCallback.onBroadcastStopped(/* reason= */ 1, /* broadcastId= */ 1); shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreference.getSummary().toString()) .isEqualTo(mContext.getString(R.string.audio_sharing_summary_off)); + assertThat(mPreference.isVisible()).isTrue(); + } + + @Test + public void testBluetoothLeBroadcastCallbacks_refreshVisibility() { + setupControllerWithKey(PREF_KEY2); + mController.updateState(mPreference); + mController.displayPreference(mScreen); + shadowOf(Looper.getMainLooper()).idle(); + assertThat(mPreference.getSummary().toString()).isEmpty(); + assertThat(mPreference.isVisible()).isFalse(); + + when(mBroadcast.isEnabled(any())).thenReturn(true); + mController.mBroadcastCallback.onBroadcastStarted(/* reason= */ 1, /* broadcastId= */ 1); + shadowOf(Looper.getMainLooper()).idle(); + assertThat(mPreference.getSummary().toString()).isEmpty(); + assertThat(mPreference.isVisible()).isTrue(); + + when(mBroadcast.isEnabled(any())).thenReturn(false); + mController.mBroadcastCallback.onBroadcastStopped(/* reason= */ 1, /* broadcastId= */ 1); + shadowOf(Looper.getMainLooper()).idle(); + assertThat(mPreference.getSummary().toString()).isEmpty(); + assertThat(mPreference.isVisible()).isFalse(); } @Test public void testBluetoothLeBroadcastCallbacks_doNothing() { + setupControllerWithKey(PREF_KEY1); mController.displayPreference(mScreen); + shadowOf(Looper.getMainLooper()).idle(); + verify(mPreference).setVisible(anyBoolean()); mController.mBroadcastCallback.onBroadcastMetadataChanged(/* reason= */ 1, mMetadata); verify(mPreference, never()).setSummary(any()); @@ -233,5 +319,34 @@ public class AudioSharingPreferenceControllerTest { mController.mBroadcastCallback.onBroadcastUpdateFailed( /* reason= */ 1, /* broadcastId= */ 1); verify(mPreference, never()).setSummary(any()); + verify(mPreference).setVisible(anyBoolean()); + + setupControllerWithKey(PREF_KEY2); + mController.displayPreference(mScreen); + shadowOf(Looper.getMainLooper()).idle(); + verify(mPreference, times(3)).setVisible(anyBoolean()); + + mController.mBroadcastCallback.onBroadcastMetadataChanged(/* reason= */ 1, mMetadata); + verify(mPreference, never()).setSummary(any()); + mController.mBroadcastCallback.onBroadcastUpdated(/* reason= */ 1, /* broadcastId= */ 1); + verify(mPreference, never()).setSummary(any()); + mController.mBroadcastCallback.onPlaybackStarted(/* reason= */ 1, /* broadcastId= */ 1); + verify(mPreference, never()).setSummary(any()); + mController.mBroadcastCallback.onPlaybackStopped(/* reason= */ 1, /* broadcastId= */ 1); + verify(mPreference, never()).setSummary(any()); + mController.mBroadcastCallback.onBroadcastStartFailed(/* reason= */ 1); + verify(mPreference, never()).setSummary(any()); + mController.mBroadcastCallback.onBroadcastStopFailed(/* reason= */ 1); + verify(mPreference, never()).setSummary(any()); + mController.mBroadcastCallback.onBroadcastUpdateFailed( + /* reason= */ 1, /* broadcastId= */ 1); + verify(mPreference, never()).setSummary(any()); + verify(mPreference, times(3)).setVisible(anyBoolean()); + } + + private void setupControllerWithKey(String preferenceKey) { + mController = new AudioSharingPreferenceController(mContext, preferenceKey); + mPreference = spy(new Preference(mContext)); + when(mScreen.findPreference(preferenceKey)).thenReturn(mPreference); } } From 75500c02b258593c048bec600b7e9d638a4497df Mon Sep 17 00:00:00 2001 From: Riley Jones Date: Fri, 17 Jan 2025 00:30:39 +0000 Subject: [PATCH 06/14] Cleanup of deprecated A11y settings functions Bug: 367414968 Test: atest com.android.settings.accessibility Flag: EXEMPT cleanup NO_IFTTT= Change does not alter preference list Change-Id: I64f5f7fba112b6fb5035b88f01c04d9ee309f2c0 --- .../accessibility/AccessibilityUtil.java | 16 -- ...cessibilityActivityPreferenceFragment.java | 19 -- ...ccessibilityServicePreferenceFragment.java | 19 -- ...oggleColorInversionPreferenceFragment.java | 8 - .../ToggleDaltonizerPreferenceFragment.java | 8 - .../ToggleFeaturePreferenceFragment.java | 9 - ...eReduceBrightColorsPreferenceFragment.java | 8 - ...ScreenMagnificationPreferenceFragment.java | 199 ++---------------- .../ShortcutOptionPreferenceController.java | 6 - .../accessibility/AccessibilityUtilTest.java | 42 +--- ...ibilityActivityPreferenceFragmentTest.java | 72 ------- ...sibilityServicePreferenceFragmentTest.java | 68 ------ ...eColorInversionPreferenceFragmentTest.java | 6 - .../ToggleFeaturePreferenceFragmentTest.java | 6 - ...enMagnificationPreferenceFragmentTest.java | 180 +++------------- .../shadow/ShadowAccessibilityManager.java | 10 +- 16 files changed, 45 insertions(+), 631 deletions(-) diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java index 04c4702de43..f3e5e6234f2 100644 --- a/src/com/android/settings/accessibility/AccessibilityUtil.java +++ b/src/com/android/settings/accessibility/AccessibilityUtil.java @@ -218,22 +218,6 @@ public final class AccessibilityUtil { return shortcutTypes; } - /** - * Converts {@link UserShortcutType} to key in Settings. - * - * @param shortcutType The shortcut type. - * @return Mapping key in Settings. - * - * @deprecated use - * {@link ShortcutUtils#convertToKey(int)} instead. - * - * (TODO 367414968: finish removal.) - */ - @Deprecated - static String convertKeyFromSettings(@UserShortcutType int shortcutType) { - return ShortcutUtils.convertToKey(shortcutType); - } - /** * Gets the width of the screen. * diff --git a/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java b/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java index f729cc7a2cc..013fdeeb215 100644 --- a/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java +++ b/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java @@ -41,7 +41,6 @@ import androidx.annotation.Nullable; import androidx.preference.Preference; import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import java.util.ArrayList; import java.util.List; @@ -116,24 +115,6 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature return mTileComponentName; } - @Override - CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { - final ComponentName componentName = getTileComponentName(); - if (componentName == null) { - return null; - } - - final CharSequence tileName = loadTileLabel(getPrefContext(), componentName); - if (tileName == null) { - return null; - } - - final int titleResId = type == QuickSettingsTooltipType.GUIDE_TO_EDIT - ? R.string.accessibility_service_qs_tooltip_content - : R.string.accessibility_service_auto_added_qs_tooltip_content; - return getString(titleResId, tileName); - } - @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Do not call super. We don't want to see the "Help & feedback" option on this page so as diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java index a2a8cf3b164..06bcdb7c2eb 100644 --- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java @@ -48,7 +48,6 @@ import androidx.annotation.Nullable; import com.android.internal.accessibility.common.ShortcutConstants; import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment; import com.android.settingslib.accessibility.AccessibilityUtils; @@ -245,24 +244,6 @@ public class ToggleAccessibilityServicePreferenceFragment extends return mTileComponentName; } - @Override - CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { - final ComponentName componentName = getTileComponentName(); - if (componentName == null) { - return null; - } - - final CharSequence tileName = loadTileLabel(getPrefContext(), componentName); - if (tileName == null) { - return null; - } - - final int titleResId = type == QuickSettingsTooltipType.GUIDE_TO_EDIT - ? R.string.accessibility_service_qs_tooltip_content - : R.string.accessibility_service_auto_added_qs_tooltip_content; - return getString(titleResId, tileName); - } - @Override protected void updateSwitchBarToggleSwitch() { final boolean checked = isAccessibilityServiceEnabled(); diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java index b779f9d2d6a..b8f31b1d618 100644 --- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java @@ -36,7 +36,6 @@ import android.view.ViewGroup; import androidx.annotation.VisibleForTesting; import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.SettingsMainSwitchPreference; import com.android.settingslib.search.SearchIndexable; @@ -179,13 +178,6 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere return COLOR_INVERSION_TILE_COMPONENT_NAME; } - @Override - CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { - return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT - ? R.string.accessibility_color_inversion_qs_tooltip_content - : R.string.accessibility_color_inversion_auto_added_qs_tooltip_content); - } - @Override protected void updateSwitchBarToggleSwitch() { final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON; diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java index fe51e69845b..42906c16345 100644 --- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java @@ -35,7 +35,6 @@ import android.view.ViewGroup; import androidx.annotation.VisibleForTesting; import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.SettingsMainSwitchPreference; import com.android.settingslib.search.SearchIndexable; @@ -194,13 +193,6 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF return DALTONIZER_TILE_COMPONENT_NAME; } - @Override - CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { - return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT - ? R.string.accessibility_color_correction_qs_tooltip_content - : R.string.accessibility_color_correction_auto_added_qs_tooltip_content); - } - @Override protected void updateSwitchBarToggleSwitch() { final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON; diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java index 91f8c4f5c22..7c34283a5f7 100644 --- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java @@ -59,7 +59,6 @@ import com.android.internal.accessibility.common.ShortcutConstants; import com.android.internal.accessibility.util.ShortcutUtils; import com.android.settings.R; import com.android.settings.SettingsActivity; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.flags.Flags; @@ -274,14 +273,6 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment /** Returns the accessibility tile component name. */ abstract ComponentName getTileComponentName(); - /** Returns the accessibility tile component name. - * - * @deprecated unused, as this class no longer displays tile tooltips. - * - * (TODO 367414968: finish removal.)*/ - @Deprecated - abstract CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type); - protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) { final CharSequence title = getString(R.string.accessibility_service_primary_switch_title, mFeatureName); diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java index ff14021108d..dc63828da3e 100644 --- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java @@ -37,7 +37,6 @@ import androidx.preference.PreferenceCategory; import androidx.preference.TwoStatePreference; import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.SeekBarPreference; import com.android.settings.widget.SettingsMainSwitchPreference; @@ -181,13 +180,6 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre return REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME; } - @Override - CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { - return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT - ? R.string.accessibility_reduce_bright_colors_qs_tooltip_content - : R.string.accessibility_reduce_bright_colors_auto_added_qs_tooltip_content); - } - @Override protected void updateSwitchBarToggleSwitch() { final boolean checked = mColorDisplayManager.isReduceBrightColorsActivated(); diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index 0d0c7fa7b02..5ecdf6770af 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -19,12 +19,6 @@ package com.android.settings.accessibility; import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_COMPONENT_NAME; import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME; import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.DEFAULT; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.GESTURE; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.QUICK_SETTINGS; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.TRIPLETAP; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.TWOFINGER_DOUBLETAP; import static com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums; import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; import static com.android.settings.accessibility.AccessibilityUtil.State.ON; @@ -39,7 +33,6 @@ import android.content.pm.PackageManager; import android.icu.text.MessageFormat; import android.net.Uri; import android.os.Bundle; -import android.os.UserHandle; import android.provider.DeviceConfig; import android.provider.Settings; import android.text.TextUtils; @@ -55,13 +48,11 @@ import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.SwitchPreferenceCompat; -import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType; import com.android.internal.accessibility.util.ShortcutUtils; import com.android.internal.annotations.VisibleForTesting; import com.android.server.accessibility.Flags; import com.android.settings.DialogCreatable; import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.core.AbstractPreferenceController; @@ -498,7 +489,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends @Override int getUserShortcutTypes() { - return getUserShortcutTypeFromSettings(getPrefContext()); + return ShortcutUtils.getEnabledShortcutTypes( + getPrefContext(), MAGNIFICATION_CONTROLLER_NAME); } @Override @@ -506,11 +498,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends return null; } - @Override - CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { - return null; - } - @Override protected void onPreferenceToggled(String preferenceKey, boolean enabled) { if (enabled && TextUtils.equals( @@ -529,11 +516,12 @@ public class ToggleScreenMagnificationPreferenceFragment extends @Override public void onToggleClicked(ShortcutPreference preference) { final int shortcutTypes = getUserPreferredShortcutTypes(); + getPrefContext().getSystemService(AccessibilityManager.class).enableShortcutsForTargets( + preference.isChecked(), shortcutTypes, + Set.of(MAGNIFICATION_CONTROLLER_NAME), getPrefContext().getUserId() + ); if (preference.isChecked()) { - optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes); showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL); - } else { - optOutAllMagnificationValuesFromSettings(getPrefContext(), shortcutTypes); } mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext())); } @@ -550,7 +538,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends @Override protected void updateShortcutPreferenceData() { - final int shortcutTypes = getUserShortcutTypeFromSettings(getPrefContext()); + final int shortcutTypes = ShortcutUtils.getEnabledShortcutTypes( + getPrefContext(), MAGNIFICATION_CONTROLLER_NAME); if (shortcutTypes != DEFAULT) { final PreferredShortcut shortcut = new PreferredShortcut( MAGNIFICATION_CONTROLLER_NAME, shortcutTypes); @@ -583,174 +572,10 @@ public class ToggleScreenMagnificationPreferenceFragment extends @Override protected void updateShortcutPreference() { - final int shortcutTypes = getUserPreferredShortcutTypes(); - mShortcutPreference.setChecked( - hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes)); + mShortcutPreference.setChecked(getUserShortcutTypes() != DEFAULT); mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext())); } - @VisibleForTesting - static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) { - if ((shortcutTypes & SOFTWARE) == SOFTWARE) { - optInMagnificationValueToSettings(context, SOFTWARE); - } - if (((shortcutTypes & HARDWARE) == HARDWARE)) { - optInMagnificationValueToSettings(context, HARDWARE); - } - if (((shortcutTypes & TRIPLETAP) == TRIPLETAP)) { - optInMagnificationValueToSettings(context, TRIPLETAP); - } - if (((shortcutTypes & GESTURE) == GESTURE)) { - optInMagnificationValueToSettings(context, GESTURE); - } - if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { - if (((shortcutTypes & TWOFINGER_DOUBLETAP) - == TWOFINGER_DOUBLETAP)) { - optInMagnificationValueToSettings(context, TWOFINGER_DOUBLETAP); - } - } - if (((shortcutTypes & QUICK_SETTINGS) - == QUICK_SETTINGS)) { - optInMagnificationValueToSettings(context, QUICK_SETTINGS); - } - } - - /** - * @deprecated use - * {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead. - * - * (TODO 367414968: finish removal.) - */ - @Deprecated - private static void optInMagnificationValueToSettings( - Context context, @UserShortcutType int shortcutType) { - AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class); - if (a11yManager != null) { - a11yManager.enableShortcutsForTargets( - /* enable= */ true, - shortcutType, - Set.of(MAGNIFICATION_CONTROLLER_NAME), - UserHandle.myUserId() - ); - } - } - - @VisibleForTesting - static void optOutAllMagnificationValuesFromSettings(Context context, - int shortcutTypes) { - if ((shortcutTypes & SOFTWARE) == SOFTWARE) { - optOutMagnificationValueFromSettings(context, SOFTWARE); - } - if (((shortcutTypes & HARDWARE) == HARDWARE)) { - optOutMagnificationValueFromSettings(context, HARDWARE); - } - if (((shortcutTypes & TRIPLETAP) == TRIPLETAP)) { - optOutMagnificationValueFromSettings(context, TRIPLETAP); - } - if (((shortcutTypes & GESTURE) == GESTURE)) { - optOutMagnificationValueFromSettings(context, GESTURE); - } - if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { - if (((shortcutTypes & TWOFINGER_DOUBLETAP) - == TWOFINGER_DOUBLETAP)) { - optOutMagnificationValueFromSettings(context, TWOFINGER_DOUBLETAP); - } - } - if (((shortcutTypes & QUICK_SETTINGS) - == QUICK_SETTINGS)) { - optOutMagnificationValueFromSettings(context, QUICK_SETTINGS); - } - } - - /** - * @deprecated use - * {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead. - * - * (TODO 367414968: finish removal.) - */ - @Deprecated - private static void optOutMagnificationValueFromSettings(Context context, - @UserShortcutType int shortcutType) { - AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class); - if (a11yManager != null) { - a11yManager.enableShortcutsForTargets( - /* enable= */ false, - shortcutType, - Set.of(MAGNIFICATION_CONTROLLER_NAME), - UserHandle.myUserId() - ); - } - } - - @VisibleForTesting - static boolean hasMagnificationValuesInSettings(Context context, int shortcutTypes) { - for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) { - if ((shortcutTypes & shortcutType) == 0) { - continue; - } - if (((shortcutType & TWOFINGER_DOUBLETAP) - == TWOFINGER_DOUBLETAP) - && !Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { - continue; - } - if (hasMagnificationValueInSettings(context, shortcutType)) { - return true; - } - } - - return false; - } - - private static boolean hasMagnificationValueInSettings(Context context, - @UserShortcutType int shortcutType) { - if (shortcutType == TRIPLETAP) { - return Settings.Secure.getInt(context.getContentResolver(), - Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF) == ON; - } - if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) { - if (shortcutType == TWOFINGER_DOUBLETAP) { - return Settings.Secure.getInt(context.getContentResolver(), - Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED, - OFF) == ON; - } - } - - final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType); - final String targetString = Settings.Secure.getString(context.getContentResolver(), - targetKey); - - if (TextUtils.isEmpty(targetString)) { - return false; - } - - sStringColonSplitter.setString(targetString); - while (sStringColonSplitter.hasNext()) { - final String name = sStringColonSplitter.next(); - if (MAGNIFICATION_CONTROLLER_NAME.equals(name)) { - return true; - } - } - return false; - } - - /** - * @deprecated use - * {@link ShortcutUtils#getEnabledShortcutTypes(Context, String)} instead. - * - * (TODO 367414968: finish removal.) - */ - @Deprecated - private static int getUserShortcutTypeFromSettings(Context context) { - int shortcutTypes = DEFAULT; - for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) { - if (hasMagnificationValueInSettings(context, shortcutType)) { - shortcutTypes |= shortcutType; - } - } - - return shortcutTypes; - } - /** * Gets the service summary of magnification. * @@ -758,7 +583,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends */ public static CharSequence getServiceSummary(Context context) { // Get the user shortcut type from settings provider. - final int userShortcutType = getUserShortcutTypeFromSettings(context); + final int userShortcutType = ShortcutUtils.getEnabledShortcutTypes( + context, MAGNIFICATION_CONTROLLER_NAME); final CharSequence featureState = (userShortcutType != DEFAULT) ? context.getText(R.string.accessibility_summary_shortcut_enabled) @@ -822,7 +648,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends // mention magnification so it may confuse users who search a term // like "Keep on". // So we hide it if the user has no magnification shortcut enabled. - || getUserShortcutTypeFromSettings(context) == DEFAULT) { + || ShortcutUtils.getEnabledShortcutTypes( + context, MAGNIFICATION_CONTROLLER_NAME) == DEFAULT) { niks.add(MagnificationAlwaysOnPreferenceController.PREF_KEY); } if (!isOneFingerPanningSupported()) { diff --git a/src/com/android/settings/accessibility/shortcuts/ShortcutOptionPreferenceController.java b/src/com/android/settings/accessibility/shortcuts/ShortcutOptionPreferenceController.java index afb5acf272c..70e8141cf50 100644 --- a/src/com/android/settings/accessibility/shortcuts/ShortcutOptionPreferenceController.java +++ b/src/com/android/settings/accessibility/shortcuts/ShortcutOptionPreferenceController.java @@ -113,13 +113,7 @@ public abstract class ShortcutOptionPreferenceController extends BasePreferenceC /** * Enable or disable the shortcut for the given accessibility features. - * - * @deprecated use - * {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead. - * - * (TODO 367414968: finish removal.) */ - @Deprecated protected void enableShortcutForTargets(boolean enable) { Set shortcutTargets = getShortcutTargets(); @ShortcutConstants.UserShortcutType int shortcutType = getShortcutType(); diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java index c93ee1e8e2e..4e8c592c44f 100644 --- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityUtilTest.java @@ -21,16 +21,8 @@ import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_GESTURE import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON; import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.QUICK_SETTINGS; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.TRIPLETAP; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.TWOFINGER_DOUBLETAP; - import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.spy; - import android.accessibilityservice.AccessibilityServiceInfo; import android.content.ComponentName; import android.content.Context; @@ -61,7 +53,6 @@ public final class AccessibilityUtilTest { private static final String SECURE_TEST_KEY = "secure_test_key"; private static final String MOCK_PACKAGE_NAME = "com.mock.example"; private static final String MOCK_CLASS_NAME = MOCK_PACKAGE_NAME + ".mock_a11y_service"; - private static final String MOCK_CLASS_NAME2 = MOCK_PACKAGE_NAME + ".mock_a11y_service2"; private static final ComponentName MOCK_COMPONENT_NAME = new ComponentName(MOCK_PACKAGE_NAME, MOCK_CLASS_NAME); @Rule @@ -71,7 +62,7 @@ public final class AccessibilityUtilTest { @Before public void setUp() { - mContext = spy(ApplicationProvider.getApplicationContext()); + mContext = ApplicationProvider.getApplicationContext(); } @Test @@ -148,37 +139,6 @@ public final class AccessibilityUtilTest { AccessibilityUtil.AccessibilityServiceFragmentType.TOGGLE); } - @Test - public void convertKeyFromSettings_shortcutTypeSoftware() { - assertThat(AccessibilityUtil.convertKeyFromSettings(SOFTWARE)) - .isEqualTo(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS); - } - - @Test - public void convertKeyFromSettings_shortcutTypeHardware() { - assertThat(AccessibilityUtil.convertKeyFromSettings(HARDWARE)) - .isEqualTo(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE); - } - - @Test - public void convertKeyFromSettings_shortcutTypeTripleTap() { - assertThat(AccessibilityUtil.convertKeyFromSettings(TRIPLETAP)) - .isEqualTo(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED); - } - - @Test - public void convertKeyFromSettings_shortcutTypeMultiFingersMultiTap() { - assertThat(AccessibilityUtil.convertKeyFromSettings(TWOFINGER_DOUBLETAP)) - .isEqualTo( - Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED); - } - - @Test - public void convertKeyFromSettings_shortcutTypeQuickSettings() { - assertThat(AccessibilityUtil.convertKeyFromSettings(QUICK_SETTINGS)) - .isEqualTo(Settings.Secure.ACCESSIBILITY_QS_TARGETS); - } - @Test @EnableFlags(android.provider.Flags.FLAG_A11Y_STANDALONE_GESTURE_ENABLED) public void getSoftwareShortcutSummary_returnsSoftwareSummary() { diff --git a/tests/robotests/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragmentTest.java index 8d5724bb197..da8fd7ef5ca 100644 --- a/tests/robotests/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragmentTest.java @@ -16,8 +16,6 @@ package com.android.settings.accessibility; -import static com.google.common.truth.Truth.assertThat; - import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -34,11 +32,7 @@ import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; -import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; - import org.junit.Before; -import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.Mock; @@ -83,72 +77,6 @@ public class LaunchAccessibilityActivityPreferenceFragmentTest { doReturn(mScreen).when(mFragment).getPreferenceScreen(); } - @Test - public void getTileTooltipContent_noTileServiceAssigned_returnNull() { - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT); - - assertThat(tileTooltipContent).isNull(); - } - - @Test - public void getTileTooltipContent_hasOneTileService_guideToEdit_haveMatchString() { - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME, - PLACEHOLDER_TILE_NAME); - - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT); - final CharSequence tileName = - mFragment.loadTileLabel(mContext, mFragment.getTileComponentName()); - assertThat(tileTooltipContent.toString()).isEqualTo( - mContext.getString(R.string.accessibility_service_qs_tooltip_content, tileName)); - } - - @Test - public void getTileTooltipContent_hasOneTileService_guideToDirectUse_haveMatchString() { - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME, - PLACEHOLDER_TILE_NAME); - - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE); - final CharSequence tileName = - mFragment.loadTileLabel(mContext, mFragment.getTileComponentName()); - assertThat(tileTooltipContent.toString()).isEqualTo( - mContext.getString( - R.string.accessibility_service_auto_added_qs_tooltip_content, tileName)); - } - - @Test - public void getTileTooltipContent_hasTwoTileServices_guideToEdit_haveMatchString() { - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME, - PLACEHOLDER_TILE_NAME); - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME2, - PLACEHOLDER_TILE_NAME2); - - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT); - final CharSequence tileName = - mFragment.loadTileLabel(mContext, mFragment.getTileComponentName()); - assertThat(tileTooltipContent.toString()).isEqualTo( - mContext.getString(R.string.accessibility_service_qs_tooltip_content, tileName)); - } - - @Test - public void getTileTooltipContent_hasTwoTileServices_guideToDirectUse_haveMatchString() { - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME, - PLACEHOLDER_TILE_NAME); - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME2, - PLACEHOLDER_TILE_NAME2); - - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE); - final CharSequence tileName = - mFragment.loadTileLabel(mContext, mFragment.getTileComponentName()); - assertThat(tileTooltipContent.toString()).isEqualTo( - mContext.getString( - R.string.accessibility_service_auto_added_qs_tooltip_content, tileName)); - } - private void setupTileService(String packageName, String name, String tileName) { final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE); final ResolveInfo info = new ResolveInfo(); diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragmentTest.java index 70290af8a61..db5aec56276 100644 --- a/tests/robotests/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragmentTest.java @@ -43,9 +43,7 @@ import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; import com.android.internal.accessibility.common.ShortcutConstants; -import com.android.settings.R; import com.android.settings.SettingsActivity; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment; import com.android.settings.widget.SettingsMainSwitchPreference; @@ -111,72 +109,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest { mShadowAccessibilityManager = Shadow.extract(AccessibilityManager.getInstance(mContext)); } - @Test - public void getTileTooltipContent_noTileServiceAssigned_returnNull() { - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT); - - assertThat(tileTooltipContent).isNull(); - } - - @Test - public void getTileTooltipContent_hasOneTileService_guideToEdit_haveMatchString() { - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME, - PLACEHOLDER_TILE_NAME); - - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT); - final CharSequence tileName = - mFragment.loadTileLabel(mContext, mFragment.getTileComponentName()); - assertThat(tileTooltipContent.toString()).isEqualTo( - mContext.getString(R.string.accessibility_service_qs_tooltip_content, tileName)); - } - - @Test - public void getTileTooltipContent_hasOneTileService_guideToDirectUse_haveMatchString() { - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME, - PLACEHOLDER_TILE_NAME); - - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE); - final CharSequence tileName = - mFragment.loadTileLabel(mContext, mFragment.getTileComponentName()); - assertThat(tileTooltipContent.toString()).isEqualTo( - mContext.getString( - R.string.accessibility_service_auto_added_qs_tooltip_content, tileName)); - } - - @Test - public void getTileTooltipContent_hasTwoTileServices_guideToEdit_haveMatchString() { - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME, - PLACEHOLDER_TILE_NAME); - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME2, - PLACEHOLDER_TILE_NAME2); - - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT); - final CharSequence tileName = - mFragment.loadTileLabel(mContext, mFragment.getTileComponentName()); - assertThat(tileTooltipContent.toString()).isEqualTo( - mContext.getString(R.string.accessibility_service_qs_tooltip_content, tileName)); - } - - @Test - public void getTileTooltipContent_hasTwoTileServices_guideToDirectUse_haveMatchString() { - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME, - PLACEHOLDER_TILE_NAME); - setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME2, - PLACEHOLDER_TILE_NAME2); - - final CharSequence tileTooltipContent = - mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE); - final CharSequence tileName = - mFragment.loadTileLabel(mContext, mFragment.getTileComponentName()); - assertThat(tileTooltipContent.toString()).isEqualTo( - mContext.getString( - R.string.accessibility_service_auto_added_qs_tooltip_content, tileName)); - } - @Test public void getAccessibilityServiceInfo() throws Throwable { final AccessibilityServiceInfo info1 = getFakeAccessibilityServiceInfo( diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragmentTest.java index cbd449305d4..ff73e7feece 100644 --- a/tests/robotests/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragmentTest.java @@ -47,7 +47,6 @@ import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.shadow.ShadowFragment; import com.android.settings.widget.SettingsMainSwitchPreference; @@ -265,11 +264,6 @@ public class ToggleColorInversionPreferenceFragmentTest { return PLACEHOLDER_COMPONENT_NAME; } - @Override - protected CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { - return PLACEHOLDER_TILE_TOOLTIP_CONTENT; - } - @Override public View getView() { return mock(View.class); diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java index ad5b1b59a99..8f9d2e1fbd0 100644 --- a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java @@ -53,7 +53,6 @@ import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; import com.android.settings.R; -import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType; import com.android.settings.flags.Flags; import com.android.settings.testutils.shadow.ShadowAccessibilityManager; import com.android.settings.testutils.shadow.ShadowFragment; @@ -378,11 +377,6 @@ public class ToggleFeaturePreferenceFragmentTest { return PLACEHOLDER_TILE_COMPONENT_NAME; } - @Override - protected CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) { - return PLACEHOLDER_TILE_TOOLTIP_CONTENT; - } - @Override public int getPreferenceScreenResId() { return R.xml.placeholder_prefs; diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java index 863452fb645..ae059ddfafd 100644 --- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java @@ -35,7 +35,6 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; 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 android.app.settings.SettingsEnums; @@ -47,7 +46,6 @@ import android.database.ContentObserver; import android.icu.text.CaseMap; import android.net.Uri; import android.os.Bundle; -import android.os.UserHandle; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; @@ -66,7 +64,7 @@ import com.android.server.accessibility.Flags; import com.android.settings.DialogCreatable; import com.android.settings.R; import com.android.settings.SettingsActivity; -import com.android.settings.testutils.AccessibilityTestUtils; +import com.android.settings.testutils.shadow.ShadowAccessibilityManager; import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settings.testutils.shadow.ShadowStorageManager; import com.android.settings.testutils.shadow.ShadowUserManager; @@ -83,6 +81,7 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.Shadows; import org.robolectric.annotation.Config; +import org.robolectric.shadow.api.Shadow; import org.robolectric.shadows.ShadowContentResolver; import org.robolectric.shadows.ShadowPackageManager; import org.robolectric.shadows.ShadowSettings; @@ -92,7 +91,6 @@ import org.robolectric.util.ReflectionHelpers; import java.util.Collection; import java.util.List; import java.util.Locale; -import java.util.Set; /** Tests for {@link ToggleScreenMagnificationPreferenceFragment}. */ @RunWith(RobolectricTestRunner.class) @@ -101,6 +99,7 @@ import java.util.Set; ShadowStorageManager.class, ShadowSettings.ShadowSecure.class, ShadowDeviceConfig.class, + ShadowAccessibilityManager.class, }) public class ToggleScreenMagnificationPreferenceFragmentTest { @@ -137,15 +136,15 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { private FragmentController mFragController; private Context mContext; - private AccessibilityManager mAccessibilityManager; private Resources mSpyResources; private ShadowPackageManager mShadowPackageManager; + private ShadowAccessibilityManager mShadowAccessibilityManager; @Before public void setUpTestFragment() { - mContext = spy(ApplicationProvider.getApplicationContext()); - mAccessibilityManager = AccessibilityTestUtils.setupMockAccessibilityManager(mContext); + mShadowAccessibilityManager = Shadow.extract( + mContext.getSystemService(AccessibilityManager.class)); // Set up the fragment that support window magnification feature mSpyResources = spy(mContext.getResources()); @@ -420,137 +419,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { assertThat(shadowContentResolver.getContentObservers(observedUri)).isEmpty(); } - @Test - public void hasValueInSettings_putValue_hasValue() { - setMagnificationTripleTapEnabled(/* enabled= */ true); - - assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings( - mContext, TRIPLETAP)).isTrue(); - } - - @Test - @EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) - public void hasMagnificationValuesInSettings_twoFingerTripleTapIsOn_isTrue() { - Settings.Secure.putInt( - mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON); - - assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings( - mContext, TWOFINGER_DOUBLETAP)).isTrue(); - } - - @Test - @EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) - public void hasMagnificationValuesInSettings_twoFingerTripleTapIsOff_isFalse() { - Settings.Secure.putInt( - mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF); - - assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings( - mContext, TWOFINGER_DOUBLETAP)).isFalse(); - } - - @Test - public void optInAllValuesToSettings_optInValue_callA11yManager() { - int shortcutTypes = - SOFTWARE | TRIPLETAP | HARDWARE - | QUICK_SETTINGS; - Set shortcutTargets = Set.of(MAGNIFICATION_CONTROLLER_NAME); - - ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext, - shortcutTypes); - - verify(mAccessibilityManager).enableShortcutsForTargets( - /* enable= */ true, SOFTWARE, - shortcutTargets, UserHandle.myUserId()); - verify(mAccessibilityManager).enableShortcutsForTargets( - /* enable= */ true, HARDWARE, - shortcutTargets, UserHandle.myUserId()); - verify(mAccessibilityManager).enableShortcutsForTargets( - /* enable= */ true, QUICK_SETTINGS, - shortcutTargets, UserHandle.myUserId()); - verify(mAccessibilityManager).enableShortcutsForTargets( - /* enable= */ true, TRIPLETAP, - shortcutTargets, UserHandle.myUserId()); - verifyNoMoreInteractions(mAccessibilityManager); - } - - @Test - public void optInAllValuesToSettings_software_sizeValueIsNotNull_sizeValueIsNotChanged() { - for (int size : new int[]{FloatingMenuSizePreferenceController.Size.LARGE, - FloatingMenuSizePreferenceController.Size.SMALL}) { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE, size); - - ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings( - mContext, - SOFTWARE); - - assertThat(Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE, - FloatingMenuSizePreferenceController.Size.UNKNOWN)).isEqualTo( - size); - } - } - - @Test - public void optInAllValuesToSettings_hardware_sizeValueIsNotChanged() { - for (int size : new int[]{FloatingMenuSizePreferenceController.Size.UNKNOWN, - FloatingMenuSizePreferenceController.Size.LARGE, - FloatingMenuSizePreferenceController.Size.SMALL}) { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE, size); - - ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings( - mContext, - HARDWARE); - - assertThat(Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE, size + 1)).isEqualTo( - size); - } - } - - @Test - public void optInAllValuesToSettings_tripletap_sizeValueIsNotChanged() { - for (int size : new int[]{FloatingMenuSizePreferenceController.Size.UNKNOWN, - FloatingMenuSizePreferenceController.Size.LARGE, - FloatingMenuSizePreferenceController.Size.SMALL}) { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE, size); - - ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings( - mContext, - TRIPLETAP); - - assertThat(Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE, size + 1)).isEqualTo( - size); - } - } - - @Test - public void optOutAllValuesToSettings_optOutValue_callA11yManager() { - Set 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 = - SOFTWARE | HARDWARE | TRIPLETAP; - - ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings( - mContext, shortcutTypes); - - verify(mAccessibilityManager).enableShortcutsForTargets( - /* enable= */ false, SOFTWARE, - shortcutTargets, UserHandle.myUserId()); - verify(mAccessibilityManager).enableShortcutsForTargets( - /* enable= */ false, HARDWARE, - shortcutTargets, UserHandle.myUserId()); - verify(mAccessibilityManager).enableShortcutsForTargets( - /* enable= */ false, TRIPLETAP, - shortcutTargets, UserHandle.myUserId()); - verifyNoMoreInteractions(mAccessibilityManager); - } - @Test public void updateShortcutPreferenceData_assignDefaultValueToVariable() { mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); @@ -565,8 +433,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Test public void updateShortcutPreferenceData_hasValueInSettings_assignToVariable() { - putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME); - setMagnificationTripleTapEnabled(/* enabled= */ true); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TRIPLETAP | SOFTWARE, List.of(MAGNIFICATION_CONTROLLER_NAME)); mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); mFragController.get().updateShortcutPreferenceData(); @@ -593,8 +461,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Test @EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) public void updateShortcutPreferenceData_hasTwoFingerTripleTapInSettings_assignToVariable() { - Settings.Secure.putInt( - mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TWOFINGER_DOUBLETAP, List.of(MAGNIFICATION_CONTROLLER_NAME)); mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); mFragController.get().updateShortcutPreferenceData(); @@ -802,7 +670,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Test public void getSummary_magnificationEnabled_returnShortcutOnWithSummary() { - setMagnificationTripleTapEnabled(true); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TRIPLETAP, List.of(MAGNIFICATION_CONTROLLER_NAME)); assertThat( ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString()) @@ -816,7 +685,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Test public void getSummary_magnificationDisabled_returnShortcutOffWithSummary() { - setMagnificationTripleTapEnabled(false); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TRIPLETAP, List.of()); assertThat( ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString()) @@ -832,8 +702,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Test @EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) public void getSummary_magnificationGestureEnabled_returnShortcutOnWithSummary() { - Settings.Secure.putInt( - mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TWOFINGER_DOUBLETAP, List.of(MAGNIFICATION_CONTROLLER_NAME)); assertThat( ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString()) @@ -848,8 +718,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Test @EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE) public void getSummary_magnificationGestureDisabled_returnShortcutOffWithSummary() { - Settings.Secure.putInt( - mContext.getContentResolver(), TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TRIPLETAP | TWOFINGER_DOUBLETAP, List.of()); assertThat( ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext).toString()) @@ -977,7 +847,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { Flags.FLAG_ENABLE_MAGNIFICATION_ONE_FINGER_PANNING_GESTURE, Flags.FLAG_ENABLE_LOW_VISION_HATS}) public void getNonIndexableKeys_hasShortcutAndAllFeaturesEnabled_allItemsSearchable() { - setMagnificationTripleTapEnabled(true); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TRIPLETAP, List.of(MAGNIFICATION_CONTROLLER_NAME)); setAlwaysOnSupported(true); setJoystickSupported(true); @@ -991,7 +862,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Test @EnableFlags(com.android.settings.accessibility.Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH) public void getNonIndexableKeys_noShortcut_alwaysOnSupported_notSearchable() { - setMagnificationTripleTapEnabled(false); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TRIPLETAP, List.of()); setAlwaysOnSupported(true); final List niks = ToggleScreenMagnificationPreferenceFragment @@ -1004,7 +876,8 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { @Test @EnableFlags(com.android.settings.accessibility.Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH) public void getNonIndexableKeys_hasShortcut_alwaysOnNotSupported_notSearchable() { - setMagnificationTripleTapEnabled(true); + mShadowAccessibilityManager.setAccessibilityShortcutTargets( + TRIPLETAP, List.of(MAGNIFICATION_CONTROLLER_NAME)); setAlwaysOnSupported(false); final List niks = ToggleScreenMagnificationPreferenceFragment @@ -1056,11 +929,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { PreferredShortcuts.saveUserShortcutType(context, shortcut); } - private void setMagnificationTripleTapEnabled(boolean enabled) { - Settings.Secure.putInt(mContext.getContentResolver(), TRIPLETAP_SHORTCUT_KEY, - enabled ? ON : OFF); - } - private void setKeyMagnificationMode(@MagnificationMode int mode) { MagnificationCapabilities.setCapabilities(mContext, mode); } diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccessibilityManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccessibilityManager.java index 2741212b23a..4de733972ce 100644 --- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccessibilityManager.java +++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAccessibilityManager.java @@ -26,6 +26,7 @@ import android.content.Context; import android.util.ArrayMap; import android.view.accessibility.AccessibilityManager; +import com.android.internal.accessibility.common.ShortcutConstants; import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType; import org.robolectric.annotation.Implementation; @@ -96,8 +97,11 @@ public class ShadowAccessibilityManager extends org.robolectric.shadows.ShadowAc /** * Used by tests to easily write directly to a shortcut targets value */ - public void setAccessibilityShortcutTargets( - @UserShortcutType int shortcutType, List targets) { - mShortcutTargets.put(shortcutType, targets); + public void setAccessibilityShortcutTargets(int shortcutTypes, List targets) { + for (int type : ShortcutConstants.USER_SHORTCUT_TYPES) { + if ((type & shortcutTypes) == type) { + mShortcutTargets.put(type, List.copyOf(targets)); + } + } } } From 82100793fdbcf246bd62294f8214f221f666b34d Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Mon, 20 Jan 2025 12:30:15 +0800 Subject: [PATCH 07/14] [Catalyst] Implement metrics logger for Get/Set/Graph API Bug: 372980186 Flag: com.android.settings.flags.catalyst Test: statsd_testdrive Change-Id: I358449612a09ef325e47d0d107e1d72339a9f741 --- src/com/android/settings/Metrics.kt | 2 +- src/com/android/settings/SettingsService.kt | 31 +--- .../metrics/SettingsRemoteOpMetricsLogger.kt | 159 ++++++++++++++++++ .../settings/service/PreferenceService.kt | 32 ++-- 4 files changed, 179 insertions(+), 45 deletions(-) create mode 100644 src/com/android/settings/metrics/SettingsRemoteOpMetricsLogger.kt diff --git a/src/com/android/settings/Metrics.kt b/src/com/android/settings/Metrics.kt index 0d5ea56aff3..8dde9d5a60f 100644 --- a/src/com/android/settings/Metrics.kt +++ b/src/com/android/settings/Metrics.kt @@ -19,9 +19,9 @@ package com.android.settings import android.content.Context import com.android.settings.overlay.FeatureFactory import com.android.settingslib.core.instrumentation.MetricsFeatureProvider -import com.android.settingslib.metadata.PreferenceUiActionMetricsLogger import com.android.settingslib.metadata.PreferenceMetadata import com.android.settingslib.metadata.PreferenceScreenMetadata +import com.android.settingslib.metadata.PreferenceUiActionMetricsLogger /** Provides metrics for preference action. */ interface PreferenceActionMetricsProvider { diff --git a/src/com/android/settings/SettingsService.kt b/src/com/android/settings/SettingsService.kt index 1783a7d423e..b7c6220bd23 100644 --- a/src/com/android/settings/SettingsService.kt +++ b/src/com/android/settings/SettingsService.kt @@ -16,11 +16,9 @@ package com.android.settings -import android.app.Application import android.content.Intent import com.android.settings.flags.Flags -import com.android.settingslib.graph.PreferenceGetterRequest -import com.android.settingslib.graph.PreferenceSetterRequest +import com.android.settings.metrics.SettingsRemoteOpMetricsLogger import com.android.settingslib.ipc.ApiPermissionChecker import com.android.settingslib.service.PreferenceService @@ -28,32 +26,11 @@ import com.android.settingslib.service.PreferenceService class SettingsService : PreferenceService( graphPermissionChecker = ApiPermissionChecker.alwaysAllow(), - setterPermissionChecker = SetterPermissionChecker(), - getterPermissionChecker = GetterPermissionChecker(), + setterPermissionChecker = ApiPermissionChecker.alwaysAllow(), + getterPermissionChecker = ApiPermissionChecker.alwaysAllow(), + metricsLogger = SettingsRemoteOpMetricsLogger(), ) { override fun onBind(intent: Intent) = if (Flags.catalystService()) super.onBind(intent) else null } - -/** Permission checker for external setter API. */ -private class SetterPermissionChecker : ApiPermissionChecker { - - override fun hasPermission( - application: Application, - callingPid: Int, - callingUid: Int, - request: PreferenceSetterRequest, - ) = true -} - -/** Permission checker for external getter API. */ -private class GetterPermissionChecker : ApiPermissionChecker { - - override fun hasPermission( - application: Application, - callingPid: Int, - callingUid: Int, - request: PreferenceGetterRequest, - ) = true -} diff --git a/src/com/android/settings/metrics/SettingsRemoteOpMetricsLogger.kt b/src/com/android/settings/metrics/SettingsRemoteOpMetricsLogger.kt new file mode 100644 index 00000000000..8653ef9ff0e --- /dev/null +++ b/src/com/android/settings/metrics/SettingsRemoteOpMetricsLogger.kt @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2025 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.metrics + +import android.app.settings.SettingsEnums +import android.content.Context +import com.android.settings.PreferenceActionMetricsProvider +import com.android.settings.core.instrumentation.SettingsStatsLog +import com.android.settingslib.graph.PreferenceGetterErrorCode +import com.android.settingslib.graph.PreferenceSetterResult +import com.android.settingslib.metadata.PreferenceCoordinate +import com.android.settingslib.metadata.PreferenceMetadata +import com.android.settingslib.metadata.PreferenceRemoteOpMetricsLogger +import com.android.settingslib.metadata.PreferenceScreenMetadata + +/** Metrics logger for settings remote operations. */ +class SettingsRemoteOpMetricsLogger : PreferenceRemoteOpMetricsLogger { + + override fun logGetterApi( + context: Context, + callingUid: Int, + preferenceCoordinate: PreferenceCoordinate, + screen: PreferenceScreenMetadata?, + preference: PreferenceMetadata?, + errorCode: Int, + latencyMs: Long, + ) = + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__TYPE__ACTION_READ.log( + context, + callingUid, + preferenceCoordinate, + preference, + errorCode, + latencyMs, + Int::convertGetterErrorCode, + ) + + override fun logSetterApi( + context: Context, + callingUid: Int, + preferenceCoordinate: PreferenceCoordinate, + screen: PreferenceScreenMetadata?, + preference: PreferenceMetadata?, + errorCode: Int, + latencyMs: Long, + ) = + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__TYPE__ACTION_WRITE.log( + context, + callingUid, + preferenceCoordinate, + preference, + errorCode, + latencyMs, + Int::convertSetterErrorCode, + ) + + private fun Int.log( + context: Context, + callingUid: Int, + preferenceCoordinate: PreferenceCoordinate, + preference: PreferenceMetadata?, + errorCode: Int, + latencyMs: Long, + errorCodeToMetricsResult: (Int) -> Int, + ) { + if (preference is PreferenceActionMetricsProvider) { + SettingsStatsLog.write( + SettingsStatsLog.SETTINGS_EXTAPI_REPORTED, + context.packageNameOfUid(callingUid), + "", + this, + errorCodeToMetricsResult(errorCode), + latencyMs, + preference.preferenceActionMetrics, + ) + } else { + SettingsStatsLog.write( + SettingsStatsLog.SETTINGS_EXTAPI_REPORTED, + context.packageNameOfUid(callingUid), + preferenceCoordinate.settingsId, + this, + errorCodeToMetricsResult(errorCode), + latencyMs, + SettingsEnums.ACTION_UNKNOWN, + ) + } + } + + override fun logGraphApi(context: Context, callingUid: Int, success: Boolean, latencyMs: Long) { + val result = + if (success) { + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_OK + } else { + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_INTERNAL_ERROR + } + SettingsStatsLog.write( + SettingsStatsLog.SETTINGS_EXTAPI_REPORTED, + context.packageNameOfUid(callingUid), + "", + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__TYPE__ACTION_GET_METADATA, + result, + latencyMs, + SettingsEnums.ACTION_UNKNOWN, + ) + } +} + +private fun Context.packageNameOfUid(uid: Int) = packageManager.getNameForUid(uid) ?: "" + +private val PreferenceCoordinate.settingsId: String + get() = "$screenKey/$key" + +private fun Int.convertGetterErrorCode() = + when (this) { + PreferenceGetterErrorCode.OK -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_OK + PreferenceGetterErrorCode.NOT_FOUND -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_UNSUPPORTED + PreferenceGetterErrorCode.DISALLOW -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_DISALLOW + else -> SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_INTERNAL_ERROR + } + +private fun Int.convertSetterErrorCode() = + when (this) { + PreferenceSetterResult.OK -> SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_OK + PreferenceSetterResult.UNSUPPORTED -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_UNSUPPORTED + PreferenceSetterResult.DISABLED -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_DISABLED + PreferenceSetterResult.RESTRICTED -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_RESTRICTED + PreferenceSetterResult.UNAVAILABLE -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_UNAVAILABLE + PreferenceSetterResult.REQUIRE_APP_PERMISSION -> + SettingsStatsLog + .SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_REQUIRE_APP_PERMISSION + PreferenceSetterResult.REQUIRE_USER_AGREEMENT -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_REQUIRE_USER_CONSENT + PreferenceSetterResult.DISALLOW -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_DISALLOW + PreferenceSetterResult.INVALID_REQUEST -> + SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_INVALID_REQUEST + else -> SettingsStatsLog.SETTINGS_EXT_API_REPORTED__RESULT__RESULT_FAILURE_INTERNAL_ERROR + } diff --git a/src/com/android/settings/service/PreferenceService.kt b/src/com/android/settings/service/PreferenceService.kt index 2e5191486c0..9843847304e 100644 --- a/src/com/android/settings/service/PreferenceService.kt +++ b/src/com/android/settings/service/PreferenceService.kt @@ -16,7 +16,6 @@ package com.android.settings.service -import android.app.Application import android.os.Binder import android.os.OutcomeReceiver import android.service.settings.preferences.GetValueRequest @@ -26,6 +25,7 @@ import android.service.settings.preferences.MetadataResult import android.service.settings.preferences.SetValueRequest import android.service.settings.preferences.SetValueResult import android.service.settings.preferences.SettingsPreferenceService +import com.android.settings.metrics.SettingsRemoteOpMetricsLogger import com.android.settingslib.graph.GetPreferenceGraphApiHandler import com.android.settingslib.graph.GetPreferenceGraphRequest import com.android.settingslib.graph.PreferenceGetterApiHandler @@ -41,9 +41,19 @@ class PreferenceService : SettingsPreferenceService() { private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) - private val getApiHandler = PreferenceGetterApiHandler(1, ApiPermissionChecker.alwaysAllow()) - private val setApiHandler = PreferenceSetterApiHandler(2, ApiPermissionChecker.alwaysAllow()) - private val graphApi = GraphProvider(3) + private val getApiHandler: PreferenceGetterApiHandler + private val setApiHandler: PreferenceSetterApiHandler + private val graphApi: GetPreferenceGraphApiHandler + + init { + val metricsLogger = SettingsRemoteOpMetricsLogger() + getApiHandler = + PreferenceGetterApiHandler(1, ApiPermissionChecker.alwaysAllow(), metricsLogger) + setApiHandler = + PreferenceSetterApiHandler(2, ApiPermissionChecker.alwaysAllow(), metricsLogger) + graphApi = + GetPreferenceGraphApiHandler(3, ApiPermissionChecker.alwaysAllow(), metricsLogger) + } override fun onGetAllPreferenceMetadata( request: MetadataRequest, @@ -58,9 +68,7 @@ class PreferenceService : SettingsPreferenceService() { application, callingPid, callingUid, - GetPreferenceGraphRequest( - flags = PreferenceGetterFlags.METADATA, - ), + GetPreferenceGraphRequest(flags = PreferenceGetterFlags.METADATA), ) val result = transformCatalystGetMetadataResponse(this@PreferenceService, graphProto) callback.onResult(result) @@ -107,14 +115,4 @@ class PreferenceService : SettingsPreferenceService() { } } } - - // Basic implementation - we already have permission to access Graph for Metadata via superclass - private class GraphProvider(override val id: Int) : GetPreferenceGraphApiHandler(emptySet()) { - override fun hasPermission( - application: Application, - callingPid: Int, - callingUid: Int, - request: GetPreferenceGraphRequest, - ) = true - } } From d38e43b82fd76b4e32ca64016c514a1e19db1531 Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Wed, 22 Jan 2025 01:25:23 +0000 Subject: [PATCH 08/14] [Catalyst] Initial migration for "Display size and text" screen Test: Manual Bug: 372776688 Flag: com.android.settings.flags.catalyst_text_reading_screen Change-Id: Iadbf36cee58083b8182ed5b275912a9e3a15b119 --- .../TextReadingDisplaySizePreference.kt | 49 ++++++++++++++++++ .../TextReadingFontSizePreference.kt | 50 +++++++++++++++++++ .../accessibility/TextReadingPreview.kt | 33 ++++++++++++ .../accessibility/TextReadingScreen.kt | 12 +++-- 4 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 src/com/android/settings/accessibility/TextReadingDisplaySizePreference.kt create mode 100644 src/com/android/settings/accessibility/TextReadingFontSizePreference.kt create mode 100644 src/com/android/settings/accessibility/TextReadingPreview.kt diff --git a/src/com/android/settings/accessibility/TextReadingDisplaySizePreference.kt b/src/com/android/settings/accessibility/TextReadingDisplaySizePreference.kt new file mode 100644 index 00000000000..139ea42c401 --- /dev/null +++ b/src/com/android/settings/accessibility/TextReadingDisplaySizePreference.kt @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2025 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 + +import android.content.Context +import com.android.settings.R +import com.android.settingslib.metadata.PreferenceMetadata +import com.android.settingslib.preference.PreferenceBinding + +internal class TextReadingDisplaySizePreference : PreferenceMetadata, PreferenceBinding { + + override val key: String + get() = KEY + + override val title: Int + get() = R.string.screen_zoom_title + + override val summary: Int + get() = R.string.screen_zoom_short_summary + + override val keywords: Int + get() = R.string.keywords_display_size + + override fun createWidget(context: Context) = + AccessibilitySeekBarPreference(context, /* attrs= */ null).apply { + setIconStart(R.drawable.ic_remove_24dp) + setIconStartContentDescription(R.string.screen_zoom_make_smaller_desc) + setIconEnd(R.drawable.ic_add_24dp) + setIconEndContentDescription(R.string.screen_zoom_make_larger_desc) + } + + companion object { + const val KEY = "display_size" + } +} diff --git a/src/com/android/settings/accessibility/TextReadingFontSizePreference.kt b/src/com/android/settings/accessibility/TextReadingFontSizePreference.kt new file mode 100644 index 00000000000..1436088bd20 --- /dev/null +++ b/src/com/android/settings/accessibility/TextReadingFontSizePreference.kt @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2025 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 + +import android.content.Context +import android.provider.Settings.System.FONT_SCALE +import com.android.settings.R +import com.android.settingslib.metadata.PreferenceMetadata +import com.android.settingslib.preference.PreferenceBinding + +internal class TextReadingFontSizePreference : PreferenceMetadata, PreferenceBinding { + + override val key: String + get() = KEY + + override val title: Int + get() = R.string.title_font_size + + override val summary: Int + get() = R.string.short_summary_font_size + + override val keywords: Int + get() = R.string.keywords_font_size + + override fun createWidget(context: Context) = + AccessibilitySeekBarPreference(context, /* attrs= */ null).apply { + setIconStart(R.drawable.ic_remove_24dp) + setIconStartContentDescription(R.string.font_size_make_smaller_desc) + setIconEnd(R.drawable.ic_add_24dp) + setIconEndContentDescription(R.string.font_size_make_larger_desc) + } + + companion object { + const val KEY = FONT_SCALE + } +} diff --git a/src/com/android/settings/accessibility/TextReadingPreview.kt b/src/com/android/settings/accessibility/TextReadingPreview.kt new file mode 100644 index 00000000000..97b3d4897f2 --- /dev/null +++ b/src/com/android/settings/accessibility/TextReadingPreview.kt @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2025 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 + +import android.content.Context +import com.android.settingslib.metadata.PreferenceMetadata +import com.android.settingslib.preference.PreferenceBinding + +internal class TextReadingPreview : PreferenceMetadata, PreferenceBinding { + override val key: String + get() = KEY + + override fun createWidget(context: Context) = + TextReadingPreviewPreference(context).apply { isSelectable = false } + + companion object { + const val KEY = "preview" + } +} diff --git a/src/com/android/settings/accessibility/TextReadingScreen.kt b/src/com/android/settings/accessibility/TextReadingScreen.kt index 02272786b6d..401c0c58fef 100644 --- a/src/com/android/settings/accessibility/TextReadingScreen.kt +++ b/src/com/android/settings/accessibility/TextReadingScreen.kt @@ -18,11 +18,10 @@ package com.android.settings.accessibility import android.content.Context import com.android.settings.R import com.android.settings.flags.Flags -import com.android.settingslib.metadata.ProvidePreferenceScreen import com.android.settingslib.metadata.preferenceHierarchy import com.android.settingslib.preference.PreferenceScreenCreator -@ProvidePreferenceScreen(TextReadingScreen.KEY) +// @ProvidePreferenceScreen(TextReadingScreen.KEY) class TextReadingScreen : PreferenceScreenCreator { override val key: String get() = KEY @@ -34,9 +33,12 @@ class TextReadingScreen : PreferenceScreenCreator { override fun fragmentClass() = TextReadingPreferenceFragment::class.java - override fun hasCompleteHierarchy() = false - - override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(context, this) {} + override fun getPreferenceHierarchy(context: Context) = + preferenceHierarchy(context, this) { + +TextReadingPreview() + +TextReadingFontSizePreference() + +TextReadingDisplaySizePreference() + } companion object { const val KEY = "text_reading_screen" From d6df87cca677ddde856b62b34945874db1bdfc07 Mon Sep 17 00:00:00 2001 From: Shawn Lin Date: Fri, 20 Dec 2024 05:37:39 +0000 Subject: [PATCH 09/14] [Biometric Onboarding & Edu] move screen lock settings to choose lock - Hide gear menu in LockScreenSafetySource - Move screen lock settings to ChooseLockGeneric Bug: 370940762 Test: atest ScreenLockPreferenceDetailsUtilsTest Flag: com.android.settings.flags.biometrics_onboarding_education Change-Id: I07c7bb16ecc2ea6e7cd64a4e1d6bf4f493c5b951 --- res/xml/security_settings_picker.xml | 42 +++++++++++++-- .../settings/password/ChooseLockGeneric.java | 52 +++++++++++++++++++ .../ScreenLockPreferenceDetailsUtils.java | 3 +- .../ScreenLockPreferenceDetailsUtilsTest.java | 30 ++++++++++- 4 files changed, 121 insertions(+), 6 deletions(-) diff --git a/res/xml/security_settings_picker.xml b/res/xml/security_settings_picker.xml index aed702983cc..aa77b4fe179 100644 --- a/res/xml/security_settings_picker.xml +++ b/res/xml/security_settings_picker.xml @@ -67,9 +67,45 @@ android:title="@string/biometrics_unlock_skip_biometrics" android:persistent="false"/> + + + + + + + + + + + + + + + + + + + android:key="lock_settings_footer" + android:selectable="false" + settings:searchable="false"/> diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java index ef6a9ad7559..22b1310b4a3 100644 --- a/src/com/android/settings/password/ChooseLockGeneric.java +++ b/src/com/android/settings/password/ChooseLockGeneric.java @@ -71,6 +71,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.internal.widget.LockPatternUtils; @@ -87,13 +88,22 @@ import com.android.settings.biometrics.BiometricUtils; import com.android.settings.biometrics.IdentityCheckBiometricErrorDialog; import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; +import com.android.settings.flags.Flags; import com.android.settings.safetycenter.LockScreenSafetySource; import com.android.settings.search.SearchFeatureProvider; +import com.android.settings.security.screenlock.AutoPinConfirmPreferenceController; +import com.android.settings.security.screenlock.LockAfterTimeoutPreferenceController; +import com.android.settings.security.screenlock.PatternVisiblePreferenceController; +import com.android.settings.security.screenlock.PinPrivacyPreferenceController; +import com.android.settings.security.screenlock.PowerButtonInstantLockPreferenceController; import com.android.settingslib.RestrictedPreference; +import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.widget.FooterPreference; import com.google.android.setupcompat.util.WizardManagerHelper; +import java.util.ArrayList; + /** * Activity class that provides a generic implementation for displaying options to choose a lock * type, either for setting up a new lock or updating an existing lock. @@ -131,6 +141,8 @@ public class ChooseLockGeneric extends SettingsActivity { private static final String WAITING_FOR_CONFIRMATION = "waiting_for_confirmation"; public static final String HIDE_INSECURE_OPTIONS = "hide_insecure_options"; public static final String TAG_FRP_WARNING_DIALOG = "frp_warning_dialog"; + + public static final String KEY_LOCK_SETTINGS = "unlock_settings"; public static final String KEY_LOCK_SETTINGS_FOOTER ="lock_settings_footer"; /** @@ -214,6 +226,9 @@ public class ChooseLockGeneric extends SettingsActivity { private boolean mWaitingForBiometricEnrollment = false; private boolean mEnrollFingerPrintOnly = false; + private final ArrayList mUnlockSettingsControllers = + new ArrayList<>(); + @Override public int getMetricsCategory() { return SettingsEnums.CHOOSE_LOCK_GENERIC; @@ -652,6 +667,12 @@ public class ChooseLockGeneric extends SettingsActivity { footer.setVisible(false); } + if (Flags.biometricsOnboardingEducation() + && !WizardManagerHelper.isAnySetupWizard(getIntent())) { + buildUnlockSettingsPreferenceControllers(); + setUpUnlockSettingsPreference(); + } + // Used for testing purposes findPreference(ScreenLockType.NONE.preferenceKey).setViewId(R.id.lock_none); findPreference(KEY_SKIP_FINGERPRINT).setViewId(R.id.lock_none); @@ -661,6 +682,37 @@ public class ChooseLockGeneric extends SettingsActivity { findPreference(ScreenLockType.PASSWORD.preferenceKey).setViewId(R.id.lock_password); } + private void buildUnlockSettingsPreferenceControllers() { + mUnlockSettingsControllers.add(new PatternVisiblePreferenceController( + getContext(), mUserId, mLockPatternUtils)); + mUnlockSettingsControllers.add(new PinPrivacyPreferenceController( + getContext(), mUserId, mLockPatternUtils)); + mUnlockSettingsControllers.add(new PowerButtonInstantLockPreferenceController( + getContext(), mUserId, mLockPatternUtils)); + mUnlockSettingsControllers.add(new LockAfterTimeoutPreferenceController( + getContext(), mUserId, mLockPatternUtils)); + mUnlockSettingsControllers.add(new AutoPinConfirmPreferenceController( + getContext(), mUserId, mLockPatternUtils, this)); + } + + private void setUpUnlockSettingsPreference() { + boolean showUnlockSettingsCategory = false; + for (AbstractPreferenceController controller : mUnlockSettingsControllers) { + final boolean isAvailable = controller.isAvailable(); + final Preference preference = findPreference(controller.getPreferenceKey()); + preference.setVisible(isAvailable); + if (!isAvailable) { + continue; + } + preference.setOnPreferenceChangeListener( + (Preference.OnPreferenceChangeListener) controller); + controller.updateState(preference); + showUnlockSettingsCategory = true; + } + final PreferenceCategory unlockSettingsCategory = findPreference(KEY_LOCK_SETTINGS); + unlockSettingsCategory.setVisible(showUnlockSettingsCategory); + } + private String getFooterString() { @StringRes int stringId; switch (mController.getAggregatedPasswordComplexity()) { diff --git a/src/com/android/settings/security/ScreenLockPreferenceDetailsUtils.java b/src/com/android/settings/security/ScreenLockPreferenceDetailsUtils.java index 88477c364f1..bc38feb20dc 100644 --- a/src/com/android/settings/security/ScreenLockPreferenceDetailsUtils.java +++ b/src/com/android/settings/security/ScreenLockPreferenceDetailsUtils.java @@ -92,7 +92,8 @@ public class ScreenLockPreferenceDetailsUtils { * Returns whether the Gear Menu should be shown. */ public boolean shouldShowGearMenu() { - return isLockPatternSecure(); + return !com.android.settings.flags.Flags.biometricsOnboardingEducation() + && isLockPatternSecure(); } /** diff --git a/tests/unit/src/com/android/settings/security/ScreenLockPreferenceDetailsUtilsTest.java b/tests/unit/src/com/android/settings/security/ScreenLockPreferenceDetailsUtilsTest.java index ad886879698..abc982db33c 100644 --- a/tests/unit/src/com/android/settings/security/ScreenLockPreferenceDetailsUtilsTest.java +++ b/tests/unit/src/com/android/settings/security/ScreenLockPreferenceDetailsUtilsTest.java @@ -32,12 +32,17 @@ import android.content.Intent; import android.content.res.Resources; import android.os.UserManager; import android.os.storage.StorageManager; +import android.platform.test.annotations.RequiresFlagsDisabled; +import android.platform.test.annotations.RequiresFlagsEnabled; +import android.platform.test.flag.junit.CheckFlagsRule; +import android.platform.test.flag.junit.DeviceFlagsValueProvider; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.android.internal.widget.LockPatternUtils; import com.android.settings.SettingsActivity; +import com.android.settings.flags.Flags; import com.android.settings.password.ChooseLockGeneric; import com.android.settings.security.screenlock.ScreenLockSettings; import com.android.settings.testutils.FakeFeatureFactory; @@ -46,6 +51,7 @@ import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -58,6 +64,8 @@ public class ScreenLockPreferenceDetailsUtilsTest { private static final int SOURCE_METRICS_CATEGORY = 10; private static final int USER_ID = 11; + @Rule + public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); @Mock private LockPatternUtils mLockPatternUtils; @Mock @@ -267,14 +275,32 @@ public class ScreenLockPreferenceDetailsUtilsTest { } @Test - public void shouldShowGearMenu_patternIsSecure_shouldReturnTrue() { + @RequiresFlagsEnabled(Flags.FLAG_BIOMETRIC_ONBOARDING_EDUCATION) + public void shouldShowGearMenu_patternIsSecure_flagOn_shouldReturnFalse() { + when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true); + + assertThat(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).isFalse(); + } + + @Test + @RequiresFlagsDisabled(Flags.FLAG_BIOMETRIC_ONBOARDING_EDUCATION) + public void shouldShowGearMenu_patternIsNotSecure_flagOff_shouldReturnFalse() { + when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false); + + assertThat(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).isFalse(); + } + + @Test + @RequiresFlagsDisabled(Flags.FLAG_BIOMETRIC_ONBOARDING_EDUCATION) + public void shouldShowGearMenu_patternIsSecure_flagOff_shouldReturnTrue() { when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true); assertThat(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).isTrue(); } @Test - public void shouldShowGearMenu_patternIsNotSecure_shouldReturnFalse() { + @RequiresFlagsEnabled(Flags.FLAG_BIOMETRIC_ONBOARDING_EDUCATION) + public void shouldShowGearMenu_patternIsNotSecure_flagOn_shouldReturnFalse() { when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false); assertThat(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).isFalse(); From 4cadb751c29729b73bcec0df8c7a07ec843df0f3 Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Wed, 22 Jan 2025 11:21:54 +0800 Subject: [PATCH 10/14] [Catalyst] Allow using zero screen res in DashboardFragment Bug: 383568136 Flag: android.app.supervision.flags.enable_supervision_settings_screen Test: manual Change-Id: Ic76121821b63aafe799cec6e784bf26bf1328092 --- src/com/android/settings/dashboard/DashboardFragment.java | 8 ++++---- .../settings/supervision/SupervisionDashboardFragment.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java index d163bda8d9f..9acdfaa9ba8 100644 --- a/src/com/android/settings/dashboard/DashboardFragment.java +++ b/src/com/android/settings/dashboard/DashboardFragment.java @@ -403,10 +403,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment * Displays resource based tiles. */ private void displayResourceTiles() { - final int resId = getPreferenceScreenResId(); - if (resId <= 0) { - return; - } PreferenceScreen screen; PreferenceScreenCreator preferenceScreenCreator = getPreferenceScreenCreator(); if (preferenceScreenCreator != null) { @@ -416,6 +412,10 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment } setPreferenceScreen(screen); } else { + final int resId = getPreferenceScreenResId(); + if (resId <= 0) { + return; + } addPreferencesFromResource(resId); screen = getPreferenceScreen(); } diff --git a/src/com/android/settings/supervision/SupervisionDashboardFragment.kt b/src/com/android/settings/supervision/SupervisionDashboardFragment.kt index 77995055737..9b1b1553f99 100644 --- a/src/com/android/settings/supervision/SupervisionDashboardFragment.kt +++ b/src/com/android/settings/supervision/SupervisionDashboardFragment.kt @@ -29,7 +29,7 @@ import com.android.settings.dashboard.DashboardFragment */ class SupervisionDashboardFragment : DashboardFragment() { - override fun getPreferenceScreenResId() = R.xml.placeholder_preference_screen + override fun getPreferenceScreenResId() = 0 override fun getMetricsCategory() = SettingsEnums.SUPERVISION_DASHBOARD From 5b70748ce95e8df9cefe95173ecf97d6bc1c5070 Mon Sep 17 00:00:00 2001 From: lbill Date: Mon, 26 Feb 2024 07:32:13 +0000 Subject: [PATCH 11/14] Fix the SUW setup Pattern view the two steps offset issue Test: manual go through SUW setup Pattern view, and make sure pattern view do not shift in confirm step Fixes: 324489595 Flag: EXEMPT bugfix/clean up layout issue Change-Id: Ia5e6ef8a8c9ecf712f69bfde2bb631dc2605210d --- .../settings/password/SetupChooseLockPattern.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/com/android/settings/password/SetupChooseLockPattern.java b/src/com/android/settings/password/SetupChooseLockPattern.java index 55b3847125e..794104912e8 100644 --- a/src/com/android/settings/password/SetupChooseLockPattern.java +++ b/src/com/android/settings/password/SetupChooseLockPattern.java @@ -16,8 +16,6 @@ package com.android.settings.password; -import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; - import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PATTERN; import android.content.Context; @@ -138,17 +136,10 @@ public class SetupChooseLockPattern extends ChooseLockPattern { protected void updateStage(Stage stage) { super.updateStage(stage); if (!showMinimalUi() && mOptionsButton != null) { - // In landscape, keep view stub to avoid pattern view shifting, but in portrait the - // header title and description could become multiple lines in confirm stage, - // gone the button view to reserve more room for growth height of header. - @View.Visibility - final int hideOrGone = - getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE - ? View.INVISIBLE : View.GONE; mOptionsButton.setVisibility( (stage == Stage.Introduction || stage == Stage.HelpScreen || stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid) - ? View.VISIBLE : hideOrGone); + ? View.VISIBLE : View.INVISIBLE); } if (stage.leftMode == LeftButtonMode.Gone && stage == Stage.Introduction) { From 8a6ea1a106446c8ce60808859539ebc090d20fd4 Mon Sep 17 00:00:00 2001 From: Chung Tang Date: Sun, 29 Dec 2024 18:03:57 +0000 Subject: [PATCH 12/14] Accommodate BATT protocol modifications. Bug: 380790573 Test: atest com.android.settings.bluetooth.AdvancedBluetoothDetailsHeaderControllerTest and Manual Flag: com.android.settings.flags.enable_battery_level_display Change-Id: Ibc4eb66aacedaf3a4111d4a411dada6cde1a5b9c --- ...ancedBluetoothDetailsHeaderController.java | 36 ++++++- ...dBluetoothDetailsHeaderControllerTest.java | 99 +++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java index ab0ed45d5e9..d0962be5d8b 100644 --- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java +++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java @@ -91,6 +91,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont private static final String ESTIMATE_READY = "estimate_ready"; private static final String DATABASE_ID = "id"; private static final String DATABASE_BLUETOOTH = "Bluetooth"; + private static final String TAG_BATT = "BATT"; private static final long TIME_OF_HOUR = TimeUnit.SECONDS.toMillis(3600); private static final long TIME_OF_MINUTE = TimeUnit.SECONDS.toMillis(60); private static final int LEFT_DEVICE_ID = 1; @@ -268,6 +269,30 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont BluetoothDevice.METADATA_MAIN_BATTERY) != BluetoothUtils.META_INT_ERROR); }); + Supplier isBattEnabled = + Suppliers.memoize( + () -> + Boolean.valueOf( + BluetoothUtils.getFastPairCustomizedField( + mCachedDevice.getDevice(), TAG_BATT))); + Supplier leftBatteryLevel = + Suppliers.memoize( + () -> + BluetoothUtils.getIntMetaData( + mCachedDevice.getDevice(), + BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)); + Supplier rightBatteryLevel = + Suppliers.memoize( + () -> + BluetoothUtils.getIntMetaData( + mCachedDevice.getDevice(), + BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY)); + Supplier caseBatteryLevel = + Suppliers.memoize( + () -> + BluetoothUtils.getIntMetaData( + mCachedDevice.getDevice(), + BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)); preloadAndRun( List.of(deviceName, disconnected, isUntetheredHeadset, summaryText), () -> { @@ -277,7 +302,16 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont final TextView summary = mLayoutPreference.findViewById(R.id.entity_header_summary); - if (disconnected.get()) { + final boolean isBatteryLevelAvailable = + Flags.enableBatteryLevelDisplay() + && isBattEnabled.get() + && (leftBatteryLevel.get() > BluetoothUtils.META_INT_ERROR + || rightBatteryLevel.get() + > BluetoothUtils.META_INT_ERROR + || caseBatteryLevel.get() + > BluetoothUtils.META_INT_ERROR); + + if (disconnected.get() && !isBatteryLevelAvailable) { summary.setText(summaryText.get()); updateDisconnectLayout(); return; diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java index 53a8f5d2cdd..8880e2c307e 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java @@ -28,6 +28,7 @@ import android.bluetooth.BluetoothDevice; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; +import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; import android.view.LayoutInflater; @@ -551,6 +552,104 @@ public class AdvancedBluetoothDetailsHeaderControllerTest { assertThat(button.getVisibility()).isEqualTo(View.GONE); } + @Test + @EnableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY) + public void enableBatt_budsDisconnected_batteryLevelShown() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) + .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) + .thenReturn(String.valueOf(false).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_LEFT).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_RIGHT).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_MAIN).getBytes()); + when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)) + .thenReturn("true".getBytes()); + when(mCachedDevice.isConnected()).thenReturn(false); + + mController.refresh(); + + assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_left), BATTERY_LEVEL_LEFT); + assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_right), BATTERY_LEVEL_RIGHT); + assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN); + } + + @Test + @DisableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY) + public void disableBatt_budsDisconnected_batteryLevelNotShown() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) + .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) + .thenReturn(String.valueOf(false).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_LEFT).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_RIGHT).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_MAIN).getBytes()); + when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)) + .thenReturn("true".getBytes()); + when(mCachedDevice.isConnected()).thenReturn(false); + + mController.refresh(); + + assertThat(mLayoutPreference.findViewById(R.id.layout_left).getVisibility()) + .isNotEqualTo(View.VISIBLE); + assertThat(mLayoutPreference.findViewById(R.id.layout_right).getVisibility()) + .isNotEqualTo(View.VISIBLE); + assertThat( + mLayoutPreference + .findViewById(R.id.layout_middle) + .findViewById(R.id.bt_battery_summary) + .getVisibility()) + .isNotEqualTo(View.VISIBLE); + assertThat( + mLayoutPreference + .findViewById(R.id.layout_middle) + .findViewById(R.id.bt_battery_icon) + .getVisibility()) + .isNotEqualTo(View.VISIBLE); + } + + @Test + @EnableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY) + public void disableFastPairBatt_budsDisconnected_batteryLevelNotShown() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) + .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) + .thenReturn(String.valueOf(false).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_LEFT).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_RIGHT).getBytes()); + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)) + .thenReturn(String.valueOf(BATTERY_LEVEL_MAIN).getBytes()); + when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)) + .thenReturn("false".getBytes()); + when(mCachedDevice.isConnected()).thenReturn(false); + + mController.refresh(); + + assertThat(mLayoutPreference.findViewById(R.id.layout_left).getVisibility()) + .isNotEqualTo(View.VISIBLE); + assertThat(mLayoutPreference.findViewById(R.id.layout_right).getVisibility()) + .isNotEqualTo(View.VISIBLE); + assertThat( + mLayoutPreference + .findViewById(R.id.layout_middle) + .findViewById(R.id.bt_battery_summary) + .getVisibility()) + .isNotEqualTo(View.VISIBLE); + assertThat( + mLayoutPreference + .findViewById(R.id.layout_middle) + .findViewById(R.id.bt_battery_icon) + .getVisibility()) + .isNotEqualTo(View.VISIBLE); + } + private void assertBatteryPredictionVisible(LinearLayout linearLayout, int visible) { final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction); assertThat(textView.getVisibility()).isEqualTo(visible); From 9e09f009564bfe3e05cc20df134548d1eae8a43e Mon Sep 17 00:00:00 2001 From: Allen Su Date: Wed, 22 Jan 2025 11:00:24 +0000 Subject: [PATCH 13/14] Fix incorrect region Bug: 388426025 Test: UI verification Flag: com.android.settings.flags.regional_preferences_api_enabled Change-Id: I62df2e3d2111ee45aece7a6af81edc561fe72b07 --- .../localepicker/LocalePickerWithRegionActivity.java | 2 +- .../RegionPickerBaseListPreferenceController.java | 5 +++-- .../settings/regionalpreferences/RegionPickerFragment.java | 3 ++- .../regionalpreferences/RegionPreferenceController.java | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java b/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java index ebd3f887b5e..6069c43fd16 100644 --- a/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java +++ b/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java @@ -111,7 +111,7 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity @Override public void onLocaleSelected(LocaleStore.LocaleInfo locale) { if (Flags.regionalPreferencesApiEnabled()) { - if (sameLanguageAndScript(locale.getLocale(), Locale.getDefault())) { + if (sameLanguageAndScript(locale.getLocale(), LocaleList.getDefault().get(0))) { Bundle args = new Bundle(); args.putInt(ARG_DIALOG_TYPE, DIALOG_CHANGE_LOCALE_REGION); args.putSerializable(ARG_TARGET_LOCALE, locale); diff --git a/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java b/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java index cb3b82b57cd..338ecc978af 100644 --- a/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java +++ b/src/com/android/settings/regionalpreferences/RegionPickerBaseListPreferenceController.java @@ -18,6 +18,7 @@ package com.android.settings.regionalpreferences; import android.content.Context; import android.os.Bundle; +import android.os.LocaleList; import android.util.Log; import androidx.annotation.NonNull; @@ -91,7 +92,7 @@ public abstract class RegionPickerBaseListPreferenceController extends BasePrefe ? getSuggestedLocaleList() : getSupportedLocaleList(); if (getPreferenceCategoryKey().contains(KEY_SUGGESTED)) { - Locale systemLocale = Locale.getDefault(); + Locale systemLocale = LocaleList.getDefault().get(0); LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(systemLocale); result.add(localeInfo); } @@ -105,7 +106,7 @@ public abstract class RegionPickerBaseListPreferenceController extends BasePrefe mPreferenceCategory.addPreference(pref); pref.setTitle(locale.getFullCountryNameNative()); pref.setKey(locale.toString()); - if (locale.getLocale().equals(Locale.getDefault())) { + if (locale.getLocale().equals(LocaleList.getDefault().get(0))) { pref.setChecked(true); } else { pref.setChecked(false); diff --git a/src/com/android/settings/regionalpreferences/RegionPickerFragment.java b/src/com/android/settings/regionalpreferences/RegionPickerFragment.java index cf4d9b99ba0..c064565fce8 100644 --- a/src/com/android/settings/regionalpreferences/RegionPickerFragment.java +++ b/src/com/android/settings/regionalpreferences/RegionPickerFragment.java @@ -19,6 +19,7 @@ package com.android.settings.regionalpreferences; import android.app.settings.SettingsEnums; import android.content.Context; import android.os.Bundle; +import android.os.LocaleList; import android.provider.Settings; import androidx.annotation.NonNull; @@ -83,7 +84,7 @@ public class RegionPickerFragment extends DashboardFragment{ private List buildPreferenceControllers( @NonNull Context context) { - Locale parentLocale = LocaleStore.getLocaleInfo(Locale.getDefault()).getParent(); + Locale parentLocale = LocaleStore.getLocaleInfo(LocaleList.getDefault().get(0)).getParent(); LocaleStore.LocaleInfo parentLocaleInfo = LocaleStore.getLocaleInfo(parentLocale); SystemRegionSuggestedListPreferenceController mSuggestedListPreferenceController = new SystemRegionSuggestedListPreferenceController( diff --git a/src/com/android/settings/regionalpreferences/RegionPreferenceController.java b/src/com/android/settings/regionalpreferences/RegionPreferenceController.java index a9d87f0f181..345bd755d8d 100644 --- a/src/com/android/settings/regionalpreferences/RegionPreferenceController.java +++ b/src/com/android/settings/regionalpreferences/RegionPreferenceController.java @@ -17,6 +17,7 @@ package com.android.settings.regionalpreferences; import android.content.Context; +import android.os.LocaleList; import androidx.annotation.NonNull; import androidx.preference.Preference; @@ -26,8 +27,6 @@ import com.android.internal.app.LocaleStore; import com.android.settings.core.BasePreferenceController; import com.android.settings.flags.Flags; -import java.util.Locale; - /** A controller for the entry of region picker page */ public class RegionPreferenceController extends BasePreferenceController { @@ -39,7 +38,8 @@ public class RegionPreferenceController extends BasePreferenceController { public void displayPreference(@NonNull PreferenceScreen screen) { super.displayPreference(screen); Preference preference = screen.findPreference(getPreferenceKey()); - LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(Locale.getDefault()); + LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo( + LocaleList.getDefault().get(0)); preference.setSummary(localeInfo.getFullCountryNameNative()); } From e866c91b845b272f17935ae5040aa2a8d46a6245 Mon Sep 17 00:00:00 2001 From: Vitor Carvalho Date: Wed, 22 Jan 2025 16:50:59 +0000 Subject: [PATCH 14/14] Fix ActionDisabledByAdminDialogHelperTest by setting a mock SupervisionManager as system service. A shadow of DPM is automatically added as system service by Robolectric infra. Since SupervisionManager is new, it doesn't have that. We will consider changing Robolectric to do the same thing when SupervisionManager becomes more stable. Flag: TEST_ONLY Bug: 382034839 Test: atest ActionDisabledByAdminDialogHelperTest Change-Id: I389938df10ce97c563511473b0aeaee52225f419 --- .../ActionDisabledByAdminDialogHelperTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java index 6db008de223..b2a928e03e3 100644 --- a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java +++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java @@ -29,7 +29,9 @@ import static org.mockito.Mockito.verify; import android.app.Activity; import android.app.admin.DevicePolicyManager; +import android.app.supervision.SupervisionManager; import android.content.ComponentName; +import android.content.Context; import android.content.pm.UserInfo; import android.os.Process; import android.os.UserHandle; @@ -49,14 +51,19 @@ import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import org.junit.Before; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.Shadows; import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; +import org.robolectric.shadows.ShadowContextImpl; import org.robolectric.shadows.ShadowProcess; @RunWith(RobolectricTestRunner.class) @@ -66,19 +73,24 @@ import org.robolectric.shadows.ShadowProcess; ShadowActivity.class }) public class ActionDisabledByAdminDialogHelperTest { + @Rule public final MockitoRule mMocks = MockitoJUnit.rule(); + private static final ComponentName ADMIN_COMPONENT = new ComponentName("some.package.name", "some.package.name.SomeClass"); private static final int USER_ID = 123; private static final EnforcedAdmin ENFORCED_ADMIN = new EnforcedAdmin(ADMIN_COMPONENT, new UserHandle(USER_ID)); + + @Mock private SupervisionManager mSupervisionManager; + private ActionDisabledByAdminDialogHelper mHelper; private Activity mActivity; - private org.robolectric.shadows.ShadowActivity mActivityShadow; @Before public void setUp() { mActivity = Robolectric.setupActivity(CustomActivity.class); - mActivityShadow = Shadow.extract(mActivity); + ShadowContextImpl shadowContext = Shadow.extract(mActivity.getBaseContext()); + shadowContext.setSystemService(Context.SUPERVISION_SERVICE, mSupervisionManager); mHelper = new ActionDisabledByAdminDialogHelper(mActivity); }