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.
(cherry picked from commit f31c942e89)
Bug: 29337859
Bug: 32163131
Test: runtest frameworks-net
Test: runtest frameworks-telephony
Change-Id: I325b13d50e88841dfb0db4c35e7e27f163ee72fe
Merged-In: I4e8e923d68dce1a4a68608dbd6c75a91165aa4ee
This commit is contained in:
@@ -82,6 +82,11 @@ public class NetworkStats implements Parcelable {
|
|||||||
/** {@link #roaming} value where roaming data is accounted. */
|
/** {@link #roaming} value where roaming data is accounted. */
|
||||||
public static final int ROAMING_YES = 1;
|
public static final int ROAMING_YES = 1;
|
||||||
|
|
||||||
|
/** Denotes a request for stats at the interface level. */
|
||||||
|
public static final int STATS_PER_IFACE = 0;
|
||||||
|
/** Denotes a request for stats at the interface and UID level. */
|
||||||
|
public static final int STATS_PER_UID = 1;
|
||||||
|
|
||||||
// TODO: move fields to "mVariable" notation
|
// TODO: move fields to "mVariable" notation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import static android.net.NetworkStats.IFACE_ALL;
|
|||||||
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.NetworkTemplate.buildTemplateMobileWildcard;
|
import static android.net.NetworkTemplate.buildTemplateMobileWildcard;
|
||||||
@@ -1032,6 +1034,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final NetworkStats xtSnapshot = getNetworkStatsXt();
|
final NetworkStats xtSnapshot = getNetworkStatsXt();
|
||||||
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
|
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
|
||||||
|
|
||||||
|
// Tethering snapshot for dev and xt stats. Counts per-interface data from tethering stats
|
||||||
|
// providers that isn't already counted by dev and XT stats.
|
||||||
|
final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_IFACE);
|
||||||
|
xtSnapshot.combineAllValues(tetherSnapshot);
|
||||||
|
devSnapshot.combineAllValues(tetherSnapshot);
|
||||||
|
|
||||||
// For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic
|
// 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.
|
// can't be reattributed to responsible apps.
|
||||||
@@ -1328,14 +1335,14 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final NetworkStats uidSnapshot = mNetworkManager.getNetworkStatsUidDetail(UID_ALL);
|
final NetworkStats uidSnapshot = mNetworkManager.getNetworkStatsUidDetail(UID_ALL);
|
||||||
|
|
||||||
// fold tethering stats and operations into uid snapshot
|
// fold tethering stats and operations into uid snapshot
|
||||||
final NetworkStats tetherSnapshot = getNetworkStatsTethering();
|
final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_UID);
|
||||||
uidSnapshot.combineAllValues(tetherSnapshot);
|
uidSnapshot.combineAllValues(tetherSnapshot);
|
||||||
|
|
||||||
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(
|
final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(
|
||||||
Context.TELEPHONY_SERVICE);
|
Context.TELEPHONY_SERVICE);
|
||||||
|
|
||||||
// fold video calling data usage stats into uid snapshot
|
// fold video calling data usage stats into uid snapshot
|
||||||
final NetworkStats vtStats = telephonyManager.getVtDataUsage(true);
|
final NetworkStats vtStats = telephonyManager.getVtDataUsage(STATS_PER_UID);
|
||||||
if (vtStats != null) {
|
if (vtStats != null) {
|
||||||
uidSnapshot.combineAllValues(vtStats);
|
uidSnapshot.combineAllValues(vtStats);
|
||||||
}
|
}
|
||||||
@@ -1354,7 +1361,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
Context.TELEPHONY_SERVICE);
|
Context.TELEPHONY_SERVICE);
|
||||||
|
|
||||||
// Merge video calling data usage into XT
|
// Merge video calling data usage into XT
|
||||||
final NetworkStats vtSnapshot = telephonyManager.getVtDataUsage(false);
|
final NetworkStats vtSnapshot = telephonyManager.getVtDataUsage(STATS_PER_IFACE);
|
||||||
if (vtSnapshot != null) {
|
if (vtSnapshot != null) {
|
||||||
xtSnapshot.combineAllValues(vtSnapshot);
|
xtSnapshot.combineAllValues(vtSnapshot);
|
||||||
}
|
}
|
||||||
@@ -1366,9 +1373,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
* Return snapshot of current tethering statistics. Will return empty
|
* Return snapshot of current tethering statistics. Will return empty
|
||||||
* {@link NetworkStats} if any problems are encountered.
|
* {@link NetworkStats} if any problems are encountered.
|
||||||
*/
|
*/
|
||||||
private NetworkStats getNetworkStatsTethering() throws RemoteException {
|
private NetworkStats getNetworkStatsTethering(int how) throws RemoteException {
|
||||||
try {
|
try {
|
||||||
return mNetworkManager.getNetworkStatsTethering();
|
return mNetworkManager.getNetworkStatsTethering(how);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
Log.wtf(TAG, "problem reading network stats", e);
|
Log.wtf(TAG, "problem reading network stats", e);
|
||||||
return new NetworkStats(0L, 10);
|
return new NetworkStats(0L, 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user