Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cce96562 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge "Do not show pointer for disabled device" into main

parents 900ee7c0 48f80dae
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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; }
@@ -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;
@@ -361,6 +364,7 @@ private:
    std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;
    std::optional<InputDeviceUsiVersion> mUsiVersion;
    int32_t mAssociatedDisplayId;
    bool mEnabled;

    bool mHasVibrator;
    bool mHasBattery;
+3 −1
Original line number Diff line number Diff line
@@ -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),
@@ -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;
@@ -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;
+5 −0
Original line number Diff line number Diff line
@@ -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;

+1 −1
Original line number Diff line number Diff line
@@ -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); });
+70 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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());
@@ -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);