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

Commit 002f60d7 authored by Michael Wright's avatar Michael Wright
Browse files

Use IndentingPrintWriter instead of manually prefixing dumpsys.

Bug: 254277939
Test: manually inspect `dumpsys input`
Change-Id: I1b93aebcf3a51dcec50b0c6fbd5375c432ff7201
parent 4e72b984
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -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();
        }
    }

+28 −23
Original line number Diff line number Diff line
@@ -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);
            }
        }
    }
+7 −4
Original line number Diff line number Diff line
@@ -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();
    }
}