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.
This commit is contained in:
Sathyanarayanan Gunasekaran 2011-07-07 19:34:22 +05:30 committed by n8fr8
parent 841d83b3b4
commit d54e72e094
3 changed files with 64 additions and 35 deletions

View File

@ -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);
}
};

View File

@ -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
*/

View File

@ -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)
{