Loading include/input/InputDevice.h +5 −1 Original line number Diff line number Diff line Loading @@ -278,7 +278,7 @@ 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, InputDeviceViewBehavior viewBehavior = {{}}); InputDeviceViewBehavior viewBehavior = {{}}, bool enabled = true); inline int32_t getId() const { return mId; } inline int32_t getControllerNumber() const { return mControllerNumber; } Loading Loading @@ -347,6 +347,9 @@ public: inline int32_t getAssociatedDisplayId() const { return mAssociatedDisplayId; } inline void setEnabled(bool enabled) { mEnabled = enabled; } inline bool isEnabled() const { return mEnabled; } private: int32_t mId; int32_t mGeneration; Loading @@ -361,6 +364,7 @@ private: std::shared_ptr<KeyCharacterMap> mKeyCharacterMap; std::optional<InputDeviceUsiVersion> mUsiVersion; int32_t mAssociatedDisplayId; bool mEnabled; bool mHasVibrator; bool mHasBattery; Loading libs/input/InputDevice.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -187,6 +187,7 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) mKeyCharacterMap(other.mKeyCharacterMap), mUsiVersion(other.mUsiVersion), mAssociatedDisplayId(other.mAssociatedDisplayId), mEnabled(other.mEnabled), mHasVibrator(other.mHasVibrator), mHasBattery(other.mHasBattery), mHasButtonUnderPad(other.mHasButtonUnderPad), Loading @@ -202,7 +203,7 @@ 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, InputDeviceViewBehavior viewBehavior) { InputDeviceViewBehavior viewBehavior, bool enabled) { mId = id; mGeneration = generation; mControllerNumber = controllerNumber; Loading @@ -213,6 +214,7 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control mSources = 0; mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE; mAssociatedDisplayId = associatedDisplayId; mEnabled = enabled; mHasVibrator = false; mHasBattery = false; mHasButtonUnderPad = false; Loading services/inputflinger/PointerChoreographer.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -434,6 +434,11 @@ PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerCo // Mark the displayIds or deviceIds of PointerControllers currently needed, and create // new PointerControllers if necessary. for (const auto& info : mInputDeviceInfos) { if (!info.isEnabled()) { // If device is disabled, we should not keep it, and should not show pointer for // disabled mouse device. continue; } const uint32_t sources = info.getSources(); const bool isKnownMouse = mMouseDevices.count(info.getId()) != 0; Loading services/inputflinger/reader/InputDevice.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -409,7 +409,7 @@ InputDeviceInfo InputDevice::getDeviceInfo() { InputDeviceInfo outDeviceInfo; outDeviceInfo.initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal, mHasMic, getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE), {mShouldSmoothScroll}); {mShouldSmoothScroll}, isEnabled()); for_each_mapper( [&outDeviceInfo](InputMapper& mapper) { mapper.populateDeviceInfo(outDeviceInfo); }); Loading services/inputflinger/tests/PointerChoreographer_test.cpp +70 −1 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ Visitor(V...) -> Visitor<V...>; constexpr int32_t DEVICE_ID = 3; constexpr int32_t SECOND_DEVICE_ID = DEVICE_ID + 1; constexpr int32_t THIRD_DEVICE_ID = SECOND_DEVICE_ID + 1; constexpr int32_t DISPLAY_ID = 5; constexpr int32_t ANOTHER_DISPLAY_ID = 10; constexpr int32_t DISPLAY_WIDTH = 480; Loading Loading @@ -537,7 +538,8 @@ TEST_F(PointerChoreographerTest, UnrelatedChangeDoesNotUnfadePointer) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE), generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, DISPLAY_ID)}}); ASSERT_FALSE(pc->isPointerShown()); Loading @@ -548,6 +550,73 @@ TEST_F(PointerChoreographerTest, UnrelatedChangeDoesNotUnfadePointer) { ASSERT_FALSE(pc->isPointerShown()); } TEST_F(PointerChoreographerTest, DisabledMouseConnected) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo mouseDeviceInfo = generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); // Disable this mouse device. mouseDeviceInfo.setEnabled(false); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); // Disabled mouse device should not create PointerController assertPointerControllerNotCreated(); } TEST_F(PointerChoreographerTest, MouseDeviceDisableLater) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo mouseDeviceInfo = generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); auto pc = assertPointerControllerCreated(PointerControllerInterface::ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); // Now we disable this mouse device mouseDeviceInfo.setEnabled(false); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); // Because the mouse device disabled, the PointerController should be removed. assertPointerControllerRemoved(pc); } TEST_F(PointerChoreographerTest, MultipleEnabledAndDisabledMiceConnectionAndRemoval) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo disabledMouseDeviceInfo = generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); disabledMouseDeviceInfo.setEnabled(false); InputDeviceInfo enabledMouseDeviceInfo = generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); InputDeviceInfo anotherEnabledMouseDeviceInfo = generateTestDeviceInfo(THIRD_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {disabledMouseDeviceInfo, enabledMouseDeviceInfo, anotherEnabledMouseDeviceInfo}}); // Mouse should show, because we have two enabled mice device. auto pc = assertPointerControllerCreated(PointerControllerInterface::ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); // Now we remove one of enabled mice device. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {disabledMouseDeviceInfo, enabledMouseDeviceInfo}}); // Because we still have an enabled mouse device, pointer should still show. ASSERT_TRUE(pc->isPointerShown()); // We finally remove last enabled mouse device. mChoreographer.notifyInputDevicesChanged({/*id=*/0, {disabledMouseDeviceInfo}}); // The PointerController should be removed, because there is no enabled mouse device. assertPointerControllerRemoved(pc); } TEST_F(PointerChoreographerTest, WhenShowTouchesEnabledAndDisabledDoesNotCreatePointerController) { // Disable show touches and add a touch device. mChoreographer.setShowTouchesEnabled(false); Loading Loading
include/input/InputDevice.h +5 −1 Original line number Diff line number Diff line Loading @@ -278,7 +278,7 @@ 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, InputDeviceViewBehavior viewBehavior = {{}}); InputDeviceViewBehavior viewBehavior = {{}}, bool enabled = true); inline int32_t getId() const { return mId; } inline int32_t getControllerNumber() const { return mControllerNumber; } Loading Loading @@ -347,6 +347,9 @@ public: inline int32_t getAssociatedDisplayId() const { return mAssociatedDisplayId; } inline void setEnabled(bool enabled) { mEnabled = enabled; } inline bool isEnabled() const { return mEnabled; } private: int32_t mId; int32_t mGeneration; Loading @@ -361,6 +364,7 @@ private: std::shared_ptr<KeyCharacterMap> mKeyCharacterMap; std::optional<InputDeviceUsiVersion> mUsiVersion; int32_t mAssociatedDisplayId; bool mEnabled; bool mHasVibrator; bool mHasBattery; Loading
libs/input/InputDevice.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -187,6 +187,7 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) mKeyCharacterMap(other.mKeyCharacterMap), mUsiVersion(other.mUsiVersion), mAssociatedDisplayId(other.mAssociatedDisplayId), mEnabled(other.mEnabled), mHasVibrator(other.mHasVibrator), mHasBattery(other.mHasBattery), mHasButtonUnderPad(other.mHasButtonUnderPad), Loading @@ -202,7 +203,7 @@ 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, InputDeviceViewBehavior viewBehavior) { InputDeviceViewBehavior viewBehavior, bool enabled) { mId = id; mGeneration = generation; mControllerNumber = controllerNumber; Loading @@ -213,6 +214,7 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control mSources = 0; mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE; mAssociatedDisplayId = associatedDisplayId; mEnabled = enabled; mHasVibrator = false; mHasBattery = false; mHasButtonUnderPad = false; Loading
services/inputflinger/PointerChoreographer.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -434,6 +434,11 @@ PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerCo // Mark the displayIds or deviceIds of PointerControllers currently needed, and create // new PointerControllers if necessary. for (const auto& info : mInputDeviceInfos) { if (!info.isEnabled()) { // If device is disabled, we should not keep it, and should not show pointer for // disabled mouse device. continue; } const uint32_t sources = info.getSources(); const bool isKnownMouse = mMouseDevices.count(info.getId()) != 0; Loading
services/inputflinger/reader/InputDevice.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -409,7 +409,7 @@ InputDeviceInfo InputDevice::getDeviceInfo() { InputDeviceInfo outDeviceInfo; outDeviceInfo.initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal, mHasMic, getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE), {mShouldSmoothScroll}); {mShouldSmoothScroll}, isEnabled()); for_each_mapper( [&outDeviceInfo](InputMapper& mapper) { mapper.populateDeviceInfo(outDeviceInfo); }); Loading
services/inputflinger/tests/PointerChoreographer_test.cpp +70 −1 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ Visitor(V...) -> Visitor<V...>; constexpr int32_t DEVICE_ID = 3; constexpr int32_t SECOND_DEVICE_ID = DEVICE_ID + 1; constexpr int32_t THIRD_DEVICE_ID = SECOND_DEVICE_ID + 1; constexpr int32_t DISPLAY_ID = 5; constexpr int32_t ANOTHER_DISPLAY_ID = 10; constexpr int32_t DISPLAY_WIDTH = 480; Loading Loading @@ -537,7 +538,8 @@ TEST_F(PointerChoreographerTest, UnrelatedChangeDoesNotUnfadePointer) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE), generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, DISPLAY_ID)}}); ASSERT_FALSE(pc->isPointerShown()); Loading @@ -548,6 +550,73 @@ TEST_F(PointerChoreographerTest, UnrelatedChangeDoesNotUnfadePointer) { ASSERT_FALSE(pc->isPointerShown()); } TEST_F(PointerChoreographerTest, DisabledMouseConnected) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo mouseDeviceInfo = generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); // Disable this mouse device. mouseDeviceInfo.setEnabled(false); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); // Disabled mouse device should not create PointerController assertPointerControllerNotCreated(); } TEST_F(PointerChoreographerTest, MouseDeviceDisableLater) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo mouseDeviceInfo = generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); auto pc = assertPointerControllerCreated(PointerControllerInterface::ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); // Now we disable this mouse device mouseDeviceInfo.setEnabled(false); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); // Because the mouse device disabled, the PointerController should be removed. assertPointerControllerRemoved(pc); } TEST_F(PointerChoreographerTest, MultipleEnabledAndDisabledMiceConnectionAndRemoval) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo disabledMouseDeviceInfo = generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); disabledMouseDeviceInfo.setEnabled(false); InputDeviceInfo enabledMouseDeviceInfo = generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); InputDeviceInfo anotherEnabledMouseDeviceInfo = generateTestDeviceInfo(THIRD_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {disabledMouseDeviceInfo, enabledMouseDeviceInfo, anotherEnabledMouseDeviceInfo}}); // Mouse should show, because we have two enabled mice device. auto pc = assertPointerControllerCreated(PointerControllerInterface::ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); // Now we remove one of enabled mice device. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {disabledMouseDeviceInfo, enabledMouseDeviceInfo}}); // Because we still have an enabled mouse device, pointer should still show. ASSERT_TRUE(pc->isPointerShown()); // We finally remove last enabled mouse device. mChoreographer.notifyInputDevicesChanged({/*id=*/0, {disabledMouseDeviceInfo}}); // The PointerController should be removed, because there is no enabled mouse device. assertPointerControllerRemoved(pc); } TEST_F(PointerChoreographerTest, WhenShowTouchesEnabledAndDisabledDoesNotCreatePointerController) { // Disable show touches and add a touch device. mChoreographer.setShowTouchesEnabled(false); Loading