Skip to content

Commit

Permalink
Merge pull request #718 from grote/non-suw-restore-uncheck
Browse files Browse the repository at this point in the history
Uncheck system apps by default if restore outside of SUW
  • Loading branch information
grote committed Aug 15, 2024
2 parents b571da7 + e4de9e1 commit 27cda5e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class RestoreActivity : RequireProvisioningActivity() {
if (savedInstanceState == null) {
showFragment(RestoreSetFragment())
}
viewModel.isSetupWizard = isSetupWizard
}

@CallSuper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ internal class RestoreViewModel(
RestorableBackupClickListener, SnapshotViewModel {

override val isRestoreOperation = true
var isSetupWizard = false

private val appSelectionManager =
AppSelectionManager(app, pluginManager, iconManager, viewModelScope)
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -116,7 +116,7 @@ internal class AppSelectionManagerTest : TransportTest() {
),
)
)
appSelectionManager.onRestoreSetChosen(backup)
appSelectionManager.onRestoreSetChosen(backup, true)

val initialApps = awaitItem()
assertEquals(4, initialApps.apps.size)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 27cda5e

Please sign in to comment.