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

Commit 7ca76ee7 authored by Pablo Gamito's avatar Pablo Gamito Committed by Android (Google) Code Review
Browse files

Merge "Rename ProtoLogService to ProtoLogConfigurationService" into main

parents ae928a0f 6017169c
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ import android.window.WindowContext;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.compat.IPlatformCompat;
import com.android.internal.compat.IPlatformCompatNative;
import com.android.internal.protolog.ProtoLogConfigurationService;

import java.io.File;
import java.io.FileInputStream;
@@ -6701,13 +6702,13 @@ public abstract class Context {

    /**
     * Use with {@link #getSystemService(String)} to retrieve the
     * {@link com.android.internal.protolog.ProtoLogService} for registering ProtoLog clients.
     * {@link ProtoLogConfigurationService} for registering ProtoLog clients.
     *
     * @see #getSystemService(String)
     * @see com.android.internal.protolog.ProtoLogService
     * @see ProtoLogConfigurationService
     * @hide
     */
    public static final String PROTOLOG_SERVICE = "protolog";
    public static final String PROTOLOG_CONFIGURATION_SERVICE = "protolog_configuration";

    /**
     * Determine whether the given permission is allowed for a particular
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ package com.android.internal.protolog;
 * The ProtoLog client interface.
 *
 * These clients will communicate bi-directionally with the ProtoLog service
 * (@see IProtoLogService.aidl) running in the system process.
 * (@see IProtoLogConfigurationService.aidl) running in the system process.
 *
 * {@hide}
 */
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import com.android.internal.protolog.IProtoLogClient;
 *
 * {@hide}
 */
interface IProtoLogService {
interface IProtoLogConfigurationService {
    interface IRegisterClientArgs {
        String[] getGroups();
        boolean[] getGroupsDefaultLogcatStatus();
+13 −11
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.internal.protolog;

import static android.content.Context.PROTOLOG_SERVICE;
import static android.content.Context.PROTOLOG_CONFIGURATION_SERVICE;
import static android.internal.perfetto.protos.InternedDataOuterClass.InternedData.PROTOLOG_STACKTRACE;
import static android.internal.perfetto.protos.InternedDataOuterClass.InternedData.PROTOLOG_STRING_ARGS;
import static android.internal.perfetto.protos.ProfileCommon.InternedString.IID;
@@ -114,7 +114,7 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto
    private final Runnable mCacheUpdater;

    @Nullable // null when the flag android.tracing.client_side_proto_logging is not flipped
    private final IProtoLogService mProtoLogService;
    private final IProtoLogConfigurationService mProtoLogConfigurationService;

    @NonNull
    private final int[] mDefaultLogLevelCounts = new int[LogLevel.values().length];
@@ -186,30 +186,32 @@ public class PerfettoProtoLogImpl extends IProtoLogClient.Stub implements IProto
        registerGroupsLocally(groups);

        if (android.tracing.Flags.clientSideProtoLogging()) {
            mProtoLogService =
                    IProtoLogService.Stub.asInterface(ServiceManager.getService(PROTOLOG_SERVICE));
            Objects.requireNonNull(mProtoLogService,
            mProtoLogConfigurationService =
                    IProtoLogConfigurationService.Stub.asInterface(ServiceManager.getService(
                            PROTOLOG_CONFIGURATION_SERVICE));
            Objects.requireNonNull(mProtoLogConfigurationService,
                    "ServiceManager returned a null ProtoLog service");

            try {
                var args = new ProtoLogService.RegisterClientArgs();
                var args = new ProtoLogConfigurationService.RegisterClientArgs();

                if (viewerConfigFilePath != null) {
                    args.setViewerConfigFile(viewerConfigFilePath);
                }

                final var groupArgs = Stream.of(groups)
                        .map(group -> new ProtoLogService.RegisterClientArgs.GroupConfig(
                                group.name(), group.isLogToLogcat()))
                        .toArray(ProtoLogService.RegisterClientArgs.GroupConfig[]::new);
                        .map(group -> new ProtoLogConfigurationService.RegisterClientArgs
                                .GroupConfig(group.name(), group.isLogToLogcat()))
                        .toArray(
                                ProtoLogConfigurationService.RegisterClientArgs.GroupConfig[]::new);
                args.setGroups(groupArgs);

                mProtoLogService.registerClient(this, args);
                mProtoLogConfigurationService.registerClient(this, args);
            } catch (RemoteException e) {
                throw new RuntimeException("Failed to register ProtoLog client");
            }
        } else {
            mProtoLogService = null;
            mProtoLogConfigurationService = null;
        }
    }

+14 −11
Original line number Diff line number Diff line
@@ -29,18 +29,20 @@ import java.util.Set;

public class ProtoLogCommandHandler extends ShellCommand {
    @NonNull
    private final ProtoLogService mProtoLogService;
    private final ProtoLogConfigurationService mProtoLogConfigurationService;
    @Nullable
    private final PrintWriter mPrintWriter;

    public ProtoLogCommandHandler(@NonNull ProtoLogService protoLogService) {
        this(protoLogService, null);
    public ProtoLogCommandHandler(
            @NonNull ProtoLogConfigurationService protoLogConfigurationService) {
        this(protoLogConfigurationService, null);
    }

    @VisibleForTesting
    public ProtoLogCommandHandler(
            @NonNull ProtoLogService protoLogService, @Nullable PrintWriter printWriter) {
        this.mProtoLogService = protoLogService;
            @NonNull ProtoLogConfigurationService protoLogConfigurationService,
            @Nullable PrintWriter printWriter) {
        this.mProtoLogConfigurationService = protoLogConfigurationService;
        this.mPrintWriter = printWriter;
    }

@@ -94,7 +96,7 @@ public class ProtoLogCommandHandler extends ShellCommand {

        switch (cmd) {
            case "list": {
                final String[] availableGroups = mProtoLogService.getGroups();
                final String[] availableGroups = mProtoLogConfigurationService.getGroups();
                if (availableGroups.length == 0) {
                    pw.println("No ProtoLog groups registered with ProtoLog service.");
                    return 0;
@@ -117,12 +119,13 @@ public class ProtoLogCommandHandler extends ShellCommand {

                pw.println("ProtoLog group " + group + "'s status:");

                if (!Set.of(mProtoLogService.getGroups()).contains(group)) {
                if (!Set.of(mProtoLogConfigurationService.getGroups()).contains(group)) {
                    pw.println("UNREGISTERED");
                    return 0;
                }

                pw.println("LOG_TO_LOGCAT = " + mProtoLogService.isLoggingToLogcat(group));
                pw.println("LOG_TO_LOGCAT = "
                        + mProtoLogConfigurationService.isLoggingToLogcat(group));
                return 0;
            }
            default: {
@@ -142,11 +145,11 @@ public class ProtoLogCommandHandler extends ShellCommand {

        switch (cmd) {
            case "enable" -> {
                mProtoLogService.enableProtoLogToLogcat(processGroups());
                mProtoLogConfigurationService.enableProtoLogToLogcat(processGroups());
                return 0;
            }
            case "disable" -> {
                mProtoLogService.disableProtoLogToLogcat(processGroups());
                mProtoLogConfigurationService.disableProtoLogToLogcat(processGroups());
                return 0;
            }
            default -> {
@@ -159,7 +162,7 @@ public class ProtoLogCommandHandler extends ShellCommand {
    @NonNull
    private String[] processGroups() {
        if (getRemainingArgsCount() == 0) {
            return mProtoLogService.getGroups();
            return mProtoLogConfigurationService.getGroups();
        }

        final List<String> groups = new ArrayList<>();
Loading