Skip to content

Commit

Permalink
Launch stopped apps before test to ensure they get backed up
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed Sep 25, 2024
1 parent d85bc02 commit c924287
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@

package com.stevesoltys.seedvault.e2e.impl

import android.content.Intent
import android.content.Intent.ACTION_MAIN
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
internal class BackupRestoreTest : SeedvaultLargeTest() {

@Test
fun `backup and restore applications`() {
launchStoppedApps()
launchBackupActivity()

if (!keyManager.hasBackupKey()) {
Expand Down Expand Up @@ -58,6 +64,25 @@ internal class BackupRestoreTest : SeedvaultLargeTest() {
}
}

private fun launchStoppedApps() {
packageService.notBackedUpPackages.forEach { packageInfo ->
val i = Intent(ACTION_MAIN).apply {
`package` = packageInfo.packageName
flags = FLAG_ACTIVITY_NEW_TASK
}
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,
Expand Down

0 comments on commit c924287

Please sign in to comment.