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

Commit 5004cd01 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Support unprocessed files when Perfetto protologging is not enabled

Some files are not processable by the ProtoLog tool yet because they use newer language features than the java parser we use supports. This means these files will use the default ProtoLog call instead of the generate implementation. The PerfettoProtoLogImpl supports tracing non-processed log messages to Perfetto, but the LogcatOnlyProtoLogImpl which is used when the logging to Perfetto flag is disabled crashes in those cases unless the REQUIRE_PROTOLOGTOOL is set to false. We want to make sure we don't crash in such cases and just warn about the unprocessed file.

Flag: EXEMPT small bug fix
Bug: 358044587
Change-Id: Ibfa1dbfaa2f7db769c245936ebd0cbb005609f2c
parent 607432e7
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import com.android.internal.protolog.common.LogLevel;
 */
@Deprecated
public class LogcatOnlyProtoLogImpl implements IProtoLog {
    private static final String LOG_TAG = LogcatOnlyProtoLogImpl.class.getName();

    @Override
    public void log(LogLevel logLevel, IProtoLogGroup group, long messageHash, int paramsMask,
            Object[] args) {
@@ -44,11 +46,12 @@ public class LogcatOnlyProtoLogImpl implements IProtoLog {

    @Override
    public void log(LogLevel logLevel, IProtoLogGroup group, String messageString, Object[] args) {
        if (REQUIRE_PROTOLOGTOOL) {
            throw new RuntimeException(
                    "REQUIRE_PROTOLOGTOOL not set to false before the first log call.");
        if (REQUIRE_PROTOLOGTOOL && group.isLogToProto()) {
            Log.w(LOG_TAG, "ProtoLog message not processed. Failed to log it to proto. "
                    + "Logging it below to logcat instead.");
        }

        if (group.isLogToLogcat() || group.isLogToProto()) {
            String formattedString = TextUtils.formatSimple(messageString, args);
            switch (logLevel) {
                case VERBOSE -> Log.v(group.getTag(), formattedString);
@@ -59,6 +62,7 @@ public class LogcatOnlyProtoLogImpl implements IProtoLog {
                case WTF -> Log.wtf(group.getTag(), formattedString);
            }
        }
    }

    @Override
    public boolean isProtoEnabled() {
+3 −2
Original line number Diff line number Diff line
@@ -58,11 +58,12 @@ public class ProtoLog {
     * @param groups The ProtoLog groups that will be used in the process.
     */
    public static void init(IProtoLogGroup... groups) {
        // These tracing instances are only used when we cannot or do not preprocess the source
        // files to extract out the log strings. Otherwise, the trace calls are replaced with calls
        // directly to the generated tracing implementations.
        if (android.tracing.Flags.perfettoProtologTracing()) {
            sProtoLogInstance = new PerfettoProtoLogImpl(groups);
        } else {
            // The first call to ProtoLog is likely to flip REQUIRE_PROTOLOGTOOL, which is when this
            // static block will be executed before REQUIRE_PROTOLOGTOOL is actually set.
            sProtoLogInstance = new LogcatOnlyProtoLogImpl();
        }
    }