Skip to content

Commit e7ffef7

Browse files
committed
Move external MultiTouch test into InputMapperUnitTest
This test is broken because it relies on an incorrect ACTION_CANCEL event being generated. Move this test over to the new InputMapperUnitTest infra before fixing it in subsequent CLs. Bug: 378308551 Test: TEST=inputflinger_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST Flag: TEST_ONLY Change-Id: I016fb66f7fcbe957cd5b6e8ca86513cb8c372cd3
1 parent 0797826 commit e7ffef7

11 files changed

Lines changed: 109 additions & 61 deletions

include/input/PrintTools.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919
#include <bitset>
2020
#include <map>
2121
#include <optional>
22-
#include <set>
22+
#include <ranges>
2323
#include <sstream>
2424
#include <string>
2525
#include <vector>
2626

2727
namespace android {
2828

29+
namespace internal {
30+
template <typename T>
31+
concept Container = std::ranges::range<T>;
32+
}
33+
2934
template <size_t N>
3035
std::string bitsetToString(const std::bitset<N>& bitset) {
3136
if (bitset.none()) {
@@ -72,10 +77,12 @@ inline std::string toString(const std::optional<T>& optional,
7277
/**
7378
* Convert a set of integral types to string.
7479
*/
75-
template <typename T>
76-
std::string dumpSet(const std::set<T>& v, std::string (*toString)(const T&) = constToString) {
80+
template <internal::Container T>
81+
std::string dumpContainer(
82+
const T& container,
83+
std::string (*toString)(const std::ranges::range_value_t<T>&) = constToString) {
7784
std::string out;
78-
for (const T& entry : v) {
85+
for (const auto& entry : container) {
7986
out += out.empty() ? "{" : ", ";
8087
out += toString(entry);
8188
}

libs/input/InputConsumerNoResampling.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define ATRACE_TAG ATRACE_TAG_INPUT
1919

2020
#include <inttypes.h>
21+
#include <set>
2122

2223
#include <android-base/logging.h>
2324
#include <android-base/properties.h>

services/inputflinger/NotifyArgs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,9 @@ const char* toString(const NotifyArgs& args) {
206206
return std::visit(toStringVisitor, args);
207207
}
208208

209+
std::ostream& operator<<(std::ostream& out, const NotifyArgs& args) {
210+
out << toString(args);
211+
return out;
212+
}
213+
209214
} // namespace android

services/inputflinger/PreferStylusOverTouchBlocker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ static std::string dumpArgs(const NotifyMotionArgs& args) {
216216

217217
std::string PreferStylusOverTouchBlocker::dump() const {
218218
std::string out;
219-
out += "mActiveStyli: " + dumpSet(mActiveStyli) + "\n";
219+
out += "mActiveStyli: " + dumpContainer(mActiveStyli) + "\n";
220220
out += "mLastTouchEvents: " + dumpMap(mLastTouchEvents, constToString, dumpArgs) + "\n";
221-
out += "mDevicesWithMixedToolType: " + dumpSet(mDevicesWithMixedToolType) + "\n";
222-
out += "mCanceledDevices: " + dumpSet(mCanceledDevices) + "\n";
221+
out += "mDevicesWithMixedToolType: " + dumpContainer(mDevicesWithMixedToolType) + "\n";
222+
out += "mCanceledDevices: " + dumpContainer(mCanceledDevices) + "\n";
223223
return out;
224224
}
225225

services/inputflinger/UnwantedInteractionBlocker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ std::vector<NotifyMotionArgs> PalmRejector::processMotion(const NotifyMotionArgs
727727
if (!std::includes(oldSuppressedIds.begin(), oldSuppressedIds.end(),
728728
mSuppressedPointerIds.begin(), mSuppressedPointerIds.end())) {
729729
ALOGI("Palm detected, removing pointer ids %s after %" PRId64 "ms from %s",
730-
dumpSet(mSuppressedPointerIds).c_str(), ns2ms(args.eventTime - args.downTime),
730+
dumpContainer(mSuppressedPointerIds).c_str(), ns2ms(args.eventTime - args.downTime),
731731
args.dump().c_str());
732732
}
733733

@@ -748,7 +748,7 @@ std::string PalmRejector::dump() const {
748748
out += "mSlotState:\n";
749749
out += addLinePrefix(mSlotState.dump(), " ");
750750
out += "mSuppressedPointerIds: ";
751-
out += dumpSet(mSuppressedPointerIds) + "\n";
751+
out += dumpContainer(mSuppressedPointerIds) + "\n";
752752
std::stringstream state;
753753
state << *mSharedPalmState;
754754
out += "mSharedPalmState: " + state.str() + "\n";

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5802,8 +5802,8 @@ bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const s
58025802
}
58035803
std::set<DeviceId> deviceIds = touchedWindow->getTouchingDeviceIds();
58045804
if (deviceIds.size() != 1) {
5805-
LOG(INFO) << "Can't transfer touch. Currently touching devices: " << dumpSet(deviceIds)
5806-
<< " for window: " << touchedWindow->dump();
5805+
LOG(INFO) << "Can't transfer touch. Currently touching devices: "
5806+
<< dumpContainer(deviceIds) << " for window: " << touchedWindow->dump();
58075807
return false;
58085808
}
58095809
const DeviceId deviceId = *deviceIds.begin();

services/inputflinger/include/NotifyArgs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,6 @@ using NotifyArgs =
225225

226226
const char* toString(const NotifyArgs& args);
227227

228+
std::ostream& operator<<(std::ostream& out, const NotifyArgs& args);
229+
228230
} // namespace android

services/inputflinger/tests/InputReader_test.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8441,41 +8441,6 @@ TEST_F(MultiTouchInputMapperTest, StylusSourceIsAddedDynamicallyFromToolType) {
84418441
WithToolType(ToolType::STYLUS))));
84428442
}
84438443

8444-
// --- MultiTouchInputMapperTest_ExternalDevice ---
8445-
8446-
class MultiTouchInputMapperTest_ExternalDevice : public MultiTouchInputMapperTest {
8447-
protected:
8448-
void SetUp() override { InputMapperTest::SetUp(DEVICE_CLASSES | InputDeviceClass::EXTERNAL); }
8449-
};
8450-
8451-
/**
8452-
* Expect fallback to internal viewport if device is external and external viewport is not present.
8453-
*/
8454-
TEST_F(MultiTouchInputMapperTest_ExternalDevice, Viewports_Fallback) {
8455-
prepareAxes(POSITION);
8456-
addConfigurationProperty("touch.deviceType", "touchScreen");
8457-
prepareDisplay(ui::ROTATION_0);
8458-
MultiTouchInputMapper& mapper = constructAndAddMapper<MultiTouchInputMapper>();
8459-
8460-
ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper.getSources());
8461-
8462-
NotifyMotionArgs motionArgs;
8463-
8464-
// Expect the event to be sent to the internal viewport,
8465-
// because an external viewport is not present.
8466-
processPosition(mapper, 100, 100);
8467-
processSync(mapper);
8468-
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
8469-
ASSERT_EQ(ui::LogicalDisplayId::DEFAULT, motionArgs.displayId);
8470-
8471-
// Expect the event to be sent to the external viewport if it is present.
8472-
prepareSecondaryDisplay(ViewportType::EXTERNAL);
8473-
processPosition(mapper, 100, 100);
8474-
processSync(mapper);
8475-
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
8476-
ASSERT_EQ(SECONDARY_DISPLAY_ID, motionArgs.displayId);
8477-
}
8478-
84798444
// TODO(b/281840344): Remove the test when the old touchpad stack is removed. It is currently
84808445
// unclear what the behavior of the touchpad logic in TouchInputMapper should do after the
84818446
// PointerChoreographer refactor.

services/inputflinger/tests/LatencyTracker_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ bool timelinesAreEqual(const InputEventTimeline& received, const InputEventTimel
8080
<< "Received timeline with productId=" << received.productId
8181
<< " instead of expected productId=" << expected.productId;
8282
LOG_IF(ERROR, expected.sources != received.sources)
83-
<< "Received timeline with sources=" << dumpSet(received.sources, ftl::enum_string)
84-
<< " instead of expected sources=" << dumpSet(expected.sources, ftl::enum_string);
83+
<< "Received timeline with sources="
84+
<< dumpContainer(received.sources, ftl::enum_string)
85+
<< " instead of expected sources=" << dumpContainer(expected.sources, ftl::enum_string);
8586
LOG_IF(ERROR, expected.inputEventActionType != received.inputEventActionType)
8687
<< "Received timeline with inputEventActionType="
8788
<< ftl::enum_string(received.inputEventActionType)

services/inputflinger/tests/MultiTouchInputMapper_test.cpp

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,30 @@ using testing::Return;
3737
using testing::SetArgPointee;
3838
using testing::VariantWith;
3939

40-
static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT;
41-
static constexpr int32_t DISPLAY_WIDTH = 480;
42-
static constexpr int32_t DISPLAY_HEIGHT = 800;
43-
static constexpr std::optional<uint8_t> NO_PORT = std::nullopt; // no physical port is specified
44-
static constexpr int32_t SLOT_COUNT = 5;
45-
46-
static constexpr int32_t ACTION_POINTER_0_UP =
40+
namespace {
41+
42+
constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT;
43+
constexpr ui::LogicalDisplayId SECOND_DISPLAY_ID = ui::LogicalDisplayId{DISPLAY_ID.val() + 1};
44+
constexpr int32_t DISPLAY_WIDTH = 480;
45+
constexpr int32_t DISPLAY_HEIGHT = 800;
46+
constexpr std::optional<uint8_t> NO_PORT = std::nullopt; // no physical port is specified
47+
constexpr int32_t SLOT_COUNT = 5;
48+
49+
constexpr int32_t ACTION_DOWN = AMOTION_EVENT_ACTION_DOWN;
50+
constexpr int32_t ACTION_CANCEL = AMOTION_EVENT_ACTION_CANCEL;
51+
constexpr int32_t ACTION_POINTER_0_UP =
4752
AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
48-
static constexpr int32_t ACTION_POINTER_1_DOWN =
53+
constexpr int32_t ACTION_POINTER_1_DOWN =
4954
AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
5055

56+
template <typename... Args>
57+
void assertNotifyArgs(const std::list<NotifyArgs>& args, Args... matchers) {
58+
ASSERT_THAT(args, ElementsAre(matchers...))
59+
<< "Got instead: " << dumpContainer(args, streamableToString);
60+
}
61+
62+
} // namespace
63+
5164
/**
5265
* Unit tests for MultiTouchInputMapper.
5366
*/
@@ -270,6 +283,58 @@ TEST_F(MultiTouchInputMapperUnitTest, MultiFingerGestureWithUnexpectedReset) {
270283
VariantWith<NotifyMotionArgs>(WithMotionAction(AMOTION_EVENT_ACTION_UP))));
271284
}
272285

286+
class ExternalMultiTouchInputMapperTest : public MultiTouchInputMapperUnitTest {
287+
protected:
288+
void SetUp() override { MultiTouchInputMapperUnitTest::SetUp(/*bus=*/0, /*isExternal=*/true); }
289+
};
290+
291+
/**
292+
* Expect fallback to internal viewport if device is external and external viewport is not present.
293+
*/
294+
TEST_F(ExternalMultiTouchInputMapperTest, Viewports_Fallback) {
295+
std::list<NotifyArgs> args;
296+
297+
// Expect the event to be sent to the internal viewport,
298+
// because an external viewport is not present.
299+
args += processKey(BTN_TOUCH, 1);
300+
args += processId(1);
301+
args += processPosition(100, 200);
302+
args += processSync();
303+
304+
assertNotifyArgs(args,
305+
VariantWith<NotifyMotionArgs>(
306+
AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(DISPLAY_ID))));
307+
308+
// Expect the event to be sent to the external viewport if it is present.
309+
DisplayViewport externalViewport =
310+
createViewport(SECOND_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0,
311+
/*isActive=*/true, "local:1", NO_PORT, ViewportType::EXTERNAL);
312+
mFakePolicy->addDisplayViewport(externalViewport);
313+
std::optional<DisplayViewport> internalViewport =
314+
mFakePolicy->getDisplayViewportByUniqueId("local:0");
315+
mReaderConfiguration.setDisplayViewports({*internalViewport, externalViewport});
316+
args = mMapper->reconfigure(systemTime(SYSTEM_TIME_MONOTONIC), mReaderConfiguration,
317+
InputReaderConfiguration::Change::DISPLAY_INFO);
318+
319+
assertNotifyArgs(args,
320+
VariantWith<NotifyMotionArgs>(AllOf(WithMotionAction(ACTION_CANCEL),
321+
WithDisplayId(SECOND_DISPLAY_ID))),
322+
VariantWith<NotifyDeviceResetArgs>(WithDeviceId(DEVICE_ID)));
323+
// Lift up the old pointer.
324+
processKey(BTN_TOUCH, 0);
325+
args = processId(-1);
326+
args += processSync();
327+
328+
// Send new pointer
329+
args += processKey(BTN_TOUCH, 1);
330+
args += processId(2);
331+
args += processPosition(111, 211);
332+
args += processSync();
333+
assertNotifyArgs(args,
334+
VariantWith<NotifyMotionArgs>(AllOf(WithMotionAction(ACTION_DOWN),
335+
WithDisplayId(SECOND_DISPLAY_ID))));
336+
}
337+
273338
class MultiTouchInputMapperPointerModeUnitTest : public MultiTouchInputMapperUnitTest {
274339
protected:
275340
void SetUp() override {

0 commit comments

Comments
 (0)