Skip to content

Commit

Permalink
Move notification permission sdk check to SDKUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
sabercodic committed Dec 14, 2023
1 parent 3fc2cb8 commit 89a9d86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.mullvad.mullvadvpn.ui

import android.Manifest
import android.app.Activity
import android.app.UiModeManager
import android.content.Intent
Expand Down Expand Up @@ -30,6 +29,7 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.dialog.ChangelogDialog
import net.mullvad.mullvadvpn.di.paymentModule
import net.mullvad.mullvadvpn.di.uiModule
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.getNotificationPermissionResource
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.isNotificationPermissionGranted
import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointConfiguration
import net.mullvad.mullvadvpn.lib.endpoint.getApiEndpointConfigurationExtras
Expand Down Expand Up @@ -334,7 +334,9 @@ open class MainActivity : FragmentActivity() {

private fun checkForNotificationPermission() {
if (isNotificationPermissionGranted().not()) {
requestNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
getNotificationPermissionResource()?.let {
requestNotificationPermissionLauncher.launch(it)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ object SdkUtils {
PackageManager.PERMISSION_GRANTED
}

fun getNotificationPermissionResource(): String? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Manifest.permission.POST_NOTIFICATIONS
} else null
}

fun Tile.setSubtitleIfSupported(subtitleText: CharSequence) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
this.subtitle = subtitleText
Expand Down

0 comments on commit 89a9d86

Please sign in to comment.