Merge "Convert ALOGV to ALOGD in various libgui_test cases" into udc-dev
diff --git a/include/input/Input.h b/include/input/Input.h
index a033535..1e810b4 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -210,7 +210,20 @@
*/
float transformAngle(const ui::Transform& transform, float angleRadians);
-const char* inputEventTypeToString(int32_t type);
+/**
+ * The type of the InputEvent.
+ * This should have 1:1 correspondence with the values of anonymous enum defined in input.h.
+ */
+enum class InputEventType {
+ KEY = AINPUT_EVENT_TYPE_KEY,
+ MOTION = AINPUT_EVENT_TYPE_MOTION,
+ FOCUS = AINPUT_EVENT_TYPE_FOCUS,
+ CAPTURE = AINPUT_EVENT_TYPE_CAPTURE,
+ DRAG = AINPUT_EVENT_TYPE_DRAG,
+ TOUCH_MODE = AINPUT_EVENT_TYPE_TOUCH_MODE,
+ ftl_first = KEY,
+ ftl_last = TOUCH_MODE,
+};
std::string inputEventSourceToString(int32_t source);
@@ -482,7 +495,7 @@
public:
virtual ~InputEvent() { }
- virtual int32_t getType() const = 0;
+ virtual InputEventType getType() const = 0;
inline int32_t getId() const { return mId; }
@@ -513,6 +526,8 @@
std::array<uint8_t, 32> mHmac;
};
+std::ostream& operator<<(std::ostream& out, const InputEvent& event);
+
/*
* Key events.
*/
@@ -520,7 +535,7 @@
public:
virtual ~KeyEvent() { }
- virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
+ virtual InputEventType getType() const { return InputEventType::KEY; }
inline int32_t getAction() const { return mAction; }
@@ -571,7 +586,7 @@
public:
virtual ~MotionEvent() { }
- virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
+ virtual InputEventType getType() const { return InputEventType::MOTION; }
inline int32_t getAction() const { return mAction; }
@@ -899,7 +914,7 @@
public:
virtual ~FocusEvent() {}
- virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_FOCUS; }
+ virtual InputEventType getType() const override { return InputEventType::FOCUS; }
inline bool getHasFocus() const { return mHasFocus; }
@@ -918,7 +933,7 @@
public:
virtual ~CaptureEvent() {}
- virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_CAPTURE; }
+ virtual InputEventType getType() const override { return InputEventType::CAPTURE; }
inline bool getPointerCaptureEnabled() const { return mPointerCaptureEnabled; }
@@ -937,7 +952,7 @@
public:
virtual ~DragEvent() {}
- virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_DRAG; }
+ virtual InputEventType getType() const override { return InputEventType::DRAG; }
inline bool isExiting() const { return mIsExiting; }
@@ -961,7 +976,7 @@
public:
virtual ~TouchModeEvent() {}
- virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_TOUCH_MODE; }
+ virtual InputEventType getType() const override { return InputEventType::TOUCH_MODE; }
inline bool isInTouchMode() const { return mIsInTouchMode; }
diff --git a/libs/binder/IBatteryStats.cpp b/libs/binder/IBatteryStats.cpp
index 0de804c..69b11c0 100644
--- a/libs/binder/IBatteryStats.cpp
+++ b/libs/binder/IBatteryStats.cpp
@@ -128,6 +128,15 @@
remote()->transact(NOTE_RESET_FLASHLIGHT_TRANSACTION, data, &reply);
}
+ virtual binder::Status noteWakeupSensorEvent(int64_t elapsedNanos, int uid, int handle) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
+ data.writeInt64(elapsedNanos);
+ data.writeInt32(uid);
+ data.writeInt32(handle);
+ status_t ret = remote()->transact(NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION, data, &reply);
+ return binder::Status::fromStatusT(ret);
+ }
};
IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats")
@@ -235,6 +244,16 @@
reply->writeNoException();
return NO_ERROR;
} break;
+ case NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION: {
+ CHECK_INTERFACE(IBatteryStats, data, reply);
+ int64_t elapsedNanos = data.readInt64();
+ int uid = data.readInt32();
+ int handle = data.readInt32();
+ noteWakeupSensorEvent(elapsedNanos, uid, handle);
+ reply->writeNoException();
+ return NO_ERROR;
+ } break;
+
default:
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/libs/binder/include_batterystats/batterystats/IBatteryStats.h b/libs/binder/include_batterystats/batterystats/IBatteryStats.h
index 6defc7f..5bb01dd 100644
--- a/libs/binder/include_batterystats/batterystats/IBatteryStats.h
+++ b/libs/binder/include_batterystats/batterystats/IBatteryStats.h
@@ -19,6 +19,7 @@
#ifndef __ANDROID_VNDK__
#include <binder/IInterface.h>
+#include <binder/Status.h>
namespace android {
@@ -43,6 +44,7 @@
virtual void noteStopCamera(int uid) = 0;
virtual void noteResetCamera() = 0;
virtual void noteResetFlashlight() = 0;
+ virtual binder::Status noteWakeupSensorEvent(int64_t elapsedNanos, int uid, int sensor) = 0;
enum {
NOTE_START_SENSOR_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
@@ -58,7 +60,8 @@
NOTE_START_CAMERA_TRANSACTION,
NOTE_STOP_CAMERA_TRANSACTION,
NOTE_RESET_CAMERA_TRANSACTION,
- NOTE_RESET_FLASHLIGHT_TRANSACTION
+ NOTE_RESET_FLASHLIGHT_TRANSACTION,
+ NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION
};
};
diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp
index 504b3ce..8d13007 100644
--- a/libs/binder/tests/binderRpcTest.cpp
+++ b/libs/binder/tests/binderRpcTest.cpp
@@ -1126,6 +1126,11 @@
android::base::unique_fd serverFd(
TEMP_FAILURE_RETRY(socket(AF_VSOCK, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)));
+
+ if (errno == EAFNOSUPPORT) {
+ return false;
+ }
+
LOG_ALWAYS_FATAL_IF(serverFd == -1, "Could not create socket: %s", strerror(errno));
sockaddr_vm serverAddr{
diff --git a/libs/bufferqueueconverter/Android.bp b/libs/bufferqueueconverter/Android.bp
index 5f145a1..d4605ea 100644
--- a/libs/bufferqueueconverter/Android.bp
+++ b/libs/bufferqueueconverter/Android.bp
@@ -13,7 +13,7 @@
export_include_dirs: ["include"],
}
-cc_library_shared {
+cc_library {
name: "libbufferqueueconverter",
vendor_available: true,
vndk: {
diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp
index 9a9bd4a..4ec7a06 100644
--- a/libs/gui/tests/EndToEndNativeInputTest.cpp
+++ b/libs/gui/tests/EndToEndNativeInputTest.cpp
@@ -164,7 +164,7 @@
void assertFocusChange(bool hasFocus) {
InputEvent *ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, ev->getType());
+ ASSERT_EQ(InputEventType::FOCUS, ev->getType());
FocusEvent *focusEvent = static_cast<FocusEvent *>(ev);
EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
}
@@ -172,7 +172,7 @@
void expectTap(int x, int y) {
InputEvent* ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
+ ASSERT_EQ(InputEventType::MOTION, ev->getType());
MotionEvent* mev = static_cast<MotionEvent*>(ev);
EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction());
EXPECT_EQ(x, mev->getX(0));
@@ -181,7 +181,7 @@
ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
+ ASSERT_EQ(InputEventType::MOTION, ev->getType());
mev = static_cast<MotionEvent*>(ev);
EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction());
EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS);
@@ -190,7 +190,7 @@
void expectTapWithFlag(int x, int y, int32_t flags) {
InputEvent *ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
+ ASSERT_EQ(InputEventType::MOTION, ev->getType());
MotionEvent *mev = static_cast<MotionEvent *>(ev);
EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction());
EXPECT_EQ(x, mev->getX(0));
@@ -199,7 +199,7 @@
ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
+ ASSERT_EQ(InputEventType::MOTION, ev->getType());
mev = static_cast<MotionEvent *>(ev);
EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction());
EXPECT_EQ(flags, mev->getFlags() & flags);
@@ -208,7 +208,7 @@
void expectTapInDisplayCoordinates(int displayX, int displayY) {
InputEvent *ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
+ ASSERT_EQ(InputEventType::MOTION, ev->getType());
MotionEvent *mev = static_cast<MotionEvent *>(ev);
EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction());
const PointerCoords &coords = *mev->getRawPointerCoords(0 /*pointerIndex*/);
@@ -218,7 +218,7 @@
ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
+ ASSERT_EQ(InputEventType::MOTION, ev->getType());
mev = static_cast<MotionEvent *>(ev);
EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction());
EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS);
@@ -227,7 +227,7 @@
void expectKey(uint32_t keycode) {
InputEvent *ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, ev->getType());
+ ASSERT_EQ(InputEventType::KEY, ev->getType());
KeyEvent *keyEvent = static_cast<KeyEvent *>(ev);
EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, keyEvent->getAction());
EXPECT_EQ(keycode, keyEvent->getKeyCode());
@@ -235,7 +235,7 @@
ev = consumeEvent();
ASSERT_NE(ev, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, ev->getType());
+ ASSERT_EQ(InputEventType::KEY, ev->getType());
keyEvent = static_cast<KeyEvent *>(ev);
EXPECT_EQ(AMOTION_EVENT_ACTION_UP, keyEvent->getAction());
EXPECT_EQ(keycode, keyEvent->getKeyCode());
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 4dbf575..00925ba 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -170,30 +170,6 @@
return atan2f(transformedPoint.x, -transformedPoint.y);
}
-const char* inputEventTypeToString(int32_t type) {
- switch (type) {
- case AINPUT_EVENT_TYPE_KEY: {
- return "KEY";
- }
- case AINPUT_EVENT_TYPE_MOTION: {
- return "MOTION";
- }
- case AINPUT_EVENT_TYPE_FOCUS: {
- return "FOCUS";
- }
- case AINPUT_EVENT_TYPE_CAPTURE: {
- return "CAPTURE";
- }
- case AINPUT_EVENT_TYPE_DRAG: {
- return "DRAG";
- }
- case AINPUT_EVENT_TYPE_TOUCH_MODE: {
- return "TOUCH_MODE";
- }
- }
- return "UNKNOWN";
-}
-
std::string inputEventSourceToString(int32_t source) {
if (source == AINPUT_SOURCE_UNKNOWN) {
return "UNKNOWN";
@@ -287,6 +263,37 @@
return idGen.nextId();
}
+std::ostream& operator<<(std::ostream& out, const InputEvent& event) {
+ switch (event.getType()) {
+ case InputEventType::KEY: {
+ const KeyEvent& keyEvent = static_cast<const KeyEvent&>(event);
+ out << keyEvent;
+ return out;
+ }
+ case InputEventType::MOTION: {
+ const MotionEvent& motionEvent = static_cast<const MotionEvent&>(event);
+ out << motionEvent;
+ return out;
+ }
+ case InputEventType::FOCUS: {
+ out << "FocusEvent";
+ return out;
+ }
+ case InputEventType::CAPTURE: {
+ out << "CaptureEvent";
+ return out;
+ }
+ case InputEventType::DRAG: {
+ out << "DragEvent";
+ return out;
+ }
+ case InputEventType::TOUCH_MODE: {
+ out << "TouchModeEvent";
+ return out;
+ }
+ }
+}
+
// --- KeyEvent ---
const char* KeyEvent::getLabel(int32_t keyCode) {
@@ -1165,44 +1172,51 @@
void PooledInputEventFactory::recycle(InputEvent* event) {
switch (event->getType()) {
- case AINPUT_EVENT_TYPE_KEY:
- if (mKeyEventPool.size() < mMaxPoolSize) {
- mKeyEventPool.push(std::unique_ptr<KeyEvent>(static_cast<KeyEvent*>(event)));
- return;
+ case InputEventType::KEY: {
+ if (mKeyEventPool.size() < mMaxPoolSize) {
+ mKeyEventPool.push(std::unique_ptr<KeyEvent>(static_cast<KeyEvent*>(event)));
+ return;
+ }
+ break;
}
- break;
- case AINPUT_EVENT_TYPE_MOTION:
- if (mMotionEventPool.size() < mMaxPoolSize) {
- mMotionEventPool.push(std::unique_ptr<MotionEvent>(static_cast<MotionEvent*>(event)));
- return;
+ case InputEventType::MOTION: {
+ if (mMotionEventPool.size() < mMaxPoolSize) {
+ mMotionEventPool.push(
+ std::unique_ptr<MotionEvent>(static_cast<MotionEvent*>(event)));
+ return;
+ }
+ break;
}
- break;
- case AINPUT_EVENT_TYPE_FOCUS:
- if (mFocusEventPool.size() < mMaxPoolSize) {
- mFocusEventPool.push(std::unique_ptr<FocusEvent>(static_cast<FocusEvent*>(event)));
- return;
+ case InputEventType::FOCUS: {
+ if (mFocusEventPool.size() < mMaxPoolSize) {
+ mFocusEventPool.push(std::unique_ptr<FocusEvent>(static_cast<FocusEvent*>(event)));
+ return;
+ }
+ break;
}
- break;
- case AINPUT_EVENT_TYPE_CAPTURE:
- if (mCaptureEventPool.size() < mMaxPoolSize) {
- mCaptureEventPool.push(
- std::unique_ptr<CaptureEvent>(static_cast<CaptureEvent*>(event)));
- return;
+ case InputEventType::CAPTURE: {
+ if (mCaptureEventPool.size() < mMaxPoolSize) {
+ mCaptureEventPool.push(
+ std::unique_ptr<CaptureEvent>(static_cast<CaptureEvent*>(event)));
+ return;
+ }
+ break;
}
- break;
- case AINPUT_EVENT_TYPE_DRAG:
- if (mDragEventPool.size() < mMaxPoolSize) {
- mDragEventPool.push(std::unique_ptr<DragEvent>(static_cast<DragEvent*>(event)));
- return;
+ case InputEventType::DRAG: {
+ if (mDragEventPool.size() < mMaxPoolSize) {
+ mDragEventPool.push(std::unique_ptr<DragEvent>(static_cast<DragEvent*>(event)));
+ return;
+ }
+ break;
}
- break;
- case AINPUT_EVENT_TYPE_TOUCH_MODE:
- if (mTouchModeEventPool.size() < mMaxPoolSize) {
- mTouchModeEventPool.push(
- std::unique_ptr<TouchModeEvent>(static_cast<TouchModeEvent*>(event)));
- return;
+ case InputEventType::TOUCH_MODE: {
+ if (mTouchModeEventPool.size() < mMaxPoolSize) {
+ mTouchModeEventPool.push(
+ std::unique_ptr<TouchModeEvent>(static_cast<TouchModeEvent*>(event)));
+ return;
+ }
+ break;
}
- break;
}
delete event;
}
diff --git a/libs/input/android/os/InputEventInjectionSync.aidl b/libs/input/android/os/InputEventInjectionSync.aidl
index 95d24cb..2d225fa 100644
--- a/libs/input/android/os/InputEventInjectionSync.aidl
+++ b/libs/input/android/os/InputEventInjectionSync.aidl
@@ -33,4 +33,7 @@
/* Waits for the input event to be completely processed. */
WAIT_FOR_FINISHED = 2,
+
+ ftl_first = NONE,
+ ftl_last = WAIT_FOR_FINISHED,
}
diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp
index 59125dd..a965573 100644
--- a/libs/input/tests/InputEvent_test.cpp
+++ b/libs/input/tests/InputEvent_test.cpp
@@ -197,7 +197,7 @@
ARBITRARY_DOWN_TIME, ARBITRARY_EVENT_TIME);
ASSERT_EQ(id, event.getId());
- ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event.getType());
+ ASSERT_EQ(InputEventType::KEY, event.getType());
ASSERT_EQ(2, event.getDeviceId());
ASSERT_EQ(AINPUT_SOURCE_GAMEPAD, event.getSource());
ASSERT_EQ(DISPLAY_ID, event.getDisplayId());
@@ -346,7 +346,7 @@
void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) {
// Check properties.
ASSERT_EQ(mId, event->getId());
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType());
+ ASSERT_EQ(InputEventType::MOTION, event->getType());
ASSERT_EQ(2, event->getDeviceId());
ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, event->getSource());
ASSERT_EQ(DISPLAY_ID, event->getDisplayId());
diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp
index 965fda7..3ecf8ee 100644
--- a/libs/input/tests/InputPublisherAndConsumer_test.cpp
+++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp
@@ -98,8 +98,7 @@
ASSERT_TRUE(event != nullptr)
<< "consumer should have returned non-NULL event";
- ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event->getType())
- << "consumer should have returned a key event";
+ ASSERT_EQ(InputEventType::KEY, event->getType()) << "consumer should have returned a key event";
KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
EXPECT_EQ(seq, consumeSeq);
@@ -207,7 +206,7 @@
ASSERT_TRUE(event != nullptr)
<< "consumer should have returned non-NULL event";
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
+ ASSERT_EQ(InputEventType::MOTION, event->getType())
<< "consumer should have returned a motion event";
MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
@@ -298,7 +297,7 @@
ASSERT_EQ(OK, status) << "consumer consume should return OK";
ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
- ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType())
+ ASSERT_EQ(InputEventType::FOCUS, event->getType())
<< "consumer should have returned a focus event";
FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
@@ -339,7 +338,7 @@
ASSERT_EQ(OK, status) << "consumer consume should return OK";
ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
- ASSERT_EQ(AINPUT_EVENT_TYPE_CAPTURE, event->getType())
+ ASSERT_EQ(InputEventType::CAPTURE, event->getType())
<< "consumer should have returned a capture event";
const CaptureEvent* captureEvent = static_cast<CaptureEvent*>(event);
@@ -381,7 +380,7 @@
ASSERT_EQ(OK, status) << "consumer consume should return OK";
ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
- ASSERT_EQ(AINPUT_EVENT_TYPE_DRAG, event->getType())
+ ASSERT_EQ(InputEventType::DRAG, event->getType())
<< "consumer should have returned a drag event";
const DragEvent& dragEvent = static_cast<const DragEvent&>(*event);
@@ -423,7 +422,7 @@
ASSERT_EQ(OK, status) << "consumer consume should return OK";
ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
- ASSERT_EQ(AINPUT_EVENT_TYPE_TOUCH_MODE, event->getType())
+ ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType())
<< "consumer should have returned a touch mode event";
const TouchModeEvent& touchModeEvent = static_cast<const TouchModeEvent&>(*event);
diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp
index b885435..e04481c 100644
--- a/services/inputflinger/Android.bp
+++ b/services/inputflinger/Android.bp
@@ -213,6 +213,7 @@
name: "checkinput",
required: [
// native targets
+ "libgui_test",
"libinput",
"libinputflinger",
"inputflinger_tests",
diff --git a/services/inputflinger/InputListener.cpp b/services/inputflinger/InputListener.cpp
index d33b298..1bc1adf 100644
--- a/services/inputflinger/InputListener.cpp
+++ b/services/inputflinger/InputListener.cpp
@@ -24,7 +24,6 @@
#include <android-base/stringprintf.h>
#include <android/log.h>
-#include <math.h>
#include <utils/Trace.h>
using android::base::StringPrintf;
@@ -47,6 +46,7 @@
void InputListenerInterface::notify(const NotifyArgs& generalArgs) {
Visitor v{
+ [&](const NotifyInputDevicesChangedArgs& args) { notifyInputDevicesChanged(args); },
[&](const NotifyConfigurationChangedArgs& args) { notifyConfigurationChanged(&args); },
[&](const NotifyKeyArgs& args) { notifyKey(&args); },
[&](const NotifyMotionArgs& args) { notifyMotion(&args); },
@@ -73,6 +73,11 @@
QueuedInputListener::QueuedInputListener(InputListenerInterface& innerListener)
: mInnerListener(innerListener) {}
+void QueuedInputListener::notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
+}
+
void QueuedInputListener::notifyConfigurationChanged(
const NotifyConfigurationChangedArgs* args) {
traceEvent(__func__, args->id);
diff --git a/services/inputflinger/InputManager.cpp b/services/inputflinger/InputManager.cpp
index 9182503..472d7a1 100644
--- a/services/inputflinger/InputManager.cpp
+++ b/services/inputflinger/InputManager.cpp
@@ -110,10 +110,6 @@
return *mReader;
}
-UnwantedInteractionBlockerInterface& InputManager::getBlocker() {
- return *mBlocker;
-}
-
InputProcessorInterface& InputManager::getProcessor() {
return *mProcessor;
}
@@ -129,6 +125,17 @@
mDispatcher->monitor();
}
+void InputManager::dump(std::string& dump) {
+ mReader->dump(dump);
+ dump += '\n';
+ mBlocker->dump(dump);
+ dump += '\n';
+ mProcessor->dump(dump);
+ dump += '\n';
+ mDispatcher->dump(dump);
+ dump += '\n';
+}
+
// Used by tests only.
binder::Status InputManager::createInputChannel(const std::string& name, InputChannel* outChannel) {
IPCThreadState* ipc = IPCThreadState::self();
diff --git a/services/inputflinger/InputManager.h b/services/inputflinger/InputManager.h
index 1137193..793757d 100644
--- a/services/inputflinger/InputManager.h
+++ b/services/inputflinger/InputManager.h
@@ -82,9 +82,6 @@
/* Gets the input reader. */
virtual InputReaderInterface& getReader() = 0;
- /* Gets the unwanted interaction blocker. */
- virtual UnwantedInteractionBlockerInterface& getBlocker() = 0;
-
/* Gets the input processor */
virtual InputProcessorInterface& getProcessor() = 0;
@@ -93,6 +90,9 @@
/* Check that the input stages have not deadlocked. */
virtual void monitor() = 0;
+
+ /* Dump the state of the components controlled by the input manager. */
+ virtual void dump(std::string& dump) = 0;
};
class InputManager : public InputManagerInterface, public BnInputFlinger {
@@ -108,10 +108,10 @@
status_t stop() override;
InputReaderInterface& getReader() override;
- UnwantedInteractionBlockerInterface& getBlocker() override;
InputProcessorInterface& getProcessor() override;
InputDispatcherInterface& getDispatcher() override;
void monitor() override;
+ void dump(std::string& dump) override;
status_t dump(int fd, const Vector<String16>& args) override;
binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override;
diff --git a/services/inputflinger/InputProcessor.cpp b/services/inputflinger/InputProcessor.cpp
index a98b383..6c0bcff 100644
--- a/services/inputflinger/InputProcessor.cpp
+++ b/services/inputflinger/InputProcessor.cpp
@@ -413,6 +413,12 @@
}
}
+void InputProcessor::notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) {
+ // pass through
+ mQueuedListener.notify(args);
+ mQueuedListener.flush();
+}
+
void InputProcessor::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
// pass through
mQueuedListener.notifyConfigurationChanged(args);
diff --git a/services/inputflinger/InputProcessor.h b/services/inputflinger/InputProcessor.h
index f4d02b6..01795a8 100644
--- a/services/inputflinger/InputProcessor.h
+++ b/services/inputflinger/InputProcessor.h
@@ -245,6 +245,7 @@
public:
explicit InputProcessor(InputListenerInterface& listener);
+ void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
void notifyKey(const NotifyKeyArgs* args) override;
void notifyMotion(const NotifyMotionArgs* args) override;
diff --git a/services/inputflinger/NotifyArgs.cpp b/services/inputflinger/NotifyArgs.cpp
index 5f2a22f..408fbed 100644
--- a/services/inputflinger/NotifyArgs.cpp
+++ b/services/inputflinger/NotifyArgs.cpp
@@ -29,6 +29,12 @@
namespace android {
+// --- NotifyInputDevicesChangedArgs ---
+
+NotifyInputDevicesChangedArgs::NotifyInputDevicesChangedArgs(int32_t id,
+ std::vector<InputDeviceInfo> infos)
+ : id(id), inputDeviceInfos(std::move(infos)) {}
+
// --- NotifyConfigurationChangedArgs ---
NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(int32_t id, nsecs_t eventTime)
@@ -234,6 +240,7 @@
const char* toString(const NotifyArgs& args) {
Visitor toStringVisitor{
+ [&](const NotifyInputDevicesChangedArgs&) { return "NotifyInputDevicesChangedArgs"; },
[&](const NotifyConfigurationChangedArgs&) { return "NotifyConfigurationChangedArgs"; },
[&](const NotifyKeyArgs&) { return "NotifyKeyArgs"; },
[&](const NotifyMotionArgs&) { return "NotifyMotionArgs"; },
diff --git a/services/inputflinger/UnwantedInteractionBlocker.cpp b/services/inputflinger/UnwantedInteractionBlocker.cpp
index ae20f86..6d43e8d 100644
--- a/services/inputflinger/UnwantedInteractionBlocker.cpp
+++ b/services/inputflinger/UnwantedInteractionBlocker.cpp
@@ -411,6 +411,13 @@
}
void UnwantedInteractionBlocker::notifyInputDevicesChanged(
+ const NotifyInputDevicesChangedArgs& args) {
+ onInputDevicesChanged(args.inputDeviceInfos);
+ mQueuedListener.notify(args);
+ mQueuedListener.flush();
+}
+
+void UnwantedInteractionBlocker::onInputDevicesChanged(
const std::vector<InputDeviceInfo>& inputDevices) {
std::scoped_lock lock(mLock);
if (!mEnablePalmRejection) {
diff --git a/services/inputflinger/UnwantedInteractionBlocker.h b/services/inputflinger/UnwantedInteractionBlocker.h
index 5d0dde8..3bc5240 100644
--- a/services/inputflinger/UnwantedInteractionBlocker.h
+++ b/services/inputflinger/UnwantedInteractionBlocker.h
@@ -90,6 +90,7 @@
explicit UnwantedInteractionBlocker(InputListenerInterface& listener);
explicit UnwantedInteractionBlocker(InputListenerInterface& listener, bool enablePalmRejection);
+ void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
void notifyKey(const NotifyKeyArgs* args) override;
void notifyMotion(const NotifyMotionArgs* args) override;
@@ -99,7 +100,6 @@
void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
- void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
void dump(std::string& dump) override;
void monitor() override;
@@ -123,6 +123,8 @@
// Call this function for outbound events so that they can be logged when logging is enabled.
void enqueueOutboundMotionLocked(const NotifyMotionArgs& args) REQUIRES(mLock);
+
+ void onInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices);
};
class SlotState {
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 851f13c..c39c408 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -117,11 +117,7 @@
return systemTime(SYSTEM_TIME_MONOTONIC);
}
-inline const char* toString(bool value) {
- return value ? "true" : "false";
-}
-
-inline const std::string toString(const sp<IBinder>& binder) {
+inline const std::string binderToString(const sp<IBinder>& binder) {
if (binder == nullptr) {
return "<null>";
}
@@ -2909,7 +2905,7 @@
info->frameBottom, dumpRegion(info->touchableRegion).c_str(),
info->name.c_str(), info->inputConfig.string().c_str(),
toString(info->token != nullptr), info->applicationInfo.name.c_str(),
- toString(info->applicationInfo.token).c_str());
+ binderToString(info->applicationInfo.token).c_str());
}
bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const {
@@ -3623,8 +3619,8 @@
const sp<Connection>& connection,
bool notify) {
if (DEBUG_DISPATCH_CYCLE) {
- ALOGD("channel '%s' ~ abortBrokenDispatchCycle - notify=%s",
- connection->getInputChannelName().c_str(), toString(notify));
+ LOG(DEBUG) << "channel '" << connection->getInputChannelName() << "'~ " << __func__
+ << " - notify=" << toString(notify);
}
// Clear the dispatch queues.
@@ -4376,10 +4372,10 @@
std::chrono::milliseconds timeout,
uint32_t policyFlags) {
if (debugInboundEventDetails()) {
- ALOGD("injectInputEvent - eventType=%d, targetUid=%s, syncMode=%d, timeout=%lld, "
- "policyFlags=0x%08x",
- event->getType(), targetUid ? std::to_string(*targetUid).c_str() : "none", syncMode,
- timeout.count(), policyFlags);
+ LOG(DEBUG) << __func__ << ": targetUid=" << toString(targetUid)
+ << ", syncMode=" << ftl::enum_string(syncMode) << ", timeout=" << timeout.count()
+ << "ms, policyFlags=0x" << std::hex << policyFlags << std::dec
+ << ", event=" << *event;
}
nsecs_t endTime = now() + std::chrono::duration_cast<std::chrono::nanoseconds>(timeout).count();
@@ -4398,7 +4394,7 @@
std::queue<std::unique_ptr<EventEntry>> injectedEntries;
switch (event->getType()) {
- case AINPUT_EVENT_TYPE_KEY: {
+ case InputEventType::KEY: {
const KeyEvent& incomingKey = static_cast<const KeyEvent&>(*event);
int32_t action = incomingKey.getAction();
if (!validateKeyEvent(action)) {
@@ -4444,7 +4440,7 @@
break;
}
- case AINPUT_EVENT_TYPE_MOTION: {
+ case InputEventType::MOTION: {
const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
const int32_t action = motionEvent.getAction();
const bool isPointerEvent =
@@ -4520,7 +4516,7 @@
}
default:
- ALOGW("Cannot inject %s events", inputEventTypeToString(event->getType()));
+ LOG(WARNING) << "Cannot inject " << ftl::enum_string(event->getType()) << " events";
return InputEventInjectionResult::FAILED;
}
@@ -4610,14 +4606,14 @@
std::array<uint8_t, 32> calculatedHmac;
std::unique_ptr<VerifiedInputEvent> result;
switch (event.getType()) {
- case AINPUT_EVENT_TYPE_KEY: {
+ case InputEventType::KEY: {
const KeyEvent& keyEvent = static_cast<const KeyEvent&>(event);
VerifiedKeyEvent verifiedKeyEvent = verifiedKeyEventFromKeyEvent(keyEvent);
result = std::make_unique<VerifiedKeyEvent>(verifiedKeyEvent);
calculatedHmac = sign(verifiedKeyEvent);
break;
}
- case AINPUT_EVENT_TYPE_MOTION: {
+ case InputEventType::MOTION: {
const MotionEvent& motionEvent = static_cast<const MotionEvent&>(event);
VerifiedMotionEvent verifiedMotionEvent =
verifiedMotionEventFromMotionEvent(motionEvent);
@@ -5519,14 +5515,14 @@
windowInfo->frameTop, windowInfo->frameRight,
windowInfo->frameBottom, windowInfo->globalScaleFactor,
windowInfo->applicationInfo.name.c_str(),
- toString(windowInfo->applicationInfo.token).c_str());
+ binderToString(windowInfo->applicationInfo.token).c_str());
dump += dumpRegion(windowInfo->touchableRegion);
dump += StringPrintf(", ownerPid=%d, ownerUid=%d, dispatchingTimeout=%" PRId64
"ms, hasToken=%s, "
"touchOcclusionMode=%s\n",
windowInfo->ownerPid, windowInfo->ownerUid,
millis(windowInfo->dispatchingTimeout),
- toString(windowInfo->token != nullptr),
+ binderToString(windowInfo->token).c_str(),
toString(windowInfo->touchOcclusionMode).c_str());
windowInfo->transform.dump(dump, "transform", INDENT4);
}
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 2246d47..aaf1214 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -93,6 +93,7 @@
status_t start() override;
status_t stop() override;
+ void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override{};
void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
void notifyKey(const NotifyKeyArgs* args) override;
void notifyMotion(const NotifyMotionArgs* args) override;
diff --git a/services/inputflinger/include/InputListener.h b/services/inputflinger/include/InputListener.h
index 1bb1968..d1b86c8 100644
--- a/services/inputflinger/include/InputListener.h
+++ b/services/inputflinger/include/InputListener.h
@@ -37,6 +37,7 @@
InputListenerInterface& operator=(const InputListenerInterface&) = delete;
virtual ~InputListenerInterface() { }
+ virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) = 0;
virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) = 0;
virtual void notifyKey(const NotifyKeyArgs* args) = 0;
virtual void notifyMotion(const NotifyMotionArgs* args) = 0;
@@ -58,6 +59,7 @@
public:
explicit QueuedInputListener(InputListenerInterface& innerListener);
+ virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
virtual void notifyKey(const NotifyKeyArgs* args) override;
virtual void notifyMotion(const NotifyMotionArgs* args) override;
diff --git a/services/inputflinger/include/NotifyArgs.h b/services/inputflinger/include/NotifyArgs.h
index c46f905..f12482b 100644
--- a/services/inputflinger/include/NotifyArgs.h
+++ b/services/inputflinger/include/NotifyArgs.h
@@ -24,6 +24,20 @@
namespace android {
+/* Describes a change in any of the connected input devices. */
+struct NotifyInputDevicesChangedArgs {
+ int32_t id;
+ std::vector<InputDeviceInfo> inputDeviceInfos;
+
+ inline NotifyInputDevicesChangedArgs() {}
+
+ NotifyInputDevicesChangedArgs(int32_t id, std::vector<InputDeviceInfo> infos);
+
+ bool operator==(const NotifyInputDevicesChangedArgs& rhs) const = default;
+
+ NotifyInputDevicesChangedArgs(const NotifyInputDevicesChangedArgs& other) = default;
+};
+
/* Describes a configuration change event. */
struct NotifyConfigurationChangedArgs {
int32_t id;
@@ -183,7 +197,6 @@
/* Describes a change in the state of Pointer Capture. */
struct NotifyPointerCaptureChangedArgs {
- // The sequence number of the Pointer Capture request, if enabled.
int32_t id;
nsecs_t eventTime;
@@ -211,9 +224,10 @@
NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other) = default;
};
-using NotifyArgs = std::variant<NotifyConfigurationChangedArgs, NotifyKeyArgs, NotifyMotionArgs,
- NotifySensorArgs, NotifySwitchArgs, NotifyDeviceResetArgs,
- NotifyPointerCaptureChangedArgs, NotifyVibratorStateArgs>;
+using NotifyArgs =
+ std::variant<NotifyInputDevicesChangedArgs, NotifyConfigurationChangedArgs, NotifyKeyArgs,
+ NotifyMotionArgs, NotifySensorArgs, NotifySwitchArgs, NotifyDeviceResetArgs,
+ NotifyPointerCaptureChangedArgs, NotifyVibratorStateArgs>;
const char* toString(const NotifyArgs& args);
diff --git a/services/inputflinger/include/UnwantedInteractionBlockerInterface.h b/services/inputflinger/include/UnwantedInteractionBlockerInterface.h
index 1a6f847..64c6114 100644
--- a/services/inputflinger/include/UnwantedInteractionBlockerInterface.h
+++ b/services/inputflinger/include/UnwantedInteractionBlockerInterface.h
@@ -27,23 +27,13 @@
*/
class UnwantedInteractionBlockerInterface : public InputListenerInterface {
public:
- /* Notifies the input reader policy that some input devices have changed
- * and provides information about all current input devices.
- * Important! This call should happen on the same thread as the calls to the
- * InputListenerInterface methods.
- * That is, same thread should call 'notifyMotion' and 'notifyInputDevicesChanged' and
- * 'notifyDeviceReset'. If this architecture changes, we will need to make the implementation
- * of this interface thread-safe.
- */
- virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) = 0;
-
/**
* Dump the state of the interaction blocker.
* This method may be called on any thread (usually by the input manager on a binder thread).
*/
virtual void dump(std::string& dump) = 0;
- /* Called by the heatbeat to ensures that the blocker has not deadlocked. */
+ /* Called by the heartbeat to ensures that the blocker has not deadlocked. */
virtual void monitor() = 0;
UnwantedInteractionBlockerInterface() {}
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index ccf4118..b5ee044 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -146,98 +146,23 @@
}
}
-void InputDevice::addEventHubDevice(int32_t eventHubId, bool populateMappers) {
+void InputDevice::addEmptyEventHubDevice(int32_t eventHubId) {
if (mDevices.find(eventHubId) != mDevices.end()) {
return;
}
std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
- ftl::Flags<InputDeviceClass> classes = contextPtr->getDeviceClasses();
std::vector<std::unique_ptr<InputMapper>> mappers;
- // Check if we should skip population
- if (!populateMappers) {
- mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
+ mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
+}
+
+void InputDevice::addEventHubDevice(int32_t eventHubId,
+ const InputReaderConfiguration& readerConfig) {
+ if (mDevices.find(eventHubId) != mDevices.end()) {
return;
}
-
- // Switch-like devices.
- if (classes.test(InputDeviceClass::SWITCH)) {
- mappers.push_back(std::make_unique<SwitchInputMapper>(*contextPtr));
- }
-
- // Scroll wheel-like devices.
- if (classes.test(InputDeviceClass::ROTARY_ENCODER)) {
- mappers.push_back(std::make_unique<RotaryEncoderInputMapper>(*contextPtr));
- }
-
- // Vibrator-like devices.
- if (classes.test(InputDeviceClass::VIBRATOR)) {
- mappers.push_back(std::make_unique<VibratorInputMapper>(*contextPtr));
- }
-
- // Battery-like devices or light-containing devices.
- // PeripheralController will be created with associated EventHub device.
- if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {
- mController = std::make_unique<PeripheralController>(*contextPtr);
- }
-
- // Keyboard-like devices.
- uint32_t keyboardSource = 0;
- int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC;
- if (classes.test(InputDeviceClass::KEYBOARD)) {
- keyboardSource |= AINPUT_SOURCE_KEYBOARD;
- }
- if (classes.test(InputDeviceClass::ALPHAKEY)) {
- keyboardType = AINPUT_KEYBOARD_TYPE_ALPHABETIC;
- }
- if (classes.test(InputDeviceClass::DPAD)) {
- keyboardSource |= AINPUT_SOURCE_DPAD;
- }
- if (classes.test(InputDeviceClass::GAMEPAD)) {
- keyboardSource |= AINPUT_SOURCE_GAMEPAD;
- }
-
- if (keyboardSource != 0) {
- mappers.push_back(
- std::make_unique<KeyboardInputMapper>(*contextPtr, keyboardSource, keyboardType));
- }
-
- // Cursor-like devices.
- if (classes.test(InputDeviceClass::CURSOR)) {
- mappers.push_back(std::make_unique<CursorInputMapper>(*contextPtr));
- }
-
- // Touchscreens and touchpad devices.
- static const bool ENABLE_TOUCHPAD_GESTURES_LIBRARY =
- sysprop::InputProperties::enable_touchpad_gestures_library().value_or(true);
- // TODO(b/272518665): Fix the new touchpad stack for Sony DualShock 4 (5c4, 9cc) touchpads, or
- // at least load this setting from the IDC file.
- const InputDeviceIdentifier identifier = contextPtr->getDeviceIdentifier();
- const bool isSonyDualShock4Touchpad = identifier.vendor == 0x054c &&
- (identifier.product == 0x05c4 || identifier.product == 0x09cc);
- if (ENABLE_TOUCHPAD_GESTURES_LIBRARY && classes.test(InputDeviceClass::TOUCHPAD) &&
- classes.test(InputDeviceClass::TOUCH_MT) && !isSonyDualShock4Touchpad) {
- mappers.push_back(std::make_unique<TouchpadInputMapper>(*contextPtr));
- } else if (classes.test(InputDeviceClass::TOUCH_MT)) {
- mappers.push_back(std::make_unique<MultiTouchInputMapper>(*contextPtr));
- } else if (classes.test(InputDeviceClass::TOUCH)) {
- mappers.push_back(std::make_unique<SingleTouchInputMapper>(*contextPtr));
- }
-
- // Joystick-like devices.
- if (classes.test(InputDeviceClass::JOYSTICK)) {
- mappers.push_back(std::make_unique<JoystickInputMapper>(*contextPtr));
- }
-
- // Motion sensor enabled devices.
- if (classes.test(InputDeviceClass::SENSOR)) {
- mappers.push_back(std::make_unique<SensorInputMapper>(*contextPtr));
- }
-
- // External stylus-like devices.
- if (classes.test(InputDeviceClass::EXTERNAL_STYLUS)) {
- mappers.push_back(std::make_unique<ExternalStylusInputMapper>(*contextPtr));
- }
+ std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
+ std::vector<std::unique_ptr<InputMapper>> mappers = createMappers(*contextPtr, readerConfig);
// insert the context into the devices set
mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
@@ -512,6 +437,92 @@
return result;
}
+std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
+ InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig) {
+ ftl::Flags<InputDeviceClass> classes = contextPtr.getDeviceClasses();
+ std::vector<std::unique_ptr<InputMapper>> mappers;
+
+ // Switch-like devices.
+ if (classes.test(InputDeviceClass::SWITCH)) {
+ mappers.push_back(std::make_unique<SwitchInputMapper>(contextPtr, readerConfig));
+ }
+
+ // Scroll wheel-like devices.
+ if (classes.test(InputDeviceClass::ROTARY_ENCODER)) {
+ mappers.push_back(std::make_unique<RotaryEncoderInputMapper>(contextPtr, readerConfig));
+ }
+
+ // Vibrator-like devices.
+ if (classes.test(InputDeviceClass::VIBRATOR)) {
+ mappers.push_back(std::make_unique<VibratorInputMapper>(contextPtr, readerConfig));
+ }
+
+ // Battery-like devices or light-containing devices.
+ // PeripheralController will be created with associated EventHub device.
+ if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {
+ mController = std::make_unique<PeripheralController>(contextPtr);
+ }
+
+ // Keyboard-like devices.
+ uint32_t keyboardSource = 0;
+ int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC;
+ if (classes.test(InputDeviceClass::KEYBOARD)) {
+ keyboardSource |= AINPUT_SOURCE_KEYBOARD;
+ }
+ if (classes.test(InputDeviceClass::ALPHAKEY)) {
+ keyboardType = AINPUT_KEYBOARD_TYPE_ALPHABETIC;
+ }
+ if (classes.test(InputDeviceClass::DPAD)) {
+ keyboardSource |= AINPUT_SOURCE_DPAD;
+ }
+ if (classes.test(InputDeviceClass::GAMEPAD)) {
+ keyboardSource |= AINPUT_SOURCE_GAMEPAD;
+ }
+
+ if (keyboardSource != 0) {
+ mappers.push_back(std::make_unique<KeyboardInputMapper>(contextPtr, readerConfig,
+ keyboardSource, keyboardType));
+ }
+
+ // Cursor-like devices.
+ if (classes.test(InputDeviceClass::CURSOR)) {
+ mappers.push_back(std::make_unique<CursorInputMapper>(contextPtr, readerConfig));
+ }
+
+ // Touchscreens and touchpad devices.
+ static const bool ENABLE_TOUCHPAD_GESTURES_LIBRARY =
+ sysprop::InputProperties::enable_touchpad_gestures_library().value_or(true);
+ // TODO(b/272518665): Fix the new touchpad stack for Sony DualShock 4 (5c4, 9cc) touchpads, or
+ // at least load this setting from the IDC file.
+ const InputDeviceIdentifier identifier = contextPtr.getDeviceIdentifier();
+ const bool isSonyDualShock4Touchpad = identifier.vendor == 0x054c &&
+ (identifier.product == 0x05c4 || identifier.product == 0x09cc);
+ if (ENABLE_TOUCHPAD_GESTURES_LIBRARY && classes.test(InputDeviceClass::TOUCHPAD) &&
+ classes.test(InputDeviceClass::TOUCH_MT) && !isSonyDualShock4Touchpad) {
+ mappers.push_back(std::make_unique<TouchpadInputMapper>(contextPtr, readerConfig));
+ } else if (classes.test(InputDeviceClass::TOUCH_MT)) {
+ mappers.push_back(std::make_unique<MultiTouchInputMapper>(contextPtr, readerConfig));
+ } else if (classes.test(InputDeviceClass::TOUCH)) {
+ mappers.push_back(std::make_unique<SingleTouchInputMapper>(contextPtr, readerConfig));
+ }
+
+ // Joystick-like devices.
+ if (classes.test(InputDeviceClass::JOYSTICK)) {
+ mappers.push_back(std::make_unique<JoystickInputMapper>(contextPtr, readerConfig));
+ }
+
+ // Motion sensor enabled devices.
+ if (classes.test(InputDeviceClass::SENSOR)) {
+ mappers.push_back(std::make_unique<SensorInputMapper>(contextPtr, readerConfig));
+ }
+
+ // External stylus-like devices.
+ if (classes.test(InputDeviceClass::EXTERNAL_STYLUS)) {
+ mappers.push_back(std::make_unique<ExternalStylusInputMapper>(contextPtr, readerConfig));
+ }
+ return mappers;
+}
+
bool InputDevice::markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
uint8_t* outFlags) {
bool result = false;
diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp
index 80459a2..6f54faa 100644
--- a/services/inputflinger/reader/InputReader.cpp
+++ b/services/inputflinger/reader/InputReader.cpp
@@ -157,6 +157,8 @@
if (oldGeneration != mGeneration) {
inputDevicesChanged = true;
inputDevices = getInputDevicesLocked();
+ notifyArgs.emplace_back(
+ NotifyInputDevicesChangedArgs{mContext.getNextId(), inputDevices});
}
} // release lock
@@ -332,7 +334,7 @@
device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
identifier);
}
- device->addEventHubDevice(eventHubId);
+ device->addEventHubDevice(eventHubId, mConfig);
return device;
}
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index ad45cb1..2091e16 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -80,7 +80,8 @@
[[nodiscard]] std::list<NotifyArgs> setEnabled(bool enabled, nsecs_t when);
void dump(std::string& dump, const std::string& eventHubDevStr);
- void addEventHubDevice(int32_t eventHubId, bool populateMappers = true);
+ void addEmptyEventHubDevice(int32_t eventHubId);
+ void addEventHubDevice(int32_t eventHubId, const InputReaderConfiguration& readerConfig);
void removeEventHubDevice(int32_t eventHubId);
[[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
const InputReaderConfiguration& readerConfig,
@@ -137,7 +138,7 @@
template <class T, typename... Args>
T& addMapper(int32_t eventHubId, Args... args) {
// ensure a device entry exists for this eventHubId
- addEventHubDevice(eventHubId, false);
+ addEmptyEventHubDevice(eventHubId);
// create mapper
auto& devicePair = mDevices[eventHubId];
@@ -152,7 +153,7 @@
template <class T>
T& addController(int32_t eventHubId) {
// ensure a device entry exists for this eventHubId
- addEventHubDevice(eventHubId, false);
+ addEmptyEventHubDevice(eventHubId);
// create controller
auto& devicePair = mDevices[eventHubId];
@@ -191,6 +192,9 @@
typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
+ std::vector<std::unique_ptr<InputMapper>> createMappers(
+ InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig);
+
PropertyMap mConfiguration;
// helpers to interate over the devices collection
diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
index 1cc614e..adc893b 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
@@ -68,8 +68,12 @@
// --- CursorInputMapper ---
-CursorInputMapper::CursorInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext), mLastEventTime(std::numeric_limits<nsecs_t>::min()) {}
+CursorInputMapper::CursorInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig),
+ mLastEventTime(std::numeric_limits<nsecs_t>::min()) {
+ configureWithZeroChanges(readerConfig);
+}
CursorInputMapper::~CursorInputMapper() {
if (mPointerController != nullptr) {
@@ -134,119 +138,28 @@
}
std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when,
- const InputReaderConfiguration& config,
+ const InputReaderConfiguration& readerConfig,
uint32_t changes) {
- std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes);
+ std::list<NotifyArgs> out = InputMapper::reconfigure(when, readerConfig, changes);
- if (!changes) { // first time only
- mCursorScrollAccumulator.configure(getDeviceContext());
-
- // Configure basic parameters.
- configureParameters();
-
- // Configure device mode.
- switch (mParameters.mode) {
- case Parameters::Mode::POINTER_RELATIVE:
- // Should not happen during first time configuration.
- ALOGE("Cannot start a device in MODE_POINTER_RELATIVE, starting in MODE_POINTER");
- mParameters.mode = Parameters::Mode::POINTER;
- [[fallthrough]];
- case Parameters::Mode::POINTER:
- mSource = AINPUT_SOURCE_MOUSE;
- mXPrecision = 1.0f;
- mYPrecision = 1.0f;
- mXScale = 1.0f;
- mYScale = 1.0f;
- mPointerController = getContext()->getPointerController(getDeviceId());
- break;
- case Parameters::Mode::NAVIGATION:
- mSource = AINPUT_SOURCE_TRACKBALL;
- mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
- mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
- mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
- mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
- break;
- }
-
- mVWheelScale = 1.0f;
- mHWheelScale = 1.0f;
+ if (!changes) {
+ configureWithZeroChanges(readerConfig);
+ return out;
}
const bool configurePointerCapture = mParameters.mode != Parameters::Mode::NAVIGATION &&
- ((!changes && config.pointerCaptureRequest.enable) ||
- (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE));
+ (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
if (configurePointerCapture) {
- if (config.pointerCaptureRequest.enable) {
- if (mParameters.mode == Parameters::Mode::POINTER) {
- mParameters.mode = Parameters::Mode::POINTER_RELATIVE;
- mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
- // Keep PointerController around in order to preserve the pointer position.
- mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
- } else {
- ALOGE("Cannot request pointer capture, device is not in MODE_POINTER");
- }
- } else {
- if (mParameters.mode == Parameters::Mode::POINTER_RELATIVE) {
- mParameters.mode = Parameters::Mode::POINTER;
- mSource = AINPUT_SOURCE_MOUSE;
- } else {
- ALOGE("Cannot release pointer capture, device is not in MODE_POINTER_RELATIVE");
- }
- }
- bumpGeneration();
- if (changes) {
- out.push_back(NotifyDeviceResetArgs(getContext()->getNextId(), when, getDeviceId()));
- }
+ configureOnPointerCapture(readerConfig);
+ out.push_back(NotifyDeviceResetArgs(getContext()->getNextId(), when, getDeviceId()));
}
- if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED) ||
- configurePointerCapture) {
- if (mParameters.mode == Parameters::Mode::POINTER_RELATIVE) {
- // Disable any acceleration or scaling for the pointer when Pointer Capture is enabled.
- mPointerVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
- mWheelXVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
- mWheelYVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
- } else {
- mPointerVelocityControl.setParameters(config.pointerVelocityControlParameters);
- mWheelXVelocityControl.setParameters(config.wheelVelocityControlParameters);
- mWheelYVelocityControl.setParameters(config.wheelVelocityControlParameters);
- }
+ if ((changes & InputReaderConfiguration::CHANGE_POINTER_SPEED) || configurePointerCapture) {
+ configureOnChangePointerSpeed(readerConfig);
}
- if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO) ||
- configurePointerCapture) {
- const bool isPointer = mParameters.mode == Parameters::Mode::POINTER;
-
- mDisplayId = ADISPLAY_ID_NONE;
- if (auto viewport = mDeviceContext.getAssociatedViewport(); viewport) {
- // This InputDevice is associated with a viewport.
- // Only generate events for the associated display.
- const bool mismatchedPointerDisplay =
- isPointer && (viewport->displayId != mPointerController->getDisplayId());
- mDisplayId = mismatchedPointerDisplay ? std::nullopt
- : std::make_optional(viewport->displayId);
- } else if (isPointer) {
- // The InputDevice is not associated with a viewport, but it controls the mouse pointer.
- mDisplayId = mPointerController->getDisplayId();
- }
-
- mOrientation = ui::ROTATION_0;
- const bool isOrientedDevice =
- (mParameters.orientationAware && mParameters.hasAssociatedDisplay);
- // InputReader works in the un-rotated display coordinate space, so we don't need to do
- // anything if the device is already orientation-aware. If the device is not
- // orientation-aware, then we need to apply the inverse rotation of the display so that
- // when the display rotation is applied later as a part of the per-window transform, we
- // get the expected screen coordinates. When pointer capture is enabled, we do not apply any
- // rotations and report values directly from the input device.
- if (!isOrientedDevice && mDisplayId &&
- mParameters.mode != Parameters::Mode::POINTER_RELATIVE) {
- if (auto viewport = config.getDisplayViewportById(*mDisplayId); viewport) {
- mOrientation = getInverseRotation(viewport->orientation);
- }
- }
-
- bumpGeneration();
+ if ((changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO) || configurePointerCapture) {
+ configureOnChangeDisplayInfo(readerConfig);
}
return out;
}
@@ -511,4 +424,117 @@
return mDisplayId;
}
+void CursorInputMapper::configureWithZeroChanges(const InputReaderConfiguration& readerConfig) {
+ // Configuration with zero changes
+ configureBasicParams();
+ if (mParameters.mode != Parameters::Mode::NAVIGATION &&
+ readerConfig.pointerCaptureRequest.enable) {
+ configureOnPointerCapture(readerConfig);
+ }
+ configureOnChangePointerSpeed(readerConfig);
+ configureOnChangeDisplayInfo(readerConfig);
+}
+
+void CursorInputMapper::configureBasicParams() {
+ mCursorScrollAccumulator.configure(getDeviceContext());
+
+ // Configure basic parameters.
+ configureParameters();
+
+ // Configure device mode.
+ switch (mParameters.mode) {
+ case Parameters::Mode::POINTER_RELATIVE:
+ // Should not happen during first time configuration.
+ ALOGE("Cannot start a device in MODE_POINTER_RELATIVE, starting in MODE_POINTER");
+ mParameters.mode = Parameters::Mode::POINTER;
+ [[fallthrough]];
+ case Parameters::Mode::POINTER:
+ mSource = AINPUT_SOURCE_MOUSE;
+ mXPrecision = 1.0f;
+ mYPrecision = 1.0f;
+ mXScale = 1.0f;
+ mYScale = 1.0f;
+ mPointerController = getContext()->getPointerController(getDeviceId());
+ break;
+ case Parameters::Mode::NAVIGATION:
+ mSource = AINPUT_SOURCE_TRACKBALL;
+ mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
+ mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
+ mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
+ mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
+ break;
+ }
+
+ mVWheelScale = 1.0f;
+ mHWheelScale = 1.0f;
+}
+
+void CursorInputMapper::configureOnPointerCapture(const InputReaderConfiguration& config) {
+ if (config.pointerCaptureRequest.enable) {
+ if (mParameters.mode == Parameters::Mode::POINTER) {
+ mParameters.mode = Parameters::Mode::POINTER_RELATIVE;
+ mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
+ // Keep PointerController around in order to preserve the pointer position.
+ mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
+ } else {
+ ALOGE("Cannot request pointer capture, device is not in MODE_POINTER");
+ }
+ } else {
+ if (mParameters.mode == Parameters::Mode::POINTER_RELATIVE) {
+ mParameters.mode = Parameters::Mode::POINTER;
+ mSource = AINPUT_SOURCE_MOUSE;
+ } else {
+ ALOGE("Cannot release pointer capture, device is not in MODE_POINTER_RELATIVE");
+ }
+ }
+ bumpGeneration();
+}
+
+void CursorInputMapper::configureOnChangePointerSpeed(const InputReaderConfiguration& config) {
+ if (mParameters.mode == Parameters::Mode::POINTER_RELATIVE) {
+ // Disable any acceleration or scaling for the pointer when Pointer Capture is enabled.
+ mPointerVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
+ mWheelXVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
+ mWheelYVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
+ } else {
+ mPointerVelocityControl.setParameters(config.pointerVelocityControlParameters);
+ mWheelXVelocityControl.setParameters(config.wheelVelocityControlParameters);
+ mWheelYVelocityControl.setParameters(config.wheelVelocityControlParameters);
+ }
+}
+
+void CursorInputMapper::configureOnChangeDisplayInfo(const InputReaderConfiguration& config) {
+ const bool isPointer = mParameters.mode == Parameters::Mode::POINTER;
+
+ mDisplayId = ADISPLAY_ID_NONE;
+ if (auto viewport = mDeviceContext.getAssociatedViewport(); viewport) {
+ // This InputDevice is associated with a viewport.
+ // Only generate events for the associated display.
+ const bool mismatchedPointerDisplay =
+ isPointer && (viewport->displayId != mPointerController->getDisplayId());
+ mDisplayId =
+ mismatchedPointerDisplay ? std::nullopt : std::make_optional(viewport->displayId);
+ } else if (isPointer) {
+ // The InputDevice is not associated with a viewport, but it controls the mouse pointer.
+ mDisplayId = mPointerController->getDisplayId();
+ }
+
+ mOrientation = ui::ROTATION_0;
+ const bool isOrientedDevice =
+ (mParameters.orientationAware && mParameters.hasAssociatedDisplay);
+ // InputReader works in the un-rotated display coordinate space, so we don't need to do
+ // anything if the device is already orientation-aware. If the device is not
+ // orientation-aware, then we need to apply the inverse rotation of the display so that
+ // when the display rotation is applied later as a part of the per-window transform, we
+ // get the expected screen coordinates. When pointer capture is enabled, we do not apply any
+ // rotations and report values directly from the input device.
+ if (!isOrientedDevice && mDisplayId && mParameters.mode != Parameters::Mode::POINTER_RELATIVE) {
+ if (auto viewport = config.getDisplayViewportById(*mDisplayId); viewport) {
+ mOrientation = getInverseRotation(viewport->orientation);
+ }
+ }
+
+ bumpGeneration();
+}
+
} // namespace android
diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h
index 5f7a3ad..a7cdd51 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.h
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.h
@@ -53,14 +53,15 @@
class CursorInputMapper : public InputMapper {
public:
- explicit CursorInputMapper(InputDeviceContext& deviceContext);
+ explicit CursorInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
virtual ~CursorInputMapper();
virtual uint32_t getSources() const override;
virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
virtual void dump(std::string& dump) override;
[[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when,
- const InputReaderConfiguration& config,
+ const InputReaderConfiguration& readerConfig,
uint32_t changes) override;
[[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
[[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override;
@@ -126,6 +127,11 @@
void configureParameters();
void dumpParameters(std::string& dump);
+ void configureWithZeroChanges(const InputReaderConfiguration& readerConfig);
+ void configureBasicParams();
+ void configureOnPointerCapture(const InputReaderConfiguration& config);
+ void configureOnChangePointerSpeed(const InputReaderConfiguration& config);
+ void configureOnChangeDisplayInfo(const InputReaderConfiguration& config);
[[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when, nsecs_t readTime);
};
diff --git a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp
index bbb641e..7100f88 100644
--- a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp
@@ -23,8 +23,9 @@
namespace android {
-ExternalStylusInputMapper::ExternalStylusInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext), mTouchButtonAccumulator(deviceContext) {}
+ExternalStylusInputMapper::ExternalStylusInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig), mTouchButtonAccumulator(deviceContext) {}
uint32_t ExternalStylusInputMapper::getSources() const {
return AINPUT_SOURCE_STYLUS;
diff --git a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h
index 3eac10d..7f926a7 100644
--- a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h
+++ b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h
@@ -26,7 +26,8 @@
class ExternalStylusInputMapper : public InputMapper {
public:
- explicit ExternalStylusInputMapper(InputDeviceContext& deviceContext);
+ explicit ExternalStylusInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
virtual ~ExternalStylusInputMapper() = default;
uint32_t getSources() const override;
diff --git a/services/inputflinger/reader/mapper/InputMapper.cpp b/services/inputflinger/reader/mapper/InputMapper.cpp
index 5dd7bc4..bd86a5a 100644
--- a/services/inputflinger/reader/mapper/InputMapper.cpp
+++ b/services/inputflinger/reader/mapper/InputMapper.cpp
@@ -25,7 +25,9 @@
namespace android {
-InputMapper::InputMapper(InputDeviceContext& deviceContext) : mDeviceContext(deviceContext) {}
+InputMapper::InputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : mDeviceContext(deviceContext) {}
InputMapper::~InputMapper() {}
diff --git a/services/inputflinger/reader/mapper/InputMapper.h b/services/inputflinger/reader/mapper/InputMapper.h
index ab573f0..211be9f 100644
--- a/services/inputflinger/reader/mapper/InputMapper.h
+++ b/services/inputflinger/reader/mapper/InputMapper.h
@@ -31,16 +31,16 @@
* different classes of events.
*
* InputMapper lifecycle:
- * - create
- * - configure with 0 changes
+ * - create and configure with 0 changes
* - reset
- * - process, process, process (may occasionally reconfigure with non-zero changes or reset)
+ * - process, process, process (may occasionally reconfigure or reset)
* - reset
* - destroy
*/
class InputMapper {
public:
- explicit InputMapper(InputDeviceContext& deviceContext);
+ explicit InputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
virtual ~InputMapper();
inline int32_t getDeviceId() { return mDeviceContext.getId(); }
diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
index 3e840ee..3450f86 100644
--- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
@@ -20,8 +20,9 @@
namespace android {
-JoystickInputMapper::JoystickInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext) {}
+JoystickInputMapper::JoystickInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig) {}
JoystickInputMapper::~JoystickInputMapper() {}
diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.h b/services/inputflinger/reader/mapper/JoystickInputMapper.h
index 6f1c6b7..c9e92de 100644
--- a/services/inputflinger/reader/mapper/JoystickInputMapper.h
+++ b/services/inputflinger/reader/mapper/JoystickInputMapper.h
@@ -22,7 +22,8 @@
class JoystickInputMapper : public InputMapper {
public:
- explicit JoystickInputMapper(InputDeviceContext& deviceContext);
+ explicit JoystickInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
virtual ~JoystickInputMapper();
virtual uint32_t getSources() const override;
diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
index f8dd3a8..63ea3a8 100644
--- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
@@ -63,9 +63,10 @@
// --- KeyboardInputMapper ---
-KeyboardInputMapper::KeyboardInputMapper(InputDeviceContext& deviceContext, uint32_t source,
- int32_t keyboardType)
- : InputMapper(deviceContext), mSource(source), mKeyboardType(keyboardType) {}
+KeyboardInputMapper::KeyboardInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig,
+ uint32_t source, int32_t keyboardType)
+ : InputMapper(deviceContext, readerConfig), mSource(source), mKeyboardType(keyboardType) {}
uint32_t KeyboardInputMapper::getSources() const {
return mSource;
diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.h b/services/inputflinger/reader/mapper/KeyboardInputMapper.h
index 0cb130d..25fad57 100644
--- a/services/inputflinger/reader/mapper/KeyboardInputMapper.h
+++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.h
@@ -23,7 +23,9 @@
class KeyboardInputMapper : public InputMapper {
public:
- KeyboardInputMapper(InputDeviceContext& deviceContext, uint32_t source, int32_t keyboardType);
+ KeyboardInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig, uint32_t source,
+ int32_t keyboardType);
~KeyboardInputMapper() override = default;
uint32_t getSources() const override;
diff --git a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp
index e871288..9c87c62 100644
--- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp
@@ -28,8 +28,9 @@
// --- MultiTouchInputMapper ---
-MultiTouchInputMapper::MultiTouchInputMapper(InputDeviceContext& deviceContext)
- : TouchInputMapper(deviceContext) {}
+MultiTouchInputMapper::MultiTouchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : TouchInputMapper(deviceContext, readerConfig) {}
MultiTouchInputMapper::~MultiTouchInputMapper() {}
diff --git a/services/inputflinger/reader/mapper/MultiTouchInputMapper.h b/services/inputflinger/reader/mapper/MultiTouchInputMapper.h
index 5f8bccf..a617420 100644
--- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.h
@@ -23,7 +23,8 @@
class MultiTouchInputMapper : public TouchInputMapper {
public:
- explicit MultiTouchInputMapper(InputDeviceContext& deviceContext);
+ explicit MultiTouchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
~MultiTouchInputMapper() override;
[[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
index b181aa0..2ffa5cd 100644
--- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
@@ -26,8 +26,9 @@
namespace android {
-RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext), mOrientation(ui::ROTATION_0) {
+RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig), mOrientation(ui::ROTATION_0) {
mSource = AINPUT_SOURCE_ROTARY_ENCODER;
}
diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h
index 37c9442..8feaf8e 100644
--- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h
+++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h
@@ -25,7 +25,8 @@
class RotaryEncoderInputMapper : public InputMapper {
public:
- explicit RotaryEncoderInputMapper(InputDeviceContext& deviceContext);
+ explicit RotaryEncoderInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
virtual ~RotaryEncoderInputMapper();
virtual uint32_t getSources() const override;
diff --git a/services/inputflinger/reader/mapper/SensorInputMapper.cpp b/services/inputflinger/reader/mapper/SensorInputMapper.cpp
index f8a520d..f7f23a4 100644
--- a/services/inputflinger/reader/mapper/SensorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/SensorInputMapper.cpp
@@ -52,8 +52,9 @@
}
}
-SensorInputMapper::SensorInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext) {}
+SensorInputMapper::SensorInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig) {}
SensorInputMapper::~SensorInputMapper() {}
diff --git a/services/inputflinger/reader/mapper/SensorInputMapper.h b/services/inputflinger/reader/mapper/SensorInputMapper.h
index fa36ab3..2f3a396 100644
--- a/services/inputflinger/reader/mapper/SensorInputMapper.h
+++ b/services/inputflinger/reader/mapper/SensorInputMapper.h
@@ -27,7 +27,8 @@
class SensorInputMapper : public InputMapper {
public:
- explicit SensorInputMapper(InputDeviceContext& deviceContext);
+ explicit SensorInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
~SensorInputMapper() override;
uint32_t getSources() const override;
diff --git a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp
index f13417a..ed0e270 100644
--- a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp
@@ -18,8 +18,9 @@
namespace android {
-SingleTouchInputMapper::SingleTouchInputMapper(InputDeviceContext& deviceContext)
- : TouchInputMapper(deviceContext) {}
+SingleTouchInputMapper::SingleTouchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : TouchInputMapper(deviceContext, readerConfig) {}
SingleTouchInputMapper::~SingleTouchInputMapper() {}
diff --git a/services/inputflinger/reader/mapper/SingleTouchInputMapper.h b/services/inputflinger/reader/mapper/SingleTouchInputMapper.h
index 662e6bc..9341007 100644
--- a/services/inputflinger/reader/mapper/SingleTouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/SingleTouchInputMapper.h
@@ -23,7 +23,8 @@
class SingleTouchInputMapper : public TouchInputMapper {
public:
- explicit SingleTouchInputMapper(InputDeviceContext& deviceContext);
+ explicit SingleTouchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
~SingleTouchInputMapper() override;
[[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
diff --git a/services/inputflinger/reader/mapper/SwitchInputMapper.cpp b/services/inputflinger/reader/mapper/SwitchInputMapper.cpp
index c4564a4..05338da 100644
--- a/services/inputflinger/reader/mapper/SwitchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/SwitchInputMapper.cpp
@@ -20,8 +20,9 @@
namespace android {
-SwitchInputMapper::SwitchInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext), mSwitchValues(0), mUpdatedSwitchMask(0) {}
+SwitchInputMapper::SwitchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig), mSwitchValues(0), mUpdatedSwitchMask(0) {}
SwitchInputMapper::~SwitchInputMapper() {}
diff --git a/services/inputflinger/reader/mapper/SwitchInputMapper.h b/services/inputflinger/reader/mapper/SwitchInputMapper.h
index 06d6504..7ec282b 100644
--- a/services/inputflinger/reader/mapper/SwitchInputMapper.h
+++ b/services/inputflinger/reader/mapper/SwitchInputMapper.h
@@ -22,7 +22,8 @@
class SwitchInputMapper : public InputMapper {
public:
- explicit SwitchInputMapper(InputDeviceContext& deviceContext);
+ explicit SwitchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
virtual ~SwitchInputMapper();
virtual uint32_t getSources() const override;
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index 9a426bf..d09bc65 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -121,8 +121,9 @@
// --- TouchInputMapper ---
-TouchInputMapper::TouchInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext),
+TouchInputMapper::TouchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig),
mTouchButtonAccumulator(deviceContext),
mSource(0),
mDeviceMode(DeviceMode::DISABLED),
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h
index 0e8ff4b..e7d66a1 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.h
@@ -146,7 +146,8 @@
class TouchInputMapper : public InputMapper {
public:
- explicit TouchInputMapper(InputDeviceContext& deviceContext);
+ explicit TouchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
~TouchInputMapper() override;
uint32_t getSources() const override;
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
index 8135071..5a1ced4 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
@@ -57,7 +57,7 @@
{std::numeric_limits<double>::infinity(), 15.04, -857.758},
};
-const std::vector<double> sensitivityFactors = {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20};
+const std::vector<double> sensitivityFactors = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18};
std::vector<double> createAccelerationCurveForSensitivity(int32_t sensitivity,
size_t propertySize) {
@@ -169,8 +169,9 @@
} // namespace
-TouchpadInputMapper::TouchpadInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext),
+TouchpadInputMapper::TouchpadInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig),
mGestureInterpreter(NewGestureInterpreter(), DeleteGestureInterpreter),
mPointerController(getContext()->getPointerController(getDeviceId())),
mStateConverter(deviceContext),
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
index 27cdde1..e051097 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
@@ -37,7 +37,8 @@
class TouchpadInputMapper : public InputMapper {
public:
- explicit TouchpadInputMapper(InputDeviceContext& deviceContext);
+ explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
~TouchpadInputMapper();
uint32_t getSources() const override;
diff --git a/services/inputflinger/reader/mapper/VibratorInputMapper.cpp b/services/inputflinger/reader/mapper/VibratorInputMapper.cpp
index 2c77fc4..8d78d0f 100644
--- a/services/inputflinger/reader/mapper/VibratorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/VibratorInputMapper.cpp
@@ -20,8 +20,9 @@
namespace android {
-VibratorInputMapper::VibratorInputMapper(InputDeviceContext& deviceContext)
- : InputMapper(deviceContext), mVibrating(false), mSequence(0) {}
+VibratorInputMapper::VibratorInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig)
+ : InputMapper(deviceContext, readerConfig), mVibrating(false), mSequence(0) {}
VibratorInputMapper::~VibratorInputMapper() {}
diff --git a/services/inputflinger/reader/mapper/VibratorInputMapper.h b/services/inputflinger/reader/mapper/VibratorInputMapper.h
index e665973..384c075 100644
--- a/services/inputflinger/reader/mapper/VibratorInputMapper.h
+++ b/services/inputflinger/reader/mapper/VibratorInputMapper.h
@@ -22,7 +22,8 @@
class VibratorInputMapper : public InputMapper {
public:
- explicit VibratorInputMapper(InputDeviceContext& deviceContext);
+ explicit VibratorInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
virtual ~VibratorInputMapper();
virtual uint32_t getSources() const override;
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index fb808eb..5e51bfc 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -213,7 +213,7 @@
void assertFilterInputEventWasCalled(const NotifyKeyArgs& args) {
assertFilterInputEventWasCalledInternal([&args](const InputEvent& event) {
- ASSERT_EQ(event.getType(), AINPUT_EVENT_TYPE_KEY);
+ ASSERT_EQ(event.getType(), InputEventType::KEY);
EXPECT_EQ(event.getDisplayId(), args.displayId);
const auto& keyEvent = static_cast<const KeyEvent&>(event);
@@ -224,7 +224,7 @@
void assertFilterInputEventWasCalled(const NotifyMotionArgs& args, vec2 point) {
assertFilterInputEventWasCalledInternal([&](const InputEvent& event) {
- ASSERT_EQ(event.getType(), AINPUT_EVENT_TYPE_MOTION);
+ ASSERT_EQ(event.getType(), InputEventType::MOTION);
EXPECT_EQ(event.getDisplayId(), args.displayId);
const auto& motionEvent = static_cast<const MotionEvent&>(event);
@@ -530,17 +530,21 @@
bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override {
std::scoped_lock lock(mLock);
switch (inputEvent->getType()) {
- case AINPUT_EVENT_TYPE_KEY: {
+ case InputEventType::KEY: {
const KeyEvent* keyEvent = static_cast<const KeyEvent*>(inputEvent);
mFilteredEvent = std::make_unique<KeyEvent>(*keyEvent);
break;
}
- case AINPUT_EVENT_TYPE_MOTION: {
+ case InputEventType::MOTION: {
const MotionEvent* motionEvent = static_cast<const MotionEvent*>(inputEvent);
mFilteredEvent = std::make_unique<MotionEvent>(*motionEvent);
break;
}
+ default: {
+ ADD_FAILURE() << "Should only filter keys or motions";
+ break;
+ }
}
return true;
}
@@ -924,7 +928,7 @@
ASSERT_EQ(OK, status);
}
- void consumeEvent(int32_t expectedEventType, int32_t expectedAction,
+ void consumeEvent(InputEventType expectedEventType, int32_t expectedAction,
std::optional<int32_t> expectedDisplayId,
std::optional<int32_t> expectedFlags) {
InputEvent* event = consume();
@@ -932,15 +936,15 @@
ASSERT_NE(nullptr, event) << mName.c_str()
<< ": consumer should have returned non-NULL event.";
ASSERT_EQ(expectedEventType, event->getType())
- << mName.c_str() << " expected " << inputEventTypeToString(expectedEventType)
- << " event, got " << inputEventTypeToString(event->getType()) << " event";
+ << mName.c_str() << " expected " << ftl::enum_string(expectedEventType)
+ << " event, got " << *event;
if (expectedDisplayId.has_value()) {
EXPECT_EQ(expectedDisplayId, event->getDisplayId());
}
switch (expectedEventType) {
- case AINPUT_EVENT_TYPE_KEY: {
+ case InputEventType::KEY: {
const KeyEvent& keyEvent = static_cast<const KeyEvent&>(*event);
EXPECT_EQ(expectedAction, keyEvent.getAction());
if (expectedFlags.has_value()) {
@@ -948,7 +952,7 @@
}
break;
}
- case AINPUT_EVENT_TYPE_MOTION: {
+ case InputEventType::MOTION: {
const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
assertMotionAction(expectedAction, motionEvent.getAction());
@@ -957,21 +961,18 @@
}
break;
}
- case AINPUT_EVENT_TYPE_FOCUS: {
+ case InputEventType::FOCUS: {
FAIL() << "Use 'consumeFocusEvent' for FOCUS events";
}
- case AINPUT_EVENT_TYPE_CAPTURE: {
+ case InputEventType::CAPTURE: {
FAIL() << "Use 'consumeCaptureEvent' for CAPTURE events";
}
- case AINPUT_EVENT_TYPE_TOUCH_MODE: {
+ case InputEventType::TOUCH_MODE: {
FAIL() << "Use 'consumeTouchModeEvent' for TOUCH_MODE events";
}
- case AINPUT_EVENT_TYPE_DRAG: {
+ case InputEventType::DRAG: {
FAIL() << "Use 'consumeDragEvent' for DRAG events";
}
- default: {
- FAIL() << mName.c_str() << ": invalid event type: " << expectedEventType;
- }
}
}
@@ -983,9 +984,8 @@
return nullptr;
}
- if (event->getType() != AINPUT_EVENT_TYPE_MOTION) {
- ADD_FAILURE() << mName << " expected a MotionEvent, got "
- << inputEventTypeToString(event->getType()) << " event";
+ if (event->getType() != InputEventType::MOTION) {
+ ADD_FAILURE() << mName << " expected a MotionEvent, got " << *event;
return nullptr;
}
return static_cast<MotionEvent*>(event);
@@ -1001,9 +1001,8 @@
InputEvent* event = consume();
ASSERT_NE(nullptr, event) << mName.c_str()
<< ": consumer should have returned non-NULL event.";
- ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType())
- << "Got " << inputEventTypeToString(event->getType())
- << " event instead of FOCUS event";
+ ASSERT_EQ(InputEventType::FOCUS, event->getType())
+ << "Instead of FocusEvent, got " << *event;
ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId())
<< mName.c_str() << ": event displayId should always be NONE.";
@@ -1016,9 +1015,8 @@
const InputEvent* event = consume();
ASSERT_NE(nullptr, event) << mName.c_str()
<< ": consumer should have returned non-NULL event.";
- ASSERT_EQ(AINPUT_EVENT_TYPE_CAPTURE, event->getType())
- << "Got " << inputEventTypeToString(event->getType())
- << " event instead of CAPTURE event";
+ ASSERT_EQ(InputEventType::CAPTURE, event->getType())
+ << "Instead of CaptureEvent, got " << *event;
ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId())
<< mName.c_str() << ": event displayId should always be NONE.";
@@ -1031,9 +1029,7 @@
const InputEvent* event = consume();
ASSERT_NE(nullptr, event) << mName.c_str()
<< ": consumer should have returned non-NULL event.";
- ASSERT_EQ(AINPUT_EVENT_TYPE_DRAG, event->getType())
- << "Got " << inputEventTypeToString(event->getType())
- << " event instead of DRAG event";
+ ASSERT_EQ(InputEventType::DRAG, event->getType()) << "Instead of DragEvent, got " << *event;
EXPECT_EQ(ADISPLAY_ID_NONE, event->getDisplayId())
<< mName.c_str() << ": event displayId should always be NONE.";
@@ -1048,9 +1044,8 @@
const InputEvent* event = consume();
ASSERT_NE(nullptr, event) << mName.c_str()
<< ": consumer should have returned non-NULL event.";
- ASSERT_EQ(AINPUT_EVENT_TYPE_TOUCH_MODE, event->getType())
- << "Got " << inputEventTypeToString(event->getType())
- << " event instead of TOUCH_MODE event";
+ ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType())
+ << "Instead of TouchModeEvent, got " << *event;
ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId())
<< mName.c_str() << ": event displayId should always be NONE.";
@@ -1063,23 +1058,23 @@
if (event == nullptr) {
return;
}
- if (event->getType() == AINPUT_EVENT_TYPE_KEY) {
+ if (event->getType() == InputEventType::KEY) {
KeyEvent& keyEvent = static_cast<KeyEvent&>(*event);
ADD_FAILURE() << "Received key event "
<< KeyEvent::actionToString(keyEvent.getAction());
- } else if (event->getType() == AINPUT_EVENT_TYPE_MOTION) {
+ } else if (event->getType() == InputEventType::MOTION) {
MotionEvent& motionEvent = static_cast<MotionEvent&>(*event);
ADD_FAILURE() << "Received motion event "
<< MotionEvent::actionToString(motionEvent.getAction());
- } else if (event->getType() == AINPUT_EVENT_TYPE_FOCUS) {
+ } else if (event->getType() == InputEventType::FOCUS) {
FocusEvent& focusEvent = static_cast<FocusEvent&>(*event);
ADD_FAILURE() << "Received focus event, hasFocus = "
<< (focusEvent.getHasFocus() ? "true" : "false");
- } else if (event->getType() == AINPUT_EVENT_TYPE_CAPTURE) {
+ } else if (event->getType() == InputEventType::CAPTURE) {
const auto& captureEvent = static_cast<CaptureEvent&>(*event);
ADD_FAILURE() << "Received capture event, pointerCaptureEnabled = "
<< (captureEvent.getPointerCaptureEnabled() ? "true" : "false");
- } else if (event->getType() == AINPUT_EVENT_TYPE_TOUCH_MODE) {
+ } else if (event->getType() == InputEventType::TOUCH_MODE) {
const auto& touchModeEvent = static_cast<TouchModeEvent&>(*event);
ADD_FAILURE() << "Received touch mode event, inTouchMode = "
<< (touchModeEvent.isInTouchMode() ? "true" : "false");
@@ -1239,12 +1234,11 @@
void setWindowOffset(float offsetX, float offsetY) { mInfo.transform.set(offsetX, offsetY); }
void consumeKeyDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) {
- consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId,
- expectedFlags);
+ consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId, expectedFlags);
}
void consumeKeyUp(int32_t expectedDisplayId, int32_t expectedFlags = 0) {
- consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, expectedDisplayId, expectedFlags);
+ consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, expectedDisplayId, expectedFlags);
}
void consumeMotionCancel(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT,
@@ -1266,7 +1260,7 @@
void consumeAnyMotionDown(std::optional<int32_t> expectedDisplayId = std::nullopt,
std::optional<int32_t> expectedFlags = std::nullopt) {
- consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN, expectedDisplayId,
+ consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_DOWN, expectedDisplayId,
expectedFlags);
}
@@ -1275,25 +1269,25 @@
int32_t expectedFlags = 0) {
int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN |
(pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
- consumeEvent(AINPUT_EVENT_TYPE_MOTION, action, expectedDisplayId, expectedFlags);
+ consumeEvent(InputEventType::MOTION, action, expectedDisplayId, expectedFlags);
}
void consumeMotionPointerUp(int32_t pointerIdx, int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT,
int32_t expectedFlags = 0) {
int32_t action = AMOTION_EVENT_ACTION_POINTER_UP |
(pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
- consumeEvent(AINPUT_EVENT_TYPE_MOTION, action, expectedDisplayId, expectedFlags);
+ consumeEvent(InputEventType::MOTION, action, expectedDisplayId, expectedFlags);
}
void consumeMotionUp(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT,
int32_t expectedFlags = 0) {
- consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_UP, expectedDisplayId,
+ consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_UP, expectedDisplayId,
expectedFlags);
}
void consumeMotionOutside(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT,
int32_t expectedFlags = 0) {
- consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE, expectedDisplayId,
+ consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE, expectedDisplayId,
expectedFlags);
}
@@ -1301,7 +1295,7 @@
int32_t expectedFlags = 0) {
InputEvent* event = consume();
ASSERT_NE(nullptr, event);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType());
+ ASSERT_EQ(InputEventType::MOTION, event->getType());
const MotionEvent& motionEvent = static_cast<MotionEvent&>(*event);
EXPECT_EQ(AMOTION_EVENT_ACTION_OUTSIDE, motionEvent.getActionMasked());
EXPECT_EQ(0.f, motionEvent.getRawPointerCoords(0)->getX());
@@ -1326,7 +1320,7 @@
ASSERT_THAT(*motionEvent, matcher);
}
- void consumeEvent(int32_t expectedEventType, int32_t expectedAction,
+ void consumeEvent(InputEventType expectedEventType, int32_t expectedAction,
std::optional<int32_t> expectedDisplayId,
std::optional<int32_t> expectedFlags) {
ASSERT_NE(mInputReceiver, nullptr) << "Invalid consume event on window with no receiver";
@@ -1375,9 +1369,8 @@
ADD_FAILURE() << "Consume failed : no event";
return nullptr;
}
- if (event->getType() != AINPUT_EVENT_TYPE_MOTION) {
- ADD_FAILURE() << "Instead of motion event, got "
- << inputEventTypeToString(event->getType());
+ if (event->getType() != InputEventType::MOTION) {
+ ADD_FAILURE() << "Instead of motion event, got " << *event;
return nullptr;
}
return static_cast<MotionEvent*>(event);
@@ -3678,7 +3671,7 @@
// on the app side.
NotifyDeviceResetArgs args(/*id=*/10, /*eventTime=*/20, DEVICE_ID);
mDispatcher->notifyDeviceReset(&args);
- window->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT,
+ window->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT,
AKEY_EVENT_FLAG_CANCELED);
}
@@ -4752,8 +4745,8 @@
sp<IBinder> getToken() { return mInputReceiver->getToken(); }
void consumeKeyDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) {
- mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_DOWN,
- expectedDisplayId, expectedFlags);
+ mInputReceiver->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId,
+ expectedFlags);
}
std::optional<int32_t> receiveEvent() { return mInputReceiver->receiveEvent(); }
@@ -4761,17 +4754,17 @@
void finishEvent(uint32_t consumeSeq) { return mInputReceiver->finishEvent(consumeSeq); }
void consumeMotionDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) {
- mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN,
+ mInputReceiver->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_DOWN,
expectedDisplayId, expectedFlags);
}
void consumeMotionMove(int32_t expectedDisplayId, int32_t expectedFlags = 0) {
- mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_MOVE,
+ mInputReceiver->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_MOVE,
expectedDisplayId, expectedFlags);
}
void consumeMotionUp(int32_t expectedDisplayId, int32_t expectedFlags = 0) {
- mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_UP,
+ mInputReceiver->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_UP,
expectedDisplayId, expectedFlags);
}
@@ -4785,7 +4778,7 @@
void consumeMotionPointerDown(int32_t pointerIdx) {
int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN |
(pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
- mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_MOTION, action, ADISPLAY_ID_DEFAULT,
+ mInputReceiver->consumeEvent(InputEventType::MOTION, action, ADISPLAY_ID_DEFAULT,
/*expectedFlags=*/0);
}
@@ -4795,8 +4788,8 @@
ADD_FAILURE() << "No event was produced";
return nullptr;
}
- if (event->getType() != AINPUT_EVENT_TYPE_MOTION) {
- ADD_FAILURE() << "Received event of type " << event->getType() << " instead of motion";
+ if (event->getType() != InputEventType::MOTION) {
+ ADD_FAILURE() << "Expected MotionEvent, got " << *event;
return nullptr;
}
return static_cast<MotionEvent*>(event);
@@ -4952,7 +4945,7 @@
motionArgs.pointerCoords[0].getX() - 10);
mDispatcher->notifyMotion(&motionArgs);
- window->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_MOVE, ADISPLAY_ID_DEFAULT,
+ window->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_MOVE, ADISPLAY_ID_DEFAULT,
/*expectedFlags=*/0);
}
@@ -5423,8 +5416,7 @@
InputEvent* repeatEvent = mWindow->consume();
ASSERT_NE(nullptr, repeatEvent);
- uint32_t eventType = repeatEvent->getType();
- ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, eventType);
+ ASSERT_EQ(InputEventType::KEY, repeatEvent->getType());
KeyEvent* repeatKeyEvent = static_cast<KeyEvent*>(repeatEvent);
uint32_t eventAction = repeatKeyEvent->getAction();
@@ -5439,7 +5431,7 @@
mDispatcher->notifyKey(&keyArgs);
// Window should receive key down event.
- mWindow->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT,
+ mWindow->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT,
/*expectedFlags=*/0);
}
};
@@ -5612,7 +5604,7 @@
mDispatcher->setInputWindows({{SECOND_DISPLAY_ID, {}}});
// Old focus should receive a cancel event.
- windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE,
+ windowInSecondary->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE,
AKEY_EVENT_FLAG_CANCELED);
// Test inject a key down, should timeout because of no target window.
@@ -5883,7 +5875,7 @@
InputEvent* received = mWindow->consume();
ASSERT_NE(nullptr, received);
ASSERT_EQ(resolvedDeviceId, received->getDeviceId());
- ASSERT_EQ(received->getType(), AINPUT_EVENT_TYPE_KEY);
+ ASSERT_EQ(received->getType(), InputEventType::KEY);
KeyEvent& keyEvent = static_cast<KeyEvent&>(*received);
ASSERT_EQ(flags, keyEvent.getFlags());
}
@@ -5918,7 +5910,7 @@
InputEvent* received = mWindow->consume();
ASSERT_NE(nullptr, received);
ASSERT_EQ(resolvedDeviceId, received->getDeviceId());
- ASSERT_EQ(received->getType(), AINPUT_EVENT_TYPE_MOTION);
+ ASSERT_EQ(received->getType(), InputEventType::MOTION);
MotionEvent& motionEvent = static_cast<MotionEvent&>(*received);
ASSERT_EQ(flags, motionEvent.getFlags());
}
@@ -6099,9 +6091,8 @@
ASSERT_NE(nullptr, event) << name.c_str()
<< ": consumer should have returned non-NULL event.";
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
- << name.c_str() << "expected " << inputEventTypeToString(AINPUT_EVENT_TYPE_MOTION)
- << " event, got " << inputEventTypeToString(event->getType()) << " event";
+ ASSERT_EQ(InputEventType::MOTION, event->getType())
+ << name.c_str() << ": expected MotionEvent, got " << *event;
const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
assertMotionAction(expectedAction, motionEvent.getAction());
@@ -6798,7 +6789,7 @@
FOCUSED_WINDOW_LOCATION))
<< "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
mFocusedWindow->consumeMotionDown();
- mUnfocusedWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE,
+ mUnfocusedWindow->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE,
ADISPLAY_ID_DEFAULT, /*flags=*/0);
// We consumed all events, so no ANR
ASSERT_TRUE(mDispatcher->waitForIdle());
@@ -6872,7 +6863,7 @@
// At the same time, FLAG_WATCH_OUTSIDE_TOUCH targets should not receive any events.
TEST_F(InputDispatcherMultiWindowAnr, DuringAnr_SecondTapIsIgnored) {
tapOnFocusedWindow();
- mUnfocusedWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE,
+ mUnfocusedWindow->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE,
ADISPLAY_ID_DEFAULT, /*flags=*/0);
// Receive the events, but don't respond
std::optional<uint32_t> downEventSequenceNum = mFocusedWindow->receiveEvent(); // ACTION_DOWN
@@ -7001,7 +6992,7 @@
generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
ADISPLAY_ID_DEFAULT, {FOCUSED_WINDOW_LOCATION});
mDispatcher->notifyMotion(&motionArgs);
- mUnfocusedWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE,
+ mUnfocusedWindow->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE,
ADISPLAY_ID_DEFAULT, /*flags=*/0);
// Touch Window 2
@@ -7022,7 +7013,7 @@
ASSERT_TRUE(moveOrCancelSequenceNum);
mFocusedWindow->finishEvent(*moveOrCancelSequenceNum);
ASSERT_NE(nullptr, event);
- ASSERT_EQ(event->getType(), AINPUT_EVENT_TYPE_MOTION);
+ ASSERT_EQ(event->getType(), InputEventType::MOTION);
MotionEvent& motionEvent = static_cast<MotionEvent&>(*event);
if (motionEvent.getAction() == AMOTION_EVENT_ACTION_MOVE) {
mFocusedWindow->consumeMotionCancel();
@@ -8234,7 +8225,7 @@
.displayId(SECOND_DISPLAY_ID)
.pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
.build()));
- windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN,
+ windowInSecondary->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_DOWN,
SECOND_DISPLAY_ID, /*expectedFlag=*/0);
// Update window again.
mDispatcher->setInputWindows({{SECOND_DISPLAY_ID, {windowInSecondary}}});
diff --git a/services/inputflinger/tests/InputMapperTest.h b/services/inputflinger/tests/InputMapperTest.h
index 63ca44c..df601ea 100644
--- a/services/inputflinger/tests/InputMapperTest.h
+++ b/services/inputflinger/tests/InputMapperTest.h
@@ -60,7 +60,8 @@
ftl::Flags<InputDeviceClass> classes, int bus = 0);
template <class T, typename... Args>
T& addMapperAndConfigure(Args... args) {
- T& mapper = mDevice->addMapper<T>(EVENTHUB_ID, args...);
+ T& mapper =
+ mDevice->addMapper<T>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(), args...);
configureDevice(0);
std::list<NotifyArgs> resetArgList = mDevice->reset(ARBITRARY_TIME);
resetArgList += mapper.reset(ARBITRARY_TIME);
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index dcf8557..da3fe5b 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -171,8 +171,9 @@
std::optional<DisplayViewport> mViewport;
public:
- FakeInputMapper(InputDeviceContext& deviceContext, uint32_t sources)
- : InputMapper(deviceContext),
+ FakeInputMapper(InputDeviceContext& deviceContext, const InputReaderConfiguration& readerConfig,
+ uint32_t sources)
+ : InputMapper(deviceContext, readerConfig),
mSources(sources),
mKeyboardType(AINPUT_KEYBOARD_TYPE_NONE),
mMetaState(0),
@@ -603,6 +604,7 @@
mReader->loopOnce();
mReader->loopOnce();
ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyInputDevicesChangedWasCalled());
ASSERT_NO_FATAL_FAILURE(mFakeEventHub->assertQueueIsEmpty());
}
@@ -622,7 +624,9 @@
uint32_t sources,
const PropertyMap* configuration) {
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, name);
- FakeInputMapper& mapper = device->addMapper<FakeInputMapper>(eventHubId, sources);
+ FakeInputMapper& mapper =
+ device->addMapper<FakeInputMapper>(eventHubId,
+ mFakePolicy->getReaderConfiguration(), sources);
mReader->pushNextDevice(device);
addDevice(eventHubId, name, classes, configuration);
return mapper;
@@ -674,8 +678,10 @@
// Add two subdevices to device
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
// Must add at least one mapper or the device will be ignored!
- device->addMapper<FakeInputMapper>(eventHubIds[0], AINPUT_SOURCE_KEYBOARD);
- device->addMapper<FakeInputMapper>(eventHubIds[1], AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubIds[0], mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubIds[1], mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
// Push same device instance for next device to be added, so they'll have same identifier.
mReader->pushNextDevice(device);
@@ -695,8 +701,10 @@
// Add two subdevices to device
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
// Must add at least one mapper or the device will be ignored!
- device->addMapper<FakeInputMapper>(eventHubIds[0], AINPUT_SOURCE_KEYBOARD);
- device->addMapper<FakeInputMapper>(eventHubIds[1], AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubIds[0], mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubIds[1], mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
// Push same device instance for next device to be added, so they'll have same identifier.
mReader->pushNextDevice(device);
@@ -721,7 +729,8 @@
constexpr int32_t eventHubId = 1;
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
// Must add at least one mapper or the device will be ignored!
- device->addMapper<FakeInputMapper>(eventHubId, AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubId, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
mReader->pushNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
@@ -967,7 +976,8 @@
constexpr int32_t eventHubId = 1;
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
// Must add at least one mapper or the device will be ignored!
- device->addMapper<FakeInputMapper>(eventHubId, AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubId, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
mReader->pushNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
@@ -1000,7 +1010,8 @@
constexpr int32_t eventHubId = 1;
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
// Must add at least one mapper or the device will be ignored!
- device->addMapper<FakeInputMapper>(eventHubId, AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubId, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
mReader->pushNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(deviceId, "fake", deviceClass, nullptr));
@@ -1016,7 +1027,8 @@
const char* DEVICE_LOCATION = "USB1";
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
FakeInputMapper& mapper =
- device->addMapper<FakeInputMapper>(eventHubId, AINPUT_SOURCE_TOUCHSCREEN);
+ device->addMapper<FakeInputMapper>(eventHubId, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_TOUCHSCREEN);
mReader->pushNextDevice(device);
const uint8_t hdmi1 = 1;
@@ -1059,8 +1071,10 @@
constexpr int32_t eventHubIds[2] = {END_RESERVED_ID, END_RESERVED_ID + 1};
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
// Must add at least one mapper or the device will be ignored!
- device->addMapper<FakeInputMapper>(eventHubIds[0], AINPUT_SOURCE_KEYBOARD);
- device->addMapper<FakeInputMapper>(eventHubIds[1], AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubIds[0], mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubIds[1], mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
mReader->pushNextDevice(device);
mReader->pushNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubIds[0], "fake1", deviceClass, nullptr));
@@ -1101,9 +1115,13 @@
// Add two subdevices to device
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
FakeInputMapper& mapperDevice1 =
- device->addMapper<FakeInputMapper>(eventHubIds[0], AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubIds[0],
+ mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
FakeInputMapper& mapperDevice2 =
- device->addMapper<FakeInputMapper>(eventHubIds[1], AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeInputMapper>(eventHubIds[1],
+ mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
mReader->pushNextDevice(device);
mReader->pushNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubIds[0], "fake1", deviceClass, nullptr));
@@ -1145,8 +1163,9 @@
class FakeVibratorInputMapper : public FakeInputMapper {
public:
- FakeVibratorInputMapper(InputDeviceContext& deviceContext, uint32_t sources)
- : FakeInputMapper(deviceContext, sources) {}
+ FakeVibratorInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig, uint32_t sources)
+ : FakeInputMapper(deviceContext, readerConfig, sources) {}
std::vector<int32_t> getVibratorIds() override { return getDeviceContext().getVibratorIds(); }
};
@@ -1159,7 +1178,9 @@
const char* DEVICE_LOCATION = "BLUETOOTH";
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
FakeVibratorInputMapper& mapper =
- device->addMapper<FakeVibratorInputMapper>(eventHubId, AINPUT_SOURCE_KEYBOARD);
+ device->addMapper<FakeVibratorInputMapper>(eventHubId,
+ mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
mReader->pushNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
@@ -1324,6 +1345,7 @@
// to the test device will show up in mReader. We wait for those input devices to
// show up before beginning the tests.
ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
+ ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyInputDevicesChangedWasCalled());
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyConfigurationChangedWasCalled());
}
@@ -2362,7 +2384,8 @@
mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, "key", "value");
FakeInputMapper& mapper1 =
- mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD);
+ mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
mapper1.setKeyboardType(AINPUT_KEYBOARD_TYPE_ALPHABETIC);
mapper1.setMetaState(AMETA_ALT_ON);
mapper1.addSupportedKeyCode(AKEYCODE_A);
@@ -2374,7 +2397,8 @@
mapper1.setSwitchState(4, AKEY_STATE_DOWN);
FakeInputMapper& mapper2 =
- mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_TOUCHSCREEN);
+ mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_TOUCHSCREEN);
mapper2.setMetaState(AMETA_SHIFT_ON);
InputReaderConfiguration config;
@@ -2455,7 +2479,8 @@
// 1. Device is disabled if the viewport corresponding to the associated display is not found
// 2. Device is disabled when setEnabled API is called
TEST_F(InputDeviceTest, Configure_AssignsDisplayPort) {
- mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_TOUCHSCREEN);
+ mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_TOUCHSCREEN);
// First Configuration.
std::list<NotifyArgs> unused =
@@ -2498,7 +2523,8 @@
TEST_F(InputDeviceTest, Configure_AssignsDisplayUniqueId) {
// Device should be enabled by default.
mFakePolicy->clearViewports();
- mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD);
+ mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
std::list<NotifyArgs> unused =
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
ASSERT_TRUE(mDevice->isEnabled());
@@ -2532,7 +2558,8 @@
TEST_F(InputDeviceTest, Configure_UniqueId_CorrectlyMatches) {
mFakePolicy->clearViewports();
- mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD);
+ mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD);
std::list<NotifyArgs> unused =
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
@@ -2554,7 +2581,7 @@
mFakeEventHub->addDevice(TEST_EVENTHUB_ID, "Test EventHub device", InputDeviceClass::BATTERY);
InputDevice device(mReader->getContext(), /*id=*/1, /*generation=*/2, /*identifier=*/{});
- device.addEventHubDevice(TEST_EVENTHUB_ID, /*populateMappers=*/true);
+ device.addEventHubDevice(TEST_EVENTHUB_ID, mFakePolicy->getReaderConfiguration());
device.removeEventHubDevice(TEST_EVENTHUB_ID);
std::string dumpStr, eventHubDevStr;
device.dump(dumpStr, eventHubDevStr);
@@ -3390,7 +3417,9 @@
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
KeyboardInputMapper& mapper2 =
- device2->addMapper<KeyboardInputMapper>(SECOND_EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD,
+ device2->addMapper<KeyboardInputMapper>(SECOND_EVENTHUB_ID,
+ mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
std::list<NotifyArgs> unused =
device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
@@ -3500,7 +3529,9 @@
mFakeEventHub->addKey(SECOND_EVENTHUB_ID, KEY_SCROLLLOCK, 0, AKEYCODE_SCROLL_LOCK, 0);
KeyboardInputMapper& mapper2 =
- device2->addMapper<KeyboardInputMapper>(SECOND_EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD,
+ device2->addMapper<KeyboardInputMapper>(SECOND_EVENTHUB_ID,
+ mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
std::list<NotifyArgs> unused =
device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
@@ -3561,7 +3592,9 @@
mFakeEventHub->addKey(SECOND_EVENTHUB_ID, KEY_SCROLLLOCK, 0, AKEYCODE_SCROLL_LOCK, 0);
KeyboardInputMapper& mapper2 =
- device2->addMapper<KeyboardInputMapper>(SECOND_EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD,
+ device2->addMapper<KeyboardInputMapper>(SECOND_EVENTHUB_ID,
+ mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
std::list<NotifyArgs> unused =
device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
@@ -3644,7 +3677,8 @@
}
TEST_F(KeyboardInputMapperTest, Configure_AssignKeyboardLayoutInfo) {
- mDevice->addMapper<KeyboardInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD,
+ mDevice->addMapper<KeyboardInputMapper>(EVENTHUB_ID, mFakePolicy->getReaderConfiguration(),
+ AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
std::list<NotifyArgs> unused =
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
@@ -9366,7 +9400,9 @@
String8("touchScreen"));
// Setup the second touch screen device.
- MultiTouchInputMapper& mapper2 = device2->addMapper<MultiTouchInputMapper>(SECOND_EVENTHUB_ID);
+ MultiTouchInputMapper& mapper2 =
+ device2->addMapper<MultiTouchInputMapper>(SECOND_EVENTHUB_ID,
+ mFakePolicy->getReaderConfiguration());
std::list<NotifyArgs> unused =
device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
/*changes=*/0);
diff --git a/services/inputflinger/tests/TestInputListener.cpp b/services/inputflinger/tests/TestInputListener.cpp
index 2801072..ac1dc05 100644
--- a/services/inputflinger/tests/TestInputListener.cpp
+++ b/services/inputflinger/tests/TestInputListener.cpp
@@ -29,6 +29,14 @@
TestInputListener::~TestInputListener() {}
+void TestInputListener::assertNotifyInputDevicesChangedWasCalled(
+ NotifyInputDevicesChangedArgs* outEventArgs) {
+ ASSERT_NO_FATAL_FAILURE(
+ assertCalled<NotifyInputDevicesChangedArgs>(outEventArgs,
+ "Expected notifyInputDevicesChanged() "
+ "to have been called."));
+}
+
void TestInputListener::assertNotifyConfigurationChangedWasCalled(
NotifyConfigurationChangedArgs* outEventArgs) {
ASSERT_NO_FATAL_FAILURE(
@@ -168,6 +176,10 @@
mCondition.notify_all();
}
+void TestInputListener::notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) {
+ addToQueue<NotifyInputDevicesChangedArgs>(&args);
+}
+
void TestInputListener::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
addToQueue<NotifyConfigurationChangedArgs>(args);
}
diff --git a/services/inputflinger/tests/TestInputListener.h b/services/inputflinger/tests/TestInputListener.h
index 9665f70..da2cab3 100644
--- a/services/inputflinger/tests/TestInputListener.h
+++ b/services/inputflinger/tests/TestInputListener.h
@@ -35,6 +35,9 @@
using TimePoint = std::chrono::time_point<std::chrono::system_clock>;
+ void assertNotifyInputDevicesChangedWasCalled(
+ NotifyInputDevicesChangedArgs* outEventArgs = nullptr);
+
void assertNotifyConfigurationChangedWasCalled(
NotifyConfigurationChangedArgs* outEventArgs = nullptr);
@@ -76,6 +79,8 @@
template <class NotifyArgsType>
void addToQueue(const NotifyArgsType* args);
+ virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
+
virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
@@ -97,7 +102,8 @@
const std::chrono::milliseconds mEventHappenedTimeout;
const std::chrono::milliseconds mEventDidNotHappenTimeout;
- std::tuple<std::vector<NotifyConfigurationChangedArgs>, //
+ std::tuple<std::vector<NotifyInputDevicesChangedArgs>, //
+ std::vector<NotifyConfigurationChangedArgs>, //
std::vector<NotifyDeviceResetArgs>, //
std::vector<NotifyKeyArgs>, //
std::vector<NotifyMotionArgs>, //
diff --git a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
index 2a9ace0..be731b1 100644
--- a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
+++ b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
@@ -492,7 +492,7 @@
*/
TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenResetHappens) {
NotifyMotionArgs args;
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
mBlocker->notifyMotion(
&(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}})));
mBlocker->notifyMotion(
@@ -505,7 +505,7 @@
}
TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenStylusSourceWithFingerToolIsReceived) {
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
NotifyMotionArgs args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}});
args.pointerProperties[0].toolType = ToolType::FINGER;
args.source = AINPUT_SOURCE_STYLUS;
@@ -518,14 +518,14 @@
*/
TEST_F(UnwantedInteractionBlockerTest, NoResetIfDeviceInfoChanges) {
NotifyMotionArgs args;
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
mBlocker->notifyMotion(
&(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}})));
mBlocker->notifyMotion(
&(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, MOVE, {{4, 5, 6}})));
// Now pretend the device changed, even though nothing is different for DEVICE_ID in practice.
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
// The MOVE event continues the gesture that started before 'devices changed', so it should not
// cause a crash.
@@ -538,7 +538,7 @@
*/
TEST_F(UnwantedInteractionBlockerTest, StylusAfterTouchWorks) {
NotifyMotionArgs args;
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
mBlocker->notifyMotion(&args);
args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, MOVE, {{4, 5, 6}});
@@ -568,7 +568,7 @@
* options
*/
TEST_F(UnwantedInteractionBlockerTest, DumpCanBeAccessedOnAnotherThread) {
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
mBlocker->notifyMotion(&args1);
std::thread dumpThread([this]() {
@@ -587,7 +587,7 @@
* of the touch is large. This is an integration test that checks that this filter kicks in.
*/
TEST_F(UnwantedInteractionBlockerTest, HeuristicFilterWorks) {
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
// Small touch down
NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
mBlocker->notifyMotion(&args1);
@@ -613,9 +613,9 @@
* This is similar to `HeuristicFilterWorks` test, but for stylus tool.
*/
TEST_F(UnwantedInteractionBlockerTest, StylusIsNotBlocked) {
- InputDeviceInfo info = generateTestDeviceInfo();
- info.addSource(AINPUT_SOURCE_STYLUS);
- mBlocker->notifyInputDevicesChanged({info});
+ NotifyInputDevicesChangedArgs deviceChangedArgs = {/*id=*/0, {generateTestDeviceInfo()}};
+ deviceChangedArgs.inputDeviceInfos[0].addSource(AINPUT_SOURCE_STYLUS);
+ mBlocker->notifyInputDevicesChanged(deviceChangedArgs);
NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
args1.pointerProperties[0].toolType = ToolType::STYLUS;
mBlocker->notifyMotion(&args1);
@@ -643,9 +643,9 @@
* Stylus event should continue to work even after touch is detected as a palm.
*/
TEST_F(UnwantedInteractionBlockerTest, TouchIsBlockedWhenMixedWithStylus) {
- InputDeviceInfo info = generateTestDeviceInfo();
- info.addSource(AINPUT_SOURCE_STYLUS);
- mBlocker->notifyInputDevicesChanged({info});
+ NotifyInputDevicesChangedArgs deviceChangedArgs = {/*id=*/0, {generateTestDeviceInfo()}};
+ deviceChangedArgs.inputDeviceInfos[0].addSource(AINPUT_SOURCE_STYLUS);
+ mBlocker->notifyInputDevicesChanged(deviceChangedArgs);
// Touch down
NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
@@ -699,7 +699,7 @@
TEST_F(UnwantedInteractionBlockerTestDeathTest, InconsistentEventAfterResetCausesACrash) {
ScopedSilentDeath _silentDeath;
NotifyMotionArgs args;
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
mBlocker->notifyMotion(
&(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}})));
mBlocker->notifyMotion(
@@ -721,7 +721,7 @@
TEST_F(UnwantedInteractionBlockerTestDeathTest, WhenMoveWithoutDownCausesACrash) {
ScopedSilentDeath _silentDeath;
NotifyMotionArgs args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, MOVE, {{1, 2, 3}});
- mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
+ mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
ASSERT_DEATH({ mBlocker->notifyMotion(&args); }, "Could not find slot");
}
diff --git a/services/inputflinger/tests/fuzzers/CursorInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/CursorInputFuzzer.cpp
index 28873a3..8ed1f31 100644
--- a/services/inputflinger/tests/fuzzers/CursorInputFuzzer.cpp
+++ b/services/inputflinger/tests/fuzzers/CursorInputFuzzer.cpp
@@ -38,8 +38,8 @@
std::make_shared<ThreadSafeFuzzedDataProvider>(data, size);
FuzzContainer fuzzer(fdp);
- CursorInputMapper& mapper = fuzzer.getMapper<CursorInputMapper>();
auto policyConfig = fuzzer.getPolicyConfig();
+ CursorInputMapper& mapper = fuzzer.getMapper<CursorInputMapper>(policyConfig);
// Loop through mapper operations until randomness is exhausted.
while (fdp->remaining_bytes() > 0) {
diff --git a/services/inputflinger/tests/fuzzers/KeyboardInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/KeyboardInputFuzzer.cpp
index 00b44b5..0a6327d 100644
--- a/services/inputflinger/tests/fuzzers/KeyboardInputFuzzer.cpp
+++ b/services/inputflinger/tests/fuzzers/KeyboardInputFuzzer.cpp
@@ -44,10 +44,10 @@
std::make_shared<ThreadSafeFuzzedDataProvider>(data, size);
FuzzContainer fuzzer(fdp);
- KeyboardInputMapper& mapper =
- fuzzer.getMapper<KeyboardInputMapper>(fdp->ConsumeIntegral<uint32_t>(),
- fdp->ConsumeIntegral<int32_t>());
auto policyConfig = fuzzer.getPolicyConfig();
+ KeyboardInputMapper& mapper =
+ fuzzer.getMapper<KeyboardInputMapper>(policyConfig, fdp->ConsumeIntegral<uint32_t>(),
+ fdp->ConsumeIntegral<int32_t>());
// Loop through mapper operations until randomness is exhausted.
while (fdp->remaining_bytes() > 0) {
diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h
index 9f4aa5c..0dc627a 100644
--- a/services/inputflinger/tests/fuzzers/MapperHelpers.h
+++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h
@@ -293,6 +293,7 @@
class FuzzInputListener : public virtual InputListenerInterface {
public:
+ void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override {}
void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override {}
void notifyKey(const NotifyKeyArgs* args) override {}
void notifyMotion(const NotifyMotionArgs* args) override {}
diff --git a/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp
index 70908ff..fdf9f41 100644
--- a/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp
+++ b/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp
@@ -61,8 +61,8 @@
std::make_shared<ThreadSafeFuzzedDataProvider>(data, size);
FuzzContainer fuzzer(fdp);
- MultiTouchInputMapper& mapper = fuzzer.getMapper<MultiTouchInputMapper>();
auto policyConfig = fuzzer.getPolicyConfig();
+ MultiTouchInputMapper& mapper = fuzzer.getMapper<MultiTouchInputMapper>(policyConfig);
// Loop through mapper operations until randomness is exhausted.
while (fdp->remaining_bytes() > 0) {
diff --git a/services/inputflinger/tests/fuzzers/SwitchInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/SwitchInputFuzzer.cpp
index c4938f2..590207e 100644
--- a/services/inputflinger/tests/fuzzers/SwitchInputFuzzer.cpp
+++ b/services/inputflinger/tests/fuzzers/SwitchInputFuzzer.cpp
@@ -24,8 +24,8 @@
std::make_shared<ThreadSafeFuzzedDataProvider>(data, size);
FuzzContainer fuzzer(fdp);
- SwitchInputMapper& mapper = fuzzer.getMapper<SwitchInputMapper>();
auto policyConfig = fuzzer.getPolicyConfig();
+ SwitchInputMapper& mapper = fuzzer.getMapper<SwitchInputMapper>(policyConfig);
// Loop through mapper operations until randomness is exhausted.
while (fdp->remaining_bytes() > 0) {
diff --git a/services/sensorservice/BatteryService.cpp b/services/sensorservice/BatteryService.cpp
index 94de55c..b0fbe5d 100644
--- a/services/sensorservice/BatteryService.cpp
+++ b/services/sensorservice/BatteryService.cpp
@@ -74,6 +74,14 @@
}
}
+void BatteryService::noteWakeupSensorEventImpl(int64_t elapsedNanos, uid_t uid, int handle) {
+ if (checkService()) {
+ int64_t identity = IPCThreadState::self()->clearCallingIdentity();
+ mBatteryStatService->noteWakeupSensorEvent(elapsedNanos, uid, handle);
+ IPCThreadState::self()->restoreCallingIdentity(identity);
+ }
+}
+
bool BatteryService::checkService() {
if (mBatteryStatService == nullptr) {
const sp<IServiceManager> sm(defaultServiceManager());
diff --git a/services/sensorservice/BatteryService.h b/services/sensorservice/BatteryService.h
index 13fc58a..60ef03f 100644
--- a/services/sensorservice/BatteryService.h
+++ b/services/sensorservice/BatteryService.h
@@ -19,11 +19,14 @@
#include <batterystats/IBatteryStats.h>
#include <utils/Singleton.h>
+#include <utils/SortedVector.h>
+#include <utils/SystemClock.h>
namespace android {
// ---------------------------------------------------------------------------
class BatteryService : public Singleton<BatteryService> {
+ static constexpr int64_t WAKEUP_SENSOR_EVENT_DEBOUNCE_MS = 1000;
friend class Singleton<BatteryService>;
sp<IBatteryStats> mBatteryStatService;
@@ -32,6 +35,7 @@
void enableSensorImpl(uid_t uid, int handle);
void disableSensorImpl(uid_t uid, int handle);
+ void noteWakeupSensorEventImpl(int64_t elapsedNanos, uid_t uid, int handle);
struct Info {
uid_t uid;
@@ -44,6 +48,7 @@
}
};
+ int64_t mLastWakeupSensorEventReportedMs;
Mutex mActivationsLock;
SortedVector<Info> mActivations;
bool addSensor(uid_t uid, int handle);
@@ -57,6 +62,15 @@
static void disableSensor(uid_t uid, int handle) {
BatteryService::getInstance().disableSensorImpl(uid, handle);
}
+ static void noteWakeupSensorEvent(int64_t elapsed, uid_t uid, int handle) {
+ BatteryService& instance = BatteryService::getInstance();
+ const int64_t nowElapsedMs = elapsedRealtime();
+ if (nowElapsedMs >= (instance.mLastWakeupSensorEventReportedMs
+ + WAKEUP_SENSOR_EVENT_DEBOUNCE_MS)) {
+ instance.noteWakeupSensorEventImpl(elapsed, uid, handle);
+ instance.mLastWakeupSensorEventReportedMs = nowElapsedMs;
+ }
+ }
};
// ---------------------------------------------------------------------------
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index 7a6b31d..dc5070c 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -23,6 +23,7 @@
#include <sensor/SensorEventQueue.h>
#include "vec.h"
+#include "BatteryService.h"
#include "SensorEventConnection.h"
#include "SensorDevice.h"
@@ -391,6 +392,8 @@
if (hasSensorAccess()) {
index_wake_up_event = findWakeUpSensorEventLocked(scratch, count);
if (index_wake_up_event >= 0) {
+ BatteryService::noteWakeupSensorEvent(scratch[index_wake_up_event].timestamp,
+ mUid, scratch[index_wake_up_event].sensor);
scratch[index_wake_up_event].flags |= WAKE_UP_SENSOR_EVENT_NEEDS_ACK;
++mWakeLockRefCount;
#if DEBUG_CONNECTIONS