diff options
| author | Felipe Leme <felipeal@google.com> | 2021-10-01 13:25:53 -0700 |
|---|---|---|
| committer | Felipe Leme <felipeal@google.com> | 2022-01-13 11:43:13 -0800 |
| commit | bcafba3a1f9294aba2cb4b10e15e72ea00fcbe46 (patch) | |
| tree | a7a6018f5a35e94f07dcb39e08c4d6552bdbae9c /core/java/android/util | |
| parent | 9ee529d8e033be8610f0ea541112b3d46e772eb6 (diff) | |
Creates a generic mechanism to dump app-side information.
Currently, 'dumpsys activity' can dump the state of some managers:
- AutofillManager
- ContentCapturemaanger
- UiTranslationController
But the support for these custom dumping is hardcoded into
Activity itself, which makes it harder to extend. For example,
automotive builds provide an app-side Car object, which currently
cannot be dumped.
This CL makes the mechanism more flexible by providing a couple new
public / SystemAPIs that let Automotive (or other mainline modules)
extend it.
Examples:
$ adb shell dumpsys activity com.android.car.carlauncher/.CarLauncher --list-dumpables
$ adb shell dumpsys activity com.android.car.carlauncher/.CarLauncher --dump-dumpable CarUserManager
$ adb shell dumpsys activity service com.android.systemui/.SystemUIService CarUserManager
NOTE: this CL only adds the new APIs; a follow-up CL will change the
existing managers to use them.
Test: see above
Test: m update-api
Bug: 149254050
CTS-Coverage-Bug: 149254050
Change-Id: I6920ff3542d3d75edd667c2c7658e9d0a7af534f
Diffstat (limited to 'core/java/android/util')
| -rw-r--r-- | core/java/android/util/Dumpable.java | 47 | ||||
| -rw-r--r-- | core/java/android/util/DumpableContainer.java | 40 |
2 files changed, 87 insertions, 0 deletions
diff --git a/core/java/android/util/Dumpable.java b/core/java/android/util/Dumpable.java new file mode 100644 index 000000000000..79c576d08866 --- /dev/null +++ b/core/java/android/util/Dumpable.java @@ -0,0 +1,47 @@ +/* + * 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); +} diff --git a/core/java/android/util/DumpableContainer.java b/core/java/android/util/DumpableContainer.java new file mode 100644 index 000000000000..04d19dc41926 --- /dev/null +++ b/core/java/android/util/DumpableContainer.java @@ -0,0 +1,40 @@ +/* + * 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); +} |
