diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java index e8625f34f0..f09f2ee223 100644 --- a/core/java/android/net/NetworkStats.java +++ b/core/java/android/net/NetworkStats.java @@ -34,7 +34,6 @@ import libcore.util.EmptyArray; import java.io.CharArrayWriter; import java.io.PrintWriter; import java.util.Arrays; -import java.util.function.Predicate; import java.util.HashSet; import java.util.Map; import java.util.Objects; @@ -995,33 +994,23 @@ public class NetworkStats implements Parcelable { if (limitUid == UID_ALL && limitTag == TAG_ALL && limitIfaces == INTERFACES_ALL) { return; } - filter(e -> (limitUid == UID_ALL || limitUid == e.uid) - && (limitTag == TAG_ALL || limitTag == e.tag) - && (limitIfaces == INTERFACES_ALL - || ArrayUtils.contains(limitIfaces, e.iface))); - } - /** - * Only keep entries with {@link #set} value less than {@link #SET_DEBUG_START}. - * - *
This mutates the original structure in place.
- */
- public void filterDebugEntries() {
- filter(e -> e.set < SET_DEBUG_START);
- }
-
- private void filter(Predicate Maintains migrated VPN stats which are result of performing TUN migration on {@link
- * #mLastUidDetailSnapshot}.
- */
- @GuardedBy("mStatsLock")
- private NetworkStats mTunAdjustedStats;
- /**
- * Used by {@link #mTunAdjustedStats} to migrate VPN traffic over delta between this snapshot
- * and latest snapshot.
- */
- @GuardedBy("mStatsLock")
- private NetworkStats mLastUidDetailSnapshot;
-
/** Must be set in factory by calling #setHandler. */
private Handler mHandler;
private Handler.Callback mHandlerCallback;
@@ -828,39 +812,15 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
@Override
public NetworkStats getDetailedUidStats(String[] requiredIfaces) {
try {
- // Get the latest snapshot from NetworkStatsFactory.
- // TODO: Querying for INTERFACES_ALL may incur performance penalty. Consider restricting
- // this to limited set of ifaces.
- NetworkStats uidDetailStats = getNetworkStatsUidDetail(INTERFACES_ALL);
-
- // Migrate traffic from VPN UID over delta and update mTunAdjustedStats.
- NetworkStats result;
- synchronized (mStatsLock) {
- migrateTunTraffic(uidDetailStats, mVpnInfos);
- result = mTunAdjustedStats.clone();
- }
-
- // Apply filter based on ifacesToQuery.
final String[] ifacesToQuery =
NetworkStatsFactory.augmentWithStackedInterfaces(requiredIfaces);
- result.filter(UID_ALL, ifacesToQuery, TAG_ALL);
- return result;
+ return getNetworkStatsUidDetail(ifacesToQuery);
} catch (RemoteException e) {
Log.wtf(TAG, "Error compiling UID stats", e);
return new NetworkStats(0L, 0);
}
}
- @VisibleForTesting
- NetworkStats getTunAdjustedStats() {
- synchronized (mStatsLock) {
- if (mTunAdjustedStats == null) {
- return null;
- }
- return mTunAdjustedStats.clone();
- }
- }
-
@Override
public String[] getMobileIfaces() {
return mMobileIfaces;
@@ -1335,34 +1295,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// a race condition between the service handler thread and the observer's
mStatsObservers.updateStats(xtSnapshot, uidSnapshot, new ArrayMap<>(mActiveIfaces),
new ArrayMap<>(mActiveUidIfaces), vpnArray, currentTime);
-
- migrateTunTraffic(uidSnapshot, vpnArray);
- }
-
- /**
- * Updates {@link #mTunAdjustedStats} with the delta containing traffic migrated off of VPNs.
- */
- @GuardedBy("mStatsLock")
- private void migrateTunTraffic(NetworkStats uidDetailStats, VpnInfo[] vpnInfoArray) {
- if (mTunAdjustedStats == null) {
- // Either device booted or system server restarted, hence traffic cannot be migrated
- // correctly without knowing the past state of VPN's underlying networks.
- mTunAdjustedStats = uidDetailStats;
- mLastUidDetailSnapshot = uidDetailStats;
- return;
- }
- // Migrate delta traffic from VPN to other apps.
- NetworkStats delta = uidDetailStats.subtract(mLastUidDetailSnapshot);
- for (VpnInfo info : vpnInfoArray) {
- delta.migrateTun(info.ownerUid, info.vpnIface, info.underlyingIfaces);
- }
- // Filter out debug entries as that may lead to over counting.
- delta.filterDebugEntries();
- // Update #mTunAdjustedStats with migrated delta.
- mTunAdjustedStats.combineAllValues(delta);
- mTunAdjustedStats.setElapsedRealtime(uidDetailStats.getElapsedRealtime());
- // Update last snapshot.
- mLastUidDetailSnapshot = uidDetailStats;
}
/**