From e613966d352af1329f706fbc50959d301723ed7f Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 23 Nov 2015 08:34:47 +0100 Subject: [PATCH] Workaround handover problems --- app/app.iml | 3 +++ .../eu/faircode/netguard/SinkholeService.java | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/app.iml b/app/app.iml index 5e46a900..401abb40 100644 --- a/app/app.iml +++ b/app/app.iml @@ -66,6 +66,7 @@ + @@ -75,6 +76,8 @@ + + diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index 63bdced2..e7200f56 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -86,6 +86,9 @@ public class SinkholeService extends VpnService { public void handleMessage(Message msg) { try { handleIntent((Intent) msg.obj); + } catch (Throwable ex) { + Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); + Util.sendCrashReport(ex, SinkholeService.this); } finally { try { PowerManager.WakeLock wl = getLock(SinkholeService.this); @@ -116,6 +119,15 @@ public class SinkholeService extends VpnService { // Seamless handover ParcelFileDescriptor prev = vpn; vpn = startVPN(); + if (prev != null && vpn == null) { + Log.w(TAG, "Handover failed"); + stopDebug(); + stopVPN(prev); + prev = null; + vpn = startVPN(); + if (vpn == null) + throw new IllegalStateException("Handover failed"); + } stopDebug(); startDebug(vpn); if (prev != null) @@ -197,10 +209,7 @@ public class SinkholeService extends VpnService { // Start VPN service try { - ParcelFileDescriptor result = builder.establish(); - if (result == null) - throw new IllegalStateException("VpnService.Builder.establish returned unexpectedly NULL"); - return result; + return builder.establish(); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));