Improves dump() to handle special cases.
When "dumpsys activity" is called with special arguments (like --list-dumpables), dump() should be handled by Activity itself, not the subclasses, otherwise the end result would be spammed. This CL fixes that behavior, but only for apps targeting T (so it maintains backward compatibility for apps that are explicitly checking for the special values). Bug: 149254050 Test: m update-api Test: manual verification with 'adb dumpsys activity ...' Test: atest CtsAppTestCases:android.app.cts.ActivityDumpTest Test: adb shell dumpsys platform_compat|grep DUMP_IGNORES_SPECIAL_ARGS||echo NOT_FOUND Change-Id: I918c9a6649cb66f9e2b6509a643005fac110d152
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -7079,7 +7093,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 <activity_component_name></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.
|
||||
@@ -7106,11 +7131,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":
|
||||
@@ -7145,6 +7179,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)));
|
||||
|
||||
@@ -4693,7 +4693,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 {
|
||||
|
||||
Reference in New Issue
Block a user