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

Commit a788a977 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Update uses of ProtoLog

Flag: ACONFIG android.tracing.Flags.perfettoProtolog DEVELOPMENT
Bug: 276432490
Test: atest FrameworksServicesTests
Change-Id: I92926a44baaeea3971e46c0901898c90b6c98adb
parent 5fe2c80e
Loading
Loading
Loading
Loading
+33 −13
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@

package com.android.wm.shell;

import com.android.wm.shell.protolog.ShellProtoLogImpl;
import com.android.internal.protolog.LegacyProtoLogImpl;
import com.android.internal.protolog.common.ILogger;
import com.android.internal.protolog.common.IProtoLog;
import com.android.internal.protolog.common.ProtoLog;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellInit;

@@ -24,19 +27,19 @@ import java.io.PrintWriter;
import java.util.Arrays;

/**
 * Controls the {@link ShellProtoLogImpl} in WMShell via adb shell commands.
 * Controls the {@link ProtoLog} in WMShell via adb shell commands.
 *
 * Use with {@code adb shell dumpsys activity service SystemUIService WMShell protolog ...}.
 */
public class ProtoLogController implements ShellCommandHandler.ShellCommandActionHandler {
    private final ShellCommandHandler mShellCommandHandler;
    private final ShellProtoLogImpl mShellProtoLog;
    private final IProtoLog mShellProtoLog;

    public ProtoLogController(ShellInit shellInit,
            ShellCommandHandler shellCommandHandler) {
        shellInit.addInitCallback(this::onInit, this);
        mShellCommandHandler = shellCommandHandler;
        mShellProtoLog = ShellProtoLogImpl.getSingleInstance();
        mShellProtoLog = ProtoLog.getSingleInstance();
    }

