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

Commit 584def72 authored by Biswarup Pal's avatar Biswarup Pal Committed by Android (Google) Code Review
Browse files

Merge "Update dependent properties when deviceType is updated" into main

parents 6d171884 9ce4d9ff
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -977,8 +977,9 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded)
        viewportChanged = mViewport != newViewport;
    }

    const bool deviceModeChanged = mDeviceMode != oldDeviceMode;
    bool skipViewportUpdate = false;
    if (viewportChanged) {
    if (viewportChanged || deviceModeChanged) {
        const bool viewportOrientationChanged = mViewport.orientation != newViewport.orientation;
        const bool viewportDisplayIdChanged = mViewport.displayId != newViewport.displayId;
        mViewport = newViewport;
@@ -1020,7 +1021,6 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded)
    }

    // If moving between pointer modes, need to reset some state.
    bool deviceModeChanged = mDeviceMode != oldDeviceMode;
    if (deviceModeChanged) {
        mOrientedRanges.clear();
    }
+81 −34
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ namespace android {

using namespace ftl::flag_operators;
using testing::AllOf;
using testing::VariantWith;
using std::chrono_literals::operator""ms;
using std::chrono_literals::operator""s;

@@ -4487,15 +4488,15 @@ protected:
    void prepareButtons();
    void prepareAxes(int axes);

    void processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y);
    void processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y);
    void processUp(SingleTouchInputMapper& mappery);
    void processPressure(SingleTouchInputMapper& mapper, int32_t pressure);
    void processToolMajor(SingleTouchInputMapper& mapper, int32_t toolMajor);
    void processDistance(SingleTouchInputMapper& mapper, int32_t distance);
    void processTilt(SingleTouchInputMapper& mapper, int32_t tiltX, int32_t tiltY);
    void processKey(SingleTouchInputMapper& mapper, int32_t code, int32_t value);
    void processSync(SingleTouchInputMapper& mapper);
    std::list<NotifyArgs> processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y);
    std::list<NotifyArgs> processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y);
    std::list<NotifyArgs> processUp(SingleTouchInputMapper& mappery);
    std::list<NotifyArgs> processPressure(SingleTouchInputMapper& mapper, int32_t pressure);
    std::list<NotifyArgs> processToolMajor(SingleTouchInputMapper& mapper, int32_t toolMajor);
    std::list<NotifyArgs> processDistance(SingleTouchInputMapper& mapper, int32_t distance);
    std::list<NotifyArgs> processTilt(SingleTouchInputMapper& mapper, int32_t tiltX, int32_t tiltY);
    std::list<NotifyArgs> processKey(SingleTouchInputMapper& mapper, int32_t code, int32_t value);
    std::list<NotifyArgs> processSync(SingleTouchInputMapper& mapper);
};

void SingleTouchInputMapperTest::prepareButtons() {
@@ -4525,47 +4526,57 @@ void SingleTouchInputMapperTest::prepareAxes(int axes) {
    }
}

void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 1);
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
std::list<NotifyArgs> SingleTouchInputMapperTest::processDown(SingleTouchInputMapper& mapper,
                                                              int32_t x, int32_t y) {
    std::list<NotifyArgs> args;
    args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 1);
    args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
    args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
    return args;
}

void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
std::list<NotifyArgs> SingleTouchInputMapperTest::processMove(SingleTouchInputMapper& mapper,
                                                              int32_t x, int32_t y) {
    std::list<NotifyArgs> args;
    args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
    args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
    return args;
}

void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper& mapper) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 0);
std::list<NotifyArgs> SingleTouchInputMapperTest::processUp(SingleTouchInputMapper& mapper) {
    return process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 0);
}

void SingleTouchInputMapperTest::processPressure(SingleTouchInputMapper& mapper, int32_t pressure) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_PRESSURE, pressure);
std::list<NotifyArgs> SingleTouchInputMapperTest::processPressure(SingleTouchInputMapper& mapper,
                                                                  int32_t pressure) {
    return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_PRESSURE, pressure);
}

void SingleTouchInputMapperTest::processToolMajor(SingleTouchInputMapper& mapper,
std::list<NotifyArgs> SingleTouchInputMapperTest::processToolMajor(SingleTouchInputMapper& mapper,
                                                                   int32_t toolMajor) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TOOL_WIDTH, toolMajor);
    return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TOOL_WIDTH, toolMajor);
}

void SingleTouchInputMapperTest::processDistance(SingleTouchInputMapper& mapper, int32_t distance) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_DISTANCE, distance);
std::list<NotifyArgs> SingleTouchInputMapperTest::processDistance(SingleTouchInputMapper& mapper,
                                                                  int32_t distance) {
    return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_DISTANCE, distance);
}

void SingleTouchInputMapperTest::processTilt(SingleTouchInputMapper& mapper, int32_t tiltX,
                                             int32_t tiltY) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_X, tiltX);
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_Y, tiltY);
std::list<NotifyArgs> SingleTouchInputMapperTest::processTilt(SingleTouchInputMapper& mapper,
                                                              int32_t tiltX, int32_t tiltY) {
    std::list<NotifyArgs> args;
    args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_X, tiltX);
    args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_Y, tiltY);
    return args;
}

void SingleTouchInputMapperTest::processKey(SingleTouchInputMapper& mapper, int32_t code,
                                            int32_t value) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, code, value);
std::list<NotifyArgs> SingleTouchInputMapperTest::processKey(SingleTouchInputMapper& mapper,
                                                             int32_t code, int32_t value) {
    return process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, code, value);
}

void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper& mapper) {
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
std::list<NotifyArgs> SingleTouchInputMapperTest::processSync(SingleTouchInputMapper& mapper) {
    return process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
}

TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) {
@@ -4656,6 +4667,42 @@ TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) {
    ASSERT_FALSE(flags[1]);
}

TEST_F(SingleTouchInputMapperTest, DeviceTypeChange_RecalculatesRawToDisplayTransform) {
    prepareDisplay(ui::ROTATION_0);
    prepareAxes(POSITION);
    addConfigurationProperty("touch.deviceType", "touchScreen");
    SingleTouchInputMapper& mapper = constructAndAddMapper<SingleTouchInputMapper>();

    const int32_t x = 900;
    const int32_t y = 75;
    std::list<NotifyArgs> args;
    args += processDown(mapper, x, y);
    args += processSync(mapper);

    // Assert that motion event is received in display coordinate space for deviceType touchScreen.
    ASSERT_THAT(args,
                ElementsAre(VariantWith<NotifyMotionArgs>(
                        AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
                              WithCoords(toDisplayX(x), toDisplayY(y))))));

    // Add device type association after the device was created.
    mFakePolicy->addDeviceTypeAssociation(DEVICE_LOCATION, "touchNavigation");
    // Send update to the mapper.
    std::list<NotifyArgs> unused =
            mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
                               InputReaderConfiguration::Change::DEVICE_TYPE /*changes*/);

    args.clear();
    args += processDown(mapper, x, y);
    args += processSync(mapper);

    // Assert that motion event is received in raw coordinate space for deviceType touchNavigation.
    ASSERT_THAT(args,
                ElementsAre(VariantWith<NotifyMotionArgs>(
                        AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
                              WithCoords(x - RAW_X_MIN, y - RAW_Y_MIN)))));
}

TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) {
    addConfigurationProperty("touch.deviceType", "touchScreen");
    prepareDisplay(ui::ROTATION_0);