diff --git a/res/layout/layout_main.xml b/res/layout/layout_main.xml index db167e33..4fae7196 100644 --- a/res/layout/layout_main.xml +++ b/res/layout/layout_main.xml @@ -57,6 +57,55 @@ android:textColor="#ffffff" /> + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 8cc6207e..9fa461d8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -31,6 +31,8 @@ About Wizard +Download +Upload Help Close diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 1a09ac73..fd0ace07 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -42,57 +42,64 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; public class Orbot extends Activity implements TorConstants, OnLongClickListener { - - - /* Useful UI bits */ - // so this is probably pretty obvious, here, but also an area - // which we might see quite a bit of change+complexity was the main screen - // UI gets new features - private TextView lblStatus = null; //the main text display widget - private ImageView imgStatus = null; //the main touchable image for activating Orbot - private ProgressDialog progressDialog; //the spinning progress dialog that shows up now and then - private MenuItem mItemOnOff = null; //the menu item which we toggle based on Orbot state - - /* Some tracking bits */ - private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service - // this is a value we get passed back from the TorService - - /* Tor Service interaction */ - /* The primary interface we will be calling on the service. */ - ITorService mService = null; //interface to remote TorService - private boolean autoStartOnBind = false; //controls whether service starts when class binds to it - SharedPreferences prefs; //what the user really wants! - - /** - * When the Orbot activity is created, we call startService - * to ensure the Tor remote service is running. However, it may - * already be running, and this should not create more than one instnace - */ + private static final int VISIBLE = 0; + /* Useful UI bits */ + private TextView lblStatus = null; //the main text display widget + private ImageView imgStatus = null; //the main touchable image for activating Orbot + private ProgressDialog progressDialog; + private MenuItem mItemOnOff = null; + private RelativeLayout trafficRow = null; // the row showing the traffic + private TextView downloadText = null; + private TextView uploadText = null; + + /* Some tracking bits */ + private int torStatus = STATUS_READY; //latest status reported from the tor service + + /* Tor Service interaction */ + /* The primary interface we will be calling on the service. */ + ITorService mService = null; + private boolean autoStartOnBind = false; + + SharedPreferences prefs; + + public static Orbot currentInstance = null; + + private static void setCurrent(Orbot current){ + Orbot.currentInstance = current; + } + + /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Orbot.setCurrent(this); + //if Tor binary is not running, then start the service up //might want to look at whether we need to call this every time //or whether binding to the service is enough - setLocale(); + setLocale(); + + startService(new Intent(INTENT_TOR_SERVICE)); + + prefs = PreferenceManager.getDefaultSharedPreferences(this); + + setContentView(R.layout.layout_main); + + lblStatus = (TextView)findViewById(R.id.lblStatus); + lblStatus.setOnLongClickListener(this); + imgStatus = (ImageView)findViewById(R.id.imgStatus); + imgStatus.setOnLongClickListener(this); + trafficRow = (RelativeLayout)findViewById(R.id.trafficRow); + downloadText = (TextView)findViewById(R.id.trafficDown); + uploadText = (TextView)findViewById(R.id.trafficUp); - prefs = PreferenceManager.getDefaultSharedPreferences(this); - - setContentView(R.layout.layout_main); - - //obvious? -yep got everything so far - lblStatus = (TextView)findViewById(R.id.lblStatus); - - imgStatus = (ImageView)findViewById(R.id.imgStatus); - imgStatus.setOnLongClickListener(this); - - startService(new Intent(INTENT_TOR_SERVICE)); } @@ -608,6 +615,8 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up)); mHandler.sendMessage(msg); + trafficRow.setVisibility(VISIBLE); + } //now we stop Tor! amazing! @@ -731,11 +740,22 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener break; case TorServiceConstants.DISABLE_TOR_MSG: - - updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG)); - - break; - + + updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG)); + + break; + + + case TorServiceConstants.MESSAGE_TRAFFIC_COUNT : + + DataCount datacount = (DataCount) msg.obj; + downloadText.setText(formatCount(datacount.Download)); + uploadText.setText(formatCount(datacount.Upload)); + downloadText.invalidate(); + uploadText.invalidate(); + + break; + default: super.handleMessage(msg); } @@ -885,5 +905,21 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener getResources().updateConfiguration(config, getResources().getDisplayMetrics()); } } - + + public class DataCount { + // data uploaded + public long Upload; + // data downloaded + public long Download; + } + + private String formatCount(long count) { + // Converts the supplied argument into a string. + // Under 2Mb, returns "xxx.xKb" + // Over 2Mb, returns "xxx.xxMb" + if (count < 1e6 * 2) + return ((float)((int)(count*10/1024))/10 + "kB"); + return ((float)((int)(count*100/1024/1024))/100 + "MB"); + } + } diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 3ffa4609..4aaf2b08 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -42,6 +42,8 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.IBinder; +import android.os.Looper; +import android.os.Message; import android.os.RemoteCallbackList; import android.os.RemoteException; import android.preference.PreferenceManager; @@ -50,7 +52,7 @@ import android.util.Log; public class TorService extends Service implements TorServiceConstants, TorConstants, Runnable, EventHandler { - public static boolean ENABLE_DEBUG_LOG = false; + public static boolean ENABLE_DEBUG_LOG = true; private static int currentStatus = STATUS_OFF; @@ -944,7 +946,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst conn.setEventHandler(this); conn.setEvents(Arrays.asList(new String[]{ - "ORCONN", "CIRC", "NOTICE", "WARN", "ERR"})); + "ORCONN", "CIRC", "NOTICE", "WARN", "ERR","BW"})); // conn.setEvents(Arrays.asList(new String[]{ // "DEBUG", "INFO", "NOTICE", "WARN", "ERR"})); @@ -1118,10 +1120,29 @@ public class TorService extends Service implements TorServiceConstants, TorConst sb.append("kb written"); logNotice(sb.toString()); + DataCount datacount = new DataCount(); + + datacount.Download = read/1000; + datacount.Upload = written/1000; + + Message message = Message.obtain(); + message.what = MESSAGE_TRAFFIC_COUNT; + message.obj = datacount; + Orbot.currentInstance.mHandler.sendMessage(message); + + //sendCallbackStatusMessage(message); + } } + public class DataCount { + // data uploaded + public long Upload; + // data downloaded + public long Download; + } + public void circuitStatus(String status, String circID, String path) { if (ENABLE_DEBUG_LOG) @@ -1441,8 +1462,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - - boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false); + + ENABLE_DEBUG_LOG = prefs.getBoolean("pref_enable_logging",true); + Log.i(TAG,"debug logging:" + ENABLE_DEBUG_LOG); + + boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false); //boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false); diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java index 3fa3c558..3776118b 100644 --- a/src/org/torproject/android/service/TorServiceConstants.java +++ b/src/org/torproject/android/service/TorServiceConstants.java @@ -85,4 +85,6 @@ public interface TorServiceConstants { //obfsproxy public static final String OBFSPROXY_ASSET_KEY = "obfsproxy"; + public static final int MESSAGE_TRAFFIC_COUNT = 5; + }