From 2dfca163ab85ce19d20b96531b0085501f77ed50 Mon Sep 17 00:00:00 2001 From: Muhammad Qureshi Date: Thu, 5 Dec 2019 18:07:12 -0800 Subject: [PATCH] Fix error handling in StatsEvent Bug: 143286399 Test: bit FrameworksCoreTests:android.util.StatsEventTest Change-Id: I2159bf138a307e45c44102a8feb7a69d0c793843 Merged-In: I2159bf138a307e45c44102a8feb7a69d0c793843 --- core/java/android/util/StatsEvent.java | 6 +++--- core/tests/coretests/src/android/util/StatsEventTest.java | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/java/android/util/StatsEvent.java b/core/java/android/util/StatsEvent.java index cc32847834c0a..7e71640427818 100644 --- a/core/java/android/util/StatsEvent.java +++ b/core/java/android/util/StatsEvent.java @@ -175,7 +175,7 @@ public final class StatsEvent { * @hide **/ @VisibleForTesting - public static final int ERROR_ATTRIBUTION_UIDS_TAGS_SIZES_NOT_EQUAL = 0x400; + public static final int ERROR_ATTRIBUTION_UIDS_TAGS_SIZES_NOT_EQUAL = 0x1000; // Size limits. @@ -593,9 +593,9 @@ public final class StatsEvent { if (0 == mErrorMask) { mBuffer.putByte(POS_NUM_ELEMENTS, (byte) mNumElements); } else { - mBuffer.putByte(0, TYPE_ERRORS); - mBuffer.putByte(POS_NUM_ELEMENTS, (byte) 3); + mPos += mBuffer.putByte(mPos, TYPE_ERRORS); mPos += mBuffer.putInt(mPos, mErrorMask); + mBuffer.putByte(POS_NUM_ELEMENTS, (byte) 3); size = mPos; } diff --git a/core/tests/coretests/src/android/util/StatsEventTest.java b/core/tests/coretests/src/android/util/StatsEventTest.java index 93f11dbccf649..097badadcea95 100644 --- a/core/tests/coretests/src/android/util/StatsEventTest.java +++ b/core/tests/coretests/src/android/util/StatsEventTest.java @@ -53,8 +53,8 @@ public class StatsEventTest { final ByteBuffer buffer = ByteBuffer.wrap(statsEvent.getBytes()).order(ByteOrder.LITTLE_ENDIAN); - assertWithMessage("Root element in buffer is not TYPE_ERRORS") - .that(buffer.get()).isEqualTo(StatsEvent.TYPE_ERRORS); + assertWithMessage("Root element in buffer is not TYPE_OBJECT") + .that(buffer.get()).isEqualTo(StatsEvent.TYPE_OBJECT); assertWithMessage("Incorrect number of elements in root object") .that(buffer.get()).isEqualTo(3); @@ -71,6 +71,9 @@ public class StatsEventTest { assertWithMessage("Incorrect atom id") .that(buffer.getInt()).isEqualTo(expectedAtomId); + assertWithMessage("Third element is not errors type") + .that(buffer.get()).isEqualTo(StatsEvent.TYPE_ERRORS); + final int errorMask = buffer.getInt(); assertWithMessage("ERROR_NO_ATOM_ID should be the only error in the error mask")