diff --git a/tunnel/tools/libwg-go/go.mod b/tunnel/tools/libwg-go/go.mod index 9318ebcf1..9f9381fff 100644 --- a/tunnel/tools/libwg-go/go.mod +++ b/tunnel/tools/libwg-go/go.mod @@ -3,12 +3,12 @@ module golang.zx2c4.com/wireguard/android go 1.20 require ( - golang.org/x/sys v0.6.0 - golang.zx2c4.com/wireguard v0.0.0-20230223181233-21636207a675 + golang.org/x/sys v0.13.0 + golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb ) require ( - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/net v0.8.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect ) diff --git a/tunnel/tools/libwg-go/go.sum b/tunnel/tools/libwg-go/go.sum index 3b49b497d..e5f8fc830 100644 --- a/tunnel/tools/libwg-go/go.sum +++ b/tunnel/tools/libwg-go/go.sum @@ -1,10 +1,13 @@ -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg= golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI= -golang.zx2c4.com/wireguard v0.0.0-20230223181233-21636207a675 h1:/J/RVnr7ng4fWPRH3xa4WtBJ1Jp+Auu4YNLmGiPv5QU= -golang.zx2c4.com/wireguard v0.0.0-20230223181233-21636207a675/go.mod h1:whfbyDBt09xhCYQWtO2+3UVjlaq6/9hDZrjg2ZE6SyA= +golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb h1:c5tyN8sSp8jSDxdCCDXVOpJwYXXhmTkNMt+g0zTSOic= +golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb/go.mod h1:tkCQ4FQXmpAgYVh++1cq16/dH4QJtmvpRv19DWGAHSA= +gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 h1:TbRPT0HtzFP3Cno1zZo7yPzEEnfu8EjLfl6IU9VfqkQ= 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) @@ -70,15 +73,15 @@ 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 intent = Intent(this@QuickTileService, TunnelToggleActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + intent.putExtra(SHOW_PROGRESS, true) + 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..9e70f0768 100644 --- a/ui/src/main/java/com/wireguard/android/activity/TunnelToggleActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/TunnelToggleActivity.kt @@ -7,6 +7,7 @@ package com.wireguard.android.activity import android.content.ComponentName import android.os.Build import android.os.Bundle +import android.os.Handler import android.service.quicksettings.TileService import android.util.Log import android.widget.Toast @@ -24,6 +25,9 @@ import kotlinx.coroutines.launch @RequiresApi(Build.VERSION_CODES.N) class TunnelToggleActivity : AppCompatActivity() { + + private var mIsVisible = false + private val permissionActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { toggleTunnelWithPermissionsResult() } @@ -38,16 +42,23 @@ class TunnelToggleActivity : AppCompatActivity() { val message = getString(R.string.toggle_error, error) Log.e(TAG, message, e) Toast.makeText(this@TunnelToggleActivity, message, Toast.LENGTH_LONG).show() - finishAffinity() + exitActivity() return@launch } TileService.requestListeningState(this@TunnelToggleActivity, ComponentName(this@TunnelToggleActivity, QuickTileService::class.java)) - finishAffinity() + exitActivity() } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + + if(intent.getBooleanExtra(SHOW_PROGRESS, false)) { + mIsVisible = true + title = "" // Otherwise the apptitle will be shown above the spinner. + setContentView(R.layout.loading_activity) + } + lifecycleScope.launch { if (Application.getBackend() is GoBackend) { val intent = GoBackend.VpnService.prepare(this@TunnelToggleActivity) @@ -58,9 +69,29 @@ class TunnelToggleActivity : AppCompatActivity() { } toggleTunnelWithPermissionsResult() } + exitActivity() + } + + private fun exitActivity() { + /* + We add this delay, so that the user gets the impression we are actually doing something. + This is to make the transition of the closing quicktile-menu more palatable, + because startActivityAndCollapse() will immediately close that menu. + This can be jarring, so we show this placeholder spinner and close it after a second. + */ + + if(mIsVisible) { + Handler().postDelayed({ + finishAffinity() + }, 1000L) + } else { + finishAffinity() + } + } companion object { private const val TAG = "WireGuard/TunnelToggleActivity" + const val SHOW_PROGRESS = "ShowLoadingbar" } } diff --git a/ui/src/main/res/layout/loading_activity.xml b/ui/src/main/res/layout/loading_activity.xml new file mode 100644 index 000000000..0e322ef3d --- /dev/null +++ b/ui/src/main/res/layout/loading_activity.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + 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 +