VPN network stat accounting changes. am: 218bfe7a33

am: 0d309b7a47

Change-Id: I797ac586581f83ada0e94639dd435122c987f1c1
This commit is contained in:
Jeremy Joslin
2016-10-21 23:43:06 +00:00
committed by android-build-merger

View File

@@ -904,7 +904,8 @@ public class NetworkStats implements Parcelable {
if (pool.isEmpty()) { if (pool.isEmpty()) {
return true; return true;
} }
Entry moved = addTrafficToApplications(tunIface, underlyingIface, tunIfaceTotal, pool); Entry moved =
addTrafficToApplications(tunUid, tunIface, underlyingIface, tunIfaceTotal, pool);
deductTrafficFromVpnApp(tunUid, underlyingIface, moved); deductTrafficFromVpnApp(tunUid, underlyingIface, moved);
if (!moved.isEmpty()) { if (!moved.isEmpty()) {
@@ -919,9 +920,9 @@ public class NetworkStats implements Parcelable {
* Initializes the data used by the migrateTun() method. * Initializes the data used by the migrateTun() method.
* *
* This is the first pass iteration which does the following work: * This is the first pass iteration which does the following work:
* (1) Adds up all the traffic through tun0. * (1) Adds up all the traffic through the tunUid's underlyingIface
* (2) Adds up all the traffic through the tunUid's underlyingIface
* (both foreground and background). * (both foreground and background).
* (2) Adds up all the traffic through tun0 excluding traffic from the vpn app itself.
*/ */
private void tunAdjustmentInit(int tunUid, String tunIface, String underlyingIface, private void tunAdjustmentInit(int tunUid, String tunIface, String underlyingIface,
Entry tunIfaceTotal, Entry underlyingIfaceTotal) { Entry tunIfaceTotal, Entry underlyingIfaceTotal) {
@@ -941,8 +942,9 @@ public class NetworkStats implements Parcelable {
underlyingIfaceTotal.add(recycle); underlyingIfaceTotal.add(recycle);
} }
if (recycle.tag == TAG_NONE && Objects.equals(tunIface, recycle.iface)) { if (recycle.uid != tunUid && recycle.tag == TAG_NONE
// Add up all tunIface traffic. && Objects.equals(tunIface, recycle.iface)) {
// Add up all tunIface traffic excluding traffic from the vpn app itself.
tunIfaceTotal.add(recycle); tunIfaceTotal.add(recycle);
} }
} }
@@ -958,13 +960,15 @@ public class NetworkStats implements Parcelable {
return pool; return pool;
} }
private Entry addTrafficToApplications(String tunIface, String underlyingIface, private Entry addTrafficToApplications(int tunUid, String tunIface, String underlyingIface,
Entry tunIfaceTotal, Entry pool) { Entry tunIfaceTotal, Entry pool) {
Entry moved = new Entry(); Entry moved = new Entry();
Entry tmpEntry = new Entry(); Entry tmpEntry = new Entry();
tmpEntry.iface = underlyingIface; tmpEntry.iface = underlyingIface;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
if (Objects.equals(iface[i], tunIface)) { // the vpn app is excluded from the redistribution but all moved traffic will be
// deducted from the vpn app (see deductTrafficFromVpnApp below).
if (Objects.equals(iface[i], tunIface) && uid[i] != tunUid) {
if (tunIfaceTotal.rxBytes > 0) { if (tunIfaceTotal.rxBytes > 0) {
tmpEntry.rxBytes = pool.rxBytes * rxBytes[i] / tunIfaceTotal.rxBytes; tmpEntry.rxBytes = pool.rxBytes * rxBytes[i] / tunIfaceTotal.rxBytes;
} else { } else {