[tor-commits] [orbot/master] Data stats - ARRRRRRRR not working

n8fr8 at torproject.org n8fr8 at torproject.org
Mon Oct 1 07:41:26 UTC 2012


commit f181f26d4e25c6514b66e06b119fe3ef12941575
Author: Sathyanarayanan Gunasekaran <gsathya.ceg at gmail.com>
Date:   Sun Jul 3 14:09:49 2011 +0530

    Data stats - ARRRRRRRR not working
---
 res/layout/layout_main.xml                         |   49 ++++++++
 res/values/strings.xml                             |    2 +
 src/org/torproject/android/Orbot.java              |  124 +++++++++++++-------
 src/org/torproject/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 db167e3..4fae719 100644
--- a/res/layout/layout_main.xml
+++ b/res/layout/layout_main.xml
@@ -57,6 +57,55 @@
 		
 		android:textColor="#ffffff"
 		 />
+	<RelativeLayout android:id="@+id/trafficRow"
+		android:gravity="bottom"
+	    android:layout_width="fill_parent"
+		android:layout_alignParentBottom="true"
+	    android:visibility="invisible"
+	    android:layout_height="80dp"
+	    android:background="#A0909090">
+	    <TextView
+	    	android:id="@+id/trafficDownLabel"
+			android:textColor="#FFFFFFFF"
+			android:layout_width="150dp"
+			android:layout_height="wrap_content"
+			android:layout_alignParentLeft="true"
+			android:textSize="16sp"
+			android:text="@string/main_layout_download"
+			android:gravity="center_vertical|center_horizontal"
+			android:textStyle="bold" />
+		<TextView
+			android:id="@+id/trafficUpLabel"
+			android:textColor="#FFFFFFFF"
+			android:layout_width="150dp"
+			android:layout_height="wrap_content"
+			android:layout_alignParentRight="true"
+			android:text="@string/main_layout_upload"
+			android:textSize="16sp"
+			android:gravity="center_vertical|center_horizontal"
+			android:textStyle="bold" />
+		<TextView
+			android:id="@+id/trafficDown"
+			android:textColor="#FF00B627"
+			android:layout_width="150dp"
+			android:layout_height="wrap_content"
+			android:layout_alignParentLeft="true"
+			android:layout_below="@+id/trafficDownLabel"
+			android:textSize="24sp"
+			android:gravity="center_vertical|center_horizontal"
+			android:textStyle="bold" />
+		<TextView
+			android:id="@+id/trafficUp"
+			android:textColor="#FFFF2211"
+			android:layout_width="150dp"
+			android:layout_height="wrap_content"
+			android:layout_alignParentRight="true"
+			android:layout_below="@+id/trafficUpLabel"
+			android:textSize="24sp"
+			android:gravity="center_vertical|center_horizontal"
+			android:textStyle="bold" />
+    </RelativeLayout>			
+
 </LinearLayout>
        
 </FrameLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8cc6207..9fa461d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -31,6 +31,8 @@
 <string name="menu_about">About</string>
 <string name="menu_wizard">Wizard</string>
 
+<string name="main_layout_download">Download</string> 
+<string name="main_layout_upload">Upload</string> 
 
 <string name="button_help">Help</string>
 <string name="button_close">Close</string>
diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index 1a09ac7..fd0ace0 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 3ffa460..4aaf2b0 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 3fa3c55..3776118 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;
+
 }





More information about the tor-commits mailing list