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

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

Merge "Creates a generic mechanism to dump app-side information."

parents d7e39b59 bcafba3a
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -47167,6 +47167,15 @@ package android.util {
    field public float ydpi;
  }
  public interface Dumpable {
    method public void dump(@NonNull java.io.PrintWriter, @Nullable String[]);
    method @NonNull public default String getDumpableName();
  }
  public interface DumpableContainer {
    method public boolean addDumpable(@NonNull android.util.Dumpable);
  }
  public class EventLog {
    method public static int getTagCode(String);
    method public static String getTagName(int);
+4 −0
Original line number Diff line number Diff line
@@ -9,6 +9,10 @@ package android {

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.View.OnCreateContextMenuListener android.view.Window.Callback {
    method public final boolean addDumpable(@NonNull android.util.Dumpable);
  }

  public class ActivityManager {
    method @RequiresPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER) public void addHomeVisibilityListener(@NonNull java.util.concurrent.Executor, @NonNull android.app.HomeVisibilityListener);
    method @RequiresPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER) public void removeHomeVisibilityListener(@NonNull android.app.HomeVisibilityListener);
+46 −1
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ import android.transition.Scene;
import android.transition.TransitionManager;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Dumpable;
import android.util.EventLog;
import android.util.Log;
import android.util.PrintWriterPrinter;
@@ -145,6 +146,7 @@ import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.ToolbarActionBar;
import com.android.internal.app.WindowDecorActionBar;
import com.android.internal.policy.PhoneWindow;
import com.android.internal.util.dump.DumpableContainerImpl;

import dalvik.system.VMRuntime;

@@ -954,6 +956,9 @@ public class Activity extends ContextThemeWrapper

    private SplashScreen mSplashScreen;

    @Nullable
    private DumpableContainerImpl mDumpableContainer;

    private final WindowControllerCallback mWindowControllerCallback =
            new WindowControllerCallback() {
        /**
@@ -7081,8 +7086,23 @@ public class Activity extends ContextThemeWrapper
        dumpInner(prefix, fd, writer, args);
    }

    /**
     * See {@link android.util.DumpableContainer#addDumpable(Dumpable)}.
     *
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public final boolean addDumpable(@NonNull Dumpable dumpable) {
        if (mDumpableContainer == null) {
            mDumpableContainer = new DumpableContainerImpl();
        }
        return mDumpableContainer.addDumpable(dumpable);
    }

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

        if (args != null && args.length > 0) {
            // Handle special cases
            switch (args[0]) {
@@ -7095,12 +7115,33 @@ public class Activity extends ContextThemeWrapper
                case "--translation":
                    dumpUiTranslation(prefix, writer);
                    return;
                case "--list-dumpables":
                    if (mDumpableContainer == null) {
                        writer.print(prefix); writer.println("No dumpables");
                        return;
                    }
                    mDumpableContainer.listDumpables(prefix, writer);
                    return;
                case "--dump-dumpable":
                    if (args.length == 1) {
                        writer.println("--dump-dumpable requires the dumpable name");
                        return;
                    }
                    if (mDumpableContainer == null) {
                        writer.println("no dumpables");
                        return;
                    }
                    // Strips --dump-dumpable NAME
                    String[] prunedArgs = new String[args.length - 2];
                    System.arraycopy(args, 2, prunedArgs, 0, prunedArgs.length);
                    mDumpableContainer.dumpOneDumpable(prefix, writer, args[1], prunedArgs);
                    return;
            }
        }

        writer.print(prefix); writer.print("Local Activity ");
                writer.print(Integer.toHexString(System.identityHashCode(this)));
                writer.println(" State:");
        String innerPrefix = prefix + "  ";
        writer.print(innerPrefix); writer.print("mResumed=");
                writer.print(mResumed); writer.print(" mStopped=");
                writer.print(mStopped); writer.print(" mFinished=");
@@ -7138,6 +7179,10 @@ public class Activity extends ContextThemeWrapper
        dumpUiTranslation(prefix, writer);

        ResourcesManager.getInstance().dump(prefix, writer);

        if (mDumpableContainer != null) {
            mDumpableContainer.dumpAllDumpables(prefix, writer, args);
        }
    }

    void dumpContentCaptureManager(String prefix, PrintWriter writer) {
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.util;

import android.annotation.NonNull;
import android.annotation.Nullable;

import java.io.PrintWriter;

/**
 * Represents an object whose state can be dumped into a {@link PrintWriter}.
 */
public interface Dumpable {

    /**
     * Gets the name of the {@link Dumpable}.
     *
     * @return class name, by default.
     */
    @NonNull
    default String getDumpableName() {
        return getClass().getName();
    }

    //TODO(b/149254050): decide whether it should take a ParcelFileDescription as well.

    /**
     * Dumps the internal state into the given {@code writer}.
     *
     * @param writer writer to be written to
     * @param args optional list of arguments
     */
    void dump(@NonNull PrintWriter writer, @Nullable String[] args);
}
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.util;

import android.annotation.NonNull;

/**
 * Objects that contains a list of {@link Dumpable}, which will be dumped when the object itself
 * is dumped.
 */
public interface DumpableContainer {

    /**
     * Adds the given {@link Dumpable dumpable} to the container.
     *
     * <p>If a dumpable with the same {@link Dumpable#getDumpableName() name} was added before, this
     * call is ignored.
     *
     * @param dumpable dumpable to be added.
     *
     * @throws IllegalArgumentException if the {@link Dumpable#getDumpableName() dumpable name} is
     * {@code null}.
     *
     * @return {@code true} if the dumpable was added, {@code false} if the call was ignored.
     */
    boolean addDumpable(@NonNull Dumpable dumpable);
}
Loading