summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/backend
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-27 18:57:52 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-27 18:57:52 +0200
commit292df1217580fdda3592f59ed356bdb289564392 (patch)
treecf2ce12534656d1f5642116ce1d6402114579d4d /app/src/main/java/com/wireguard/android/backend
parentf988306c17a8acbc4e0c9784a99d63a16ad19950 (diff)
Support always-on-vpn
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/backend')
-rw-r--r--app/src/main/java/com/wireguard/android/backend/GoBackend.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/backend/GoBackend.java b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
index d11802f3..ffd05eae 100644
--- a/app/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -6,6 +6,7 @@
package com.wireguard.android.backend;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.ParcelFileDescriptor;
@@ -13,9 +14,11 @@ import android.support.v4.util.ArraySet;
import android.util.Log;
import com.wireguard.android.Application;
+import com.wireguard.android.activity.MainActivity;
import com.wireguard.android.model.Tunnel;
import com.wireguard.android.model.Tunnel.State;
import com.wireguard.android.model.Tunnel.Statistics;
+import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.config.Config;
import com.wireguard.config.IPCidr;
import com.wireguard.config.Interface;
@@ -158,6 +161,10 @@ public final class GoBackend implements Backend {
final VpnService.Builder builder = service.getBuilder();
builder.setSession(tunnel.getName());
+ final Intent configureIntent = new Intent(context, MainActivity.class);
+ configureIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ builder.setConfigureIntent(PendingIntent.getActivity(context, 0, configureIntent, 0));
+
for (final IPCidr addr : config.getInterface().getAddresses())
builder.addAddress(addr.getAddress(), addr.getCidr());
@@ -202,6 +209,7 @@ public final class GoBackend implements Backend {
}
private void startVpnService() {
+ Log.d(TAG, "Requesting to start VpnService");
context.startService(new Intent(context, VpnService.class));
}
@@ -225,5 +233,15 @@ public final class GoBackend implements Backend {
vpnService = vpnService.newIncompleteFuture();
super.onDestroy();
}
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ vpnService.complete(this);
+ if (intent == null || intent.getComponent() == null || !intent.getComponent().getPackageName().equals(getPackageName())) {
+ Log.d(TAG, "Service started by Always-on VPN feature");
+ Application.getComponent().getTunnelManager().restoreState(true).whenComplete(ExceptionLoggers.D);
+ }
+ return super.onStartCommand(intent, flags, startId);
+ }
}
}