From f181f26d4e25c6514b66e06b119fe3ef12941575 Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Sun, 3 Jul 2011 14:09:49 +0530 Subject: [PATCH 1/8] Data stats - ARRRRRRRR not working --- res/layout/layout_main.xml | 49 +++++++ res/values/strings.xml | 2 + src/org/torproject/android/Orbot.java | 124 +++++++++++------- .../android/service/TorService.java | 32 ++++- .../android/service/TorServiceConstants.java | 2 + 5 files changed, 161 insertions(+), 48 deletions(-) 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; + } From a2981152a73dec763db542345305427d7cef49d6 Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Sun, 3 Jul 2011 17:11:11 +0530 Subject: [PATCH 2/8] Traffic is shown in the main UI --- src/org/torproject/android/Orbot.java | 42 +++++++++---------- .../android/service/TorService.java | 16 +++++-- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index fd0ace07..93cec946 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -47,8 +47,6 @@ import android.widget.TextView; public class Orbot extends Activity implements TorConstants, OnLongClickListener { - - 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 @@ -615,23 +613,22 @@ 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); + trafficRow.setVisibility(RelativeLayout.VISIBLE); } //now we stop Tor! amazing! private void stopTor () throws RemoteException { - //if the service is bound, then turn it off, using the same "PROFILE_" technique - if (mService != null) - { - mService.setProfile(TorServiceConstants.PROFILE_OFF); - - //again this is related to the progress dialog or some other threaded UI object - Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG); - mHandler.sendMessage(msg); - } - + if (mService != null) + { + mService.setProfile(TorServiceConstants.PROFILE_OFF); + Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG); + mHandler.sendMessage(msg); + trafficRow.setVisibility(RelativeLayout.GONE); + + } + } @@ -748,11 +745,11 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener case TorServiceConstants.MESSAGE_TRAFFIC_COUNT : - DataCount datacount = (DataCount) msg.obj; + Bundle data = msg.getData(); + DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download")); downloadText.setText(formatCount(datacount.Download)); uploadText.setText(formatCount(datacount.Upload)); - downloadText.invalidate(); - uploadText.invalidate(); + break; @@ -911,15 +908,16 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener public long Upload; // data downloaded public long Download; + + DataCount(long Upload, long Download){ + this.Upload = Upload; + this.Download = 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"); + + return count+" kB"; } } diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 4aaf2b08..01151460 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -41,9 +41,11 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.os.Bundle; import android.os.IBinder; import android.os.Looper; import android.os.Message; +import android.os.Parcelable; import android.os.RemoteCallbackList; import android.os.RemoteException; import android.preference.PreferenceManager; @@ -1125,10 +1127,16 @@ public class TorService extends Service implements TorServiceConstants, TorConst 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); + Message msg = Message.obtain(); + msg.what = MESSAGE_TRAFFIC_COUNT; + //msg.obj = datacount; + Bundle data = new Bundle(); + data.putLong("upload", datacount.Upload); + data.putLong("download", datacount.Download); + + msg.setData(data); + + Orbot.currentInstance.mHandler.sendMessage(msg); //sendCallbackStatusMessage(message); From e114be51d005e00f470f1bb870e6bcaa0ee295f7 Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Sun, 3 Jul 2011 17:41:43 +0530 Subject: [PATCH 3/8] Improved Formatting Now shows the data with upto 2 decimal places. If under 2Mb, shows "xxx.xKb", else shows "xxx.xxMb" --- src/org/torproject/android/Orbot.java | 13 ++++++++++--- src/org/torproject/android/service/TorService.java | 11 +++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 93cec946..6eaa124f 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -749,7 +749,8 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download")); downloadText.setText(formatCount(datacount.Download)); uploadText.setText(formatCount(datacount.Upload)); - + downloadText.invalidate(); + uploadText.invalidate(); break; @@ -916,8 +917,14 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener } private String formatCount(long count) { - - return count+" kB"; + // 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"); + + //return count+" kB"; } } diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 01151460..e9fc2248 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -1122,10 +1122,7 @@ 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; + DataCount datacount = new DataCount(written,read); Message msg = Message.obtain(); msg.what = MESSAGE_TRAFFIC_COUNT; @@ -1149,6 +1146,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst public long Upload; // data downloaded public long Download; + + + DataCount(long Upload, long Download){ + this.Upload = Upload; + this.Download = Download; + } } public void circuitStatus(String status, String circID, String path) { From 841d83b3b4688c19b87cff2fbc6a72ed19ad9b1a Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Wed, 6 Jul 2011 21:31:36 +0530 Subject: [PATCH 4/8] Bugfixes + improved formatting --- src/org/torproject/android/Orbot.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 6eaa124f..1b9ca85c 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -613,7 +613,6 @@ 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(RelativeLayout.VISIBLE); } @@ -744,7 +743,8 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener case TorServiceConstants.MESSAGE_TRAFFIC_COUNT : - + + trafficRow.setVisibility(RelativeLayout.VISIBLE); Bundle data = msg.getData(); DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download")); downloadText.setText(formatCount(datacount.Download)); @@ -921,8 +921,8 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener // 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"); + return ((float)((int)(count*10/1024))/10 + " kbps"); + return ((float)((int)(count*100/1024/1024))/100 + " mbps"); //return count+" kB"; } From d54e72e0942307cc0c3172f574e41db4e592afca Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Thu, 7 Jul 2011 19:34:22 +0530 Subject: [PATCH 5/8] ENABLE_DEBUG_TOGGLE update, proper AIDL implementation Data stats are now shown irrespective of whether ENABLE_DEBUG_TOGGLE is toggled or not. ITorServiceCallback.aidl has been updated to include a new method updateBandwidth(long ,long) to hook the data passed from the service into the GUI. --- src/org/torproject/android/Orbot.java | 33 +++++++--- .../android/service/ITorServiceCallback.aidl | 5 ++ .../android/service/TorService.java | 61 +++++++++++-------- 3 files changed, 64 insertions(+), 35 deletions(-) diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 1b9ca85c..68e4aafd 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -694,14 +694,31 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener mHandler.sendMessage(msg); } - - public void logMessage(String value) throws RemoteException { - - Message msg = mHandler.obtainMessage(TorServiceConstants.LOG_MSG); - msg.getData().putString(HANDLER_TOR_MSG, value); - mHandler.sendMessage(msg); - - } + @Override + public void logMessage(String value) throws RemoteException { + + Message msg = mHandler.obtainMessage(TorServiceConstants.LOG_MSG); + msg.getData().putString(HANDLER_TOR_MSG, value); + mHandler.sendMessage(msg); + + } + + @Override + public void updateBandwidth(long upload, long download) + throws RemoteException { + + Message msg = Message.obtain(); + msg.what = TorServiceConstants.MESSAGE_TRAFFIC_COUNT; + + + Bundle data = new Bundle(); + data.putLong("upload", upload); + data.putLong("download", download); + + msg.setData(data); + mHandler.sendMessage(msg); + + } }; diff --git a/src/org/torproject/android/service/ITorServiceCallback.aidl b/src/org/torproject/android/service/ITorServiceCallback.aidl index 86fe28f7..2492206f 100644 --- a/src/org/torproject/android/service/ITorServiceCallback.aidl +++ b/src/org/torproject/android/service/ITorServiceCallback.aidl @@ -11,6 +11,11 @@ oneway interface ITorServiceCallback { */ void statusChanged(String value); + /** + * Called when the service returns the bandwidth user to display to the user + */ + void updateBandwidth(long value, long value2); + /** * Called when the service has something to add to the log */ diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index e9fc2248..a4b01712 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -1122,37 +1122,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst sb.append("kb written"); logNotice(sb.toString()); - DataCount datacount = new DataCount(written,read); - - Message msg = Message.obtain(); - msg.what = MESSAGE_TRAFFIC_COUNT; - //msg.obj = datacount; - Bundle data = new Bundle(); - data.putLong("upload", datacount.Upload); - data.putLong("download", datacount.Download); - - msg.setData(data); - - Orbot.currentInstance.mHandler.sendMessage(msg); - - //sendCallbackStatusMessage(message); - } + + sendCallbackStatusMessage(written, read); + + } - public class DataCount { - // data uploaded - public long Upload; - // data downloaded - public long Download; - - - DataCount(long Upload, long Download){ - this.Upload = Upload; - this.Download = Download; - } - } public void circuitStatus(String status, String circID, String path) { @@ -1422,6 +1399,36 @@ public class TorService extends Service implements TorServiceConstants, TorConst mCallbacks.finishBroadcast(); inCallback = false; } + + private synchronized void sendCallbackStatusMessage (long upload, long download) + { + + if (mCallbacks == null) + return; + + // Broadcast to all clients the new value. + final int N = mCallbacks.beginBroadcast(); + + inCallback = true; + + if (N > 0) + { + for (int i=0; i Date: Mon, 25 Jul 2011 17:49:03 -0400 Subject: [PATCH 6/8] Adding neccessary prep code for Total BW --- src/org/torproject/android/service/TorService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index a4b01712..01c693c2 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -1109,7 +1109,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst } } - + public void bandwidthUsed(long read, long written) { if (ENABLE_DEBUG_LOG) @@ -1120,7 +1120,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst sb.append("kb read / "); sb.append(written/1000); sb.append("kb written"); - + /* try { + sb.append("Total upload :"+conn.getInfo("traffic/written")); + sb.append("Total Download "+conn.getInfo("traffic/read")); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ logNotice(sb.toString()); } From 5b6e83c6f6373147712dd49c404785c1839f7e65 Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Tue, 26 Jul 2011 13:16:30 -0400 Subject: [PATCH 7/8] Total Bandwidth prep code --- res/layout/layout_main.xml | 3 +- src/org/torproject/android/Orbot.java | 13 +++++++- .../android/service/ITorService.aidl | 5 +++ .../android/service/TorService.java | 33 ++++++++++++------- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/res/layout/layout_main.xml b/res/layout/layout_main.xml index 4fae7196..1a25febc 100644 --- a/res/layout/layout_main.xml +++ b/res/layout/layout_main.xml @@ -105,7 +105,8 @@ android:gravity="center_vertical|center_horizontal" android:textStyle="bold" /> - + + diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 68e4aafd..f9c949df 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -768,7 +768,18 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener uploadText.setText(formatCount(datacount.Upload)); downloadText.invalidate(); uploadText.invalidate(); - + + try { + String TotalUpload = mService.getInfo("traffic/written"); + String TotalDownload = mService.getInfo("traffic/read"); + StringBuilder sb = new StringBuilder(); + sb.append("Total Upload " + TotalUpload); + sb.append("Total Download" + TotalDownload); + Log.d(TAG,sb.toString()); + } catch (RemoteException e) { + Log.d(TAG,"Total bandwidth error"+e.getMessage()); + } + break; default: diff --git a/src/org/torproject/android/service/ITorService.aidl b/src/org/torproject/android/service/ITorService.aidl index e643b4db..07fa8089 100644 --- a/src/org/torproject/android/service/ITorService.aidl +++ b/src/org/torproject/android/service/ITorService.aidl @@ -48,4 +48,9 @@ interface ITorService { */ String getConfiguration (String name); + /** + * Get information + */ + String getInfo (String args); + } diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 01c693c2..23921a98 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; import net.freehaven.tor.control.ConfigEntry; @@ -1120,14 +1121,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst sb.append("kb read / "); sb.append(written/1000); sb.append("kb written"); - /* try { - sb.append("Total upload :"+conn.getInfo("traffic/written")); - sb.append("Total Download "+conn.getInfo("traffic/read")); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - */ + logNotice(sb.toString()); } @@ -1136,7 +1130,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst } - + public void circuitStatus(String status, String circID, String path) { @@ -1274,8 +1268,25 @@ public class TorService extends Service implements TorServiceConstants, TorConst } } - - + + + public String getInfo (String key) { + try + { + if(conn !=null) + { + String m = conn.getInfo(key); + return m; + + } + } + catch(IOException ioe) + { + Log.e(TAG,"Unable to get Tor information",ioe); + logNotice("Unable to get Tor information"+ioe.getMessage()); + } + return null; + } public String getConfiguration (String name) { From bfcebdaba28e142e521e962c1c6aab0cef175074 Mon Sep 17 00:00:00 2001 From: n8fr8 Date: Sun, 30 Sep 2012 18:14:25 +0530 Subject: [PATCH 8/8] small updates for datastats merge --- res/layout/layout_main.xml | 4 +--- src/org/torproject/android/Orbot.java | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/res/layout/layout_main.xml b/res/layout/layout_main.xml index 1a25febc..a9444e1f 100644 --- a/res/layout/layout_main.xml +++ b/res/layout/layout_main.xml @@ -104,9 +104,7 @@ android:textSize="24sp" android:gravity="center_vertical|center_horizontal" android:textStyle="bold" /> - - - + diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index f9c949df..c51b1047 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -57,7 +57,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener private TextView uploadText = null; /* Some tracking bits */ - private int torStatus = STATUS_READY; //latest status reported from the tor service + private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service /* Tor Service interaction */ /* The primary interface we will be calling on the service. */