summaryrefslogtreecommitdiffhomepage
path: root/app/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-04-23 16:37:42 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-04-23 17:04:17 +0200
commit88cf839c90e59823c4fee1e70e5525b943287a10 (patch)
tree2cb5400b7cd61944d7c7a3f843dd1c7e1502dc8c /app/src
parenta1c6f4b3b74aec0224045d9cd5f3345c4773919d (diff)
Update application state based on wg-quick
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/AndroidManifest.xml7
-rw-r--r--app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java11
-rw-r--r--app/src/main/java/com/wireguard/android/model/TunnelManager.java9
-rw-r--r--app/src/main/java/com/wireguard/android/util/RootShell.java2
4 files changed, 27 insertions, 2 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d42eabdc..096ec08b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -43,13 +43,18 @@
android:parentActivityName=".activity.MainActivity" />
<receiver android:name=".BootShutdownReceiver">
-
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
+ <receiver android:name=".backend.WgQuickBackend$WgQuickChangeReceiver">
+ <intent-filter>
+ <action android:name="com.wireguard.android.WGQUICK_CHANGE" />
+ </intent-filter>
+ </receiver>
+
<service
android:name=".backend.GoBackend$VpnService"
android:permission="android.permission.BIND_VPN_SERVICE" >
diff --git a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
index 760aac85..a0371842 100644
--- a/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
+++ b/app/src/main/java/com/wireguard/android/backend/WgQuickBackend.java
@@ -1,8 +1,11 @@
package com.wireguard.android.backend;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
import android.util.Log;
+import com.wireguard.android.Application;
import com.wireguard.android.model.Tunnel;
import com.wireguard.android.model.Tunnel.State;
import com.wireguard.android.model.Tunnel.Statistics;
@@ -111,4 +114,12 @@ public final class WgQuickBackend implements Backend {
if (result != 0)
throw new Exception("Unable to configure tunnel (wg-quick returned " + result + ')');
}
+
+ public final static class WgQuickChangeReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.d(TAG, "Refreshing tunnel states");
+ Application.getComponent().getTunnelManager().refreshTunnelStates();
+ }
+ }
}
diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java
index 381e7f77..61468920 100644
--- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java
+++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java
@@ -128,6 +128,15 @@ public final class TunnelManager extends BaseObservable {
return tunnels;
}
+ public void refreshTunnelStates() {
+ asyncWorker.supplyAsync(backend::enumerate)
+ .thenAccept(running -> {
+ for (final Tunnel tunnel : tunnels)
+ tunnel.onStateChanged(running.contains(tunnel.getName()) ? State.UP : State.DOWN);
+ })
+ .whenComplete(ExceptionLoggers.E);
+ }
+
public void onCreate() {
asyncWorker.supplyAsync(configStore::enumerate)
.thenAcceptBoth(asyncWorker.supplyAsync(backend::enumerate), this::onTunnelsLoaded)
diff --git a/app/src/main/java/com/wireguard/android/util/RootShell.java b/app/src/main/java/com/wireguard/android/util/RootShell.java
index 9e487a31..d24f6051 100644
--- a/app/src/main/java/com/wireguard/android/util/RootShell.java
+++ b/app/src/main/java/com/wireguard/android/util/RootShell.java
@@ -44,7 +44,7 @@ public class RootShell {
final File cacheDir = context.getCacheDir();
localBinaryDir = new File(cacheDir, "bin");
localTemporaryDir = new File(cacheDir, "tmp");
- preamble = String.format("export PATH=\"%s:$PATH\" TMPDIR='%s'; id -u\n",
+ preamble = String.format("export CALLING_PACKAGE=com.wireguard.android; export PATH=\"%s:$PATH\" TMPDIR='%s'; id -u\n",
localBinaryDir, localTemporaryDir);
}