diff --git a/src/org/torproject/android/OrbotConstants.java b/src/org/torproject/android/OrbotConstants.java index 373ff3fd..10309fb7 100644 --- a/src/org/torproject/android/OrbotConstants.java +++ b/src/org/torproject/android/OrbotConstants.java @@ -16,11 +16,7 @@ public interface OrbotConstants { public final static String URL_TOR_CHECK = "https://check.torproject.org"; public final static String URL_TOR_BRIDGES = "https://bridges.torproject.org/bridges?transport="; - - public final static String NEWLINE = "\n"; - - public final static String HANDLER_TOR_MSG = "torServiceMsg"; - + public final static String PREF_BRIDGES_UPDATED = "pref_bridges_enabled"; //public final static String PREF_BRIDGES_OBFUSCATED = "pref_bridges_obfuscated"; public final static String PREF_OR = "pref_or"; diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java index a2e97502..c9c13b00 100644 --- a/src/org/torproject/android/OrbotMainActivity.java +++ b/src/org/torproject/android/OrbotMainActivity.java @@ -92,7 +92,11 @@ public class OrbotMainActivity extends Activity private final static int REQUEST_VPN = 8888; private final static int REQUEST_SETTINGS = 0x9874; - + + // message types for mStatusUpdateHandler + private final static int STATUS_UPDATE = 1; + private static final int MESSAGE_TRAFFIC_COUNT = 2; + /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -141,8 +145,9 @@ public class OrbotMainActivity extends Activity return; if (action.equals(TorServiceConstants.LOCAL_ACTION_LOG)) { - String log = intent.getStringExtra(TorServiceConstants.LOCAL_EXTRA_LOG); - updateStatus(log); + Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE); + msg.obj = intent.getStringExtra(TorServiceConstants.LOCAL_EXTRA_LOG); + mStatusUpdateHandler.sendMessage(msg); } else if (action.equals(TorServiceConstants.LOCAL_ACTION_BANDWIDTH)) { long upload = intent.getLongExtra("up", 0); @@ -150,8 +155,7 @@ public class OrbotMainActivity extends Activity long written = intent.getLongExtra("written", 0); long read = intent.getLongExtra("read", 0); - Message msg = mStatusUpdateHandler - .obtainMessage(TorServiceConstants.MESSAGE_TRAFFIC_COUNT); + Message msg = mStatusUpdateHandler.obtainMessage(MESSAGE_TRAFFIC_COUNT); msg.getData().putLong("download", download); msg.getData().putLong("upload", upload); msg.getData().putLong("readTotal", read); @@ -160,7 +164,9 @@ public class OrbotMainActivity extends Activity } else if (action.equals(TorServiceConstants.ACTION_STATUS)) { torStatus = intent.getStringExtra(TorServiceConstants.EXTRA_STATUS); - updateStatus(""); + Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE); + msg.obj = ""; + mStatusUpdateHandler.sendMessage(msg); } } }; @@ -1122,8 +1128,8 @@ public class OrbotMainActivity extends Activity lblStatus.setText(getString(R.string.status_starting_up)); //we send a message here to the progressDialog i believe, but we can clarify that shortly - Message msg = mStatusUpdateHandler.obtainMessage(TorServiceConstants.ENABLE_TOR_MSG); - msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up)); + Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE); + msg.obj = getString(R.string.status_starting_up); mStatusUpdateHandler.sendMessage(msg); } @@ -1144,38 +1150,16 @@ public class OrbotMainActivity extends Activity // this is what takes messages or values from the callback threads or other non-mainUI threads //and passes them back into the main UI thread for display to the user private Handler mStatusUpdateHandler = new Handler() { - - private String lastServiceMsg = null; - - public void handleMessage(Message msg) { + + @Override + public void handleMessage(final Message msg) { switch (msg.what) { - case TorServiceConstants.STATUS_MSG: - case TorServiceConstants.LOG_MSG: - - String torServiceMsg = (String)msg.getData().getString(HANDLER_TOR_MSG); - - if (lastServiceMsg == null || !lastServiceMsg.equals(torServiceMsg)) - { - updateStatus(torServiceMsg); - - lastServiceMsg = torServiceMsg; - } - + case STATUS_UPDATE: + updateStatus((String) msg.obj); break; - case TorServiceConstants.ENABLE_TOR_MSG: - - updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG)); - - break; - case TorServiceConstants.DISABLE_TOR_MSG: - - updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG)); - - break; - - case TorServiceConstants.MESSAGE_TRAFFIC_COUNT : - + case MESSAGE_TRAFFIC_COUNT: + Bundle data = msg.getData(); DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download")); @@ -1190,12 +1174,9 @@ public class OrbotMainActivity extends Activity super.handleMessage(msg); } } - - - }; - @Override + @Override protected void onDestroy() { super.onDestroy(); LocalBroadcastManager.getInstance(this).unregisterReceiver(mLocalBroadcastReceiver); diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java index c2c326a1..c31a6703 100644 --- a/src/org/torproject/android/service/TorServiceConstants.java +++ b/src/org/torproject/android/service/TorServiceConstants.java @@ -78,12 +78,7 @@ public interface TorServiceConstants { public final static String STATUS_ON = "ON"; public final static String STATUS_STARTING = "STARTING"; public final static String STATUS_STOPPING = "STOPPING"; - - public static final int STATUS_MSG = 1; - public static final int ENABLE_TOR_MSG = 2; - public static final int DISABLE_TOR_MSG = 3; - public static final int LOG_MSG = 4; - + public static final String CMD_START = "start"; public static final String CMD_SIGNAL_HUP = "signal_hup"; public static final String CMD_FLUSH = "flush"; @@ -100,11 +95,6 @@ public interface TorServiceConstants { public static final String OBFSCLIENT_ASSET_KEY = "obfs4proxy"; public static final String MEEK_ASSET_KEY = "meek-client"; - - - public static final int MESSAGE_TRAFFIC_COUNT = 5; - - //name of the iptables binary public final static String IPTABLES_ASSET_KEY = "xtables";