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

Commit 828149e6 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Don't try to log to logcat before the service is ready to trace messages to logcat

This means we need to wait for the relevant parts of the viewer config to be loaded into memory.

Flag: EXEMPT minor bug fix
Bug: 369052956
Test: atest TracingTests
Change-Id: I1472eaccb309ac6b3eccbf4a6b58aab8dc51b9b1
parent 6257d935
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -113,6 +113,9 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
    private final Lock mBackgroundServiceLock = new ReentrantLock();
    protected ExecutorService mBackgroundLoggingService = Executors.newSingleThreadExecutor();

    // Set to true once this is ready to accept protolog to logcat requests.
    private boolean mLogcatReady = false;

    protected PerfettoProtoLogImpl(
            @NonNull Runnable cacheUpdater,
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
@@ -288,6 +291,10 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
        }
    }

    protected void readyToLogToLogcat() {
        mLogcatReady = true;
    }

    /**
     * Responds to a shell command.
     */
@@ -391,6 +398,13 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen

    private void logToLogcat(@NonNull String tag, @NonNull LogLevel level, @NonNull Message message,
            @Nullable Object[] args) {
        if (!mLogcatReady) {
            Log.w(LOG_TAG, "Trying to log a protolog message with hash "
                    + message.getMessageHash() + " to logcat before the service is ready to accept "
                    + "such requests.");
            return;
        }

        String messageString = getLogcatMessageString(message);
        logToLogcat(tag, level, messageString, args);
    }
+4 −2
Original line number Diff line number Diff line
@@ -163,7 +163,9 @@ public class ProcessedPerfettoProtoLogImpl extends PerfettoProtoLogImpl {
        // Load in background to avoid delay in boot process.
        // The caveat is that any log message that is also logged to logcat will not be
        // successfully decoded until this completes.
        mBackgroundLoggingService.execute(() -> mViewerConfigReader
                .loadViewerConfig(groupsLoggingToLogcat.toArray(new String[0])));
        mBackgroundLoggingService.execute(() -> {
            mViewerConfigReader.loadViewerConfig(groupsLoggingToLogcat.toArray(new String[0]));
            readyToLogToLogcat();
        });
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ public class UnprocessedPerfettoProtoLogImpl extends PerfettoProtoLogImpl {
    public UnprocessedPerfettoProtoLogImpl(@NonNull Runnable cacheUpdater,
            @NonNull IProtoLogGroup[] groups) throws ServiceManager.ServiceNotFoundException {
        super(cacheUpdater, groups);
        readyToLogToLogcat();
    }

    @NonNull