Skip to content

Commit

Permalink
Fix InlinedApi lint issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sabercodic committed Oct 9, 2023
1 parent 817866f commit c3a4f91
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
11 changes: 0 additions & 11 deletions android/app/lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,6 @@
column="74"/>
</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 @@ -32,6 +31,7 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.dialog.ChangelogDialog
import net.mullvad.mullvadvpn.di.uiModule
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.isNotificationPermissionGranted
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.requestNotificationPermission
import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointConfiguration
import net.mullvad.mullvadvpn.lib.endpoint.getApiEndpointConfigurationExtras
import net.mullvad.mullvadvpn.lib.theme.AppTheme
Expand Down Expand Up @@ -352,7 +352,7 @@ open class MainActivity : FragmentActivity() {

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

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

fun Context.requestNotificationPermission(requestPermission: (String) -> Unit) {
if (
(Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) &&
checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) ==
PackageManager.PERMISSION_GRANTED
) {
requestPermission(Manifest.permission.POST_NOTIFICATIONS)
}
}

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

0 comments on commit c3a4f91

Please sign in to comment.