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 { lintOptions {
abortOnError false disable "CheckedExceptions"
abortOnError true
} }
compileOptions { compileOptions {
targetCompatibility 1.8 targetCompatibility 1.8

View file

@ -12,7 +12,6 @@ import com.stevesoltys.seedvault.assertReadEquals
import com.stevesoltys.seedvault.coAssertThrows import com.stevesoltys.seedvault.coAssertThrows
import com.stevesoltys.seedvault.getRandomBase64 import com.stevesoltys.seedvault.getRandomBase64
import com.stevesoltys.seedvault.getRandomByteArray import com.stevesoltys.seedvault.getRandomByteArray
import com.stevesoltys.seedvault.metadata.MetadataManager
import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.settings.SettingsManager
import com.stevesoltys.seedvault.writeAndClose import com.stevesoltys.seedvault.writeAndClose
import io.mockk.Runs import io.mockk.Runs
@ -43,7 +42,6 @@ import kotlin.random.Random
class DocumentsStorageTest : KoinComponent { class DocumentsStorageTest : KoinComponent {
private val context = InstrumentationRegistry.getInstrumentation().targetContext private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val metadataManager by inject<MetadataManager>()
private val settingsManager by inject<SettingsManager>() private val settingsManager by inject<SettingsManager>()
private val storage = DocumentsStorage(context, settingsManager) private val storage = DocumentsStorage(context, settingsManager)

View file

@ -76,6 +76,7 @@ class App : Application() {
* after sufficient time has passed. * after sufficient time has passed.
*/ */
private fun migrateTokenFromMetadataToSettingsManager() { private fun migrateTokenFromMetadataToSettingsManager() {
@Suppress("DEPRECATION")
val token = metadataManager.getBackupToken() val token = metadataManager.getBackupToken()
if (token != 0L && settingsManager.getToken() == null) { if (token != 0L && settingsManager.getToken() == null) {
settingsManager.setNewToken(token) settingsManager.setNewToken(token)

View file

@ -1,5 +1,6 @@
package com.stevesoltys.seedvault.transport.backup package com.stevesoltys.seedvault.transport.backup
import android.annotation.SuppressLint
import android.content.pm.PackageInfo import android.content.pm.PackageInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.Signature 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. * @return new [PackageMetadata] if an APK backup was made or null if no backup was made.
*/ */
@Throws(IOException::class) @Throws(IOException::class)
@SuppressLint("NewApi") // can be removed when minSdk is set to 30
suspend fun backupApkIfNecessary( suspend fun backupApkIfNecessary(
packageInfo: PackageInfo, packageInfo: PackageInfo,
packageState: PackageState, packageState: PackageState,

View file

@ -123,7 +123,7 @@ internal class ApkRestore(
publicSourceDir = cachedApk.absolutePath publicSourceDir = cachedApk.absolutePath
} }
val icon = appInfo.loadIcon(pm) 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) } installResult.update(packageName) { it.copy(status = IN_PROGRESS, name = name, icon = icon) }
emit(installResult) emit(installResult)

View file

@ -1,5 +1,6 @@
package com.stevesoltys.seedvault.ui.notification package com.stevesoltys.seedvault.ui.notification
import android.annotation.SuppressLint
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.app.NotificationManager.IMPORTANCE_DEFAULT import android.app.NotificationManager.IMPORTANCE_DEFAULT
@ -213,6 +214,7 @@ internal class BackupNotificationManager(private val context: Context) {
return false return false
} }
@SuppressLint("RestrictedApi")
fun onBackupError() { fun onBackupError() {
val intent = Intent(context, SettingsActivity::class.java) val intent = Intent(context, SettingsActivity::class.java)
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
@ -234,6 +236,7 @@ internal class BackupNotificationManager(private val context: Context) {
nm.cancel(NOTIFICATION_ID_ERROR) nm.cancel(NOTIFICATION_ID_ERROR)
} }
@SuppressLint("RestrictedApi")
fun onRemovableStorageNotAvailableForRestore(packageName: String, storageName: String) { fun onRemovableStorageNotAvailableForRestore(packageName: String, storageName: String) {
val appName = try { val appName = try {
val appInfo = context.packageManager.getApplicationInfo(packageName, 0) val appInfo = context.packageManager.getApplicationInfo(packageName, 0)

View file

@ -105,7 +105,7 @@ fun getAppName(context: Context, packageId: String): CharSequence {
} }
return try { return try {
val appInfo = context.packageManager.getApplicationInfo(packageId, 0) val appInfo = context.packageManager.getApplicationInfo(packageId, 0)
context.packageManager.getApplicationLabel(appInfo) ?: packageId context.packageManager.getApplicationLabel(appInfo)
} catch (e: NameNotFoundException) { } catch (e: NameNotFoundException) {
packageId packageId
} }

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".settings.RecoveryCodeFragment"> tools:context=".ui.recoverycode.RecoveryCodeActivity">
<ImageView <ImageView
android:id="@+id/introIcon" android:id="@+id/introIcon"

View file

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

View file

@ -8,9 +8,6 @@
<!-- Settings --> <!-- Settings -->
<string name="settings_backup">Backup my data</string> <string name="settings_backup">Backup my data</string>
<string name="settings_backup_location">Backup location</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_none">None</string>
<string name="settings_backup_location_internal">Internal storage</string> <string name="settings_backup_location_internal">Internal storage</string>
<string name="settings_backup_last_backup_never">Never</string> <string name="settings_backup_last_backup_never">Never</string>
@ -74,9 +71,6 @@
<!-- Notification --> <!-- Notification -->
<string name="notification_channel_title">Backup notification</string> <string name="notification_channel_title">Backup notification</string>
<string name="notification_title">Backup running</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_backup_already_running">Backup already in progress</string>
<string name="notification_success_title">Backup finished</string> <string name="notification_success_title">Backup finished</string>

View file

@ -34,6 +34,7 @@ import java.io.FileOutputStream
import java.io.IOException import java.io.IOException
import kotlin.random.Random import kotlin.random.Random
@Suppress("DEPRECATION")
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
@Config(sdk = [29]) // robolectric does not support 30, yet @Config(sdk = [29]) // robolectric does not support 30, yet
class MetadataManagerTest { class MetadataManagerTest {
@ -213,7 +214,7 @@ class MetadataManagerTest {
// expected // expected
} }
assertEquals(0L, manager.getLastBackupTime()) // time was reverted assertEquals(0L, manager.getLastBackupTime()) // time was reverted
assertEquals(initialMetadata.packageMetadataMap[packageName], manager.getPackageMetadata(packageName)) 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_SYSTEM
import android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP import android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
import android.content.pm.InstallSourceInfo
import android.content.pm.PackageInfo import android.content.pm.PackageInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.Signature import android.content.pm.Signature
@ -44,9 +45,9 @@ internal class ApkBackupTest : BackupTest() {
private val signatureHash = byteArrayOf(0x03, 0x02, 0x01) private val signatureHash = byteArrayOf(0x03, 0x02, 0x01)
private val sigs = arrayOf(Signature(signatureBytes)) private val sigs = arrayOf(Signature(signatureBytes))
private val packageMetadata = PackageMetadata( private val packageMetadata = PackageMetadata(
time = Random.nextLong(), time = Random.nextLong(),
version = packageInfo.longVersionCode - 1, version = packageInfo.longVersionCode - 1,
signatures = listOf("AwIB") signatures = listOf("AwIB")
) )
init { init {
@ -79,7 +80,7 @@ internal class ApkBackupTest : BackupTest() {
fun `does not back up the same version`() = runBlocking { fun `does not back up the same version`() = runBlocking {
packageInfo.applicationInfo.flags = FLAG_UPDATED_SYSTEM_APP packageInfo.applicationInfo.flags = FLAG_UPDATED_SYSTEM_APP
val packageMetadata = packageMetadata.copy( val packageMetadata = packageMetadata.copy(
version = packageInfo.longVersionCode version = packageInfo.longVersionCode
) )
expectChecks(packageMetadata) expectChecks(packageMetadata)
@ -120,20 +121,31 @@ internal class ApkBackupTest : BackupTest() {
}.absolutePath }.absolutePath
val apkOutputStream = ByteArrayOutputStream() val apkOutputStream = ByteArrayOutputStream()
val updatedMetadata = PackageMetadata( val updatedMetadata = PackageMetadata(
time = 0L, time = 0L,
state = UNKNOWN_ERROR, state = UNKNOWN_ERROR,
version = packageInfo.longVersionCode, version = packageInfo.longVersionCode,
installer = getRandomString(), installer = getRandomString(),
sha256 = "eHx5jjmlvBkQNVuubQzYejay4Q_QICqD47trAF2oNHI", sha256 = "eHx5jjmlvBkQNVuubQzYejay4Q_QICqD47trAF2oNHI",
signatures = packageMetadata.signatures signatures = packageMetadata.signatures
) )
expectChecks() expectChecks()
coEvery { streamGetter.invoke() } returns apkOutputStream coEvery { streamGetter.invoke() } returns apkOutputStream
every { pm.getInstallerPackageName(packageInfo.packageName) } returns updatedMetadata.installer every {
every { metadataManager.onApkBackedUp(packageInfo, updatedMetadata, outputStream) } just Runs 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()) assertArrayEquals(apkBytes, apkOutputStream.toByteArray())
} }