Launch stopped apps before test to ensure they get backed up
This commit is contained in:
parent
f38bed9616
commit
910c68aa52
1 changed files with 25 additions and 0 deletions
|
@ -5,11 +5,15 @@
|
|||
|
||||
package com.stevesoltys.seedvault.e2e.impl
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import android.util.Log
|
||||
import androidx.test.filters.LargeTest
|
||||
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
|
||||
import com.stevesoltys.seedvault.e2e.SeedvaultLargeTest
|
||||
import com.stevesoltys.seedvault.e2e.SeedvaultLargeTestResult
|
||||
import com.stevesoltys.seedvault.metadata.PackageState
|
||||
import com.stevesoltys.seedvault.settings.SettingsActivity
|
||||
import org.junit.Test
|
||||
|
||||
@LargeTest
|
||||
|
@ -17,6 +21,7 @@ internal class BackupRestoreTest : SeedvaultLargeTest() {
|
|||
|
||||
@Test
|
||||
fun `backup and restore applications`() {
|
||||
launchStoppedApps()
|
||||
launchBackupActivity()
|
||||
|
||||
if (!keyManager.hasBackupKey()) {
|
||||
|
@ -58,6 +63,26 @@ internal class BackupRestoreTest : SeedvaultLargeTest() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun launchStoppedApps() {
|
||||
val packageManager = targetContext.packageManager
|
||||
packageService.notBackedUpPackages.forEach { packageInfo ->
|
||||
val i = packageManager.getLaunchIntentForPackage(packageInfo.packageName)?.apply {
|
||||
addFlags(FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
Log.i("TEST", "Launching $i")
|
||||
try {
|
||||
targetContext.startActivity(i)
|
||||
} catch (e: Exception) {
|
||||
Log.e("TEST", "Could not launch activity for ${packageInfo.packageName}", e)
|
||||
}
|
||||
}
|
||||
// at the end launch us again, so we are back to foreground
|
||||
val i = Intent(targetContext, SettingsActivity::class.java).apply {
|
||||
flags = FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
targetContext.startActivity(i)
|
||||
}
|
||||
|
||||
private fun assertValidResults(
|
||||
backup: SeedvaultLargeTestResult,
|
||||
restore: SeedvaultLargeTestResult,
|
||||
|
|
Loading…
Reference in a new issue