From ddc11bc03ab48e885f652b89df5f92ff283bcd4a Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Wed, 31 Jan 2024 16:29:01 +0800 Subject: [PATCH 01/16] Replace getCallingActivity() with getLaunchedFromPackage() getLaunchedFromPackage() reports who launched this Activity or built PendingIntent used to launch it, whereas getCallingActivity() reports who will get result of Activity. Bug: 316891059 Test: robotest, manual Change-Id: If97018c2741caef622f0596bbfeaa42ef1788b78 Merged-In: If97018c2741caef622f0596bbfeaa42ef1788b78 (cherry picked from commit 901880a1d2e632179eb4ac708fc4bc18d9d50791) --- .../settings/search/SearchFeatureProvider.java | 2 +- .../search/SearchFeatureProviderImpl.java | 18 ++++++++---------- .../search/SearchResultTrampoline.java | 13 ++++++------- .../search/SearchFeatureProviderImplTest.java | 15 ++++++++------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java index cd096ec6e16..c2257b47c9e 100644 --- a/src/com/android/settings/search/SearchFeatureProvider.java +++ b/src/com/android/settings/search/SearchFeatureProvider.java @@ -56,7 +56,7 @@ public interface SearchFeatureProvider { * @throws IllegalArgumentException when caller is null * @throws SecurityException when caller is not allowed to launch search result page */ - void verifyLaunchSearchResultPageCaller(Context context, @NonNull ComponentName caller) + void verifyLaunchSearchResultPageCaller(@NonNull Context context, @NonNull String callerPackage) throws SecurityException, IllegalArgumentException; /** diff --git a/src/com/android/settings/search/SearchFeatureProviderImpl.java b/src/com/android/settings/search/SearchFeatureProviderImpl.java index 6f909709058..3a62ddfb67e 100644 --- a/src/com/android/settings/search/SearchFeatureProviderImpl.java +++ b/src/com/android/settings/search/SearchFeatureProviderImpl.java @@ -17,13 +17,14 @@ package com.android.settings.search; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.provider.Settings; import android.text.TextUtils; +import androidx.annotation.NonNull; + import com.android.settingslib.search.SearchIndexableResources; import com.android.settingslib.search.SearchIndexableResourcesMobile; @@ -32,21 +33,18 @@ import com.android.settingslib.search.SearchIndexableResourcesMobile; */ public class SearchFeatureProviderImpl implements SearchFeatureProvider { - private static final String TAG = "SearchFeatureProvider"; - private SearchIndexableResources mSearchIndexableResources; @Override - public void verifyLaunchSearchResultPageCaller(Context context, ComponentName caller) { - if (caller == null) { + public void verifyLaunchSearchResultPageCaller(@NonNull Context context, + @NonNull String callerPackage) { + if (TextUtils.isEmpty(callerPackage)) { throw new IllegalArgumentException("ExternalSettingsTrampoline intents " + "must be called with startActivityForResult"); } - final String packageName = caller.getPackageName(); - final boolean isSettingsPackage = TextUtils.equals(packageName, context.getPackageName()) - || TextUtils.equals(getSettingsIntelligencePkgName(context), packageName); - final boolean isAllowlistedPackage = - isSignatureAllowlisted(context, caller.getPackageName()); + final boolean isSettingsPackage = TextUtils.equals(callerPackage, context.getPackageName()) + || TextUtils.equals(getSettingsIntelligencePkgName(context), callerPackage); + final boolean isAllowlistedPackage = isSignatureAllowlisted(context, callerPackage); if (isSettingsPackage || isAllowlistedPackage) { return; } diff --git a/src/com/android/settings/search/SearchResultTrampoline.java b/src/com/android/settings/search/SearchResultTrampoline.java index 6ba0338bfc9..504e2985742 100644 --- a/src/com/android/settings/search/SearchResultTrampoline.java +++ b/src/com/android/settings/search/SearchResultTrampoline.java @@ -20,7 +20,6 @@ import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENT import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB; import android.app.Activity; -import android.content.ComponentName; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -52,11 +51,11 @@ public class SearchResultTrampoline extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - final ComponentName callingActivity = getCallingActivity(); + final String callerPackage = getLaunchedFromPackage(); // First make sure caller has privilege to launch a search result page. FeatureFactory.getFactory(this) .getSearchFeatureProvider() - .verifyLaunchSearchResultPageCaller(this, callingActivity); + .verifyLaunchSearchResultPageCaller(this, callerPackage); // Didn't crash, proceed and launch the result as a subsetting. Intent intent = getIntent(); final String highlightMenuKey = intent.getStringExtra( @@ -105,7 +104,7 @@ public class SearchResultTrampoline extends Activity { if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this) || ActivityEmbeddingUtils.isAlreadyEmbedded(this)) { startActivity(intent); - } else if (isSettingsIntelligence(callingActivity)) { + } else if (isSettingsIntelligence(callerPackage)) { if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SETTINGS_SEARCH_ALWAYS_EXPAND)) { startActivity(SettingsActivity.getTrampolineIntent(intent, highlightMenuKey) .setClass(this, DeepLinkHomepageActivityInternal.class) @@ -138,9 +137,9 @@ public class SearchResultTrampoline extends Activity { finish(); } - private boolean isSettingsIntelligence(ComponentName callingActivity) { - return callingActivity != null && TextUtils.equals( - callingActivity.getPackageName(), + private boolean isSettingsIntelligence(String callerPackage) { + return TextUtils.equals( + callerPackage, FeatureFactory.getFactory(this).getSearchFeatureProvider() .getSettingsIntelligencePkgName(this)); } diff --git a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java index 0aa49eb6d68..7a1b2606a92 100644 --- a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java +++ b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java @@ -20,7 +20,6 @@ package com.android.settings.search; import static com.google.common.truth.Truth.assertThat; import android.app.settings.SettingsEnums; -import android.content.ComponentName; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ResolveInfo; @@ -136,20 +135,22 @@ public class SearchFeatureProviderImplTest { @Test(expected = SecurityException.class) public void verifyLaunchSearchResultPageCaller_badCaller_shouldCrash() { - final ComponentName cn = new ComponentName("pkg", "class"); - mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn); + final String packageName = "pkg"; + + mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName); } @Test public void verifyLaunchSearchResultPageCaller_settingsCaller_shouldNotCrash() { - final ComponentName cn = new ComponentName(mActivity.getPackageName(), "class"); - mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn); + final String packageName = mActivity.getPackageName(); + + mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName); } @Test public void verifyLaunchSearchResultPageCaller_settingsIntelligenceCaller_shouldNotCrash() { final String packageName = mProvider.getSettingsIntelligencePkgName(mActivity); - final ComponentName cn = new ComponentName(packageName, "class"); - mProvider.verifyLaunchSearchResultPageCaller(mActivity, cn); + + mProvider.verifyLaunchSearchResultPageCaller(mActivity, packageName); } } From 812d880ee7c5ef27537b11639030ee156f243d1a Mon Sep 17 00:00:00 2001 From: Simon Wingrove Date: Tue, 27 Feb 2024 11:27:24 +0000 Subject: [PATCH 02/16] Prevent full-screen face enroll on tablet The full-screen flow is preventing ConfirmLock from launching properly. As an immediate workaround to prevent this, stop launching the intro enrollment flow as fullscreen. Test: Manually Bug: 324018644 Change-Id: I432536fa3a93eebdc8120ee453642e6dee0eff78 --- .../activityembedding/ActivityEmbeddingRulesController.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java index 4e39070febd..b2ec589c965 100644 --- a/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java +++ b/src/com/android/settings/activityembedding/ActivityEmbeddingRulesController.java @@ -39,7 +39,6 @@ import com.android.settings.Settings; import com.android.settings.SettingsActivity; import com.android.settings.SubSettings; import com.android.settings.biometrics.face.FaceEnrollIntroduction; -import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal; import com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling; import com.android.settings.biometrics.fingerprint.FingerprintEnrollIntroduction; import com.android.settings.biometrics.fingerprint.FingerprintEnrollIntroductionInternal; @@ -260,7 +259,6 @@ public class ActivityEmbeddingRulesController { addActivityFilter(activityFilters, FingerprintEnrollIntroduction.class); addActivityFilter(activityFilters, FingerprintEnrollIntroductionInternal.class); addActivityFilter(activityFilters, FingerprintEnrollEnrolling.class); - addActivityFilter(activityFilters, FaceEnrollIntroductionInternal.class); addActivityFilter(activityFilters, FaceEnrollIntroduction.class); addActivityFilter(activityFilters, RemoteAuthActivity.class); addActivityFilter(activityFilters, RemoteAuthActivityInternal.class); From 3715b076844d5940d7efb004406678ccb8aea24d Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Wed, 28 Feb 2024 14:37:10 +0000 Subject: [PATCH 03/16] Touchpad: add Framework Input team as owners Also replace references to frameworks/base:/services/core/java/com/android/server/input/OWNERS with ones directly to frameworks/base:/INPUT_OWNERS. Bug: 324058706 Test: none Change-Id: Ib8943ca749887da7d5eebae908516e86310f2077 --- src/com/android/settings/inputmethod/OWNERS | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/inputmethod/OWNERS b/src/com/android/settings/inputmethod/OWNERS index 7c7d7928cfc..8dc48707865 100644 --- a/src/com/android/settings/inputmethod/OWNERS +++ b/src/com/android/settings/inputmethod/OWNERS @@ -3,6 +3,7 @@ include platform/frameworks/base:/services/core/java/com/android/server/inputmet include /OWNERS # Settings for physical keyboard and game pad are better to be reviewed by the input team -per-file GameControllerPreferenceController.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS -per-file KeyboardLayoutPicker*.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS -per-file PhysicalKeyboard*.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS +per-file GameControllerPreferenceController.java = file:platform/frameworks/base:/INPUT_OWNERS +per-file KeyboardLayoutPicker*.java = file:platform/frameworks/base:/INPUT_OWNERS +per-file PhysicalKeyboard*.java = file:platform/frameworks/base:/INPUT_OWNERS +per-file Trackpad*.java = file:platform/frameworks/base:/INPUT_OWNERS From cf1a34ab93a3ac8d23f291576f32c7e981317221 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Wed, 24 Jan 2024 16:32:51 +0000 Subject: [PATCH 04/16] Touchpad: add tap dragging setting Screenshot: go/ag-26012379-screenshot Bug: 321978150 Bug: 324058706 Test: with the flag disabled, check the new entry doesn't appear Test: with the flag enabled, toggle the setting and check that it enables and disables tap dragging (tapping then immediately putting your finger back on the touchpad and moving it) Test: with the flag enabled, check the setting appears in search results Test: atest SettingsRoboTests:com.android.settings.inputmethod Change-Id: Iccfbe842ff655ea295edc764cfc400709948df7d --- res/values/strings.xml | 2 + res/xml/trackpad_settings.xml | 7 +++ ...ackpadTapDraggingPreferenceController.java | 53 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/com/android/settings/inputmethod/TrackpadTapDraggingPreferenceController.java diff --git a/res/values/strings.xml b/res/values/strings.xml index fc0ee78cdf4..bdf100791ec 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4362,6 +4362,8 @@ Tap to click + + Tap dragging Touchpad gestures diff --git a/res/xml/trackpad_settings.xml b/res/xml/trackpad_settings.xml index cca92a30673..dfbd0eb873f 100644 --- a/res/xml/trackpad_settings.xml +++ b/res/xml/trackpad_settings.xml @@ -52,6 +52,13 @@ android:order="30" settings:keywords="@string/keywords_trackpad_bottom_right_tap"/> + + + Date: Tue, 27 Feb 2024 15:42:31 +0000 Subject: [PATCH 05/16] Touchpad: remove icons We don't have an icon for the tap dragging setting, and settings screens should either have icons for everything or nothing, so we decided to remove all the icons. For all except ic_trackpad_touch_gestures_inverse, they're only used in this one location, so the drawables can be removed as well. Screenshot: go/b-324058706-icon-removal-screenshot Bug: 324058706 Test: with a touchpad connected, check that the System > Touchpad screen has no icons on it. Change-Id: I0c0a76c757f568cd20799c53a96cfb895ed00238 --- .../ic_trackpad_bottom_right_click.xml | 25 ------------------- res/drawable/ic_trackpad_pointer_speed.xml | 25 ------------------- .../ic_trackpad_reverse_scrolling.xml | 25 ------------------- res/drawable/ic_trackpad_tap_to_click.xml | 25 ------------------- .../ic_trackpad_touch_gestures_normal.xml | 25 ------------------- res/xml/trackpad_settings.xml | 6 ----- 6 files changed, 131 deletions(-) delete mode 100644 res/drawable/ic_trackpad_bottom_right_click.xml delete mode 100644 res/drawable/ic_trackpad_pointer_speed.xml delete mode 100644 res/drawable/ic_trackpad_reverse_scrolling.xml delete mode 100644 res/drawable/ic_trackpad_tap_to_click.xml delete mode 100644 res/drawable/ic_trackpad_touch_gestures_normal.xml diff --git a/res/drawable/ic_trackpad_bottom_right_click.xml b/res/drawable/ic_trackpad_bottom_right_click.xml deleted file mode 100644 index ec85830255f..00000000000 --- a/res/drawable/ic_trackpad_bottom_right_click.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_trackpad_pointer_speed.xml b/res/drawable/ic_trackpad_pointer_speed.xml deleted file mode 100644 index 128282fec94..00000000000 --- a/res/drawable/ic_trackpad_pointer_speed.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_trackpad_reverse_scrolling.xml b/res/drawable/ic_trackpad_reverse_scrolling.xml deleted file mode 100644 index a62f904300b..00000000000 --- a/res/drawable/ic_trackpad_reverse_scrolling.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_trackpad_tap_to_click.xml b/res/drawable/ic_trackpad_tap_to_click.xml deleted file mode 100644 index 7db0454935e..00000000000 --- a/res/drawable/ic_trackpad_tap_to_click.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_trackpad_touch_gestures_normal.xml b/res/drawable/ic_trackpad_touch_gestures_normal.xml deleted file mode 100644 index 34619c80432..00000000000 --- a/res/drawable/ic_trackpad_touch_gestures_normal.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/xml/trackpad_settings.xml b/res/xml/trackpad_settings.xml index dfbd0eb873f..6601036073f 100644 --- a/res/xml/trackpad_settings.xml +++ b/res/xml/trackpad_settings.xml @@ -23,7 +23,6 @@ android:key="trackpad_gesture_settings" android:title="@string/trackpad_touchpad_gesture_title" android:summary="@string/trackpad_touchpad_gesture_summary" - android:icon="@drawable/ic_trackpad_touch_gestures_normal" android:order="-10" android:fragment="com.android.settings.inputmethod.TrackpadTouchGestureSettings" settings:controller="com.android.settings.inputmethod.TrackpadTouchGestureSettingsController"/> @@ -31,7 +30,6 @@ @@ -39,7 +37,6 @@ android:key="trackpad_reverse_scrolling" android:title="@string/trackpad_reverse_scrolling_title" android:summary="@string/trackpad_reverse_scrolling_summary" - android:icon="@drawable/ic_trackpad_reverse_scrolling" settings:controller="com.android.settings.inputmethod.TrackpadReverseScrollingPreferenceController" android:order="20"/> @@ -47,7 +44,6 @@ android:key="trackpad_bottom_right_tap" android:title="@string/trackpad_bottom_right_tap_title" android:summary="@string/trackpad_bottom_right_tap_summary" - android:icon="@drawable/ic_trackpad_bottom_right_click" settings:controller="com.android.settings.inputmethod.TrackpadBottomPreferenceController" android:order="30" settings:keywords="@string/keywords_trackpad_bottom_right_tap"/> @@ -62,7 +58,6 @@ @@ -70,6 +65,5 @@ From 9c332802599d0a6d07b593ceed09df227579ff8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Hern=C3=A1ndez?= Date: Wed, 28 Feb 2024 17:56:21 +0100 Subject: [PATCH 06/16] Moved zen-conversion-related methods into ZenAdapters Update calls from Settings. Bug: 309922141 Test: atest ZenModeHelperTest ZenAdaptersTest Change-Id: I354dea651a8c6f64eb87fe4bc90dab5ffdf7610f --- .../android/settings/notification/zen/ZenModeBackend.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/notification/zen/ZenModeBackend.java b/src/com/android/settings/notification/zen/ZenModeBackend.java index c290c83f5d2..921a5ee73a5 100644 --- a/src/com/android/settings/notification/zen/ZenModeBackend.java +++ b/src/com/android/settings/notification/zen/ZenModeBackend.java @@ -30,6 +30,7 @@ import android.icu.text.MessageFormat; import android.net.Uri; import android.provider.ContactsContract; import android.provider.Settings; +import android.service.notification.ZenAdapters; import android.service.notification.ZenModeConfig; import android.service.notification.ZenPolicy; import android.util.Log; @@ -399,14 +400,16 @@ public class ZenModeBackend { ZenPolicy setDefaultZenPolicy(ZenPolicy zenPolicy) { int calls; if (mPolicy.allowCalls()) { - calls = ZenModeConfig.getZenPolicySenders(mPolicy.allowCallsFrom()); + calls = ZenAdapters.notificationPolicySendersToZenPolicyPeopleType( + mPolicy.allowCallsFrom()); } else { calls = ZenPolicy.PEOPLE_TYPE_NONE; } int messages; if (mPolicy.allowMessages()) { - messages = ZenModeConfig.getZenPolicySenders(mPolicy.allowMessagesFrom()); + messages = ZenAdapters.notificationPolicySendersToZenPolicyPeopleType( + mPolicy.allowMessagesFrom()); } else { messages = ZenPolicy.PEOPLE_TYPE_NONE; } From e5c4c6e677bc571c9441ab8c14b69c81394fedcd Mon Sep 17 00:00:00 2001 From: Kangping Dong Date: Fri, 1 Mar 2024 00:49:03 +0800 Subject: [PATCH 07/16] [Thread] fix wrong kotlin argument name Fixes build warning: ``` the corresponding parameter in the supertype 'LifecycleEventObserver' is named 'source'. This may cause problems when calling this function with named arguments. override fun onStateChanged(lifecycleOwner: LifecycleOwner, event: Lifecycle.Event) { ``` Bug: 327098435 Change-Id: I9c50ab508cd39bf2eda02c423deeef9ca5342f4f --- .../threadnetwork/ThreadNetworkPreferenceController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkPreferenceController.kt b/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkPreferenceController.kt index 10e3f849905..f5c0a87fde2 100644 --- a/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkPreferenceController.kt +++ b/src/com/android/settings/connecteddevice/threadnetwork/ThreadNetworkPreferenceController.kt @@ -156,7 +156,7 @@ class ThreadNetworkPreferenceController @VisibleForTesting constructor( return true } - override fun onStateChanged(lifecycleOwner: LifecycleOwner, event: Lifecycle.Event) { + override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { if (threadController == null) { return } From 9b63fbb772c0d6855f2bc4ddd79e9303102bdcd8 Mon Sep 17 00:00:00 2001 From: David Liu Date: Fri, 1 Mar 2024 06:59:03 +0000 Subject: [PATCH 08/16] Fix toolbar keyboard navigation and touch. - toolbar default has touchscreenBlocksFocus enabled which make toolbar not focusable when touch screen present. Explicitly set touchscreenBlocksFocus to false make the toolbar can be focus when keyboard navigation. - Remove focusableInTouchMode which breaks normal touch control. Read https://android-developers.googleblog.com/2008/12/touch-mode.html for more details. Fix: 327025582 Fix: 324420544 Test: manual test with keyboard and touch navigation Change-Id: I6cad869e3a51926405a6f3ae894daa5416050bf8 --- res/layout/search_bar.xml | 3 +-- res/layout/search_bar_two_pane_version.xml | 3 +-- src/com/android/settings/search/SearchFeatureProvider.java | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/res/layout/search_bar.xml b/res/layout/search_bar.xml index 1e83e22156c..5f6f9c514bb 100644 --- a/res/layout/search_bar.xml +++ b/res/layout/search_bar.xml @@ -34,8 +34,7 @@ android:paddingStart="@dimen/search_bar_padding_start" android:paddingEnd="@dimen/search_bar_padding_end" android:background="@drawable/search_bar_selected_background" - android:focusable="true" - android:focusableInTouchMode="true" + android:touchscreenBlocksFocus="false" android:nextFocusForward="@+id/homepage_container" android:contentInsetStartWithNavigation="@dimen/search_bar_content_inset" android:navigationIcon="@drawable/ic_homepage_search"> diff --git a/res/layout/search_bar_two_pane_version.xml b/res/layout/search_bar_two_pane_version.xml index 337294e0280..dec1c450fc5 100644 --- a/res/layout/search_bar_two_pane_version.xml +++ b/res/layout/search_bar_two_pane_version.xml @@ -29,8 +29,7 @@ android:paddingStart="@dimen/search_bar_padding_start_two_pane" android:paddingEnd="@dimen/search_bar_padding_end_two_pane" android:background="@drawable/search_bar_selected_background" - android:focusable="true" - android:focusableInTouchMode="true" + android:touchscreenBlocksFocus="false" android:nextFocusForward="@+id/homepage_container" android:contentInsetStartWithNavigation="@dimen/search_bar_content_inset" android:navigationIcon="@drawable/ic_homepage_search"> diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java index b1d04d4398c..5707bc28f79 100644 --- a/src/com/android/settings/search/SearchFeatureProvider.java +++ b/src/com/android/settings/search/SearchFeatureProvider.java @@ -100,6 +100,7 @@ public interface SearchFeatureProvider { // and goes to the search UI. Also set the background to null so there's no ripple. final View navView = toolbar.getNavigationView(); navView.setClickable(false); + navView.setFocusable(false); navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); navView.setBackground(null); From 654e43b2e82f39f2c8107fecca5e77d5ca82ded3 Mon Sep 17 00:00:00 2001 From: Roy Chou Date: Tue, 27 Feb 2024 15:27:42 +0000 Subject: [PATCH 09/16] chore(magnification): remove onResume overrides for controllers in ToggleScreenMagnificationPreferenceFragment As b/186731461, so far MagnificationModePreferenceController and other magnification preference controllers are only used in ToggleScreenMagnificationPreferenceFragment, which is DashboardFragment. Since DashboardFragment already updates preference state in its onResume, so we can remove the onResume overrides in those controllers. Besides, we can also remove the LifeCycle dependency for the controllers since it's not used anymore. Bug: 186731461 Flag: NA Test: manually atest ToggleScreenMagnificationPreferenceFragmentTest atest MagnificationAlwaysOnPreferenceControllerTest atest MagnificationFollowTypingPreferenceControllerTest atest MagnificationJoystickPreferenceControllerTest atest MagnificationModePreferenceControllerTest Change-Id: I379a6a3a985c9d8b7a37bbb878b84cee1bd6adfb --- ...ificationAlwaysOnPreferenceController.java | 31 +-- ...ationFollowTypingPreferenceController.java | 31 +-- ...ificationJoystickPreferenceController.java | 31 +-- ...MagnificationModePreferenceController.java | 9 +- ...ScreenMagnificationPreferenceFragment.java | 35 ++-- ...ationAlwaysOnPreferenceControllerTest.java | 33 +--- ...nFollowTypingPreferenceControllerTest.java | 33 +--- ...ationJoystickPreferenceControllerTest.java | 33 +--- ...ificationModePreferenceControllerTest.java | 1 - ...enMagnificationPreferenceFragmentTest.java | 183 +++++++++++++++++- 10 files changed, 211 insertions(+), 209 deletions(-) diff --git a/src/com/android/settings/accessibility/MagnificationAlwaysOnPreferenceController.java b/src/com/android/settings/accessibility/MagnificationAlwaysOnPreferenceController.java index e455aa87695..f3d857580aa 100644 --- a/src/com/android/settings/accessibility/MagnificationAlwaysOnPreferenceController.java +++ b/src/com/android/settings/accessibility/MagnificationAlwaysOnPreferenceController.java @@ -22,12 +22,6 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import android.content.Context; import android.provider.Settings; -import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.LifecycleObserver; -import androidx.lifecycle.OnLifecycleEvent; -import androidx.preference.PreferenceScreen; -import androidx.preference.TwoStatePreference; - import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; @@ -36,15 +30,12 @@ import com.android.settings.core.TogglePreferenceController; * feature, where the magnifier will not deactivate on Activity transitions; it will only zoom out * to 100%. */ -public class MagnificationAlwaysOnPreferenceController extends TogglePreferenceController - implements LifecycleObserver { +public class MagnificationAlwaysOnPreferenceController extends TogglePreferenceController { private static final String TAG = MagnificationAlwaysOnPreferenceController.class.getSimpleName(); static final String PREF_KEY = Settings.Secure.ACCESSIBILITY_MAGNIFICATION_ALWAYS_ON_ENABLED; - private TwoStatePreference mSwitchPreference; - public MagnificationAlwaysOnPreferenceController(Context context, String preferenceKey) { super(context, preferenceKey); } @@ -71,24 +62,4 @@ public class MagnificationAlwaysOnPreferenceController extends TogglePreferenceC public int getSliceHighlightMenuRes() { return R.string.menu_key_accessibility; } - - @Override - public void displayPreference(PreferenceScreen screen) { - super.displayPreference(screen); - mSwitchPreference = screen.findPreference(getPreferenceKey()); - } - - // TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only. - @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) - void onResume() { - updateState(); - } - - /** - * Updates the state of preference components which has been displayed by - * {@link MagnificationAlwaysOnPreferenceController#displayPreference}. - */ - void updateState() { - updateState(mSwitchPreference); - } } diff --git a/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceController.java b/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceController.java index 86983e3c06d..b269a9975e5 100644 --- a/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceController.java +++ b/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceController.java @@ -22,25 +22,16 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import android.content.Context; import android.provider.Settings; -import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.LifecycleObserver; -import androidx.lifecycle.OnLifecycleEvent; -import androidx.preference.PreferenceScreen; -import androidx.preference.TwoStatePreference; - import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; /** Controller that accesses and switches the preference status of following typing feature */ -public class MagnificationFollowTypingPreferenceController extends TogglePreferenceController - implements LifecycleObserver { +public class MagnificationFollowTypingPreferenceController extends TogglePreferenceController { private static final String TAG = MagnificationFollowTypingPreferenceController.class.getSimpleName(); static final String PREF_KEY = "magnification_follow_typing"; - private TwoStatePreference mFollowTypingPreference; - public MagnificationFollowTypingPreferenceController(Context context, String preferenceKey) { super(context, preferenceKey); } @@ -67,24 +58,4 @@ public class MagnificationFollowTypingPreferenceController extends TogglePrefere public int getSliceHighlightMenuRes() { return R.string.menu_key_accessibility; } - - @Override - public void displayPreference(PreferenceScreen screen) { - super.displayPreference(screen); - mFollowTypingPreference = screen.findPreference(getPreferenceKey()); - } - - // TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only. - @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) - void onResume() { - updateState(); - } - - /** - * Updates the state of preference components which has been displayed by - * {@link MagnificationFollowTypingPreferenceController#displayPreference}. - */ - void updateState() { - updateState(mFollowTypingPreference); - } } diff --git a/src/com/android/settings/accessibility/MagnificationJoystickPreferenceController.java b/src/com/android/settings/accessibility/MagnificationJoystickPreferenceController.java index 0a24e96f6e3..b480a0a3f2f 100644 --- a/src/com/android/settings/accessibility/MagnificationJoystickPreferenceController.java +++ b/src/com/android/settings/accessibility/MagnificationJoystickPreferenceController.java @@ -22,27 +22,18 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import android.content.Context; import android.provider.Settings; -import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.LifecycleObserver; -import androidx.lifecycle.OnLifecycleEvent; -import androidx.preference.PreferenceScreen; -import androidx.preference.TwoStatePreference; - import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; /** * Controller that accesses and switches the preference status of the magnification joystick feature */ -public class MagnificationJoystickPreferenceController extends TogglePreferenceController - implements LifecycleObserver { +public class MagnificationJoystickPreferenceController extends TogglePreferenceController { private static final String TAG = MagnificationJoystickPreferenceController.class.getSimpleName(); static final String PREF_KEY = Settings.Secure.ACCESSIBILITY_MAGNIFICATION_JOYSTICK_ENABLED; - private TwoStatePreference mSwitchPreference; - public MagnificationJoystickPreferenceController(Context context, String preferenceKey) { super(context, preferenceKey); } @@ -69,24 +60,4 @@ public class MagnificationJoystickPreferenceController extends TogglePreferenceC public int getSliceHighlightMenuRes() { return R.string.menu_key_accessibility; } - - @Override - public void displayPreference(PreferenceScreen screen) { - super.displayPreference(screen); - mSwitchPreference = screen.findPreference(getPreferenceKey()); - } - - // TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only. - @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) - void onResume() { - updateState(); - } - - /** - * Updates the state of preference components which has been displayed by - * {@link MagnificationJoystickPreferenceController#displayPreference}. - */ - void updateState() { - updateState(mSwitchPreference); - } } diff --git a/src/com/android/settings/accessibility/MagnificationModePreferenceController.java b/src/com/android/settings/accessibility/MagnificationModePreferenceController.java index 4acf2308981..a8814acbb5a 100644 --- a/src/com/android/settings/accessibility/MagnificationModePreferenceController.java +++ b/src/com/android/settings/accessibility/MagnificationModePreferenceController.java @@ -47,7 +47,6 @@ import com.android.settings.core.BasePreferenceController; import com.android.settings.utils.AnnotationSpan; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnCreate; -import com.android.settingslib.core.lifecycle.events.OnResume; import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState; import java.util.ArrayList; @@ -55,7 +54,7 @@ import java.util.List; /** Controller that shows the magnification area mode summary and the preference click behavior. */ public class MagnificationModePreferenceController extends BasePreferenceController implements - DialogCreatable, LifecycleObserver, OnCreate, OnResume, OnSaveInstanceState { + DialogCreatable, LifecycleObserver, OnCreate, OnSaveInstanceState { static final String PREF_KEY = "screen_magnification_mode"; private static final int DIALOG_ID_BASE = 10; @@ -297,12 +296,6 @@ public class MagnificationModePreferenceController extends BasePreferenceControl updateCapabilitiesAndSummary(mModeCache); } - // TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only. - @Override - public void onResume() { - updateState(mModePreference); - } - /** * An interface to help the delegate to show the dialog. It will be injected to the delegate. */ diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index 023556cbfdb..d9baa03d177 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -206,22 +206,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends magnificationModePreferenceController.setDialogHelper(this); getSettingsLifecycle().addObserver(magnificationModePreferenceController); magnificationModePreferenceController.displayPreference(getPreferenceScreen()); + addPreferenceController(magnificationModePreferenceController); - mFollowingTypingSwitchPreference = new SwitchPreferenceCompat(getPrefContext()); - mFollowingTypingSwitchPreference.setTitle( - R.string.accessibility_screen_magnification_follow_typing_title); - mFollowingTypingSwitchPreference.setSummary( - R.string.accessibility_screen_magnification_follow_typing_summary); - mFollowingTypingSwitchPreference.setKey( - MagnificationFollowTypingPreferenceController.PREF_KEY); - generalCategory.addPreference(mFollowingTypingSwitchPreference); - - mFollowTypingPreferenceController = new MagnificationFollowTypingPreferenceController( - getContext(), MagnificationFollowTypingPreferenceController.PREF_KEY); - getSettingsLifecycle().addObserver(mFollowTypingPreferenceController); - mFollowTypingPreferenceController.displayPreference(getPreferenceScreen()); - addPreferenceController(mFollowTypingPreferenceController); - + addFollowTypingSetting(generalCategory); addAlwaysOnSetting(generalCategory); addJoystickSetting(generalCategory); } @@ -250,6 +237,22 @@ public class ToggleScreenMagnificationPreferenceFragment extends super.onProcessArguments(arguments); } + private void addFollowTypingSetting(PreferenceCategory generalCategory) { + var followTypingSwitchPreference = new SwitchPreferenceCompat(getPrefContext()); + followTypingSwitchPreference.setTitle( + R.string.accessibility_screen_magnification_follow_typing_title); + followTypingSwitchPreference.setSummary( + R.string.accessibility_screen_magnification_follow_typing_summary); + followTypingSwitchPreference.setKey( + MagnificationFollowTypingPreferenceController.PREF_KEY); + generalCategory.addPreference(followTypingSwitchPreference); + + var followTypingPreferenceController = new MagnificationFollowTypingPreferenceController( + getContext(), MagnificationFollowTypingPreferenceController.PREF_KEY); + followTypingPreferenceController.displayPreference(getPreferenceScreen()); + addPreferenceController(followTypingPreferenceController); + } + private boolean isAlwaysOnSettingEnabled() { final boolean defaultValue = getContext().getResources().getBoolean( com.android.internal.R.bool.config_magnification_always_on_enabled); @@ -276,7 +279,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends var alwaysOnPreferenceController = new MagnificationAlwaysOnPreferenceController( getContext(), MagnificationAlwaysOnPreferenceController.PREF_KEY); - getSettingsLifecycle().addObserver(alwaysOnPreferenceController); alwaysOnPreferenceController.displayPreference(getPreferenceScreen()); addPreferenceController(alwaysOnPreferenceController); } @@ -304,7 +306,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends getContext(), MagnificationJoystickPreferenceController.PREF_KEY ); - getSettingsLifecycle().addObserver(joystickPreferenceController); joystickPreferenceController.displayPreference(getPreferenceScreen()); addPreferenceController(joystickPreferenceController); } diff --git a/tests/robotests/src/com/android/settings/accessibility/MagnificationAlwaysOnPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/MagnificationAlwaysOnPreferenceControllerTest.java index e8015c5afcf..417c3d412aa 100644 --- a/tests/robotests/src/com/android/settings/accessibility/MagnificationAlwaysOnPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/MagnificationAlwaysOnPreferenceControllerTest.java @@ -17,10 +17,10 @@ package com.android.settings.accessibility; import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; -import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -56,38 +56,13 @@ public class MagnificationAlwaysOnPreferenceControllerTest { mSwitchPreference.setKey(MagnificationAlwaysOnPreferenceController.PREF_KEY); screen.addPreference(mSwitchPreference); mController.displayPreference(screen); - } - @Test - public void isChecked_defaultStateForAlwaysOn_onResumeShouldReturnTrue() { - mController.onResume(); - - assertThat(mController.isChecked()).isTrue(); - assertThat(mSwitchPreference.isChecked()).isTrue(); - } - - @Test - public void isChecked_enableAlwaysOn_onResumeShouldReturnTrue() { - Settings.Secure.putInt(mContext.getContentResolver(), KEY_ALWAYS_ON, ON); - mController.onResume(); - - assertThat(mController.isChecked()).isTrue(); - assertThat(mSwitchPreference.isChecked()).isTrue(); - } - - @Test - public void isChecked_disableAlwaysOn_onResumeShouldReturnFalse() { - Settings.Secure.putInt(mContext.getContentResolver(), KEY_ALWAYS_ON, OFF); - mController.onResume(); - - assertThat(mController.isChecked()).isFalse(); - assertThat(mSwitchPreference.isChecked()).isFalse(); + mController.updateState(mSwitchPreference); + reset(mSwitchPreference); } @Test public void performClick_switchDefaultStateForAlwaysOn_shouldReturnFalse() { - mController.onResume(); - mSwitchPreference.performClick(); verify(mSwitchPreference).setChecked(false); @@ -99,7 +74,7 @@ public class MagnificationAlwaysOnPreferenceControllerTest { public void updateState_disableAlwaysOn_shouldReturnFalse() { Settings.Secure.putInt(mContext.getContentResolver(), KEY_ALWAYS_ON, OFF); - mController.updateState(); + mController.updateState(mSwitchPreference); verify(mSwitchPreference).setChecked(false); assertThat(mController.isChecked()).isFalse(); diff --git a/tests/robotests/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceControllerTest.java index fd282a06932..3aeeca8f59c 100644 --- a/tests/robotests/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceControllerTest.java @@ -17,10 +17,10 @@ package com.android.settings.accessibility; import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; -import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -56,38 +56,13 @@ public class MagnificationFollowTypingPreferenceControllerTest { mSwitchPreference.setKey(MagnificationFollowTypingPreferenceController.PREF_KEY); screen.addPreference(mSwitchPreference); mController.displayPreference(screen); - } - @Test - public void isChecked_defaultStateForFollowTyping_onResumeShouldReturnTrue() { - mController.onResume(); - - assertThat(mController.isChecked()).isTrue(); - assertThat(mSwitchPreference.isChecked()).isTrue(); - } - - @Test - public void isChecked_enableFollowTyping_onResumeShouldReturnTrue() { - Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING, ON); - mController.onResume(); - - assertThat(mController.isChecked()).isTrue(); - assertThat(mSwitchPreference.isChecked()).isTrue(); - } - - @Test - public void isChecked_disableFollowTyping_onResumeShouldReturnFalse() { - Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING, OFF); - mController.onResume(); - - assertThat(mController.isChecked()).isFalse(); - assertThat(mSwitchPreference.isChecked()).isFalse(); + mController.updateState(mSwitchPreference); + reset(mSwitchPreference); } @Test public void performClick_switchDefaultStateForFollowTyping_shouldReturnFalse() { - mController.onResume(); - mSwitchPreference.performClick(); verify(mSwitchPreference).setChecked(false); @@ -99,7 +74,7 @@ public class MagnificationFollowTypingPreferenceControllerTest { public void updateState_disableFollowTyping_shouldReturnFalse() { Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING, OFF); - mController.updateState(); + mController.updateState(mSwitchPreference); verify(mSwitchPreference).setChecked(false); assertThat(mController.isChecked()).isFalse(); diff --git a/tests/robotests/src/com/android/settings/accessibility/MagnificationJoystickPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/MagnificationJoystickPreferenceControllerTest.java index 236f18ce70b..11258bb6041 100644 --- a/tests/robotests/src/com/android/settings/accessibility/MagnificationJoystickPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/MagnificationJoystickPreferenceControllerTest.java @@ -17,10 +17,10 @@ package com.android.settings.accessibility; import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; -import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -56,38 +56,13 @@ public class MagnificationJoystickPreferenceControllerTest { mSwitchPreference.setKey(MagnificationJoystickPreferenceController.PREF_KEY); screen.addPreference(mSwitchPreference); mController.displayPreference(screen); - } - @Test - public void isChecked_defaultStateForJoystick_onResumeShouldReturnFalse() { - mController.onResume(); - - assertThat(mController.isChecked()).isFalse(); - assertThat(mSwitchPreference.isChecked()).isFalse(); - } - - @Test - public void isChecked_enableJoystick_onResumeShouldReturnTrue() { - Settings.Secure.putInt(mContext.getContentResolver(), KEY_JOYSTICK, ON); - mController.onResume(); - - assertThat(mController.isChecked()).isTrue(); - assertThat(mSwitchPreference.isChecked()).isTrue(); - } - - @Test - public void isChecked_disableJoystick_onResumeShouldReturnFalse() { - Settings.Secure.putInt(mContext.getContentResolver(), KEY_JOYSTICK, OFF); - mController.onResume(); - - assertThat(mController.isChecked()).isFalse(); - assertThat(mSwitchPreference.isChecked()).isFalse(); + mController.updateState(mSwitchPreference); + reset(mSwitchPreference); } @Test public void performClick_switchDefaultStateForJoystick_shouldReturnTrue() { - mController.onResume(); - mSwitchPreference.performClick(); verify(mSwitchPreference).setChecked(true); @@ -99,7 +74,7 @@ public class MagnificationJoystickPreferenceControllerTest { public void updateState_disableJoystick_shouldReturnFalse() { Settings.Secure.putInt(mContext.getContentResolver(), KEY_JOYSTICK, OFF); - mController.updateState(); + mController.updateState(mSwitchPreference); verify(mSwitchPreference).setChecked(false); assertThat(mController.isChecked()).isFalse(); diff --git a/tests/robotests/src/com/android/settings/accessibility/MagnificationModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/MagnificationModePreferenceControllerTest.java index 62ff39b0e95..0bc3862ceb1 100644 --- a/tests/robotests/src/com/android/settings/accessibility/MagnificationModePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/MagnificationModePreferenceControllerTest.java @@ -90,7 +90,6 @@ public class MagnificationModePreferenceControllerTest { mModePreference.getOnPreferenceClickListener().onPreferenceClick(mModePreference); assertThat(getCheckedModeFromDialog()).isEqualTo(MAGNIFICATION_MODE_DEFAULT); - } @Test diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java index 4c4939550f4..b459faafac1 100644 --- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java @@ -19,6 +19,7 @@ package com.android.settings.accessibility; import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; import static com.android.settings.accessibility.AccessibilityUtil.State.ON; import static com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; +import static com.android.settings.accessibility.MagnificationCapabilities.MagnificationMode; import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_USER_SHORTCUT_TYPE; import static com.google.common.truth.Truth.assertThat; @@ -43,9 +44,11 @@ import android.os.Bundle; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; +import android.provider.DeviceConfig; import android.provider.Settings; import androidx.appcompat.app.AlertDialog; +import androidx.preference.Preference; import androidx.preference.TwoStatePreference; import androidx.test.core.app.ApplicationProvider; @@ -54,12 +57,14 @@ import com.android.settings.DialogCreatable; import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType; +import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settings.testutils.shadow.ShadowStorageManager; import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.google.common.truth.Correspondence; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -82,6 +87,7 @@ import java.util.List; ShadowUserManager.class, ShadowStorageManager.class, ShadowSettings.ShadowSecure.class, + ShadowDeviceConfig.class, }) public class ToggleScreenMagnificationPreferenceFragmentTest { @@ -109,6 +115,11 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { private static final String KEY_FOLLOW_TYPING = Settings.Secure.ACCESSIBILITY_MAGNIFICATION_FOLLOW_TYPING_ENABLED; + private static final String KEY_ALWAYS_ON = + Settings.Secure.ACCESSIBILITY_MAGNIFICATION_ALWAYS_ON_ENABLED; + private static final String KEY_JOYSTICK = + Settings.Secure.ACCESSIBILITY_MAGNIFICATION_JOYSTICK_ENABLED; + private FragmentController mFragController; private Context mContext; private Resources mSpyResources; @@ -137,15 +148,48 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { mFragController = FragmentController.of(fragment, SettingsActivity.class); } + @After + public void tearDown() { + ShadowDeviceConfig.reset(); + } + + @Test + public void onResume_defaultStateForMagnificationMode_preferenceShouldReturnFullScreen() { + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + // Default is MagnificationMode.FULLSCREEN + final String expected = + MagnificationCapabilities.getSummary(mContext, MagnificationMode.FULLSCREEN); + + final Preference preference = mFragController.get().findPreference( + MagnificationModePreferenceController.PREF_KEY); + assertThat(preference).isNotNull(); + assertThat(preference.getSummary()).isEqualTo(expected); + } + + @Test + public void onResume_setMagnificationModeToAll_preferenceShouldReturnAll() { + setKeyMagnificationMode(MagnificationMode.ALL); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final String expected = + MagnificationCapabilities.getSummary(mContext, MagnificationMode.ALL); + + final Preference preference = mFragController.get().findPreference( + MagnificationModePreferenceController.PREF_KEY); + assertThat(preference).isNotNull(); + assertThat(preference.getSummary()).isEqualTo(expected); + } + @Test public void onResume_defaultStateForFollowingTyping_switchPreferenceShouldReturnTrue() { setKeyFollowTypingEnabled(true); mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); - final TwoStatePreference switchPreference = - mFragController.get().findPreference( - MagnificationFollowTypingPreferenceController.PREF_KEY); + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationFollowTypingPreferenceController.PREF_KEY); assertThat(switchPreference).isNotNull(); assertThat(switchPreference.isChecked()).isTrue(); } @@ -156,9 +200,84 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); - final TwoStatePreference switchPreference = - mFragController.get().findPreference( - MagnificationFollowTypingPreferenceController.PREF_KEY); + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationFollowTypingPreferenceController.PREF_KEY); + assertThat(switchPreference).isNotNull(); + assertThat(switchPreference.isChecked()).isFalse(); + } + + @Test + public void onResume_defaultStateForAlwaysOn_switchPreferenceShouldReturnTrue() { + setAlwaysOnSupported(true); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationAlwaysOnPreferenceController.PREF_KEY); + assertThat(switchPreference).isNotNull(); + assertThat(switchPreference.isChecked()).isTrue(); + } + + @Test + public void onResume_enableAlwaysOn_switchPreferenceShouldReturnTrue() { + setAlwaysOnSupported(true); + setKeyAlwaysOnEnabled(true); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationAlwaysOnPreferenceController.PREF_KEY); + assertThat(switchPreference).isNotNull(); + assertThat(switchPreference.isChecked()).isTrue(); + } + + @Test + public void onResume_disableAlwaysOn_switchPreferenceShouldReturnFalse() { + setAlwaysOnSupported(true); + setKeyAlwaysOnEnabled(false); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationAlwaysOnPreferenceController.PREF_KEY); + assertThat(switchPreference).isNotNull(); + assertThat(switchPreference.isChecked()).isFalse(); + } + + @Test + public void onResume_defaultStateForJoystick_switchPreferenceShouldReturnFalse() { + setJoystickSupported(true); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationJoystickPreferenceController.PREF_KEY); + assertThat(switchPreference).isNotNull(); + assertThat(switchPreference.isChecked()).isFalse(); + } + + @Test + public void onResume_enableJoystick_switchPreferenceShouldReturnTrue() { + setJoystickSupported(true); + setKeyJoystickEnabled(true); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationJoystickPreferenceController.PREF_KEY); + assertThat(switchPreference).isNotNull(); + assertThat(switchPreference.isChecked()).isTrue(); + } + + @Test + public void onResume_disableJoystick_switchPreferenceShouldReturnFalse() { + setJoystickSupported(true); + setKeyJoystickEnabled(false); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationJoystickPreferenceController.PREF_KEY); assertThat(switchPreference).isNotNull(); assertThat(switchPreference.isChecked()).isFalse(); } @@ -556,6 +675,28 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { assertThat(mFragController.get().mSettingsPreference).isNull(); } + @Test + public void onCreateView_alwaysOnNotSupported_settingsPreferenceIsNull() { + setAlwaysOnSupported(false); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationAlwaysOnPreferenceController.PREF_KEY); + assertThat(switchPreference).isNull(); + } + + @Test + public void onCreateView_joystickNotSupported_settingsPreferenceIsNull() { + setJoystickSupported(false); + + mFragController.create(R.id.main_content, /* bundle= */ null).start().resume(); + + final TwoStatePreference switchPreference = mFragController.get().findPreference( + MagnificationJoystickPreferenceController.PREF_KEY); + assertThat(switchPreference).isNull(); + } + @Test public void onCreateView_setDialogDelegateAndAddTheControllerToLifeCycleObserver() { Correspondence instanceOf = Correspondence.transforming( @@ -690,11 +831,41 @@ public class ToggleScreenMagnificationPreferenceFragmentTest { enabled ? ON : OFF); } + private void setKeyMagnificationMode(@MagnificationMode int mode) { + MagnificationCapabilities.setCapabilities(mContext, mode); + } + private void setKeyFollowTypingEnabled(boolean enabled) { Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING, enabled ? ON : OFF); } + private void setAlwaysOnSupported(boolean supported) { + ShadowDeviceConfig.setProperty( + DeviceConfig.NAMESPACE_WINDOW_MANAGER, + "AlwaysOnMagnifier__enable_always_on_magnifier", + supported ? "true" : "false", + /* makeDefault= */ false); + } + + private void setKeyAlwaysOnEnabled(boolean enabled) { + Settings.Secure.putInt(mContext.getContentResolver(), KEY_ALWAYS_ON, + enabled ? ON : OFF); + } + + private void setJoystickSupported(boolean supported) { + ShadowDeviceConfig.setProperty( + DeviceConfig.NAMESPACE_WINDOW_MANAGER, + "MagnificationJoystick__enable_magnification_joystick", + supported ? "true" : "false", + /* makeDefault= */ false); + } + + private void setKeyJoystickEnabled(boolean enabled) { + Settings.Secure.putInt(mContext.getContentResolver(), KEY_JOYSTICK, + enabled ? ON : OFF); + } + private String getStringFromSettings(String key) { return Settings.Secure.getString(mContext.getContentResolver(), key); } From 8c8d310767d0898e7f1a7233729eb1c7d2b068ea Mon Sep 17 00:00:00 2001 From: Fan Wu Date: Mon, 4 Mar 2024 16:16:10 +0800 Subject: [PATCH 10/16] Fix settings/widget test failures Also ignore color checker complain introduced by ag/26310215 Bug: 315133235 Test: atest SettingsRoboTests Change-Id: I88081ab4bb1b01dfbd7b7a0045e2031e7170028a --- color-check-baseline.xml | 156 ++++++++++-------- .../settings/widget/RestrictedButtonTest.java | 4 +- .../settings/widget/VideoPreferenceTest.java | 4 +- 3 files changed, 90 insertions(+), 74 deletions(-) diff --git a/color-check-baseline.xml b/color-check-baseline.xml index 5a0e98ef9be..ecc795ee4c6 100644 --- a/color-check-baseline.xml +++ b/color-check-baseline.xml @@ -653,7 +653,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -669,7 +669,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1577,11 +1577,11 @@ priority="4" summary="Using hardcoded color" explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes. This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app." - errorLine1=" <color name="screen_flash_color_button_outer_circle_stroke_color">#FFFFFF</color>" - errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> + errorLine1=" <color name="battery_good_color_light">#43a047</color> <!-- Material Green 600 -->" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1593,11 +1593,11 @@ priority="4" summary="Using hardcoded color" explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes. This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app." - errorLine1=" <color name="battery_good_color_light">#43a047</color> <!-- Material Green 600 -->" - errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> + errorLine1=" <color name="screen_flash_color_button_outer_circle_stroke_color">#FFFFFF</color>" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1629,7 +1629,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2269,7 +2269,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2285,7 +2285,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2301,7 +2301,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2317,7 +2317,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2333,7 +2333,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2349,7 +2349,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2365,7 +2365,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2381,7 +2381,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2397,7 +2397,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2413,7 +2413,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2429,7 +2429,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2445,7 +2445,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2461,7 +2461,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2477,7 +2477,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2493,7 +2493,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2509,7 +2509,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2525,7 +2525,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2541,7 +2541,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2557,7 +2557,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2573,7 +2573,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2589,7 +2589,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2605,7 +2605,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2621,7 +2621,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2637,7 +2637,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2653,7 +2653,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2669,7 +2669,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2685,7 +2685,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2701,7 +2701,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2717,7 +2717,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2733,7 +2733,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2749,7 +2749,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2765,7 +2765,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2781,7 +2781,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2797,7 +2797,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2813,7 +2813,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2829,7 +2829,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2845,7 +2845,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2861,7 +2861,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2877,7 +2877,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2893,7 +2893,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2909,7 +2909,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2925,7 +2925,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2941,7 +2941,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2957,7 +2957,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2973,7 +2973,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2989,7 +2989,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -3005,7 +3005,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -3937,6 +3937,22 @@ column="13"/> + + + + @@ -6141,7 +6157,7 @@ errorLine2=" ^"> @@ -6157,7 +6173,7 @@ errorLine2=" ^"> @@ -6173,7 +6189,7 @@ errorLine2=" ^"> @@ -6189,7 +6205,7 @@ errorLine2=" ^"> @@ -6205,7 +6221,7 @@ errorLine2=" ^"> @@ -6221,7 +6237,7 @@ errorLine2=" ^"> @@ -6237,7 +6253,7 @@ errorLine2=" ^"> @@ -6253,7 +6269,7 @@ errorLine2=" ^"> @@ -6269,7 +6285,7 @@ errorLine2=" ^"> @@ -6285,7 +6301,7 @@ errorLine2=" ^"> @@ -6301,7 +6317,7 @@ errorLine2=" ^"> diff --git a/tests/robotests/src/com/android/settings/widget/RestrictedButtonTest.java b/tests/robotests/src/com/android/settings/widget/RestrictedButtonTest.java index d6963425c50..b3c70495697 100644 --- a/tests/robotests/src/com/android/settings/widget/RestrictedButtonTest.java +++ b/tests/robotests/src/com/android/settings/widget/RestrictedButtonTest.java @@ -34,18 +34,18 @@ import com.android.settings.testutils.shadow.ShadowDevicePolicyManager; import com.android.settings.testutils.shadow.ShadowUserManager; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; +import org.robolectric.annotation.LooperMode; import java.util.ArrayList; import java.util.List; -@Ignore("b/315133235") @RunWith(RobolectricTestRunner.class) +@LooperMode(LooperMode.Mode.LEGACY) @Config(shadows = {ShadowUserManager.class, ShadowDevicePolicyManager.class}) public class RestrictedButtonTest { diff --git a/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java index 35dc6669b94..293c4e48233 100644 --- a/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java @@ -40,7 +40,6 @@ import com.android.settings.R; import com.android.settings.testutils.shadow.ShadowSettingsMediaPlayer; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -48,6 +47,7 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; +import org.robolectric.annotation.LooperMode; import org.robolectric.shadows.androidx.fragment.FragmentController; @RunWith(RobolectricTestRunner.class) @@ -141,7 +141,7 @@ public class VideoPreferenceTest { assertThat(mAnimationController.isPlaying()).isTrue(); } - @Ignore("b/315133235") + @LooperMode(LooperMode.Mode.LEGACY) @Test @Config(qualifiers = "mcc999") public void onViewVisible_createAnimationController() { From 8754f114ac48cb80c367c11769947553f5c56034 Mon Sep 17 00:00:00 2001 From: Vaibhav Devmurari Date: Tue, 27 Feb 2024 20:35:14 +0000 Subject: [PATCH 11/16] Modify PK Settings page to make it more user friendly PK Settings page: - Show current PK layout selected for the current user profile and current IME language instead of a list of IMEs PK layout mapping page: - Show IME name in header only if multiple active IMEs - Show the PK layout selection criteria (Automatic v/s User selected) Bug: 325925410 Bug: 326195401 Test: manual Change-Id: I93a2e169742a800fa116fa5d55e1a91e5548cebb --- res/values/strings.xml | 6 ++ ...wKeyboardLayoutEnabledLocalesFragment.java | 20 ++++-- .../NewKeyboardLayoutPickerController.java | 7 +- .../inputmethod/NewKeyboardSettingsUtils.java | 72 +++++++++++++++---- .../inputmethod/PhysicalKeyboardFragment.java | 18 ++--- 5 files changed, 85 insertions(+), 38 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index a369d3da828..994162ade9a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4478,8 +4478,14 @@ Choose a new key for %1$s: + + %s layout Default + + Automatic: %s + + User selected: %s Speech diff --git a/src/com/android/settings/inputmethod/NewKeyboardLayoutEnabledLocalesFragment.java b/src/com/android/settings/inputmethod/NewKeyboardLayoutEnabledLocalesFragment.java index 05dc5bea33a..2bbb5676038 100644 --- a/src/com/android/settings/inputmethod/NewKeyboardLayoutEnabledLocalesFragment.java +++ b/src/com/android/settings/inputmethod/NewKeyboardLayoutEnabledLocalesFragment.java @@ -21,6 +21,7 @@ import android.content.Context; import android.hardware.input.InputDeviceIdentifier; import android.hardware.input.InputManager; import android.hardware.input.KeyboardLayout; +import android.hardware.input.KeyboardLayoutSelectionResult; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; @@ -180,7 +181,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment mapLanguageWithLayout(info, subtype); } } - updatePreferenceLayout(preferenceScreen, info); + updatePreferenceLayout(preferenceScreen, info, infoList.size() > 1); } } @@ -189,14 +190,15 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment KeyboardLayout[] keyboardLayouts = NewKeyboardSettingsUtils.getKeyboardLayouts( mIm, mUserId, mInputDeviceIdentifier, info, subtype); - String layout = NewKeyboardSettingsUtils.getKeyboardLayout( + KeyboardLayoutSelectionResult result = NewKeyboardSettingsUtils.getKeyboardLayout( mIm, mUserId, mInputDeviceIdentifier, info, subtype); - if (layout != null) { + if (result.getLayoutDescriptor() != null) { for (int i = 0; i < keyboardLayouts.length; i++) { - if (keyboardLayouts[i].getDescriptor().equals(layout)) { + if (keyboardLayouts[i].getDescriptor().equals(result.getLayoutDescriptor())) { KeyboardInfo keyboardInfo = new KeyboardInfo( subtypeLabel, keyboardLayouts[i].getLabel(), + result.getSelectionCriteria(), info, subtype); mKeyboardInfoList.add(keyboardInfo); @@ -208,18 +210,22 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment KeyboardInfo keyboardInfo = new KeyboardInfo( subtypeLabel, mContext.getString(R.string.keyboard_default_layout), + KeyboardLayoutSelectionResult.LAYOUT_SELECTION_CRITERIA_UNSPECIFIED, info, subtype); mKeyboardInfoList.add(keyboardInfo); } } - private void updatePreferenceLayout(PreferenceScreen preferenceScreen, InputMethodInfo info) { + private void updatePreferenceLayout(PreferenceScreen preferenceScreen, InputMethodInfo info, + boolean hasMultipleImes) { if (mKeyboardInfoList.isEmpty()) { return; } PreferenceCategory preferenceCategory = new PreferenceCategory(mContext); - preferenceCategory.setTitle(info.loadLabel(mContext.getPackageManager())); + preferenceCategory.setTitle(hasMultipleImes ? mContext.getString(R.string.ime_label_title, + info.loadLabel(mContext.getPackageManager())) + : mContext.getString(R.string.enabled_locales_keyboard_layout)); preferenceCategory.setKey(info.getPackageName()); preferenceScreen.addPreference(preferenceCategory); Collections.sort(mKeyboardInfoList, new Comparator() { @@ -234,7 +240,7 @@ public class NewKeyboardLayoutEnabledLocalesFragment extends DashboardFragment final Preference pref = new Preference(mContext); pref.setKey(keyboardInfo.getPrefId()); pref.setTitle(keyboardInfo.getSubtypeLabel()); - pref.setSummary(keyboardInfo.getLayout()); + pref.setSummary(keyboardInfo.getLayoutSummaryText(mContext)); pref.setOnPreferenceClickListener( preference -> { showKeyboardLayoutPicker( diff --git a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java index ac8037f74c4..ec727e8a55b 100644 --- a/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java +++ b/src/com/android/settings/inputmethod/NewKeyboardLayoutPickerController.java @@ -21,6 +21,7 @@ import android.content.Context; import android.hardware.input.InputDeviceIdentifier; import android.hardware.input.InputManager; import android.hardware.input.KeyboardLayout; +import android.hardware.input.KeyboardLayoutSelectionResult; import android.os.Bundle; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; @@ -201,13 +202,13 @@ public class NewKeyboardLayoutPickerController extends BasePreferenceController private String getSelectedLayoutLabel() { String label = mContext.getString(R.string.keyboard_default_layout); - String layout = NewKeyboardSettingsUtils.getKeyboardLayout( + KeyboardLayoutSelectionResult result = NewKeyboardSettingsUtils.getKeyboardLayout( mIm, mUserId, mInputDeviceIdentifier, mInputMethodInfo, mInputMethodSubtype); KeyboardLayout[] keyboardLayouts = NewKeyboardSettingsUtils.getKeyboardLayouts( mIm, mUserId, mInputDeviceIdentifier, mInputMethodInfo, mInputMethodSubtype); - if (layout != null) { + if (result.getLayoutDescriptor() != null) { for (KeyboardLayout keyboardLayout : keyboardLayouts) { - if (keyboardLayout.getDescriptor().equals(layout)) { + if (keyboardLayout.getDescriptor().equals(result.getLayoutDescriptor())) { label = keyboardLayout.getLabel(); break; } diff --git a/src/com/android/settings/inputmethod/NewKeyboardSettingsUtils.java b/src/com/android/settings/inputmethod/NewKeyboardSettingsUtils.java index a927165cb88..8f1e5c88a5b 100644 --- a/src/com/android/settings/inputmethod/NewKeyboardSettingsUtils.java +++ b/src/com/android/settings/inputmethod/NewKeyboardSettingsUtils.java @@ -16,20 +16,30 @@ package com.android.settings.inputmethod; +import static android.hardware.input.KeyboardLayoutSelectionResult.LAYOUT_SELECTION_CRITERIA_USER; +import static android.hardware.input.KeyboardLayoutSelectionResult.LAYOUT_SELECTION_CRITERIA_DEVICE; +import static android.hardware.input.KeyboardLayoutSelectionResult.LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SuppressLint; +import android.annotation.UserIdInt; import android.content.Context; import android.hardware.input.InputDeviceIdentifier; import android.hardware.input.InputManager; import android.hardware.input.KeyboardLayout; +import android.hardware.input.KeyboardLayoutSelectionResult; +import android.hardware.input.KeyboardLayoutSelectionResult.LayoutSelectionCriteria; import android.os.UserHandle; import android.view.InputDevice; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; -import java.util.ArrayList; +import com.android.settings.R; + import java.util.Arrays; import java.util.Comparator; -import java.util.List; /** * Utilities of keyboard settings @@ -56,36 +66,47 @@ public class NewKeyboardSettingsUtils { return false; } - static List getSuitableImeLabels(Context context, InputMethodManager imm, int userId) { - List suitableInputMethodInfoLabels = new ArrayList<>(); - List infoList = imm.getEnabledInputMethodListAsUser(UserHandle.of(userId)); - for (InputMethodInfo info : infoList) { - List subtypes = - imm.getEnabledInputMethodSubtypeList(info, true); - for (InputMethodSubtype subtype : subtypes) { - if (subtype.isSuitableForPhysicalKeyboardLayoutMapping()) { - suitableInputMethodInfoLabels.add( - info.loadLabel(context.getPackageManager()).toString()); - break; + @SuppressLint("MissingPermission") + @Nullable + static String getSelectedKeyboardLayoutLabelForUser(Context context, @UserIdInt int userId, + InputDeviceIdentifier inputDeviceIdentifier) { + InputMethodManager imm = context.getSystemService(InputMethodManager.class); + InputManager im = context.getSystemService(InputManager.class); + if (imm == null || im == null) { + return null; + } + InputMethodInfo imeInfo = imm.getCurrentInputMethodInfoAsUser(UserHandle.of(userId)); + InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype(); + KeyboardLayout[] keyboardLayouts = getKeyboardLayouts(im, userId, inputDeviceIdentifier, + imeInfo, subtype); + KeyboardLayoutSelectionResult result = getKeyboardLayout(im, userId, inputDeviceIdentifier, + imeInfo, subtype); + if (result != null) { + for (KeyboardLayout keyboardLayout : keyboardLayouts) { + if (keyboardLayout.getDescriptor().equals(result.getLayoutDescriptor())) { + return keyboardLayout.getLabel(); } } } - return suitableInputMethodInfoLabels; + return null; } static class KeyboardInfo { CharSequence mSubtypeLabel; String mLayout; + @LayoutSelectionCriteria int mSelectionCriteria; InputMethodInfo mInputMethodInfo; InputMethodSubtype mInputMethodSubtype; KeyboardInfo( CharSequence subtypeLabel, String layout, + @LayoutSelectionCriteria int selectionCriteria, InputMethodInfo inputMethodInfo, InputMethodSubtype inputMethodSubtype) { mSubtypeLabel = subtypeLabel; mLayout = layout; + mSelectionCriteria = selectionCriteria; mInputMethodInfo = inputMethodInfo; mInputMethodSubtype = inputMethodSubtype; } @@ -102,6 +123,17 @@ public class NewKeyboardSettingsUtils { return mLayout; } + String getLayoutSummaryText(Context context) { + if (isAutomaticSelection(mSelectionCriteria)) { + return context.getResources().getString(R.string.automatic_keyboard_layout_label, + mLayout); + } else if (isUserSelection(mSelectionCriteria)) { + return context.getResources().getString( + R.string.user_selected_keyboard_layout_label, mLayout); + } + return mLayout; + } + InputMethodInfo getInputMethodInfo() { return mInputMethodInfo; } @@ -121,11 +153,21 @@ public class NewKeyboardSettingsUtils { return inputManager.getKeyboardLayoutListForInputDevice(identifier, userId, info, subtype); } - static String getKeyboardLayout(InputManager inputManager, int userId, + @NonNull + static KeyboardLayoutSelectionResult getKeyboardLayout(InputManager inputManager, int userId, InputDeviceIdentifier identifier, InputMethodInfo info, InputMethodSubtype subtype) { return inputManager.getKeyboardLayoutForInputDevice(identifier, userId, info, subtype); } + static boolean isAutomaticSelection(@LayoutSelectionCriteria int criteria) { + return criteria == LAYOUT_SELECTION_CRITERIA_DEVICE + || criteria == LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD; + } + + static boolean isUserSelection(@LayoutSelectionCriteria int criteria) { + return criteria == LAYOUT_SELECTION_CRITERIA_USER; + } + static void sortKeyboardLayoutsByLabel(KeyboardLayout[] keyboardLayouts) { Arrays.sort( keyboardLayouts, diff --git a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java index b06edb2957b..ff203e0d452 100644 --- a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java +++ b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java @@ -280,19 +280,11 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment final Preference pref = new Preference(getPrefContext()); pref.setTitle(hardKeyboardDeviceInfo.mDeviceName); if (mIsNewKeyboardSettings) { - List suitableImes = new ArrayList<>(); - suitableImes.addAll( - NewKeyboardSettingsUtils.getSuitableImeLabels( - getContext(), mImm, UserHandle.myUserId())); - if (!suitableImes.isEmpty()) { - String summary = suitableImes.get(0); - StringBuilder result = new StringBuilder(summary); - for (int i = 1; i < suitableImes.size(); i++) { - result.append(", ").append(suitableImes.get(i)); - } - pref.setSummary(result.toString()); - } else { - pref.setSummary(hardKeyboardDeviceInfo.mLayoutLabel); + String currentLayout = + NewKeyboardSettingsUtils.getSelectedKeyboardLayoutLabelForUser(getContext(), + UserHandle.myUserId(), hardKeyboardDeviceInfo.mDeviceIdentifier); + if (currentLayout != null) { + pref.setSummary(currentLayout); } pref.setOnPreferenceClickListener( preference -> { From cbc0ec7111de8a01d42454fc8c648c0af12dd681 Mon Sep 17 00:00:00 2001 From: Anna Zhuravleva Date: Mon, 4 Mar 2024 13:08:21 +0000 Subject: [PATCH 12/16] Log change in autolock settings Bug: 327181532 Test: statsd_testdrive https://paste.googleplex.com/4866138112000000 Change-Id: I4133e35ff343e32261cb0fc190af4a32474b69e3 --- .../privatespace/autolock/AutoLockSettingsFragment.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/com/android/settings/privatespace/autolock/AutoLockSettingsFragment.java b/src/com/android/settings/privatespace/autolock/AutoLockSettingsFragment.java index ef8bf8e84b7..4380c534a04 100644 --- a/src/com/android/settings/privatespace/autolock/AutoLockSettingsFragment.java +++ b/src/com/android/settings/privatespace/autolock/AutoLockSettingsFragment.java @@ -38,6 +38,8 @@ import java.util.List; public class AutoLockSettingsFragment extends RadioButtonPickerFragment { private static final String TAG = "PSAutoLockSetting"; + + private static final String AUTOLOCK_METRIC_KEY = "private_space_autolock_mode"; private PrivateSpaceMaintainer mPrivateSpaceMaintainer; private CharSequence[] mAutoLockRadioOptions; private CharSequence[] mAutoLockRadioValues; @@ -111,6 +113,12 @@ public class AutoLockSettingsFragment extends RadioButtonPickerFragment { try { @Settings.Secure.PrivateSpaceAutoLockOption final int value = Integer.parseInt(key); mPrivateSpaceMaintainer.setPrivateSpaceAutoLockSetting(value); + mMetricsFeatureProvider.action( + mMetricsFeatureProvider.getAttribution(getActivity()), + SettingsEnums.ACTION_SET_PRIVATE_SPACE_AUTOLOCK, + getMetricsCategory(), + AUTOLOCK_METRIC_KEY, + value /* value */); } catch (NumberFormatException e) { Log.e(TAG, "could not persist screen timeout setting", e); } From 55e9f41bda14bd19d246657978a9aae4eda8a8d0 Mon Sep 17 00:00:00 2001 From: Manish Singh Date: Mon, 4 Mar 2024 16:00:03 +0000 Subject: [PATCH 13/16] Return true only if the userManager belongs to private profile The existing code asks the main user's userManager if there's a private profile belonging to it. If a private profile exists then the answer to that question will always be true. So, we always end up showing the apps from the private profile for the personal case. We should instead ask the userManager if it belongs to the private profile or not. Bug: 327598131 Test: manual Change-Id: I7bc9d58c371341235579d3456b54ea85f598892b --- .../credentials/DefaultCombinedPickerPrivate.java | 10 +--------- .../CredentialsPickerActivityTest.java | 15 +++++++-------- .../DefaultCombinedPreferenceControllerTest.java | 2 +- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/com/android/settings/applications/credentials/DefaultCombinedPickerPrivate.java b/src/com/android/settings/applications/credentials/DefaultCombinedPickerPrivate.java index 8d8af0e385d..52adc4de2a3 100644 --- a/src/com/android/settings/applications/credentials/DefaultCombinedPickerPrivate.java +++ b/src/com/android/settings/applications/credentials/DefaultCombinedPickerPrivate.java @@ -17,7 +17,6 @@ package com.android.settings.applications.credentials; import android.os.UserManager; -import android.util.Slog; import com.android.settings.Utils; import com.android.settings.dashboard.profileselector.ProfileSelectFragment.ProfileType; @@ -33,13 +32,6 @@ public class DefaultCombinedPickerPrivate extends DefaultCombinedPicker { /** Returns whether the user is handled by this fragment. */ public static boolean isUserHandledByFragment(UserManager userManager) { - try { - // If there is no private profile then this will throw an exception. - Utils.getCurrentUserIdOfType(userManager, ProfileType.PRIVATE); - return true; - } catch (IllegalStateException e) { - Slog.e(TAG, "Failed to get private profile user id", e); - return false; - } + return android.os.Flags.allowPrivateProfile() && userManager.isPrivateProfile(); } } diff --git a/tests/unit/src/com/android/settings/applications/credentials/CredentialsPickerActivityTest.java b/tests/unit/src/com/android/settings/applications/credentials/CredentialsPickerActivityTest.java index 044c23dbc51..62e99097e4d 100644 --- a/tests/unit/src/com/android/settings/applications/credentials/CredentialsPickerActivityTest.java +++ b/tests/unit/src/com/android/settings/applications/credentials/CredentialsPickerActivityTest.java @@ -19,21 +19,21 @@ package com.android.settings.applications.credentials; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; -import android.content.pm.UserInfo; -import android.os.UserHandle; +import android.os.Flags; import android.os.UserManager; +import android.platform.test.flag.junit.SetFlagsRule; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; -import com.google.common.collect.Lists; - import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -41,6 +41,7 @@ import org.mockito.MockitoAnnotations; @RunWith(AndroidJUnit4.class) public class CredentialsPickerActivityTest { + @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Mock private UserManager mUserManager; @@ -76,13 +77,11 @@ public class CredentialsPickerActivityTest { @Test public void testInjectFragmentIntoIntent_privateProfile() { + mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE); Intent intent = new Intent(); // Simulate private profile. - UserHandle privateUser = new UserHandle(100); - when(mUserManager.getUserInfo(100)) - .thenReturn(new UserInfo(100, "", "", 0, UserManager.USER_TYPE_PROFILE_PRIVATE)); - when(mUserManager.getUserProfiles()).thenReturn(Lists.newArrayList(privateUser)); + doReturn(true).when(mUserManager).isPrivateProfile(); assertThat(DefaultCombinedPickerPrivate.isUserHandledByFragment(mUserManager)).isTrue(); CredentialsPickerActivity.injectFragmentIntoIntent(mMockContext, intent); diff --git a/tests/unit/src/com/android/settings/applications/credentials/DefaultCombinedPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/credentials/DefaultCombinedPreferenceControllerTest.java index d02240e3786..99fb7a4c884 100644 --- a/tests/unit/src/com/android/settings/applications/credentials/DefaultCombinedPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/applications/credentials/DefaultCombinedPreferenceControllerTest.java @@ -117,7 +117,7 @@ public class DefaultCombinedPreferenceControllerTest { // Set the preference back to none and make sure the view was updated. dcpc.updatePreferenceForProvider(ppp, null, null, null, null, null); - assertThat(ppp.getTitle().toString()).isEqualTo("None"); + assertThat(ppp.getTitle().toString()).isEqualTo("None selected"); assertThat(ppp.getSummary()).isNull(); assertThat(ppp.getIcon()).isNull(); } From 29286ec8c380858116db4850bf537694cccb30f6 Mon Sep 17 00:00:00 2001 From: songferngwang Date: Mon, 4 Mar 2024 22:35:38 +0000 Subject: [PATCH 14/16] Fix the test case failed -Add flag FLAG_IS_DUAL_SIM_ONBOARDING_ENABLED -Add mock for SubscriptionManager.createForAllUserProfiles Bug: 323652989 Test: atest NetworkProviderCallsSmsFragmentTest atest SubscriptionsPreferenceControllerTest atest DefaultSubscriptionControllerTest atest DisableSimFooterPreferenceControllerTest atest MobileDataPreferenceControllerTest atest MobileNetworkSwitchControllerTest atest MobileNetworkUtilsTest atest NetworkSelectSettingsTest Change-Id: I4d473140f291daec0f8e56c01bd8f7cfa2d0c82e --- .../network/NetworkProviderCallsSmsFragmentTest.java | 8 +++++++- .../SubscriptionsPreferenceControllerTest.java | 1 + .../telephony/DefaultSubscriptionControllerTest.java | 10 ++++++++-- .../DisableSimFooterPreferenceControllerTest.java | 2 ++ .../telephony/MobileDataPreferenceControllerTest.java | 6 ++++++ .../telephony/MobileNetworkSwitchControllerTest.java | 6 ++++++ .../network/telephony/MobileNetworkUtilsTest.java | 4 ++++ .../network/telephony/NetworkSelectSettingsTest.java | 11 ++++++++++- 8 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsFragmentTest.java b/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsFragmentTest.java index d00e2dd891c..cc9e116b544 100644 --- a/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsFragmentTest.java +++ b/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsFragmentTest.java @@ -22,12 +22,16 @@ import static org.mockito.Mockito.spy; import android.content.Context; import android.os.Looper; +import android.platform.test.flag.junit.SetFlagsRule; import androidx.test.annotation.UiThreadTest; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.android.settings.flags.Flags; + import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.MockitoAnnotations; @@ -36,7 +40,8 @@ import java.util.List; @RunWith(AndroidJUnit4.class) public class NetworkProviderCallsSmsFragmentTest { - + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); private Context mContext; private List mPreferenceKeyList; @@ -49,6 +54,7 @@ public class NetworkProviderCallsSmsFragmentTest { if (Looper.myLooper() == null) { Looper.prepare(); } + mSetFlagsRule.disableFlags(Flags.FLAG_IS_DUAL_SIM_ONBOARDING_ENABLED); } @Test diff --git a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java index bca12c17f21..58a3f3a1d85 100644 --- a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java @@ -148,6 +148,7 @@ public class SubscriptionsPreferenceControllerTest { when(mUserManager.isAdminUser()).thenReturn(true); when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager); when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry); + when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager); mPreferenceManager = new PreferenceManager(mContext); mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext); diff --git a/tests/unit/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java index ef5d4a72718..42e3a839ba2 100644 --- a/tests/unit/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.os.Looper; +import android.platform.test.flag.junit.SetFlagsRule; import android.telecom.TelecomManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; @@ -40,6 +41,7 @@ import androidx.test.annotation.UiThreadTest; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.android.settings.flags.Flags; import com.android.settings.network.SubscriptionUtil; import com.android.settings.testutils.ResourcesUtils; import com.android.settingslib.core.lifecycle.Lifecycle; @@ -47,6 +49,7 @@ import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -58,6 +61,8 @@ import java.util.List; @RunWith(AndroidJUnit4.class) public class DefaultSubscriptionControllerTest { + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); private static final String SUB_ID_1 = "1"; private static final String SUB_ID_2 = "2"; @@ -105,10 +110,11 @@ public class DefaultSubscriptionControllerTest { if (Looper.myLooper() == null) { Looper.prepare(); } - + mSetFlagsRule.disableFlags(Flags.FLAG_IS_DUAL_SIM_ONBOARDING_ENABLED); mContext = spy(ApplicationProvider.getApplicationContext()); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubMgr); when(mContext.getSystemService(TelecomManager.class)).thenReturn(mTelecomManager); + when(mSubMgr.createForAllUserProfiles()).thenReturn(mSubMgr); final String key = "prefkey"; mController = new TestDefaultSubscriptionController(mContext, key, mLifecycle, @@ -312,9 +318,9 @@ public class DefaultSubscriptionControllerTest { mController.setDefaultSubscription(Integer.parseInt(mSubInfo1.subId)); mSubscriptionInfoEntityList.add(mSubInfo1); mSubscriptionInfoEntityList.add(mSubInfo2); - mController.onActiveSubInfoChanged(mSubscriptionInfoEntityList); mController.displayPreference(mScreen); + mController.onActiveSubInfoChanged(mSubscriptionInfoEntityList); assertThat(mListPreference.getEntries().length).isEqualTo(3); mSubscriptionInfoEntityList.add(mSubInfo3); diff --git a/tests/unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java index 72feb30d649..bbbee216994 100644 --- a/tests/unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/DisableSimFooterPreferenceControllerTest.java @@ -57,6 +57,8 @@ public class DisableSimFooterPreferenceControllerTest { MockitoAnnotations.initMocks(this); mContext = spy(ApplicationProvider.getApplicationContext()); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); + when(mSubscriptionManager.createForAllUserProfiles()).thenReturn(mSubscriptionManager); + when(mInfo.getSubscriptionId()).thenReturn(SUB_ID); SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mInfo)); mController = new DisableSimFooterPreferenceController(mContext, PREF_KEY); diff --git a/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java index 11a490ef76e..152091a0226 100644 --- a/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java @@ -28,6 +28,7 @@ import static org.mockito.Mockito.when; import android.app.Instrumentation; import android.content.Context; import android.os.Looper; +import android.platform.test.flag.junit.SetFlagsRule; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; @@ -41,12 +42,14 @@ import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.platform.app.InstrumentationRegistry; +import com.android.settings.flags.Flags; import com.android.settings.testutils.ResourcesUtils; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity; import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -54,6 +57,8 @@ import org.mockito.MockitoAnnotations; @RunWith(AndroidJUnit4.class) public class MobileDataPreferenceControllerTest { + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); private static final String SUB_ID_1 = "1"; private static final String SUB_ID_2 = "2"; private static final String DISPLAY_NAME_1 = "Sub 1"; @@ -93,6 +98,7 @@ public class MobileDataPreferenceControllerTest { if (Looper.myLooper() == null) { Looper.prepare(); } + mSetFlagsRule.disableFlags(Flags.FLAG_IS_DUAL_SIM_ONBOARDING_ENABLED); mContext = spy(ApplicationProvider.getApplicationContext()); doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE); diff --git a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java index 3cdd23ab1f5..ae10ca84700 100644 --- a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java @@ -33,6 +33,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Looper; +import android.platform.test.flag.junit.SetFlagsRule; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyCallback; @@ -47,6 +48,7 @@ import androidx.preference.PreferenceViewHolder; import androidx.test.annotation.UiThreadTest; import androidx.test.core.app.ApplicationProvider; +import com.android.settings.flags.Flags; import com.android.settings.network.SubscriptionUtil; import com.android.settings.widget.SettingsMainSwitchPreference; @@ -63,6 +65,8 @@ import java.util.Arrays; import java.util.concurrent.Executor; public class MobileNetworkSwitchControllerTest { + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); @@ -82,6 +86,8 @@ public class MobileNetworkSwitchControllerTest { @Before public void setUp() { + mSetFlagsRule.disableFlags(Flags.FLAG_IS_DUAL_SIM_ONBOARDING_ENABLED); + if (Looper.myLooper() == null) { Looper.prepare(); } diff --git a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java index 947ba75db66..a6f8f2d5670 100644 --- a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java @@ -134,6 +134,10 @@ public class MobileNetworkUtilsTest { when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn( Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)); + when(mSubscriptionManager.getActiveSubscriptionInfo(SUB_ID_1)).thenReturn( + mSubscriptionInfo1); + when(mSubscriptionManager.getActiveSubscriptionInfo(SUB_ID_2)).thenReturn( + mSubscriptionInfo2); when(mTelephonyManager.getNetworkOperatorName()).thenReturn( PLMN_FROM_TELEPHONY_MANAGER_API); diff --git a/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java b/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java index 080534eeb7b..512e48454f8 100644 --- a/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java @@ -109,7 +109,9 @@ public class NetworkSelectSettingsTest { PersistableBundle config = new PersistableBundle(); config.putBoolean(CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL, true); - doReturn(config).when(mCarrierConfigManager).getConfigForSubId(SUB_ID); + doReturn(config).when(mCarrierConfigManager).getConfigForSubId(SUB_ID, + CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL, + CarrierConfigManager.KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL); doReturn(TelephonyManager.DATA_CONNECTED).when(mTelephonyManager).getDataState(); } @@ -267,6 +269,13 @@ public class NetworkSelectSettingsTest { @Test public void doAggregation_hasDuplicateItemsDiffMccMncCase3_removeSamePlmnRatItem() { + PersistableBundle config = new PersistableBundle(); + config.putBoolean( + CarrierConfigManager.KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL, false); + doReturn(config).when(mCarrierConfigManager).getConfigForSubId(eq(SUB_ID), + eq(CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL), + eq(CarrierConfigManager.KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL)); + mNetworkSelectSettings.onCreateInitialization(); List testList = Arrays.asList( createLteCellInfo(false, 123, "123", "232", "CarrierA"), From f8237aee940d7abfebb3895c4cce151b9a83f218 Mon Sep 17 00:00:00 2001 From: Riley Jones Date: Thu, 29 Feb 2024 21:43:46 +0000 Subject: [PATCH 15/16] Change EditShortcutsPreferenceFragment to use a Preference for subtitle/description Replaces PreferenceCategory with unselectable Preference to better match desired visuals Screenshot at https://x20web.corp.google.com/users/jo/jonesriley/dragToEdit/editScreenWithSubtitle.png Flag: N/A Test: N/A Bug: 323388734 Change-Id: Ia1b333bc246ea4dd98070a646d5a8a1716ccbcee --- res/xml/accessibility_edit_shortcuts.xml | 112 +++++++++--------- .../EditShortcutsPreferenceFragment.java | 4 +- 2 files changed, 59 insertions(+), 57 deletions(-) diff --git a/res/xml/accessibility_edit_shortcuts.xml b/res/xml/accessibility_edit_shortcuts.xml index 8be0ee50857..fdb5b99a641 100644 --- a/res/xml/accessibility_edit_shortcuts.xml +++ b/res/xml/accessibility_edit_shortcuts.xml @@ -18,66 +18,68 @@ - + - + - + - + - + - + - - - - + + \ No newline at end of file diff --git a/src/com/android/settings/accessibility/shortcuts/EditShortcutsPreferenceFragment.java b/src/com/android/settings/accessibility/shortcuts/EditShortcutsPreferenceFragment.java index 5a3b13ab640..aba342a792e 100644 --- a/src/com/android/settings/accessibility/shortcuts/EditShortcutsPreferenceFragment.java +++ b/src/com/android/settings/accessibility/shortcuts/EditShortcutsPreferenceFragment.java @@ -207,9 +207,9 @@ public class EditShortcutsPreferenceFragment extends DashboardFragment { activity.setTitle(titles.first); - String categoryKey = activity.getResources().getString( + String screenDescriptionPrefKey = getString( R.string.accessibility_shortcut_description_pref); - findPreference(categoryKey).setTitle(titles.second); + findPreference(screenDescriptionPrefKey).setSummary(titles.second); } @NonNull From dd5a8e610cf939e3bebdf6f48b165dacab30c525 Mon Sep 17 00:00:00 2001 From: Manish Singh Date: Wed, 14 Feb 2024 16:07:32 +0000 Subject: [PATCH 16/16] Add controller for location for private profile Bug: 303196278 Test: manual Change-Id: I0997918e5046ac803c2c2d117c2e027b4aacc2c2 --- res/values/strings.xml | 2 + res/xml/location_settings.xml | 8 + ...ForPrivateProfilePreferenceController.java | 117 +++++++++++ .../settings/location/LocationSettings.java | 1 + ...rivateProfilePreferenceControllerTest.java | 189 ++++++++++++++++++ 5 files changed, 317 insertions(+) create mode 100644 src/com/android/settings/location/LocationForPrivateProfilePreferenceController.java create mode 100644 tests/robotests/src/com/android/settings/location/LocationForPrivateProfilePreferenceControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 46b7e868321..75fc6660415 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3542,6 +3542,8 @@ Location for work profile + + Location for private space App location permissions diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml index fe87efd73d7..206cc46bb24 100644 --- a/res/xml/location_settings.xml +++ b/res/xml/location_settings.xml @@ -49,6 +49,14 @@ settings:forWork="true" settings:useAdminDisabledSummary="true"/> + + + mLifecycle; + mLifecycle = new Lifecycle(mLifecycleOwner); + mLocationSettings = spy(new LocationSettings()); + when(mLocationSettings.getSettingsLifecycle()).thenReturn(mLifecycle); + mController = new LocationForPrivateProfilePreferenceController(mContext, "key"); + mController.init(mLocationSettings); + ReflectionHelpers.setField(mController, "mLocationEnabler", mEnabler); + when(mScreen.findPreference(any())).thenReturn(mPreference); + final String key = mController.getPreferenceKey(); + when(mPreference.getKey()).thenReturn(key); + when(mPreference.isVisible()).thenReturn(true); + } + + @Test + public void handlePreferenceTreeClick_preferenceChecked_shouldSetRestrictionAndOnSummary() { + mController.displayPreference(mScreen); + when(mPreference.isChecked()).thenReturn(true); + + mController.handlePreferenceTreeClick(mPreference); + + verify(mUserManager) + .setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, false, mUserHandle); + verify(mPreference).setSummary(R.string.switch_on_text); + } + + @Test + public void handlePreferenceTreeClick_preferenceUnchecked_shouldSetRestritionAndOffSummary() { + mController.displayPreference(mScreen); + when(mPreference.isChecked()).thenReturn(false); + + mController.handlePreferenceTreeClick(mPreference); + + verify(mUserManager) + .setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, mUserHandle); + verify(mPreference).setSummary(R.string.switch_off_text); + } + + @Test + public void onLocationModeChanged_disabledByAdmin_shouldDisablePreference() { + mController.displayPreference(mScreen); + final EnforcedAdmin admin = mock(EnforcedAdmin.class); + doReturn(admin).when(mEnabler).getShareLocationEnforcedAdmin(anyInt()); + doReturn(false).when(mEnabler).hasShareLocationRestriction(anyInt()); + + mController.onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, false); + + verify(mPreference).setDisabledByAdmin(any()); + } + + @Test + public void onLocationModeChanged_locationOff_shouldDisablePreference() { + mController.displayPreference(mScreen); + doReturn(null).when(mEnabler).getShareLocationEnforcedAdmin(anyInt()); + doReturn(false).when(mEnabler).hasShareLocationRestriction(anyInt()); + + mController.onLocationModeChanged(Settings.Secure.LOCATION_MODE_OFF, false); + + verify(mPreference).setEnabled(false); + verify(mPreference).setChecked(false); + verify(mPreference).setSummary(R.string.location_app_permission_summary_location_off); + } + + @Test + public void onLocationModeChanged_locationOn_shouldEnablePreference() { + mController.displayPreference(mScreen); + doReturn(null).when(mEnabler).getShareLocationEnforcedAdmin(anyInt()); + doReturn(false).when(mEnabler).hasShareLocationRestriction(anyInt()); + doReturn(true).when(mEnabler).isEnabled(anyInt()); + + mController.onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, false); + + verify(mPreference, times(2)).setEnabled(true); + verify(mPreference).setSummary(R.string.switch_on_text); + } + + @Test + public void onLocationModeChanged_noRestriction_shouldCheckedPreference() { + mController.displayPreference(mScreen); + doReturn(null).when(mEnabler).getShareLocationEnforcedAdmin(anyInt()); + doReturn(false).when(mEnabler).hasShareLocationRestriction(anyInt()); + doReturn(true).when(mEnabler).isEnabled(anyInt()); + + mController.onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, false); + + verify(mPreference).setChecked(true); + } + + @Test + public void onLocationModeChanged_hasRestriction_shouldCheckedPreference() { + mController.displayPreference(mScreen); + doReturn(null).when(mEnabler).getShareLocationEnforcedAdmin(anyInt()); + doReturn(true).when(mEnabler).hasShareLocationRestriction(anyInt()); + + mController.onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, false); + + verify(mPreference).setChecked(false); + } + + private void mockPrivateProfile() { + final List userProfiles = new ArrayList<>(); + doReturn(9).when(mUserHandle).getIdentifier(); + userProfiles.add(mUserHandle); + doReturn(userProfiles).when(mUserManager).getUserProfiles(); + doReturn(new UserInfo( + 9, + "user 9", + "", + 0, + UserManager.USER_TYPE_PROFILE_PRIVATE)).when(mUserManager).getUserInfo(9); + } +}