Populate RELATIVE_X and RELATIVE_Y motion range for touchpad pointer capture mode.

When input device is set to touchpad pointer capture mode, Populate
device info with motion range of RELATIVE_X and RELATIVE_Y axes.

Bug: 117859192
Test: atest inputflinger_tests

Change-Id: Ic963d0e718c669bd26dd7c83fba814fa29905fa6
Merged-In: Ic963d0e718c669bd26dd7c83fba814fa29905fa6
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index 2770c14..394c9e4 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -190,6 +190,19 @@
         info->addMotionRange(mOrientedRanges.y);
         info->addMotionRange(mOrientedRanges.pressure);
 
+        if (mDeviceMode == DeviceMode::UNSCALED && mSource == AINPUT_SOURCE_TOUCHPAD) {
+            // Populate RELATIVE_X and RELATIVE_Y motion range for touchpad capture mode
+            // RELATIVE_X and RELATIVE_Y motion range is the largest possible hardware relative
+            // motion, e.g. the hardware size finger moved completely across the touchpad in one
+            // sample cycle.
+            const InputDeviceInfo::MotionRange& x = mOrientedRanges.x;
+            const InputDeviceInfo::MotionRange& y = mOrientedRanges.y;
+            info->addMotionRange(AMOTION_EVENT_AXIS_RELATIVE_X, mSource, -x.max, x.max, x.flat,
+                                 x.fuzz, x.resolution);
+            info->addMotionRange(AMOTION_EVENT_AXIS_RELATIVE_Y, mSource, -y.max, y.max, y.flat,
+                                 y.fuzz, y.resolution);
+        }
+
         if (mOrientedRanges.haveSize) {
             info->addMotionRange(mOrientedRanges.size);
         }