Transition from DEV network stats to XT.
When XT stats are available, transition to prefer them over DEV, since they aren't subject to hardware driver bugs. Only switches at the first atomic XT bucket, and adds a Settings.Secure flag to force back to DEV if needed. Includes tests to cover transition. Fix tests where device overlay would change which network types reflected data usage. Test both history and summary APIs. Fixed collection timestamps to reflect full buckets. Bug: 6504744 Change-Id: Idd7f3b2fdb064c36547c85c51c214fd938c59b7e
This commit is contained in:
@@ -111,6 +111,14 @@ public class NetworkStats implements Parcelable {
|
||||
&& operations == 0;
|
||||
}
|
||||
|
||||
public void add(Entry another) {
|
||||
this.rxBytes += another.rxBytes;
|
||||
this.rxPackets += another.rxPackets;
|
||||
this.txBytes += another.txBytes;
|
||||
this.txPackets += another.txPackets;
|
||||
this.operations += another.operations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
@@ -342,11 +342,23 @@ public class NetworkStatsHistory implements Parcelable {
|
||||
* for combining together stats for external reporting.
|
||||
*/
|
||||
public void recordEntireHistory(NetworkStatsHistory input) {
|
||||
recordHistory(input, Long.MIN_VALUE, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Record given {@link NetworkStatsHistory} into this history, copying only
|
||||
* buckets that atomically occur in the inclusive time range. Doesn't
|
||||
* interpolate across partial buckets.
|
||||
*/
|
||||
public void recordHistory(NetworkStatsHistory input, long start, long end) {
|
||||
final NetworkStats.Entry entry = new NetworkStats.Entry(
|
||||
IFACE_ALL, UID_ALL, SET_DEFAULT, TAG_NONE, 0L, 0L, 0L, 0L, 0L);
|
||||
for (int i = 0; i < input.bucketCount; i++) {
|
||||
final long start = input.bucketStart[i];
|
||||
final long end = start + input.bucketDuration;
|
||||
final long bucketStart = input.bucketStart[i];
|
||||
final long bucketEnd = bucketStart + input.bucketDuration;
|
||||
|
||||
// skip when bucket is outside requested range
|
||||
if (bucketStart < start || bucketEnd > end) continue;
|
||||
|
||||
entry.rxBytes = getLong(input.rxBytes, i, 0L);
|
||||
entry.rxPackets = getLong(input.rxPackets, i, 0L);
|
||||
@@ -354,7 +366,7 @@ public class NetworkStatsHistory implements Parcelable {
|
||||
entry.txPackets = getLong(input.txPackets, i, 0L);
|
||||
entry.operations = getLong(input.operations, i, 0L);
|
||||
|
||||
recordData(start, end, entry);
|
||||
recordData(bucketStart, bucketEnd, entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,13 @@ public class NetworkTemplate implements Parcelable {
|
||||
com.android.internal.R.array.config_data_usage_network_types);
|
||||
}
|
||||
|
||||
private static boolean sForceAllNetworkTypes = false;
|
||||
|
||||
// @VisibleForTesting
|
||||
public static void forceAllNetworkTypes() {
|
||||
sForceAllNetworkTypes = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||
* the given IMSI.
|
||||
@@ -225,7 +232,7 @@ public class NetworkTemplate implements Parcelable {
|
||||
// TODO: consider matching against WiMAX subscriber identity
|
||||
return true;
|
||||
} else {
|
||||
return (contains(DATA_USAGE_NETWORK_TYPES, ident.mType)
|
||||
return ((sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType))
|
||||
&& Objects.equal(mSubscriberId, ident.mSubscriberId));
|
||||
}
|
||||
}
|
||||
@@ -291,7 +298,7 @@ public class NetworkTemplate implements Parcelable {
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
return true;
|
||||
} else {
|
||||
return contains(DATA_USAGE_NETWORK_TYPES, ident.mType);
|
||||
return sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user