Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40d13eec authored by Jeff Sharkey's avatar Jeff Sharkey Committed by android-build-merger
Browse files

Merge "Last-ditch clamping of negative NetworkStats." into pi-dev am: 44eae19b

am: 08211d94

Change-Id: I572ef538dafb59d8947958df8eac155e890d08f0
parents 73468a04 08211d94
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -1100,6 +1100,8 @@ public class NetworkStats implements Parcelable {
    public interface NonMonotonicObserver<C> {
    public interface NonMonotonicObserver<C> {
        public void foundNonMonotonic(
        public void foundNonMonotonic(
                NetworkStats left, int leftIndex, NetworkStats right, int rightIndex, C cookie);
                NetworkStats left, int leftIndex, NetworkStats right, int rightIndex, C cookie);
        public void foundNonMonotonic(
                NetworkStats stats, int statsIndex, C cookie);
    }
    }


    /**
    /**
+14 −0
Original line number Original line Diff line number Diff line
@@ -241,6 +241,20 @@ public class NetworkStatsRecorder {
        NetworkStats.Entry entry = null;
        NetworkStats.Entry entry = null;
        for (int i = 0; i < delta.size(); i++) {
        for (int i = 0; i < delta.size(); i++) {
            entry = delta.getValues(i, entry);
            entry = delta.getValues(i, entry);

            // As a last-ditch sanity check, report any negative values and
            // clamp them so recording below doesn't croak.
            if (entry.isNegative()) {
                if (mObserver != null) {
                    mObserver.foundNonMonotonic(delta, i, mCookie);
                }
                entry.rxBytes = Math.max(entry.rxBytes, 0);
                entry.rxPackets = Math.max(entry.rxPackets, 0);
                entry.txBytes = Math.max(entry.txBytes, 0);
                entry.txPackets = Math.max(entry.txPackets, 0);
                entry.operations = Math.max(entry.operations, 0);
            }

            final NetworkIdentitySet ident = ifaceIdent.get(entry.iface);
            final NetworkIdentitySet ident = ifaceIdent.get(entry.iface);
            if (ident == null) {
            if (ident == null) {
                unknownIfaces.add(entry.iface);
                unknownIfaces.add(entry.iface);
+16 −4
Original line number Original line Diff line number Diff line
@@ -1711,7 +1711,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
        @Override
        @Override
        public void foundNonMonotonic(NetworkStats left, int leftIndex, NetworkStats right,
        public void foundNonMonotonic(NetworkStats left, int leftIndex, NetworkStats right,
                int rightIndex, String cookie) {
                int rightIndex, String cookie) {
            Log.w(TAG, "found non-monotonic values; saving to dropbox");
            Log.w(TAG, "Found non-monotonic values; saving to dropbox");


            // record error for debugging
            // record error for debugging
            final StringBuilder builder = new StringBuilder();
            final StringBuilder builder = new StringBuilder();
@@ -1720,9 +1720,21 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
            builder.append("left=").append(left).append('\n');
            builder.append("left=").append(left).append('\n');
            builder.append("right=").append(right).append('\n');
            builder.append("right=").append(right).append('\n');


            final DropBoxManager dropBox = (DropBoxManager) mContext.getSystemService(
            mContext.getSystemService(DropBoxManager.class).addText(TAG_NETSTATS_ERROR,
                    Context.DROPBOX_SERVICE);
                    builder.toString());
            dropBox.addText(TAG_NETSTATS_ERROR, builder.toString());
        }

        @Override
        public void foundNonMonotonic(
                NetworkStats stats, int statsIndex, String cookie) {
            Log.w(TAG, "Found non-monotonic values; saving to dropbox");

            final StringBuilder builder = new StringBuilder();
            builder.append("Found non-monotonic " + cookie + " values at [" + statsIndex + "]\n");
            builder.append("stats=").append(stats).append('\n');

            mContext.getSystemService(DropBoxManager.class).addText(TAG_NETSTATS_ERROR,
                    builder.toString());
        }
        }
    }
    }