diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt index e79b3f4bf3ad3..a910ab58444da 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt @@ -34,6 +34,7 @@ import com.android.systemui.R import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.dagger.qualifiers.Main +import com.android.systemui.settings.UserTracker import com.android.systemui.statusbar.phone.SystemUIDialog import com.android.systemui.util.concurrency.DelayableExecutor import com.android.systemui.util.settings.SecureSettings @@ -48,6 +49,7 @@ class FontScalingDialog( private val systemSettings: SystemSettings, private val secureSettings: SecureSettings, private val systemClock: SystemClock, + private val userTracker: UserTracker, @Main mainHandler: Handler, @Background private val backgroundDelayableExecutor: DelayableExecutor ) : SystemUIDialog(context) { @@ -98,7 +100,8 @@ class FontScalingDialog( seekBarWithIconButtonsView.setMax((strEntryValues).size - 1) - val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, 1.0f) + val currentScale = + systemSettings.getFloatForUser(Settings.System.FONT_SCALE, 1.0f, userTracker.userId) lastProgress.set(fontSizeValueToIndex(currentScale)) seekBarWithIconButtonsView.setProgress(lastProgress.get()) @@ -195,18 +198,25 @@ class FontScalingDialog( @WorkerThread fun updateFontScale() { - systemSettings.putString(Settings.System.FONT_SCALE, strEntryValues[lastProgress.get()]) + systemSettings.putStringForUser( + Settings.System.FONT_SCALE, + strEntryValues[lastProgress.get()], + userTracker.userId + ) } @WorkerThread fun updateSecureSettingsIfNeeded() { if ( - secureSettings.getString(Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED) != - ON - ) { - secureSettings.putString( + secureSettings.getStringForUser( Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED, - ON + userTracker.userId + ) != ON + ) { + secureSettings.putStringForUser( + Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED, + ON, + userTracker.userId ) } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt index c013486b83e4f..423fa80cacdb4 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt @@ -38,7 +38,9 @@ import com.android.systemui.qs.QSHost import com.android.systemui.qs.QsEventLogger import com.android.systemui.qs.logging.QSLogger import com.android.systemui.qs.tileimpl.QSTileImpl +import com.android.systemui.settings.UserTracker import com.android.systemui.statusbar.phone.SystemUIDialog +import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.util.concurrency.DelayableExecutor import com.android.systemui.util.settings.SecureSettings import com.android.systemui.util.settings.SystemSettings @@ -57,11 +59,13 @@ constructor( statusBarStateController: StatusBarStateController, activityStarter: ActivityStarter, qsLogger: QSLogger, + private val keyguardStateController: KeyguardStateController, private val dialogLaunchAnimator: DialogLaunchAnimator, private val systemSettings: SystemSettings, private val secureSettings: SecureSettings, private val systemClock: SystemClock, private val featureFlags: FeatureFlags, + private val userTracker: UserTracker, @Background private val backgroundDelayableExecutor: DelayableExecutor ) : QSTileImpl( @@ -86,26 +90,40 @@ constructor( } override fun handleClick(view: View?) { - mUiHandler.post { + // We animate from the touched view only if we are not on the keyguard + val animateFromView: Boolean = view != null && !keyguardStateController.isShowing + + val runnable = Runnable { val dialog: SystemUIDialog = FontScalingDialog( mContext, systemSettings, secureSettings, systemClock, + userTracker, mainHandler, backgroundDelayableExecutor ) - if (view != null) { + if (animateFromView) { dialogLaunchAnimator.showFromView( dialog, - view, + view!!, DialogCuj(InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN, INTERACTION_JANK_TAG) ) } else { dialog.show() } } + + mainHandler.post { + mActivityStarter.executeRunnableDismissingKeyguard( + runnable, + /* cancelAction= */ null, + /* dismissShade= */ true, + /* afterKeyguardGone= */ true, + /* deferred= */ false + ) + } } override fun handleUpdateState(state: QSTile.State?, arg: Any?) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt b/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt index f10c21bc514ac..a10f5dd4878d6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt @@ -25,6 +25,7 @@ import androidx.test.filters.SmallTest import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView +import com.android.systemui.settings.UserTracker import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.capture import com.android.systemui.util.mockito.whenever @@ -38,6 +39,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor import org.mockito.Captor +import org.mockito.Mock import org.mockito.Mockito.spy import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @@ -63,6 +65,7 @@ class FontScalingDialogTest : SysuiTestCase() { .getResources() .getStringArray(com.android.settingslib.R.array.entryvalues_font_size) + @Mock private lateinit var userTracker: UserTracker @Captor private lateinit var seekBarChangeCaptor: ArgumentCaptor @@ -72,7 +75,7 @@ class FontScalingDialogTest : SysuiTestCase() { val mainHandler = Handler(TestableLooper.get(this).getLooper()) systemSettings = FakeSettings() // Guarantee that the systemSettings always starts with the default font scale. - systemSettings.putFloat(Settings.System.FONT_SCALE, 1.0f) + systemSettings.putFloatForUser(Settings.System.FONT_SCALE, 1.0f, userTracker.userId) secureSettings = FakeSettings() systemClock = FakeSystemClock() backgroundDelayableExecutor = FakeExecutor(systemClock) @@ -82,6 +85,7 @@ class FontScalingDialogTest : SysuiTestCase() { systemSettings, secureSettings, systemClock, + userTracker, mainHandler, backgroundDelayableExecutor ) @@ -93,7 +97,12 @@ class FontScalingDialogTest : SysuiTestCase() { val seekBar: SeekBar = fontScalingDialog.findViewById(R.id.seekbar)!! val progress: Int = seekBar.getProgress() - val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) + val currentScale = + systemSettings.getFloatForUser( + Settings.System.FONT_SCALE, + /* def= */ 1.0f, + userTracker.userId + ) assertThat(currentScale).isEqualTo(fontSizeValueArray[progress].toFloat()) @@ -119,7 +128,12 @@ class FontScalingDialogTest : SysuiTestCase() { backgroundDelayableExecutor.advanceClockToNext() backgroundDelayableExecutor.runAllReady() - val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) + val currentScale = + systemSettings.getFloatForUser( + Settings.System.FONT_SCALE, + /* def= */ 1.0f, + userTracker.userId + ) assertThat(seekBar.getProgress()).isEqualTo(1) assertThat(currentScale).isEqualTo(fontSizeValueArray[1].toFloat()) @@ -145,7 +159,12 @@ class FontScalingDialogTest : SysuiTestCase() { backgroundDelayableExecutor.advanceClockToNext() backgroundDelayableExecutor.runAllReady() - val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) + val currentScale = + systemSettings.getFloatForUser( + Settings.System.FONT_SCALE, + /* def= */ 1.0f, + userTracker.userId + ) assertThat(seekBar.getProgress()).isEqualTo(fontSizeValueArray.size - 2) assertThat(currentScale) .isEqualTo(fontSizeValueArray[fontSizeValueArray.size - 2].toFloat()) @@ -159,16 +178,21 @@ class FontScalingDialogTest : SysuiTestCase() { val seekBarWithIconButtonsView: SeekBarWithIconButtonsView = fontScalingDialog.findViewById(R.id.font_scaling_slider)!! - secureSettings.putInt(Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED, OFF) + secureSettings.putIntForUser( + Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED, + OFF, + userTracker.userId + ) // Default seekbar progress for font size is 1, set it to another progress 0 seekBarWithIconButtonsView.setProgress(0) backgroundDelayableExecutor.runAllReady() val currentSettings = - secureSettings.getInt( + secureSettings.getIntForUser( Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED, - /* def = */ OFF + /* def = */ OFF, + userTracker.userId ) assertThat(currentSettings).isEqualTo(ON) @@ -199,7 +223,12 @@ class FontScalingDialogTest : SysuiTestCase() { backgroundDelayableExecutor.runAllReady() // Verify that the scale of font size remains the default value 1.0f. - var systemScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) + var systemScale = + systemSettings.getFloatForUser( + Settings.System.FONT_SCALE, + /* def= */ 1.0f, + userTracker.userId + ) assertThat(systemScale).isEqualTo(1.0f) // Simulate releasing the finger from the seekbar. @@ -209,7 +238,12 @@ class FontScalingDialogTest : SysuiTestCase() { backgroundDelayableExecutor.runAllReady() // Verify that the scale of font size has been updated. - systemScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) + systemScale = + systemSettings.getFloatForUser( + Settings.System.FONT_SCALE, + /* def= */ 1.0f, + userTracker.userId + ) assertThat(systemScale).isEqualTo(fontSizeValueArray[0].toFloat()) fontScalingDialog.dismiss() diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt index ddbfca57e6880..cbc3553805688 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt @@ -33,6 +33,8 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.qs.QSHost import com.android.systemui.qs.QsEventLogger import com.android.systemui.qs.logging.QSLogger +import com.android.systemui.settings.UserTracker +import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.eq @@ -44,8 +46,11 @@ import org.junit.After import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor import org.mockito.Mock import org.mockito.Mockito.anyBoolean +import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations @@ -61,6 +66,8 @@ class FontScalingTileTest : SysuiTestCase() { @Mock private lateinit var qsLogger: QSLogger @Mock private lateinit var dialogLaunchAnimator: DialogLaunchAnimator @Mock private lateinit var uiEventLogger: QsEventLogger + @Mock private lateinit var userTracker: UserTracker + @Mock private lateinit var keyguardStateController: KeyguardStateController private lateinit var testableLooper: TestableLooper private lateinit var systemClock: FakeSystemClock @@ -69,6 +76,8 @@ class FontScalingTileTest : SysuiTestCase() { val featureFlags = FakeFeatureFlags() + @Captor private lateinit var argumentCaptor: ArgumentCaptor + @Before fun setUp() { MockitoAnnotations.initMocks(this) @@ -88,11 +97,13 @@ class FontScalingTileTest : SysuiTestCase() { statusBarStateController, activityStarter, qsLogger, + keyguardStateController, dialogLaunchAnimator, FakeSettings(), FakeSettings(), FakeSystemClock(), featureFlags, + userTracker, backgroundDelayableExecutor, ) fontScalingTile.initialize() @@ -124,14 +135,44 @@ class FontScalingTileTest : SysuiTestCase() { } @Test - fun clickTile_showDialog() { + fun clickTile_screenUnlocked_showDialogAnimationFromView() { + `when`(keyguardStateController.isShowing).thenReturn(false) val view = View(context) fontScalingTile.click(view) testableLooper.processAllMessages() + verify(activityStarter) + .executeRunnableDismissingKeyguard( + argumentCaptor.capture(), + eq(null), + eq(true), + eq(true), + eq(false) + ) + argumentCaptor.value.run() verify(dialogLaunchAnimator).showFromView(any(), eq(view), nullable(), anyBoolean()) } + @Test + fun clickTile_onLockScreen_neverShowDialogAnimationFromView() { + `when`(keyguardStateController.isShowing).thenReturn(true) + val view = View(context) + fontScalingTile.click(view) + testableLooper.processAllMessages() + + verify(activityStarter) + .executeRunnableDismissingKeyguard( + argumentCaptor.capture(), + eq(null), + eq(true), + eq(true), + eq(false) + ) + argumentCaptor.value.run() + verify(dialogLaunchAnimator, never()) + .showFromView(any(), eq(view), nullable(), anyBoolean()) + } + @Test fun getLongClickIntent_getExpectedIntent() { val intent: Intent? = fontScalingTile.getLongClickIntent()