Fix lint warnings

This commit is contained in:
Torsten Grote 2020-09-14 17:47:01 -03:00 committed by Chirayu Desai
parent af4b6807f2
commit 57f404281c
12 changed files with 40 additions and 28 deletions

View file

@ -22,7 +22,8 @@ android {
}
lintOptions {
abortOnError false
disable "CheckedExceptions"
abortOnError true
}
compileOptions {
targetCompatibility 1.8

View file

@ -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<MetadataManager>()
private val settingsManager by inject<SettingsManager>()
private val storage = DocumentsStorage(context, settingsManager)

View file

@ -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)

View file

@ -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,

View file

@ -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)

View file

@ -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)

View file

@ -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
}

View file

@ -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">
<ImageView
android:id="@+id/introIcon"

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!--
Normally, restoring from backup is only available during initial device setup.
You can make it always available at your own risk.
@ -11,7 +11,7 @@
<bool name="show_restore_in_settings">false</bool>
<!-- Add only storage that is also available when restoring from backup (e.g. initial device setup) -->
<string-array name="storage_authority_whitelist">
<string-array name="storage_authority_whitelist" tools:ignore="InconsistentArrays">
<item>com.android.externalstorage.documents</item>
<item>org.nextcloud.documents</item>
</string-array>

View file

@ -8,9 +8,6 @@
<!-- Settings -->
<string name="settings_backup">Backup my data</string>
<string name="settings_backup_location">Backup location</string>
<string name="settings_backup_location_picker">Choose backup location</string>
<string name="settings_backup_location_title">Backup location</string>
<string name="settings_backup_location_invalid">The chosen location can not be used.</string>
<string name="settings_backup_location_none">None</string>
<string name="settings_backup_location_internal">Internal storage</string>
<string name="settings_backup_last_backup_never">Never</string>
@ -74,9 +71,6 @@
<!-- Notification -->
<string name="notification_channel_title">Backup notification</string>
<string name="notification_title">Backup running</string>
<string name="notification_backup_result_complete">Backup complete</string>
<string name="notification_backup_result_rejected">Not backed up</string>
<string name="notification_backup_result_error">Backup failed</string>
<string name="notification_backup_already_running">Backup already in progress</string>
<string name="notification_success_title">Backup finished</string>

View file

@ -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))
}

View file

@ -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())
}