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

Commit d2650882 authored by Muhammad Qureshi's avatar Muhammad Qureshi
Browse files

Fix error handling in StatsEvent

Bug: 143286399
Test: bit FrameworksCoreTests:android.util.StatsEventTest
Change-Id: I2159bf138a307e45c44102a8feb7a69d0c793843
parent 9064ede6
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -177,7 +177,7 @@ public final class StatsEvent implements Parcelable {
     * @hide
     * @hide
     **/
     **/
    @VisibleForTesting
    @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.
    // Size limits.


@@ -628,9 +628,9 @@ public final class StatsEvent implements Parcelable {
            if (0 == mErrorMask) {
            if (0 == mErrorMask) {
                mBuffer.putByte(POS_NUM_ELEMENTS, (byte) mNumElements);
                mBuffer.putByte(POS_NUM_ELEMENTS, (byte) mNumElements);
            } else {
            } else {
                mBuffer.putByte(0, TYPE_ERRORS);
                mPos += mBuffer.putByte(mPos, TYPE_ERRORS);
                mBuffer.putByte(POS_NUM_ELEMENTS, (byte) 3);
                mPos += mBuffer.putInt(mPos, mErrorMask);
                mPos += mBuffer.putInt(mPos, mErrorMask);
                mBuffer.putByte(POS_NUM_ELEMENTS, (byte) 3);
                size = mPos;
                size = mPos;
            }
            }


+5 −2
Original line number Original line Diff line number Diff line
@@ -53,8 +53,8 @@ public class StatsEventTest {
        final ByteBuffer buffer =
        final ByteBuffer buffer =
                ByteBuffer.wrap(statsEvent.getBytes()).order(ByteOrder.LITTLE_ENDIAN);
                ByteBuffer.wrap(statsEvent.getBytes()).order(ByteOrder.LITTLE_ENDIAN);


        assertWithMessage("Root element in buffer is not TYPE_ERRORS")
        assertWithMessage("Root element in buffer is not TYPE_OBJECT")
                .that(buffer.get()).isEqualTo(StatsEvent.TYPE_ERRORS);
                .that(buffer.get()).isEqualTo(StatsEvent.TYPE_OBJECT);


        assertWithMessage("Incorrect number of elements in root object")
        assertWithMessage("Incorrect number of elements in root object")
                .that(buffer.get()).isEqualTo(3);
                .that(buffer.get()).isEqualTo(3);
@@ -71,6 +71,9 @@ public class StatsEventTest {
        assertWithMessage("Incorrect atom id")
        assertWithMessage("Incorrect atom id")
                .that(buffer.getInt()).isEqualTo(expectedAtomId);
                .that(buffer.getInt()).isEqualTo(expectedAtomId);


        assertWithMessage("Third element is not errors type")
                .that(buffer.get()).isEqualTo(StatsEvent.TYPE_ERRORS);

        final int errorMask = buffer.getInt();
        final int errorMask = buffer.getInt();


        assertWithMessage("ERROR_NO_ATOM_ID should be the only error in the error mask")
        assertWithMessage("ERROR_NO_ATOM_ID should be the only error in the error mask")