diff --git a/app/src/main/java/cx/myth/zjuconnect/MyVpnService.java b/app/src/main/java/cx/myth/zjuconnect/MyVpnService.java index 4a9716c..4c7ef63 100644 --- a/app/src/main/java/cx/myth/zjuconnect/MyVpnService.java +++ b/app/src/main/java/cx/myth/zjuconnect/MyVpnService.java @@ -46,15 +46,21 @@ public int onStartCommand(Intent intent, int flags, int startId) { localBroadcastManager.sendBroadcast(new Intent("cx.myth.zjuconnect.LOGIN_SUCCEEDED")); - Builder builder = new Builder().addAddress(ip, 8).addRoute("10.0.0.0", 8).addDnsServer(dnsServer).setMtu(1400); - tun = builder.establish(); - - executors.submit(() -> { - Mobile.startStack(tun.getFd()); - localBroadcastManager.sendBroadcast(new Intent("cx.myth.zjuconnect.STACK_STOPPED")); - stop(); + try { + Builder builder = new Builder().addAddress(ip, 8).addRoute("10.0.0.0", 8).addDnsServer(dnsServer).setMtu(1400); + tun = builder.establish(); + + executors.submit(() -> { + Mobile.startStack(tun.getFd()); + localBroadcastManager.sendBroadcast(new Intent("cx.myth.zjuconnect.STACK_STOPPED")); + stop(); + stopSelf(); + }); + } catch (Exception e) { + e.printStackTrace(); + localBroadcastManager.sendBroadcast(new Intent("cx.myth.zjuconnect.LOGIN_FAILED")); stopSelf(); - }); + } }).start(); return START_STICKY;