[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] ENABLE_DEBUG_TOGGLE update, proper AIDL implementation



commit d54e72e0942307cc0c3172f574e41db4e592afca
Author: Sathyanarayanan Gunasekaran <gsathya.ceg@xxxxxxxxx>
Date:   Thu Jul 7 19:34:22 2011 +0530

    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 ++
 src/org/torproject/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 1b9ca85..68e4aaf 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 86fe28f..2492206 100644
--- a/src/org/torproject/android/service/ITorServiceCallback.aidl
+++ b/src/org/torproject/android/service/ITorServiceCallback.aidl
@@ -12,6 +12,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
      */
     void logMessage(String value);
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index e9fc224..a4b0171 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<N; i++) {
+		            try {
+		                mCallbacks.getBroadcastItem(i).updateBandwidth(upload, download);
+		                
+		                
+		            } catch (RemoteException e) {
+		                // The RemoteCallbackList will take care of removing
+		                // the dead object for us.
+		            }
+		        }
+        }
+        
+        mCallbacks.finishBroadcast();
+        inCallback = false;
+    }
+    
     
     private synchronized void sendCallbackLogMessage (String logMessage)
     {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits