From 40d0f5501214ae5f820d0f24ac1ff206de9dce1b Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 28 Aug 2024 13:34:08 -0300 Subject: [PATCH] Show app is in progress before we download APKs --- .../stevesoltys/seedvault/restore/install/ApkRestore.kt | 7 +++++++ .../seedvault/restore/install/ApkBackupRestoreTest.kt | 7 +++++++ .../seedvault/restore/install/ApkRestoreTest.kt | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/install/ApkRestore.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/install/ApkRestore.kt index dc3af875..630e10a9 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/install/ApkRestore.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/install/ApkRestore.kt @@ -153,6 +153,13 @@ internal class ApkRestore( packageName: String, metadata: PackageMetadata, ) { + // show that app is in progress, before we start downloading stuff + mInstallResult.update { + it.update(packageName) { result -> + result.copy(state = IN_PROGRESS) + } + } + // cache the APK and get its hash val (cachedApk, sha256) = cacheApk(backup.version, backup.token, backup.salt, packageName) diff --git a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt index 562766b7..b1bd25ff 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkBackupRestoreTest.kt @@ -194,6 +194,13 @@ internal class ApkBackupRestoreTest : TransportTest() { assertEquals(IN_PROGRESS, it.installResults[packageName]?.state) assertFalse(it.isFinished) } + awaitItem().also { + assertFalse(it.hasFailed) + assertEquals(1, it.total) + assertEquals(1, it.list.size) + assertEquals(IN_PROGRESS, it.installResults[packageName]?.state) + assertFalse(it.isFinished) + } awaitItem().also { assertFalse(it.hasFailed) assertEquals(1, it.total) diff --git a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreTest.kt b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreTest.kt index 8d2548c4..6679be3a 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreTest.kt @@ -46,6 +46,7 @@ import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir @@ -758,6 +759,14 @@ internal class ApkRestoreTest : TransportTest() { } private suspend fun TurbineTestContext.awaitInProgressItem(): InstallResult { + awaitItem().also { item -> + val result = item[packageName] + assertEquals(IN_PROGRESS, result.state) + assertFalse(item.hasFailed) + assertEquals(1, item.total) + assertEquals(1, item.list.size) + assertNull(result.icon) + } val item = awaitItem() // name and icon are available now val result = item[packageName]