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:
commit
27cda5eba4
4 changed files with 40 additions and 10 deletions
|
@ -52,7 +52,7 @@ internal class AppSelectionManager(
|
||||||
val selectedAppsFlow = selectedApps.asStateFlow()
|
val selectedAppsFlow = selectedApps.asStateFlow()
|
||||||
val selectedAppsLiveData: LiveData<SelectedAppsState> = selectedApps.asLiveData()
|
val selectedAppsLiveData: LiveData<SelectedAppsState> = selectedApps.asLiveData()
|
||||||
|
|
||||||
fun onRestoreSetChosen(restorableBackup: RestorableBackup) {
|
fun onRestoreSetChosen(restorableBackup: RestorableBackup, isSetupWizard: Boolean) {
|
||||||
// filter and sort app items for display
|
// filter and sort app items for display
|
||||||
val items = restorableBackup.packageMetadataMap.mapNotNull { (packageName, metadata) ->
|
val items = restorableBackup.packageMetadataMap.mapNotNull { (packageName, metadata) ->
|
||||||
if (metadata.time == 0L && !metadata.hasApk()) null
|
if (metadata.time == 0L && !metadata.hasApk()) null
|
||||||
|
@ -80,7 +80,7 @@ internal class AppSelectionManager(
|
||||||
system = true,
|
system = true,
|
||||||
name = context.getString(R.string.backup_system_apps),
|
name = context.getString(R.string.backup_system_apps),
|
||||||
),
|
),
|
||||||
selected = true,
|
selected = isSetupWizard,
|
||||||
)
|
)
|
||||||
items.add(0, systemItem)
|
items.add(0, systemItem)
|
||||||
items.addAll(0, systemDataItems)
|
items.addAll(0, systemDataItems)
|
||||||
|
|
|
@ -49,6 +49,7 @@ class RestoreActivity : RequireProvisioningActivity() {
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
showFragment(RestoreSetFragment())
|
showFragment(RestoreSetFragment())
|
||||||
}
|
}
|
||||||
|
viewModel.isSetupWizard = isSetupWizard
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
|
|
|
@ -72,6 +72,7 @@ internal class RestoreViewModel(
|
||||||
RestorableBackupClickListener, SnapshotViewModel {
|
RestorableBackupClickListener, SnapshotViewModel {
|
||||||
|
|
||||||
override val isRestoreOperation = true
|
override val isRestoreOperation = true
|
||||||
|
var isSetupWizard = false
|
||||||
|
|
||||||
private val appSelectionManager =
|
private val appSelectionManager =
|
||||||
AppSelectionManager(app, pluginManager, iconManager, viewModelScope)
|
AppSelectionManager(app, pluginManager, iconManager, viewModelScope)
|
||||||
|
@ -125,7 +126,7 @@ internal class RestoreViewModel(
|
||||||
|
|
||||||
override fun onRestorableBackupClicked(restorableBackup: RestorableBackup) {
|
override fun onRestorableBackupClicked(restorableBackup: RestorableBackup) {
|
||||||
mChosenRestorableBackup.value = restorableBackup
|
mChosenRestorableBackup.value = restorableBackup
|
||||||
appSelectionManager.onRestoreSetChosen(restorableBackup)
|
appSelectionManager.onRestoreSetChosen(restorableBackup, isSetupWizard)
|
||||||
mDisplayFragment.setEvent(SELECT_APPS)
|
mDisplayFragment.setEvent(SELECT_APPS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ internal class AppSelectionManagerTest : TransportTest() {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
appSelectionManager.onRestoreSetChosen(backup)
|
appSelectionManager.onRestoreSetChosen(backup, true)
|
||||||
|
|
||||||
val initialApps = awaitItem()
|
val initialApps = awaitItem()
|
||||||
// only the meta system app item remains
|
// 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()
|
val initialApps = awaitItem()
|
||||||
assertEquals(4, initialApps.apps.size)
|
assertEquals(4, initialApps.apps.size)
|
||||||
|
@ -138,7 +138,7 @@ internal class AppSelectionManagerTest : TransportTest() {
|
||||||
packageName2 to PackageMetadata(time = 42L),
|
packageName2 to PackageMetadata(time = 42L),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
appSelectionManager.onRestoreSetChosen(backup)
|
appSelectionManager.onRestoreSetChosen(backup, true)
|
||||||
|
|
||||||
// first all are selected
|
// first all are selected
|
||||||
val initialApps = awaitItem()
|
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
|
// all apps (except special ones) have an unknown item state initially
|
||||||
val initialApps = awaitItem()
|
val initialApps = awaitItem()
|
||||||
|
@ -232,7 +232,7 @@ internal class AppSelectionManagerTest : TransportTest() {
|
||||||
packageName2 to PackageMetadata(time = 42L),
|
packageName2 to PackageMetadata(time = 42L),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
appSelectionManager.onRestoreSetChosen(backup)
|
appSelectionManager.onRestoreSetChosen(backup, true)
|
||||||
|
|
||||||
val initialApps = awaitItem()
|
val initialApps = awaitItem()
|
||||||
assertEquals(3, initialApps.apps.size)
|
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
|
@Test
|
||||||
fun `@pm@ doesn't get filtered out`() = runTest {
|
fun `@pm@ doesn't get filtered out`() = runTest {
|
||||||
appSelectionManager.selectedAppsFlow.test {
|
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
|
// only system apps meta item in list
|
||||||
val initialApps = awaitItem()
|
val initialApps = awaitItem()
|
||||||
|
@ -385,7 +413,7 @@ internal class AppSelectionManagerTest : TransportTest() {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
appSelectionManager.onRestoreSetChosen(backup)
|
appSelectionManager.onRestoreSetChosen(backup, true)
|
||||||
|
|
||||||
val initialApps = awaitItem()
|
val initialApps = awaitItem()
|
||||||
// we have 6 real apps (two are hidden) plus system meta item, makes 5
|
// we have 6 real apps (two are hidden) plus system meta item, makes 5
|
||||||
|
|
Loading…
Reference in a new issue