diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index e5cd0c55027bd..082f3855affc7 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -99,6 +99,7 @@
- accessibility_display_daltonizer_enabled:color_correction
- accessibility_display_inversion_enabled:inversion
- one_handed_mode_enabled:onehanded
+ - accessibility_font_scaling_has_been_changed:font_scaling
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 53a421d9eccc0..1836ce8577835 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt
@@ -15,6 +15,7 @@
*/
package com.android.systemui.accessibility.fontscaling
+import android.annotation.WorkerThread
import android.content.Context
import android.content.pm.ActivityInfo
import android.content.res.Configuration
@@ -27,18 +28,26 @@ import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import com.android.systemui.R
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView
+import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.statusbar.phone.SystemUIDialog
+import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SystemSettings
+import java.util.concurrent.Executor
import kotlin.math.roundToInt
/** The Dialog that contains a seekbar for changing the font size. */
-class FontScalingDialog(context: Context, private val systemSettings: SystemSettings) :
- SystemUIDialog(context) {
+class FontScalingDialog(
+ context: Context,
+ private val systemSettings: SystemSettings,
+ private val secureSettings: SecureSettings,
+ @Background private val backgroundExecutor: Executor
+) : SystemUIDialog(context) {
private val strEntryValues: Array =
context.resources.getStringArray(com.android.settingslib.R.array.entryvalues_font_size)
private lateinit var title: TextView
private lateinit var doneButton: Button
private lateinit var seekBarWithIconButtonsView: SeekBarWithIconButtonsView
+ private var lastProgress: Int = -1
private val configuration: Configuration =
Configuration(context.getResources().getConfiguration())
@@ -70,12 +79,22 @@ class FontScalingDialog(context: Context, private val systemSettings: SystemSett
seekBarWithIconButtonsView.setMax((strEntryValues).size - 1)
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, 1.0f)
- seekBarWithIconButtonsView.setProgress(fontSizeValueToIndex(currentScale))
+ lastProgress = fontSizeValueToIndex(currentScale)
+ seekBarWithIconButtonsView.setProgress(lastProgress)
seekBarWithIconButtonsView.setOnSeekBarChangeListener(
object : OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
- systemSettings.putString(Settings.System.FONT_SCALE, strEntryValues[progress])
+ if (progress != lastProgress) {
+ if (!fontSizeHasBeenChangedFromTile) {
+ backgroundExecutor.execute { updateSecureSettingsIfNeeded() }
+ fontSizeHasBeenChangedFromTile = true
+ }
+
+ backgroundExecutor.execute { updateFontScale(strEntryValues[progress]) }
+
+ lastProgress = progress
+ }
}
override fun onStartTrackingTouch(seekBar: SeekBar) {
@@ -115,4 +134,28 @@ class FontScalingDialog(context: Context, private val systemSettings: SystemSett
}
}
}
+
+ @WorkerThread
+ fun updateFontScale(newScale: String) {
+ systemSettings.putString(Settings.System.FONT_SCALE, newScale)
+ }
+
+ @WorkerThread
+ fun updateSecureSettingsIfNeeded() {
+ if (
+ secureSettings.getString(Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED) !=
+ ON
+ ) {
+ secureSettings.putString(
+ Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED,
+ ON
+ )
+ }
+ }
+
+ companion object {
+ private const val ON = "1"
+ private const val OFF = "0"
+ private var fontSizeHasBeenChangedFromTile = false
+ }
}
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 a915ddba4f1c5..3f514344cee1f 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt
@@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles
import android.content.Intent
import android.os.Handler
+import android.os.HandlerExecutor
import android.os.Looper
import android.provider.Settings
import android.view.View
@@ -38,6 +39,7 @@ import com.android.systemui.qs.QSHost
import com.android.systemui.qs.logging.QSLogger
import com.android.systemui.qs.tileimpl.QSTileImpl
import com.android.systemui.statusbar.phone.SystemUIDialog
+import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SystemSettings
import javax.inject.Inject
@@ -54,6 +56,7 @@ constructor(
qsLogger: QSLogger,
private val dialogLaunchAnimator: DialogLaunchAnimator,
private val systemSettings: SystemSettings,
+ private val secureSettings: SecureSettings,
private val featureFlags: FeatureFlags
) :
QSTileImpl(
@@ -78,7 +81,13 @@ constructor(
override fun handleClick(view: View?) {
mUiHandler.post {
- val dialog: SystemUIDialog = FontScalingDialog(mContext, systemSettings)
+ val dialog: SystemUIDialog =
+ FontScalingDialog(
+ mContext,
+ systemSettings,
+ secureSettings,
+ HandlerExecutor(mHandler)
+ )
if (view != null) {
dialogLaunchAnimator.showFromView(
dialog,
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 ca6f42618e2a0..eb8295653199e 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,12 +25,19 @@ 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.util.concurrency.FakeExecutor
import com.android.systemui.util.settings.FakeSettings
+import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SystemSettings
+import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+import org.mockito.MockitoAnnotations
+
+private const val ON: Int = 1
+private const val OFF: Int = 0
/** Tests for [FontScalingDialog]. */
@SmallTest
@@ -39,6 +46,8 @@ import org.junit.runner.RunWith
class FontScalingDialogTest : SysuiTestCase() {
private lateinit var fontScalingDialog: FontScalingDialog
private lateinit var systemSettings: SystemSettings
+ private lateinit var secureSettings: SecureSettings
+ private lateinit var backgroundExecutor: FakeExecutor
private val fontSizeValueArray: Array =
mContext
.getResources()
@@ -46,9 +55,13 @@ class FontScalingDialogTest : SysuiTestCase() {
@Before
fun setUp() {
+ MockitoAnnotations.initMocks(this)
val mainHandler = Handler(TestableLooper.get(this).getLooper())
systemSettings = FakeSettings()
- fontScalingDialog = FontScalingDialog(mContext, systemSettings as FakeSettings)
+ secureSettings = FakeSettings()
+ backgroundExecutor = FakeExecutor(FakeSystemClock())
+ fontScalingDialog =
+ FontScalingDialog(mContext, systemSettings, secureSettings, backgroundExecutor)
}
@Test
@@ -76,6 +89,7 @@ class FontScalingDialogTest : SysuiTestCase() {
seekBarWithIconButtonsView.setProgress(0)
iconEndFrame.performClick()
+ backgroundExecutor.runAllReady()
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
assertThat(seekBar.getProgress()).isEqualTo(1)
@@ -96,6 +110,7 @@ class FontScalingDialogTest : SysuiTestCase() {
seekBarWithIconButtonsView.setProgress(fontSizeValueArray.size - 1)
iconStartFrame.performClick()
+ backgroundExecutor.runAllReady()
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
assertThat(seekBar.getProgress()).isEqualTo(fontSizeValueArray.size - 2)
@@ -104,4 +119,26 @@ class FontScalingDialogTest : SysuiTestCase() {
fontScalingDialog.dismiss()
}
+
+ @Test
+ fun progressChanged_keyWasNotSetBefore_fontScalingHasBeenChangedIsOn() {
+ fontScalingDialog.show()
+
+ val seekBarWithIconButtonsView: SeekBarWithIconButtonsView =
+ fontScalingDialog.findViewById(R.id.font_scaling_slider)!!
+ secureSettings.putInt(Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED, OFF)
+
+ // Default seekbar progress for font size is 1, set it to another progress 0
+ seekBarWithIconButtonsView.setProgress(0)
+ backgroundExecutor.runAllReady()
+
+ val currentSettings =
+ secureSettings.getInt(
+ Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED,
+ /* def = */ OFF
+ )
+ assertThat(currentSettings).isEqualTo(ON)
+
+ 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 bd99cd482859b..eeebd4fb7792c 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
@@ -84,6 +84,7 @@ class FontScalingTileTest : SysuiTestCase() {
qsLogger,
dialogLaunchAnimator,
FakeSettings(),
+ FakeSettings(),
featureFlags
)
fontScalingTile.initialize()