Remove VPN info arrays from NetworkStats(Observer|Recorder)
This change removes the now-unused VPN arrays in the network stats
observer and recorder classes. These are always null values in every
call site.
Bug: 113122541
Bug: 120145746
Bug: 129264869
Bug: 134244752
Test: FrameworksNetTest passing
Test: Manual tests show data usage fixes maintained.
Merged-In: Ieb8645acc400fdaeb0df7092c5369b96f9f35af9
Change-Id: I66f263d7e12bce7668901306c0c2ecdda634abaf
(cherry picked from commit 833603caab)
This commit is contained in:
@@ -39,7 +39,6 @@ import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.net.VpnInfo;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -104,9 +103,9 @@ class NetworkStatsObservers {
|
||||
public void updateStats(NetworkStats xtSnapshot, NetworkStats uidSnapshot,
|
||||
ArrayMap<String, NetworkIdentitySet> activeIfaces,
|
||||
ArrayMap<String, NetworkIdentitySet> activeUidIfaces,
|
||||
VpnInfo[] vpnArray, long currentTime) {
|
||||
long currentTime) {
|
||||
StatsContext statsContext = new StatsContext(xtSnapshot, uidSnapshot, activeIfaces,
|
||||
activeUidIfaces, vpnArray, currentTime);
|
||||
activeUidIfaces, currentTime);
|
||||
getHandler().sendMessage(mHandler.obtainMessage(MSG_UPDATE_STATS, statsContext));
|
||||
}
|
||||
|
||||
@@ -354,7 +353,7 @@ class NetworkStatsObservers {
|
||||
// thread will update it. We pass a null VPN array because usage is aggregated by uid
|
||||
// for this snapshot, so VPN traffic can't be reattributed to responsible apps.
|
||||
mRecorder.recordSnapshotLocked(statsContext.mXtSnapshot, statsContext.mActiveIfaces,
|
||||
null /* vpnArray */, statsContext.mCurrentTime);
|
||||
statsContext.mCurrentTime);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,7 +395,7 @@ class NetworkStatsObservers {
|
||||
// thread will update it. We pass the VPN info so VPN traffic is reattributed to
|
||||
// responsible apps.
|
||||
mRecorder.recordSnapshotLocked(statsContext.mUidSnapshot, statsContext.mActiveUidIfaces,
|
||||
statsContext.mVpnArray, statsContext.mCurrentTime);
|
||||
statsContext.mCurrentTime);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,18 +426,16 @@ class NetworkStatsObservers {
|
||||
NetworkStats mUidSnapshot;
|
||||
ArrayMap<String, NetworkIdentitySet> mActiveIfaces;
|
||||
ArrayMap<String, NetworkIdentitySet> mActiveUidIfaces;
|
||||
VpnInfo[] mVpnArray;
|
||||
long mCurrentTime;
|
||||
|
||||
StatsContext(NetworkStats xtSnapshot, NetworkStats uidSnapshot,
|
||||
ArrayMap<String, NetworkIdentitySet> activeIfaces,
|
||||
ArrayMap<String, NetworkIdentitySet> activeUidIfaces,
|
||||
VpnInfo[] vpnArray, long currentTime) {
|
||||
long currentTime) {
|
||||
mXtSnapshot = xtSnapshot;
|
||||
mUidSnapshot = uidSnapshot;
|
||||
mActiveIfaces = activeIfaces;
|
||||
mActiveUidIfaces = activeUidIfaces;
|
||||
mVpnArray = vpnArray;
|
||||
mCurrentTime = currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import static android.text.format.DateUtils.YEAR_IN_MILLIS;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.net.NetworkStats;
|
||||
import android.net.NetworkStats.NonMonotonicObserver;
|
||||
import android.net.NetworkStatsHistory;
|
||||
@@ -37,7 +36,6 @@ import android.util.MathUtils;
|
||||
import android.util.Slog;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
|
||||
import com.android.internal.net.VpnInfo;
|
||||
import com.android.internal.util.FileRotator;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
|
||||
@@ -202,18 +200,12 @@ public class NetworkStatsRecorder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Record any delta that occurred since last {@link NetworkStats} snapshot,
|
||||
* using the given {@link Map} to identify network interfaces. First
|
||||
* snapshot is considered bootstrap, and is not counted as delta.
|
||||
*
|
||||
* @param vpnArray Optional info about the currently active VPN, if any. This is used to
|
||||
* redistribute traffic from the VPN app to the underlying responsible apps.
|
||||
* This should always be set to null if the provided snapshot is aggregated
|
||||
* across all UIDs (e.g. contains UID_ALL buckets), regardless of VPN state.
|
||||
* Record any delta that occurred since last {@link NetworkStats} snapshot, using the given
|
||||
* {@link Map} to identify network interfaces. First snapshot is considered bootstrap, and is
|
||||
* not counted as delta.
|
||||
*/
|
||||
public void recordSnapshotLocked(NetworkStats snapshot,
|
||||
Map<String, NetworkIdentitySet> ifaceIdent, @Nullable VpnInfo[] vpnArray,
|
||||
long currentTimeMillis) {
|
||||
Map<String, NetworkIdentitySet> ifaceIdent, long currentTimeMillis) {
|
||||
final HashSet<String> unknownIfaces = Sets.newHashSet();
|
||||
|
||||
// skip recording when snapshot missing
|
||||
@@ -232,12 +224,6 @@ public class NetworkStatsRecorder {
|
||||
final long end = currentTimeMillis;
|
||||
final long start = end - delta.getElapsedRealtime();
|
||||
|
||||
if (vpnArray != null) {
|
||||
for (VpnInfo info : vpnArray) {
|
||||
delta.migrateTun(info.ownerUid, info.vpnIface, info.underlyingIfaces);
|
||||
}
|
||||
}
|
||||
|
||||
NetworkStats.Entry entry = null;
|
||||
for (int i = 0; i < delta.size(); i++) {
|
||||
entry = delta.getValues(i, entry);
|
||||
|
||||
@@ -1265,28 +1265,24 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
// For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic
|
||||
// can't be reattributed to responsible apps.
|
||||
Trace.traceBegin(TRACE_TAG_NETWORK, "recordDev");
|
||||
mDevRecorder.recordSnapshotLocked(
|
||||
devSnapshot, mActiveIfaces, null /* vpnArray */, currentTime);
|
||||
mDevRecorder.recordSnapshotLocked(devSnapshot, mActiveIfaces, currentTime);
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
Trace.traceBegin(TRACE_TAG_NETWORK, "recordXt");
|
||||
mXtRecorder.recordSnapshotLocked(
|
||||
xtSnapshot, mActiveIfaces, null /* vpnArray */, currentTime);
|
||||
mXtRecorder.recordSnapshotLocked(xtSnapshot, mActiveIfaces, currentTime);
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
|
||||
// For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps.
|
||||
Trace.traceBegin(TRACE_TAG_NETWORK, "recordUid");
|
||||
mUidRecorder.recordSnapshotLocked(
|
||||
uidSnapshot, mActiveUidIfaces, null /* vpnArray */, currentTime);
|
||||
mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, currentTime);
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
Trace.traceBegin(TRACE_TAG_NETWORK, "recordUidTag");
|
||||
mUidTagRecorder.recordSnapshotLocked(
|
||||
uidSnapshot, mActiveUidIfaces, null /* vpnArray */, currentTime);
|
||||
mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, currentTime);
|
||||
Trace.traceEnd(TRACE_TAG_NETWORK);
|
||||
|
||||
// We need to make copies of member fields that are sent to the observer to avoid
|
||||
// a race condition between the service handler thread and the observer's
|
||||
mStatsObservers.updateStats(xtSnapshot, uidSnapshot, new ArrayMap<>(mActiveIfaces),
|
||||
new ArrayMap<>(mActiveUidIfaces), null /* vpnArray */, currentTime);
|
||||
new ArrayMap<>(mActiveUidIfaces), currentTime);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,7 +54,6 @@ import android.util.ArrayMap;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.net.VpnInfo;
|
||||
import com.android.server.net.NetworkStatsServiceTest.LatchedHandler;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -94,8 +93,6 @@ public class NetworkStatsObserversTest {
|
||||
private static final long BASE_BYTES = 7 * MB_IN_BYTES;
|
||||
private static final int INVALID_TYPE = -1;
|
||||
|
||||
private static final VpnInfo[] VPN_INFO = new VpnInfo[0];
|
||||
|
||||
private long mElapsedRealtime;
|
||||
|
||||
private HandlerThread mObserverHandlerThread;
|
||||
@@ -248,8 +245,7 @@ public class NetworkStatsObserversTest {
|
||||
NetworkStats uidSnapshot = null;
|
||||
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
waitForObserverToIdle();
|
||||
}
|
||||
|
||||
@@ -272,15 +268,13 @@ public class NetworkStatsObserversTest {
|
||||
.addIfaceValues(TEST_IFACE, BASE_BYTES, 8L, BASE_BYTES, 16L);
|
||||
NetworkStats uidSnapshot = null;
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
|
||||
// Delta
|
||||
xtSnapshot = new NetworkStats(TEST_START, 1 /* initialSize */)
|
||||
.addIfaceValues(TEST_IFACE, BASE_BYTES + 1024L, 10L, BASE_BYTES + 2048L, 20L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
waitForObserverToIdle();
|
||||
}
|
||||
|
||||
@@ -304,16 +298,14 @@ public class NetworkStatsObserversTest {
|
||||
.addIfaceValues(TEST_IFACE, BASE_BYTES, 8L, BASE_BYTES, 16L);
|
||||
NetworkStats uidSnapshot = null;
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
|
||||
// Delta
|
||||
xtSnapshot = new NetworkStats(TEST_START + MINUTE_IN_MILLIS, 1 /* initialSize */)
|
||||
.addIfaceValues(TEST_IFACE, BASE_BYTES + THRESHOLD_BYTES, 12L,
|
||||
BASE_BYTES + THRESHOLD_BYTES, 22L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
waitForObserverToIdle();
|
||||
assertEquals(NetworkStatsManager.CALLBACK_LIMIT_REACHED, mHandler.lastMessageType);
|
||||
}
|
||||
@@ -338,8 +330,7 @@ public class NetworkStatsObserversTest {
|
||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
|
||||
DEFAULT_NETWORK_YES, BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
|
||||
// Delta
|
||||
uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
|
||||
@@ -347,8 +338,7 @@ public class NetworkStatsObserversTest {
|
||||
DEFAULT_NETWORK_NO, BASE_BYTES + THRESHOLD_BYTES, 2L,
|
||||
BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
waitForObserverToIdle();
|
||||
assertEquals(NetworkStatsManager.CALLBACK_LIMIT_REACHED, mHandler.lastMessageType);
|
||||
}
|
||||
@@ -373,8 +363,7 @@ public class NetworkStatsObserversTest {
|
||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
|
||||
DEFAULT_NETWORK_NO, BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
|
||||
// Delta
|
||||
uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
|
||||
@@ -382,8 +371,7 @@ public class NetworkStatsObserversTest {
|
||||
DEFAULT_NETWORK_NO, BASE_BYTES + THRESHOLD_BYTES, 2L,
|
||||
BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
waitForObserverToIdle();
|
||||
}
|
||||
|
||||
@@ -407,8 +395,7 @@ public class NetworkStatsObserversTest {
|
||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
|
||||
DEFAULT_NETWORK_YES, BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
|
||||
// Delta
|
||||
uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
|
||||
@@ -416,8 +403,7 @@ public class NetworkStatsObserversTest {
|
||||
DEFAULT_NETWORK_YES, BASE_BYTES + THRESHOLD_BYTES, 2L,
|
||||
BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
waitForObserverToIdle();
|
||||
assertEquals(NetworkStatsManager.CALLBACK_LIMIT_REACHED, mHandler.lastMessageType);
|
||||
}
|
||||
@@ -442,8 +428,7 @@ public class NetworkStatsObserversTest {
|
||||
.addValues(TEST_IFACE, UID_ANOTHER_USER, SET_DEFAULT, TAG_NONE, METERED_NO,
|
||||
ROAMING_NO, DEFAULT_NETWORK_YES, BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
|
||||
// Delta
|
||||
uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
|
||||
@@ -451,8 +436,7 @@ public class NetworkStatsObserversTest {
|
||||
ROAMING_NO, DEFAULT_NETWORK_NO, BASE_BYTES + THRESHOLD_BYTES, 2L,
|
||||
BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
|
||||
mStatsObservers.updateStats(
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
|
||||
VPN_INFO, TEST_START);
|
||||
xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces, TEST_START);
|
||||
waitForObserverToIdle();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user