From 53673dae75b168cc555a01dc0e4f35ab9c6f1169 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Sun, 4 May 2014 00:35:14 -0400 Subject: [PATCH] fix bridge/PT enable code based on bridge types --- src/org/torproject/android/TorConstants.java | 2 +- .../android/service/TorService.java | 64 ++++++++++--------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/org/torproject/android/TorConstants.java b/src/org/torproject/android/TorConstants.java index 36cdf484..79ea7e0a 100644 --- a/src/org/torproject/android/TorConstants.java +++ b/src/org/torproject/android/TorConstants.java @@ -32,7 +32,7 @@ public interface TorConstants { public final static String PREF_BRIDGES_ENABLED = "pref_bridges_enabled"; public final static String PREF_BRIDGES_UPDATED = "pref_bridges_enabled"; public final static String PREF_BRIDGES_LIST = "pref_bridges_list"; - public final static String PREF_BRIDGES_OBFUSCATED = "pref_bridges_obfuscated"; + //public final static String PREF_BRIDGES_OBFUSCATED = "pref_bridges_obfuscated"; public final static String PREF_OR = "pref_or"; public final static String PREF_OR_PORT = "pref_or_port"; public final static String PREF_OR_NICKNAME = "pref_or_nickname"; diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 13c653c1..a54c3e23 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -1710,9 +1710,41 @@ public class TorService extends Service implements TorServiceConstants, TorConst { logMessage ("Using bridges"); - boolean obfsBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_OBFUSCATED, false); String bridgeCfgKey = "Bridge"; + String bridgeList = prefs.getString(TorConstants.PREF_BRIDGES_LIST,null); + + if (bridgeList == null || bridgeList.length() == 0) + { + String msgBridge = getString(R.string.bridge_requires_ip) + + getString(R.string.send_email_for_bridges); + showToolbarNotification(msgBridge, ERROR_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false); + logMessage(msgBridge); + + return false; + } + + + String bridgeDelim = "\n"; + + if (bridgeList.indexOf(",") != -1) + { + bridgeDelim = ","; + } + + showToolbarNotification(getString(R.string.notification_using_bridges) + ": " + bridgeList, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false); + + StringTokenizer st = new StringTokenizer(bridgeList,bridgeDelim); + while (st.hasMoreTokens()) + { + String bridgeConfigLine = st.nextToken().trim(); + logMessage("Adding bridge: " + bridgeConfigLine); + mBinder.updateConfiguration(bridgeCfgKey, bridgeConfigLine, false); + + } + + //check if any PT bridges are needed + boolean obfsBridges = bridgeList.contains("obfs2")||bridgeList.contains("obfs3")||bridgeList.contains("scramblesuit"); if (obfsBridges) { @@ -1727,37 +1759,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst logMessage ("Using standard bridges"); } - String bridgeList = prefs.getString(TorConstants.PREF_BRIDGES_LIST,null); - if (bridgeList == null || bridgeList.length() == 0) - { - String msgBridge = getString(R.string.bridge_requires_ip) + - getString(R.string.send_email_for_bridges); - showToolbarNotification(msgBridge, ERROR_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false); - logMessage(msgBridge); - - return false; - } - - String bridgeDelim = "\n"; - - if (bridgeList.indexOf(",") != -1) - { - bridgeDelim = ","; - } - - showToolbarNotification(getString(R.string.notification_using_bridges) + ": " + bridgeList, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1, false); - - - - StringTokenizer st = new StringTokenizer(bridgeList,bridgeDelim); - while (st.hasMoreTokens()) - { - String bridgeConfigLine = st.nextToken().trim(); - logMessage("Adding bridge: " + bridgeConfigLine); - mBinder.updateConfiguration(bridgeCfgKey, bridgeConfigLine, false); - - } mBinder.updateConfiguration("UpdateBridgesFromAuthority", "0", false);