Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/data/repository/QSPreferencesRepositoryTest.kt +98 −17 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.testScope import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.qs.pipeline.shared.TilesUpgradePath import com.android.systemui.settings.userFileManager import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.fakeUserRepository Loading Loading @@ -76,11 +77,11 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { @Test fun setLargeTilesSpecs_inSharedPreferences() { val setA = setOf("tileA", "tileB") underTest.setLargeTilesSpecs(setA.toTileSpecs()) underTest.writeLargeTileSpecs(setA.toTileSpecs()) assertThat(getLargeTilesSpecsFromSharedPreferences()).isEqualTo(setA) val setB = setOf("tileA", "tileB") underTest.setLargeTilesSpecs(setB.toTileSpecs()) underTest.writeLargeTileSpecs(setB.toTileSpecs()) assertThat(getLargeTilesSpecsFromSharedPreferences()).isEqualTo(setB) } Loading @@ -92,12 +93,12 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) val setA = setOf("tileA", "tileB") underTest.setLargeTilesSpecs(setA.toTileSpecs()) underTest.writeLargeTileSpecs(setA.toTileSpecs()) assertThat(getLargeTilesSpecsFromSharedPreferences()).isEqualTo(setA) fakeUserRepository.setSelectedUserInfo(ANOTHER_USER) val setB = setOf("tileA", "tileB") underTest.setLargeTilesSpecs(setB.toTileSpecs()) underTest.writeLargeTileSpecs(setB.toTileSpecs()) assertThat(getLargeTilesSpecsFromSharedPreferences()).isEqualTo(setB) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) Loading @@ -106,7 +107,7 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { } @Test fun setInitialTilesFromSettings_noLargeTiles_tilesSet() = fun setUpgradePathFromSettings_noLargeTiles_tilesSet() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -117,14 +118,17 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { assertThat(getSharedPreferences().contains(LARGE_TILES_SPECS_KEY)).isFalse() underTest.setInitialLargeTilesSpecs(tiles, PRIMARY_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(tiles), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(tiles) } } @Test fun setInitialTilesFromSettings_alreadyLargeTiles_tilesNotSet() = fun setUpgradePathFromSettings_alreadyLargeTiles_tilesNotSet() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -133,14 +137,17 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { fakeUserRepository.setSelectedUserInfo(ANOTHER_USER) setLargeTilesSpecsInSharedPreferences(setOf("tileC")) underTest.setInitialLargeTilesSpecs(setOf("tileA").toTileSpecs(), ANOTHER_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(setOf("tileA").toTileSpecs()), ANOTHER_USER_ID, ) assertThat(largeTiles).isEqualTo(setOf("tileC").toTileSpecs()) } } @Test fun setInitialTilesFromSettings_emptyLargeTiles_tilesNotSet() = fun setUpgradePathFromSettings_emptyLargeTiles_tilesNotSet() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -149,14 +156,17 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { fakeUserRepository.setSelectedUserInfo(ANOTHER_USER) setLargeTilesSpecsInSharedPreferences(emptySet()) underTest.setInitialLargeTilesSpecs(setOf("tileA").toTileSpecs(), ANOTHER_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(setOf("tileA").toTileSpecs()), ANOTHER_USER_ID, ) assertThat(largeTiles).isEmpty() } } @Test fun setInitialTilesFromSettings_nonCurrentUser_tilesSetForCorrectUser() = fun setUpgradePathFromSettings_nonCurrentUser_tilesSetForCorrectUser() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -164,7 +174,10 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { fakeUserRepository.setUserInfos(USERS) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) underTest.setInitialLargeTilesSpecs(setOf("tileA").toTileSpecs(), ANOTHER_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(setOf("tileA").toTileSpecs()), ANOTHER_USER_ID, ) assertThat(largeTiles).isEqualTo(defaultLargeTilesRepository.defaultLargeTiles) Loading @@ -174,7 +187,7 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { } @Test fun setInitialTiles_afterDefaultRead_noSetOnRepository_initialTilesCorrect() = fun setUpgradePath_afterDefaultRead_noSetOnRepository_initialTilesCorrect() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -186,14 +199,17 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { assertThat(currentLargeTiles).isNotEmpty() val tiles = setOf("tileA", "tileB") underTest.setInitialLargeTilesSpecs(tiles.toTileSpecs(), PRIMARY_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(tiles.toTileSpecs()), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(tiles.toTileSpecs()) } } @Test fun setInitialTiles_afterDefaultRead_largeTilesSetOnRepository_initialTilesCorrect() = fun setUpgradePath_afterDefaultRead_largeTilesSetOnRepository_initialTilesCorrect() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -204,15 +220,80 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { assertThat(currentLargeTiles).isNotEmpty() underTest.setLargeTilesSpecs(setOf(TileSpec.create("tileC"))) underTest.writeLargeTileSpecs(setOf(TileSpec.create("tileC"))) val tiles = setOf("tileA", "tileB") underTest.setInitialLargeTilesSpecs(tiles.toTileSpecs(), PRIMARY_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(tiles.toTileSpecs()), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(setOf(TileSpec.create("tileC"))) } } @Test fun setTilesRestored_noLargeTiles_tilesSet() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) fakeUserRepository.setUserInfos(USERS) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) val tiles = setOf("tileA", "tileB").toTileSpecs() assertThat(getSharedPreferences().contains(LARGE_TILES_SPECS_KEY)).isFalse() underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.RestoreFromBackup(tiles), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(tiles) } } @Test fun setDefaultTilesInitial_defaultSetLarge() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) fakeUserRepository.setUserInfos(USERS) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.DefaultSet, PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(defaultLargeTilesRepository.defaultLargeTiles) } } @Test fun setTilesRestored_afterDefaultSet_tilesSet() = with(kosmos) { testScope.runTest { underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.DefaultSet, PRIMARY_USER_ID, ) val largeTiles by collectLastValue(underTest.largeTilesSpecs) fakeUserRepository.setUserInfos(USERS) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) val tiles = setOf("tileA", "tileB").toTileSpecs() underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.RestoreFromBackup(tiles), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(tiles) } } private fun getSharedPreferences(): SharedPreferences = with(kosmos) { return userFileManager.getSharedPreferences( Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/LargeTilesUpgradePathsTest.kt 0 → 100644 +328 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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.systemui.qs.panels.domain import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.content.res.mainResources import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.backup.BackupHelper.Companion.ACTION_RESTORE_FINISHED import com.android.systemui.broadcast.broadcastDispatcher import com.android.systemui.common.shared.model.PackageChangeModel.Empty.packageName import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.qs.panels.data.repository.QSPreferencesRepository import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository import com.android.systemui.qs.panels.domain.interactor.qsPreferencesInteractor import com.android.systemui.qs.pipeline.data.repository.DefaultTilesQSHostRepository import com.android.systemui.qs.pipeline.data.repository.defaultTilesRepository import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.qs.pipeline.shared.TilesUpgradePath import com.android.systemui.settings.userFileManager import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.userRepository import com.google.common.truth.Truth.assertThat import kotlin.test.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class LargeTilesUpgradePathsTest : SysuiTestCase() { private val kosmos = testKosmos().apply { defaultTilesRepository = DefaultTilesQSHostRepository(mainResources) } private val defaultTiles = kosmos.defaultTilesRepository.defaultTiles.toSet() private val underTest = kosmos.qsPreferencesInteractor private val Kosmos.userId get() = userRepository.getSelectedUserInfo().id private val Kosmos.intent get() = Intent(ACTION_RESTORE_FINISHED).apply { `package` = packageName putExtra(Intent.EXTRA_USER_ID, kosmos.userId) flags = Intent.FLAG_RECEIVER_REGISTERED_ONLY } /** * This test corresponds to the case of a fresh start. * * The resulting large tiles are the default set of large tiles. */ @Test fun defaultTiles_noDataInSharedPreferences_defaultLargeTiles() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) underTest.setInitialOrUpgradeLargeTilesSpecs(TilesUpgradePath.DefaultSet, userId) assertThat(largeTiles).isEqualTo(defaultLargeTilesRepository.defaultLargeTiles) } /** * This test corresponds to a user that upgraded in place from a build that didn't support large * tiles to one that does. The current tiles of the user are read from settings. * * The resulting large tiles are those that were read from Settings. */ @Test fun upgradeInPlace_noDataInSharedPreferences_allLargeTiles() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val tiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(tiles), userId, ) assertThat(largeTiles).isEqualTo(tiles) } /** * This test corresponds to a fresh start, and then the user restarts the device, without ever * having modified the set of large tiles. * * The resulting large tiles are the default large tiles that were set on the fresh start */ @Test fun defaultSet_restartDevice_largeTilesDontChange() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) underTest.setInitialOrUpgradeLargeTilesSpecs(TilesUpgradePath.DefaultSet, userId) // User restarts the device, this will send a read from settings with the default // set of tiles underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(defaultTiles), userId, ) assertThat(largeTiles).isEqualTo(defaultLargeTilesRepository.defaultLargeTiles) } /** * This test corresponds to a fresh start, following the user changing the sizes of some tiles. * After that, the user restarts the device. * * The resulting set of large tiles are those that the user determined before restarting the * device. */ @Test fun defaultSet_someSizeChanges_restart_correctSet() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) underTest.setInitialOrUpgradeLargeTilesSpecs(TilesUpgradePath.DefaultSet, userId) underTest.setLargeTilesSpecs(largeTiles!! + setOf("a", "b").toTileSpecs()) val largeTilesBeforeRestart = largeTiles!! // Restart underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(defaultTiles), userId, ) assertThat(largeTiles).isEqualTo(largeTilesBeforeRestart) } /** * This test corresponds to a user that upgraded, and after that performed some size changes. * After that, the user restarts the device. * * The resulting set of large tiles are those that the user determined before restarting the * device. */ @Test fun readFromSettings_changeSizes_restart_newLargeSet() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val readTiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(readTiles), userId, ) underTest.setLargeTilesSpecs(emptySet()) assertThat(largeTiles).isEmpty() // Restart underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(readTiles), userId, ) assertThat(largeTiles).isEmpty() } /** * This test corresponds to a user that upgraded from a build that didn't support tile sizes to * one that does, via restore from backup. Note that there's no file in SharedPreferences to * restore. * * The resulting set of large tiles are those that were restored from the backup. */ @Test fun restoreFromBackup_noDataInSharedPreferences_allLargeTiles() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val tiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(tiles), userId, ) assertThat(largeTiles).isEqualTo(tiles) } /** * This test corresponds to a user that upgraded from a build that didn't support tile sizes to * one that does, via restore from backup. However, the restore happens after SystemUI's * initialization has set the tiles to default. Note that there's no file in SharedPreferences * to restore. * * The resulting set of large tiles are those that were restored from the backup. */ @Test fun restoreFromBackup_afterDefault_noDataInSharedPreferences_allLargeTiles() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) underTest.setInitialOrUpgradeLargeTilesSpecs(TilesUpgradePath.DefaultSet, userId) val tiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(tiles), userId, ) assertThat(largeTiles).isEqualTo(tiles) } /** * This test corresponds to a user that restored from a build that supported different sizes * tiles. First the list of tiles is restored in Settings and then a file containing some large * tiles overrides the current shared preferences file * * The resulting set of large tiles are those that were restored from the shared preferences * backup (and not the full list). */ @Test fun restoreFromBackup_thenRestoreOfSharedPrefs_sharedPrefsAreLarge() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val tiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(tiles), userId, ) val tilesFromBackupOfSharedPrefs = setOf("a") setLargeTilesSpecsInSharedPreferences(tilesFromBackupOfSharedPrefs) broadcastDispatcher.sendIntentToMatchingReceiversOnly(context, intent) assertThat(largeTiles).isEqualTo(tilesFromBackupOfSharedPrefs.toTileSpecs()) } /** * This test corresponds to a user that restored from a build that supported different sizes * tiles. However, this restore of settings happened after SystemUI's restore of the SharedPrefs * containing the user's previous selections to large/small tiles. * * The resulting set of large tiles are those that were restored from the shared preferences * backup (and not the full list). */ @Test fun restoreFromBackup_afterRestoreOfSharedPrefs_sharedPrefsAreLarge() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val tiles = setOf("a", "b", "c").toTileSpecs() val tilesFromBackupOfSharedPrefs = setOf("a") setLargeTilesSpecsInSharedPreferences(tilesFromBackupOfSharedPrefs) broadcastDispatcher.sendIntentToMatchingReceiversOnly(context, intent) underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(tiles), userId, ) assertThat(largeTiles).isEqualTo(tilesFromBackupOfSharedPrefs.toTileSpecs()) } /** * This test corresponds to a user that upgraded from a build that didn't support tile sizes to * one that does, via restore from backup. After that, the user modifies the size of some tiles * and then restarts the device. * * The resulting set of large tiles are those after the user modifications. */ @Test fun restoreFromBackup_changeSizes_restart_newLargeSet() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val readTiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(readTiles), userId, ) underTest.setLargeTilesSpecs(emptySet()) assertThat(largeTiles).isEmpty() // Restart underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(readTiles), userId, ) assertThat(largeTiles).isEmpty() } private companion object { private const val LARGE_TILES_SPECS_KEY = "large_tiles_specs" private fun Kosmos.getSharedPreferences(): SharedPreferences = userFileManager.getSharedPreferences( QSPreferencesRepository.FILE_NAME, Context.MODE_PRIVATE, userRepository.getSelectedUserInfo().id, ) private fun Kosmos.setLargeTilesSpecsInSharedPreferences(specs: Set<String>) { getSharedPreferences().edit().putStringSet(LARGE_TILES_SPECS_KEY, specs).apply() } private fun Kosmos.getLargeTilesSpecsFromSharedPreferences(): Set<String> { return getSharedPreferences().getStringSet(LARGE_TILES_SPECS_KEY, emptySet())!! } private fun Set<String>.toTileSpecs(): Set<TileSpec> { return map { TileSpec.create(it) }.toSet() } } } packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/IconTilesInteractorTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ class IconTilesInteractorTest : SysuiTestCase() { runCurrent() // Resize it to large qsPreferencesRepository.setLargeTilesSpecs(setOf(spec)) qsPreferencesRepository.writeLargeTileSpecs(setOf(spec)) runCurrent() // Assert that the new tile was added to the large tiles set Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/TileSpecSettingsRepositoryTest.kt +9 −5 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.coroutines.collectValues import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.qs.pipeline.shared.TilesUpgradePath import com.android.systemui.qs.pipeline.shared.logging.QSPipelineLogger import com.android.systemui.res.R import com.android.systemui.retail.data.repository.FakeRetailModeRepository Loading Loading @@ -242,9 +243,12 @@ class TileSpecSettingsRepositoryTest : SysuiTestCase() { storeTilesForUser(startingTiles, userId) val tiles by collectLastValue(underTest.tilesSpecs(userId)) val tilesRead by collectLastValue(underTest.tilesReadFromSetting.consumeAsFlow()) val tilesRead by collectLastValue(underTest.tilesUpgradePath.consumeAsFlow()) assertThat(tilesRead).isEqualTo(startingTiles.toTileSpecs().toSet() to userId) assertThat(tilesRead) .isEqualTo( TilesUpgradePath.ReadFromSettings(startingTiles.toTileSpecs().toSet()) to userId ) } @Test Loading @@ -258,13 +262,13 @@ class TileSpecSettingsRepositoryTest : SysuiTestCase() { val tiles10 by collectLastValue(underTest.tilesSpecs(10)) val tiles11 by collectLastValue(underTest.tilesSpecs(11)) val tilesRead by collectValues(underTest.tilesReadFromSetting.consumeAsFlow()) val tilesRead by collectValues(underTest.tilesUpgradePath.consumeAsFlow()) assertThat(tilesRead).hasSize(2) assertThat(tilesRead) .containsExactly( startingTiles10.toTileSpecs().toSet() to 10, startingTiles11.toTileSpecs().toSet() to 11, TilesUpgradePath.ReadFromSettings(startingTiles10.toTileSpecs().toSet()) to 10, TilesUpgradePath.ReadFromSettings(startingTiles11.toTileSpecs().toSet()) to 11, ) } Loading packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/UserTileSpecRepositoryTest.kt +34 −9 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/data/repository/QSPreferencesRepositoryTest.kt +98 −17 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.testScope import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.qs.pipeline.shared.TilesUpgradePath import com.android.systemui.settings.userFileManager import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.fakeUserRepository Loading Loading @@ -76,11 +77,11 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { @Test fun setLargeTilesSpecs_inSharedPreferences() { val setA = setOf("tileA", "tileB") underTest.setLargeTilesSpecs(setA.toTileSpecs()) underTest.writeLargeTileSpecs(setA.toTileSpecs()) assertThat(getLargeTilesSpecsFromSharedPreferences()).isEqualTo(setA) val setB = setOf("tileA", "tileB") underTest.setLargeTilesSpecs(setB.toTileSpecs()) underTest.writeLargeTileSpecs(setB.toTileSpecs()) assertThat(getLargeTilesSpecsFromSharedPreferences()).isEqualTo(setB) } Loading @@ -92,12 +93,12 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) val setA = setOf("tileA", "tileB") underTest.setLargeTilesSpecs(setA.toTileSpecs()) underTest.writeLargeTileSpecs(setA.toTileSpecs()) assertThat(getLargeTilesSpecsFromSharedPreferences()).isEqualTo(setA) fakeUserRepository.setSelectedUserInfo(ANOTHER_USER) val setB = setOf("tileA", "tileB") underTest.setLargeTilesSpecs(setB.toTileSpecs()) underTest.writeLargeTileSpecs(setB.toTileSpecs()) assertThat(getLargeTilesSpecsFromSharedPreferences()).isEqualTo(setB) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) Loading @@ -106,7 +107,7 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { } @Test fun setInitialTilesFromSettings_noLargeTiles_tilesSet() = fun setUpgradePathFromSettings_noLargeTiles_tilesSet() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -117,14 +118,17 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { assertThat(getSharedPreferences().contains(LARGE_TILES_SPECS_KEY)).isFalse() underTest.setInitialLargeTilesSpecs(tiles, PRIMARY_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(tiles), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(tiles) } } @Test fun setInitialTilesFromSettings_alreadyLargeTiles_tilesNotSet() = fun setUpgradePathFromSettings_alreadyLargeTiles_tilesNotSet() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -133,14 +137,17 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { fakeUserRepository.setSelectedUserInfo(ANOTHER_USER) setLargeTilesSpecsInSharedPreferences(setOf("tileC")) underTest.setInitialLargeTilesSpecs(setOf("tileA").toTileSpecs(), ANOTHER_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(setOf("tileA").toTileSpecs()), ANOTHER_USER_ID, ) assertThat(largeTiles).isEqualTo(setOf("tileC").toTileSpecs()) } } @Test fun setInitialTilesFromSettings_emptyLargeTiles_tilesNotSet() = fun setUpgradePathFromSettings_emptyLargeTiles_tilesNotSet() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -149,14 +156,17 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { fakeUserRepository.setSelectedUserInfo(ANOTHER_USER) setLargeTilesSpecsInSharedPreferences(emptySet()) underTest.setInitialLargeTilesSpecs(setOf("tileA").toTileSpecs(), ANOTHER_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(setOf("tileA").toTileSpecs()), ANOTHER_USER_ID, ) assertThat(largeTiles).isEmpty() } } @Test fun setInitialTilesFromSettings_nonCurrentUser_tilesSetForCorrectUser() = fun setUpgradePathFromSettings_nonCurrentUser_tilesSetForCorrectUser() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -164,7 +174,10 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { fakeUserRepository.setUserInfos(USERS) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) underTest.setInitialLargeTilesSpecs(setOf("tileA").toTileSpecs(), ANOTHER_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(setOf("tileA").toTileSpecs()), ANOTHER_USER_ID, ) assertThat(largeTiles).isEqualTo(defaultLargeTilesRepository.defaultLargeTiles) Loading @@ -174,7 +187,7 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { } @Test fun setInitialTiles_afterDefaultRead_noSetOnRepository_initialTilesCorrect() = fun setUpgradePath_afterDefaultRead_noSetOnRepository_initialTilesCorrect() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -186,14 +199,17 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { assertThat(currentLargeTiles).isNotEmpty() val tiles = setOf("tileA", "tileB") underTest.setInitialLargeTilesSpecs(tiles.toTileSpecs(), PRIMARY_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(tiles.toTileSpecs()), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(tiles.toTileSpecs()) } } @Test fun setInitialTiles_afterDefaultRead_largeTilesSetOnRepository_initialTilesCorrect() = fun setUpgradePath_afterDefaultRead_largeTilesSetOnRepository_initialTilesCorrect() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) Loading @@ -204,15 +220,80 @@ class QSPreferencesRepositoryTest : SysuiTestCase() { assertThat(currentLargeTiles).isNotEmpty() underTest.setLargeTilesSpecs(setOf(TileSpec.create("tileC"))) underTest.writeLargeTileSpecs(setOf(TileSpec.create("tileC"))) val tiles = setOf("tileA", "tileB") underTest.setInitialLargeTilesSpecs(tiles.toTileSpecs(), PRIMARY_USER_ID) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.ReadFromSettings(tiles.toTileSpecs()), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(setOf(TileSpec.create("tileC"))) } } @Test fun setTilesRestored_noLargeTiles_tilesSet() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) fakeUserRepository.setUserInfos(USERS) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) val tiles = setOf("tileA", "tileB").toTileSpecs() assertThat(getSharedPreferences().contains(LARGE_TILES_SPECS_KEY)).isFalse() underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.RestoreFromBackup(tiles), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(tiles) } } @Test fun setDefaultTilesInitial_defaultSetLarge() = with(kosmos) { testScope.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) fakeUserRepository.setUserInfos(USERS) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.DefaultSet, PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(defaultLargeTilesRepository.defaultLargeTiles) } } @Test fun setTilesRestored_afterDefaultSet_tilesSet() = with(kosmos) { testScope.runTest { underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.DefaultSet, PRIMARY_USER_ID, ) val largeTiles by collectLastValue(underTest.largeTilesSpecs) fakeUserRepository.setUserInfos(USERS) fakeUserRepository.setSelectedUserInfo(PRIMARY_USER) val tiles = setOf("tileA", "tileB").toTileSpecs() underTest.setInitialOrUpgradeLargeTiles( TilesUpgradePath.RestoreFromBackup(tiles), PRIMARY_USER_ID, ) assertThat(largeTiles).isEqualTo(tiles) } } private fun getSharedPreferences(): SharedPreferences = with(kosmos) { return userFileManager.getSharedPreferences( Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/LargeTilesUpgradePathsTest.kt 0 → 100644 +328 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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.systemui.qs.panels.domain import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.content.res.mainResources import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.backup.BackupHelper.Companion.ACTION_RESTORE_FINISHED import com.android.systemui.broadcast.broadcastDispatcher import com.android.systemui.common.shared.model.PackageChangeModel.Empty.packageName import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.qs.panels.data.repository.QSPreferencesRepository import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository import com.android.systemui.qs.panels.domain.interactor.qsPreferencesInteractor import com.android.systemui.qs.pipeline.data.repository.DefaultTilesQSHostRepository import com.android.systemui.qs.pipeline.data.repository.defaultTilesRepository import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.qs.pipeline.shared.TilesUpgradePath import com.android.systemui.settings.userFileManager import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.userRepository import com.google.common.truth.Truth.assertThat import kotlin.test.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class LargeTilesUpgradePathsTest : SysuiTestCase() { private val kosmos = testKosmos().apply { defaultTilesRepository = DefaultTilesQSHostRepository(mainResources) } private val defaultTiles = kosmos.defaultTilesRepository.defaultTiles.toSet() private val underTest = kosmos.qsPreferencesInteractor private val Kosmos.userId get() = userRepository.getSelectedUserInfo().id private val Kosmos.intent get() = Intent(ACTION_RESTORE_FINISHED).apply { `package` = packageName putExtra(Intent.EXTRA_USER_ID, kosmos.userId) flags = Intent.FLAG_RECEIVER_REGISTERED_ONLY } /** * This test corresponds to the case of a fresh start. * * The resulting large tiles are the default set of large tiles. */ @Test fun defaultTiles_noDataInSharedPreferences_defaultLargeTiles() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) underTest.setInitialOrUpgradeLargeTilesSpecs(TilesUpgradePath.DefaultSet, userId) assertThat(largeTiles).isEqualTo(defaultLargeTilesRepository.defaultLargeTiles) } /** * This test corresponds to a user that upgraded in place from a build that didn't support large * tiles to one that does. The current tiles of the user are read from settings. * * The resulting large tiles are those that were read from Settings. */ @Test fun upgradeInPlace_noDataInSharedPreferences_allLargeTiles() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val tiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(tiles), userId, ) assertThat(largeTiles).isEqualTo(tiles) } /** * This test corresponds to a fresh start, and then the user restarts the device, without ever * having modified the set of large tiles. * * The resulting large tiles are the default large tiles that were set on the fresh start */ @Test fun defaultSet_restartDevice_largeTilesDontChange() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) underTest.setInitialOrUpgradeLargeTilesSpecs(TilesUpgradePath.DefaultSet, userId) // User restarts the device, this will send a read from settings with the default // set of tiles underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(defaultTiles), userId, ) assertThat(largeTiles).isEqualTo(defaultLargeTilesRepository.defaultLargeTiles) } /** * This test corresponds to a fresh start, following the user changing the sizes of some tiles. * After that, the user restarts the device. * * The resulting set of large tiles are those that the user determined before restarting the * device. */ @Test fun defaultSet_someSizeChanges_restart_correctSet() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) underTest.setInitialOrUpgradeLargeTilesSpecs(TilesUpgradePath.DefaultSet, userId) underTest.setLargeTilesSpecs(largeTiles!! + setOf("a", "b").toTileSpecs()) val largeTilesBeforeRestart = largeTiles!! // Restart underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(defaultTiles), userId, ) assertThat(largeTiles).isEqualTo(largeTilesBeforeRestart) } /** * This test corresponds to a user that upgraded, and after that performed some size changes. * After that, the user restarts the device. * * The resulting set of large tiles are those that the user determined before restarting the * device. */ @Test fun readFromSettings_changeSizes_restart_newLargeSet() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val readTiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(readTiles), userId, ) underTest.setLargeTilesSpecs(emptySet()) assertThat(largeTiles).isEmpty() // Restart underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(readTiles), userId, ) assertThat(largeTiles).isEmpty() } /** * This test corresponds to a user that upgraded from a build that didn't support tile sizes to * one that does, via restore from backup. Note that there's no file in SharedPreferences to * restore. * * The resulting set of large tiles are those that were restored from the backup. */ @Test fun restoreFromBackup_noDataInSharedPreferences_allLargeTiles() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val tiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(tiles), userId, ) assertThat(largeTiles).isEqualTo(tiles) } /** * This test corresponds to a user that upgraded from a build that didn't support tile sizes to * one that does, via restore from backup. However, the restore happens after SystemUI's * initialization has set the tiles to default. Note that there's no file in SharedPreferences * to restore. * * The resulting set of large tiles are those that were restored from the backup. */ @Test fun restoreFromBackup_afterDefault_noDataInSharedPreferences_allLargeTiles() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) underTest.setInitialOrUpgradeLargeTilesSpecs(TilesUpgradePath.DefaultSet, userId) val tiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(tiles), userId, ) assertThat(largeTiles).isEqualTo(tiles) } /** * This test corresponds to a user that restored from a build that supported different sizes * tiles. First the list of tiles is restored in Settings and then a file containing some large * tiles overrides the current shared preferences file * * The resulting set of large tiles are those that were restored from the shared preferences * backup (and not the full list). */ @Test fun restoreFromBackup_thenRestoreOfSharedPrefs_sharedPrefsAreLarge() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val tiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(tiles), userId, ) val tilesFromBackupOfSharedPrefs = setOf("a") setLargeTilesSpecsInSharedPreferences(tilesFromBackupOfSharedPrefs) broadcastDispatcher.sendIntentToMatchingReceiversOnly(context, intent) assertThat(largeTiles).isEqualTo(tilesFromBackupOfSharedPrefs.toTileSpecs()) } /** * This test corresponds to a user that restored from a build that supported different sizes * tiles. However, this restore of settings happened after SystemUI's restore of the SharedPrefs * containing the user's previous selections to large/small tiles. * * The resulting set of large tiles are those that were restored from the shared preferences * backup (and not the full list). */ @Test fun restoreFromBackup_afterRestoreOfSharedPrefs_sharedPrefsAreLarge() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val tiles = setOf("a", "b", "c").toTileSpecs() val tilesFromBackupOfSharedPrefs = setOf("a") setLargeTilesSpecsInSharedPreferences(tilesFromBackupOfSharedPrefs) broadcastDispatcher.sendIntentToMatchingReceiversOnly(context, intent) underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(tiles), userId, ) assertThat(largeTiles).isEqualTo(tilesFromBackupOfSharedPrefs.toTileSpecs()) } /** * This test corresponds to a user that upgraded from a build that didn't support tile sizes to * one that does, via restore from backup. After that, the user modifies the size of some tiles * and then restarts the device. * * The resulting set of large tiles are those after the user modifications. */ @Test fun restoreFromBackup_changeSizes_restart_newLargeSet() = kosmos.runTest { val largeTiles by collectLastValue(underTest.largeTilesSpecs) val readTiles = setOf("a", "b", "c").toTileSpecs() underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.RestoreFromBackup(readTiles), userId, ) underTest.setLargeTilesSpecs(emptySet()) assertThat(largeTiles).isEmpty() // Restart underTest.setInitialOrUpgradeLargeTilesSpecs( TilesUpgradePath.ReadFromSettings(readTiles), userId, ) assertThat(largeTiles).isEmpty() } private companion object { private const val LARGE_TILES_SPECS_KEY = "large_tiles_specs" private fun Kosmos.getSharedPreferences(): SharedPreferences = userFileManager.getSharedPreferences( QSPreferencesRepository.FILE_NAME, Context.MODE_PRIVATE, userRepository.getSelectedUserInfo().id, ) private fun Kosmos.setLargeTilesSpecsInSharedPreferences(specs: Set<String>) { getSharedPreferences().edit().putStringSet(LARGE_TILES_SPECS_KEY, specs).apply() } private fun Kosmos.getLargeTilesSpecsFromSharedPreferences(): Set<String> { return getSharedPreferences().getStringSet(LARGE_TILES_SPECS_KEY, emptySet())!! } private fun Set<String>.toTileSpecs(): Set<TileSpec> { return map { TileSpec.create(it) }.toSet() } } }
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/domain/interactor/IconTilesInteractorTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ class IconTilesInteractorTest : SysuiTestCase() { runCurrent() // Resize it to large qsPreferencesRepository.setLargeTilesSpecs(setOf(spec)) qsPreferencesRepository.writeLargeTileSpecs(setOf(spec)) runCurrent() // Assert that the new tile was added to the large tiles set Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/TileSpecSettingsRepositoryTest.kt +9 −5 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.coroutines.collectValues import com.android.systemui.qs.pipeline.shared.TileSpec import com.android.systemui.qs.pipeline.shared.TilesUpgradePath import com.android.systemui.qs.pipeline.shared.logging.QSPipelineLogger import com.android.systemui.res.R import com.android.systemui.retail.data.repository.FakeRetailModeRepository Loading Loading @@ -242,9 +243,12 @@ class TileSpecSettingsRepositoryTest : SysuiTestCase() { storeTilesForUser(startingTiles, userId) val tiles by collectLastValue(underTest.tilesSpecs(userId)) val tilesRead by collectLastValue(underTest.tilesReadFromSetting.consumeAsFlow()) val tilesRead by collectLastValue(underTest.tilesUpgradePath.consumeAsFlow()) assertThat(tilesRead).isEqualTo(startingTiles.toTileSpecs().toSet() to userId) assertThat(tilesRead) .isEqualTo( TilesUpgradePath.ReadFromSettings(startingTiles.toTileSpecs().toSet()) to userId ) } @Test Loading @@ -258,13 +262,13 @@ class TileSpecSettingsRepositoryTest : SysuiTestCase() { val tiles10 by collectLastValue(underTest.tilesSpecs(10)) val tiles11 by collectLastValue(underTest.tilesSpecs(11)) val tilesRead by collectValues(underTest.tilesReadFromSetting.consumeAsFlow()) val tilesRead by collectValues(underTest.tilesUpgradePath.consumeAsFlow()) assertThat(tilesRead).hasSize(2) assertThat(tilesRead) .containsExactly( startingTiles10.toTileSpecs().toSet() to 10, startingTiles11.toTileSpecs().toSet() to 11, TilesUpgradePath.ReadFromSettings(startingTiles10.toTileSpecs().toSet()) to 10, TilesUpgradePath.ReadFromSettings(startingTiles11.toTileSpecs().toSet()) to 11, ) } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/UserTileSpecRepositoryTest.kt +34 −9 File changed.Preview size limit exceeded, changes collapsed. Show changes