Merge pull request #718 from grote/non-suw-restore-uncheck

Uncheck system apps by default if restore outside of SUW
This commit is contained in:
Torsten Grote 2024-08-15 18:04:23 -03:00 committed by GitHub
commit 27cda5eba4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 10 deletions

View file

@ -52,7 +52,7 @@ internal class AppSelectionManager(
val selectedAppsFlow = selectedApps.asStateFlow()
val selectedAppsLiveData: LiveData<SelectedAppsState> = selectedApps.asLiveData()
fun onRestoreSetChosen(restorableBackup: RestorableBackup) {
fun onRestoreSetChosen(restorableBackup: RestorableBackup, isSetupWizard: Boolean) {
// filter and sort app items for display
val items = restorableBackup.packageMetadataMap.mapNotNull { (packageName, metadata) ->
if (metadata.time == 0L && !metadata.hasApk()) null
@ -80,7 +80,7 @@ internal class AppSelectionManager(
system = true,
name = context.getString(R.string.backup_system_apps),
),
selected = true,
selected = isSetupWizard,
)
items.add(0, systemItem)
items.addAll(0, systemDataItems)

View file

@ -49,6 +49,7 @@ class RestoreActivity : RequireProvisioningActivity() {
if (savedInstanceState == null) {
showFragment(RestoreSetFragment())
}
viewModel.isSetupWizard = isSetupWizard
}
@CallSuper

View file

@ -72,6 +72,7 @@ internal class RestoreViewModel(
RestorableBackupClickListener, SnapshotViewModel {
override val isRestoreOperation = true
var isSetupWizard = false
private val appSelectionManager =
AppSelectionManager(app, pluginManager, iconManager, viewModelScope)
@ -125,7 +126,7 @@ internal class RestoreViewModel(
override fun onRestorableBackupClicked(restorableBackup: RestorableBackup) {
mChosenRestorableBackup.value = restorableBackup
appSelectionManager.onRestoreSetChosen(restorableBackup)
appSelectionManager.onRestoreSetChosen(restorableBackup, isSetupWizard)
mDisplayFragment.setEvent(SELECT_APPS)
}

View file

@ -83,7 +83,7 @@ internal class AppSelectionManagerTest : TransportTest() {
),
)
)
appSelectionManager.onRestoreSetChosen(backup)
appSelectionManager.onRestoreSetChosen(backup, true)
val initialApps = awaitItem()
// only the meta system app item remains
@ -116,7 +116,7 @@ internal class AppSelectionManagerTest : TransportTest() {
),
)
)
appSelectionManager.onRestoreSetChosen(backup)
appSelectionManager.onRestoreSetChosen(backup, true)
val initialApps = awaitItem()
assertEquals(4, initialApps.apps.size)
@ -138,7 +138,7 @@ internal class AppSelectionManagerTest : TransportTest() {
packageName2 to PackageMetadata(time = 42L),
)
)
appSelectionManager.onRestoreSetChosen(backup)
appSelectionManager.onRestoreSetChosen(backup, true)
// first all are selected
val initialApps = awaitItem()
@ -196,7 +196,7 @@ internal class AppSelectionManagerTest : TransportTest() {
),
)
)
appSelectionManager.onRestoreSetChosen(backup)
appSelectionManager.onRestoreSetChosen(backup, true)
// all apps (except special ones) have an unknown item state initially
val initialApps = awaitItem()
@ -232,7 +232,7 @@ internal class AppSelectionManagerTest : TransportTest() {
packageName2 to PackageMetadata(time = 42L),
)
)
appSelectionManager.onRestoreSetChosen(backup)
appSelectionManager.onRestoreSetChosen(backup, true)
val initialApps = awaitItem()
assertEquals(3, initialApps.apps.size)
@ -318,6 +318,34 @@ internal class AppSelectionManagerTest : TransportTest() {
}
}
@Test
fun `system apps only pre-selected in setup wizard`() = runTest {
val backup = getRestorableBackup(
mutableMapOf(
packageName1 to PackageMetadata(system = true, isLaunchableSystemApp = false),
)
)
// choose restore set in setup wizard
appSelectionManager.selectedAppsFlow.test {
awaitItem()
appSelectionManager.onRestoreSetChosen(backup, true)
// only system apps meta item in list
val initialApps = awaitItem()
assertEquals(1, initialApps.apps.size)
assertEquals(PACKAGE_NAME_SYSTEM, initialApps.apps[0].packageName)
assertTrue(initialApps.apps[0].selected) // system settings is selected
}
appSelectionManager.selectedAppsFlow.test {
awaitItem()
appSelectionManager.onRestoreSetChosen(backup, false)
// only system apps meta item in list
val initialApps = awaitItem()
assertEquals(1, initialApps.apps.size)
assertEquals(PACKAGE_NAME_SYSTEM, initialApps.apps[0].packageName)
assertFalse(initialApps.apps[0].selected) // system settings is NOT selected
}
}
@Test
fun `@pm@ doesn't get filtered out`() = runTest {
appSelectionManager.selectedAppsFlow.test {
@ -331,7 +359,7 @@ internal class AppSelectionManagerTest : TransportTest() {
),
)
)
appSelectionManager.onRestoreSetChosen(backup)
appSelectionManager.onRestoreSetChosen(backup, true)
// only system apps meta item in list
val initialApps = awaitItem()
@ -385,7 +413,7 @@ internal class AppSelectionManagerTest : TransportTest() {
),
)
)
appSelectionManager.onRestoreSetChosen(backup)
appSelectionManager.onRestoreSetChosen(backup, true)
val initialApps = awaitItem()
// we have 6 real apps (two are hidden) plus system meta item, makes 5