commit a336a294fbd37739096c1f06a52a147cf19a31cb Author: Hans-Christoph Steiner hans@eds.org Date: Mon Jun 8 14:54:38 2015 -0400
convert status variable to String for easy sharing in Intents
Instead of making the apps who receive the broadcasts decipher a number scheme, send the string of the status. Then it'll be self-documenting. --- src/org/torproject/android/OrbotMainActivity.java | 4 +-- src/org/torproject/android/service/TorService.java | 26 +++++++------------- .../android/service/TorServiceConstants.java | 9 ++++--- 3 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java index 786849a..e9c9699 100644 --- a/src/org/torproject/android/OrbotMainActivity.java +++ b/src/org/torproject/android/OrbotMainActivity.java @@ -87,7 +87,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon private Toolbar mToolbar; /* Some tracking bits */ - private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service + private String torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
private SharedPreferences mPrefs = null;
@@ -178,7 +178,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon } else if (intent.hasExtra("status")) { - torStatus = intent.getIntExtra("status", TorServiceConstants.STATUS_OFF); + torStatus = intent.getStringExtra("status"); updateStatus(""); }
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 195fe98..7a97e70 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -84,7 +84,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
public static boolean ENABLE_DEBUG_LOG = true;
- private int mCurrentStatus = STATUS_OFF; + private String mCurrentStatus = STATUS_OFF;
private final static int CONTROL_SOCKET_TIMEOUT = 0;
@@ -223,14 +223,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
- - public int getTorStatus () - { - + public String getTorStatus() { return mCurrentStatus; - } - + private void clearNotifications () { if (mNotificationManager != null) @@ -1427,7 +1423,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon }
- public void setTorProfile(int newState) { + public void setTorProfile(String newState) {
if (newState == STATUS_ON) { @@ -2111,17 +2107,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
- private void sendCallbackStatus (int currentStatus) - { - - - Intent intent = new Intent("status"); - // You can also include some extra data. - intent.putExtra("status", currentStatus); - LocalBroadcastManager.getInstance(this).sendBroadcast(intent); + private void sendCallbackStatus(String currentStatus) { + Intent intent = new Intent("status"); // TODO rename to proper action + // You can also include some extra data. + intent.putExtra("status", currentStatus); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
} -
/* * Another way to do this would be to use the Observer pattern by defining the diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java index 55ff6c3..29ac47b 100644 --- a/src/org/torproject/android/service/TorServiceConstants.java +++ b/src/org/torproject/android/service/TorServiceConstants.java @@ -66,10 +66,11 @@ public interface TorServiceConstants {
//control port public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%"; - - public final static int STATUS_OFF = 0; - public final static int STATUS_ON = 1; - public final static int STATUS_CONNECTING = 2; + + public final static String STATUS_OFF = "OFF"; + public final static String STATUS_ON = "ON"; + public final static String STATUS_CONNECTING = "CONNECTING"; + public final static String STATUS_DISCONNECTING = "DISCONNECTING";
public static final int STATUS_MSG = 1; public static final int ENABLE_TOR_MSG = 2;