diff --git a/app/build.gradle b/app/build.gradle index 4f0f0f4e..738f6cab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,7 +22,8 @@ android { } lintOptions { - abortOnError false + disable "CheckedExceptions" + abortOnError true } compileOptions { targetCompatibility 1.8 diff --git a/app/src/androidTest/java/com/stevesoltys/seedvault/plugins/saf/DocumentsStorageTest.kt b/app/src/androidTest/java/com/stevesoltys/seedvault/plugins/saf/DocumentsStorageTest.kt index 3ea8999d..8068aed4 100644 --- a/app/src/androidTest/java/com/stevesoltys/seedvault/plugins/saf/DocumentsStorageTest.kt +++ b/app/src/androidTest/java/com/stevesoltys/seedvault/plugins/saf/DocumentsStorageTest.kt @@ -12,7 +12,6 @@ import com.stevesoltys.seedvault.assertReadEquals import com.stevesoltys.seedvault.coAssertThrows import com.stevesoltys.seedvault.getRandomBase64 import com.stevesoltys.seedvault.getRandomByteArray -import com.stevesoltys.seedvault.metadata.MetadataManager import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.writeAndClose import io.mockk.Runs @@ -43,7 +42,6 @@ import kotlin.random.Random class DocumentsStorageTest : KoinComponent { private val context = InstrumentationRegistry.getInstrumentation().targetContext - private val metadataManager by inject() private val settingsManager by inject() private val storage = DocumentsStorage(context, settingsManager) diff --git a/app/src/main/java/com/stevesoltys/seedvault/App.kt b/app/src/main/java/com/stevesoltys/seedvault/App.kt index d5dde682..5b56a661 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/App.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/App.kt @@ -76,6 +76,7 @@ class App : Application() { * after sufficient time has passed. */ private fun migrateTokenFromMetadataToSettingsManager() { + @Suppress("DEPRECATION") val token = metadataManager.getBackupToken() if (token != 0L && settingsManager.getToken() == null) { settingsManager.setNewToken(token) diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt index 12c4d42b..4cf7ce3e 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt @@ -1,5 +1,6 @@ package com.stevesoltys.seedvault.transport.backup +import android.annotation.SuppressLint import android.content.pm.PackageInfo import android.content.pm.PackageManager import android.content.pm.Signature @@ -35,6 +36,7 @@ class ApkBackup( * @return new [PackageMetadata] if an APK backup was made or null if no backup was made. */ @Throws(IOException::class) + @SuppressLint("NewApi") // can be removed when minSdk is set to 30 suspend fun backupApkIfNecessary( packageInfo: PackageInfo, packageState: PackageState, diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/ApkRestore.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/ApkRestore.kt index fe7a6421..3a358bf4 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/ApkRestore.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/ApkRestore.kt @@ -123,7 +123,7 @@ internal class ApkRestore( publicSourceDir = cachedApk.absolutePath } val icon = appInfo.loadIcon(pm) - val name = pm.getApplicationLabel(appInfo) ?: packageName + val name = pm.getApplicationLabel(appInfo) installResult.update(packageName) { it.copy(status = IN_PROGRESS, name = name, icon = icon) } emit(installResult) diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt index 3ba8d563..0352edbf 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt @@ -1,5 +1,6 @@ package com.stevesoltys.seedvault.ui.notification +import android.annotation.SuppressLint import android.app.NotificationChannel import android.app.NotificationManager import android.app.NotificationManager.IMPORTANCE_DEFAULT @@ -213,6 +214,7 @@ internal class BackupNotificationManager(private val context: Context) { return false } + @SuppressLint("RestrictedApi") fun onBackupError() { val intent = Intent(context, SettingsActivity::class.java) val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) @@ -234,6 +236,7 @@ internal class BackupNotificationManager(private val context: Context) { nm.cancel(NOTIFICATION_ID_ERROR) } + @SuppressLint("RestrictedApi") fun onRemovableStorageNotAvailableForRestore(packageName: String, storageName: String) { val appName = try { val appInfo = context.packageManager.getApplicationInfo(packageName, 0) 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 b4a30cf1..ef5fa809 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 @@ -105,7 +105,7 @@ fun getAppName(context: Context, packageId: String): CharSequence { } return try { val appInfo = context.packageManager.getApplicationInfo(packageId, 0) - context.packageManager.getApplicationLabel(appInfo) ?: packageId + context.packageManager.getApplicationLabel(appInfo) } catch (e: NameNotFoundException) { packageId } diff --git a/app/src/main/res/layout/fragment_recovery_code_output.xml b/app/src/main/res/layout/fragment_recovery_code_output.xml index 1448fa91..8a84d5bd 100644 --- a/app/src/main/res/layout/fragment_recovery_code_output.xml +++ b/app/src/main/res/layout/fragment_recovery_code_output.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".settings.RecoveryCodeFragment"> + tools:context=".ui.recoverycode.RecoveryCodeActivity"> - + - + com.android.externalstorage.documents org.nextcloud.documents diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6cc9dc50..e797e5e1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,9 +8,6 @@ Backup my data Backup location - Choose backup location - Backup location - The chosen location can not be used. None Internal storage Never @@ -74,9 +71,6 @@ Backup notification Backup running - Backup complete - Not backed up - Backup failed Backup already in progress Backup finished diff --git a/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt index bff5f1d7..cd9e3b1e 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/metadata/MetadataManagerTest.kt @@ -34,6 +34,7 @@ import java.io.FileOutputStream import java.io.IOException import kotlin.random.Random +@Suppress("DEPRECATION") @RunWith(AndroidJUnit4::class) @Config(sdk = [29]) // robolectric does not support 30, yet class MetadataManagerTest { @@ -213,7 +214,7 @@ class MetadataManagerTest { // expected } - assertEquals(0L, manager.getLastBackupTime()) // time was reverted + assertEquals(0L, manager.getLastBackupTime()) // time was reverted assertEquals(initialMetadata.packageMetadataMap[packageName], manager.getPackageMetadata(packageName)) } diff --git a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/ApkBackupTest.kt b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/ApkBackupTest.kt index 3a863780..d34bbaa0 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/transport/backup/ApkBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/transport/backup/ApkBackupTest.kt @@ -2,6 +2,7 @@ package com.stevesoltys.seedvault.transport.backup import android.content.pm.ApplicationInfo.FLAG_SYSTEM import android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP +import android.content.pm.InstallSourceInfo import android.content.pm.PackageInfo import android.content.pm.PackageManager import android.content.pm.Signature @@ -44,9 +45,9 @@ internal class ApkBackupTest : BackupTest() { private val signatureHash = byteArrayOf(0x03, 0x02, 0x01) private val sigs = arrayOf(Signature(signatureBytes)) private val packageMetadata = PackageMetadata( - time = Random.nextLong(), - version = packageInfo.longVersionCode - 1, - signatures = listOf("AwIB") + time = Random.nextLong(), + version = packageInfo.longVersionCode - 1, + signatures = listOf("AwIB") ) init { @@ -79,7 +80,7 @@ internal class ApkBackupTest : BackupTest() { fun `does not back up the same version`() = runBlocking { packageInfo.applicationInfo.flags = FLAG_UPDATED_SYSTEM_APP val packageMetadata = packageMetadata.copy( - version = packageInfo.longVersionCode + version = packageInfo.longVersionCode ) expectChecks(packageMetadata) @@ -120,20 +121,31 @@ internal class ApkBackupTest : BackupTest() { }.absolutePath val apkOutputStream = ByteArrayOutputStream() val updatedMetadata = PackageMetadata( - time = 0L, - state = UNKNOWN_ERROR, - version = packageInfo.longVersionCode, - installer = getRandomString(), - sha256 = "eHx5jjmlvBkQNVuubQzYejay4Q_QICqD47trAF2oNHI", - signatures = packageMetadata.signatures + time = 0L, + state = UNKNOWN_ERROR, + version = packageInfo.longVersionCode, + installer = getRandomString(), + sha256 = "eHx5jjmlvBkQNVuubQzYejay4Q_QICqD47trAF2oNHI", + signatures = packageMetadata.signatures ) expectChecks() coEvery { streamGetter.invoke() } returns apkOutputStream - every { pm.getInstallerPackageName(packageInfo.packageName) } returns updatedMetadata.installer - every { metadataManager.onApkBackedUp(packageInfo, updatedMetadata, outputStream) } just Runs + every { + pm.getInstallSourceInfo(packageInfo.packageName) + } returns InstallSourceInfo(null, null, null, updatedMetadata.installer) + every { + metadataManager.onApkBackedUp( + packageInfo, + updatedMetadata, + outputStream + ) + } just Runs - assertEquals(updatedMetadata, apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter)) + assertEquals( + updatedMetadata, + apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter) + ) assertArrayEquals(apkBytes, apkOutputStream.toByteArray()) }