backup: detekt clean (71 tests)
- Commit
c80eca9fc3bf42e5d834cf7a23d61bde7e5e2c3a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-14 23:11 UTC (21 days ago)
- Parents
3148982
Fix all 16 detekt findings: real KDoc for 15 undocumented public classes (MainActivity, Route destinations, companion objects, BackupViewModel) and split Crypto.decrypt (CyclomaticComplexMethod 16>14, regression from commit 092560712 which added v2 terminator checks) into readVersion/decryptSegments/nextSegmentLength/decryptSegment/checkTerminator, preserving v1-EOF vs v2-missing-terminator, ordering and trailing-data checks verbatim. Why backup failed despite the 'detekt-clean reference' claim: commit 9cd53f7c7 enabled UndocumentedPublicClass with searchInNestedClass/InnerObject, newly flagging companion objects and nested Route objects; the decrypt refactor then added the only Error-severity finding. AGENTS.md claim is stale. Verified: ./gradlew :backup:detekt :backup:testDevUnitTest :backup:lint --max-workers=32 — BUILD SUCCESSFUL, 71 unit tests pass. No @Suppress added.
Diff
backup/src/main/java/com/vayunmathur/backup/MainActivity.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/MainActivity.kt b/backup/src/main/java/com/vayunmathur/backup/MainActivity.ktindex c79ae2e091..bac822e974 100644--- a/backup/src/main/java/com/vayunmathur/backup/MainActivity.kt+++ b/backup/src/main/java/com/vayunmathur/backup/MainActivity.kt@@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import com.vayunmathur.backup.platform.BackupViewModel import com.vayunmathur.library.ui.MaActivity +/** Entry activity hosting the backup onboarding and dashboard navigation. */ class MainActivity : MaActivity() { private val viewModel: BackupViewModel by viewModels()
backup/src/main/java/com/vayunmathur/backup/Route.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/Route.kt b/backup/src/main/java/com/vayunmathur/backup/Route.ktindex c57fbcc6ca..5d132e6488 100644--- a/backup/src/main/java/com/vayunmathur/backup/Route.kt+++ b/backup/src/main/java/com/vayunmathur/backup/Route.kt@@ -4,10 +4,13 @@ import com.vayunmathur.library.util.NavKey import kotlinx.serialization.Serializable @Serializable+/** Navigation destinations for the backup app. */ sealed interface Route : NavKey { @Serializable+ /** First-run setup: recovery code and backup destination. */ data object Onboarding : Route @Serializable+ /** Main backup status and controls screen. */ data object Dashboard : Route }
backup/src/main/java/com/vayunmathur/backup/data/BackupConfig.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/data/BackupConfig.kt b/backup/src/main/java/com/vayunmathur/backup/data/BackupConfig.ktindex feb5fc2db7..da8fe293c9 100644--- a/backup/src/main/java/com/vayunmathur/backup/data/BackupConfig.kt+++ b/backup/src/main/java/com/vayunmathur/backup/data/BackupConfig.kt@@ -84,6 +84,7 @@ class BackupConfig(private val context: Context) { context.backupDataStore.edit { it.clear() } } + /** DataStore preference keys for [BackupConfig]. */ companion object { private val KEY_BACKEND = stringPreferencesKey("backend_type") private val KEY_SAF_URI = stringPreferencesKey("saf_tree_uri")
backup/src/main/java/com/vayunmathur/backup/data/backend/BackupBackend.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/data/backend/BackupBackend.kt b/backup/src/main/java/com/vayunmathur/backup/data/backend/BackupBackend.ktindex 0379c6ed48..f1ce4a97a6 100644--- a/backup/src/main/java/com/vayunmathur/backup/data/backend/BackupBackend.kt+++ b/backup/src/main/java/com/vayunmathur/backup/data/backend/BackupBackend.kt@@ -44,6 +44,7 @@ interface BackupBackend { suspend fun loadOrNull(path: String): ByteArray? = if (exists(path)) load(path) else null + /** Stream helpers shared by [BackupBackend] implementations and callers. */ companion object { fun bytesWriter(bytes: ByteArray): suspend (OutputStream) -> Unit = { it.write(bytes); it.flush() }
backup/src/main/java/com/vayunmathur/backup/data/backend/BackupRepository.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/data/backend/BackupRepository.kt b/backup/src/main/java/com/vayunmathur/backup/data/backend/BackupRepository.ktindex 5ed5a0a367..b66277c1fc 100644--- a/backup/src/main/java/com/vayunmathur/backup/data/backend/BackupRepository.kt+++ b/backup/src/main/java/com/vayunmathur/backup/data/backend/BackupRepository.kt@@ -42,6 +42,7 @@ class BackupRepository( suspend fun list(dir: String) = backend.list(dir) + /** Backend path constants and path builders for the backup layout. */ companion object { const val METADATA = "metadata.json" const val KV_DIR = "kv"
backup/src/main/java/com/vayunmathur/backup/data/backend/SafBackend.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/data/backend/SafBackend.kt b/backup/src/main/java/com/vayunmathur/backup/data/backend/SafBackend.ktindex dd7f46fa47..66811d94a9 100644--- a/backup/src/main/java/com/vayunmathur/backup/data/backend/SafBackend.kt+++ b/backup/src/main/java/com/vayunmathur/backup/data/backend/SafBackend.kt@@ -147,6 +147,7 @@ class SafBackend( private fun segments(path: String): List<String> = path.split('/').filter { it.isNotEmpty() } + /** MIME type used when creating backup blobs in the SAF tree. */ companion object { private const val MIME_OCTET = "application/octet-stream" }
backup/src/main/java/com/vayunmathur/backup/data/backend/WebDavBackend.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/data/backend/WebDavBackend.kt b/backup/src/main/java/com/vayunmathur/backup/data/backend/WebDavBackend.ktindex c1288275cf..8f3cec9b74 100644--- a/backup/src/main/java/com/vayunmathur/backup/data/backend/WebDavBackend.kt+++ b/backup/src/main/java/com/vayunmathur/backup/data/backend/WebDavBackend.kt@@ -114,6 +114,7 @@ class WebDavBackend( return resp.status == HTTP_MULTI_STATUS || resp.isSuccess } + /** HTTP status constants used by [WebDavBackend]. */ companion object { private const val HTTP_OK = 200 private const val HTTP_CREATED = 201
backup/src/main/java/com/vayunmathur/backup/data/files/FileBackupManager.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/data/files/FileBackupManager.kt b/backup/src/main/java/com/vayunmathur/backup/data/files/FileBackupManager.ktindex c5f9a18f5c..a2aa46b49c 100644--- a/backup/src/main/java/com/vayunmathur/backup/data/files/FileBackupManager.kt+++ b/backup/src/main/java/com/vayunmathur/backup/data/files/FileBackupManager.kt@@ -145,6 +145,7 @@ class FileBackupManager( private data class Collection(val uri: Uri, val type: String) + /** Manifest path and media collections backed up by [FileBackupManager]. */ companion object { private const val INDEX = "${BackupRepository.FILES_DIR}/index.json"
backup/src/main/java/com/vayunmathur/backup/domain/crypto/Crypto.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/domain/crypto/Crypto.kt b/backup/src/main/java/com/vayunmathur/backup/domain/crypto/Crypto.ktindex 708a7a6ae0..069a7afede 100644--- a/backup/src/main/java/com/vayunmathur/backup/domain/crypto/Crypto.kt+++ b/backup/src/main/java/com/vayunmathur/backup/domain/crypto/Crypto.kt@@ -62,37 +62,62 @@ class Crypto(private val masterKey: ByteArray) { } fun decrypt(input: InputStream, output: OutputStream) {+ val version = readVersion(input)+ decryptSegments(input, output, version)+ output.flush()+ }++ private fun readVersion(input: InputStream): Int { val version = input.read() if (version < 0) throw IOException("empty backup stream") require(version == VERSION || version == VERSION_V1) { "unsupported backup version: $version" }+ return version+ }++ private fun decryptSegments(input: InputStream, output: OutputStream, version: Int) { var expectedIndex = 0 while (true) {- val length = readIntFrom(input) ?: run {- // Clean EOF between segments. Only a legacy v1 stream may end- // here; a v2 stream must end with its terminator segment.- if (version == VERSION) throw IOException("truncated backup stream: missing terminator")- break- }- if (length <= 0 || length > MAX_SEGMENT_BLOB) throw IOException("invalid segment length: $length")- val segment = ByteArray(length)- if (fill(input, segment) != length) throw IOException("truncated segment")- val plain = E2ee.aesDecrypt(masterKey, segment)- if (plain.size < 4) throw IOException("corrupt segment")+ val length = nextSegmentLength(input, version) ?: return+ val plain = decryptSegment(input, length) val index = readIntBE(plain, 0)- if (index != expectedIndex) throw IOException("segment out of order: $index != $expectedIndex")+ if (index != expectedIndex) {+ throw IOException("segment out of order: $index != $expectedIndex")+ } if (plain.size == 4) {- // Terminator segment (v2 only; a v1 writer never emitted one).- if (version == VERSION_V1) throw IOException("corrupt segment")- if (readIntFrom(input) != null) throw IOException("trailing data after terminator")- output.flush()+ checkTerminator(input, version) return } output.write(plain, 4, plain.size - 4) expectedIndex++ }- output.flush()+ }++ /** Next segment length, or null for a clean legacy-v1 EOF between segments. */+ private fun nextSegmentLength(input: InputStream, version: Int): Int? {+ val length = readIntFrom(input) ?: run {+ // Clean EOF between segments. Only a legacy v1 stream may end+ // here; a v2 stream must end with its terminator segment.+ if (version == VERSION) throw IOException("truncated backup stream: missing terminator")+ return null+ }+ if (length <= 0 || length > MAX_SEGMENT_BLOB) throw IOException("invalid segment length: $length")+ return length+ }++ private fun decryptSegment(input: InputStream, length: Int): ByteArray {+ val segment = ByteArray(length)+ if (fill(input, segment) != length) throw IOException("truncated segment")+ val plain = E2ee.aesDecrypt(masterKey, segment)+ if (plain.size < 4) throw IOException("corrupt segment")+ return plain+ }++ private fun checkTerminator(input: InputStream, version: Int) {+ // Terminator segment (v2 only; a v1 writer never emitted one).+ if (version == VERSION_V1) throw IOException("corrupt segment")+ if (readIntFrom(input) != null) throw IOException("trailing data after terminator") } fun encrypt(plain: ByteArray): ByteArray =@@ -101,6 +126,7 @@ class Crypto(private val masterKey: ByteArray) { fun decrypt(blob: ByteArray): ByteArray = ByteArrayOutputStream().also { decrypt(ByteArrayInputStream(blob), it) }.toByteArray() + /** Format versions, segment sizing and stream helpers for [Crypto]. */ companion object { const val VERSION = 2 private const val VERSION_V1 = 1
backup/src/main/java/com/vayunmathur/backup/platform/BackupViewModel.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/platform/BackupViewModel.kt b/backup/src/main/java/com/vayunmathur/backup/platform/BackupViewModel.ktindex 2fc942d78d..67d5bd98c9 100644--- a/backup/src/main/java/com/vayunmathur/backup/platform/BackupViewModel.kt+++ b/backup/src/main/java/com/vayunmathur/backup/platform/BackupViewModel.kt@@ -35,6 +35,7 @@ data class BackupUiState( val onboarded: Boolean get() = hasKey && settings.isConfigured } +/** ViewModel holding backup configuration, key state and one-shot UI messages. */ class BackupViewModel(app: Application) : AndroidViewModel(app) { private val config = BackupConfig(app) private val keyManager = KeyManager(app)
backup/src/main/java/com/vayunmathur/backup/platform/FileBackupWorker.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/platform/FileBackupWorker.kt b/backup/src/main/java/com/vayunmathur/backup/platform/FileBackupWorker.ktindex a8b98a9609..46452155d1 100644--- a/backup/src/main/java/com/vayunmathur/backup/platform/FileBackupWorker.kt+++ b/backup/src/main/java/com/vayunmathur/backup/platform/FileBackupWorker.kt@@ -42,6 +42,7 @@ class FileBackupWorker( } } + /** Work name and scheduling entry point for [FileBackupWorker]. */ companion object { private const val WORK_NAME = "backup_file_backup"
backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.kt b/backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.ktindex 9e7907d4d7..d8063f3d7e 100644--- a/backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.kt+++ b/backup/src/main/java/com/vayunmathur/backup/platform/crypto/KeyManager.kt@@ -30,6 +30,7 @@ class KeyManager(context: Context) : DatabaseHelper(context) { fun clear() = deleteKey() + /** Key-derivation constants for [KeyManager]. */ companion object { private val MASTER_KEY_INFO = "com.vayunmathur.backup/master-key".toByteArray(Charsets.UTF_8)
backup/src/main/java/com/vayunmathur/backup/service/ConfigurableBackupTransport.kt
diff --git a/backup/src/main/java/com/vayunmathur/backup/service/ConfigurableBackupTransport.kt b/backup/src/main/java/com/vayunmathur/backup/service/ConfigurableBackupTransport.ktindex a136b01ecc..690d69152c 100644--- a/backup/src/main/java/com/vayunmathur/backup/service/ConfigurableBackupTransport.kt+++ b/backup/src/main/java/com/vayunmathur/backup/service/ConfigurableBackupTransport.kt@@ -364,6 +364,7 @@ class ConfigurableBackupTransport(private val context: Context) : BackupTranspor private fun decodeKey(keyId: String): String = String(Base64.decode(keyId, Base64.URL_SAFE or Base64.NO_WRAP or Base64.NO_PADDING), Charsets.UTF_8) + /** Transport component name and streaming constants for [ConfigurableBackupTransport]. */ companion object { private const val COMPONENT = "com.vayunmathur.backup/.service.ConfigurableBackupTransportService" private const val CHUNK = 32 * 1024