From 0d5b6efd5cbb681e54de0c13c296c11ee6f5cc31 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL <46314705+mnaturel@users.noreply.github.com> Date: Wed, 4 Jan 2023 14:56:41 +0100 Subject: [PATCH 1/2] Use latest version of lint --- gradle.properties | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gradle.properties b/gradle.properties index 2c999af35d..ea70ad5e51 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 From 36b1c12b81358fbc4a0614c25de090d93f179708 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL <46314705+mnaturel@users.noreply.github.com> Date: Wed, 4 Jan 2023 15:04:42 +0100 Subject: [PATCH 2/2] Fix error reported for usage of some methods from API 33 --- .../home/NotificationPermissionManager.kt | 16 +++++----------- .../troubleshoot/TestSystemSettings.kt | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/NotificationPermissionManager.kt b/vector/src/main/java/im/vector/app/features/home/NotificationPermissionManager.kt index 33ba1be02b..4f585becca 100644 --- a/vector/src/main/java/im/vector/app/features/home/NotificationPermissionManager.kt +++ b/vector/src/main/java/im/vector/app/features/home/NotificationPermissionManager.kt @@ -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( diff --git a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestSystemSettings.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestSystemSettings.kt index 0f362d5019..589edecad9 100644 --- a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestSystemSettings.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestSystemSettings.kt @@ -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 }