5
5
package com.wireguard.android
6
6
7
7
import android.app.PendingIntent
8
+ import android.content.Context
8
9
import android.content.Intent
9
10
import android.graphics.Bitmap
10
11
import android.graphics.Canvas
@@ -52,6 +53,7 @@ class QuickTileService : TileService() {
52
53
}
53
54
54
55
override fun onClick () {
56
+ updateTile()
55
57
when (val tunnel = tunnel) {
56
58
null -> {
57
59
val intent = Intent (this , MainActivity ::class .java)
@@ -64,21 +66,22 @@ class QuickTileService : TileService() {
64
66
}
65
67
}
66
68
else -> {
69
+ Log .e(" TAG" , " click" )
67
70
unlockAndRun {
68
71
applicationScope.launch {
69
72
try {
70
73
tunnel.setStateAsync(Tunnel .State .TOGGLE )
71
74
updateTile()
72
75
} 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)
78
84
}
79
- val toggleIntent = Intent (this @QuickTileService, TunnelToggleActivity ::class .java)
80
- toggleIntent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
81
- startActivity(toggleIntent)
82
85
}
83
86
}
84
87
}
@@ -133,7 +136,7 @@ class QuickTileService : TileService() {
133
136
isAdded = false
134
137
}
135
138
136
- private fun updateTile () {
139
+ private fun updateTile (isConnecting : Boolean = false ) {
137
140
// Update the tunnel.
138
141
val newTunnel = Application .getTunnelManager().lastUsedTunnel
139
142
if (newTunnel != tunnel) {
@@ -148,6 +151,12 @@ class QuickTileService : TileService() {
148
151
null -> {
149
152
tile.label = getString(R .string.app_name)
150
153
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
+ }
151
160
tile.icon = iconOff
152
161
}
153
162
else -> {
0 commit comments