diff --git a/core/java/android/app/usage/NetworkStats.java b/core/java/android/app/usage/NetworkStats.java index 9f1a9cf01e..6d5c81b142 100644 --- a/core/java/android/app/usage/NetworkStats.java +++ b/core/java/android/app/usage/NetworkStats.java @@ -16,6 +16,7 @@ package android.app.usage; +import android.annotation.IntDef; import android.content.Context; import android.net.INetworkStatsService; import android.net.INetworkStatsSession; @@ -29,6 +30,9 @@ import android.util.Log; import dalvik.system.CloseGuard; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * Class providing enumeration over buckets of network usage statistics. {@link NetworkStats} objects * are returned as results to various queries in {@link NetworkStatsManager}. @@ -119,6 +123,11 @@ public final class NetworkStats implements AutoCloseable { * aggregated (e.g. time or state) some values may be equal across all buckets. */ public static class Bucket { + /** @hide */ + @IntDef({STATE_ALL, STATE_DEFAULT, STATE_FOREGROUND}) + @Retention(RetentionPolicy.SOURCE) + public @interface State {} + /** * Combined usage across all states. */ @@ -149,20 +158,34 @@ public final class NetworkStats implements AutoCloseable { */ public static final int UID_TETHERING = TrafficStats.UID_TETHERING; + /** @hide */ + @IntDef({ROAMING_ALL, ROAMING_NO, ROAMING_YES}) + @Retention(RetentionPolicy.SOURCE) + public @interface Roaming {} + /** - * Combined usage across all roaming states. + * Combined usage across all roaming states. Covers both roaming and non-roaming usage. */ public static final int ROAMING_ALL = -1; /** - * Usage not accounted for in any other roaming state. + * Usage that occurs on a home, non-roaming network. + * + *

Any cellular usage in this bucket was incurred while the device was connected to a + * tower owned or operated by the user's wireless carrier, or a tower that the user's + * wireless carrier has indicated should be treated as a home network regardless. + * + *

This is also the default value for network types that do not support roaming. */ - public static final int ROAMING_DEFAULT = 0x1; + public static final int ROAMING_NO = 0x1; /** - * Roaming usage. + * Usage that occurs on a roaming network. + * + *

Any cellular usage in this bucket as incurred while the device was roaming on another + * carrier's network, for which additional charges may apply. */ - public static final int ROAMING_ROAMING = 0x2; + public static final int ROAMING_YES = 0x2; /** * Special TAG value matching any tag. @@ -185,7 +208,7 @@ public final class NetworkStats implements AutoCloseable { private long mTxBytes; private long mTxPackets; - private static int convertState(int networkStatsSet) { + private static @State int convertState(int networkStatsSet) { switch (networkStatsSet) { case android.net.NetworkStats.SET_ALL : return STATE_ALL; case android.net.NetworkStats.SET_DEFAULT : return STATE_DEFAULT; @@ -210,11 +233,11 @@ public final class NetworkStats implements AutoCloseable { return tag; } - private static int convertRoaming(int roaming) { + private static @Roaming int convertRoaming(int roaming) { switch (roaming) { case android.net.NetworkStats.ROAMING_ALL : return ROAMING_ALL; - case android.net.NetworkStats.ROAMING_DEFAULT : return ROAMING_DEFAULT; - case android.net.NetworkStats.ROAMING_ROAMING : return ROAMING_ROAMING; + case android.net.NetworkStats.ROAMING_NO: return ROAMING_NO; + case android.net.NetworkStats.ROAMING_YES: return ROAMING_YES; } return 0; } @@ -252,7 +275,7 @@ public final class NetworkStats implements AutoCloseable { * * @return Usage state. */ - public int getState() { + public @State int getState() { return mState; } @@ -260,11 +283,11 @@ public final class NetworkStats implements AutoCloseable { * Roaming state. One of the following values:

*

*/ - public int getRoaming() { + public @Roaming int getRoaming() { return mRoaming; } diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java index 3d8b0917a3..25806fa776 100644 --- a/core/java/android/net/NetworkStats.java +++ b/core/java/android/net/NetworkStats.java @@ -71,9 +71,9 @@ public class NetworkStats implements Parcelable { /** {@link #set} value for all roaming values. */ public static final int ROAMING_ALL = -1; /** {@link #set} value where native, non-roaming data is accounted. */ - public static final int ROAMING_DEFAULT = 0; + public static final int ROAMING_NO = 0; /** {@link #set} value where roaming data is accounted. */ - public static final int ROAMING_ROAMING = 1; + public static final int ROAMING_YES = 1; // TODO: move fields to "mVariable" notation @@ -123,7 +123,7 @@ public class NetworkStats implements Parcelable { public Entry(String iface, int uid, int set, int tag, long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) { - this(iface, uid, set, tag, ROAMING_DEFAULT, rxBytes, rxPackets, txBytes, txPackets, + this(iface, uid, set, tag, ROAMING_NO, rxBytes, rxPackets, txBytes, txPackets, operations); } @@ -836,10 +836,10 @@ public class NetworkStats implements Parcelable { switch (roaming) { case ROAMING_ALL: return "ALL"; - case ROAMING_DEFAULT: - return "DEFAULT"; - case ROAMING_ROAMING: - return "ROAMING"; + case ROAMING_NO: + return "NO"; + case ROAMING_YES: + return "YES"; default: return "UNKNOWN"; } @@ -1019,18 +1019,18 @@ public class NetworkStats implements Parcelable { // Caveat: if the vpn software uses tag, the total tagged traffic may be greater than // the TAG_NONE traffic. // - // Relies on the fact that the underlying traffic only has state ROAMING_DEFAULT, which + // Relies on the fact that the underlying traffic only has state ROAMING_NO, which // should be the case as it comes directly from the /proc file. We only blend in the // roaming data after applying these adjustments, by checking the NetworkIdentity of the // underlying iface. int idxVpnBackground = findIndex(underlyingIface, tunUid, SET_DEFAULT, TAG_NONE, - ROAMING_DEFAULT); + ROAMING_NO); if (idxVpnBackground != -1) { tunSubtract(idxVpnBackground, this, moved); } int idxVpnForeground = findIndex(underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE, - ROAMING_DEFAULT); + ROAMING_NO); if (idxVpnForeground != -1) { tunSubtract(idxVpnForeground, this, moved); } diff --git a/services/core/java/com/android/server/net/NetworkStatsCollection.java b/services/core/java/com/android/server/net/NetworkStatsCollection.java index d986e94b02..673dd8fbbd 100644 --- a/services/core/java/com/android/server/net/NetworkStatsCollection.java +++ b/services/core/java/com/android/server/net/NetworkStatsCollection.java @@ -17,8 +17,8 @@ package com.android.server.net; import static android.net.NetworkStats.IFACE_ALL; -import static android.net.NetworkStats.ROAMING_DEFAULT; -import static android.net.NetworkStats.ROAMING_ROAMING; +import static android.net.NetworkStats.ROAMING_NO; +import static android.net.NetworkStats.ROAMING_YES; import static android.net.NetworkStats.SET_ALL; import static android.net.NetworkStats.SET_DEFAULT; import static android.net.NetworkStats.TAG_NONE; @@ -242,7 +242,7 @@ public class NetworkStatsCollection implements FileRotator.Reader { entry.uid = key.uid; entry.set = key.set; entry.tag = key.tag; - entry.roaming = key.ident.isAnyMemberRoaming() ? ROAMING_ROAMING : ROAMING_DEFAULT; + entry.roaming = key.ident.isAnyMemberRoaming() ? ROAMING_YES : ROAMING_NO; entry.rxBytes = historyEntry.rxBytes; entry.rxPackets = historyEntry.rxPackets; entry.txBytes = historyEntry.txBytes;