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
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<QSTile.State?>(
|
||||
@@ -93,6 +95,7 @@ constructor(
|
||||
systemSettings,
|
||||
secureSettings,
|
||||
systemClock,
|
||||
userTracker,
|
||||
mainHandler,
|
||||
backgroundDelayableExecutor
|
||||
)
|
||||
|
||||
@@ -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<SeekBar.OnSeekBarChangeListener>
|
||||
|
||||
@@ -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<SeekBar>(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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user