From e4de9e1c41c476da510faa6fde45be12b257a8c4 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 15 Aug 2024 15:46:40 -0300 Subject: [PATCH] Uncheck system apps by default if restore outside of SUW --- .../seedvault/restore/AppSelectionManager.kt | 4 +- .../seedvault/restore/RestoreActivity.kt | 1 + .../seedvault/restore/RestoreViewModel.kt | 3 +- .../restore/AppSelectionManagerTest.kt | 42 +++++++++++++++---- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/AppSelectionManager.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/AppSelectionManager.kt index 40ac98636..993837d7d 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/AppSelectionManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/AppSelectionManager.kt @@ -52,7 +52,7 @@ internal class AppSelectionManager( val selectedAppsFlow = selectedApps.asStateFlow() val selectedAppsLiveData: LiveData = 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) diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreActivity.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreActivity.kt index 8f99db587..d3c5f1012 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreActivity.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreActivity.kt @@ -49,6 +49,7 @@ class RestoreActivity : RequireProvisioningActivity() { if (savedInstanceState == null) { showFragment(RestoreSetFragment()) } + viewModel.isSetupWizard = isSetupWizard } @CallSuper diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt index 22af1365d..ccaca2956 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt @@ -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) } diff --git a/app/src/test/java/com/stevesoltys/seedvault/restore/AppSelectionManagerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/restore/AppSelectionManagerTest.kt index ec7e2019a..5333c1f98 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/restore/AppSelectionManagerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/restore/AppSelectionManagerTest.kt @@ -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