Rename NetworkUsageStats -> NetworkStats
Also making other changes to Data Usage API as requested by API review.
Bug: 20823478
Change-Id: Id766c5a725c856da9d8883d73ae788fc1472440a
diff --git a/core/java/android/app/usage/NetworkUsageStats.java b/core/java/android/app/usage/NetworkStats.java
similarity index 92%
rename from core/java/android/app/usage/NetworkUsageStats.java
rename to core/java/android/app/usage/NetworkStats.java
index 990d231..5193563 100644
--- a/core/java/android/app/usage/NetworkUsageStats.java
+++ b/core/java/android/app/usage/NetworkStats.java
@@ -19,7 +19,6 @@
import android.content.Context;
import android.net.INetworkStatsService;
import android.net.INetworkStatsSession;
-import android.net.NetworkStats;
import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate;
import android.net.TrafficStats;
@@ -33,7 +32,7 @@
* Class providing enumeration over buckets of network usage statistics. NetworkUsageStats objects
* are returned as results to various queries in {@link NetworkStatsManager}.
*/
-public final class NetworkUsageStats implements AutoCloseable {
+public final class NetworkStats implements AutoCloseable {
private final static String TAG = "NetworkUsageStats";
private final CloseGuard mCloseGuard = CloseGuard.get();
@@ -70,7 +69,7 @@
/**
* Results of a summary query.
*/
- private NetworkStats mSummary = null;
+ private android.net.NetworkStats mSummary = null;
/**
* Results of detail queries.
@@ -85,11 +84,11 @@
/**
* Recycling entry objects to prevent heap fragmentation.
*/
- private NetworkStats.Entry mRecycledSummaryEntry = null;
+ private android.net.NetworkStats.Entry mRecycledSummaryEntry = null;
private NetworkStatsHistory.Entry mRecycledHistoryEntry = null;
/** @hide */
- NetworkUsageStats(Context context, NetworkTemplate template, long startTimestamp,
+ NetworkStats(Context context, NetworkTemplate template, long startTimestamp,
long endTimestamp) throws RemoteException, SecurityException {
final INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
@@ -136,14 +135,19 @@
public static final int STATE_FOREGROUND = 0x2;
/**
+ * Special UID value for aggregate/unspecified.
+ */
+ public static final int UID_ALL = android.net.NetworkStats.UID_ALL;
+
+ /**
* Special UID value for removed apps.
*/
- public static final int UID_REMOVED = -4;
+ public static final int UID_REMOVED = TrafficStats.UID_REMOVED;
/**
* Special UID value for data usage by tethering.
*/
- public static final int UID_TETHERING = -5;
+ public static final int UID_TETHERING = TrafficStats.UID_TETHERING;
private int mUid;
private int mState;
@@ -156,9 +160,9 @@
private static int convertState(int networkStatsSet) {
switch (networkStatsSet) {
- case NetworkStats.SET_ALL : return STATE_ALL;
- case NetworkStats.SET_DEFAULT : return STATE_DEFAULT;
- case NetworkStats.SET_FOREGROUND : return STATE_FOREGROUND;
+ case android.net.NetworkStats.SET_ALL : return STATE_ALL;
+ case android.net.NetworkStats.SET_DEFAULT : return STATE_DEFAULT;
+ case android.net.NetworkStats.SET_FOREGROUND : return STATE_FOREGROUND;
}
return 0;
}
@@ -337,8 +341,8 @@
void startHistoryEnumeration(int uid) {
mHistory = null;
try {
- mHistory = mSession.getHistoryForUid(mTemplate, uid, NetworkStats.SET_ALL,
- NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL);
+ mHistory = mSession.getHistoryForUid(mTemplate, uid, android.net.NetworkStats.SET_ALL,
+ android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL);
setSingleUid(uid);
} catch (RemoteException e) {
Log.w(TAG, e);
@@ -364,8 +368,9 @@
stepUid();
mHistory = null;
try {
- mHistory = mSession.getHistoryForUid(mTemplate, getUid(), NetworkStats.SET_ALL,
- NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL);
+ mHistory = mSession.getHistoryForUid(mTemplate, getUid(),
+ android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE,
+ NetworkStatsHistory.FIELD_ALL);
} catch (RemoteException e) {
Log.w(TAG, e);
// Leaving mHistory null
@@ -405,7 +410,7 @@
}
Bucket bucket = new Bucket();
if (mRecycledSummaryEntry == null) {
- mRecycledSummaryEntry = new NetworkStats.Entry();
+ mRecycledSummaryEntry = new android.net.NetworkStats.Entry();
}
mSummary.getTotal(mRecycledSummaryEntry);
fillBucketFromSummaryEntry(bucket);
diff --git a/core/java/android/app/usage/NetworkStatsManager.java b/core/java/android/app/usage/NetworkStatsManager.java
index af7c053..2ae0181 100644
--- a/core/java/android/app/usage/NetworkStatsManager.java
+++ b/core/java/android/app/usage/NetworkStatsManager.java
@@ -16,18 +16,17 @@
package android.app.usage;
-import android.app.usage.NetworkUsageStats.Bucket;
+import android.app.usage.NetworkStats.Bucket;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkIdentity;
import android.net.NetworkTemplate;
import android.os.RemoteException;
-import android.os.UserHandle;
import android.util.Log;
/**
* Provides access to network usage history and statistics. Usage data is collected in
- * discrete bins of time called 'Buckets'. See {@link NetworkUsageStats.Bucket} for details.
+ * discrete bins of time called 'Buckets'. See {@link NetworkStats.Bucket} for details.
* <p />
* Queries can define a time interval in the form of start and end timestamps (Long.MIN_VALUE and
* Long.MAX_VALUE can be used to simulate open ended intervals). All queries (except
@@ -37,15 +36,20 @@
* <h3>
* Summary queries
* </h3>
+ * {@link #querySummaryForDevice} <p />
+ * {@link #querySummaryForUser} <p />
+ * {@link #querySummary} <p />
* These queries aggregate network usage across the whole interval. Therefore there will be only one
* bucket for a particular key and state combination. In case of the user-wide and device-wide
* summaries a single bucket containing the totalised network usage is returned.
* <h3>
* History queries
* </h3>
+ * {@link #queryDetailsForUid} <p />
+ * {@link #queryDetails} <p />
* These queries do not aggregate over time but do aggregate over state. Therefore there can be
* multiple buckets for a particular key but all Bucket's state is going to be
- * {@link NetworkUsageStats.Bucket#STATE_ALL}.
+ * {@link NetworkStats.Bucket#STATE_ALL}.
* <p />
* <b>NOTE:</b> This API requires the permission
* {@link android.Manifest.permission#PACKAGE_USAGE_STATS}, which is a system-level permission and
@@ -68,7 +72,10 @@
}
/**
* Query network usage statistics summaries. Result is summarised data usage for the whole
- * device. Result is a single Bucket aggregated over time, state and uid.
+ * device. Result is a single Bucket aggregated over time, state and uid. This means the
+ * bucket's start and end timestamp are going to be the same as the 'startTime' and 'endTime'
+ * parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid
+ * {@link NetworkStats.Bucket#UID_ALL}.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -89,7 +96,7 @@
}
Bucket bucket = null;
- NetworkUsageStats stats = new NetworkUsageStats(mContext, template, startTime, endTime);
+ NetworkStats stats = new NetworkStats(mContext, template, startTime, endTime);
bucket = stats.getDeviceSummaryForNetwork(startTime, endTime);
stats.close();
@@ -99,6 +106,9 @@
/**
* Query network usage statistics summaries. Result is summarised data usage for all uids
* belonging to calling user. Result is a single Bucket aggregated over time, state and uid.
+ * This means the bucket's start and end timestamp are going to be the same as the 'startTime'
+ * and 'endTime' parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid
+ * {@link NetworkStats.Bucket#UID_ALL}.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -118,8 +128,8 @@
return null;
}
- NetworkUsageStats stats;
- stats = new NetworkUsageStats(mContext, template, startTime, endTime);
+ NetworkStats stats;
+ stats = new NetworkStats(mContext, template, startTime, endTime);
stats.startSummaryEnumeration(startTime, endTime);
stats.close();
@@ -129,7 +139,9 @@
/**
* Query network usage statistics summaries. Result filtered to include only uids belonging to
* calling user. Result is aggregated over time, hence all buckets will have the same start and
- * end timestamps. Not aggregated over state or uid.
+ * end timestamps. Not aggregated over state or uid. This means buckets' start and end
+ * timestamps are going to be the same as the 'startTime' and 'endTime' parameters, state and
+ * uid are going to vary.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -142,15 +154,15 @@
* @return Statistics object or null if permissions are insufficient or error happened during
* statistics collection.
*/
- public NetworkUsageStats querySummary(int networkType, String subscriberId, long startTime,
+ public NetworkStats querySummary(int networkType, String subscriberId, long startTime,
long endTime) throws SecurityException, RemoteException {
NetworkTemplate template = createTemplate(networkType, subscriberId);
if (template == null) {
return null;
}
- NetworkUsageStats result;
- result = new NetworkUsageStats(mContext, template, startTime, endTime);
+ NetworkStats result;
+ result = new NetworkStats(mContext, template, startTime, endTime);
result.startSummaryEnumeration(startTime, endTime);
return result;
@@ -158,7 +170,9 @@
/**
* Query network usage statistics details. Only usable for uids belonging to calling user.
- * Result is aggregated over state but not aggregated over time.
+ * Result is aggregated over state but not aggregated over time. This means buckets' start and
+ * end timestamps are going to be between 'startTime' and 'endTime' parameters, state is going
+ * to be {@link NetworkStats.Bucket#STATE_ALL} and uid the same as the 'uid' parameter.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -172,15 +186,15 @@
* @return Statistics object or null if permissions are insufficient or error happened during
* statistics collection.
*/
- public NetworkUsageStats queryDetailsForUid(int networkType, String subscriberId,
+ public NetworkStats queryDetailsForUid(int networkType, String subscriberId,
long startTime, long endTime, int uid) throws SecurityException, RemoteException {
NetworkTemplate template = createTemplate(networkType, subscriberId);
if (template == null) {
return null;
}
- NetworkUsageStats result;
- result = new NetworkUsageStats(mContext, template, startTime, endTime);
+ NetworkStats result;
+ result = new NetworkStats(mContext, template, startTime, endTime);
result.startHistoryEnumeration(uid);
return result;
@@ -188,7 +202,9 @@
/**
* Query network usage statistics details. Result filtered to include only uids belonging to
- * calling user. Result is aggregated over state but not aggregated over time or uid.
+ * calling user. Result is aggregated over state but not aggregated over time or uid. This means
+ * buckets' start and end timestamps are going to be between 'startTime' and 'endTime'
+ * parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid will vary.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -201,14 +217,14 @@
* @return Statistics object or null if permissions are insufficient or error happened during
* statistics collection.
*/
- public NetworkUsageStats queryDetails(int networkType, String subscriberId, long startTime,
+ public NetworkStats queryDetails(int networkType, String subscriberId, long startTime,
long endTime) throws SecurityException, RemoteException {
NetworkTemplate template = createTemplate(networkType, subscriberId);
if (template == null) {
return null;
}
- NetworkUsageStats result;
- result = new NetworkUsageStats(mContext, template, startTime, endTime);
+ NetworkStats result;
+ result = new NetworkStats(mContext, template, startTime, endTime);
result.startUserUidEnumeration();
return result;
}