summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2022-07-19 19:01:49 +0000
committercyberta <cyberta@riseup.net>2022-07-19 19:01:49 +0000
commitb6ff36e721a91621b49632a1ef5cefc9bb2506d8 (patch)
tree5aab488eff3c87fdf4ad4c33660f070d3b3ad24b /app/src/main
parent6bc3a79e6d09a8fa1857f1d502a87c1c0633be35 (diff)
parent5b244cd71989b504d70936ce5575dc947cb5ab6b (diff)
Merge branch 'hide_experimental_vpn_tethering_on_calyx_os' into 'master'
hide tethering option on CalyxOS 11 (SDK 30) Closes #9088 See merge request leap/bitmask_android!199
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java7
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/SystemPropertiesHelper.java36
4 files changed, 52 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java b/app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java
index 6c8e3115..3f73e49d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/BitmaskApp.java
@@ -43,6 +43,7 @@ import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES;
import static se.leap.bitmaskclient.appUpdate.DownloadBroadcastReceiver.ACTION_DOWNLOAD;
import static se.leap.bitmaskclient.appUpdate.DownloadServiceCommand.CHECK_VERSION_FILE;
import static se.leap.bitmaskclient.appUpdate.DownloadServiceCommand.DOWNLOAD_UPDATE;
+import static se.leap.bitmaskclient.base.utils.ConfigHelper.isCalyxOSWithTetheringSupport;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getSavedProviderFromSharedPreferences;
/**
@@ -75,7 +76,9 @@ public class BitmaskApp extends MultiDexApplication {
torStatusObservable = TorStatusObservable.getInstance();
EipSetupObserver.init(this, preferences);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
- TetheringStateManager.getInstance().init(this);
+ if (!isCalyxOSWithTetheringSupport(this)) {
+ TetheringStateManager.getInstance().init(this);
+ }
if (BuildConfig.FLAVOR.contains("Fatweb")) {
downloadBroadcastReceiver = new DownloadBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter(BROADCAST_DOWNLOAD_SERVICE_EVENT);
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java
index 94f737b4..9d15f839 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java
@@ -11,6 +11,7 @@ import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES;
import static se.leap.bitmaskclient.base.models.Constants.USE_IPv6_FIREWALL;
import static se.leap.bitmaskclient.base.utils.ConfigHelper.ObfsVpnHelper.useObfsVpn;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.allowExperimentalTransports;
+import static se.leap.bitmaskclient.base.utils.ConfigHelper.isCalyxOSWithTetheringSupport;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferUDP;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getShowAlwaysOnDialog;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges;
@@ -213,6 +214,12 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh
private void initTetheringEntry(View rootView) {
tethering = rootView.findViewById(R.id.tethering);
+
+ if (isCalyxOSWithTetheringSupport(this.getContext())) {
+ tethering.setVisibility(GONE);
+ return;
+ }
+
tethering.setOnClickListener((buttonView) -> {
showTetheringAlert();
});
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
index 8ac5baf0..102756c4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
@@ -273,6 +273,11 @@ public class ConfigHelper {
Matcher matcher = IPv4_PATTERN.matcher(ipv4);
return matcher.matches();
}
+
+ public static boolean isCalyxOSWithTetheringSupport(Context context) {
+ return SystemPropertiesHelper.contains("ro.calyxos.version", context) &&
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.R;
+ }
// ObfsVpnHelper class allows us to mock BuildConfig.use_obfsvpn while
// not mocking the whole ConfigHelper class
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/SystemPropertiesHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/SystemPropertiesHelper.java
new file mode 100644
index 00000000..b148f685
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/SystemPropertiesHelper.java
@@ -0,0 +1,36 @@
+package se.leap.bitmaskclient.base.utils;
+
+import android.content.Context;
+
+import java.lang.reflect.Method;
+
+
+public class SystemPropertiesHelper {
+
+ /**
+ * Checks if SystemProperties contains a given key using reflection
+ * @return true if reflection was successful and the key was found
+ */
+ public static boolean contains(String key, Context context) {
+ String result = null;
+ try {
+ ClassLoader cl = context.getClassLoader();
+ @SuppressWarnings("rawtypes")
+ Class SystemProperties = cl.loadClass("android.os.SystemProperties");
+ @SuppressWarnings("rawtypes")
+ Class[] paramTypes= new Class[1];
+ paramTypes[0]= String.class;
+
+ Method get = SystemProperties.getMethod("get", paramTypes);
+ Object[] params= new Object[1];
+ params[0]= key;
+
+ result = (String) get.invoke(SystemProperties, params);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return result != null;
+ }
+}
+