summaryrefslogtreecommitdiff
path: root/services/inputflinger/tests
diff options
context:
space:
mode:
Diffstat (limited to 'services/inputflinger/tests')
-rw-r--r--services/inputflinger/tests/Android.bp24
-rw-r--r--services/inputflinger/tests/BlockingQueue_test.cpp2
-rw-r--r--services/inputflinger/tests/EventHub_test.cpp73
-rw-r--r--services/inputflinger/tests/FocusResolver_test.cpp292
-rw-r--r--services/inputflinger/tests/IInputFlingerQuery.aidl30
-rw-r--r--services/inputflinger/tests/InputClassifierConverter_test.cpp14
-rw-r--r--services/inputflinger/tests/InputClassifier_test.cpp21
-rw-r--r--services/inputflinger/tests/InputDispatcher_test.cpp3519
-rw-r--r--services/inputflinger/tests/InputFlingerService_test.cpp462
-rw-r--r--services/inputflinger/tests/InputReader_test.cpp3044
-rw-r--r--services/inputflinger/tests/LatencyTracker_test.cpp253
-rw-r--r--services/inputflinger/tests/TestInputListener.cpp42
-rw-r--r--services/inputflinger/tests/TestInputListener.h23
-rw-r--r--services/inputflinger/tests/UinputDevice.cpp5
-rw-r--r--services/inputflinger/tests/UinputDevice.h1
15 files changed, 1431 insertions, 6374 deletions
diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp
index 918e1bef7a..a0d2f4f172 100644
--- a/services/inputflinger/tests/Android.bp
+++ b/services/inputflinger/tests/Android.bp
@@ -12,15 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package {
- // See: http://go/android-license-faq
- // A large-scale-change added 'default_applicable_licenses' to import
- // all of the 'license_kinds' from "frameworks_native_license"
- // to get the below license kinds:
- // SPDX-license-identifier-Apache-2.0
- default_applicable_licenses: ["frameworks_native_license"],
-}
-
cc_test {
name: "inputflinger_tests",
defaults: [
@@ -39,25 +30,12 @@ cc_test {
"AnrTracker_test.cpp",
"BlockingQueue_test.cpp",
"EventHub_test.cpp",
- "FocusResolver_test.cpp",
- "IInputFlingerQuery.aidl",
+ "TestInputListener.cpp",
"InputClassifier_test.cpp",
"InputClassifierConverter_test.cpp",
"InputDispatcher_test.cpp",
"InputReader_test.cpp",
- "InputFlingerService_test.cpp",
- "LatencyTracker_test.cpp",
- "TestInputListener.cpp",
"UinputDevice.cpp",
],
- aidl: {
- include_dirs: [
- "frameworks/native/libs/input",
- ],
- },
- static_libs: [
- "libc++fs"
- ],
require_root: true,
- test_suites: ["device-tests"],
}
diff --git a/services/inputflinger/tests/BlockingQueue_test.cpp b/services/inputflinger/tests/BlockingQueue_test.cpp
index fd9d9d5bd3..0dea8d7861 100644
--- a/services/inputflinger/tests/BlockingQueue_test.cpp
+++ b/services/inputflinger/tests/BlockingQueue_test.cpp
@@ -26,7 +26,7 @@ namespace android {
// --- BlockingQueueTest ---
/**
- * Validate basic pop and push operation.
+ * Sanity check of basic pop and push operation.
*/
TEST(BlockingQueueTest, Queue_AddAndRemove) {
constexpr size_t capacity = 10;
diff --git a/services/inputflinger/tests/EventHub_test.cpp b/services/inputflinger/tests/EventHub_test.cpp
index ef68a84fdb..71731b046c 100644
--- a/services/inputflinger/tests/EventHub_test.cpp
+++ b/services/inputflinger/tests/EventHub_test.cpp
@@ -199,76 +199,3 @@ TEST_F(EventHubTest, InputEvent_TimestampIsMonotonic) {
lastEventTime = event.when; // Ensure all returned events are monotonic
}
}
-
-// --- BitArrayTest ---
-class BitArrayTest : public testing::Test {
-protected:
- static constexpr size_t SINGLE_ELE_BITS = 32UL;
- static constexpr size_t MULTI_ELE_BITS = 256UL;
-
- virtual void SetUp() override {
- mBitmaskSingle.loadFromBuffer(mBufferSingle);
- mBitmaskMulti.loadFromBuffer(mBufferMulti);
- }
-
- android::BitArray<SINGLE_ELE_BITS> mBitmaskSingle;
- android::BitArray<MULTI_ELE_BITS> mBitmaskMulti;
-
-private:
- const typename android::BitArray<SINGLE_ELE_BITS>::Buffer mBufferSingle = {
- 0x800F0F0FUL // bit 0 - 31
- };
- const typename android::BitArray<MULTI_ELE_BITS>::Buffer mBufferMulti = {
- 0xFFFFFFFFUL, // bit 0 - 31
- 0x01000001UL, // bit 32 - 63
- 0x00000000UL, // bit 64 - 95
- 0x80000000UL, // bit 96 - 127
- 0x00000000UL, // bit 128 - 159
- 0x00000000UL, // bit 160 - 191
- 0x80000008UL, // bit 192 - 223
- 0x00000000UL, // bit 224 - 255
- };
-};
-
-TEST_F(BitArrayTest, SetBit) {
- ASSERT_TRUE(mBitmaskSingle.test(0));
- ASSERT_TRUE(mBitmaskSingle.test(31));
- ASSERT_FALSE(mBitmaskSingle.test(7));
-
- ASSERT_TRUE(mBitmaskMulti.test(32));
- ASSERT_TRUE(mBitmaskMulti.test(56));
- ASSERT_FALSE(mBitmaskMulti.test(192));
- ASSERT_TRUE(mBitmaskMulti.test(223));
- ASSERT_FALSE(mBitmaskMulti.test(255));
-}
-
-TEST_F(BitArrayTest, AnyBit) {
- ASSERT_TRUE(mBitmaskSingle.any(31, 32));
- ASSERT_FALSE(mBitmaskSingle.any(12, 16));
-
- ASSERT_TRUE(mBitmaskMulti.any(31, 32));
- ASSERT_FALSE(mBitmaskMulti.any(33, 33));
- ASSERT_TRUE(mBitmaskMulti.any(32, 55));
- ASSERT_TRUE(mBitmaskMulti.any(33, 57));
- ASSERT_FALSE(mBitmaskMulti.any(33, 55));
- ASSERT_FALSE(mBitmaskMulti.any(130, 190));
-
- ASSERT_FALSE(mBitmaskMulti.any(128, 195));
- ASSERT_TRUE(mBitmaskMulti.any(128, 196));
- ASSERT_TRUE(mBitmaskMulti.any(128, 224));
- ASSERT_FALSE(mBitmaskMulti.any(255, 256));
-}
-
-TEST_F(BitArrayTest, SetBit_InvalidBitIndex) {
- ASSERT_FALSE(mBitmaskSingle.test(32));
- ASSERT_FALSE(mBitmaskMulti.test(256));
-}
-
-TEST_F(BitArrayTest, AnyBit_InvalidBitIndex) {
- ASSERT_FALSE(mBitmaskSingle.any(32, 32));
- ASSERT_FALSE(mBitmaskSingle.any(33, 34));
-
- ASSERT_FALSE(mBitmaskMulti.any(256, 256));
- ASSERT_FALSE(mBitmaskMulti.any(257, 258));
- ASSERT_FALSE(mBitmaskMulti.any(0, 0));
-}
diff --git a/services/inputflinger/tests/FocusResolver_test.cpp b/services/inputflinger/tests/FocusResolver_test.cpp
deleted file mode 100644
index 9051ff12c2..0000000000
--- a/services/inputflinger/tests/FocusResolver_test.cpp
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gtest/gtest.h>
-
-#include "../FocusResolver.h"
-
-#define ASSERT_FOCUS_CHANGE(_changes, _oldFocus, _newFocus) \
- { \
- ASSERT_EQ(_oldFocus, _changes->oldFocus); \
- ASSERT_EQ(_newFocus, _changes->newFocus); \
- }
-
-// atest inputflinger_tests:FocusResolverTest
-
-namespace android::inputdispatcher {
-
-class FakeWindowHandle : public InputWindowHandle {
-public:
- FakeWindowHandle(const std::string& name, const sp<IBinder>& token, bool focusable,
- bool visible) {
- mInfo.token = token;
- mInfo.name = name;
- mInfo.visible = visible;
- mInfo.focusable = focusable;
- }
-
- bool updateInfo() { return true; }
- void setFocusable(bool focusable) { mInfo.focusable = focusable; }
- void setVisible(bool visible) { mInfo.visible = visible; }
-};
-
-TEST(FocusResolverTest, SetFocusedWindow) {
- sp<IBinder> focusableWindowToken = new BBinder();
- sp<IBinder> invisibleWindowToken = new BBinder();
- sp<IBinder> unfocusableWindowToken = new BBinder();
- std::vector<sp<InputWindowHandle>> windows;
- windows.push_back(new FakeWindowHandle("Focusable", focusableWindowToken, true /* focusable */,
- true /* visible */));
- windows.push_back(new FakeWindowHandle("Invisible", invisibleWindowToken, true /* focusable */,
- false /* visible */));
- windows.push_back(new FakeWindowHandle("unfocusable", unfocusableWindowToken,
- false /* focusable */, true /* visible */));
-
- // focusable window can get focused
- FocusRequest request;
- request.displayId = 42;
- request.token = focusableWindowToken;
- FocusResolver focusResolver;
- std::optional<FocusResolver::FocusChanges> changes =
- focusResolver.setFocusedWindow(request, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ focusableWindowToken);
- ASSERT_EQ(request.displayId, changes->displayId);
-
- // invisible window cannot get focused
- request.token = invisibleWindowToken;
- changes = focusResolver.setFocusedWindow(request, windows);
- ASSERT_EQ(focusableWindowToken, changes->oldFocus);
- ASSERT_EQ(nullptr, changes->newFocus);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ focusableWindowToken, /*to*/ nullptr);
-
- // unfocusableWindowToken window cannot get focused
- request.token = unfocusableWindowToken;
- changes = focusResolver.setFocusedWindow(request, windows);
- ASSERT_FALSE(changes);
-}
-
-TEST(FocusResolverTest, SetFocusedMirroredWindow) {
- sp<IBinder> focusableWindowToken = new BBinder();
- sp<IBinder> invisibleWindowToken = new BBinder();
- sp<IBinder> unfocusableWindowToken = new BBinder();
- std::vector<sp<InputWindowHandle>> windows;
- windows.push_back(new FakeWindowHandle("Mirror1", focusableWindowToken, true /* focusable */,
- true /* visible */));
- windows.push_back(new FakeWindowHandle("Mirror1", focusableWindowToken, true /* focusable */,
- true /* visible */));
-
- windows.push_back(new FakeWindowHandle("Mirror2Visible", invisibleWindowToken,
- true /* focusable */, true /* visible */));
- windows.push_back(new FakeWindowHandle("Mirror2Invisible", invisibleWindowToken,
- true /* focusable */, false /* visible */));
-
- windows.push_back(new FakeWindowHandle("Mirror3Focusable", unfocusableWindowToken,
- true /* focusable */, true /* visible */));
- windows.push_back(new FakeWindowHandle("Mirror3Unfocusable", unfocusableWindowToken,
- false /* focusable */, true /* visible */));
-
- // mirrored window can get focused
- FocusRequest request;
- request.displayId = 42;
- request.token = focusableWindowToken;
- FocusResolver focusResolver;
- std::optional<FocusResolver::FocusChanges> changes =
- focusResolver.setFocusedWindow(request, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ focusableWindowToken);
-
- // mirrored window with one visible window can get focused
- request.token = invisibleWindowToken;
- changes = focusResolver.setFocusedWindow(request, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ focusableWindowToken, /*to*/ invisibleWindowToken);
-
- // mirrored window with one or more unfocusable window cannot get focused
- request.token = unfocusableWindowToken;
- changes = focusResolver.setFocusedWindow(request, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ invisibleWindowToken, /*to*/ nullptr);
-}
-
-TEST(FocusResolverTest, SetInputWindows) {
- sp<IBinder> focusableWindowToken = new BBinder();
- std::vector<sp<InputWindowHandle>> windows;
- sp<FakeWindowHandle> window = new FakeWindowHandle("Focusable", focusableWindowToken,
- true /* focusable */, true /* visible */);
- windows.push_back(window);
-
- // focusable window can get focused
- FocusRequest request;
- request.displayId = 42;
- request.token = focusableWindowToken;
- FocusResolver focusResolver;
- std::optional<FocusResolver::FocusChanges> changes =
- focusResolver.setFocusedWindow(request, windows);
- ASSERT_EQ(focusableWindowToken, changes->newFocus);
-
- // Window visibility changes and the window loses focus
- window->setVisible(false);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ focusableWindowToken, /*to*/ nullptr);
-}
-
-TEST(FocusResolverTest, FocusRequestsCanBePending) {
- sp<IBinder> invisibleWindowToken = new BBinder();
- std::vector<sp<InputWindowHandle>> windows;
-
- sp<FakeWindowHandle> invisibleWindow =
- new FakeWindowHandle("Invisible", invisibleWindowToken, true /* focusable */,
- false /* visible */);
- windows.push_back(invisibleWindow);
-
- // invisible window cannot get focused
- FocusRequest request;
- request.displayId = 42;
- request.token = invisibleWindowToken;
- FocusResolver focusResolver;
- std::optional<FocusResolver::FocusChanges> changes =
- focusResolver.setFocusedWindow(request, windows);
- ASSERT_FALSE(changes);
-
- // Window visibility changes and the window gets focused
- invisibleWindow->setVisible(true);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ invisibleWindowToken);
-}
-
-TEST(FocusResolverTest, FocusRequestsArePersistent) {
- sp<IBinder> windowToken = new BBinder();
- std::vector<sp<InputWindowHandle>> windows;
-
- sp<FakeWindowHandle> window = new FakeWindowHandle("Test Window", windowToken,
- false /* focusable */, true /* visible */);
- windows.push_back(window);
-
- // non-focusable window cannot get focused
- FocusRequest request;
- request.displayId = 42;
- request.token = windowToken;
- FocusResolver focusResolver;
- std::optional<FocusResolver::FocusChanges> changes =
- focusResolver.setFocusedWindow(request, windows);
- ASSERT_FALSE(changes);
-
- // Focusability changes and the window gets focused
- window->setFocusable(true);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken);
-
- // Visibility changes and the window loses focus
- window->setVisible(false);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ windowToken, /*to*/ nullptr);
-
- // Visibility changes and the window gets focused
- window->setVisible(true);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken);
-
- // Window is gone and the window loses focus
- changes = focusResolver.setInputWindows(request.displayId, {});
- ASSERT_FOCUS_CHANGE(changes, /*from*/ windowToken, /*to*/ nullptr);
-
- // Window returns and the window gains focus
- changes = focusResolver.setInputWindows(request.displayId, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken);
-}
-
-TEST(FocusResolverTest, ConditionalFocusRequestsAreNotPersistent) {
- sp<IBinder> hostWindowToken = new BBinder();
- std::vector<sp<InputWindowHandle>> windows;
-
- sp<FakeWindowHandle> hostWindow =
- new FakeWindowHandle("Host Window", hostWindowToken, true /* focusable */,
- true /* visible */);
- windows.push_back(hostWindow);
- sp<IBinder> embeddedWindowToken = new BBinder();
- sp<FakeWindowHandle> embeddedWindow =
- new FakeWindowHandle("Embedded Window", embeddedWindowToken, true /* focusable */,
- true /* visible */);
- windows.push_back(embeddedWindow);
-
- FocusRequest request;
- request.displayId = 42;
- request.token = hostWindowToken;
- FocusResolver focusResolver;
- std::optional<FocusResolver::FocusChanges> changes =
- focusResolver.setFocusedWindow(request, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ hostWindowToken);
-
- request.focusedToken = hostWindow->getToken();
- request.token = embeddedWindowToken;
- changes = focusResolver.setFocusedWindow(request, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ hostWindowToken, /*to*/ embeddedWindowToken);
-
- embeddedWindow->setFocusable(false);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- // The embedded window is no longer focusable, provide focus back to the original focused
- // window.
- ASSERT_FOCUS_CHANGE(changes, /*from*/ embeddedWindowToken, /*to*/ hostWindowToken);
-
- embeddedWindow->setFocusable(true);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- // The embedded window is focusable again, but we it cannot gain focus unless there is another
- // focus request.
- ASSERT_FALSE(changes);
-
- embeddedWindow->setVisible(false);
- changes = focusResolver.setFocusedWindow(request, windows);
- // If the embedded window is not visible/focusable, then we do not grant it focus and the
- // request is dropped.
- ASSERT_FALSE(changes);
-
- embeddedWindow->setVisible(true);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- // If the embedded window becomes visble/focusable, nothing changes since the request has been
- // dropped.
- ASSERT_FALSE(changes);
-}
-TEST(FocusResolverTest, FocusRequestsAreClearedWhenWindowIsRemoved) {
- sp<IBinder> windowToken = new BBinder();
- std::vector<sp<InputWindowHandle>> windows;
-
- sp<FakeWindowHandle> window = new FakeWindowHandle("Test Window", windowToken,
- true /* focusable */, true /* visible */);
- windows.push_back(window);
-
- FocusRequest request;
- request.displayId = 42;
- request.token = windowToken;
- FocusResolver focusResolver;
- std::optional<FocusResolver::FocusChanges> changes =
- focusResolver.setFocusedWindow(request, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken);
- ASSERT_EQ(request.displayId, changes->displayId);
-
- // Start with a focused window
- window->setFocusable(true);
- changes = focusResolver.setInputWindows(request.displayId, windows);
- ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken);
-
- // When a display is removed, all windows are removed from the display
- // and our focused window loses focus
- changes = focusResolver.setInputWindows(request.displayId, {});
- ASSERT_FOCUS_CHANGE(changes, /*from*/ windowToken, /*to*/ nullptr);
- focusResolver.displayRemoved(request.displayId);
-
- // When a display is readded, the window does not get focus since the request was cleared.
- changes = focusResolver.setInputWindows(request.displayId, windows);
- ASSERT_FALSE(changes);
-}
-
-} // namespace android::inputdispatcher
diff --git a/services/inputflinger/tests/IInputFlingerQuery.aidl b/services/inputflinger/tests/IInputFlingerQuery.aidl
deleted file mode 100644
index 5c8a8da612..0000000000
--- a/services/inputflinger/tests/IInputFlingerQuery.aidl
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Copyright (c) 2020, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import android.FocusRequest;
-import android.InputChannel;
-import android.InputWindowInfo;
-import android.os.ISetInputWindowsListener;
-
-/** @hide */
-interface IInputFlingerQuery
-{
- /* Test interfaces */
- void getInputWindows(out InputWindowInfo[] inputHandles);
- void getInputChannels(out InputChannel[] channels);
- void getLastFocusRequest(out FocusRequest request);
- void resetInputManager();
-}
diff --git a/services/inputflinger/tests/InputClassifierConverter_test.cpp b/services/inputflinger/tests/InputClassifierConverter_test.cpp
index c0ada9d517..f58b6281df 100644
--- a/services/inputflinger/tests/InputClassifierConverter_test.cpp
+++ b/services/inputflinger/tests/InputClassifierConverter_test.cpp
@@ -38,13 +38,13 @@ static NotifyMotionArgs generateBasicMotionArgs() {
coords.setAxisValue(AMOTION_EVENT_AXIS_Y, 2);
coords.setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.5);
static constexpr nsecs_t downTime = 2;
- NotifyMotionArgs motionArgs(1 /*sequenceNum*/, downTime /*eventTime*/, 2 /*readTime*/,
- 3 /*deviceId*/, AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT,
- 4 /*policyFlags*/, AMOTION_EVENT_ACTION_DOWN, 0 /*actionButton*/,
- 0 /*flags*/, AMETA_NONE, 0 /*buttonState*/,
- MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE,
- 1 /*pointerCount*/, &properties, &coords, 0 /*xPrecision*/,
- 0 /*yPrecision*/, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ NotifyMotionArgs motionArgs(1 /*sequenceNum*/, downTime /*eventTime*/, 3 /*deviceId*/,
+ AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT, 4 /*policyFlags*/,
+ AMOTION_EVENT_ACTION_DOWN, 0 /*actionButton*/, 0 /*flags*/,
+ AMETA_NONE, 0 /*buttonState*/, MotionClassification::NONE,
+ AMOTION_EVENT_EDGE_FLAG_NONE, 1 /*pointerCount*/, &properties,
+ &coords, 0 /*xPrecision*/, 0 /*yPrecision*/,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION,
AMOTION_EVENT_INVALID_CURSOR_POSITION, downTime,
{} /*videoFrames*/);
return motionArgs;
diff --git a/services/inputflinger/tests/InputClassifier_test.cpp b/services/inputflinger/tests/InputClassifier_test.cpp
index a72df01ce6..ab74a0498d 100644
--- a/services/inputflinger/tests/InputClassifier_test.cpp
+++ b/services/inputflinger/tests/InputClassifier_test.cpp
@@ -41,13 +41,13 @@ static NotifyMotionArgs generateBasicMotionArgs() {
coords.setAxisValue(AMOTION_EVENT_AXIS_X, 1);
coords.setAxisValue(AMOTION_EVENT_AXIS_Y, 1);
static constexpr nsecs_t downTime = 2;
- NotifyMotionArgs motionArgs(1 /*sequenceNum*/, downTime /*eventTime*/, 2 /*readTime*/,
- 3 /*deviceId*/, AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT,
- 4 /*policyFlags*/, AMOTION_EVENT_ACTION_DOWN, 0 /*actionButton*/,
- 0 /*flags*/, AMETA_NONE, 0 /*buttonState*/,
- MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE,
- 1 /*pointerCount*/, &properties, &coords, 0 /*xPrecision*/,
- 0 /*yPrecision*/, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ NotifyMotionArgs motionArgs(1 /*sequenceNum*/, downTime /*eventTime*/, 3 /*deviceId*/,
+ AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT, 4 /*policyFlags*/,
+ AMOTION_EVENT_ACTION_DOWN, 0 /*actionButton*/, 0 /*flags*/,
+ AMETA_NONE, 0 /*buttonState*/, MotionClassification::NONE,
+ AMOTION_EVENT_EDGE_FLAG_NONE, 1 /*pointerCount*/, &properties,
+ &coords, 0 /*xPrecision*/, 0 /*yPrecision*/,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION,
AMOTION_EVENT_INVALID_CURSOR_POSITION, downTime,
{} /*videoFrames*/);
return motionArgs;
@@ -85,10 +85,9 @@ TEST_F(InputClassifierTest, SendToNextStage_NotifyConfigurationChangedArgs) {
TEST_F(InputClassifierTest, SendToNextStage_NotifyKeyArgs) {
// Create a basic key event and send to classifier
- NotifyKeyArgs args(1 /*sequenceNum*/, 2 /*eventTime*/, 21 /*readTime*/, 3 /*deviceId*/,
- AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_DEFAULT, 0 /*policyFlags*/,
- AKEY_EVENT_ACTION_DOWN, 4 /*flags*/, AKEYCODE_HOME, 5 /*scanCode*/,
- AMETA_NONE, 6 /*downTime*/);
+ NotifyKeyArgs args(1/*sequenceNum*/, 2/*eventTime*/, 3/*deviceId*/, AINPUT_SOURCE_KEYBOARD,
+ ADISPLAY_ID_DEFAULT, 0/*policyFlags*/, AKEY_EVENT_ACTION_DOWN, 4/*flags*/,
+ AKEYCODE_HOME, 5/*scanCode*/, AMETA_NONE, 6/*downTime*/);
mClassifier->notifyKey(&args);
NotifyKeyArgs outArgs;
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 3a9dede89b..86c0503662 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -29,10 +29,6 @@
#include <vector>
using android::base::StringPrintf;
-using android::os::InputEventInjectionResult;
-using android::os::InputEventInjectionSync;
-using android::os::TouchOcclusionMode;
-using namespace android::flag_operators;
namespace android::inputdispatcher {
@@ -49,9 +45,6 @@ static const int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT;
static const int32_t INJECTOR_PID = 999;
static const int32_t INJECTOR_UID = 1001;
-// An arbitrary pid of the gesture monitor window
-static constexpr int32_t MONITOR_PID = 2001;
-
struct PointF {
float x;
float y;
@@ -128,84 +121,33 @@ public:
// This function must be called soon after the expected ANR timer starts,
// because we are also checking how much time has passed.
- void assertNotifyNoFocusedWindowAnrWasCalled(
- std::chrono::nanoseconds timeout,
- const std::shared_ptr<InputApplicationHandle>& expectedApplication) {
- std::shared_ptr<InputApplicationHandle> application;
- { // acquire lock
- std::unique_lock lock(mLock);
- android::base::ScopedLockAssertion assumeLocked(mLock);
- ASSERT_NO_FATAL_FAILURE(
- application = getAnrTokenLockedInterruptible(timeout, mAnrApplications, lock));
- } // release lock
- ASSERT_EQ(expectedApplication, application);
- }
-
- void assertNotifyWindowUnresponsiveWasCalled(std::chrono::nanoseconds timeout,
- const sp<IBinder>& expectedConnectionToken) {
- sp<IBinder> connectionToken = getUnresponsiveWindowToken(timeout);
- ASSERT_EQ(expectedConnectionToken, connectionToken);
- }
-
- void assertNotifyWindowResponsiveWasCalled(const sp<IBinder>& expectedConnectionToken) {
- sp<IBinder> connectionToken = getResponsiveWindowToken();
- ASSERT_EQ(expectedConnectionToken, connectionToken);
- }
-
- void assertNotifyMonitorUnresponsiveWasCalled(std::chrono::nanoseconds timeout) {
- int32_t pid = getUnresponsiveMonitorPid(timeout);
- ASSERT_EQ(MONITOR_PID, pid);
- }
-
- void assertNotifyMonitorResponsiveWasCalled() {
- int32_t pid = getResponsiveMonitorPid();
- ASSERT_EQ(MONITOR_PID, pid);
- }
-
- sp<IBinder> getUnresponsiveWindowToken(std::chrono::nanoseconds timeout) {
- std::unique_lock lock(mLock);
- android::base::ScopedLockAssertion assumeLocked(mLock);
- return getAnrTokenLockedInterruptible(timeout, mAnrWindowTokens, lock);
- }
-
- sp<IBinder> getResponsiveWindowToken() {
- std::unique_lock lock(mLock);
- android::base::ScopedLockAssertion assumeLocked(mLock);
- return getAnrTokenLockedInterruptible(0s, mResponsiveWindowTokens, lock);
- }
-
- int32_t getUnresponsiveMonitorPid(std::chrono::nanoseconds timeout) {
- std::unique_lock lock(mLock);
- android::base::ScopedLockAssertion assumeLocked(mLock);
- return getAnrTokenLockedInterruptible(timeout, mAnrMonitorPids, lock);
- }
-
- int32_t getResponsiveMonitorPid() {
- std::unique_lock lock(mLock);
- android::base::ScopedLockAssertion assumeLocked(mLock);
- return getAnrTokenLockedInterruptible(0s, mResponsiveMonitorPids, lock);
+ void assertNotifyAnrWasCalled(std::chrono::nanoseconds timeout,
+ const sp<InputApplicationHandle>& expectedApplication,
+ const sp<IBinder>& expectedToken) {
+ std::pair<sp<InputApplicationHandle>, sp<IBinder>> anrData;
+ ASSERT_NO_FATAL_FAILURE(anrData = getNotifyAnrData(timeout));
+ ASSERT_EQ(expectedApplication, anrData.first);
+ ASSERT_EQ(expectedToken, anrData.second);
}
- // All three ANR-related callbacks behave the same way, so we use this generic function to wait
- // for a specific container to become non-empty. When the container is non-empty, return the
- // first entry from the container and erase it.
- template <class T>
- T getAnrTokenLockedInterruptible(std::chrono::nanoseconds timeout, std::queue<T>& storage,
- std::unique_lock<std::mutex>& lock) REQUIRES(mLock) {
+ std::pair<sp<InputApplicationHandle>, sp<IBinder>> getNotifyAnrData(
+ std::chrono::nanoseconds timeout) {
const std::chrono::time_point start = std::chrono::steady_clock::now();
+ std::unique_lock lock(mLock);
std::chrono::duration timeToWait = timeout + 100ms; // provide some slack
+ android::base::ScopedLockAssertion assumeLocked(mLock);
// If there is an ANR, Dispatcher won't be idle because there are still events
// in the waitQueue that we need to check on. So we can't wait for dispatcher to be idle
// before checking if ANR was called.
- // Since dispatcher is not guaranteed to call notifyNoFocusedWindowAnr right away, we need
- // to provide it some time to act. 100ms seems reasonable.
- mNotifyAnr.wait_for(lock, timeToWait,
- [&storage]() REQUIRES(mLock) { return !storage.empty(); });
+ // Since dispatcher is not guaranteed to call notifyAnr right away, we need to provide
+ // it some time to act. 100ms seems reasonable.
+ mNotifyAnr.wait_for(lock, timeToWait, [this]() REQUIRES(mLock) {
+ return !mAnrApplications.empty() && !mAnrWindowTokens.empty();
+ });
const std::chrono::duration waited = std::chrono::steady_clock::now() - start;
- if (storage.empty()) {
- ADD_FAILURE() << "Did not receive the ANR callback";
- return {};
+ if (mAnrApplications.empty() || mAnrWindowTokens.empty()) {
+ ADD_FAILURE() << "Did not receive ANR callback";
}
// Ensure that the ANR didn't get raised too early. We can't be too strict here because
// the dispatcher started counting before this function was called
@@ -216,22 +158,17 @@ public:
<< std::chrono::duration_cast<std::chrono::milliseconds>(waited).count()
<< "ms instead";
}
- T token = storage.front();
- storage.pop();
- return token;
+ std::pair<sp<InputApplicationHandle>, sp<IBinder>> result =
+ std::make_pair(mAnrApplications.front(), mAnrWindowTokens.front());
+ mAnrApplications.pop();
+ mAnrWindowTokens.pop();
+ return result;
}
void assertNotifyAnrWasNotCalled() {
std::scoped_lock lock(mLock);
ASSERT_TRUE(mAnrApplications.empty());
ASSERT_TRUE(mAnrWindowTokens.empty());
- ASSERT_TRUE(mAnrMonitorPids.empty());
- ASSERT_TRUE(mResponsiveWindowTokens.empty())
- << "ANR was not called, but please also consume the 'connection is responsive' "
- "signal";
- ASSERT_TRUE(mResponsiveMonitorPids.empty())
- << "Monitor ANR was not called, but please also consume the 'monitor is responsive'"
- " signal";
}
void setKeyRepeatConfiguration(nsecs_t timeout, nsecs_t delay) {
@@ -239,39 +176,7 @@ public:
mConfig.keyRepeatDelay = delay;
}
- void waitForSetPointerCapture(bool enabled) {
- std::unique_lock lock(mLock);
- base::ScopedLockAssertion assumeLocked(mLock);
-
- if (!mPointerCaptureChangedCondition.wait_for(lock, 100ms,
- [this, enabled]() REQUIRES(mLock) {
- return mPointerCaptureEnabled &&
- *mPointerCaptureEnabled ==
- enabled;
- })) {
- FAIL() << "Timed out waiting for setPointerCapture(" << enabled << ") to be called.";
- }
- mPointerCaptureEnabled.reset();
- }
-
- void assertSetPointerCaptureNotCalled() {
- std::unique_lock lock(mLock);
- base::ScopedLockAssertion assumeLocked(mLock);
-
- if (mPointerCaptureChangedCondition.wait_for(lock, 100ms) != std::cv_status::timeout) {
- FAIL() << "Expected setPointerCapture(enabled) to not be called, but was called. "
- "enabled = "
- << *mPointerCaptureEnabled;
- }
- mPointerCaptureEnabled.reset();
- }
-
- void assertDropTargetEquals(const sp<IBinder>& targetToken) {
- std::scoped_lock lock(mLock);
- ASSERT_TRUE(mNotifyDropWindowWasCalled);
- ASSERT_EQ(targetToken, mDropTargetWindowToken);
- mNotifyDropWindowWasCalled = false;
- }
+ void setAnrTimeout(std::chrono::nanoseconds timeout) { mAnrTimeout = timeout; }
private:
std::mutex mLock;
@@ -280,75 +185,35 @@ private:
sp<IBinder> mOnPointerDownToken GUARDED_BY(mLock);
std::optional<NotifySwitchArgs> mLastNotifySwitch GUARDED_BY(mLock);
- std::condition_variable mPointerCaptureChangedCondition;
- std::optional<bool> mPointerCaptureEnabled GUARDED_BY(mLock);
-
// ANR handling
- std::queue<std::shared_ptr<InputApplicationHandle>> mAnrApplications GUARDED_BY(mLock);
+ std::queue<sp<InputApplicationHandle>> mAnrApplications GUARDED_BY(mLock);
std::queue<sp<IBinder>> mAnrWindowTokens GUARDED_BY(mLock);
- std::queue<sp<IBinder>> mResponsiveWindowTokens GUARDED_BY(mLock);
- std::queue<int32_t> mAnrMonitorPids GUARDED_BY(mLock);
- std::queue<int32_t> mResponsiveMonitorPids GUARDED_BY(mLock);
std::condition_variable mNotifyAnr;
+ std::chrono::nanoseconds mAnrTimeout = 0ms;
- sp<IBinder> mDropTargetWindowToken GUARDED_BY(mLock);
- bool mNotifyDropWindowWasCalled GUARDED_BY(mLock) = false;
-
- void notifyConfigurationChanged(nsecs_t when) override {
+ virtual void notifyConfigurationChanged(nsecs_t when) override {
std::scoped_lock lock(mLock);
mConfigurationChangedTime = when;
}
- void notifyWindowUnresponsive(const sp<IBinder>& connectionToken, const std::string&) override {
- std::scoped_lock lock(mLock);
- mAnrWindowTokens.push(connectionToken);
- mNotifyAnr.notify_all();
- }
-
- void notifyMonitorUnresponsive(int32_t pid, const std::string&) override {
- std::scoped_lock lock(mLock);
- mAnrMonitorPids.push(pid);
- mNotifyAnr.notify_all();
- }
-
- void notifyWindowResponsive(const sp<IBinder>& connectionToken) override {
+ virtual nsecs_t notifyAnr(const sp<InputApplicationHandle>& application,
+ const sp<IBinder>& windowToken, const std::string&) override {
std::scoped_lock lock(mLock);
- mResponsiveWindowTokens.push(connectionToken);
+ mAnrApplications.push(application);
+ mAnrWindowTokens.push(windowToken);
mNotifyAnr.notify_all();
+ return mAnrTimeout.count();
}
- void notifyMonitorResponsive(int32_t pid) override {
- std::scoped_lock lock(mLock);
- mResponsiveMonitorPids.push(pid);
- mNotifyAnr.notify_all();
- }
-
- void notifyNoFocusedWindowAnr(
- const std::shared_ptr<InputApplicationHandle>& applicationHandle) override {
- std::scoped_lock lock(mLock);
- mAnrApplications.push(applicationHandle);
- mNotifyAnr.notify_all();
- }
-
- void notifyInputChannelBroken(const sp<IBinder>&) override {}
+ virtual void notifyInputChannelBroken(const sp<IBinder>&) override {}
- void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) override {}
+ virtual void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) override {}
- void notifyUntrustedTouch(const std::string& obscuringPackage) override {}
- void notifySensorEvent(int32_t deviceId, InputDeviceSensorType sensorType,
- InputDeviceSensorAccuracy accuracy, nsecs_t timestamp,
- const std::vector<float>& values) override {}
-
- void notifySensorAccuracy(int deviceId, InputDeviceSensorType sensorType,
- InputDeviceSensorAccuracy accuracy) override {}
-
- void notifyVibratorState(int32_t deviceId, bool isOn) override {}
-
- void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override {
+ virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override {
*outConfig = mConfig;
}
- bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override {
+ virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override {
std::scoped_lock lock(mLock);
switch (inputEvent->getType()) {
case AINPUT_EVENT_TYPE_KEY: {
@@ -366,20 +231,22 @@ private:
return true;
}
- void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {}
+ virtual void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {}
- void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {}
+ virtual void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {}
- nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*, uint32_t) override {
+ virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*,
+ uint32_t) override {
return 0;
}
- bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t, KeyEvent*) override {
+ virtual bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t,
+ KeyEvent*) override {
return false;
}
- void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
- uint32_t policyFlags) override {
+ virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
+ uint32_t policyFlags) override {
std::scoped_lock lock(mLock);
/** We simply reconstruct NotifySwitchArgs in policy because InputDispatcher is
* essentially a passthrough for notifySwitch.
@@ -387,29 +254,17 @@ private:
mLastNotifySwitch = NotifySwitchArgs(1 /*id*/, when, policyFlags, switchValues, switchMask);
}
- void pokeUserActivity(nsecs_t, int32_t, int32_t) override {}
+ virtual void pokeUserActivity(nsecs_t, int32_t) override {}
- bool checkInjectEventsPermissionNonReentrant(int32_t pid, int32_t uid) override {
- return pid == INJECTOR_PID && uid == INJECTOR_UID;
+ virtual bool checkInjectEventsPermissionNonReentrant(int32_t, int32_t) override {
+ return false;
}
- void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {
+ virtual void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {
std::scoped_lock lock(mLock);
mOnPointerDownToken = newToken;
}
- void setPointerCapture(bool enabled) override {
- std::scoped_lock lock(mLock);
- mPointerCaptureEnabled = {enabled};
- mPointerCaptureChangedCondition.notify_all();
- }
-
- void notifyDropWindow(const sp<IBinder>& token, float x, float y) override {
- std::scoped_lock lock(mLock);
- mNotifyDropWindowWasCalled = true;
- mDropTargetWindowToken = token;
- }
-
void assertFilterInputEventWasCalled(int type, nsecs_t eventTime, int32_t action,
int32_t displayId) {
std::scoped_lock lock(mLock);
@@ -434,6 +289,70 @@ private:
}
};
+// --- HmacKeyManagerTest ---
+
+class HmacKeyManagerTest : public testing::Test {
+protected:
+ HmacKeyManager mHmacKeyManager;
+};
+
+/**
+ * Ensure that separate calls to sign the same data are generating the same key.
+ * We avoid asserting against INVALID_HMAC. Since the key is random, there is a non-zero chance
+ * that a specific key and data combination would produce INVALID_HMAC, which would cause flaky
+ * tests.
+ */
+TEST_F(HmacKeyManagerTest, GeneratedHmac_IsConsistent) {
+ KeyEvent event = getTestKeyEvent();
+ VerifiedKeyEvent verifiedEvent = verifiedKeyEventFromKeyEvent(event);
+
+ std::array<uint8_t, 32> hmac1 = mHmacKeyManager.sign(verifiedEvent);
+ std::array<uint8_t, 32> hmac2 = mHmacKeyManager.sign(verifiedEvent);
+ ASSERT_EQ(hmac1, hmac2);
+}
+
+/**
+ * Ensure that changes in VerifiedKeyEvent produce a different hmac.
+ */
+TEST_F(HmacKeyManagerTest, GeneratedHmac_ChangesWhenFieldsChange) {
+ KeyEvent event = getTestKeyEvent();
+ VerifiedKeyEvent verifiedEvent = verifiedKeyEventFromKeyEvent(event);
+ std::array<uint8_t, 32> initialHmac = mHmacKeyManager.sign(verifiedEvent);
+
+ verifiedEvent.deviceId += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.source += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.eventTimeNanos += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.displayId += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.action += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.downTimeNanos += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.flags += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.keyCode += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.scanCode += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.metaState += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+
+ verifiedEvent.repeatCount += 1;
+ ASSERT_NE(initialHmac, mHmacKeyManager.sign(verifiedEvent));
+}
+
// --- InputDispatcherTest ---
class InputDispatcherTest : public testing::Test {
@@ -441,7 +360,7 @@ protected:
sp<FakeInputDispatcherPolicy> mFakePolicy;
sp<InputDispatcher> mDispatcher;
- void SetUp() override {
+ virtual void SetUp() override {
mFakePolicy = new FakeInputDispatcherPolicy();
mDispatcher = new InputDispatcher(mFakePolicy);
mDispatcher->setInputDispatchMode(/*enabled*/ true, /*frozen*/ false);
@@ -449,7 +368,7 @@ protected:
ASSERT_EQ(OK, mDispatcher->start());
}
- void TearDown() override {
+ virtual void TearDown() override {
ASSERT_EQ(OK, mDispatcher->stop());
mFakePolicy.clear();
mDispatcher.clear();
@@ -468,19 +387,6 @@ protected:
ALOGE("%s", to.c_str());
}
}
-
- void setFocusedWindow(const sp<InputWindowHandle>& window,
- const sp<InputWindowHandle>& focusedWindow = nullptr) {
- FocusRequest request;
- request.token = window->getToken();
- request.windowName = window->getName();
- if (focusedWindow) {
- request.focusedToken = focusedWindow->getToken();
- }
- request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
- request.displayId = window->getInfo()->displayId;
- mDispatcher->setFocusedWindow(request);
- }
};
TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) {
@@ -491,18 +397,18 @@ TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) {
INVALID_HMAC,
/*action*/ -1, 0, AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME,
ARBITRARY_TIME);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject key events with undefined action.";
// Rejects ACTION_MULTIPLE since it is not supported despite being defined in the API.
event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE,
INVALID_HMAC, AKEY_EVENT_ACTION_MULTIPLE, 0, AKEYCODE_A, KEY_A, AMETA_NONE, 0,
ARBITRARY_TIME, ARBITRARY_TIME);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject key events with ACTION_MULTIPLE.";
}
@@ -522,119 +428,113 @@ TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesMotionEvents) {
constexpr int32_t metaState = AMETA_NONE;
constexpr MotionClassification classification = MotionClassification::NONE;
- ui::Transform identityTransform;
// Rejects undefined motion actions.
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
- /*action*/ -1, 0, 0, edgeFlags, metaState, 0, classification,
- identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, ARBITRARY_TIME, ARBITRARY_TIME,
+ /*action*/ -1, 0, 0, edgeFlags, metaState, 0, classification, 1 /* xScale */,
+ 1 /* yScale */, 0, 0, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, ARBITRARY_TIME, ARBITRARY_TIME,
/*pointerCount*/ 1, pointerProperties, pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with undefined action.";
// Rejects pointer down with invalid index.
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_POINTER_DOWN |
(1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- 0, 0, edgeFlags, metaState, 0, classification, identityTransform, 0, 0,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- ARBITRARY_TIME, ARBITRARY_TIME, /*pointerCount*/ 1, pointerProperties,
- pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ 0, 0, edgeFlags, metaState, 0, classification, 1 /* xScale */, 1 /* yScale */,
+ 0, 0, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, ARBITRARY_TIME, ARBITRARY_TIME,
+ /*pointerCount*/ 1, pointerProperties, pointerCoords);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with pointer down index too large.";
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_POINTER_DOWN |
(~0U << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- 0, 0, edgeFlags, metaState, 0, classification, identityTransform, 0, 0,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- ARBITRARY_TIME, ARBITRARY_TIME, /*pointerCount*/ 1, pointerProperties,
- pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ 0, 0, edgeFlags, metaState, 0, classification, 1 /* xScale */, 1 /* yScale */,
+ 0, 0, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, ARBITRARY_TIME, ARBITRARY_TIME,
+ /*pointerCount*/ 1, pointerProperties, pointerCoords);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with pointer down index too small.";
// Rejects pointer up with invalid index.
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_POINTER_UP |
(1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- 0, 0, edgeFlags, metaState, 0, classification, identityTransform, 0, 0,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- ARBITRARY_TIME, ARBITRARY_TIME, /*pointerCount*/ 1, pointerProperties,
- pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ 0, 0, edgeFlags, metaState, 0, classification, 1 /* xScale */, 1 /* yScale */,
+ 0, 0, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, ARBITRARY_TIME, ARBITRARY_TIME,
+ /*pointerCount*/ 1, pointerProperties, pointerCoords);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with pointer up index too large.";
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_POINTER_UP |
(~0U << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- 0, 0, edgeFlags, metaState, 0, classification, identityTransform, 0, 0,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- ARBITRARY_TIME, ARBITRARY_TIME, /*pointerCount*/ 1, pointerProperties,
- pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ 0, 0, edgeFlags, metaState, 0, classification, 1 /* xScale */, 1 /* yScale */,
+ 0, 0, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, ARBITRARY_TIME, ARBITRARY_TIME,
+ /*pointerCount*/ 1, pointerProperties, pointerCoords);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with pointer up index too small.";
// Rejects motion events with invalid number of pointers.
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification,
- identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, ARBITRARY_TIME, ARBITRARY_TIME,
+ 1 /* xScale */, 1 /* yScale */, 0, 0, 0, 0,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ ARBITRARY_TIME, ARBITRARY_TIME,
/*pointerCount*/ 0, pointerProperties, pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with 0 pointers.";
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification,
- identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, ARBITRARY_TIME, ARBITRARY_TIME,
+ 1 /* xScale */, 1 /* yScale */, 0, 0, 0, 0,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ ARBITRARY_TIME, ARBITRARY_TIME,
/*pointerCount*/ MAX_POINTERS + 1, pointerProperties, pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with more than MAX_POINTERS pointers.";
// Rejects motion events with invalid pointer ids.
pointerProperties[0].id = -1;
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification,
- identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, ARBITRARY_TIME, ARBITRARY_TIME,
+ 1 /* xScale */, 1 /* yScale */, 0, 0, 0, 0,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ ARBITRARY_TIME, ARBITRARY_TIME,
/*pointerCount*/ 1, pointerProperties, pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with pointer ids less than 0.";
pointerProperties[0].id = MAX_POINTER_ID + 1;
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification,
- identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, ARBITRARY_TIME, ARBITRARY_TIME,
+ 1 /* xScale */, 1 /* yScale */, 0, 0, 0, 0,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ ARBITRARY_TIME, ARBITRARY_TIME,
/*pointerCount*/ 1, pointerProperties, pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with pointer ids greater than MAX_POINTER_ID.";
// Rejects motion events with duplicate pointer ids.
@@ -642,13 +542,13 @@ TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesMotionEvents) {
pointerProperties[1].id = 1;
event.initialize(InputEvent::nextId(), DEVICE_ID, source, DISPLAY_ID, INVALID_HMAC,
AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, metaState, 0, classification,
- identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_DISPLAY_SIZE,
- AMOTION_EVENT_INVALID_DISPLAY_SIZE, ARBITRARY_TIME, ARBITRARY_TIME,
+ 1 /* xScale */, 1 /* yScale */, 0, 0, 0, 0,
+ AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
+ ARBITRARY_TIME, ARBITRARY_TIME,
/*pointerCount*/ 2, pointerProperties, pointerCoords);
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::NONE, 0ms, 0))
+ INPUT_EVENT_INJECTION_SYNC_NONE, 0ms, 0))
<< "Should reject motion events with duplicate pointer ids.";
}
@@ -682,23 +582,22 @@ public:
FakeApplicationHandle() {
mInfo.name = "Fake Application";
mInfo.token = new BBinder();
- mInfo.dispatchingTimeoutMillis =
- std::chrono::duration_cast<std::chrono::milliseconds>(DISPATCHING_TIMEOUT).count();
+ mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT.count();
}
virtual ~FakeApplicationHandle() {}
virtual bool updateInfo() override { return true; }
- void setDispatchingTimeout(std::chrono::milliseconds timeout) {
- mInfo.dispatchingTimeoutMillis = timeout.count();
+ void setDispatchingTimeout(std::chrono::nanoseconds timeout) {
+ mInfo.dispatchingTimeout = timeout.count();
}
};
class FakeInputReceiver {
public:
- explicit FakeInputReceiver(std::unique_ptr<InputChannel> clientChannel, const std::string name)
+ explicit FakeInputReceiver(const sp<InputChannel>& clientChannel, const std::string name)
: mName(name) {
- mConsumer = std::make_unique<InputConsumer>(std::move(clientChannel));
+ mConsumer = std::make_unique<InputConsumer>(clientChannel);
}
InputEvent* consume() {
@@ -757,14 +656,8 @@ public:
ASSERT_EQ(OK, status) << mName.c_str() << ": consumer sendFinishedSignal should return OK.";
}
- void sendTimeline(int32_t inputEventId, std::array<nsecs_t, GraphicsTimeline::SIZE> timeline) {
- const status_t status = mConsumer->sendTimeline(inputEventId, timeline);
- ASSERT_EQ(OK, status);
- }
-
- void consumeEvent(int32_t expectedEventType, int32_t expectedAction,
- std::optional<int32_t> expectedDisplayId,
- std::optional<int32_t> expectedFlags) {
+ void consumeEvent(int32_t expectedEventType, int32_t expectedAction, int32_t expectedDisplayId,
+ int32_t expectedFlags) {
InputEvent* event = consume();
ASSERT_NE(nullptr, event) << mName.c_str()
@@ -773,36 +666,24 @@ public:
<< mName.c_str() << " expected " << inputEventTypeToString(expectedEventType)
<< " event, got " << inputEventTypeToString(event->getType()) << " event";
- if (expectedDisplayId.has_value()) {
- EXPECT_EQ(expectedDisplayId, event->getDisplayId());
- }
+ EXPECT_EQ(expectedDisplayId, event->getDisplayId());
switch (expectedEventType) {
case AINPUT_EVENT_TYPE_KEY: {
const KeyEvent& keyEvent = static_cast<const KeyEvent&>(*event);
EXPECT_EQ(expectedAction, keyEvent.getAction());
- if (expectedFlags.has_value()) {
- EXPECT_EQ(expectedFlags.value(), keyEvent.getFlags());
- }
+ EXPECT_EQ(expectedFlags, keyEvent.getFlags());
break;
}
case AINPUT_EVENT_TYPE_MOTION: {
const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
EXPECT_EQ(expectedAction, motionEvent.getAction());
- if (expectedFlags.has_value()) {
- EXPECT_EQ(expectedFlags.value(), motionEvent.getFlags());
- }
+ EXPECT_EQ(expectedFlags, motionEvent.getFlags());
break;
}
case AINPUT_EVENT_TYPE_FOCUS: {
FAIL() << "Use 'consumeFocusEvent' for FOCUS events";
}
- case AINPUT_EVENT_TYPE_CAPTURE: {
- FAIL() << "Use 'consumeCaptureEvent' for CAPTURE events";
- }
- case AINPUT_EVENT_TYPE_DRAG: {
- FAIL() << "Use 'consumeDragEvent' for DRAG events";
- }
default: {
FAIL() << mName.c_str() << ": invalid event type: " << expectedEventType;
}
@@ -825,38 +706,6 @@ public:
EXPECT_EQ(inTouchMode, focusEvent->getInTouchMode());
}
- void consumeCaptureEvent(bool hasCapture) {
- 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(ADISPLAY_ID_NONE, event->getDisplayId())
- << mName.c_str() << ": event displayId should always be NONE.";
-
- const auto& captureEvent = static_cast<const CaptureEvent&>(*event);
- EXPECT_EQ(hasCapture, captureEvent.getPointerCaptureEnabled());
- }
-
- void consumeDragEvent(bool isExiting, float x, float y) {
- 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";
-
- EXPECT_EQ(ADISPLAY_ID_NONE, event->getDisplayId())
- << mName.c_str() << ": event displayId should always be NONE.";
-
- const auto& dragEvent = static_cast<const DragEvent&>(*event);
- EXPECT_EQ(isExiting, dragEvent.isExiting());
- EXPECT_EQ(x, dragEvent.getX());
- EXPECT_EQ(y, dragEvent.getY());
- }
-
void assertNoEvents() {
InputEvent* event = consume();
if (event == nullptr) {
@@ -874,10 +723,6 @@ public:
FocusEvent& focusEvent = static_cast<FocusEvent&>(*event);
ADD_FAILURE() << "Received focus event, hasFocus = "
<< (focusEvent.getHasFocus() ? "true" : "false");
- } else if (event->getType() == AINPUT_EVENT_TYPE_CAPTURE) {
- const auto& captureEvent = static_cast<CaptureEvent&>(*event);
- ADD_FAILURE() << "Received capture event, pointerCaptureEnabled = "
- << (captureEvent.getPointerCaptureEnabled() ? "true" : "false");
}
FAIL() << mName.c_str()
<< ": should not have received any events, so consume() should return NULL";
@@ -897,87 +742,71 @@ public:
static const int32_t WIDTH = 600;
static const int32_t HEIGHT = 800;
- FakeWindowHandle(const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle,
+ FakeWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle,
const sp<InputDispatcher>& dispatcher, const std::string name,
- int32_t displayId, std::optional<sp<IBinder>> token = std::nullopt)
+ int32_t displayId, sp<IBinder> token = nullptr)
: mName(name) {
- if (token == std::nullopt) {
- base::Result<std::unique_ptr<InputChannel>> channel =
- dispatcher->createInputChannel(name);
- token = (*channel)->getConnectionToken();
- mInputReceiver = std::make_unique<FakeInputReceiver>(std::move(*channel), name);
+ if (token == nullptr) {
+ sp<InputChannel> serverChannel, clientChannel;
+ InputChannel::openInputChannelPair(name, serverChannel, clientChannel);
+ mInputReceiver = std::make_unique<FakeInputReceiver>(clientChannel, name);
+ dispatcher->registerInputChannel(serverChannel);
+ token = serverChannel->getConnectionToken();
}
inputApplicationHandle->updateInfo();
mInfo.applicationInfo = *inputApplicationHandle->getInfo();
- mInfo.token = *token;
+ mInfo.token = token;
mInfo.id = sId++;
mInfo.name = name;
- mInfo.type = InputWindowInfo::Type::APPLICATION;
- mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT;
- mInfo.alpha = 1.0;
+ mInfo.layoutParamsFlags = 0;
+ mInfo.layoutParamsType = InputWindowInfo::TYPE_APPLICATION;
+ mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT.count();
mInfo.frameLeft = 0;
mInfo.frameTop = 0;
mInfo.frameRight = WIDTH;
mInfo.frameBottom = HEIGHT;
- mInfo.transform.set(0, 0);
mInfo.globalScaleFactor = 1.0;
mInfo.touchableRegion.clear();
mInfo.addTouchableRegion(Rect(0, 0, WIDTH, HEIGHT));
mInfo.visible = true;
- mInfo.focusable = false;
+ mInfo.canReceiveKeys = true;
+ mInfo.hasFocus = false;
mInfo.hasWallpaper = false;
mInfo.paused = false;
mInfo.ownerPid = INJECTOR_PID;
mInfo.ownerUid = INJECTOR_UID;
+ mInfo.inputFeatures = 0;
mInfo.displayId = displayId;
}
virtual bool updateInfo() { return true; }
- void setFocusable(bool focusable) { mInfo.focusable = focusable; }
-
- void setVisible(bool visible) { mInfo.visible = visible; }
+ void setFocus(bool hasFocus) { mInfo.hasFocus = hasFocus; }
void setDispatchingTimeout(std::chrono::nanoseconds timeout) {
- mInfo.dispatchingTimeout = timeout;
+ mInfo.dispatchingTimeout = timeout.count();
}
void setPaused(bool paused) { mInfo.paused = paused; }
- void setAlpha(float alpha) { mInfo.alpha = alpha; }
-
- void setTouchOcclusionMode(android::os::TouchOcclusionMode mode) {
- mInfo.touchOcclusionMode = mode;
- }
-
- void setApplicationToken(sp<IBinder> token) { mInfo.applicationInfo.token = token; }
-
void setFrame(const Rect& frame) {
mInfo.frameLeft = frame.left;
mInfo.frameTop = frame.top;
mInfo.frameRight = frame.right;
mInfo.frameBottom = frame.bottom;
- mInfo.transform.set(-frame.left, -frame.top);
mInfo.touchableRegion.clear();
mInfo.addTouchableRegion(frame);
}
- void addFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags |= flags; }
-
- void setFlags(Flags<InputWindowInfo::Flag> flags) { mInfo.flags = flags; }
+ void setLayoutParamFlags(int32_t flags) { mInfo.layoutParamsFlags = flags; }
- void setInputFeatures(InputWindowInfo::Feature features) { mInfo.inputFeatures = features; }
-
- void setWindowTransform(float dsdx, float dtdx, float dtdy, float dsdy) {
- mInfo.transform.set(dsdx, dtdx, dtdy, dsdy);
+ void setWindowScale(float xScale, float yScale) {
+ mInfo.windowXScale = xScale;
+ mInfo.windowYScale = yScale;
}
- void setWindowScale(float xScale, float yScale) { setWindowTransform(xScale, 0, 0, yScale); }
-
- 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);
@@ -1001,11 +830,6 @@ public:
void consumeMotionDown(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT,
int32_t expectedFlags = 0) {
- consumeAnyMotionDown(expectedDisplayId, expectedFlags);
- }
-
- 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,
expectedFlags);
}
@@ -1031,36 +855,19 @@ public:
expectedFlags);
}
- void consumeMotionOutside(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT,
- int32_t expectedFlags = 0) {
- consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE, expectedDisplayId,
- expectedFlags);
- }
-
void consumeFocusEvent(bool hasFocus, bool inTouchMode = true) {
ASSERT_NE(mInputReceiver, nullptr)
<< "Cannot consume events from a window with no receiver";
mInputReceiver->consumeFocusEvent(hasFocus, inTouchMode);
}
- void consumeCaptureEvent(bool hasCapture) {
- ASSERT_NE(mInputReceiver, nullptr)
- << "Cannot consume events from a window with no receiver";
- mInputReceiver->consumeCaptureEvent(hasCapture);
- }
-
- void consumeEvent(int32_t expectedEventType, int32_t expectedAction,
- std::optional<int32_t> expectedDisplayId,
- std::optional<int32_t> expectedFlags) {
+ void consumeEvent(int32_t expectedEventType, int32_t expectedAction, int32_t expectedDisplayId,
+ int32_t expectedFlags) {
ASSERT_NE(mInputReceiver, nullptr) << "Invalid consume event on window with no receiver";
mInputReceiver->consumeEvent(expectedEventType, expectedAction, expectedDisplayId,
expectedFlags);
}
- void consumeDragEvent(bool isExiting, float x, float y) {
- mInputReceiver->consumeDragEvent(isExiting, x, y);
- }
-
std::optional<uint32_t> receiveEvent(InputEvent** outEvent = nullptr) {
if (mInputReceiver == nullptr) {
ADD_FAILURE() << "Invalid receive event on window with no receiver";
@@ -1074,11 +881,6 @@ public:
mInputReceiver->finishEvent(sequenceNum);
}
- void sendTimeline(int32_t inputEventId, std::array<nsecs_t, GraphicsTimeline::SIZE> timeline) {
- ASSERT_NE(mInputReceiver, nullptr) << "Invalid receive event on window with no receiver";
- mInputReceiver->sendTimeline(inputEventId, timeline);
- }
-
InputEvent* consume() {
if (mInputReceiver == nullptr) {
return nullptr;
@@ -1086,27 +888,9 @@ public:
return mInputReceiver->consume();
}
- MotionEvent* consumeMotion() {
- InputEvent* event = consume();
- if (event == nullptr) {
- 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());
- return nullptr;
- }
- return static_cast<MotionEvent*>(event);
- }
-
void assertNoEvents() {
- if (mInputReceiver == nullptr &&
- mInfo.inputFeatures.test(InputWindowInfo::Feature::NO_INPUT_CHANNEL)) {
- return; // Can't receive events if the window does not have input channel
- }
- ASSERT_NE(nullptr, mInputReceiver)
- << "Window without InputReceiver must specify feature NO_INPUT_CHANNEL";
+ ASSERT_NE(mInputReceiver, nullptr)
+ << "Call 'assertNoEvents' on a window with an InputReceiver";
mInputReceiver->assertNoEvents();
}
@@ -1127,12 +911,10 @@ private:
std::atomic<int32_t> FakeWindowHandle::sId{1};
-static InputEventInjectionResult injectKey(
- const sp<InputDispatcher>& dispatcher, int32_t action, int32_t repeatCount,
- int32_t displayId = ADISPLAY_ID_NONE,
- InputEventInjectionSync syncMode = InputEventInjectionSync::WAIT_FOR_RESULT,
- std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT,
- bool allowKeyRepeat = true) {
+static int32_t injectKey(const sp<InputDispatcher>& dispatcher, int32_t action, int32_t repeatCount,
+ int32_t displayId = ADISPLAY_ID_NONE,
+ int32_t syncMode = INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
+ std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT) {
KeyEvent event;
nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
@@ -1141,203 +923,74 @@ static InputEventInjectionResult injectKey(
INVALID_HMAC, action, /* flags */ 0, AKEYCODE_A, KEY_A, AMETA_NONE,
repeatCount, currentTime, currentTime);
- int32_t policyFlags = POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER;
- if (!allowKeyRepeat) {
- policyFlags |= POLICY_FLAG_DISABLE_KEY_REPEAT;
- }
// Inject event until dispatch out.
return dispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID, syncMode,
- injectionTimeout, policyFlags);
+ injectionTimeout,
+ POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER);
}
-static InputEventInjectionResult injectKeyDown(const sp<InputDispatcher>& dispatcher,
- int32_t displayId = ADISPLAY_ID_NONE) {
+static int32_t injectKeyDown(const sp<InputDispatcher>& dispatcher,
+ int32_t displayId = ADISPLAY_ID_NONE) {
return injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /* repeatCount */ 0, displayId);
}
-// Inject a down event that has key repeat disabled. This allows InputDispatcher to idle without
-// sending a subsequent key up. When key repeat is enabled, the dispatcher cannot idle because it
-// has to be woken up to process the repeating key.
-static InputEventInjectionResult injectKeyDownNoRepeat(const sp<InputDispatcher>& dispatcher,
- int32_t displayId = ADISPLAY_ID_NONE) {
- return injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /* repeatCount */ 0, displayId,
- InputEventInjectionSync::WAIT_FOR_RESULT, INJECT_EVENT_TIMEOUT,
- /* allowKeyRepeat */ false);
-}
-
-static InputEventInjectionResult injectKeyUp(const sp<InputDispatcher>& dispatcher,
- int32_t displayId = ADISPLAY_ID_NONE) {
+static int32_t injectKeyUp(const sp<InputDispatcher>& dispatcher,
+ int32_t displayId = ADISPLAY_ID_NONE) {
return injectKey(dispatcher, AKEY_EVENT_ACTION_UP, /* repeatCount */ 0, displayId);
}
-class PointerBuilder {
-public:
- PointerBuilder(int32_t id, int32_t toolType) {
- mProperties.clear();
- mProperties.id = id;
- mProperties.toolType = toolType;
- mCoords.clear();
- }
-
- PointerBuilder& x(float x) { return axis(AMOTION_EVENT_AXIS_X, x); }
-
- PointerBuilder& y(float y) { return axis(AMOTION_EVENT_AXIS_Y, y); }
-
- PointerBuilder& axis(int32_t axis, float value) {
- mCoords.setAxisValue(axis, value);
- return *this;
- }
-
- PointerProperties buildProperties() const { return mProperties; }
-
- PointerCoords buildCoords() const { return mCoords; }
-
-private:
- PointerProperties mProperties;
- PointerCoords mCoords;
-};
-
-class MotionEventBuilder {
-public:
- MotionEventBuilder(int32_t action, int32_t source) {
- mAction = action;
- mSource = source;
- mEventTime = systemTime(SYSTEM_TIME_MONOTONIC);
- }
-
- MotionEventBuilder& eventTime(nsecs_t eventTime) {
- mEventTime = eventTime;
- return *this;
- }
-
- MotionEventBuilder& displayId(int32_t displayId) {
- mDisplayId = displayId;
- return *this;
- }
-
- MotionEventBuilder& actionButton(int32_t actionButton) {
- mActionButton = actionButton;
- return *this;
- }
-
- MotionEventBuilder& buttonState(int32_t buttonState) {
- mButtonState = buttonState;
- return *this;
- }
-
- MotionEventBuilder& rawXCursorPosition(float rawXCursorPosition) {
- mRawXCursorPosition = rawXCursorPosition;
- return *this;
- }
-
- MotionEventBuilder& rawYCursorPosition(float rawYCursorPosition) {
- mRawYCursorPosition = rawYCursorPosition;
- return *this;
- }
-
- MotionEventBuilder& pointer(PointerBuilder pointer) {
- mPointers.push_back(pointer);
- return *this;
- }
-
- MotionEventBuilder& addFlag(uint32_t flags) {
- mFlags |= flags;
- return *this;
- }
-
- MotionEvent build() {
- std::vector<PointerProperties> pointerProperties;
- std::vector<PointerCoords> pointerCoords;
- for (const PointerBuilder& pointer : mPointers) {
- pointerProperties.push_back(pointer.buildProperties());
- pointerCoords.push_back(pointer.buildCoords());
- }
-
- // Set mouse cursor position for the most common cases to avoid boilerplate.
- if (mSource == AINPUT_SOURCE_MOUSE &&
- !MotionEvent::isValidCursorPosition(mRawXCursorPosition, mRawYCursorPosition) &&
- mPointers.size() == 1) {
- mRawXCursorPosition = pointerCoords[0].getX();
- mRawYCursorPosition = pointerCoords[0].getY();
- }
-
- MotionEvent event;
- ui::Transform identityTransform;
- event.initialize(InputEvent::nextId(), DEVICE_ID, mSource, mDisplayId, INVALID_HMAC,
- mAction, mActionButton, mFlags, /* edgeFlags */ 0, AMETA_NONE,
- mButtonState, MotionClassification::NONE, identityTransform,
- /* xPrecision */ 0, /* yPrecision */ 0, mRawXCursorPosition,
- mRawYCursorPosition, mDisplayWidth, mDisplayHeight, mEventTime, mEventTime,
- mPointers.size(), pointerProperties.data(), pointerCoords.data());
-
- return event;
- }
-
-private:
- int32_t mAction;
- int32_t mSource;
- nsecs_t mEventTime;
- int32_t mDisplayId{ADISPLAY_ID_DEFAULT};
- int32_t mActionButton{0};
- int32_t mButtonState{0};
- int32_t mFlags{0};
- float mRawXCursorPosition{AMOTION_EVENT_INVALID_CURSOR_POSITION};
- float mRawYCursorPosition{AMOTION_EVENT_INVALID_CURSOR_POSITION};
- int32_t mDisplayWidth{AMOTION_EVENT_INVALID_DISPLAY_SIZE};
- int32_t mDisplayHeight{AMOTION_EVENT_INVALID_DISPLAY_SIZE};
-
- std::vector<PointerBuilder> mPointers;
-};
-
-static InputEventInjectionResult injectMotionEvent(
- const sp<InputDispatcher>& dispatcher, const MotionEvent& event,
- std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT,
- InputEventInjectionSync injectionMode = InputEventInjectionSync::WAIT_FOR_RESULT) {
- return dispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID, injectionMode,
- injectionTimeout,
- POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER);
-}
-
-static InputEventInjectionResult injectMotionEvent(
+static int32_t injectMotionEvent(
const sp<InputDispatcher>& dispatcher, int32_t action, int32_t source, int32_t displayId,
const PointF& position,
const PointF& cursorPosition = {AMOTION_EVENT_INVALID_CURSOR_POSITION,
AMOTION_EVENT_INVALID_CURSOR_POSITION},
std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT,
- InputEventInjectionSync injectionMode = InputEventInjectionSync::WAIT_FOR_RESULT,
+ int32_t injectionMode = INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC)) {
- MotionEvent event = MotionEventBuilder(action, source)
- .displayId(displayId)
- .eventTime(eventTime)
- .rawXCursorPosition(cursorPosition.x)
- .rawYCursorPosition(cursorPosition.y)
- .pointer(PointerBuilder(/* id */ 0, AMOTION_EVENT_TOOL_TYPE_FINGER)
- .x(position.x)
- .y(position.y))
- .build();
+ MotionEvent event;
+ PointerProperties pointerProperties[1];
+ PointerCoords pointerCoords[1];
+
+ pointerProperties[0].clear();
+ pointerProperties[0].id = 0;
+ pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
+
+ pointerCoords[0].clear();
+ pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, position.x);
+ pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, position.y);
+
+ // Define a valid motion down event.
+ event.initialize(InputEvent::nextId(), DEVICE_ID, source, displayId, INVALID_HMAC, action,
+ /* actionButton */ 0,
+ /* flags */ 0,
+ /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE,
+ /* xScale */ 1, /* yScale */ 1, /* xOffset */ 0, /* yOffset */ 0,
+ /* xPrecision */ 0, /* yPrecision */ 0, cursorPosition.x, cursorPosition.y,
+ eventTime, eventTime,
+ /*pointerCount*/ 1, pointerProperties, pointerCoords);
// Inject event until dispatch out.
- return injectMotionEvent(dispatcher, event, injectionTimeout, injectionMode);
+ return dispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID, injectionMode,
+ injectionTimeout,
+ POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER);
}
-static InputEventInjectionResult injectMotionDown(const sp<InputDispatcher>& dispatcher,
- int32_t source, int32_t displayId,
- const PointF& location = {100, 200}) {
+static int32_t injectMotionDown(const sp<InputDispatcher>& dispatcher, int32_t source,
+ int32_t displayId, const PointF& location = {100, 200}) {
return injectMotionEvent(dispatcher, AMOTION_EVENT_ACTION_DOWN, source, displayId, location);
}
-static InputEventInjectionResult injectMotionUp(const sp<InputDispatcher>& dispatcher,
- int32_t source, int32_t displayId,
- const PointF& location = {100, 200}) {
+static int32_t injectMotionUp(const sp<InputDispatcher>& dispatcher, int32_t source,
+ int32_t displayId, const PointF& location = {100, 200}) {
return injectMotionEvent(dispatcher, AMOTION_EVENT_ACTION_UP, source, displayId, location);
}
static NotifyKeyArgs generateKeyArgs(int32_t action, int32_t displayId = ADISPLAY_ID_NONE) {
nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
// Define a valid key event.
- NotifyKeyArgs args(/* id */ 0, currentTime, 0 /*readTime*/, DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
- displayId, POLICY_FLAG_PASS_TO_USER, action, /* flags */ 0, AKEYCODE_A,
- KEY_A, AMETA_NONE, currentTime);
+ NotifyKeyArgs args(/* id */ 0, currentTime, DEVICE_ID, AINPUT_SOURCE_KEYBOARD, displayId,
+ POLICY_FLAG_PASS_TO_USER, action, /* flags */ 0, AKEYCODE_A, KEY_A,
+ AMETA_NONE, currentTime);
return args;
}
@@ -1364,7 +1017,7 @@ static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, int32
nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
// Define a valid motion event.
- NotifyMotionArgs args(/* id */ 0, currentTime, 0 /*readTime*/, DEVICE_ID, source, displayId,
+ NotifyMotionArgs args(/* id */ 0, currentTime, DEVICE_ID, source, displayId,
POLICY_FLAG_PASS_TO_USER, action, /* actionButton */ 0, /* flags */ 0,
AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE,
AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, pointerProperties,
@@ -1379,19 +1032,15 @@ static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, int32
return generateMotionArgs(action, source, displayId, {PointF{100, 200}});
}
-static NotifyPointerCaptureChangedArgs generatePointerCaptureChangedArgs(bool enabled) {
- return NotifyPointerCaptureChangedArgs(/* id */ 0, systemTime(SYSTEM_TIME_MONOTONIC), enabled);
-}
-
TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
+ sp<FakeWindowHandle> window = new FakeWindowHandle(application, mDispatcher, "Fake Window",
+ ADISPLAY_ID_DEFAULT);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
// Window should receive motion event.
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
@@ -1406,17 +1055,17 @@ TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) {
* called twice.
*/
TEST_F(InputDispatcherTest, SetInputWindowOnce_SingleWindowTouch) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
window->setFrame(Rect(0, 0, 100, 100));
- window->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+ window->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
{50, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
// Window should receive motion event.
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
@@ -1429,18 +1078,18 @@ TEST_F(InputDispatcherTest, SetInputWindowOnce_SingleWindowTouch) {
* when finding touched windows.
*/
TEST_F(InputDispatcherTest, SetInputWindowTwice_SingleWindowTouch) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
window->setFrame(Rect(0, 0, 100, 100));
- window->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+ window->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
{50, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
// Window should receive motion event.
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
@@ -1448,225 +1097,107 @@ TEST_F(InputDispatcherTest, SetInputWindowTwice_SingleWindowTouch) {
// The foreground window should receive the first touch down event.
TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> windowTop =
- new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT);
- sp<FakeWindowHandle> windowSecond =
- new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT);
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
+ sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top",
+ ADISPLAY_ID_DEFAULT);
+ sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second",
+ ADISPLAY_ID_DEFAULT);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}});
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
// Top window should receive the touch down event. Second window should not receive anything.
windowTop->consumeMotionDown(ADISPLAY_ID_DEFAULT);
windowSecond->assertNoEvents();
}
-TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> windowLeft =
- new FakeWindowHandle(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT);
- windowLeft->setFrame(Rect(0, 0, 600, 800));
- windowLeft->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
- sp<FakeWindowHandle> windowRight =
- new FakeWindowHandle(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT);
- windowRight->setFrame(Rect(600, 0, 1200, 800));
- windowRight->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+TEST_F(InputDispatcherTest, SetInputWindow_FocusedWindow) {
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
+ sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top",
+ ADISPLAY_ID_DEFAULT);
+ sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second",
+ ADISPLAY_ID_DEFAULT);
+ // Set focused application.
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowLeft, windowRight}}});
+ // Display should have only one focused window
+ windowSecond->setFocus(true);
+ mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}});
- // Start cursor position in right window so that we can move the cursor to left window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE,
- AINPUT_SOURCE_MOUSE)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(900)
- .y(400))
- .build()));
- windowRight->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_ENTER,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
- windowRight->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_MOVE,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
-
- // Move cursor into left window
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE,
- AINPUT_SOURCE_MOUSE)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- windowRight->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_EXIT,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
- windowLeft->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_ENTER,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
- windowLeft->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_MOVE,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
-
- // Inject a series of mouse events for a mouse click
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- windowLeft->consumeMotionDown(ADISPLAY_ID_DEFAULT);
+ windowSecond->consumeFocusEvent(true);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS,
- AINPUT_SOURCE_MOUSE)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- windowLeft->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_BUTTON_PRESS,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_RELEASE,
- AINPUT_SOURCE_MOUSE)
- .buttonState(0)
- .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- windowLeft->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_BUTTON_RELEASE,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE)
- .buttonState(0)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- windowLeft->consumeMotionUp(ADISPLAY_ID_DEFAULT);
-
- // Move mouse cursor back to right window
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE,
- AINPUT_SOURCE_MOUSE)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(900)
- .y(400))
- .build()));
- windowLeft->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_EXIT,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
- windowRight->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_ENTER,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
- windowRight->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_MOVE,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
+ // Focused window should receive event.
+ windowTop->assertNoEvents();
+ windowSecond->consumeKeyDown(ADISPLAY_ID_NONE);
}
-// This test is different from the test above that HOVER_ENTER and HOVER_EXIT events are injected
-// directly in this test.
-TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT);
- window->setFrame(Rect(0, 0, 1200, 800));
- window->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+TEST_F(InputDispatcherTest, SetInputWindow_FocusPriority) {
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
+ sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top",
+ ADISPLAY_ID_DEFAULT);
+ sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second",
+ ADISPLAY_ID_DEFAULT);
+ // Set focused application.
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
+ // Display has two focused windows. Add them to inputWindowsHandles in z-order (top most first)
+ windowTop->setFocus(true);
+ windowSecond->setFocus(true);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER,
- AINPUT_SOURCE_MOUSE)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- window->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_ENTER,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
-
- // Inject a series of mouse events for a mouse click
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
+ mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}});
+ windowTop->consumeFocusEvent(true);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS,
- AINPUT_SOURCE_MOUSE)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- window->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_BUTTON_PRESS,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_BUTTON_RELEASE,
- AINPUT_SOURCE_MOUSE)
- .buttonState(0)
- .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- window->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_BUTTON_RELEASE,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE)
- .buttonState(0)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- window->consumeMotionUp(ADISPLAY_ID_DEFAULT);
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_EXIT,
- AINPUT_SOURCE_MOUSE)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE)
- .x(300)
- .y(400))
- .build()));
- window->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_HOVER_EXIT,
- ADISPLAY_ID_DEFAULT, 0 /* expectedFlag */);
+ // Top focused window should receive event.
+ windowTop->consumeKeyDown(ADISPLAY_ID_NONE);
+ windowSecond->assertNoEvents();
+}
+
+TEST_F(InputDispatcherTest, SetInputWindow_InputWindowInfo) {
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
+
+ sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top",
+ ADISPLAY_ID_DEFAULT);
+ sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second",
+ ADISPLAY_ID_DEFAULT);
+
+ // Set focused application.
+ mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
+
+ windowTop->setFocus(true);
+ windowSecond->setFocus(true);
+ // Release channel for window is no longer valid.
+ windowTop->releaseChannel();
+ mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}});
+ windowSecond->consumeFocusEvent(true);
+
+ // Test inject a key down, should dispatch to a valid window.
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
+
+ // Top window is invalid, so it should not receive any input event.
+ windowTop->assertNoEvents();
+ windowSecond->consumeKeyDown(ADISPLAY_ID_NONE);
}
TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> windowLeft =
new FakeWindowHandle(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT);
windowLeft->setFrame(Rect(0, 0, 600, 800));
- windowLeft->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+ windowLeft->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
sp<FakeWindowHandle> windowRight =
new FakeWindowHandle(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT);
windowRight->setFrame(Rect(600, 0, 1200, 800));
- windowRight->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+ windowRight->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
@@ -1674,7 +1205,7 @@ TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) {
// Inject an event with coordinate in the area of right window, with mouse cursor in the area of
// left window. This event should be dispatched to the left window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE,
ADISPLAY_ID_DEFAULT, {610, 400}, {599, 400}));
windowLeft->consumeMotionDown(ADISPLAY_ID_DEFAULT);
@@ -1682,14 +1213,12 @@ TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) {
}
TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsKeyStream) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
- window->setFocusable(true);
+ window->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
-
window->consumeFocusEvent(true);
NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
@@ -1707,7 +1236,7 @@ TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsKeyStream) {
}
TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsMotionStream) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
@@ -1729,14 +1258,8 @@ TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsMotionStream) {
0 /*expectedFlags*/);
}
-using TransferFunction =
- std::function<bool(sp<InputDispatcher> dispatcher, sp<IBinder>, sp<IBinder>)>;
-
-class TransferTouchFixture : public InputDispatcherTest,
- public ::testing::WithParamInterface<TransferFunction> {};
-
-TEST_P(TransferTouchFixture, TransferTouch_OnePointer) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+TEST_F(InputDispatcherTest, TransferTouchFocus_OnePointer) {
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
// Create a couple of windows
sp<FakeWindowHandle> firstWindow =
@@ -1756,10 +1279,8 @@ TEST_P(TransferTouchFixture, TransferTouch_OnePointer) {
firstWindow->consumeMotionDown();
secondWindow->assertNoEvents();
- // Transfer touch to the second window
- TransferFunction f = GetParam();
- const bool success = f(mDispatcher, firstWindow->getToken(), secondWindow->getToken());
- ASSERT_TRUE(success);
+ // Transfer touch focus to the second window
+ mDispatcher->transferTouchFocus(firstWindow->getToken(), secondWindow->getToken());
// The first window gets cancel and the second gets down
firstWindow->consumeMotionCancel();
secondWindow->consumeMotionDown();
@@ -1774,8 +1295,8 @@ TEST_P(TransferTouchFixture, TransferTouch_OnePointer) {
secondWindow->consumeMotionUp();
}
-TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+TEST_F(InputDispatcherTest, TransferTouchFocus_TwoPointerNoSplitTouch) {
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
PointF touchPoint = {10, 10};
@@ -1809,9 +1330,7 @@ TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) {
secondWindow->assertNoEvents();
// Transfer touch focus to the second window
- TransferFunction f = GetParam();
- bool success = f(mDispatcher, firstWindow->getToken(), secondWindow->getToken());
- ASSERT_TRUE(success);
+ mDispatcher->transferTouchFocus(firstWindow->getToken(), secondWindow->getToken());
// The first window gets cancel and the second gets down and pointer down
firstWindow->consumeMotionCancel();
secondWindow->consumeMotionDown();
@@ -1838,37 +1357,22 @@ TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) {
secondWindow->consumeMotionUp();
}
-// For the cases of single pointer touch and two pointers non-split touch, the api's
-// 'transferTouch' and 'transferTouchFocus' are equivalent in behaviour. They only differ
-// for the case where there are multiple pointers split across several windows.
-INSTANTIATE_TEST_SUITE_P(TransferFunctionTests, TransferTouchFixture,
- ::testing::Values(
- [&](sp<InputDispatcher> dispatcher, sp<IBinder> /*ignored*/,
- sp<IBinder> destChannelToken) {
- return dispatcher->transferTouch(destChannelToken);
- },
- [&](sp<InputDispatcher> dispatcher, sp<IBinder> from,
- sp<IBinder> to) {
- return dispatcher->transferTouchFocus(from, to,
- false /*isDragAndDrop*/);
- }));
-
TEST_F(InputDispatcherTest, TransferTouchFocus_TwoPointersSplitTouch) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
// Create a non touch modal window that supports split touch
sp<FakeWindowHandle> firstWindow =
new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT);
firstWindow->setFrame(Rect(0, 0, 600, 400));
- firstWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
+ firstWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL
+ | InputWindowInfo::FLAG_SPLIT_TOUCH);
// Create a non touch modal window that supports split touch
sp<FakeWindowHandle> secondWindow =
new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT);
secondWindow->setFrame(Rect(0, 400, 600, 800));
- secondWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
+ secondWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL
+ | InputWindowInfo::FLAG_SPLIT_TOUCH);
// Add the windows to the dispatcher
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {firstWindow, secondWindow}}});
@@ -1923,90 +1427,13 @@ TEST_F(InputDispatcherTest, TransferTouchFocus_TwoPointersSplitTouch) {
secondWindow->consumeMotionUp();
}
-// Same as TransferTouchFocus_TwoPointersSplitTouch, but using 'transferTouch' api.
-// Unlike 'transferTouchFocus', calling 'transferTouch' when there are two windows receiving
-// touch is not supported, so the touch should continue on those windows and the transferred-to
-// window should get nothing.
-TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
-
- // Create a non touch modal window that supports split touch
- sp<FakeWindowHandle> firstWindow =
- new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT);
- firstWindow->setFrame(Rect(0, 0, 600, 400));
- firstWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
-
- // Create a non touch modal window that supports split touch
- sp<FakeWindowHandle> secondWindow =
- new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT);
- secondWindow->setFrame(Rect(0, 400, 600, 800));
- secondWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
-
- // Add the windows to the dispatcher
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {firstWindow, secondWindow}}});
-
- PointF pointInFirst = {300, 200};
- PointF pointInSecond = {300, 600};
-
- // Send down to the first window
- NotifyMotionArgs firstDownMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInFirst});
- mDispatcher->notifyMotion(&firstDownMotionArgs);
- // Only the first window should get the down event
- firstWindow->consumeMotionDown();
- secondWindow->assertNoEvents();
-
- // Send down to the second window
- NotifyMotionArgs secondDownMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_POINTER_DOWN |
- (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- mDispatcher->notifyMotion(&secondDownMotionArgs);
- // The first window gets a move and the second a down
- firstWindow->consumeMotionMove();
- secondWindow->consumeMotionDown();
-
- // Transfer touch focus to the second window
- const bool transferred = mDispatcher->transferTouch(secondWindow->getToken());
- // The 'transferTouch' call should not succeed, because there are 2 touched windows
- ASSERT_FALSE(transferred);
- firstWindow->assertNoEvents();
- secondWindow->assertNoEvents();
-
- // The rest of the dispatch should proceed as normal
- // Send pointer up to the second window
- NotifyMotionArgs pointerUpMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_POINTER_UP |
- (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- mDispatcher->notifyMotion(&pointerUpMotionArgs);
- // The first window gets MOVE and the second gets pointer up
- firstWindow->consumeMotionMove();
- secondWindow->consumeMotionUp();
-
- // Send up event to the first window
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
- // The first window gets nothing and the second gets up
- firstWindow->consumeMotionUp();
- secondWindow->assertNoEvents();
-}
-
TEST_F(InputDispatcherTest, FocusedWindow_ReceivesFocusEventAndKeyEvent) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
- window->setFocusable(true);
+ window->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
window->consumeFocusEvent(true);
@@ -2018,7 +1445,7 @@ TEST_F(InputDispatcherTest, FocusedWindow_ReceivesFocusEventAndKeyEvent) {
}
TEST_F(InputDispatcherTest, UnfocusedWindow_DoesNotReceiveFocusEventOrKeyEvent) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
@@ -2033,7 +1460,7 @@ TEST_F(InputDispatcherTest, UnfocusedWindow_DoesNotReceiveFocusEventOrKeyEvent)
// If a window is touchable, but does not have focus, it should receive motion events, but not keys
TEST_F(InputDispatcherTest, UnfocusedWindow_ReceivesMotionsButNotKeys) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
@@ -2053,93 +1480,14 @@ TEST_F(InputDispatcherTest, UnfocusedWindow_ReceivesMotionsButNotKeys) {
window->assertNoEvents(); // Key event or focus event will not be received
}
-TEST_F(InputDispatcherTest, PointerCancel_SendCancelWhenSplitTouch) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
-
- // Create first non touch modal window that supports split touch
- sp<FakeWindowHandle> firstWindow =
- new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT);
- firstWindow->setFrame(Rect(0, 0, 600, 400));
- firstWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
-
- // Create second non touch modal window that supports split touch
- sp<FakeWindowHandle> secondWindow =
- new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT);
- secondWindow->setFrame(Rect(0, 400, 600, 800));
- secondWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
-
- // Add the windows to the dispatcher
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {firstWindow, secondWindow}}});
-
- PointF pointInFirst = {300, 200};
- PointF pointInSecond = {300, 600};
-
- // Send down to the first window
- NotifyMotionArgs firstDownMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInFirst});
- mDispatcher->notifyMotion(&firstDownMotionArgs);
- // Only the first window should get the down event
- firstWindow->consumeMotionDown();
- secondWindow->assertNoEvents();
-
- // Send down to the second window
- NotifyMotionArgs secondDownMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_POINTER_DOWN |
- (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- mDispatcher->notifyMotion(&secondDownMotionArgs);
- // The first window gets a move and the second a down
- firstWindow->consumeMotionMove();
- secondWindow->consumeMotionDown();
-
- // Send pointer cancel to the second window
- NotifyMotionArgs pointerUpMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_POINTER_UP |
- (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- pointerUpMotionArgs.flags |= AMOTION_EVENT_FLAG_CANCELED;
- mDispatcher->notifyMotion(&pointerUpMotionArgs);
- // The first window gets move and the second gets cancel.
- firstWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_CANCELED);
- secondWindow->consumeMotionCancel(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_CANCELED);
-
- // Send up event.
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
- // The first window gets up and the second gets nothing.
- firstWindow->consumeMotionUp();
- secondWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherTest, SendTimeline_DoesNotCrashDispatcher) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
-
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
- graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 2;
- graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 3;
-
- window->sendTimeline(1 /*inputEventId*/, graphicsTimeline);
- window->assertNoEvents();
- mDispatcher->waitForIdle();
-}
-
class FakeMonitorReceiver {
public:
FakeMonitorReceiver(const sp<InputDispatcher>& dispatcher, const std::string name,
int32_t displayId, bool isGestureMonitor = false) {
- base::Result<std::unique_ptr<InputChannel>> channel =
- dispatcher->createInputMonitor(displayId, isGestureMonitor, name, MONITOR_PID);
- mInputReceiver = std::make_unique<FakeInputReceiver>(std::move(*channel), name);
+ sp<InputChannel> serverChannel, clientChannel;
+ InputChannel::openInputChannelPair(name, serverChannel, clientChannel);
+ mInputReceiver = std::make_unique<FakeInputReceiver>(clientChannel, name);
+ dispatcher->registerInputMonitor(serverChannel, displayId, isGestureMonitor);
}
sp<IBinder> getToken() { return mInputReceiver->getToken(); }
@@ -2163,19 +1511,6 @@ public:
expectedDisplayId, expectedFlags);
}
- MotionEvent* consumeMotion() {
- InputEvent* event = mInputReceiver->consume();
- if (!event) {
- 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";
- return nullptr;
- }
- return static_cast<MotionEvent*>(event);
- }
-
void assertNoEvents() { mInputReceiver->assertNoEvents(); }
private:
@@ -2184,7 +1519,7 @@ private:
// Tests for gesture monitors
TEST_F(InputDispatcherTest, GestureMonitor_ReceivesMotionEvents) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
@@ -2192,37 +1527,35 @@ TEST_F(InputDispatcherTest, GestureMonitor_ReceivesMotionEvents) {
FakeMonitorReceiver monitor = FakeMonitorReceiver(mDispatcher, "GM_1", ADISPLAY_ID_DEFAULT,
true /*isGestureMonitor*/);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
monitor.consumeMotionDown(ADISPLAY_ID_DEFAULT);
}
TEST_F(InputDispatcherTest, GestureMonitor_DoesNotReceiveKeyEvents) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
- window->setFocusable(true);
+ window->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
-
window->consumeFocusEvent(true);
FakeMonitorReceiver monitor = FakeMonitorReceiver(mDispatcher, "GM_1", ADISPLAY_ID_DEFAULT,
true /*isGestureMonitor*/);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
window->consumeKeyDown(ADISPLAY_ID_DEFAULT);
monitor.assertNoEvents();
}
TEST_F(InputDispatcherTest, GestureMonitor_CanPilferAfterWindowIsRemovedMidStream) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
@@ -2230,9 +1563,9 @@ TEST_F(InputDispatcherTest, GestureMonitor_CanPilferAfterWindowIsRemovedMidStrea
FakeMonitorReceiver monitor = FakeMonitorReceiver(mDispatcher, "GM_1", ADISPLAY_ID_DEFAULT,
true /*isGestureMonitor*/);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
monitor.consumeMotionDown(ADISPLAY_ID_DEFAULT);
@@ -2240,9 +1573,9 @@ TEST_F(InputDispatcherTest, GestureMonitor_CanPilferAfterWindowIsRemovedMidStrea
mDispatcher->pilferPointers(monitor.getToken());
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
monitor.consumeMotionUp(ADISPLAY_ID_DEFAULT);
}
@@ -2251,40 +1584,18 @@ TEST_F(InputDispatcherTest, UnresponsiveGestureMonitor_GetsAnr) {
FakeMonitorReceiver(mDispatcher, "Gesture monitor", ADISPLAY_ID_DEFAULT,
true /*isGestureMonitor*/);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
std::optional<uint32_t> consumeSeq = monitor.receiveEvent();
ASSERT_TRUE(consumeSeq);
- mFakePolicy->assertNotifyMonitorUnresponsiveWasCalled(DISPATCHING_TIMEOUT);
+ mFakePolicy->assertNotifyAnrWasCalled(DISPATCHING_TIMEOUT, nullptr, monitor.getToken());
monitor.finishEvent(*consumeSeq);
ASSERT_TRUE(mDispatcher->waitForIdle());
- mFakePolicy->assertNotifyMonitorResponsiveWasCalled();
-}
-
-// Tests for gesture monitors
-TEST_F(InputDispatcherTest, GestureMonitor_NoWindowTransform) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- window->setWindowOffset(20, 40);
- window->setWindowTransform(0, 1, -1, 0);
-
- FakeMonitorReceiver monitor = FakeMonitorReceiver(mDispatcher, "GM_1", ADISPLAY_ID_DEFAULT,
- true /*isGestureMonitor*/);
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
- MotionEvent* event = monitor.consumeMotion();
- // Even though window has transform, gesture monitor must not.
- ASSERT_EQ(ui::Transform(), event->getTransform());
}
TEST_F(InputDispatcherTest, TestMoveEvent) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
@@ -2315,58 +1626,52 @@ TEST_F(InputDispatcherTest, TestMoveEvent) {
* and the action of enabling / disabling.
*/
TEST_F(InputDispatcherTest, TouchModeState_IsSentToApps) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT);
// Set focused application.
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
- window->setFocusable(true);
+ window->setFocus(true);
SCOPED_TRACE("Check default value of touch mode");
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
-
window->consumeFocusEvent(true /*hasFocus*/, true /*inTouchMode*/);
SCOPED_TRACE("Remove the window to trigger focus loss");
- window->setFocusable(false);
+ window->setFocus(false);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
window->consumeFocusEvent(false /*hasFocus*/, true /*inTouchMode*/);
SCOPED_TRACE("Disable touch mode");
mDispatcher->setInTouchMode(false);
- window->setFocusable(true);
+ window->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
window->consumeFocusEvent(true /*hasFocus*/, false /*inTouchMode*/);
SCOPED_TRACE("Remove the window to trigger focus loss");
- window->setFocusable(false);
+ window->setFocus(false);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
window->consumeFocusEvent(false /*hasFocus*/, false /*inTouchMode*/);
SCOPED_TRACE("Enable touch mode again");
mDispatcher->setInTouchMode(true);
- window->setFocusable(true);
+ window->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
window->consumeFocusEvent(true /*hasFocus*/, true /*inTouchMode*/);
window->assertNoEvents();
}
TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT);
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
- window->setFocusable(true);
+ window->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
-
window->consumeFocusEvent(true /*hasFocus*/, true /*inTouchMode*/);
NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN);
@@ -2396,7 +1701,7 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) {
}
TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT);
@@ -2432,279 +1737,6 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState);
}
-TEST_F(InputDispatcherTest, NonPointerMotionEvent_NotTransformed) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT);
- const std::string name = window->getName();
-
- // Window gets transformed by offset values.
- window->setWindowOffset(500.0f, 500.0f);
-
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
- window->setFocusable(true);
-
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
-
- // First, we set focused window so that focusedWindowHandle is not null.
- setFocusedWindow(window);
-
- // Second, we consume focus event if it is right or wrong according to onFocusChangedLocked.
- window->consumeFocusEvent(true);
-
- constexpr const std::array nonPointerSources = {AINPUT_SOURCE_TRACKBALL,
- AINPUT_SOURCE_MOUSE_RELATIVE,
- AINPUT_SOURCE_JOYSTICK};
- for (const int source : nonPointerSources) {
- // Notify motion with a non-pointer source.
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, source, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
-
- MotionEvent* event = window->consumeMotion();
- ASSERT_NE(event, nullptr);
-
- const MotionEvent& motionEvent = *event;
- EXPECT_EQ(AMOTION_EVENT_ACTION_MOVE, motionEvent.getAction());
- EXPECT_EQ(motionArgs.pointerCount, motionEvent.getPointerCount());
-
- float expectedX = motionArgs.pointerCoords[0].getX();
- float expectedY = motionArgs.pointerCoords[0].getY();
-
- // Ensure the axis values from the final motion event are not transformed.
- EXPECT_EQ(expectedX, motionEvent.getX(0))
- << "expected " << expectedX << " for x coord of " << name.c_str() << ", got "
- << motionEvent.getX(0);
- EXPECT_EQ(expectedY, motionEvent.getY(0))
- << "expected " << expectedY << " for y coord of " << name.c_str() << ", got "
- << motionEvent.getY(0);
- // Ensure the raw and transformed axis values for the motion event are the same.
- EXPECT_EQ(motionEvent.getRawX(0), motionEvent.getX(0))
- << "expected raw and transformed X-axis values to be equal";
- EXPECT_EQ(motionEvent.getRawY(0), motionEvent.getY(0))
- << "expected raw and transformed Y-axis values to be equal";
- }
-}
-
-/**
- * Ensure that separate calls to sign the same data are generating the same key.
- * We avoid asserting against INVALID_HMAC. Since the key is random, there is a non-zero chance
- * that a specific key and data combination would produce INVALID_HMAC, which would cause flaky
- * tests.
- */
-TEST_F(InputDispatcherTest, GeneratedHmac_IsConsistent) {
- KeyEvent event = getTestKeyEvent();
- VerifiedKeyEvent verifiedEvent = verifiedKeyEventFromKeyEvent(event);
-
- std::array<uint8_t, 32> hmac1 = mDispatcher->sign(verifiedEvent);
- std::array<uint8_t, 32> hmac2 = mDispatcher->sign(verifiedEvent);
- ASSERT_EQ(hmac1, hmac2);
-}
-
-/**
- * Ensure that changes in VerifiedKeyEvent produce a different hmac.
- */
-TEST_F(InputDispatcherTest, GeneratedHmac_ChangesWhenFieldsChange) {
- KeyEvent event = getTestKeyEvent();
- VerifiedKeyEvent verifiedEvent = verifiedKeyEventFromKeyEvent(event);
- std::array<uint8_t, 32> initialHmac = mDispatcher->sign(verifiedEvent);
-
- verifiedEvent.deviceId += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.source += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.eventTimeNanos += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.displayId += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.action += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.downTimeNanos += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.flags += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.keyCode += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.scanCode += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.metaState += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-
- verifiedEvent.repeatCount += 1;
- ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent));
-}
-
-TEST_F(InputDispatcherTest, SetFocusedWindow) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> windowTop =
- new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT);
- sp<FakeWindowHandle> windowSecond =
- new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT);
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
-
- // Top window is also focusable but is not granted focus.
- windowTop->setFocusable(true);
- windowSecond->setFocusable(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}});
- setFocusedWindow(windowSecond);
-
- windowSecond->consumeFocusEvent(true);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
-
- // Focused window should receive event.
- windowSecond->consumeKeyDown(ADISPLAY_ID_NONE);
- windowTop->assertNoEvents();
-}
-
-TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestInvalidChannel) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT);
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
-
- window->setFocusable(true);
- // Release channel for window is no longer valid.
- window->releaseChannel();
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
-
- // Test inject a key down, should timeout.
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::TIMED_OUT";
-
- // window channel is invalid, so it should not receive any input event.
- window->assertNoEvents();
-}
-
-TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestNoFocusableWindow) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT);
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
-
- // Window is not focusable.
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
-
- // Test inject a key down, should timeout.
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::TIMED_OUT";
-
- // window is invalid, so it should not receive any input event.
- window->assertNoEvents();
-}
-
-TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> windowTop =
- new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT);
- sp<FakeWindowHandle> windowSecond =
- new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT);
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
-
- windowTop->setFocusable(true);
- windowSecond->setFocusable(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}});
- setFocusedWindow(windowTop);
- windowTop->consumeFocusEvent(true);
-
- setFocusedWindow(windowSecond, windowTop);
- windowSecond->consumeFocusEvent(true);
- windowTop->consumeFocusEvent(false);
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
-
- // Focused window should receive event.
- windowSecond->consumeKeyDown(ADISPLAY_ID_NONE);
-}
-
-TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestFocusTokenNotFocused) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> windowTop =
- new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT);
- sp<FakeWindowHandle> windowSecond =
- new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT);
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
-
- windowTop->setFocusable(true);
- windowSecond->setFocusable(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}});
- setFocusedWindow(windowSecond, windowTop);
-
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::TIMED_OUT";
-
- // Event should be dropped.
- windowTop->assertNoEvents();
- windowSecond->assertNoEvents();
-}
-
-TEST_F(InputDispatcherTest, SetFocusedWindow_DeferInvisibleWindow) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT);
- sp<FakeWindowHandle> previousFocusedWindow =
- new FakeWindowHandle(application, mDispatcher, "previousFocusedWindow",
- ADISPLAY_ID_DEFAULT);
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
-
- window->setFocusable(true);
- previousFocusedWindow->setFocusable(true);
- window->setVisible(false);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window, previousFocusedWindow}}});
- setFocusedWindow(previousFocusedWindow);
- previousFocusedWindow->consumeFocusEvent(true);
-
- // Requesting focus on invisible window takes focus from currently focused window.
- setFocusedWindow(window);
- previousFocusedWindow->consumeFocusEvent(false);
-
- // Injected key goes to pending queue.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */,
- ADISPLAY_ID_DEFAULT, InputEventInjectionSync::NONE));
-
- // Window does not get focus event or key down.
- window->assertNoEvents();
-
- // Window becomes visible.
- window->setVisible(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
-
- // Window receives focus event.
- window->consumeFocusEvent(true);
- // Focused window receives key down.
- window->consumeKeyDown(ADISPLAY_ID_DEFAULT);
-}
-
-TEST_F(InputDispatcherTest, DisplayRemoved) {
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(application, mDispatcher, "window", ADISPLAY_ID_DEFAULT);
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
-
- // window is granted focus.
- window->setFocusable(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- setFocusedWindow(window);
- window->consumeFocusEvent(true);
-
- // When a display is removed window loses focus.
- mDispatcher->displayRemoved(ADISPLAY_ID_DEFAULT);
- window->consumeFocusEvent(false);
-}
-
/**
* Launch two windows, with different owners. One window (slipperyExitWindow) has Flag::SLIPPERY,
* and overlaps the other window, slipperyEnterWindow. The window 'slipperyExitWindow' is on top
@@ -2732,13 +1764,13 @@ TEST_F(InputDispatcherTest, SlipperyWindow_SetsFlagPartiallyObscured) {
constexpr int32_t SLIPPERY_PID = INJECTOR_PID + 1;
constexpr int32_t SLIPPERY_UID = INJECTOR_UID + 1;
- std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
sp<FakeWindowHandle> slipperyExitWindow =
new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT);
- slipperyExitWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SLIPPERY);
+ slipperyExitWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL |
+ InputWindowInfo::FLAG_SLIPPERY);
// Make sure this one overlaps the bottom window
slipperyExitWindow->setFrame(Rect(25, 25, 75, 75));
// Change the owner uid/pid of the window so that it is considered to be occluding the bottom
@@ -2776,7 +1808,7 @@ protected:
static constexpr nsecs_t KEY_REPEAT_TIMEOUT = 40 * 1000000; // 40 ms
static constexpr nsecs_t KEY_REPEAT_DELAY = 40 * 1000000; // 40 ms
- std::shared_ptr<FakeApplicationHandle> mApp;
+ sp<FakeApplicationHandle> mApp;
sp<FakeWindowHandle> mWindow;
virtual void SetUp() override {
@@ -2790,18 +1822,17 @@ protected:
}
void setUpWindow() {
- mApp = std::make_shared<FakeApplicationHandle>();
+ mApp = new FakeApplicationHandle();
mWindow = new FakeWindowHandle(mApp, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
- mWindow->setFocusable(true);
+ mWindow->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}});
- setFocusedWindow(mWindow);
+
mWindow->consumeFocusEvent(true);
}
- void sendAndConsumeKeyDown(int32_t deviceId) {
+ void sendAndConsumeKeyDown() {
NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- keyArgs.deviceId = deviceId;
keyArgs.policyFlags |= POLICY_FLAG_TRUSTED; // Otherwise it won't generate repeat event
mDispatcher->notifyKey(&keyArgs);
@@ -2823,9 +1854,8 @@ protected:
EXPECT_EQ(repeatCount, repeatKeyEvent->getRepeatCount());
}
- void sendAndConsumeKeyUp(int32_t deviceId) {
+ void sendAndConsumeKeyUp() {
NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
- keyArgs.deviceId = deviceId;
keyArgs.policyFlags |= POLICY_FLAG_TRUSTED; // Unless it won't generate repeat event
mDispatcher->notifyKey(&keyArgs);
@@ -2836,59 +1866,21 @@ protected:
};
TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_ReceivesKeyRepeat) {
- sendAndConsumeKeyDown(1 /* deviceId */);
- for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) {
- expectKeyRepeatOnce(repeatCount);
- }
-}
-
-TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_ReceivesKeyRepeatFromTwoDevices) {
- sendAndConsumeKeyDown(1 /* deviceId */);
- for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) {
- expectKeyRepeatOnce(repeatCount);
- }
- sendAndConsumeKeyDown(2 /* deviceId */);
- /* repeatCount will start from 1 for deviceId 2 */
+ sendAndConsumeKeyDown();
for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) {
expectKeyRepeatOnce(repeatCount);
}
}
TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_StopsKeyRepeatAfterUp) {
- sendAndConsumeKeyDown(1 /* deviceId */);
- expectKeyRepeatOnce(1 /*repeatCount*/);
- sendAndConsumeKeyUp(1 /* deviceId */);
- mWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_KeyRepeatAfterStaleDeviceKeyUp) {
- sendAndConsumeKeyDown(1 /* deviceId */);
- expectKeyRepeatOnce(1 /*repeatCount*/);
- sendAndConsumeKeyDown(2 /* deviceId */);
- expectKeyRepeatOnce(1 /*repeatCount*/);
- // Stale key up from device 1.
- sendAndConsumeKeyUp(1 /* deviceId */);
- // Device 2 is still down, keep repeating
- expectKeyRepeatOnce(2 /*repeatCount*/);
- expectKeyRepeatOnce(3 /*repeatCount*/);
- // Device 2 key up
- sendAndConsumeKeyUp(2 /* deviceId */);
- mWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_KeyRepeatStopsAfterRepeatingKeyUp) {
- sendAndConsumeKeyDown(1 /* deviceId */);
- expectKeyRepeatOnce(1 /*repeatCount*/);
- sendAndConsumeKeyDown(2 /* deviceId */);
+ sendAndConsumeKeyDown();
expectKeyRepeatOnce(1 /*repeatCount*/);
- // Device 2 which holds the key repeating goes up, expect the repeating to stop.
- sendAndConsumeKeyUp(2 /* deviceId */);
- // Device 1 still holds key down, but the repeating was already stopped
+ sendAndConsumeKeyUp();
mWindow->assertNoEvents();
}
TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_RepeatKeyEventsUseEventIdFromInputDispatcher) {
- sendAndConsumeKeyDown(1 /* deviceId */);
+ sendAndConsumeKeyDown();
for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) {
InputEvent* repeatEvent = mWindow->consume();
ASSERT_NE(nullptr, repeatEvent) << "Didn't receive event with repeat count " << repeatCount;
@@ -2898,7 +1890,7 @@ TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_RepeatKeyEventsUseEventIdFrom
}
TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_RepeatKeyEventsUseUniqueEventId) {
- sendAndConsumeKeyDown(1 /* deviceId */);
+ sendAndConsumeKeyDown();
std::unordered_set<int32_t> idSet;
for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) {
@@ -2917,87 +1909,84 @@ public:
virtual void SetUp() override {
InputDispatcherTest::SetUp();
- application1 = std::make_shared<FakeApplicationHandle>();
- windowInPrimary =
- new FakeWindowHandle(application1, mDispatcher, "D_1", ADISPLAY_ID_DEFAULT);
+ application1 = new FakeApplicationHandle();
+ windowInPrimary = new FakeWindowHandle(application1, mDispatcher, "D_1",
+ ADISPLAY_ID_DEFAULT);
// Set focus window for primary display, but focused display would be second one.
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application1);
- windowInPrimary->setFocusable(true);
+ windowInPrimary->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowInPrimary}}});
- setFocusedWindow(windowInPrimary);
windowInPrimary->consumeFocusEvent(true);
- application2 = std::make_shared<FakeApplicationHandle>();
- windowInSecondary =
- new FakeWindowHandle(application2, mDispatcher, "D_2", SECOND_DISPLAY_ID);
+ application2 = new FakeApplicationHandle();
+ windowInSecondary = new FakeWindowHandle(application2, mDispatcher, "D_2",
+ SECOND_DISPLAY_ID);
// Set focus to second display window.
// Set focus display to second one.
mDispatcher->setFocusedDisplay(SECOND_DISPLAY_ID);
// Set focus window for second display.
mDispatcher->setFocusedApplication(SECOND_DISPLAY_ID, application2);
- windowInSecondary->setFocusable(true);
+ windowInSecondary->setFocus(true);
mDispatcher->setInputWindows({{SECOND_DISPLAY_ID, {windowInSecondary}}});
- setFocusedWindow(windowInSecondary);
windowInSecondary->consumeFocusEvent(true);
}
virtual void TearDown() override {
InputDispatcherTest::TearDown();
- application1.reset();
+ application1.clear();
windowInPrimary.clear();
- application2.reset();
+ application2.clear();
windowInSecondary.clear();
}
protected:
- std::shared_ptr<FakeApplicationHandle> application1;
+ sp<FakeApplicationHandle> application1;
sp<FakeWindowHandle> windowInPrimary;
- std::shared_ptr<FakeApplicationHandle> application2;
+ sp<FakeApplicationHandle> application2;
sp<FakeWindowHandle> windowInSecondary;
};
TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayTouch) {
// Test touch down on primary display.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
windowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT);
windowInSecondary->assertNoEvents();
// Test touch down on second display.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
+ AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID))
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
windowInPrimary->assertNoEvents();
windowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID);
}
TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus) {
// Test inject a key down with display id specified.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectKeyDownNoRepeat(mDispatcher, ADISPLAY_ID_DEFAULT))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
windowInPrimary->consumeKeyDown(ADISPLAY_ID_DEFAULT);
windowInSecondary->assertNoEvents();
// Test inject a key down without display id specified.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDownNoRepeat(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
windowInPrimary->assertNoEvents();
windowInSecondary->consumeKeyDown(ADISPLAY_ID_NONE);
// Remove all windows in secondary display.
mDispatcher->setInputWindows({{SECOND_DISPLAY_ID, {}}});
- // Old focus should receive a cancel event.
+ // Expect old focus should receive a cancel event.
windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE,
AKEY_EVENT_FLAG_CANCELED);
// Test inject a key down, should timeout because of no target window.
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDownNoRepeat(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::TIMED_OUT";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_TIMED_OUT, injectKeyDown(mDispatcher))
+ << "Inject key event should return INPUT_EVENT_INJECTION_TIMED_OUT";
windowInPrimary->assertNoEvents();
windowInSecondary->consumeFocusEvent(false);
windowInSecondary->assertNoEvents();
@@ -3011,18 +2000,18 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) {
FakeMonitorReceiver(mDispatcher, "M_2", SECOND_DISPLAY_ID);
// Test touch down on primary display.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
windowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT);
monitorInPrimary.consumeMotionDown(ADISPLAY_ID_DEFAULT);
windowInSecondary->assertNoEvents();
monitorInSecondary.assertNoEvents();
// Test touch down on second display.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
+ AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID))
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
windowInPrimary->assertNoEvents();
monitorInPrimary.assertNoEvents();
windowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID);
@@ -3031,9 +2020,9 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) {
// Test inject a non-pointer motion event.
// If specific a display, it will dispatch to the focused window of particular display,
// or it will dispatch to the focused window of focused display.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TRACKBALL, ADISPLAY_ID_NONE))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
+ AINPUT_SOURCE_TRACKBALL, ADISPLAY_ID_NONE))
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
windowInPrimary->assertNoEvents();
monitorInPrimary.assertNoEvents();
windowInSecondary->consumeMotionDown(ADISPLAY_ID_NONE);
@@ -3049,31 +2038,14 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorKeyEvent_MultiDisplay) {
FakeMonitorReceiver(mDispatcher, "M_2", SECOND_DISPLAY_ID);
// Test inject a key down.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
windowInPrimary->assertNoEvents();
monitorInPrimary.assertNoEvents();
windowInSecondary->consumeKeyDown(ADISPLAY_ID_NONE);
monitorInSecondary.consumeKeyDown(ADISPLAY_ID_NONE);
}
-TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CanFocusWindowOnUnfocusedDisplay) {
- sp<FakeWindowHandle> secondWindowInPrimary =
- new FakeWindowHandle(application1, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT);
- secondWindowInPrimary->setFocusable(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowInPrimary, secondWindowInPrimary}}});
- setFocusedWindow(secondWindowInPrimary);
- windowInPrimary->consumeFocusEvent(false);
- secondWindowInPrimary->consumeFocusEvent(true);
-
- // Test inject a key down.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- windowInPrimary->assertNoEvents();
- windowInSecondary->assertNoEvents();
- secondWindowInPrimary->consumeKeyDown(ADISPLAY_ID_DEFAULT);
-}
-
class InputFilterTest : public InputDispatcherTest {
protected:
static constexpr int32_t SECOND_DISPLAY_ID = 1;
@@ -3147,144 +2119,29 @@ TEST_F(InputFilterTest, KeyEvent_InputFilter) {
testNotifyKey(/*expectToBeFiltered*/ false);
}
-class InputFilterInjectionPolicyTest : public InputDispatcherTest {
-protected:
- virtual void SetUp() override {
- InputDispatcherTest::SetUp();
-
- /**
- * We don't need to enable input filter to test the injected event policy, but we enabled it
- * here to make the tests more realistic, since this policy only matters when inputfilter is
- * on.
- */
- mDispatcher->setInputFilterEnabled(true);
-
- std::shared_ptr<InputApplicationHandle> application =
- std::make_shared<FakeApplicationHandle>();
- mWindow =
- new FakeWindowHandle(application, mDispatcher, "Test Window", ADISPLAY_ID_DEFAULT);
-
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
- mWindow->setFocusable(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}});
- setFocusedWindow(mWindow);
- mWindow->consumeFocusEvent(true);
- }
-
- void testInjectedKey(int32_t policyFlags, int32_t injectedDeviceId, int32_t resolvedDeviceId,
- int32_t flags) {
- KeyEvent event;
-
- const nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC);
- event.initialize(InputEvent::nextId(), injectedDeviceId, AINPUT_SOURCE_KEYBOARD,
- ADISPLAY_ID_NONE, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, 0, AKEYCODE_A,
- KEY_A, AMETA_NONE, 0 /*repeatCount*/, eventTime, eventTime);
- const int32_t additionalPolicyFlags =
- POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_DISABLE_KEY_REPEAT;
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::WAIT_FOR_RESULT, 10ms,
- policyFlags | additionalPolicyFlags));
-
- InputEvent* received = mWindow->consume();
- ASSERT_NE(nullptr, received);
- ASSERT_EQ(resolvedDeviceId, received->getDeviceId());
- ASSERT_EQ(received->getType(), AINPUT_EVENT_TYPE_KEY);
- KeyEvent& keyEvent = static_cast<KeyEvent&>(*received);
- ASSERT_EQ(flags, keyEvent.getFlags());
- }
-
- void testInjectedMotion(int32_t policyFlags, int32_t injectedDeviceId, int32_t resolvedDeviceId,
- int32_t flags) {
- MotionEvent event;
- PointerProperties pointerProperties[1];
- PointerCoords pointerCoords[1];
- pointerProperties[0].clear();
- pointerProperties[0].id = 0;
- pointerCoords[0].clear();
- pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 300);
- pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 400);
-
- ui::Transform identityTransform;
- const nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC);
- event.initialize(InputEvent::nextId(), injectedDeviceId, AINPUT_SOURCE_TOUCHSCREEN,
- DISPLAY_ID, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, 0, 0,
- AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, 0, MotionClassification::NONE,
- identityTransform, 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
- AMOTION_EVENT_INVALID_CURSOR_POSITION,
- 0 /*AMOTION_EVENT_INVALID_DISPLAY_SIZE*/,
- 0 /*AMOTION_EVENT_INVALID_DISPLAY_SIZE*/, eventTime, eventTime,
- /*pointerCount*/ 1, pointerProperties, pointerCoords);
-
- const int32_t additionalPolicyFlags = POLICY_FLAG_PASS_TO_USER;
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- mDispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
- InputEventInjectionSync::WAIT_FOR_RESULT, 10ms,
- policyFlags | additionalPolicyFlags));
-
- InputEvent* received = mWindow->consume();
- ASSERT_NE(nullptr, received);
- ASSERT_EQ(resolvedDeviceId, received->getDeviceId());
- ASSERT_EQ(received->getType(), AINPUT_EVENT_TYPE_MOTION);
- MotionEvent& motionEvent = static_cast<MotionEvent&>(*received);
- ASSERT_EQ(flags, motionEvent.getFlags());
- }
-
-private:
- sp<FakeWindowHandle> mWindow;
-};
-
-TEST_F(InputFilterInjectionPolicyTest, TrustedFilteredEvents_KeepOriginalDeviceId) {
- // Must have POLICY_FLAG_FILTERED here to indicate that the event has gone through the input
- // filter. Without it, the event will no different from a regularly injected event, and the
- // injected device id will be overwritten.
- testInjectedKey(POLICY_FLAG_FILTERED, 3 /*injectedDeviceId*/, 3 /*resolvedDeviceId*/,
- 0 /*flags*/);
-}
-
-TEST_F(InputFilterInjectionPolicyTest, KeyEventsInjectedFromAccessibility_HaveAccessibilityFlag) {
- testInjectedKey(POLICY_FLAG_FILTERED | POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY,
- 3 /*injectedDeviceId*/, 3 /*resolvedDeviceId*/,
- AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT);
-}
-
-TEST_F(InputFilterInjectionPolicyTest,
- MotionEventsInjectedFromAccessibility_HaveAccessibilityFlag) {
- testInjectedMotion(POLICY_FLAG_FILTERED | POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY,
- 3 /*injectedDeviceId*/, 3 /*resolvedDeviceId*/,
- AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT);
-}
-
-TEST_F(InputFilterInjectionPolicyTest, RegularInjectedEvents_ReceiveVirtualDeviceId) {
- testInjectedKey(0 /*policyFlags*/, 3 /*injectedDeviceId*/,
- VIRTUAL_KEYBOARD_ID /*resolvedDeviceId*/, 0 /*flags*/);
-}
-
class InputDispatcherOnPointerDownOutsideFocus : public InputDispatcherTest {
virtual void SetUp() override {
InputDispatcherTest::SetUp();
- std::shared_ptr<FakeApplicationHandle> application =
- std::make_shared<FakeApplicationHandle>();
- mUnfocusedWindow =
- new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT);
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
+ mUnfocusedWindow = new FakeWindowHandle(application, mDispatcher, "Top",
+ ADISPLAY_ID_DEFAULT);
mUnfocusedWindow->setFrame(Rect(0, 0, 30, 30));
// Adding FLAG_NOT_TOUCH_MODAL to ensure taps outside this window are not sent to this
// window.
- mUnfocusedWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+ mUnfocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
mFocusedWindow =
new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT);
mFocusedWindow->setFrame(Rect(50, 50, 100, 100));
- mFocusedWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+ mFocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
// Set focused application.
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
- mFocusedWindow->setFocusable(true);
+ mFocusedWindow->setFocus(true);
// Expect one focus window exist in display.
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mUnfocusedWindow, mFocusedWindow}}});
- setFocusedWindow(mFocusedWindow);
mFocusedWindow->consumeFocusEvent(true);
}
@@ -3305,10 +2162,10 @@ protected:
// DOWN on the window that doesn't have focus. Ensure the window that didn't have focus received
// the onPointerDownOutsideFocus callback.
TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_Success) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
{20, 20}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
mUnfocusedWindow->consumeMotionDown();
ASSERT_TRUE(mDispatcher->waitForIdle());
@@ -3319,9 +2176,9 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_Succe
// DOWN on the window that doesn't have focus. Ensure no window received the
// onPointerDownOutsideFocus callback.
TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonPointerSource) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TRACKBALL, ADISPLAY_ID_DEFAULT, {20, 20}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
mFocusedWindow->consumeMotionDown();
ASSERT_TRUE(mDispatcher->waitForIdle());
@@ -3331,9 +2188,8 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonPo
// Have two windows, one with focus. Inject KeyEvent with action DOWN on the window that doesn't
// have focus. Ensure no window received the onPointerDownOutsideFocus callback.
TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonMotionFailure) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectKeyDownNoRepeat(mDispatcher, ADISPLAY_ID_DEFAULT))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT))
+ << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
mFocusedWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT);
ASSERT_TRUE(mDispatcher->waitForIdle());
@@ -3343,56 +2199,37 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonMo
// Have two windows, one with focus. Inject MotionEvent with source TOUCHSCREEN and action
// DOWN on the window that already has focus. Ensure no window received the
// onPointerDownOutsideFocus callback.
-TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_OnAlreadyFocusedWindow) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+TEST_F(InputDispatcherOnPointerDownOutsideFocus,
+ OnPointerDownOutsideFocus_OnAlreadyFocusedWindow) {
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
FOCUSED_WINDOW_TOUCH_POINT))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
mFocusedWindow->consumeMotionDown();
ASSERT_TRUE(mDispatcher->waitForIdle());
mFakePolicy->assertOnPointerDownWasNotCalled();
}
-// Have two windows, one with focus. Injecting a trusted DOWN MotionEvent with the flag
-// NO_FOCUS_CHANGE on the unfocused window should not call the onPointerDownOutsideFocus callback.
-TEST_F(InputDispatcherOnPointerDownOutsideFocus, NoFocusChangeFlag) {
- const MotionEvent event =
- MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE)
- .eventTime(systemTime(SYSTEM_TIME_MONOTONIC))
- .pointer(PointerBuilder(/* id */ 0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(20).y(20))
- .addFlag(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)
- .build();
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, event))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mUnfocusedWindow->consumeAnyMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);
-
- ASSERT_TRUE(mDispatcher->waitForIdle());
- mFakePolicy->assertOnPointerDownWasNotCalled();
- // Ensure that the unfocused window did not receive any FOCUS events.
- mUnfocusedWindow->assertNoEvents();
-}
-
// These tests ensures we can send touch events to a single client when there are multiple input
// windows that point to the same client token.
class InputDispatcherMultiWindowSameTokenTests : public InputDispatcherTest {
virtual void SetUp() override {
InputDispatcherTest::SetUp();
- std::shared_ptr<FakeApplicationHandle> application =
- std::make_shared<FakeApplicationHandle>();
+ sp<FakeApplicationHandle> application = new FakeApplicationHandle();
mWindow1 = new FakeWindowHandle(application, mDispatcher, "Fake Window 1",
ADISPLAY_ID_DEFAULT);
// Adding FLAG_NOT_TOUCH_MODAL otherwise all taps will go to the top most window.
// We also need FLAG_SPLIT_TOUCH or we won't be able to get touches for both windows.
- mWindow1->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
+ mWindow1->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL |
+ InputWindowInfo::FLAG_SPLIT_TOUCH);
mWindow1->setFrame(Rect(0, 0, 100, 100));
mWindow2 = new FakeWindowHandle(application, mDispatcher, "Fake Window 2",
ADISPLAY_ID_DEFAULT, mWindow1->getToken());
- mWindow2->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
+ mWindow2->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL |
+ InputWindowInfo::FLAG_SPLIT_TOUCH);
mWindow2->setFrame(Rect(100, 100, 200, 200));
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow1, mWindow2}}});
@@ -3404,8 +2241,9 @@ protected:
// Helper function to convert the point from screen coordinates into the window's space
static PointF getPointInWindow(const InputWindowInfo* windowInfo, const PointF& point) {
- vec2 vals = windowInfo->transform.transform(point.x, point.y);
- return {vals.x, vals.y};
+ float x = windowInfo->windowXScale * (point.x - windowInfo->frameLeft);
+ float y = windowInfo->windowYScale * (point.y - windowInfo->frameTop);
+ return {x, y};
}
void consumeMotionEvent(const sp<FakeWindowHandle>& window, int32_t expectedAction,
@@ -3435,123 +2273,133 @@ protected:
<< ", got " << motionEvent.getY(i);
}
}
-
- void touchAndAssertPositions(int32_t action, std::vector<PointF> touchedPoints,
- std::vector<PointF> expectedPoints) {
- NotifyMotionArgs motionArgs = generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, touchedPoints);
- mDispatcher->notifyMotion(&motionArgs);
-
- // Always consume from window1 since it's the window that has the InputReceiver
- consumeMotionEvent(mWindow1, action, expectedPoints);
- }
};
TEST_F(InputDispatcherMultiWindowSameTokenTests, SingleTouchSameScale) {
// Touch Window 1
PointF touchedPoint = {10, 10};
PointF expectedPoint = getPointInWindow(mWindow1->getInfo(), touchedPoint);
- touchAndAssertPositions(AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint});
+
+ NotifyMotionArgs motionArgs =
+ generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {touchedPoint});
+ mDispatcher->notifyMotion(&motionArgs);
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_DOWN, {expectedPoint});
// Release touch on Window 1
- touchAndAssertPositions(AMOTION_EVENT_ACTION_UP, {touchedPoint}, {expectedPoint});
+ motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {touchedPoint});
+ mDispatcher->notifyMotion(&motionArgs);
+ // consume the UP event
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_UP, {expectedPoint});
// Touch Window 2
touchedPoint = {150, 150};
expectedPoint = getPointInWindow(mWindow2->getInfo(), touchedPoint);
- touchAndAssertPositions(AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint});
+
+ motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {touchedPoint});
+ mDispatcher->notifyMotion(&motionArgs);
+
+ // Consuming from window1 since it's the window that has the InputReceiver
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_DOWN, {expectedPoint});
}
-TEST_F(InputDispatcherMultiWindowSameTokenTests, SingleTouchDifferentTransform) {
- // Set scale value for window2
+TEST_F(InputDispatcherMultiWindowSameTokenTests, SingleTouchDifferentScale) {
mWindow2->setWindowScale(0.5f, 0.5f);
// Touch Window 1
PointF touchedPoint = {10, 10};
PointF expectedPoint = getPointInWindow(mWindow1->getInfo(), touchedPoint);
- touchAndAssertPositions(AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint});
+
+ NotifyMotionArgs motionArgs =
+ generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {touchedPoint});
+ mDispatcher->notifyMotion(&motionArgs);
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_DOWN, {expectedPoint});
+
// Release touch on Window 1
- touchAndAssertPositions(AMOTION_EVENT_ACTION_UP, {touchedPoint}, {expectedPoint});
+ motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {touchedPoint});
+ mDispatcher->notifyMotion(&motionArgs);
+ // consume the UP event
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_UP, {expectedPoint});
// Touch Window 2
touchedPoint = {150, 150};
expectedPoint = getPointInWindow(mWindow2->getInfo(), touchedPoint);
- touchAndAssertPositions(AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint});
- touchAndAssertPositions(AMOTION_EVENT_ACTION_UP, {touchedPoint}, {expectedPoint});
- // Update the transform so rotation is set
- mWindow2->setWindowTransform(0, -1, 1, 0);
- expectedPoint = getPointInWindow(mWindow2->getInfo(), touchedPoint);
- touchAndAssertPositions(AMOTION_EVENT_ACTION_DOWN, {touchedPoint}, {expectedPoint});
+ motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {touchedPoint});
+ mDispatcher->notifyMotion(&motionArgs);
+
+ // Consuming from window1 since it's the window that has the InputReceiver
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_DOWN, {expectedPoint});
}
-TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleTouchDifferentTransform) {
+TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleTouchDifferentScale) {
mWindow2->setWindowScale(0.5f, 0.5f);
// Touch Window 1
std::vector<PointF> touchedPoints = {PointF{10, 10}};
std::vector<PointF> expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0])};
- touchAndAssertPositions(AMOTION_EVENT_ACTION_DOWN, touchedPoints, expectedPoints);
+
+ NotifyMotionArgs motionArgs =
+ generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints);
+ mDispatcher->notifyMotion(&motionArgs);
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_DOWN, expectedPoints);
// Touch Window 2
int32_t actionPointerDown =
AMOTION_EVENT_ACTION_POINTER_DOWN + (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
- touchedPoints.push_back(PointF{150, 150});
- expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1]));
- touchAndAssertPositions(actionPointerDown, touchedPoints, expectedPoints);
-
- // Release Window 2
- int32_t actionPointerUp =
- AMOTION_EVENT_ACTION_POINTER_UP + (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
- touchAndAssertPositions(actionPointerUp, touchedPoints, expectedPoints);
- expectedPoints.pop_back();
-
- // Update the transform so rotation is set for Window 2
- mWindow2->setWindowTransform(0, -1, 1, 0);
- expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1]));
- touchAndAssertPositions(actionPointerDown, touchedPoints, expectedPoints);
+ touchedPoints.emplace_back(PointF{150, 150});
+ expectedPoints.emplace_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1]));
+
+ motionArgs = generateMotionArgs(actionPointerDown, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints);
+ mDispatcher->notifyMotion(&motionArgs);
+
+ // Consuming from window1 since it's the window that has the InputReceiver
+ consumeMotionEvent(mWindow1, actionPointerDown, expectedPoints);
}
-TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleTouchMoveDifferentTransform) {
+TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleTouchMoveDifferentScale) {
mWindow2->setWindowScale(0.5f, 0.5f);
// Touch Window 1
std::vector<PointF> touchedPoints = {PointF{10, 10}};
std::vector<PointF> expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0])};
- touchAndAssertPositions(AMOTION_EVENT_ACTION_DOWN, touchedPoints, expectedPoints);
+
+ NotifyMotionArgs motionArgs =
+ generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints);
+ mDispatcher->notifyMotion(&motionArgs);
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_DOWN, expectedPoints);
// Touch Window 2
int32_t actionPointerDown =
AMOTION_EVENT_ACTION_POINTER_DOWN + (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
- touchedPoints.push_back(PointF{150, 150});
- expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1]));
-
- touchAndAssertPositions(actionPointerDown, touchedPoints, expectedPoints);
-
- // Move both windows
- touchedPoints = {{20, 20}, {175, 175}};
- expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0]),
- getPointInWindow(mWindow2->getInfo(), touchedPoints[1])};
+ touchedPoints.emplace_back(PointF{150, 150});
+ expectedPoints.emplace_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1]));
- touchAndAssertPositions(AMOTION_EVENT_ACTION_MOVE, touchedPoints, expectedPoints);
-
- // Release Window 2
- int32_t actionPointerUp =
- AMOTION_EVENT_ACTION_POINTER_UP + (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
- touchAndAssertPositions(actionPointerUp, touchedPoints, expectedPoints);
- expectedPoints.pop_back();
+ motionArgs = generateMotionArgs(actionPointerDown, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints);
+ mDispatcher->notifyMotion(&motionArgs);
- // Touch Window 2
- mWindow2->setWindowTransform(0, -1, 1, 0);
- expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1]));
- touchAndAssertPositions(actionPointerDown, touchedPoints, expectedPoints);
+ // Consuming from window1 since it's the window that has the InputReceiver
+ consumeMotionEvent(mWindow1, actionPointerDown, expectedPoints);
// Move both windows
touchedPoints = {{20, 20}, {175, 175}};
expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0]),
getPointInWindow(mWindow2->getInfo(), touchedPoints[1])};
- touchAndAssertPositions(AMOTION_EVENT_ACTION_MOVE, touchedPoints, expectedPoints);
+ motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints);
+ mDispatcher->notifyMotion(&motionArgs);
+
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_MOVE, expectedPoints);
}
TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleWindowsFirstTouchWithScale) {
@@ -3560,44 +2408,57 @@ TEST_F(InputDispatcherMultiWindowSameTokenTests, MultipleWindowsFirstTouchWithSc
// Touch Window 1
std::vector<PointF> touchedPoints = {PointF{10, 10}};
std::vector<PointF> expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0])};
- touchAndAssertPositions(AMOTION_EVENT_ACTION_DOWN, touchedPoints, expectedPoints);
+
+ NotifyMotionArgs motionArgs =
+ generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints);
+ mDispatcher->notifyMotion(&motionArgs);
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_DOWN, expectedPoints);
// Touch Window 2
int32_t actionPointerDown =
AMOTION_EVENT_ACTION_POINTER_DOWN + (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
- touchedPoints.push_back(PointF{150, 150});
- expectedPoints.push_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1]));
+ touchedPoints.emplace_back(PointF{150, 150});
+ expectedPoints.emplace_back(getPointInWindow(mWindow2->getInfo(), touchedPoints[1]));
+
+ motionArgs = generateMotionArgs(actionPointerDown, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints);
+ mDispatcher->notifyMotion(&motionArgs);
- touchAndAssertPositions(actionPointerDown, touchedPoints, expectedPoints);
+ // Consuming from window1 since it's the window that has the InputReceiver
+ consumeMotionEvent(mWindow1, actionPointerDown, expectedPoints);
// Move both windows
touchedPoints = {{20, 20}, {175, 175}};
expectedPoints = {getPointInWindow(mWindow1->getInfo(), touchedPoints[0]),
getPointInWindow(mWindow2->getInfo(), touchedPoints[1])};
- touchAndAssertPositions(AMOTION_EVENT_ACTION_MOVE, touchedPoints, expectedPoints);
+ motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints);
+ mDispatcher->notifyMotion(&motionArgs);
+
+ consumeMotionEvent(mWindow1, AMOTION_EVENT_ACTION_MOVE, expectedPoints);
}
class InputDispatcherSingleWindowAnr : public InputDispatcherTest {
virtual void SetUp() override {
InputDispatcherTest::SetUp();
- mApplication = std::make_shared<FakeApplicationHandle>();
+ mApplication = new FakeApplicationHandle();
mApplication->setDispatchingTimeout(20ms);
mWindow =
new FakeWindowHandle(mApplication, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT);
mWindow->setFrame(Rect(0, 0, 30, 30));
- mWindow->setDispatchingTimeout(30ms);
- mWindow->setFocusable(true);
+ mWindow->setDispatchingTimeout(10ms);
+ mWindow->setFocus(true);
// Adding FLAG_NOT_TOUCH_MODAL to ensure taps outside this window are not sent to this
// window.
- mWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
+ mWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
// Set focused application.
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApplication);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}});
- setFocusedWindow(mWindow);
mWindow->consumeFocusEvent(true);
}
@@ -3607,15 +2468,15 @@ class InputDispatcherSingleWindowAnr : public InputDispatcherTest {
}
protected:
- std::shared_ptr<FakeApplicationHandle> mApplication;
+ sp<FakeApplicationHandle> mApplication;
sp<FakeWindowHandle> mWindow;
static constexpr PointF WINDOW_LOCATION = {20, 20};
void tapOnWindow() {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
WINDOW_LOCATION));
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
WINDOW_LOCATION));
}
@@ -3632,72 +2493,51 @@ TEST_F(InputDispatcherSingleWindowAnr, WhenTouchIsConsumed_NoAnr) {
// Send a regular key and respond, which should not cause an ANR.
TEST_F(InputDispatcherSingleWindowAnr, WhenKeyIsConsumed_NoAnr) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDownNoRepeat(mDispatcher));
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher));
mWindow->consumeKeyDown(ADISPLAY_ID_NONE);
ASSERT_TRUE(mDispatcher->waitForIdle());
mFakePolicy->assertNotifyAnrWasNotCalled();
}
-TEST_F(InputDispatcherSingleWindowAnr, WhenFocusedApplicationChanges_NoAnr) {
- mWindow->setFocusable(false);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}});
- mWindow->consumeFocusEvent(false);
-
- InputEventInjectionResult result =
- injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /*repeatCount*/, ADISPLAY_ID_DEFAULT,
- InputEventInjectionSync::NONE, 10ms /*injectionTimeout*/,
- false /* allowKeyRepeat */);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result);
- // Key will not go to window because we have no focused window.
- // The 'no focused window' ANR timer should start instead.
-
- // Now, the focused application goes away.
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, nullptr);
- // The key should get dropped and there should be no ANR.
-
- ASSERT_TRUE(mDispatcher->waitForIdle());
- mFakePolicy->assertNotifyAnrWasNotCalled();
-}
-
// Send an event to the app and have the app not respond right away.
// When ANR is raised, policy will tell the dispatcher to cancel the events for that window.
// So InputDispatcher will enqueue ACTION_CANCEL event as well.
TEST_F(InputDispatcherSingleWindowAnr, OnPointerDown_BasicAnr) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
WINDOW_LOCATION));
std::optional<uint32_t> sequenceNum = mWindow->receiveEvent(); // ACTION_DOWN
ASSERT_TRUE(sequenceNum);
const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/, mWindow->getToken());
+ // The remaining lines are not really needed for the test, but kept as a sanity check
mWindow->finishEvent(*sequenceNum);
mWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_CANCEL,
ADISPLAY_ID_DEFAULT, 0 /*flags*/);
ASSERT_TRUE(mDispatcher->waitForIdle());
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken());
}
// Send a key to the app and have the app not respond right away.
TEST_F(InputDispatcherSingleWindowAnr, OnKeyDown_BasicAnr) {
// Inject a key, and don't respond - expect that ANR is called.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDownNoRepeat(mDispatcher));
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher));
std::optional<uint32_t> sequenceNum = mWindow->receiveEvent();
ASSERT_TRUE(sequenceNum);
const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/, mWindow->getToken());
ASSERT_TRUE(mDispatcher->waitForIdle());
}
// We have a focused application, but no focused window
TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_NoFocusedWindow) {
- mWindow->setFocusable(false);
+ mWindow->setFocus(false);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}});
mWindow->consumeFocusEvent(false);
// taps on the window work as normal
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
WINDOW_LOCATION));
ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionDown());
@@ -3707,59 +2547,62 @@ TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_NoFocusedWindow) {
// Once a focused event arrives, we get an ANR for this application
// We specify the injection timeout to be smaller than the application timeout, to ensure that
// injection times out (instead of failing).
- const InputEventInjectionResult result =
+ const int32_t result =
injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */, ADISPLAY_ID_DEFAULT,
- InputEventInjectionSync::WAIT_FOR_RESULT, 10ms, false /* allowKeyRepeat */);
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result);
+ INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, 10ms);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_TIMED_OUT, result);
const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(timeout, mApplication);
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, mApplication, nullptr /*windowToken*/);
ASSERT_TRUE(mDispatcher->waitForIdle());
}
// We have a focused application, but no focused window
-// Make sure that we don't notify policy twice about the same ANR.
-TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DoesNotSendDuplicateAnr) {
- mWindow->setFocusable(false);
+// If the policy wants to keep waiting on the focused window to be added, make sure
+// that this timeout extension is honored and ANR is raised again.
+TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_ExtendsAnr) {
+ mWindow->setFocus(false);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}});
mWindow->consumeFocusEvent(false);
+ const std::chrono::duration timeout = 5ms;
+ mFakePolicy->setAnrTimeout(timeout);
// Once a focused event arrives, we get an ANR for this application
// We specify the injection timeout to be smaller than the application timeout, to ensure that
// injection times out (instead of failing).
- const InputEventInjectionResult result =
+ const int32_t result =
injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */, ADISPLAY_ID_DEFAULT,
- InputEventInjectionSync::WAIT_FOR_RESULT, 10ms, false /* allowKeyRepeat */);
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result);
+ INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, 10ms);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_TIMED_OUT, result);
const std::chrono::duration appTimeout =
mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(appTimeout, mApplication);
+ mFakePolicy->assertNotifyAnrWasCalled(appTimeout, mApplication, nullptr /*windowToken*/);
- std::this_thread::sleep_for(appTimeout);
- // ANR should not be raised again. It is up to policy to do that if it desires.
- mFakePolicy->assertNotifyAnrWasNotCalled();
+ // After the extended time has passed, ANR should be raised again
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, mApplication, nullptr /*windowToken*/);
- // If we now get a focused window, the ANR should stop, but the policy handles that via
- // 'notifyFocusChanged' callback. This is implemented in the policy so we can't test it here.
+ // If we stop extending the timeout, dispatcher should go to idle.
+ // Another ANR may be raised during this time
+ mFakePolicy->setAnrTimeout(0ms);
ASSERT_TRUE(mDispatcher->waitForIdle());
}
// We have a focused application, but no focused window
TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DropsFocusedEvents) {
- mWindow->setFocusable(false);
+ mWindow->setFocus(false);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}});
mWindow->consumeFocusEvent(false);
// Once a focused event arrives, we get an ANR for this application
- const InputEventInjectionResult result =
+ const int32_t result =
injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */, ADISPLAY_ID_DEFAULT,
- InputEventInjectionSync::WAIT_FOR_RESULT, 10ms);
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result);
+ INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, 10ms);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_TIMED_OUT, result);
const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(timeout, mApplication);
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, mApplication, nullptr /*windowToken*/);
// Future focused events get dropped right away
- ASSERT_EQ(InputEventInjectionResult::FAILED, injectKeyDown(mDispatcher));
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, injectKeyDown(mDispatcher));
ASSERT_TRUE(mDispatcher->waitForIdle());
mWindow->assertNoEvents();
}
@@ -3779,19 +2622,19 @@ TEST_F(InputDispatcherSingleWindowAnr, Anr_HandlesEventsWithIdenticalTimestamps)
ADISPLAY_ID_DEFAULT, WINDOW_LOCATION,
{AMOTION_EVENT_INVALID_CURSOR_POSITION,
AMOTION_EVENT_INVALID_CURSOR_POSITION},
- 500ms, InputEventInjectionSync::WAIT_FOR_RESULT, currentTime);
+ 500ms, INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, currentTime);
// Now send ACTION_UP, with identical timestamp
injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
ADISPLAY_ID_DEFAULT, WINDOW_LOCATION,
{AMOTION_EVENT_INVALID_CURSOR_POSITION,
AMOTION_EVENT_INVALID_CURSOR_POSITION},
- 500ms, InputEventInjectionSync::WAIT_FOR_RESULT, currentTime);
+ 500ms, INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, currentTime);
// We have now sent down and up. Let's consume first event and then ANR on the second.
mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT);
const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/, mWindow->getToken());
}
// If an app is not responding to a key event, gesture monitors should continue to receive
@@ -3801,14 +2644,13 @@ TEST_F(InputDispatcherSingleWindowAnr, GestureMonitors_ReceiveEventsDuringAppAnr
FakeMonitorReceiver(mDispatcher, "Gesture monitor", ADISPLAY_ID_DEFAULT,
true /*isGestureMonitor*/);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT));
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT));
mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(mDispatcher, ADISPLAY_ID_DEFAULT));
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyUp(mDispatcher, ADISPLAY_ID_DEFAULT));
// Stuck on the ACTION_UP
const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr, mWindow->getToken());
// New tap will go to the gesture monitor, but not to the window
tapOnWindow();
@@ -3817,7 +2659,6 @@ TEST_F(InputDispatcherSingleWindowAnr, GestureMonitors_ReceiveEventsDuringAppAnr
mWindow->consumeKeyUp(ADISPLAY_ID_DEFAULT); // still the previous motion
mDispatcher->waitForIdle();
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken());
mWindow->assertNoEvents();
monitor.assertNoEvents();
}
@@ -3836,7 +2677,7 @@ TEST_F(InputDispatcherSingleWindowAnr, GestureMonitors_ReceiveEventsDuringAppAnr
mWindow->consumeMotionDown();
// Stuck on the ACTION_UP
const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr, mWindow->getToken());
// New tap will go to the gesture monitor, but not to the window
tapOnWindow();
@@ -3845,7 +2686,6 @@ TEST_F(InputDispatcherSingleWindowAnr, GestureMonitors_ReceiveEventsDuringAppAnr
mWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT); // still the previous motion
mDispatcher->waitForIdle();
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken());
mWindow->assertNoEvents();
monitor.assertNoEvents();
}
@@ -3862,43 +2702,46 @@ TEST_F(InputDispatcherSingleWindowAnr, SameWindow_CanReceiveAnrTwice) {
mWindow->consumeMotionDown();
// Block on ACTION_UP
const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/, mWindow->getToken());
mWindow->consumeMotionUp(); // Now the connection should be healthy again
mDispatcher->waitForIdle();
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken());
mWindow->assertNoEvents();
tapOnWindow();
mWindow->consumeMotionDown();
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/, mWindow->getToken());
mWindow->consumeMotionUp();
mDispatcher->waitForIdle();
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken());
- mFakePolicy->assertNotifyAnrWasNotCalled();
mWindow->assertNoEvents();
}
-// If a connection remains unresponsive for a while, make sure policy is only notified once about
-// it.
-TEST_F(InputDispatcherSingleWindowAnr, Policy_DoesNotGetDuplicateAnr) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+// If the policy tells us to raise ANR again after some time, ensure that the timeout extension
+// is honored
+TEST_F(InputDispatcherSingleWindowAnr, Policy_CanExtendTimeout) {
+ const std::chrono::duration timeout = 5ms;
+ mFakePolicy->setAnrTimeout(timeout);
+
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
WINDOW_LOCATION));
const std::chrono::duration windowTimeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(windowTimeout, mWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(windowTimeout, nullptr /*application*/,
+ mWindow->getToken());
+
+ // Since the policy wanted to extend ANR, make sure it is called again after the extension
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/, mWindow->getToken());
+ mFakePolicy->setAnrTimeout(0ms);
std::this_thread::sleep_for(windowTimeout);
- // 'notifyConnectionUnresponsive' should only be called once per connection
- mFakePolicy->assertNotifyAnrWasNotCalled();
- // When the ANR happened, dispatcher should abort the current event stream via ACTION_CANCEL
+ // We are not checking if ANR has been called, because it may have been called again by the
+ // time we set the timeout to 0
+
+ // When the policy finally says stop, we should get ACTION_CANCEL
mWindow->consumeMotionDown();
mWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_CANCEL,
ADISPLAY_ID_DEFAULT, 0 /*flags*/);
mWindow->assertNoEvents();
- mDispatcher->waitForIdle();
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken());
- mFakePolicy->assertNotifyAnrWasNotCalled();
}
/**
@@ -3927,10 +2770,10 @@ TEST_F(InputDispatcherSingleWindowAnr, Key_StaysPendingWhileMotionIsProcessed) {
// window even if motions are still being processed. But because the injection timeout is short,
// we will receive INJECTION_TIMED_OUT as the result.
- InputEventInjectionResult result =
+ int32_t result =
injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */, ADISPLAY_ID_DEFAULT,
- InputEventInjectionSync::WAIT_FOR_RESULT, 10ms);
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result);
+ INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, 10ms);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_TIMED_OUT, result);
// Key will not be sent to the window, yet, because the window is still processing events
// and the key remains pending, waiting for the touch events to be processed
std::optional<uint32_t> keySequenceNum = mWindow->receiveEvent();
@@ -3962,9 +2805,9 @@ TEST_F(InputDispatcherSingleWindowAnr,
ASSERT_TRUE(upSequenceNum);
// Don't finish the events yet, and send a key
// Injection is async, so it will succeed
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */,
- ADISPLAY_ID_DEFAULT, InputEventInjectionSync::NONE));
+ ADISPLAY_ID_DEFAULT, INPUT_EVENT_INJECTION_SYNC_NONE));
// At this point, key is still pending, and should not be sent to the application yet.
std::optional<uint32_t> keySequenceNum = mWindow->receiveEvent();
ASSERT_FALSE(keySequenceNum);
@@ -3984,7 +2827,7 @@ class InputDispatcherMultiWindowAnr : public InputDispatcherTest {
virtual void SetUp() override {
InputDispatcherTest::SetUp();
- mApplication = std::make_shared<FakeApplicationHandle>();
+ mApplication = new FakeApplicationHandle();
mApplication->setDispatchingTimeout(10ms);
mUnfocusedWindow =
new FakeWindowHandle(mApplication, mDispatcher, "Unfocused", ADISPLAY_ID_DEFAULT);
@@ -3992,24 +2835,23 @@ class InputDispatcherMultiWindowAnr : public InputDispatcherTest {
// Adding FLAG_NOT_TOUCH_MODAL to ensure taps outside this window are not sent to this
// window.
// Adding FLAG_WATCH_OUTSIDE_TOUCH to receive ACTION_OUTSIDE when another window is tapped
- mUnfocusedWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH |
- InputWindowInfo::Flag::SPLIT_TOUCH);
+ mUnfocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL |
+ InputWindowInfo::FLAG_WATCH_OUTSIDE_TOUCH |
+ InputWindowInfo::FLAG_SPLIT_TOUCH);
mFocusedWindow =
new FakeWindowHandle(mApplication, mDispatcher, "Focused", ADISPLAY_ID_DEFAULT);
- mFocusedWindow->setDispatchingTimeout(30ms);
+ mFocusedWindow->setDispatchingTimeout(10ms);
mFocusedWindow->setFrame(Rect(50, 50, 100, 100));
- mFocusedWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL |
- InputWindowInfo::Flag::SPLIT_TOUCH);
+ mFocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL |
+ InputWindowInfo::FLAG_SPLIT_TOUCH);
// Set focused application.
mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApplication);
- mFocusedWindow->setFocusable(true);
+ mFocusedWindow->setFocus(true);
// Expect one focus window exist in display.
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mUnfocusedWindow, mFocusedWindow}}});
- setFocusedWindow(mFocusedWindow);
mFocusedWindow->consumeFocusEvent(true);
}
@@ -4021,7 +2863,7 @@ class InputDispatcherMultiWindowAnr : public InputDispatcherTest {
}
protected:
- std::shared_ptr<FakeApplicationHandle> mApplication;
+ sp<FakeApplicationHandle> mApplication;
sp<FakeWindowHandle> mUnfocusedWindow;
sp<FakeWindowHandle> mFocusedWindow;
static constexpr PointF UNFOCUSED_WINDOW_LOCATION = {20, 20};
@@ -4034,10 +2876,10 @@ protected:
private:
void tap(const PointF& location) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
location));
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
location));
}
@@ -4046,10 +2888,10 @@ private:
// If we have 2 windows that are both unresponsive, the one with the shortest timeout
// should be ANR'd first.
TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsive) {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
FOCUSED_WINDOW_LOCATION))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
mFocusedWindow->consumeMotionDown();
mUnfocusedWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE,
ADISPLAY_ID_DEFAULT, 0 /*flags*/);
@@ -4057,27 +2899,22 @@ TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsive) {
ASSERT_TRUE(mDispatcher->waitForIdle());
mFakePolicy->assertNotifyAnrWasNotCalled();
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
FOCUSED_WINDOW_LOCATION));
std::optional<uint32_t> unfocusedSequenceNum = mUnfocusedWindow->receiveEvent();
ASSERT_TRUE(unfocusedSequenceNum);
+ std::optional<uint32_t> focusedSequenceNum = mFocusedWindow->receiveEvent();
+ ASSERT_TRUE(focusedSequenceNum);
const std::chrono::duration timeout =
mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mFocusedWindow->getToken());
- // Because we injected two DOWN events in a row, CANCEL is enqueued for the first event
- // sequence to make it consistent
- mFocusedWindow->consumeMotionCancel();
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/,
+ mFocusedWindow->getToken());
+
+ mFocusedWindow->finishEvent(*focusedSequenceNum);
mUnfocusedWindow->finishEvent(*unfocusedSequenceNum);
- mFocusedWindow->consumeMotionDown();
- // This cancel is generated because the connection was unresponsive
- mFocusedWindow->consumeMotionCancel();
- mFocusedWindow->assertNoEvents();
- mUnfocusedWindow->assertNoEvents();
ASSERT_TRUE(mDispatcher->waitForIdle());
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mFocusedWindow->getToken());
- mFakePolicy->assertNotifyAnrWasNotCalled();
}
// If we have 2 windows with identical timeouts that are both unresponsive,
@@ -4090,31 +2927,19 @@ TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsiveWithSameTimeout
tapOnFocusedWindow();
// we should have ACTION_DOWN/ACTION_UP on focused window and ACTION_OUTSIDE on unfocused window
- sp<IBinder> anrConnectionToken1 = mFakePolicy->getUnresponsiveWindowToken(10ms);
- sp<IBinder> anrConnectionToken2 = mFakePolicy->getUnresponsiveWindowToken(0ms);
+ std::pair<sp<InputApplicationHandle>, sp<IBinder>> anrData1 =
+ mFakePolicy->getNotifyAnrData(10ms);
+ std::pair<sp<InputApplicationHandle>, sp<IBinder>> anrData2 =
+ mFakePolicy->getNotifyAnrData(0ms);
// We don't know which window will ANR first. But both of them should happen eventually.
- ASSERT_TRUE(mFocusedWindow->getToken() == anrConnectionToken1 ||
- mFocusedWindow->getToken() == anrConnectionToken2);
- ASSERT_TRUE(mUnfocusedWindow->getToken() == anrConnectionToken1 ||
- mUnfocusedWindow->getToken() == anrConnectionToken2);
+ ASSERT_TRUE(mFocusedWindow->getToken() == anrData1.second ||
+ mFocusedWindow->getToken() == anrData2.second);
+ ASSERT_TRUE(mUnfocusedWindow->getToken() == anrData1.second ||
+ mUnfocusedWindow->getToken() == anrData2.second);
ASSERT_TRUE(mDispatcher->waitForIdle());
mFakePolicy->assertNotifyAnrWasNotCalled();
-
- mFocusedWindow->consumeMotionDown();
- mFocusedWindow->consumeMotionUp();
- mUnfocusedWindow->consumeMotionOutside();
-
- sp<IBinder> responsiveToken1 = mFakePolicy->getResponsiveWindowToken();
- sp<IBinder> responsiveToken2 = mFakePolicy->getResponsiveWindowToken();
-
- // Both applications should be marked as responsive, in any order
- ASSERT_TRUE(mFocusedWindow->getToken() == responsiveToken1 ||
- mFocusedWindow->getToken() == responsiveToken2);
- ASSERT_TRUE(mUnfocusedWindow->getToken() == responsiveToken1 ||
- mUnfocusedWindow->getToken() == responsiveToken2);
- mFakePolicy->assertNotifyAnrWasNotCalled();
}
// If a window is already not responding, the second tap on the same window should be ignored.
@@ -4131,14 +2956,15 @@ TEST_F(InputDispatcherMultiWindowAnr, DuringAnr_SecondTapIsIgnored) {
ASSERT_TRUE(upEventSequenceNum);
const std::chrono::duration timeout =
mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mFocusedWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/,
+ mFocusedWindow->getToken());
// Tap once again
// We cannot use "tapOnFocusedWindow" because it asserts the injection result to be success
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
FOCUSED_WINDOW_LOCATION));
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
FOCUSED_WINDOW_LOCATION));
// Unfocused window does not receive ACTION_OUTSIDE because the tapped window is not a
@@ -4151,14 +2977,13 @@ TEST_F(InputDispatcherMultiWindowAnr, DuringAnr_SecondTapIsIgnored) {
ASSERT_TRUE(mDispatcher->waitForIdle());
// The second tap did not go to the focused window
mFocusedWindow->assertNoEvents();
- // Since all events are finished, connection should be deemed healthy again
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mFocusedWindow->getToken());
+ // should not have another ANR after the window just became healthy again
mFakePolicy->assertNotifyAnrWasNotCalled();
}
// If you tap outside of all windows, there will not be ANR
TEST_F(InputDispatcherMultiWindowAnr, TapOutsideAllWindows_DoesNotAnr) {
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
LOCATION_OUTSIDE_ALL_WINDOWS));
ASSERT_TRUE(mDispatcher->waitForIdle());
@@ -4170,7 +2995,7 @@ TEST_F(InputDispatcherMultiWindowAnr, Window_CanBePaused) {
mFocusedWindow->setPaused(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mUnfocusedWindow, mFocusedWindow}}});
- ASSERT_EQ(InputEventInjectionResult::FAILED,
+ ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED,
injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
FOCUSED_WINDOW_LOCATION));
@@ -4210,20 +3035,19 @@ TEST_F(InputDispatcherMultiWindowAnr, PendingKey_GoesToNewlyFocusedWindow) {
// Injection will succeed because we will eventually give up and send the key to the focused
// window even if motions are still being processed.
- InputEventInjectionResult result =
+ int32_t result =
injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /*repeatCount*/, ADISPLAY_ID_DEFAULT,
- InputEventInjectionSync::NONE, 10ms /*injectionTimeout*/);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result);
+ INPUT_EVENT_INJECTION_SYNC_NONE, 10ms /*injectionTimeout*/);
+ ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, result);
// Key will not be sent to the window, yet, because the window is still processing events
// and the key remains pending, waiting for the touch events to be processed
std::optional<uint32_t> keySequenceNum = mFocusedWindow->receiveEvent();
ASSERT_FALSE(keySequenceNum);
// Switch the focus to the "unfocused" window that we tapped. Expect the key to go there
- mFocusedWindow->setFocusable(false);
- mUnfocusedWindow->setFocusable(true);
+ mFocusedWindow->setFocus(false);
+ mUnfocusedWindow->setFocus(true);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mFocusedWindow, mUnfocusedWindow}}});
- setFocusedWindow(mUnfocusedWindow);
// Focus events should precede the key events
mUnfocusedWindow->consumeFocusEvent(true);
@@ -4238,7 +3062,6 @@ TEST_F(InputDispatcherMultiWindowAnr, PendingKey_GoesToNewlyFocusedWindow) {
mUnfocusedWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT);
mFocusedWindow->assertNoEvents();
mUnfocusedWindow->assertNoEvents();
- mFakePolicy->assertNotifyAnrWasNotCalled();
}
// When the touch stream is split across 2 windows, and one of them does not respond,
@@ -4264,7 +3087,8 @@ TEST_F(InputDispatcherMultiWindowAnr, SplitTouch_SingleWindowAnr) {
const std::chrono::duration timeout =
mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
- mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mFocusedWindow->getToken());
+ mFakePolicy->assertNotifyAnrWasCalled(timeout, nullptr /*application*/,
+ mFocusedWindow->getToken());
mUnfocusedWindow->consumeMotionDown();
mFocusedWindow->consumeMotionDown();
@@ -4282,1027 +3106,10 @@ TEST_F(InputDispatcherMultiWindowAnr, SplitTouch_SingleWindowAnr) {
} else {
ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionEvent.getAction());
}
- ASSERT_TRUE(mDispatcher->waitForIdle());
- mFakePolicy->assertNotifyWindowResponsiveWasCalled(mFocusedWindow->getToken());
+ ASSERT_TRUE(mDispatcher->waitForIdle());
mUnfocusedWindow->assertNoEvents();
mFocusedWindow->assertNoEvents();
- mFakePolicy->assertNotifyAnrWasNotCalled();
-}
-
-/**
- * If we have no focused window, and a key comes in, we start the ANR timer.
- * The focused application should add a focused window before the timer runs out to prevent ANR.
- *
- * If the user touches another application during this time, the key should be dropped.
- * Next, if a new focused window comes in, without toggling the focused application,
- * then no ANR should occur.
- *
- * Normally, we would expect the new focused window to be accompanied by 'setFocusedApplication',
- * but in some cases the policy may not update the focused application.
- */
-TEST_F(InputDispatcherMultiWindowAnr, FocusedWindowWithoutSetFocusedApplication_NoAnr) {
- std::shared_ptr<FakeApplicationHandle> focusedApplication =
- std::make_shared<FakeApplicationHandle>();
- focusedApplication->setDispatchingTimeout(60ms);
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, focusedApplication);
- // The application that owns 'mFocusedWindow' and 'mUnfocusedWindow' is not focused.
- mFocusedWindow->setFocusable(false);
-
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mFocusedWindow, mUnfocusedWindow}}});
- mFocusedWindow->consumeFocusEvent(false);
-
- // Send a key. The ANR timer should start because there is no focused window.
- // 'focusedApplication' will get blamed if this timer completes.
- // Key will not be sent anywhere because we have no focused window. It will remain pending.
- InputEventInjectionResult result =
- injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /*repeatCount*/, ADISPLAY_ID_DEFAULT,
- InputEventInjectionSync::NONE, 10ms /*injectionTimeout*/,
- false /* allowKeyRepeat */);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result);
-
- // Wait until dispatcher starts the "no focused window" timer. If we don't wait here,
- // then the injected touches won't cause the focused event to get dropped.
- // The dispatcher only checks for whether the queue should be pruned upon queueing.
- // If we inject the touch right away and the ANR timer hasn't started, the touch event would
- // simply be added to the queue without 'shouldPruneInboundQueueLocked' returning 'true'.
- // For this test, it means that the key would get delivered to the window once it becomes
- // focused.
- std::this_thread::sleep_for(10ms);
-
- // Touch unfocused window. This should force the pending key to get dropped.
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {UNFOCUSED_WINDOW_LOCATION});
- mDispatcher->notifyMotion(&motionArgs);
-
- // We do not consume the motion right away, because that would require dispatcher to first
- // process (== drop) the key event, and by that time, ANR will be raised.
- // Set the focused window first.
- mFocusedWindow->setFocusable(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mFocusedWindow, mUnfocusedWindow}}});
- setFocusedWindow(mFocusedWindow);
- mFocusedWindow->consumeFocusEvent(true);
- // We do not call "setFocusedApplication" here, even though the newly focused window belongs
- // to another application. This could be a bug / behaviour in the policy.
-
- mUnfocusedWindow->consumeMotionDown();
-
- ASSERT_TRUE(mDispatcher->waitForIdle());
- // Should not ANR because we actually have a focused window. It was just added too slowly.
- ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertNotifyAnrWasNotCalled());
-}
-
-// These tests ensure we cannot send touch events to a window that's positioned behind a window
-// that has feature NO_INPUT_CHANNEL.
-// Layout:
-// Top (closest to user)
-// mNoInputWindow (above all windows)
-// mBottomWindow
-// Bottom (furthest from user)
-class InputDispatcherMultiWindowOcclusionTests : public InputDispatcherTest {
- virtual void SetUp() override {
- InputDispatcherTest::SetUp();
-
- mApplication = std::make_shared<FakeApplicationHandle>();
- mNoInputWindow = new FakeWindowHandle(mApplication, mDispatcher,
- "Window without input channel", ADISPLAY_ID_DEFAULT,
- std::make_optional<sp<IBinder>>(nullptr) /*token*/);
-
- mNoInputWindow->setInputFeatures(InputWindowInfo::Feature::NO_INPUT_CHANNEL);
- mNoInputWindow->setFrame(Rect(0, 0, 100, 100));
- // It's perfectly valid for this window to not have an associated input channel
-
- mBottomWindow = new FakeWindowHandle(mApplication, mDispatcher, "Bottom window",
- ADISPLAY_ID_DEFAULT);
- mBottomWindow->setFrame(Rect(0, 0, 100, 100));
-
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mNoInputWindow, mBottomWindow}}});
- }
-
-protected:
- std::shared_ptr<FakeApplicationHandle> mApplication;
- sp<FakeWindowHandle> mNoInputWindow;
- sp<FakeWindowHandle> mBottomWindow;
-};
-
-TEST_F(InputDispatcherMultiWindowOcclusionTests, NoInputChannelFeature_DropsTouches) {
- PointF touchedPoint = {10, 10};
-
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {touchedPoint});
- mDispatcher->notifyMotion(&motionArgs);
-
- mNoInputWindow->assertNoEvents();
- // Even though the window 'mNoInputWindow' positioned above 'mBottomWindow' does not have
- // an input channel, it is not marked as FLAG_NOT_TOUCHABLE,
- // and therefore should prevent mBottomWindow from receiving touches
- mBottomWindow->assertNoEvents();
-}
-
-/**
- * If a window has feature NO_INPUT_CHANNEL, and somehow (by mistake) still has an input channel,
- * ensure that this window does not receive any touches, and blocks touches to windows underneath.
- */
-TEST_F(InputDispatcherMultiWindowOcclusionTests,
- NoInputChannelFeature_DropsTouchesWithValidChannel) {
- mNoInputWindow = new FakeWindowHandle(mApplication, mDispatcher,
- "Window with input channel and NO_INPUT_CHANNEL",
- ADISPLAY_ID_DEFAULT);
-
- mNoInputWindow->setInputFeatures(InputWindowInfo::Feature::NO_INPUT_CHANNEL);
- mNoInputWindow->setFrame(Rect(0, 0, 100, 100));
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mNoInputWindow, mBottomWindow}}});
-
- PointF touchedPoint = {10, 10};
-
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {touchedPoint});
- mDispatcher->notifyMotion(&motionArgs);
-
- mNoInputWindow->assertNoEvents();
- mBottomWindow->assertNoEvents();
-}
-
-class InputDispatcherMirrorWindowFocusTests : public InputDispatcherTest {
-protected:
- std::shared_ptr<FakeApplicationHandle> mApp;
- sp<FakeWindowHandle> mWindow;
- sp<FakeWindowHandle> mMirror;
-
- virtual void SetUp() override {
- InputDispatcherTest::SetUp();
- mApp = std::make_shared<FakeApplicationHandle>();
- mWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT);
- mMirror = new FakeWindowHandle(mApp, mDispatcher, "TestWindowMirror", ADISPLAY_ID_DEFAULT,
- mWindow->getToken());
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp);
- mWindow->setFocusable(true);
- mMirror->setFocusable(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow, mMirror}}});
- }
-};
-
-TEST_F(InputDispatcherMirrorWindowFocusTests, CanGetFocus) {
- // Request focus on a mirrored window
- setFocusedWindow(mMirror);
-
- // window gets focused
- mWindow->consumeFocusEvent(true);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyDown(ADISPLAY_ID_NONE);
-}
-
-// A focused & mirrored window remains focused only if the window and its mirror are both
-// focusable.
-TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedIfAllWindowsFocusable) {
- setFocusedWindow(mMirror);
-
- // window gets focused
- mWindow->consumeFocusEvent(true);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyDown(ADISPLAY_ID_NONE);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyUp(ADISPLAY_ID_NONE);
-
- mMirror->setFocusable(false);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow, mMirror}}});
-
- // window loses focus since one of the windows associated with the token in not focusable
- mWindow->consumeFocusEvent(false);
-
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::TIMED_OUT";
- mWindow->assertNoEvents();
-}
-
-// A focused & mirrored window remains focused until the window and its mirror both become
-// invisible.
-TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedIfAnyWindowVisible) {
- setFocusedWindow(mMirror);
-
- // window gets focused
- mWindow->consumeFocusEvent(true);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyDown(ADISPLAY_ID_NONE);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyUp(ADISPLAY_ID_NONE);
-
- mMirror->setVisible(false);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow, mMirror}}});
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyDown(ADISPLAY_ID_NONE);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyUp(ADISPLAY_ID_NONE);
-
- mWindow->setVisible(false);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow, mMirror}}});
-
- // window loses focus only after all windows associated with the token become invisible.
- mWindow->consumeFocusEvent(false);
-
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::TIMED_OUT";
- mWindow->assertNoEvents();
-}
-
-// A focused & mirrored window remains focused until both windows are removed.
-TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedWhileWindowsAlive) {
- setFocusedWindow(mMirror);
-
- // window gets focused
- mWindow->consumeFocusEvent(true);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyDown(ADISPLAY_ID_NONE);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyUp(ADISPLAY_ID_NONE);
-
- // single window is removed but the window token remains focused
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mMirror}}});
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyDown(ADISPLAY_ID_NONE);
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::SUCCEEDED";
- mWindow->consumeKeyUp(ADISPLAY_ID_NONE);
-
- // Both windows are removed
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {}}});
- mWindow->consumeFocusEvent(false);
-
- ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, injectKeyDown(mDispatcher))
- << "Inject key event should return InputEventInjectionResult::TIMED_OUT";
- mWindow->assertNoEvents();
-}
-
-// Focus request can be pending until one window becomes visible.
-TEST_F(InputDispatcherMirrorWindowFocusTests, DeferFocusWhenInvisible) {
- // Request focus on an invisible mirror.
- mWindow->setVisible(false);
- mMirror->setVisible(false);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow, mMirror}}});
- setFocusedWindow(mMirror);
-
- // Injected key goes to pending queue.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */,
- ADISPLAY_ID_DEFAULT, InputEventInjectionSync::NONE));
-
- mMirror->setVisible(true);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow, mMirror}}});
-
- // window gets focused
- mWindow->consumeFocusEvent(true);
- // window gets the pending key event
- mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT);
-}
-
-class InputDispatcherPointerCaptureTests : public InputDispatcherTest {
-protected:
- std::shared_ptr<FakeApplicationHandle> mApp;
- sp<FakeWindowHandle> mWindow;
- sp<FakeWindowHandle> mSecondWindow;
-
- void SetUp() override {
- InputDispatcherTest::SetUp();
- mApp = std::make_shared<FakeApplicationHandle>();
- mWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT);
- mWindow->setFocusable(true);
- mSecondWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT);
- mSecondWindow->setFocusable(true);
-
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow, mSecondWindow}}});
-
- setFocusedWindow(mWindow);
- mWindow->consumeFocusEvent(true);
- }
-
- void notifyPointerCaptureChanged(bool enabled) {
- const NotifyPointerCaptureChangedArgs args = generatePointerCaptureChangedArgs(enabled);
- mDispatcher->notifyPointerCaptureChanged(&args);
- }
-
- void requestAndVerifyPointerCapture(const sp<FakeWindowHandle>& window, bool enabled) {
- mDispatcher->requestPointerCapture(window->getToken(), enabled);
- mFakePolicy->waitForSetPointerCapture(enabled);
- notifyPointerCaptureChanged(enabled);
- window->consumeCaptureEvent(enabled);
- }
-};
-
-TEST_F(InputDispatcherPointerCaptureTests, EnablePointerCaptureWhenFocused) {
- // Ensure that capture cannot be obtained for unfocused windows.
- mDispatcher->requestPointerCapture(mSecondWindow->getToken(), true);
- mFakePolicy->assertSetPointerCaptureNotCalled();
- mSecondWindow->assertNoEvents();
-
- // Ensure that capture can be enabled from the focus window.
- requestAndVerifyPointerCapture(mWindow, true);
-
- // Ensure that capture cannot be disabled from a window that does not have capture.
- mDispatcher->requestPointerCapture(mSecondWindow->getToken(), false);
- mFakePolicy->assertSetPointerCaptureNotCalled();
-
- // Ensure that capture can be disabled from the window with capture.
- requestAndVerifyPointerCapture(mWindow, false);
-}
-
-TEST_F(InputDispatcherPointerCaptureTests, DisablesPointerCaptureAfterWindowLosesFocus) {
- requestAndVerifyPointerCapture(mWindow, true);
-
- setFocusedWindow(mSecondWindow);
-
- // Ensure that the capture disabled event was sent first.
- mWindow->consumeCaptureEvent(false);
- mWindow->consumeFocusEvent(false);
- mSecondWindow->consumeFocusEvent(true);
- mFakePolicy->waitForSetPointerCapture(false);
-
- // Ensure that additional state changes from InputReader are not sent to the window.
- notifyPointerCaptureChanged(false);
- notifyPointerCaptureChanged(true);
- notifyPointerCaptureChanged(false);
- mWindow->assertNoEvents();
- mSecondWindow->assertNoEvents();
- mFakePolicy->assertSetPointerCaptureNotCalled();
-}
-
-TEST_F(InputDispatcherPointerCaptureTests, UnexpectedStateChangeDisablesPointerCapture) {
- requestAndVerifyPointerCapture(mWindow, true);
-
- // InputReader unexpectedly disables and enables pointer capture.
- notifyPointerCaptureChanged(false);
- notifyPointerCaptureChanged(true);
-
- // Ensure that Pointer Capture is disabled.
- mFakePolicy->waitForSetPointerCapture(false);
- mWindow->consumeCaptureEvent(false);
- mWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherPointerCaptureTests, OutOfOrderRequests) {
- requestAndVerifyPointerCapture(mWindow, true);
-
- // The first window loses focus.
- setFocusedWindow(mSecondWindow);
- mFakePolicy->waitForSetPointerCapture(false);
- mWindow->consumeCaptureEvent(false);
-
- // Request Pointer Capture from the second window before the notification from InputReader
- // arrives.
- mDispatcher->requestPointerCapture(mSecondWindow->getToken(), true);
- mFakePolicy->waitForSetPointerCapture(true);
-
- // InputReader notifies Pointer Capture was disabled (because of the focus change).
- notifyPointerCaptureChanged(false);
-
- // InputReader notifies Pointer Capture was enabled (because of mSecondWindow's request).
- notifyPointerCaptureChanged(true);
-
- mSecondWindow->consumeFocusEvent(true);
- mSecondWindow->consumeCaptureEvent(true);
-}
-
-class InputDispatcherUntrustedTouchesTest : public InputDispatcherTest {
-protected:
- constexpr static const float MAXIMUM_OBSCURING_OPACITY = 0.8;
-
- constexpr static const float OPACITY_ABOVE_THRESHOLD = 0.9;
- static_assert(OPACITY_ABOVE_THRESHOLD > MAXIMUM_OBSCURING_OPACITY);
-
- constexpr static const float OPACITY_BELOW_THRESHOLD = 0.7;
- static_assert(OPACITY_BELOW_THRESHOLD < MAXIMUM_OBSCURING_OPACITY);
-
- // When combined twice, ie 1 - (1 - 0.5)*(1 - 0.5) = 0.75 < 8, is still below the threshold
- constexpr static const float OPACITY_FAR_BELOW_THRESHOLD = 0.5;
- static_assert(OPACITY_FAR_BELOW_THRESHOLD < MAXIMUM_OBSCURING_OPACITY);
- static_assert(1 - (1 - OPACITY_FAR_BELOW_THRESHOLD) * (1 - OPACITY_FAR_BELOW_THRESHOLD) <
- MAXIMUM_OBSCURING_OPACITY);
-
- static const int32_t TOUCHED_APP_UID = 10001;
- static const int32_t APP_B_UID = 10002;
- static const int32_t APP_C_UID = 10003;
-
- sp<FakeWindowHandle> mTouchWindow;
-
- virtual void SetUp() override {
- InputDispatcherTest::SetUp();
- mTouchWindow = getWindow(TOUCHED_APP_UID, "Touched");
- mDispatcher->setBlockUntrustedTouchesMode(android::os::BlockUntrustedTouchesMode::BLOCK);
- mDispatcher->setMaximumObscuringOpacityForTouch(MAXIMUM_OBSCURING_OPACITY);
- }
-
- virtual void TearDown() override {
- InputDispatcherTest::TearDown();
- mTouchWindow.clear();
- }
-
- sp<FakeWindowHandle> getOccludingWindow(int32_t uid, std::string name,
- os::TouchOcclusionMode mode, float alpha = 1.0f) {
- sp<FakeWindowHandle> window = getWindow(uid, name);
- window->setFlags(InputWindowInfo::Flag::NOT_TOUCHABLE);
- window->setTouchOcclusionMode(mode);
- window->setAlpha(alpha);
- return window;
- }
-
- sp<FakeWindowHandle> getWindow(int32_t uid, std::string name) {
- std::shared_ptr<FakeApplicationHandle> app = std::make_shared<FakeApplicationHandle>();
- sp<FakeWindowHandle> window =
- new FakeWindowHandle(app, mDispatcher, name, ADISPLAY_ID_DEFAULT);
- // Generate an arbitrary PID based on the UID
- window->setOwnerInfo(1777 + (uid % 10000), uid);
- return window;
- }
-
- void touch(const std::vector<PointF>& points = {PointF{100, 200}}) {
- NotifyMotionArgs args =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, points);
- mDispatcher->notifyMotion(&args);
- }
-};
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithBlockUntrustedOcclusionMode_BlocksTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowWithBlockUntrustedOcclusionModeWithOpacityBelowThreshold_BlocksTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.7f);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowWithBlockUntrustedOcclusionMode_DoesNotReceiveTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- w->assertNoEvents();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithAllowOcclusionMode_AllowsTouch) {
- const sp<FakeWindowHandle>& w = getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::ALLOW);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, TouchOutsideOccludingWindow_AllowsTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED);
- w->setFrame(Rect(0, 0, 50, 50));
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch({PointF{100, 100}});
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowFromSameUid_AllowsTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(TOUCHED_APP_UID, "A", TouchOcclusionMode::BLOCK_UNTRUSTED);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithZeroOpacity_AllowsTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithZeroOpacity_DoesNotReceiveTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- w->assertNoEvents();
-}
-
-/**
- * This is important to make sure apps can't indirectly learn the position of touches (outside vs
- * inside) while letting them pass-through. Note that even though touch passes through the occluding
- * window, the occluding window will still receive ACTION_OUTSIDE event.
- */
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowWithZeroOpacityAndWatchOutside_ReceivesOutsideEvent) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f);
- w->addFlags(InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- w->consumeMotionOutside();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, OutsideEvent_HasZeroCoordinates) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED, 0.0f);
- w->addFlags(InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- InputEvent* event = w->consume();
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType());
- MotionEvent& motionEvent = static_cast<MotionEvent&>(*event);
- EXPECT_EQ(0.0f, motionEvent.getRawPointerCoords(0)->getX());
- EXPECT_EQ(0.0f, motionEvent.getRawPointerCoords(0)->getY());
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityBelowThreshold_AllowsTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityAtThreshold_AllowsTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- MAXIMUM_OBSCURING_OPACITY);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowWithOpacityAboveThreshold_BlocksTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- OPACITY_ABOVE_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowsWithCombinedOpacityAboveThreshold_BlocksTouch) {
- // Resulting opacity = 1 - (1 - 0.7)*(1 - 0.7) = .91
- const sp<FakeWindowHandle>& w1 =
- getOccludingWindow(APP_B_UID, "B1", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- const sp<FakeWindowHandle>& w2 =
- getOccludingWindow(APP_B_UID, "B2", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w1, w2, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowsWithCombinedOpacityBelowThreshold_AllowsTouch) {
- // Resulting opacity = 1 - (1 - 0.5)*(1 - 0.5) = .75
- const sp<FakeWindowHandle>& w1 =
- getOccludingWindow(APP_B_UID, "B1", TouchOcclusionMode::USE_OPACITY,
- OPACITY_FAR_BELOW_THRESHOLD);
- const sp<FakeWindowHandle>& w2 =
- getOccludingWindow(APP_B_UID, "B2", TouchOcclusionMode::USE_OPACITY,
- OPACITY_FAR_BELOW_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w1, w2, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowsFromDifferentAppsEachBelowThreshold_AllowsTouch) {
- const sp<FakeWindowHandle>& wB =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- const sp<FakeWindowHandle>& wC =
- getOccludingWindow(APP_C_UID, "C", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {wB, wC, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, WindowsFromDifferentAppsOneAboveThreshold_BlocksTouch) {
- const sp<FakeWindowHandle>& wB =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- const sp<FakeWindowHandle>& wC =
- getOccludingWindow(APP_C_UID, "C", TouchOcclusionMode::USE_OPACITY,
- OPACITY_ABOVE_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {wB, wC, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowWithOpacityAboveThresholdAndSelfWindow_BlocksTouch) {
- const sp<FakeWindowHandle>& wA =
- getOccludingWindow(TOUCHED_APP_UID, "T", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- const sp<FakeWindowHandle>& wB =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- OPACITY_ABOVE_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {wA, wB, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowWithOpacityBelowThresholdAndSelfWindow_AllowsTouch) {
- const sp<FakeWindowHandle>& wA =
- getOccludingWindow(TOUCHED_APP_UID, "T", TouchOcclusionMode::USE_OPACITY,
- OPACITY_ABOVE_THRESHOLD);
- const sp<FakeWindowHandle>& wB =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {wA, wB, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, SelfWindowWithOpacityAboveThreshold_AllowsTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(TOUCHED_APP_UID, "T", TouchOcclusionMode::USE_OPACITY,
- OPACITY_ABOVE_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, SelfWindowWithBlockUntrustedMode_AllowsTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(TOUCHED_APP_UID, "T", TouchOcclusionMode::BLOCK_UNTRUSTED);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest,
- OpacityThresholdIs0AndWindowAboveThreshold_BlocksTouch) {
- mDispatcher->setMaximumObscuringOpacityForTouch(0.0f);
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.1f);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest, OpacityThresholdIs0AndWindowAtThreshold_AllowsTouch) {
- mDispatcher->setMaximumObscuringOpacityForTouch(0.0f);
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY, 0.0f);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest,
- OpacityThresholdIs1AndWindowBelowThreshold_AllowsTouch) {
- mDispatcher->setMaximumObscuringOpacityForTouch(1.0f);
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- OPACITY_ABOVE_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowWithBlockUntrustedModeAndWindowWithOpacityBelowFromSameApp_BlocksTouch) {
- const sp<FakeWindowHandle>& w1 =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED,
- OPACITY_BELOW_THRESHOLD);
- const sp<FakeWindowHandle>& w2 =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w1, w2, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-/**
- * Window B of BLOCK_UNTRUSTED occlusion mode is enough to block the touch, we're testing that the
- * addition of another window (C) of USE_OPACITY occlusion mode and opacity below the threshold
- * (which alone would result in allowing touches) does not affect the blocking behavior.
- */
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowWithBlockUntrustedModeAndWindowWithOpacityBelowFromDifferentApps_BlocksTouch) {
- const sp<FakeWindowHandle>& wB =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED,
- OPACITY_BELOW_THRESHOLD);
- const sp<FakeWindowHandle>& wC =
- getOccludingWindow(APP_C_UID, "C", TouchOcclusionMode::USE_OPACITY,
- OPACITY_BELOW_THRESHOLD);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {wB, wC, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->assertNoEvents();
-}
-
-/**
- * This test is testing that a window from a different UID but with same application token doesn't
- * block the touch. Apps can share the application token for close UI collaboration for example.
- */
-TEST_F(InputDispatcherUntrustedTouchesTest,
- WindowWithSameApplicationTokenFromDifferentApp_AllowsTouch) {
- const sp<FakeWindowHandle>& w =
- getOccludingWindow(APP_B_UID, "B", TouchOcclusionMode::BLOCK_UNTRUSTED);
- w->setApplicationToken(mTouchWindow->getApplicationToken());
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {w, mTouchWindow}}});
-
- touch();
-
- mTouchWindow->consumeAnyMotionDown();
-}
-
-class InputDispatcherDragTests : public InputDispatcherTest {
-protected:
- std::shared_ptr<FakeApplicationHandle> mApp;
- sp<FakeWindowHandle> mWindow;
- sp<FakeWindowHandle> mSecondWindow;
- sp<FakeWindowHandle> mDragWindow;
-
- void SetUp() override {
- InputDispatcherTest::SetUp();
- mApp = std::make_shared<FakeApplicationHandle>();
- mWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT);
- mWindow->setFrame(Rect(0, 0, 100, 100));
- mWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
-
- mSecondWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT);
- mSecondWindow->setFrame(Rect(100, 0, 200, 100));
- mSecondWindow->setFlags(InputWindowInfo::Flag::NOT_TOUCH_MODAL);
-
- mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow, mSecondWindow}}});
- }
-
- // Start performing drag, we will create a drag window and transfer touch to it.
- void performDrag() {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {50, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
-
- // Window should receive motion event.
- mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT);
-
- // The drag window covers the entire display
- mDragWindow = new FakeWindowHandle(mApp, mDispatcher, "DragWindow", ADISPLAY_ID_DEFAULT);
- mDispatcher->setInputWindows(
- {{ADISPLAY_ID_DEFAULT, {mDragWindow, mWindow, mSecondWindow}}});
-
- // Transfer touch focus to the drag window
- mDispatcher->transferTouchFocus(mWindow->getToken(), mDragWindow->getToken(),
- true /* isDragDrop */);
- mWindow->consumeMotionCancel();
- mDragWindow->consumeMotionDown();
- }
-
- // Start performing drag, we will create a drag window and transfer touch to it.
- void performStylusDrag() {
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN,
- AINPUT_SOURCE_STYLUS)
- .buttonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY)
- .pointer(PointerBuilder(0,
- AMOTION_EVENT_TOOL_TYPE_STYLUS)
- .x(50)
- .y(50))
- .build()));
- mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT);
-
- // The drag window covers the entire display
- mDragWindow = new FakeWindowHandle(mApp, mDispatcher, "DragWindow", ADISPLAY_ID_DEFAULT);
- mDispatcher->setInputWindows(
- {{ADISPLAY_ID_DEFAULT, {mDragWindow, mWindow, mSecondWindow}}});
-
- // Transfer touch focus to the drag window
- mDispatcher->transferTouchFocus(mWindow->getToken(), mDragWindow->getToken(),
- true /* isDragDrop */);
- mWindow->consumeMotionCancel();
- mDragWindow->consumeMotionDown();
- }
-};
-
-TEST_F(InputDispatcherDragTests, DragEnterAndDragExit) {
- performDrag();
-
- // Move on window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {50, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->consumeDragEvent(false, 50, 50);
- mSecondWindow->assertNoEvents();
-
- // Move to another window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {150, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->consumeDragEvent(true, 150, 50);
- mSecondWindow->consumeDragEvent(false, 50, 50);
-
- // Move back to original window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {50, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->consumeDragEvent(false, 50, 50);
- mSecondWindow->consumeDragEvent(true, -50, 50);
-
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, {50, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
- mWindow->assertNoEvents();
- mSecondWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherDragTests, DragAndDrop) {
- performDrag();
-
- // Move on window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {50, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->consumeDragEvent(false, 50, 50);
- mSecondWindow->assertNoEvents();
-
- // Move to another window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {150, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->consumeDragEvent(true, 150, 50);
- mSecondWindow->consumeDragEvent(false, 50, 50);
-
- // drop to another window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {150, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
- mFakePolicy->assertDropTargetEquals(mSecondWindow->getToken());
- mWindow->assertNoEvents();
- mSecondWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherDragTests, StylusDragAndDrop) {
- performStylusDrag();
-
- // Move on window and keep button pressed.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS)
- .buttonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS)
- .x(50)
- .y(50))
- .build()))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->consumeDragEvent(false, 50, 50);
- mSecondWindow->assertNoEvents();
-
- // Move to another window and release button, expect to drop item.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS)
- .buttonState(0)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS)
- .x(150)
- .y(50))
- .build()))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->assertNoEvents();
- mSecondWindow->assertNoEvents();
- mFakePolicy->assertDropTargetEquals(mSecondWindow->getToken());
-
- // nothing to the window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher,
- MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_STYLUS)
- .buttonState(0)
- .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS)
- .x(150)
- .y(50))
- .build()))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
- mWindow->assertNoEvents();
- mSecondWindow->assertNoEvents();
-}
-
-TEST_F(InputDispatcherDragTests, DragAndDrop_InvalidWindow) {
- performDrag();
-
- // Set second window invisible.
- mSecondWindow->setVisible(false);
- mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mDragWindow, mWindow, mSecondWindow}}});
-
- // Move on window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {50, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->consumeDragEvent(false, 50, 50);
- mSecondWindow->assertNoEvents();
-
- // Move to another window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {150, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
- mWindow->consumeDragEvent(true, 150, 50);
- mSecondWindow->assertNoEvents();
-
- // drop to another window.
- ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
- injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {150, 50}))
- << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
- mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
- mFakePolicy->assertDropTargetEquals(nullptr);
- mWindow->assertNoEvents();
- mSecondWindow->assertNoEvents();
}
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/tests/InputFlingerService_test.cpp b/services/inputflinger/tests/InputFlingerService_test.cpp
deleted file mode 100644
index c368e79f41..0000000000
--- a/services/inputflinger/tests/InputFlingerService_test.cpp
+++ /dev/null
@@ -1,462 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <BnInputFlingerQuery.h>
-#include <IInputFlingerQuery.h>
-
-#include <android/os/BnInputFlinger.h>
-#include <android/os/BnSetInputWindowsListener.h>
-#include <android/os/IInputFlinger.h>
-#include <android/os/ISetInputWindowsListener.h>
-
-#include <binder/Binder.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-#include <binder/Parcel.h>
-#include <binder/ProcessState.h>
-
-#include <input/Input.h>
-#include <input/InputTransport.h>
-#include <input/InputWindow.h>
-
-#include <gtest/gtest.h>
-#include <inttypes.h>
-#include <linux/uinput.h>
-#include <log/log.h>
-#include <ui/Rect.h>
-#include <ui/Region.h>
-#include <chrono>
-#include <thread>
-#include <unordered_map>
-
-#define TAG "InputFlingerServiceTest"
-
-using android::os::BnInputFlinger;
-using android::os::BnSetInputWindowsListener;
-using android::os::IInputFlinger;
-using android::os::ISetInputWindowsListener;
-
-using std::chrono_literals::operator""ms;
-using std::chrono_literals::operator""s;
-
-namespace android {
-
-static const sp<IBinder> TestInfoToken = new BBinder();
-static const sp<IBinder> FocusedTestInfoToken = new BBinder();
-static constexpr int32_t TestInfoId = 1;
-static const std::string TestInfoName = "InputFlingerServiceTestInputWindowInfo";
-static constexpr Flags<InputWindowInfo::Flag> TestInfoFlags = InputWindowInfo::Flag::NOT_FOCUSABLE;
-static constexpr InputWindowInfo::Type TestInfoType = InputWindowInfo::Type::INPUT_METHOD;
-static constexpr std::chrono::duration TestInfoDispatchingTimeout = 2532ms;
-static constexpr int32_t TestInfoFrameLeft = 93;
-static constexpr int32_t TestInfoFrameTop = 34;
-static constexpr int32_t TestInfoFrameRight = 16;
-static constexpr int32_t TestInfoFrameBottom = 19;
-static constexpr int32_t TestInfoSurfaceInset = 17;
-static constexpr float TestInfoGlobalScaleFactor = 0.3;
-static constexpr float TestInfoWindowXScale = 0.4;
-static constexpr float TestInfoWindowYScale = 0.5;
-static const Rect TestInfoTouchableRegionRect = {100 /* left */, 150 /* top */, 400 /* right */,
- 450 /* bottom */};
-static const Region TestInfoTouchableRegion(TestInfoTouchableRegionRect);
-static constexpr bool TestInfoVisible = false;
-static constexpr bool TestInfoTrustedOverlay = true;
-static constexpr bool TestInfoFocusable = false;
-static constexpr bool TestInfoHasWallpaper = false;
-static constexpr bool TestInfoPaused = false;
-static constexpr int32_t TestInfoOwnerPid = 19;
-static constexpr int32_t TestInfoOwnerUid = 24;
-static constexpr InputWindowInfo::Feature TestInfoInputFeatures =
- InputWindowInfo::Feature::NO_INPUT_CHANNEL;
-static constexpr int32_t TestInfoDisplayId = 34;
-static constexpr int32_t TestInfoPortalToDisplayId = 2;
-static constexpr bool TestInfoReplaceTouchableRegionWithCrop = true;
-static const sp<IBinder> TestInfoTouchableRegionCropHandle = new BBinder();
-
-static const std::string TestAppInfoName = "InputFlingerServiceTestInputApplicationInfo";
-static const sp<IBinder> TestAppInfoToken = new BBinder();
-static constexpr std::chrono::duration TestAppInfoDispatchingTimeout = 12345678ms;
-
-static const String16 kTestServiceName = String16("InputFlingerService");
-static const String16 kQueryServiceName = String16("InputFlingerQueryService");
-
-struct SetInputWindowsListener;
-// --- InputFlingerServiceTest ---
-class InputFlingerServiceTest : public testing::Test {
-public:
- void SetUp() override;
- void TearDown() override;
-
-protected:
- void InitializeInputFlinger();
- void setInputWindowsByInfos(const std::vector<InputWindowInfo>& infos);
- void setFocusedWindow(const sp<IBinder> token, const sp<IBinder> focusedToken,
- nsecs_t timestampNanos);
-
- void setInputWindowsFinished();
- void verifyInputWindowInfo(const InputWindowInfo& info) const;
- InputWindowInfo& getInfo() const { return const_cast<InputWindowInfo&>(mInfo); }
-
- sp<IInputFlinger> mService;
- sp<IInputFlingerQuery> mQuery;
-
-private:
- sp<SetInputWindowsListener> mSetInputWindowsListener;
- std::unique_ptr<InputChannel> mServerChannel, mClientChannel;
- InputWindowInfo mInfo;
- std::mutex mLock;
- std::condition_variable mSetInputWindowsFinishedCondition;
-};
-
-struct SetInputWindowsListener : BnSetInputWindowsListener {
- explicit SetInputWindowsListener(std::function<void()> cbFunc) : mCbFunc(cbFunc) {}
-
- binder::Status onSetInputWindowsFinished() override;
-
- std::function<void()> mCbFunc;
-};
-
-class TestInputManager : public BnInputFlinger {
-protected:
- virtual ~TestInputManager(){};
-
-public:
- TestInputManager(){};
-
- binder::Status getInputWindows(std::vector<::android::InputWindowInfo>* inputHandles);
- binder::Status getInputChannels(std::vector<::android::InputChannel>* channels);
- binder::Status getLastFocusRequest(FocusRequest*);
-
- status_t dump(int fd, const Vector<String16>& args) override;
-
- binder::Status setInputWindows(
- const std::vector<InputWindowInfo>& handles,
- const sp<ISetInputWindowsListener>& setInputWindowsListener) override;
-
- binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override;
- binder::Status removeInputChannel(const sp<IBinder>& connectionToken) override;
- binder::Status setFocusedWindow(const FocusRequest&) override;
-
- void reset();
-
-private:
- mutable Mutex mLock;
- std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>> mHandlesPerDisplay;
- std::vector<std::shared_ptr<InputChannel>> mInputChannels;
- FocusRequest mFocusRequest;
-};
-
-class TestInputQuery : public BnInputFlingerQuery {
-public:
- TestInputQuery(sp<android::TestInputManager> manager) : mManager(manager){};
- binder::Status getInputWindows(std::vector<::android::InputWindowInfo>* inputHandles) override;
- binder::Status getInputChannels(std::vector<::android::InputChannel>* channels) override;
- binder::Status getLastFocusRequest(FocusRequest*) override;
- binder::Status resetInputManager() override;
-
-private:
- sp<android::TestInputManager> mManager;
-};
-
-binder::Status TestInputQuery::getInputWindows(
- std::vector<::android::InputWindowInfo>* inputHandles) {
- return mManager->getInputWindows(inputHandles);
-}
-
-binder::Status TestInputQuery::getInputChannels(std::vector<::android::InputChannel>* channels) {
- return mManager->getInputChannels(channels);
-}
-
-binder::Status TestInputQuery::getLastFocusRequest(FocusRequest* request) {
- return mManager->getLastFocusRequest(request);
-}
-
-binder::Status TestInputQuery::resetInputManager() {
- mManager->reset();
- return binder::Status::ok();
-}
-
-binder::Status SetInputWindowsListener::onSetInputWindowsFinished() {
- if (mCbFunc != nullptr) {
- mCbFunc();
- }
- return binder::Status::ok();
-}
-
-binder::Status TestInputManager::setInputWindows(
- const std::vector<InputWindowInfo>& infos,
- const sp<ISetInputWindowsListener>& setInputWindowsListener) {
- AutoMutex _l(mLock);
-
- for (const auto& info : infos) {
- mHandlesPerDisplay.emplace(info.displayId, std::vector<sp<InputWindowHandle>>());
- mHandlesPerDisplay[info.displayId].push_back(new InputWindowHandle(info));
- }
- if (setInputWindowsListener) {
- setInputWindowsListener->onSetInputWindowsFinished();
- }
- return binder::Status::ok();
-}
-
-binder::Status TestInputManager::createInputChannel(const std::string& name,
- InputChannel* outChannel) {
- AutoMutex _l(mLock);
- std::unique_ptr<InputChannel> serverChannel;
- std::unique_ptr<InputChannel> clientChannel;
- InputChannel::openInputChannelPair(name, serverChannel, clientChannel);
-
- clientChannel->copyTo(*outChannel);
-
- mInputChannels.emplace_back(std::move(serverChannel));
-
- return binder::Status::ok();
-}
-
-binder::Status TestInputManager::removeInputChannel(const sp<IBinder>& connectionToken) {
- AutoMutex _l(mLock);
-
- auto it = std::find_if(mInputChannels.begin(), mInputChannels.end(),
- [&](std::shared_ptr<InputChannel>& c) {
- return c->getConnectionToken() == connectionToken;
- });
- if (it != mInputChannels.end()) {
- mInputChannels.erase(it);
- }
-
- return binder::Status::ok();
-}
-
-status_t TestInputManager::dump(int fd, const Vector<String16>& args) {
- std::string dump;
-
- dump += " InputFlinger dump\n";
-
- ::write(fd, dump.c_str(), dump.size());
- return NO_ERROR;
-}
-
-binder::Status TestInputManager::getInputWindows(
- std::vector<::android::InputWindowInfo>* inputInfos) {
- for (auto& [displayId, inputHandles] : mHandlesPerDisplay) {
- for (auto& inputHandle : inputHandles) {
- inputInfos->push_back(*inputHandle->getInfo());
- }
- }
- return binder::Status::ok();
-}
-
-binder::Status TestInputManager::getInputChannels(std::vector<::android::InputChannel>* channels) {
- channels->clear();
- for (std::shared_ptr<InputChannel>& channel : mInputChannels) {
- channels->push_back(*channel);
- }
- return binder::Status::ok();
-}
-
-binder::Status TestInputManager::getLastFocusRequest(FocusRequest* request) {
- *request = mFocusRequest;
- return binder::Status::ok();
-}
-
-binder::Status TestInputManager::setFocusedWindow(const FocusRequest& request) {
- mFocusRequest = request;
- return binder::Status::ok();
-}
-
-void TestInputManager::reset() {
- mHandlesPerDisplay.clear();
- mInputChannels.clear();
- mFocusRequest = FocusRequest();
-}
-
-void InputFlingerServiceTest::SetUp() {
- mSetInputWindowsListener = new SetInputWindowsListener([&]() {
- std::unique_lock<std::mutex> lock(mLock);
- mSetInputWindowsFinishedCondition.notify_all();
- });
- InputChannel::openInputChannelPair("testchannels", mServerChannel, mClientChannel);
-
- mInfo.token = TestInfoToken;
- mInfo.id = TestInfoId;
- mInfo.name = TestInfoName;
- mInfo.flags = TestInfoFlags;
- mInfo.type = TestInfoType;
- mInfo.dispatchingTimeout = TestInfoDispatchingTimeout;
- mInfo.frameLeft = TestInfoFrameLeft;
- mInfo.frameTop = TestInfoFrameTop;
- mInfo.frameRight = TestInfoFrameRight;
- mInfo.frameBottom = TestInfoFrameBottom;
- mInfo.surfaceInset = TestInfoSurfaceInset;
- mInfo.globalScaleFactor = TestInfoGlobalScaleFactor;
- mInfo.transform.set({TestInfoWindowXScale, 0, TestInfoFrameLeft, 0, TestInfoWindowYScale,
- TestInfoFrameTop, 0, 0, 1});
- mInfo.touchableRegion = TestInfoTouchableRegion;
- mInfo.visible = TestInfoVisible;
- mInfo.trustedOverlay = TestInfoTrustedOverlay;
- mInfo.focusable = TestInfoFocusable;
-
- mInfo.hasWallpaper = TestInfoHasWallpaper;
- mInfo.paused = TestInfoPaused;
- mInfo.ownerPid = TestInfoOwnerPid;
- mInfo.ownerUid = TestInfoOwnerUid;
- mInfo.inputFeatures = TestInfoInputFeatures;
- mInfo.displayId = TestInfoDisplayId;
- mInfo.portalToDisplayId = TestInfoPortalToDisplayId;
- mInfo.replaceTouchableRegionWithCrop = TestInfoReplaceTouchableRegionWithCrop;
- mInfo.touchableRegionCropHandle = TestInfoTouchableRegionCropHandle;
-
- mInfo.applicationInfo.name = TestAppInfoName;
- mInfo.applicationInfo.token = TestAppInfoToken;
- mInfo.applicationInfo.dispatchingTimeoutMillis =
- std::chrono::duration_cast<std::chrono::milliseconds>(TestAppInfoDispatchingTimeout)
- .count();
-
- InitializeInputFlinger();
-}
-
-void InputFlingerServiceTest::TearDown() {
- mQuery->resetInputManager();
-}
-
-void InputFlingerServiceTest::verifyInputWindowInfo(const InputWindowInfo& info) const {
- EXPECT_EQ(mInfo, info);
-}
-
-void InputFlingerServiceTest::InitializeInputFlinger() {
- sp<IBinder> input(defaultServiceManager()->waitForService(kTestServiceName));
- ASSERT_TRUE(input != nullptr);
- mService = interface_cast<IInputFlinger>(input);
-
- input = defaultServiceManager()->waitForService(kQueryServiceName);
- ASSERT_TRUE(input != nullptr);
- mQuery = interface_cast<IInputFlingerQuery>(input);
-}
-
-void InputFlingerServiceTest::setInputWindowsByInfos(const std::vector<InputWindowInfo>& infos) {
- std::unique_lock<std::mutex> lock(mLock);
- mService->setInputWindows(infos, mSetInputWindowsListener);
- // Verify listener call
- EXPECT_NE(mSetInputWindowsFinishedCondition.wait_for(lock, 1s), std::cv_status::timeout);
-}
-
-void InputFlingerServiceTest::setFocusedWindow(const sp<IBinder> token,
- const sp<IBinder> focusedToken,
- nsecs_t timestampNanos) {
- FocusRequest request;
- request.token = TestInfoToken;
- request.focusedToken = focusedToken;
- request.timestamp = timestampNanos;
- mService->setFocusedWindow(request);
- // call set input windows and wait for the callback to drain the queue.
- setInputWindowsByInfos(std::vector<InputWindowInfo>());
-}
-
-/**
- * Test InputFlinger service interface SetInputWindows
- */
-TEST_F(InputFlingerServiceTest, InputWindow_SetInputWindows) {
- std::vector<InputWindowInfo> infos = {getInfo()};
- setInputWindowsByInfos(infos);
-
- // Verify input windows from service
- std::vector<::android::InputWindowInfo> windowInfos;
- mQuery->getInputWindows(&windowInfos);
- for (const ::android::InputWindowInfo& windowInfo : windowInfos) {
- verifyInputWindowInfo(windowInfo);
- }
-}
-
-/**
- * Test InputFlinger service interface createInputChannel
- */
-TEST_F(InputFlingerServiceTest, CreateInputChannelReturnsUnblockedFd) {
- // Test that the unblocked file descriptor flag is kept across processes over binder
- // transactions.
-
- InputChannel channel;
- ASSERT_TRUE(mService->createInputChannel("testchannels", &channel).isOk());
-
- const base::unique_fd& fd = channel.getFd();
- ASSERT_TRUE(fd.ok());
-
- const int result = fcntl(fd, F_GETFL);
- EXPECT_NE(result, -1);
- EXPECT_EQ(result & O_NONBLOCK, O_NONBLOCK);
-}
-
-TEST_F(InputFlingerServiceTest, InputWindow_CreateInputChannel) {
- InputChannel channel;
- ASSERT_TRUE(mService->createInputChannel("testchannels", &channel).isOk());
-
- std::vector<::android::InputChannel> channels;
- mQuery->getInputChannels(&channels);
- ASSERT_EQ(channels.size(), 1UL);
- EXPECT_EQ(channels[0].getConnectionToken(), channel.getConnectionToken());
-
- mService->removeInputChannel(channel.getConnectionToken());
- mQuery->getInputChannels(&channels);
- EXPECT_EQ(channels.size(), 0UL);
-}
-
-TEST_F(InputFlingerServiceTest, InputWindow_setFocusedWindow) {
- nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
- setFocusedWindow(TestInfoToken, nullptr /* focusedToken */, now);
-
- FocusRequest request;
- mQuery->getLastFocusRequest(&request);
-
- EXPECT_EQ(request.token, TestInfoToken);
- EXPECT_EQ(request.focusedToken, nullptr);
- EXPECT_EQ(request.timestamp, now);
-}
-
-TEST_F(InputFlingerServiceTest, InputWindow_setFocusedWindowWithFocusedToken) {
- nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
- setFocusedWindow(TestInfoToken, FocusedTestInfoToken, now);
-
- FocusRequest request;
- mQuery->getLastFocusRequest(&request);
-
- EXPECT_EQ(request.token, TestInfoToken);
- EXPECT_EQ(request.focusedToken, FocusedTestInfoToken);
- EXPECT_EQ(request.timestamp, now);
-}
-
-} // namespace android
-
-int main(int argc, char** argv) {
- pid_t forkPid = fork();
-
- if (forkPid == 0) {
- // Server process
- android::sp<android::TestInputManager> manager = new android::TestInputManager();
- android::sp<android::TestInputQuery> query = new android::TestInputQuery(manager);
-
- android::defaultServiceManager()->addService(android::kTestServiceName, manager,
- false /*allowIsolated*/);
- android::defaultServiceManager()->addService(android::kQueryServiceName, query,
- false /*allowIsolated*/);
- android::ProcessState::self()->startThreadPool();
- android::IPCThreadState::self()->joinThreadPool();
- } else {
- android::ProcessState::self()->startThreadPool();
- ::testing::InitGoogleTest(&argc, argv);
- int result = RUN_ALL_TESTS();
- kill(forkPid, SIGKILL);
- return result;
- }
- return 0;
-}
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 997cbe88a1..c457a1525f 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -22,61 +22,38 @@
#include <InputReaderFactory.h>
#include <KeyboardInputMapper.h>
#include <MultiTouchInputMapper.h>
-#include <PeripheralController.h>
-#include <SensorInputMapper.h>
#include <SingleTouchInputMapper.h>
#include <SwitchInputMapper.h>
#include <TestInputListener.h>
#include <TouchInputMapper.h>
#include <UinputDevice.h>
-#include <VibratorInputMapper.h>
+
#include <android-base/thread_annotations.h>
#include <gtest/gtest.h>
#include <inttypes.h>
#include <math.h>
-#include <memory>
-#include <regex>
-#include "input/DisplayViewport.h"
-#include "input/Input.h"
-
namespace android {
using std::chrono_literals::operator""ms;
-using namespace android::flag_operators;
// Timeout for waiting for an expected event
static constexpr std::chrono::duration WAIT_TIMEOUT = 100ms;
// An arbitrary time value.
-static constexpr nsecs_t ARBITRARY_TIME = 1234;
-static constexpr nsecs_t READ_TIME = 4321;
+static const nsecs_t ARBITRARY_TIME = 1234;
// Arbitrary display properties.
-static constexpr int32_t DISPLAY_ID = 0;
-static constexpr int32_t SECONDARY_DISPLAY_ID = DISPLAY_ID + 1;
-static constexpr int32_t DISPLAY_WIDTH = 480;
-static constexpr int32_t DISPLAY_HEIGHT = 800;
-static constexpr int32_t VIRTUAL_DISPLAY_ID = 1;
-static constexpr int32_t VIRTUAL_DISPLAY_WIDTH = 400;
-static constexpr int32_t VIRTUAL_DISPLAY_HEIGHT = 500;
+static const int32_t DISPLAY_ID = 0;
+static const int32_t SECONDARY_DISPLAY_ID = DISPLAY_ID + 1;
+static const int32_t DISPLAY_WIDTH = 480;
+static const int32_t DISPLAY_HEIGHT = 800;
+static const int32_t VIRTUAL_DISPLAY_ID = 1;
+static const int32_t VIRTUAL_DISPLAY_WIDTH = 400;
+static const int32_t VIRTUAL_DISPLAY_HEIGHT = 500;
static const char* VIRTUAL_DISPLAY_UNIQUE_ID = "virtual:1";
static constexpr std::optional<uint8_t> NO_PORT = std::nullopt; // no physical port is specified
-static constexpr int32_t FIRST_SLOT = 0;
-static constexpr int32_t SECOND_SLOT = 1;
-static constexpr int32_t THIRD_SLOT = 2;
-static constexpr int32_t INVALID_TRACKING_ID = -1;
-static constexpr int32_t FIRST_TRACKING_ID = 0;
-static constexpr int32_t SECOND_TRACKING_ID = 1;
-static constexpr int32_t THIRD_TRACKING_ID = 2;
-static constexpr int32_t DEFAULT_BATTERY = 1;
-static constexpr int32_t BATTERY_STATUS = 4;
-static constexpr int32_t BATTERY_CAPACITY = 66;
-static constexpr int32_t LIGHT_BRIGHTNESS = 0x55000000;
-static constexpr int32_t LIGHT_COLOR = 0x7F448866;
-static constexpr int32_t LIGHT_PLAYER_ID = 2;
-
// Error tolerance for floating point assertions.
static const float EPSILON = 0.001f;
@@ -89,10 +66,6 @@ static inline float avg(float x, float y) {
return (x + y) / 2;
}
-// Mapping for light color name and the light color
-const std::unordered_map<std::string, LightColor> LIGHT_COLORS = {{"red", LightColor::RED},
- {"green", LightColor::GREEN},
- {"blue", LightColor::BLUE}};
// --- FakePointerController ---
@@ -103,14 +76,15 @@ class FakePointerController : public PointerControllerInterface {
int32_t mButtonState;
int32_t mDisplayId;
+protected:
+ virtual ~FakePointerController() { }
+
public:
FakePointerController() :
mHaveBounds(false), mMinX(0), mMinY(0), mMaxX(0), mMaxY(0), mX(0), mY(0),
mButtonState(0), mDisplayId(ADISPLAY_ID_DEFAULT) {
}
- virtual ~FakePointerController() {}
-
void setBounds(float minX, float minY, float maxX, float maxY) {
mHaveBounds = true;
mMinX = minX;
@@ -119,23 +93,29 @@ public:
mMaxY = maxY;
}
- void setPosition(float x, float y) override {
+ virtual void setPosition(float x, float y) {
mX = x;
mY = y;
}
- void setButtonState(int32_t buttonState) override { mButtonState = buttonState; }
+ virtual void setButtonState(int32_t buttonState) {
+ mButtonState = buttonState;
+ }
- int32_t getButtonState() const override { return mButtonState; }
+ virtual int32_t getButtonState() const {
+ return mButtonState;
+ }
- void getPosition(float* outX, float* outY) const override {
+ virtual void getPosition(float* outX, float* outY) const {
*outX = mX;
*outY = mY;
}
- int32_t getDisplayId() const override { return mDisplayId; }
+ virtual int32_t getDisplayId() const {
+ return mDisplayId;
+ }
- void setDisplayViewport(const DisplayViewport& viewport) override {
+ virtual void setDisplayViewport(const DisplayViewport& viewport) {
mDisplayId = viewport.displayId;
}
@@ -144,7 +124,7 @@ public:
}
private:
- bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const override {
+ virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const {
*outMinX = mMinX;
*outMinY = mMinY;
*outMaxX = mMaxX;
@@ -152,7 +132,7 @@ private:
return mHaveBounds;
}
- void move(float deltaX, float deltaY) override {
+ virtual void move(float deltaX, float deltaY) {
mX += deltaX;
if (mX < mMinX) mX = mMinX;
if (mX > mMaxX) mX = mMaxX;
@@ -161,14 +141,17 @@ private:
if (mY > mMaxY) mY = mMaxY;
}
- void fade(Transition) override {}
+ virtual void fade(Transition) {
+ }
- void unfade(Transition) override {}
+ virtual void unfade(Transition) {
+ }
- void setPresentation(Presentation) override {}
+ virtual void setPresentation(Presentation) {
+ }
- void setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits,
- int32_t displayId) override {
+ virtual void setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits,
+ int32_t displayId) {
std::vector<int32_t> newSpots;
// Add spots for fingers that are down.
for (BitSet32 idBits(spotIdBits); !idBits.isEmpty(); ) {
@@ -179,7 +162,8 @@ private:
mSpotsByDisplay[displayId] = newSpots;
}
- void clearSpots() override {}
+ virtual void clearSpots() {
+ }
std::map<int32_t, std::vector<int32_t>> mSpotsByDisplay;
};
@@ -192,14 +176,14 @@ class FakeInputReaderPolicy : public InputReaderPolicyInterface {
std::condition_variable mDevicesChangedCondition;
InputReaderConfiguration mConfig;
- std::unordered_map<int32_t, std::shared_ptr<FakePointerController>> mPointerControllers;
+ KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers;
std::vector<InputDeviceInfo> mInputDevices GUARDED_BY(mLock);
bool mInputDevicesChanged GUARDED_BY(mLock){false};
std::vector<DisplayViewport> mViewports;
TouchAffineTransformation transform;
protected:
- virtual ~FakeInputReaderPolicy() {}
+ virtual ~FakeInputReaderPolicy() { }
public:
FakeInputReaderPolicy() {
@@ -238,11 +222,10 @@ public:
}
void addDisplayViewport(int32_t displayId, int32_t width, int32_t height, int32_t orientation,
- bool isActive, const std::string& uniqueId,
- std::optional<uint8_t> physicalPort, ViewportType viewportType) {
- const DisplayViewport viewport =
- createDisplayViewport(displayId, width, height, orientation, isActive, uniqueId,
- physicalPort, viewportType);
+ const std::string& uniqueId, std::optional<uint8_t> physicalPort,
+ ViewportType viewportType) {
+ const DisplayViewport viewport = createDisplayViewport(displayId, width, height,
+ orientation, uniqueId, physicalPort, viewportType);
mViewports.push_back(viewport);
mConfig.setDisplayViewports(mViewports);
}
@@ -269,17 +252,12 @@ public:
mConfig.portAssociations.insert({inputPort, displayPort});
}
- void addInputUniqueIdAssociation(const std::string& inputUniqueId,
- const std::string& displayUniqueId) {
- mConfig.uniqueIdAssociations.insert({inputUniqueId, displayUniqueId});
- }
-
void addDisabledDevice(int32_t deviceId) { mConfig.disabledDevices.insert(deviceId); }
void removeDisabledDevice(int32_t deviceId) { mConfig.disabledDevices.erase(deviceId); }
- void setPointerController(int32_t deviceId, std::shared_ptr<FakePointerController> controller) {
- mPointerControllers.insert_or_assign(deviceId, std::move(controller));
+ void setPointerController(int32_t deviceId, const sp<FakePointerController>& controller) {
+ mPointerControllers.add(deviceId, controller);
}
const InputReaderConfiguration* getReaderConfiguration() const {
@@ -311,13 +289,10 @@ public:
mConfig.defaultPointerDisplayId = pointerDisplayId;
}
- float getPointerGestureMovementSpeedRatio() { return mConfig.pointerGestureMovementSpeedRatio; }
-
private:
DisplayViewport createDisplayViewport(int32_t displayId, int32_t width, int32_t height,
- int32_t orientation, bool isActive,
- const std::string& uniqueId,
- std::optional<uint8_t> physicalPort, ViewportType type) {
+ int32_t orientation, const std::string& uniqueId, std::optional<uint8_t> physicalPort,
+ ViewportType type) {
bool isRotated = (orientation == DISPLAY_ORIENTATION_90
|| orientation == DISPLAY_ORIENTATION_270);
DisplayViewport v;
@@ -333,34 +308,34 @@ private:
v.physicalBottom = isRotated ? width : height;
v.deviceWidth = isRotated ? height : width;
v.deviceHeight = isRotated ? width : height;
- v.isActive = isActive;
v.uniqueId = uniqueId;
v.physicalPort = physicalPort;
v.type = type;
return v;
}
- void getReaderConfiguration(InputReaderConfiguration* outConfig) override {
+ virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) {
*outConfig = mConfig;
}
- std::shared_ptr<PointerControllerInterface> obtainPointerController(int32_t deviceId) override {
- return mPointerControllers[deviceId];
+ virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) {
+ return mPointerControllers.valueFor(deviceId);
}
- void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override {
+ virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) {
std::scoped_lock<std::mutex> lock(mLock);
mInputDevices = inputDevices;
mInputDevicesChanged = true;
mDevicesChangedCondition.notify_all();
}
- std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
- const InputDeviceIdentifier&) override {
+ virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier&) {
return nullptr;
}
- std::string getDeviceAlias(const InputDeviceIdentifier&) override { return ""; }
+ virtual std::string getDeviceAlias(const InputDeviceIdentifier&) {
+ return "";
+ }
void waitForInputDevices(std::function<void(bool)> processDevicesChanged) {
std::unique_lock<std::mutex> lock(mLock);
@@ -383,14 +358,9 @@ class FakeEventHub : public EventHubInterface {
uint32_t flags;
};
- struct SensorInfo {
- InputDeviceSensorType sensorType;
- int32_t sensorDataIndex;
- };
-
struct Device {
InputDeviceIdentifier identifier;
- Flags<InputDeviceClass> classes;
+ uint32_t classes;
PropertyMap configuration;
KeyedVector<int, RawAbsoluteAxisInfo> absoluteAxes;
KeyedVector<int, bool> relativeAxes;
@@ -401,8 +371,6 @@ class FakeEventHub : public EventHubInterface {
KeyedVector<int32_t, KeyInfo> keysByScanCode;
KeyedVector<int32_t, KeyInfo> keysByUsageCode;
KeyedVector<int32_t, bool> leds;
- std::unordered_map<int32_t, SensorInfo> sensorsByAbsCode;
- BitArray<MSC_MAX> mscBitmask;
std::vector<VirtualKeyDefinition> virtualKeys;
bool enabled;
@@ -416,7 +384,9 @@ class FakeEventHub : public EventHubInterface {
return OK;
}
- explicit Device(Flags<InputDeviceClass> classes) : classes(classes), enabled(true) {}
+ explicit Device(uint32_t classes) :
+ classes(classes), enabled(true) {
+ }
};
std::mutex mLock;
@@ -424,15 +394,8 @@ class FakeEventHub : public EventHubInterface {
KeyedVector<int32_t, Device*> mDevices;
std::vector<std::string> mExcludedDevices;
- std::vector<RawEvent> mEvents GUARDED_BY(mLock);
+ List<RawEvent> mEvents GUARDED_BY(mLock);
std::unordered_map<int32_t /*deviceId*/, std::vector<TouchVideoFrame>> mVideoFrames;
- std::vector<int32_t> mVibrators = {0, 1};
- std::unordered_map<int32_t, RawLightInfo> mRawLightInfos;
- // Simulates a device light brightness, from light id to light brightness.
- std::unordered_map<int32_t /* lightId */, int32_t /* brightness*/> mLightBrightness;
- // Simulates a device light intensities, from light id to light intensities map.
- std::unordered_map<int32_t /* lightId */, std::unordered_map<LightColor, int32_t>>
- mLightIntensities;
public:
virtual ~FakeEventHub() {
@@ -443,19 +406,19 @@ public:
FakeEventHub() { }
- void addDevice(int32_t deviceId, const std::string& name, Flags<InputDeviceClass> classes) {
+ void addDevice(int32_t deviceId, const std::string& name, uint32_t classes) {
Device* device = new Device(classes);
device->identifier.name = name;
mDevices.add(deviceId, device);
- enqueueEvent(ARBITRARY_TIME, READ_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0);
+ enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0);
}
void removeDevice(int32_t deviceId) {
delete mDevices.valueFor(deviceId);
mDevices.removeItem(deviceId);
- enqueueEvent(ARBITRARY_TIME, READ_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0);
+ enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0);
}
bool isDeviceEnabled(int32_t deviceId) {
@@ -496,7 +459,7 @@ public:
}
void finishDeviceScan() {
- enqueueEvent(ARBITRARY_TIME, READ_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0);
+ enqueueEvent(ARBITRARY_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0);
}
void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) {
@@ -567,35 +530,6 @@ public:
device->leds.add(led, initialState);
}
- void addSensorAxis(int32_t deviceId, int32_t absCode, InputDeviceSensorType sensorType,
- int32_t sensorDataIndex) {
- Device* device = getDevice(deviceId);
- SensorInfo info;
- info.sensorType = sensorType;
- info.sensorDataIndex = sensorDataIndex;
- device->sensorsByAbsCode.emplace(absCode, info);
- }
-
- void setMscEvent(int32_t deviceId, int32_t mscEvent) {
- Device* device = getDevice(deviceId);
- typename BitArray<MSC_MAX>::Buffer buffer;
- buffer[mscEvent / 32] = 1 << mscEvent % 32;
- device->mscBitmask.loadFromBuffer(buffer);
- }
-
- void addRawLightInfo(int32_t rawId, RawLightInfo&& info) {
- mRawLightInfos.emplace(rawId, std::move(info));
- }
-
- void fakeLightBrightness(int32_t rawId, int32_t brightness) {
- mLightBrightness.emplace(rawId, brightness);
- }
-
- void fakeLightIntensities(int32_t rawId,
- const std::unordered_map<LightColor, int32_t> intensities) {
- mLightIntensities.emplace(rawId, std::move(intensities));
- }
-
bool getLedState(int32_t deviceId, int32_t led) {
Device* device = getDevice(deviceId);
return device->leds.valueFor(led);
@@ -610,12 +544,11 @@ public:
device->virtualKeys.push_back(definition);
}
- void enqueueEvent(nsecs_t when, nsecs_t readTime, int32_t deviceId, int32_t type, int32_t code,
- int32_t value) {
+ void enqueueEvent(nsecs_t when, int32_t deviceId, int32_t type,
+ int32_t code, int32_t value) {
std::scoped_lock<std::mutex> lock(mLock);
RawEvent event;
event.when = when;
- event.readTime = readTime;
event.deviceId = deviceId;
event.type = type;
event.code = code;
@@ -649,27 +582,29 @@ private:
return index >= 0 ? mDevices.valueAt(index) : nullptr;
}
- Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const override {
+ virtual uint32_t getDeviceClasses(int32_t deviceId) const {
Device* device = getDevice(deviceId);
- return device ? device->classes : Flags<InputDeviceClass>(0);
+ return device ? device->classes : 0;
}
- InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const override {
+ virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const {
Device* device = getDevice(deviceId);
return device ? device->identifier : InputDeviceIdentifier();
}
- int32_t getDeviceControllerNumber(int32_t) const override { return 0; }
+ virtual int32_t getDeviceControllerNumber(int32_t) const {
+ return 0;
+ }
- void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const override {
+ virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const {
Device* device = getDevice(deviceId);
if (device) {
*outConfiguration = device->configuration;
}
}
- status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
- RawAbsoluteAxisInfo* outAxisInfo) const override {
+ virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
+ RawAbsoluteAxisInfo* outAxisInfo) const {
Device* device = getDevice(deviceId);
if (device && device->enabled) {
ssize_t index = device->absoluteAxes.indexOfKey(axis);
@@ -682,7 +617,7 @@ private:
return -1;
}
- bool hasRelativeAxis(int32_t deviceId, int axis) const override {
+ virtual bool hasRelativeAxis(int32_t deviceId, int axis) const {
Device* device = getDevice(deviceId);
if (device) {
return device->relativeAxes.indexOfKey(axis) >= 0;
@@ -690,18 +625,13 @@ private:
return false;
}
- bool hasInputProperty(int32_t, int) const override { return false; }
-
- bool hasMscEvent(int32_t deviceId, int mscEvent) const override final {
- Device* device = getDevice(deviceId);
- if (device) {
- return mscEvent >= 0 && mscEvent <= MSC_MAX ? device->mscBitmask.test(mscEvent) : false;
- }
+ virtual bool hasInputProperty(int32_t, int) const {
return false;
}
- status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t metaState,
- int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const override {
+ virtual status_t mapKey(int32_t deviceId,
+ int32_t scanCode, int32_t usageCode, int32_t metaState,
+ int32_t* outKeycode, int32_t *outMetaState, uint32_t* outFlags) const {
Device* device = getDevice(deviceId);
if (device) {
const KeyInfo* key = getKey(device, scanCode, usageCode);
@@ -737,38 +667,27 @@ private:
return nullptr;
}
- status_t mapAxis(int32_t, int32_t, AxisInfo*) const override { return NAME_NOT_FOUND; }
-
- base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t deviceId,
- int32_t absCode) {
- Device* device = getDevice(deviceId);
- if (!device) {
- return Errorf("Sensor device not found.");
- }
- auto it = device->sensorsByAbsCode.find(absCode);
- if (it == device->sensorsByAbsCode.end()) {
- return Errorf("Sensor map not found.");
- }
- const SensorInfo& info = it->second;
- return std::make_pair(info.sensorType, info.sensorDataIndex);
+ virtual status_t mapAxis(int32_t, int32_t, AxisInfo*) const {
+ return NAME_NOT_FOUND;
}
- void setExcludedDevices(const std::vector<std::string>& devices) override {
+ virtual void setExcludedDevices(const std::vector<std::string>& devices) {
mExcludedDevices = devices;
}
- size_t getEvents(int, RawEvent* buffer, size_t bufferSize) override {
- std::scoped_lock lock(mLock);
-
- const size_t filledSize = std::min(mEvents.size(), bufferSize);
- std::copy(mEvents.begin(), mEvents.begin() + filledSize, buffer);
+ virtual size_t getEvents(int, RawEvent* buffer, size_t) {
+ std::scoped_lock<std::mutex> lock(mLock);
+ if (mEvents.empty()) {
+ return 0;
+ }
- mEvents.erase(mEvents.begin(), mEvents.begin() + filledSize);
+ *buffer = *mEvents.begin();
+ mEvents.erase(mEvents.begin());
mEventsCondition.notify_all();
- return filledSize;
+ return 1;
}
- std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) override {
+ virtual std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) {
auto it = mVideoFrames.find(deviceId);
if (it != mVideoFrames.end()) {
std::vector<TouchVideoFrame> frames = std::move(it->second);
@@ -778,7 +697,7 @@ private:
return {};
}
- int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override {
+ virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const {
Device* device = getDevice(deviceId);
if (device) {
ssize_t index = device->scanCodeStates.indexOfKey(scanCode);
@@ -789,7 +708,7 @@ private:
return AKEY_STATE_UNKNOWN;
}
- int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override {
+ virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
Device* device = getDevice(deviceId);
if (device) {
ssize_t index = device->keyCodeStates.indexOfKey(keyCode);
@@ -800,7 +719,7 @@ private:
return AKEY_STATE_UNKNOWN;
}
- int32_t getSwitchState(int32_t deviceId, int32_t sw) const override {
+ virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const {
Device* device = getDevice(deviceId);
if (device) {
ssize_t index = device->switchStates.indexOfKey(sw);
@@ -811,8 +730,8 @@ private:
return AKEY_STATE_UNKNOWN;
}
- status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
- int32_t* outValue) const override {
+ virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
+ int32_t* outValue) const {
Device* device = getDevice(deviceId);
if (device) {
ssize_t index = device->absoluteAxisValue.indexOfKey(axis);
@@ -825,22 +744,22 @@ private:
return -1;
}
- // Return true if the device has non-empty key layout.
- bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
- uint8_t* outFlags) const override {
+ virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
+ uint8_t* outFlags) const {
bool result = false;
Device* device = getDevice(deviceId);
if (device) {
- result = device->keysByScanCode.size() > 0 || device->keysByUsageCode.size() > 0;
for (size_t i = 0; i < numCodes; i++) {
for (size_t j = 0; j < device->keysByScanCode.size(); j++) {
if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) {
outFlags[i] = 1;
+ result = true;
}
}
for (size_t j = 0; j < device->keysByUsageCode.size(); j++) {
if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) {
outFlags[i] = 1;
+ result = true;
}
}
}
@@ -848,7 +767,7 @@ private:
return result;
}
- bool hasScanCode(int32_t deviceId, int32_t scanCode) const override {
+ virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const {
Device* device = getDevice(deviceId);
if (device) {
ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
@@ -857,12 +776,12 @@ private:
return false;
}
- bool hasLed(int32_t deviceId, int32_t led) const override {
+ virtual bool hasLed(int32_t deviceId, int32_t led) const {
Device* device = getDevice(deviceId);
return device && device->leds.indexOfKey(led) >= 0;
}
- void setLedState(int32_t deviceId, int32_t led, bool on) override {
+ virtual void setLedState(int32_t deviceId, int32_t led, bool on) {
Device* device = getDevice(deviceId);
if (device) {
ssize_t index = device->leds.indexOfKey(led);
@@ -876,8 +795,8 @@ private:
}
}
- void getVirtualKeyDefinitions(
- int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const override {
+ virtual void getVirtualKeyDefinitions(int32_t deviceId,
+ std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
outVirtualKeys.clear();
Device* device = getDevice(deviceId);
@@ -886,89 +805,146 @@ private:
}
}
- const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(int32_t) const override {
+ virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t) const {
return nullptr;
}
- bool setKeyboardLayoutOverlay(int32_t, std::shared_ptr<KeyCharacterMap>) override {
+ virtual bool setKeyboardLayoutOverlay(int32_t, const sp<KeyCharacterMap>&) {
return false;
}
- void vibrate(int32_t, const VibrationElement&) override {}
+ virtual void vibrate(int32_t, nsecs_t) {
+ }
- void cancelVibrate(int32_t) override {}
+ virtual void cancelVibrate(int32_t) {
+ }
- std::vector<int32_t> getVibratorIds(int32_t deviceId) override { return mVibrators; };
+ virtual bool isExternal(int32_t) const {
+ return false;
+ }
- std::optional<int32_t> getBatteryCapacity(int32_t, int32_t) const override {
- return BATTERY_CAPACITY;
+ virtual void dump(std::string&) {
}
- std::optional<int32_t> getBatteryStatus(int32_t, int32_t) const override {
- return BATTERY_STATUS;
+ virtual void monitor() {
}
- const std::vector<int32_t> getRawBatteryIds(int32_t deviceId) { return {}; }
+ virtual void requestReopenDevices() {
+ }
- std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId, int32_t batteryId) {
- return std::nullopt;
+ virtual void wake() {
}
+};
- const std::vector<int32_t> getRawLightIds(int32_t deviceId) override {
- std::vector<int32_t> ids;
- for (const auto& [rawId, info] : mRawLightInfos) {
- ids.push_back(rawId);
- }
- return ids;
+
+// --- FakeInputReaderContext ---
+
+class FakeInputReaderContext : public InputReaderContext {
+ std::shared_ptr<EventHubInterface> mEventHub;
+ sp<InputReaderPolicyInterface> mPolicy;
+ sp<InputListenerInterface> mListener;
+ int32_t mGlobalMetaState;
+ bool mUpdateGlobalMetaStateWasCalled;
+ int32_t mGeneration;
+ int32_t mNextId;
+ wp<PointerControllerInterface> mPointerController;
+
+public:
+ FakeInputReaderContext(std::shared_ptr<EventHubInterface> eventHub,
+ const sp<InputReaderPolicyInterface>& policy,
+ const sp<InputListenerInterface>& listener)
+ : mEventHub(eventHub),
+ mPolicy(policy),
+ mListener(listener),
+ mGlobalMetaState(0),
+ mNextId(1) {}
+
+ virtual ~FakeInputReaderContext() { }
+
+ void assertUpdateGlobalMetaStateWasCalled() {
+ ASSERT_TRUE(mUpdateGlobalMetaStateWasCalled)
+ << "Expected updateGlobalMetaState() to have been called.";
+ mUpdateGlobalMetaStateWasCalled = false;
}
- std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId, int32_t lightId) override {
- auto it = mRawLightInfos.find(lightId);
- if (it == mRawLightInfos.end()) {
- return std::nullopt;
+ void setGlobalMetaState(int32_t state) {
+ mGlobalMetaState = state;
+ }
+
+ uint32_t getGeneration() {
+ return mGeneration;
+ }
+
+ void updatePointerDisplay() {
+ sp<PointerControllerInterface> controller = mPointerController.promote();
+ if (controller != nullptr) {
+ InputReaderConfiguration config;
+ mPolicy->getReaderConfiguration(&config);
+ auto viewport = config.getDisplayViewportById(config.defaultPointerDisplayId);
+ if (viewport) {
+ controller->setDisplayViewport(*viewport);
+ }
}
- return it->second;
}
- void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) override {
- mLightBrightness.emplace(lightId, brightness);
+private:
+ virtual void updateGlobalMetaState() {
+ mUpdateGlobalMetaStateWasCalled = true;
}
- void setLightIntensities(int32_t deviceId, int32_t lightId,
- std::unordered_map<LightColor, int32_t> intensities) override {
- mLightIntensities.emplace(lightId, intensities);
- };
+ virtual int32_t getGlobalMetaState() {
+ return mGlobalMetaState;
+ }
- std::optional<int32_t> getLightBrightness(int32_t deviceId, int32_t lightId) override {
- auto lightIt = mLightBrightness.find(lightId);
- if (lightIt == mLightBrightness.end()) {
- return std::nullopt;
- }
- return lightIt->second;
+ virtual EventHubInterface* getEventHub() {
+ return mEventHub.get();
+ }
+
+ virtual InputReaderPolicyInterface* getPolicy() {
+ return mPolicy.get();
+ }
+
+ virtual InputListenerInterface* getListener() {
+ return mListener.get();
+ }
+
+ virtual void disableVirtualKeysUntil(nsecs_t) {
}
- std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
- int32_t deviceId, int32_t lightId) override {
- auto lightIt = mLightIntensities.find(lightId);
- if (lightIt == mLightIntensities.end()) {
- return std::nullopt;
+ virtual bool shouldDropVirtualKey(nsecs_t, int32_t, int32_t) { return false; }
+
+ virtual sp<PointerControllerInterface> getPointerController(int32_t deviceId) {
+ sp<PointerControllerInterface> controller = mPointerController.promote();
+ if (controller == nullptr) {
+ controller = mPolicy->obtainPointerController(deviceId);
+ mPointerController = controller;
+ updatePointerDisplay();
}
- return lightIt->second;
- };
+ return controller;
+ }
- virtual bool isExternal(int32_t) const {
- return false;
+ virtual void fadePointer() {
}
- void dump(std::string&) override {}
+ virtual void requestTimeoutAtTime(nsecs_t) {
+ }
- void monitor() override {}
+ virtual int32_t bumpGeneration() {
+ return ++mGeneration;
+ }
+
+ virtual void getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) {
+
+ }
- void requestReopenDevices() override {}
+ virtual void dispatchExternalStylusState(const StylusState&) {
- void wake() override {}
+ }
+
+ virtual int32_t getNextId() { return mNextId++; }
};
+
// --- FakeInputMapper ---
class FakeInputMapper : public InputMapper {
@@ -998,7 +974,7 @@ public:
mResetWasCalled(false),
mProcessWasCalled(false) {}
- virtual ~FakeInputMapper() {}
+ virtual ~FakeInputMapper() { }
void setKeyboardType(int32_t keyboardType) {
mKeyboardType = keyboardType;
@@ -1067,9 +1043,11 @@ public:
}
private:
- uint32_t getSources() override { return mSources; }
+ virtual uint32_t getSources() {
+ return mSources;
+ }
- void populateDeviceInfo(InputDeviceInfo* deviceInfo) override {
+ virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) {
InputMapper::populateDeviceInfo(deviceInfo);
if (mKeyboardType != AINPUT_KEYBOARD_TYPE_NONE) {
@@ -1077,7 +1055,7 @@ private:
}
}
- void configure(nsecs_t, const InputReaderConfiguration* config, uint32_t changes) override {
+ virtual void configure(nsecs_t, const InputReaderConfiguration* config, uint32_t changes) {
std::scoped_lock<std::mutex> lock(mLock);
mConfigureWasCalled = true;
@@ -1090,45 +1068,45 @@ private:
mStateChangedCondition.notify_all();
}
- void reset(nsecs_t) override {
+ virtual void reset(nsecs_t) {
std::scoped_lock<std::mutex> lock(mLock);
mResetWasCalled = true;
mStateChangedCondition.notify_all();
}
- void process(const RawEvent* rawEvent) override {
+ virtual void process(const RawEvent* rawEvent) {
std::scoped_lock<std::mutex> lock(mLock);
mLastEvent = *rawEvent;
mProcessWasCalled = true;
mStateChangedCondition.notify_all();
}
- int32_t getKeyCodeState(uint32_t, int32_t keyCode) override {
+ virtual int32_t getKeyCodeState(uint32_t, int32_t keyCode) {
ssize_t index = mKeyCodeStates.indexOfKey(keyCode);
return index >= 0 ? mKeyCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN;
}
- int32_t getScanCodeState(uint32_t, int32_t scanCode) override {
+ virtual int32_t getScanCodeState(uint32_t, int32_t scanCode) {
ssize_t index = mScanCodeStates.indexOfKey(scanCode);
return index >= 0 ? mScanCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN;
}
- int32_t getSwitchState(uint32_t, int32_t switchCode) override {
+ virtual int32_t getSwitchState(uint32_t, int32_t switchCode) {
ssize_t index = mSwitchStates.indexOfKey(switchCode);
return index >= 0 ? mSwitchStates.valueAt(index) : AKEY_STATE_UNKNOWN;
}
- // Return true if the device has non-empty key layout.
- bool markSupportedKeyCodes(uint32_t, size_t numCodes, const int32_t* keyCodes,
- uint8_t* outFlags) override {
+ virtual bool markSupportedKeyCodes(uint32_t, size_t numCodes,
+ const int32_t* keyCodes, uint8_t* outFlags) {
+ bool result = false;
for (size_t i = 0; i < numCodes; i++) {
for (size_t j = 0; j < mSupportedKeyCodes.size(); j++) {
if (keyCodes[i] == mSupportedKeyCodes[j]) {
outFlags[i] = 1;
+ result = true;
}
}
}
- bool result = mSupportedKeyCodes.size() > 0;
return result;
}
@@ -1151,17 +1129,17 @@ private:
// --- InstrumentedInputReader ---
class InstrumentedInputReader : public InputReader {
- std::queue<std::shared_ptr<InputDevice>> mNextDevices;
+ std::shared_ptr<InputDevice> mNextDevice;
public:
InstrumentedInputReader(std::shared_ptr<EventHubInterface> eventHub,
const sp<InputReaderPolicyInterface>& policy,
const sp<InputListenerInterface>& listener)
- : InputReader(eventHub, policy, listener), mFakeContext(this) {}
+ : InputReader(eventHub, policy, listener), mNextDevice(nullptr) {}
virtual ~InstrumentedInputReader() {}
- void pushNextDevice(std::shared_ptr<InputDevice> device) { mNextDevices.push(device); }
+ void setNextDevice(std::shared_ptr<InputDevice> device) { mNextDevice = device; }
std::shared_ptr<InputDevice> newDevice(int32_t deviceId, const std::string& name,
const std::string& location = "") {
@@ -1169,68 +1147,24 @@ public:
identifier.name = name;
identifier.location = location;
int32_t generation = deviceId + 1;
- return std::make_shared<InputDevice>(&mFakeContext, deviceId, generation, identifier);
+ return std::make_shared<InputDevice>(&mContext, deviceId, generation, identifier);
}
// Make the protected loopOnce method accessible to tests.
using InputReader::loopOnce;
protected:
- virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t eventHubId,
- const InputDeviceIdentifier& identifier)
- REQUIRES(mLock) {
- if (!mNextDevices.empty()) {
- std::shared_ptr<InputDevice> device(std::move(mNextDevices.front()));
- mNextDevices.pop();
+ virtual std::shared_ptr<InputDevice> createDeviceLocked(
+ int32_t eventHubId, const InputDeviceIdentifier& identifier) {
+ if (mNextDevice) {
+ std::shared_ptr<InputDevice> device(mNextDevice);
+ mNextDevice = nullptr;
return device;
}
return InputReader::createDeviceLocked(eventHubId, identifier);
}
- // --- FakeInputReaderContext ---
- class FakeInputReaderContext : public ContextImpl {
- int32_t mGlobalMetaState;
- bool mUpdateGlobalMetaStateWasCalled;
- int32_t mGeneration;
-
- public:
- FakeInputReaderContext(InputReader* reader)
- : ContextImpl(reader),
- mGlobalMetaState(0),
- mUpdateGlobalMetaStateWasCalled(false),
- mGeneration(1) {}
-
- virtual ~FakeInputReaderContext() {}
-
- void assertUpdateGlobalMetaStateWasCalled() {
- ASSERT_TRUE(mUpdateGlobalMetaStateWasCalled)
- << "Expected updateGlobalMetaState() to have been called.";
- mUpdateGlobalMetaStateWasCalled = false;
- }
-
- void setGlobalMetaState(int32_t state) { mGlobalMetaState = state; }
-
- uint32_t getGeneration() { return mGeneration; }
-
- void updateGlobalMetaState() override {
- mUpdateGlobalMetaStateWasCalled = true;
- ContextImpl::updateGlobalMetaState();
- }
-
- int32_t getGlobalMetaState() override {
- return mGlobalMetaState | ContextImpl::getGlobalMetaState();
- }
-
- int32_t bumpGeneration() override {
- mGeneration = ContextImpl::bumpGeneration();
- return mGeneration;
- }
- } mFakeContext;
-
friend class InputReaderTest;
-
-public:
- FakeInputReaderContext* getContext() { return &mFakeContext; }
};
// --- InputReaderPolicyTest ---
@@ -1238,8 +1172,8 @@ class InputReaderPolicyTest : public testing::Test {
protected:
sp<FakeInputReaderPolicy> mFakePolicy;
- void SetUp() override { mFakePolicy = new FakeInputReaderPolicy(); }
- void TearDown() override { mFakePolicy.clear(); }
+ virtual void SetUp() override { mFakePolicy = new FakeInputReaderPolicy(); }
+ virtual void TearDown() override { mFakePolicy.clear(); }
};
/**
@@ -1254,21 +1188,20 @@ TEST_F(InputReaderPolicyTest, Viewports_GetCleared) {
// We didn't add any viewports yet, so there shouldn't be any.
std::optional<DisplayViewport> internalViewport =
- mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL);
+ mFakePolicy->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
ASSERT_FALSE(internalViewport);
// Add an internal viewport, then clear it
mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId, NO_PORT,
- ViewportType::INTERNAL);
+ DISPLAY_ORIENTATION_0, uniqueId, NO_PORT, ViewportType::VIEWPORT_INTERNAL);
// Check matching by uniqueId
internalViewport = mFakePolicy->getDisplayViewportByUniqueId(uniqueId);
ASSERT_TRUE(internalViewport);
- ASSERT_EQ(ViewportType::INTERNAL, internalViewport->type);
+ ASSERT_EQ(ViewportType::VIEWPORT_INTERNAL, internalViewport->type);
// Check matching by viewport type
- internalViewport = mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL);
+ internalViewport = mFakePolicy->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
ASSERT_TRUE(internalViewport);
ASSERT_EQ(uniqueId, internalViewport->uniqueId);
@@ -1276,7 +1209,7 @@ TEST_F(InputReaderPolicyTest, Viewports_GetCleared) {
// Make sure nothing is found after clear
internalViewport = mFakePolicy->getDisplayViewportByUniqueId(uniqueId);
ASSERT_FALSE(internalViewport);
- internalViewport = mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL);
+ internalViewport = mFakePolicy->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
ASSERT_FALSE(internalViewport);
}
@@ -1290,30 +1223,26 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByType) {
// Add an internal viewport
mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, internalUniqueId,
- NO_PORT, ViewportType::INTERNAL);
+ DISPLAY_ORIENTATION_0, internalUniqueId, NO_PORT, ViewportType::VIEWPORT_INTERNAL);
// Add an external viewport
mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, externalUniqueId,
- NO_PORT, ViewportType::EXTERNAL);
+ DISPLAY_ORIENTATION_0, externalUniqueId, NO_PORT, ViewportType::VIEWPORT_EXTERNAL);
// Add an virtual viewport
mFakePolicy->addDisplayViewport(virtualDisplayId1, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, virtualUniqueId1,
- NO_PORT, ViewportType::VIRTUAL);
+ DISPLAY_ORIENTATION_0, virtualUniqueId1, NO_PORT, ViewportType::VIEWPORT_VIRTUAL);
// Add another virtual viewport
mFakePolicy->addDisplayViewport(virtualDisplayId2, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, virtualUniqueId2,
- NO_PORT, ViewportType::VIRTUAL);
+ DISPLAY_ORIENTATION_0, virtualUniqueId2, NO_PORT, ViewportType::VIEWPORT_VIRTUAL);
// Check matching by type for internal
std::optional<DisplayViewport> internalViewport =
- mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL);
+ mFakePolicy->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
ASSERT_TRUE(internalViewport);
ASSERT_EQ(internalUniqueId, internalViewport->uniqueId);
// Check matching by type for external
std::optional<DisplayViewport> externalViewport =
- mFakePolicy->getDisplayViewportByType(ViewportType::EXTERNAL);
+ mFakePolicy->getDisplayViewportByType(ViewportType::VIEWPORT_EXTERNAL);
ASSERT_TRUE(externalViewport);
ASSERT_EQ(externalUniqueId, externalViewport->uniqueId);
@@ -1321,7 +1250,7 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByType) {
std::optional<DisplayViewport> virtualViewport1 =
mFakePolicy->getDisplayViewportByUniqueId(virtualUniqueId1);
ASSERT_TRUE(virtualViewport1);
- ASSERT_EQ(ViewportType::VIRTUAL, virtualViewport1->type);
+ ASSERT_EQ(ViewportType::VIEWPORT_VIRTUAL, virtualViewport1->type);
ASSERT_EQ(virtualUniqueId1, virtualViewport1->uniqueId);
ASSERT_EQ(virtualDisplayId1, virtualViewport1->displayId);
@@ -1329,7 +1258,7 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByType) {
std::optional<DisplayViewport> virtualViewport2 =
mFakePolicy->getDisplayViewportByUniqueId(virtualUniqueId2);
ASSERT_TRUE(virtualViewport2);
- ASSERT_EQ(ViewportType::VIRTUAL, virtualViewport2->type);
+ ASSERT_EQ(ViewportType::VIEWPORT_VIRTUAL, virtualViewport2->type);
ASSERT_EQ(virtualUniqueId2, virtualViewport2->uniqueId);
ASSERT_EQ(virtualDisplayId2, virtualViewport2->displayId);
}
@@ -1346,18 +1275,16 @@ TEST_F(InputReaderPolicyTest, Viewports_TwoOfSameType) {
constexpr int32_t displayId1 = 2;
constexpr int32_t displayId2 = 3;
- std::vector<ViewportType> types = {ViewportType::INTERNAL, ViewportType::EXTERNAL,
- ViewportType::VIRTUAL};
+ std::vector<ViewportType> types = {ViewportType::VIEWPORT_INTERNAL,
+ ViewportType::VIEWPORT_EXTERNAL, ViewportType::VIEWPORT_VIRTUAL};
for (const ViewportType& type : types) {
mFakePolicy->clearViewports();
// Add a viewport
mFakePolicy->addDisplayViewport(displayId1, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId1,
- NO_PORT, type);
+ DISPLAY_ORIENTATION_0, uniqueId1, NO_PORT, type);
// Add another viewport
mFakePolicy->addDisplayViewport(displayId2, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId2,
- NO_PORT, type);
+ DISPLAY_ORIENTATION_0, uniqueId2, NO_PORT, type);
// Check that correct display viewport was returned by comparing the display IDs.
std::optional<DisplayViewport> viewport1 =
@@ -1384,51 +1311,10 @@ TEST_F(InputReaderPolicyTest, Viewports_TwoOfSameType) {
}
/**
- * When we have multiple internal displays make sure we always return the default display when
- * querying by type.
- */
-TEST_F(InputReaderPolicyTest, Viewports_ByTypeReturnsDefaultForInternal) {
- const std::string uniqueId1 = "uniqueId1";
- const std::string uniqueId2 = "uniqueId2";
- constexpr int32_t nonDefaultDisplayId = 2;
- static_assert(nonDefaultDisplayId != ADISPLAY_ID_DEFAULT,
- "Test display ID should not be ADISPLAY_ID_DEFAULT");
-
- // Add the default display first and ensure it gets returned.
- mFakePolicy->clearViewports();
- mFakePolicy->addDisplayViewport(ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId1, NO_PORT,
- ViewportType::INTERNAL);
- mFakePolicy->addDisplayViewport(nonDefaultDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId2, NO_PORT,
- ViewportType::INTERNAL);
-
- std::optional<DisplayViewport> viewport =
- mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL);
- ASSERT_TRUE(viewport);
- ASSERT_EQ(ADISPLAY_ID_DEFAULT, viewport->displayId);
- ASSERT_EQ(ViewportType::INTERNAL, viewport->type);
-
- // Add the default display second to make sure order doesn't matter.
- mFakePolicy->clearViewports();
- mFakePolicy->addDisplayViewport(nonDefaultDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId2, NO_PORT,
- ViewportType::INTERNAL);
- mFakePolicy->addDisplayViewport(ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId1, NO_PORT,
- ViewportType::INTERNAL);
-
- viewport = mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL);
- ASSERT_TRUE(viewport);
- ASSERT_EQ(ADISPLAY_ID_DEFAULT, viewport->displayId);
- ASSERT_EQ(ViewportType::INTERNAL, viewport->type);
-}
-
-/**
* Check getDisplayViewportByPort
*/
TEST_F(InputReaderPolicyTest, Viewports_GetByPort) {
- constexpr ViewportType type = ViewportType::EXTERNAL;
+ constexpr ViewportType type = ViewportType::VIEWPORT_EXTERNAL;
const std::string uniqueId1 = "uniqueId1";
const std::string uniqueId2 = "uniqueId2";
constexpr int32_t displayId1 = 1;
@@ -1440,12 +1326,10 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByPort) {
mFakePolicy->clearViewports();
// Add a viewport that's associated with some display port that's not of interest.
mFakePolicy->addDisplayViewport(displayId1, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId1, hdmi3,
- type);
+ DISPLAY_ORIENTATION_0, uniqueId1, hdmi3, type);
// Add another viewport, connected to HDMI1 port
mFakePolicy->addDisplayViewport(displayId2, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId2, hdmi1,
- type);
+ DISPLAY_ORIENTATION_0, uniqueId2, hdmi1, type);
// Check that correct display viewport was returned by comparing the display ports.
std::optional<DisplayViewport> hdmi1Viewport = mFakePolicy->getDisplayViewportByPort(hdmi1);
@@ -1474,7 +1358,7 @@ protected:
std::shared_ptr<FakeEventHub> mFakeEventHub;
std::unique_ptr<InstrumentedInputReader> mReader;
- void SetUp() override {
+ virtual void SetUp() override {
mFakeEventHub = std::make_unique<FakeEventHub>();
mFakePolicy = new FakeInputReaderPolicy();
mFakeListener = new TestInputListener();
@@ -1483,12 +1367,12 @@ protected:
mFakeListener);
}
- void TearDown() override {
+ virtual void TearDown() override {
mFakeListener.clear();
mFakePolicy.clear();
}
- void addDevice(int32_t eventHubId, const std::string& name, Flags<InputDeviceClass> classes,
+ void addDevice(int32_t eventHubId, const std::string& name, uint32_t classes,
const PropertyMap* configuration) {
mFakeEventHub->addDevice(eventHubId, name, classes);
@@ -1513,87 +1397,50 @@ protected:
}
FakeInputMapper& addDeviceWithFakeInputMapper(int32_t deviceId, int32_t eventHubId,
- const std::string& name,
- Flags<InputDeviceClass> classes, uint32_t sources,
+ const std::string& name, uint32_t classes,
+ uint32_t sources,
const PropertyMap* configuration) {
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, name);
FakeInputMapper& mapper = device->addMapper<FakeInputMapper>(eventHubId, sources);
- mReader->pushNextDevice(device);
+ mReader->setNextDevice(device);
addDevice(eventHubId, name, classes, configuration);
return mapper;
}
};
-TEST_F(InputReaderTest, PolicyGetInputDevices) {
- ASSERT_NO_FATAL_FAILURE(addDevice(1, "keyboard", InputDeviceClass::KEYBOARD, nullptr));
- ASSERT_NO_FATAL_FAILURE(addDevice(2, "ignored", Flags<InputDeviceClass>(0),
- nullptr)); // no classes so device will be ignored
+TEST_F(InputReaderTest, GetInputDevices) {
+ ASSERT_NO_FATAL_FAILURE(addDevice(1, "keyboard",
+ INPUT_DEVICE_CLASS_KEYBOARD, nullptr));
+ ASSERT_NO_FATAL_FAILURE(addDevice(2, "ignored",
+ 0, nullptr)); // no classes so device will be ignored
- // Should also have received a notification describing the new input devices.
- const std::vector<InputDeviceInfo>& inputDevices = mFakePolicy->getInputDevices();
+ std::vector<InputDeviceInfo> inputDevices;
+ mReader->getInputDevices(inputDevices);
ASSERT_EQ(1U, inputDevices.size());
ASSERT_EQ(END_RESERVED_ID + 1, inputDevices[0].getId());
ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str());
ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType());
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources());
- ASSERT_EQ(0U, inputDevices[0].getMotionRanges().size());
-}
-
-TEST_F(InputReaderTest, GetMergedInputDevices) {
- constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr int32_t eventHubIds[2] = {END_RESERVED_ID, END_RESERVED_ID + 1};
- // 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);
-
- // Push same device instance for next device to be added, so they'll have same identifier.
- mReader->pushNextDevice(device);
- mReader->pushNextDevice(device);
- ASSERT_NO_FATAL_FAILURE(
- addDevice(eventHubIds[0], "fake1", InputDeviceClass::KEYBOARD, nullptr));
- ASSERT_NO_FATAL_FAILURE(
- addDevice(eventHubIds[1], "fake2", InputDeviceClass::KEYBOARD, nullptr));
-
- // Two devices will be merged to one input device as they have same identifier
- ASSERT_EQ(1U, mFakePolicy->getInputDevices().size());
-}
+ ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size());
-TEST_F(InputReaderTest, GetMergedInputDevicesEnabled) {
- constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr int32_t eventHubIds[2] = {END_RESERVED_ID, END_RESERVED_ID + 1};
- // 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);
-
- // Push same device instance for next device to be added, so they'll have same identifier.
- mReader->pushNextDevice(device);
- mReader->pushNextDevice(device);
- // Sensor device is initially disabled
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubIds[0], "fake1",
- InputDeviceClass::KEYBOARD | InputDeviceClass::SENSOR,
- nullptr));
- // Device is disabled because the only sub device is a sensor device and disabled initially.
- ASSERT_FALSE(mFakeEventHub->isDeviceEnabled(eventHubIds[0]));
- ASSERT_FALSE(device->isEnabled());
- ASSERT_NO_FATAL_FAILURE(
- addDevice(eventHubIds[1], "fake2", InputDeviceClass::KEYBOARD, nullptr));
- // The merged device is enabled if any sub device is enabled
- ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(eventHubIds[1]));
- ASSERT_TRUE(device->isEnabled());
+ // Should also have received a notification describing the new input devices.
+ inputDevices = mFakePolicy->getInputDevices();
+ ASSERT_EQ(1U, inputDevices.size());
+ ASSERT_EQ(END_RESERVED_ID + 1, inputDevices[0].getId());
+ ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str());
+ ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType());
+ ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources());
+ ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size());
}
TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) {
constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass(InputDeviceClass::KEYBOARD);
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
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);
- mReader->pushNextDevice(device);
+ mReader->setNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyConfigurationChangedWasCalled(nullptr));
@@ -1625,7 +1472,7 @@ TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) {
TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) {
constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
constexpr int32_t eventHubId = 1;
FakeInputMapper& mapper =
addDeviceWithFakeInputMapper(deviceId, eventHubId, "fake", deviceClass,
@@ -1658,7 +1505,7 @@ TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) {
TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) {
constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
constexpr int32_t eventHubId = 1;
FakeInputMapper& mapper =
addDeviceWithFakeInputMapper(deviceId, eventHubId, "fake", deviceClass,
@@ -1691,7 +1538,7 @@ TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) {
TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) {
constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
constexpr int32_t eventHubId = 1;
FakeInputMapper& mapper =
addDeviceWithFakeInputMapper(deviceId, eventHubId, "fake", deviceClass,
@@ -1724,7 +1571,7 @@ TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) {
TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) {
constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
constexpr int32_t eventHubId = 1;
FakeInputMapper& mapper =
addDeviceWithFakeInputMapper(deviceId, eventHubId, "fake", deviceClass,
@@ -1766,7 +1613,7 @@ TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) {
TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChanged) {
constexpr int32_t eventHubId = 1;
- addDevice(eventHubId, "ignored", InputDeviceClass::KEYBOARD, nullptr);
+ addDevice(eventHubId, "ignored", INPUT_DEVICE_CLASS_KEYBOARD, nullptr);
NotifyConfigurationChangedArgs args;
@@ -1776,22 +1623,19 @@ TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChange
TEST_F(InputReaderTest, LoopOnce_ForwardsRawEventsToMappers) {
constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
- constexpr nsecs_t when = 0;
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
constexpr int32_t eventHubId = 1;
- constexpr nsecs_t readTime = 2;
FakeInputMapper& mapper =
addDeviceWithFakeInputMapper(deviceId, eventHubId, "fake", deviceClass,
AINPUT_SOURCE_KEYBOARD, nullptr);
- mFakeEventHub->enqueueEvent(when, readTime, eventHubId, EV_KEY, KEY_A, 1);
+ mFakeEventHub->enqueueEvent(0, eventHubId, EV_KEY, KEY_A, 1);
mReader->loopOnce();
ASSERT_NO_FATAL_FAILURE(mFakeEventHub->assertQueueIsEmpty());
RawEvent event;
ASSERT_NO_FATAL_FAILURE(mapper.assertProcessWasCalled(&event));
- ASSERT_EQ(when, event.when);
- ASSERT_EQ(readTime, event.readTime);
+ ASSERT_EQ(0, event.when);
ASSERT_EQ(eventHubId, event.deviceId);
ASSERT_EQ(EV_KEY, event.type);
ASSERT_EQ(KEY_A, event.code);
@@ -1800,12 +1644,12 @@ TEST_F(InputReaderTest, LoopOnce_ForwardsRawEventsToMappers) {
TEST_F(InputReaderTest, DeviceReset_RandomId) {
constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
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);
- mReader->pushNextDevice(device);
+ mReader->setNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
NotifyDeviceResetArgs resetArgs;
@@ -1833,12 +1677,12 @@ TEST_F(InputReaderTest, DeviceReset_RandomId) {
TEST_F(InputReaderTest, DeviceReset_GenerateIdWithInputReaderSource) {
constexpr int32_t deviceId = 1;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
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);
- mReader->pushNextDevice(device);
+ mReader->setNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(deviceId, "fake", deviceClass, nullptr));
NotifyDeviceResetArgs resetArgs;
@@ -1848,13 +1692,13 @@ TEST_F(InputReaderTest, DeviceReset_GenerateIdWithInputReaderSource) {
TEST_F(InputReaderTest, Device_CanDispatchToDisplay) {
constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
+ constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD;
constexpr int32_t eventHubId = 1;
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);
- mReader->pushNextDevice(device);
+ mReader->setNextDevice(device);
const uint8_t hdmi1 = 1;
@@ -1864,11 +1708,9 @@ TEST_F(InputReaderTest, Device_CanDispatchToDisplay) {
// Add default and second display.
mFakePolicy->clearViewports();
mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, "local:0", NO_PORT,
- ViewportType::INTERNAL);
+ DISPLAY_ORIENTATION_0, "local:0", NO_PORT, ViewportType::VIEWPORT_INTERNAL);
mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, "local:1", hdmi1,
- ViewportType::EXTERNAL);
+ DISPLAY_ORIENTATION_0, "local:1", hdmi1, ViewportType::VIEWPORT_EXTERNAL);
mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
mReader->loopOnce();
@@ -1891,221 +1733,6 @@ TEST_F(InputReaderTest, Device_CanDispatchToDisplay) {
ASSERT_FALSE(mReader->canDispatchToDisplay(deviceId, SECONDARY_DISPLAY_ID));
}
-TEST_F(InputReaderTest, WhenEnabledChanges_AllSubdevicesAreUpdated) {
- constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
- 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);
- mReader->pushNextDevice(device);
- mReader->pushNextDevice(device);
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubIds[0], "fake1", deviceClass, nullptr));
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubIds[1], "fake2", deviceClass, nullptr));
-
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyConfigurationChangedWasCalled(nullptr));
-
- NotifyDeviceResetArgs resetArgs;
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
- ASSERT_EQ(deviceId, resetArgs.deviceId);
- ASSERT_TRUE(device->isEnabled());
- ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(eventHubIds[0]));
- ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(eventHubIds[1]));
-
- disableDevice(deviceId);
- mReader->loopOnce();
-
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
- ASSERT_EQ(deviceId, resetArgs.deviceId);
- ASSERT_FALSE(device->isEnabled());
- ASSERT_FALSE(mFakeEventHub->isDeviceEnabled(eventHubIds[0]));
- ASSERT_FALSE(mFakeEventHub->isDeviceEnabled(eventHubIds[1]));
-
- enableDevice(deviceId);
- mReader->loopOnce();
-
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
- ASSERT_EQ(deviceId, resetArgs.deviceId);
- ASSERT_TRUE(device->isEnabled());
- ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(eventHubIds[0]));
- ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(eventHubIds[1]));
-}
-
-TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToSubdeviceMappers) {
- constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- constexpr Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD;
- constexpr int32_t eventHubIds[2] = {END_RESERVED_ID, END_RESERVED_ID + 1};
- // Add two subdevices to device
- std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake");
- FakeInputMapper& mapperDevice1 =
- device->addMapper<FakeInputMapper>(eventHubIds[0], AINPUT_SOURCE_KEYBOARD);
- FakeInputMapper& mapperDevice2 =
- device->addMapper<FakeInputMapper>(eventHubIds[1], AINPUT_SOURCE_KEYBOARD);
- mReader->pushNextDevice(device);
- mReader->pushNextDevice(device);
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubIds[0], "fake1", deviceClass, nullptr));
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubIds[1], "fake2", deviceClass, nullptr));
-
- mapperDevice1.setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN);
- mapperDevice2.setKeyCodeState(AKEYCODE_B, AKEY_STATE_DOWN);
-
- ASSERT_EQ(AKEY_STATE_DOWN,
- mReader->getKeyCodeState(deviceId, AINPUT_SOURCE_KEYBOARD, AKEYCODE_A));
- ASSERT_EQ(AKEY_STATE_DOWN,
- mReader->getKeyCodeState(deviceId, AINPUT_SOURCE_KEYBOARD, AKEYCODE_B));
- ASSERT_EQ(AKEY_STATE_UNKNOWN,
- mReader->getKeyCodeState(deviceId, AINPUT_SOURCE_KEYBOARD, AKEYCODE_C));
-}
-
-TEST_F(InputReaderTest, ChangingPointerCaptureNotifiesInputListener) {
- NotifyPointerCaptureChangedArgs args;
-
- mFakePolicy->setPointerCapture(true);
- mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
- mReader->loopOnce();
- mFakeListener->assertNotifyCaptureWasCalled(&args);
- ASSERT_TRUE(args.enabled) << "Pointer Capture should be enabled.";
-
- mFakePolicy->setPointerCapture(false);
- mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
- mReader->loopOnce();
- mFakeListener->assertNotifyCaptureWasCalled(&args);
- ASSERT_FALSE(args.enabled) << "Pointer Capture should be disabled.";
-
- // Verify that the Pointer Capture state is re-configured correctly when the configuration value
- // does not change.
- mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
- mReader->loopOnce();
- mFakeListener->assertNotifyCaptureWasCalled(&args);
- ASSERT_FALSE(args.enabled) << "Pointer Capture should be disabled.";
-}
-
-class FakeVibratorInputMapper : public FakeInputMapper {
-public:
- FakeVibratorInputMapper(InputDeviceContext& deviceContext, uint32_t sources)
- : FakeInputMapper(deviceContext, sources) {}
-
- std::vector<int32_t> getVibratorIds() override { return getDeviceContext().getVibratorIds(); }
-};
-
-TEST_F(InputReaderTest, VibratorGetVibratorIds) {
- constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD | InputDeviceClass::VIBRATOR;
- constexpr int32_t eventHubId = 1;
- 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);
- mReader->pushNextDevice(device);
-
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
- ASSERT_NO_FATAL_FAILURE(mapper.assertConfigureWasCalled());
-
- ASSERT_EQ(mapper.getVibratorIds().size(), 2U);
- ASSERT_EQ(mReader->getVibratorIds(deviceId).size(), 2U);
-}
-
-// --- FakePeripheralController ---
-
-class FakePeripheralController : public PeripheralControllerInterface {
-public:
- FakePeripheralController(InputDeviceContext& deviceContext) : mDeviceContext(deviceContext) {}
-
- ~FakePeripheralController() override {}
-
- void populateDeviceInfo(InputDeviceInfo* deviceInfo) override {}
-
- void dump(std::string& dump) override {}
-
- std::optional<int32_t> getBatteryCapacity(int32_t batteryId) override {
- return getDeviceContext().getBatteryCapacity(batteryId);
- }
-
- std::optional<int32_t> getBatteryStatus(int32_t batteryId) override {
- return getDeviceContext().getBatteryStatus(batteryId);
- }
-
- bool setLightColor(int32_t lightId, int32_t color) override {
- getDeviceContext().setLightBrightness(lightId, color >> 24);
- return true;
- }
-
- std::optional<int32_t> getLightColor(int32_t lightId) override {
- std::optional<int32_t> result = getDeviceContext().getLightBrightness(lightId);
- if (!result.has_value()) {
- return std::nullopt;
- }
- return result.value() << 24;
- }
-
- bool setLightPlayerId(int32_t lightId, int32_t playerId) override { return true; }
-
- std::optional<int32_t> getLightPlayerId(int32_t lightId) override { return std::nullopt; }
-
-private:
- InputDeviceContext& mDeviceContext;
- inline int32_t getDeviceId() { return mDeviceContext.getId(); }
- inline InputDeviceContext& getDeviceContext() { return mDeviceContext; }
-};
-
-TEST_F(InputReaderTest, BatteryGetCapacity) {
- constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD | InputDeviceClass::BATTERY;
- constexpr int32_t eventHubId = 1;
- const char* DEVICE_LOCATION = "BLUETOOTH";
- std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
- FakePeripheralController& controller =
- device->addController<FakePeripheralController>(eventHubId);
- mReader->pushNextDevice(device);
-
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
-
- ASSERT_EQ(controller.getBatteryCapacity(DEFAULT_BATTERY), BATTERY_CAPACITY);
- ASSERT_EQ(mReader->getBatteryCapacity(deviceId), BATTERY_CAPACITY);
-}
-
-TEST_F(InputReaderTest, BatteryGetStatus) {
- constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD | InputDeviceClass::BATTERY;
- constexpr int32_t eventHubId = 1;
- const char* DEVICE_LOCATION = "BLUETOOTH";
- std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
- FakePeripheralController& controller =
- device->addController<FakePeripheralController>(eventHubId);
- mReader->pushNextDevice(device);
-
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
-
- ASSERT_EQ(controller.getBatteryStatus(DEFAULT_BATTERY), BATTERY_STATUS);
- ASSERT_EQ(mReader->getBatteryStatus(deviceId), BATTERY_STATUS);
-}
-
-TEST_F(InputReaderTest, LightGetColor) {
- constexpr int32_t deviceId = END_RESERVED_ID + 1000;
- Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD | InputDeviceClass::LIGHT;
- constexpr int32_t eventHubId = 1;
- const char* DEVICE_LOCATION = "BLUETOOTH";
- std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
- FakePeripheralController& controller =
- device->addController<FakePeripheralController>(eventHubId);
- mReader->pushNextDevice(device);
- RawLightInfo info = {.id = 1,
- .name = "Mono",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS,
- .path = ""};
- mFakeEventHub->addRawLightInfo(1 /* rawId */, std::move(info));
- mFakeEventHub->fakeLightBrightness(1 /* rawId */, 0x55);
-
- ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
-
- ASSERT_TRUE(controller.setLightColor(1 /* lightId */, LIGHT_BRIGHTNESS));
- ASSERT_EQ(controller.getLightColor(1 /* lightId */), LIGHT_BRIGHTNESS);
- ASSERT_TRUE(mReader->setLightColor(deviceId, 1 /* lightId */, LIGHT_BRIGHTNESS));
- ASSERT_EQ(mReader->getLightColor(deviceId, 1 /* lightId */), LIGHT_BRIGHTNESS);
-}
-
// --- InputReaderIntegrationTest ---
// These tests create and interact with the InputReader only through its interface.
@@ -2119,7 +1746,7 @@ protected:
sp<FakeInputReaderPolicy> mFakePolicy;
sp<InputReaderInterface> mReader;
- void SetUp() override {
+ virtual void SetUp() override {
mFakePolicy = new FakeInputReaderPolicy();
mTestListener = new TestInputListener(2000ms /*eventHappenedTimeout*/,
30ms /*eventDidNotHappenTimeout*/);
@@ -2134,7 +1761,7 @@ protected:
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyConfigurationChangedWasCalled());
}
- void TearDown() override {
+ virtual void TearDown() override {
ASSERT_EQ(mReader->stop(), OK);
mTestListener.clear();
mFakePolicy.clear();
@@ -2175,17 +1802,20 @@ TEST_F(InputReaderIntegrationTest, AddNewDevice) {
ASSERT_EQ(initialNumDevices + 1, mFakePolicy->getInputDevices().size());
// Find the test device by its name.
- const std::vector<InputDeviceInfo> inputDevices = mFakePolicy->getInputDevices();
- const auto& it =
- std::find_if(inputDevices.begin(), inputDevices.end(),
- [&keyboard](const InputDeviceInfo& info) {
- return info.getIdentifier().name == keyboard->getName();
- });
-
- ASSERT_NE(it, inputDevices.end());
- ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, it->getKeyboardType());
- ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, it->getSources());
- ASSERT_EQ(0U, it->getMotionRanges().size());
+ std::vector<InputDeviceInfo> inputDevices;
+ mReader->getInputDevices(inputDevices);
+ InputDeviceInfo* keyboardInfo = nullptr;
+ const char* keyboardName = keyboard->getName();
+ for (unsigned int i = 0; i < initialNumDevices + 1; i++) {
+ if (!strcmp(inputDevices[i].getIdentifier().name.c_str(), keyboardName)) {
+ keyboardInfo = &inputDevices[i];
+ break;
+ }
+ }
+ ASSERT_NE(keyboardInfo, nullptr);
+ ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, keyboardInfo->getKeyboardType());
+ ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyboardInfo->getSources());
+ ASSERT_EQ(0U, keyboardInfo->getMotionRanges().size());
keyboard.reset();
ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
@@ -2210,14 +1840,12 @@ TEST_F(InputReaderIntegrationTest, SendsEventsToInputListener) {
ASSERT_NE(prevId, keyArgs.id);
prevId = keyArgs.id;
ASSERT_LE(prevTimestamp, keyArgs.eventTime);
- ASSERT_LE(keyArgs.eventTime, keyArgs.readTime);
prevTimestamp = keyArgs.eventTime;
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
ASSERT_NE(prevId, keyArgs.id);
ASSERT_LE(prevTimestamp, keyArgs.eventTime);
- ASSERT_LE(keyArgs.eventTime, keyArgs.readTime);
}
/**
@@ -2245,14 +1873,18 @@ TEST_F(InputReaderIntegrationTest, SendsGearDownAndUpToInputListener) {
// --- TouchProcessTest ---
class TouchIntegrationTest : public InputReaderIntegrationTest {
protected:
+ static const int32_t FIRST_SLOT = 0;
+ static const int32_t SECOND_SLOT = 1;
+ static const int32_t FIRST_TRACKING_ID = 0;
+ static const int32_t SECOND_TRACKING_ID = 1;
const std::string UNIQUE_ID = "local:0";
- void SetUp() override {
+ virtual void SetUp() override {
InputReaderIntegrationTest::SetUp();
// At least add an internal display.
setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_0, UNIQUE_ID, NO_PORT,
- ViewportType::INTERNAL);
+ ViewportType::VIEWPORT_INTERNAL);
mDevice = createUinputDevice<UinputTouchScreen>(Rect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT));
ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
@@ -2263,8 +1895,8 @@ protected:
int32_t orientation, const std::string& uniqueId,
std::optional<uint8_t> physicalPort,
ViewportType viewportType) {
- mFakePolicy->addDisplayViewport(displayId, width, height, orientation, true /*isActive*/,
- uniqueId, physicalPort, viewportType);
+ mFakePolicy->addDisplayViewport(displayId, width, height, orientation, uniqueId,
+ physicalPort, viewportType);
mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
}
@@ -2276,7 +1908,6 @@ TEST_F(TouchIntegrationTest, InputEvent_ProcessSingleTouch) {
const Point centerPoint = mDevice->getCenterPoint();
// ACTION_DOWN
- mDevice->sendTrackingId(FIRST_TRACKING_ID);
mDevice->sendDown(centerPoint);
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
@@ -2297,8 +1928,6 @@ TEST_F(TouchIntegrationTest, InputEvent_ProcessMultiTouch) {
const Point centerPoint = mDevice->getCenterPoint();
// ACTION_DOWN
- mDevice->sendSlot(FIRST_SLOT);
- mDevice->sendTrackingId(FIRST_TRACKING_ID);
mDevice->sendDown(centerPoint);
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
@@ -2318,9 +1947,9 @@ TEST_F(TouchIntegrationTest, InputEvent_ProcessMultiTouch) {
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
// ACTION_POINTER_UP (Second slot)
- mDevice->sendPointerUp();
+ mDevice->sendUp();
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+ ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
args.action);
// ACTION_UP
@@ -2335,13 +1964,11 @@ TEST_F(TouchIntegrationTest, InputEvent_ProcessPalm) {
const Point centerPoint = mDevice->getCenterPoint();
// ACTION_DOWN
- mDevice->sendSlot(FIRST_SLOT);
- mDevice->sendTrackingId(FIRST_TRACKING_ID);
mDevice->sendDown(centerPoint);
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
- // ACTION_POINTER_DOWN (second slot)
+ // ACTION_POINTER_DOWN (Second slot)
const Point secondPoint = centerPoint + Point(100, 100);
mDevice->sendSlot(SECOND_SLOT);
mDevice->sendTrackingId(SECOND_TRACKING_ID);
@@ -2350,31 +1977,26 @@ TEST_F(TouchIntegrationTest, InputEvent_ProcessPalm) {
ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
args.action);
- // ACTION_MOVE (second slot)
+ // ACTION_MOVE (Second slot)
mDevice->sendMove(secondPoint + Point(1, 1));
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- // Send MT_TOOL_PALM (second slot), which indicates that the touch IC has determined this to be
- // a palm event.
- // Expect to receive the ACTION_POINTER_UP with cancel flag.
+ // Send MT_TOOL_PALM, which indicates that the touch IC has determined this to be a grip event.
+ // Expect to receive ACTION_CANCEL, to abort the entire gesture.
mDevice->sendToolType(MT_TOOL_PALM);
ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- args.action);
- ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, args.flags);
+ ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, args.action);
- // Send up to second slot, expect first slot send moving.
- mDevice->sendPointerUp();
- ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
+ // ACTION_POINTER_UP (Second slot)
+ mDevice->sendUp();
- // Send ACTION_UP (first slot)
+ // ACTION_UP
mDevice->sendSlot(FIRST_SLOT);
mDevice->sendUp();
- ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
+ // Expect no event received after abort the entire gesture.
+ ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasNotCalled());
}
// --- InputDeviceTest ---
@@ -2385,32 +2007,33 @@ protected:
static const int32_t DEVICE_ID;
static const int32_t DEVICE_GENERATION;
static const int32_t DEVICE_CONTROLLER_NUMBER;
- static const Flags<InputDeviceClass> DEVICE_CLASSES;
+ static const uint32_t DEVICE_CLASSES;
static const int32_t EVENTHUB_ID;
std::shared_ptr<FakeEventHub> mFakeEventHub;
sp<FakeInputReaderPolicy> mFakePolicy;
sp<TestInputListener> mFakeListener;
- std::unique_ptr<InstrumentedInputReader> mReader;
+ FakeInputReaderContext* mFakeContext;
+
std::shared_ptr<InputDevice> mDevice;
- void SetUp() override {
+ virtual void SetUp() override {
mFakeEventHub = std::make_unique<FakeEventHub>();
mFakePolicy = new FakeInputReaderPolicy();
mFakeListener = new TestInputListener();
- mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
- mFakeListener);
+ mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener);
+
+ mFakeEventHub->addDevice(EVENTHUB_ID, DEVICE_NAME, 0);
InputDeviceIdentifier identifier;
identifier.name = DEVICE_NAME;
identifier.location = DEVICE_LOCATION;
- mDevice = std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, DEVICE_GENERATION,
+ mDevice = std::make_shared<InputDevice>(mFakeContext, DEVICE_ID, DEVICE_GENERATION,
identifier);
- mReader->pushNextDevice(mDevice);
- mFakeEventHub->addDevice(EVENTHUB_ID, DEVICE_NAME, Flags<InputDeviceClass>(0));
- mReader->loopOnce();
}
- void TearDown() override {
+ virtual void TearDown() override {
+ mDevice = nullptr;
+ delete mFakeContext;
mFakeListener.clear();
mFakePolicy.clear();
}
@@ -2421,14 +2044,14 @@ const char* InputDeviceTest::DEVICE_LOCATION = "USB1";
const int32_t InputDeviceTest::DEVICE_ID = END_RESERVED_ID + 1000;
const int32_t InputDeviceTest::DEVICE_GENERATION = 2;
const int32_t InputDeviceTest::DEVICE_CONTROLLER_NUMBER = 0;
-const Flags<InputDeviceClass> InputDeviceTest::DEVICE_CLASSES =
- InputDeviceClass::KEYBOARD | InputDeviceClass::TOUCH | InputDeviceClass::JOYSTICK;
+const uint32_t InputDeviceTest::DEVICE_CLASSES = INPUT_DEVICE_CLASS_KEYBOARD
+ | INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_JOYSTICK;
const int32_t InputDeviceTest::EVENTHUB_ID = 1;
TEST_F(InputDeviceTest, ImmutableProperties) {
ASSERT_EQ(DEVICE_ID, mDevice->getId());
ASSERT_STREQ(DEVICE_NAME, mDevice->getName().c_str());
- ASSERT_EQ(Flags<InputDeviceClass>(0), mDevice->getClasses());
+ ASSERT_EQ(0U, mDevice->getClasses());
}
TEST_F(InputDeviceTest, WhenDeviceCreated_EnabledIsFalse) {
@@ -2452,7 +2075,8 @@ TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) {
ASSERT_TRUE(mDevice->isIgnored());
ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, mDevice->getSources());
- InputDeviceInfo info = mDevice->getDeviceInfo();
+ InputDeviceInfo info;
+ mDevice->getDeviceInfo(&info);
ASSERT_EQ(DEVICE_ID, info.getId());
ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.c_str());
ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NONE, info.getKeyboardType());
@@ -2521,7 +2145,8 @@ TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRe
ASSERT_FALSE(mDevice->isIgnored());
ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), mDevice->getSources());
- InputDeviceInfo info = mDevice->getDeviceInfo();
+ InputDeviceInfo info;
+ mDevice->getDeviceInfo(&info);
ASSERT_EQ(DEVICE_ID, info.getId());
ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.c_str());
ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, info.getKeyboardType());
@@ -2595,43 +2220,8 @@ TEST_F(InputDeviceTest, Configure_AssignsDisplayPort) {
// Prepare displays.
mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, UNIQUE_ID, hdmi,
- ViewportType::INTERNAL);
- mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
- InputReaderConfiguration::CHANGE_DISPLAY_INFO);
- ASSERT_TRUE(mDevice->isEnabled());
-
- // Device should be disabled after set disable.
- mFakePolicy->addDisabledDevice(mDevice->getId());
- mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
- InputReaderConfiguration::CHANGE_ENABLED_STATE);
- ASSERT_FALSE(mDevice->isEnabled());
-
- // Device should still be disabled even found the associated display.
- mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
- InputReaderConfiguration::CHANGE_DISPLAY_INFO);
- ASSERT_FALSE(mDevice->isEnabled());
-}
-
-TEST_F(InputDeviceTest, Configure_AssignsDisplayUniqueId) {
- // Device should be enabled by default.
- mFakePolicy->clearViewports();
- mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD);
- mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
- ASSERT_TRUE(mDevice->isEnabled());
-
- // Device should be disabled because it is associated with a specific display, but the
- // corresponding display is not found.
- const std::string DISPLAY_UNIQUE_ID = "displayUniqueId";
- mFakePolicy->addInputUniqueIdAssociation(DEVICE_NAME, DISPLAY_UNIQUE_ID);
- mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
- InputReaderConfiguration::CHANGE_DISPLAY_INFO);
- ASSERT_FALSE(mDevice->isEnabled());
-
- // Device should be enabled when a display is found.
- mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID,
- NO_PORT, ViewportType::INTERNAL);
+ DISPLAY_ORIENTATION_0, UNIQUE_ID, hdmi,
+ ViewportType::VIEWPORT_INTERNAL);
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
InputReaderConfiguration::CHANGE_DISPLAY_INFO);
ASSERT_TRUE(mDevice->isEnabled());
@@ -2657,27 +2247,33 @@ protected:
static const int32_t DEVICE_ID;
static const int32_t DEVICE_GENERATION;
static const int32_t DEVICE_CONTROLLER_NUMBER;
- static const Flags<InputDeviceClass> DEVICE_CLASSES;
+ static const uint32_t DEVICE_CLASSES;
static const int32_t EVENTHUB_ID;
std::shared_ptr<FakeEventHub> mFakeEventHub;
sp<FakeInputReaderPolicy> mFakePolicy;
sp<TestInputListener> mFakeListener;
- std::unique_ptr<InstrumentedInputReader> mReader;
- std::shared_ptr<InputDevice> mDevice;
+ FakeInputReaderContext* mFakeContext;
+ InputDevice* mDevice;
- virtual void SetUp(Flags<InputDeviceClass> classes) {
+ virtual void SetUp(uint32_t classes) {
mFakeEventHub = std::make_unique<FakeEventHub>();
mFakePolicy = new FakeInputReaderPolicy();
mFakeListener = new TestInputListener();
- mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
- mFakeListener);
- mDevice = newDevice(DEVICE_ID, DEVICE_NAME, DEVICE_LOCATION, EVENTHUB_ID, classes);
+ mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener);
+ InputDeviceIdentifier identifier;
+ identifier.name = DEVICE_NAME;
+ identifier.location = DEVICE_LOCATION;
+ mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION, identifier);
+
+ mFakeEventHub->addDevice(EVENTHUB_ID, DEVICE_NAME, classes);
}
- void SetUp() override { SetUp(DEVICE_CLASSES); }
+ virtual void SetUp() override { SetUp(DEVICE_CLASSES); }
- void TearDown() override {
+ virtual void TearDown() override {
+ delete mDevice;
+ delete mFakeContext;
mFakeListener.clear();
mFakePolicy.clear();
}
@@ -2688,41 +2284,24 @@ protected:
void configureDevice(uint32_t changes) {
if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
- mReader->requestRefreshConfiguration(changes);
- mReader->loopOnce();
+ mFakeContext->updatePointerDisplay();
}
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), changes);
}
- std::shared_ptr<InputDevice> newDevice(int32_t deviceId, const std::string& name,
- const std::string& location, int32_t eventHubId,
- Flags<InputDeviceClass> classes) {
- InputDeviceIdentifier identifier;
- identifier.name = name;
- identifier.location = location;
- std::shared_ptr<InputDevice> device =
- std::make_shared<InputDevice>(mReader->getContext(), deviceId, DEVICE_GENERATION,
- identifier);
- mReader->pushNextDevice(device);
- mFakeEventHub->addDevice(eventHubId, name, classes);
- mReader->loopOnce();
- return device;
- }
-
template <class T, typename... Args>
T& addMapperAndConfigure(Args... args) {
T& mapper = mDevice->addMapper<T>(EVENTHUB_ID, args...);
configureDevice(0);
mDevice->reset(ARBITRARY_TIME);
- mapper.reset(ARBITRARY_TIME);
return mapper;
}
void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height,
int32_t orientation, const std::string& uniqueId,
std::optional<uint8_t> physicalPort, ViewportType viewportType) {
- mFakePolicy->addDisplayViewport(displayId, width, height, orientation, true /*isActive*/,
- uniqueId, physicalPort, viewportType);
+ mFakePolicy->addDisplayViewport(
+ displayId, width, height, orientation, uniqueId, physicalPort, viewportType);
configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
}
@@ -2730,17 +2309,15 @@ protected:
mFakePolicy->clearViewports();
}
- void process(InputMapper& mapper, nsecs_t when, nsecs_t readTime, int32_t type, int32_t code,
- int32_t value) {
+ static void process(InputMapper& mapper, nsecs_t when, int32_t type, int32_t code,
+ int32_t value) {
RawEvent event;
event.when = when;
- event.readTime = readTime;
event.deviceId = mapper.getDeviceContext().getEventHubId();
event.type = type;
event.code = code;
event.value = value;
mapper.process(&event);
- mReader->loopOnce();
}
static void assertMotionRange(const InputDeviceInfo& info,
@@ -2755,29 +2332,25 @@ protected:
ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source;
}
- static void assertPointerCoords(const PointerCoords& coords, float x, float y, float pressure,
- float size, float touchMajor, float touchMinor, float toolMajor,
- float toolMinor, float orientation, float distance,
- float scaledAxisEpsilon = 1.f) {
- ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), scaledAxisEpsilon);
- ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), scaledAxisEpsilon);
+ static void assertPointerCoords(const PointerCoords& coords,
+ float x, float y, float pressure, float size,
+ float touchMajor, float touchMinor, float toolMajor, float toolMinor,
+ float orientation, float distance) {
+ ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), 1);
+ ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON);
ASSERT_NEAR(size, coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE), EPSILON);
- ASSERT_NEAR(touchMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
- scaledAxisEpsilon);
- ASSERT_NEAR(touchMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
- scaledAxisEpsilon);
- ASSERT_NEAR(toolMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
- scaledAxisEpsilon);
- ASSERT_NEAR(toolMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
- scaledAxisEpsilon);
+ ASSERT_NEAR(touchMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), 1);
+ ASSERT_NEAR(touchMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), 1);
+ ASSERT_NEAR(toolMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), 1);
+ ASSERT_NEAR(toolMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), 1);
ASSERT_NEAR(orientation, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), EPSILON);
ASSERT_NEAR(distance, coords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), EPSILON);
}
- static void assertPosition(const FakePointerController& controller, float x, float y) {
+ static void assertPosition(const sp<FakePointerController>& controller, float x, float y) {
float actualX, actualY;
- controller.getPosition(&actualX, &actualY);
+ controller->getPosition(&actualX, &actualY);
ASSERT_NEAR(x, actualX, 1);
ASSERT_NEAR(y, actualY, 1);
}
@@ -2788,8 +2361,7 @@ const char* InputMapperTest::DEVICE_LOCATION = "USB1";
const int32_t InputMapperTest::DEVICE_ID = END_RESERVED_ID + 1000;
const int32_t InputMapperTest::DEVICE_GENERATION = 2;
const int32_t InputMapperTest::DEVICE_CONTROLLER_NUMBER = 0;
-const Flags<InputDeviceClass> InputMapperTest::DEVICE_CLASSES =
- Flags<InputDeviceClass>(0); // not needed for current tests
+const uint32_t InputMapperTest::DEVICE_CLASSES = 0; // not needed for current tests
const int32_t InputMapperTest::EVENTHUB_ID = 1;
// --- SwitchInputMapperTest ---
@@ -2817,10 +2389,10 @@ TEST_F(SwitchInputMapperTest, GetSwitchState) {
TEST_F(SwitchInputMapperTest, Process) {
SwitchInputMapper& mapper = addMapperAndConfigure<SwitchInputMapper>();
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_LID, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_JACK_PHYSICAL_INSERT, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_HEADPHONE_INSERT, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_SW, SW_LID, 1);
+ process(mapper, ARBITRARY_TIME, EV_SW, SW_JACK_PHYSICAL_INSERT, 1);
+ process(mapper, ARBITRARY_TIME, EV_SW, SW_HEADPHONE_INSERT, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
NotifySwitchArgs args;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySwitchWasCalled(&args));
@@ -2831,215 +2403,6 @@ TEST_F(SwitchInputMapperTest, Process) {
ASSERT_EQ(uint32_t(0), args.policyFlags);
}
-// --- VibratorInputMapperTest ---
-class VibratorInputMapperTest : public InputMapperTest {
-protected:
- void SetUp() override { InputMapperTest::SetUp(DEVICE_CLASSES | InputDeviceClass::VIBRATOR); }
-};
-
-TEST_F(VibratorInputMapperTest, GetSources) {
- VibratorInputMapper& mapper = addMapperAndConfigure<VibratorInputMapper>();
-
- ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, mapper.getSources());
-}
-
-TEST_F(VibratorInputMapperTest, GetVibratorIds) {
- VibratorInputMapper& mapper = addMapperAndConfigure<VibratorInputMapper>();
-
- ASSERT_EQ(mapper.getVibratorIds().size(), 2U);
-}
-
-TEST_F(VibratorInputMapperTest, Vibrate) {
- constexpr uint8_t DEFAULT_AMPLITUDE = 192;
- constexpr int32_t VIBRATION_TOKEN = 100;
- VibratorInputMapper& mapper = addMapperAndConfigure<VibratorInputMapper>();
-
- VibrationElement pattern(2);
- VibrationSequence sequence(2);
- pattern.duration = std::chrono::milliseconds(200);
- pattern.channels = {{0 /* vibratorId */, DEFAULT_AMPLITUDE / 2},
- {1 /* vibratorId */, DEFAULT_AMPLITUDE}};
- sequence.addElement(pattern);
- pattern.duration = std::chrono::milliseconds(500);
- pattern.channels = {{0 /* vibratorId */, DEFAULT_AMPLITUDE / 4},
- {1 /* vibratorId */, DEFAULT_AMPLITUDE}};
- sequence.addElement(pattern);
-
- std::vector<int64_t> timings = {0, 1};
- std::vector<uint8_t> amplitudes = {DEFAULT_AMPLITUDE, DEFAULT_AMPLITUDE / 2};
-
- ASSERT_FALSE(mapper.isVibrating());
- // Start vibrating
- mapper.vibrate(sequence, -1 /* repeat */, VIBRATION_TOKEN);
- ASSERT_TRUE(mapper.isVibrating());
- // Verify vibrator state listener was notified.
- mReader->loopOnce();
- NotifyVibratorStateArgs args;
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyVibratorStateWasCalled(&args));
- ASSERT_EQ(DEVICE_ID, args.deviceId);
- ASSERT_TRUE(args.isOn);
- // Stop vibrating
- mapper.cancelVibrate(VIBRATION_TOKEN);
- ASSERT_FALSE(mapper.isVibrating());
- // Verify vibrator state listener was notified.
- mReader->loopOnce();
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyVibratorStateWasCalled(&args));
- ASSERT_EQ(DEVICE_ID, args.deviceId);
- ASSERT_FALSE(args.isOn);
-}
-
-// --- SensorInputMapperTest ---
-
-class SensorInputMapperTest : public InputMapperTest {
-protected:
- static const int32_t ACCEL_RAW_MIN;
- static const int32_t ACCEL_RAW_MAX;
- static const int32_t ACCEL_RAW_FUZZ;
- static const int32_t ACCEL_RAW_FLAT;
- static const int32_t ACCEL_RAW_RESOLUTION;
-
- static const int32_t GYRO_RAW_MIN;
- static const int32_t GYRO_RAW_MAX;
- static const int32_t GYRO_RAW_FUZZ;
- static const int32_t GYRO_RAW_FLAT;
- static const int32_t GYRO_RAW_RESOLUTION;
-
- static const float GRAVITY_MS2_UNIT;
- static const float DEGREE_RADIAN_UNIT;
-
- void prepareAccelAxes();
- void prepareGyroAxes();
- void setAccelProperties();
- void setGyroProperties();
- void SetUp() override { InputMapperTest::SetUp(DEVICE_CLASSES | InputDeviceClass::SENSOR); }
-};
-
-const int32_t SensorInputMapperTest::ACCEL_RAW_MIN = -32768;
-const int32_t SensorInputMapperTest::ACCEL_RAW_MAX = 32768;
-const int32_t SensorInputMapperTest::ACCEL_RAW_FUZZ = 16;
-const int32_t SensorInputMapperTest::ACCEL_RAW_FLAT = 0;
-const int32_t SensorInputMapperTest::ACCEL_RAW_RESOLUTION = 8192;
-
-const int32_t SensorInputMapperTest::GYRO_RAW_MIN = -2097152;
-const int32_t SensorInputMapperTest::GYRO_RAW_MAX = 2097152;
-const int32_t SensorInputMapperTest::GYRO_RAW_FUZZ = 16;
-const int32_t SensorInputMapperTest::GYRO_RAW_FLAT = 0;
-const int32_t SensorInputMapperTest::GYRO_RAW_RESOLUTION = 1024;
-
-const float SensorInputMapperTest::GRAVITY_MS2_UNIT = 9.80665f;
-const float SensorInputMapperTest::DEGREE_RADIAN_UNIT = 0.0174533f;
-
-void SensorInputMapperTest::prepareAccelAxes() {
- mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_X, ACCEL_RAW_MIN, ACCEL_RAW_MAX, ACCEL_RAW_FUZZ,
- ACCEL_RAW_FLAT, ACCEL_RAW_RESOLUTION);
- mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_Y, ACCEL_RAW_MIN, ACCEL_RAW_MAX, ACCEL_RAW_FUZZ,
- ACCEL_RAW_FLAT, ACCEL_RAW_RESOLUTION);
- mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_Z, ACCEL_RAW_MIN, ACCEL_RAW_MAX, ACCEL_RAW_FUZZ,
- ACCEL_RAW_FLAT, ACCEL_RAW_RESOLUTION);
-}
-
-void SensorInputMapperTest::prepareGyroAxes() {
- mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_RX, GYRO_RAW_MIN, GYRO_RAW_MAX, GYRO_RAW_FUZZ,
- GYRO_RAW_FLAT, GYRO_RAW_RESOLUTION);
- mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_RY, GYRO_RAW_MIN, GYRO_RAW_MAX, GYRO_RAW_FUZZ,
- GYRO_RAW_FLAT, GYRO_RAW_RESOLUTION);
- mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_RZ, GYRO_RAW_MIN, GYRO_RAW_MAX, GYRO_RAW_FUZZ,
- GYRO_RAW_FLAT, GYRO_RAW_RESOLUTION);
-}
-
-void SensorInputMapperTest::setAccelProperties() {
- mFakeEventHub->addSensorAxis(EVENTHUB_ID, /* absCode */ 0, InputDeviceSensorType::ACCELEROMETER,
- /* sensorDataIndex */ 0);
- mFakeEventHub->addSensorAxis(EVENTHUB_ID, /* absCode */ 1, InputDeviceSensorType::ACCELEROMETER,
- /* sensorDataIndex */ 1);
- mFakeEventHub->addSensorAxis(EVENTHUB_ID, /* absCode */ 2, InputDeviceSensorType::ACCELEROMETER,
- /* sensorDataIndex */ 2);
- mFakeEventHub->setMscEvent(EVENTHUB_ID, MSC_TIMESTAMP);
- addConfigurationProperty("sensor.accelerometer.reportingMode", "0");
- addConfigurationProperty("sensor.accelerometer.maxDelay", "100000");
- addConfigurationProperty("sensor.accelerometer.minDelay", "5000");
- addConfigurationProperty("sensor.accelerometer.power", "1.5");
-}
-
-void SensorInputMapperTest::setGyroProperties() {
- mFakeEventHub->addSensorAxis(EVENTHUB_ID, /* absCode */ 3, InputDeviceSensorType::GYROSCOPE,
- /* sensorDataIndex */ 0);
- mFakeEventHub->addSensorAxis(EVENTHUB_ID, /* absCode */ 4, InputDeviceSensorType::GYROSCOPE,
- /* sensorDataIndex */ 1);
- mFakeEventHub->addSensorAxis(EVENTHUB_ID, /* absCode */ 5, InputDeviceSensorType::GYROSCOPE,
- /* sensorDataIndex */ 2);
- mFakeEventHub->setMscEvent(EVENTHUB_ID, MSC_TIMESTAMP);
- addConfigurationProperty("sensor.gyroscope.reportingMode", "0");
- addConfigurationProperty("sensor.gyroscope.maxDelay", "100000");
- addConfigurationProperty("sensor.gyroscope.minDelay", "5000");
- addConfigurationProperty("sensor.gyroscope.power", "0.8");
-}
-
-TEST_F(SensorInputMapperTest, GetSources) {
- SensorInputMapper& mapper = addMapperAndConfigure<SensorInputMapper>();
-
- ASSERT_EQ(static_cast<uint32_t>(AINPUT_SOURCE_SENSOR), mapper.getSources());
-}
-
-TEST_F(SensorInputMapperTest, ProcessAccelerometerSensor) {
- setAccelProperties();
- prepareAccelAxes();
- SensorInputMapper& mapper = addMapperAndConfigure<SensorInputMapper>();
-
- ASSERT_TRUE(mapper.enableSensor(InputDeviceSensorType::ACCELEROMETER,
- std::chrono::microseconds(10000),
- std::chrono::microseconds(0)));
- ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(EVENTHUB_ID));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, 20000);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, -20000);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Z, 40000);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_MSC, MSC_TIMESTAMP, 1000);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
-
- NotifySensorArgs args;
- std::vector<float> values = {20000.0f / ACCEL_RAW_RESOLUTION * GRAVITY_MS2_UNIT,
- -20000.0f / ACCEL_RAW_RESOLUTION * GRAVITY_MS2_UNIT,
- 40000.0f / ACCEL_RAW_RESOLUTION * GRAVITY_MS2_UNIT};
-
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySensorWasCalled(&args));
- ASSERT_EQ(args.source, AINPUT_SOURCE_SENSOR);
- ASSERT_EQ(args.deviceId, DEVICE_ID);
- ASSERT_EQ(args.sensorType, InputDeviceSensorType::ACCELEROMETER);
- ASSERT_EQ(args.accuracy, InputDeviceSensorAccuracy::ACCURACY_HIGH);
- ASSERT_EQ(args.hwTimestamp, ARBITRARY_TIME);
- ASSERT_EQ(args.values, values);
- mapper.flushSensor(InputDeviceSensorType::ACCELEROMETER);
-}
-
-TEST_F(SensorInputMapperTest, ProcessGyroscopeSensor) {
- setGyroProperties();
- prepareGyroAxes();
- SensorInputMapper& mapper = addMapperAndConfigure<SensorInputMapper>();
-
- ASSERT_TRUE(mapper.enableSensor(InputDeviceSensorType::GYROSCOPE,
- std::chrono::microseconds(10000),
- std::chrono::microseconds(0)));
- ASSERT_TRUE(mFakeEventHub->isDeviceEnabled(EVENTHUB_ID));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_RX, 20000);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_RY, -20000);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_RZ, 40000);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_MSC, MSC_TIMESTAMP, 1000);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
-
- NotifySensorArgs args;
- std::vector<float> values = {20000.0f / GYRO_RAW_RESOLUTION * DEGREE_RADIAN_UNIT,
- -20000.0f / GYRO_RAW_RESOLUTION * DEGREE_RADIAN_UNIT,
- 40000.0f / GYRO_RAW_RESOLUTION * DEGREE_RADIAN_UNIT};
-
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySensorWasCalled(&args));
- ASSERT_EQ(args.source, AINPUT_SOURCE_SENSOR);
- ASSERT_EQ(args.deviceId, DEVICE_ID);
- ASSERT_EQ(args.sensorType, InputDeviceSensorType::GYROSCOPE);
- ASSERT_EQ(args.accuracy, InputDeviceSensorAccuracy::ACCURACY_HIGH);
- ASSERT_EQ(args.hwTimestamp, ARBITRARY_TIME);
- ASSERT_EQ(args.values, values);
- mapper.flushSensor(InputDeviceSensorType::GYROSCOPE);
-}
// --- KeyboardInputMapperTest ---
@@ -3058,8 +2421,8 @@ protected:
* orientation.
*/
void KeyboardInputMapperTest::prepareDisplay(int32_t orientation) {
- setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation, UNIQUE_ID,
- NO_PORT, ViewportType::INTERNAL);
+ setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
+ orientation, UNIQUE_ID, NO_PORT, ViewportType::VIEWPORT_INTERNAL);
}
void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper& mapper,
@@ -3067,14 +2430,14 @@ void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper& mapper,
int32_t rotatedKeyCode, int32_t displayId) {
NotifyKeyArgs args;
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, originalScanCode, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, originalScanCode, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
ASSERT_EQ(originalScanCode, args.scanCode);
ASSERT_EQ(rotatedKeyCode, args.keyCode);
ASSERT_EQ(displayId, args.displayId);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, originalScanCode, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, originalScanCode, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
ASSERT_EQ(originalScanCode, args.scanCode);
@@ -3095,19 +2458,13 @@ TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
const int32_t USAGE_UNKNOWN = 0x07ffff;
mFakeEventHub->addKey(EVENTHUB_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE);
mFakeEventHub->addKey(EVENTHUB_ID, 0, USAGE_A, AKEYCODE_A, POLICY_FLAG_WAKE);
- mFakeEventHub->addKey(EVENTHUB_ID, 0, KEY_NUMLOCK, AKEYCODE_NUM_LOCK, POLICY_FLAG_WAKE);
- mFakeEventHub->addKey(EVENTHUB_ID, 0, KEY_CAPSLOCK, AKEYCODE_CAPS_LOCK, POLICY_FLAG_WAKE);
- mFakeEventHub->addKey(EVENTHUB_ID, 0, KEY_SCROLLLOCK, AKEYCODE_SCROLL_LOCK, POLICY_FLAG_WAKE);
KeyboardInputMapper& mapper =
addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
- // Initial metastate to AMETA_NONE.
- ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper.getMetaState());
- mapper.updateMetaState(AKEYCODE_NUM_LOCK);
// Key down by scan code.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_HOME, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_HOME, 1);
NotifyKeyArgs args;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DEVICE_ID, args.deviceId);
@@ -3122,7 +2479,7 @@ TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
// Key up by scan code.
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_HOME, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_HOME, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DEVICE_ID, args.deviceId);
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
@@ -3136,8 +2493,8 @@ TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
// Key down by usage code.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_MSC, MSC_SCAN, USAGE_A);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, 0, 1);
+ process(mapper, ARBITRARY_TIME, EV_MSC, MSC_SCAN, USAGE_A);
+ process(mapper, ARBITRARY_TIME, EV_KEY, 0, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DEVICE_ID, args.deviceId);
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
@@ -3151,8 +2508,8 @@ TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
// Key up by usage code.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_MSC, MSC_SCAN, USAGE_A);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, 0, 0);
+ process(mapper, ARBITRARY_TIME, EV_MSC, MSC_SCAN, USAGE_A);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, 0, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DEVICE_ID, args.deviceId);
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
@@ -3166,8 +2523,8 @@ TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
// Key down with unknown scan code or usage code.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_MSC, MSC_SCAN, USAGE_UNKNOWN);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UNKNOWN, 1);
+ process(mapper, ARBITRARY_TIME, EV_MSC, MSC_SCAN, USAGE_UNKNOWN);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UNKNOWN, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DEVICE_ID, args.deviceId);
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
@@ -3181,8 +2538,8 @@ TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
// Key up with unknown scan code or usage code.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_MSC, MSC_SCAN, USAGE_UNKNOWN);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_UNKNOWN, 0);
+ process(mapper, ARBITRARY_TIME, EV_MSC, MSC_SCAN, USAGE_UNKNOWN);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_UNKNOWN, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DEVICE_ID, args.deviceId);
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
@@ -3196,69 +2553,43 @@ TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
}
-/**
- * Ensure that the readTime is set to the time when the EV_KEY is received.
- */
-TEST_F(KeyboardInputMapperTest, Process_SendsReadTime) {
- mFakeEventHub->addKey(EVENTHUB_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE);
-
- KeyboardInputMapper& mapper =
- addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD,
- AINPUT_KEYBOARD_TYPE_ALPHABETIC);
- NotifyKeyArgs args;
-
- // Key down
- process(mapper, ARBITRARY_TIME, 12 /*readTime*/, EV_KEY, KEY_HOME, 1);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
- ASSERT_EQ(12, args.readTime);
-
- // Key up
- process(mapper, ARBITRARY_TIME, 15 /*readTime*/, EV_KEY, KEY_HOME, 1);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
- ASSERT_EQ(15, args.readTime);
-}
-
TEST_F(KeyboardInputMapperTest, Process_ShouldUpdateMetaState) {
mFakeEventHub->addKey(EVENTHUB_ID, KEY_LEFTSHIFT, 0, AKEYCODE_SHIFT_LEFT, 0);
mFakeEventHub->addKey(EVENTHUB_ID, KEY_A, 0, AKEYCODE_A, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, 0, KEY_NUMLOCK, AKEYCODE_NUM_LOCK, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, 0, KEY_CAPSLOCK, AKEYCODE_CAPS_LOCK, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, 0, KEY_SCROLLLOCK, AKEYCODE_SCROLL_LOCK, 0);
KeyboardInputMapper& mapper =
addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
- // Initial metastate to AMETA_NONE.
- ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper.getMetaState());
- mapper.updateMetaState(AKEYCODE_NUM_LOCK);
+ // Initial metastate.
+ ASSERT_EQ(AMETA_NONE, mapper.getMetaState());
// Metakey down.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_LEFTSHIFT, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_LEFTSHIFT, 1);
NotifyKeyArgs args;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper.getMetaState());
- ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertUpdateGlobalMetaStateWasCalled());
+ ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled());
// Key down.
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_A, 1);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_A, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper.getMetaState());
// Key up.
- process(mapper, ARBITRARY_TIME + 2, READ_TIME, EV_KEY, KEY_A, 0);
+ process(mapper, ARBITRARY_TIME + 2, EV_KEY, KEY_A, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper.getMetaState());
// Metakey up.
- process(mapper, ARBITRARY_TIME + 3, READ_TIME, EV_KEY, KEY_LEFTSHIFT, 0);
+ process(mapper, ARBITRARY_TIME + 3, EV_KEY, KEY_LEFTSHIFT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AMETA_NONE, args.metaState);
ASSERT_EQ(AMETA_NONE, mapper.getMetaState());
- ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertUpdateGlobalMetaStateWasCalled());
+ ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled());
}
TEST_F(KeyboardInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateDPad) {
@@ -3341,7 +2672,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
NotifyKeyArgs args;
clearViewports();
prepareDisplay(DISPLAY_ORIENTATION_270);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
ASSERT_EQ(KEY_UP, args.scanCode);
@@ -3349,7 +2680,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
clearViewports();
prepareDisplay(DISPLAY_ORIENTATION_180);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
ASSERT_EQ(KEY_UP, args.scanCode);
@@ -3367,16 +2698,16 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_NotOrientationAware
NotifyKeyArgs args;
// Display id should be ADISPLAY_ID_NONE without any display configuration.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(ADISPLAY_ID_NONE, args.displayId);
prepareDisplay(DISPLAY_ORIENTATION_0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(ADISPLAY_ID_NONE, args.displayId);
}
@@ -3396,20 +2727,20 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_OrientationAware) {
// ^--- already checked by the previous test
setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0,
- UNIQUE_ID, NO_PORT, ViewportType::INTERNAL);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1);
+ UNIQUE_ID, NO_PORT, ViewportType::VIEWPORT_INTERNAL);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DISPLAY_ID, args.displayId);
constexpr int32_t newDisplayId = 2;
clearViewports();
setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0,
- UNIQUE_ID, NO_PORT, ViewportType::INTERNAL);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1);
+ UNIQUE_ID, NO_PORT, ViewportType::VIEWPORT_INTERNAL);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_UP, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(newDisplayId, args.displayId);
}
@@ -3463,9 +2794,6 @@ TEST_F(KeyboardInputMapperTest, Process_LockedKeysShouldToggleMetaStateAndLeds)
KeyboardInputMapper& mapper =
addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
- // Initialize metastate to AMETA_NUM_LOCK_ON.
- ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper.getMetaState());
- mapper.updateMetaState(AKEYCODE_NUM_LOCK);
// Initialization should have turned all of the lights off.
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
@@ -3473,91 +2801,54 @@ TEST_F(KeyboardInputMapperTest, Process_LockedKeysShouldToggleMetaStateAndLeds)
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
// Toggle caps lock on.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_CAPSLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_CAPSLOCK, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_CAPSLOCK, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_CAPSLOCK, 0);
ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_NUML));
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
ASSERT_EQ(AMETA_CAPS_LOCK_ON, mapper.getMetaState());
// Toggle num lock on.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_NUMLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_NUMLOCK, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_NUMLOCK, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_NUMLOCK, 0);
ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_NUML));
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON, mapper.getMetaState());
// Toggle caps lock off.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_CAPSLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_CAPSLOCK, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_CAPSLOCK, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_CAPSLOCK, 0);
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_NUML));
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper.getMetaState());
// Toggle scroll lock on.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_SCROLLLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_SCROLLLOCK, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_SCROLLLOCK, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_SCROLLLOCK, 0);
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_NUML));
ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
ASSERT_EQ(AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON, mapper.getMetaState());
// Toggle num lock off.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_NUMLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_NUMLOCK, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_NUMLOCK, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_NUMLOCK, 0);
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_NUML));
ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
ASSERT_EQ(AMETA_SCROLL_LOCK_ON, mapper.getMetaState());
// Toggle scroll lock off.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_SCROLLLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_SCROLLLOCK, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_SCROLLLOCK, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_SCROLLLOCK, 0);
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_NUML));
ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
ASSERT_EQ(AMETA_NONE, mapper.getMetaState());
}
-TEST_F(KeyboardInputMapperTest, NoMetaStateWhenMetaKeysNotPresent) {
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_A, 0, AKEYCODE_BUTTON_A, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_B, 0, AKEYCODE_BUTTON_B, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_X, 0, AKEYCODE_BUTTON_X, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_Y, 0, AKEYCODE_BUTTON_Y, 0);
-
- KeyboardInputMapper& mapper =
- addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD,
- AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC);
-
- // Initial metastate should be AMETA_NONE as no meta keys added.
- ASSERT_EQ(AMETA_NONE, mapper.getMetaState());
- // Meta state should be AMETA_NONE after reset
- mapper.reset(ARBITRARY_TIME);
- ASSERT_EQ(AMETA_NONE, mapper.getMetaState());
- // Meta state should be AMETA_NONE with update, as device doesn't have the keys.
- mapper.updateMetaState(AKEYCODE_NUM_LOCK);
- ASSERT_EQ(AMETA_NONE, mapper.getMetaState());
-
- NotifyKeyArgs args;
- // Press button "A"
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_A, 1);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
- ASSERT_EQ(AMETA_NONE, args.metaState);
- ASSERT_EQ(AMETA_NONE, mapper.getMetaState());
- ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
- ASSERT_EQ(AKEYCODE_BUTTON_A, args.keyCode);
-
- // Button up.
- process(mapper, ARBITRARY_TIME + 2, READ_TIME, EV_KEY, BTN_A, 0);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
- ASSERT_EQ(AMETA_NONE, args.metaState);
- ASSERT_EQ(AMETA_NONE, mapper.getMetaState());
- ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
- ASSERT_EQ(AKEYCODE_BUTTON_A, args.keyCode);
-}
-
TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) {
// keyboard 1.
mFakeEventHub->addKey(EVENTHUB_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0);
@@ -3567,13 +2858,15 @@ TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) {
// keyboard 2.
const std::string USB2 = "USB2";
- const std::string DEVICE_NAME2 = "KEYBOARD2";
constexpr int32_t SECOND_DEVICE_ID = DEVICE_ID + 1;
constexpr int32_t SECOND_EVENTHUB_ID = EVENTHUB_ID + 1;
- std::shared_ptr<InputDevice> device2 =
- newDevice(SECOND_DEVICE_ID, DEVICE_NAME2, USB2, SECOND_EVENTHUB_ID,
- Flags<InputDeviceClass>(0));
-
+ InputDeviceIdentifier identifier;
+ identifier.name = "KEYBOARD2";
+ identifier.location = USB2;
+ std::unique_ptr<InputDevice> device2 =
+ std::make_unique<InputDevice>(mFakeContext, SECOND_DEVICE_ID, DEVICE_GENERATION,
+ identifier);
+ mFakeEventHub->addDevice(SECOND_EVENTHUB_ID, DEVICE_NAME, 0 /*classes*/);
mFakeEventHub->addKey(SECOND_EVENTHUB_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0);
mFakeEventHub->addKey(SECOND_EVENTHUB_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0);
mFakeEventHub->addKey(SECOND_EVENTHUB_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0);
@@ -3605,9 +2898,9 @@ TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) {
// Prepare second display.
constexpr int32_t newDisplayId = 2;
setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0,
- UNIQUE_ID, hdmi1, ViewportType::INTERNAL);
+ UNIQUE_ID, hdmi1, ViewportType::VIEWPORT_INTERNAL);
setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0,
- SECONDARY_UNIQUE_ID, hdmi2, ViewportType::EXTERNAL);
+ SECONDARY_UNIQUE_ID, hdmi2, ViewportType::VIEWPORT_EXTERNAL);
// Default device will reconfigure above, need additional reconfiguration for another device.
device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
InputReaderConfiguration::CHANGE_DISPLAY_INFO);
@@ -3636,80 +2929,13 @@ TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) {
AKEYCODE_DPAD_LEFT, newDisplayId));
}
-TEST_F(KeyboardInputMapperTest, Process_LockedKeysShouldToggleAfterReattach) {
- mFakeEventHub->addLed(EVENTHUB_ID, LED_CAPSL, true /*initially on*/);
- mFakeEventHub->addLed(EVENTHUB_ID, LED_NUML, false /*initially off*/);
- mFakeEventHub->addLed(EVENTHUB_ID, LED_SCROLLL, false /*initially off*/);
- mFakeEventHub->addKey(EVENTHUB_ID, KEY_CAPSLOCK, 0, AKEYCODE_CAPS_LOCK, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, KEY_NUMLOCK, 0, AKEYCODE_NUM_LOCK, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, KEY_SCROLLLOCK, 0, AKEYCODE_SCROLL_LOCK, 0);
-
- KeyboardInputMapper& mapper =
- addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD,
- AINPUT_KEYBOARD_TYPE_ALPHABETIC);
- // Initial metastate to AMETA_NONE.
- ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper.getMetaState());
- mapper.updateMetaState(AKEYCODE_NUM_LOCK);
-
- // Initialization should have turned all of the lights off.
- ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
- ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_NUML));
- ASSERT_FALSE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
-
- // Toggle caps lock on.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_CAPSLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_CAPSLOCK, 0);
- ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_CAPSL));
- ASSERT_EQ(AMETA_CAPS_LOCK_ON, mapper.getMetaState());
-
- // Toggle num lock on.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_NUMLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_NUMLOCK, 0);
- ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_NUML));
- ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON, mapper.getMetaState());
-
- // Toggle scroll lock on.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_SCROLLLOCK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_SCROLLLOCK, 0);
- ASSERT_TRUE(mFakeEventHub->getLedState(EVENTHUB_ID, LED_SCROLLL));
- ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON, mapper.getMetaState());
-
- mFakeEventHub->removeDevice(EVENTHUB_ID);
- mReader->loopOnce();
-
- // keyboard 2 should default toggle keys.
- const std::string USB2 = "USB2";
- const std::string DEVICE_NAME2 = "KEYBOARD2";
- constexpr int32_t SECOND_DEVICE_ID = DEVICE_ID + 1;
- constexpr int32_t SECOND_EVENTHUB_ID = EVENTHUB_ID + 1;
- std::shared_ptr<InputDevice> device2 =
- newDevice(SECOND_DEVICE_ID, DEVICE_NAME2, USB2, SECOND_EVENTHUB_ID,
- Flags<InputDeviceClass>(0));
- mFakeEventHub->addLed(SECOND_EVENTHUB_ID, LED_CAPSL, true /*initially on*/);
- mFakeEventHub->addLed(SECOND_EVENTHUB_ID, LED_NUML, false /*initially off*/);
- mFakeEventHub->addLed(SECOND_EVENTHUB_ID, LED_SCROLLL, false /*initially off*/);
- mFakeEventHub->addKey(SECOND_EVENTHUB_ID, KEY_CAPSLOCK, 0, AKEYCODE_CAPS_LOCK, 0);
- mFakeEventHub->addKey(SECOND_EVENTHUB_ID, KEY_NUMLOCK, 0, AKEYCODE_NUM_LOCK, 0);
- mFakeEventHub->addKey(SECOND_EVENTHUB_ID, KEY_SCROLLLOCK, 0, AKEYCODE_SCROLL_LOCK, 0);
-
- KeyboardInputMapper& mapper2 =
- device2->addMapper<KeyboardInputMapper>(SECOND_EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD,
- AINPUT_KEYBOARD_TYPE_ALPHABETIC);
- device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0 /*changes*/);
- device2->reset(ARBITRARY_TIME);
-
- ASSERT_TRUE(mFakeEventHub->getLedState(SECOND_EVENTHUB_ID, LED_CAPSL));
- ASSERT_TRUE(mFakeEventHub->getLedState(SECOND_EVENTHUB_ID, LED_NUML));
- ASSERT_TRUE(mFakeEventHub->getLedState(SECOND_EVENTHUB_ID, LED_SCROLLL));
- ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON,
- mapper2.getMetaState());
-}
-
// --- KeyboardInputMapperTest_ExternalDevice ---
class KeyboardInputMapperTest_ExternalDevice : public InputMapperTest {
protected:
- void SetUp() override { InputMapperTest::SetUp(DEVICE_CLASSES | InputDeviceClass::EXTERNAL); }
+ virtual void SetUp() override {
+ InputMapperTest::SetUp(DEVICE_CLASSES | INPUT_DEVICE_CLASS_EXTERNAL);
+ }
};
TEST_F(KeyboardInputMapperTest_ExternalDevice, WakeBehavior) {
@@ -3725,28 +2951,28 @@ TEST_F(KeyboardInputMapperTest_ExternalDevice, WakeBehavior) {
addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_HOME, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_HOME, 1);
NotifyKeyArgs args;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_HOME, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_HOME, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(uint32_t(0), args.policyFlags);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_PLAY, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAY, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(uint32_t(0), args.policyFlags);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_PLAY, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAY, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(uint32_t(0), args.policyFlags);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_PLAYPAUSE, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAYPAUSE, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_PLAYPAUSE, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAYPAUSE, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
}
@@ -3763,28 +2989,28 @@ TEST_F(KeyboardInputMapperTest_ExternalDevice, DoNotWakeByDefaultBehavior) {
addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD,
AINPUT_KEYBOARD_TYPE_ALPHABETIC);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_HOME, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_HOME, 1);
NotifyKeyArgs args;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_HOME, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_HOME, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_DOWN, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_DOWN, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(uint32_t(0), args.policyFlags);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_DOWN, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_DOWN, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(uint32_t(0), args.policyFlags);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_PLAY, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAY, 1);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_PLAY, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAY, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
}
@@ -3795,12 +3021,12 @@ class CursorInputMapperTest : public InputMapperTest {
protected:
static const int32_t TRACKBALL_MOVEMENT_THRESHOLD;
- std::shared_ptr<FakePointerController> mFakePointerController;
+ sp<FakePointerController> mFakePointerController;
- void SetUp() override {
+ virtual void SetUp() override {
InputMapperTest::SetUp();
- mFakePointerController = std::make_shared<FakePointerController>();
+ mFakePointerController = new FakePointerController();
mFakePolicy->setPointerController(mDevice->getId(), mFakePointerController);
}
@@ -3809,16 +3035,10 @@ protected:
void prepareDisplay(int32_t orientation) {
const std::string uniqueId = "local:0";
- const ViewportType viewportType = ViewportType::INTERNAL;
+ const ViewportType viewportType = ViewportType::VIEWPORT_INTERNAL;
setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
orientation, uniqueId, NO_PORT, viewportType);
}
-
- static void assertCursorPointerCoords(const PointerCoords& coords, float x, float y,
- float pressure) {
- ASSERT_NO_FATAL_FAILURE(assertPointerCoords(coords, x, y, pressure, 0.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, EPSILON));
- }
};
const int32_t CursorInputMapperTest::TRACKBALL_MOVEMENT_THRESHOLD = 6;
@@ -3828,15 +3048,15 @@ void CursorInputMapperTest::testMotionRotation(CursorInputMapper& mapper, int32_
int32_t rotatedY) {
NotifyMotionArgs args;
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, originalX);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, originalY);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, originalX);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, originalY);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(args.pointerCoords[0],
- float(rotatedX) / TRACKBALL_MOVEMENT_THRESHOLD,
- float(rotatedY) / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ float(rotatedX) / TRACKBALL_MOVEMENT_THRESHOLD,
+ float(rotatedY) / TRACKBALL_MOVEMENT_THRESHOLD,
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
}
TEST_F(CursorInputMapperTest, WhenModeIsPointer_GetSources_ReturnsMouse) {
@@ -3905,14 +3125,14 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat
addConfigurationProperty("cursor.mode", "navigation");
CursorInputMapper& mapper = addMapperAndConfigure<CursorInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyMotionArgs args;
// Button press.
// Mostly testing non x/y behavior here so we don't need to check again elsewhere.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MOUSE, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MOUSE, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
ASSERT_EQ(DEVICE_ID, args.deviceId);
@@ -3926,7 +3146,8 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat
ASSERT_EQ(uint32_t(1), args.pointerCount);
ASSERT_EQ(0, args.pointerProperties[0].id);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision);
ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision);
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
@@ -3944,14 +3165,15 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat
ASSERT_EQ(uint32_t(1), args.pointerCount);
ASSERT_EQ(0, args.pointerProperties[0].id);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision);
ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision);
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
// Button release. Should have same down time.
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, BTN_MOUSE, 0);
- process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_KEY, BTN_MOUSE, 0);
+ process(mapper, ARBITRARY_TIME + 1, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
ASSERT_EQ(DEVICE_ID, args.deviceId);
@@ -3965,7 +3187,8 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat
ASSERT_EQ(uint32_t(1), args.pointerCount);
ASSERT_EQ(0, args.pointerProperties[0].id);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision);
ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision);
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
@@ -3983,7 +3206,8 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat
ASSERT_EQ(uint32_t(1), args.pointerCount);
ASSERT_EQ(0, args.pointerProperties[0].id);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision);
ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision);
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
@@ -3996,21 +3220,20 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentXYUpdates) {
NotifyMotionArgs args;
// Motion in X but not Y.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0],
- 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f,
- 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
// Motion in Y but not X.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, -2);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, -2);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f,
- -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
}
TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentButtonUpdates) {
@@ -4020,26 +3243,30 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentButtonUpdates) {
NotifyMotionArgs args;
// Button press.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MOUSE, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MOUSE, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
// Button release.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MOUSE, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MOUSE, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
}
TEST_F(CursorInputMapperTest, Process_ShouldHandleCombinedXYAndButtonUpdates) {
@@ -4049,42 +3276,44 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleCombinedXYAndButtonUpdates) {
NotifyMotionArgs args;
// Combined X, Y and Button.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, -2);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MOUSE, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 1);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, -2);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MOUSE, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0],
- 1.0f / TRACKBALL_MOVEMENT_THRESHOLD,
- -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD,
+ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0],
- 1.0f / TRACKBALL_MOVEMENT_THRESHOLD,
- -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD,
+ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
// Move X, Y a bit while pressed.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, 2);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 2);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0],
- 2.0f / TRACKBALL_MOVEMENT_THRESHOLD,
- 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD,
+ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
// Release Button.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MOUSE, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MOUSE, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
- ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
}
TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateMotions) {
@@ -4160,65 +3389,65 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) {
NotifyKeyArgs keyArgs;
// press BTN_LEFT, release BTN_LEFT
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_LEFT, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_LEFT, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_LEFT, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_LEFT, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
// press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_RIGHT, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MIDDLE, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_RIGHT, 1);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MIDDLE, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action);
@@ -4226,53 +3455,53 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) {
motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_RIGHT, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_RIGHT, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 1.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MIDDLE, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MIDDLE, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MIDDLE, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MIDDLE, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
// press BTN_BACK, release BTN_BACK
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_BACK, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_BACK, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
@@ -4281,39 +3510,39 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) {
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_BACK, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_BACK, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
// press BTN_SIDE, release BTN_SIDE
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_SIDE, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_SIDE, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
@@ -4322,39 +3551,39 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) {
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_SIDE, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_SIDE, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
// press BTN_FORWARD, release BTN_FORWARD
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_FORWARD, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_FORWARD, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
@@ -4363,39 +3592,39 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) {
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_FORWARD, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_FORWARD, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
// press BTN_EXTRA, release BTN_EXTRA
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_EXTRA, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_EXTRA, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
@@ -4404,31 +3633,31 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) {
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_EXTRA, 0);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_EXTRA, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_EQ(0, motionArgs.buttonState);
ASSERT_EQ(0, mFakePointerController->getButtonState());
- ASSERT_NO_FATAL_FAILURE(
- assertCursorPointerCoords(motionArgs.pointerCoords[0], 100.0f, 200.0f, 0.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+ 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
@@ -4445,15 +3674,15 @@ TEST_F(CursorInputMapperTest, Process_WhenModeIsPointer_ShouldMoveThePointerArou
NotifyMotionArgs args;
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, 10);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, 20);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 10);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, 20);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AINPUT_SOURCE_MOUSE, args.source);
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 110.0f, 220.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 110.0f, 220.0f));
}
TEST_F(CursorInputMapperTest, Process_PointerCapture) {
@@ -4473,19 +3702,19 @@ TEST_F(CursorInputMapperTest, Process_PointerCapture) {
NotifyMotionArgs args;
// Move.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, 10);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, 20);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 10);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, 20);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source);
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
10.0f, 20.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 100.0f, 200.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 100.0f, 200.0f));
// Button press.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MOUSE, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_MOUSE, 1);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source);
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
@@ -4498,8 +3727,8 @@ TEST_F(CursorInputMapperTest, Process_PointerCapture) {
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
// Button release.
- process(mapper, ARBITRARY_TIME + 2, READ_TIME, EV_KEY, BTN_MOUSE, 0);
- process(mapper, ARBITRARY_TIME + 2, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME + 2, EV_KEY, BTN_MOUSE, 0);
+ process(mapper, ARBITRARY_TIME + 2, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source);
ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, args.action);
@@ -4512,36 +3741,36 @@ TEST_F(CursorInputMapperTest, Process_PointerCapture) {
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
// Another move.
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, 30);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, 40);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 30);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, 40);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source);
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
30.0f, 40.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 100.0f, 200.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 100.0f, 200.0f));
// Disable pointer capture and check that the device generation got bumped
// and events are generated the usual way.
- const uint32_t generation = mReader->getContext()->getGeneration();
+ const uint32_t generation = mFakeContext->getGeneration();
mFakePolicy->setPointerCapture(false);
configureDevice(InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
- ASSERT_TRUE(mReader->getContext()->getGeneration() != generation);
+ ASSERT_TRUE(mFakeContext->getGeneration() != generation);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime);
ASSERT_EQ(DEVICE_ID, resetArgs.deviceId);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, 10);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, 20);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 10);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, 20);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AINPUT_SOURCE_MOUSE, args.source);
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 110.0f, 220.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 110.0f, 220.0f));
}
TEST_F(CursorInputMapperTest, Process_ShouldHandleDisplayId) {
@@ -4551,8 +3780,8 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleDisplayId) {
constexpr int32_t SECOND_DISPLAY_ID = 1;
const std::string SECOND_DISPLAY_UNIQUE_ID = "local:1";
mFakePolicy->addDisplayViewport(SECOND_DISPLAY_ID, 800, 480, DISPLAY_ORIENTATION_0,
- true /*isActive*/, SECOND_DISPLAY_UNIQUE_ID, NO_PORT,
- ViewportType::EXTERNAL);
+ SECOND_DISPLAY_UNIQUE_ID, NO_PORT,
+ ViewportType::VIEWPORT_EXTERNAL);
mFakePolicy->setDefaultPointerDisplayId(SECOND_DISPLAY_ID);
configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
@@ -4561,15 +3790,15 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleDisplayId) {
mFakePointerController->setButtonState(0);
NotifyMotionArgs args;
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_X, 10);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_REL, REL_Y, 20);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 10);
+ process(mapper, ARBITRARY_TIME, EV_REL, REL_Y, 20);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AINPUT_SOURCE_MOUSE, args.source);
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
- ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 110.0f, 220.0f));
+ ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 110.0f, 220.0f));
ASSERT_EQ(SECOND_DISPLAY_ID, args.displayId);
}
@@ -4679,8 +3908,8 @@ const VirtualKeyDefinition TouchInputMapperTest::VIRTUAL_KEYS[2] = {
};
void TouchInputMapperTest::prepareDisplay(int32_t orientation, std::optional<uint8_t> port) {
- setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation, UNIQUE_ID,
- port, ViewportType::INTERNAL);
+ setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation,
+ UNIQUE_ID, port, ViewportType::VIEWPORT_INTERNAL);
}
void TouchInputMapperTest::prepareSecondaryDisplay(ViewportType type, std::optional<uint8_t> port) {
@@ -4689,9 +3918,9 @@ void TouchInputMapperTest::prepareSecondaryDisplay(ViewportType type, std::optio
}
void TouchInputMapperTest::prepareVirtualDisplay(int32_t orientation) {
- setDisplayInfoAndReconfigure(VIRTUAL_DISPLAY_ID, VIRTUAL_DISPLAY_WIDTH, VIRTUAL_DISPLAY_HEIGHT,
- orientation, VIRTUAL_DISPLAY_UNIQUE_ID, NO_PORT,
- ViewportType::VIRTUAL);
+ setDisplayInfoAndReconfigure(VIRTUAL_DISPLAY_ID, VIRTUAL_DISPLAY_WIDTH,
+ VIRTUAL_DISPLAY_HEIGHT, orientation,
+ VIRTUAL_DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::VIEWPORT_VIRTUAL);
}
void TouchInputMapperTest::prepareVirtualKeys() {
@@ -4786,46 +4015,46 @@ void SingleTouchInputMapperTest::prepareAxes(int axes) {
}
void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 1);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_TOUCH, 1);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_X, x);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_Y, y);
}
void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_X, x);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_Y, y);
}
void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper& mapper) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 0);
+ process(mapper, ARBITRARY_TIME, EV_KEY, BTN_TOUCH, 0);
}
void SingleTouchInputMapperTest::processPressure(SingleTouchInputMapper& mapper, int32_t pressure) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_PRESSURE, pressure);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_PRESSURE, pressure);
}
void SingleTouchInputMapperTest::processToolMajor(SingleTouchInputMapper& mapper,
int32_t toolMajor) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TOOL_WIDTH, toolMajor);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_TOOL_WIDTH, toolMajor);
}
void SingleTouchInputMapperTest::processDistance(SingleTouchInputMapper& mapper, int32_t distance) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_DISTANCE, distance);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_DISTANCE, distance);
}
void SingleTouchInputMapperTest::processTilt(SingleTouchInputMapper& mapper, int32_t tiltX,
int32_t tiltY) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_X, tiltX);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_Y, tiltY);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_TILT_X, tiltX);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_TILT_Y, tiltY);
}
void SingleTouchInputMapperTest::processKey(SingleTouchInputMapper& mapper, int32_t code,
int32_t value) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, code, value);
+ process(mapper, ARBITRARY_TIME, EV_KEY, code, value);
}
void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper& mapper) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
}
TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) {
@@ -4943,7 +4172,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNor
prepareVirtualKeys();
SingleTouchInputMapper& mapper = addMapperAndConfigure<SingleTouchInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyKeyArgs args;
@@ -4993,7 +4222,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfB
prepareVirtualKeys();
SingleTouchInputMapper& mapper = addMapperAndConfigure<SingleTouchInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyKeyArgs keyArgs;
@@ -5114,7 +4343,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMoves
prepareVirtualKeys();
SingleTouchInputMapper& mapper = addMapperAndConfigure<SingleTouchInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyMotionArgs motionArgs;
@@ -5189,7 +4418,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl
prepareVirtualKeys();
SingleTouchInputMapper& mapper = addMapperAndConfigure<SingleTouchInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyMotionArgs motionArgs;
@@ -5285,7 +4514,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) {
prepareVirtualKeys();
SingleTouchInputMapper& mapper = addMapperAndConfigure<SingleTouchInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyMotionArgs motionArgs;
@@ -6113,64 +5342,64 @@ void MultiTouchInputMapperTest::prepareAxes(int axes) {
void MultiTouchInputMapperTest::processPosition(MultiTouchInputMapper& mapper, int32_t x,
int32_t y) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_POSITION_X, x);
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_POSITION_Y, y);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, x);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, y);
}
void MultiTouchInputMapperTest::processTouchMajor(MultiTouchInputMapper& mapper,
int32_t touchMajor) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_TOUCH_MAJOR, touchMajor);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_TOUCH_MAJOR, touchMajor);
}
void MultiTouchInputMapperTest::processTouchMinor(MultiTouchInputMapper& mapper,
int32_t touchMinor) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_TOUCH_MINOR, touchMinor);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_TOUCH_MINOR, touchMinor);
}
void MultiTouchInputMapperTest::processToolMajor(MultiTouchInputMapper& mapper, int32_t toolMajor) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_WIDTH_MAJOR, toolMajor);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_WIDTH_MAJOR, toolMajor);
}
void MultiTouchInputMapperTest::processToolMinor(MultiTouchInputMapper& mapper, int32_t toolMinor) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_WIDTH_MINOR, toolMinor);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_WIDTH_MINOR, toolMinor);
}
void MultiTouchInputMapperTest::processOrientation(MultiTouchInputMapper& mapper,
int32_t orientation) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_ORIENTATION, orientation);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_ORIENTATION, orientation);
}
void MultiTouchInputMapperTest::processPressure(MultiTouchInputMapper& mapper, int32_t pressure) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_PRESSURE, pressure);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_PRESSURE, pressure);
}
void MultiTouchInputMapperTest::processDistance(MultiTouchInputMapper& mapper, int32_t distance) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_DISTANCE, distance);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_DISTANCE, distance);
}
void MultiTouchInputMapperTest::processId(MultiTouchInputMapper& mapper, int32_t id) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_TRACKING_ID, id);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_TRACKING_ID, id);
}
void MultiTouchInputMapperTest::processSlot(MultiTouchInputMapper& mapper, int32_t slot) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_SLOT, slot);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_SLOT, slot);
}
void MultiTouchInputMapperTest::processToolType(MultiTouchInputMapper& mapper, int32_t toolType) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_MT_TOOL_TYPE, toolType);
+ process(mapper, ARBITRARY_TIME, EV_ABS, ABS_MT_TOOL_TYPE, toolType);
}
void MultiTouchInputMapperTest::processKey(MultiTouchInputMapper& mapper, int32_t code,
int32_t value) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, code, value);
+ process(mapper, ARBITRARY_TIME, EV_KEY, code, value);
}
void MultiTouchInputMapperTest::processMTSync(MultiTouchInputMapper& mapper) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_MT_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_MT_REPORT, 0);
}
void MultiTouchInputMapperTest::processSync(MultiTouchInputMapper& mapper) {
- process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
+ process(mapper, ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
}
TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackingIds) {
@@ -6180,7 +5409,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin
prepareVirtualKeys();
MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyMotionArgs motionArgs;
@@ -6456,7 +5685,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId
prepareVirtualKeys();
MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyMotionArgs motionArgs;
@@ -6631,7 +5860,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) {
prepareVirtualKeys();
MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
- mReader->getContext()->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+ mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
NotifyMotionArgs motionArgs;
@@ -7544,7 +6773,7 @@ TEST_F(MultiTouchInputMapperTest, Configure_AssignsDisplayPort) {
const uint8_t hdmi1 = 0;
const uint8_t hdmi2 = 1;
const std::string secondaryUniqueId = "uniqueId2";
- constexpr ViewportType type = ViewportType::EXTERNAL;
+ constexpr ViewportType type = ViewportType::VIEWPORT_EXTERNAL;
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareAxes(POSITION);
@@ -7577,15 +6806,14 @@ TEST_F(MultiTouchInputMapperTest, Configure_AssignsDisplayPort) {
TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShouldHandleDisplayId) {
// Setup for second display.
- std::shared_ptr<FakePointerController> fakePointerController =
- std::make_shared<FakePointerController>();
+ sp<FakePointerController> fakePointerController = new FakePointerController();
fakePointerController->setBounds(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1);
fakePointerController->setPosition(100, 200);
fakePointerController->setButtonState(0);
mFakePolicy->setPointerController(mDevice->getId(), fakePointerController);
mFakePolicy->setDefaultPointerDisplayId(SECONDARY_DISPLAY_ID);
- prepareSecondaryDisplay(ViewportType::EXTERNAL);
+ prepareSecondaryDisplay(ViewportType::VIEWPORT_EXTERNAL);
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareAxes(POSITION);
@@ -7603,103 +6831,6 @@ TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShouldHandleDisplayId) {
ASSERT_EQ(SECONDARY_DISPLAY_ID, motionArgs.displayId);
}
-/**
- * Ensure that the readTime is set to the SYN_REPORT value when processing touch events.
- */
-TEST_F(MultiTouchInputMapperTest, Process_SendsReadTime) {
- addConfigurationProperty("touch.deviceType", "touchScreen");
- prepareAxes(POSITION);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- prepareDisplay(DISPLAY_ORIENTATION_0);
- process(mapper, 10, 11 /*readTime*/, EV_ABS, ABS_MT_TRACKING_ID, 1);
- process(mapper, 15, 16 /*readTime*/, EV_ABS, ABS_MT_POSITION_X, 100);
- process(mapper, 20, 21 /*readTime*/, EV_ABS, ABS_MT_POSITION_Y, 100);
- process(mapper, 25, 26 /*readTime*/, EV_SYN, SYN_REPORT, 0);
-
- NotifyMotionArgs args;
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(26, args.readTime);
-
- process(mapper, 30, 31 /*readTime*/, EV_ABS, ABS_MT_POSITION_X, 110);
- process(mapper, 30, 32 /*readTime*/, EV_ABS, ABS_MT_POSITION_Y, 220);
- process(mapper, 30, 33 /*readTime*/, EV_SYN, SYN_REPORT, 0);
-
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(33, args.readTime);
-}
-
-/**
- * When the viewport is not active (isActive=false), the touch mapper should be disabled and the
- * events should not be delivered to the listener.
- */
-TEST_F(MultiTouchInputMapperTest, WhenViewportIsNotActive_TouchesAreDropped) {
- addConfigurationProperty("touch.deviceType", "touchScreen");
- mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, false /*isActive*/, UNIQUE_ID, NO_PORT,
- ViewportType::INTERNAL);
- configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
- prepareAxes(POSITION);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- NotifyMotionArgs motionArgs;
- processPosition(mapper, 100, 100);
- processSync(mapper);
-
- mFakeListener->assertNotifyMotionWasNotCalled();
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_DeactivateViewport_AbortTouches) {
- addConfigurationProperty("touch.deviceType", "touchScreen");
- mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
- DISPLAY_ORIENTATION_0, true /*isActive*/, UNIQUE_ID, NO_PORT,
- ViewportType::INTERNAL);
- std::optional<DisplayViewport> optionalDisplayViewport =
- mFakePolicy->getDisplayViewportByUniqueId(UNIQUE_ID);
- ASSERT_TRUE(optionalDisplayViewport.has_value());
- DisplayViewport displayViewport = *optionalDisplayViewport;
-
- configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
- prepareAxes(POSITION);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- // Finger down
- int32_t x = 100, y = 100;
- processPosition(mapper, x, y);
- processSync(mapper);
-
- NotifyMotionArgs motionArgs;
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-
- // Deactivate display viewport
- displayViewport.isActive = false;
- ASSERT_TRUE(mFakePolicy->updateViewport(displayViewport));
- configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
-
- // Finger move
- x += 10, y += 10;
- processPosition(mapper, x, y);
- processSync(mapper);
-
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- EXPECT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionArgs.action);
-
- // Reactivate display viewport
- displayViewport.isActive = true;
- ASSERT_TRUE(mFakePolicy->updateViewport(displayViewport));
- configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
-
- // Finger move again
- x += 10, y += 10;
- processPosition(mapper, x, y);
- processSync(mapper);
-
- // Gesture is aborted, so events after display is activated won't be dispatched until there is
- // no pointer on the touch device.
- mFakeListener->assertNotifyMotionWasNotCalled();
-}
-
TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShowTouches) {
// Setup the first touch screen device.
prepareAxes(POSITION | ID | SLOT);
@@ -7708,13 +6839,15 @@ TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShowTouches) {
// Create the second touch screen device, and enable multi fingers.
const std::string USB2 = "USB2";
- const std::string DEVICE_NAME2 = "TOUCHSCREEN2";
constexpr int32_t SECOND_DEVICE_ID = DEVICE_ID + 1;
constexpr int32_t SECOND_EVENTHUB_ID = EVENTHUB_ID + 1;
- std::shared_ptr<InputDevice> device2 =
- newDevice(SECOND_DEVICE_ID, DEVICE_NAME2, USB2, SECOND_EVENTHUB_ID,
- Flags<InputDeviceClass>(0));
-
+ InputDeviceIdentifier identifier;
+ identifier.name = "TOUCHSCREEN2";
+ identifier.location = USB2;
+ std::unique_ptr<InputDevice> device2 =
+ std::make_unique<InputDevice>(mFakeContext, SECOND_DEVICE_ID, DEVICE_GENERATION,
+ identifier);
+ mFakeEventHub->addDevice(SECOND_EVENTHUB_ID, DEVICE_NAME, 0 /*classes*/);
mFakeEventHub->addAbsoluteAxis(SECOND_EVENTHUB_ID, ABS_MT_POSITION_X, RAW_X_MIN, RAW_X_MAX,
0 /*flat*/, 0 /*fuzz*/);
mFakeEventHub->addAbsoluteAxis(SECOND_EVENTHUB_ID, ABS_MT_POSITION_Y, RAW_Y_MIN, RAW_Y_MAX,
@@ -7733,8 +6866,7 @@ TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShowTouches) {
device2->reset(ARBITRARY_TIME);
// Setup PointerController.
- std::shared_ptr<FakePointerController> fakePointerController =
- std::make_shared<FakePointerController>();
+ sp<FakePointerController> fakePointerController = new FakePointerController();
mFakePolicy->setPointerController(mDevice->getId(), fakePointerController);
mFakePolicy->setPointerController(SECOND_DEVICE_ID, fakePointerController);
@@ -7747,11 +6879,11 @@ TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShowTouches) {
// Create displays.
prepareDisplay(DISPLAY_ORIENTATION_0, hdmi1);
- prepareSecondaryDisplay(ViewportType::EXTERNAL, hdmi2);
+ prepareSecondaryDisplay(ViewportType::VIEWPORT_EXTERNAL, hdmi2);
// Default device will reconfigure above, need additional reconfiguration for another device.
device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
- InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+ InputReaderConfiguration::CHANGE_DISPLAY_INFO);
// Two fingers down at default display.
int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500;
@@ -7858,7 +6990,7 @@ TEST_F(MultiTouchInputMapperTest, VideoFrames_MultipleFramesAreRotated) {
TEST_F(MultiTouchInputMapperTest, Configure_EnabledForAssociatedDisplay) {
constexpr uint8_t hdmi2 = 1;
const std::string secondaryUniqueId = "uniqueId2";
- constexpr ViewportType type = ViewportType::EXTERNAL;
+ constexpr ViewportType type = ViewportType::VIEWPORT_EXTERNAL;
mFakePolicy->addInputPortAssociation(DEVICE_LOCATION, hdmi2);
@@ -7881,6 +7013,8 @@ TEST_F(MultiTouchInputMapperTest, Configure_EnabledForAssociatedDisplay) {
ASSERT_EQ(SECONDARY_DISPLAY_ID, args.displayId);
}
+
+
TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) {
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareDisplay(DISPLAY_ORIENTATION_0);
@@ -7923,10 +7057,10 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) {
}
/**
- * Test single touch should be canceled when received the MT_TOOL_PALM event, and the following
- * MOVE and UP events should be ignored.
+ * Test touch should be canceled when received the MT_TOOL_PALM event, and the following MOVE and
+ * UP events should be ignored.
*/
-TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer) {
+TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType) {
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareAxes(POSITION | ID | SLOT | TOOL_TYPE);
@@ -7936,7 +7070,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer
// default tool type is finger
constexpr int32_t x1 = 100, y1 = 200, x2 = 120, y2 = 220, x3 = 140, y3 = 240;
- processId(mapper, FIRST_TRACKING_ID);
+ processId(mapper, 1);
processPosition(mapper, x1, y1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
@@ -7950,19 +7084,19 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer
ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionArgs.action);
// Ignore the following MOVE and UP events if had detect a palm event.
- processId(mapper, FIRST_TRACKING_ID);
+ processId(mapper, 1);
processPosition(mapper, x2, y2);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
// finger up.
- processId(mapper, INVALID_TRACKING_ID);
+ processId(mapper, -1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
// new finger down
- processId(mapper, FIRST_TRACKING_ID);
processToolType(mapper, MT_TOOL_FINGER);
+ processId(mapper, 1);
processPosition(mapper, x3, y3);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
@@ -7971,10 +7105,11 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer
}
/**
- * Test multi-touch should sent POINTER_UP when received the MT_TOOL_PALM event from some finger,
- * and the rest active fingers could still be allowed to receive the events
+ * Test multi-touch should be canceled when received the MT_TOOL_PALM event from some finger,
+ * and could be allowed again after all non-MT_TOOL_PALM is release and the new point is
+ * MT_TOOL_FINGER.
*/
-TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_TwoPointers) {
+TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType2) {
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareAxes(POSITION | ID | SLOT | TOOL_TYPE);
@@ -7983,85 +7118,8 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_TwoPointers)
NotifyMotionArgs motionArgs;
// default tool type is finger
- constexpr int32_t x1 = 100, y1 = 200, x2 = 120, y2 = 220;
- processId(mapper, FIRST_TRACKING_ID);
- processPosition(mapper, x1, y1);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
- ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
- // Second finger down.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, SECOND_TRACKING_ID);
- processPosition(mapper, x2, y2);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- motionArgs.action);
- ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-
- // If the tool type of the first finger changes to MT_TOOL_PALM,
- // we expect to receive ACTION_POINTER_UP with cancel flag.
- processSlot(mapper, FIRST_SLOT);
- processId(mapper, FIRST_TRACKING_ID);
- processToolType(mapper, MT_TOOL_PALM);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- motionArgs.action);
- ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, motionArgs.flags);
-
- // The following MOVE events of second finger should be processed.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, SECOND_TRACKING_ID);
- processPosition(mapper, x2 + 1, y2 + 1);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
-
- // First finger up. It used to be in palm mode, and we already generated ACTION_POINTER_UP for
- // it. Second finger receive move.
- processSlot(mapper, FIRST_SLOT);
- processId(mapper, INVALID_TRACKING_ID);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
-
- // Second finger keeps moving.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, SECOND_TRACKING_ID);
- processPosition(mapper, x2 + 2, y2 + 2);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
-
- // Second finger up.
- processId(mapper, INVALID_TRACKING_ID);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
- ASSERT_NE(AMOTION_EVENT_FLAG_CANCELED, motionArgs.flags);
-}
-
-/**
- * Test multi-touch should sent POINTER_UP when received the MT_TOOL_PALM event, if only 1 finger
- * is active, it should send CANCEL after receiving the MT_TOOL_PALM event.
- */
-TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelWhenAllTouchIsPalm) {
- addConfigurationProperty("touch.deviceType", "touchScreen");
- prepareDisplay(DISPLAY_ORIENTATION_0);
- prepareAxes(POSITION | ID | SLOT | TOOL_TYPE);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- NotifyMotionArgs motionArgs;
-
constexpr int32_t x1 = 100, y1 = 200, x2 = 120, y2 = 220, x3 = 140, y3 = 240;
- // First finger down.
- processId(mapper, FIRST_TRACKING_ID);
+ processId(mapper, 1);
processPosition(mapper, x1, y1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
@@ -8069,226 +7127,60 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelW
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
// Second finger down.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, SECOND_TRACKING_ID);
+ processSlot(mapper, 1);
processPosition(mapper, x2, y2);
+ processId(mapper, 2);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
- // If the tool type of the first finger changes to MT_TOOL_PALM,
- // we expect to receive ACTION_POINTER_UP with cancel flag.
- processSlot(mapper, FIRST_SLOT);
- processId(mapper, FIRST_TRACKING_ID);
- processToolType(mapper, MT_TOOL_PALM);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- motionArgs.action);
- ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, motionArgs.flags);
-
- // Second finger keeps moving.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, SECOND_TRACKING_ID);
- processPosition(mapper, x2 + 1, y2 + 1);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
- // second finger becomes palm, receive cancel due to only 1 finger is active.
- processId(mapper, SECOND_TRACKING_ID);
+ // If the tool type of the first pointer changes to MT_TOOL_PALM,
+ // the entire gesture should be aborted, so we expect to receive ACTION_CANCEL.
+ processSlot(mapper, 0);
+ processId(mapper, 1);
processToolType(mapper, MT_TOOL_PALM);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionArgs.action);
- // third finger down.
- processSlot(mapper, THIRD_SLOT);
- processId(mapper, THIRD_TRACKING_ID);
- processToolType(mapper, MT_TOOL_FINGER);
+ // Ignore the following MOVE and UP events if had detect a palm event.
+ processSlot(mapper, 1);
+ processId(mapper, 2);
processPosition(mapper, x3, y3);
processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
- ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
-
- // third finger move
- processId(mapper, THIRD_TRACKING_ID);
- processPosition(mapper, x3 + 1, y3 + 1);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
- // first finger up, third finger receive move.
- processSlot(mapper, FIRST_SLOT);
- processId(mapper, INVALID_TRACKING_ID);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
-
- // second finger up, third finger receive move.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, INVALID_TRACKING_ID);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
-
- // third finger up.
- processSlot(mapper, THIRD_SLOT);
- processId(mapper, INVALID_TRACKING_ID);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
- ASSERT_NE(AMOTION_EVENT_FLAG_CANCELED, motionArgs.flags);
-}
-
-/**
- * Test multi-touch should sent POINTER_UP when received the MT_TOOL_PALM event from some finger,
- * and the active finger could still be allowed to receive the events
- */
-TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_KeepFirstPointer) {
- addConfigurationProperty("touch.deviceType", "touchScreen");
- prepareDisplay(DISPLAY_ORIENTATION_0);
- prepareAxes(POSITION | ID | SLOT | TOOL_TYPE);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- NotifyMotionArgs motionArgs;
-
- // default tool type is finger
- constexpr int32_t x1 = 100, y1 = 200, x2 = 120, y2 = 220;
- processId(mapper, FIRST_TRACKING_ID);
- processPosition(mapper, x1, y1);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
- ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
- // Second finger down.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, SECOND_TRACKING_ID);
- processPosition(mapper, x2, y2);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- motionArgs.action);
- ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
- // If the tool type of the second finger changes to MT_TOOL_PALM,
- // we expect to receive ACTION_POINTER_UP with cancel flag.
- processId(mapper, SECOND_TRACKING_ID);
- processToolType(mapper, MT_TOOL_PALM);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- motionArgs.action);
- ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, motionArgs.flags);
-
- // The following MOVE event should be processed.
- processSlot(mapper, FIRST_SLOT);
- processId(mapper, FIRST_TRACKING_ID);
- processPosition(mapper, x1 + 1, y1 + 1);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
// second finger up.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, INVALID_TRACKING_ID);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
- // first finger keep moving
- processSlot(mapper, FIRST_SLOT);
- processId(mapper, FIRST_TRACKING_ID);
- processPosition(mapper, x1 + 2, y1 + 2);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
- // first finger up.
- processId(mapper, INVALID_TRACKING_ID);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
- ASSERT_NE(AMOTION_EVENT_FLAG_CANCELED, motionArgs.flags);
-}
-
-/**
- * Test multi-touch should sent ACTION_POINTER_UP/ACTION_UP when received the INVALID_TRACKING_ID,
- * to prevent the driver side may send unexpected data after set tracking id as INVALID_TRACKING_ID
- * cause slot be valid again.
- */
-TEST_F(MultiTouchInputMapperTest, Process_MultiTouch_WithInvalidTrackingId) {
- addConfigurationProperty("touch.deviceType", "touchScreen");
- prepareDisplay(DISPLAY_ORIENTATION_0);
- prepareAxes(POSITION | ID | SLOT | PRESSURE);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- NotifyMotionArgs motionArgs;
-
- constexpr int32_t x1 = 100, y1 = 200, x2 = 0, y2 = 0;
- // First finger down.
- processId(mapper, FIRST_TRACKING_ID);
- processPosition(mapper, x1, y1);
- processPressure(mapper, RAW_PRESSURE_MAX);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
-
- // First finger move.
- processId(mapper, FIRST_TRACKING_ID);
- processPosition(mapper, x1 + 1, y1 + 1);
- processPressure(mapper, RAW_PRESSURE_MAX);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
-
- // Second finger down.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, SECOND_TRACKING_ID);
- processPosition(mapper, x2, y2);
- processPressure(mapper, RAW_PRESSURE_MAX);
+ processId(mapper, -1);
processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- motionArgs.action);
- ASSERT_EQ(uint32_t(2), motionArgs.pointerCount);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
- // second finger up with some unexpected data.
- processSlot(mapper, SECOND_SLOT);
- processId(mapper, INVALID_TRACKING_ID);
- processPosition(mapper, x2, y2);
+ // first finger move, but still in palm
+ processSlot(mapper, 0);
+ processId(mapper, 1);
+ processPosition(mapper, x1 - 1, y1 - 1);
processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- motionArgs.action);
- ASSERT_EQ(uint32_t(2), motionArgs.pointerCount);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
- // first finger up with some unexpected data.
- processSlot(mapper, FIRST_SLOT);
- processId(mapper, INVALID_TRACKING_ID);
+ // second finger down, expect as new finger down.
+ processSlot(mapper, 1);
+ processId(mapper, 2);
processPosition(mapper, x2, y2);
- processPressure(mapper, RAW_PRESSURE_MAX);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
- ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
- ASSERT_EQ(uint32_t(1), motionArgs.pointerCount);
+ ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+ ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
}
// --- MultiTouchInputMapperTest_ExternalDevice ---
class MultiTouchInputMapperTest_ExternalDevice : public MultiTouchInputMapperTest {
protected:
- void SetUp() override { InputMapperTest::SetUp(DEVICE_CLASSES | InputDeviceClass::EXTERNAL); }
+ virtual void SetUp() override {
+ InputMapperTest::SetUp(DEVICE_CLASSES | INPUT_DEVICE_CLASS_EXTERNAL);
+ }
};
/**
@@ -8312,7 +7204,7 @@ TEST_F(MultiTouchInputMapperTest_ExternalDevice, Viewports_Fallback) {
ASSERT_EQ(ADISPLAY_ID_DEFAULT, motionArgs.displayId);
// Expect the event to be sent to the external viewport if it is present.
- prepareSecondaryDisplay(ViewportType::EXTERNAL);
+ prepareSecondaryDisplay(ViewportType::VIEWPORT_EXTERNAL);
processPosition(mapper, 100, 100);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
@@ -8326,7 +7218,7 @@ class MultiTouchInputMapperTest_SurfaceRange : public MultiTouchInputMapperTest
protected:
void halfDisplayToCenterHorizontal(int32_t orientation) {
std::optional<DisplayViewport> internalViewport =
- mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL);
+ mFakePolicy->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
// Half display to (width/4, 0, width * 3/4, height) to make display has offset.
internalViewport->orientation = orientation;
@@ -8362,8 +7254,8 @@ protected:
configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
}
- void processPositionAndVerify(MultiTouchInputMapper& mapper, int32_t xOutside, int32_t yOutside,
- int32_t xInside, int32_t yInside, int32_t xExpected,
+ void processPositionAndVerify(MultiTouchInputMapper& mapper, int32_t xInside, int32_t yInside,
+ int32_t xOutside, int32_t yOutside, int32_t xExpected,
int32_t yExpected) {
// touch on outside area should not work.
processPosition(mapper, toRawX(xOutside), toRawY(yOutside));
@@ -8444,464 +7336,4 @@ TEST_F(MultiTouchInputMapperTest_SurfaceRange, Viewports_SurfaceRange_270) {
constexpr int32_t yExpected = (x + 1) - DISPLAY_WIDTH / 4;
processPositionAndVerify(mapper, x - 1, y, x + 1, y, xExpected, yExpected);
}
-
-TEST_F(MultiTouchInputMapperTest_SurfaceRange, Viewports_SurfaceRange_Corner) {
- addConfigurationProperty("touch.deviceType", "touchScreen");
- prepareDisplay(DISPLAY_ORIENTATION_0);
- prepareAxes(POSITION);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- const int32_t x = 0;
- const int32_t y = 0;
-
- const int32_t xExpected = x;
- const int32_t yExpected = y;
- processPositionAndVerify(mapper, x - 1, y, x, y, xExpected, yExpected);
-
- clearViewports();
- prepareDisplay(DISPLAY_ORIENTATION_90);
- // expect x/y = swap x/y then reverse y.
- const int32_t xExpected90 = y;
- const int32_t yExpected90 = DISPLAY_WIDTH - 1;
- processPositionAndVerify(mapper, x - 1, y, x, y, xExpected90, yExpected90);
-
- clearViewports();
- prepareDisplay(DISPLAY_ORIENTATION_270);
- // expect x/y = swap x/y then reverse x.
- const int32_t xExpected270 = DISPLAY_HEIGHT - 1;
- const int32_t yExpected270 = x;
- processPositionAndVerify(mapper, x - 1, y, x, y, xExpected270, yExpected270);
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_TouchpadCapture) {
- // we need a pointer controller for mouse mode of touchpad (start pointer at 0,0)
- std::shared_ptr<FakePointerController> fakePointerController =
- std::make_shared<FakePointerController>();
- fakePointerController->setBounds(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1);
- fakePointerController->setPosition(0, 0);
- fakePointerController->setButtonState(0);
-
- // prepare device and capture
- prepareDisplay(DISPLAY_ORIENTATION_0);
- prepareAxes(POSITION | ID | SLOT);
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_LEFT, 0, AKEYCODE_UNKNOWN, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0);
- mFakePolicy->setPointerCapture(true);
- mFakePolicy->setPointerController(mDevice->getId(), fakePointerController);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- // captured touchpad should be a touchpad source
- NotifyDeviceResetArgs resetArgs;
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
- ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper.getSources());
-
- InputDeviceInfo deviceInfo = mDevice->getDeviceInfo();
-
- const InputDeviceInfo::MotionRange* relRangeX =
- deviceInfo.getMotionRange(AMOTION_EVENT_AXIS_RELATIVE_X, AINPUT_SOURCE_TOUCHPAD);
- ASSERT_NE(relRangeX, nullptr);
- ASSERT_EQ(relRangeX->min, -(RAW_X_MAX - RAW_X_MIN));
- ASSERT_EQ(relRangeX->max, RAW_X_MAX - RAW_X_MIN);
- const InputDeviceInfo::MotionRange* relRangeY =
- deviceInfo.getMotionRange(AMOTION_EVENT_AXIS_RELATIVE_Y, AINPUT_SOURCE_TOUCHPAD);
- ASSERT_NE(relRangeY, nullptr);
- ASSERT_EQ(relRangeY->min, -(RAW_Y_MAX - RAW_Y_MIN));
- ASSERT_EQ(relRangeY->max, RAW_Y_MAX - RAW_Y_MIN);
-
- // run captured pointer tests - note that this is unscaled, so input listener events should be
- // identical to what the hardware sends (accounting for any
- // calibration).
- // FINGER 0 DOWN
- processSlot(mapper, 0);
- processId(mapper, 1);
- processPosition(mapper, 100 + RAW_X_MIN, 100 + RAW_Y_MIN);
- processKey(mapper, BTN_TOUCH, 1);
- processSync(mapper);
-
- // expect coord[0] to contain initial location of touch 0
- NotifyMotionArgs args;
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
- ASSERT_EQ(1U, args.pointerCount);
- ASSERT_EQ(0, args.pointerProperties[0].id);
- ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, args.source);
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[0], 100, 100, 1, 0, 0, 0, 0, 0, 0, 0));
-
- // FINGER 1 DOWN
- processSlot(mapper, 1);
- processId(mapper, 2);
- processPosition(mapper, 560 + RAW_X_MIN, 154 + RAW_Y_MIN);
- processSync(mapper);
-
- // expect coord[0] to contain previous location, coord[1] to contain new touch 1 location
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
- args.action);
- ASSERT_EQ(2U, args.pointerCount);
- ASSERT_EQ(0, args.pointerProperties[0].id);
- ASSERT_EQ(1, args.pointerProperties[1].id);
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[0], 100, 100, 1, 0, 0, 0, 0, 0, 0, 0));
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[1], 560, 154, 1, 0, 0, 0, 0, 0, 0, 0));
-
- // FINGER 1 MOVE
- processPosition(mapper, 540 + RAW_X_MIN, 690 + RAW_Y_MIN);
- processSync(mapper);
-
- // expect coord[0] to contain previous location, coord[1] to contain new touch 1 location
- // from move
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[0], 100, 100, 1, 0, 0, 0, 0, 0, 0, 0));
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[1], 540, 690, 1, 0, 0, 0, 0, 0, 0, 0));
-
- // FINGER 0 MOVE
- processSlot(mapper, 0);
- processPosition(mapper, 50 + RAW_X_MIN, 800 + RAW_Y_MIN);
- processSync(mapper);
-
- // expect coord[0] to contain new touch 0 location, coord[1] to contain previous location
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[0], 50, 800, 1, 0, 0, 0, 0, 0, 0, 0));
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[1], 540, 690, 1, 0, 0, 0, 0, 0, 0, 0));
-
- // BUTTON DOWN
- processKey(mapper, BTN_LEFT, 1);
- processSync(mapper);
-
- // touchinputmapper design sends a move before button press
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, args.action);
-
- // BUTTON UP
- processKey(mapper, BTN_LEFT, 0);
- processSync(mapper);
-
- // touchinputmapper design sends a move after button release
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, args.action);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
-
- // FINGER 0 UP
- processId(mapper, -1);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | 0x0000, args.action);
-
- // FINGER 1 MOVE
- processSlot(mapper, 1);
- processPosition(mapper, 320 + RAW_X_MIN, 900 + RAW_Y_MIN);
- processSync(mapper);
-
- // expect coord[0] to contain new location of touch 1, and properties[0].id to contain 1
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
- ASSERT_EQ(1U, args.pointerCount);
- ASSERT_EQ(1, args.pointerProperties[0].id);
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[0], 320, 900, 1, 0, 0, 0, 0, 0, 0, 0));
-
- // FINGER 1 UP
- processId(mapper, -1);
- processKey(mapper, BTN_TOUCH, 0);
- processSync(mapper);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
-
- // non captured touchpad should be a mouse source
- mFakePolicy->setPointerCapture(false);
- configureDevice(InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
- ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper.getSources());
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_UnCapturedTouchpadPointer) {
- std::shared_ptr<FakePointerController> fakePointerController =
- std::make_shared<FakePointerController>();
- fakePointerController->setBounds(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1);
- fakePointerController->setPosition(0, 0);
- fakePointerController->setButtonState(0);
-
- // prepare device and capture
- prepareDisplay(DISPLAY_ORIENTATION_0);
- prepareAxes(POSITION | ID | SLOT);
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_LEFT, 0, AKEYCODE_UNKNOWN, 0);
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0);
- mFakePolicy->setPointerController(mDevice->getId(), fakePointerController);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
- // run uncaptured pointer tests - pushes out generic events
- // FINGER 0 DOWN
- processId(mapper, 3);
- processPosition(mapper, 100, 100);
- processKey(mapper, BTN_TOUCH, 1);
- processSync(mapper);
-
- // start at (100,100), cursor should be at (0,0) * scale
- NotifyMotionArgs args;
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(
- assertPointerCoords(args.pointerCoords[0], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
-
- // FINGER 0 MOVE
- processPosition(mapper, 200, 200);
- processSync(mapper);
-
- // compute scaling to help with touch position checking
- float rawDiagonal = hypotf(RAW_X_MAX - RAW_X_MIN, RAW_Y_MAX - RAW_Y_MIN);
- float displayDiagonal = hypotf(DISPLAY_WIDTH, DISPLAY_HEIGHT);
- float scale =
- mFakePolicy->getPointerGestureMovementSpeedRatio() * displayDiagonal / rawDiagonal;
-
- // translate from (100,100) -> (200,200), cursor should have changed to (100,100) * scale)
- ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
- ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 100 * scale, 100 * scale, 0,
- 0, 0, 0, 0, 0, 0, 0));
-}
-
-TEST_F(MultiTouchInputMapperTest, WhenCapturedAndNotCaptured_GetSources) {
- std::shared_ptr<FakePointerController> fakePointerController =
- std::make_shared<FakePointerController>();
-
- prepareDisplay(DISPLAY_ORIENTATION_0);
- prepareAxes(POSITION | ID | SLOT);
- mFakeEventHub->addKey(EVENTHUB_ID, BTN_LEFT, 0, AKEYCODE_UNKNOWN, 0);
- mFakePolicy->setPointerController(mDevice->getId(), fakePointerController);
- mFakePolicy->setPointerCapture(false);
- MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
-
- // uncaptured touchpad should be a pointer device
- ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper.getSources());
-
- // captured touchpad should be a touchpad device
- mFakePolicy->setPointerCapture(true);
- configureDevice(InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
- ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper.getSources());
-}
-
-// --- PeripheralControllerTest ---
-
-class PeripheralControllerTest : public testing::Test {
-protected:
- static const char* DEVICE_NAME;
- static const char* DEVICE_LOCATION;
- static const int32_t DEVICE_ID;
- static const int32_t DEVICE_GENERATION;
- static const int32_t DEVICE_CONTROLLER_NUMBER;
- static const Flags<InputDeviceClass> DEVICE_CLASSES;
- static const int32_t EVENTHUB_ID;
-
- std::shared_ptr<FakeEventHub> mFakeEventHub;
- sp<FakeInputReaderPolicy> mFakePolicy;
- sp<TestInputListener> mFakeListener;
- std::unique_ptr<InstrumentedInputReader> mReader;
- std::shared_ptr<InputDevice> mDevice;
-
- virtual void SetUp(Flags<InputDeviceClass> classes) {
- mFakeEventHub = std::make_unique<FakeEventHub>();
- mFakePolicy = new FakeInputReaderPolicy();
- mFakeListener = new TestInputListener();
- mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
- mFakeListener);
- mDevice = newDevice(DEVICE_ID, DEVICE_NAME, DEVICE_LOCATION, EVENTHUB_ID, classes);
- }
-
- void SetUp() override { SetUp(DEVICE_CLASSES); }
-
- void TearDown() override {
- mFakeListener.clear();
- mFakePolicy.clear();
- }
-
- void configureDevice(uint32_t changes) {
- if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
- mReader->requestRefreshConfiguration(changes);
- mReader->loopOnce();
- }
- mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), changes);
- }
-
- std::shared_ptr<InputDevice> newDevice(int32_t deviceId, const std::string& name,
- const std::string& location, int32_t eventHubId,
- Flags<InputDeviceClass> classes) {
- InputDeviceIdentifier identifier;
- identifier.name = name;
- identifier.location = location;
- std::shared_ptr<InputDevice> device =
- std::make_shared<InputDevice>(mReader->getContext(), deviceId, DEVICE_GENERATION,
- identifier);
- mReader->pushNextDevice(device);
- mFakeEventHub->addDevice(eventHubId, name, classes);
- mReader->loopOnce();
- return device;
- }
-
- template <class T, typename... Args>
- T& addControllerAndConfigure(Args... args) {
- T& controller = mDevice->addController<T>(EVENTHUB_ID, args...);
-
- return controller;
- }
-};
-
-const char* PeripheralControllerTest::DEVICE_NAME = "device";
-const char* PeripheralControllerTest::DEVICE_LOCATION = "BLUETOOTH";
-const int32_t PeripheralControllerTest::DEVICE_ID = END_RESERVED_ID + 1000;
-const int32_t PeripheralControllerTest::DEVICE_GENERATION = 2;
-const int32_t PeripheralControllerTest::DEVICE_CONTROLLER_NUMBER = 0;
-const Flags<InputDeviceClass> PeripheralControllerTest::DEVICE_CLASSES =
- Flags<InputDeviceClass>(0); // not needed for current tests
-const int32_t PeripheralControllerTest::EVENTHUB_ID = 1;
-
-// --- BatteryControllerTest ---
-class BatteryControllerTest : public PeripheralControllerTest {
-protected:
- void SetUp() override {
- PeripheralControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::BATTERY);
- }
-};
-
-TEST_F(BatteryControllerTest, GetBatteryCapacity) {
- PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
-
- ASSERT_TRUE(controller.getBatteryCapacity(DEFAULT_BATTERY));
- ASSERT_EQ(controller.getBatteryCapacity(DEFAULT_BATTERY).value_or(-1), BATTERY_CAPACITY);
-}
-
-TEST_F(BatteryControllerTest, GetBatteryStatus) {
- PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
-
- ASSERT_TRUE(controller.getBatteryStatus(DEFAULT_BATTERY));
- ASSERT_EQ(controller.getBatteryStatus(DEFAULT_BATTERY).value_or(-1), BATTERY_STATUS);
-}
-
-// --- LightControllerTest ---
-class LightControllerTest : public PeripheralControllerTest {
-protected:
- void SetUp() override {
- PeripheralControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::LIGHT);
- }
-};
-
-TEST_F(LightControllerTest, MonoLight) {
- RawLightInfo infoMono = {.id = 1,
- .name = "Mono",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS,
- .path = ""};
- mFakeEventHub->addRawLightInfo(infoMono.id, std::move(infoMono));
-
- PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
- InputDeviceInfo info;
- controller.populateDeviceInfo(&info);
- std::vector<InputDeviceLightInfo> lights = info.getLights();
- ASSERT_EQ(1U, lights.size());
- ASSERT_EQ(InputDeviceLightType::MONO, lights[0].type);
-
- ASSERT_TRUE(controller.setLightColor(lights[0].id, LIGHT_BRIGHTNESS));
- ASSERT_EQ(controller.getLightColor(lights[0].id).value_or(-1), LIGHT_BRIGHTNESS);
-}
-
-TEST_F(LightControllerTest, RGBLight) {
- RawLightInfo infoRed = {.id = 1,
- .name = "red",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS | InputLightClass::RED,
- .path = ""};
- RawLightInfo infoGreen = {.id = 2,
- .name = "green",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS | InputLightClass::GREEN,
- .path = ""};
- RawLightInfo infoBlue = {.id = 3,
- .name = "blue",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS | InputLightClass::BLUE,
- .path = ""};
- mFakeEventHub->addRawLightInfo(infoRed.id, std::move(infoRed));
- mFakeEventHub->addRawLightInfo(infoGreen.id, std::move(infoGreen));
- mFakeEventHub->addRawLightInfo(infoBlue.id, std::move(infoBlue));
-
- PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
- InputDeviceInfo info;
- controller.populateDeviceInfo(&info);
- std::vector<InputDeviceLightInfo> lights = info.getLights();
- ASSERT_EQ(1U, lights.size());
- ASSERT_EQ(InputDeviceLightType::RGB, lights[0].type);
-
- ASSERT_TRUE(controller.setLightColor(lights[0].id, LIGHT_COLOR));
- ASSERT_EQ(controller.getLightColor(lights[0].id).value_or(-1), LIGHT_COLOR);
-}
-
-TEST_F(LightControllerTest, MultiColorRGBLight) {
- RawLightInfo infoColor = {.id = 1,
- .name = "red",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS |
- InputLightClass::MULTI_INTENSITY |
- InputLightClass::MULTI_INDEX,
- .path = ""};
-
- mFakeEventHub->addRawLightInfo(infoColor.id, std::move(infoColor));
-
- PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
- InputDeviceInfo info;
- controller.populateDeviceInfo(&info);
- std::vector<InputDeviceLightInfo> lights = info.getLights();
- ASSERT_EQ(1U, lights.size());
- ASSERT_EQ(InputDeviceLightType::MULTI_COLOR, lights[0].type);
-
- ASSERT_TRUE(controller.setLightColor(lights[0].id, LIGHT_COLOR));
- ASSERT_EQ(controller.getLightColor(lights[0].id).value_or(-1), LIGHT_COLOR);
-}
-
-TEST_F(LightControllerTest, PlayerIdLight) {
- RawLightInfo info1 = {.id = 1,
- .name = "player1",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS,
- .path = ""};
- RawLightInfo info2 = {.id = 2,
- .name = "player2",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS,
- .path = ""};
- RawLightInfo info3 = {.id = 3,
- .name = "player3",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS,
- .path = ""};
- RawLightInfo info4 = {.id = 4,
- .name = "player4",
- .maxBrightness = 255,
- .flags = InputLightClass::BRIGHTNESS,
- .path = ""};
- mFakeEventHub->addRawLightInfo(info1.id, std::move(info1));
- mFakeEventHub->addRawLightInfo(info2.id, std::move(info2));
- mFakeEventHub->addRawLightInfo(info3.id, std::move(info3));
- mFakeEventHub->addRawLightInfo(info4.id, std::move(info4));
-
- PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
- InputDeviceInfo info;
- controller.populateDeviceInfo(&info);
- std::vector<InputDeviceLightInfo> lights = info.getLights();
- ASSERT_EQ(1U, lights.size());
- ASSERT_EQ(InputDeviceLightType::PLAYER_ID, lights[0].type);
-
- ASSERT_FALSE(controller.setLightColor(lights[0].id, LIGHT_COLOR));
- ASSERT_TRUE(controller.setLightPlayerId(lights[0].id, LIGHT_PLAYER_ID));
- ASSERT_EQ(controller.getLightPlayerId(lights[0].id).value_or(-1), LIGHT_PLAYER_ID);
-}
-
} // namespace android
diff --git a/services/inputflinger/tests/LatencyTracker_test.cpp b/services/inputflinger/tests/LatencyTracker_test.cpp
deleted file mode 100644
index e7e1937235..0000000000
--- a/services/inputflinger/tests/LatencyTracker_test.cpp
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "../dispatcher/LatencyTracker.h"
-
-#include <binder/Binder.h>
-#include <gtest/gtest.h>
-#include <inttypes.h>
-#include <log/log.h>
-
-#define TAG "LatencyTracker_test"
-
-using android::inputdispatcher::InputEventTimeline;
-using android::inputdispatcher::LatencyTracker;
-
-namespace android::inputdispatcher {
-
-InputEventTimeline getTestTimeline() {
- InputEventTimeline t(
- /*isDown*/ true,
- /*eventTime*/ 2,
- /*readTime*/ 3);
- ConnectionTimeline expectedCT(/*deliveryTime*/ 6, /* consumeTime*/ 7, /*finishTime*/ 8);
- std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
- graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 9;
- graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 10;
- expectedCT.setGraphicsTimeline(std::move(graphicsTimeline));
- t.connectionTimelines.emplace(new BBinder(), std::move(expectedCT));
- return t;
-}
-
-// --- LatencyTrackerTest ---
-class LatencyTrackerTest : public testing::Test, public InputEventTimelineProcessor {
-protected:
- std::unique_ptr<LatencyTracker> mTracker;
- sp<IBinder> connection1;
- sp<IBinder> connection2;
-
- void SetUp() override {
- connection1 = new BBinder();
- connection2 = new BBinder();
-
- mTracker = std::make_unique<LatencyTracker>(this);
- }
- void TearDown() override {}
-
- void assertReceivedTimeline(const InputEventTimeline& timeline);
- /**
- * Timelines can be received in any order (order is not guaranteed). So if we are expecting more
- * than 1 timeline, use this function to check that the set of received timelines matches
- * what we expected.
- */
- void assertReceivedTimelines(const std::vector<InputEventTimeline>& timelines);
-
-private:
- void processTimeline(const InputEventTimeline& timeline) override {
- mReceivedTimelines.push_back(timeline);
- }
- std::deque<InputEventTimeline> mReceivedTimelines;
-};
-
-void LatencyTrackerTest::assertReceivedTimeline(const InputEventTimeline& timeline) {
- mTracker->reportNow();
- ASSERT_FALSE(mReceivedTimelines.empty());
- const InputEventTimeline& t = mReceivedTimelines.front();
- ASSERT_EQ(timeline, t);
- mReceivedTimelines.pop_front();
-}
-
-/**
- * We are essentially comparing two multisets, but without constructing them.
- * This comparison is inefficient, but it avoids having to construct a set, and also avoids the
- * declaration of copy constructor for ConnectionTimeline.
- * We ensure that collections A and B have the same size, that for every element in A, there is an
- * equal element in B, and for every element in B there is an equal element in A.
- */
-void LatencyTrackerTest::assertReceivedTimelines(const std::vector<InputEventTimeline>& timelines) {
- mTracker->reportNow();
- ASSERT_EQ(timelines.size(), mReceivedTimelines.size());
- for (const InputEventTimeline& expectedTimeline : timelines) {
- bool found = false;
- for (const InputEventTimeline& receivedTimeline : mReceivedTimelines) {
- if (receivedTimeline == expectedTimeline) {
- found = true;
- break;
- }
- }
- ASSERT_TRUE(found) << "Could not find expected timeline with eventTime="
- << expectedTimeline.eventTime;
- }
- for (const InputEventTimeline& receivedTimeline : mReceivedTimelines) {
- bool found = false;
- for (const InputEventTimeline& expectedTimeline : timelines) {
- if (receivedTimeline == expectedTimeline) {
- found = true;
- break;
- }
- }
- ASSERT_TRUE(found) << "Could not find received timeline with eventTime="
- << receivedTimeline.eventTime;
- }
- mReceivedTimelines.clear();
-}
-
-/**
- * Ensure that calling 'trackListener' in isolation only creates an inputflinger timeline, without
- * any additional ConnectionTimeline's.
- */
-TEST_F(LatencyTrackerTest, TrackListener_DoesNotTriggerReporting) {
- mTracker->trackListener(1 /*inputEventId*/, false /*isDown*/, 2 /*eventTime*/, 3 /*readTime*/);
- assertReceivedTimeline(InputEventTimeline{false, 2, 3});
-}
-
-/**
- * A single call to trackFinishedEvent should not cause a timeline to be reported.
- */
-TEST_F(LatencyTrackerTest, TrackFinishedEvent_DoesNotTriggerReporting) {
- mTracker->trackFinishedEvent(1 /*inputEventId*/, connection1, 2 /*deliveryTime*/,
- 3 /*consumeTime*/, 4 /*finishTime*/);
- assertReceivedTimelines({});
-}
-
-/**
- * A single call to trackGraphicsLatency should not cause a timeline to be reported.
- */
-TEST_F(LatencyTrackerTest, TrackGraphicsLatency_DoesNotTriggerReporting) {
- std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
- graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 2;
- graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 3;
- mTracker->trackGraphicsLatency(1 /*inputEventId*/, connection2, graphicsTimeline);
- assertReceivedTimelines({});
-}
-
-TEST_F(LatencyTrackerTest, TrackAllParameters_ReportsFullTimeline) {
- constexpr int32_t inputEventId = 1;
- InputEventTimeline expected = getTestTimeline();
-
- const auto& [connectionToken, expectedCT] = *expected.connectionTimelines.begin();
-
- mTracker->trackListener(inputEventId, expected.isDown, expected.eventTime, expected.readTime);
- mTracker->trackFinishedEvent(inputEventId, connectionToken, expectedCT.deliveryTime,
- expectedCT.consumeTime, expectedCT.finishTime);
- mTracker->trackGraphicsLatency(inputEventId, connectionToken, expectedCT.graphicsTimeline);
-
- assertReceivedTimeline(expected);
-}
-
-TEST_F(LatencyTrackerTest, MultipleEvents_AreReportedConsistently) {
- constexpr int32_t inputEventId1 = 1;
- InputEventTimeline timeline1(
- /*isDown*/ true,
- /*eventTime*/ 2,
- /*readTime*/ 3);
- timeline1.connectionTimelines.emplace(connection1,
- ConnectionTimeline(/*deliveryTime*/ 6, /*consumeTime*/ 7,
- /*finishTime*/ 8));
- ConnectionTimeline& connectionTimeline1 = timeline1.connectionTimelines.begin()->second;
- std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline1;
- graphicsTimeline1[GraphicsTimeline::GPU_COMPLETED_TIME] = 9;
- graphicsTimeline1[GraphicsTimeline::PRESENT_TIME] = 10;
- connectionTimeline1.setGraphicsTimeline(std::move(graphicsTimeline1));
-
- constexpr int32_t inputEventId2 = 10;
- InputEventTimeline timeline2(
- /*isDown*/ false,
- /*eventTime*/ 20,
- /*readTime*/ 30);
- timeline2.connectionTimelines.emplace(connection2,
- ConnectionTimeline(/*deliveryTime*/ 60,
- /*consumeTime*/ 70,
- /*finishTime*/ 80));
- ConnectionTimeline& connectionTimeline2 = timeline2.connectionTimelines.begin()->second;
- std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline2;
- graphicsTimeline2[GraphicsTimeline::GPU_COMPLETED_TIME] = 90;
- graphicsTimeline2[GraphicsTimeline::PRESENT_TIME] = 100;
- connectionTimeline2.setGraphicsTimeline(std::move(graphicsTimeline2));
-
- // Start processing first event
- mTracker->trackListener(inputEventId1, timeline1.isDown, timeline1.eventTime,
- timeline1.readTime);
- // Start processing second event
- mTracker->trackListener(inputEventId2, timeline2.isDown, timeline2.eventTime,
- timeline2.readTime);
- mTracker->trackFinishedEvent(inputEventId1, connection1, connectionTimeline1.deliveryTime,
- connectionTimeline1.consumeTime, connectionTimeline1.finishTime);
-
- mTracker->trackFinishedEvent(inputEventId2, connection2, connectionTimeline2.deliveryTime,
- connectionTimeline2.consumeTime, connectionTimeline2.finishTime);
- mTracker->trackGraphicsLatency(inputEventId1, connection1,
- connectionTimeline1.graphicsTimeline);
- mTracker->trackGraphicsLatency(inputEventId2, connection2,
- connectionTimeline2.graphicsTimeline);
- // Now both events should be completed
- assertReceivedTimelines({timeline1, timeline2});
-}
-
-/**
- * Check that LatencyTracker consistently tracks events even if there are many incomplete events.
- */
-TEST_F(LatencyTrackerTest, IncompleteEvents_AreHandledConsistently) {
- InputEventTimeline timeline = getTestTimeline();
- std::vector<InputEventTimeline> expectedTimelines;
- const ConnectionTimeline& expectedCT = timeline.connectionTimelines.begin()->second;
- const sp<IBinder>& token = timeline.connectionTimelines.begin()->first;
-
- for (size_t i = 1; i <= 100; i++) {
- mTracker->trackListener(i /*inputEventId*/, timeline.isDown, timeline.eventTime,
- timeline.readTime);
- expectedTimelines.push_back(
- InputEventTimeline{timeline.isDown, timeline.eventTime, timeline.readTime});
- }
- // Now, complete the first event that was sent.
- mTracker->trackFinishedEvent(1 /*inputEventId*/, token, expectedCT.deliveryTime,
- expectedCT.consumeTime, expectedCT.finishTime);
- mTracker->trackGraphicsLatency(1 /*inputEventId*/, token, expectedCT.graphicsTimeline);
-
- expectedTimelines[0].connectionTimelines.emplace(token, std::move(expectedCT));
- assertReceivedTimelines(expectedTimelines);
-}
-
-/**
- * For simplicity of the implementation, LatencyTracker only starts tracking an event when
- * 'trackListener' is invoked.
- * Both 'trackFinishedEvent' and 'trackGraphicsLatency' should not start a new event.
- * If they are received before 'trackListener' (which should not be possible), they are ignored.
- */
-TEST_F(LatencyTrackerTest, EventsAreTracked_WhenTrackListenerIsCalledFirst) {
- constexpr int32_t inputEventId = 1;
- InputEventTimeline expected = getTestTimeline();
- const ConnectionTimeline& expectedCT = expected.connectionTimelines.begin()->second;
- mTracker->trackFinishedEvent(inputEventId, connection1, expectedCT.deliveryTime,
- expectedCT.consumeTime, expectedCT.finishTime);
- mTracker->trackGraphicsLatency(inputEventId, connection1, expectedCT.graphicsTimeline);
-
- mTracker->trackListener(inputEventId, expected.isDown, expected.eventTime, expected.readTime);
- assertReceivedTimeline(
- InputEventTimeline{expected.isDown, expected.eventTime, expected.readTime});
-}
-
-} // namespace android::inputdispatcher
diff --git a/services/inputflinger/tests/TestInputListener.cpp b/services/inputflinger/tests/TestInputListener.cpp
index fb7de97b49..9bff166565 100644
--- a/services/inputflinger/tests/TestInputListener.cpp
+++ b/services/inputflinger/tests/TestInputListener.cpp
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-#include "TestInputListener.h"
#include <gtest/gtest.h>
+#include "TestInputListener.h"
+
namespace android {
// --- TestInputListener ---
@@ -27,7 +28,7 @@ TestInputListener::TestInputListener(std::chrono::milliseconds eventHappenedTime
: mEventHappenedTimeout(eventHappenedTimeout),
mEventDidNotHappenTimeout(eventDidNotHappenTimeout) {}
-TestInputListener::~TestInputListener() {}
+TestInputListener::~TestInputListener() { }
void TestInputListener::assertNotifyConfigurationChangedWasCalled(
NotifyConfigurationChangedArgs* outEventArgs) {
@@ -42,7 +43,8 @@ void TestInputListener::assertNotifyConfigurationChangedWasNotCalled() {
"notifyConfigurationChanged() should not be called."));
}
-void TestInputListener::assertNotifyDeviceResetWasCalled(NotifyDeviceResetArgs* outEventArgs) {
+void TestInputListener::assertNotifyDeviceResetWasCalled(
+ NotifyDeviceResetArgs* outEventArgs) {
ASSERT_NO_FATAL_FAILURE(
assertCalled<
NotifyDeviceResetArgs>(outEventArgs,
@@ -71,7 +73,7 @@ void TestInputListener::assertNotifyMotionWasCalled(NotifyMotionArgs* outEventAr
void TestInputListener::assertNotifyMotionWasNotCalled() {
ASSERT_NO_FATAL_FAILURE(
- assertNotCalled<NotifyMotionArgs>("notifyMotion() should not be called."));
+ assertNotCalled<NotifySwitchArgs>("notifySwitch() should not be called."));
}
void TestInputListener::assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs) {
@@ -80,26 +82,6 @@ void TestInputListener::assertNotifySwitchWasCalled(NotifySwitchArgs* outEventAr
"Expected notifySwitch() to have been called."));
}
-void TestInputListener::assertNotifySensorWasCalled(NotifySensorArgs* outEventArgs) {
- ASSERT_NO_FATAL_FAILURE(
- assertCalled<NotifySensorArgs>(outEventArgs,
- "Expected notifySensor() to have been called."));
-}
-
-void TestInputListener::assertNotifyVibratorStateWasCalled(NotifyVibratorStateArgs* outEventArgs) {
- ASSERT_NO_FATAL_FAILURE(assertCalled<NotifyVibratorStateArgs>(outEventArgs,
- "Expected notifyVibratorState() "
- "to have been called."));
-}
-
-void TestInputListener::assertNotifyCaptureWasCalled(
- NotifyPointerCaptureChangedArgs* outEventArgs) {
- ASSERT_NO_FATAL_FAILURE(
- assertCalled<NotifyPointerCaptureChangedArgs>(outEventArgs,
- "Expected notifyPointerCaptureChanged() "
- "to have been called."));
-}
-
template <class NotifyArgsType>
void TestInputListener::assertCalled(NotifyArgsType* outEventArgs, std::string message) {
std::unique_lock<std::mutex> lock(mLock);
@@ -163,16 +145,4 @@ void TestInputListener::notifySwitch(const NotifySwitchArgs* args) {
notify<NotifySwitchArgs>(args);
}
-void TestInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) {
- notify<NotifyPointerCaptureChangedArgs>(args);
-}
-
-void TestInputListener::notifySensor(const NotifySensorArgs* args) {
- notify<NotifySensorArgs>(args);
-}
-
-void TestInputListener::notifyVibratorState(const NotifyVibratorStateArgs* args) {
- notify<NotifyVibratorStateArgs>(args);
-}
-
} // namespace android
diff --git a/services/inputflinger/tests/TestInputListener.h b/services/inputflinger/tests/TestInputListener.h
index 0ffcaaa527..d50c6bcd51 100644
--- a/services/inputflinger/tests/TestInputListener.h
+++ b/services/inputflinger/tests/TestInputListener.h
@@ -54,10 +54,6 @@ public:
void assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs = nullptr);
- void assertNotifyCaptureWasCalled(NotifyPointerCaptureChangedArgs* outEventArgs = nullptr);
- void assertNotifySensorWasCalled(NotifySensorArgs* outEventArgs = nullptr);
- void assertNotifyVibratorStateWasCalled(NotifyVibratorStateArgs* outEventArgs = nullptr);
-
private:
template <class NotifyArgsType>
void assertCalled(NotifyArgsType* outEventArgs, std::string message);
@@ -78,25 +74,16 @@ private:
virtual void notifySwitch(const NotifySwitchArgs* args) override;
- virtual void notifySensor(const NotifySensorArgs* args) override;
-
- virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) override;
-
- virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
-
std::mutex mLock;
std::condition_variable mCondition;
const std::chrono::milliseconds mEventHappenedTimeout;
const std::chrono::milliseconds mEventDidNotHappenTimeout;
- std::tuple<std::vector<NotifyConfigurationChangedArgs>, //
- std::vector<NotifyDeviceResetArgs>, //
- std::vector<NotifyKeyArgs>, //
- std::vector<NotifyMotionArgs>, //
- std::vector<NotifySwitchArgs>, //
- std::vector<NotifySensorArgs>, //
- std::vector<NotifyVibratorStateArgs>, //
- std::vector<NotifyPointerCaptureChangedArgs>> //
+ std::tuple<std::vector<NotifyConfigurationChangedArgs>, //
+ std::vector<NotifyDeviceResetArgs>, //
+ std::vector<NotifyKeyArgs>, //
+ std::vector<NotifyMotionArgs>, //
+ std::vector<NotifySwitchArgs>> //
mQueues GUARDED_BY(mLock);
};
diff --git a/services/inputflinger/tests/UinputDevice.cpp b/services/inputflinger/tests/UinputDevice.cpp
index 7fec2c8b4b..0659511d25 100644
--- a/services/inputflinger/tests/UinputDevice.cpp
+++ b/services/inputflinger/tests/UinputDevice.cpp
@@ -179,11 +179,6 @@ void UinputTouchScreen::sendMove(const Point& point) {
injectEvent(EV_SYN, SYN_REPORT, 0);
}
-void UinputTouchScreen::sendPointerUp() {
- sendTrackingId(0xffffffff);
- injectEvent(EV_SYN, SYN_REPORT, 0);
-}
-
void UinputTouchScreen::sendUp() {
sendTrackingId(0xffffffff);
injectEvent(EV_KEY, BTN_TOUCH, 0);
diff --git a/services/inputflinger/tests/UinputDevice.h b/services/inputflinger/tests/UinputDevice.h
index 01a557cc70..22d1f630fc 100644
--- a/services/inputflinger/tests/UinputDevice.h
+++ b/services/inputflinger/tests/UinputDevice.h
@@ -139,7 +139,6 @@ public:
void sendTrackingId(int32_t trackingId);
void sendDown(const Point& point);
void sendMove(const Point& point);
- void sendPointerUp();
void sendUp();
void sendToolType(int32_t toolType);