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 4, 2023
1 parent 12dc193 commit 31f5672
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
16 changes: 2 additions & 14 deletions android/app/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.0.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.0.2)" variant="all" version="8.0.2">

<issues format="6" by="lint 8.1.0" type="baseline" client="gradle" dependencies="false" name="AGP (8.1.0)" variant="all" version="8.1.0">

<issue
id="MissingSuperCall"
Expand All @@ -9,7 +8,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt"
line="139"
line="134"
column="18"/>
</issue>

Expand All @@ -35,17 +34,6 @@
column="36"/>
</issue>

<issue
id="InlinedApi"
message="Field requires API level 33 (current min is 26): `android.Manifest.permission#POST_NOTIFICATIONS`"
errorLine1=" requestNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt"
line="359"
column="58"/>
</issue>

<issue
id="RedundantLabel"
message="Redundant label can be removed"
Expand Down
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 31f5672

Please sign in to comment.