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

Commit ecc781ba authored by Alec Mouri's avatar Alec Mouri
Browse files

Add support for UIDs in bootstrap atoms

Bug: 329474645
Flag: EXEMPT logging
Test: adb shell cmd stats print-logs then  adb logcat | grep statsd | grep ATOM_ID
Change-Id: I9797f0a921e29104e41046d57aab3d5a36cfcdc1
parent ffda9a50
Loading
Loading
Loading
Loading
+33 −9
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@ package android.os;
 *
 * @hide
 */
union StatsBootstrapAtomValue {
parcelable StatsBootstrapAtomValue {
    union Primitive {
        boolean boolValue;
        int intValue;
        long longValue;
@@ -28,3 +29,26 @@ union StatsBootstrapAtomValue {
        byte[] bytesValue;
	String[] stringArrayValue;
    }

    Primitive value;

    parcelable Annotation {
        // Match the definitions in
        // packages/modules/StatsD/framework/java/android/util/StatsLog.java
        // Only supports UIDs for now.
        @Backing(type="byte")
        enum Id {
            NONE,
            IS_UID,
        }
        Id id;

        union Primitive {
            boolean boolValue;
            int intValue;
        }
        Primitive value;
    }

    Annotation[] annotations;
}
+28 −8
Original line number Diff line number Diff line
@@ -42,27 +42,28 @@ public class StatsBootstrapAtomService extends IStatsBootstrapAtomService.Stub {
            return;
        }
        StatsEvent.Builder builder = StatsEvent.newBuilder().setAtomId(atom.atomId);
        for (StatsBootstrapAtomValue value : atom.values) {
        for (StatsBootstrapAtomValue atomValue : atom.values) {
            StatsBootstrapAtomValue.Primitive value = atomValue.value;
            switch (value.getTag()) {
                case StatsBootstrapAtomValue.boolValue:
                case StatsBootstrapAtomValue.Primitive.boolValue:
                    builder.writeBoolean(value.getBoolValue());
                    break;
                case StatsBootstrapAtomValue.intValue:
                case StatsBootstrapAtomValue.Primitive.intValue:
                    builder.writeInt(value.getIntValue());
                    break;
                case StatsBootstrapAtomValue.longValue:
                case StatsBootstrapAtomValue.Primitive.longValue:
                    builder.writeLong(value.getLongValue());
                    break;
                case StatsBootstrapAtomValue.floatValue:
                case StatsBootstrapAtomValue.Primitive.floatValue:
                    builder.writeFloat(value.getFloatValue());
                    break;
                case StatsBootstrapAtomValue.stringValue:
                case StatsBootstrapAtomValue.Primitive.stringValue:
                    builder.writeString(value.getStringValue());
                    break;
                case StatsBootstrapAtomValue.bytesValue:
                case StatsBootstrapAtomValue.Primitive.bytesValue:
                    builder.writeByteArray(value.getBytesValue());
                    break;
                case StatsBootstrapAtomValue.stringArrayValue:
                case StatsBootstrapAtomValue.Primitive.stringArrayValue:
                    builder.writeStringArray(value.getStringArrayValue());
                    break;
                default:
@@ -71,6 +72,25 @@ public class StatsBootstrapAtomService extends IStatsBootstrapAtomService.Stub {
                    return;

            }
            StatsBootstrapAtomValue.Annotation[] annotations = atomValue.annotations;
            for (StatsBootstrapAtomValue.Annotation annotation : atomValue.annotations) {
                if (annotation.id != StatsBootstrapAtomValue.Annotation.Id.IS_UID) {
                    Slog.e(TAG, "Unexpected annotation ID: " + annotation.id
                            + ", for atom " + atom.atomId + ": only UIDs are supported!");
                    return;
                }

                switch (annotation.value.getTag()) {
                    case StatsBootstrapAtomValue.Annotation.Primitive.boolValue:
                        builder.addBooleanAnnotation(
                                annotation.id, annotation.value.getBoolValue());
                        break;
                    default:
                        Slog.e(TAG, "Unexpected value type " + annotation.value.getTag()
                                + " when logging UID for atom " + atom.atomId);
                        return;
                }
            }
        }
        StatsLog.write(builder.usePooledBuffer().build());
    }