From be6f7c2c7ae5764082d6ebd50e5bea2303a31813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Mon, 27 Nov 2023 22:18:58 +0100 Subject: [PATCH 1/3] remove requirement to draw over other apps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Felix Nüsse --- ui/src/main/AndroidManifest.xml | 3 --- .../com/wireguard/android/QuickTileService.kt | 27 ++++++++++++------- .../android/activity/TunnelToggleActivity.kt | 1 + ui/src/main/res/values/strings.xml | 1 + ui/src/main/res/values/styles.xml | 5 +++- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/ui/src/main/AndroidManifest.xml b/ui/src/main/AndroidManifest.xml index 754992d5d..72617f3b1 100644 --- a/ui/src/main/AndroidManifest.xml +++ b/ui/src/main/AndroidManifest.xml @@ -7,9 +7,6 @@ - { val intent = Intent(this, MainActivity::class.java) @@ -64,21 +66,22 @@ class QuickTileService : TileService() { } } else -> { + Log.e("TAG", "click") unlockAndRun { applicationScope.launch { try { 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 + Log.e("TAG", "click?") + val intent = Intent(this@QuickTileService, TunnelToggleActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + startActivityAndCollapse(PendingIntent.getActivity(this@QuickTileService, 0, intent, PendingIntent.FLAG_IMMUTABLE)) + } else { + @Suppress("DEPRECATION") + startActivity(intent) } - val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java) - toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - startActivity(toggleIntent) } } } @@ -133,7 +136,7 @@ class QuickTileService : TileService() { isAdded = false } - private fun updateTile() { + private fun updateTile(isConnecting: Boolean = false) { // Update the tunnel. val newTunnel = Application.getTunnelManager().lastUsedTunnel if (newTunnel != tunnel) { @@ -148,6 +151,12 @@ class QuickTileService : TileService() { null -> { tile.label = getString(R.string.app_name) tile.state = Tile.STATE_INACTIVE + if(isConnecting) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + tile.subtitle = getString(R.string.quick_settings_tile_connecting) + tile.state = Tile.STATE_ACTIVE + } + } tile.icon = iconOff } else -> { diff --git a/ui/src/main/java/com/wireguard/android/activity/TunnelToggleActivity.kt b/ui/src/main/java/com/wireguard/android/activity/TunnelToggleActivity.kt index 59b9349f5..1142e8b08 100644 --- a/ui/src/main/java/com/wireguard/android/activity/TunnelToggleActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/TunnelToggleActivity.kt @@ -48,6 +48,7 @@ class TunnelToggleActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + moveTaskToBack(true) lifecycleScope.launch { if (Application.getBackend() is GoBackend) { val intent = GoBackend.VpnService.prepare(this@TunnelToggleActivity) diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index df3d33406..c3a849a53 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -257,4 +257,5 @@ Authenticate to view private key Authentication failure Authentication failure: %s + Connecting… diff --git a/ui/src/main/res/values/styles.xml b/ui/src/main/res/values/styles.xml index 39c382478..120886c2a 100644 --- a/ui/src/main/res/values/styles.xml +++ b/ui/src/main/res/values/styles.xml @@ -33,9 +33,12 @@ @android:color/transparent @android:color/transparent @android:color/transparent - true + false @android:anim/fade_in @android:anim/fade_out + true + @null +