summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/de')
-rw-r--r--src/de/blinkt/openvpn/OpenVPNMangement.java1
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java4
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java21
3 files changed, 16 insertions, 10 deletions
diff --git a/src/de/blinkt/openvpn/OpenVPNMangement.java b/src/de/blinkt/openvpn/OpenVPNMangement.java
index 0c6d7163..85a3f784 100644
--- a/src/de/blinkt/openvpn/OpenVPNMangement.java
+++ b/src/de/blinkt/openvpn/OpenVPNMangement.java
@@ -1,6 +1,7 @@
package de.blinkt.openvpn;
public interface OpenVPNMangement {
+ int mBytecountinterval=2;
void reconnect();
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index 5cd70987..d17ed6c5 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -25,7 +25,6 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNMangement {
private VpnProfile mProfile;
private OpenVpnService mOpenVPNService;
private LinkedList<FileDescriptor> mFDList=new LinkedList<FileDescriptor>();
- private int mBytecountinterval=2;
private LocalServerSocket mServerSocket;
private boolean mReleaseHold=true;
private boolean mWaitingForRelease=false;
@@ -273,8 +272,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNMangement {
long out = Long.parseLong(argument.substring(comma+1));
OpenVPN.updateByteCount(in,out);
-
-
+
}
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index cacbb85e..66ab9e30 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -565,9 +565,9 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
if(mDisplayBytecount) {
String netstat = String.format(getString(R.string.statusline_bytecount),
humanReadableByteCount(in, false),
- humanReadableByteCount(diffin, false),
+ humanReadableByteCount(diffin/OpenVPNMangement.mBytecountinterval, true),
humanReadableByteCount(out, false),
- humanReadableByteCount(diffout, false));
+ humanReadableByteCount(diffout/OpenVPNMangement.mBytecountinterval, true));
boolean lowpriority = !mNotificationalwaysVisible;
showNotification(netstat,null,lowpriority,mConnecttime, OpenVPN.LEVEL_CONNECTED);
@@ -576,12 +576,19 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
}
// From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
- public static String humanReadableByteCount(long bytes, boolean si) {
- int unit = si ? 1000 : 1024;
- if (bytes < unit) return bytes + " B";
+ public static String humanReadableByteCount(long bytes, boolean mbit) {
+ if(mbit)
+ bytes = bytes *8;
+ int unit = mbit ? 1000 : 1024;
+ if (bytes < unit)
+ return bytes + (mbit ? " bit" : " B");
+
int exp = (int) (Math.log(bytes) / Math.log(unit));
- String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
- return String.format(Locale.getDefault(),"%.1f %sB", bytes / Math.pow(unit, exp), pre);
+ String pre = (mbit ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (mbit ? "" : "");
+ if(mbit)
+ return String.format(Locale.getDefault(),"%.1f %sbit", bytes / Math.pow(unit, exp), pre);
+ else
+ return String.format(Locale.getDefault(),"%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
@Override