diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-01-10 17:24:44 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2012-01-10 17:24:44 -0800 |
commit | 5a7bcf31a44d9875ca5fc010dc213aa2bd5b1168 (patch) | |
tree | b0dbf2bd072f3c50d1030b65eea8e50384614229 /services | |
parent | b8f90a0e6eae582778bbe10b6347acbf5fc69bfb (diff) | |
download | frameworks_base-5a7bcf31a44d9875ca5fc010dc213aa2bd5b1168.zip frameworks_base-5a7bcf31a44d9875ca5fc010dc213aa2bd5b1168.tar.gz frameworks_base-5a7bcf31a44d9875ca5fc010dc213aa2bd5b1168.tar.bz2 |
Move non-monotonic reporting to interface.
Report non-monotonic NetworkStats through an observer interface
instead of throwing, since those events are still recoverable.
Change-Id: Ic0749f4634b0ac05dbe90e95ca490957ec8b2f23
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/net/NetworkStatsService.java | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index 6a82679..eeb7fec 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -71,7 +71,7 @@ import android.net.NetworkIdentity; import android.net.NetworkInfo; import android.net.NetworkState; import android.net.NetworkStats; -import android.net.NetworkStats.NonMonotonicException; +import android.net.NetworkStats.NonMonotonicObserver; import android.net.NetworkStatsHistory; import android.net.NetworkTemplate; import android.os.Binder; @@ -1551,6 +1551,30 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } + private StatsObserver mStatsObserver = new StatsObserver(); + + private class StatsObserver implements NonMonotonicObserver { + private String mCurrentType; + + public void setCurrentType(String type) { + mCurrentType = type; + } + + /** {@inheritDoc} */ + public void foundNonMonotonic( + NetworkStats left, int leftIndex, NetworkStats right, int rightIndex) { + Log.w(TAG, "found non-monotonic values; saving to dropbox"); + + // record error for debugging + final StringBuilder builder = new StringBuilder(); + builder.append("found non-monotonic " + mCurrentType + " values at left[" + leftIndex + + "] - right[" + rightIndex + "]\n"); + builder.append("left=").append(left).append('\n'); + builder.append("right=").append(right).append('\n'); + mDropBox.addText(TAG_NETSTATS_ERROR, builder.toString()); + } + } + /** * Return the delta between two {@link NetworkStats} snapshots, where {@code * before} can be {@code null}. @@ -1558,27 +1582,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private NetworkStats computeStatsDelta( NetworkStats before, NetworkStats current, boolean collectStale, String type) { if (before != null) { - try { - return current.subtract(before, false); - } catch (NonMonotonicException e) { - Log.w(TAG, "found non-monotonic values; saving to dropbox"); - - // record error for debugging - final StringBuilder builder = new StringBuilder(); - builder.append("found non-monotonic " + type + " values at left[" + e.leftIndex - + "] - right[" + e.rightIndex + "]\n"); - builder.append("left=").append(e.left).append('\n'); - builder.append("right=").append(e.right).append('\n'); - mDropBox.addText(TAG_NETSTATS_ERROR, builder.toString()); - - try { - // return clamped delta to help recover - return current.subtract(before, true); - } catch (NonMonotonicException e1) { - Log.wtf(TAG, "found non-monotonic values; returning empty delta", e1); - return new NetworkStats(0L, 10); - } - } + mStatsObserver.setCurrentType(type); + return NetworkStats.subtract(current, before, mStatsObserver); } else if (collectStale) { // caller is okay collecting stale stats for first call. return current; |