Address internal comments: Pointer icon refactor for mouse

Bug: 293587049
Test: atest inputflinger_tests
Change-Id: I9609e186ec92f283c25d2c9734ea2c3465445d5c
diff --git a/services/inputflinger/PointerChoreographer.cpp b/services/inputflinger/PointerChoreographer.cpp
index 4dfd05f..1092bdb 100644
--- a/services/inputflinger/PointerChoreographer.cpp
+++ b/services/inputflinger/PointerChoreographer.cpp
@@ -77,20 +77,17 @@
 
 NotifyMotionArgs PointerChoreographer::processMouseEventLocked(const NotifyMotionArgs& args) {
     if (args.getPointerCount() != 1) {
-        LOG(FATAL) << "Wrong number of pointers " << args.dump();
+        LOG(FATAL) << "Only mouse events with a single pointer are currently supported: "
+                   << args.dump();
     }
 
     const int32_t displayId = getTargetMouseDisplayLocked(args.displayId);
-    auto it = mMousePointersByDisplay.find(displayId);
-    if (it == mMousePointersByDisplay.end()) {
-        it = mMousePointersByDisplay
-                     .insert({displayId,
-                              mPolicy.createPointerController(
-                                      PointerControllerInterface::ControllerType::MOUSE)})
-                     .first;
-        if (const auto viewport = findViewportByIdLocked(displayId); viewport) {
-            it->second->setDisplayViewport(*viewport);
-        }
+
+    // Get the mouse pointer controller for the display, or create one if it doesn't exist.
+    auto [it, emplaced] =
+            mMousePointersByDisplay.try_emplace(displayId,
+                                                getMouseControllerConstructor(displayId));
+    if (emplaced) {
         notifyPointerDisplayIdChangedLocked();
     }
 
@@ -194,9 +191,10 @@
 
     // Remove PointerControllers no longer needed.
     // This has the side-effect of fading pointers or clearing spots before removal.
-    std::erase_if(mMousePointersByDisplay, [&mouseDisplaysToKeep](const auto& item) {
-        if (mouseDisplaysToKeep.find(item.first) == mouseDisplaysToKeep.end()) {
-            item.second->fade(PointerControllerInterface::Transition::IMMEDIATE);
+    std::erase_if(mMousePointersByDisplay, [&mouseDisplaysToKeep](const auto& pair) {
+        auto& [displayId, controller] = pair;
+        if (mouseDisplaysToKeep.find(displayId) == mouseDisplaysToKeep.end()) {
+            controller->fade(PointerControllerInterface::Transition::IMMEDIATE);
             return true;
         }
         return false;
@@ -211,8 +209,12 @@
     FloatPoint cursorPosition = {0, 0};
     if (const auto it = mMousePointersByDisplay.find(mDefaultMouseDisplayId);
         it != mMousePointersByDisplay.end()) {
-        displayIdToNotify = it->second->getDisplayId();
-        cursorPosition = it->second->getPosition();
+        const auto& pointerController = it->second;
+        // Use the displayId from the pointerController, because it accurately reflects whether
+        // the viewport has been added for that display. Otherwise, we would have to check if
+        // the viewport exists separately.
+        displayIdToNotify = pointerController->getDisplayId();
+        cursorPosition = pointerController->getPosition();
     }
 
     if (mNotifiedPointerDisplayId == displayIdToNotify) {
@@ -232,8 +234,7 @@
 void PointerChoreographer::setDisplayViewports(const std::vector<DisplayViewport>& viewports) {
     std::scoped_lock _l(mLock);
     for (const auto& viewport : viewports) {
-        int32_t displayId = viewport.displayId;
-        if (const auto it = mMousePointersByDisplay.find(displayId);
+        if (const auto it = mMousePointersByDisplay.find(viewport.displayId);
             it != mMousePointersByDisplay.end()) {
             it->second->setDisplayViewport(viewport);
         }
@@ -262,4 +263,18 @@
     return {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION};
 }
 
+PointerChoreographer::ControllerConstructor PointerChoreographer::getMouseControllerConstructor(
+        int32_t displayId) {
+    std::function<std::shared_ptr<PointerControllerInterface>()> ctor =
+            [this, displayId]() REQUIRES(mLock) {
+                auto pc = mPolicy.createPointerController(
+                        PointerControllerInterface::ControllerType::MOUSE);
+                if (const auto viewport = findViewportByIdLocked(displayId); viewport) {
+                    pc->setDisplayViewport(*viewport);
+                }
+                return pc;
+            };
+    return ConstructorDelegate(std::move(ctor));
+}
+
 } // namespace android
diff --git a/services/inputflinger/PointerChoreographer.h b/services/inputflinger/PointerChoreographer.h
index 4300d70..c1b900f 100644
--- a/services/inputflinger/PointerChoreographer.h
+++ b/services/inputflinger/PointerChoreographer.h
@@ -21,10 +21,25 @@
 #include "PointerChoreographerPolicyInterface.h"
 
 #include <android-base/thread_annotations.h>
+#include <type_traits>
 
 namespace android {
 
 /**
+ * A helper class that wraps a factory method that acts as a constructor for the type returned
+ * by the factory method.
+ */
+template <typename Factory>
+struct ConstructorDelegate {
+    constexpr ConstructorDelegate(Factory&& factory) : mFactory(std::move(factory)) {}
+
+    using ConstructedType = std::invoke_result_t<const Factory&>;
+    constexpr operator ConstructedType() const { return mFactory(); }
+
+    Factory mFactory;
+};
+
+/**
  * PointerChoreographer manages the icons shown by the system for input interactions.
  * This includes showing the mouse cursor, stylus hover icons, and touch spots.
  * It is responsible for accumulating the location of the mouse cursor, and populating
@@ -81,6 +96,10 @@
     NotifyMotionArgs processMouseEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock);
     NotifyMotionArgs processTouchscreenEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock);
 
+    using ControllerConstructor =
+            ConstructorDelegate<std::function<std::shared_ptr<PointerControllerInterface>()>>;
+    ControllerConstructor getMouseControllerConstructor(int32_t displayId) REQUIRES(mLock);
+
     std::mutex mLock;
 
     InputListenerInterface& mNextListener;
diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h
index e9737dd..efc8b26 100644
--- a/services/inputflinger/include/InputReaderBase.h
+++ b/services/inputflinger/include/InputReaderBase.h
@@ -452,11 +452,14 @@
     /* Returns true if any InputConnection is currently active. */
     virtual bool isInputMethodConnectionActive() = 0;
 
-    /* Gets the viewport of a particular display. The logical bounds of the viewport should be used
-     * as the range of possible values for pointing devices, like mice and touchpads.
+    /* Gets the viewport of a particular display that the pointer device is associated with. If
+     * the pointer device is not associated with any display, it should ADISPLAY_IS_NONE to get
+     * the viewport that should be used. The device should get a new viewport using this method
+     * every time there is a display configuration change. The logical bounds of the viewport should
+     * be used as the range of possible values for pointing devices, like mice and touchpads.
      */
-    virtual std::optional<DisplayViewport> getViewportForPointerDevice(
-            int32_t associatedDisplayId) = 0;
+    virtual std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
+            int32_t associatedDisplayId = ADISPLAY_ID_NONE) = 0;
 };
 
 } // namespace android
diff --git a/services/inputflinger/include/PointerChoreographerPolicyInterface.h b/services/inputflinger/include/PointerChoreographerPolicyInterface.h
index 93c0bdf..8b47b55 100644
--- a/services/inputflinger/include/PointerChoreographerPolicyInterface.h
+++ b/services/inputflinger/include/PointerChoreographerPolicyInterface.h
@@ -41,6 +41,12 @@
     virtual std::shared_ptr<PointerControllerInterface> createPointerController(
             PointerControllerInterface::ControllerType type) = 0;
 
+    /**
+     * Notifies the policy that the default pointer displayId has changed. PointerChoreographer is
+     * the single source of truth for all pointers on screen.
+     * @param displayId The updated display on which the mouse cursor is shown
+     * @param position The new position of the mouse cursor on the logical display
+     */
     virtual void notifyPointerDisplayIdChanged(int32_t displayId, const FloatPoint& position) = 0;
 };
 
diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
index 35cdba0..7aeb215 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
@@ -37,8 +37,6 @@
 // The default velocity control parameters that has no effect.
 static const VelocityControlParameters FLAT_VELOCITY_CONTROL_PARAMS{};
 
-static const DisplayViewport INVALID_VIEWPORT{};
-
 // --- CursorMotionAccumulator ---
 
 CursorMotionAccumulator::CursorMotionAccumulator() {
@@ -76,7 +74,8 @@
 CursorInputMapper::CursorInputMapper(InputDeviceContext& deviceContext,
                                      const InputReaderConfiguration& readerConfig)
       : InputMapper(deviceContext, readerConfig),
-        mLastEventTime(std::numeric_limits<nsecs_t>::min()) {}
+        mLastEventTime(std::numeric_limits<nsecs_t>::min()),
+        mEnablePointerChoreographer(input_flags::enable_pointer_choreographer()) {}
 
 CursorInputMapper::~CursorInputMapper() {
     if (mPointerController != nullptr) {
@@ -288,7 +287,7 @@
     float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
     float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
     if (mSource == AINPUT_SOURCE_MOUSE) {
-        if (!input_flags::enable_pointer_choreographer()) {
+        if (!mEnablePointerChoreographer) {
             if (moved || scrolled || buttonsChanged) {
                 mPointerController->setPresentation(
                         PointerControllerInterface::Presentation::POINTER);
@@ -507,14 +506,14 @@
     const bool isPointer = mParameters.mode == Parameters::Mode::POINTER;
 
     mDisplayId = ADISPLAY_ID_NONE;
-    DisplayViewport resolvedViewport = INVALID_VIEWPORT;
+    std::optional<DisplayViewport> resolvedViewport;
     bool isBoundsSet = false;
     if (auto assocViewport = mDeviceContext.getAssociatedViewport(); assocViewport) {
         // This InputDevice is associated with a viewport.
         // Only generate events for the associated display.
         mDisplayId = assocViewport->displayId;
         resolvedViewport = *assocViewport;
-        if (!input_flags::enable_pointer_choreographer()) {
+        if (!mEnablePointerChoreographer) {
             const bool mismatchedPointerDisplay =
                     isPointer && (assocViewport->displayId != mPointerController->getDisplayId());
             if (mismatchedPointerDisplay) {
@@ -525,13 +524,13 @@
         }
     } else if (isPointer) {
         // The InputDevice is not associated with a viewport, but it controls the mouse pointer.
-        if (input_flags::enable_pointer_choreographer()) {
+        if (mEnablePointerChoreographer) {
             // Always use DISPLAY_ID_NONE for mouse events.
             // PointerChoreographer will make it target the correct the displayId later.
             const auto pointerViewport =
-                    getContext()->getPolicy()->getViewportForPointerDevice(ADISPLAY_ID_NONE);
+                    getContext()->getPolicy()->getPointerViewportForAssociatedDisplay();
             mDisplayId = pointerViewport ? std::make_optional(ADISPLAY_ID_NONE) : std::nullopt;
-            resolvedViewport = pointerViewport.value_or(INVALID_VIEWPORT);
+            resolvedViewport = pointerViewport;
         } else {
             mDisplayId = mPointerController->getDisplayId();
             if (auto v = config.getDisplayViewportById(*mDisplayId); v) {
@@ -545,15 +544,17 @@
     }
 
     mOrientation = (mParameters.orientationAware && mParameters.hasAssociatedDisplay) ||
-                    mParameters.mode == Parameters::Mode::POINTER_RELATIVE
+                    mParameters.mode == Parameters::Mode::POINTER_RELATIVE || !resolvedViewport
             ? ui::ROTATION_0
-            : getInverseRotation(resolvedViewport.orientation);
+            : getInverseRotation(resolvedViewport->orientation);
 
     if (!isBoundsSet) {
-        mBoundsInLogicalDisplay = {static_cast<float>(resolvedViewport.logicalLeft),
-                                   static_cast<float>(resolvedViewport.logicalTop),
-                                   static_cast<float>(resolvedViewport.logicalRight - 1),
-                                   static_cast<float>(resolvedViewport.logicalBottom - 1)};
+        mBoundsInLogicalDisplay = resolvedViewport
+                ? FloatRect{static_cast<float>(resolvedViewport->logicalLeft),
+                            static_cast<float>(resolvedViewport->logicalTop),
+                            static_cast<float>(resolvedViewport->logicalRight - 1),
+                            static_cast<float>(resolvedViewport->logicalBottom - 1)}
+                : FloatRect{0, 0, 0, 0};
     }
 
     bumpGeneration();
diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h
index e6523a5..308adaa 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.h
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.h
@@ -128,6 +128,8 @@
     nsecs_t mDownTime;
     nsecs_t mLastEventTime;
 
+    const bool mEnablePointerChoreographer;
+
     explicit CursorInputMapper(InputDeviceContext& deviceContext,
                                const InputReaderConfiguration& readerConfig);
     void dumpParameters(std::string& dump);
diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.cpp b/services/inputflinger/tests/FakeInputReaderPolicy.cpp
index 305685d..88f514f 100644
--- a/services/inputflinger/tests/FakeInputReaderPolicy.cpp
+++ b/services/inputflinger/tests/FakeInputReaderPolicy.cpp
@@ -261,7 +261,7 @@
     mStylusGestureNotified = deviceId;
 }
 
-std::optional<DisplayViewport> FakeInputReaderPolicy::getViewportForPointerDevice(
+std::optional<DisplayViewport> FakeInputReaderPolicy::getPointerViewportForAssociatedDisplay(
         int32_t associatedDisplayId) {
     if (associatedDisplayId == ADISPLAY_ID_NONE) {
         associatedDisplayId = mConfig.defaultPointerDisplayId;
diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.h b/services/inputflinger/tests/FakeInputReaderPolicy.h
index 084aae1..4ef9c3e 100644
--- a/services/inputflinger/tests/FakeInputReaderPolicy.h
+++ b/services/inputflinger/tests/FakeInputReaderPolicy.h
@@ -79,7 +79,7 @@
     void setStylusPointerIconEnabled(bool enabled);
     void setIsInputMethodConnectionActive(bool active);
     bool isInputMethodConnectionActive() override;
-    std::optional<DisplayViewport> getViewportForPointerDevice(
+    std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
             int32_t associatedDisplayId) override;
 
 private:
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 53a55f8..5044b3e 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -4930,7 +4930,7 @@
     }
 };
 
-TEST_F(CursorInputMapperTestWithChoreographer, PopulateDeviceInfo_ReturnsRangeFromPolicy) {
+TEST_F(CursorInputMapperTestWithChoreographer, PopulateDeviceInfoReturnsRangeFromPolicy) {
     addConfigurationProperty("cursor.mode", "pointer");
     CursorInputMapper& mapper = constructAndAddMapper<CursorInputMapper>();
 
@@ -4961,7 +4961,7 @@
                                               AINPUT_SOURCE_MOUSE, 0.0f, 1.0f, 0.0f, 0.0f));
 }
 
-TEST_F(CursorInputMapperTestWithChoreographer, Process_ShouldHandleAllButtonsWithZeroCoords) {
+TEST_F(CursorInputMapperTestWithChoreographer, ProcessShouldHandleAllButtonsWithZeroCoords) {
     addConfigurationProperty("cursor.mode", "pointer");
     CursorInputMapper& mapper = constructAndAddMapper<CursorInputMapper>();
 
@@ -5218,7 +5218,7 @@
     ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
 }
 
-TEST_F(CursorInputMapperTestWithChoreographer, Process_WhenModeIsPointer_ShouldKeepZeroCoords) {
+TEST_F(CursorInputMapperTestWithChoreographer, ProcessWhenModeIsPointerShouldKeepZeroCoords) {
     addConfigurationProperty("cursor.mode", "pointer");
     CursorInputMapper& mapper = constructAndAddMapper<CursorInputMapper>();
 
@@ -5242,8 +5242,8 @@
 
 TEST_F(CursorInputMapperTestWithChoreographer, PointerCaptureDisablesVelocityProcessing) {
     addConfigurationProperty("cursor.mode", "pointer");
-    const VelocityControlParameters testParams(/*scale=*/5.f, /*low threshold=*/0.f,
-                                               /*high threshold=*/100.f, /*acceleration=*/10.f);
+    const VelocityControlParameters testParams(/*scale=*/5.f, /*lowThreshold=*/0.f,
+                                               /*highThreshold=*/100.f, /*acceleration=*/10.f);
     mFakePolicy->setVelocityControlParams(testParams);
     CursorInputMapper& mapper = constructAndAddMapper<CursorInputMapper>();
 
@@ -5289,7 +5289,7 @@
     ASSERT_EQ(20, relY2);
 }
 
-TEST_F(CursorInputMapperTestWithChoreographer, ConfigureDisplayId_NoAssociatedViewport) {
+TEST_F(CursorInputMapperTestWithChoreographer, ConfigureDisplayIdNoAssociatedViewport) {
     CursorInputMapper& mapper = constructAndAddMapper<CursorInputMapper>();
 
     // Set up the default display.
@@ -5315,7 +5315,7 @@
                   WithCoords(0.0f, 0.0f))));
 }
 
-TEST_F(CursorInputMapperTestWithChoreographer, ConfigureDisplayId_WithAssociatedViewport) {
+TEST_F(CursorInputMapperTestWithChoreographer, ConfigureDisplayIdWithAssociatedViewport) {
     CursorInputMapper& mapper = constructAndAddMapper<CursorInputMapper>();
 
     // Set up the default display.
@@ -5343,7 +5343,7 @@
 }
 
 TEST_F(CursorInputMapperTestWithChoreographer,
-       ConfigureDisplayId_ShouldGenerateEventWithMismatchedPointerDisplay) {
+       ConfigureDisplayIdShouldGenerateEventWithMismatchedPointerDisplay) {
     CursorInputMapper& mapper = constructAndAddMapper<CursorInputMapper>();
 
     // Set up the default display as the display on which the pointer should be shown.
diff --git a/services/inputflinger/tests/PointerChoreographer_test.cpp b/services/inputflinger/tests/PointerChoreographer_test.cpp
index 84673a6..4bce824 100644
--- a/services/inputflinger/tests/PointerChoreographer_test.cpp
+++ b/services/inputflinger/tests/PointerChoreographer_test.cpp
@@ -38,13 +38,17 @@
 constexpr int32_t DISPLAY_ID = 5;
 constexpr int32_t ANOTHER_DISPLAY_ID = 10;
 
+const auto MOUSE_POINTER = PointerBuilder(/*id=*/0, ToolType::MOUSE)
+                                   .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
+                                   .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20);
+
 static InputDeviceInfo generateTestDeviceInfo(int32_t deviceId, uint32_t source,
                                               int32_t associatedDisplayId) {
     InputDeviceIdentifier identifier;
 
     auto info = InputDeviceInfo();
-    info.initialize(deviceId, /*generation*/ 1, /*controllerNumber*/ 1, identifier, "alias",
-                    /*isExternal*/ false, /*hasMic*/ false, associatedDisplayId);
+    info.initialize(deviceId, /*generation=*/1, /*controllerNumber=*/1, identifier, "alias",
+                    /*isExternal=*/false, /*hasMic=*/false, associatedDisplayId);
     info.addSource(source);
     return info;
 }
@@ -161,21 +165,19 @@
     }
 }
 
-TEST_F(PointerChoreographerTest, WhenMouseIsJustAdded_DoesNotCreatePointerController) {
+TEST_F(PointerChoreographerTest, WhenMouseIsJustAddedDoesNotCreatePointerController) {
     mChoreographer.notifyInputDevicesChanged(
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     assertPointerControllerNotCreated();
     assertPointerControllerCount(size_t(0));
 }
 
-TEST_F(PointerChoreographerTest, WhenMouseEventOccurs_CreatesPointerController) {
+TEST_F(PointerChoreographerTest, WhenMouseEventOccursCreatesPointerController) {
     mChoreographer.notifyInputDevicesChanged(
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -183,14 +185,12 @@
     assertPointerControllerCount(size_t(1));
 }
 
-TEST_F(PointerChoreographerTest, WhenMouseIsRemoved_RemovesPointerController) {
+TEST_F(PointerChoreographerTest, WhenMouseIsRemovedRemovesPointerController) {
     mChoreographer.notifyInputDevicesChanged(
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -202,7 +202,7 @@
     assertPointerControllerCount(size_t(0));
 }
 
-TEST_F(PointerChoreographerTest, WhenKeyboardIsAdded_DoesNotCreatePointerController) {
+TEST_F(PointerChoreographerTest, WhenKeyboardIsAddedDoesNotCreatePointerController) {
     mChoreographer.notifyInputDevicesChanged(
             {/*id=*/0,
              {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE)}});
@@ -220,9 +220,7 @@
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, DISPLAY_ID)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(DISPLAY_ID)
                     .build());
@@ -231,16 +229,14 @@
     ASSERT_EQ(DISPLAY_ID, mPointerControllers.back().lock()->getDisplayId());
 }
 
-TEST_F(PointerChoreographerTest, WhenViewportSetLater_SetsViewportForAssociatedMouse) {
+TEST_F(PointerChoreographerTest, WhenViewportSetLaterSetsViewportForAssociatedMouse) {
     // Without viewport information, PointerController will be created by a mouse event
     // but viewport won't be set.
     mChoreographer.notifyInputDevicesChanged(
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, DISPLAY_ID)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(DISPLAY_ID)
                     .build());
@@ -263,9 +259,7 @@
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -275,7 +269,7 @@
 }
 
 TEST_F(PointerChoreographerTest,
-       WhenDefaultMouseDisplayChanges_SetsDefaultMouseViewportForPointerController) {
+       WhenDefaultMouseDisplayChangesSetsDefaultMouseViewportForPointerController) {
     // Set one display as a default mouse display and emit mouse event to create PointerController.
     mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID, ANOTHER_DISPLAY_ID}));
     mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID);
@@ -283,9 +277,7 @@
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -301,9 +293,7 @@
     // New PointerController for the new default display will be created by the motion event.
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -319,9 +309,7 @@
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -329,15 +317,13 @@
     assertPointerDisplayIdNotified(DISPLAY_ID);
 }
 
-TEST_F(PointerChoreographerTest, WhenViewportIsSetLater_CallsNotifyPointerDisplayIdChanged) {
+TEST_F(PointerChoreographerTest, WhenViewportIsSetLaterCallsNotifyPointerDisplayIdChanged) {
     mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID);
     mChoreographer.notifyInputDevicesChanged(
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -347,16 +333,14 @@
     assertPointerDisplayIdNotified(DISPLAY_ID);
 }
 
-TEST_F(PointerChoreographerTest, WhenMouseIsRemoved_CallsNotifyPointerDisplayIdChanged) {
+TEST_F(PointerChoreographerTest, WhenMouseIsRemovedCallsNotifyPointerDisplayIdChanged) {
     mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID);
     mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID}));
     mChoreographer.notifyInputDevicesChanged(
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -368,8 +352,7 @@
     assertPointerControllerCount(size_t(0));
 }
 
-TEST_F(PointerChoreographerTest,
-       WhenDefaultMouseDisplayChanges_CallsNotifyPointerDisplayIdChanged) {
+TEST_F(PointerChoreographerTest, WhenDefaultMouseDisplayChangesCallsNotifyPointerDisplayIdChanged) {
     // Add two viewports.
     mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID, ANOTHER_DISPLAY_ID}));
 
@@ -379,9 +362,7 @@
             {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}});
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
@@ -395,9 +376,7 @@
     // After a mouse event, pointer display ID will be notified with new default mouse display.
     mChoreographer.notifyMotion(
             MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE)
-                    .pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10)
-                                     .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20))
+                    .pointer(MOUSE_POINTER)
                     .deviceId(DEVICE_ID)
                     .displayId(ADISPLAY_ID_NONE)
                     .build());
diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h
index 6245a22..2f84497 100644
--- a/services/inputflinger/tests/fuzzers/MapperHelpers.h
+++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h
@@ -310,7 +310,7 @@
     void setTouchAffineTransformation(const TouchAffineTransformation t) { mTransform = t; }
     void notifyStylusGestureStarted(int32_t, nsecs_t) {}
     bool isInputMethodConnectionActive() override { return mFdp->ConsumeBool(); }
-    std::optional<DisplayViewport> getViewportForPointerDevice(
+    std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
             int32_t associatedDisplayId) override {
         return {};
     }