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

Commit 5737f20f authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Pointer Icon Refactor: Remove get/setVirtualMousePointerDisplayId

The API is no longer needed when the refactoring is enabled, since the
creation of the associated mouse will automatically create a mouse
pointer for the display.

Bug: 311651709
Test: atest InputControllerTest
Test: atest VirtualDeviceManagerServiceTest
Change-Id: Ic5fedd6fb5951f213ea8158e33db05025e2adb7e
parent bdf93698
Loading
Loading
Loading
Loading
+31 −21
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ class InputController {
        createDeviceInternal(InputDeviceDescriptor.TYPE_MOUSE, deviceName, vendorId, productId,
                deviceToken, displayId, phys,
                () -> mNativeWrapper.openUinputMouse(deviceName, vendorId, productId, phys));
        mInputManagerInternal.setVirtualMousePointerDisplayId(displayId);
        setVirtualMousePointerDisplayId(displayId);
    }

    void createTouchscreen(@NonNull String deviceName, int vendorId, int productId,
@@ -235,8 +235,7 @@ class InputController {
        // 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 (mInputManagerInternal.getVirtualMousePointerDisplayId()
                    == inputDeviceDescriptor.getDisplayId()) {
            if (getVirtualMousePointerDisplayId() == inputDeviceDescriptor.getDisplayId()) {
                updateActivePointerDisplayIdLocked();
            }
        }
@@ -271,6 +270,7 @@ class InputController {
        mWindowManager.setDisplayImePolicy(displayId, policy);
    }

    // TODO(b/293587049): Remove after pointer icon refactor is complete.
    @GuardedBy("mLock")
    private void updateActivePointerDisplayIdLocked() {
        InputDeviceDescriptor mostRecentlyCreatedMouse = null;
@@ -285,11 +285,11 @@ class InputController {
            }
        }
        if (mostRecentlyCreatedMouse != null) {
            mInputManagerInternal.setVirtualMousePointerDisplayId(
            setVirtualMousePointerDisplayId(
                    mostRecentlyCreatedMouse.getDisplayId());
        } else {
            // All mice have been unregistered
            mInputManagerInternal.setVirtualMousePointerDisplayId(Display.INVALID_DISPLAY);
            setVirtualMousePointerDisplayId(Display.INVALID_DISPLAY);
        }
    }

@@ -349,10 +349,8 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeButtonEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getButtonCode(), event.getAction(), event.getEventTimeNanos());
@@ -380,10 +378,8 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeRelativeEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getRelativeX(), event.getRelativeY(), event.getEventTimeNanos());
@@ -397,10 +393,8 @@ class InputController {
            if (inputDeviceDescriptor == null) {
                return false;
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return mNativeWrapper.writeScrollEvent(inputDeviceDescriptor.getNativePointer(),
                    event.getXAxisMovement(), event.getYAxisMovement(), event.getEventTimeNanos());
@@ -415,10 +409,8 @@ class InputController {
                throw new IllegalArgumentException(
                        "Could not get cursor position for input device for given token");
            }
            if (inputDeviceDescriptor.getDisplayId()
                    != mInputManagerInternal.getVirtualMousePointerDisplayId()) {
                mInputManagerInternal.setVirtualMousePointerDisplayId(
                        inputDeviceDescriptor.getDisplayId());
            if (inputDeviceDescriptor.getDisplayId() != getVirtualMousePointerDisplayId()) {
                setVirtualMousePointerDisplayId(inputDeviceDescriptor.getDisplayId());
            }
            return LocalServices.getService(InputManagerInternal.class).getCursorPosition();
        }
@@ -847,4 +839,22 @@ 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();
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -87,12 +87,16 @@ public abstract class InputManagerInternal {
     * 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();

+8 −0
Original line number Diff line number Diff line
@@ -1449,6 +1449,10 @@ public class InputManagerService extends IInputManager.Stub
    }

    private boolean setVirtualMousePointerDisplayIdBlocking(int overrideDisplayId) {
        if (com.android.input.flags.Flags.enablePointerChoreographer()) {
            throw new IllegalStateException(
                    "This must not be used when PointerChoreographer is enabled");
        }
        final boolean isRemovingOverride = overrideDisplayId == Display.INVALID_DISPLAY;

        // Take care to not make calls to window manager while holding internal locks.
@@ -1487,6 +1491,10 @@ public class InputManagerService extends IInputManager.Stub
    }

    private int getVirtualMousePointerDisplayId() {
        if (com.android.input.flags.Flags.enablePointerChoreographer()) {
            throw new IllegalStateException(
                    "This must not be used when PointerChoreographer is enabled");
        }
        synchronized (mAdditionalDisplayInputPropertiesLock) {
            return mOverriddenPointerDisplayId;
        }
+8 −9
Original line number Diff line number Diff line
@@ -33,19 +33,21 @@ 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.Display;
import android.view.DisplayInfo;
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;
@@ -58,6 +60,9 @@ 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
@@ -72,11 +77,12 @@ 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);

        doReturn(true).when(mInputManagerInternalMock).setVirtualMousePointerDisplayId(anyInt());
        LocalServices.removeServiceForTest(InputManagerInternal.class);
        LocalServices.addService(InputManagerInternal.class, mInputManagerInternalMock);

@@ -129,11 +135,7 @@ public class InputControllerTest {
        mInputController.createMouse("name", /*vendorId= */ 1, /*productId= */ 1, deviceToken,
                /* displayId= */ 1);
        verify(mNativeWrapperMock).openUinputMouse(eq("name"), eq(1), eq(1), anyString());
        verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(eq(1));
        doReturn(1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId();
        mInputController.unregisterInputDevice(deviceToken);
        verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(
                eq(Display.INVALID_DISPLAY));
    }

    @Test
@@ -143,14 +145,11 @@ public class InputControllerTest {
        mInputController.createMouse("mouse1", /*vendorId= */ 1, /*productId= */ 1, deviceToken,
                /* displayId= */ 1);
        verify(mNativeWrapperMock).openUinputMouse(eq("mouse1"), eq(1), eq(1), anyString());
        verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(eq(1));
        final IBinder deviceToken2 = new Binder();
        mInputController.createMouse("mouse2", /*vendorId= */ 1, /*productId= */ 1, deviceToken2,
                /* displayId= */ 2);
        verify(mNativeWrapperMock).openUinputMouse(eq("mouse2"), eq(1), eq(1), anyString());
        verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(eq(2));
        mInputController.unregisterInputDevice(deviceToken);
        verify(mInputManagerInternalMock).setVirtualMousePointerDisplayId(eq(1));
    }

    @Test
+1 −4
Original line number Diff line number Diff line
@@ -339,8 +339,8 @@ public class VirtualDeviceManagerServiceTest {
        LocalServices.addService(DisplayManagerInternal.class, mDisplayManagerInternalMock);

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

        doReturn(true).when(mInputManagerInternalMock).setVirtualMousePointerDisplayId(anyInt());
        doNothing().when(mInputManagerInternalMock)
                .setMousePointerAccelerationEnabled(anyBoolean(), anyInt());
        doNothing().when(mInputManagerInternalMock).setPointerIconVisible(anyBoolean(), anyInt());
@@ -1333,7 +1333,6 @@ public class VirtualDeviceManagerServiceTest {
        mInputController.addDeviceForTesting(BINDER, fd,
                InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS,
                DEVICE_NAME_1, INPUT_DEVICE_ID);
        doReturn(DISPLAY_ID_1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId();
        assertThat(mDeviceImpl.sendButtonEvent(BINDER,
                new VirtualMouseButtonEvent.Builder()
                        .setButtonCode(buttonCode)
@@ -1363,7 +1362,6 @@ public class VirtualDeviceManagerServiceTest {
        mInputController.addDeviceForTesting(BINDER, fd,
                InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1,
                INPUT_DEVICE_ID);
        doReturn(DISPLAY_ID_1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId();
        assertThat(mDeviceImpl.sendRelativeEvent(BINDER,
                new VirtualMouseRelativeEvent.Builder()
                        .setRelativeX(x)
@@ -1394,7 +1392,6 @@ public class VirtualDeviceManagerServiceTest {
        mInputController.addDeviceForTesting(BINDER, fd,
                InputController.InputDeviceDescriptor.TYPE_MOUSE, DISPLAY_ID_1, PHYS, DEVICE_NAME_1,
                INPUT_DEVICE_ID);
        doReturn(DISPLAY_ID_1).when(mInputManagerInternalMock).getVirtualMousePointerDisplayId();
        assertThat(mDeviceImpl.sendScrollEvent(BINDER,
                new VirtualMouseScrollEvent.Builder()
                        .setXAxisMovement(x)
Loading