Skip to content

Commit 4a49249

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "KeyboardInputMapper: migrate most tests to InputMapperUnitTest" into main
2 parents 3f518c7 + d62330d commit 4a49249

6 files changed

Lines changed: 544 additions & 548 deletions

File tree

include/input/Input.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ enum class KeyboardType {
294294
NONE = AINPUT_KEYBOARD_TYPE_NONE,
295295
NON_ALPHABETIC = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC,
296296
ALPHABETIC = AINPUT_KEYBOARD_TYPE_ALPHABETIC,
297+
ftl_first = NONE,
298+
ftl_last = ALPHABETIC,
297299
};
298300

299301
bool isStylusToolType(ToolType toolType);

services/inputflinger/reader/include/InputDevice.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class InputDevice {
4848
inline InputReaderContext* getContext() { return mContext; }
4949
inline int32_t getId() const { return mId; }
5050
inline int32_t getControllerNumber() const { return mControllerNumber; }
51-
inline int32_t getGeneration() const { return mGeneration; }
51+
inline virtual int32_t getGeneration() const { return mGeneration; }
5252
inline const std::string getName() const { return mIdentifier.name; }
5353
inline const std::string getDescriptor() { return mIdentifier.descriptor; }
5454
inline std::optional<std::string> getBluetoothAddress() const {
@@ -59,7 +59,7 @@ class InputDevice {
5959
inline virtual uint32_t getSources() const { return mSources; }
6060
inline bool hasEventHubDevices() const { return !mDevices.empty(); }
6161

62-
inline bool isExternal() { return mIsExternal; }
62+
inline virtual bool isExternal() { return mIsExternal; }
6363
inline std::optional<uint8_t> getAssociatedDisplayPort() const {
6464
return mAssociatedDisplayPort;
6565
}
@@ -79,7 +79,7 @@ class InputDevice {
7979

8080
inline bool isIgnored() { return !getMapperCount() && !mController; }
8181

82-
inline KeyboardType getKeyboardType() const { return mKeyboardType; }
82+
inline virtual KeyboardType getKeyboardType() const { return mKeyboardType; }
8383

8484
bool isEnabled();
8585

@@ -124,7 +124,7 @@ class InputDevice {
124124
int32_t getMetaState();
125125
void setKeyboardType(KeyboardType keyboardType);
126126

127-
void bumpGeneration();
127+
virtual void bumpGeneration();
128128

129129
[[nodiscard]] NotifyDeviceResetArgs notifyReset(nsecs_t when);
130130

services/inputflinger/tests/InputMapperTest.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@ std::list<NotifyArgs> InputMapperUnitTest::process(int32_t type, int32_t code, i
100100

101101
std::list<NotifyArgs> InputMapperUnitTest::process(nsecs_t when, int32_t type, int32_t code,
102102
int32_t value) {
103+
return process(when, when, type, code, value);
104+
}
105+
106+
std::list<NotifyArgs> InputMapperUnitTest::process(nsecs_t when, nsecs_t readTime, int32_t type,
107+
int32_t code, int32_t value) {
103108
RawEvent event;
104109
event.when = when;
105-
event.readTime = when;
110+
event.readTime = readTime;
106111
event.deviceId = mMapper->getDeviceContext().getEventHubId();
107112
event.type = type;
108113
event.code = code;

services/inputflinger/tests/InputMapperTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class InputMapperUnitTest : public testing::Test {
5656

5757
std::list<NotifyArgs> process(int32_t type, int32_t code, int32_t value);
5858
std::list<NotifyArgs> process(nsecs_t when, int32_t type, int32_t code, int32_t value);
59+
std::list<NotifyArgs> process(nsecs_t when, nsecs_t readTime, int32_t type, int32_t code,
60+
int32_t value);
5961

6062
InputDeviceIdentifier mIdentifier;
6163
MockEventHubInterface mMockEventHub;

services/inputflinger/tests/InterfaceMocks.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ class MockInputDevice : public InputDevice {
201201

202202
MOCK_METHOD(uint32_t, getSources, (), (const, override));
203203
MOCK_METHOD(std::optional<DisplayViewport>, getAssociatedViewport, (), (const));
204+
MOCK_METHOD(KeyboardType, getKeyboardType, (), (const, override));
204205
MOCK_METHOD(bool, isEnabled, (), ());
206+
MOCK_METHOD(bool, isExternal, (), (override));
205207

206208
MOCK_METHOD(void, dump, (std::string& dump, const std::string& eventHubDevStr), ());
207209
MOCK_METHOD(void, addEmptyEventHubDevice, (int32_t eventHubId), ());
@@ -249,8 +251,6 @@ class MockInputDevice : public InputDevice {
249251
MOCK_METHOD(int32_t, getMetaState, (), ());
250252
MOCK_METHOD(void, setKeyboardType, (KeyboardType keyboardType), ());
251253

252-
MOCK_METHOD(void, bumpGeneration, (), ());
253-
254254
MOCK_METHOD(const PropertyMap&, getConfiguration, (), (const, override));
255255

256256
MOCK_METHOD(NotifyDeviceResetArgs, notifyReset, (nsecs_t when), ());
@@ -260,5 +260,11 @@ class MockInputDevice : public InputDevice {
260260
MOCK_METHOD(void, updateLedState, (bool reset), ());
261261

262262
MOCK_METHOD(size_t, getMapperCount, (), ());
263+
264+
virtual int32_t getGeneration() const override { return mGeneration; }
265+
virtual void bumpGeneration() override { mGeneration++; }
266+
267+
private:
268+
int32_t mGeneration = 0;
263269
};
264270
} // namespace android

0 commit comments

Comments
 (0)