Addressing comments for http://ag/7700679.

(cherry picked from commit 81e79803de)

Note, that its in a separate CL so we could cherry-pick this CL to aosp.
http://ag/7700679 is already in aosp (http://aosp/865073).

Bug: 113122541
Bug: 120145746
Test: atest FrameworksNetTests

Change-Id: Ic1767bc8bf1460e4223f86465fc72344428e6055
Merged-In: I7cfda226b4ed11b67002b83b38fba0f5caf96718
This commit is contained in:
Varun Anand
2019-05-24 16:29:22 -07:00
parent 47090f9dd0
commit 6018f64055

View File

@@ -1300,7 +1300,8 @@ public class NetworkStats implements Parcelable {
} }
final Entry tmpEntry = new Entry(); final Entry tmpEntry = new Entry();
for (int i = 0; i < size; i++) { final int origSize = size;
for (int i = 0; i < origSize; i++) {
if (!Objects.equals(iface[i], tunIface)) { if (!Objects.equals(iface[i], tunIface)) {
// Consider only entries that go onto the VPN interface. // Consider only entries that go onto the VPN interface.
continue; continue;
@@ -1316,8 +1317,9 @@ public class NetworkStats implements Parcelable {
tmpEntry.roaming = roaming[i]; tmpEntry.roaming = roaming[i];
tmpEntry.defaultNetwork = defaultNetwork[i]; tmpEntry.defaultNetwork = defaultNetwork[i];
// In a first pass, compute each UID's total share of data across all underlyingIfaces. // In a first pass, compute this entry's total share of data across all
// This is computed on the basis of the share of each UID's usage over tunIface. // underlyingIfaces. This is computed on the basis of the share of this entry's usage
// over tunIface.
// TODO: Consider refactoring first pass into a separate helper method. // TODO: Consider refactoring first pass into a separate helper method.
long totalRxBytes = 0; long totalRxBytes = 0;
if (tunIfaceTotal.rxBytes > 0) { if (tunIfaceTotal.rxBytes > 0) {
@@ -1394,9 +1396,11 @@ public class NetworkStats implements Parcelable {
* perInterfaceTotal[j].operations * perInterfaceTotal[j].operations
/ underlyingIfacesTotal.operations; / underlyingIfacesTotal.operations;
} }
// tmpEntry now contains the migrated data of the i-th entry for the j-th underlying
// interface. Add that data usage to this object.
combineValues(tmpEntry); combineValues(tmpEntry);
if (tag[i] == TAG_NONE) { if (tag[i] == TAG_NONE) {
// Add the migrated data to moved so it is deducted from the VPN app later.
moved[j].add(tmpEntry); moved[j].add(tmpEntry);
// Add debug info // Add debug info
tmpEntry.set = SET_DBG_VPN_IN; tmpEntry.set = SET_DBG_VPN_IN;
@@ -1412,8 +1416,8 @@ public class NetworkStats implements Parcelable {
@NonNull String[] underlyingIfaces, @NonNull String[] underlyingIfaces,
@NonNull Entry[] moved) { @NonNull Entry[] moved) {
for (int i = 0; i < underlyingIfaces.length; i++) { for (int i = 0; i < underlyingIfaces.length; i++) {
// Add debug info
moved[i].uid = tunUid; moved[i].uid = tunUid;
// Add debug info
moved[i].set = SET_DBG_VPN_OUT; moved[i].set = SET_DBG_VPN_OUT;
moved[i].tag = TAG_NONE; moved[i].tag = TAG_NONE;
moved[i].iface = underlyingIfaces[i]; moved[i].iface = underlyingIfaces[i];