diff options
author | cyberta <cyberta@riseup.net> | 2020-01-25 14:40:13 -0600 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2020-01-25 14:40:13 -0600 |
commit | 20f906ef16d10d7f69a7355bd590ae99cb64723b (patch) | |
tree | 7ac1f22830665496ff742b097f53d5b73ba3c74f /app/src/main/java/se | |
parent | e29188b051aa57939e56d5fc9110eddb1d9a4bdf (diff) |
add and remove configuring tethering rules on vpn start and shutdown
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java | 35 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/firewall/ShutdownIPv6FirewallTask.java (renamed from app/src/main/java/se/leap/bitmaskclient/firewall/ShutdownFirewallTask.java) | 4 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/firewall/StartIPv6FirewallTask.java (renamed from app/src/main/java/se/leap/bitmaskclient/firewall/StartFirewallTask.java) | 4 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/tethering/TetheringObservable.java | 4 |
4 files changed, 36 insertions, 11 deletions
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 ce402ef8..78166671 100644 --- a/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/firewall/FirewallManager.java @@ -19,6 +19,7 @@ package se.leap.bitmaskclient.firewall; import android.content.Context; import de.blinkt.openvpn.core.VpnStatus; +import se.leap.bitmaskclient.tethering.TetheringObservable; import se.leap.bitmaskclient.tethering.TetheringState; import se.leap.bitmaskclient.utils.PreferenceHelper; @@ -72,14 +73,24 @@ public class FirewallManager implements FirewallCallback { } - public void startFirewall() { - StartFirewallTask task = new StartFirewallTask(this); - task.execute(); + public void start() { + startIPv6Firewall(); + if (TetheringObservable.getInstance().hasAnyTetheringEnabled()) { + TetheringState deviceTethering = TetheringObservable.getInstance().getTetheringState(); + TetheringState vpnTethering = new TetheringState(); + vpnTethering.isWifiTetheringEnabled = deviceTethering.isWifiTetheringEnabled && PreferenceHelper.getWifiTethering(context); + vpnTethering.isUsbTetheringEnabled = deviceTethering.isUsbTetheringEnabled && PreferenceHelper.getUsbTethering(context); + vpnTethering.isBluetoothTetheringEnabled = deviceTethering.isBluetoothTetheringEnabled && PreferenceHelper.getBluetoothTethering(context); + configureTethering(vpnTethering); + } } - - public void shutdownFirewall() { - ShutdownFirewallTask task = new ShutdownFirewallTask(this); - task.execute(); + public void stop() { + shutdownIPv6Firewall(); + TetheringState allowedTethering = new TetheringState(); + allowedTethering.isWifiTetheringEnabled = PreferenceHelper.getWifiTethering(context); + allowedTethering.isUsbTetheringEnabled = PreferenceHelper.getUsbTethering(context); + allowedTethering.isBluetoothTetheringEnabled = PreferenceHelper.getBluetoothTethering(context); + configureTethering(allowedTethering); } public void configureTethering(TetheringState state) { @@ -87,4 +98,14 @@ public class FirewallManager implements FirewallCallback { task.execute(state); } + private void startIPv6Firewall() { + StartIPv6FirewallTask task = new StartIPv6FirewallTask(this); + task.execute(); + } + + private void shutdownIPv6Firewall() { + ShutdownIPv6FirewallTask task = new ShutdownIPv6FirewallTask(this); + task.execute(); + } + } diff --git a/app/src/main/java/se/leap/bitmaskclient/firewall/ShutdownFirewallTask.java b/app/src/main/java/se/leap/bitmaskclient/firewall/ShutdownIPv6FirewallTask.java index 50fa77cd..dbdbf769 100644 --- a/app/src/main/java/se/leap/bitmaskclient/firewall/ShutdownFirewallTask.java +++ b/app/src/main/java/se/leap/bitmaskclient/firewall/ShutdownIPv6FirewallTask.java @@ -8,11 +8,11 @@ import java.lang.ref.WeakReference; import static se.leap.bitmaskclient.firewall.FirewallManager.BITMASK_CHAIN; import static se.leap.bitmaskclient.utils.Cmd.runBlockingCmd; -class ShutdownFirewallTask extends AsyncTask<Void, Boolean, Boolean> { +class ShutdownIPv6FirewallTask extends AsyncTask<Void, Boolean, Boolean> { private WeakReference<FirewallCallback> callbackWeakReference; - ShutdownFirewallTask(FirewallCallback callback) { + ShutdownIPv6FirewallTask(FirewallCallback callback) { callbackWeakReference = new WeakReference<>(callback); } diff --git a/app/src/main/java/se/leap/bitmaskclient/firewall/StartFirewallTask.java b/app/src/main/java/se/leap/bitmaskclient/firewall/StartIPv6FirewallTask.java index 3bf6d684..1dbfb9f8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/firewall/StartFirewallTask.java +++ b/app/src/main/java/se/leap/bitmaskclient/firewall/StartIPv6FirewallTask.java @@ -8,11 +8,11 @@ import java.lang.ref.WeakReference; import static se.leap.bitmaskclient.firewall.FirewallManager.BITMASK_CHAIN; import static se.leap.bitmaskclient.utils.Cmd.runBlockingCmd; -class StartFirewallTask extends AsyncTask<Void, Boolean, Boolean> { +class StartIPv6FirewallTask extends AsyncTask<Void, Boolean, Boolean> { private WeakReference<FirewallCallback> callbackWeakReference; - StartFirewallTask(FirewallCallback callback) { + StartIPv6FirewallTask(FirewallCallback callback) { callbackWeakReference = new WeakReference<>(callback); } diff --git a/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringObservable.java b/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringObservable.java index fc06ee12..79c1ec6d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringObservable.java +++ b/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringObservable.java @@ -67,4 +67,8 @@ public class TetheringObservable extends Observable { public TetheringState getTetheringState() { return tetheringState; } + + public boolean hasAnyTetheringEnabled() { + return tetheringState.isBluetoothTetheringEnabled || tetheringState.isUsbTetheringEnabled || tetheringState.isWifiTetheringEnabled; + } } |