Updates to SlopController

- Addressed comments in ag/23670464
- Moved the creation of the controller from the rotary input mapper
  constructor, to its `populateDeviceInfo`, since the slop params were
  not being read in the constructor (since the device property map is
  not initialized when the input mapper is created).
- Added logs to note the slop params

Bug: 285957835
Test: atest SlopControllerTest

Change-Id: Id1bd77b52c9d93d30d3d2594662e19ccc40a1bb6
diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
index 5220b10..7251830 100644
--- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
@@ -20,6 +20,7 @@
 
 #include "RotaryEncoderInputMapper.h"
 
+#include <utils/Timers.h>
 #include <optional>
 
 #include "CursorScrollAccumulator.h"
@@ -30,14 +31,6 @@
                                                    const InputReaderConfiguration& readerConfig)
       : InputMapper(deviceContext, readerConfig), mOrientation(ui::ROTATION_0) {
     mSource = AINPUT_SOURCE_ROTARY_ENCODER;
-
-    const PropertyMap& config = getDeviceContext().getConfiguration();
-    float slopThreshold = config.getInt("rotary_encoder.slop_threshold").value_or(0);
-    int32_t slopDurationMs = config.getInt("rotary_encoder.slop_duration_ms").value_or(0);
-    if (slopThreshold > 0 && slopDurationMs > 0) {
-        mSlopController = std::make_unique<SlopController>(slopThreshold,
-                                                           (nsecs_t)(slopDurationMs * 1000000));
-    }
 }
 
 RotaryEncoderInputMapper::~RotaryEncoderInputMapper() {}
@@ -70,6 +63,7 @@
     dump += INDENT2 "Rotary Encoder Input Mapper:\n";
     dump += StringPrintf(INDENT3 "HaveWheel: %s\n",
                          toString(mRotaryEncoderScrollAccumulator.haveRelativeVWheel()));
+    dump += StringPrintf(INDENT3 "HaveSlopController: %s\n", toString(mSlopController != nullptr));
 }
 
 std::list<NotifyArgs> RotaryEncoderInputMapper::reconfigure(nsecs_t when,
@@ -78,6 +72,16 @@
     std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes);
     if (!changes.any()) {
         mRotaryEncoderScrollAccumulator.configure(getDeviceContext());
+
+        const PropertyMap& propertyMap = getDeviceContext().getConfiguration();
+        float slopThreshold = propertyMap.getInt("rotary_encoder.slop_threshold").value_or(0);
+        int32_t slopDurationNs = milliseconds_to_nanoseconds(
+                propertyMap.getInt("rotary_encoder.slop_duration_ms").value_or(0));
+        if (slopThreshold > 0 && slopDurationNs > 0) {
+            mSlopController = std::make_unique<SlopController>(slopThreshold, slopDurationNs);
+        } else {
+            mSlopController = nullptr;
+        }
     }
     if (!changes.any() || changes.test(InputReaderConfiguration::Change::DISPLAY_INFO)) {
         std::optional<DisplayViewport> internalViewport =
diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h
index 4732bcd..fe5d152 100644
--- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h
+++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h
@@ -47,7 +47,7 @@
     int32_t mSource;
     float mScalingFactor;
     ui::Rotation mOrientation;
-    std::unique_ptr<SlopController> mSlopController = nullptr;
+    std::unique_ptr<SlopController> mSlopController;
 
     explicit RotaryEncoderInputMapper(InputDeviceContext& deviceContext,
                                       const InputReaderConfiguration& readerConfig);
diff --git a/services/inputflinger/reader/mapper/SlopController.cpp b/services/inputflinger/reader/mapper/SlopController.cpp
index 6f31d0e..f79219f 100644
--- a/services/inputflinger/reader/mapper/SlopController.cpp
+++ b/services/inputflinger/reader/mapper/SlopController.cpp
@@ -33,8 +33,6 @@
 SlopController::SlopController(float slopThreshold, nsecs_t slopDurationNanos)
       : mSlopThreshold(slopThreshold), mSlopDurationNanos(slopDurationNanos) {}
 
-SlopController::~SlopController() {}
-
 float SlopController::consumeEvent(nsecs_t eventTimeNanos, float value) {
     if (mSlopDurationNanos == 0) {
         return value;
@@ -64,7 +62,7 @@
     return 0;
 }
 
-bool SlopController::shouldResetSlopTracking(nsecs_t eventTimeNanos, float value) {
+bool SlopController::shouldResetSlopTracking(nsecs_t eventTimeNanos, float value) const {
     const nsecs_t ageNanos = eventTimeNanos - mLastEventTimeNanos;
     if (ageNanos >= mSlopDurationNanos) {
         return true;
diff --git a/services/inputflinger/reader/mapper/SlopController.h b/services/inputflinger/reader/mapper/SlopController.h
index bd6ee77..c106410 100644
--- a/services/inputflinger/reader/mapper/SlopController.h
+++ b/services/inputflinger/reader/mapper/SlopController.h
@@ -28,10 +28,9 @@
  * Current slop logic:
  *      "If time since last event > Xns, then discard the next N values."
  */
-class SlopController {
+class SlopController final {
 public:
     SlopController(float slopThreshold, nsecs_t slopDurationNanos);
-    virtual ~SlopController();
 
     /**
      * Consumes an event with a given time and value for slop processing.
@@ -40,7 +39,7 @@
     float consumeEvent(nsecs_t eventTime, float value);
 
 private:
-    bool shouldResetSlopTracking(nsecs_t eventTimeNanos, float value);
+    bool shouldResetSlopTracking(nsecs_t eventTimeNanos, float value) const;
 
     /** The amount of event values ignored after an inactivity of the slop duration. */
     const float mSlopThreshold;