Skip to content

Commit

Permalink
feat: Add try-catch at connection
Browse files Browse the repository at this point in the history
  • Loading branch information
oldkingOK committed Jul 28, 2024
1 parent a48d10f commit baa3489
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions app/src/main/java/cx/myth/zjuconnect/MyVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit baa3489

Please sign in to comment.