From 2bb66f5d4824f152d4a3b1884c942f7014893e34 Mon Sep 17 00:00:00 2001 From: Antonio Cansado Date: Thu, 10 Dec 2015 15:57:56 -0800 Subject: [PATCH] Retuning tag information through NetworkStatsManager. Network tags could be set since ICS but was not exposed through the SDK. This CL extends existing functionality of NetworkStatsManager to return network tags. Bug: 25813338 Change-Id: I414b98193249ba88a3f2d64cb2e0d2633f64fa3f --- core/java/android/app/usage/NetworkStats.java | 44 ++++++++-- .../app/usage/NetworkStatsManager.java | 87 ++++++++++++++----- core/java/android/net/NetworkStats.java | 2 + 3 files changed, 105 insertions(+), 28 deletions(-) diff --git a/core/java/android/app/usage/NetworkStats.java b/core/java/android/app/usage/NetworkStats.java index 5622207941..9f1a9cf01e 100644 --- a/core/java/android/app/usage/NetworkStats.java +++ b/core/java/android/app/usage/NetworkStats.java @@ -48,7 +48,6 @@ public final class NetworkStats implements AutoCloseable { */ private final long mEndTimeStamp; - /** * Non-null array indicates the query enumerates over uids. */ @@ -165,7 +164,18 @@ public final class NetworkStats implements AutoCloseable { */ public static final int ROAMING_ROAMING = 0x2; + /** + * Special TAG value matching any tag. + */ + public static final int TAG_ANY = android.net.NetworkStats.TAG_ALL; + + /** + * Special TAG value for total data across all tags + */ + public static final int TAG_ALL = android.net.NetworkStats.TAG_NONE; + private int mUid; + private int mTag; private int mState; private int mRoaming; private long mBeginTimeStamp; @@ -192,6 +202,14 @@ public final class NetworkStats implements AutoCloseable { return uid; } + private static int convertTag(int tag) { + switch (tag) { + case android.net.NetworkStats.TAG_ALL: return TAG_ANY; + case android.net.NetworkStats.TAG_NONE: return TAG_ALL; + } + return tag; + } + private static int convertRoaming(int roaming) { switch (roaming) { case android.net.NetworkStats.ROAMING_ALL : return ROAMING_ALL; @@ -217,6 +235,14 @@ public final class NetworkStats implements AutoCloseable { return mUid; } + /** + * Tag of the bucket.

+ * @return Bucket tag. + */ + public int getTag() { + return mTag; + } + /** * Usage state. One of the following values:

*