Skip to content

Commit

Permalink
Merge branch 'notification-permission-api-check-droid-386'
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Jan 12, 2024
2 parents 2f05885 + 0dd07d9 commit 3b33f3f
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 121 deletions.
50 changes: 3 additions & 47 deletions android/app/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<issues format="6" by="lint 8.1.4" type="baseline" client="gradle" dependencies="false" name="AGP (8.1.4)" variant="all" version="8.1.4">

<issue
id="MissingSuperCall"
Expand All @@ -8,43 +8,10 @@
errorLine2=" ~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt"
line="134"
line="70"
column="18"/>
</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="357"
column="58"/>
</issue>

<issue
id="RedundantLabel"
message="Redundant label can be removed"
errorLine1=" android:label=&quot;@string/app_name&quot;"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/debug/AndroidManifest.xml"
line="21"
column="13"/>
</issue>

<issue
id="RedundantLabel"
message="Redundant label can be removed"
errorLine1=" android:label=&quot;@string/app_name&quot;"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/AndroidManifest.xml"
line="33"
column="19"/>
</issue>

<issue
id="UseCheckPermission"
message="The result of `checkPermission` is not used"
Expand All @@ -63,7 +30,7 @@
errorLine2=" ~~~~~">
<location
file="src/main/AndroidManifest.xml"
line="23"
line="25"
column="39"/>
</issue>

Expand All @@ -78,15 +45,4 @@
column="22"/>
</issue>

<issue
id="MergeRootFrame"
message="This `&lt;FrameLayout>` can be replaced with a `&lt;merge>` tag"
errorLine1="&lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;"
errorLine2="^">
<location
file="src/main/res/layout/main.xml"
line="1"
column="1"/>
</issue>

</issues>
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.content.Intent
import android.net.VpnService
Expand All @@ -13,7 +12,7 @@ import androidx.core.view.WindowCompat
import net.mullvad.mullvadvpn.compose.screen.MullvadApp
import net.mullvad.mullvadvpn.di.paymentModule
import net.mullvad.mullvadvpn.di.uiModule
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.isNotificationPermissionGranted
import net.mullvad.mullvadvpn.lib.common.util.SdkUtils.requestNotificationPermissionIfMissing
import net.mullvad.mullvadvpn.lib.endpoint.getApiEndpointConfigurationExtras
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.repository.AccountRepository
Expand Down Expand Up @@ -61,7 +60,7 @@ class MainActivity : ComponentActivity() {
}

fun initializeStateHandlerAndServiceConnection() {
checkForNotificationPermission()
requestNotificationPermissionIfMissing(requestNotificationPermissionLauncher)
serviceConnectionManager.bind(
vpnPermissionRequestHandler = ::requestVpnPermission,
apiEndpointConfiguration = intent?.getApiEndpointConfigurationExtras()
Expand Down Expand Up @@ -101,10 +100,4 @@ class MainActivity : ComponentActivity() {

startActivityForResult(intent, 0)
}

private fun checkForNotificationPermission() {
if (isNotificationPermissionGranted().not()) {
requestNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}
}
2 changes: 1 addition & 1 deletion android/lib/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ android {

lint {
lintConfig = file("${rootProject.projectDir}/config/lint.xml")
baseline = file("lint-baseline.xml")
abortOnError = true
warningsAsErrors = true
}
Expand All @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions android/lib/common/lint-baseline.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
85 changes: 43 additions & 42 deletions android/lib/resource/lint-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<issues format="6" by="lint 8.1.4" type="baseline" client="gradle" dependencies="false" name="AGP (8.1.4)" variant="all" version="8.1.4">

<issue
id="ImpliedQuantity"
Expand Down Expand Up @@ -70,154 +70,154 @@
<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a un jour&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>Les crédits du compte expirent dans un jour&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-fr/plurals.xml"
line="16"
line="24"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;> um dia&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>O crédito da conta expira dentro de um dia&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-pt/plurals.xml"
line="16"
line="24"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a une minute&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>Les crédits du compte expirent dans une heure&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-fr/plurals.xml"
line="20"
line="28"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>há um minuto&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>O crédito da conta expira dentro de uma hora&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-pt/plurals.xml"
line="20"
line="28"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a un mois&lt;/item>"
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a un jour&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-fr/plurals.xml"
line="24"
line="32"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>há um mês&lt;/item>"
errorLine1=" &lt;item quantity=&quot;one&quot;>há um dia&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-pt/plurals.xml"
line="24"
line="32"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a un an&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a une minute&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-fr/plurals.xml"
line="28"
line="36"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>há um ano&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>há um minuto&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-pt/plurals.xml"
line="28"
line="36"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a une heure&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a un mois&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-fr/plurals.xml"
line="32"
line="40"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>há uma hora&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>há um mês&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-pt/plurals.xml"
line="32"
line="40"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>Les crédits du compte expirent dans un jour&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a un an&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-fr/plurals.xml"
line="36"
line="44"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>O crédito da conta expira dentro de um dia&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>um ano&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-pt/plurals.xml"
line="36"
line="44"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>Les crédits du compte expirent dans une heure&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;>il y a une heure&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-fr/plurals.xml"
line="40"
line="48"
column="9"/>
</issue>

<issue
id="ImpliedQuantity"
message="The quantity `&apos;one&apos;` matches more than one specific number in this locale (0, 1), but the message did not \&#xA;include a formatting argument (such as `%d`). This is usually an internationalization error. See full issue \&#xA;explanation for more."
errorLine1=" &lt;item quantity=&quot;one&quot;>O crédito da conta expira dentro de uma hora&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
errorLine1=" &lt;item quantity=&quot;one&quot;> uma hora&lt;/item>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values-pt/plurals.xml"
line="40"
line="48"
column="9"/>
</issue>

Expand All @@ -235,7 +235,8 @@
errorLine2=" ~~~~~~~~~">
<location
file="src/main/res/drawable/account_history_remove_pressed.xml"
line="8"/>
line="7"
column="30"/>
</issue>

<issue
Expand Down
Loading

0 comments on commit 3b33f3f

Please sign in to comment.