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

Commit 16b0df15 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "protolog-static-init" into main

* changes:
  Register IME tracker protolog groups statically
  Add API to register ProtoLog groups seperately from initialization
parents 3cb2f473 9ea8f066
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -609,7 +609,7 @@ public interface ImeTracker {
            SystemProperties.addChangeCallback(this::reloadSystemProperties);

            if (android.tracing.Flags.imetrackerProtolog()) {
                // TODO(b/410517697): Register ProtoLog groups
                ProtoLog.registerLogGroupInProcess(IME_TRACKER);
            }
        }

+7 −0
Original line number Diff line number Diff line
@@ -47,7 +47,14 @@ interface IProtoLogConfigurationService {
        String viewerConfigFile;
    }

    parcelable RegisterGroupsArgs {
        String[] groups;
        boolean[] groupsDefaultLogcatStatus;
    }

    oneway void registerClient(IProtoLogClient client, in RegisterClientArgs args);

    oneway void registerGroups(IProtoLogClient client, in RegisterGroupsArgs args);

    oneway void unregisterClient(IProtoLogClient  client);
}
+5 −0
Original line number Diff line number Diff line
@@ -95,4 +95,9 @@ public class LogcatOnlyProtoLogImpl implements IProtoLog {
    public List<IProtoLogGroup> getRegisteredGroups() {
        return Collections.emptyList();
    }

    @Override
    public void registerGroups(IProtoLogGroup... groups) {
        // No-op
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -77,6 +77,11 @@ public class NoViewerConfigProtoLogImpl implements IProtoLog {
        return List.of();
    }

    @Override
    public void registerGroups(IProtoLogGroup... groups) {
        // No-op
    }

    private void logMessage(LogLevel logLevel, String tag, String message) {
        switch (logLevel) {
            case VERBOSE -> Log.v(tag, message);
+39 −1
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Stream;

/**
 * A service for the ProtoLog logging system.
@@ -175,6 +176,17 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
        mDataSource.registerOnStopCallback(this);
    }

    @Override
    public void registerGroups(IProtoLogGroup... groups) {
        registerGroupsLocally(groups);

        if (mConfigurationService != null) {
            registerGroupsWithConfigurationServiceAsync(groups);
        } else {
            Log.w(LOG_TAG, "Missing configuration service... Not registering groups with it.");
        }
    }

    private void connectToConfigurationService() {
        Objects.requireNonNull(mConfigurationService,
                "A null ProtoLog Configuration Service was provided!");
@@ -200,6 +212,28 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
        });
    }

    private void registerGroupsWithConfigurationServiceAsync(IProtoLogGroup... groups) {
        Objects.requireNonNull(mConfigurationService,
                "A null ProtoLog Configuration Service was provided!");

        mBackgroundHandler.post(() -> {
            try {
                var args = new IProtoLogConfigurationService.RegisterGroupsArgs();
                args.groups = new String[groups.length];
                args.groupsDefaultLogcatStatus = new boolean[groups.length];
                var i = 0;
                for (var group : groups) {
                    args.groups[i] = group.name();
                    args.groupsDefaultLogcatStatus[i] = group.isLogToLogcat();
                    i++;
                }
                mConfigurationService.registerGroups(this, args);
            } catch (RemoteException e) {
                throw new RuntimeException("Failed to register ProtoLog groups", e);
            }
        });
    }

    /**
     * Should be called when we no longer want to use the ProtoLog logger to unlink ourselves from
     * the datasource and the configuration service to ensure we no longer receive the callback.
@@ -332,7 +366,11 @@ public abstract class PerfettoProtoLogImpl extends IProtoLogClient.Stub implemen
    private void registerGroupsLocally(@NonNull IProtoLogGroup[] protoLogGroups) {
        // Verify we don't have id collisions, if we do we want to know as soon as possible and
        // we might want to manually specify an id for the group with a collision
        verifyNoCollisionsOrDuplicates(protoLogGroups);
        IProtoLogGroup[] allGroups = Stream.concat(
                mLogGroups.values().stream(),
                Arrays.stream(protoLogGroups)
        ).toArray(IProtoLogGroup[]::new);
        verifyNoCollisionsOrDuplicates(allGroups);

        for (IProtoLogGroup protoLogGroup : protoLogGroups) {
            mLogGroups.put(protoLogGroup.name(), protoLogGroup);
Loading