    void onInit() {
@@ -45,22 +48,35 @@ public class ProtoLogController implements ShellCommandHandler.ShellCommandActio

    @Override
    public boolean onShellCommand(String[] args, PrintWriter pw) {
        final ILogger logger = pw::println;
        switch (args[0]) {
            case "status": {
                pw.println(mShellProtoLog.getStatus());
                if (android.tracing.Flags.perfettoProtolog()) {
                    pw.println("(Deprecated) legacy command. Use Perfetto commands instead.");
                    return false;
                }
                ((LegacyProtoLogImpl) mShellProtoLog).getStatus();
                return true;
            }
            case "start": {
                mShellProtoLog.startProtoLog(pw);
                if (android.tracing.Flags.perfettoProtolog()) {
                    pw.println("(Deprecated) legacy command. Use Perfetto commands instead.");
                    return false;
                }
                ((LegacyProtoLogImpl) mShellProtoLog).startProtoLog(pw);
                return true;
            }
            case "stop": {
                mShellProtoLog.stopProtoLog(pw, true /* writeToFile */);
                if (android.tracing.Flags.perfettoProtolog()) {
                    pw.println("(Deprecated) legacy command. Use Perfetto commands instead.");
                    return false;
                }
                ((LegacyProtoLogImpl) mShellProtoLog).stopProtoLog(pw, true);
                return true;
            }
            case "enable-text": {
                String[] groups = Arrays.copyOfRange(args, 1, args.length);
                int result = mShellProtoLog.startTextLogging(groups, pw);
                int result = mShellProtoLog.startLoggingToLogcat(groups, logger);
                if (result == 0) {
                    pw.println("Starting logging on groups: " + Arrays.toString(groups));
                    return true;
@@ -69,7 +85,7 @@ public class ProtoLogController implements ShellCommandHandler.ShellCommandActio
            }
            case "disable-text": {
                String[] groups = Arrays.copyOfRange(args, 1, args.length);
                int result = mShellProtoLog.stopTextLogging(groups, pw);
                int result = mShellProtoLog.stopLoggingToLogcat(groups, logger);
                if (result == 0) {
                    pw.println("Stopping logging on groups: " + Arrays.toString(groups));
                    return true;
@@ -78,19 +94,23 @@ public class ProtoLogController implements ShellCommandHandler.ShellCommandActio
            }
            case "enable": {
                String[] groups = Arrays.copyOfRange(args, 1, args.length);
                return mShellProtoLog.startTextLogging(groups, pw) == 0;
                return mShellProtoLog.startLoggingToLogcat(groups, logger) == 0;
            }
            case "disable": {
                String[] groups = Arrays.copyOfRange(args, 1, args.length);
                return mShellProtoLog.stopTextLogging(groups, pw) == 0;
                return mShellProtoLog.stopLoggingToLogcat(groups, logger) == 0;
            }
            case "save-for-bugreport": {
                if (android.tracing.Flags.perfettoProtolog()) {
                    pw.println("(Deprecated) legacy command");
                    return false;
                }
                if (!mShellProtoLog.isProtoEnabled()) {
                    pw.println("Logging to proto is not enabled for WMShell.");
                    return false;
                }
                mShellProtoLog.stopProtoLog(pw, true /* writeToFile */);
                mShellProtoLog.startProtoLog(pw);
                ((LegacyProtoLogImpl) mShellProtoLog).stopProtoLog(pw, true /* writeToFile */);
                ((LegacyProtoLogImpl) mShellProtoLog).startProtoLog(pw);
                return true;
            }
            default: {
+7 −7
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.wm.shell.util

import android.util.Log
import com.android.internal.protolog.common.IProtoLogGroup
import com.android.wm.shell.protolog.ShellProtoLogImpl
import com.android.internal.protolog.common.ProtoLog

/**
 * Log messages using an API similar to [com.android.internal.protolog.common.ProtoLog]. Useful for
@@ -31,42 +31,42 @@ class KtProtoLog {
    companion object {
        /** @see [com.android.internal.protolog.common.ProtoLog.d] */
        fun d(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
            if (ProtoLog.isEnabled(group)) {
                Log.d(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.v] */
        fun v(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
            if (ProtoLog.isEnabled(group)) {
                Log.v(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.i] */
        fun i(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
            if (ProtoLog.isEnabled(group)) {
                Log.i(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.w] */
        fun w(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
            if (ProtoLog.isEnabled(group)) {
                Log.w(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.e] */
        fun e(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
            if (ProtoLog.isEnabled(group)) {
                Log.e(group.tag, String.format(messageString, *args))
            }
        }

        /** @see [com.android.internal.protolog.common.ProtoLog.wtf] */
        fun wtf(group: IProtoLogGroup, messageString: String, vararg args: Any) {
            if (ShellProtoLogImpl.isEnabled(group)) {
            if (ProtoLog.isEnabled(group)) {
                Log.wtf(group.tag, String.format(messageString, *args))
            }
        }
+1 −2
Original line number Diff line number Diff line
@@ -137,7 +137,6 @@ import android.view.animation.TranslateAnimation;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.policy.TransitionAnimation;
import com.android.internal.protolog.ProtoLogImpl;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.util.DumpUtils.Dump;
import com.android.internal.util.function.pooled.PooledLambda;
@@ -248,7 +247,7 @@ public class AppTransition implements Dump {
        mHandler = new Handler(service.mH.getLooper());
        mDisplayContent = displayContent;
        mTransitionAnimation = new TransitionAnimation(
                context, ProtoLogImpl.isEnabled(WM_DEBUG_ANIM), TAG);
                context, ProtoLog.isEnabled(WM_DEBUG_ANIM), TAG);

        mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);

+1 −2
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ import android.view.SurfaceControl.Transaction;
import android.view.WindowManager;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.ProtoLogImpl;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.util.FastPrintWriter;
import com.android.server.wm.SurfaceAnimator.AnimationType;
@@ -210,7 +209,7 @@ class RemoteAnimationController implements DeathRecipient {
                Slog.e(TAG, "Failed to start remote animation", e);
                onAnimationFinished();
            }
            if (ProtoLogImpl.isEnabled(WM_DEBUG_REMOTE_ANIMATIONS)) {
            if (ProtoLog.isEnabled(WM_DEBUG_REMOTE_ANIMATIONS)) {
                ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "startAnimation(): Notify animation start:");
                writeStartDebugStatement();
            }
+1 −2
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.view.SurfaceControl;
import android.view.SurfaceControl.Transaction;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.ProtoLogImpl;
import com.android.internal.protolog.common.ProtoLog;

import java.io.PrintWriter;
@@ -193,7 +192,7 @@ public class SurfaceAnimator {
            return;
        }
        mAnimation.startAnimation(mLeash, t, type, mInnerAnimationFinishedCallback);
        if (ProtoLogImpl.isEnabled(WM_DEBUG_ANIM)) {
        if (ProtoLog.isEnabled(WM_DEBUG_ANIM)) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            mAnimation.dump(pw, "");
Loading