From 307ccf57de8086406eab6c2b23bb99dcf8c2a75b Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 17 Sep 2024 10:21:13 -0300 Subject: [PATCH] Move new classes to repo package as they all relate to interacting with the backup repository --- .../backup/KvBackupInstrumentationTest.kt | 2 + .../seedvault/worker/IconManagerTest.kt | 10 ++-- .../java/com/stevesoltys/seedvault/App.kt | 2 + .../seedvault/backend/BackendManager.kt | 2 +- .../seedvault/metadata/Metadata.kt | 2 +- .../backup => repo}/AppBackupManager.kt | 3 +- .../stevesoltys/seedvault/repo/BackupData.kt | 25 +++++++++ .../backup => repo}/BackupReceiver.kt | 19 +------ .../{transport/backup => repo}/BlobCache.kt | 2 +- .../{transport/backup => repo}/BlobCreator.kt | 4 +- .../{transport/restore => repo}/Loader.kt | 44 +--------------- .../seedvault/repo/PaddedInputStream.kt | 51 +++++++++++++++++++ .../{transport/backup => repo}/Padding.kt | 2 +- .../stevesoltys/seedvault/repo/RepoModule.kt | 22 ++++++++ .../backup => repo}/SnapshotCreator.kt | 18 ++----- .../seedvault/repo/SnapshotCreatorFactory.kt | 26 ++++++++++ .../{transport => repo}/SnapshotManager.kt | 5 +- .../seedvault/restore/install/ApkRestore.kt | 4 +- .../transport/backup/BackupCoordinator.kt | 1 + .../transport/backup/BackupModule.kt | 10 ---- .../seedvault/transport/backup/FullBackup.kt | 2 + .../seedvault/transport/backup/KVBackup.kt | 2 + .../transport/restore/FullRestore.kt | 1 + .../seedvault/transport/restore/KVRestore.kt | 1 + .../transport/restore/RestoreCoordinator.kt | 3 +- .../transport/restore/RestoreModule.kt | 1 - .../NotificationBackupObserver.kt | 4 +- .../stevesoltys/seedvault/worker/ApkBackup.kt | 8 +-- .../seedvault/worker/ApkBackupManager.kt | 2 +- .../seedvault/worker/AppBackupWorker.kt | 2 +- .../seedvault/worker/IconManager.kt | 6 +-- .../seedvault/worker/WorkerModule.kt | 2 +- .../backup => repo}/AppBackupManagerTest.kt | 3 +- .../backup => repo}/BackupReceiverTest.kt | 2 +- .../backup => repo}/BlobCacheTest.kt | 2 +- .../backup => repo}/BlobCreatorTest.kt | 3 +- .../{transport/backup => repo}/PaddingTest.kt | 4 +- .../backup => repo}/SnapshotCreatorTest.kt | 3 +- .../SnapshotManagerTest.kt | 4 +- .../restore/install/ApkBackupRestoreTest.kt | 12 ++--- .../restore/install/ApkRestoreTest.kt | 4 +- .../restore/install/ApkRestoreV1Test.kt | 2 +- .../transport/CoordinatorIntegrationTest.kt | 8 +-- .../seedvault/transport/TransportTest.kt | 4 +- .../transport/backup/BackupCoordinatorTest.kt | 2 + .../transport/backup/FullBackupTest.kt | 1 + .../transport/backup/KVBackupTest.kt | 1 + .../transport/restore/FullRestoreTest.kt | 1 + .../transport/restore/KVRestoreTest.kt | 1 + .../transport/restore/KVRestoreV1Test.kt | 1 + .../restore/RestoreCoordinatorTest.kt | 1 + .../restore/RestoreV0IntegrationTest.kt | 1 + .../seedvault/worker/ApkBackupManagerTest.kt | 2 +- .../seedvault/worker/ApkBackupTest.kt | 8 +-- 54 files changed, 210 insertions(+), 148 deletions(-) rename app/src/main/java/com/stevesoltys/seedvault/{transport/backup => repo}/AppBackupManager.kt (97%) create mode 100644 app/src/main/java/com/stevesoltys/seedvault/repo/BackupData.kt rename app/src/main/java/com/stevesoltys/seedvault/{transport/backup => repo}/BackupReceiver.kt (88%) rename app/src/main/java/com/stevesoltys/seedvault/{transport/backup => repo}/BlobCache.kt (99%) rename app/src/main/java/com/stevesoltys/seedvault/{transport/backup => repo}/BlobCreator.kt (96%) rename app/src/main/java/com/stevesoltys/seedvault/{transport/restore => repo}/Loader.kt (77%) create mode 100644 app/src/main/java/com/stevesoltys/seedvault/repo/PaddedInputStream.kt rename app/src/main/java/com/stevesoltys/seedvault/{transport/backup => repo}/Padding.kt (92%) create mode 100644 app/src/main/java/com/stevesoltys/seedvault/repo/RepoModule.kt rename app/src/main/java/com/stevesoltys/seedvault/{transport/backup => repo}/SnapshotCreator.kt (92%) create mode 100644 app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotCreatorFactory.kt rename app/src/main/java/com/stevesoltys/seedvault/{transport => repo}/SnapshotManager.kt (98%) rename app/src/test/java/com/stevesoltys/seedvault/{transport/backup => repo}/AppBackupManagerTest.kt (97%) rename app/src/test/java/com/stevesoltys/seedvault/{transport/backup => repo}/BackupReceiverTest.kt (99%) rename app/src/test/java/com/stevesoltys/seedvault/{transport/backup => repo}/BlobCacheTest.kt (98%) rename app/src/test/java/com/stevesoltys/seedvault/{transport/backup => repo}/BlobCreatorTest.kt (98%) rename app/src/test/java/com/stevesoltys/seedvault/{transport/backup => repo}/PaddingTest.kt (89%) rename app/src/test/java/com/stevesoltys/seedvault/{transport/backup => repo}/SnapshotCreatorTest.kt (98%) rename app/src/test/java/com/stevesoltys/seedvault/{transport => repo}/SnapshotManagerTest.kt (98%) diff --git a/app/src/androidTest/java/com/stevesoltys/seedvault/transport/backup/KvBackupInstrumentationTest.kt b/app/src/androidTest/java/com/stevesoltys/seedvault/transport/backup/KvBackupInstrumentationTest.kt index a5bf58b0..5fd73ac0 100644 --- a/app/src/androidTest/java/com/stevesoltys/seedvault/transport/backup/KvBackupInstrumentationTest.kt +++ b/app/src/androidTest/java/com/stevesoltys/seedvault/transport/backup/KvBackupInstrumentationTest.kt @@ -11,6 +11,8 @@ import android.content.pm.PackageInfo import android.os.ParcelFileDescriptor import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest +import com.stevesoltys.seedvault.repo.BackupData +import com.stevesoltys.seedvault.repo.BackupReceiver import com.stevesoltys.seedvault.settings.SettingsManager import io.mockk.CapturingSlot import io.mockk.Runs diff --git a/app/src/androidTest/java/com/stevesoltys/seedvault/worker/IconManagerTest.kt b/app/src/androidTest/java/com/stevesoltys/seedvault/worker/IconManagerTest.kt index 8ca84c63..a11321f3 100644 --- a/app/src/androidTest/java/com/stevesoltys/seedvault/worker/IconManagerTest.kt +++ b/app/src/androidTest/java/com/stevesoltys/seedvault/worker/IconManagerTest.kt @@ -10,12 +10,12 @@ import androidx.test.filters.MediumTest import androidx.test.platform.app.InstrumentationRegistry import com.google.protobuf.ByteString import com.stevesoltys.seedvault.proto.SnapshotKt.blob -import com.stevesoltys.seedvault.transport.backup.AppBackupManager -import com.stevesoltys.seedvault.transport.backup.BackupData -import com.stevesoltys.seedvault.transport.backup.BackupReceiver +import com.stevesoltys.seedvault.repo.AppBackupManager +import com.stevesoltys.seedvault.repo.BackupData +import com.stevesoltys.seedvault.repo.BackupReceiver import com.stevesoltys.seedvault.transport.backup.PackageService -import com.stevesoltys.seedvault.transport.backup.SnapshotCreatorFactory -import com.stevesoltys.seedvault.transport.restore.Loader +import com.stevesoltys.seedvault.repo.SnapshotCreatorFactory +import com.stevesoltys.seedvault.repo.Loader import io.mockk.Runs import io.mockk.coEvery import io.mockk.every diff --git a/app/src/main/java/com/stevesoltys/seedvault/App.kt b/app/src/main/java/com/stevesoltys/seedvault/App.kt index 57ac6b34..7fbfd358 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/App.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/App.kt @@ -30,6 +30,7 @@ import com.stevesoltys.seedvault.backend.webdav.storagePluginModuleWebDav import com.stevesoltys.seedvault.crypto.cryptoModule import com.stevesoltys.seedvault.header.headerModule import com.stevesoltys.seedvault.metadata.metadataModule +import com.stevesoltys.seedvault.repo.repoModule import com.stevesoltys.seedvault.restore.install.installModule import com.stevesoltys.seedvault.restore.restoreUiModule import com.stevesoltys.seedvault.settings.AppListRetriever @@ -147,6 +148,7 @@ open class App : Application() { restoreModule, installModule, storageModule, + repoModule, workerModule, restoreUiModule, appModule diff --git a/app/src/main/java/com/stevesoltys/seedvault/backend/BackendManager.kt b/app/src/main/java/com/stevesoltys/seedvault/backend/BackendManager.kt index 89b2bb8f..95fbbeb8 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/backend/BackendManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/backend/BackendManager.kt @@ -12,7 +12,7 @@ import com.stevesoltys.seedvault.getStorageContext import com.stevesoltys.seedvault.permitDiskReads import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.settings.StoragePluginType -import com.stevesoltys.seedvault.transport.backup.BlobCache +import com.stevesoltys.seedvault.repo.BlobCache import org.calyxos.seedvault.core.backends.Backend import org.calyxos.seedvault.core.backends.BackendFactory import org.calyxos.seedvault.core.backends.BackendProperties diff --git a/app/src/main/java/com/stevesoltys/seedvault/metadata/Metadata.kt b/app/src/main/java/com/stevesoltys/seedvault/metadata/Metadata.kt index d1362e1d..153b6098 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/metadata/Metadata.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/metadata/Metadata.kt @@ -12,7 +12,7 @@ import com.stevesoltys.seedvault.encodeBase64 import com.stevesoltys.seedvault.header.VERSION import com.stevesoltys.seedvault.metadata.PackageState.UNKNOWN_ERROR import com.stevesoltys.seedvault.proto.Snapshot -import com.stevesoltys.seedvault.transport.backup.hexFromProto +import com.stevesoltys.seedvault.repo.hexFromProto import com.stevesoltys.seedvault.worker.BASE_SPLIT import org.calyxos.backup.storage.crypto.StreamCrypto.toByteArray import java.nio.ByteBuffer diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/AppBackupManager.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/AppBackupManager.kt similarity index 97% rename from app/src/main/java/com/stevesoltys/seedvault/transport/backup/AppBackupManager.kt rename to app/src/main/java/com/stevesoltys/seedvault/repo/AppBackupManager.kt index d42fa27e..1e7e0781 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/AppBackupManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/AppBackupManager.kt @@ -3,14 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import androidx.annotation.WorkerThread import com.stevesoltys.seedvault.MemoryLogger import com.stevesoltys.seedvault.backend.BackendManager import com.stevesoltys.seedvault.crypto.Crypto import com.stevesoltys.seedvault.settings.SettingsManager -import com.stevesoltys.seedvault.transport.SnapshotManager import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.delay import org.calyxos.seedvault.core.backends.AppBackupFileType.Blob diff --git a/app/src/main/java/com/stevesoltys/seedvault/repo/BackupData.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/BackupData.kt new file mode 100644 index 00000000..40a0ce91 --- /dev/null +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/BackupData.kt @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: 2024 The Calyx Institute + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.stevesoltys.seedvault.repo + +import com.stevesoltys.seedvault.proto.Snapshot.Blob + +/** + * Essential metadata returned when storing backup data. + * + * @param chunkIds an ordered(!) list of the chunk IDs required to re-assemble the backup data. + * @param blobMap a mapping from chunk ID to [Blob] on the backend. + * Needed for fetching blobs from the backend for re-assembly. + */ +data class BackupData( + val chunkIds: List, + val blobMap: Map, +) { + /** + * The uncompressed plaintext size of all blobs. + */ + val size get() = blobMap.values.sumOf { it.uncompressedLength }.toLong() +} diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupReceiver.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/BackupReceiver.kt similarity index 88% rename from app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupReceiver.kt rename to app/src/main/java/com/stevesoltys/seedvault/repo/BackupReceiver.kt index 6f15e895..40759ed4 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupReceiver.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/BackupReceiver.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import androidx.annotation.WorkerThread import com.stevesoltys.seedvault.crypto.Crypto @@ -15,23 +15,6 @@ import org.calyxos.seedvault.core.toHexString import java.io.IOException import java.io.InputStream -/** - * Essential metadata returned when storing backup data. - * - * @param chunkIds an ordered(!) list of the chunk IDs required to re-assemble the backup data. - * @param blobMap a mapping from chunk ID to [Blob] on the backend. - * Needed for fetching blobs from the backend for re-assembly. - */ -data class BackupData( - val chunkIds: List, - val blobMap: Map, -) { - /** - * The uncompressed plaintext size of all blobs. - */ - val size get() = blobMap.values.sumOf { it.uncompressedLength }.toLong() -} - /** * The single point for receiving data for backup. * Data received will get split into smaller chunks, if needed. diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BlobCache.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/BlobCache.kt similarity index 99% rename from app/src/main/java/com/stevesoltys/seedvault/transport/backup/BlobCache.kt rename to app/src/main/java/com/stevesoltys/seedvault/repo/BlobCache.kt index 28e5c8e9..66204289 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BlobCache.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/BlobCache.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import android.content.Context import android.content.Context.MODE_APPEND diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BlobCreator.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/BlobCreator.kt similarity index 96% rename from app/src/main/java/com/stevesoltys/seedvault/transport/backup/BlobCreator.kt rename to app/src/main/java/com/stevesoltys/seedvault/repo/BlobCreator.kt index c75249cb..ea271951 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BlobCreator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/BlobCreator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import androidx.annotation.WorkerThread import com.github.luben.zstd.ZstdOutputStream @@ -14,7 +14,7 @@ import com.stevesoltys.seedvault.crypto.Crypto import com.stevesoltys.seedvault.header.VERSION import com.stevesoltys.seedvault.proto.Snapshot.Blob import com.stevesoltys.seedvault.proto.SnapshotKt.blob -import com.stevesoltys.seedvault.transport.backup.Padding.getPadTo +import com.stevesoltys.seedvault.repo.Padding.getPadTo import okio.Buffer import okio.buffer import okio.sink diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/Loader.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/Loader.kt similarity index 77% rename from app/src/main/java/com/stevesoltys/seedvault/transport/restore/Loader.kt rename to app/src/main/java/com/stevesoltys/seedvault/repo/Loader.kt index 0c295d9f..45a6745a 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/Loader.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/Loader.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.restore +package com.stevesoltys.seedvault.repo import com.android.internal.R.attr.handle import com.github.luben.zstd.ZstdInputStream @@ -17,11 +17,8 @@ import org.calyxos.seedvault.core.backends.AppBackupFileType import org.calyxos.seedvault.core.toHexString import java.io.ByteArrayInputStream import java.io.File -import java.io.FilterInputStream -import java.io.IOException import java.io.InputStream import java.io.SequenceInputStream -import java.nio.ByteBuffer import java.security.GeneralSecurityException import java.util.Enumeration @@ -107,42 +104,3 @@ internal class Loader( } } - -private class PaddedInputStream(inputStream: InputStream) : FilterInputStream(inputStream) { - - val size: Int - var bytesRead: Int = 0 - - init { - val sizeBytes = ByteArray(4) - val bytesRead = inputStream.read(sizeBytes) - if (bytesRead != 4) { - throw IOException("Could not read padding size: ${sizeBytes.toHexString()}") - } - size = ByteBuffer.wrap(sizeBytes).getInt() - } - - override fun read(): Int { - if (bytesRead >= size) return -1 - return getReadBytes(super.read()) - } - - override fun read(b: ByteArray, off: Int, len: Int): Int { - if (bytesRead >= size) return -1 - if (bytesRead + len >= size) { - return getReadBytes(super.read(b, off, size - bytesRead)) - } - return getReadBytes(super.read(b, off, len)) - } - - override fun available(): Int { - return size - bytesRead - } - - private fun getReadBytes(read: Int): Int { - if (read == -1) return -1 - bytesRead += read - if (bytesRead > size) return -1 - return read - } -} diff --git a/app/src/main/java/com/stevesoltys/seedvault/repo/PaddedInputStream.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/PaddedInputStream.kt new file mode 100644 index 00000000..50e6312e --- /dev/null +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/PaddedInputStream.kt @@ -0,0 +1,51 @@ +/* + * SPDX-FileCopyrightText: 2024 The Calyx Institute + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.stevesoltys.seedvault.repo + +import org.calyxos.seedvault.core.toHexString +import java.io.FilterInputStream +import java.io.IOException +import java.io.InputStream +import java.nio.ByteBuffer + +internal class PaddedInputStream(inputStream: InputStream) : FilterInputStream(inputStream) { + + private val size: Int + private var bytesRead: Int = 0 + + init { + val sizeBytes = ByteArray(4) + val bytesRead = inputStream.read(sizeBytes) + if (bytesRead != 4) { + throw IOException("Could not read padding size: ${sizeBytes.toHexString()}") + } + size = ByteBuffer.wrap(sizeBytes).getInt() + } + + override fun read(): Int { + if (bytesRead >= size) return -1 + return getReadBytes(super.read()) + } + + override fun read(b: ByteArray, off: Int, len: Int): Int { + if (bytesRead >= size) return -1 + if (bytesRead + len >= size) { + return getReadBytes(super.read(b, off, size - bytesRead)) + } + return getReadBytes(super.read(b, off, len)) + } + + override fun available(): Int { + return size - bytesRead + } + + private fun getReadBytes(read: Int): Int { + if (read == -1) return -1 + bytesRead += read + if (bytesRead > size) return -1 + return read + } +} diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/Padding.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/Padding.kt similarity index 92% rename from app/src/main/java/com/stevesoltys/seedvault/transport/backup/Padding.kt rename to app/src/main/java/com/stevesoltys/seedvault/repo/Padding.kt index a868c24e..cf1f8bd4 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/Padding.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/Padding.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import kotlin.math.floor import kotlin.math.log2 diff --git a/app/src/main/java/com/stevesoltys/seedvault/repo/RepoModule.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/RepoModule.kt new file mode 100644 index 00000000..305198b2 --- /dev/null +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/RepoModule.kt @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: 2024 The Calyx Institute + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.stevesoltys.seedvault.repo + +import org.koin.android.ext.koin.androidContext +import org.koin.dsl.module +import java.io.File + +val repoModule = module { + single { BackupReceiver(get(), get(), get()) } + single { BlobCache(androidContext()) } + single { BlobCreator(get(), get()) } + single { Loader(get(), get()) } + single { + val snapshotFolder = File(androidContext().filesDir, FOLDER_SNAPSHOTS) + SnapshotManager(snapshotFolder, get(), get(), get()) + } + factory { SnapshotCreatorFactory(androidContext(), get(), get(), get(), get()) } +} diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/SnapshotCreator.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotCreator.kt similarity index 92% rename from app/src/main/java/com/stevesoltys/seedvault/transport/backup/SnapshotCreator.kt rename to app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotCreator.kt index be8c6f21..15ee5f87 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/SnapshotCreator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotCreator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import android.Manifest import android.annotation.SuppressLint @@ -24,24 +24,12 @@ import com.stevesoltys.seedvault.proto.Snapshot.Apk import com.stevesoltys.seedvault.proto.Snapshot.App import com.stevesoltys.seedvault.proto.Snapshot.Blob import com.stevesoltys.seedvault.settings.SettingsManager +import com.stevesoltys.seedvault.transport.backup.PackageService +import com.stevesoltys.seedvault.transport.backup.isSystemApp import io.github.oshai.kotlinlogging.KotlinLogging import org.calyxos.seedvault.core.backends.AppBackupFileType import org.calyxos.seedvault.core.toHexString -/** - * Creates a new [SnapshotCreator], because one is only valid for a single backup run. - */ -internal class SnapshotCreatorFactory( - private val context: Context, - private val clock: Clock, - private val packageService: PackageService, - private val settingsManager: SettingsManager, - private val metadataManager: MetadataManager, -) { - fun createSnapshotCreator() = - SnapshotCreator(context, clock, packageService, settingsManager, metadataManager) -} - /** * Assembles snapshot information over the course of a single backup run * and creates a [Snapshot] object in the end by calling [finalizeSnapshot]. diff --git a/app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotCreatorFactory.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotCreatorFactory.kt new file mode 100644 index 00000000..905dc9ad --- /dev/null +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotCreatorFactory.kt @@ -0,0 +1,26 @@ +/* + * SPDX-FileCopyrightText: 2024 The Calyx Institute + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.stevesoltys.seedvault.repo + +import android.content.Context +import com.stevesoltys.seedvault.Clock +import com.stevesoltys.seedvault.metadata.MetadataManager +import com.stevesoltys.seedvault.settings.SettingsManager +import com.stevesoltys.seedvault.transport.backup.PackageService + +/** + * Creates a new [SnapshotCreator], because one is only valid for a single backup run. + */ +internal class SnapshotCreatorFactory( + private val context: Context, + private val clock: Clock, + private val packageService: PackageService, + private val settingsManager: SettingsManager, + private val metadataManager: MetadataManager, +) { + fun createSnapshotCreator() = + SnapshotCreator(context, clock, packageService, settingsManager, metadataManager) +} diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/SnapshotManager.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotManager.kt similarity index 98% rename from app/src/main/java/com/stevesoltys/seedvault/transport/SnapshotManager.kt rename to app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotManager.kt index 5a3cd002..f3946045 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/SnapshotManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/SnapshotManager.kt @@ -3,14 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport +package com.stevesoltys.seedvault.repo import com.github.luben.zstd.ZstdOutputStream import com.stevesoltys.seedvault.backend.BackendManager import com.stevesoltys.seedvault.crypto.Crypto import com.stevesoltys.seedvault.header.VERSION import com.stevesoltys.seedvault.proto.Snapshot -import com.stevesoltys.seedvault.transport.restore.Loader import io.github.oshai.kotlinlogging.KotlinLogging import org.calyxos.seedvault.core.backends.AppBackupFileType import org.calyxos.seedvault.core.toHexString @@ -19,6 +18,8 @@ import java.io.File import java.io.IOException import java.nio.ByteBuffer +internal const val FOLDER_SNAPSHOTS = "snapshots" + /** * Manages interactions with snapshots, such as loading, saving and removing them. * Also keeps a reference to the [latestSnapshot] that holds important re-usable data. 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 99f0e372..b6ceed1d 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 @@ -27,9 +27,9 @@ import com.stevesoltys.seedvault.restore.install.ApkInstallState.FAILED_SYSTEM_A import com.stevesoltys.seedvault.restore.install.ApkInstallState.IN_PROGRESS import com.stevesoltys.seedvault.restore.install.ApkInstallState.QUEUED import com.stevesoltys.seedvault.restore.install.ApkInstallState.SUCCEEDED -import com.stevesoltys.seedvault.transport.backup.getBlobHandles +import com.stevesoltys.seedvault.repo.getBlobHandles import com.stevesoltys.seedvault.transport.backup.isSystemApp -import com.stevesoltys.seedvault.transport.restore.Loader +import com.stevesoltys.seedvault.repo.Loader import com.stevesoltys.seedvault.transport.restore.RestorableBackup import com.stevesoltys.seedvault.worker.hashSignature import kotlinx.coroutines.TimeoutCancellationException diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt index a4a7312b..a67494ce 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt @@ -29,6 +29,7 @@ import com.stevesoltys.seedvault.metadata.PackageState import com.stevesoltys.seedvault.metadata.PackageState.NO_DATA import com.stevesoltys.seedvault.metadata.PackageState.QUOTA_EXCEEDED import com.stevesoltys.seedvault.metadata.PackageState.UNKNOWN_ERROR +import com.stevesoltys.seedvault.repo.AppBackupManager import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import java.io.IOException diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt index ca49095d..8bd7bd54 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt @@ -5,21 +5,11 @@ package com.stevesoltys.seedvault.transport.backup -import com.stevesoltys.seedvault.transport.SnapshotManager import org.koin.android.ext.koin.androidContext import org.koin.dsl.module -import java.io.File val backupModule = module { single { BackupInitializer(get()) } - single { BackupReceiver(get(), get(), get()) } - single { BlobCache(androidContext()) } - single { BlobCreator(get(), get()) } - single { - val snapshotFolder = File(androidContext().filesDir, "snapshots") - SnapshotManager(snapshotFolder, get(), get(), get()) - } - single { SnapshotCreatorFactory(androidContext(), get(), get(), get(), get()) } single { InputFactory() } single { PackageService( diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt index 3ecc0258..d645fe35 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt @@ -14,6 +14,8 @@ import android.content.pm.PackageInfo import android.os.ParcelFileDescriptor import android.util.Log import com.stevesoltys.seedvault.backend.isOutOfSpace +import com.stevesoltys.seedvault.repo.BackupData +import com.stevesoltys.seedvault.repo.BackupReceiver import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import java.io.Closeable diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt index 0a27cdf6..6a7ad05b 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt @@ -14,6 +14,8 @@ import android.app.backup.BackupTransport.TRANSPORT_OK import android.content.pm.PackageInfo import android.os.ParcelFileDescriptor import android.util.Log +import com.stevesoltys.seedvault.repo.BackupData +import com.stevesoltys.seedvault.repo.BackupReceiver import com.stevesoltys.seedvault.settings.SettingsManager import java.io.IOException diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/FullRestore.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/FullRestore.kt index 4377de6c..a5240362 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/FullRestore.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/FullRestore.kt @@ -19,6 +19,7 @@ import com.stevesoltys.seedvault.header.HeaderReader import com.stevesoltys.seedvault.header.MAX_SEGMENT_LENGTH import com.stevesoltys.seedvault.header.UnsupportedVersionException import com.stevesoltys.seedvault.header.getADForFull +import com.stevesoltys.seedvault.repo.Loader import libcore.io.IoUtils.closeQuietly import org.calyxos.seedvault.core.backends.AppBackupFileType.Blob import org.calyxos.seedvault.core.backends.LegacyAppBackupFile diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/KVRestore.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/KVRestore.kt index 127ab067..5b645e11 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/KVRestore.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/KVRestore.kt @@ -21,6 +21,7 @@ import com.stevesoltys.seedvault.decodeBase64 import com.stevesoltys.seedvault.header.HeaderReader import com.stevesoltys.seedvault.header.UnsupportedVersionException import com.stevesoltys.seedvault.header.getADForKV +import com.stevesoltys.seedvault.repo.Loader import com.stevesoltys.seedvault.transport.backup.KVDb import com.stevesoltys.seedvault.transport.backup.KvDbManager import libcore.io.IoUtils.closeQuietly diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinator.kt index a6b29bff..f6d68018 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinator.kt @@ -27,10 +27,11 @@ import com.stevesoltys.seedvault.metadata.DecryptionFailedException import com.stevesoltys.seedvault.metadata.MetadataManager import com.stevesoltys.seedvault.metadata.MetadataReader import com.stevesoltys.seedvault.proto.Snapshot +import com.stevesoltys.seedvault.repo.Loader import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.transport.D2D_TRANSPORT_FLAGS import com.stevesoltys.seedvault.transport.DEFAULT_TRANSPORT_FLAGS -import com.stevesoltys.seedvault.transport.backup.getBlobHandles +import com.stevesoltys.seedvault.repo.getBlobHandles import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import org.calyxos.seedvault.core.backends.AppBackupFileType import org.calyxos.seedvault.core.backends.Backend diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreModule.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreModule.kt index b786064b..151a8b58 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreModule.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreModule.kt @@ -10,7 +10,6 @@ import org.koin.dsl.module val restoreModule = module { single { OutputFactory() } - single { Loader(get(), get()) } single { KVRestore(get(), get(), get(), get(), get(), get(), get()) } single { FullRestore(get(), get(), get(), get(), get(), get()) } single { diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt index 8296887c..4e7a5667 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt @@ -20,9 +20,9 @@ import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.metadata.MetadataManager import com.stevesoltys.seedvault.settings.SettingsManager -import com.stevesoltys.seedvault.transport.backup.AppBackupManager +import com.stevesoltys.seedvault.repo.AppBackupManager import com.stevesoltys.seedvault.transport.backup.PackageService -import com.stevesoltys.seedvault.transport.backup.hexFromProto +import com.stevesoltys.seedvault.repo.hexFromProto import com.stevesoltys.seedvault.worker.BackupRequester import kotlinx.coroutines.runBlocking import org.koin.core.component.KoinComponent diff --git a/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackup.kt index f1d45489..120f66c3 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackup.kt @@ -18,10 +18,10 @@ import com.stevesoltys.seedvault.proto.Snapshot.Apk import com.stevesoltys.seedvault.proto.Snapshot.Blob import com.stevesoltys.seedvault.proto.SnapshotKt.split import com.stevesoltys.seedvault.settings.SettingsManager -import com.stevesoltys.seedvault.transport.backup.AppBackupManager -import com.stevesoltys.seedvault.transport.backup.BackupReceiver -import com.stevesoltys.seedvault.transport.backup.forProto -import com.stevesoltys.seedvault.transport.backup.hexFromProto +import com.stevesoltys.seedvault.repo.AppBackupManager +import com.stevesoltys.seedvault.repo.BackupReceiver +import com.stevesoltys.seedvault.repo.forProto +import com.stevesoltys.seedvault.repo.hexFromProto import com.stevesoltys.seedvault.transport.backup.isNotUpdatedSystemApp import com.stevesoltys.seedvault.transport.backup.isTestOnly import org.calyxos.seedvault.core.toHexString diff --git a/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt b/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt index ef5ea76d..7f12415e 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt @@ -13,7 +13,7 @@ import com.stevesoltys.seedvault.metadata.MetadataManager import com.stevesoltys.seedvault.metadata.PackageState.NOT_ALLOWED import com.stevesoltys.seedvault.metadata.PackageState.WAS_STOPPED import com.stevesoltys.seedvault.settings.SettingsManager -import com.stevesoltys.seedvault.transport.SnapshotManager +import com.stevesoltys.seedvault.repo.SnapshotManager import com.stevesoltys.seedvault.transport.backup.PackageService import com.stevesoltys.seedvault.transport.backup.isStopped import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager diff --git a/app/src/main/java/com/stevesoltys/seedvault/worker/AppBackupWorker.kt b/app/src/main/java/com/stevesoltys/seedvault/worker/AppBackupWorker.kt index 985604a6..f2cc6c4e 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/worker/AppBackupWorker.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/worker/AppBackupWorker.kt @@ -25,7 +25,7 @@ import androidx.work.WorkerParameters import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.backend.BackendManager import com.stevesoltys.seedvault.settings.SettingsManager -import com.stevesoltys.seedvault.transport.backup.AppBackupManager +import com.stevesoltys.seedvault.repo.AppBackupManager import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import com.stevesoltys.seedvault.ui.notification.NOTIFICATION_ID_OBSERVER import org.koin.core.component.KoinComponent diff --git a/app/src/main/java/com/stevesoltys/seedvault/worker/IconManager.kt b/app/src/main/java/com/stevesoltys/seedvault/worker/IconManager.kt index 44e4ea9d..fc1ffe5c 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/worker/IconManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/worker/IconManager.kt @@ -18,10 +18,10 @@ import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.crypto.Crypto import com.stevesoltys.seedvault.crypto.TYPE_ICONS import com.stevesoltys.seedvault.proto.Snapshot -import com.stevesoltys.seedvault.transport.backup.AppBackupManager -import com.stevesoltys.seedvault.transport.backup.BackupReceiver +import com.stevesoltys.seedvault.repo.AppBackupManager +import com.stevesoltys.seedvault.repo.BackupReceiver import com.stevesoltys.seedvault.transport.backup.PackageService -import com.stevesoltys.seedvault.transport.restore.Loader +import com.stevesoltys.seedvault.repo.Loader import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.calyxos.backup.storage.crypto.StreamCrypto.toByteArray diff --git a/app/src/main/java/com/stevesoltys/seedvault/worker/WorkerModule.kt b/app/src/main/java/com/stevesoltys/seedvault/worker/WorkerModule.kt index 2a74cf3a..768822f7 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/worker/WorkerModule.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/worker/WorkerModule.kt @@ -5,7 +5,7 @@ package com.stevesoltys.seedvault.worker -import com.stevesoltys.seedvault.transport.backup.AppBackupManager +import com.stevesoltys.seedvault.repo.AppBackupManager import org.koin.android.ext.koin.androidContext import org.koin.dsl.module diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/AppBackupManagerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/repo/AppBackupManagerTest.kt similarity index 97% rename from app/src/test/java/com/stevesoltys/seedvault/transport/backup/AppBackupManagerTest.kt rename to app/src/test/java/com/stevesoltys/seedvault/repo/AppBackupManagerTest.kt index d7913d4b..6ceda99c 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/AppBackupManagerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/repo/AppBackupManagerTest.kt @@ -3,10 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import com.stevesoltys.seedvault.backend.BackendManager -import com.stevesoltys.seedvault.transport.SnapshotManager import com.stevesoltys.seedvault.transport.TransportTest import io.mockk.Runs import io.mockk.andThenJust diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupReceiverTest.kt b/app/src/test/java/com/stevesoltys/seedvault/repo/BackupReceiverTest.kt similarity index 99% rename from app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupReceiverTest.kt rename to app/src/test/java/com/stevesoltys/seedvault/repo/BackupReceiverTest.kt index 9c7af8a3..d7f72f4a 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupReceiverTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/repo/BackupReceiverTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import com.stevesoltys.seedvault.getRandomByteArray import com.stevesoltys.seedvault.proto.Snapshot diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BlobCacheTest.kt b/app/src/test/java/com/stevesoltys/seedvault/repo/BlobCacheTest.kt similarity index 98% rename from app/src/test/java/com/stevesoltys/seedvault/transport/backup/BlobCacheTest.kt rename to app/src/test/java/com/stevesoltys/seedvault/repo/BlobCacheTest.kt index 5e489316..7d91bdff 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BlobCacheTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/repo/BlobCacheTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import android.content.Context import com.stevesoltys.seedvault.transport.TransportTest diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BlobCreatorTest.kt b/app/src/test/java/com/stevesoltys/seedvault/repo/BlobCreatorTest.kt similarity index 98% rename from app/src/test/java/com/stevesoltys/seedvault/transport/backup/BlobCreatorTest.kt rename to app/src/test/java/com/stevesoltys/seedvault/repo/BlobCreatorTest.kt index 9aea051e..86ad6334 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BlobCreatorTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/repo/BlobCreatorTest.kt @@ -3,12 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import com.stevesoltys.seedvault.backend.BackendManager import com.stevesoltys.seedvault.getRandomByteArray import com.stevesoltys.seedvault.transport.TransportTest -import com.stevesoltys.seedvault.transport.restore.Loader import io.mockk.coEvery import io.mockk.every import io.mockk.mockk diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/PaddingTest.kt b/app/src/test/java/com/stevesoltys/seedvault/repo/PaddingTest.kt similarity index 89% rename from app/src/test/java/com/stevesoltys/seedvault/transport/backup/PaddingTest.kt rename to app/src/test/java/com/stevesoltys/seedvault/repo/PaddingTest.kt index 644e4d6f..2f7cf16e 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/PaddingTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/repo/PaddingTest.kt @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo -import com.stevesoltys.seedvault.transport.backup.Padding.getPadTo +import com.stevesoltys.seedvault.repo.Padding.getPadTo import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/SnapshotCreatorTest.kt b/app/src/test/java/com/stevesoltys/seedvault/repo/SnapshotCreatorTest.kt similarity index 98% rename from app/src/test/java/com/stevesoltys/seedvault/transport/backup/SnapshotCreatorTest.kt rename to app/src/test/java/com/stevesoltys/seedvault/repo/SnapshotCreatorTest.kt index 720cd522..413c14cc 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/SnapshotCreatorTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/repo/SnapshotCreatorTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport.backup +package com.stevesoltys.seedvault.repo import android.content.Context import android.content.pm.ActivityInfo @@ -17,6 +17,7 @@ import com.stevesoltys.seedvault.header.VERSION import com.stevesoltys.seedvault.metadata.BackupType import com.stevesoltys.seedvault.proto.Snapshot import com.stevesoltys.seedvault.transport.TransportTest +import com.stevesoltys.seedvault.transport.backup.PackageService import io.mockk.Runs import io.mockk.every import io.mockk.just diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/SnapshotManagerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/repo/SnapshotManagerTest.kt similarity index 98% rename from app/src/test/java/com/stevesoltys/seedvault/transport/SnapshotManagerTest.kt rename to app/src/test/java/com/stevesoltys/seedvault/repo/SnapshotManagerTest.kt index 1c441928..960f9125 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/SnapshotManagerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/repo/SnapshotManagerTest.kt @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package com.stevesoltys.seedvault.transport +package com.stevesoltys.seedvault.repo import com.stevesoltys.seedvault.backend.BackendManager import com.stevesoltys.seedvault.proto.snapshot -import com.stevesoltys.seedvault.transport.restore.Loader +import com.stevesoltys.seedvault.transport.TransportTest import io.mockk.Runs import io.mockk.coEvery import io.mockk.coVerify 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 7456f0b9..1e291836 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 @@ -25,13 +25,13 @@ import com.stevesoltys.seedvault.proto.Snapshot import com.stevesoltys.seedvault.restore.install.ApkInstallState.IN_PROGRESS import com.stevesoltys.seedvault.restore.install.ApkInstallState.QUEUED import com.stevesoltys.seedvault.restore.install.ApkInstallState.SUCCEEDED -import com.stevesoltys.seedvault.transport.SnapshotManager +import com.stevesoltys.seedvault.repo.SnapshotManager import com.stevesoltys.seedvault.transport.TransportTest -import com.stevesoltys.seedvault.transport.backup.AppBackupManager -import com.stevesoltys.seedvault.transport.backup.BackupReceiver -import com.stevesoltys.seedvault.transport.backup.SnapshotCreator -import com.stevesoltys.seedvault.transport.backup.hexFromProto -import com.stevesoltys.seedvault.transport.restore.Loader +import com.stevesoltys.seedvault.repo.AppBackupManager +import com.stevesoltys.seedvault.repo.BackupReceiver +import com.stevesoltys.seedvault.repo.SnapshotCreator +import com.stevesoltys.seedvault.repo.hexFromProto +import com.stevesoltys.seedvault.repo.Loader import com.stevesoltys.seedvault.transport.restore.RestorableBackup import com.stevesoltys.seedvault.worker.ApkBackup import io.mockk.Runs 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 89501a12..13f446de 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 @@ -36,8 +36,8 @@ import com.stevesoltys.seedvault.restore.install.ApkInstallState.IN_PROGRESS import com.stevesoltys.seedvault.restore.install.ApkInstallState.QUEUED import com.stevesoltys.seedvault.restore.install.ApkInstallState.SUCCEEDED import com.stevesoltys.seedvault.transport.TransportTest -import com.stevesoltys.seedvault.transport.backup.hexFromProto -import com.stevesoltys.seedvault.transport.restore.Loader +import com.stevesoltys.seedvault.repo.hexFromProto +import com.stevesoltys.seedvault.repo.Loader import io.mockk.Runs import io.mockk.coEvery import io.mockk.every diff --git a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreV1Test.kt b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreV1Test.kt index 3abfca1d..82c40490 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreV1Test.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/restore/install/ApkRestoreV1Test.kt @@ -33,7 +33,7 @@ import com.stevesoltys.seedvault.restore.install.ApkInstallState.IN_PROGRESS import com.stevesoltys.seedvault.restore.install.ApkInstallState.QUEUED import com.stevesoltys.seedvault.restore.install.ApkInstallState.SUCCEEDED import com.stevesoltys.seedvault.transport.TransportTest -import com.stevesoltys.seedvault.transport.restore.Loader +import com.stevesoltys.seedvault.repo.Loader import io.mockk.Runs import io.mockk.coEvery import io.mockk.every diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt index c4c2cc57..ffc0d156 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/CoordinatorIntegrationTest.kt @@ -22,18 +22,18 @@ import com.stevesoltys.seedvault.header.MAX_SEGMENT_CLEARTEXT_LENGTH import com.stevesoltys.seedvault.metadata.BackupType import com.stevesoltys.seedvault.metadata.MetadataReaderImpl import com.stevesoltys.seedvault.metadata.PackageMetadata -import com.stevesoltys.seedvault.transport.backup.AppBackupManager +import com.stevesoltys.seedvault.repo.AppBackupManager +import com.stevesoltys.seedvault.repo.BackupReceiver +import com.stevesoltys.seedvault.repo.Loader +import com.stevesoltys.seedvault.repo.SnapshotCreator import com.stevesoltys.seedvault.transport.backup.BackupCoordinator -import com.stevesoltys.seedvault.transport.backup.BackupReceiver import com.stevesoltys.seedvault.transport.backup.FullBackup import com.stevesoltys.seedvault.transport.backup.InputFactory import com.stevesoltys.seedvault.transport.backup.KVBackup import com.stevesoltys.seedvault.transport.backup.PackageService -import com.stevesoltys.seedvault.transport.backup.SnapshotCreator import com.stevesoltys.seedvault.transport.backup.TestKvDbManager import com.stevesoltys.seedvault.transport.restore.FullRestore import com.stevesoltys.seedvault.transport.restore.KVRestore -import com.stevesoltys.seedvault.transport.restore.Loader import com.stevesoltys.seedvault.transport.restore.OutputFactory import com.stevesoltys.seedvault.transport.restore.RestorableBackup import com.stevesoltys.seedvault.transport.restore.RestoreCoordinator diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt index 2ab54e8d..6ebd3b60 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/TransportTest.kt @@ -30,9 +30,9 @@ import com.stevesoltys.seedvault.proto.SnapshotKt import com.stevesoltys.seedvault.proto.SnapshotKt.blob import com.stevesoltys.seedvault.proto.SnapshotKt.split import com.stevesoltys.seedvault.proto.snapshot +import com.stevesoltys.seedvault.repo.BackupData +import com.stevesoltys.seedvault.repo.hexFromProto import com.stevesoltys.seedvault.settings.SettingsManager -import com.stevesoltys.seedvault.transport.backup.BackupData -import com.stevesoltys.seedvault.transport.backup.hexFromProto import com.stevesoltys.seedvault.worker.BASE_SPLIT import io.mockk.every import io.mockk.mockk diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt index f3d2086b..7074056c 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinatorTest.kt @@ -17,6 +17,8 @@ import com.stevesoltys.seedvault.metadata.PackageMetadata import com.stevesoltys.seedvault.metadata.PackageState.NO_DATA import com.stevesoltys.seedvault.metadata.PackageState.QUOTA_EXCEEDED import com.stevesoltys.seedvault.metadata.PackageState.UNKNOWN_ERROR +import com.stevesoltys.seedvault.repo.AppBackupManager +import com.stevesoltys.seedvault.repo.SnapshotCreator import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import com.stevesoltys.seedvault.worker.ApkBackup import io.mockk.Runs diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/FullBackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/FullBackupTest.kt index 4aa18856..886ff74c 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/FullBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/FullBackupTest.kt @@ -9,6 +9,7 @@ import android.app.backup.BackupTransport.TRANSPORT_ERROR import android.app.backup.BackupTransport.TRANSPORT_OK import android.app.backup.BackupTransport.TRANSPORT_PACKAGE_REJECTED import android.app.backup.BackupTransport.TRANSPORT_QUOTA_EXCEEDED +import com.stevesoltys.seedvault.repo.BackupReceiver import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import io.mockk.Runs import io.mockk.coEvery diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/KVBackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/KVBackupTest.kt index e2712ccc..0dfb8959 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/KVBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/KVBackupTest.kt @@ -15,6 +15,7 @@ import android.app.backup.BackupTransport.TRANSPORT_OK import android.content.pm.PackageInfo import com.stevesoltys.seedvault.getRandomString import com.stevesoltys.seedvault.header.MAX_KEY_LENGTH_SIZE +import com.stevesoltys.seedvault.repo.BackupReceiver import io.mockk.CapturingSlot import io.mockk.Runs import io.mockk.coEvery diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/FullRestoreTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/FullRestoreTest.kt index 7d98c235..724d644f 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/FullRestoreTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/FullRestoreTest.kt @@ -15,6 +15,7 @@ import com.stevesoltys.seedvault.coAssertThrows import com.stevesoltys.seedvault.getRandomByteArray import com.stevesoltys.seedvault.header.MAX_SEGMENT_LENGTH import com.stevesoltys.seedvault.header.VERSION +import com.stevesoltys.seedvault.repo.Loader import io.mockk.CapturingSlot import io.mockk.Runs import io.mockk.coEvery diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/KVRestoreTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/KVRestoreTest.kt index 24180ba6..8402fb47 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/KVRestoreTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/KVRestoreTest.kt @@ -16,6 +16,7 @@ import com.stevesoltys.seedvault.backend.BackendManager import com.stevesoltys.seedvault.coAssertThrows import com.stevesoltys.seedvault.getRandomByteArray import com.stevesoltys.seedvault.header.VERSION +import com.stevesoltys.seedvault.repo.Loader import com.stevesoltys.seedvault.transport.backup.KVDb import com.stevesoltys.seedvault.transport.backup.KvDbManager import io.mockk.Runs diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/KVRestoreV1Test.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/KVRestoreV1Test.kt index c56555e8..123c91d1 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/KVRestoreV1Test.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/KVRestoreV1Test.kt @@ -16,6 +16,7 @@ import com.stevesoltys.seedvault.getRandomByteArray import com.stevesoltys.seedvault.header.UnsupportedVersionException import com.stevesoltys.seedvault.header.VersionHeader import com.stevesoltys.seedvault.header.getADForKV +import com.stevesoltys.seedvault.repo.Loader import com.stevesoltys.seedvault.transport.backup.KVDb import com.stevesoltys.seedvault.transport.backup.KvDbManager import io.mockk.Runs diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinatorTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinatorTest.kt index a7a5a091..7bf154a8 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinatorTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinatorTest.kt @@ -22,6 +22,7 @@ import com.stevesoltys.seedvault.metadata.BackupType import com.stevesoltys.seedvault.metadata.MetadataReader import com.stevesoltys.seedvault.metadata.PackageMetadata import com.stevesoltys.seedvault.proto.copy +import com.stevesoltys.seedvault.repo.Loader import com.stevesoltys.seedvault.transport.TransportTest import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import io.mockk.Runs diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/RestoreV0IntegrationTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/RestoreV0IntegrationTest.kt index 229b3d37..c6a04fc9 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/restore/RestoreV0IntegrationTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/restore/RestoreV0IntegrationTest.kt @@ -20,6 +20,7 @@ import com.stevesoltys.seedvault.crypto.KeyManagerTestImpl import com.stevesoltys.seedvault.encodeBase64 import com.stevesoltys.seedvault.header.HeaderReaderImpl import com.stevesoltys.seedvault.metadata.MetadataReaderImpl +import com.stevesoltys.seedvault.repo.Loader import com.stevesoltys.seedvault.toByteArrayFromHex import com.stevesoltys.seedvault.transport.TransportTest import com.stevesoltys.seedvault.transport.backup.KvDbManager diff --git a/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt index bc1f3640..28d5d638 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupManagerTest.kt @@ -15,7 +15,7 @@ import com.stevesoltys.seedvault.metadata.PackageMetadata import com.stevesoltys.seedvault.metadata.PackageState.NOT_ALLOWED import com.stevesoltys.seedvault.metadata.PackageState.UNKNOWN_ERROR import com.stevesoltys.seedvault.metadata.PackageState.WAS_STOPPED -import com.stevesoltys.seedvault.transport.SnapshotManager +import com.stevesoltys.seedvault.repo.SnapshotManager import com.stevesoltys.seedvault.transport.TransportTest import com.stevesoltys.seedvault.transport.backup.PackageService import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager diff --git a/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupTest.kt index b9bceec5..05d6f125 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/worker/ApkBackupTest.kt @@ -20,11 +20,11 @@ import com.stevesoltys.seedvault.getRandomString import com.stevesoltys.seedvault.proto.Snapshot import com.stevesoltys.seedvault.proto.SnapshotKt.app import com.stevesoltys.seedvault.proto.copy -import com.stevesoltys.seedvault.transport.backup.AppBackupManager -import com.stevesoltys.seedvault.transport.backup.BackupData -import com.stevesoltys.seedvault.transport.backup.BackupReceiver +import com.stevesoltys.seedvault.repo.AppBackupManager +import com.stevesoltys.seedvault.repo.BackupData +import com.stevesoltys.seedvault.repo.BackupReceiver import com.stevesoltys.seedvault.transport.backup.BackupTest -import com.stevesoltys.seedvault.transport.backup.SnapshotCreator +import com.stevesoltys.seedvault.repo.SnapshotCreator import io.mockk.Runs import io.mockk.coEvery import io.mockk.coVerify