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/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/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/res/values/strings.xml b/res/values/strings.xml index 55c48af6ac8..7ae9074242a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3562,6 +3562,8 @@ Location for work profile + + Location for private space App location permissions @@ -4375,6 +4377,8 @@ Tap to click + + Tap dragging Touchpad gestures @@ -4478,8 +4482,14 @@ Choose a new key for %1$s: + + %s layout Default + + Automatic: %s + + User selected: %s Speech 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/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"/> + + + @@ -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,15 +44,20 @@ 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"/> + + + @@ -63,6 +65,5 @@ 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/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 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); 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/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 } 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/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 diff --git a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java index f2ac5508d80..e102241f63a 100644 --- a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java +++ b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java @@ -288,19 +288,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 -> { diff --git a/src/com/android/settings/inputmethod/TrackpadTapDraggingPreferenceController.java b/src/com/android/settings/inputmethod/TrackpadTapDraggingPreferenceController.java new file mode 100644 index 00000000000..28c2915e4d7 --- /dev/null +++ b/src/com/android/settings/inputmethod/TrackpadTapDraggingPreferenceController.java @@ -0,0 +1,53 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.inputmethod; + +import android.content.Context; +import android.hardware.input.InputSettings; + +import com.android.settings.R; +import com.android.settings.core.TogglePreferenceController; + +public class TrackpadTapDraggingPreferenceController extends TogglePreferenceController { + + public TrackpadTapDraggingPreferenceController(Context context, String key) { + super(context, key); + } + + @Override + public boolean isChecked() { + return InputSettings.useTouchpadTapDragging(mContext); + } + + @Override + public boolean setChecked(boolean isChecked) { + InputSettings.setTouchpadTapDragging(mContext, isChecked); + // TODO(b/321978150): add a metric for tap dragging settings changes. + return true; + } + + @Override + public int getAvailabilityStatus() { + return InputSettings.isTouchpadTapDraggingFeatureFlagEnabled() + ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; + } + + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_system; + } +} diff --git a/src/com/android/settings/location/LocationForPrivateProfilePreferenceController.java b/src/com/android/settings/location/LocationForPrivateProfilePreferenceController.java new file mode 100644 index 00000000000..a7be7a50ade --- /dev/null +++ b/src/com/android/settings/location/LocationForPrivateProfilePreferenceController.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.location; + +import android.content.Context; +import android.os.UserHandle; +import android.os.UserManager; +import android.text.TextUtils; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.preference.Preference; +import androidx.preference.PreferenceScreen; + +import com.android.settings.R; +import com.android.settings.Utils; +import com.android.settings.dashboard.profileselector.ProfileSelectFragment.ProfileType; +import com.android.settingslib.RestrictedLockUtils; +import com.android.settingslib.RestrictedSwitchPreference; + +public class LocationForPrivateProfilePreferenceController + extends LocationBasePreferenceController { + @Nullable private RestrictedSwitchPreference mPreference; + @Nullable private final UserHandle mPrivateProfileHandle; + public LocationForPrivateProfilePreferenceController( + @NonNull Context context, @NonNull String key) { + super(context, key); + mPrivateProfileHandle = Utils.getProfileOfType(mUserManager, ProfileType.PRIVATE); + } + + @Override + public boolean handlePreferenceTreeClick(@NonNull Preference preference) { + if (TextUtils.equals(preference.getKey(), getPreferenceKey())) { + final boolean switchState = mPreference.isChecked(); + mUserManager.setUserRestriction( + UserManager.DISALLOW_SHARE_LOCATION, + !switchState, + mPrivateProfileHandle); + mPreference.setSummary(switchState + ? R.string.switch_on_text : R.string.switch_off_text); + return true; + } + return false; + } + + @Override + public void displayPreference(@NonNull PreferenceScreen screen) { + super.displayPreference(screen); + mPreference = screen.findPreference(getPreferenceKey()); + if (mPreference != null) { + mPreference.setEnabled(isPrivateProfileAvailable()); + } + } + + @Override + public int getAvailabilityStatus() { + if (!android.os.Flags.allowPrivateProfile() + || !android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace() + || !isPrivateProfileAvailable()) { + return CONDITIONALLY_UNAVAILABLE; + } + return AVAILABLE; + } + + @Override + public void onLocationModeChanged(int mode, boolean restricted) { + if ((mPreference != null && !mPreference.isVisible()) + || !isAvailable() + || !isPrivateProfileAvailable()) { + return; + } + + // The profile owner (which is the admin for the child profile) might have added a location + // sharing restriction. + final RestrictedLockUtils.EnforcedAdmin admin = + mLocationEnabler.getShareLocationEnforcedAdmin( + mPrivateProfileHandle.getIdentifier()); + if (admin != null) { + mPreference.setDisabledByAdmin(admin); + } else { + final boolean enabled = mLocationEnabler.isEnabled(mode); + mPreference.setEnabled(enabled); + int summaryResId; + + final boolean isRestrictedByBase = + mLocationEnabler + .hasShareLocationRestriction(mPrivateProfileHandle.getIdentifier()); + if (isRestrictedByBase || !enabled) { + mPreference.setChecked(false); + summaryResId = enabled ? R.string.switch_off_text + : R.string.location_app_permission_summary_location_off; + } else { + mPreference.setChecked(true); + summaryResId = R.string.switch_on_text; + } + mPreference.setSummary(summaryResId); + } + } + + private boolean isPrivateProfileAvailable() { + return mPrivateProfileHandle != null + && !mUserManager.isQuietModeEnabled(mPrivateProfileHandle); + } +} diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java index 7bb02285676..87e8817808f 100644 --- a/src/com/android/settings/location/LocationSettings.java +++ b/src/com/android/settings/location/LocationSettings.java @@ -119,6 +119,7 @@ public class LocationSettings extends DashboardFragment implements use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this); use(LocationForWorkPreferenceController.class).init(this); use(LocationSettingsFooterPreferenceController.class).init(this); + use(LocationForPrivateProfilePreferenceController.class).init(this); } @Override 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; } 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); } 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); 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); } diff --git a/tests/robotests/src/com/android/settings/location/LocationForPrivateProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationForPrivateProfilePreferenceControllerTest.java new file mode 100644 index 00000000000..bf6261f1469 --- /dev/null +++ b/tests/robotests/src/com/android/settings/location/LocationForPrivateProfilePreferenceControllerTest.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.location; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.content.pm.UserInfo; +import android.os.UserHandle; +import android.os.UserManager; +import android.provider.Settings; + +import androidx.lifecycle.LifecycleOwner; +import androidx.preference.PreferenceScreen; +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; +import com.android.settingslib.RestrictedSwitchPreference; +import com.android.settingslib.core.lifecycle.Lifecycle; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.util.ReflectionHelpers; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +public class LocationForPrivateProfilePreferenceControllerTest { + + @Mock + private RestrictedSwitchPreference mPreference; + @Mock + private PreferenceScreen mScreen; + @Mock + private UserManager mUserManager; + @Mock + private LocationEnabler mEnabler; + @Mock + private UserHandle mUserHandle; + + private Context mContext; + private LocationForPrivateProfilePreferenceController mController; + private LifecycleOwner mLifecycleOwner; + private Lifecycle mLifecycle; + private LocationSettings mLocationSettings; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = spy(ApplicationProvider.getApplicationContext()); + doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE); + mockPrivateProfile(); + mLifecycleOwner = () -> 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); + } +} 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() { 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(); } 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"),