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

Commit f7c4dc87 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow debug InputManagerGlobal logs to be dynamic" into main

parents 4c51d153 2c5fb358
Loading
Loading
Loading
Loading
+16 −10
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.SomeArgs;
import com.android.internal.os.SomeArgs;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.Executor;
@@ -76,8 +77,9 @@ import java.util.concurrent.Executor;
public final class InputManagerGlobal {
public final class InputManagerGlobal {
    private static final String TAG = "InputManagerGlobal";
    private static final String TAG = "InputManagerGlobal";
    // To enable these logs, run: 'adb shell setprop log.tag.InputManagerGlobal DEBUG'
    // To enable these logs, run: 'adb shell setprop log.tag.InputManagerGlobal DEBUG'
    // (requires restart)
    private boolean debug() {
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
        return Log.isLoggable(TAG, Log.DEBUG);
    }


    @GuardedBy("mInputDeviceListeners")
    @GuardedBy("mInputDeviceListeners")
    @Nullable private SparseArray<InputDevice> mInputDevices;
    @Nullable private SparseArray<InputDevice> mInputDevices;
@@ -269,16 +271,19 @@ public final class InputManagerGlobal {
    }
    }


    private void onInputDevicesChanged(int[] deviceIdAndGeneration) {
    private void onInputDevicesChanged(int[] deviceIdAndGeneration) {
        if (DEBUG) {
        final boolean enableDebugLogs = debug();
            Log.d(TAG, "Received input devices changed.");
        if (enableDebugLogs) {
            Log.d(TAG, "Received input devices changed: " + Arrays.toString(deviceIdAndGeneration));
        }
        }


        synchronized (mInputDeviceListeners) {
        synchronized (mInputDeviceListeners) {
            for (int i = mInputDevices.size(); --i > 0; ) {
            for (int i = mInputDevices.size(); --i > 0; ) {
                final int deviceId = mInputDevices.keyAt(i);
                final int deviceId = mInputDevices.keyAt(i);
                if (!containsDeviceId(deviceIdAndGeneration, deviceId)) {
                if (!containsDeviceId(deviceIdAndGeneration, deviceId)) {
                    if (DEBUG) {
                    if (enableDebugLogs) {
                        Log.d(TAG, "Device removed: " + deviceId);
                        final InputDevice device = mInputDevices.valueAt(i);
                        final String name = device != null ? device.getName() : "<null>";
                        Log.d(TAG, "Device removed: " + deviceId + " (" + name + ")");
                    }
                    }
                    mInputDevices.removeAt(i);
                    mInputDevices.removeAt(i);
                    if (mInputDeviceSensorManager != null) {
                    if (mInputDeviceSensorManager != null) {
@@ -297,8 +302,9 @@ public final class InputManagerGlobal {
                    if (device != null) {
                    if (device != null) {
                        final int generation = deviceIdAndGeneration[i + 1];
                        final int generation = deviceIdAndGeneration[i + 1];
                        if (device.getGeneration() != generation) {
                        if (device.getGeneration() != generation) {
                            if (DEBUG) {
                            if (enableDebugLogs) {
                                Log.d(TAG, "Device changed: " + deviceId);
                                Log.d(TAG, "Device changed: " + deviceId + " ("
                                        + device.getName() + ")");
                            }
                            }
                            mInputDevices.setValueAt(index, null);
                            mInputDevices.setValueAt(index, null);
                            if (mInputDeviceSensorManager != null) {
                            if (mInputDeviceSensorManager != null) {
@@ -309,7 +315,7 @@ public final class InputManagerGlobal {
                        }
                        }
                    }
                    }
                } else {
                } else {
                    if (DEBUG) {
                    if (enableDebugLogs) {
                        Log.d(TAG, "Device added: " + deviceId);
                        Log.d(TAG, "Device added: " + deviceId);
                    }
                    }
                    mInputDevices.put(deviceId, null);
                    mInputDevices.put(deviceId, null);
@@ -517,7 +523,7 @@ public final class InputManagerGlobal {
    }
    }


    private void onTabletModeChanged(long whenNanos, boolean inTabletMode) {
    private void onTabletModeChanged(long whenNanos, boolean inTabletMode) {
        if (DEBUG) {
        if (debug()) {
            Log.d(TAG, "Received tablet mode changed: "
            Log.d(TAG, "Received tablet mode changed: "
                    + "whenNanos=" + whenNanos + ", inTabletMode=" + inTabletMode);
                    + "whenNanos=" + whenNanos + ", inTabletMode=" + inTabletMode);
        }
        }