field public static final android.os.Parcelable.Creator<android.app.usage.ConfigurationStats> CREATOR;
}
- public class DataUsagePolicy {
- field public final int networkType;
- field public final java.lang.String[] subscriberIds;
- field public final long thresholdInBytes;
- field public final int[] uids;
- }
-
- public static class DataUsagePolicy.Builder {
- ctor public DataUsagePolicy.Builder();
- method public android.app.usage.DataUsagePolicy.Builder addSubscriberId(java.lang.String);
- method public android.app.usage.DataUsagePolicy.Builder addUid(int);
- method public android.app.usage.DataUsagePolicy build();
- method public android.app.usage.DataUsagePolicy.Builder setNetworkType(int);
- method public android.app.usage.DataUsagePolicy.Builder setThreshold(long);
- }
-
public final class NetworkStats implements java.lang.AutoCloseable {
method public void close();
method public boolean getNextBucket(android.app.usage.NetworkStats.Bucket);
field public static final int STATE_ALL = -1; // 0xffffffff
field public static final int STATE_DEFAULT = 1; // 0x1
field public static final int STATE_FOREGROUND = 2; // 0x2
- field public static final int TAG_ALL = 0; // 0x0
- field public static final int TAG_ANY = -1; // 0xffffffff
+ field public static final int TAG_NONE = 0; // 0x0
field public static final int UID_ALL = -1; // 0xffffffff
field public static final int UID_REMOVED = -4; // 0xfffffffc
field public static final int UID_TETHERING = -5; // 0xfffffffb
public class NetworkStatsManager {
method public android.app.usage.NetworkStats queryDetails(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats queryDetailsForUid(int, java.lang.String, long, long, int) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats queryDetailsForUidTag(int, java.lang.String, long, long, int, int) throws android.os.RemoteException, java.lang.SecurityException;
+ method public android.app.usage.NetworkStats queryDetailsForUidTag(int, java.lang.String, long, long, int, int);
method public android.app.usage.NetworkStats querySummary(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats querySummary(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats.Bucket querySummaryForDevice(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
- method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback);
- method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback, android.os.Handler);
- method public void unregisterDataUsageCallback(android.app.usage.NetworkStatsManager.DataUsageCallback);
+ method public void registerUsageCallback(int, java.lang.String, long, android.app.usage.NetworkStatsManager.UsageCallback);
+ method public void registerUsageCallback(int, java.lang.String, long, android.app.usage.NetworkStatsManager.UsageCallback, android.os.Handler);
+ method public void unregisterUsageCallback(android.app.usage.NetworkStatsManager.UsageCallback);
}
- public static class NetworkStatsManager.DataUsageCallback {
- ctor public NetworkStatsManager.DataUsageCallback();
- method public void onLimitReached();
+ public static abstract class NetworkStatsManager.UsageCallback {
+ ctor public NetworkStatsManager.UsageCallback();
+ method public abstract void onThresholdReached(int, java.lang.String);
}
public final class UsageEvents implements android.os.Parcelable {
method public int getUid();
}
- public final class DataUsageRequest implements android.os.Parcelable {
- method public int describeContents();
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.net.DataUsageRequest> CREATOR;
- }
-
public class DhcpInfo implements android.os.Parcelable {
ctor public DhcpInfo();
method public int describeContents();
}
+package android.app.usage {
+
+ public class DataUsagePolicy {
+ field public final int networkType;
+ field public final java.lang.String[] subscriberIds;
+ field public final long thresholdInBytes;
+ field public final int[] uids;
+ }
+
+ public static class DataUsagePolicy.Builder {
+ ctor public DataUsagePolicy.Builder();
+ method public android.app.usage.DataUsagePolicy.Builder addSubscriberId(java.lang.String);
+ method public android.app.usage.DataUsagePolicy.Builder addUid(int);
+ method public android.app.usage.DataUsagePolicy build();
+ method public android.app.usage.DataUsagePolicy.Builder setNetworkType(int);
+ method public android.app.usage.DataUsagePolicy.Builder setThreshold(long);
+ }
+
+ public class NetworkStatsManager {
+ method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback, android.os.Handler);
+ method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.UsageCallback, android.os.Handler);
+ method public void unregisterDataUsageCallback(android.app.usage.NetworkStatsManager.DataUsageCallback);
+ }
+
+ public static abstract class NetworkStatsManager.DataUsageCallback {
+ ctor public NetworkStatsManager.DataUsageCallback();
+ method public deprecated void onLimitReached();
+ }
+
+}
+
package android.content {
public abstract class Context {
field public static final android.os.Parcelable.Creator<android.app.usage.ConfigurationStats> CREATOR;
}
- public class DataUsagePolicy {
- field public final int networkType;
- field public final java.lang.String[] subscriberIds;
- field public final long thresholdInBytes;
- field public final int[] uids;
- }
-
- public static class DataUsagePolicy.Builder {
- ctor public DataUsagePolicy.Builder();
- method public android.app.usage.DataUsagePolicy.Builder addSubscriberId(java.lang.String);
- method public android.app.usage.DataUsagePolicy.Builder addUid(int);
- method public android.app.usage.DataUsagePolicy build();
- method public android.app.usage.DataUsagePolicy.Builder setNetworkType(int);
- method public android.app.usage.DataUsagePolicy.Builder setThreshold(long);
- }
-
public final class NetworkStats implements java.lang.AutoCloseable {
method public void close();
method public boolean getNextBucket(android.app.usage.NetworkStats.Bucket);
field public static final int STATE_ALL = -1; // 0xffffffff
field public static final int STATE_DEFAULT = 1; // 0x1
field public static final int STATE_FOREGROUND = 2; // 0x2
- field public static final int TAG_ALL = 0; // 0x0
- field public static final int TAG_ANY = -1; // 0xffffffff
+ field public static final int TAG_NONE = 0; // 0x0
field public static final int UID_ALL = -1; // 0xffffffff
field public static final int UID_REMOVED = -4; // 0xfffffffc
field public static final int UID_TETHERING = -5; // 0xfffffffb
public class NetworkStatsManager {
method public android.app.usage.NetworkStats queryDetails(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats queryDetailsForUid(int, java.lang.String, long, long, int) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats queryDetailsForUidTag(int, java.lang.String, long, long, int, int) throws android.os.RemoteException, java.lang.SecurityException;
+ method public android.app.usage.NetworkStats queryDetailsForUidTag(int, java.lang.String, long, long, int, int);
method public android.app.usage.NetworkStats querySummary(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats querySummary(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats.Bucket querySummaryForDevice(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
- method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback);
- method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback, android.os.Handler);
- method public void unregisterDataUsageCallback(android.app.usage.NetworkStatsManager.DataUsageCallback);
+ method public void registerUsageCallback(int, java.lang.String, long, android.app.usage.NetworkStatsManager.UsageCallback);
+ method public void registerUsageCallback(int, java.lang.String, long, android.app.usage.NetworkStatsManager.UsageCallback, android.os.Handler);
+ method public void unregisterUsageCallback(android.app.usage.NetworkStatsManager.UsageCallback);
}
- public static class NetworkStatsManager.DataUsageCallback {
- ctor public NetworkStatsManager.DataUsageCallback();
- method public void onLimitReached();
+ public static abstract class NetworkStatsManager.UsageCallback {
+ ctor public NetworkStatsManager.UsageCallback();
+ method public abstract void onThresholdReached(int, java.lang.String);
}
public final class UsageEvents implements android.os.Parcelable {
method public int getUid();
}
- public final class DataUsageRequest implements android.os.Parcelable {
- method public int describeContents();
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.net.DataUsageRequest> CREATOR;
- }
-
public class DhcpInfo implements android.os.Parcelable {
ctor public DhcpInfo();
method public int describeContents();
}
+package android.app.usage {
+
+ public class DataUsagePolicy {
+ field public final int networkType;
+ field public final java.lang.String[] subscriberIds;
+ field public final long thresholdInBytes;
+ field public final int[] uids;
+ }
+
+ public static class DataUsagePolicy.Builder {
+ ctor public DataUsagePolicy.Builder();
+ method public android.app.usage.DataUsagePolicy.Builder addSubscriberId(java.lang.String);
+ method public android.app.usage.DataUsagePolicy.Builder addUid(int);
+ method public android.app.usage.DataUsagePolicy build();
+ method public android.app.usage.DataUsagePolicy.Builder setNetworkType(int);
+ method public android.app.usage.DataUsagePolicy.Builder setThreshold(long);
+ }
+
+ public class NetworkStatsManager {
+ method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback, android.os.Handler);
+ method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.UsageCallback, android.os.Handler);
+ method public void unregisterDataUsageCallback(android.app.usage.NetworkStatsManager.DataUsageCallback);
+ }
+
+ public static abstract class NetworkStatsManager.DataUsageCallback {
+ ctor public NetworkStatsManager.DataUsageCallback();
+ method public deprecated void onLimitReached();
+ }
+
+}
+
package android.content {
public abstract class Context {
field public static final android.os.Parcelable.Creator<android.app.usage.ConfigurationStats> CREATOR;
}
- public class DataUsagePolicy {
- field public final int networkType;
- field public final java.lang.String[] subscriberIds;
- field public final long thresholdInBytes;
- field public final int[] uids;
- }
-
- public static class DataUsagePolicy.Builder {
- ctor public DataUsagePolicy.Builder();
- method public android.app.usage.DataUsagePolicy.Builder addSubscriberId(java.lang.String);
- method public android.app.usage.DataUsagePolicy.Builder addUid(int);
- method public android.app.usage.DataUsagePolicy build();
- method public android.app.usage.DataUsagePolicy.Builder setNetworkType(int);
- method public android.app.usage.DataUsagePolicy.Builder setThreshold(long);
- }
-
public final class NetworkStats implements java.lang.AutoCloseable {
method public void close();
method public boolean getNextBucket(android.app.usage.NetworkStats.Bucket);
field public static final int STATE_ALL = -1; // 0xffffffff
field public static final int STATE_DEFAULT = 1; // 0x1
field public static final int STATE_FOREGROUND = 2; // 0x2
- field public static final int TAG_ALL = 0; // 0x0
- field public static final int TAG_ANY = -1; // 0xffffffff
+ field public static final int TAG_NONE = 0; // 0x0
field public static final int UID_ALL = -1; // 0xffffffff
field public static final int UID_REMOVED = -4; // 0xfffffffc
field public static final int UID_TETHERING = -5; // 0xfffffffb
public class NetworkStatsManager {
method public android.app.usage.NetworkStats queryDetails(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats queryDetailsForUid(int, java.lang.String, long, long, int) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats queryDetailsForUidTag(int, java.lang.String, long, long, int, int) throws android.os.RemoteException, java.lang.SecurityException;
+ method public android.app.usage.NetworkStats queryDetailsForUidTag(int, java.lang.String, long, long, int, int);
method public android.app.usage.NetworkStats querySummary(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats querySummary(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats.Bucket querySummaryForDevice(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
- method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
- method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback);
- method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback, android.os.Handler);
- method public void unregisterDataUsageCallback(android.app.usage.NetworkStatsManager.DataUsageCallback);
+ method public void registerUsageCallback(int, java.lang.String, long, android.app.usage.NetworkStatsManager.UsageCallback);
+ method public void registerUsageCallback(int, java.lang.String, long, android.app.usage.NetworkStatsManager.UsageCallback, android.os.Handler);
+ method public void unregisterUsageCallback(android.app.usage.NetworkStatsManager.UsageCallback);
}
- public static class NetworkStatsManager.DataUsageCallback {
- ctor public NetworkStatsManager.DataUsageCallback();
- method public void onLimitReached();
+ public static abstract class NetworkStatsManager.UsageCallback {
+ ctor public NetworkStatsManager.UsageCallback();
+ method public abstract void onThresholdReached(int, java.lang.String);
}
public final class UsageEvents implements android.os.Parcelable {
method public int getUid();
}
- public final class DataUsageRequest implements android.os.Parcelable {
- method public int describeContents();
- method public void writeToParcel(android.os.Parcel, int);
- field public static final android.os.Parcelable.Creator<android.net.DataUsageRequest> CREATOR;
- }
-
public class DhcpInfo implements android.os.Parcelable {
ctor public DhcpInfo();
method public int describeContents();
}
+package android.app.usage {
+
+ public class DataUsagePolicy {
+ field public final int networkType;
+ field public final java.lang.String[] subscriberIds;
+ field public final long thresholdInBytes;
+ field public final int[] uids;
+ }
+
+ public static class DataUsagePolicy.Builder {
+ ctor public DataUsagePolicy.Builder();
+ method public android.app.usage.DataUsagePolicy.Builder addSubscriberId(java.lang.String);
+ method public android.app.usage.DataUsagePolicy.Builder addUid(int);
+ method public android.app.usage.DataUsagePolicy build();
+ method public android.app.usage.DataUsagePolicy.Builder setNetworkType(int);
+ method public android.app.usage.DataUsagePolicy.Builder setThreshold(long);
+ }
+
+ public class NetworkStatsManager {
+ method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.DataUsageCallback, android.os.Handler);
+ method public void registerDataUsageCallback(android.app.usage.DataUsagePolicy, android.app.usage.NetworkStatsManager.UsageCallback, android.os.Handler);
+ method public void unregisterDataUsageCallback(android.app.usage.NetworkStatsManager.DataUsageCallback);
+ }
+
+ public static abstract class NetworkStatsManager.DataUsageCallback {
+ ctor public NetworkStatsManager.DataUsageCallback();
+ method public deprecated void onLimitReached();
+ }
+
+}
+
package android.content {
public abstract class Context {
/**
* Defines a policy for data usage callbacks, made through {@link DataUsagePolicy.Builder} and used
* to be notified on data usage via {@link NetworkStatsManager#registerDataUsageCallback}.
+ * @removed
*/
public class DataUsagePolicy {
public static final int ROAMING_YES = 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;
+ public static final int TAG_NONE = android.net.NetworkStats.TAG_NONE;
private int mUid;
private int mTag;
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;
+ case android.net.NetworkStats.TAG_NONE: return TAG_NONE;
}
return tag;
}
* Collects summary results and sets summary enumeration mode.
* @throws RemoteException
*/
- void startSummaryEnumeration(boolean includeTags) throws RemoteException {
+ void startSummaryEnumeration() throws RemoteException {
mSummary = mSession.getSummaryForAllUid(mTemplate, mStartTimeStamp, mEndTimeStamp,
- includeTags);
+ false /* includeTags */);
mEnumerationIndex = 0;
}
* device. Result is a single Bucket aggregated over time, state, uid, tag and roaming. 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}, uid
- * {@link NetworkStats.Bucket#UID_ALL}, tag {@link NetworkStats.Bucket#TAG_ALL}
+ * {@link NetworkStats.Bucket#UID_ALL}, tag {@link NetworkStats.Bucket#TAG_NONE}
* and roaming {@link NetworkStats.Bucket#ROAMING_ALL}.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
*/
public Bucket querySummaryForDevice(int networkType, String subscriberId,
long startTime, long endTime) throws SecurityException, RemoteException {
- NetworkTemplate template = createTemplate(networkType, subscriberId);
- if (template == null) {
+ NetworkTemplate template;
+ try {
+ template = createTemplate(networkType, subscriberId);
+ } catch (IllegalArgumentException e) {
+ if (DBG) Log.e(TAG, "Cannot create template", e);
return null;
}
}
/**
- * Query network usage statistics summaries aggregated across tags.
- *
- * #see querySummaryForUser(int, String, long, long, boolean)
- */
- public Bucket querySummaryForUser(int networkType, String subscriberId, long startTime,
- long endTime) throws SecurityException, RemoteException {
- return querySummaryForUser(networkType, subscriberId, startTime, endTime,
- false /* includeTags */);
- }
-
- /**
* 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
+ * 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 java.lang.System#currentTimeMillis}.
* @param endTime End of period. Defined in terms of "Unix time", see
* {@link java.lang.System#currentTimeMillis}.
- * @param includeTags whether to include network tags. If {@code true}, tags will be returned
- * and history retention may be shorter.
* @return Bucket object or null if permissions are insufficient or error happened during
* statistics collection.
*/
public Bucket querySummaryForUser(int networkType, String subscriberId, long startTime,
- long endTime, boolean includeTags) throws SecurityException, RemoteException {
- NetworkTemplate template = createTemplate(networkType, subscriberId);
- if (template == null) {
+ long endTime) throws SecurityException, RemoteException {
+ NetworkTemplate template;
+ try {
+ template = createTemplate(networkType, subscriberId);
+ } catch (IllegalArgumentException e) {
+ if (DBG) Log.e(TAG, "Cannot create template", e);
return null;
}
NetworkStats stats;
stats = new NetworkStats(mContext, template, startTime, endTime);
- stats.startSummaryEnumeration(includeTags);
+ stats.startSummaryEnumeration();
stats.close();
return stats.getSummaryAggregate();
}
/**
- * Query network usage statistics summaries aggregated across tags.
- *
- * #see querySummary(int, String, long, long, boolean)
- */
- public NetworkStats querySummary(int networkType, String subscriberId, long startTime,
- long endTime) throws SecurityException, RemoteException {
- return querySummary(networkType, subscriberId, startTime, endTime, false /* includeTags */);
- }
-
- /**
* 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 or tag. This means buckets' start and end
- * timestamps are going to be the same as the 'startTime' and 'endTime' parameters. State,
- * uid and tag are going to vary.
+ * 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, and tag is going to be the same.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
* {@link java.lang.System#currentTimeMillis}.
* @param endTime End of period. Defined in terms of "Unix time", see
* {@link java.lang.System#currentTimeMillis}.
- * @param includeTags whether to include network tags. If {@code true}, tags will be returned
- * and history retention may be shorter.
* @return Statistics object or null if permissions are insufficient or error happened during
* statistics collection.
*/
public NetworkStats querySummary(int networkType, String subscriberId, long startTime,
- long endTime, boolean includeTags) throws SecurityException, RemoteException {
- NetworkTemplate template = createTemplate(networkType, subscriberId);
- if (template == null) {
+ long endTime) throws SecurityException, RemoteException {
+ NetworkTemplate template;
+ try {
+ template = createTemplate(networkType, subscriberId);
+ } catch (IllegalArgumentException e) {
+ if (DBG) Log.e(TAG, "Cannot create template", e);
return null;
}
NetworkStats result;
result = new NetworkStats(mContext, template, startTime, endTime);
- result.startSummaryEnumeration(includeTags);
+ result.startSummaryEnumeration();
return result;
}
public NetworkStats queryDetailsForUid(int networkType, String subscriberId,
long startTime, long endTime, int uid) throws SecurityException, RemoteException {
return queryDetailsForUidTag(networkType, subscriberId, startTime, endTime, uid,
- NetworkStats.Bucket.TAG_ALL);
+ NetworkStats.Bucket.TAG_NONE);
}
/**
* @param endTime End of period. Defined in terms of "Unix time", see
* {@link java.lang.System#currentTimeMillis}.
* @param uid UID of app
- * @param tag TAG of interest. Use {@link NetworkStats.Bucket#TAG_ANY} for any tags, use
- * {@link NetworkStats.Bucket#TAG_ALL} to aggregate over tags.
+ * @param tag TAG of interest. Use {@link NetworkStats.Bucket#TAG_NONE} for no tags.
* @return Statistics object or null if permissions are insufficient or error happened during
* statistics collection.
*/
public NetworkStats queryDetailsForUidTag(int networkType, String subscriberId,
- long startTime, long endTime, int uid, int tag) throws SecurityException,
- RemoteException {
- NetworkTemplate template = createTemplate(networkType, subscriberId);
- if (template == null) {
+ long startTime, long endTime, int uid, int tag) {
+ NetworkTemplate template;
+ try {
+ template = createTemplate(networkType, subscriberId);
+ } catch (IllegalArgumentException e) {
+ if (DBG) Log.e(TAG, "Cannot create template", e);
return null;
}
NetworkStats result;
- result = new NetworkStats(mContext, template, startTime, endTime);
- result.startHistoryEnumeration(uid, tag);
+ try {
+ result = new NetworkStats(mContext, template, startTime, endTime);
+ result.startHistoryEnumeration(uid, tag);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error while querying stats for uid=" + uid + " tag=" + tag, e);
+ return null;
+ }
return result;
}
* 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}, uid will vary,
- * tag {@link NetworkStats.Bucket#TAG_ALL} and roaming is going to be
+ * tag {@link NetworkStats.Bucket#TAG_NONE} and roaming is going to be
* {@link NetworkStats.Bucket#ROAMING_ALL}.
* <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't
* interpolate across partial buckets. Since bucket length is in the order of hours, this
*/
public NetworkStats queryDetails(int networkType, String subscriberId, long startTime,
long endTime) throws SecurityException, RemoteException {
- NetworkTemplate template = createTemplate(networkType, subscriberId);
- if (template == null) {
+ NetworkTemplate template;
+ try {
+ template = createTemplate(networkType, subscriberId);
+ } catch (IllegalArgumentException e) {
+ if (DBG) Log.e(TAG, "Cannot create template", e);
return null;
}
+
NetworkStats result;
result = new NetworkStats(mContext, template, startTime, endTime);
result.startUserUidEnumeration();
return result;
}
+ /** @removed */
+ public void registerDataUsageCallback(DataUsagePolicy policy, DataUsageCallback callback,
+ @Nullable Handler handler) {}
+
+ /** @removed */
+ public void registerDataUsageCallback(DataUsagePolicy policy, UsageCallback callback,
+ @Nullable Handler handler) {}
+
+ /** @removed */
+ public void unregisterDataUsageCallback(DataUsageCallback callback) {}
+
/**
- * Registers to receive notifications about data usage on specified networks and uids.
- * The callbacks will continue to be called as long as the process is live or
- * {@link #unregisterDataUsageCallback} is called.
+ * Registers to receive notifications about data usage on specified networks.
*
- * @param policy {@link DataUsagePolicy} describing this request.
- * @param callback The {@link DataUsageCallback} that the system will call when data usage
- * has exceeded the specified threshold.
+ * #see registerUsageCallback(int, String[], long, UsageCallback, Handler)
*/
- public void registerDataUsageCallback(DataUsagePolicy policy, DataUsageCallback callback) {
- registerDataUsageCallback(policy, callback, null /* handler */);
+ public void registerUsageCallback(int networkType, String subscriberId, long thresholdBytes,
+ UsageCallback callback) {
+ registerUsageCallback(networkType, subscriberId, thresholdBytes, null /* handler */);
}
/**
- * Registers to receive notifications about data usage on specified networks and uids.
- * The callbacks will continue to be called as long as the process is live or
- * {@link #unregisterDataUsageCallback} is called.
+ * Registers to receive notifications about data usage on specified networks.
*
- * @param policy {@link DataUsagePolicy} describing this request.
- * @param callback The {@link DataUsageCallback} that the system will call when data usage
+ * <p>The callbacks will continue to be called as long as the process is live or
+ * {@link #unregisterUsageCallback} is called.
+ *
+ * @param networkType Type of network to monitor. Either
+ {@link ConnectivityManager#TYPE_MOBILE} or {@link ConnectivityManager#TYPE_WIFI}.
+ * @param subscriberId If applicable, the subscriber id of the network interface.
+ * @param thresholdBytes Threshold in bytes to be notified on.
+ * @param callback The {@link UsageCallback} that the system will call when data usage
* has exceeded the specified threshold.
* @param handler to dispatch callback events through, otherwise if {@code null} it uses
* the calling thread.
*/
- public void registerDataUsageCallback(DataUsagePolicy policy, DataUsageCallback callback,
- @Nullable Handler handler) {
- checkNotNull(policy, "DataUsagePolicy cannot be null");
- checkNotNull(callback, "DataUsageCallback cannot be null");
+ public void registerUsageCallback(int networkType, String subscriberId, long thresholdBytes,
+ UsageCallback callback, @Nullable Handler handler) {
+ checkNotNull(callback, "UsageCallback cannot be null");
final Looper looper;
if (handler == null) {
looper = handler.getLooper();
}
- if (DBG) Log.d(TAG, "registerDataUsageCallback called with " + policy);
-
- NetworkTemplate[] templates;
- if (policy.subscriberIds == null || policy.subscriberIds.length == 0) {
- templates = new NetworkTemplate[1];
- templates[0] = createTemplate(policy.networkType, null /* subscriberId */);
- } else {
- templates = new NetworkTemplate[policy.subscriberIds.length];
- for (int i = 0; i < policy.subscriberIds.length; i++) {
- templates[i] = createTemplate(policy.networkType, policy.subscriberIds[i]);
- }
+ if (DBG) {
+ Log.d(TAG, "registerUsageCallback called with: {"
+ + " networkType=" + networkType
+ + " subscriberId=" + subscriberId
+ + " thresholdBytes=" + thresholdBytes
+ + " }");
}
+
+ NetworkTemplate template = createTemplate(networkType, subscriberId);
DataUsageRequest request = new DataUsageRequest(DataUsageRequest.REQUEST_ID_UNSET,
- templates, policy.uids, policy.thresholdInBytes);
+ template, thresholdBytes);
try {
- CallbackHandler callbackHandler = new CallbackHandler(looper, callback);
- callback.request = mService.registerDataUsageCallback(
+ CallbackHandler callbackHandler = new CallbackHandler(looper, networkType,
+ subscriberId, callback);
+ callback.request = mService.registerUsageCallback(
mContext.getOpPackageName(), request, new Messenger(callbackHandler),
new Binder());
- if (DBG) Log.d(TAG, "registerDataUsageCallback returned " + callback.request);
+ if (DBG) Log.d(TAG, "registerUsageCallback returned " + callback.request);
if (callback.request == null) {
Log.e(TAG, "Request from callback is null; should not happen");
}
} catch (RemoteException e) {
if (DBG) Log.d(TAG, "Remote exception when registering callback");
+ throw e.rethrowFromSystemServer();
}
}
/**
* Unregisters callbacks on data usage.
*
- * @param callback The {@link DataUsageCallback} used when registering.
+ * @param callback The {@link UsageCallback} used when registering.
*/
- public void unregisterDataUsageCallback(DataUsageCallback callback) {
+ public void unregisterUsageCallback(UsageCallback callback) {
if (callback == null || callback.request == null
|| callback.request.requestId == DataUsageRequest.REQUEST_ID_UNSET) {
- throw new IllegalArgumentException("Invalid DataUsageCallback");
+ throw new IllegalArgumentException("Invalid UsageCallback");
}
try {
- mService.unregisterDataUsageRequest(callback.request);
+ mService.unregisterUsageRequest(callback.request);
} catch (RemoteException e) {
if (DBG) Log.d(TAG, "Remote exception when unregistering callback");
+ throw e.rethrowFromSystemServer();
}
}
+ /** @removed */
+ public static abstract class DataUsageCallback {
+ /** @removed */
+ @Deprecated
+ public void onLimitReached() {}
+ }
+
/**
- * Base class for data usage callbacks. Should be extended by applications wanting
- * notifications.
+ * Base class for usage callbacks. Should be extended by applications wanting notifications.
*/
- public static class DataUsageCallback {
+ public static abstract class UsageCallback {
+
/**
- * Called when data usage has reached the given policy threshold.
+ * Called when data usage has reached the given threshold.
*/
- public void onLimitReached() {}
+ public abstract void onThresholdReached(int networkType, String subscriberId);
+ /**
+ * @hide used for internal bookkeeping
+ */
private DataUsageRequest request;
}
template = NetworkTemplate.buildTemplateWifiWildcard();
} break;
default: {
- Log.w(TAG, "Cannot create template for network type " + networkType
- + ", subscriberId '" + NetworkIdentity.scrubSubscriberId(subscriberId) +
- "'.");
+ throw new IllegalArgumentException("Cannot create template for network type "
+ + networkType + ", subscriberId '"
+ + NetworkIdentity.scrubSubscriberId(subscriberId) + "'.");
}
}
return template;
}
private static class CallbackHandler extends Handler {
- private DataUsageCallback mCallback;
- CallbackHandler(Looper looper, DataUsageCallback callback) {
+ private final int mNetworkType;
+ private final String mSubscriberId;
+ private UsageCallback mCallback;
+
+ CallbackHandler(Looper looper, int networkType, String subscriberId,
+ UsageCallback callback) {
super(looper);
+ mNetworkType = networkType;
+ mSubscriberId = subscriberId;
mCallback = callback;
}
switch (message.what) {
case CALLBACK_LIMIT_REACHED: {
if (mCallback != null) {
- mCallback.onLimitReached();
+ mCallback.onThresholdReached(mNetworkType, mSubscriberId);
} else {
Log.e(TAG, "limit reached with released callback for " + request);
}
import android.os.Parcel;
import android.os.Parcelable;
-import java.util.Arrays;
import java.util.Objects;
/**
* {@link android.app.usage.NetworkStatsManager#registerDataUsageCallback}.
* If no {@code uid}s are set, callbacks are restricted to device-owners,
* carrier-privileged apps, or system apps.
+ *
+ * @hide
*/
public final class DataUsageRequest implements Parcelable {
- /**
- * @hide
- */
public static final String PARCELABLE_KEY = "DataUsageRequest";
-
- /**
- * @hide
- */
public static final int REQUEST_ID_UNSET = 0;
/**
* Identifies the request. {@link DataUsageRequest}s should only be constructed by
* the Framework and it is used internally to identify the request.
- * @hide
*/
public final int requestId;
/**
- * Set of {@link NetworkTemplate}s describing the networks to monitor.
- * @hide
+ * {@link NetworkTemplate} describing the network to monitor.
*/
- public final NetworkTemplate[] templates;
-
- /**
- * Set of UIDs of which to monitor data usage.
- *
- * <p>If not {@code null}, the caller will be notified when any of the uids exceed
- * the given threshold. If {@code null} all uids for which the calling process has access
- * to stats will be monitored.
- * @hide
- */
- public final int[] uids;
+ public final NetworkTemplate template;
/**
* Threshold in bytes to be notified on.
- * @hide
*/
public final long thresholdInBytes;
- /**
- * @hide
- */
- public DataUsageRequest(int requestId, NetworkTemplate[] templates, int[] uids,
- long thresholdInBytes) {
+ public DataUsageRequest(int requestId, NetworkTemplate template, long thresholdInBytes) {
this.requestId = requestId;
- this.templates = templates;
- this.uids = uids;
+ this.template = template;
this.thresholdInBytes = thresholdInBytes;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(requestId);
- dest.writeTypedArray(templates, flags);
- dest.writeIntArray(uids);
+ dest.writeParcelable(template, flags);
dest.writeLong(thresholdInBytes);
}
@Override
public DataUsageRequest createFromParcel(Parcel in) {
int requestId = in.readInt();
- NetworkTemplate[] templates = in.createTypedArray(NetworkTemplate.CREATOR);
- int[] uids = in.createIntArray();
+ NetworkTemplate template = in.readParcelable(null);
long thresholdInBytes = in.readLong();
- DataUsageRequest result = new DataUsageRequest(requestId,
- templates, uids, thresholdInBytes);
+ DataUsageRequest result = new DataUsageRequest(requestId, template,
+ thresholdInBytes);
return result;
}
@Override
public String toString() {
return "DataUsageRequest [ requestId=" + requestId
- + ", networkTemplates=" + Arrays.toString(templates)
- + ", uids=" + Arrays.toString(uids)
+ + ", networkTemplate=" + template
+ ", thresholdInBytes=" + thresholdInBytes + " ]";
}
if (obj instanceof DataUsageRequest == false) return false;
DataUsageRequest that = (DataUsageRequest) obj;
return that.requestId == this.requestId
- && Arrays.deepEquals(that.templates, this.templates)
- && Arrays.equals(that.uids, this.uids)
+ && Objects.equals(that.template, this.template)
&& that.thresholdInBytes == this.thresholdInBytes;
}
@Override
public int hashCode() {
- // Start with a non-zero constant.
- int result = 17;
-
- // Include a hash for each field.
- result = 31 * result + requestId;
- result = 31 * result + Arrays.deepHashCode(templates);
- result = 31 * result + Arrays.hashCode(uids);
- result = 31 * result + (int) (thresholdInBytes ^ (thresholdInBytes >>> 32));
-
- return result;
+ return Objects.hash(requestId, template, thresholdInBytes);
}
}
void advisePersistThreshold(long thresholdBytes);
/** Registers a callback on data usage. */
- DataUsageRequest registerDataUsageCallback(String callingPackage,
+ DataUsageRequest registerUsageCallback(String callingPackage,
in DataUsageRequest request, in Messenger messenger, in IBinder binder);
/** Unregisters a callback on data usage. */
- void unregisterDataUsageRequest(in DataUsageRequest request);
+ void unregisterUsageRequest(in DataUsageRequest request);
}
*/
public DataUsageRequest register(DataUsageRequest inputRequest, Messenger messenger,
IBinder binder, int callingUid, @NetworkStatsAccess.Level int accessLevel) {
- checkVisibilityUids(callingUid, accessLevel, inputRequest.uids);
-
DataUsageRequest request = buildRequest(inputRequest);
RequestInfo requestInfo = buildRequestInfo(request, messenger, binder, callingUid,
accessLevel);
+ ". Overriding to a safer default of " + thresholdInBytes + " bytes");
}
return new DataUsageRequest(mNextDataUsageRequestId.incrementAndGet(),
- request.templates, request.uids, thresholdInBytes);
+ request.template, thresholdInBytes);
}
private RequestInfo buildRequestInfo(DataUsageRequest request,
Messenger messenger, IBinder binder, int callingUid,
@NetworkStatsAccess.Level int accessLevel) {
- if (accessLevel <= NetworkStatsAccess.Level.USER
- || request.uids != null && request.uids.length > 0) {
+ if (accessLevel <= NetworkStatsAccess.Level.USER) {
return new UserUsageRequestInfo(this, request, messenger, binder, callingUid,
accessLevel);
} else {
}
}
- private void checkVisibilityUids(int callingUid, @NetworkStatsAccess.Level int accessLevel,
- int[] uids) {
- if (uids == null) {
- return;
- }
- for (int i = 0; i < uids.length; i++) {
- if (!NetworkStatsAccess.isAccessibleToUser(uids[i], callingUid, accessLevel)) {
- throw new SecurityException("Caller " + callingUid + " cannot monitor network stats"
- + " for uid " + uids[i] + " with accessLevel " + accessLevel);
- }
- }
- }
-
/**
* Tracks information relevant to a data usage observer.
* It will notice when the calling process dies so we can self-expire.
@Override
protected boolean checkStats() {
- for (int i = 0; i < mRequest.templates.length; i++) {
- long bytesSoFar = getTotalBytesForNetwork(mRequest.templates[i]);
- if (LOGV) {
- Slog.v(TAG, bytesSoFar + " bytes so far since notification for "
- + mRequest.templates[i]);
- }
- if (bytesSoFar > mRequest.thresholdInBytes) {
- return true;
- }
+ long bytesSoFar = getTotalBytesForNetwork(mRequest.template);
+ if (LOGV) {
+ Slog.v(TAG, bytesSoFar + " bytes so far since notification for "
+ + mRequest.template);
+ }
+ if (bytesSoFar > mRequest.thresholdInBytes) {
+ return true;
}
return false;
}
@Override
protected boolean checkStats() {
- int[] uidsToMonitor = getUidsToMonitor();
-
- for (int i = 0; i < mRequest.templates.length; i++) {
- for (int j = 0; j < uidsToMonitor.length; j++) {
- long bytesSoFar = getTotalBytesForNetworkUid(mRequest.templates[i],
- uidsToMonitor[j]);
-
- if (LOGV) {
- Slog.v(TAG, bytesSoFar + " bytes so far since notification for "
- + mRequest.templates[i] + " for uid=" + uidsToMonitor[j]);
- }
- if (bytesSoFar > mRequest.thresholdInBytes) {
- return true;
- }
+ int[] uidsToMonitor = mCollection.getRelevantUids(mAccessLevel, mCallingUid);
+
+ for (int i = 0; i < uidsToMonitor.length; i++) {
+ long bytesSoFar = getTotalBytesForNetworkUid(mRequest.template, uidsToMonitor[i]);
+
+ if (LOGV) {
+ Slog.v(TAG, bytesSoFar + " bytes so far since notification for "
+ + mRequest.template + " for uid=" + uidsToMonitor[i]);
+ }
+ if (bytesSoFar > mRequest.thresholdInBytes) {
+ return true;
}
}
return false;
return 0;
}
}
-
- private int[] getUidsToMonitor() {
- if (mRequest.uids == null || mRequest.uids.length == 0) {
- return mCollection.getRelevantUids(mAccessLevel, mCallingUid);
- }
- // Pick only uids from the request that are currently accessible to the user
- IntArray accessibleUids = new IntArray(mRequest.uids.length);
- for (int i = 0; i < mRequest.uids.length; i++) {
- int uid = mRequest.uids[i];
- if (NetworkStatsAccess.isAccessibleToUser(uid, mCallingUid, mAccessLevel)) {
- accessibleUids.add(uid);
- }
- }
- return accessibleUids.toArray();
- }
}
private static class StatsContext {
if (tag == TAG_NONE) {
return getUidComplete().getHistory(template, uid, set, tag, fields, start, end,
accessLevel);
- } else {
+ } else if (uid == Binder.getCallingUid()) {
return getUidTagComplete().getHistory(template, uid, set, tag, fields,
start, end, accessLevel);
+ } else {
+ throw new SecurityException("Calling package " + mCallingPackage
+ + " cannot access tag information from a different uid");
}
}
}
@Override
- public DataUsageRequest registerDataUsageCallback(String callingPackage,
+ public DataUsageRequest registerUsageCallback(String callingPackage,
DataUsageRequest request, Messenger messenger, IBinder binder) {
checkNotNull(callingPackage, "calling package is null");
checkNotNull(request, "DataUsageRequest is null");
- checkNotNull(request.templates, "NetworkTemplate is null");
- checkArgument(request.templates.length > 0);
+ checkNotNull(request.template, "NetworkTemplate is null");
checkNotNull(messenger, "messenger is null");
checkNotNull(binder, "binder is null");
}
@Override
- public void unregisterDataUsageRequest(DataUsageRequest request) {
+ public void unregisterUsageRequest(DataUsageRequest request) {
checkNotNull(request, "DataUsageRequest is null");
int callingUid = Binder.getCallingUid();
import com.android.server.net.NetworkStatsServiceTest.LatchedHandler;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Objects;
import java.util.List;
import junit.framework.TestCase;
private static final long BASE_BYTES = 7 * MB_IN_BYTES;
private static final int INVALID_TYPE = -1;
- private static final int[] NO_UIDS = null;
private static final VpnInfo[] VPN_INFO = new VpnInfo[0];
private long mElapsedRealtime;
public void testRegister_thresholdTooLow_setsDefaultThreshold() throws Exception {
long thresholdTooLowBytes = 1L;
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateWifi };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, thresholdTooLowBytes);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateWifi, thresholdTooLowBytes);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateWifi, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
}
public void testRegister_highThreshold_accepted() throws Exception {
long highThresholdBytes = 2 * THRESHOLD_BYTES;
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateWifi };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, highThresholdBytes);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateWifi, highThresholdBytes);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateWifi, request.template));
assertEquals(highThresholdBytes, request.thresholdInBytes);
}
public void testRegister_twoRequests_twoIds() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateWifi };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateWifi, THRESHOLD_BYTES);
DataUsageRequest request1 = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
assertTrue(request1.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request1.templates));
- assertNull(request1.uids);
+ assertTrue(Objects.equals(sTemplateWifi, request1.template));
assertEquals(THRESHOLD_BYTES, request1.thresholdInBytes);
DataUsageRequest request2 = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
assertTrue(request2.requestId > request1.requestId);
- assertTrue(Arrays.deepEquals(templates, request2.templates));
- assertNull(request2.uids);
+ assertTrue(Objects.equals(sTemplateWifi, request2.template));
assertEquals(THRESHOLD_BYTES, request2.thresholdInBytes);
}
- public void testRegister_defaultAccess_otherUids_securityException() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
- int[] uids = new int[] { UID_RED, UID_BLUE, UID_GREEN };
- DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, uids, THRESHOLD_BYTES);
-
- try {
- mStatsObservers.register(inputRequest, mMessenger, mockBinder, UID_RED,
- NetworkStatsAccess.Level.DEFAULT);
- fail("Should have denied access");
- } catch (SecurityException expected) {}
- }
-
- public void testRegister_userAccess_otherUidsSameUser()
- throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
- int[] uids = new int[] { UID_RED, UID_BLUE, UID_GREEN };
- DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, uids, THRESHOLD_BYTES);
-
- DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
- UID_RED, NetworkStatsAccess.Level.USER);
- assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertTrue(Arrays.equals(uids, request.uids));
- assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
- }
-
- public void testRegister_defaultAccess_sameUid() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
- int[] uids = new int[] { UID_RED };
- DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, uids, THRESHOLD_BYTES);
-
- DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
- UID_RED, NetworkStatsAccess.Level.DEFAULT);
- assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertTrue(Arrays.equals(uids, request.uids));
- assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
- }
-
public void testUnregister_unknownRequest_noop() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateWifi };
DataUsageRequest unknownRequest = new DataUsageRequest(
- 123456 /* id */, templates, NO_UIDS, THRESHOLD_BYTES);
+ 123456 /* id */, sTemplateWifi, THRESHOLD_BYTES);
mStatsObservers.unregister(unknownRequest, UID_RED);
}
public void testUnregister_knownRequest_releasesCaller() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
Mockito.verify(mockBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
}
public void testUnregister_knownRequest_invalidUid_doesNotUnregister() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
UID_RED, NetworkStatsAccess.Level.DEVICE);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
Mockito.verify(mockBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
}
public void testUpdateStats_initialSample_doesNotNotify() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
NetworkIdentitySet identSet = new NetworkIdentitySet();
}
public void testUpdateStats_belowThreshold_doesNotNotify() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
NetworkIdentitySet identSet = new NetworkIdentitySet();
assertEquals(INVALID_TYPE, mHandler.mLastMessageType);
}
- public void testUpdateStats_aboveThresholdNetwork_notifies() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
+ public void testUpdateStats_deviceAccess_notifies() throws Exception {
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
NetworkIdentitySet identSet = new NetworkIdentitySet();
assertEquals(NetworkStatsManager.CALLBACK_LIMIT_REACHED, mHandler.mLastMessageType);
}
- public void testUpdateStats_aboveThresholdMultipleNetwork_notifies() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1, sTemplateImsi2 };
- DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
-
- DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
- UID_RED, NetworkStatsAccess.Level.DEVICESUMMARY);
- assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
- assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
-
- NetworkIdentitySet identSet1 = new NetworkIdentitySet();
- identSet1.add(new NetworkIdentity(
- TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN,
- IMSI_1, null /* networkId */, false /* roaming */, true /* metered */));
- mActiveIfaces.put(TEST_IFACE, identSet1);
-
- NetworkIdentitySet identSet2 = new NetworkIdentitySet();
- identSet2.add(new NetworkIdentity(
- TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN,
- IMSI_2, null /* networkId */, false /* roaming */, true /* metered */));
- mActiveIfaces.put(TEST_IFACE2, identSet2);
-
- // Baseline
- NetworkStats xtSnapshot = new NetworkStats(TEST_START, 1 /* initialSize */)
- .addIfaceValues(TEST_IFACE, BASE_BYTES, 8L, BASE_BYTES, 16L)
- .addIfaceValues(TEST_IFACE2, BASE_BYTES + 1234L, 18L, BASE_BYTES, 12L);
- NetworkStats uidSnapshot = null;
- mStatsObservers.updateStats(
- xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
- VPN_INFO, TEST_START);
-
- // Delta - traffic on IMSI2
- xtSnapshot = new NetworkStats(TEST_START + MINUTE_IN_MILLIS, 1 /* initialSize */)
- .addIfaceValues(TEST_IFACE, BASE_BYTES, 8L, BASE_BYTES, 16L)
- .addIfaceValues(TEST_IFACE2, BASE_BYTES + THRESHOLD_BYTES, 22L,
- BASE_BYTES + THRESHOLD_BYTES, 24L);
- mStatsObservers.updateStats(
- xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
- VPN_INFO, TEST_START);
- waitForObserverToIdle();
-
- assertTrue(mCv.block(WAIT_TIMEOUT));
- assertEquals(NetworkStatsManager.CALLBACK_LIMIT_REACHED, mHandler.mLastMessageType);
- }
-
- public void testUpdateStats_aboveThresholdUid_notifies() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
- int[] uids = new int[] { UID_RED, UID_BLUE, UID_GREEN };
- DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, uids, THRESHOLD_BYTES);
-
- DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
- Process.SYSTEM_UID, NetworkStatsAccess.Level.DEVICE);
- assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertTrue(Arrays.equals(uids,request.uids));
- assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
-
- NetworkIdentitySet identSet = new NetworkIdentitySet();
- identSet.add(new NetworkIdentity(
- TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN,
- IMSI_1, null /* networkId */, false /* roaming */, true /* metered */));
- mActiveUidIfaces.put(TEST_IFACE, identSet);
-
- // Baseline
- NetworkStats xtSnapshot = null;
- NetworkStats uidSnapshot = new NetworkStats(TEST_START, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
- BASE_BYTES, 2L, BASE_BYTES, 2L, 0L);
- mStatsObservers.updateStats(
- xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
- VPN_INFO, TEST_START);
-
- // Delta
- uidSnapshot = new NetworkStats(TEST_START+ 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
- BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
- mStatsObservers.updateStats(
- xtSnapshot, uidSnapshot, mActiveIfaces, mActiveUidIfaces,
- VPN_INFO, TEST_START);
- waitForObserverToIdle();
-
- assertTrue(mCv.block(WAIT_TIMEOUT));
- assertEquals(NetworkStatsManager.CALLBACK_LIMIT_REACHED, mHandler.mLastMessageType);
- }
-
- public void testUpdateStats_defaultAccess_noUid_notifiesSameUid() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
+ public void testUpdateStats_defaultAccess_notifiesSameUid() throws Exception {
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
UID_RED, NetworkStatsAccess.Level.DEFAULT);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
NetworkIdentitySet identSet = new NetworkIdentitySet();
VPN_INFO, TEST_START);
// Delta
- uidSnapshot = new NetworkStats(TEST_START+ 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
+ uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
mStatsObservers.updateStats(
assertEquals(NetworkStatsManager.CALLBACK_LIMIT_REACHED, mHandler.mLastMessageType);
}
- public void testUpdateStats_defaultAccess_noUid_usageOtherUid_doesNotNotify() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
+ public void testUpdateStats_defaultAccess_usageOtherUid_doesNotNotify() throws Exception {
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
UID_BLUE, NetworkStatsAccess.Level.DEFAULT);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
NetworkIdentitySet identSet = new NetworkIdentitySet();
VPN_INFO, TEST_START);
// Delta
- uidSnapshot = new NetworkStats(TEST_START+ 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
+ uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
mStatsObservers.updateStats(
}
public void testUpdateStats_userAccess_usageSameUser_notifies() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
UID_BLUE, NetworkStatsAccess.Level.USER);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
NetworkIdentitySet identSet = new NetworkIdentitySet();
VPN_INFO, TEST_START);
// Delta
- uidSnapshot = new NetworkStats(TEST_START+ 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
+ uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
.addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
mStatsObservers.updateStats(
}
public void testUpdateStats_userAccess_usageAnotherUser_doesNotNotify() throws Exception {
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1 };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, NO_UIDS, THRESHOLD_BYTES);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateImsi1, THRESHOLD_BYTES);
DataUsageRequest request = mStatsObservers.register(inputRequest, mMessenger, mockBinder,
UID_RED, NetworkStatsAccess.Level.USER);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateImsi1, request.template));
assertEquals(THRESHOLD_BYTES, request.thresholdInBytes);
NetworkIdentitySet identSet = new NetworkIdentitySet();
VPN_INFO, TEST_START);
// Delta
- uidSnapshot = new NetworkStats(TEST_START+ 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
+ uidSnapshot = new NetworkStats(TEST_START + 2 * MINUTE_IN_MILLIS, 2 /* initialSize */)
.addValues(TEST_IFACE, UID_ANOTHER_USER, SET_DEFAULT, TAG_NONE, ROAMING_NO,
BASE_BYTES + THRESHOLD_BYTES, 2L, BASE_BYTES + THRESHOLD_BYTES, 2L, 0L);
mStatsObservers.updateStats(
import java.io.File;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Objects;
import java.util.List;
/**
}
- public void testRegisterDataUsageCallback_network() throws Exception {
+ public void testRegisterUsageCallback() throws Exception {
// pretend that wifi network comes online; service should ask about full
// network state, and poll any existing interfaces before updating.
expectCurrentTime();
String callingPackage = "the.calling.package";
long thresholdInBytes = 1L; // very small; should be overriden by framework
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateWifi };
DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, null /* uids */, thresholdInBytes);
+ DataUsageRequest.REQUEST_ID_UNSET, sTemplateWifi, thresholdInBytes);
// Create a messenger that waits for callback activity
ConditionVariable cv = new ConditionVariable(false);
// Register and verify request and that binder was called
DataUsageRequest request =
- mService.registerDataUsageCallback(callingPackage, inputRequest,
+ mService.registerUsageCallback(callingPackage, inputRequest,
messenger, mockBinder);
assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertNull(request.uids);
+ assertTrue(Objects.equals(sTemplateWifi, request.template));
long minThresholdInBytes = 2 * 1024 * 1024; // 2 MB
assertEquals(minThresholdInBytes, request.thresholdInBytes);
EasyMock.replay(mockBinder);
// Unregister request
- mService.unregisterDataUsageRequest(request);
+ mService.unregisterUsageRequest(request);
// Wait for the caller to ack receipt of CALLBACK_RELEASED
assertTrue(cv.block(WAIT_TIMEOUT));
EasyMock.verify(mockBinder);
}
- public void testRegisterDataUsageCallback_uids() throws Exception {
- // pretend that network comes online
- expectCurrentTime();
- expectDefaultSettings();
- expectNetworkState(buildMobile3gState(IMSI_1, true /* isRoaming */));
- expectNetworkStatsSummary(buildEmptyStats());
- expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
- expectBandwidthControlCheck();
-
- replay();
- mService.forceUpdateIfaces();
- verifyAndReset();
-
- String callingPackage = "the.calling.package";
- long thresholdInBytes = 10 * 1024 * 1024; // 10 MB
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1, sTemplateImsi2 };
- int[] uids = new int[] { UID_RED };
- DataUsageRequest inputRequest = new DataUsageRequest(
- DataUsageRequest.REQUEST_ID_UNSET, templates, uids, thresholdInBytes);
-
- // Create a messenger that waits for callback activity
- ConditionVariable cv = new ConditionVariable(false);
- cv.close();
- LatchedHandler latchedHandler = new LatchedHandler(Looper.getMainLooper(), cv);
- Messenger messenger = new Messenger(latchedHandler);
-
- // Allow binder to connect
- IBinder mockBinder = createMock(IBinder.class);
- mockBinder.linkToDeath((IBinder.DeathRecipient) anyObject(), anyInt());
- EasyMock.replay(mockBinder);
-
- // Force poll
- expectCurrentTime();
- expectDefaultSettings();
- expectNetworkStatsSummary(buildEmptyStats());
- expectNetworkStatsUidDetail(buildEmptyStats());
- expectNetworkStatsPoll();
- replay();
-
- // Register and verify request and that binder was called
- DataUsageRequest request =
- mService.registerDataUsageCallback(callingPackage, inputRequest,
- messenger, mockBinder);
- assertTrue(request.requestId > 0);
- assertTrue(Arrays.deepEquals(templates, request.templates));
- assertTrue(Arrays.equals(uids, request.uids));
- assertEquals(thresholdInBytes, request.thresholdInBytes);
-
- // Wait for service to handle internal MSG_REGISTER_DATA_USAGE_LISTENER
- mHandler.sendMessage(mHandler.obtainMessage(-1));
- mHandlerThread.waitForIdle(WAIT_TIMEOUT);
-
- verifyAndReset();
-
- // Make sure that the caller binder gets connected
- EasyMock.verify(mockBinder);
- EasyMock.reset(mockBinder);
-
- // modify some number on mobile interface, and trigger poll event
- // not enough traffic to call data usage callback
- incrementCurrentTime(HOUR_IN_MILLIS);
- expectCurrentTime();
- expectDefaultSettings();
- expectNetworkStatsSummary(buildEmptyStats());
- expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO, 128L, 2L,
- 128L, 2L, 0L)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_NO, 64L, 1L, 64L,
- 1L, 0L));
- expectNetworkStatsPoll();
-
- replay();
- forcePollAndWaitForIdle();
-
- // verify service recorded history
- assertUidTotal(sTemplateImsi1, UID_RED, 128L, 2L, 128L, 2L, 0);
-
- // verify entire history present
- NetworkStats stats = mSession.getSummaryForAllUid(
- sTemplateImsi1, Long.MIN_VALUE, Long.MAX_VALUE, true);
- assertEquals(2, stats.size());
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_YES, 128L, 2L,
- 128L, 2L, 0);
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_YES, 64L, 1L, 64L,
- 1L, 0);
-
- verifyAndReset();
-
- // make sure callback has not being called
- assertEquals(INVALID_TYPE, latchedHandler.mLastMessageType);
-
- // and bump forward again, with counters going higher. this is
- // important, since it will trigger the data usage callback
- incrementCurrentTime(DAY_IN_MILLIS);
- expectCurrentTime();
- expectDefaultSettings();
- expectNetworkStatsSummary(buildEmptyStats());
- expectNetworkStatsUidDetail(new NetworkStats(getElapsedRealtime(), 1)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_NO,
- 128000000L, 2L, 128000000L, 2L, 0L)
- .addValues(TEST_IFACE, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_NO,
- 64000000L, 1L, 64000000L, 1L, 0L));
- expectNetworkStatsPoll();
-
- replay();
- forcePollAndWaitForIdle();
-
- // verify service recorded history
- assertUidTotal(sTemplateImsi1, UID_RED, 128000000L, 2L, 128000000L, 2L, 0);
-
- // verify entire history present
- stats = mSession.getSummaryForAllUid(
- sTemplateImsi1, Long.MIN_VALUE, Long.MAX_VALUE, true);
- assertEquals(2, stats.size());
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, TAG_NONE, ROAMING_YES,
- 128000000L, 2L, 128000000L, 2L, 0);
- assertValues(stats, IFACE_ALL, UID_RED, SET_DEFAULT, 0xF00D, ROAMING_YES,
- 64000000L, 1L, 64000000L, 1L, 0);
-
- verifyAndReset();
-
- // Wait for the caller to ack receipt of CALLBACK_LIMIT_REACHED
- assertTrue(cv.block(WAIT_TIMEOUT));
- assertEquals(NetworkStatsManager.CALLBACK_LIMIT_REACHED, latchedHandler.mLastMessageType);
- cv.close();
-
- // Allow binder to disconnect
- expect(mockBinder.unlinkToDeath((IBinder.DeathRecipient) anyObject(), anyInt()))
- .andReturn(true);
- EasyMock.replay(mockBinder);
-
- // Unregister request
- mService.unregisterDataUsageRequest(request);
-
- // Wait for the caller to ack receipt of CALLBACK_RELEASED
- assertTrue(cv.block(WAIT_TIMEOUT));
- assertEquals(NetworkStatsManager.CALLBACK_RELEASED, latchedHandler.mLastMessageType);
-
- // Make sure that the caller binder gets disconnected
- EasyMock.verify(mockBinder);
- }
-
- public void testUnregisterDataUsageCallback_unknown_noop() throws Exception {
+ public void testUnregisterUsageCallback_unknown_noop() throws Exception {
String callingPackage = "the.calling.package";
long thresholdInBytes = 10 * 1024 * 1024; // 10 MB
- NetworkTemplate[] templates = new NetworkTemplate[] { sTemplateImsi1, sTemplateImsi2 };
DataUsageRequest unknownRequest = new DataUsageRequest(
- 2, templates, null /* uids */, thresholdInBytes);
+ 2 /* requestId */, sTemplateImsi1, thresholdInBytes);
- mService.unregisterDataUsageRequest(unknownRequest);
+ mService.unregisterUsageRequest(unknownRequest);
}
private static File getBaseDir(File statsDir) {