diff options
| author | 2015-08-17 14:53:53 +0000 | |
|---|---|---|
| committer | 2015-08-17 14:53:53 +0000 | |
| commit | aed1c9fbc5c4f77bfc8c44fb7bd87bbdb6dc0174 (patch) | |
| tree | a7cdf9c3ab1da339bfe6883e9fbdd4ba61966db1 | |
| parent | ea49b2f6e822924c7e5ebcaf1b7bac4a2e54fd6b (diff) | |
| parent | 5d467ac54ab0390d6b911628d56294bb4277d2f1 (diff) | |
am 5d467ac5: Merge "Remove uids with empty history from NetworkStats uid enumeration" into mnc-dev
* commit '5d467ac54ab0390d6b911628d56294bb4277d2f1':
Remove uids with empty history from NetworkStats uid enumeration
| -rw-r--r-- | core/java/android/app/usage/NetworkStats.java | 26 |
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 9d5eabbc0732..ef08eb9e8987 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; |