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

Commit e9858f7d authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

VirtualDeviceManager: Cleanup after PointerChoreogpraher refactor

Bug: 311416205
Test: build, presubmit
Change-Id: I7b2bc9feecedf26d5c2d89bce77962e3658bd471
parent 0affab46
Loading
Loading
Loading
Loading
+0 −64
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import android.os.RemoteException;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
import android.view.Display;
import android.view.InputDevice;
import android.view.WindowManager;

@@ -169,7 +168,6 @@ class InputController {
        createDeviceInternal(InputDeviceDescriptor.TYPE_MOUSE, deviceName, vendorId, productId,
                deviceToken, displayId, phys,
                () -> mNativeWrapper.openUinputMouse(deviceName, vendorId, productId, phys));
        setVirtualMousePointerDisplayId(displayId);
    }

    void createTouchscreen(@NonNull String deviceName, int vendorId, int productId,
@@ -236,15 +234,6 @@ class InputController {
        if (inputDeviceDescriptor.getType() == InputDeviceDescriptor.TYPE_KEYBOARD) {
            mInputManagerInternal.removeKeyboardLayoutAssociation(phys);
        }

        // Reset values to the default if all virtual mice are unregistered, or set display
        // id if there's another mouse (choose the most recent). The inputDeviceDescriptor must be
        // removed from the mInputDeviceDescriptors instance variable prior to this point.
        if (inputDeviceDescriptor.isMouse()) {
            if (getVirtualMousePointerDisplayId() == inputDeviceDescriptor.getDisplayId()) {
                updateActivePointerDisplayIdLocked();
            }
        }
    }

    /**
@@ -276,29 +265,6 @@ class InputController {
        mWindowManager.setDisplayImePolicy(displayId, policy);
    }

    // TODO(b/293587049): Remove after pointer icon refactor is complete.
    @GuardedBy("mLock")
    private void updateActivePointerDisplayIdLocked() {
        InputDeviceDescriptor mostRecentlyCreatedMouse = null;
        for (int i = 0; i < mInputDeviceDescriptors.size(); ++i) {
            InputDeviceDescriptor otherInputDeviceDescriptor = mInputDeviceDescriptors.valueAt(i);
            if (otherInputDeviceDescriptor.isMouse()) {
                if (mostRecentlyCreatedMouse == null
                        || (otherInputDeviceDescriptor.getCreationOrderNumber()
                        > mostRecentlyCreatedMouse.getCreationOrderNumber())) {
                    mostRecentlyCreatedMouse = otherInputDeviceDescriptor;
                }
            }
        }
        if (mostRecentlyCreatedMouse != null) {
            setVirtualMousePointerDisplayId(
                    mostRecentlyCreatedMouse.getDisplayId());
        } else {
            // All mice have been unregistered
            setVirtualMousePointerDisplayId(Display.INVALID_DISPLAY);
        }
    }

    /**
     * Validates a device name by checking whether a device with the same name already exists.
     * @param deviceName The name of the device to be validated
@@ -355,9 +321,6 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeButtonEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getButtonCode(), event.getAction(), event.getEventTimeNanos());
        }
@@ -384,9 +347,6 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeRelativeEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getRelativeX(), event.getRelativeY(), event.getEventTimeNanos());
        }
@@ -399,9 +359,6 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeScrollEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getXAxisMovement(), event.getYAxisMovement(), event.getEventTimeNanos());
        }
@@ -415,9 +372,6 @@ class InputController {
                throw new IllegalArgumentException(
                        "Could not get cursor position for input device for given token");
            }
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return LocalServices.getService(InputManagerInternal.class).getCursorPosition(
                    inputDeviceDescriptor.getDisplayId());
        }
@@ -878,22 +832,4 @@ class InputController {
        /** Returns true if the calling thread is a valid thread for device creation. */
        boolean isValidThread();
    }

    // TODO(b/293587049): Remove after pointer icon refactor is complete.
    private void setVirtualMousePointerDisplayId(int displayId) {
        if (com.android.input.flags.Flags.enablePointerChoreographer()) {
            // We no longer need to set the pointer display when pointer choreographer is enabled.
            return;
        }
        mInputManagerInternal.setVirtualMousePointerDisplayId(displayId);
    }

    // TODO(b/293587049): Remove after pointer icon refactor is complete.
    private int getVirtualMousePointerDisplayId() {
        if (com.android.input.flags.Flags.enablePointerChoreographer()) {
            // We no longer need to get the pointer display when pointer choreographer is enabled.
            return Display.INVALID_DISPLAY;
        }
        return mInputManagerInternal.getVirtualMousePointerDisplayId();
    }
}
+0 −23
Original line number Diff line number Diff line
@@ -83,29 +83,6 @@ public abstract class InputManagerInternal {
    public abstract boolean transferTouchGesture(@NonNull IBinder fromChannelToken,
            @NonNull IBinder toChannelToken);

    /**
     * Sets the display id that the MouseCursorController will be forced to target. Pass
     * {@link android.view.Display#INVALID_DISPLAY} to clear the override.
     *
     * Note: This method generally blocks until the pointer display override has propagated.
     * When setting a new override, the caller should ensure that an input device that can control
     * the mouse pointer is connected. If a new override is set when no such input device is
     * connected, the caller may be blocked for an arbitrary period of time.
     *
     * @return true if the pointer displayId was set successfully, or false if it fails.
     *
     * @deprecated TODO(b/293587049): Not needed - remove after Pointer Icon Refactor is complete.
     */
    public abstract boolean setVirtualMousePointerDisplayId(int pointerDisplayId);

    /**
     * Gets the display id that the MouseCursorController is being forced to target. Returns
     * {@link android.view.Display#INVALID_DISPLAY} if there is no override
     *
     * @deprecated TODO(b/293587049): Not needed - remove after Pointer Icon Refactor is complete.
     */
    public abstract int getVirtualMousePointerDisplayId();

    /**
     * Gets the current position of the mouse cursor.
     *
+0 −10
Original line number Diff line number Diff line
@@ -3137,16 +3137,6 @@ public class InputManagerService extends IInputManager.Stub
            return InputManagerService.this.transferTouchGesture(fromChannelToken, toChannelToken);
        }

        @Override
        public boolean setVirtualMousePointerDisplayId(int pointerDisplayId) {
            return false;
        }

        @Override
        public int getVirtualMousePointerDisplayId() {
            return Display.INVALID_DISPLAY;
        }

        @Override
        public PointF getCursorPosition(int displayId) {
            final float[] p = mNative.getMouseCursorPosition(displayId);
+0 −8
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.SetFlagsRule;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.DisplayInfo;
@@ -41,13 +40,11 @@ import android.view.WindowManager;

import androidx.test.InstrumentationRegistry;

import com.android.input.flags.Flags;
import com.android.server.LocalServices;
import com.android.server.input.InputManagerInternal;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -60,9 +57,6 @@ public class InputControllerTest {
    private static final String LANGUAGE_TAG = "en-US";
    private static final String LAYOUT_TYPE = "qwerty";

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Mock
    private InputManagerInternal mInputManagerInternalMock;
    @Mock
@@ -77,8 +71,6 @@ public class InputControllerTest {

    @Before
    public void setUp() throws Exception {
        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_POINTER_CHOREOGRAPHER);

        MockitoAnnotations.initMocks(this);
        mInputManagerMockHelper = new InputManagerMockHelper(
                TestableLooper.get(this), mNativeWrapperMock, mIInputManagerMock);
+0 −2
Original line number Diff line number Diff line
@@ -339,8 +339,6 @@ public class VirtualDeviceManagerServiceTest {
        LocalServices.removeServiceForTest(DisplayManagerInternal.class);
        LocalServices.addService(DisplayManagerInternal.class, mDisplayManagerInternalMock);

        mSetFlagsRule.enableFlags(com.android.input.flags.Flags.FLAG_ENABLE_POINTER_CHOREOGRAPHER);

        doNothing().when(mInputManagerInternalMock)
                .setMousePointerAccelerationEnabled(anyBoolean(), anyInt());
        doNothing().when(mInputManagerInternalMock).setPointerIconVisible(anyBoolean(), anyInt());