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

Commit 11ef3cc3 authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Improves dump() to handle special cases."

parents 475be0c9 4381e4f0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ package android.app {

  @UiContext public class Activity extends android.view.ContextThemeWrapper implements android.content.ComponentCallbacks2 android.view.KeyEvent.Callback android.view.LayoutInflater.Factory2 android.view.OnBackInvokedDispatcherOwner android.view.View.OnCreateContextMenuListener android.view.Window.Callback {
    method public final boolean addDumpable(@NonNull android.util.Dumpable);
    method public void dumpInternal(@NonNull String, @Nullable java.io.FileDescriptor, @NonNull java.io.PrintWriter, @Nullable String[]);
    method public void onMovedToDisplay(int, android.content.res.Configuration);
  }

+45 −5
Original line number Diff line number Diff line
@@ -33,12 +33,16 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.StyleRes;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UiContext;
import android.app.VoiceInteractor.Request;
import android.app.admin.DevicePolicyManager;
import android.app.assist.AssistContent;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
@@ -788,6 +792,16 @@ public class Activity extends ContextThemeWrapper
    private static final int LOG_AM_ON_TOP_RESUMED_GAINED_CALLED = 30064;
    private static final int LOG_AM_ON_TOP_RESUMED_LOST_CALLED = 30065;

    /**
     * After {@link Build.VERSION_CODES#TIRAMISU},
     * {@link #dump(String, FileDescriptor, PrintWriter, String[])} is not called if
     * {@code dumpsys activity} is called with some special arguments.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
    @VisibleForTesting
    private static final long DUMP_IGNORES_SPECIAL_ARGS = 149254050L;

    private static class ManagedDialog {
        Dialog mDialog;
        Bundle mArgs;
@@ -7102,7 +7116,18 @@ public class Activity extends ContextThemeWrapper

    /**
     * Print the Activity's state into the given stream.  This gets invoked if
     * you run "adb shell dumpsys activity <activity_component_name>".
     * you run <code>adb shell dumpsys activity &lt;activity_component_name&gt;</code>.
     *
     * <p>This method won't be called if the app targets
     * {@link android.os.Build.VERSION_CODES#TIRAMISU} or later if the dump request starts with one
     * of the following arguments:
     * <ul>
     *   <li>--autofill
     *   <li>--contentcapture
     *   <li>--translation
     *   <li>--list-dumpables
     *   <li>--dump-dumpable
     * </ul>
     *
     * @param prefix Desired prefix to prepend at each line of output.
     * @param fd The raw file descriptor that the dump is being sent to.
@@ -7129,11 +7154,20 @@ public class Activity extends ContextThemeWrapper
        return mDumpableContainer.addDumpable(dumpable);
    }

    void dumpInner(@NonNull String prefix, @Nullable FileDescriptor fd,
    /**
     * This is the real method called by {@code ActivityThread}, but it's also exposed so
     * CTS can test for the special args cases.
     *
     * @hide
     */
    @TestApi
    @VisibleForTesting
    @SuppressLint("OnNameExpected")
    public void dumpInternal(@NonNull String prefix,
            @SuppressLint("UseParcelFileDescriptor") @Nullable FileDescriptor fd,
            @NonNull PrintWriter writer, @Nullable String[] args) {
        String innerPrefix = prefix + "  ";

        if (args != null && args.length > 0) {
        if (args != null && args.length > 0
                && CompatChanges.isChangeEnabled(DUMP_IGNORES_SPECIAL_ARGS)) {
            // Handle special cases
            switch (args[0]) {
                case "--autofill":
@@ -7168,6 +7202,12 @@ public class Activity extends ContextThemeWrapper
                    return;
            }
        }
        dump(prefix, fd, writer, args);
    }

    void dumpInner(@NonNull String prefix, @Nullable FileDescriptor fd,
            @NonNull PrintWriter writer, @Nullable String[] args) {
        String innerPrefix = prefix + "  ";

        writer.print(prefix); writer.print("Local Activity ");
                writer.print(Integer.toHexString(System.identityHashCode(this)));
+1 −1
Original line number Diff line number Diff line
@@ -4591,7 +4591,7 @@ public final class ActivityThread extends ClientTransactionHandler
            if (r != null && r.activity != null) {
                PrintWriter pw = new FastPrintWriter(new FileOutputStream(
                        info.fd.getFileDescriptor()));
                r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args);
                r.activity.dumpInternal(info.prefix, info.fd.getFileDescriptor(), pw, info.args);
                pw.flush();
            }
        } finally {