From a0477eddc3fc29b6a3bfa0d99cd11ef38ad0359e Mon Sep 17 00:00:00 2001 From: Candice Lo Date: Tue, 6 Jun 2023 08:35:05 +0000 Subject: [PATCH 1/2] Fix Font Size Dialog user settings in second/guest user Get/put settings value from current user in Font Size Dialog to ensure that we are always read/modify font scale from/for current user. Bug: 284084419 Test: manually - testing Font Size tile on Second user and Guest Test: atest FontScalingDialogTest FontScalingTileTest Change-Id: I11be9d8ece0d6a65b270cb209c6462610874fad1 --- .../fontscaling/FontScalingDialog.kt | 24 ++++++--- .../systemui/qs/tiles/FontScalingTile.kt | 3 ++ .../fontscaling/FontScalingDialogTest.kt | 52 +++++++++++++++---- .../systemui/qs/tiles/FontScalingTileTest.kt | 3 ++ 4 files changed, 66 insertions(+), 16 deletions(-) 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..1e227e513ba24 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt @@ -38,6 +38,7 @@ 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.util.concurrency.DelayableExecutor import com.android.systemui.util.settings.SecureSettings @@ -62,6 +63,7 @@ constructor( private val secureSettings: SecureSettings, private val systemClock: SystemClock, private val featureFlags: FeatureFlags, + private val userTracker: UserTracker, @Background private val backgroundDelayableExecutor: DelayableExecutor ) : QSTileImpl( @@ -93,6 +95,7 @@ constructor( systemSettings, secureSettings, systemClock, + userTracker, mainHandler, backgroundDelayableExecutor ) 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..1670a4248e26a 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,7 @@ 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.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.eq @@ -61,6 +62,7 @@ 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 private lateinit var testableLooper: TestableLooper private lateinit var systemClock: FakeSystemClock @@ -93,6 +95,7 @@ class FontScalingTileTest : SysuiTestCase() { FakeSettings(), FakeSystemClock(), featureFlags, + userTracker, backgroundDelayableExecutor, ) fontScalingTile.initialize() From 40016bffce8bf60302fc09c2cdf62e31045a22a5 Mon Sep 17 00:00:00 2001 From: Candice Lo Date: Mon, 15 May 2023 04:10:00 +0000 Subject: [PATCH 2/2] Hide Quick Settings shade when the FontScalingDialog is opened When the users try to modify the font size through the Quick Settings, we would like to hide the QS shade so users could see the text content upderlying when they are modifying the font scale. We consider the following cases: 1. Screen unlocked: hide the shade and show the dialog 2. Screen locked: dismiss keyguard, hide the shade, and show the dialog Bug: 282110776 Test: manually - attach video to the bug Test: atest FontScalingTileTest Change-Id: I66a1c6b5df903c671b4b9c0eab178c5b6de99d61 --- .../systemui/qs/tiles/FontScalingTile.kt | 21 ++++++++-- .../systemui/qs/tiles/FontScalingTileTest.kt | 40 ++++++++++++++++++- 2 files changed, 57 insertions(+), 4 deletions(-) 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 1e227e513ba24..423fa80cacdb4 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt @@ -40,6 +40,7 @@ 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 @@ -58,6 +59,7 @@ constructor( statusBarStateController: StatusBarStateController, activityStarter: ActivityStarter, qsLogger: QSLogger, + private val keyguardStateController: KeyguardStateController, private val dialogLaunchAnimator: DialogLaunchAnimator, private val systemSettings: SystemSettings, private val secureSettings: SecureSettings, @@ -88,7 +90,10 @@ 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, @@ -99,16 +104,26 @@ constructor( 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/qs/tiles/FontScalingTileTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/FontScalingTileTest.kt index 1670a4248e26a..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 @@ -34,6 +34,7 @@ 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 @@ -45,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 @@ -63,6 +67,7 @@ class FontScalingTileTest : SysuiTestCase() { @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 @@ -71,6 +76,8 @@ class FontScalingTileTest : SysuiTestCase() { val featureFlags = FakeFeatureFlags() + @Captor private lateinit var argumentCaptor: ArgumentCaptor + @Before fun setUp() { MockitoAnnotations.initMocks(this) @@ -90,6 +97,7 @@ class FontScalingTileTest : SysuiTestCase() { statusBarStateController, activityStarter, qsLogger, + keyguardStateController, dialogLaunchAnimator, FakeSettings(), FakeSettings(), @@ -127,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()