Update application state based on wg-quick
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user