diff options
author | 2024-01-24 12:47:00 -0800 | |
---|---|---|
committer | 2024-02-01 12:36:56 -0800 | |
commit | b1b96db1eb56bd0df2bdf78d3922e10d65d08925 (patch) | |
tree | cf926df32ac232d15580f6a576f1e229df96c7ae | |
parent | 02c971640a149401a97960019a7236e6212ccf40 (diff) |
Support for InputDevice ViewBehavior
This change creates a struct within InputDeviceInfo to hold View related
behaviors of an input device. Currently, a single behavior is supported:
device.viewBehavior_smoothScroll. This can be specified in an IDC file
to hint clients of the InputDevice that they should animate scrolls for
motion events generated by the InputDevice.
Bug: 246946631
Test: add property in IDC, check API returns expected value
Test: atest frameworks/native/services/inputflinger/tests/InputReader_test.cpp
Change-Id: Ibe373cadc40d2a08116e787b744dd30812638edb
-rw-r--r-- | include/input/InputDevice.h | 18 | ||||
-rw-r--r-- | libs/input/InputDevice.cpp | 7 | ||||
-rw-r--r-- | libs/input/input_flags.aconfig | 7 | ||||
-rw-r--r-- | services/inputflinger/reader/InputDevice.cpp | 4 | ||||
-rw-r--r-- | services/inputflinger/reader/include/InputDevice.h | 1 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 25 |
6 files changed, 58 insertions, 4 deletions
diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h index b7751f704a..57b659d9ee 100644 --- a/include/input/InputDevice.h +++ b/include/input/InputDevice.h @@ -75,6 +75,17 @@ struct InputDeviceIdentifier { bool operator!=(const InputDeviceIdentifier&) const = default; }; +/** + * Holds View related behaviors for an InputDevice. + */ +struct InputDeviceViewBehavior { + /** + * The smooth scroll behavior that applies for all source/axis, if defined by the device. + * Empty optional if the device has not specified the default smooth scroll behavior. + */ + std::optional<bool> shouldSmoothScroll; +}; + /* Types of input device sensors. Keep sync with core/java/android/hardware/Sensor.java */ enum class InputDeviceSensorType : int32_t { ACCELEROMETER = ASENSOR_TYPE_ACCELEROMETER, @@ -266,7 +277,8 @@ public: void initialize(int32_t id, int32_t generation, int32_t controllerNumber, const InputDeviceIdentifier& identifier, const std::string& alias, - bool isExternal, bool hasMic, int32_t associatedDisplayId); + bool isExternal, bool hasMic, int32_t associatedDisplayId, + InputDeviceViewBehavior viewBehavior = {{}}); inline int32_t getId() const { return mId; } inline int32_t getControllerNumber() const { return mControllerNumber; } @@ -298,6 +310,8 @@ public: return mKeyboardLayoutInfo; } + inline const InputDeviceViewBehavior& getViewBehavior() const { return mViewBehavior; } + inline void setKeyCharacterMap(const std::shared_ptr<KeyCharacterMap> value) { mKeyCharacterMap = value; } @@ -359,6 +373,8 @@ private: std::unordered_map<int32_t, InputDeviceLightInfo> mLights; /* Map from battery ID to battery info */ std::unordered_map<int32_t, InputDeviceBatteryInfo> mBatteries; + /** The View related behaviors for the device. */ + InputDeviceViewBehavior mViewBehavior; }; /* Types of input device configuration files. */ diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp index 9c7c0c19ed..d4dbc45090 100644 --- a/libs/input/InputDevice.cpp +++ b/libs/input/InputDevice.cpp @@ -190,14 +190,16 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) mHasSensor(other.mHasSensor), mMotionRanges(other.mMotionRanges), mSensors(other.mSensors), - mLights(other.mLights) {} + mLights(other.mLights), + mViewBehavior(other.mViewBehavior) {} InputDeviceInfo::~InputDeviceInfo() { } void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t controllerNumber, const InputDeviceIdentifier& identifier, const std::string& alias, - bool isExternal, bool hasMic, int32_t associatedDisplayId) { + bool isExternal, bool hasMic, int32_t associatedDisplayId, + InputDeviceViewBehavior viewBehavior) { mId = id; mGeneration = generation; mControllerNumber = controllerNumber; @@ -212,6 +214,7 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control mHasBattery = false; mHasButtonUnderPad = false; mHasSensor = false; + mViewBehavior = viewBehavior; mUsiVersion.reset(); mMotionRanges.clear(); mSensors.clear(); diff --git a/libs/input/input_flags.aconfig b/libs/input/input_flags.aconfig index 174464d86f..ec7a2849ea 100644 --- a/libs/input/input_flags.aconfig +++ b/libs/input/input_flags.aconfig @@ -111,3 +111,10 @@ flag { description: "Move user-activity poke rate-limiting from PowerManagerService to InputDispatcher." bug: "320499729" } + +flag { + name: "input_device_view_behavior_api" + namespace: "input" + description: "Controls the API to provide InputDevice view behavior." + bug: "246946631" +} diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index a41064b361..f3f15df151 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -251,6 +251,7 @@ std::list<NotifyArgs> InputDevice::configureInternal(nsecs_t when, mAssociatedDeviceType = getValueByKey(readerConfig.deviceTypeAssociations, mIdentifier.location); mIsWaking = mConfiguration.getBool("device.wake").value_or(false); + mShouldSmoothScroll = mConfiguration.getBool("device.viewBehavior_smoothScroll"); } if (!changes.any() || changes.test(Change::DEVICE_ALIAS)) { @@ -401,7 +402,8 @@ std::list<NotifyArgs> InputDevice::updateExternalStylusState(const StylusState& InputDeviceInfo InputDevice::getDeviceInfo() { InputDeviceInfo outDeviceInfo; outDeviceInfo.initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal, - mHasMic, getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE)); + mHasMic, getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE), + {mShouldSmoothScroll}); for_each_mapper( [&outDeviceInfo](InputMapper& mapper) { mapper.populateDeviceInfo(outDeviceInfo); }); diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h index ba7234b3e1..0719b0ce3c 100644 --- a/services/inputflinger/reader/include/InputDevice.h +++ b/services/inputflinger/reader/include/InputDevice.h @@ -199,6 +199,7 @@ private: std::optional<DisplayViewport> mAssociatedViewport; bool mHasMic; bool mDropUntilNextSync; + std::optional<bool> mShouldSmoothScroll; typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code); int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 460a7b185d..c1dc7ffcfb 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -2706,6 +2706,31 @@ TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRe ASSERT_NO_FATAL_FAILURE(mapper2.assertProcessWasCalled()); } +TEST_F(InputDeviceTest, Configure_SmoothScrollViewBehaviorNotSet) { + // Set some behavior to force the configuration to be update. + mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, "device.wake", "1"); + mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(), + AINPUT_SOURCE_KEYBOARD); + + std::list<NotifyArgs> unused = + mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), + /*changes=*/{}); + + ASSERT_FALSE(mDevice->getDeviceInfo().getViewBehavior().shouldSmoothScroll.has_value()); +} + +TEST_F(InputDeviceTest, Configure_SmoothScrollViewBehaviorEnabled) { + mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, "device.viewBehavior_smoothScroll", "1"); + mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(), + AINPUT_SOURCE_KEYBOARD); + + std::list<NotifyArgs> unused = + mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), + /*changes=*/{}); + + ASSERT_TRUE(mDevice->getDeviceInfo().getViewBehavior().shouldSmoothScroll.value_or(false)); +} + TEST_F(InputDeviceTest, WakeDevice_AddsWakeFlagToProcessNotifyArgs) { mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, "device.wake", "1"); FakeInputMapper& mapper = |