Skip to content

Commit 6be50ad

Browse files
committed
Fix trampoline activity launch on Android 14
In my opinion, it would be better to start a VPN Service as a foreground one, but I've seen(WireGuard#29) that you don't want additional permissions that come with it. Signed-off-by: Alexander Perfilyev <[email protected]>
1 parent db7f707 commit 6be50ad

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ui/src/main/java/com/wireguard/android/QuickTileService.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ class QuickTileService : TileService() {
5454
null -> {
5555
val intent = Intent(this, MainActivity::class.java)
5656
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
57-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
58-
startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE))
59-
} else {
60-
@Suppress("DEPRECATION")
61-
startActivityAndCollapse(intent)
62-
}
57+
startActivityCompat(intent)
6358
}
6459
else -> {
6560
unlockAndRun {
@@ -70,14 +65,23 @@ class QuickTileService : TileService() {
7065
} catch (_: Throwable) {
7166
val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java)
7267
toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
73-
startActivity(toggleIntent)
68+
startActivityCompat(toggleIntent)
7469
}
7570
}
7671
}
7772
}
7873
}
7974
}
8075

76+
private fun startActivityCompat(intent: Intent) {
77+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
78+
startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE))
79+
} else {
80+
@Suppress("DEPRECATION", "StartActivityAndCollapseDeprecated")
81+
startActivityAndCollapse(intent)
82+
}
83+
}
84+
8185
override fun onCreate() {
8286
isAdded = true
8387
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

0 commit comments

Comments
 (0)