From 9ac251d1169639c7b955d63b21e80cbc5c394090 Mon Sep 17 00:00:00 2001 From: Stephen Chen Date: Tue, 18 Oct 2016 16:41:47 -0700 Subject: [PATCH] Define API for metering network stats buckets. This is a continuation of b/26545374, since now we can also set the metered bit with NetworkScorer. The tracking of metered state changes will be implemented in a seperate CL. Bug: 31015360 Bug: 26545374 Test: N/A Change-Id: I0eccd10c0316357abb03af4d9cf0c4191a66abfb --- api/current.txt | 4 ++ api/system-current.txt | 4 ++ api/test-current.txt | 4 ++ core/java/android/app/usage/NetworkStats.java | 42 +++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/api/current.txt b/api/current.txt index 564653ae1824d..279de4ba2e9b9 100644 --- a/api/current.txt +++ b/api/current.txt @@ -6501,6 +6501,7 @@ package android.app.usage { public static class NetworkStats.Bucket { ctor public NetworkStats.Bucket(); method public long getEndTimeStamp(); + method public int getMetered(); method public int getRoaming(); method public long getRxBytes(); method public long getRxPackets(); @@ -6510,6 +6511,9 @@ package android.app.usage { method public long getTxBytes(); method public long getTxPackets(); method public int getUid(); + field public static final int METERED_ALL = -1; // 0xffffffff + field public static final int METERED_NO = 1; // 0x1 + field public static final int METERED_YES = 2; // 0x2 field public static final int ROAMING_ALL = -1; // 0xffffffff field public static final int ROAMING_NO = 1; // 0x1 field public static final int ROAMING_YES = 2; // 0x2 diff --git a/api/system-current.txt b/api/system-current.txt index fd51a6a7eb529..69d4b395598ed 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6790,6 +6790,7 @@ package android.app.usage { public static class NetworkStats.Bucket { ctor public NetworkStats.Bucket(); method public long getEndTimeStamp(); + method public int getMetered(); method public int getRoaming(); method public long getRxBytes(); method public long getRxPackets(); @@ -6799,6 +6800,9 @@ package android.app.usage { method public long getTxBytes(); method public long getTxPackets(); method public int getUid(); + field public static final int METERED_ALL = -1; // 0xffffffff + field public static final int METERED_NO = 1; // 0x1 + field public static final int METERED_YES = 2; // 0x2 field public static final int ROAMING_ALL = -1; // 0xffffffff field public static final int ROAMING_NO = 1; // 0x1 field public static final int ROAMING_YES = 2; // 0x2 diff --git a/api/test-current.txt b/api/test-current.txt index 150fbfeb226c3..fd6342fbb40cf 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -6510,6 +6510,7 @@ package android.app.usage { public static class NetworkStats.Bucket { ctor public NetworkStats.Bucket(); method public long getEndTimeStamp(); + method public int getMetered(); method public int getRoaming(); method public long getRxBytes(); method public long getRxPackets(); @@ -6519,6 +6520,9 @@ package android.app.usage { method public long getTxBytes(); method public long getTxPackets(); method public int getUid(); + field public static final int METERED_ALL = -1; // 0xffffffff + field public static final int METERED_NO = 1; // 0x1 + field public static final int METERED_YES = 2; // 0x2 field public static final int ROAMING_ALL = -1; // 0xffffffff field public static final int ROAMING_NO = 1; // 0x1 field public static final int ROAMING_YES = 2; // 0x2 diff --git a/core/java/android/app/usage/NetworkStats.java b/core/java/android/app/usage/NetworkStats.java index 226aa8f2706da..f64bec73e4c8f 100644 --- a/core/java/android/app/usage/NetworkStats.java +++ b/core/java/android/app/usage/NetworkStats.java @@ -163,6 +163,29 @@ public final class NetworkStats implements AutoCloseable { */ public static final int UID_TETHERING = TrafficStats.UID_TETHERING; + /** @hide */ + @IntDef({METERED_ALL, METERED_NO, METERED_YES}) + @Retention(RetentionPolicy.SOURCE) + public @interface Metered {} + + /** + * Combined usage across all metered states. Covers metered and unmetered usage. + */ + public static final int METERED_ALL = -1; + + /** + * Usage that occurs on an unmetered network. + */ + public static final int METERED_NO = 0x1; + + /** + * Usage that occurs on a metered network. + * + *

A network is classified as metered when the user is sensitive to heavy data usage on + * that connection. + */ + public static final int METERED_YES = 0x2; + /** @hide */ @IntDef({ROAMING_ALL, ROAMING_NO, ROAMING_YES}) @Retention(RetentionPolicy.SOURCE) @@ -200,6 +223,7 @@ public final class NetworkStats implements AutoCloseable { private int mUid; private int mTag; private int mState; + private int mMetered; private int mRoaming; private long mBeginTimeStamp; private long mEndTimeStamp; @@ -278,6 +302,21 @@ public final class NetworkStats implements AutoCloseable { return mState; } + /** + * Metered state. One of the following values:

+ *

+ *

A network is classified as metered when the user is sensitive to heavy data usage on + * that connection. Apps may warn before using these networks for large downloads. The + * metered state can be set by the user within data usage network restrictions. + */ + public @Metered int getMetered() { + return mMetered; + } + /** * Roaming state. One of the following values:

*