Merge changes I801ddc49,Id1b8f41b am: 2395cf16b9 am: 14b1bb2401
Change-Id: Ibc0b7c74ce55198fc6804b5cf1ea414aad912a4f
This commit is contained in:
@@ -21,7 +21,6 @@ import static android.os.Process.CLAT_UID;
|
|||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
@@ -58,9 +57,12 @@ import java.util.function.Predicate;
|
|||||||
public final class NetworkStats implements Parcelable {
|
public final class NetworkStats implements Parcelable {
|
||||||
private static final String TAG = "NetworkStats";
|
private static final String TAG = "NetworkStats";
|
||||||
|
|
||||||
/** {@link #iface} value when interface details unavailable. */
|
/**
|
||||||
@SuppressLint("CompileTimeConstant")
|
* {@link #iface} value when interface details unavailable.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Nullable public static final String IFACE_ALL = null;
|
@Nullable public static final String IFACE_ALL = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Virtual network interface for video telephony. This is for VT data usage counting
|
* Virtual network interface for video telephony. This is for VT data usage counting
|
||||||
* purpose.
|
* purpose.
|
||||||
@@ -248,7 +250,13 @@ public final class NetworkStats implements Parcelable {
|
|||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
private long[] operations;
|
private long[] operations;
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* Basic element of network statistics. Contains the number of packets and number of bytes
|
||||||
|
* transferred on both directions in a given set of conditions. See
|
||||||
|
* {@link Entry#Entry(String, int, int, int, int, int, int, long, long, long, long, long)}.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -319,6 +327,35 @@ public final class NetworkStats implements Parcelable {
|
|||||||
rxBytes, rxPackets, txBytes, txPackets, operations);
|
rxBytes, rxPackets, txBytes, txPackets, operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a {@link Entry} object by giving statistics of packet and byte transferred on
|
||||||
|
* both direction, and associated with a set of given conditions.
|
||||||
|
*
|
||||||
|
* @param iface interface name of this {@link Entry}. Or null if not specified.
|
||||||
|
* @param uid uid of this {@link Entry}. {@link #UID_TETHERING} if this {@link Entry} is
|
||||||
|
* for tethering. Or {@link #UID_ALL} if this {@link NetworkStats} is only
|
||||||
|
* counting iface stats.
|
||||||
|
* @param set usage state of this {@link Entry}. Should be one of the following
|
||||||
|
* values: {@link #SET_DEFAULT}, {@link #SET_FOREGROUND}.
|
||||||
|
* @param tag tag of this {@link Entry}.
|
||||||
|
* @param metered metered state of this {@link Entry}. Should be one of the following
|
||||||
|
* values: {link #METERED_YES}, {link #METERED_NO}.
|
||||||
|
* @param roaming roaming state of this {@link Entry}. Should be one of the following
|
||||||
|
* values: {link #ROAMING_YES}, {link #ROAMING_NO}.
|
||||||
|
* @param defaultNetwork default network status of this {@link Entry}. Should be one
|
||||||
|
* of the following values: {link #DEFAULT_NETWORK_YES},
|
||||||
|
* {link #DEFAULT_NETWORK_NO}.
|
||||||
|
* @param rxBytes Number of bytes received for this {@link Entry}. Statistics should
|
||||||
|
* represent the contents of IP packets, including IP headers.
|
||||||
|
* @param rxPackets Number of packets received for this {@link Entry}. Statistics should
|
||||||
|
* represent the contents of IP packets, including IP headers.
|
||||||
|
* @param txBytes Number of bytes transmitted for this {@link Entry}. Statistics should
|
||||||
|
* represent the contents of IP packets, including IP headers.
|
||||||
|
* @param txPackets Number of bytes transmitted for this {@link Entry}. Statistics should
|
||||||
|
* represent the contents of IP packets, including IP headers.
|
||||||
|
* @param operations count of network operations performed for this {@link Entry}. This can
|
||||||
|
* be used to derive bytes-per-operation.
|
||||||
|
*/
|
||||||
public Entry(@Nullable String iface, int uid, @State int set, int tag,
|
public Entry(@Nullable String iface, int uid, @State int set, int tag,
|
||||||
@Meteredness int metered, @Roaming int roaming, @DefaultNetwork int defaultNetwork,
|
@Meteredness int metered, @Roaming int roaming, @DefaultNetwork int defaultNetwork,
|
||||||
long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
|
long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
|
||||||
@@ -466,7 +503,7 @@ public final class NetworkStats implements Parcelable {
|
|||||||
NetworkStats.Entry entry = null;
|
NetworkStats.Entry entry = null;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
entry = getValues(i, entry);
|
entry = getValues(i, entry);
|
||||||
clone.addEntry(entry);
|
clone.insertEntry(entry);
|
||||||
}
|
}
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
@@ -493,26 +530,26 @@ public final class NetworkStats implements Parcelable {
|
|||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public NetworkStats addIfaceValues(
|
public NetworkStats insertEntry(
|
||||||
String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) {
|
String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) {
|
||||||
return addEntry(
|
return insertEntry(
|
||||||
iface, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, 0L);
|
iface, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public NetworkStats addEntry(String iface, int uid, int set, int tag, long rxBytes,
|
public NetworkStats insertEntry(String iface, int uid, int set, int tag, long rxBytes,
|
||||||
long rxPackets, long txBytes, long txPackets, long operations) {
|
long rxPackets, long txBytes, long txPackets, long operations) {
|
||||||
return addEntry(new Entry(
|
return insertEntry(new Entry(
|
||||||
iface, uid, set, tag, rxBytes, rxPackets, txBytes, txPackets, operations));
|
iface, uid, set, tag, rxBytes, rxPackets, txBytes, txPackets, operations));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public NetworkStats addEntry(String iface, int uid, int set, int tag, int metered, int roaming,
|
public NetworkStats insertEntry(String iface, int uid, int set, int tag, int metered,
|
||||||
int defaultNetwork, long rxBytes, long rxPackets, long txBytes, long txPackets,
|
int roaming, int defaultNetwork, long rxBytes, long rxPackets, long txBytes,
|
||||||
long operations) {
|
long txPackets, long operations) {
|
||||||
return addEntry(new Entry(
|
return insertEntry(new Entry(
|
||||||
iface, uid, set, tag, metered, roaming, defaultNetwork, rxBytes, rxPackets,
|
iface, uid, set, tag, metered, roaming, defaultNetwork, rxBytes, rxPackets,
|
||||||
txBytes, txPackets, operations));
|
txBytes, txPackets, operations));
|
||||||
}
|
}
|
||||||
@@ -522,7 +559,7 @@ public final class NetworkStats implements Parcelable {
|
|||||||
* object can be recycled across multiple calls.
|
* object can be recycled across multiple calls.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public NetworkStats addEntry(Entry entry) {
|
public NetworkStats insertEntry(Entry entry) {
|
||||||
if (size >= capacity) {
|
if (size >= capacity) {
|
||||||
final int newLength = Math.max(size, 10) * 3 / 2;
|
final int newLength = Math.max(size, 10) * 3 / 2;
|
||||||
iface = Arrays.copyOf(iface, newLength);
|
iface = Arrays.copyOf(iface, newLength);
|
||||||
@@ -665,7 +702,7 @@ public final class NetworkStats implements Parcelable {
|
|||||||
entry.roaming, entry.defaultNetwork);
|
entry.roaming, entry.defaultNetwork);
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
// only create new entry when positive contribution
|
// only create new entry when positive contribution
|
||||||
addEntry(entry);
|
insertEntry(entry);
|
||||||
} else {
|
} else {
|
||||||
rxBytes[i] += entry.rxBytes;
|
rxBytes[i] += entry.rxBytes;
|
||||||
rxPackets[i] += entry.rxPackets;
|
rxPackets[i] += entry.rxPackets;
|
||||||
@@ -1003,7 +1040,7 @@ public final class NetworkStats implements Parcelable {
|
|||||||
entry.operations = Math.max(entry.operations, 0);
|
entry.operations = Math.max(entry.operations, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.addEntry(entry);
|
result.insertEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ public class NetworkStatsFactory {
|
|||||||
entry.txPackets += reader.nextLong();
|
entry.txPackets += reader.nextLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.addEntry(entry);
|
stats.insertEntry(entry);
|
||||||
reader.finishLine();
|
reader.finishLine();
|
||||||
}
|
}
|
||||||
} catch (NullPointerException|NumberFormatException e) {
|
} catch (NullPointerException|NumberFormatException e) {
|
||||||
@@ -279,7 +279,7 @@ public class NetworkStatsFactory {
|
|||||||
entry.txBytes = reader.nextLong();
|
entry.txBytes = reader.nextLong();
|
||||||
entry.txPackets = reader.nextLong();
|
entry.txPackets = reader.nextLong();
|
||||||
|
|
||||||
stats.addEntry(entry);
|
stats.insertEntry(entry);
|
||||||
reader.finishLine();
|
reader.finishLine();
|
||||||
}
|
}
|
||||||
} catch (NullPointerException|NumberFormatException e) {
|
} catch (NullPointerException|NumberFormatException e) {
|
||||||
@@ -439,7 +439,7 @@ public class NetworkStatsFactory {
|
|||||||
if ((limitIfaces == null || ArrayUtils.contains(limitIfaces, entry.iface))
|
if ((limitIfaces == null || ArrayUtils.contains(limitIfaces, entry.iface))
|
||||||
&& (limitUid == UID_ALL || limitUid == entry.uid)
|
&& (limitUid == UID_ALL || limitUid == entry.uid)
|
||||||
&& (limitTag == TAG_ALL || limitTag == entry.tag)) {
|
&& (limitTag == TAG_ALL || limitTag == entry.tag)) {
|
||||||
stats.addEntry(entry);
|
stats.insertEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.finishLine();
|
reader.finishLine();
|
||||||
|
|||||||
@@ -759,7 +759,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final NetworkStatsHistory.Entry entry = history.getValues(start, end, now, null);
|
final NetworkStatsHistory.Entry entry = history.getValues(start, end, now, null);
|
||||||
|
|
||||||
final NetworkStats stats = new NetworkStats(end - start, 1);
|
final NetworkStats stats = new NetworkStats(end - start, 1);
|
||||||
stats.addEntry(new NetworkStats.Entry(IFACE_ALL, UID_ALL, SET_ALL, TAG_NONE,
|
stats.insertEntry(new NetworkStats.Entry(IFACE_ALL, UID_ALL, SET_ALL, TAG_NONE,
|
||||||
METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, entry.rxBytes, entry.rxPackets,
|
METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, entry.rxBytes, entry.rxPackets,
|
||||||
entry.txBytes, entry.txPackets, entry.operations));
|
entry.txBytes, entry.txPackets, entry.operations));
|
||||||
return stats;
|
return stats;
|
||||||
|
|||||||
Reference in New Issue
Block a user