Skip to content

Commit

Permalink
Fix trampoline activity launch on Android 14
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aperfilyev committed Oct 16, 2023
1 parent db7f707 commit d3377f9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ui/src/main/java/com/wireguard/android/QuickTileService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ class QuickTileService : TileService() {
null -> {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE))
} else {
@Suppress("DEPRECATION")
startActivityAndCollapse(intent)
}
startActivityCompat(intent)
}
else -> {
unlockAndRun {
Expand All @@ -70,14 +65,23 @@ class QuickTileService : TileService() {
} catch (_: Throwable) {
val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java)
toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(toggleIntent)
startActivityCompat(toggleIntent)
}
}
}
}
}
}

private fun startActivityCompat(intent: Intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE))
} else {
@Suppress("DEPRECATION", "StartActivityAndCollapseDeprecated")
startActivityAndCollapse(intent)
}
}

override fun onCreate() {
isAdded = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Expand Down

0 comments on commit d3377f9

Please sign in to comment.