Skip to content

Commit cec3940

Browse files
committed
Fixed an issue when VPN was not restarting after configuration change
1 parent ad87214 commit cec3940

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

app/src/main/java/io/github/krlvm/powertunnel/android/services/TunnelingVpnService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class TunnelingVpnService extends VpnService {
6868

6969
private ProxyManager proxy;
7070
private ParcelFileDescriptor vpn = null;
71+
private Intent disconnectBroadcast = null;
7172

7273
private static final boolean vpnResolveHosts = true;
7374

@@ -100,7 +101,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
100101
proxy = new ProxyManager(
101102
this,
102103
(status) -> {
103-
if (status == ProxyStatus.RUNNING) {
104+
System.out.println(" >>> GOT PROXY STATUS : " + status);
105+
if (status == ProxyStatus.RUNNING) {
104106
connect();
105107
} else if (status == ProxyStatus.NOT_RUNNING) {
106108
disconnect();
@@ -201,14 +203,17 @@ private void disconnect() {
201203
}
202204

203205
private void disconnect(Intent broadcast) {
204-
Log.i(LOG_TAG, "Stopping...");
205-
206+
if (disconnectBroadcast == null) {
207+
disconnectBroadcast = broadcast;
208+
}
206209
if(proxy != null) {
207210
if(proxy.isRunning()) {
208211
proxy.stop();
209212
}
210213
proxy = null;
214+
return;
211215
}
216+
// We need to wait until the proxy has stopped
212217
if (vpn != null) {
213218
try {
214219
jni_stop(vpn.getFd());
@@ -228,7 +233,8 @@ private void disconnect(Intent broadcast) {
228233
PowerTunnelService.STATUS = GlobalStatus.NOT_RUNNING;
229234
stopForeground(true);
230235

231-
sendBroadcast(broadcast);
236+
sendBroadcast(disconnectBroadcast);
237+
disconnectBroadcast = null;
232238
BootReceiver.rememberState(this, false);
233239
}
234240

0 commit comments

Comments
 (0)