Skip to content

Commit 6f65067

Browse files
committed
remove requirement to draw over other apps
1 parent 4ba8794 commit 6f65067

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

ui/src/main/AndroidManifest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<uses-permission android:name="android.permission.INTERNET" />
88
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
99
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
10-
<uses-permission
11-
android:name="android.permission.SYSTEM_ALERT_WINDOW"
12-
android:minSdkVersion="34" />
1310
<uses-permission
1411
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
1512
android:maxSdkVersion="28"

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.wireguard.android
66

77
import android.app.PendingIntent
8+
import android.content.Context
89
import android.content.Intent
910
import android.graphics.Bitmap
1011
import android.graphics.Canvas
@@ -52,6 +53,7 @@ class QuickTileService : TileService() {
5253
}
5354

5455
override fun onClick() {
56+
updateTile()
5557
when (val tunnel = tunnel) {
5658
null -> {
5759
val intent = Intent(this, MainActivity::class.java)
@@ -64,21 +66,22 @@ class QuickTileService : TileService() {
6466
}
6567
}
6668
else -> {
69+
Log.e("TAG", "click")
6770
unlockAndRun {
6871
applicationScope.launch {
6972
try {
7073
tunnel.setStateAsync(Tunnel.State.TOGGLE)
7174
updateTile()
7275
} catch (_: Throwable) {
73-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !Settings.canDrawOverlays(this@QuickTileService)) {
74-
val permissionIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName"))
75-
permissionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
76-
startActivityAndCollapse(PendingIntent.getActivity(this@QuickTileService, 0, permissionIntent, PendingIntent.FLAG_IMMUTABLE))
77-
return@launch
76+
Log.e("TAG", "click?")
77+
val intent = Intent(this@QuickTileService, TunnelToggleActivity::class.java)
78+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
79+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
80+
startActivityAndCollapse(PendingIntent.getActivity(this@QuickTileService, 0, intent, PendingIntent.FLAG_IMMUTABLE))
81+
} else {
82+
@Suppress("DEPRECATION")
83+
startActivity(intent)
7884
}
79-
val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java)
80-
toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
81-
startActivity(toggleIntent)
8285
}
8386
}
8487
}
@@ -133,7 +136,7 @@ class QuickTileService : TileService() {
133136
isAdded = false
134137
}
135138

136-
private fun updateTile() {
139+
private fun updateTile(isConnecting: Boolean = false) {
137140
// Update the tunnel.
138141
val newTunnel = Application.getTunnelManager().lastUsedTunnel
139142
if (newTunnel != tunnel) {
@@ -148,6 +151,12 @@ class QuickTileService : TileService() {
148151
null -> {
149152
tile.label = getString(R.string.app_name)
150153
tile.state = Tile.STATE_INACTIVE
154+
if(isConnecting) {
155+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
156+
tile.subtitle = getString(R.string.quick_settings_tile_connecting)
157+
tile.state = Tile.STATE_ACTIVE
158+
}
159+
}
151160
tile.icon = iconOff
152161
}
153162
else -> {

ui/src/main/java/com/wireguard/android/activity/TunnelToggleActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TunnelToggleActivity : AppCompatActivity() {
4848

4949
override fun onCreate(savedInstanceState: Bundle?) {
5050
super.onCreate(savedInstanceState)
51+
moveTaskToBack(true)
5152
lifecycleScope.launch {
5253
if (Application.getBackend() is GoBackend) {
5354
val intent = GoBackend.VpnService.prepare(this@TunnelToggleActivity)

ui/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,5 @@
257257
<string name="biometric_prompt_private_key_title">Authenticate to view private key</string>
258258
<string name="biometric_auth_error">Authentication failure</string>
259259
<string name="biometric_auth_error_reason">Authentication failure: %s</string>
260+
<string name="quick_settings_tile_connecting">Connecting…</string>
260261
</resources>

ui/src/main/res/values/styles.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@
3333
<item name="android:windowBackground">@android:color/transparent</item>
3434
<item name="android:background">@android:color/transparent</item>
3535
<item name="colorPrimaryDark">@android:color/transparent</item>
36-
<item name="android:backgroundDimEnabled">true</item>
36+
<item name="android:backgroundDimEnabled">false</item>
3737
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
3838
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
39+
<item name="android:windowIsFloating">true</item>
40+
<item name="android:colorBackgroundCacheHint">@null</item>
41+
3942
</style>
4043

4144
<style name="TvTheme" parent="AppTheme">

0 commit comments

Comments
 (0)