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

Commit 3fa0c033 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Change ProtoLog to log WTF instead of throwing when uninitialized.

When ProtoLog is called before its initialization, log a WTF message using `Log.wtf` with the tag "ProtoLog" instead of throwing an `IllegalStateException`. This prevents crashes in scenarios where ProtoLog might be used unexpectedly early in a process's lifecycle.

Bug: 434439761
Flag: EXEMPT minor bug fix
Change-Id: I0c6349e69e0676216289e28d92cf58f428deea85
parent f5a04944
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.tracing.perfetto.DataSourceParams;
import android.tracing.perfetto.InitArguments;
import android.tracing.perfetto.Producer;

import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.common.IProtoLog;
import com.android.internal.protolog.common.IProtoLogGroup;
@@ -53,6 +55,8 @@ import com.android.internal.protolog.common.LogLevel;
public class ProtoLog {
// LINT.ThenChange(frameworks/base/tools/protologtool/src/com/android/protolog/tool/ProtoLogTool.kt)

    private static final String LOG_TAG = "ProtoLog";

    // Needs to be set directly otherwise the protologtool tries to transform the method call
    @Deprecated
    public static boolean REQUIRE_PROTOLOGTOOL = true;
@@ -236,8 +240,8 @@ public class ProtoLog {
            @NonNull String stringMessage, @NonNull Object... args) {
        final var instance = sController.mProtoLogInstance;
        if (instance == null) {
            throw new IllegalStateException(
                    "Trying to use ProtoLog before it is initialized in this process.");
            Log.wtf(LOG_TAG, "Trying to use ProtoLog before it is initialized in this process.");
            return;
        }

        if (instance.isEnabled(group, logLevel)) {