Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest version of Lint (8.0.0-alpha10) #7891

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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) {

Expand All @@ -39,21 +42,21 @@ 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) {
override fun doFix() {
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
}
Expand Down