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