summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorZoltan Szatmary-Ban <szatmz@google.com>2015-08-13 16:53:10 +0100
committerZoltan Szatmary-Ban <szatmz@google.com>2015-08-14 16:21:52 +0100
commit887cffea244c88ec06d9dbec1792f05eea87a7c6 (patch)
treee58b32d00714a078dd19f041eb7eece07b6fa8e7 /core
parentcfcf6af915bee878bdaea04f48592bbbe506ad26 (diff)
downloadframeworks_base-887cffea244c88ec06d9dbec1792f05eea87a7c6.zip
frameworks_base-887cffea244c88ec06d9dbec1792f05eea87a7c6.tar.gz
frameworks_base-887cffea244c88ec06d9dbec1792f05eea87a7c6.tar.bz2
Remove uids with empty history from NetworkStats uid enumeration
Bug: 23018174 Change-Id: I1a482280599e0f5da18a208e727653d4bd4107ec
Diffstat (limited to 'core')
-rw-r--r--core/java/android/app/usage/NetworkStats.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/core/java/android/app/usage/NetworkStats.java b/core/java/android/app/usage/NetworkStats.java
index 9d5eabb..ef08eb9 100644
--- a/core/java/android/app/usage/NetworkStats.java
+++ b/core/java/android/app/usage/NetworkStats.java
@@ -24,6 +24,7 @@ import android.net.NetworkTemplate;
import android.net.TrafficStats;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.util.IntArray;
import android.util.Log;
import dalvik.system.CloseGuard;
@@ -353,7 +354,25 @@ public final class NetworkStats implements AutoCloseable {
* @throws RemoteException
*/
void startUserUidEnumeration() throws RemoteException {
- setUidEnumeration(mSession.getRelevantUids());
+ // TODO: getRelevantUids should be sensitive to time interval. When that's done,
+ // the filtering logic below can be removed.
+ int[] uids = mSession.getRelevantUids();
+ // Filtering of uids with empty history.
+ IntArray filteredUids = new IntArray(uids.length);
+ for (int uid : uids) {
+ try {
+ NetworkStatsHistory history = mSession.getHistoryIntervalForUid(mTemplate, uid,
+ android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE,
+ NetworkStatsHistory.FIELD_ALL, mStartTimeStamp, mEndTimeStamp);
+ if (history != null && history.size() > 0) {
+ filteredUids.add(uid);
+ }
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error while getting history of uid " + uid, e);
+ }
+ }
+ mUids = filteredUids.toArray();
+ mUidOrUidIndex = -1;
stepHistory();
}
@@ -468,11 +487,6 @@ public final class NetworkStats implements AutoCloseable {
mUidOrUidIndex = uid;
}
- private void setUidEnumeration(int[] uids) {
- mUids = uids;
- mUidOrUidIndex = -1;
- }
-
private void stepUid() {
if (mUids != null) {
++mUidOrUidIndex;