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

Commit 3a3403a6 authored by Charles Yo's avatar Charles Yo
Browse files

Revert "Handle potentially null strings passed as ProtoLog parameter"

Revert submission 28147757-no-processing-protolog

Reason for revert: b/351458758

Reverted changes: /q/submissionid:28147757-no-processing-protolog

Change-Id: Id57d46e0521064b61af5cb081d214568a548f33e
parent 1688d1db
Loading
Loading
Loading
Loading
+4 −20
Original line number Original line Diff line number Diff line
@@ -91,7 +91,6 @@ import java.util.concurrent.locks.ReentrantLock;
 */
 */
public class PerfettoProtoLogImpl implements IProtoLog {
public class PerfettoProtoLogImpl implements IProtoLog {
    private static final String LOG_TAG = "ProtoLog";
    private static final String LOG_TAG = "ProtoLog";
    public static final String NULL_STRING = "null";
    private final AtomicInteger mTracingInstances = new AtomicInteger();
    private final AtomicInteger mTracingInstances = new AtomicInteger();


    private final ProtoLogDataSource mDataSource = new ProtoLogDataSource(
    private final ProtoLogDataSource mDataSource = new ProtoLogDataSource(
@@ -321,14 +320,8 @@ public class PerfettoProtoLogImpl implements IProtoLog {
            StringBuilder builder = new StringBuilder("UNKNOWN MESSAGE");
            StringBuilder builder = new StringBuilder("UNKNOWN MESSAGE");
            if (args != null) {
            if (args != null) {
                builder.append(" args = (");
                builder.append(" args = (");
                builder.append(String.join(", ", Arrays.stream(args)
                builder.append(String.join(", ", Arrays.stream(args).map(
                        .map(it -> {
                        Object::toString).toList()));
                            if (it == null) {
                                return "null";
                            } else {
                                return it.toString();
                            }
                        }).toList()));
                builder.append(")");
                builder.append(")");
            }
            }
            messageString = builder.toString();
            messageString = builder.toString();
@@ -419,12 +412,8 @@ public class PerfettoProtoLogImpl implements IProtoLog {
                for (Object o : args) {
                for (Object o : args) {
                    int type = LogDataType.bitmaskToLogDataType(message.getMessageMask(), argIndex);
                    int type = LogDataType.bitmaskToLogDataType(message.getMessageMask(), argIndex);
                    if (type == LogDataType.STRING) {
                    if (type == LogDataType.STRING) {
                        if (o == null) {
                            internStringArg(ctx, NULL_STRING);
                        } else {
                        internStringArg(ctx, o.toString());
                        internStringArg(ctx, o.toString());
                    }
                    }
                    }
                    argIndex++;
                    argIndex++;
                }
                }
            }
            }
@@ -466,12 +455,7 @@ public class PerfettoProtoLogImpl implements IProtoLog {
                    try {
                    try {
                        switch (type) {
                        switch (type) {
                            case LogDataType.STRING:
                            case LogDataType.STRING:
                                final int internedStringId;
                                final int internedStringId = internStringArg(ctx, o.toString());
                                if (o == null) {
                                    internedStringId = internStringArg(ctx, NULL_STRING);
                                } else {
                                    internedStringId = internStringArg(ctx, o.toString());
                                }
                                os.write(STR_PARAM_IIDS, internedStringId);
                                os.write(STR_PARAM_IIDS, internedStringId);
                                needsIncrementalState = true;
                                needsIncrementalState = true;
                                break;
                                break;
+0 −23
Original line number Original line Diff line number Diff line
@@ -688,29 +688,6 @@ public class PerfettoProtoLogImplTest {
                .isFalse();
                .isFalse();
    }
    }


    @Test
    public void supportsNullString() throws IOException {
        PerfettoTraceMonitor traceMonitor =
                PerfettoTraceMonitor.newBuilder().enableProtoLog(true)
                        .build();

        try {
            traceMonitor.start();

            mProtoLog.log(LogLevel.DEBUG, TestProtoLogGroup.TEST_GROUP,
                    "My test null string: %s", null);
        } finally {
            traceMonitor.stop(mWriter);
        }

        final ResultReader reader = new ResultReader(mWriter.write(), mTraceConfig);
        final ProtoLogTrace protolog = reader.readProtoLogTrace();

        Truth.assertThat(protolog.messages).hasSize(1);
        Truth.assertThat(protolog.messages.get(0).getMessage())
                .isEqualTo("My test null string: null");
    }

    private enum TestProtoLogGroup implements IProtoLogGroup {
    private enum TestProtoLogGroup implements IProtoLogGroup {
        TEST_GROUP(true, true, false, "TEST_TAG");
        TEST_GROUP(true, true, false, "TEST_TAG");