From 839055385062dc46f1b75b6497db7c09672b9e37 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 18 Oct 2023 13:34:29 +0200 Subject: [PATCH] QuickTileService: require SYSTEM_ALERT_WINDOW to start background activity Due to buggy changes in Android 14, we now need to bother the user about enabling "draw over other apps" for the quick settings toggle to work when the app isn't already running. Link: https://issuetracker.google.com/issues/305035828 Signed-off-by: Jason A. Donenfeld --- ui/src/main/AndroidManifest.xml | 3 +++ .../java/com/wireguard/android/QuickTileService.kt | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ui/src/main/AndroidManifest.xml b/ui/src/main/AndroidManifest.xml index 72617f3b..754992d5 100644 --- a/ui/src/main/AndroidManifest.xml +++ b/ui/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + = Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)) + startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)) } else { @Suppress("DEPRECATION") startActivityAndCollapse(intent) @@ -68,6 +70,12 @@ class QuickTileService : TileService() { tunnel.setStateAsync(Tunnel.State.TOGGLE) updateTile() } catch (_: Throwable) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !Settings.canDrawOverlays(this@QuickTileService)) { + val permissionIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName")) + permissionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + startActivityAndCollapse(PendingIntent.getActivity(this@QuickTileService, 0, permissionIntent, PendingIntent.FLAG_IMMUTABLE)) + return@launch + } val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java) toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) startActivity(toggleIntent)