summaryrefslogtreecommitdiffhomepage
path: root/android/lib/common
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2024-01-12 10:33:54 +0100
committerAlbin <albin@mullvad.net>2024-01-12 10:33:54 +0100
commit3b33f3f1bd5a137ed8b898c62e78a3745a7a9897 (patch)
tree325f82725bc5acecdb7c2439308ffa2f5f492fd4 /android/lib/common
parent2f05885b58dadfe89bf9b683f1be65bb9f704f01 (diff)
parent0dd07d9ecb2cfeddfe9247b723f742cd3494c1ed (diff)
downloadmullvadvpn-3b33f3f1bd5a137ed8b898c62e78a3745a7a9897.tar.xz
mullvadvpn-3b33f3f1bd5a137ed8b898c62e78a3745a7a9897.zip
Merge branch 'notification-permission-api-check-droid-386'
Diffstat (limited to 'android/lib/common')
-rw-r--r--android/lib/common/build.gradle.kts2
-rw-r--r--android/lib/common/lint-baseline.xml15
-rw-r--r--android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/SdkUtils.kt15
3 files changed, 13 insertions, 19 deletions
diff --git a/android/lib/common/build.gradle.kts b/android/lib/common/build.gradle.kts
index ba33ab7db7..e327a8922c 100644
--- a/android/lib/common/build.gradle.kts
+++ b/android/lib/common/build.gradle.kts
@@ -19,7 +19,6 @@ android {
lint {
lintConfig = file("${rootProject.projectDir}/config/lint.xml")
- baseline = file("lint-baseline.xml")
abortOnError = true
warningsAsErrors = true
}
@@ -30,6 +29,7 @@ dependencies {
implementation(project(Dependencies.Mullvad.resourceLib))
implementation(project(Dependencies.Mullvad.talpidLib))
+ implementation(Dependencies.AndroidX.appcompat)
implementation(Dependencies.jodaTime)
implementation(Dependencies.Kotlin.stdlib)
implementation(Dependencies.KotlinX.coroutinesAndroid)
diff --git a/android/lib/common/lint-baseline.xml b/android/lib/common/lint-baseline.xml
deleted file mode 100644
index 141342d165..0000000000
--- a/android/lib/common/lint-baseline.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?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">
-
- <issue
- id="QueryAllPackagesPermission"
- message="A `&lt;queries>` declaration should generally be used instead of QUERY_ALL_PACKAGES; \&#xA;see https://g.co/dev/packagevisibility for details"
- errorLine1=" &lt;uses-permission android:name=&quot;android.permission.QUERY_ALL_PACKAGES&quot; />"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
- <location
- file="src/main/AndroidManifest.xml"
- line="3"
- column="22"/>
- </issue>
-
-</issues>
diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/SdkUtils.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/SdkUtils.kt
index fe9564c45d..92f97146f8 100644
--- a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/SdkUtils.kt
+++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/SdkUtils.kt
@@ -8,6 +8,8 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import android.service.quicksettings.Tile
+import androidx.activity.result.ActivityResultLauncher
+import androidx.annotation.ChecksSdkIntAtLeast
object SdkUtils {
fun getSupportedPendingIntentFlags(): Int {
@@ -22,12 +24,19 @@ object SdkUtils {
}
}
- fun Context.isNotificationPermissionGranted(): Boolean {
- return (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) ||
- checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) ==
+ @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU)
+ fun Context.isNotificationPermissionMissing(): Boolean {
+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) &&
+ checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) !=
PackageManager.PERMISSION_GRANTED
}
+ fun Context.requestNotificationPermissionIfMissing(launcher: ActivityResultLauncher<String>) {
+ if (isNotificationPermissionMissing()) {
+ launcher.launch(Manifest.permission.POST_NOTIFICATIONS)
+ }
+ }
+
fun Tile.setSubtitleIfSupported(subtitleText: CharSequence) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
this.subtitle = subtitleText