Fix error reported for usage of some methods from API 33
This commit is contained in:
parent
0d5b6efd5c
commit
36b1c12b81
@ -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(
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user