Add tether offload traffic to interface stats as well.
Currently, we only count add tethering traffic to per-UID stats, but not to total data usage (i.e., dev and XT stats). This is correct for software tethering, because all software forwarded packets are already included in interface counters, but it is incorrect for hardware offload, because such packets do not increment interface counters. To fix this: 1. Add an argument to ITetheringStatsProvider#getTetherStats to indicate whether per-UID stats are requested. For clarity, define integer constants STATS_PER_IFACE and STATS_PER_UID to represent these operations. 2. Make NetdTetheringStatsProvider return stats only if per-UID stats are requested. (Otherwise tethering traffic would be double-counted). 3. Make OffloadController's stats provider return the same stats regardless of whether per-UID stats were requested or not. 4. Make NetworkStatsService add non-per-UID tethering stats to the dev and XT snapshots. The per-UID snapshots were already correctly adding in per-UID stats. Bug: 29337859 Bug: 32163131 Test: runtest frameworks-net Test: runtest frameworks-telephony Change-Id: I7a4d04ab47694d754874136179f8edad71099638
This commit is contained in:
@@ -31,6 +31,8 @@ import static android.net.NetworkStats.ROAMING_YES;
|
|||||||
import static android.net.NetworkStats.SET_ALL;
|
import static android.net.NetworkStats.SET_ALL;
|
||||||
import static android.net.NetworkStats.SET_DEFAULT;
|
import static android.net.NetworkStats.SET_DEFAULT;
|
||||||
import static android.net.NetworkStats.SET_FOREGROUND;
|
import static android.net.NetworkStats.SET_FOREGROUND;
|
||||||
|
import static android.net.NetworkStats.STATS_PER_IFACE;
|
||||||
|
import static android.net.NetworkStats.STATS_PER_UID;
|
||||||
import static android.net.NetworkStats.TAG_NONE;
|
import static android.net.NetworkStats.TAG_NONE;
|
||||||
import static android.net.NetworkStats.UID_ALL;
|
import static android.net.NetworkStats.UID_ALL;
|
||||||
import static android.net.NetworkStatsHistory.FIELD_ALL;
|
import static android.net.NetworkStatsHistory.FIELD_ALL;
|
||||||
@@ -823,17 +825,24 @@ public class NetworkStatsServiceTest {
|
|||||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||||
expectCurrentTime();
|
expectCurrentTime();
|
||||||
expectDefaultSettings();
|
expectDefaultSettings();
|
||||||
expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1)
|
|
||||||
.addIfaceValues(TEST_IFACE, 2048L, 16L, 512L, 4L));
|
|
||||||
|
|
||||||
|
// Traffic seen by kernel counters (includes software tethering).
|
||||||
|
final NetworkStats ifaceStats = new NetworkStats(getElapsedRealtime(), 1)
|
||||||
|
.addIfaceValues(TEST_IFACE, 1536L, 12L, 384L, 3L);
|
||||||
|
// Hardware tethering traffic, not seen by kernel counters.
|
||||||
|
final NetworkStats tetherStatsHardware = new NetworkStats(getElapsedRealtime(), 1)
|
||||||
|
.addIfaceValues(TEST_IFACE, 512L, 4L, 128L, 1L);
|
||||||
|
|
||||||
|
// Traffic for UID_RED.
|
||||||
final NetworkStats uidStats = new NetworkStats(getElapsedRealtime(), 1)
|
final NetworkStats uidStats = new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 128L, 2L, 128L, 2L, 0L);
|
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, 128L, 2L, 128L, 2L, 0L);
|
||||||
final String[] tetherIfacePairs = new String[] { TEST_IFACE, "wlan0" };
|
// All tethering traffic, both hardware and software.
|
||||||
final NetworkStats tetherStats = new NetworkStats(getElapsedRealtime(), 1)
|
final NetworkStats tetherStats = new NetworkStats(getElapsedRealtime(), 1)
|
||||||
.addValues(TEST_IFACE, UID_TETHERING, SET_DEFAULT, TAG_NONE, 1920L, 14L, 384L, 2L,
|
.addValues(TEST_IFACE, UID_TETHERING, SET_DEFAULT, TAG_NONE, 1920L, 14L, 384L, 2L,
|
||||||
0L);
|
0L);
|
||||||
|
|
||||||
expectNetworkStatsUidDetail(uidStats, tetherIfacePairs, tetherStats);
|
expectNetworkStatsSummary(ifaceStats, tetherStatsHardware);
|
||||||
|
expectNetworkStatsUidDetail(uidStats, tetherStats);
|
||||||
forcePollAndWaitForIdle();
|
forcePollAndWaitForIdle();
|
||||||
|
|
||||||
// verify service recorded history
|
// verify service recorded history
|
||||||
@@ -1013,10 +1022,16 @@ public class NetworkStatsServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
|
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
|
||||||
|
expectNetworkStatsSummary(summary, new NetworkStats(0L, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectNetworkStatsSummary(NetworkStats summary, NetworkStats tetherStats)
|
||||||
|
throws Exception {
|
||||||
when(mConnManager.getAllVpnInfo()).thenReturn(new VpnInfo[0]);
|
when(mConnManager.getAllVpnInfo()).thenReturn(new VpnInfo[0]);
|
||||||
|
|
||||||
expectNetworkStatsSummaryDev(summary);
|
expectNetworkStatsTethering(STATS_PER_IFACE, tetherStats);
|
||||||
expectNetworkStatsSummaryXt(summary);
|
expectNetworkStatsSummaryDev(summary.clone());
|
||||||
|
expectNetworkStatsSummaryXt(summary.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsSummaryDev(NetworkStats summary) throws Exception {
|
private void expectNetworkStatsSummaryDev(NetworkStats summary) throws Exception {
|
||||||
@@ -1027,17 +1042,21 @@ public class NetworkStatsServiceTest {
|
|||||||
when(mNetManager.getNetworkStatsSummaryXt()).thenReturn(summary);
|
when(mNetManager.getNetworkStatsSummaryXt()).thenReturn(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsUidDetail(NetworkStats detail) throws Exception {
|
private void expectNetworkStatsTethering(int how, NetworkStats stats)
|
||||||
expectNetworkStatsUidDetail(detail, new String[0], new NetworkStats(0L, 0));
|
throws Exception {
|
||||||
|
when(mNetManager.getNetworkStatsTethering(how)).thenReturn(stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsUidDetail(
|
private void expectNetworkStatsUidDetail(NetworkStats detail) throws Exception {
|
||||||
NetworkStats detail, String[] tetherIfacePairs, NetworkStats tetherStats)
|
expectNetworkStatsUidDetail(detail, new NetworkStats(0L, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectNetworkStatsUidDetail(NetworkStats detail, NetworkStats tetherStats)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
when(mNetManager.getNetworkStatsUidDetail(UID_ALL)).thenReturn(detail);
|
when(mNetManager.getNetworkStatsUidDetail(UID_ALL)).thenReturn(detail);
|
||||||
|
|
||||||
// also include tethering details, since they are folded into UID
|
// also include tethering details, since they are folded into UID
|
||||||
when(mNetManager.getNetworkStatsTethering()).thenReturn(tetherStats);
|
when(mNetManager.getNetworkStatsTethering(STATS_PER_UID)).thenReturn(tetherStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectDefaultSettings() throws Exception {
|
private void expectDefaultSettings() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user