diff options
-rw-r--r-- | app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java | 53 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java | 14 |
2 files changed, 33 insertions, 34 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 72962493..67d3c4f2 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -309,7 +309,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac return START_REDELIVER_INTENT; } - /* TODO: check that for Bitmask */ + /* TODO: check that for Bitmask */ // Always show notification here to avoid problem with startForeground timeout VpnStatus.logInfo(R.string.building_configration); VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START); @@ -449,14 +449,12 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac mProcessThread.start(); } - firewallManager.start(); - new Handler(getMainLooper()).post(() -> { - if (mDeviceStateReceiver != null) { - unregisterDeviceStateReceiver(); - } - registerDeviceStateReceiver(mManagement); - } + if (mDeviceStateReceiver != null) { + unregisterDeviceStateReceiver(); + } + registerDeviceStateReceiver(mManagement); + } ); } @@ -968,30 +966,25 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac String channel = NOTIFICATION_CHANNEL_NEWSTATUS_ID; // Display byte count only after being connected - { - if (level == LEVEL_CONNECTED) { - mDisplayBytecount = true; - mConnecttime = System.currentTimeMillis(); - if (!runningOnAndroidTV()) - channel = NOTIFICATION_CHANNEL_BG_ID; - } else { - mDisplayBytecount = false; - } + if (level == LEVEL_CONNECTED) { + mDisplayBytecount = true; + mConnecttime = System.currentTimeMillis(); + if (!runningOnAndroidTV()) + channel = NOTIFICATION_CHANNEL_BG_ID; + firewallManager.start(); + } else { + mDisplayBytecount = false; + } - // Other notifications are shown, - // This also mean we are no longer connected, ignore bytecount messages until next - // CONNECTED - // Does not work :( - notificationManager.buildOpenVpnNotification( - mProfile != null ? mProfile.mName : "", - mProfile != null && mProfile.mUsePluggableTransports, - VpnStatus.getLastCleanLogMessage(this), - VpnStatus.getLastCleanLogMessage(this), - level, - 0, - channel); + notificationManager.buildOpenVpnNotification( + mProfile != null ? mProfile.mName : "", + mProfile != null && mProfile.mUsePluggableTransports, + VpnStatus.getLastCleanLogMessage(this), + VpnStatus.getLastCleanLogMessage(this), + level, + 0, + channel); - } } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java b/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java index 67cc4625..30ecebea 100644 --- a/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java @@ -31,6 +31,7 @@ public class FirewallManager implements FirewallCallback, Observer { public static String BITMASK_FORWARD = "bitmask_forward"; public static String BITMASK_POSTROUTING = "bitmask_postrouting"; static final String TAG = FirewallManager.class.getSimpleName(); + private boolean isRunning = false; private Context context; @@ -91,14 +92,19 @@ public class FirewallManager implements FirewallCallback, Observer { public void start() { - startIPv6Firewall(); - TetheringState tetheringState = TetheringObservable.getInstance().getTetheringState(); - if (tetheringState.hasAnyDeviceTetheringEnabled() && tetheringState.hasAnyVpnTetheringAllowed()) { - startTethering(); + if (!isRunning) { + isRunning = true; + startIPv6Firewall(); + TetheringState tetheringState = TetheringObservable.getInstance().getTetheringState(); + if (tetheringState.hasAnyDeviceTetheringEnabled() && tetheringState.hasAnyVpnTetheringAllowed()) { + startTethering(); + } } + } public void stop() { + isRunning = false; stopIPv6Firewall(); stopTethering(); } |