Cleaning up NetworkStatsManager.

- Throwing SecurityExceptionand and IllegalArgumentException instead of null for new APIs
- removing @removed APIs

Bug:27530098,27379882
Change-Id: Ifbe65bfc5051aa33aff2baa22cfa8e67b0f7c358
This commit is contained in:
Antonio Cansado
2016-05-25 09:57:21 -07:00
parent fe78ecbb2c
commit bfd4e42c8d
2 changed files with 4 additions and 37 deletions

View File

@@ -240,18 +240,13 @@ public class NetworkStatsManager {
* {@link java.lang.System#currentTimeMillis}.
* @param uid UID of app
* @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.
* @return Statistics object or null if an error happened during statistics collection.
* @throws SecurityException if permissions are insufficient to read network statistics.
*/
public NetworkStats queryDetailsForUidTag(int networkType, String subscriberId,
long startTime, long endTime, int uid, int tag) {
long startTime, long endTime, int uid, int tag) throws SecurityException {
NetworkTemplate template;
try {
template = createTemplate(networkType, subscriberId);
} catch (IllegalArgumentException e) {
if (DBG) Log.e(TAG, "Cannot create template", e);
return null;
}
NetworkStats result;
try {
@@ -303,17 +298,6 @@ public class NetworkStatsManager {
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.
*
@@ -396,13 +380,6 @@ public class NetworkStatsManager {
}
}
/** @removed */
public static abstract class DataUsageCallback {
/** @removed */
@Deprecated
public void onLimitReached() {}
}
/**
* Base class for usage callbacks. Should be extended by applications wanting notifications.
*/

View File

@@ -190,11 +190,9 @@ class NetworkStatsObservers {
private void handleUpdateStats(StatsContext statsContext) {
if (mDataUsageRequests.size() == 0) {
if (LOGV) Slog.v(TAG, "No registered listeners of data usage");
return;
}
if (LOGV) Slog.v(TAG, "Checking if any registered observer needs to be notified");
for (int i = 0; i < mDataUsageRequests.size(); i++) {
RequestInfo requestInfo = mDataUsageRequests.valueAt(i);
requestInfo.updateStats(statsContext);
@@ -371,9 +369,6 @@ class NetworkStatsObservers {
NetworkStats stats = mCollection.getSummary(template,
Long.MIN_VALUE /* start */, Long.MAX_VALUE /* end */,
mAccessLevel, mCallingUid);
if (LOGV) {
Slog.v(TAG, "Netstats for " + template + ": " + stats);
}
return stats.getTotalBytes();
}
}
@@ -391,11 +386,6 @@ class NetworkStatsObservers {
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;
}