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

Commit 71d6737b authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Move REQUIRE_PROTOLOG check into LogcatOnlyProtoLogImpl

We were checking this condition in the static block of ProtoLog but this would be called on the first use of the ProtoLog class. So if we wanted to set ProtoLog.REQUIRE_PROTOLOGTOOL to false, this static block would execute before toggling REQUIRE_PROTOLOGTOOL. This was causing crashes in the initalization of SysUI which doesn't always pre-process the code.

Bug: 351458758
Flag: EXEMPT bug fix
Test: build a next target and boot the device
Change-Id: If5fe3d3d5738ed09c87aafdfabb8b6e427957c1c
parent 0d98f3df
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.protolog;

import static com.android.internal.protolog.ProtoLog.REQUIRE_PROTOLOGTOOL;

import android.text.TextUtils;
import android.util.Log;

@@ -42,6 +44,11 @@ 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.");
        }

        String formattedString = TextUtils.formatSimple(messageString, args);
        switch (logLevel) {
            case VERBOSE -> Log.v(group.getTag(), formattedString);
+3 −5
Original line number Diff line number Diff line
@@ -174,11 +174,9 @@ public class ProtoLog {
        if (android.tracing.Flags.perfettoProtologTracing()) {
            sProtoLogInstance = new PerfettoProtoLogImpl();
        } else {
            if (REQUIRE_PROTOLOGTOOL) {
                throw new RuntimeException("REQUIRE_PROTOLOGTOOL not set to false.");
            } 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();
        }
    }
}
}