diff options
author | cyBerta <cyberta@riseup.net> | 2020-03-07 01:04:19 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2020-03-07 01:04:19 +0100 |
commit | 649635bc8f8178aba36f07b59ada813f55dc34a0 (patch) | |
tree | 45c5bff6f52b8aaff87d2cfc98f151d176bdefff | |
parent | 2a8d82d85f4cfd34143d87174ee022966e364f69 (diff) |
fix bluetooth tethering
3 files changed, 27 insertions, 6 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/firewall/SetupTetheringTask.java b/app/src/main/java/se/leap/bitmaskclient/firewall/SetupTetheringTask.java index 6ce8ee61..edf79add 100644 --- a/app/src/main/java/se/leap/bitmaskclient/firewall/SetupTetheringTask.java +++ b/app/src/main/java/se/leap/bitmaskclient/firewall/SetupTetheringTask.java @@ -147,18 +147,19 @@ public class SetupTetheringTask extends AsyncTask<Void, Boolean, Boolean> { return runBlockingCmd(addRules, log) == 0; } - private boolean removeBluetoothTetheringRules(TetheringState state, StringBuilder log) throws Exception { + private boolean addBluetoothTetheringRules(TetheringState state, StringBuilder log) throws Exception { Log.d(TAG, "add bluetooth tethering rules"); String[] addRules = getAdditionRules(state.bluetoothAddress, state.bluetoothInterface); return runBlockingCmd(addRules, log) == 0; } - private boolean addBluetoothTetheringRules(TetheringState state, StringBuilder log) throws Exception { + private boolean removeBluetoothTetheringRules(TetheringState state, StringBuilder log) throws Exception { Log.d(TAG, "remove bluetooth tethering rules"); String[] addRules = getDeletionRules(state, state.lastSeenBluetoothAddress, state.lastSeenBluetoothInterface); return runBlockingCmd(addRules, log) == 0; } + private String[] getAdditionRules(String addressRange, String interfaceName) { return new String[] { "su", 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 75d29417..9bca25e9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringObservable.java +++ b/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringObservable.java @@ -91,9 +91,16 @@ public class TetheringObservable extends Observable { } } - static void setBluetoothTethering(boolean enabled) { - if (getInstance().tetheringState.isBluetoothTetheringEnabled != enabled) { - getInstance().tetheringState.isBluetoothTetheringEnabled = enabled; + static void setBluetoothTethering(boolean enabled, @NonNull String address, @NonNull String interfaceName) { + if (getInstance().tetheringState.isBluetoothTetheringEnabled != enabled || + !getInstance().tetheringState.bluetoothAddress.equals(address) || + !getInstance().tetheringState.bluetoothInterface.equals(interfaceName)) { + TetheringState state = getInstance().tetheringState; + state.isBluetoothTetheringEnabled = enabled; + state.bluetoothAddress = address; + state.bluetoothInterface = interfaceName; + state.lastSeenBluetoothAddress = address.isEmpty() ? state.lastSeenBluetoothAddress : address; + state.lastSeenBluetoothInterface = interfaceName.isEmpty() ? state.lastSeenBluetoothInterface : interfaceName; getInstance().setChanged(); getInstance().notifyObservers(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringStateManager.java b/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringStateManager.java index 1a11945b..0af4c357 100644 --- a/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringStateManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringStateManager.java @@ -85,7 +85,7 @@ public class TetheringStateManager { } static void updateBluetoothTetheringState() { - TetheringObservable.setBluetoothTethering(isBluetoothTetheringEnabled()); + TetheringObservable.setBluetoothTethering(isBluetoothTetheringEnabled(), getBluetoothAddressRange(), getBluetoothInterfaceName()); } private static String getWifiAddressRange() { @@ -98,6 +98,11 @@ public class TetheringStateManager { return getAddressRange(interfaceAddress); } + private static String getBluetoothAddressRange() { + String interfaceAddress = getInterfaceAddress(getBluetoothInterface()); + return getAddressRange(interfaceAddress); + } + private static String getWlanInterfaceName() { return getInterfaceName(getWlanInterface()); } @@ -106,6 +111,10 @@ public class TetheringStateManager { return getInterfaceName(getUsbInterface()); } + private static String getBluetoothInterfaceName() { + return getInterfaceName(getBluetoothInterface()); + } + private static NetworkInterface getWlanInterface() { return getNetworkInterface(new String[]{"wlan", "eth"}); } @@ -114,6 +123,10 @@ public class TetheringStateManager { return getNetworkInterface(new String[]{"rndis"}); } + private static NetworkInterface getBluetoothInterface() { + return getNetworkInterface(new String[]{"bt-pan"}); + } + private static boolean isBluetoothTetheringEnabled() { StringBuilder log = new StringBuilder(); boolean hasBtPan = false; |