Merge pull request #7891 from vector-im/fix/mna/false-positives

Update to latest version of Lint (8.0.0-alpha10)
This commit is contained in:
Maxime NATUREL 2023-01-04 16:00:59 +01:00 committed by GitHub
commit 87928b4e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 19 deletions

View File

@ -39,3 +39,7 @@ signing.element.keyPassword=Secret
signing.element.nightly.storePassword=Secret
signing.element.nightly.keyId=Secret
signing.element.nightly.keyPassword=Secret
# Customise the Lint version to use a more recent version than the one bundled with AGP
# https://googlesamples.github.io/android-custom-lint-rules/usage/newer-lint.md.html
android.experimental.lint.version=8.0.0-alpha10

View File

@ -21,7 +21,6 @@ import android.app.Activity
import android.content.pm.PackageManager
import android.os.Build
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import im.vector.app.R
@ -35,17 +34,12 @@ class NotificationPermissionManager @Inject constructor(
private val vectorPreferences: VectorPreferences,
) {
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU)
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
fun isPermissionGranted(activity: Activity): Boolean {
return if (sdkIntProvider.isAtLeast(Build.VERSION_CODES.TIRAMISU)) {
ContextCompat.checkSelfPermission(
activity,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
} else {
// No notification permission management before API 33.
true
}
return ContextCompat.checkSelfPermission(
activity,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
}
fun eventuallyRequestPermission(

View File

@ -15,12 +15,14 @@
*/
package im.vector.app.features.settings.troubleshoot
import android.os.Build
import androidx.core.app.NotificationManagerCompat
import androidx.fragment.app.FragmentActivity
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.startNotificationSettingsIntent
import im.vector.app.features.home.NotificationPermissionManager
import org.matrix.android.sdk.api.util.BuildVersionSdkIntProvider
import javax.inject.Inject
/**
@ -30,6 +32,7 @@ import javax.inject.Inject
class TestSystemSettings @Inject constructor(
private val context: FragmentActivity,
private val stringProvider: StringProvider,
private val sdkIntProvider: BuildVersionSdkIntProvider,
private val notificationPermissionManager: NotificationPermissionManager,
) : TroubleshootTest(R.string.settings_troubleshoot_test_system_settings_title) {
@ -39,14 +42,7 @@ class TestSystemSettings @Inject constructor(
quickFix = null
status = TestStatus.SUCCESS
} else {
if (notificationPermissionManager.isPermissionGranted(context)) {
description = stringProvider.getString(R.string.settings_troubleshoot_test_system_settings_failed)
quickFix = object : TroubleshootQuickFix(R.string.open_settings) {
override fun doFix() {
startNotificationSettingsIntent(context, testParameters.activityResultLauncher)
}
}
} else {
if (sdkIntProvider.isAtLeast(Build.VERSION_CODES.TIRAMISU) && notificationPermissionManager.isPermissionGranted(context).not()) {
// In this case, we can ask for user permission
description = stringProvider.getString(R.string.settings_troubleshoot_test_system_settings_permission_failed)
quickFix = object : TroubleshootQuickFix(R.string.grant_permission) {
@ -54,6 +50,13 @@ class TestSystemSettings @Inject constructor(
notificationPermissionManager.askPermission(testParameters.permissionResultLauncher)
}
}
} else {
description = stringProvider.getString(R.string.settings_troubleshoot_test_system_settings_failed)
quickFix = object : TroubleshootQuickFix(R.string.open_settings) {
override fun doFix() {
startNotificationSettingsIntent(context, testParameters.activityResultLauncher)
}
}
}
status = TestStatus.FAILED
}