[tor-commits] [orbot/master] bandwidth propagates correctly from TorEventHandler -> OrbotService -> OrbotMainActivity
n8fr8 at torproject.org
n8fr8 at torproject.org
Wed Dec 22 21:55:08 UTC 2021
commit 491e3572e694f4add61ce43d8ff17eff3fe1d334
Author: bim <dsnake at protonmail.com>
Date: Tue Jun 1 19:42:21 2021 -0400
bandwidth propagates correctly from TorEventHandler -> OrbotService -> OrbotMainActivity
---
.../org/torproject/android/OrbotMainActivity.java | 28 +++++++++++-----------
.../torproject/android/service/OrbotService.java | 10 ++++----
.../android/service/TorEventHandler.java | 12 +++-------
3 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index 0090410e..6a351e5d 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -158,16 +158,16 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
break;
}
case TorServiceConstants.LOCAL_ACTION_BANDWIDTH: {
- long upload = intent.getLongExtra("up", 0);
- long download = intent.getLongExtra("down", 0);
- long written = intent.getLongExtra("written", 0);
- long read = intent.getLongExtra("read", 0);
+ long totalWritten = intent.getLongExtra("totalWritten", 0);
+ long totalRead = intent.getLongExtra("totalRead", 0);
+ long lastWritten = intent.getLongExtra("lastWritten", 0);
+ long lastRead = intent.getLongExtra("lastRead", 0);
Message msg = mStatusUpdateHandler.obtainMessage(MESSAGE_TRAFFIC_COUNT);
- msg.getData().putLong("download", download);
- msg.getData().putLong("upload", upload);
- msg.getData().putLong("readTotal", read);
- msg.getData().putLong("writeTotal", written);
+ msg.getData().putLong("lastRead", lastRead);
+ msg.getData().putLong("lastWritten", lastWritten);
+ msg.getData().putLong("totalWritten", totalWritten);
+ msg.getData().putLong("totalRead", totalRead);
msg.getData().putString("status", intent.getStringExtra(TorServiceConstants.EXTRA_STATUS));
mStatusUpdateHandler.sendMessage(msg);
@@ -1174,12 +1174,12 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
switch (msg.what) {
case MESSAGE_TRAFFIC_COUNT:
- long upload = data.getLong("upload");
- long download = data.getLong("download");
- long totalRead = data.getLong("readTotal");
- long totalWrite = data.getLong("writeTotal");
- oma.downloadText.setText(String.format("%s / %s", OrbotService.formatBandwidthCount(oma, download), oma.formatTotal(totalRead)));
- oma.uploadText.setText(String.format("%s / %s", OrbotService.formatBandwidthCount(oma, upload), oma.formatTotal(totalWrite)));
+ long lastWritten = data.getLong("lastWritten");
+ long lastRead = data.getLong("lastRead");
+ long totalRead = data.getLong("totalRead");
+ long totalWrite = data.getLong("totalWritten");
+ oma.downloadText.setText(String.format("%s / %s", OrbotService.formatBandwidthCount(oma, lastRead), oma.formatTotal(totalRead)));
+ oma.uploadText.setText(String.format("%s / %s", OrbotService.formatBandwidthCount(oma, lastWritten), oma.formatTotal(totalWrite)));
break;
case MESSAGE_PORTS:
diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
index 3b802aff..5781b564 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
@@ -986,13 +986,13 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
}
}
- protected void sendCallbackBandwidth(long upload, long download, long written, long read) {
+ protected void sendCallbackBandwidth(long lastWritten, long lastRead, long totalWritten, long totalRead) {
Intent intent = new Intent(LOCAL_ACTION_BANDWIDTH);
- intent.putExtra("up", upload);
- intent.putExtra("down", download);
- intent.putExtra("written", written);
- intent.putExtra("read", read);
+ intent.putExtra("totalWritten", totalWritten);
+ intent.putExtra("totalRead", totalRead);
+ intent.putExtra("lastWritten", lastWritten);
+ intent.putExtra("lastRead", lastRead);
intent.putExtra(EXTRA_STATUS, mCurrentStatus);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java b/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java
index 29af35f7..0b49b461 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java
@@ -1,7 +1,6 @@
package org.torproject.android.service;
import android.text.TextUtils;
-import android.util.Log;
import net.freehaven.tor.control.EventHandler;
@@ -35,7 +34,6 @@ public class TorEventHandler implements EventHandler, TorServiceConstants {
@Override
public void message(String severity, String msg) {
- Log.d("bim", "message: " + msg);
if (severity.equalsIgnoreCase("debug"))
mService.debug(severity + ": " + msg);
else
@@ -90,18 +88,14 @@ public class TorEventHandler implements EventHandler, TorServiceConstants {
if (read > 0 || written > 0)
iconId = R.drawable.ic_stat_tor_xfer;
- String sb = OrbotService.formatBandwidthCount(mService, read) +
- " \u2193" +
- " / " +
- OrbotService.formatBandwidthCount(mService, written) +
- " \u2191";
- Log.d("bim", "bandWidthUsed " + read + ", " + written);
+ String sb = OrbotService.formatBandwidthCount(mService, read) + " \u2193" + " / " +
+ OrbotService.formatBandwidthCount(mService, written) + " \u2191";
mService.showToolbarNotification(sb, OrbotService.NOTIFY_ID, iconId);
mTotalTrafficWritten += written;
mTotalTrafficRead += read;
- mService.sendCallbackBandwidth(lastWritten, lastRead, mTotalTrafficWritten, mTotalTrafficRead);
+ mService.sendCallbackBandwidth(written, read, mTotalTrafficWritten, mTotalTrafficRead);
lastWritten = 0;
lastRead = 0;
More information about the tor-commits
mailing list