From 002f60d74594dd1a3ba22a73dc99c18157345755 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 1 Nov 2022 14:01:14 +0000 Subject: [PATCH] Use IndentingPrintWriter instead of manually prefixing dumpsys. Bug: 254277939 Test: manually inspect `dumpsys input` Change-Id: I1b93aebcf3a51dcec50b0c6fbd5375c432ff7201 --- .../server/input/BatteryController.java | 25 +++++---- .../server/input/InputManagerService.java | 51 ++++++++++--------- .../input/KeyboardBacklightController.java | 11 ++-- 3 files changed, 50 insertions(+), 37 deletions(-) diff --git a/services/core/java/com/android/server/input/BatteryController.java b/services/core/java/com/android/server/input/BatteryController.java index 9d4f181135554..c83fa2d3942c4 100644 --- a/services/core/java/com/android/server/input/BatteryController.java +++ b/services/core/java/com/android/server/input/BatteryController.java @@ -32,6 +32,7 @@ import android.os.SystemClock; import android.os.UEventObserver; import android.util.ArrayMap; import android.util.ArraySet; +import android.util.IndentingPrintWriter; import android.util.Log; import android.util.Slog; import android.view.InputDevice; @@ -382,24 +383,28 @@ final class BatteryController { } } - public void dump(PrintWriter pw, String prefix) { + public void dump(PrintWriter pw) { + IndentingPrintWriter ipw = new IndentingPrintWriter(pw); synchronized (mLock) { - final String indent = prefix + " "; - final String indent2 = indent + " "; - - pw.println(prefix + TAG + ":"); - pw.println(indent + "State: Polling = " + mIsPolling + ipw.println(TAG + ":"); + ipw.increaseIndent(); + ipw.println("State: Polling = " + mIsPolling + ", Interactive = " + mIsInteractive); - pw.println(indent + "Listeners: " + mListenerRecords.size() + " battery listeners"); + ipw.println("Listeners: " + mListenerRecords.size() + " battery listeners"); + ipw.increaseIndent(); for (int i = 0; i < mListenerRecords.size(); i++) { - pw.println(indent2 + i + ": " + mListenerRecords.valueAt(i)); + ipw.println(i + ": " + mListenerRecords.valueAt(i)); } + ipw.decreaseIndent(); - pw.println(indent + "Device Monitors: " + mDeviceMonitors.size() + " monitors"); + ipw.println("Device Monitors: " + mDeviceMonitors.size() + " monitors"); + ipw.increaseIndent(); for (int i = 0; i < mDeviceMonitors.size(); i++) { - pw.println(indent2 + i + ": " + mDeviceMonitors.valueAt(i)); + ipw.println(i + ": " + mDeviceMonitors.valueAt(i)); } + ipw.decreaseIndent(); + ipw.decreaseIndent(); } } diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index d2282c3ee072e..c973cb8488803 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -91,6 +91,7 @@ import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import android.text.TextUtils; import android.util.ArrayMap; +import android.util.IndentingPrintWriter; import android.util.Log; import android.util.Slog; import android.util.SparseArray; @@ -2689,74 +2690,78 @@ public class InputManagerService extends IInputManager.Stub @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; + IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); - pw.println("INPUT MANAGER (dumpsys input)\n"); + ipw.println("INPUT MANAGER (dumpsys input)\n"); String dumpStr = mNative.dump(); if (dumpStr != null) { pw.println(dumpStr); } - pw.println("Input Manager Service (Java) State:"); - dumpAssociations(pw, " " /*prefix*/); - dumpSpyWindowGestureMonitors(pw, " " /*prefix*/); - dumpDisplayInputPropertiesValues(pw, " " /*prefix*/); - mBatteryController.dump(pw, " " /*prefix*/); - mKeyboardBacklightController.dump(pw, " " /*prefix*/); + ipw.println("Input Manager Service (Java) State:"); + ipw.increaseIndent(); + dumpAssociations(ipw); + dumpSpyWindowGestureMonitors(ipw); + dumpDisplayInputPropertiesValues(ipw); + mBatteryController.dump(ipw); + mKeyboardBacklightController.dump(ipw); } - private void dumpAssociations(PrintWriter pw, String prefix) { + private void dumpAssociations(IndentingPrintWriter pw) { if (!mStaticAssociations.isEmpty()) { - pw.println(prefix + "Static Associations:"); + pw.println("Static Associations:"); mStaticAssociations.forEach((k, v) -> { - pw.print(prefix + " port: " + k); + pw.print(" port: " + k); pw.println(" display: " + v); }); } synchronized (mAssociationsLock) { if (!mRuntimeAssociations.isEmpty()) { - pw.println(prefix + "Runtime Associations:"); + pw.println("Runtime Associations:"); mRuntimeAssociations.forEach((k, v) -> { - pw.print(prefix + " port: " + k); + pw.print(" port: " + k); pw.println(" display: " + v); }); } if (!mUniqueIdAssociations.isEmpty()) { - pw.println(prefix + "Unique Id Associations:"); + pw.println("Unique Id Associations:"); mUniqueIdAssociations.forEach((k, v) -> { - pw.print(prefix + " port: " + k); + pw.print(" port: " + k); pw.println(" uniqueId: " + v); }); } } } - private void dumpSpyWindowGestureMonitors(PrintWriter pw, String prefix) { + private void dumpSpyWindowGestureMonitors(IndentingPrintWriter pw) { synchronized (mInputMonitors) { if (mInputMonitors.isEmpty()) return; - pw.println(prefix + "Gesture Monitors (implemented as spy windows):"); + pw.println("Gesture Monitors (implemented as spy windows):"); int i = 0; for (final GestureMonitorSpyWindow monitor : mInputMonitors.values()) { - pw.append(prefix + " " + i++ + ": ").println(monitor.dump()); + pw.append(" " + i++ + ": ").println(monitor.dump()); } } } - private void dumpDisplayInputPropertiesValues(PrintWriter pw, String prefix) { + private void dumpDisplayInputPropertiesValues(IndentingPrintWriter pw) { synchronized (mAdditionalDisplayInputPropertiesLock) { if (mAdditionalDisplayInputProperties.size() != 0) { - pw.println(prefix + "mAdditionalDisplayInputProperties:"); + pw.println("mAdditionalDisplayInputProperties:"); + pw.increaseIndent(); for (int i = 0; i < mAdditionalDisplayInputProperties.size(); i++) { - pw.println(prefix + " displayId: " + pw.println("displayId: " + mAdditionalDisplayInputProperties.keyAt(i)); final AdditionalDisplayInputProperties properties = mAdditionalDisplayInputProperties.valueAt(i); - pw.println(prefix + " pointerAcceleration: " + properties.pointerAcceleration); - pw.println(prefix + " pointerIconVisible: " + properties.pointerIconVisible); + pw.println("pointerAcceleration: " + properties.pointerAcceleration); + pw.println("pointerIconVisible: " + properties.pointerIconVisible); } + pw.decreaseIndent(); } if (mOverriddenPointerDisplayId != Display.INVALID_DISPLAY) { - pw.println(prefix + "mOverriddenPointerDisplayId: " + mOverriddenPointerDisplayId); + pw.println("mOverriddenPointerDisplayId: " + mOverriddenPointerDisplayId); } } } diff --git a/services/core/java/com/android/server/input/KeyboardBacklightController.java b/services/core/java/com/android/server/input/KeyboardBacklightController.java index e33f28c229987..b207e27b4005e 100644 --- a/services/core/java/com/android/server/input/KeyboardBacklightController.java +++ b/services/core/java/com/android/server/input/KeyboardBacklightController.java @@ -24,6 +24,7 @@ import android.hardware.lights.Light; import android.os.Handler; import android.os.Looper; import android.os.Message; +import android.util.IndentingPrintWriter; import android.util.Log; import android.util.Slog; import android.util.SparseArray; @@ -216,12 +217,14 @@ final class KeyboardBacklightController implements InputManager.InputDeviceListe return null; } - void dump(PrintWriter pw, String prefix) { - pw.println(prefix + TAG + ": " + mKeyboardBacklights.size() + " keyboard backlights"); + void dump(PrintWriter pw) { + IndentingPrintWriter ipw = new IndentingPrintWriter(pw); + ipw.println(TAG + ": " + mKeyboardBacklights.size() + " keyboard backlights"); + ipw.increaseIndent(); for (int i = 0; i < mKeyboardBacklights.size(); i++) { Light light = mKeyboardBacklights.get(i); - pw.println(prefix + " " + i + ": { id: " + light.getId() + ", name: " + light.getName() - + " }"); + ipw.println(i + ": { id: " + light.getId() + ", name: " + light.getName() + " }"); } + ipw.decreaseIndent(); } }