diff options
112 files changed, 1147 insertions, 1036 deletions
diff --git a/include/input/DisplayViewport.h b/include/input/DisplayViewport.h index b0eceefba0..97c2ab8451 100644 --- a/include/input/DisplayViewport.h +++ b/include/input/DisplayViewport.h @@ -19,7 +19,6 @@ #include <android-base/stringprintf.h> #include <ftl/enum.h> #include <ftl/string.h> -#include <gui/constants.h> #include <input/Input.h> #include <ui/Rotation.h> @@ -47,7 +46,7 @@ enum class ViewportType : int32_t { * See com.android.server.display.DisplayViewport. */ struct DisplayViewport { - int32_t displayId; // -1 if invalid + ui::LogicalDisplayId displayId; // ADISPLAY_ID_NONE if invalid ui::Rotation orientation; int32_t logicalLeft; int32_t logicalTop; @@ -67,7 +66,7 @@ struct DisplayViewport { ViewportType type; DisplayViewport() - : displayId(ADISPLAY_ID_NONE), + : displayId(ui::ADISPLAY_ID_NONE), orientation(ui::ROTATION_0), logicalLeft(0), logicalTop(0), @@ -99,12 +98,10 @@ struct DisplayViewport { return !(*this == other); } - inline bool isValid() const { - return displayId >= 0; - } + inline bool isValid() const { return displayId.isValid(); } void setNonDisplayViewport(int32_t width, int32_t height) { - displayId = ADISPLAY_ID_NONE; + displayId = ui::ADISPLAY_ID_NONE; orientation = ui::ROTATION_0; logicalLeft = 0; logicalTop = 0; @@ -123,12 +120,13 @@ struct DisplayViewport { } std::string toString() const { - return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, " + return StringPrintf("Viewport %s: displayId=%s, uniqueId=%s, port=%s, orientation=%d, " "logicalFrame=[%d, %d, %d, %d], " "physicalFrame=[%d, %d, %d, %d], " "deviceSize=[%d, %d], " "isActive=[%d]", - ftl::enum_string(type).c_str(), displayId, uniqueId.c_str(), + ftl::enum_string(type).c_str(), displayId.toString().c_str(), + uniqueId.c_str(), physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>", static_cast<int>(orientation), logicalLeft, logicalTop, logicalRight, logicalBottom, physicalLeft, physicalTop, physicalRight, physicalBottom, diff --git a/include/input/Input.h b/include/input/Input.h index 3f81fb05fd..092a6982ed 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -29,6 +29,7 @@ #include <android/os/PointerIconType.h> #include <math.h> #include <stdint.h> +#include <ui/LogicalDisplayId.h> #include <ui/Transform.h> #include <utils/BitSet.h> #include <utils/Timers.h> @@ -547,9 +548,9 @@ public: inline void setSource(uint32_t source) { mSource = source; } - inline int32_t getDisplayId() const { return mDisplayId; } + inline ui::LogicalDisplayId getDisplayId() const { return mDisplayId; } - inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; } + inline void setDisplayId(ui::LogicalDisplayId displayId) { mDisplayId = displayId; } inline std::array<uint8_t, 32> getHmac() const { return mHmac; } @@ -558,7 +559,7 @@ public: bool operator==(const InputEvent&) const = default; protected: - void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId, + void initialize(int32_t id, DeviceId deviceId, uint32_t source, ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac); void initialize(const InputEvent& from); @@ -566,7 +567,7 @@ protected: int32_t mId; DeviceId mDeviceId; uint32_t mSource; - int32_t mDisplayId; + ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_NONE}; std::array<uint8_t, 32> mHmac; }; @@ -602,7 +603,7 @@ public: static const char* getLabel(int32_t keyCode); static std::optional<int> getKeyCodeFromLabel(const char* label); - void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId, + void initialize(int32_t id, DeviceId deviceId, uint32_t source, ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); @@ -864,7 +865,7 @@ public: ssize_t findPointerIndex(int32_t pointerId) const; - void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId, + void initialize(int32_t id, DeviceId deviceId, uint32_t source, ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, const ui::Transform& transform, @@ -1073,7 +1074,7 @@ struct __attribute__((__packed__)) VerifiedInputEvent { DeviceId deviceId; nsecs_t eventTimeNanos; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId; }; /** diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h index e93fe8c2dd..8783d9c192 100644 --- a/include/input/InputDevice.h +++ b/include/input/InputDevice.h @@ -280,7 +280,7 @@ public: void initialize(int32_t id, int32_t generation, int32_t controllerNumber, const InputDeviceIdentifier& identifier, const std::string& alias, - bool isExternal, bool hasMic, int32_t associatedDisplayId, + bool isExternal, bool hasMic, ui::LogicalDisplayId associatedDisplayId, InputDeviceViewBehavior viewBehavior = {{}}, bool enabled = true); inline int32_t getId() const { return mId; } @@ -348,7 +348,7 @@ public: } inline std::optional<InputDeviceUsiVersion> getUsiVersion() const { return mUsiVersion; } - inline int32_t getAssociatedDisplayId() const { return mAssociatedDisplayId; } + inline ui::LogicalDisplayId getAssociatedDisplayId() const { return mAssociatedDisplayId; } inline void setEnabled(bool enabled) { mEnabled = enabled; } inline bool isEnabled() const { return mEnabled; } @@ -366,7 +366,7 @@ private: int32_t mKeyboardType; std::shared_ptr<KeyCharacterMap> mKeyCharacterMap; std::optional<InputDeviceUsiVersion> mUsiVersion; - int32_t mAssociatedDisplayId; + ui::LogicalDisplayId mAssociatedDisplayId{ui::ADISPLAY_ID_NONE}; bool mEnabled; bool mHasVibrator; diff --git a/include/input/InputEventBuilders.h b/include/input/InputEventBuilders.h index c0c5e2412d..837e70e114 100644 --- a/include/input/InputEventBuilders.h +++ b/include/input/InputEventBuilders.h @@ -18,7 +18,6 @@ #include <android/input.h> #include <attestation/HmacKeyManager.h> -#include <gui/constants.h> #include <input/Input.h> #include <utils/Timers.h> // for nsecs_t, systemTime @@ -83,7 +82,7 @@ public: return *this; } - MotionEventBuilder& displayId(int32_t displayId) { + MotionEventBuilder& displayId(ui::LogicalDisplayId displayId) { mDisplayId = displayId; return *this; } @@ -159,7 +158,7 @@ private: int32_t mSource; nsecs_t mDownTime; nsecs_t mEventTime; - int32_t mDisplayId{ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT}; int32_t mActionButton{0}; int32_t mButtonState{0}; int32_t mFlags{0}; @@ -209,7 +208,7 @@ public: return *this; } - KeyEventBuilder& displayId(int32_t displayId) { + KeyEventBuilder& displayId(ui::LogicalDisplayId displayId) { mDisplayId = displayId; return *this; } @@ -248,7 +247,7 @@ private: uint32_t mSource; nsecs_t mDownTime; nsecs_t mEventTime; - int32_t mDisplayId{ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT}; uint32_t mPolicyFlags = DEFAULT_POLICY_FLAGS; int32_t mFlags{0}; int32_t mKeyCode{AKEYCODE_UNKNOWN}; diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index 5f9c8f5a5c..6548810ca8 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -353,9 +353,10 @@ public: * Other errors probably indicate that the channel is broken. */ status_t publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, - int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, - int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, - int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); + ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac, + int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, + int32_t metaState, int32_t repeatCount, nsecs_t downTime, + nsecs_t eventTime); /* Publishes a motion event to the input channel. * @@ -366,9 +367,9 @@ public: * Other errors probably indicate that the channel is broken. */ status_t publishMotionEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, - int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, - int32_t actionButton, int32_t flags, int32_t edgeFlags, - int32_t metaState, int32_t buttonState, + ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac, + int32_t action, int32_t actionButton, int32_t flags, + int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, const ui::Transform& transform, float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, const ui::Transform& rawTransform, diff --git a/libs/gui/DisplayInfo.cpp b/libs/gui/DisplayInfo.cpp index bd640df81e..47cec0778e 100644 --- a/libs/gui/DisplayInfo.cpp +++ b/libs/gui/DisplayInfo.cpp @@ -37,8 +37,9 @@ status_t DisplayInfo::readFromParcel(const android::Parcel* parcel) { return BAD_VALUE; } + int32_t displayIdInt; float dsdx, dtdx, tx, dtdy, dsdy, ty; - SAFE_PARCEL(parcel->readInt32, &displayId); + SAFE_PARCEL(parcel->readInt32, &displayIdInt); SAFE_PARCEL(parcel->readInt32, &logicalWidth); SAFE_PARCEL(parcel->readInt32, &logicalHeight); SAFE_PARCEL(parcel->readFloat, &dsdx); @@ -48,6 +49,7 @@ status_t DisplayInfo::readFromParcel(const android::Parcel* parcel) { SAFE_PARCEL(parcel->readFloat, &dsdy); SAFE_PARCEL(parcel->readFloat, &ty); + displayId = ui::LogicalDisplayId{displayIdInt}; transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); return OK; @@ -59,7 +61,7 @@ status_t DisplayInfo::writeToParcel(android::Parcel* parcel) const { return BAD_VALUE; } - SAFE_PARCEL(parcel->writeInt32, displayId); + SAFE_PARCEL(parcel->writeInt32, displayId.val()); SAFE_PARCEL(parcel->writeInt32, logicalWidth); SAFE_PARCEL(parcel->writeInt32, logicalHeight); SAFE_PARCEL(parcel->writeFloat, transform.dsdx()); @@ -76,7 +78,7 @@ void DisplayInfo::dump(std::string& out, const char* prefix) const { using android::base::StringAppendF; out += prefix; - StringAppendF(&out, "DisplayViewport[id=%" PRId32 "]\n", displayId); + StringAppendF(&out, "DisplayViewport[id=%s]\n", displayId.toString().c_str()); out += prefix; StringAppendF(&out, INDENT "Width=%" PRId32 ", Height=%" PRId32 "\n", logicalWidth, logicalHeight); diff --git a/libs/gui/WindowInfo.cpp b/libs/gui/WindowInfo.cpp index ad0d99d11e..82d2554340 100644 --- a/libs/gui/WindowInfo.cpp +++ b/libs/gui/WindowInfo.cpp @@ -146,7 +146,7 @@ status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { parcel->writeInt32(ownerUid.val()) ?: parcel->writeUtf8AsUtf16(packageName) ?: parcel->writeInt32(inputConfig.get()) ?: - parcel->writeInt32(displayId) ?: + parcel->writeInt32(displayId.val()) ?: applicationInfo.writeToParcel(parcel) ?: parcel->write(touchableRegion) ?: parcel->writeBool(replaceTouchableRegionWithCrop) ?: @@ -175,7 +175,8 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { } float dsdx, dtdx, tx, dtdy, dsdy, ty; - int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerPidInt, ownerUidInt; + int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerPidInt, ownerUidInt, + displayIdInt; sp<IBinder> touchableRegionCropHandleSp; // clang-format off @@ -198,7 +199,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { parcel->readInt32(&ownerUidInt) ?: parcel->readUtf8FromUtf16(&packageName) ?: parcel->readInt32(&inputConfigInt) ?: - parcel->readInt32(&displayId) ?: + parcel->readInt32(&displayIdInt) ?: applicationInfo.readFromParcel(parcel) ?: parcel->read(touchableRegion) ?: parcel->readBool(&replaceTouchableRegionWithCrop) ?: @@ -221,6 +222,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { ownerPid = Pid{ownerPidInt}; ownerUid = Uid{static_cast<uid_t>(ownerUidInt)}; touchableRegionCropHandle = touchableRegionCropHandleSp; + displayId = ui::LogicalDisplayId{displayIdInt}; return OK; } diff --git a/libs/gui/include/gui/DisplayInfo.h b/libs/gui/include/gui/DisplayInfo.h index 42b62c755c..7282b807a4 100644 --- a/libs/gui/include/gui/DisplayInfo.h +++ b/libs/gui/include/gui/DisplayInfo.h @@ -18,7 +18,7 @@ #include <binder/Parcel.h> #include <binder/Parcelable.h> -#include <gui/constants.h> +#include <ui/LogicalDisplayId.h> #include <ui/Transform.h> namespace android::gui { @@ -29,7 +29,7 @@ namespace android::gui { * This should only be used by InputFlinger to support raw coordinates in logical display space. */ struct DisplayInfo : public Parcelable { - int32_t displayId = ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; // Logical display dimensions. int32_t logicalWidth = 0; diff --git a/libs/gui/include/gui/WindowInfo.h b/libs/gui/include/gui/WindowInfo.h index b73e497032..3ea3f67bd8 100644 --- a/libs/gui/include/gui/WindowInfo.h +++ b/libs/gui/include/gui/WindowInfo.h @@ -23,7 +23,7 @@ #include <ftl/flags.h> #include <ftl/mixins.h> #include <gui/PidUid.h> -#include <gui/constants.h> +#include <ui/LogicalDisplayId.h> #include <ui/Rect.h> #include <ui/Region.h> #include <ui/Size.h> @@ -234,7 +234,7 @@ struct WindowInfo : public Parcelable { Uid ownerUid = Uid::INVALID; std::string packageName; ftl::Flags<InputConfig> inputConfig; - int32_t displayId = ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; InputApplicationInfo applicationInfo; bool replaceTouchableRegionWithCrop = false; wp<IBinder> touchableRegionCropHandle; diff --git a/libs/gui/include/gui/constants.h b/libs/gui/include/gui/constants.h deleted file mode 100644 index 8eab3783e9..0000000000 --- a/libs/gui/include/gui/constants.h +++ /dev/null @@ -1,37 +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. - */ - -#pragma once - -#include <stdint.h> - -namespace android { - -/** - * Invalid value for display size. Used when display size isn't available. - */ -constexpr int32_t INVALID_DISPLAY_SIZE = 0; - -enum { - /* Used when an event is not associated with any display. - * Typically used for non-pointer events. */ - ADISPLAY_ID_NONE = -1, - - /* The default display id. */ - ADISPLAY_ID_DEFAULT = 0, -}; - -} // namespace android
\ No newline at end of file diff --git a/libs/gui/tests/DisplayInfo_test.cpp b/libs/gui/tests/DisplayInfo_test.cpp index df3329cd52..4df76b1591 100644 --- a/libs/gui/tests/DisplayInfo_test.cpp +++ b/libs/gui/tests/DisplayInfo_test.cpp @@ -28,7 +28,7 @@ namespace test { TEST(DisplayInfo, Parcelling) { DisplayInfo info; - info.displayId = 42; + info.displayId = ui::LogicalDisplayId{42}; info.logicalWidth = 99; info.logicalHeight = 78; info.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1}); diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp index f441eaa95a..c0e79655f8 100644 --- a/libs/gui/tests/EndToEndNativeInputTest.cpp +++ b/libs/gui/tests/EndToEndNativeInputTest.cpp @@ -59,8 +59,16 @@ using android::gui::FocusRequest; using android::gui::InputApplicationInfo; using android::gui::TouchOcclusionMode; using android::gui::WindowInfo; +using android::ui::ADISPLAY_ID_DEFAULT; +using android::ui::ADISPLAY_ID_NONE; -namespace android::test { +namespace android { +namespace { +ui::LogicalDisplayId toDisplayId(ui::LayerStack layerStack) { + return ui::LogicalDisplayId{static_cast<int32_t>(layerStack.id)}; +} +} // namespace +namespace test { using Transaction = SurfaceComposerClient::Transaction; @@ -68,7 +76,9 @@ sp<IInputFlinger> getInputFlinger() { sp<IBinder> input(defaultServiceManager()->waitForService(String16("inputflinger"))); if (input == nullptr) { ALOGE("Failed to link to input service"); - } else { ALOGE("Linked to input"); } + } else { + ALOGE("Linked to input"); + } return interface_cast<IInputFlinger>(input); } @@ -99,7 +109,7 @@ private: class InputSurface { public: - InputSurface(const sp<SurfaceControl> &sc, int width, int height, bool noInputChannel = false) { + InputSurface(const sp<SurfaceControl>& sc, int width, int height, bool noInputChannel = false) { mSurfaceControl = sc; mInputFlinger = getInputFlinger(); @@ -130,7 +140,7 @@ public: mInputInfo.applicationInfo = aInfo; } - static std::unique_ptr<InputSurface> makeColorInputSurface(const sp<SurfaceComposerClient> &scc, + static std::unique_ptr<InputSurface> makeColorInputSurface(const sp<SurfaceComposerClient>& scc, int width, int height) { sp<SurfaceControl> surfaceControl = scc->createSurface(String8("Test Surface"), 0 /* bufHeight */, 0 /* bufWidth */, @@ -140,7 +150,7 @@ public: } static std::unique_ptr<InputSurface> makeBufferInputSurface( - const sp<SurfaceComposerClient> &scc, int width, int height) { + const sp<SurfaceComposerClient>& scc, int width, int height) { sp<SurfaceControl> surfaceControl = scc->createSurface(String8("Test Buffer Surface"), width, height, PIXEL_FORMAT_RGBA_8888, 0 /* flags */); @@ -148,7 +158,7 @@ public: } static std::unique_ptr<InputSurface> makeContainerInputSurface( - const sp<SurfaceComposerClient> &scc, int width, int height) { + const sp<SurfaceComposerClient>& scc, int width, int height) { sp<SurfaceControl> surfaceControl = scc->createSurface(String8("Test Container Surface"), 0 /* bufHeight */, 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, @@ -157,7 +167,7 @@ public: } static std::unique_ptr<InputSurface> makeContainerInputSurfaceNoInputChannel( - const sp<SurfaceComposerClient> &scc, int width, int height) { + const sp<SurfaceComposerClient>& scc, int width, int height) { sp<SurfaceControl> surfaceControl = scc->createSurface(String8("Test Container Surface"), 100 /* height */, 100 /* width */, PIXEL_FORMAT_RGBA_8888, @@ -167,7 +177,7 @@ public: } static std::unique_ptr<InputSurface> makeCursorInputSurface( - const sp<SurfaceComposerClient> &scc, int width, int height) { + const sp<SurfaceComposerClient>& scc, int width, int height) { sp<SurfaceControl> surfaceControl = scc->createSurface(String8("Test Cursor Surface"), 0 /* bufHeight */, 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, @@ -178,7 +188,7 @@ public: InputEvent* consumeEvent(std::chrono::milliseconds timeout = 3000ms) { mClientChannel->waitForMessage(timeout); - InputEvent *ev; + InputEvent* ev; uint32_t seqId; status_t consumed = mInputConsumer->consume(&mInputEventFactory, true, -1, &seqId, &ev); if (consumed != OK) { @@ -190,10 +200,10 @@ public: } void assertFocusChange(bool hasFocus) { - InputEvent *ev = consumeEvent(); + InputEvent* ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::FOCUS, ev->getType()); - FocusEvent *focusEvent = static_cast<FocusEvent *>(ev); + FocusEvent* focusEvent = static_cast<FocusEvent*>(ev); EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); } @@ -216,10 +226,10 @@ public: } void expectTapWithFlag(int x, int y, int32_t flags) { - InputEvent *ev = consumeEvent(); + InputEvent* ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::MOTION, ev->getType()); - MotionEvent *mev = static_cast<MotionEvent *>(ev); + MotionEvent* mev = static_cast<MotionEvent*>(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); EXPECT_EQ(x, mev->getX(0)); EXPECT_EQ(y, mev->getY(0)); @@ -228,18 +238,18 @@ public: ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::MOTION, ev->getType()); - mev = static_cast<MotionEvent *>(ev); + mev = static_cast<MotionEvent*>(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); EXPECT_EQ(flags, mev->getFlags() & flags); } void expectTapInDisplayCoordinates(int displayX, int displayY) { - InputEvent *ev = consumeEvent(); + InputEvent* ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::MOTION, ev->getType()); - MotionEvent *mev = static_cast<MotionEvent *>(ev); + MotionEvent* mev = static_cast<MotionEvent*>(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); - const PointerCoords &coords = *mev->getRawPointerCoords(0 /*pointerIndex*/); + const PointerCoords& coords = *mev->getRawPointerCoords(0 /*pointerIndex*/); EXPECT_EQ(displayX, coords.getX()); EXPECT_EQ(displayY, coords.getY()); EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); @@ -247,16 +257,16 @@ public: ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::MOTION, ev->getType()); - mev = static_cast<MotionEvent *>(ev); + mev = static_cast<MotionEvent*>(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); } void expectKey(int32_t keycode) { - InputEvent *ev = consumeEvent(); + InputEvent* ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::KEY, ev->getType()); - KeyEvent *keyEvent = static_cast<KeyEvent *>(ev); + KeyEvent* keyEvent = static_cast<KeyEvent*>(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, keyEvent->getAction()); EXPECT_EQ(keycode, keyEvent->getKeyCode()); EXPECT_EQ(0, keyEvent->getFlags() & VERIFIED_KEY_EVENT_FLAGS); @@ -264,7 +274,7 @@ public: ev = consumeEvent(); ASSERT_NE(ev, nullptr); ASSERT_EQ(InputEventType::KEY, ev->getType()); - keyEvent = static_cast<KeyEvent *>(ev); + keyEvent = static_cast<KeyEvent*>(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_UP, keyEvent->getAction()); EXPECT_EQ(keycode, keyEvent->getKeyCode()); EXPECT_EQ(0, keyEvent->getFlags() & VERIFIED_KEY_EVENT_FLAGS); @@ -282,7 +292,7 @@ public: } virtual void doTransaction( - std::function<void(SurfaceComposerClient::Transaction &, const sp<SurfaceControl> &)> + std::function<void(SurfaceComposerClient::Transaction&, const sp<SurfaceControl>&)> transactionBody) { SurfaceComposerClient::Transaction t; transactionBody(t, mSurfaceControl); @@ -303,13 +313,13 @@ public: reportedListener->wait(); } - void requestFocus(int displayId = ADISPLAY_ID_DEFAULT) { + void requestFocus(ui::LogicalDisplayId displayId = ADISPLAY_ID_DEFAULT) { SurfaceComposerClient::Transaction t; FocusRequest request; request.token = mInputInfo.token; request.windowName = mInputInfo.name; request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); - request.displayId = displayId; + request.displayId = displayId.val(); t.setFocusedWindow(request); t.apply(true); } @@ -327,7 +337,7 @@ public: class BlastInputSurface : public InputSurface { public: - BlastInputSurface(const sp<SurfaceControl> &sc, const sp<SurfaceControl> &parentSc, int width, + BlastInputSurface(const sp<SurfaceControl>& sc, const sp<SurfaceControl>& parentSc, int width, int height) : InputSurface(sc, width, height) { mParentSurfaceControl = parentSc; @@ -336,7 +346,7 @@ public: ~BlastInputSurface() = default; static std::unique_ptr<BlastInputSurface> makeBlastInputSurface( - const sp<SurfaceComposerClient> &scc, int width, int height) { + const sp<SurfaceComposerClient>& scc, int width, int height) { sp<SurfaceControl> parentSc = scc->createSurface(String8("Test Parent Surface"), 0 /* bufHeight */, 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, @@ -351,7 +361,7 @@ public: } void doTransaction( - std::function<void(SurfaceComposerClient::Transaction &, const sp<SurfaceControl> &)> + std::function<void(SurfaceComposerClient::Transaction&, const sp<SurfaceControl>&)> transactionBody) override { SurfaceComposerClient::Transaction t; transactionBody(t, mParentSurfaceControl); @@ -378,9 +388,7 @@ private: class InputSurfacesTest : public ::testing::Test { public: - InputSurfacesTest() { - ProcessState::self()->startThreadPool(); - } + InputSurfacesTest() { ProcessState::self()->startThreadPool(); } void SetUp() { mComposerClient = new SurfaceComposerClient; @@ -400,15 +408,13 @@ public: mBufferPostDelay = static_cast<int32_t>(1e6 / mode.peakRefreshRate) * 3; } - void TearDown() { - mComposerClient->dispose(); - } + void TearDown() { mComposerClient->dispose(); } std::unique_ptr<InputSurface> makeSurface(int width, int height) { return InputSurface::makeColorInputSurface(mComposerClient, width, height); } - void postBuffer(const sp<SurfaceControl> &layer, int32_t w, int32_t h) { + void postBuffer(const sp<SurfaceControl>& layer, int32_t w, int32_t h) { int64_t usageFlags = BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_TEXTURE; sp<GraphicBuffer> buffer = @@ -421,11 +427,11 @@ public: int32_t mBufferPostDelay; }; -void injectTapOnDisplay(int x, int y, int displayId) { +void injectTapOnDisplay(int x, int y, ui::LogicalDisplayId displayId) { char *buf1, *buf2, *bufDisplayId; asprintf(&buf1, "%d", x); asprintf(&buf2, "%d", y); - asprintf(&bufDisplayId, "%d", displayId); + asprintf(&bufDisplayId, "%d", displayId.val()); if (fork() == 0) { execlp("input", "input", "-d", bufDisplayId, "tap", buf1, buf2, NULL); } @@ -435,10 +441,10 @@ void injectTap(int x, int y) { injectTapOnDisplay(x, y, ADISPLAY_ID_DEFAULT); } -void injectKeyOnDisplay(uint32_t keycode, int displayId) { +void injectKeyOnDisplay(uint32_t keycode, ui::LogicalDisplayId displayId) { char *buf1, *bufDisplayId; asprintf(&buf1, "%d", keycode); - asprintf(&bufDisplayId, "%d", displayId); + asprintf(&bufDisplayId, "%d", displayId.val()); if (fork() == 0) { execlp("input", "input", "-d", bufDisplayId, "keyevent", buf1, NULL); } @@ -476,12 +482,8 @@ TEST_F(InputSurfacesTest, input_respects_positioning) { injectTap(101, 101); surface->expectTap(1, 1); - surface2->doTransaction([](auto &t, auto &sc) { - t.setPosition(sc, 100, 100); - }); - surface->doTransaction([](auto &t, auto &sc) { - t.setPosition(sc, 200, 200); - }); + surface2->doTransaction([](auto& t, auto& sc) { t.setPosition(sc, 100, 100); }); + surface->doTransaction([](auto& t, auto& sc) { t.setPosition(sc, 200, 200); }); injectTap(101, 101); surface2->expectTap(1, 1); @@ -497,23 +499,17 @@ TEST_F(InputSurfacesTest, input_respects_layering) { surface->showAt(10, 10); surface2->showAt(10, 10); - surface->doTransaction([](auto &t, auto &sc) { - t.setLayer(sc, LAYER_BASE + 1); - }); + surface->doTransaction([](auto& t, auto& sc) { t.setLayer(sc, LAYER_BASE + 1); }); injectTap(11, 11); surface->expectTap(1, 1); - surface2->doTransaction([](auto &t, auto &sc) { - t.setLayer(sc, LAYER_BASE + 1); - }); + surface2->doTransaction([](auto& t, auto& sc) { t.setLayer(sc, LAYER_BASE + 1); }); injectTap(11, 11); surface2->expectTap(1, 1); - surface2->doTransaction([](auto &t, auto &sc) { - t.hide(sc); - }); + surface2->doTransaction([](auto& t, auto& sc) { t.hide(sc); }); injectTap(11, 11); surface->expectTap(1, 1); @@ -562,7 +558,7 @@ TEST_F(InputSurfacesTest, input_respects_cropped_surface_insets) { childSurface->mInputInfo.surfaceInset = 10; childSurface->showAt(100, 100); - childSurface->doTransaction([&](auto &t, auto &sc) { + childSurface->doTransaction([&](auto& t, auto& sc) { t.setPosition(sc, -5, -5); t.reparent(sc, parentSurface->mSurfaceControl); }); @@ -583,7 +579,7 @@ TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets) { fgSurface->mInputInfo.surfaceInset = 5; fgSurface->showAt(100, 100); - fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 4.0); }); + fgSurface->doTransaction([&](auto& t, auto& sc) { t.setMatrix(sc, 2.0, 0, 0, 4.0); }); // expect = touch / scale - inset injectTap(112, 124); @@ -602,7 +598,7 @@ TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets_overflow) { fgSurface->mInputInfo.surfaceInset = INT32_MAX; fgSurface->showAt(100, 100); - fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); }); + fgSurface->doTransaction([&](auto& t, auto& sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); }); // expect no crash for overflow, and inset size to be clamped to surface size injectTap(112, 124); @@ -651,7 +647,7 @@ TEST_F(InputSurfacesTest, input_respects_scaled_touchable_region_overflow) { fgSurface->mInputInfo.touchableRegion.orSelf(Rect{INT32_MIN, INT32_MIN, INT32_MAX, INT32_MAX}); fgSurface->showAt(0, 0); - fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); }); + fgSurface->doTransaction([&](auto& t, auto& sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); }); // Expect no crash for overflow. injectTap(12, 24); @@ -661,7 +657,7 @@ TEST_F(InputSurfacesTest, input_respects_scaled_touchable_region_overflow) { // Ensure we ignore transparent region when getting screen bounds when positioning input frame. TEST_F(InputSurfacesTest, input_ignores_transparent_region) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { Region transparentRegion(Rect(0, 0, 10, 10)); t.setTransparentRegionHint(sc, transparentRegion); }); @@ -702,7 +698,7 @@ TEST_F(InputSurfacesTest, input_respects_buffer_layer_alpha) { injectTap(11, 11); bufferSurface->expectTap(1, 1); - bufferSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); }); + bufferSurface->doTransaction([](auto& t, auto& sc) { t.setAlpha(sc, 0.0); }); injectTap(11, 11); bgSurface->expectTap(1, 1); @@ -718,7 +714,7 @@ TEST_F(InputSurfacesTest, input_ignores_color_layer_alpha) { injectTap(11, 11); fgSurface->expectTap(1, 1); - fgSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); }); + fgSurface->doTransaction([](auto& t, auto& sc) { t.setAlpha(sc, 0.0); }); injectTap(11, 11); fgSurface->expectTap(1, 1); @@ -735,7 +731,7 @@ TEST_F(InputSurfacesTest, input_respects_container_layer_visiblity) { injectTap(11, 11); containerSurface->expectTap(1, 1); - containerSurface->doTransaction([](auto &t, auto &sc) { t.hide(sc); }); + containerSurface->doTransaction([](auto& t, auto& sc) { t.hide(sc); }); injectTap(11, 11); bgSurface->expectTap(1, 1); @@ -775,19 +771,19 @@ TEST_F(InputSurfacesTest, can_be_focused) { TEST_F(InputSurfacesTest, rotate_surface) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); surface->showAt(10, 10); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, 0, 1, -1, 0); // 90 degrees }); injectTap(8, 11); surface->expectTap(1, 2); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, -1, 0, 0, -1); // 180 degrees }); injectTap(9, 8); surface->expectTap(1, 2); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, 0, -1, 1, 0); // 270 degrees }); injectTap(12, 9); @@ -797,19 +793,19 @@ TEST_F(InputSurfacesTest, rotate_surface) { TEST_F(InputSurfacesTest, rotate_surface_with_scale) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); surface->showAt(10, 10); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, 0, 2, -4, 0); // 90 degrees }); injectTap(2, 12); surface->expectTap(1, 2); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, -2, 0, 0, -4); // 180 degrees }); injectTap(8, 2); surface->expectTap(1, 2); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, 0, -2, 4, 0); // 270 degrees }); injectTap(18, 8); @@ -821,19 +817,19 @@ TEST_F(InputSurfacesTest, rotate_surface_with_scale_and_insets) { surface->mInputInfo.surfaceInset = 5; surface->showAt(100, 100); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, 0, 2, -4, 0); // 90 degrees }); injectTap(40, 120); surface->expectTap(5, 10); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, -2, 0, 0, -4); // 180 degrees }); injectTap(80, 40); surface->expectTap(5, 10); - surface->doTransaction([](auto &t, auto &sc) { + surface->doTransaction([](auto& t, auto& sc) { t.setMatrix(sc, 0, -2, 4, 0); // 270 degrees }); injectTap(160, 80); @@ -874,7 +870,7 @@ TEST_F(InputSurfacesTest, touch_flag_partially_obscured_with_crop) { nonTouchableSurface->showAt(0, 0); parentSurface->showAt(100, 100); - nonTouchableSurface->doTransaction([&](auto &t, auto &sc) { + nonTouchableSurface->doTransaction([&](auto& t, auto& sc) { t.setCrop(parentSurface->mSurfaceControl, Rect(0, 0, 50, 50)); t.reparent(sc, parentSurface->mSurfaceControl); }); @@ -898,7 +894,7 @@ TEST_F(InputSurfacesTest, touch_not_obscured_with_crop) { nonTouchableSurface->showAt(0, 0); parentSurface->showAt(50, 50); - nonTouchableSurface->doTransaction([&](auto &t, auto &sc) { + nonTouchableSurface->doTransaction([&](auto& t, auto& sc) { t.setCrop(parentSurface->mSurfaceControl, Rect(0, 0, 50, 50)); t.reparent(sc, parentSurface->mSurfaceControl); }); @@ -940,7 +936,7 @@ TEST_F(InputSurfacesTest, touch_not_obscured_with_zero_sized_blast) { TEST_F(InputSurfacesTest, strict_unobscured_input_unobscured_window) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); surface->doTransaction( - [&](auto &t, auto &sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); + [&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); surface->showAt(100, 100); injectTap(101, 101); @@ -954,7 +950,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_unobscured_window) { TEST_F(InputSurfacesTest, strict_unobscured_input_scaled_without_crop_window) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); - surface->doTransaction([&](auto &t, auto &sc) { + surface->doTransaction([&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); t.setMatrix(sc, 2.0, 0, 0, 2.0); }); @@ -973,7 +969,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_obscured_window) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); surface->mInputInfo.ownerUid = gui::Uid{11111}; surface->doTransaction( - [&](auto &t, auto &sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); + [&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); surface->showAt(100, 100); std::unique_ptr<InputSurface> obscuringSurface = makeSurface(100, 100); obscuringSurface->mInputInfo.setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, true); @@ -992,7 +988,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_partially_obscured_window) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); surface->mInputInfo.ownerUid = gui::Uid{11111}; surface->doTransaction( - [&](auto &t, auto &sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); + [&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); }); surface->showAt(100, 100); std::unique_ptr<InputSurface> obscuringSurface = makeSurface(100, 100); obscuringSurface->mInputInfo.setInputConfig(WindowInfo::InputConfig::NOT_TOUCHABLE, true); @@ -1015,7 +1011,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_alpha_window) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); surface->showAt(100, 100); - surface->doTransaction([&](auto &t, auto &sc) { + surface->doTransaction([&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); t.reparent(sc, parentSurface->mSurfaceControl); t.setAlpha(parentSurface->mSurfaceControl, 0.9f); @@ -1036,7 +1032,7 @@ TEST_F(InputSurfacesTest, strict_unobscured_input_cropped_window) { parentSurface->showAt(0, 0, Rect(0, 0, 300, 300)); std::unique_ptr<InputSurface> surface = makeSurface(100, 100); - surface->doTransaction([&](auto &t, auto &sc) { + surface->doTransaction([&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::OBSCURED); t.reparent(sc, parentSurface->mSurfaceControl); t.setCrop(parentSurface->mSurfaceControl, Rect(10, 10, 100, 100)); @@ -1070,7 +1066,7 @@ TEST_F(InputSurfacesTest, ignore_touch_region_with_zero_sized_blast) { TEST_F(InputSurfacesTest, drop_input_policy) { std::unique_ptr<InputSurface> surface = makeSurface(100, 100); surface->doTransaction( - [&](auto &t, auto &sc) { t.setDropInputMode(sc, gui::DropInputMode::ALL); }); + [&](auto& t, auto& sc) { t.setDropInputMode(sc, gui::DropInputMode::ALL); }); surface->showAt(100, 100); injectTap(101, 101); @@ -1102,7 +1098,7 @@ TEST_F(InputSurfacesTest, cropped_container_replaces_touchable_region_with_null_ std::unique_ptr<InputSurface> containerSurface = InputSurface::makeContainerInputSurface(mComposerClient, 100, 100); containerSurface->doTransaction( - [&](auto &t, auto &sc) { t.reparent(sc, parentContainer->mSurfaceControl); }); + [&](auto& t, auto& sc) { t.reparent(sc, parentContainer->mSurfaceControl); }); containerSurface->mInputInfo.replaceTouchableRegionWithCrop = true; containerSurface->mInputInfo.touchableRegionCropHandle = nullptr; parentContainer->showAt(10, 10, Rect(0, 0, 20, 20)); @@ -1127,7 +1123,7 @@ TEST_F(InputSurfacesTest, uncropped_container_replaces_touchable_region_with_nul std::unique_ptr<InputSurface> containerSurface = InputSurface::makeContainerInputSurface(mComposerClient, 100, 100); containerSurface->doTransaction( - [&](auto &t, auto &sc) { t.reparent(sc, parentContainer->mSurfaceControl); }); + [&](auto& t, auto& sc) { t.reparent(sc, parentContainer->mSurfaceControl); }); containerSurface->mInputInfo.replaceTouchableRegionWithCrop = true; containerSurface->mInputInfo.touchableRegionCropHandle = nullptr; parentContainer->showAt(10, 10, Rect(0, 0, 20, 20)); @@ -1179,7 +1175,7 @@ TEST_F(InputSurfacesTest, child_container_with_no_input_channel_blocks_parent) { InputSurface::makeContainerInputSurfaceNoInputChannel(mComposerClient, 100, 100); childContainerSurface->showAt(0, 0); childContainerSurface->doTransaction( - [&](auto &t, auto &sc) { t.reparent(sc, parent->mSurfaceControl); }); + [&](auto& t, auto& sc) { t.reparent(sc, parent->mSurfaceControl); }); injectTap(101, 101); parent->assertNoEvent(); @@ -1188,8 +1184,9 @@ TEST_F(InputSurfacesTest, child_container_with_no_input_channel_blocks_parent) { class MultiDisplayTests : public InputSurfacesTest { public: MultiDisplayTests() : InputSurfacesTest() { ProcessState::self()->startThreadPool(); } + void TearDown() override { - for (auto &token : mVirtualDisplays) { + for (auto& token : mVirtualDisplays) { SurfaceComposerClient::destroyDisplay(token); } InputSurfacesTest::TearDown(); @@ -1226,18 +1223,18 @@ TEST_F(MultiDisplayTests, drop_touch_if_layer_on_invalid_display) { ui::LayerStack layerStack = ui::LayerStack::fromValue(42); // Do not create a display associated with the LayerStack. std::unique_ptr<InputSurface> surface = makeSurface(100, 100); - surface->doTransaction([&](auto &t, auto &sc) { t.setLayerStack(sc, layerStack); }); + surface->doTransaction([&](auto& t, auto& sc) { t.setLayerStack(sc, layerStack); }); surface->showAt(100, 100); // Touches should be dropped if the layer is on an invalid display. - injectTapOnDisplay(101, 101, layerStack.id); + injectTapOnDisplay(101, 101, toDisplayId(layerStack)); surface->assertNoEvent(); // However, we still let the window be focused and receive keys. - surface->requestFocus(layerStack.id); + surface->requestFocus(toDisplayId(layerStack)); surface->assertFocusChange(true); - injectKeyOnDisplay(AKEYCODE_V, layerStack.id); + injectKeyOnDisplay(AKEYCODE_V, toDisplayId(layerStack)); surface->expectKey(AKEYCODE_V); } @@ -1245,15 +1242,15 @@ TEST_F(MultiDisplayTests, virtual_display_receives_input) { ui::LayerStack layerStack = ui::LayerStack::fromValue(42); createDisplay(1000, 1000, false /*isSecure*/, layerStack); std::unique_ptr<InputSurface> surface = makeSurface(100, 100); - surface->doTransaction([&](auto &t, auto &sc) { t.setLayerStack(sc, layerStack); }); + surface->doTransaction([&](auto& t, auto& sc) { t.setLayerStack(sc, layerStack); }); surface->showAt(100, 100); - injectTapOnDisplay(101, 101, layerStack.id); + injectTapOnDisplay(101, 101, toDisplayId(layerStack)); surface->expectTap(1, 1); - surface->requestFocus(layerStack.id); + surface->requestFocus(toDisplayId(layerStack)); surface->assertFocusChange(true); - injectKeyOnDisplay(AKEYCODE_V, layerStack.id); + injectKeyOnDisplay(AKEYCODE_V, toDisplayId(layerStack)); surface->expectKey(AKEYCODE_V); } @@ -1261,19 +1258,19 @@ TEST_F(MultiDisplayTests, drop_input_for_secure_layer_on_nonsecure_display) { ui::LayerStack layerStack = ui::LayerStack::fromValue(42); createDisplay(1000, 1000, false /*isSecure*/, layerStack); std::unique_ptr<InputSurface> surface = makeSurface(100, 100); - surface->doTransaction([&](auto &t, auto &sc) { + surface->doTransaction([&](auto& t, auto& sc) { t.setFlags(sc, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure); t.setLayerStack(sc, layerStack); }); surface->showAt(100, 100); - injectTapOnDisplay(101, 101, layerStack.id); + injectTapOnDisplay(101, 101, toDisplayId(layerStack)); surface->assertNoEvent(); - surface->requestFocus(layerStack.id); + surface->requestFocus(toDisplayId(layerStack)); surface->assertFocusChange(true); - injectKeyOnDisplay(AKEYCODE_V, layerStack.id); + injectKeyOnDisplay(AKEYCODE_V, toDisplayId(layerStack)); surface->assertNoEvent(); } @@ -1287,20 +1284,21 @@ TEST_F(MultiDisplayTests, dont_drop_input_for_secure_layer_on_secure_display) { seteuid(AID_ROOT); std::unique_ptr<InputSurface> surface = makeSurface(100, 100); - surface->doTransaction([&](auto &t, auto &sc) { + surface->doTransaction([&](auto& t, auto& sc) { t.setFlags(sc, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure); t.setLayerStack(sc, layerStack); }); surface->showAt(100, 100); - injectTapOnDisplay(101, 101, layerStack.id); + injectTapOnDisplay(101, 101, toDisplayId(layerStack)); surface->expectTap(1, 1); - surface->requestFocus(layerStack.id); + surface->requestFocus(toDisplayId(layerStack)); surface->assertFocusChange(true); - injectKeyOnDisplay(AKEYCODE_V, layerStack.id); + injectKeyOnDisplay(AKEYCODE_V, toDisplayId(layerStack)); surface->expectKey(AKEYCODE_V); } -} // namespace android::test +} // namespace test +} // namespace android diff --git a/libs/gui/tests/WindowInfo_test.cpp b/libs/gui/tests/WindowInfo_test.cpp index 5eb5d3bff0..ce22082a9f 100644 --- a/libs/gui/tests/WindowInfo_test.cpp +++ b/libs/gui/tests/WindowInfo_test.cpp @@ -64,7 +64,7 @@ TEST(WindowInfo, Parcelling) { i.ownerUid = gui::Uid{24}; i.packageName = "com.example.package"; i.inputConfig = WindowInfo::InputConfig::NOT_FOCUSABLE; - i.displayId = 34; + i.displayId = ui::LogicalDisplayId{34}; i.replaceTouchableRegionWithCrop = true; i.touchableRegionCropHandle = touchableRegionCropHandle; i.applicationInfo.name = "ApplicationFooBar"; diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 61a964ece9..d27156383a 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -27,7 +27,6 @@ #include <android-base/logging.h> #include <android-base/stringprintf.h> #include <cutils/compiler.h> -#include <gui/constants.h> #include <input/DisplayViewport.h> #include <input/Input.h> #include <input/InputDevice.h> @@ -293,8 +292,8 @@ VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event) event.getButtonState()}; } -void InputEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, - std::array<uint8_t, 32> hmac) { +void InputEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, + ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac) { mId = id; mDeviceId = deviceId; mSource = source; @@ -356,10 +355,11 @@ std::optional<int> KeyEvent::getKeyCodeFromLabel(const char* label) { return InputEventLookup::getKeyCodeByLabel(label); } -void KeyEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, - std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, - int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, - nsecs_t downTime, nsecs_t eventTime) { +void KeyEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, + ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac, + int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, + int32_t metaState, int32_t repeatCount, nsecs_t downTime, + nsecs_t eventTime) { InputEvent::initialize(id, deviceId, source, displayId, hmac); mAction = action; mFlags = flags; @@ -556,14 +556,15 @@ void PointerCoords::transform(const ui::Transform& transform) { // --- MotionEvent --- -void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, - std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, - int32_t flags, int32_t edgeFlags, int32_t metaState, - int32_t buttonState, MotionClassification classification, - const ui::Transform& transform, float xPrecision, float yPrecision, - float rawXCursorPosition, float rawYCursorPosition, - const ui::Transform& rawTransform, nsecs_t downTime, nsecs_t eventTime, - size_t pointerCount, const PointerProperties* pointerProperties, +void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, + ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac, + int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, + int32_t metaState, int32_t buttonState, + MotionClassification classification, const ui::Transform& transform, + float xPrecision, float yPrecision, float rawXCursorPosition, + float rawYCursorPosition, const ui::Transform& rawTransform, + nsecs_t downTime, nsecs_t eventTime, size_t pointerCount, + const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) { InputEvent::initialize(id, deviceId, source, displayId, hmac); mAction = action; @@ -835,7 +836,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { mId = parcel->readInt32(); mDeviceId = parcel->readInt32(); mSource = parcel->readUint32(); - mDisplayId = parcel->readInt32(); + mDisplayId = ui::LogicalDisplayId{parcel->readInt32()}; std::vector<uint8_t> hmac; status_t result = parcel->readByteVector(&hmac); if (result != OK || hmac.size() != 32) { @@ -903,7 +904,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const { parcel->writeInt32(mId); parcel->writeInt32(mDeviceId); parcel->writeUint32(mSource); - parcel->writeInt32(mDisplayId); + parcel->writeInt32(mDisplayId.val()); std::vector<uint8_t> hmac(mHmac.begin(), mHmac.end()); parcel->writeByteVector(hmac); parcel->writeInt32(mAction); @@ -1203,7 +1204,7 @@ std::ostream& operator<<(std::ostream& out, const MotionEvent& event) { void FocusEvent::initialize(int32_t id, bool hasFocus) { InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, - ADISPLAY_ID_NONE, INVALID_HMAC); + ui::ADISPLAY_ID_NONE, INVALID_HMAC); mHasFocus = hasFocus; } @@ -1216,7 +1217,7 @@ void FocusEvent::initialize(const FocusEvent& from) { void CaptureEvent::initialize(int32_t id, bool pointerCaptureEnabled) { InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, - ADISPLAY_ID_NONE, INVALID_HMAC); + ui::ADISPLAY_ID_NONE, INVALID_HMAC); mPointerCaptureEnabled = pointerCaptureEnabled; } @@ -1229,7 +1230,7 @@ void CaptureEvent::initialize(const CaptureEvent& from) { void DragEvent::initialize(int32_t id, float x, float y, bool isExiting) { InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, - ADISPLAY_ID_NONE, INVALID_HMAC); + ui::ADISPLAY_ID_NONE, INVALID_HMAC); mIsExiting = isExiting; mX = x; mY = y; @@ -1246,7 +1247,7 @@ void DragEvent::initialize(const DragEvent& from) { void TouchModeEvent::initialize(int32_t id, bool isInTouchMode) { InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, - ADISPLAY_ID_NONE, INVALID_HMAC); + ui::ADISPLAY_ID_NONE, INVALID_HMAC); mIsInTouchMode = isInTouchMode; } diff --git a/libs/input/InputConsumer.cpp b/libs/input/InputConsumer.cpp index be2110e42b..abc039281a 100644 --- a/libs/input/InputConsumer.cpp +++ b/libs/input/InputConsumer.cpp @@ -81,10 +81,10 @@ bool debugResampling() { void initializeKeyEvent(KeyEvent& event, const InputMessage& msg) { event.initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source, - msg.body.key.displayId, msg.body.key.hmac, msg.body.key.action, - msg.body.key.flags, msg.body.key.keyCode, msg.body.key.scanCode, - msg.body.key.metaState, msg.body.key.repeatCount, msg.body.key.downTime, - msg.body.key.eventTime); + ui::LogicalDisplayId{msg.body.key.displayId}, msg.body.key.hmac, + msg.body.key.action, msg.body.key.flags, msg.body.key.keyCode, + msg.body.key.scanCode, msg.body.key.metaState, msg.body.key.repeatCount, + msg.body.key.downTime, msg.body.key.eventTime); } void initializeFocusEvent(FocusEvent& event, const InputMessage& msg) { @@ -117,13 +117,14 @@ void initializeMotionEvent(MotionEvent& event, const InputMessage& msg) { msg.body.motion.dtdyRaw, msg.body.motion.dsdyRaw, msg.body.motion.tyRaw, 0, 0, 1}); event.initialize(msg.body.motion.eventId, msg.body.motion.deviceId, msg.body.motion.source, - msg.body.motion.displayId, msg.body.motion.hmac, msg.body.motion.action, - msg.body.motion.actionButton, msg.body.motion.flags, msg.body.motion.edgeFlags, - msg.body.motion.metaState, msg.body.motion.buttonState, - msg.body.motion.classification, transform, msg.body.motion.xPrecision, - msg.body.motion.yPrecision, msg.body.motion.xCursorPosition, - msg.body.motion.yCursorPosition, displayTransform, msg.body.motion.downTime, - msg.body.motion.eventTime, pointerCount, pointerProperties, pointerCoords); + ui::LogicalDisplayId{msg.body.motion.displayId}, msg.body.motion.hmac, + msg.body.motion.action, msg.body.motion.actionButton, msg.body.motion.flags, + msg.body.motion.edgeFlags, msg.body.motion.metaState, + msg.body.motion.buttonState, msg.body.motion.classification, transform, + msg.body.motion.xPrecision, msg.body.motion.yPrecision, + msg.body.motion.xCursorPosition, msg.body.motion.yCursorPosition, + displayTransform, msg.body.motion.downTime, msg.body.motion.eventTime, + pointerCount, pointerProperties, pointerCoords); } void addSample(MotionEvent& event, const InputMessage& msg) { diff --git a/libs/input/InputConsumerNoResampling.cpp b/libs/input/InputConsumerNoResampling.cpp index 76f2b4a4f8..15d992f9f3 100644 --- a/libs/input/InputConsumerNoResampling.cpp +++ b/libs/input/InputConsumerNoResampling.cpp @@ -47,10 +47,10 @@ const bool DEBUG_TRANSPORT_CONSUMER = std::unique_ptr<KeyEvent> createKeyEvent(const InputMessage& msg) { std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>(); event->initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source, - msg.body.key.displayId, msg.body.key.hmac, msg.body.key.action, - msg.body.key.flags, msg.body.key.keyCode, msg.body.key.scanCode, - msg.body.key.metaState, msg.body.key.repeatCount, msg.body.key.downTime, - msg.body.key.eventTime); + ui::LogicalDisplayId{msg.body.key.displayId}, msg.body.key.hmac, + msg.body.key.action, msg.body.key.flags, msg.body.key.keyCode, + msg.body.key.scanCode, msg.body.key.metaState, msg.body.key.repeatCount, + msg.body.key.downTime, msg.body.key.eventTime); return event; } @@ -93,8 +93,8 @@ std::unique_ptr<MotionEvent> createMotionEvent(const InputMessage& msg) { msg.body.motion.dtdyRaw, msg.body.motion.dsdyRaw, msg.body.motion.tyRaw, 0, 0, 1}); event->initialize(msg.body.motion.eventId, msg.body.motion.deviceId, msg.body.motion.source, - msg.body.motion.displayId, msg.body.motion.hmac, msg.body.motion.action, - msg.body.motion.actionButton, msg.body.motion.flags, + ui::LogicalDisplayId{msg.body.motion.displayId}, msg.body.motion.hmac, + msg.body.motion.action, msg.body.motion.actionButton, msg.body.motion.flags, msg.body.motion.edgeFlags, msg.body.motion.metaState, msg.body.motion.buttonState, msg.body.motion.classification, transform, msg.body.motion.xPrecision, msg.body.motion.yPrecision, diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp index 222647db56..50239a1f9f 100644 --- a/libs/input/InputDevice.cpp +++ b/libs/input/InputDevice.cpp @@ -23,7 +23,6 @@ #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <ftl/enum.h> -#include <gui/constants.h> #include <input/InputDevice.h> #include <input/InputEventLabels.h> @@ -170,7 +169,7 @@ std::string InputDeviceIdentifier::getCanonicalName() const { // --- InputDeviceInfo --- InputDeviceInfo::InputDeviceInfo() { - initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false, ADISPLAY_ID_NONE); + initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false, ui::ADISPLAY_ID_NONE); } InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) @@ -202,7 +201,8 @@ InputDeviceInfo::~InputDeviceInfo() { void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t controllerNumber, const InputDeviceIdentifier& identifier, const std::string& alias, - bool isExternal, bool hasMic, int32_t associatedDisplayId, + bool isExternal, bool hasMic, + ui::LogicalDisplayId associatedDisplayId, InputDeviceViewBehavior viewBehavior, bool enabled) { mId = id; mGeneration = generation; diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 3ca6ccc7d5..47b422857e 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -530,7 +530,7 @@ InputPublisher::~InputPublisher() { } status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, - int32_t source, int32_t displayId, + int32_t source, ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, @@ -558,7 +558,7 @@ status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t eventId, int32_t msg.body.key.eventId = eventId; msg.body.key.deviceId = deviceId; msg.body.key.source = source; - msg.body.key.displayId = displayId; + msg.body.key.displayId = displayId.val(); msg.body.key.hmac = std::move(hmac); msg.body.key.action = action; msg.body.key.flags = flags; @@ -572,11 +572,11 @@ status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t eventId, int32_t } status_t InputPublisher::publishMotionEvent( - uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, - std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, - int32_t edgeFlags, int32_t metaState, int32_t buttonState, - MotionClassification classification, const ui::Transform& transform, float xPrecision, - float yPrecision, float xCursorPosition, float yCursorPosition, + uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, + ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac, int32_t action, + int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, + int32_t buttonState, MotionClassification classification, const ui::Transform& transform, + float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, const ui::Transform& rawTransform, nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) { @@ -596,13 +596,13 @@ status_t InputPublisher::publishMotionEvent( std::string transformString; transform.dump(transformString, "transform", " "); ALOGD("channel '%s' publisher ~ %s: seq=%u, id=%d, deviceId=%d, source=%s, " - "displayId=%" PRId32 ", " + "displayId=%s, " "action=%s, actionButton=0x%08x, flags=0x%x, edgeFlags=0x%x, " "metaState=0x%x, buttonState=0x%x, classification=%s," "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", " "pointerCount=%" PRIu32 "\n%s", mChannel->getName().c_str(), __func__, seq, eventId, deviceId, - inputEventSourceToString(source).c_str(), displayId, + inputEventSourceToString(source).c_str(), displayId.toString().c_str(), MotionEvent::actionToString(action).c_str(), actionButton, flags, edgeFlags, metaState, buttonState, motionClassificationToString(classification), xPrecision, yPrecision, downTime, eventTime, pointerCount, transformString.c_str()); @@ -625,7 +625,7 @@ status_t InputPublisher::publishMotionEvent( msg.body.motion.eventId = eventId; msg.body.motion.deviceId = deviceId; msg.body.motion.source = source; - msg.body.motion.displayId = displayId; + msg.body.motion.displayId = displayId.val(); msg.body.motion.hmac = std::move(hmac); msg.body.motion.action = action; msg.body.motion.actionButton = actionButton; diff --git a/libs/input/KeyCharacterMap.cpp b/libs/input/KeyCharacterMap.cpp index e2feabcbbe..41909bfb2d 100644 --- a/libs/input/KeyCharacterMap.cpp +++ b/libs/input/KeyCharacterMap.cpp @@ -28,7 +28,6 @@ #include <input/KeyCharacterMap.h> #include <input/Keyboard.h> -#include <gui/constants.h> #include <utils/Errors.h> #include <utils/Log.h> #include <utils/Timers.h> @@ -496,11 +495,11 @@ bool KeyCharacterMap::findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMeta return false; } -void KeyCharacterMap::addKey(Vector<KeyEvent>& outEvents, - int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time) { +void KeyCharacterMap::addKey(Vector<KeyEvent>& outEvents, int32_t deviceId, int32_t keyCode, + int32_t metaState, bool down, nsecs_t time) { outEvents.push(); KeyEvent& event = outEvents.editTop(); - event.initialize(InputEvent::nextId(), deviceId, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE, + event.initialize(InputEvent::nextId(), deviceId, AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_NONE, INVALID_HMAC, down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP, 0, keyCode, 0, metaState, 0, time, time); } diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index 0df06b790e..cc2574de9a 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -21,14 +21,13 @@ #include <attestation/HmacKeyManager.h> #include <binder/Parcel.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <input/Input.h> #include <input/InputEventBuilders.h> namespace android { // Default display id. -static constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; +static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; static constexpr float EPSILON = MotionEvent::ROUNDING_PRECISION; @@ -229,7 +228,7 @@ TEST_F(KeyEventTest, Properties) { ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource()); // Set display id. - constexpr int32_t newDisplayId = 2; + constexpr ui::LogicalDisplayId newDisplayId = ui::LogicalDisplayId{2}; event.setDisplayId(newDisplayId); ASSERT_EQ(newDisplayId, event.getDisplayId()); } @@ -528,7 +527,7 @@ TEST_F(MotionEventTest, Properties) { ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource()); // Set displayId. - constexpr int32_t newDisplayId = 2; + constexpr ui::LogicalDisplayId newDisplayId = ui::LogicalDisplayId{2}; event.setDisplayId(newDisplayId); ASSERT_EQ(newDisplayId, event.getDisplayId()); @@ -860,7 +859,7 @@ MotionEvent createMotionEvent(int32_t source, uint32_t action, float x, float y, nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC); MotionEvent event; event.initialize(InputEvent::nextId(), /* deviceId */ 1, source, - /* displayId */ 0, INVALID_HMAC, action, + /* displayId */ ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, action, /* actionButton */ 0, /* flags */ 0, /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, transform, /* xPrecision */ 0, /* yPrecision */ 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, diff --git a/libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp b/libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp index 6593497763..7ae1cd8444 100644 --- a/libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp @@ -18,7 +18,6 @@ #include <attestation/HmacKeyManager.h> #include <ftl/enum.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <input/BlockingQueue.h> #include <input/InputConsumerNoResampling.h> #include <input/InputTransport.h> @@ -56,7 +55,7 @@ struct PublishMotionArgs { const int32_t eventId; const int32_t deviceId = 1; const uint32_t source = AINPUT_SOURCE_TOUCHSCREEN; - const int32_t displayId = ADISPLAY_ID_DEFAULT; + const ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT; const int32_t actionButton = 0; const int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP; const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON; @@ -446,7 +445,7 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeKeyEvent() { int32_t eventId = InputEvent::nextId(); constexpr int32_t deviceId = 1; constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD; - constexpr int32_t displayId = ADISPLAY_ID_DEFAULT; + constexpr ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT; constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; @@ -738,9 +737,10 @@ TEST_F(InputPublisherAndConsumerNoResamplingTest, ui::Transform identityTransform; status = - mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0, - 0, 0, 0, MotionClassification::NONE, identityTransform, - 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, + mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, ui::ADISPLAY_ID_DEFAULT, + INVALID_HMAC, 0, 0, 0, 0, 0, 0, + MotionClassification::NONE, identityTransform, 0, 0, + AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0, 0, pointerCount, pointerProperties, pointerCoords); ASSERT_EQ(BAD_VALUE, status) << "publisher publishMotionEvent should return BAD_VALUE"; @@ -755,9 +755,10 @@ TEST_F(InputPublisherAndConsumerNoResamplingTest, ui::Transform identityTransform; status = - mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0, - 0, 0, 0, MotionClassification::NONE, identityTransform, - 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, + mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, ui::ADISPLAY_ID_DEFAULT, + INVALID_HMAC, 0, 0, 0, 0, 0, 0, + MotionClassification::NONE, identityTransform, 0, 0, + AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0, 0, pointerCount, pointerProperties, pointerCoords); ASSERT_EQ(BAD_VALUE, status) << "publisher publishMotionEvent should return BAD_VALUE"; @@ -776,9 +777,10 @@ TEST_F(InputPublisherAndConsumerNoResamplingTest, ui::Transform identityTransform; status = - mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0, - 0, 0, 0, MotionClassification::NONE, identityTransform, - 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, + mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, ui::ADISPLAY_ID_DEFAULT, + INVALID_HMAC, 0, 0, 0, 0, 0, 0, + MotionClassification::NONE, identityTransform, 0, 0, + AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0, 0, pointerCount, pointerProperties, pointerCoords); ASSERT_EQ(BAD_VALUE, status) << "publisher publishMotionEvent should return BAD_VALUE"; diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index 332831febb..d0dbe2ad31 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -16,7 +16,6 @@ #include <attestation/HmacKeyManager.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <input/InputConsumer.h> #include <input/InputTransport.h> @@ -49,7 +48,7 @@ struct PublishMotionArgs { const int32_t eventId; const int32_t deviceId = 1; const uint32_t source = AINPUT_SOURCE_TOUCHSCREEN; - const int32_t displayId = ADISPLAY_ID_DEFAULT; + const ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT; const int32_t actionButton = 0; const int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP; const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON; @@ -263,7 +262,7 @@ void InputPublisherAndConsumerTest::publishAndConsumeKeyEvent() { int32_t eventId = InputEvent::nextId(); constexpr int32_t deviceId = 1; constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD; - constexpr int32_t displayId = ADISPLAY_ID_DEFAULT; + constexpr ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT; constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; @@ -623,13 +622,13 @@ TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZer ui::Transform identityTransform; status = - mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0, - 0, 0, 0, MotionClassification::NONE, identityTransform, - 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, + mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, ui::ADISPLAY_ID_DEFAULT, + INVALID_HMAC, 0, 0, 0, 0, 0, 0, + MotionClassification::NONE, identityTransform, 0, 0, + AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0, 0, pointerCount, pointerProperties, pointerCoords); - ASSERT_EQ(BAD_VALUE, status) - << "publisher publishMotionEvent should return BAD_VALUE"; + ASSERT_EQ(BAD_VALUE, status) << "publisher publishMotionEvent should return BAD_VALUE"; } TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) { @@ -640,17 +639,17 @@ TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessTha ui::Transform identityTransform; status = - mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0, - 0, 0, 0, MotionClassification::NONE, identityTransform, - 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, + mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, ui::ADISPLAY_ID_DEFAULT, + INVALID_HMAC, 0, 0, 0, 0, 0, 0, + MotionClassification::NONE, identityTransform, 0, 0, + AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0, 0, pointerCount, pointerProperties, pointerCoords); - ASSERT_EQ(BAD_VALUE, status) - << "publisher publishMotionEvent should return BAD_VALUE"; + ASSERT_EQ(BAD_VALUE, status) << "publisher publishMotionEvent should return BAD_VALUE"; } TEST_F(InputPublisherAndConsumerTest, - PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) { + PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) { status_t status; const size_t pointerCount = MAX_POINTERS + 1; PointerProperties pointerProperties[pointerCount]; @@ -662,13 +661,13 @@ TEST_F(InputPublisherAndConsumerTest, ui::Transform identityTransform; status = - mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0, - 0, 0, 0, MotionClassification::NONE, identityTransform, - 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, + mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, ui::ADISPLAY_ID_DEFAULT, + INVALID_HMAC, 0, 0, 0, 0, 0, 0, + MotionClassification::NONE, identityTransform, 0, 0, + AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0, 0, pointerCount, pointerProperties, pointerCoords); - ASSERT_EQ(BAD_VALUE, status) - << "publisher publishMotionEvent should return BAD_VALUE"; + ASSERT_EQ(BAD_VALUE, status) << "publisher publishMotionEvent should return BAD_VALUE"; } TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) { diff --git a/libs/input/tests/MotionPredictor_test.cpp b/libs/input/tests/MotionPredictor_test.cpp index b8f1caa068..1c9f0c7399 100644 --- a/libs/input/tests/MotionPredictor_test.cpp +++ b/libs/input/tests/MotionPredictor_test.cpp @@ -22,7 +22,6 @@ #include <flag_macros.h> #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <input/Input.h> #include <input/MotionPredictor.h> @@ -59,8 +58,8 @@ static MotionEvent getMotionEvent(int32_t action, float x, float y, } ui::Transform identityTransform; - event.initialize(InputEvent::nextId(), deviceId, AINPUT_SOURCE_STYLUS, ADISPLAY_ID_DEFAULT, {0}, - action, /*actionButton=*/0, /*flags=*/0, AMOTION_EVENT_EDGE_FLAG_NONE, + event.initialize(InputEvent::nextId(), deviceId, AINPUT_SOURCE_STYLUS, ui::ADISPLAY_ID_DEFAULT, + {0}, action, /*actionButton=*/0, /*flags=*/0, AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, identityTransform, /*xPrecision=*/0.1, /*yPrecision=*/0.2, /*xCursorPosition=*/280, /*yCursorPosition=*/540, diff --git a/libs/input/tests/TouchResampling_test.cpp b/libs/input/tests/TouchResampling_test.cpp index 6e23d4e910..1694cadfbe 100644 --- a/libs/input/tests/TouchResampling_test.cpp +++ b/libs/input/tests/TouchResampling_test.cpp @@ -84,7 +84,8 @@ status_t TouchResamplingTest::publishSimpleMotionEventWithCoords( ADD_FAILURE() << "Downtime should be equal to 0 (hardcoded for convenience)"; } return mPublisher->publishMotionEvent(mSeq++, InputEvent::nextId(), /*deviceId=*/1, - AINPUT_SOURCE_TOUCHSCREEN, /*displayId=*/0, INVALID_HMAC, + AINPUT_SOURCE_TOUCHSCREEN, + /*displayId=*/ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, action, /*actionButton=*/0, /*flags=*/0, /*edgeFlags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, identityTransform, /*xPrecision=*/0, /*yPrecision=*/0, diff --git a/libs/input/tests/VelocityTracker_test.cpp b/libs/input/tests/VelocityTracker_test.cpp index f9ca28083d..b4c4e1286d 100644 --- a/libs/input/tests/VelocityTracker_test.cpp +++ b/libs/input/tests/VelocityTracker_test.cpp @@ -24,7 +24,6 @@ #include <android-base/stringprintf.h> #include <attestation/HmacKeyManager.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <input/VelocityTracker.h> using std::literals::chrono_literals::operator""ms; @@ -34,7 +33,7 @@ using android::base::StringPrintf; namespace android { -constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; // default display id +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; // default display id constexpr int32_t DEFAULT_POINTER_ID = 0; // pointer ID used for manually defined tests @@ -156,7 +155,7 @@ static std::vector<MotionEvent> createAxisScrollMotionEventStream( MotionEvent event; ui::Transform identityTransform; event.initialize(InputEvent::nextId(), /*deviceId=*/5, AINPUT_SOURCE_ROTARY_ENCODER, - ADISPLAY_ID_NONE, INVALID_HMAC, AMOTION_EVENT_ACTION_SCROLL, + ui::ADISPLAY_ID_NONE, INVALID_HMAC, AMOTION_EVENT_ACTION_SCROLL, /*actionButton=*/0, /*flags=*/0, AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, identityTransform, /*xPrecision=*/0, /*yPrecision=*/0, AMOTION_EVENT_INVALID_CURSOR_POSITION, diff --git a/libs/input/tests/VerifiedInputEvent_test.cpp b/libs/input/tests/VerifiedInputEvent_test.cpp index 277d74dd1c..40cfaaeb05 100644 --- a/libs/input/tests/VerifiedInputEvent_test.cpp +++ b/libs/input/tests/VerifiedInputEvent_test.cpp @@ -16,7 +16,6 @@ #include <attestation/HmacKeyManager.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <input/Input.h> namespace android { @@ -24,7 +23,7 @@ namespace android { static KeyEvent getKeyEventWithFlags(int32_t flags) { KeyEvent event; event.initialize(InputEvent::nextId(), /*deviceId=*/2, AINPUT_SOURCE_GAMEPAD, - ADISPLAY_ID_DEFAULT, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, flags, + ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, flags, AKEYCODE_BUTTON_X, /*scanCode=*/121, AMETA_ALT_ON, /*repeatCount=*/1, /*downTime=*/1000, /*eventTime=*/2000); return event; @@ -44,10 +43,11 @@ static MotionEvent getMotionEventWithFlags(int32_t flags) { ui::Transform transform; transform.set({2, 0, 4, 0, 3, 5, 0, 0, 1}); ui::Transform identity; - event.initialize(InputEvent::nextId(), /*deviceId=*/0, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_DEFAULT, - INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, /*actionButton=*/0, flags, - AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, /*buttonState=*/0, - MotionClassification::NONE, transform, /*xPrecision=*/0.1, /*yPrecision=*/0.2, + event.initialize(InputEvent::nextId(), /*deviceId=*/0, AINPUT_SOURCE_MOUSE, + ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, + /*actionButton=*/0, flags, AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, + /*buttonState=*/0, MotionClassification::NONE, transform, /*xPrecision=*/0.1, + /*yPrecision=*/0.2, /*xCursorPosition=*/280, /*yCursorPosition=*/540, identity, /*downTime=*/100, /*eventTime=*/200, pointerCount, pointerProperties, pointerCoords); return event; diff --git a/libs/ui/include/ui/LogicalDisplayId.h b/libs/ui/include/ui/LogicalDisplayId.h new file mode 100644 index 0000000000..3e504e7101 --- /dev/null +++ b/libs/ui/include/ui/LogicalDisplayId.h @@ -0,0 +1,56 @@ +/* + * Copyright 2024 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. + */ + +#pragma once + +#include <ftl/mixins.h> +#include <sys/types.h> +#include <string> + +#include <ostream> + +namespace android::ui { + +// Type-safe wrapper for a logical display id. +struct LogicalDisplayId : ftl::Constructible<LogicalDisplayId, int32_t>, + ftl::Equatable<LogicalDisplayId>, + ftl::Orderable<LogicalDisplayId> { + using Constructible::Constructible; + + constexpr auto val() const { return ftl::to_underlying(*this); } + + constexpr bool isValid() const { return val() >= 0; } + + std::string toString() const { return std::to_string(val()); } +}; + +constexpr LogicalDisplayId ADISPLAY_ID_NONE{-1}; +constexpr LogicalDisplayId ADISPLAY_ID_DEFAULT{0}; + +inline std::ostream& operator<<(std::ostream& stream, LogicalDisplayId displayId) { + return stream << displayId.val(); +} + +} // namespace android::ui + +namespace std { +template <> +struct hash<android::ui::LogicalDisplayId> { + size_t operator()(const android::ui::LogicalDisplayId& displayId) const { + return hash<int32_t>()(displayId.val()); + } +}; +} // namespace std
\ No newline at end of file diff --git a/services/inputflinger/InputCommonConverter.cpp b/services/inputflinger/InputCommonConverter.cpp index 417c1f333b..e376734b86 100644 --- a/services/inputflinger/InputCommonConverter.cpp +++ b/services/inputflinger/InputCommonConverter.cpp @@ -314,7 +314,7 @@ common::MotionEvent notifyMotionArgsToHalMotionEvent(const NotifyMotionArgs& arg common::MotionEvent event; event.deviceId = args.deviceId; event.source = getSource(args.source); - event.displayId = args.displayId; + event.displayId = args.displayId.val(); event.downTime = args.downTime; event.eventTime = args.eventTime; event.deviceTimestamp = 0; diff --git a/services/inputflinger/InputFilter.cpp b/services/inputflinger/InputFilter.cpp index 1ada5e5678..8e73ce5d94 100644 --- a/services/inputflinger/InputFilter.cpp +++ b/services/inputflinger/InputFilter.cpp @@ -32,7 +32,7 @@ AidlKeyEvent notifyKeyArgsToKeyEvent(const NotifyKeyArgs& args) { event.eventTime = args.eventTime; event.deviceId = args.deviceId; event.source = static_cast<Source>(args.source); - event.displayId = args.displayId; + event.displayId = args.displayId.val(); event.policyFlags = args.policyFlags; event.action = static_cast<KeyEventAction>(args.action); event.flags = args.flags; diff --git a/services/inputflinger/InputFilterCallbacks.cpp b/services/inputflinger/InputFilterCallbacks.cpp index a9bdbec105..5fbdc84c4b 100644 --- a/services/inputflinger/InputFilterCallbacks.cpp +++ b/services/inputflinger/InputFilterCallbacks.cpp @@ -30,9 +30,9 @@ using AidlKeyEvent = aidl::com::android::server::inputflinger::KeyEvent; NotifyKeyArgs keyEventToNotifyKeyArgs(const AidlKeyEvent& event) { return NotifyKeyArgs(event.id, event.eventTime, event.readTime, event.deviceId, - static_cast<uint32_t>(event.source), event.displayId, event.policyFlags, - static_cast<int32_t>(event.action), event.flags, event.keyCode, - event.scanCode, event.metaState, event.downTime); + static_cast<uint32_t>(event.source), ui::LogicalDisplayId{event.displayId}, + event.policyFlags, static_cast<int32_t>(event.action), event.flags, + event.keyCode, event.scanCode, event.metaState, event.downTime); } namespace { diff --git a/services/inputflinger/InputReaderBase.cpp b/services/inputflinger/InputReaderBase.cpp index 4ec5b898b1..29b487f1d2 100644 --- a/services/inputflinger/InputReaderBase.cpp +++ b/services/inputflinger/InputReaderBase.cpp @@ -68,7 +68,7 @@ std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByTyp if (currentViewport.type == type) { if (!result || (type == ViewportType::INTERNAL && - currentViewport.displayId == ADISPLAY_ID_DEFAULT)) { + currentViewport.displayId == ui::ADISPLAY_ID_DEFAULT)) { result = std::make_optional(currentViewport); } count++; @@ -93,7 +93,7 @@ std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByPor } std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportById( - int32_t displayId) const { + ui::LogicalDisplayId displayId) const { for (const DisplayViewport& currentViewport : mDisplays) { if (currentViewport.displayId == displayId) { return std::make_optional(currentViewport); diff --git a/services/inputflinger/NotifyArgs.cpp b/services/inputflinger/NotifyArgs.cpp index de836e93a4..19a4f26a1e 100644 --- a/services/inputflinger/NotifyArgs.cpp +++ b/services/inputflinger/NotifyArgs.cpp @@ -43,7 +43,7 @@ NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(int32_t id, nsecs // --- NotifyKeyArgs --- NotifyKeyArgs::NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId, - uint32_t source, int32_t displayId, uint32_t policyFlags, + uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, nsecs_t downTime) : id(id), @@ -64,7 +64,7 @@ NotifyKeyArgs::NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, in NotifyMotionArgs::NotifyMotionArgs( int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId, uint32_t source, - int32_t displayId, uint32_t policyFlags, int32_t action, int32_t actionButton, + ui::LogicalDisplayId displayId, uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState, MotionClassification classification, int32_t edgeFlags, uint32_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords, float xPrecision, float yPrecision, diff --git a/services/inputflinger/PointerChoreographer.cpp b/services/inputflinger/PointerChoreographer.cpp index a3d0c2b488..d6c6f938d4 100644 --- a/services/inputflinger/PointerChoreographer.cpp +++ b/services/inputflinger/PointerChoreographer.cpp @@ -67,8 +67,9 @@ bool isMouseOrTouchpad(uint32_t sources) { !isFromSource(sources, AINPUT_SOURCE_STYLUS)); } -inline void notifyPointerDisplayChange(std::optional<std::tuple<int32_t, FloatPoint>> change, - PointerChoreographerPolicyInterface& policy) { +inline void notifyPointerDisplayChange( + std::optional<std::tuple<ui::LogicalDisplayId, FloatPoint>> change, + PointerChoreographerPolicyInterface& policy) { if (!change) { return; } @@ -100,8 +101,8 @@ PointerChoreographer::PointerChoreographer(InputListenerInterface& listener, }), mNextListener(listener), mPolicy(policy), - mDefaultMouseDisplayId(ADISPLAY_ID_DEFAULT), - mNotifiedPointerDisplayId(ADISPLAY_ID_NONE), + mDefaultMouseDisplayId(ui::ADISPLAY_ID_DEFAULT), + mNotifiedPointerDisplayId(ui::ADISPLAY_ID_NONE), mShowTouchesEnabled(false), mStylusPointerIconEnabled(false) {} @@ -235,7 +236,7 @@ NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMo } void PointerChoreographer::processDrawingTabletEventLocked(const android::NotifyMotionArgs& args) { - if (args.displayId == ADISPLAY_ID_NONE) { + if (args.displayId == ui::ADISPLAY_ID_NONE) { return; } @@ -272,7 +273,7 @@ void PointerChoreographer::processDrawingTabletEventLocked(const android::Notify * For touch events, we do not need to populate the cursor position. */ void PointerChoreographer::processTouchscreenAndStylusEventLocked(const NotifyMotionArgs& args) { - if (args.displayId == ADISPLAY_ID_NONE) { + if (!args.displayId.isValid()) { return; } @@ -315,7 +316,7 @@ void PointerChoreographer::processTouchscreenAndStylusEventLocked(const NotifyMo } void PointerChoreographer::processStylusHoverEventLocked(const NotifyMotionArgs& args) { - if (args.displayId == ADISPLAY_ID_NONE) { + if (!args.displayId.isValid()) { return; } @@ -423,7 +424,7 @@ void PointerChoreographer::dump(std::string& dump) { dump += INDENT "MousePointerControllers:\n"; for (const auto& [displayId, mousePointerController] : mMousePointersByDisplay) { std::string pointerControllerDump = addLinePrefix(mousePointerController->dump(), INDENT); - dump += INDENT + std::to_string(displayId) + " : " + pointerControllerDump; + dump += INDENT + displayId.toString() + " : " + pointerControllerDump; } dump += INDENT "TouchPointerControllers:\n"; for (const auto& [deviceId, touchPointerController] : mTouchPointersByDevice) { @@ -443,7 +444,8 @@ void PointerChoreographer::dump(std::string& dump) { dump += "\n"; } -const DisplayViewport* PointerChoreographer::findViewportByIdLocked(int32_t displayId) const { +const DisplayViewport* PointerChoreographer::findViewportByIdLocked( + ui::LogicalDisplayId displayId) const { for (auto& viewport : mViewports) { if (viewport.displayId == displayId) { return &viewport; @@ -452,13 +454,14 @@ const DisplayViewport* PointerChoreographer::findViewportByIdLocked(int32_t disp return nullptr; } -int32_t PointerChoreographer::getTargetMouseDisplayLocked(int32_t associatedDisplayId) const { - return associatedDisplayId == ADISPLAY_ID_NONE ? mDefaultMouseDisplayId : associatedDisplayId; +ui::LogicalDisplayId PointerChoreographer::getTargetMouseDisplayLocked( + ui::LogicalDisplayId associatedDisplayId) const { + return associatedDisplayId.isValid() ? associatedDisplayId : mDefaultMouseDisplayId; } -std::pair<int32_t, PointerControllerInterface&> PointerChoreographer::ensureMouseControllerLocked( - int32_t associatedDisplayId) { - const int32_t displayId = getTargetMouseDisplayLocked(associatedDisplayId); +std::pair<ui::LogicalDisplayId, PointerControllerInterface&> +PointerChoreographer::ensureMouseControllerLocked(ui::LogicalDisplayId associatedDisplayId) { + const ui::LogicalDisplayId displayId = getTargetMouseDisplayLocked(associatedDisplayId); auto it = mMousePointersByDisplay.find(displayId); if (it == mMousePointersByDisplay.end()) { @@ -476,12 +479,12 @@ InputDeviceInfo* PointerChoreographer::findInputDeviceLocked(DeviceId deviceId) return it != mInputDeviceInfos.end() ? &(*it) : nullptr; } -bool PointerChoreographer::canUnfadeOnDisplay(int32_t displayId) { +bool PointerChoreographer::canUnfadeOnDisplay(ui::LogicalDisplayId displayId) { return mDisplaysWithPointersHidden.find(displayId) == mDisplaysWithPointersHidden.end(); } PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerControllersLocked() { - std::set<int32_t /*displayId*/> mouseDisplaysToKeep; + std::set<ui::LogicalDisplayId /*displayId*/> mouseDisplaysToKeep; std::set<DeviceId> touchDevicesToKeep; std::set<DeviceId> stylusDevicesToKeep; std::set<DeviceId> drawingTabletDevicesToKeep; @@ -498,7 +501,8 @@ PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerCo const bool isKnownMouse = mMouseDevices.count(info.getId()) != 0; if (isMouseOrTouchpad(sources) || isKnownMouse) { - const int32_t displayId = getTargetMouseDisplayLocked(info.getAssociatedDisplayId()); + const ui::LogicalDisplayId displayId = + getTargetMouseDisplayLocked(info.getAssociatedDisplayId()); mouseDisplaysToKeep.insert(displayId); // For mice, show the cursor immediately when the device is first connected or // when it moves to a new display. @@ -513,15 +517,15 @@ PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerCo } } if (isFromSource(sources, AINPUT_SOURCE_TOUCHSCREEN) && mShowTouchesEnabled && - info.getAssociatedDisplayId() != ADISPLAY_ID_NONE) { + info.getAssociatedDisplayId().isValid()) { touchDevicesToKeep.insert(info.getId()); } if (isFromSource(sources, AINPUT_SOURCE_STYLUS) && mStylusPointerIconEnabled && - info.getAssociatedDisplayId() != ADISPLAY_ID_NONE) { + info.getAssociatedDisplayId().isValid()) { stylusDevicesToKeep.insert(info.getId()); } if (isFromSource(sources, AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE) && - info.getAssociatedDisplayId() != ADISPLAY_ID_NONE) { + info.getAssociatedDisplayId().isValid()) { drawingTabletDevicesToKeep.insert(info.getId()); } } @@ -553,7 +557,7 @@ PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerCo PointerChoreographer::PointerDisplayChange PointerChoreographer::calculatePointerDisplayChangeToNotify() { - int32_t displayIdToNotify = ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayIdToNotify = ui::ADISPLAY_ID_NONE; FloatPoint cursorPosition = {0, 0}; if (const auto it = mMousePointersByDisplay.find(mDefaultMouseDisplayId); it != mMousePointersByDisplay.end()) { @@ -571,7 +575,7 @@ PointerChoreographer::calculatePointerDisplayChangeToNotify() { return {{displayIdToNotify, cursorPosition}}; } -void PointerChoreographer::setDefaultMouseDisplayId(int32_t displayId) { +void PointerChoreographer::setDefaultMouseDisplayId(ui::LogicalDisplayId displayId) { PointerDisplayChange pointerDisplayChange; { // acquire lock @@ -590,7 +594,7 @@ void PointerChoreographer::setDisplayViewports(const std::vector<DisplayViewport { // acquire lock std::scoped_lock _l(mLock); for (const auto& viewport : viewports) { - const int32_t displayId = viewport.displayId; + const ui::LogicalDisplayId displayId = viewport.displayId; if (const auto it = mMousePointersByDisplay.find(displayId); it != mMousePointersByDisplay.end()) { it->second->setDisplayViewport(viewport); @@ -616,18 +620,18 @@ void PointerChoreographer::setDisplayViewports(const std::vector<DisplayViewport } std::optional<DisplayViewport> PointerChoreographer::getViewportForPointerDevice( - int32_t associatedDisplayId) { + ui::LogicalDisplayId associatedDisplayId) { std::scoped_lock _l(mLock); - const int32_t resolvedDisplayId = getTargetMouseDisplayLocked(associatedDisplayId); + const ui::LogicalDisplayId resolvedDisplayId = getTargetMouseDisplayLocked(associatedDisplayId); if (const auto viewport = findViewportByIdLocked(resolvedDisplayId); viewport) { return *viewport; } return std::nullopt; } -FloatPoint PointerChoreographer::getMouseCursorPosition(int32_t displayId) { +FloatPoint PointerChoreographer::getMouseCursorPosition(ui::LogicalDisplayId displayId) { std::scoped_lock _l(mLock); - const int32_t resolvedDisplayId = getTargetMouseDisplayLocked(displayId); + const ui::LogicalDisplayId resolvedDisplayId = getTargetMouseDisplayLocked(displayId); if (auto it = mMousePointersByDisplay.find(resolvedDisplayId); it != mMousePointersByDisplay.end()) { return it->second->getPosition(); @@ -666,8 +670,8 @@ void PointerChoreographer::setStylusPointerIconEnabled(bool enabled) { } bool PointerChoreographer::setPointerIcon( - std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, int32_t displayId, - DeviceId deviceId) { + std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, + ui::LogicalDisplayId displayId, DeviceId deviceId) { std::scoped_lock _l(mLock); if (deviceId < 0) { LOG(WARNING) << "Invalid device id " << deviceId << ". Cannot set pointer icon."; @@ -715,8 +719,8 @@ void PointerChoreographer::onWindowInfosChangedLocked( const std::vector<android::gui::WindowInfo>& windowInfos) { // Mark all spot controllers secure on displays containing secure windows and // remove secure flag from others if required - std::unordered_set<int32_t> privacySensitiveDisplays; - std::unordered_set<int32_t> allDisplayIds; + std::unordered_set<ui::LogicalDisplayId> privacySensitiveDisplays; + std::unordered_set<ui::LogicalDisplayId> allDisplayIds; for (const auto& windowInfo : windowInfos) { allDisplayIds.insert(windowInfo.displayId); if (!windowInfo.inputConfig.test(gui::WindowInfo::InputConfig::NOT_VISIBLE) && @@ -727,7 +731,7 @@ void PointerChoreographer::onWindowInfosChangedLocked( for (auto& it : mTouchPointersByDevice) { auto& pc = it.second; - for (int32_t displayId : allDisplayIds) { + for (ui::LogicalDisplayId displayId : allDisplayIds) { pc->setSkipScreenshot(displayId, privacySensitiveDisplays.find(displayId) != privacySensitiveDisplays.end()); @@ -736,7 +740,7 @@ void PointerChoreographer::onWindowInfosChangedLocked( // TODO (b/325252005): update skip screenshot flag for other types of pointer controllers } -void PointerChoreographer::setPointerIconVisibility(int32_t displayId, bool visible) { +void PointerChoreographer::setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) { std::scoped_lock lock(mLock); if (visible) { mDisplaysWithPointersHidden.erase(displayId); @@ -759,7 +763,7 @@ void PointerChoreographer::setPointerIconVisibility(int32_t displayId, bool visi } PointerChoreographer::ControllerConstructor PointerChoreographer::getMouseControllerConstructor( - int32_t displayId) { + ui::LogicalDisplayId displayId) { std::function<std::shared_ptr<PointerControllerInterface>()> ctor = [this, displayId]() REQUIRES(mLock) { auto pc = mPolicy.createPointerController( @@ -773,7 +777,7 @@ PointerChoreographer::ControllerConstructor PointerChoreographer::getMouseContro } PointerChoreographer::ControllerConstructor PointerChoreographer::getStylusControllerConstructor( - int32_t displayId) { + ui::LogicalDisplayId displayId) { std::function<std::shared_ptr<PointerControllerInterface>()> ctor = [this, displayId]() REQUIRES(mLock) { auto pc = mPolicy.createPointerController( diff --git a/services/inputflinger/PointerChoreographer.h b/services/inputflinger/PointerChoreographer.h index b29d9cdb7c..fda5f5231e 100644 --- a/services/inputflinger/PointerChoreographer.h +++ b/services/inputflinger/PointerChoreographer.h @@ -54,11 +54,11 @@ public: * Set the display that pointers, like the mouse cursor and drawing tablets, * should be drawn on. */ - virtual void setDefaultMouseDisplayId(int32_t displayId) = 0; + virtual void setDefaultMouseDisplayId(ui::LogicalDisplayId displayId) = 0; virtual void setDisplayViewports(const std::vector<DisplayViewport>& viewports) = 0; virtual std::optional<DisplayViewport> getViewportForPointerDevice( - int32_t associatedDisplayId = ADISPLAY_ID_NONE) = 0; - virtual FloatPoint getMouseCursorPosition(int32_t displayId) = 0; + ui::LogicalDisplayId associatedDisplayId = ui::ADISPLAY_ID_NONE) = 0; + virtual FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0; virtual void setShowTouchesEnabled(bool enabled) = 0; virtual void setStylusPointerIconEnabled(bool enabled) = 0; /** @@ -67,12 +67,12 @@ public: * Returns true if the icon was changed successfully, false otherwise. */ virtual bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, - int32_t displayId, DeviceId deviceId) = 0; + ui::LogicalDisplayId displayId, DeviceId deviceId) = 0; /** * Set whether pointer icons for mice, touchpads, and styluses should be visible on the * given display. */ - virtual void setPointerIconVisibility(int32_t displayId, bool visible) = 0; + virtual void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) = 0; /** * This method may be called on any thread (usually by the input manager on a binder thread). @@ -86,16 +86,16 @@ public: PointerChoreographerPolicyInterface&); ~PointerChoreographer() override; - void setDefaultMouseDisplayId(int32_t displayId) override; + void setDefaultMouseDisplayId(ui::LogicalDisplayId displayId) override; void setDisplayViewports(const std::vector<DisplayViewport>& viewports) override; std::optional<DisplayViewport> getViewportForPointerDevice( - int32_t associatedDisplayId) override; - FloatPoint getMouseCursorPosition(int32_t displayId) override; + ui::LogicalDisplayId associatedDisplayId) override; + FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId) override; void setShowTouchesEnabled(bool enabled) override; void setStylusPointerIconEnabled(bool enabled) override; bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, - int32_t displayId, DeviceId deviceId) override; - void setPointerIconVisibility(int32_t displayId, bool visible) override; + ui::LogicalDisplayId displayId, DeviceId deviceId) override; + void setPointerIconVisibility(ui::LogicalDisplayId displayId, bool visible) override; void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override; void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override; @@ -113,16 +113,18 @@ public: void dump(std::string& dump) override; private: - using PointerDisplayChange = - std::optional<std::tuple<int32_t /*displayId*/, FloatPoint /*cursorPosition*/>>; + using PointerDisplayChange = std::optional< + std::tuple<ui::LogicalDisplayId /*displayId*/, FloatPoint /*cursorPosition*/>>; [[nodiscard]] PointerDisplayChange updatePointerControllersLocked() REQUIRES(mLock); [[nodiscard]] PointerDisplayChange calculatePointerDisplayChangeToNotify() REQUIRES(mLock); - const DisplayViewport* findViewportByIdLocked(int32_t displayId) const REQUIRES(mLock); - int32_t getTargetMouseDisplayLocked(int32_t associatedDisplayId) const REQUIRES(mLock); - std::pair<int32_t /*displayId*/, PointerControllerInterface&> ensureMouseControllerLocked( - int32_t associatedDisplayId) REQUIRES(mLock); + const DisplayViewport* findViewportByIdLocked(ui::LogicalDisplayId displayId) const + REQUIRES(mLock); + ui::LogicalDisplayId getTargetMouseDisplayLocked(ui::LogicalDisplayId associatedDisplayId) const + REQUIRES(mLock); + std::pair<ui::LogicalDisplayId /*displayId*/, PointerControllerInterface&> + ensureMouseControllerLocked(ui::LogicalDisplayId associatedDisplayId) REQUIRES(mLock); InputDeviceInfo* findInputDeviceLocked(DeviceId deviceId) REQUIRES(mLock); - bool canUnfadeOnDisplay(int32_t displayId) REQUIRES(mLock); + bool canUnfadeOnDisplay(ui::LogicalDisplayId displayId) REQUIRES(mLock); NotifyMotionArgs processMotion(const NotifyMotionArgs& args); NotifyMotionArgs processMouseEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock); @@ -151,16 +153,18 @@ private: using ControllerConstructor = ConstructorDelegate<std::function<std::shared_ptr<PointerControllerInterface>()>>; ControllerConstructor mTouchControllerConstructor GUARDED_BY(mLock); - ControllerConstructor getMouseControllerConstructor(int32_t displayId) REQUIRES(mLock); - ControllerConstructor getStylusControllerConstructor(int32_t displayId) REQUIRES(mLock); + ControllerConstructor getMouseControllerConstructor(ui::LogicalDisplayId displayId) + REQUIRES(mLock); + ControllerConstructor getStylusControllerConstructor(ui::LogicalDisplayId displayId) + REQUIRES(mLock); std::mutex mLock; InputListenerInterface& mNextListener; PointerChoreographerPolicyInterface& mPolicy; - std::map<int32_t, std::shared_ptr<PointerControllerInterface>> mMousePointersByDisplay - GUARDED_BY(mLock); + std::map<ui::LogicalDisplayId, std::shared_ptr<PointerControllerInterface>> + mMousePointersByDisplay GUARDED_BY(mLock); std::map<DeviceId, std::shared_ptr<PointerControllerInterface>> mTouchPointersByDevice GUARDED_BY(mLock); std::map<DeviceId, std::shared_ptr<PointerControllerInterface>> mStylusPointersByDevice @@ -168,14 +172,14 @@ private: std::map<DeviceId, std::shared_ptr<PointerControllerInterface>> mDrawingTabletPointersByDevice GUARDED_BY(mLock); - int32_t mDefaultMouseDisplayId GUARDED_BY(mLock); - int32_t mNotifiedPointerDisplayId GUARDED_BY(mLock); + ui::LogicalDisplayId mDefaultMouseDisplayId GUARDED_BY(mLock); + ui::LogicalDisplayId mNotifiedPointerDisplayId GUARDED_BY(mLock); std::vector<InputDeviceInfo> mInputDeviceInfos GUARDED_BY(mLock); std::set<DeviceId> mMouseDevices GUARDED_BY(mLock); std::vector<DisplayViewport> mViewports GUARDED_BY(mLock); bool mShowTouchesEnabled GUARDED_BY(mLock); bool mStylusPointerIconEnabled GUARDED_BY(mLock); - std::set<int32_t /*displayId*/> mDisplaysWithPointersHidden; + std::set<ui::LogicalDisplayId /*displayId*/> mDisplaysWithPointersHidden; }; } // namespace android diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index 5f955908c5..66e4a297dd 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -18,7 +18,6 @@ #include <android/os/IInputConstants.h> #include <binder/Binder.h> -#include <gui/constants.h> #include "../dispatcher/InputDispatcher.h" #include "../tests/FakeApplicationHandle.h" #include "../tests/FakeInputDispatcherPolicy.h" @@ -38,7 +37,7 @@ namespace { constexpr DeviceId DEVICE_ID = 1; // An arbitrary display id -constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 5s; @@ -63,7 +62,7 @@ static MotionEvent generateMotionEvent() { ui::Transform identityTransform; MotionEvent event; event.initialize(IInputConstants::INVALID_INPUT_EVENT_ID, DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, + ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, /* actionButton */ 0, /* flags */ 0, /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, identityTransform, /* xPrecision */ 0, @@ -89,7 +88,7 @@ static NotifyMotionArgs generateMotionArgs() { const nsecs_t currentTime = now(); // Define a valid motion event. NotifyMotionArgs args(IInputConstants::INVALID_INPUT_EVENT_ID, currentTime, currentTime, - DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, ui::ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER, AMOTION_EVENT_ACTION_DOWN, /* actionButton */ 0, /* flags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1, diff --git a/services/inputflinger/dispatcher/CancelationOptions.h b/services/inputflinger/dispatcher/CancelationOptions.h index 9c73f03dc8..4a0889f596 100644 --- a/services/inputflinger/dispatcher/CancelationOptions.h +++ b/services/inputflinger/dispatcher/CancelationOptions.h @@ -48,7 +48,7 @@ struct CancelationOptions { std::optional<int32_t> deviceId = std::nullopt; // The specific display id of events to cancel, or nullopt to cancel events on any display. - std::optional<int32_t> displayId = std::nullopt; + std::optional<ui::LogicalDisplayId> displayId = std::nullopt; // The specific pointers to cancel, or nullopt to cancel all pointer events std::optional<std::bitset<MAX_POINTER_ID + 1>> pointerIds = std::nullopt; diff --git a/services/inputflinger/dispatcher/Entry.cpp b/services/inputflinger/dispatcher/Entry.cpp index c8bc87f035..ad9cec1791 100644 --- a/services/inputflinger/dispatcher/Entry.cpp +++ b/services/inputflinger/dispatcher/Entry.cpp @@ -132,9 +132,9 @@ std::string DragEntry::getDescription() const { // --- KeyEntry --- KeyEntry::KeyEntry(int32_t id, std::shared_ptr<InjectionState> injectionState, nsecs_t eventTime, - int32_t deviceId, uint32_t source, int32_t displayId, uint32_t policyFlags, - int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, - int32_t metaState, int32_t repeatCount, nsecs_t downTime) + int32_t deviceId, uint32_t source, ui::LogicalDisplayId displayId, + uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode, + int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime) : EventEntry(id, Type::KEY, eventTime, policyFlags), deviceId(deviceId), source(source), @@ -156,13 +156,14 @@ std::string KeyEntry::getDescription() const { if (!IS_DEBUGGABLE_BUILD) { return "KeyEvent"; } - return StringPrintf("KeyEvent(deviceId=%d, eventTime=%" PRIu64 ", source=%s, displayId=%" PRId32 - ", action=%s, " + return StringPrintf("KeyEvent(deviceId=%d, eventTime=%" PRIu64 ", source=%s, displayId=%s, " + "action=%s, " "flags=0x%08x, keyCode=%s(%d), scanCode=%d, metaState=0x%08x, " "repeatCount=%d), policyFlags=0x%08x", - deviceId, eventTime, inputEventSourceToString(source).c_str(), displayId, - KeyEvent::actionToString(action), flags, KeyEvent::getLabel(keyCode), - keyCode, scanCode, metaState, repeatCount, policyFlags); + deviceId, eventTime, inputEventSourceToString(source).c_str(), + displayId.toString().c_str(), KeyEvent::actionToString(action), flags, + KeyEvent::getLabel(keyCode), keyCode, scanCode, metaState, repeatCount, + policyFlags); } std::ostream& operator<<(std::ostream& out, const KeyEntry& keyEntry) { @@ -172,7 +173,8 @@ std::ostream& operator<<(std::ostream& out, const KeyEntry& keyEntry) { // --- TouchModeEntry --- -TouchModeEntry::TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode, int displayId) +TouchModeEntry::TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode, + ui::LogicalDisplayId displayId) : EventEntry(id, Type::TOUCH_MODE_CHANGED, eventTime, POLICY_FLAG_PASS_TO_USER), inTouchMode(inTouchMode), displayId(displayId) {} @@ -184,12 +186,13 @@ std::string TouchModeEntry::getDescription() const { // --- MotionEntry --- MotionEntry::MotionEntry(int32_t id, std::shared_ptr<InjectionState> injectionState, - nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId, - uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags, - int32_t metaState, int32_t buttonState, - MotionClassification classification, int32_t edgeFlags, float xPrecision, - float yPrecision, float xCursorPosition, float yCursorPosition, - nsecs_t downTime, const std::vector<PointerProperties>& pointerProperties, + nsecs_t eventTime, int32_t deviceId, uint32_t source, + ui::LogicalDisplayId displayId, uint32_t policyFlags, int32_t action, + int32_t actionButton, int32_t flags, int32_t metaState, + int32_t buttonState, MotionClassification classification, + int32_t edgeFlags, float xPrecision, float yPrecision, + float xCursorPosition, float yCursorPosition, nsecs_t downTime, + const std::vector<PointerProperties>& pointerProperties, const std::vector<PointerCoords>& pointerCoords) : EventEntry(id, Type::MOTION, eventTime, policyFlags), deviceId(deviceId), @@ -218,15 +221,16 @@ std::string MotionEntry::getDescription() const { } std::string msg; msg += StringPrintf("MotionEvent(deviceId=%d, eventTime=%" PRIu64 - ", source=%s, displayId=%" PRId32 - ", action=%s, actionButton=0x%08x, flags=0x%08x, metaState=0x%08x, " + ", source=%s, displayId=%s, action=%s, actionButton=0x%08x, flags=0x%08x," + " metaState=0x%08x, " "buttonState=0x%08x, " "classification=%s, edgeFlags=0x%08x, xPrecision=%.1f, yPrecision=%.1f, " "xCursorPosition=%0.1f, yCursorPosition=%0.1f, pointers=[", - deviceId, eventTime, inputEventSourceToString(source).c_str(), displayId, - MotionEvent::actionToString(action).c_str(), actionButton, flags, metaState, - buttonState, motionClassificationToString(classification), edgeFlags, - xPrecision, yPrecision, xCursorPosition, yCursorPosition); + deviceId, eventTime, inputEventSourceToString(source).c_str(), + displayId.toString().c_str(), MotionEvent::actionToString(action).c_str(), + actionButton, flags, metaState, buttonState, + motionClassificationToString(classification), edgeFlags, xPrecision, + yPrecision, xCursorPosition, yCursorPosition); for (uint32_t i = 0; i < getPointerCount(); i++) { if (i) { diff --git a/services/inputflinger/dispatcher/Entry.h b/services/inputflinger/dispatcher/Entry.h index 06d5c7dd4b..f2f31d88ef 100644 --- a/services/inputflinger/dispatcher/Entry.h +++ b/services/inputflinger/dispatcher/Entry.h @@ -120,7 +120,7 @@ struct DragEntry : EventEntry { struct KeyEntry : EventEntry { int32_t deviceId; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId; int32_t action; int32_t keyCode; int32_t scanCode; @@ -144,9 +144,9 @@ struct KeyEntry : EventEntry { mutable int32_t repeatCount; KeyEntry(int32_t id, std::shared_ptr<InjectionState> injectionState, nsecs_t eventTime, - int32_t deviceId, uint32_t source, int32_t displayId, uint32_t policyFlags, - int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, - int32_t repeatCount, nsecs_t downTime); + int32_t deviceId, uint32_t source, ui::LogicalDisplayId displayId, + uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, + int32_t metaState, int32_t repeatCount, nsecs_t downTime); std::string getDescription() const override; }; @@ -155,7 +155,7 @@ std::ostream& operator<<(std::ostream& out, const KeyEntry& motionEntry); struct MotionEntry : EventEntry { int32_t deviceId; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId; int32_t action; int32_t actionButton; int32_t flags; @@ -175,11 +175,12 @@ struct MotionEntry : EventEntry { size_t getPointerCount() const { return pointerProperties.size(); } MotionEntry(int32_t id, std::shared_ptr<InjectionState> injectionState, nsecs_t eventTime, - int32_t deviceId, uint32_t source, int32_t displayId, uint32_t policyFlags, - int32_t action, int32_t actionButton, int32_t flags, int32_t metaState, - int32_t buttonState, MotionClassification classification, int32_t edgeFlags, - float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, - nsecs_t downTime, const std::vector<PointerProperties>& pointerProperties, + int32_t deviceId, uint32_t source, ui::LogicalDisplayId displayId, + uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags, + int32_t metaState, int32_t buttonState, MotionClassification classification, + int32_t edgeFlags, float xPrecision, float yPrecision, float xCursorPosition, + float yCursorPosition, nsecs_t downTime, + const std::vector<PointerProperties>& pointerProperties, const std::vector<PointerCoords>& pointerCoords); std::string getDescription() const override; }; @@ -205,9 +206,9 @@ struct SensorEntry : EventEntry { struct TouchModeEntry : EventEntry { bool inTouchMode; - int32_t displayId; + ui::LogicalDisplayId displayId; - TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode, int32_t displayId); + TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode, ui::LogicalDisplayId displayId); std::string getDescription() const override; }; diff --git a/services/inputflinger/dispatcher/FocusResolver.cpp b/services/inputflinger/dispatcher/FocusResolver.cpp index 0e4e79e88e..b374fad4bc 100644 --- a/services/inputflinger/dispatcher/FocusResolver.cpp +++ b/services/inputflinger/dispatcher/FocusResolver.cpp @@ -41,12 +41,12 @@ struct SpHash { size_t operator()(const sp<T>& k) const { return std::hash<T*>()(k.get()); } }; -sp<IBinder> FocusResolver::getFocusedWindowToken(int32_t displayId) const { +sp<IBinder> FocusResolver::getFocusedWindowToken(ui::LogicalDisplayId displayId) const { auto it = mFocusedWindowTokenByDisplay.find(displayId); return it != mFocusedWindowTokenByDisplay.end() ? it->second.second : nullptr; } -std::optional<FocusRequest> FocusResolver::getFocusRequest(int32_t displayId) { +std::optional<FocusRequest> FocusResolver::getFocusRequest(ui::LogicalDisplayId displayId) { auto it = mFocusRequestByDisplay.find(displayId); return it != mFocusRequestByDisplay.end() ? std::make_optional<>(it->second) : std::nullopt; } @@ -58,7 +58,7 @@ std::optional<FocusRequest> FocusResolver::getFocusRequest(int32_t displayId) { * we will check if the previous focus request is eligible to receive focus. */ std::optional<FocusResolver::FocusChanges> FocusResolver::setInputWindows( - int32_t displayId, const std::vector<sp<WindowInfoHandle>>& windows) { + ui::LogicalDisplayId displayId, const std::vector<sp<WindowInfoHandle>>& windows) { std::string removeFocusReason; const std::optional<FocusRequest> request = getFocusRequest(displayId); @@ -94,12 +94,11 @@ std::optional<FocusResolver::FocusChanges> FocusResolver::setInputWindows( std::optional<FocusResolver::FocusChanges> FocusResolver::setFocusedWindow( const FocusRequest& request, const std::vector<sp<WindowInfoHandle>>& windows) { - const int32_t displayId = request.displayId; + const ui::LogicalDisplayId displayId = ui::LogicalDisplayId{request.displayId}; const sp<IBinder> currentFocus = getFocusedWindowToken(displayId); if (currentFocus == request.token) { - ALOGD_IF(DEBUG_FOCUS, - "setFocusedWindow %s on display %" PRId32 " ignored, reason: already focused", - request.windowName.c_str(), displayId); + ALOGD_IF(DEBUG_FOCUS, "setFocusedWindow %s on display %s ignored, reason: already focused", + request.windowName.c_str(), displayId.toString().c_str()); return std::nullopt; } @@ -193,7 +192,7 @@ FocusResolver::Focusability FocusResolver::isTokenFocusable( } std::optional<FocusResolver::FocusChanges> FocusResolver::updateFocusedWindow( - int32_t displayId, const std::string& reason, const sp<IBinder>& newFocus, + ui::LogicalDisplayId displayId, const std::string& reason, const sp<IBinder>& newFocus, const std::string& tokenName) { sp<IBinder> oldFocus = getFocusedWindowToken(displayId); if (newFocus == oldFocus) { @@ -216,8 +215,8 @@ std::string FocusResolver::dumpFocusedWindows() const { std::string dump; dump += INDENT "FocusedWindows:\n"; for (const auto& [displayId, namedToken] : mFocusedWindowTokenByDisplay) { - dump += base::StringPrintf(INDENT2 "displayId=%" PRId32 ", name='%s'\n", displayId, - namedToken.first.c_str()); + dump += base::StringPrintf(INDENT2 "displayId=%s, name='%s'\n", + displayId.toString().c_str(), namedToken.first.c_str()); } return dump; } @@ -233,13 +232,14 @@ std::string FocusResolver::dump() const { auto it = mLastFocusResultByDisplay.find(displayId); std::string result = it != mLastFocusResultByDisplay.end() ? ftl::enum_string(it->second) : ""; - dump += base::StringPrintf(INDENT2 "displayId=%" PRId32 ", name='%s' result='%s'\n", - displayId, request.windowName.c_str(), result.c_str()); + dump += base::StringPrintf(INDENT2 "displayId=%s, name='%s' result='%s'\n", + displayId.toString().c_str(), request.windowName.c_str(), + result.c_str()); } return dump; } -void FocusResolver::displayRemoved(int32_t displayId) { +void FocusResolver::displayRemoved(ui::LogicalDisplayId displayId) { mFocusRequestByDisplay.erase(displayId); mLastFocusResultByDisplay.erase(displayId); } diff --git a/services/inputflinger/dispatcher/FocusResolver.h b/services/inputflinger/dispatcher/FocusResolver.h index 5bb157b7c6..2910ba44c8 100644 --- a/services/inputflinger/dispatcher/FocusResolver.h +++ b/services/inputflinger/dispatcher/FocusResolver.h @@ -49,22 +49,23 @@ namespace android::inputdispatcher { class FocusResolver { public: // Returns the focused window token on the specified display. - sp<IBinder> getFocusedWindowToken(int32_t displayId) const; + sp<IBinder> getFocusedWindowToken(ui::LogicalDisplayId displayId) const; struct FocusChanges { sp<IBinder> oldFocus; sp<IBinder> newFocus; - int32_t displayId; + ui::LogicalDisplayId displayId; std::string reason; }; std::optional<FocusResolver::FocusChanges> setInputWindows( - int32_t displayId, const std::vector<sp<android::gui::WindowInfoHandle>>& windows); + ui::LogicalDisplayId displayId, + const std::vector<sp<android::gui::WindowInfoHandle>>& windows); std::optional<FocusResolver::FocusChanges> setFocusedWindow( const android::gui::FocusRequest& request, const std::vector<sp<android::gui::WindowInfoHandle>>& windows); // Display has been removed from the system, clean up old references. - void displayRemoved(int32_t displayId); + void displayRemoved(ui::LogicalDisplayId displayId); // exposed for debugging bool hasFocusedWindowTokens() const { return !mFocusedWindowTokenByDisplay.empty(); } @@ -105,20 +106,23 @@ private: // the same token. Focus is tracked by the token per display and the events are dispatched // to the channel associated by this token. typedef std::pair<std::string /* name */, sp<IBinder>> NamedToken; - std::unordered_map<int32_t /* displayId */, NamedToken> mFocusedWindowTokenByDisplay; + std::unordered_map<ui::LogicalDisplayId /* displayId */, NamedToken> + mFocusedWindowTokenByDisplay; // This map will store the focus request per display. When the input window handles are updated, // the current request will be checked to see if it can be processed at that time. - std::unordered_map<int32_t /* displayId */, android::gui::FocusRequest> mFocusRequestByDisplay; + std::unordered_map<ui::LogicalDisplayId /* displayId */, android::gui::FocusRequest> + mFocusRequestByDisplay; // Last reason for not granting a focus request. This is used to add more debug information // in the event logs. - std::unordered_map<int32_t /* displayId */, Focusability> mLastFocusResultByDisplay; + std::unordered_map<ui::LogicalDisplayId /* displayId */, Focusability> + mLastFocusResultByDisplay; std::optional<FocusResolver::FocusChanges> updateFocusedWindow( - int32_t displayId, const std::string& reason, const sp<IBinder>& token, + ui::LogicalDisplayId displayId, const std::string& reason, const sp<IBinder>& token, const std::string& tokenName = ""); - std::optional<android::gui::FocusRequest> getFocusRequest(int32_t displayId); + std::optional<android::gui::FocusRequest> getFocusRequest(ui::LogicalDisplayId displayId); }; } // namespace android::inputdispatcher diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 79b8560590..c4bfa624f5 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -571,8 +571,8 @@ bool isUserActivityEvent(const EventEntry& eventEntry) { } // Returns true if the given window can accept pointer events at the given display location. -bool windowAcceptsTouchAt(const WindowInfo& windowInfo, int32_t displayId, float x, float y, - bool isStylus, const ui::Transform& displayTransform) { +bool windowAcceptsTouchAt(const WindowInfo& windowInfo, ui::LogicalDisplayId displayId, float x, + float y, bool isStylus, const ui::Transform& displayTransform) { const auto inputConfig = windowInfo.inputConfig; if (windowInfo.displayId != displayId || inputConfig.test(WindowInfo::InputConfig::NOT_VISIBLE)) { @@ -600,8 +600,8 @@ bool windowAcceptsTouchAt(const WindowInfo& windowInfo, int32_t displayId, float // Returns true if the given window's frame can occlude pointer events at the given display // location. -bool windowOccludesTouchAt(const WindowInfo& windowInfo, int displayId, float x, float y, - const ui::Transform& displayTransform) { +bool windowOccludesTouchAt(const WindowInfo& windowInfo, ui::LogicalDisplayId displayId, float x, + float y, const ui::Transform& displayTransform) { if (windowInfo.displayId != displayId) { return false; } @@ -815,9 +815,9 @@ bool shouldSplitTouch(const TouchState& touchState, const MotionEntry& entry) { /** * Return true if stylus is currently down anywhere on the specified display, and false otherwise. */ -bool isStylusActiveInDisplay( - int32_t displayId, - const std::unordered_map<int32_t /*displayId*/, TouchState>& touchStatesByDisplay) { +bool isStylusActiveInDisplay(ui::LogicalDisplayId displayId, + const std::unordered_map<ui::LogicalDisplayId /*displayId*/, + TouchState>& touchStatesByDisplay) { const auto it = touchStatesByDisplay.find(displayId); if (it == touchStatesByDisplay.end()) { return false; @@ -918,8 +918,9 @@ InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy, mDispatchFrozen(false), mInputFilterEnabled(false), mMaximumObscuringOpacityForTouch(1.0f), - mFocusedDisplayId(ADISPLAY_ID_DEFAULT), + mFocusedDisplayId(ui::ADISPLAY_ID_DEFAULT), mWindowTokenWithPointerCapture(nullptr), + mAwaitedApplicationDisplayId(ui::ADISPLAY_ID_NONE), mLatencyAggregator(), mLatencyTracker(&mLatencyAggregator) { mLooper = sp<Looper>::make(false); @@ -1286,7 +1287,7 @@ bool InputDispatcher::shouldPruneInboundQueueLocked(const MotionEntry& motionEnt // If the application takes too long to catch up then we drop all events preceding // the touch into the other window. if (isPointerDownEvent && mAwaitedFocusedApplication != nullptr) { - const int32_t displayId = motionEntry.displayId; + const ui::LogicalDisplayId displayId = motionEntry.displayId; const auto [x, y] = resolveTouchedPosition(motionEntry); const bool isStylus = isPointerFromStylus(motionEntry, /*pointerIndex=*/0); @@ -1411,8 +1412,8 @@ void InputDispatcher::addRecentEventLocked(std::shared_ptr<const EventEntry> ent } } -sp<WindowInfoHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t displayId, float x, float y, - bool isStylus, +sp<WindowInfoHandle> InputDispatcher::findTouchedWindowAtLocked(ui::LogicalDisplayId displayId, + float x, float y, bool isStylus, bool ignoreDragWindow) const { // Traverse windows from front to back to find touched window. const auto& windowHandles = getWindowHandlesLocked(displayId); @@ -1431,7 +1432,8 @@ sp<WindowInfoHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t displayI } std::vector<InputTarget> InputDispatcher::findOutsideTargetsLocked( - int32_t displayId, const sp<WindowInfoHandle>& touchedWindow, int32_t pointerId) const { + ui::LogicalDisplayId displayId, const sp<WindowInfoHandle>& touchedWindow, + int32_t pointerId) const { if (touchedWindow == nullptr) { return {}; } @@ -1458,7 +1460,7 @@ std::vector<InputTarget> InputDispatcher::findOutsideTargetsLocked( } std::vector<sp<WindowInfoHandle>> InputDispatcher::findTouchedSpyWindowsAtLocked( - int32_t displayId, float x, float y, bool isStylus) const { + ui::LogicalDisplayId displayId, float x, float y, bool isStylus) const { // Traverse windows from front to back and gather the touched spy windows. std::vector<sp<WindowInfoHandle>> spyWindows; const auto& windowHandles = getWindowHandlesLocked(displayId); @@ -1951,12 +1953,12 @@ bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<con void InputDispatcher::logOutboundKeyDetails(const char* prefix, const KeyEntry& entry) { if (DEBUG_OUTBOUND_EVENT_DETAILS) { - ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=0x%x, displayId=%" PRId32 ", " + ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=0x%x, displayId=%s, " "policyFlags=0x%x, action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, " "metaState=0x%x, repeatCount=%d, downTime=%" PRId64, - prefix, entry.eventTime, entry.deviceId, entry.source, entry.displayId, - entry.policyFlags, entry.action, entry.flags, entry.keyCode, entry.scanCode, - entry.metaState, entry.repeatCount, entry.downTime); + prefix, entry.eventTime, entry.deviceId, entry.source, + entry.displayId.toString().c_str(), entry.policyFlags, entry.action, entry.flags, + entry.keyCode, entry.scanCode, entry.metaState, entry.repeatCount, entry.downTime); } } @@ -2105,16 +2107,15 @@ void InputDispatcher::dispatchDragLocked(nsecs_t currentTime, void InputDispatcher::logOutboundMotionDetails(const char* prefix, const MotionEntry& entry) { if (DEBUG_OUTBOUND_EVENT_DETAILS) { - ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=%s, displayId=%" PRId32 - ", policyFlags=0x%x, " + ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=%s, displayId=%s, policyFlags=0x%x, " "action=%s, actionButton=0x%x, flags=0x%x, " "metaState=0x%x, buttonState=0x%x," "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%" PRId64, prefix, entry.eventTime, entry.deviceId, - inputEventSourceToString(entry.source).c_str(), entry.displayId, entry.policyFlags, - MotionEvent::actionToString(entry.action).c_str(), entry.actionButton, entry.flags, - entry.metaState, entry.buttonState, entry.edgeFlags, entry.xPrecision, - entry.yPrecision, entry.downTime); + inputEventSourceToString(entry.source).c_str(), entry.displayId.toString().c_str(), + entry.policyFlags, MotionEvent::actionToString(entry.action).c_str(), + entry.actionButton, entry.flags, entry.metaState, entry.buttonState, entry.edgeFlags, + entry.xPrecision, entry.yPrecision, entry.downTime); for (uint32_t i = 0; i < entry.getPointerCount(); i++) { ALOGD(" Pointer %d: id=%d, toolType=%s, " @@ -2199,8 +2200,8 @@ void InputDispatcher::resetNoFocusedWindowTimeoutLocked() { * then it should be dispatched to that display. Otherwise, the event goes to the focused display. * Focused display is the display that the user most recently interacted with. */ -int32_t InputDispatcher::getTargetDisplayId(const EventEntry& entry) { - int32_t displayId; +ui::LogicalDisplayId InputDispatcher::getTargetDisplayId(const EventEntry& entry) { + ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; switch (entry.type) { case EventEntry::Type::KEY: { const KeyEntry& keyEntry = static_cast<const KeyEntry&>(entry); @@ -2220,10 +2221,10 @@ int32_t InputDispatcher::getTargetDisplayId(const EventEntry& entry) { case EventEntry::Type::SENSOR: case EventEntry::Type::DRAG: { ALOGE("%s events do not have a target display", ftl::enum_string(entry.type).c_str()); - return ADISPLAY_ID_NONE; + return ui::ADISPLAY_ID_NONE; } } - return displayId == ADISPLAY_ID_NONE ? mFocusedDisplayId : displayId; + return displayId == ui::ADISPLAY_ID_NONE ? mFocusedDisplayId : displayId; } bool InputDispatcher::shouldWaitToSendKeyLocked(nsecs_t currentTime, @@ -2262,7 +2263,7 @@ sp<WindowInfoHandle> InputDispatcher::findFocusedWindowTargetLocked( InputEventInjectionResult& outInjectionResult) { outInjectionResult = InputEventInjectionResult::FAILED; // Default result - int32_t displayId = getTargetDisplayId(entry); + ui::LogicalDisplayId displayId = getTargetDisplayId(entry); sp<WindowInfoHandle> focusedWindowHandle = getFocusedWindowHandleLocked(displayId); std::shared_ptr<InputApplicationHandle> focusedApplicationHandle = getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); @@ -2271,8 +2272,8 @@ sp<WindowInfoHandle> InputDispatcher::findFocusedWindowTargetLocked( // then drop the event. if (focusedWindowHandle == nullptr && focusedApplicationHandle == nullptr) { ALOGI("Dropping %s event because there is no focused window or focused application in " - "display %" PRId32 ".", - ftl::enum_string(entry.type).c_str(), displayId); + "display %s.", + ftl::enum_string(entry.type).c_str(), displayId.toString().c_str()); return nullptr; } @@ -2380,7 +2381,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked( std::vector<InputTarget> targets; // For security reasons, we defer updating the touch state until we are sure that // event injection will be allowed. - const int32_t displayId = entry.displayId; + const ui::LogicalDisplayId displayId = entry.displayId; const int32_t action = entry.action; const int32_t maskedAction = MotionEvent::getActionMasked(action); @@ -2450,7 +2451,8 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked( } // Handle the case where we did not find a window. if (newTouchedWindowHandle == nullptr) { - ALOGD("No new touched window at (%.1f, %.1f) in display %" PRId32, x, y, displayId); + ALOGD("No new touched window at (%.1f, %.1f) in display %s", x, y, + displayId.toString().c_str()); // Try to assign the pointer to the first foreground window we find, if there is one. newTouchedWindowHandle = tempTouchState.getFirstForegroundWindowHandle(entry.deviceId); } @@ -2491,8 +2493,8 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked( if (newTouchedWindows.empty()) { ALOGI("Dropping event because there is no touchable window at (%.1f, %.1f) on display " - "%d.", - x, y, displayId); + "%s.", + x, y, displayId.toString().c_str()); outInjectionResult = InputEventInjectionResult::FAILED; return {}; } @@ -2640,9 +2642,9 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked( if (newTouchedWindowHandle != nullptr && !haveSameToken(oldTouchedWindowHandle, newTouchedWindowHandle)) { - ALOGI("Touch is slipping out of window %s into window %s in display %" PRId32, + ALOGI("Touch is slipping out of window %s into window %s in display %s", oldTouchedWindowHandle->getName().c_str(), - newTouchedWindowHandle->getName().c_str(), displayId); + newTouchedWindowHandle->getName().c_str(), displayId.toString().c_str()); // Make a slippery exit from the old window. std::bitset<MAX_POINTER_ID + 1> pointerIds; @@ -2827,7 +2829,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked( // Save changes unless the action was scroll in which case the temporary touch // state was only valid for this one action. if (maskedAction != AMOTION_EVENT_ACTION_SCROLL) { - if (displayId >= 0) { + if (displayId >= ui::ADISPLAY_ID_DEFAULT) { tempTouchState.clearWindowsWithoutPointers(); mTouchStatesByDisplay[displayId] = tempTouchState; } else { @@ -2842,7 +2844,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked( return targets; } -void InputDispatcher::finishDragAndDrop(int32_t displayId, float x, float y) { +void InputDispatcher::finishDragAndDrop(ui::LogicalDisplayId displayId, float x, float y) { // Prevent stylus interceptor windows from affecting drag and drop behavior for now, until we // have an explicit reason to support it. constexpr bool isStylus = false; @@ -3059,7 +3061,7 @@ void InputDispatcher::addPointerWindowTargetLocked( } void InputDispatcher::addGlobalMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets, - int32_t displayId) { + ui::LogicalDisplayId displayId) { auto monitorsIt = mGlobalMonitorsByDisplay.find(displayId); if (monitorsIt == mGlobalMonitorsByDisplay.end()) return; @@ -3131,7 +3133,7 @@ static bool canBeObscuredBy(const sp<WindowInfoHandle>& windowHandle, InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLocked( const sp<WindowInfoHandle>& windowHandle, float x, float y) const { const WindowInfo* windowInfo = windowHandle->getInfo(); - int32_t displayId = windowInfo->displayId; + ui::LogicalDisplayId displayId = windowInfo->displayId; const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesLocked(displayId); TouchOcclusionInfo info; info.hasBlockingOcclusion = false; @@ -3215,7 +3217,7 @@ bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionIn bool InputDispatcher::isWindowObscuredAtPointLocked(const sp<WindowInfoHandle>& windowHandle, float x, float y) const { - int32_t displayId = windowHandle->getInfo()->displayId; + ui::LogicalDisplayId displayId = windowHandle->getInfo()->displayId; const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesLocked(displayId); for (const sp<WindowInfoHandle>& otherHandle : windowHandles) { if (windowHandle == otherHandle) { @@ -3231,7 +3233,7 @@ bool InputDispatcher::isWindowObscuredAtPointLocked(const sp<WindowInfoHandle>& } bool InputDispatcher::isWindowObscuredLocked(const sp<WindowInfoHandle>& windowHandle) const { - int32_t displayId = windowHandle->getInfo()->displayId; + ui::LogicalDisplayId displayId = windowHandle->getInfo()->displayId; const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesLocked(displayId); const WindowInfo* windowInfo = windowHandle->getInfo(); for (const sp<WindowInfoHandle>& otherHandle : windowHandles) { @@ -3239,8 +3241,7 @@ bool InputDispatcher::isWindowObscuredLocked(const sp<WindowInfoHandle>& windowH break; // All future windows are below us. Exit early. } const WindowInfo* otherInfo = otherHandle->getInfo(); - if (canBeObscuredBy(windowHandle, otherHandle) && - otherInfo->overlaps(windowInfo)) { + if (canBeObscuredBy(windowHandle, otherHandle) && otherInfo->overlaps(windowInfo)) { return true; } } @@ -3282,7 +3283,7 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) { } } - int32_t displayId = getTargetDisplayId(eventEntry); + ui::LogicalDisplayId displayId = getTargetDisplayId(eventEntry); sp<WindowInfoHandle> focusedWindowHandle = getFocusedWindowHandleLocked(displayId); const WindowInfo* windowDisablingUserActivityInfo = nullptr; if (focusedWindowHandle != nullptr) { @@ -4465,12 +4466,13 @@ void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChange void InputDispatcher::notifyKey(const NotifyKeyArgs& args) { ALOGD_IF(debugInboundEventDetails(), "notifyKey - id=%" PRIx32 ", eventTime=%" PRId64 - ", deviceId=%d, source=%s, displayId=%" PRId32 - "policyFlags=0x%x, action=%s, flags=0x%x, keyCode=%s, scanCode=0x%x, metaState=0x%x, " + ", deviceId=%d, source=%s, displayId=%s, policyFlags=0x%x, action=%s, flags=0x%x, " + "keyCode=%s, scanCode=0x%x, metaState=0x%x, " "downTime=%" PRId64, args.id, args.eventTime, args.deviceId, inputEventSourceToString(args.source).c_str(), - args.displayId, args.policyFlags, KeyEvent::actionToString(args.action), args.flags, - KeyEvent::getLabel(args.keyCode), args.scanCode, args.metaState, args.downTime); + args.displayId.toString().c_str(), args.policyFlags, + KeyEvent::actionToString(args.action), args.flags, KeyEvent::getLabel(args.keyCode), + args.scanCode, args.metaState, args.downTime); Result<void> keyCheck = validateKeyEvent(args.action); if (!keyCheck.ok()) { LOG(ERROR) << "invalid key event: " << keyCheck.error(); @@ -4546,15 +4548,15 @@ bool InputDispatcher::shouldSendKeyToInputFilterLocked(const NotifyKeyArgs& args void InputDispatcher::notifyMotion(const NotifyMotionArgs& args) { if (debugInboundEventDetails()) { ALOGD("notifyMotion - id=%" PRIx32 " eventTime=%" PRId64 ", deviceId=%d, source=%s, " - "displayId=%" PRId32 ", policyFlags=0x%x, " + "displayId=%s, policyFlags=0x%x, " "action=%s, actionButton=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x, " "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, xCursorPosition=%f, " "yCursorPosition=%f, downTime=%" PRId64, args.id, args.eventTime, args.deviceId, inputEventSourceToString(args.source).c_str(), - args.displayId, args.policyFlags, MotionEvent::actionToString(args.action).c_str(), - args.actionButton, args.flags, args.metaState, args.buttonState, args.edgeFlags, - args.xPrecision, args.yPrecision, args.xCursorPosition, args.yCursorPosition, - args.downTime); + args.displayId.toString().c_str(), args.policyFlags, + MotionEvent::actionToString(args.action).c_str(), args.actionButton, args.flags, + args.metaState, args.buttonState, args.edgeFlags, args.xPrecision, args.yPrecision, + args.xCursorPosition, args.yCursorPosition, args.downTime); for (uint32_t i = 0; i < args.getPointerCount(); i++) { ALOGD(" Pointer %d: id=%d, toolType=%s, x=%f, y=%f, pressure=%f, size=%f, " "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, orientation=%f", @@ -4583,7 +4585,8 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs& args) { if (DEBUG_VERIFY_EVENTS) { auto [it, _] = mVerifiersByDisplay.try_emplace(args.displayId, - StringPrintf("display %" PRId32, args.displayId)); + StringPrintf("display %s", + args.displayId.toString().c_str())); Result<void> result = it->second.processMovement(args.deviceId, args.source, args.action, args.getPointerCount(), args.pointerProperties.data(), @@ -4857,8 +4860,9 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev const bool isPointerEvent = isFromSource(event->getSource(), AINPUT_SOURCE_CLASS_POINTER); // If a pointer event has no displayId specified, inject it to the default display. - const int32_t displayId = isPointerEvent && (event->getDisplayId() == ADISPLAY_ID_NONE) - ? ADISPLAY_ID_DEFAULT + const ui::LogicalDisplayId displayId = + isPointerEvent && (event->getDisplayId() == ui::ADISPLAY_ID_NONE) + ? ui::ADISPLAY_ID_DEFAULT : event->getDisplayId(); int32_t flags = motionEvent.getFlags(); @@ -5125,22 +5129,21 @@ void InputDispatcher::decrementPendingForegroundDispatches(const EventEntry& ent } const std::vector<sp<WindowInfoHandle>>& InputDispatcher::getWindowHandlesLocked( - int32_t displayId) const { + ui::LogicalDisplayId displayId) const { static const std::vector<sp<WindowInfoHandle>> EMPTY_WINDOW_HANDLES; auto it = mWindowHandlesByDisplay.find(displayId); return it != mWindowHandlesByDisplay.end() ? it->second : EMPTY_WINDOW_HANDLES; } sp<WindowInfoHandle> InputDispatcher::getWindowHandleLocked( - const sp<IBinder>& windowHandleToken, std::optional<int32_t> displayId) const { + const sp<IBinder>& windowHandleToken, std::optional<ui::LogicalDisplayId> displayId) const { if (windowHandleToken == nullptr) { return nullptr; } if (!displayId) { // Look through all displays. - for (auto& it : mWindowHandlesByDisplay) { - const std::vector<sp<WindowInfoHandle>>& windowHandles = it.second; + for (const auto& [_, windowHandles] : mWindowHandlesByDisplay) { for (const sp<WindowInfoHandle>& windowHandle : windowHandles) { if (windowHandle->getToken() == windowHandleToken) { return windowHandle; @@ -5161,16 +5164,15 @@ sp<WindowInfoHandle> InputDispatcher::getWindowHandleLocked( sp<WindowInfoHandle> InputDispatcher::getWindowHandleLocked( const sp<WindowInfoHandle>& windowHandle) const { - for (auto& it : mWindowHandlesByDisplay) { - const std::vector<sp<WindowInfoHandle>>& windowHandles = it.second; + for (const auto& [displayId, windowHandles] : mWindowHandlesByDisplay) { for (const sp<WindowInfoHandle>& handle : windowHandles) { if (handle->getId() == windowHandle->getId() && handle->getToken() == windowHandle->getToken()) { - if (windowHandle->getInfo()->displayId != it.first) { - ALOGE("Found window %s in display %" PRId32 - ", but it should belong to display %" PRId32, - windowHandle->getName().c_str(), it.first, - windowHandle->getInfo()->displayId); + if (windowHandle->getInfo()->displayId != displayId) { + ALOGE("Found window %s in display %s" + ", but it should belong to display %s", + windowHandle->getName().c_str(), displayId.toString().c_str(), + windowHandle->getInfo()->displayId.toString().c_str()); } return handle; } @@ -5179,12 +5181,13 @@ sp<WindowInfoHandle> InputDispatcher::getWindowHandleLocked( return nullptr; } -sp<WindowInfoHandle> InputDispatcher::getFocusedWindowHandleLocked(int displayId) const { +sp<WindowInfoHandle> InputDispatcher::getFocusedWindowHandleLocked( + ui::LogicalDisplayId displayId) const { sp<IBinder> focusedToken = mFocusResolver.getFocusedWindowToken(displayId); return getWindowHandleLocked(focusedToken, displayId); } -ui::Transform InputDispatcher::getTransformLocked(int32_t displayId) const { +ui::Transform InputDispatcher::getTransformLocked(ui::LogicalDisplayId displayId) const { auto displayInfoIt = mDisplayInfos.find(displayId); return displayInfoIt != mDisplayInfos.end() ? displayInfoIt->second.transform : kIdentityTransform; @@ -5253,7 +5256,8 @@ bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& w } void InputDispatcher::updateWindowHandlesForDisplayLocked( - const std::vector<sp<WindowInfoHandle>>& windowInfoHandles, int32_t displayId) { + const std::vector<sp<WindowInfoHandle>>& windowInfoHandles, + ui::LogicalDisplayId displayId) { if (windowInfoHandles.empty()) { // Remove all handles on a display if there are no windows left. mWindowHandlesByDisplay.erase(displayId); @@ -5285,13 +5289,14 @@ void InputDispatcher::updateWindowHandlesForDisplayLocked( } if (info->displayId != displayId) { - ALOGE("Window %s updated by wrong display %d, should belong to display %d", - handle->getName().c_str(), displayId, info->displayId); + ALOGE("Window %s updated by wrong display %s, should belong to display %s", + handle->getName().c_str(), displayId.toString().c_str(), + info->displayId.toString().c_str()); continue; } if ((oldHandlesById.find(handle->getId()) != oldHandlesById.end()) && - (oldHandlesById.at(handle->getId())->getToken() == handle->getToken())) { + (oldHandlesById.at(handle->getId())->getToken() == handle->getToken())) { const sp<WindowInfoHandle>& oldHandle = oldHandlesById.at(handle->getId()); oldHandle->updateFrom(handle); newHandles.push_back(oldHandle); @@ -5312,7 +5317,8 @@ void InputDispatcher::updateWindowHandlesForDisplayLocked( * For removed handle, check if need to send a cancel event if already in touch. */ void InputDispatcher::setInputWindowsLocked( - const std::vector<sp<WindowInfoHandle>>& windowInfoHandles, int32_t displayId) { + const std::vector<sp<WindowInfoHandle>>& windowInfoHandles, + ui::LogicalDisplayId displayId) { if (DEBUG_FOCUS) { std::string windowList; for (const sp<WindowInfoHandle>& iwh : windowInfoHandles) { @@ -5417,9 +5423,10 @@ void InputDispatcher::setInputWindowsLocked( } void InputDispatcher::setFocusedApplication( - int32_t displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) { + ui::LogicalDisplayId displayId, + const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) { if (DEBUG_FOCUS) { - ALOGD("setFocusedApplication displayId=%" PRId32 " %s", displayId, + ALOGD("setFocusedApplication displayId=%s %s", displayId.toString().c_str(), inputApplicationHandle ? inputApplicationHandle->getName().c_str() : "<nullptr>"); } { // acquire lock @@ -5432,7 +5439,8 @@ void InputDispatcher::setFocusedApplication( } void InputDispatcher::setFocusedApplicationLocked( - int32_t displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) { + ui::LogicalDisplayId displayId, + const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) { std::shared_ptr<InputApplicationHandle> oldFocusedApplicationHandle = getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); @@ -5469,9 +5477,9 @@ void InputDispatcher::setMinTimeBetweenUserActivityPokes(std::chrono::millisecon * cancel all the unreleased display-unspecified events for the focused window on the old focused * display. The display-specified events won't be affected. */ -void InputDispatcher::setFocusedDisplay(int32_t displayId) { +void InputDispatcher::setFocusedDisplay(ui::LogicalDisplayId displayId) { if (DEBUG_FOCUS) { - ALOGD("setFocusedDisplay displayId=%" PRId32, displayId); + ALOGD("setFocusedDisplay displayId=%s", displayId.toString().c_str()); } { // acquire lock std::scoped_lock _l(mLock); @@ -5490,7 +5498,7 @@ void InputDispatcher::setFocusedDisplay(int32_t displayId) { options(CancelationOptions::Mode::CANCEL_NON_POINTER_EVENTS, "The display which contains this window no longer has focus.", traceContext.getTracker()); - options.displayId = ADISPLAY_ID_NONE; + options.displayId = ui::ADISPLAY_ID_NONE; synthesizeCancelationEventsForWindowLocked(windowHandle, options); } mFocusedDisplayId = displayId; @@ -5500,7 +5508,8 @@ void InputDispatcher::setFocusedDisplay(int32_t displayId) { sendFocusChangedCommandLocked(oldFocusedWindowToken, newFocusedWindowToken); if (newFocusedWindowToken == nullptr) { - ALOGW("Focused display #%" PRId32 " does not have a focused window.", displayId); + ALOGW("Focused display #%s does not have a focused window.", + displayId.toString().c_str()); if (mFocusResolver.hasFocusedWindowTokens()) { ALOGE("But another display has a focused window\n%s", mFocusResolver.dumpFocusedWindows().c_str()); @@ -5566,15 +5575,15 @@ void InputDispatcher::setInputFilterEnabled(bool enabled) { } bool InputDispatcher::setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, - bool hasPermission, int32_t displayId) { + bool hasPermission, ui::LogicalDisplayId displayId) { bool needWake = false; { std::scoped_lock lock(mLock); ALOGD_IF(DEBUG_TOUCH_MODE, "Request to change touch mode to %s (calling pid=%s, uid=%s, " - "hasPermission=%s, target displayId=%d, mTouchModePerDisplay[displayId]=%s)", + "hasPermission=%s, target displayId=%s, mTouchModePerDisplay[displayId]=%s)", toString(inTouchMode), pid.toString().c_str(), uid.toString().c_str(), - toString(hasPermission), displayId, + toString(hasPermission), displayId.toString().c_str(), mTouchModePerDisplay.count(displayId) == 0 ? "not set" : std::to_string(mTouchModePerDisplay[displayId]).c_str()); @@ -5632,7 +5641,7 @@ void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) { mMaximumObscuringOpacityForTouch = opacity; } -std::tuple<TouchState*, TouchedWindow*, int32_t /*displayId*/> +std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId /*displayId*/> InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) { for (auto& [displayId, state] : mTouchStatesByDisplay) { for (TouchedWindow& w : state.windows) { @@ -5641,7 +5650,7 @@ InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) } } } - return std::make_tuple(nullptr, nullptr, ADISPLAY_ID_DEFAULT); + return std::make_tuple(nullptr, nullptr, ui::ADISPLAY_ID_DEFAULT); } bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken, @@ -5748,10 +5757,11 @@ bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const s * Return null if there are no windows touched on that display, or if more than one foreground * window is being touched. */ -sp<WindowInfoHandle> InputDispatcher::findTouchedForegroundWindowLocked(int32_t displayId) const { +sp<WindowInfoHandle> InputDispatcher::findTouchedForegroundWindowLocked( + ui::LogicalDisplayId displayId) const { auto stateIt = mTouchStatesByDisplay.find(displayId); if (stateIt == mTouchStatesByDisplay.end()) { - ALOGI("No touch state on display %" PRId32, displayId); + ALOGI("No touch state on display %s", displayId.toString().c_str()); return nullptr; } @@ -5774,14 +5784,14 @@ sp<WindowInfoHandle> InputDispatcher::findTouchedForegroundWindowLocked(int32_t // Binder call bool InputDispatcher::transferTouchOnDisplay(const sp<IBinder>& destChannelToken, - int32_t displayId) { + ui::LogicalDisplayId displayId) { sp<IBinder> fromToken; { // acquire lock std::scoped_lock _l(mLock); sp<WindowInfoHandle> toWindowHandle = getWindowHandleLocked(destChannelToken, displayId); if (toWindowHandle == nullptr) { - ALOGW("Could not find window associated with token=%p on display %" PRId32, - destChannelToken.get(), displayId); + ALOGW("Could not find window associated with token=%p on display %s", + destChannelToken.get(), displayId.toString().c_str()); return false; } @@ -5850,18 +5860,19 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { dump += StringPrintf(INDENT "DispatchEnabled: %s\n", toString(mDispatchEnabled)); dump += StringPrintf(INDENT "DispatchFrozen: %s\n", toString(mDispatchFrozen)); dump += StringPrintf(INDENT "InputFilterEnabled: %s\n", toString(mInputFilterEnabled)); - dump += StringPrintf(INDENT "FocusedDisplayId: %" PRId32 "\n", mFocusedDisplayId); + dump += StringPrintf(INDENT "FocusedDisplayId: %s\n", mFocusedDisplayId.toString().c_str()); if (!mFocusedApplicationHandlesByDisplay.empty()) { dump += StringPrintf(INDENT "FocusedApplications:\n"); for (auto& it : mFocusedApplicationHandlesByDisplay) { - const int32_t displayId = it.first; + const ui::LogicalDisplayId displayId = it.first; const std::shared_ptr<InputApplicationHandle>& applicationHandle = it.second; const std::chrono::duration timeout = applicationHandle->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT); - dump += StringPrintf(INDENT2 "displayId=%" PRId32 - ", name='%s', dispatchingTimeout=%" PRId64 "ms\n", - displayId, applicationHandle->getName().c_str(), millis(timeout)); + dump += StringPrintf(INDENT2 "displayId=%s, name='%s', dispatchingTimeout=%" PRId64 + "ms\n", + displayId.toString().c_str(), applicationHandle->getName().c_str(), + millis(timeout)); } } else { dump += StringPrintf(INDENT "FocusedApplications: <none>\n"); @@ -5874,7 +5885,7 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { dump += StringPrintf(INDENT "TouchStatesByDisplay:\n"); for (const auto& [displayId, state] : mTouchStatesByDisplay) { std::string touchStateDump = addLinePrefix(state.dump(), INDENT2); - dump += INDENT2 + std::to_string(displayId) + " : " + touchStateDump; + dump += INDENT2 + displayId.toString() + " : " + touchStateDump; } } else { dump += INDENT "TouchStates: <no displays touched>\n"; @@ -5887,7 +5898,7 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { if (!mWindowHandlesByDisplay.empty()) { for (const auto& [displayId, windowHandles] : mWindowHandlesByDisplay) { - dump += StringPrintf(INDENT "Display: %" PRId32 "\n", displayId); + dump += StringPrintf(INDENT "Display: %s\n", displayId.toString().c_str()); if (const auto& it = mDisplayInfos.find(displayId); it != mDisplayInfos.end()) { const auto& displayInfo = it->second; dump += StringPrintf(INDENT2 "logicalSize=%dx%d\n", displayInfo.logicalWidth, @@ -5913,7 +5924,8 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { if (!mGlobalMonitorsByDisplay.empty()) { for (const auto& [displayId, monitors] : mGlobalMonitorsByDisplay) { - dump += StringPrintf(INDENT "Global monitors on display %d:\n", displayId); + dump += StringPrintf(INDENT "Global monitors on display %s:\n", + displayId.toString().c_str()); dumpMonitors(dump, monitors); } } else { @@ -6002,8 +6014,8 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { if (!mTouchModePerDisplay.empty()) { dump += INDENT "TouchModePerDisplay:\n"; for (const auto& [displayId, touchMode] : mTouchModePerDisplay) { - dump += StringPrintf(INDENT2 "Display: %" PRId32 " TouchMode: %s\n", displayId, - std::to_string(touchMode).c_str()); + dump += StringPrintf(INDENT2 "Display: %s TouchMode: %s\n", + displayId.toString().c_str(), std::to_string(touchMode).c_str()); } } else { dump += INDENT "TouchModePerDisplay: <none>\n"; @@ -6076,9 +6088,8 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputChannel(const return clientChannel; } -Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(int32_t displayId, - const std::string& name, - gui::Pid pid) { +Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor( + ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid) { std::unique_ptr<InputChannel> serverChannel; std::unique_ptr<InputChannel> clientChannel; status_t result = InputChannel::openInputChannelPair(name, serverChannel, clientChannel); @@ -6089,7 +6100,7 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(int32_ { // acquire lock std::scoped_lock _l(mLock); - if (displayId < 0) { + if (displayId < ui::ADISPLAY_ID_DEFAULT) { return base::Error(BAD_VALUE) << "Attempted to create input monitor with name " << name << " without a specified display."; } @@ -6274,7 +6285,8 @@ void InputDispatcher::requestPointerCapture(const sp<IBinder>& windowToken, bool mLooper->wake(); } -void InputDispatcher::setDisplayEligibilityForPointerCapture(int32_t displayId, bool isEligible) { +void InputDispatcher::setDisplayEligibilityForPointerCapture(ui::LogicalDisplayId displayId, + bool isEligible) { { // acquire lock std::scoped_lock _l(mLock); std::erase(mIneligibleDisplaysForPointerCapture, displayId); @@ -6850,7 +6862,9 @@ void InputDispatcher::setFocusedWindow(const FocusRequest& request) { { // acquire lock std::scoped_lock _l(mLock); std::optional<FocusResolver::FocusChanges> changes = - mFocusResolver.setFocusedWindow(request, getWindowHandlesLocked(request.displayId)); + mFocusResolver.setFocusedWindow(request, + getWindowHandlesLocked( + ui::LogicalDisplayId{request.displayId})); ScopedSyntheticEventTracer traceContext(mTracer); if (changes) { onFocusChangedLocked(*changes, traceContext.getTracker()); @@ -6934,7 +6948,7 @@ void InputDispatcher::setPointerCaptureLocked(const sp<IBinder>& windowToken) { postCommandLocked(std::move(command)); } -void InputDispatcher::displayRemoved(int32_t displayId) { +void InputDispatcher::displayRemoved(ui::LogicalDisplayId displayId) { { // acquire lock std::scoped_lock _l(mLock); // Set an empty list to remove all handles from the specific display. @@ -6966,7 +6980,7 @@ void InputDispatcher::onWindowInfosChanged(const gui::WindowInfosUpdate& update) }; // The listener sends the windows as a flattened array. Separate the windows by display for // more convenient parsing. - std::unordered_map<int32_t, std::vector<sp<WindowInfoHandle>>> handlesPerDisplay; + std::unordered_map<ui::LogicalDisplayId, std::vector<sp<WindowInfoHandle>>> handlesPerDisplay; for (const auto& info : update.windowInfos) { handlesPerDisplay.emplace(info.displayId, std::vector<sp<WindowInfoHandle>>()); handlesPerDisplay[info.displayId].push_back(sp<WindowInfoHandle>::make(info)); @@ -7008,10 +7022,10 @@ bool InputDispatcher::shouldDropInput( WindowInfo::InputConfig::DROP_INPUT_IF_OBSCURED) && isWindowObscuredLocked(windowHandle))) { ALOGW("Dropping %s event targeting %s as requested by the input configuration {%s} on " - "display %" PRId32 ".", + "display %s.", ftl::enum_string(entry.type).c_str(), windowHandle->getName().c_str(), windowHandle->getInfo()->inputConfig.string().c_str(), - windowHandle->getInfo()->displayId); + windowHandle->getInfo()->displayId.toString().c_str()); return true; } return false; @@ -7155,8 +7169,9 @@ void InputDispatcher::setKeyRepeatConfiguration(std::chrono::nanoseconds timeout mConfig.keyRepeatDelay = delay.count(); } -bool InputDispatcher::isPointerInWindow(const sp<android::IBinder>& token, int32_t displayId, - DeviceId deviceId, int32_t pointerId) { +bool InputDispatcher::isPointerInWindow(const sp<android::IBinder>& token, + ui::LogicalDisplayId displayId, DeviceId deviceId, + int32_t pointerId) { std::scoped_lock _l(mLock); auto touchStateIt = mTouchStatesByDisplay.find(displayId); if (touchStateIt == mTouchStatesByDisplay.end()) { diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index 3d127c296a..f671ea71f4 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -114,35 +114,37 @@ public: std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) override; void setFocusedApplication( - int32_t displayId, + ui::LogicalDisplayId displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) override; - void setFocusedDisplay(int32_t displayId) override; + void setFocusedDisplay(ui::LogicalDisplayId displayId) override; void setMinTimeBetweenUserActivityPokes(std::chrono::milliseconds interval) override; void setInputDispatchMode(bool enabled, bool frozen) override; void setInputFilterEnabled(bool enabled) override; bool setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission, - int32_t displayId) override; + ui::LogicalDisplayId displayId) override; void setMaximumObscuringOpacityForTouch(float opacity) override; bool transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken, bool isDragDrop = false) override; - bool transferTouchOnDisplay(const sp<IBinder>& destChannelToken, int32_t displayId) override; + bool transferTouchOnDisplay(const sp<IBinder>& destChannelToken, + ui::LogicalDisplayId displayId) override; base::Result<std::unique_ptr<InputChannel>> createInputChannel( const std::string& name) override; void setFocusedWindow(const android::gui::FocusRequest&) override; - base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId, + base::Result<std::unique_ptr<InputChannel>> createInputMonitor(ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid) override; status_t removeInputChannel(const sp<IBinder>& connectionToken) override; status_t pilferPointers(const sp<IBinder>& token) override; void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) override; bool flushSensor(int deviceId, InputDeviceSensorType sensorType) override; - void setDisplayEligibilityForPointerCapture(int displayId, bool isEligible) override; + void setDisplayEligibilityForPointerCapture(ui::LogicalDisplayId displayId, + bool isEligible) override; std::array<uint8_t, 32> sign(const VerifiedInputEvent& event) const; - void displayRemoved(int32_t displayId) override; + void displayRemoved(ui::LogicalDisplayId displayId) override; // Public because it's also used by tests to simulate the WindowInfosListener callback void onWindowInfosChanged(const gui::WindowInfosUpdate&); @@ -155,8 +157,8 @@ public: void setKeyRepeatConfiguration(std::chrono::nanoseconds timeout, std::chrono::nanoseconds delay) override; - bool isPointerInWindow(const sp<IBinder>& token, int32_t displayId, DeviceId deviceId, - int32_t pointerId) override; + bool isPointerInWindow(const sp<IBinder>& token, ui::LogicalDisplayId displayId, + DeviceId deviceId, int32_t pointerId) override; void setInputMethodConnectionIsActive(bool isActive) override; @@ -249,17 +251,17 @@ private: std::shared_ptr<const EventEntry> mNextUnblockedEvent GUARDED_BY(mLock); sp<android::gui::WindowInfoHandle> findTouchedWindowAtLocked( - int32_t displayId, float x, float y, bool isStylus = false, + ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false, bool ignoreDragWindow = false) const REQUIRES(mLock); std::vector<InputTarget> findOutsideTargetsLocked( - int32_t displayId, const sp<android::gui::WindowInfoHandle>& touchedWindow, + ui::LogicalDisplayId displayId, const sp<android::gui::WindowInfoHandle>& touchedWindow, int32_t pointerId) const REQUIRES(mLock); std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAtLocked( - int32_t displayId, float x, float y, bool isStylus) const REQUIRES(mLock); + ui::LogicalDisplayId displayId, float x, float y, bool isStylus) const REQUIRES(mLock); - sp<android::gui::WindowInfoHandle> findTouchedForegroundWindowLocked(int32_t displayId) const - REQUIRES(mLock); + sp<android::gui::WindowInfoHandle> findTouchedForegroundWindowLocked( + ui::LogicalDisplayId displayId) const REQUIRES(mLock); std::shared_ptr<Connection> getConnectionLocked(const sp<IBinder>& inputConnectionToken) const REQUIRES(mLock); @@ -283,7 +285,8 @@ private: std::optional<gui::Pid> findMonitorPidByTokenLocked(const sp<IBinder>& token) REQUIRES(mLock); // Input channels that will receive a copy of all input events sent to the provided display. - std::unordered_map<int32_t, std::vector<Monitor>> mGlobalMonitorsByDisplay GUARDED_BY(mLock); + std::unordered_map<ui::LogicalDisplayId, std::vector<Monitor>> mGlobalMonitorsByDisplay + GUARDED_BY(mLock); const HmacKeyManager mHmacKeyManager; const std::array<uint8_t, 32> getSignature(const MotionEntry& motionEntry, @@ -342,7 +345,8 @@ private: // This map is not really needed, but it helps a lot with debugging (dumpsys input). // In the java layer, touch mode states are spread across multiple DisplayContent objects, // making harder to snapshot and retrieve them. - std::map<int32_t /*displayId*/, bool /*inTouchMode*/> mTouchModePerDisplay GUARDED_BY(mLock); + std::map<ui::LogicalDisplayId /*displayId*/, bool /*inTouchMode*/> mTouchModePerDisplay + GUARDED_BY(mLock); class DispatcherWindowListener : public gui::WindowInfosListener { public: @@ -354,25 +358,26 @@ private: }; sp<gui::WindowInfosListener> mWindowInfoListener; - std::unordered_map<int32_t /*displayId*/, std::vector<sp<android::gui::WindowInfoHandle>>> + std::unordered_map<ui::LogicalDisplayId /*displayId*/, + std::vector<sp<android::gui::WindowInfoHandle>>> mWindowHandlesByDisplay GUARDED_BY(mLock); - std::unordered_map<int32_t /*displayId*/, android::gui::DisplayInfo> mDisplayInfos + std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo> mDisplayInfos GUARDED_BY(mLock); void setInputWindowsLocked( const std::vector<sp<android::gui::WindowInfoHandle>>& inputWindowHandles, - int32_t displayId) REQUIRES(mLock); + ui::LogicalDisplayId displayId) REQUIRES(mLock); // Get a reference to window handles by display, return an empty vector if not found. const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesLocked( - int32_t displayId) const REQUIRES(mLock); - ui::Transform getTransformLocked(int32_t displayId) const REQUIRES(mLock); + ui::LogicalDisplayId displayId) const REQUIRES(mLock); + ui::Transform getTransformLocked(ui::LogicalDisplayId displayId) const REQUIRES(mLock); sp<android::gui::WindowInfoHandle> getWindowHandleLocked( - const sp<IBinder>& windowHandleToken, std::optional<int32_t> displayId = {}) const - REQUIRES(mLock); + const sp<IBinder>& windowHandleToken, + std::optional<ui::LogicalDisplayId> displayId = {}) const REQUIRES(mLock); sp<android::gui::WindowInfoHandle> getWindowHandleLocked( const sp<android::gui::WindowInfoHandle>& windowHandle) const REQUIRES(mLock); - sp<android::gui::WindowInfoHandle> getFocusedWindowHandleLocked(int displayId) const - REQUIRES(mLock); + sp<android::gui::WindowInfoHandle> getFocusedWindowHandleLocked( + ui::LogicalDisplayId displayId) const REQUIRES(mLock); bool canWindowReceiveMotionLocked(const sp<android::gui::WindowInfoHandle>& window, const MotionEntry& motionEntry) const REQUIRES(mLock); @@ -387,20 +392,21 @@ private: */ void updateWindowHandlesForDisplayLocked( const std::vector<sp<android::gui::WindowInfoHandle>>& inputWindowHandles, - int32_t displayId) REQUIRES(mLock); + ui::LogicalDisplayId displayId) REQUIRES(mLock); - std::unordered_map<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock); + std::unordered_map<ui::LogicalDisplayId /*displayId*/, TouchState> mTouchStatesByDisplay + GUARDED_BY(mLock); std::unique_ptr<DragState> mDragState GUARDED_BY(mLock); void setFocusedApplicationLocked( - int32_t displayId, + ui::LogicalDisplayId displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) REQUIRES(mLock); // Focused applications. - std::unordered_map<int32_t, std::shared_ptr<InputApplicationHandle>> + std::unordered_map<ui::LogicalDisplayId /*displayId*/, std::shared_ptr<InputApplicationHandle>> mFocusedApplicationHandlesByDisplay GUARDED_BY(mLock); // Top focused display. - int32_t mFocusedDisplayId GUARDED_BY(mLock); + ui::LogicalDisplayId mFocusedDisplayId GUARDED_BY(mLock); // Keeps track of the focused window per display and determines focus changes. FocusResolver mFocusResolver GUARDED_BY(mLock); @@ -417,7 +423,8 @@ private: // Displays that are ineligible for pointer capture. // TODO(b/214621487): Remove or move to a display flag. - std::vector<int32_t> mIneligibleDisplaysForPointerCapture GUARDED_BY(mLock); + std::vector<ui::LogicalDisplayId /*displayId*/> mIneligibleDisplaysForPointerCapture + GUARDED_BY(mLock); // Disable Pointer Capture as a result of loss of window focus. void disablePointerCaptureForcedLocked() REQUIRES(mLock); @@ -492,7 +499,7 @@ private: /** * The displayId that the focused application is associated with. */ - int32_t mAwaitedApplicationDisplayId GUARDED_BY(mLock); + ui::LogicalDisplayId mAwaitedApplicationDisplayId GUARDED_BY(mLock); void processNoFocusedWindowAnrLocked() REQUIRES(mLock); /** @@ -526,7 +533,7 @@ private: // shade is pulled down while we are counting down the timeout). void resetNoFocusedWindowTimeoutLocked() REQUIRES(mLock); - int32_t getTargetDisplayId(const EventEntry& entry); + ui::LogicalDisplayId getTargetDisplayId(const EventEntry& entry); sp<android::gui::WindowInfoHandle> findFocusedWindowTargetLocked( nsecs_t currentTime, const EventEntry& entry, nsecs_t& nextWakeupTime, android::os::InputEventInjectionResult& outInjectionResult) REQUIRES(mLock); @@ -551,13 +558,13 @@ private: std::bitset<MAX_POINTER_ID + 1> pointerIds, std::optional<nsecs_t> firstDownTimeInTarget, std::vector<InputTarget>& inputTargets) const REQUIRES(mLock); - void addGlobalMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets, int32_t displayId) - REQUIRES(mLock); + void addGlobalMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets, + ui::LogicalDisplayId displayId) REQUIRES(mLock); void pokeUserActivityLocked(const EventEntry& eventEntry) REQUIRES(mLock); // Enqueue a drag event if needed, and update the touch state. // Uses findTouchedWindowTargetsLocked to make the decision void addDragEventLocked(const MotionEntry& entry) REQUIRES(mLock); - void finishDragAndDrop(int32_t displayId, float x, float y) REQUIRES(mLock); + void finishDragAndDrop(ui::LogicalDisplayId displayId, float x, float y) REQUIRES(mLock); struct TouchOcclusionInfo { bool hasBlockingOcclusion; @@ -675,14 +682,14 @@ private: const std::string& reason) REQUIRES(mLock); void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason) REQUIRES(mLock); - std::map<int32_t /*displayId*/, InputVerifier> mVerifiersByDisplay; + std::map<ui::LogicalDisplayId /*displayId*/, InputVerifier> mVerifiersByDisplay; // Returns a fallback KeyEntry that should be sent to the connection, if required. std::unique_ptr<const KeyEntry> afterKeyEventLockedInterruptable( const std::shared_ptr<Connection>& connection, DispatchEntry& dispatchEntry, const KeyEntry& keyEntry, bool handled) REQUIRES(mLock); // Find touched state and touched window by token. - std::tuple<TouchState*, TouchedWindow*, int32_t /*displayId*/> + std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId /*displayId*/> findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) REQUIRES(mLock); // Statistics gathering. diff --git a/services/inputflinger/dispatcher/InputState.cpp b/services/inputflinger/dispatcher/InputState.cpp index 02bc3680bf..46e7e8b35e 100644 --- a/services/inputflinger/dispatcher/InputState.cpp +++ b/services/inputflinger/dispatcher/InputState.cpp @@ -28,7 +28,8 @@ InputState::InputState(const IdGenerator& idGenerator) : mIdGenerator(idGenerato InputState::~InputState() {} -bool InputState::isHovering(DeviceId deviceId, uint32_t source, int32_t displayId) const { +bool InputState::isHovering(DeviceId deviceId, uint32_t source, + ui::LogicalDisplayId displayId) const { for (const MotionMemento& memento : mMotionMementos) { if (memento.deviceId == deviceId && memento.source == source && memento.displayId == displayId && memento.hovering) { diff --git a/services/inputflinger/dispatcher/InputState.h b/services/inputflinger/dispatcher/InputState.h index d49469ddc1..ab83ef911d 100644 --- a/services/inputflinger/dispatcher/InputState.h +++ b/services/inputflinger/dispatcher/InputState.h @@ -36,7 +36,7 @@ public: // Returns true if the specified source is known to have received a hover enter // motion event. - bool isHovering(DeviceId deviceId, uint32_t source, int32_t displayId) const; + bool isHovering(DeviceId deviceId, uint32_t source, ui::LogicalDisplayId displayId) const; // Records tracking information for a key event that has just been published. // Returns true if the event should be delivered, false if it is inconsistent @@ -90,7 +90,7 @@ private: struct KeyMemento { DeviceId deviceId; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; int32_t keyCode; int32_t scanCode; int32_t metaState; @@ -102,7 +102,7 @@ private: struct MotionMemento { DeviceId deviceId; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; int32_t flags; float xPrecision; float yPrecision; diff --git a/services/inputflinger/dispatcher/InputTarget.h b/services/inputflinger/dispatcher/InputTarget.h index 60a75ee107..90374f1481 100644 --- a/services/inputflinger/dispatcher/InputTarget.h +++ b/services/inputflinger/dispatcher/InputTarget.h @@ -18,7 +18,6 @@ #include <ftl/flags.h> #include <gui/WindowInfo.h> -#include <gui/constants.h> #include <ui/Transform.h> #include <utils/BitSet.h> #include <bitset> diff --git a/services/inputflinger/dispatcher/include/InputDispatcherInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherInterface.h index 6b9262cfa3..653f595670 100644 --- a/services/inputflinger/dispatcher/include/InputDispatcherInterface.h +++ b/services/inputflinger/dispatcher/include/InputDispatcherInterface.h @@ -92,14 +92,14 @@ public: * This method may be called on any thread (usually by the input manager). */ virtual void setFocusedApplication( - int32_t displayId, + ui::LogicalDisplayId displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0; /* Sets the focused display. * * This method may be called on any thread (usually by the input manager). */ - virtual void setFocusedDisplay(int32_t displayId) = 0; + virtual void setFocusedDisplay(ui::LogicalDisplayId displayId) = 0; /** Sets the minimum time between user activity pokes. */ virtual void setMinTimeBetweenUserActivityPokes(std::chrono::milliseconds interval) = 0; @@ -130,7 +130,7 @@ public: * Returns true when changing touch mode state. */ virtual bool setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission, - int32_t displayId) = 0; + ui::LogicalDisplayId displayId) = 0; /** * Sets the maximum allowed obscuring opacity by UID to propagate touches. @@ -156,7 +156,8 @@ public: * Returns true on success, false if there was no on-going touch on the display. * @deprecated */ - virtual bool transferTouchOnDisplay(const sp<IBinder>& destChannelToken, int32_t displayId) = 0; + virtual bool transferTouchOnDisplay(const sp<IBinder>& destChannelToken, + ui::LogicalDisplayId displayId) = 0; /** * Sets focus on the specified window. @@ -179,9 +180,8 @@ public: * * This method may be called on any thread (usually by the input manager). */ - virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId, - const std::string& name, - gui::Pid pid) = 0; + virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor( + ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid) = 0; /* Removes input channels that will no longer receive input events. * @@ -207,7 +207,8 @@ public: * ineligible, all attempts to request pointer capture for windows on that display will fail. * TODO(b/214621487): Remove or move to a display flag. */ - virtual void setDisplayEligibilityForPointerCapture(int displayId, bool isEligible) = 0; + virtual void setDisplayEligibilityForPointerCapture(ui::LogicalDisplayId displayId, + bool isEligible) = 0; /* Flush input device motion sensor. * @@ -218,7 +219,7 @@ public: /** * Called when a display has been removed from the system. */ - virtual void displayRemoved(int32_t displayId) = 0; + virtual void displayRemoved(ui::LogicalDisplayId displayId) = 0; /* * Abort the current touch stream. @@ -234,8 +235,8 @@ public: /* * Determine if a pointer from a device is being dispatched to the given window. */ - virtual bool isPointerInWindow(const sp<IBinder>& token, int32_t displayId, DeviceId deviceId, - int32_t pointerId) = 0; + virtual bool isPointerInWindow(const sp<IBinder>& token, ui::LogicalDisplayId displayId, + DeviceId deviceId, int32_t pointerId) = 0; /* * Notify the dispatcher that the state of the input method connection changed. diff --git a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h index 62c2b02967..0f03620f05 100644 --- a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h +++ b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h @@ -99,8 +99,9 @@ public: * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event * should be dispatched to applications. */ - virtual void interceptMotionBeforeQueueing(int32_t displayId, uint32_t source, int32_t action, - nsecs_t when, uint32_t& policyFlags) = 0; + virtual void interceptMotionBeforeQueueing(ui::LogicalDisplayId displayId, uint32_t source, + int32_t action, nsecs_t when, + uint32_t& policyFlags) = 0; /* Allows the policy a chance to intercept a key before dispatching. */ virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token, @@ -119,7 +120,8 @@ public: uint32_t policyFlags) = 0; /* Poke user activity for an event dispatched to a window. */ - virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) = 0; + virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType, + ui::LogicalDisplayId displayId) = 0; /* * Return true if the provided event is stale, and false otherwise. Used for determining diff --git a/services/inputflinger/dispatcher/trace/AndroidInputEventProtoConverter.cpp b/services/inputflinger/dispatcher/trace/AndroidInputEventProtoConverter.cpp index c431fb726a..2d7554c9c1 100644 --- a/services/inputflinger/dispatcher/trace/AndroidInputEventProtoConverter.cpp +++ b/services/inputflinger/dispatcher/trace/AndroidInputEventProtoConverter.cpp @@ -47,7 +47,7 @@ void AndroidInputEventProtoConverter::toProtoMotionEvent(const TracedMotionEvent outProto.set_source(event.source); outProto.set_action(event.action); outProto.set_device_id(event.deviceId); - outProto.set_display_id(event.displayId); + outProto.set_display_id(event.displayId.val()); outProto.set_classification(static_cast<int32_t>(event.classification)); outProto.set_flags(event.flags); outProto.set_policy_flags(event.policyFlags); @@ -88,7 +88,7 @@ void AndroidInputEventProtoConverter::toProtoKeyEvent(const TracedKeyEvent& even outProto.set_source(event.source); outProto.set_action(event.action); outProto.set_device_id(event.deviceId); - outProto.set_display_id(event.displayId); + outProto.set_display_id(event.displayId.val()); outProto.set_repeat_count(event.repeatCount); outProto.set_flags(event.flags); outProto.set_policy_flags(event.policyFlags); diff --git a/services/inputflinger/dispatcher/trace/InputTracingBackendInterface.h b/services/inputflinger/dispatcher/trace/InputTracingBackendInterface.h index 2b45e3ae1c..25099c3199 100644 --- a/services/inputflinger/dispatcher/trace/InputTracingBackendInterface.h +++ b/services/inputflinger/dispatcher/trace/InputTracingBackendInterface.h @@ -50,7 +50,7 @@ struct TracedKeyEvent { uint32_t policyFlags; int32_t deviceId; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId; int32_t action; int32_t keyCode; int32_t scanCode; @@ -70,7 +70,7 @@ struct TracedMotionEvent { uint32_t policyFlags; int32_t deviceId; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId; int32_t action; int32_t actionButton; int32_t flags; diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h index 4d8ed99eb4..e5c3aa08d1 100644 --- a/services/inputflinger/include/InputReaderBase.h +++ b/services/inputflinger/include/InputReaderBase.h @@ -125,7 +125,7 @@ struct InputReaderConfiguration { std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations; // The suggested display ID to show the cursor. - int32_t defaultPointerDisplayId; + ui::LogicalDisplayId defaultPointerDisplayId; // The mouse pointer speed, as a number from -7 (slowest) to 7 (fastest). // @@ -135,7 +135,7 @@ struct InputReaderConfiguration { // Displays on which an acceleration curve shouldn't be applied for pointer movements from mice. // // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled. - std::set<int32_t> displaysWithMousePointerAccelerationDisabled; + std::set<ui::LogicalDisplayId> displaysWithMousePointerAccelerationDisabled; // Velocity control parameters for mouse pointer movements. // @@ -243,6 +243,7 @@ struct InputReaderConfiguration { InputReaderConfiguration() : virtualKeyQuietTime(0), + defaultPointerDisplayId(ui::ADISPLAY_ID_DEFAULT), mousePointerSpeed(0), displaysWithMousePointerAccelerationDisabled(), pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, @@ -275,7 +276,7 @@ struct InputReaderConfiguration { std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId) const; std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const; - std::optional<DisplayViewport> getDisplayViewportById(int32_t displayId) const; + std::optional<DisplayViewport> getDisplayViewportById(ui::LogicalDisplayId displayId) const; void setDisplayViewports(const std::vector<DisplayViewport>& viewports); void dump(std::string& dump) const; @@ -366,7 +367,7 @@ public: virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0; /* Return true if the device can send input events to the specified display. */ - virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0; + virtual bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) = 0; /* Enable sensor in input reader mapper. */ virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType, @@ -471,7 +472,7 @@ public: * be used as the range of possible values for pointing devices, like mice and touchpads. */ virtual std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay( - int32_t associatedDisplayId = ADISPLAY_ID_NONE) = 0; + ui::LogicalDisplayId associatedDisplayId = ui::ADISPLAY_ID_NONE) = 0; }; } // namespace android diff --git a/services/inputflinger/include/NotifyArgs.h b/services/inputflinger/include/NotifyArgs.h index 736b1e07b7..865f3d0302 100644 --- a/services/inputflinger/include/NotifyArgs.h +++ b/services/inputflinger/include/NotifyArgs.h @@ -61,7 +61,7 @@ struct NotifyKeyArgs { int32_t deviceId; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; uint32_t policyFlags; int32_t action; int32_t flags; @@ -74,9 +74,9 @@ struct NotifyKeyArgs { inline NotifyKeyArgs() {} NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId, - uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action, - int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, - nsecs_t downTime); + uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags, + int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, + int32_t metaState, nsecs_t downTime); bool operator==(const NotifyKeyArgs& rhs) const = default; @@ -91,7 +91,7 @@ struct NotifyMotionArgs { int32_t deviceId; uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; uint32_t policyFlags; int32_t action; int32_t actionButton; @@ -123,12 +123,12 @@ struct NotifyMotionArgs { inline NotifyMotionArgs() {} NotifyMotionArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId, - uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action, - int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState, - MotionClassification classification, int32_t edgeFlags, uint32_t pointerCount, - const PointerProperties* pointerProperties, const PointerCoords* pointerCoords, - float xPrecision, float yPrecision, float xCursorPosition, - float yCursorPosition, nsecs_t downTime, + uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags, + int32_t action, int32_t actionButton, int32_t flags, int32_t metaState, + int32_t buttonState, MotionClassification classification, int32_t edgeFlags, + uint32_t pointerCount, const PointerProperties* pointerProperties, + const PointerCoords* pointerCoords, float xPrecision, float yPrecision, + float xCursorPosition, float yCursorPosition, nsecs_t downTime, const std::vector<TouchVideoFrame>& videoFrames); NotifyMotionArgs(const NotifyMotionArgs& other) = default; diff --git a/services/inputflinger/include/NotifyArgsBuilders.h b/services/inputflinger/include/NotifyArgsBuilders.h index 1bd55958d9..1ba0cfd20a 100644 --- a/services/inputflinger/include/NotifyArgsBuilders.h +++ b/services/inputflinger/include/NotifyArgsBuilders.h @@ -19,7 +19,6 @@ #include <NotifyArgs.h> #include <android/input.h> #include <attestation/HmacKeyManager.h> -#include <gui/constants.h> #include <input/Input.h> #include <input/InputEventBuilders.h> #include <utils/Timers.h> // for nsecs_t, systemTime @@ -55,7 +54,7 @@ public: return *this; } - MotionArgsBuilder& displayId(int32_t displayId) { + MotionArgsBuilder& displayId(ui::LogicalDisplayId displayId) { mDisplayId = displayId; return *this; } @@ -151,7 +150,7 @@ private: uint32_t mSource; nsecs_t mDownTime; nsecs_t mEventTime; - int32_t mDisplayId{ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT}; uint32_t mPolicyFlags = DEFAULT_POLICY_FLAGS; int32_t mActionButton{0}; int32_t mButtonState{0}; @@ -187,7 +186,7 @@ public: return *this; } - KeyArgsBuilder& displayId(int32_t displayId) { + KeyArgsBuilder& displayId(ui::LogicalDisplayId displayId) { mDisplayId = displayId; return *this; } @@ -230,7 +229,7 @@ private: uint32_t mSource; nsecs_t mDownTime; nsecs_t mEventTime; - int32_t mDisplayId{ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT}; uint32_t mPolicyFlags = DEFAULT_POLICY_FLAGS; int32_t mFlags{0}; int32_t mKeyCode{AKEYCODE_UNKNOWN}; diff --git a/services/inputflinger/include/PointerChoreographerPolicyInterface.h b/services/inputflinger/include/PointerChoreographerPolicyInterface.h index 462aedc539..f6dc10997a 100644 --- a/services/inputflinger/include/PointerChoreographerPolicyInterface.h +++ b/services/inputflinger/include/PointerChoreographerPolicyInterface.h @@ -53,7 +53,8 @@ public: * @param displayId The updated display on which the mouse cursor is shown * @param position The new position of the mouse cursor on the logical display */ - virtual void notifyPointerDisplayIdChanged(int32_t displayId, const FloatPoint& position) = 0; + virtual void notifyPointerDisplayIdChanged(ui::LogicalDisplayId displayId, + const FloatPoint& position) = 0; }; } // namespace android diff --git a/services/inputflinger/include/PointerControllerInterface.h b/services/inputflinger/include/PointerControllerInterface.h index c1467b3eed..cee44fc6b3 100644 --- a/services/inputflinger/include/PointerControllerInterface.h +++ b/services/inputflinger/include/PointerControllerInterface.h @@ -125,13 +125,13 @@ public: * pressed (not hovering). */ virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, - BitSet32 spotIdBits, int32_t displayId) = 0; + BitSet32 spotIdBits, ui::LogicalDisplayId displayId) = 0; /* Removes all spots. */ virtual void clearSpots() = 0; /* Gets the id of the display where the pointer should be shown. */ - virtual int32_t getDisplayId() const = 0; + virtual ui::LogicalDisplayId getDisplayId() const = 0; /* Sets the associated display of this pointer. Pointer should show on that display. */ virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0; @@ -145,7 +145,7 @@ public: /* Sets the flag to skip screenshot of the pointer indicators on the display matching the * provided displayId. */ - virtual void setSkipScreenshot(int32_t displayId, bool skip) = 0; + virtual void setSkipScreenshot(ui::LogicalDisplayId displayId, bool skip) = 0; }; } // namespace android diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index 44dfd15aaa..15586e2c4b 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -442,7 +442,7 @@ std::list<NotifyArgs> InputDevice::updateExternalStylusState(const StylusState& InputDeviceInfo InputDevice::getDeviceInfo() { InputDeviceInfo outDeviceInfo; outDeviceInfo.initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal, - mHasMic, getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE), + mHasMic, getAssociatedDisplayId().value_or(ui::ADISPLAY_ID_NONE), {mShouldSmoothScroll}, isEnabled()); for_each_mapper( @@ -699,14 +699,14 @@ NotifyDeviceResetArgs InputDevice::notifyReset(nsecs_t when) { return NotifyDeviceResetArgs(mContext->getNextId(), when, mId); } -std::optional<int32_t> InputDevice::getAssociatedDisplayId() { +std::optional<ui::LogicalDisplayId> InputDevice::getAssociatedDisplayId() { // Check if we had associated to the specific display. if (mAssociatedViewport) { return mAssociatedViewport->displayId; } // No associated display port, check if some InputMapper is associated. - return first_in_mappers<int32_t>( + return first_in_mappers<ui::LogicalDisplayId>( [](InputMapper& mapper) { return mapper.getAssociatedDisplayId(); }); } diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index 903c6ed9bc..12f52b899c 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -856,7 +856,7 @@ bool InputReader::isInputDeviceEnabled(int32_t deviceId) { return false; } -bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { +bool InputReader::canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) { std::scoped_lock _l(mLock); InputDevice* device = findInputDeviceLocked(deviceId); @@ -870,10 +870,9 @@ bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { return false; } - std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId(); + std::optional<ui::LogicalDisplayId> associatedDisplayId = device->getAssociatedDisplayId(); // No associated display. By default, can dispatch to all displays. - if (!associatedDisplayId || - *associatedDisplayId == ADISPLAY_ID_NONE) { + if (!associatedDisplayId || !associatedDisplayId->isValid()) { return true; } diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h index feb407152c..4c9af2e30e 100644 --- a/services/inputflinger/reader/include/InputDevice.h +++ b/services/inputflinger/reader/include/InputDevice.h @@ -131,7 +131,7 @@ public: inline const PropertyMap& getConfiguration() { return mConfiguration; } inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } - std::optional<int32_t> getAssociatedDisplayId(); + std::optional<ui::LogicalDisplayId> getAssociatedDisplayId(); void updateLedState(bool reset); diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h index 5f882cfcd3..d9ac917031 100644 --- a/services/inputflinger/reader/include/InputReader.h +++ b/services/inputflinger/reader/include/InputReader.h @@ -86,7 +86,7 @@ public: std::vector<int32_t> getVibratorIds(int32_t deviceId) override; - bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) override; + bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) override; bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod, diff --git a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp index 061c6a3e75..21dec6ffa6 100644 --- a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp +++ b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp @@ -19,7 +19,6 @@ #include <sstream> #include <android-base/stringprintf.h> -#include <gui/constants.h> #include <input/PrintTools.h> #include <linux/input-event-codes.h> #include <log/log_main.h> @@ -279,7 +278,7 @@ NotifyMotionArgs CapturedTouchpadEventConverter::makeMotionArgs( LOG_ALWAYS_FATAL_IF(coords.size() != properties.size(), "Mismatched coords and properties arrays."); return NotifyMotionArgs(mReaderContext.getNextId(), when, readTime, mDeviceId, SOURCE, - ADISPLAY_ID_NONE, /*policyFlags=*/POLICY_FLAG_WAKE, action, + ui::ADISPLAY_ID_NONE, /*policyFlags=*/POLICY_FLAG_WAKE, action, /*actionButton=*/actionButton, flags, mReaderContext.getGlobalMetaState(), mButtonState, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, coords.size(), diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index ede2d72c44..d5fe0400b2 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -129,7 +129,8 @@ void CursorInputMapper::dump(std::string& dump) { mWheelXVelocityControl.getParameters().dump().c_str()); dump += StringPrintf(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale); dump += StringPrintf(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale); - dump += StringPrintf(INDENT3 "DisplayId: %s\n", toString(mDisplayId).c_str()); + dump += StringPrintf(INDENT3 "DisplayId: %s\n", + toString(mDisplayId, streamableToString).c_str()); dump += StringPrintf(INDENT3 "Orientation: %s\n", ftl::enum_string(mOrientation).c_str()); dump += StringPrintf(INDENT3 "ButtonState: 0x%08x\n", mButtonState); dump += StringPrintf(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState))); @@ -417,7 +418,7 @@ int32_t CursorInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCod } } -std::optional<int32_t> CursorInputMapper::getAssociatedDisplayId() { +std::optional<ui::LogicalDisplayId> CursorInputMapper::getAssociatedDisplayId() { return mDisplayId; } @@ -487,13 +488,13 @@ void CursorInputMapper::configureOnChangePointerSpeed(const InputReaderConfigura if (mEnableNewMousePointerBallistics) { mNewPointerVelocityControl.setAccelerationEnabled( config.displaysWithMousePointerAccelerationDisabled.count( - mDisplayId.value_or(ADISPLAY_ID_NONE)) == 0); + mDisplayId.value_or(ui::ADISPLAY_ID_NONE)) == 0); mNewPointerVelocityControl.setCurve( createAccelerationCurveForPointerSensitivity(config.mousePointerSpeed)); } else { mOldPointerVelocityControl.setParameters( (config.displaysWithMousePointerAccelerationDisabled.count( - mDisplayId.value_or(ADISPLAY_ID_NONE)) == 0) + mDisplayId.value_or(ui::ADISPLAY_ID_NONE)) == 0) ? config.pointerVelocityControlParameters : FLAT_VELOCITY_CONTROL_PARAMS); } @@ -505,7 +506,7 @@ void CursorInputMapper::configureOnChangePointerSpeed(const InputReaderConfigura void CursorInputMapper::configureOnChangeDisplayInfo(const InputReaderConfiguration& config) { const bool isPointer = mParameters.mode == Parameters::Mode::POINTER; - mDisplayId = ADISPLAY_ID_NONE; + mDisplayId = ui::ADISPLAY_ID_NONE; std::optional<DisplayViewport> resolvedViewport; if (auto assocViewport = mDeviceContext.getAssociatedViewport(); assocViewport) { // This InputDevice is associated with a viewport. @@ -517,7 +518,7 @@ void CursorInputMapper::configureOnChangeDisplayInfo(const InputReaderConfigurat // Always use DISPLAY_ID_NONE for mouse events. // PointerChoreographer will make it target the correct the displayId later. resolvedViewport = getContext()->getPolicy()->getPointerViewportForAssociatedDisplay(); - mDisplayId = resolvedViewport ? std::make_optional(ADISPLAY_ID_NONE) : std::nullopt; + mDisplayId = resolvedViewport ? std::make_optional(ui::ADISPLAY_ID_NONE) : std::nullopt; } mOrientation = (mParameters.orientationAware && mParameters.hasAssociatedDisplay) || diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h index 3daae2fe1d..e45105ad3a 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.h +++ b/services/inputflinger/reader/mapper/CursorInputMapper.h @@ -66,7 +66,7 @@ public: virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override; - virtual std::optional<int32_t> getAssociatedDisplayId() override; + virtual std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() override; private: // Amount that trackball needs to move in order to generate a key event. @@ -115,7 +115,7 @@ private: // The display that events generated by this mapper should target. This can be set to // ADISPLAY_ID_NONE to target the focused display. If there is no display target (i.e. // std::nullopt), all events will be ignored. - std::optional<int32_t> mDisplayId; + std::optional<ui::LogicalDisplayId> mDisplayId; ui::Rotation mOrientation{ui::ROTATION_0}; FloatRect mBoundsInLogicalDisplay{}; diff --git a/services/inputflinger/reader/mapper/InputMapper.h b/services/inputflinger/reader/mapper/InputMapper.h index 06de4c25e3..c7eea0e980 100644 --- a/services/inputflinger/reader/mapper/InputMapper.h +++ b/services/inputflinger/reader/mapper/InputMapper.h @@ -117,7 +117,7 @@ public: [[nodiscard]] virtual std::list<NotifyArgs> updateExternalStylusState(const StylusState& state); - virtual std::optional<int32_t> getAssociatedDisplayId() { return std::nullopt; } + virtual std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() { return std::nullopt; } virtual void updateLedState(bool reset) {} protected: diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp index 8a9ea75a97..7fcff951b0 100644 --- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp +++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp @@ -341,7 +341,7 @@ std::list<NotifyArgs> JoystickInputMapper::sync(nsecs_t when, nsecs_t readTime, // button will likely wake the device. // TODO: Use the input device configuration to control this behavior more finely. uint32_t policyFlags = 0; - int32_t displayId = ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; if (getDeviceContext().getAssociatedViewport()) { displayId = getDeviceContext().getAssociatedViewport()->displayId; } diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp index 658ceabcc3..be8d183215 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp @@ -110,11 +110,11 @@ ui::Rotation KeyboardInputMapper::getOrientation() { return ui::ROTATION_0; } -int32_t KeyboardInputMapper::getDisplayId() { +ui::LogicalDisplayId KeyboardInputMapper::getDisplayId() { if (mViewport) { return mViewport->displayId; } - return ADISPLAY_ID_NONE; + return ui::ADISPLAY_ID_NONE; } std::optional<KeyboardLayoutInfo> KeyboardInputMapper::getKeyboardLayoutInfo() const { @@ -457,7 +457,7 @@ void KeyboardInputMapper::updateLedStateForModifier(LedState& ledState, int32_t } } -std::optional<int32_t> KeyboardInputMapper::getAssociatedDisplayId() { +std::optional<ui::LogicalDisplayId> KeyboardInputMapper::getAssociatedDisplayId() { if (mViewport) { return std::make_optional(mViewport->displayId); } diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.h b/services/inputflinger/reader/mapper/KeyboardInputMapper.h index 500256b21f..f2d3f4d7d8 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.h +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.h @@ -46,7 +46,7 @@ public: int32_t getMetaState() override; bool updateMetaState(int32_t keyCode) override; - std::optional<int32_t> getAssociatedDisplayId() override; + std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() override; void updateLedState(bool reset) override; private: @@ -91,7 +91,7 @@ private: void dumpParameters(std::string& dump) const; ui::Rotation getOrientation(); - int32_t getDisplayId(); + ui::LogicalDisplayId getDisplayId(); [[nodiscard]] std::list<NotifyArgs> processKey(nsecs_t when, nsecs_t readTime, bool down, int32_t scanCode, int32_t usageCode); diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp index 07ae5b1cac..a3206c2844 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp @@ -125,7 +125,7 @@ std::list<NotifyArgs> RotaryEncoderInputMapper::sync(nsecs_t when, nsecs_t readT if (scrolled) { int32_t metaState = getContext()->getGlobalMetaState(); // This is not a pointer, so it's not associated with a display. - int32_t displayId = ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; if (mOrientation == ui::ROTATION_180) { scroll = -scroll; diff --git a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.cpp b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.cpp index c12e95dfa0..d60dc5546b 100644 --- a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.cpp +++ b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.cpp @@ -28,7 +28,7 @@ namespace { [[nodiscard]] std::list<NotifyArgs> synthesizeButtonKey( InputReaderContext* context, int32_t action, nsecs_t when, nsecs_t readTime, - int32_t deviceId, uint32_t source, int32_t displayId, uint32_t policyFlags, + int32_t deviceId, uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState, int32_t buttonState, int32_t keyCode) { std::list<NotifyArgs> out; if ((action == AKEY_EVENT_ACTION_DOWN && !(lastButtonState & buttonState) && @@ -88,7 +88,7 @@ bool isPointerDown(int32_t buttonState) { [[nodiscard]] std::list<NotifyArgs> synthesizeButtonKeys( InputReaderContext* context, int32_t action, nsecs_t when, nsecs_t readTime, - int32_t deviceId, uint32_t source, int32_t displayId, uint32_t policyFlags, + int32_t deviceId, uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState) { std::list<NotifyArgs> out; out += synthesizeButtonKey(context, action, when, readTime, deviceId, source, displayId, diff --git a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h index 3023e686c2..13d952b99c 100644 --- a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h +++ b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h @@ -36,7 +36,7 @@ bool isPointerDown(int32_t buttonState); [[nodiscard]] std::list<NotifyArgs> synthesizeButtonKeys( InputReaderContext* context, int32_t action, nsecs_t when, nsecs_t readTime, - int32_t deviceId, uint32_t source, int32_t displayId, uint32_t policyFlags, + int32_t deviceId, uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState); // For devices connected over Bluetooth, although they may produce events at a consistent rate, diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index cf07506d52..489bea8959 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -555,8 +555,8 @@ std::optional<DisplayViewport> TouchInputMapper::findViewport() { if (viewport) { return viewport; } else { - ALOGW("Can't find designated display viewport with ID %" PRId32 " for pointers.", - mConfig.defaultPointerDisplayId); + ALOGW("Can't find designated display viewport with ID %s for pointers.", + mConfig.defaultPointerDisplayId.toString().c_str()); } } @@ -1043,10 +1043,10 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded) if ((viewportChanged && !skipViewportUpdate) || deviceModeChanged) { ALOGI("Device reconfigured: id=%d, name='%s', size %s, orientation %s, mode %s, " - "display id %d", + "display id %s", getDeviceId(), getDeviceName().c_str(), toString(mDisplayBounds).c_str(), ftl::enum_string(mInputDeviceOrientation).c_str(), - ftl::enum_string(mDeviceMode).c_str(), mViewport.displayId); + ftl::enum_string(mDeviceMode).c_str(), mViewport.displayId.toString().c_str()); configureVirtualKeys(); @@ -2646,7 +2646,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns PointerCoords pointerCoords; pointerCoords.clear(); out.push_back(NotifyMotionArgs(getContext()->getNextId(), when, readTime, getDeviceId(), - mSource, ADISPLAY_ID_NONE, policyFlags, + mSource, ui::ADISPLAY_ID_NONE, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, flags, metaState, buttonState, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties, @@ -3477,7 +3477,7 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerMouse(nsecs_t when, nsecs hovering = false; } - return dispatchPointerSimple(when, readTime, policyFlags, down, hovering, ADISPLAY_ID_NONE); + return dispatchPointerSimple(when, readTime, policyFlags, down, hovering, ui::ADISPLAY_ID_NONE); } std::list<NotifyArgs> TouchInputMapper::abortPointerMouse(nsecs_t when, nsecs_t readTime, @@ -3491,7 +3491,8 @@ std::list<NotifyArgs> TouchInputMapper::abortPointerMouse(nsecs_t when, nsecs_t std::list<NotifyArgs> TouchInputMapper::dispatchPointerSimple(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, bool down, - bool hovering, int32_t displayId) { + bool hovering, + ui::LogicalDisplayId displayId) { LOG_ALWAYS_FATAL_IF(mDeviceMode != DeviceMode::POINTER, "%s cannot be used when the device is not in POINTER mode.", __func__); std::list<NotifyArgs> out; @@ -3683,14 +3684,14 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion( source |= AINPUT_SOURCE_BLUETOOTH_STYLUS; } - const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE); + const ui::LogicalDisplayId displayId = getAssociatedDisplayId().value_or(ui::ADISPLAY_ID_NONE); float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; if (mDeviceMode == DeviceMode::POINTER) { xCursorPosition = yCursorPosition = 0.f; } - const int32_t deviceId = getDeviceId(); + const DeviceId deviceId = getDeviceId(); std::vector<TouchVideoFrame> frames = getDeviceContext().getVideoFrames(); std::for_each(frames.begin(), frames.end(), [this](TouchVideoFrame& frame) { frame.rotate(this->mInputDeviceOrientation); }); @@ -3957,10 +3958,10 @@ bool TouchInputMapper::markSupportedKeyCodes(uint32_t sourceMask, return true; } -std::optional<int32_t> TouchInputMapper::getAssociatedDisplayId() { +std::optional<ui::LogicalDisplayId> TouchInputMapper::getAssociatedDisplayId() { if (mParameters.hasAssociatedDisplay) { if (mDeviceMode == DeviceMode::POINTER) { - return ADISPLAY_ID_NONE; + return ui::ADISPLAY_ID_NONE; } else { return std::make_optional(mViewport.displayId); } diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index 6485ab2159..0c9ffa24d0 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -26,13 +26,12 @@ #include <utility> #include <vector> -#include <stdint.h> -#include <gui/constants.h> #include <input/DisplayViewport.h> #include <input/Input.h> #include <input/InputDevice.h> #include <input/VelocityControl.h> #include <input/VelocityTracker.h> +#include <stdint.h> #include <ui/Rect.h> #include <ui/Rotation.h> #include <ui/Size.h> @@ -186,7 +185,7 @@ public: [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> updateExternalStylusState( const StylusState& state) override; - std::optional<int32_t> getAssociatedDisplayId() override; + std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() override; protected: CursorButtonAccumulator mCursorButtonAccumulator; @@ -706,7 +705,7 @@ private: // Values reported for the last pointer event. uint32_t source; - int32_t displayId; + ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; float lastCursorX; float lastCursorY; @@ -719,7 +718,7 @@ private: hovering = false; downTime = 0; source = 0; - displayId = ADISPLAY_ID_NONE; + displayId = ui::ADISPLAY_ID_NONE; lastCursorX = 0.f; lastCursorY = 0.f; } @@ -810,7 +809,8 @@ private: [[nodiscard]] std::list<NotifyArgs> dispatchPointerSimple(nsecs_t when, nsecs_t readTime, uint32_t policyFlags, bool down, - bool hovering, int32_t displayId); + bool hovering, + ui::LogicalDisplayId displayId); [[nodiscard]] std::list<NotifyArgs> abortPointerSimple(nsecs_t when, nsecs_t readTime, uint32_t policyFlags); diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp index 6a38aa7b08..e157862f85 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp @@ -309,7 +309,8 @@ void TouchpadInputMapper::dump(std::string& dump) { } dump += INDENT3 "Captured event converter:\n"; dump += addLinePrefix(mCapturedEventConverter.dump(), INDENT4); - dump += StringPrintf(INDENT3 "DisplayId: %s\n", toString(mDisplayId).c_str()); + dump += StringPrintf(INDENT3 "DisplayId: %s\n", + toString(mDisplayId, streamableToString).c_str()); } std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when, @@ -321,7 +322,7 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when, } if (!changes.any() || changes.test(InputReaderConfiguration::Change::DISPLAY_INFO)) { - mDisplayId = ADISPLAY_ID_NONE; + mDisplayId = ui::ADISPLAY_ID_NONE; std::optional<DisplayViewport> resolvedViewport; std::optional<FloatRect> boundsInLogicalDisplay; if (auto assocViewport = mDeviceContext.getAssociatedViewport(); assocViewport) { @@ -334,7 +335,7 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when, // Always use DISPLAY_ID_NONE for touchpad events. // PointerChoreographer will make it target the correct the displayId later. resolvedViewport = getContext()->getPolicy()->getPointerViewportForAssociatedDisplay(); - mDisplayId = resolvedViewport ? std::make_optional(ADISPLAY_ID_NONE) : std::nullopt; + mDisplayId = resolvedViewport ? std::make_optional(ui::ADISPLAY_ID_NONE) : std::nullopt; } mGestureConverter.setDisplayId(mDisplayId); @@ -497,7 +498,7 @@ std::list<NotifyArgs> TouchpadInputMapper::processGestures(nsecs_t when, nsecs_t return out; } -std::optional<int32_t> TouchpadInputMapper::getAssociatedDisplayId() { +std::optional<ui::LogicalDisplayId> TouchpadInputMapper::getAssociatedDisplayId() { return mDisplayId; } diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h index 9f685ec6a8..f27895fd9c 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h @@ -66,7 +66,7 @@ public: using MetricsIdentifier = std::tuple<uint16_t /*busId*/, uint16_t /*vendorId*/, uint16_t /*productId*/, uint16_t /*version*/>; - std::optional<int32_t> getAssociatedDisplayId() override; + std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() override; private: void resetGestureInterpreter(nsecs_t when); @@ -109,7 +109,7 @@ private: // The display that events generated by this mapper should target. This can be set to // ADISPLAY_ID_NONE to target the focused display. If there is no display target (i.e. // std::nullopt), all events will be ignored. - std::optional<int32_t> mDisplayId; + std::optional<ui::LogicalDisplayId> mDisplayId; nsecs_t mGestureStartTime{0}; }; diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.h b/services/inputflinger/reader/mapper/gestures/GestureConverter.h index e6ced0f02c..829fb9289b 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.h +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.h @@ -51,7 +51,7 @@ public: void setOrientation(ui::Rotation orientation) { mOrientation = orientation; } [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when); - void setDisplayId(std::optional<int32_t> displayId) { mDisplayId = displayId; } + void setDisplayId(std::optional<ui::LogicalDisplayId> displayId) { mDisplayId = displayId; } void setBoundsInLogicalDisplay(FloatRect bounds) { mBoundsInLogicalDisplay = bounds; } @@ -100,7 +100,7 @@ private: InputReaderContext& mReaderContext; const bool mEnableFlingStop; - std::optional<int32_t> mDisplayId; + std::optional<ui::LogicalDisplayId> mDisplayId; FloatRect mBoundsInLogicalDisplay{}; ui::Rotation mOrientation = ui::ROTATION_0; RawAbsoluteAxisInfo mXAxisInfo; diff --git a/services/inputflinger/tests/CursorInputMapper_test.cpp b/services/inputflinger/tests/CursorInputMapper_test.cpp index c237fb68aa..72b5573047 100644 --- a/services/inputflinger/tests/CursorInputMapper_test.cpp +++ b/services/inputflinger/tests/CursorInputMapper_test.cpp @@ -50,8 +50,8 @@ constexpr auto BUTTON_PRESS = AMOTION_EVENT_ACTION_BUTTON_PRESS; constexpr auto BUTTON_RELEASE = AMOTION_EVENT_ACTION_BUTTON_RELEASE; constexpr auto HOVER_MOVE = AMOTION_EVENT_ACTION_HOVER_MOVE; constexpr auto INVALID_CURSOR_POSITION = AMOTION_EVENT_INVALID_CURSOR_POSITION; -constexpr int32_t DISPLAY_ID = 0; -constexpr int32_t SECONDARY_DISPLAY_ID = DISPLAY_ID + 1; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId SECONDARY_DISPLAY_ID = ui::LogicalDisplayId{DISPLAY_ID.val() + 1}; constexpr int32_t DISPLAY_WIDTH = 480; constexpr int32_t DISPLAY_HEIGHT = 800; @@ -909,7 +909,7 @@ TEST_F(CursorInputMapperUnitTest, ConfigureDisplayIdNoAssociatedViewport) { EXPECT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), - WithSource(AINPUT_SOURCE_MOUSE), WithDisplayId(ADISPLAY_ID_NONE), + WithSource(AINPUT_SOURCE_MOUSE), WithDisplayId(ui::ADISPLAY_ID_NONE), WithCoords(0.0f, 0.0f))))); } diff --git a/services/inputflinger/tests/FakeInputDispatcherPolicy.cpp b/services/inputflinger/tests/FakeInputDispatcherPolicy.cpp index 36491ab64f..530416c7aa 100644 --- a/services/inputflinger/tests/FakeInputDispatcherPolicy.cpp +++ b/services/inputflinger/tests/FakeInputDispatcherPolicy.cpp @@ -396,8 +396,8 @@ void FakeInputDispatcherPolicy::interceptKeyBeforeQueueing(const KeyEvent& input } } -void FakeInputDispatcherPolicy::interceptMotionBeforeQueueing(int32_t, uint32_t, int32_t, nsecs_t, - uint32_t&) {} +void FakeInputDispatcherPolicy::interceptMotionBeforeQueueing(ui::LogicalDisplayId, uint32_t, + int32_t, nsecs_t, uint32_t&) {} nsecs_t FakeInputDispatcherPolicy::interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) { @@ -426,7 +426,7 @@ void FakeInputDispatcherPolicy::notifySwitch(nsecs_t when, uint32_t switchValues } void FakeInputDispatcherPolicy::pokeUserActivity(nsecs_t eventTime, int32_t eventType, - int32_t displayId) { + ui::LogicalDisplayId displayId) { std::scoped_lock lock(mLock); mNotifyUserActivity.notify_all(); mUserActivityPokeEvents.push({eventTime, eventType, displayId}); diff --git a/services/inputflinger/tests/FakeInputDispatcherPolicy.h b/services/inputflinger/tests/FakeInputDispatcherPolicy.h index 25d3d3c7ed..2c86146ba3 100644 --- a/services/inputflinger/tests/FakeInputDispatcherPolicy.h +++ b/services/inputflinger/tests/FakeInputDispatcherPolicy.h @@ -53,7 +53,7 @@ public: struct UserActivityPokeEvent { nsecs_t eventTime; int32_t eventType; - int32_t displayId; + ui::LogicalDisplayId displayId; bool operator==(const UserActivityPokeEvent& rhs) const = default; inline friend std::ostream& operator<<(std::ostream& os, const UserActivityPokeEvent& ev) { @@ -183,13 +183,15 @@ private: void notifyVibratorState(int32_t deviceId, bool isOn) override; bool filterInputEvent(const InputEvent& inputEvent, uint32_t policyFlags) override; void interceptKeyBeforeQueueing(const KeyEvent& inputEvent, uint32_t&) override; - void interceptMotionBeforeQueueing(int32_t, uint32_t, int32_t, nsecs_t, uint32_t&) override; + void interceptMotionBeforeQueueing(ui::LogicalDisplayId, uint32_t, int32_t, nsecs_t, + uint32_t&) override; nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) override; std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent& event, uint32_t) override; void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) override; - void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) override; + void pokeUserActivity(nsecs_t eventTime, int32_t eventType, + ui::LogicalDisplayId displayId) override; bool isStaleEvent(nsecs_t currentTime, nsecs_t eventTime) override; void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override; void setPointerCapture(const PointerCaptureRequest& request) override; diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.cpp b/services/inputflinger/tests/FakeInputReaderPolicy.cpp index e2dcb41ac0..088c7df046 100644 --- a/services/inputflinger/tests/FakeInputReaderPolicy.cpp +++ b/services/inputflinger/tests/FakeInputReaderPolicy.cpp @@ -82,9 +82,9 @@ void FakeInputReaderPolicy::addDisplayViewport(DisplayViewport viewport) { mConfig.setDisplayViewports(mViewports); } -void FakeInputReaderPolicy::addDisplayViewport(int32_t displayId, int32_t width, int32_t height, - ui::Rotation orientation, bool isActive, - const std::string& uniqueId, +void FakeInputReaderPolicy::addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, + int32_t height, ui::Rotation orientation, + bool isActive, const std::string& uniqueId, std::optional<uint8_t> physicalPort, ViewportType type) { const bool isRotated = orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270; @@ -178,7 +178,7 @@ PointerCaptureRequest FakeInputReaderPolicy::setPointerCapture(const sp<IBinder> return mConfig.pointerCaptureRequest; } -void FakeInputReaderPolicy::setDefaultPointerDisplayId(int32_t pointerDisplayId) { +void FakeInputReaderPolicy::setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId) { mConfig.defaultPointerDisplayId = pointerDisplayId; } @@ -255,8 +255,8 @@ void FakeInputReaderPolicy::notifyStylusGestureStarted(int32_t deviceId, nsecs_t } std::optional<DisplayViewport> FakeInputReaderPolicy::getPointerViewportForAssociatedDisplay( - int32_t associatedDisplayId) { - if (associatedDisplayId == ADISPLAY_ID_NONE) { + ui::LogicalDisplayId associatedDisplayId) { + if (!associatedDisplayId.isValid()) { associatedDisplayId = mConfig.defaultPointerDisplayId; } for (auto& viewport : mViewports) { diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.h b/services/inputflinger/tests/FakeInputReaderPolicy.h index 88f0ba7f9b..94f1311a1e 100644 --- a/services/inputflinger/tests/FakeInputReaderPolicy.h +++ b/services/inputflinger/tests/FakeInputReaderPolicy.h @@ -48,7 +48,7 @@ public: std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const; std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t displayPort) const; void addDisplayViewport(DisplayViewport viewport); - void addDisplayViewport(int32_t displayId, int32_t width, int32_t height, + void addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height, ui::Rotation orientation, bool isActive, const std::string& uniqueId, std::optional<uint8_t> physicalPort, ViewportType type); bool updateViewport(const DisplayViewport& viewport); @@ -67,7 +67,7 @@ public: ui::Rotation surfaceRotation); void setTouchAffineTransformation(const TouchAffineTransformation t); PointerCaptureRequest setPointerCapture(const sp<IBinder>& window); - void setDefaultPointerDisplayId(int32_t pointerDisplayId); + void setDefaultPointerDisplayId(ui::LogicalDisplayId pointerDisplayId); void setPointerGestureEnabled(bool enabled); float getPointerGestureMovementSpeedRatio(); float getPointerGestureZoomSpeedRatio(); @@ -77,7 +77,7 @@ public: void setIsInputMethodConnectionActive(bool active); bool isInputMethodConnectionActive() override; std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay( - int32_t associatedDisplayId) override; + ui::LogicalDisplayId associatedDisplayId) override; private: void getReaderConfiguration(InputReaderConfiguration* outConfig) override; diff --git a/services/inputflinger/tests/FakePointerController.cpp b/services/inputflinger/tests/FakePointerController.cpp index 28d4b6751d..731a28668f 100644 --- a/services/inputflinger/tests/FakePointerController.cpp +++ b/services/inputflinger/tests/FakePointerController.cpp @@ -32,7 +32,7 @@ void FakePointerController::clearBounds() { mHaveBounds = false; } -const std::map<int32_t, std::vector<int32_t>>& FakePointerController::getSpots() { +const std::map<ui::LogicalDisplayId, std::vector<int32_t>>& FakePointerController::getSpots() { return mSpotsByDisplay; } @@ -51,9 +51,9 @@ FloatPoint FakePointerController::getPosition() const { return {mX, mY}; } -int32_t FakePointerController::getDisplayId() const { +ui::LogicalDisplayId FakePointerController::getDisplayId() const { if (!mEnabled || !mDisplayId) { - return ADISPLAY_ID_NONE; + return ui::ADISPLAY_ID_NONE; } return *mDisplayId; } @@ -76,7 +76,7 @@ void FakePointerController::setCustomPointerIcon(const SpriteIcon& icon) { mCustomIconStyle = icon.style; } -void FakePointerController::setSkipScreenshot(int32_t displayId, bool skip) { +void FakePointerController::setSkipScreenshot(ui::LogicalDisplayId displayId, bool skip) { if (skip) { mDisplaysToSkipScreenshot.insert(displayId); } else { @@ -84,7 +84,7 @@ void FakePointerController::setSkipScreenshot(int32_t displayId, bool skip) { } }; -void FakePointerController::assertViewportSet(int32_t displayId) { +void FakePointerController::assertViewportSet(ui::LogicalDisplayId displayId) { ASSERT_TRUE(mDisplayId); ASSERT_EQ(displayId, mDisplayId); } @@ -99,7 +99,7 @@ void FakePointerController::assertPosition(float x, float y) { ASSERT_NEAR(y, actualY, 1); } -void FakePointerController::assertSpotCount(int32_t displayId, int32_t count) { +void FakePointerController::assertSpotCount(ui::LogicalDisplayId displayId, int32_t count) { auto it = mSpotsByDisplay.find(displayId); ASSERT_TRUE(it != mSpotsByDisplay.end()) << "Spots not found for display " << displayId; ASSERT_EQ(static_cast<size_t>(count), it->second.size()); @@ -125,7 +125,8 @@ void FakePointerController::assertCustomPointerIconNotSet() { ASSERT_EQ(std::nullopt, mCustomIconStyle); } -void FakePointerController::assertIsHiddenOnMirroredDisplays(int32_t displayId, bool isHidden) { +void FakePointerController::assertIsHiddenOnMirroredDisplays(ui::LogicalDisplayId displayId, + bool isHidden) { if (isHidden) { ASSERT_TRUE(mDisplaysToSkipScreenshot.find(displayId) != mDisplaysToSkipScreenshot.end()); } else { @@ -166,7 +167,7 @@ void FakePointerController::unfade(Transition) { } void FakePointerController::setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits, - int32_t displayId) { + ui::LogicalDisplayId displayId) { if (!mEnabled) return; std::vector<int32_t> newSpots; diff --git a/services/inputflinger/tests/FakePointerController.h b/services/inputflinger/tests/FakePointerController.h index b5b982e012..5bc713f80d 100644 --- a/services/inputflinger/tests/FakePointerController.h +++ b/services/inputflinger/tests/FakePointerController.h @@ -17,7 +17,6 @@ #pragma once #include <PointerControllerInterface.h> -#include <gui/constants.h> #include <input/DisplayViewport.h> #include <input/Input.h> #include <utils/BitSet.h> @@ -38,26 +37,26 @@ public: void setBounds(float minX, float minY, float maxX, float maxY); void clearBounds(); - const std::map<int32_t, std::vector<int32_t>>& getSpots(); + const std::map<ui::LogicalDisplayId, std::vector<int32_t>>& getSpots(); void setPosition(float x, float y) override; FloatPoint getPosition() const override; - int32_t getDisplayId() const override; + ui::LogicalDisplayId getDisplayId() const override; void setDisplayViewport(const DisplayViewport& viewport) override; void updatePointerIcon(PointerIconStyle iconId) override; void setCustomPointerIcon(const SpriteIcon& icon) override; - void setSkipScreenshot(int32_t displayId, bool skip) override; + void setSkipScreenshot(ui::LogicalDisplayId displayId, bool skip) override; void fade(Transition) override; - void assertViewportSet(int32_t displayId); + void assertViewportSet(ui::LogicalDisplayId displayId); void assertViewportNotSet(); void assertPosition(float x, float y); - void assertSpotCount(int32_t displayId, int32_t count); + void assertSpotCount(ui::LogicalDisplayId displayId, int32_t count); void assertPointerIconSet(PointerIconStyle iconId); void assertPointerIconNotSet(); void assertCustomPointerIconSet(PointerIconStyle iconId); void assertCustomPointerIconNotSet(); - void assertIsHiddenOnMirroredDisplays(int32_t displayId, bool isHidden); + void assertIsHiddenOnMirroredDisplays(ui::LogicalDisplayId displayId, bool isHidden); bool isPointerShown(); private: @@ -67,20 +66,20 @@ private: void unfade(Transition) override; void setPresentation(Presentation) override {} void setSpots(const PointerCoords*, const uint32_t*, BitSet32 spotIdBits, - int32_t displayId) override; + ui::LogicalDisplayId displayId) override; void clearSpots() override; const bool mEnabled; bool mHaveBounds{false}; float mMinX{0}, mMinY{0}, mMaxX{0}, mMaxY{0}; float mX{0}, mY{0}; - std::optional<int32_t> mDisplayId; + std::optional<ui::LogicalDisplayId> mDisplayId; bool mIsPointerShown{false}; std::optional<PointerIconStyle> mIconStyle; std::optional<PointerIconStyle> mCustomIconStyle; - std::map<int32_t, std::vector<int32_t>> mSpotsByDisplay; - std::unordered_set<int32_t> mDisplaysToSkipScreenshot; + std::map<ui::LogicalDisplayId, std::vector<int32_t>> mSpotsByDisplay; + std::unordered_set<ui::LogicalDisplayId> mDisplaysToSkipScreenshot; }; } // namespace android diff --git a/services/inputflinger/tests/FakeWindows.cpp b/services/inputflinger/tests/FakeWindows.cpp index a6955eca94..c800d6ad4e 100644 --- a/services/inputflinger/tests/FakeWindows.cpp +++ b/services/inputflinger/tests/FakeWindows.cpp @@ -81,7 +81,7 @@ void FakeInputReceiver::sendTimeline(int32_t inputEventId, } void FakeInputReceiver::consumeEvent(InputEventType expectedEventType, int32_t expectedAction, - std::optional<int32_t> expectedDisplayId, + std::optional<ui::LogicalDisplayId> expectedDisplayId, std::optional<int32_t> expectedFlags) { std::unique_ptr<InputEvent> event = consume(CONSUME_TIMEOUT_EVENT_EXPECTED); @@ -152,7 +152,7 @@ void FakeInputReceiver::consumeFocusEvent(bool hasFocus, bool inTouchMode) { ASSERT_NE(nullptr, event) << mName.c_str() << ": consumer should have returned non-NULL event."; ASSERT_EQ(InputEventType::FOCUS, event->getType()) << "Instead of FocusEvent, got " << *event; - ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId()) + ASSERT_EQ(ui::ADISPLAY_ID_NONE, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; FocusEvent& focusEvent = static_cast<FocusEvent&>(*event); @@ -165,7 +165,7 @@ void FakeInputReceiver::consumeCaptureEvent(bool hasCapture) { ASSERT_EQ(InputEventType::CAPTURE, event->getType()) << "Instead of CaptureEvent, got " << *event; - ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId()) + ASSERT_EQ(ui::ADISPLAY_ID_NONE, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; const auto& captureEvent = static_cast<const CaptureEvent&>(*event); @@ -177,7 +177,7 @@ void FakeInputReceiver::consumeDragEvent(bool isExiting, float x, float y) { ASSERT_NE(nullptr, event) << mName.c_str() << ": consumer should have returned non-NULL event."; ASSERT_EQ(InputEventType::DRAG, event->getType()) << "Instead of DragEvent, got " << *event; - EXPECT_EQ(ADISPLAY_ID_NONE, event->getDisplayId()) + EXPECT_EQ(ui::ADISPLAY_ID_NONE, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; const auto& dragEvent = static_cast<const DragEvent&>(*event); @@ -192,7 +192,7 @@ void FakeInputReceiver::consumeTouchModeEvent(bool inTouchMode) { ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType()) << "Instead of TouchModeEvent, got " << *event; - ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId()) + ASSERT_EQ(ui::ADISPLAY_ID_NONE, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; const auto& touchModeEvent = static_cast<const TouchModeEvent&>(*event); EXPECT_EQ(inTouchMode, touchModeEvent.isInTouchMode()); @@ -244,7 +244,7 @@ std::atomic<int32_t> FakeWindowHandle::sId{1}; FakeWindowHandle::FakeWindowHandle( const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle, const std::unique_ptr<inputdispatcher::InputDispatcher>& dispatcher, const std::string name, - int32_t displayId, bool createInputChannel) + ui::LogicalDisplayId displayId, bool createInputChannel) : mName(name) { sp<IBinder> token; if (createInputChannel) { @@ -272,7 +272,7 @@ FakeWindowHandle::FakeWindowHandle( mInfo.inputConfig = InputConfig::DEFAULT; } -sp<FakeWindowHandle> FakeWindowHandle::clone(int32_t displayId) { +sp<FakeWindowHandle> FakeWindowHandle::clone(ui::LogicalDisplayId displayId) { sp<FakeWindowHandle> handle = sp<FakeWindowHandle>::make(mInfo.name + "(Mirror)"); handle->mInfo = mInfo; handle->mInfo.displayId = displayId; diff --git a/services/inputflinger/tests/FakeWindows.h b/services/inputflinger/tests/FakeWindows.h index 6cd76b229d..8a40337db4 100644 --- a/services/inputflinger/tests/FakeWindows.h +++ b/services/inputflinger/tests/FakeWindows.h @@ -79,7 +79,7 @@ public: void sendTimeline(int32_t inputEventId, std::array<nsecs_t, GraphicsTimeline::SIZE> timeline); void consumeEvent(android::InputEventType expectedEventType, int32_t expectedAction, - std::optional<int32_t> expectedDisplayId, + std::optional<ui::LogicalDisplayId> expectedDisplayId, std::optional<int32_t> expectedFlags); std::unique_ptr<MotionEvent> consumeMotion(); @@ -119,9 +119,10 @@ public: FakeWindowHandle(const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle, const std::unique_ptr<inputdispatcher::InputDispatcher>& dispatcher, - const std::string name, int32_t displayId, bool createInputChannel = true); + const std::string name, ui::LogicalDisplayId displayId, + bool createInputChannel = true); - sp<FakeWindowHandle> clone(int32_t displayId); + sp<FakeWindowHandle> clone(ui::LogicalDisplayId displayId); inline void setTouchable(bool touchable) { mInfo.setInputConfig(InputConfig::NOT_TOUCHABLE, !touchable); @@ -249,37 +250,39 @@ public: return keyEvent; } - inline void consumeKeyDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) { + inline void consumeKeyDown(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { consumeKeyEvent(testing::AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags))); } - inline void consumeKeyUp(int32_t expectedDisplayId, int32_t expectedFlags = 0) { + inline void consumeKeyUp(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { consumeKeyEvent(testing::AllOf(WithKeyAction(AKEY_EVENT_ACTION_UP), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags))); } - inline void consumeMotionCancel(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, - int32_t expectedFlags = 0) { + inline void consumeMotionCancel( + ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, + int32_t expectedFlags = 0) { consumeMotionEvent(testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags | AMOTION_EVENT_FLAG_CANCELED))); } - inline void consumeMotionMove(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, + inline void consumeMotionMove(ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, int32_t expectedFlags = 0) { consumeMotionEvent(testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags))); } - inline void consumeMotionDown(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, + inline void consumeMotionDown(ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, int32_t expectedFlags = 0) { consumeAnyMotionDown(expectedDisplayId, expectedFlags); } - inline void consumeAnyMotionDown(std::optional<int32_t> expectedDisplayId = std::nullopt, - std::optional<int32_t> expectedFlags = std::nullopt) { + inline void consumeAnyMotionDown( + std::optional<ui::LogicalDisplayId> expectedDisplayId = std::nullopt, + std::optional<int32_t> expectedFlags = std::nullopt) { consumeMotionEvent( testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), testing::Conditional(expectedDisplayId.has_value(), @@ -288,9 +291,9 @@ public: WithFlags(*expectedFlags), testing::_))); } - inline void consumeMotionPointerDown(int32_t pointerIdx, - int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, - int32_t expectedFlags = 0) { + inline void consumeMotionPointerDown( + int32_t pointerIdx, ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, + int32_t expectedFlags = 0) { const int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); consumeMotionEvent(testing::AllOf(WithMotionAction(action), @@ -298,9 +301,9 @@ public: WithFlags(expectedFlags))); } - inline void consumeMotionPointerUp(int32_t pointerIdx, - int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, - int32_t expectedFlags = 0) { + inline void consumeMotionPointerUp( + int32_t pointerIdx, ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, + int32_t expectedFlags = 0) { const int32_t action = AMOTION_EVENT_ACTION_POINTER_UP | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); consumeMotionEvent(testing::AllOf(WithMotionAction(action), @@ -308,15 +311,16 @@ public: WithFlags(expectedFlags))); } - inline void consumeMotionUp(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, + inline void consumeMotionUp(ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, int32_t expectedFlags = 0) { consumeMotionEvent(testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags))); } - inline void consumeMotionOutside(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, - int32_t expectedFlags = 0) { + inline void consumeMotionOutside( + ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, + int32_t expectedFlags = 0) { consumeMotionEvent(testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_OUTSIDE), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags))); diff --git a/services/inputflinger/tests/FocusResolver_test.cpp b/services/inputflinger/tests/FocusResolver_test.cpp index cb8c3cb03c..f794da5daf 100644 --- a/services/inputflinger/tests/FocusResolver_test.cpp +++ b/services/inputflinger/tests/FocusResolver_test.cpp @@ -74,7 +74,7 @@ TEST(FocusResolverTest, SetFocusedWindow) { std::optional<FocusResolver::FocusChanges> changes = focusResolver.setFocusedWindow(request, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ focusableWindowToken); - ASSERT_EQ(request.displayId, changes->displayId); + ASSERT_EQ(ui::LogicalDisplayId{request.displayId}, changes->displayId); // invisible window cannot get focused request.token = invisibleWindowToken; @@ -169,19 +169,20 @@ TEST(FocusResolverTest, FocusTransferToMirror) { ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ focusableWindowToken); // The mirror window now comes on top, and the focus does not change - changes = focusResolver.setInputWindows(request.displayId, {mirror, window}); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, + {mirror, window}); ASSERT_FALSE(changes.has_value()); // The window now comes on top while the mirror is removed, and the focus does not change - changes = focusResolver.setInputWindows(request.displayId, {window}); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, {window}); ASSERT_FALSE(changes.has_value()); // The window is removed but the mirror is on top, and focus does not change - changes = focusResolver.setInputWindows(request.displayId, {mirror}); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, {mirror}); ASSERT_FALSE(changes.has_value()); // All windows removed - changes = focusResolver.setInputWindows(request.displayId, {}); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, {}); ASSERT_FOCUS_CHANGE(changes, /*from*/ focusableWindowToken, /*to*/ nullptr); } @@ -203,12 +204,12 @@ TEST(FocusResolverTest, SetInputWindows) { ASSERT_EQ(focusableWindowToken, changes->newFocus); // When there are no changes to the window, focus does not change - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FALSE(changes.has_value()); // Window visibility changes and the window loses focus window->setVisible(false); - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ focusableWindowToken, /*to*/ nullptr); } @@ -232,7 +233,7 @@ TEST(FocusResolverTest, FocusRequestsCanBePending) { // Window visibility changes and the window gets focused invisibleWindow->setVisible(true); - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ invisibleWindowToken); } @@ -256,25 +257,25 @@ TEST(FocusResolverTest, FocusRequestsArePersistent) { // Focusability changes and the window gets focused window->setFocusable(true); - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{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); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{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); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken); // Window is gone and the window loses focus - changes = focusResolver.setInputWindows(request.displayId, {}); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, {}); ASSERT_FOCUS_CHANGE(changes, /*from*/ windowToken, /*to*/ nullptr); // Window returns and the window gains focus - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken); } @@ -307,27 +308,27 @@ TEST(FocusResolverTest, FocusTransferTarget) { // Embedded is now focusable so will gain focus embeddedWindow->setFocusable(true); - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ hostWindowToken, /*to*/ embeddedWindowToken); // Embedded is not visible so host will get focus embeddedWindow->setVisible(false); - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ embeddedWindowToken, /*to*/ hostWindowToken); // Embedded is now visible so will get focus embeddedWindow->setVisible(true); - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ hostWindowToken, /*to*/ embeddedWindowToken); // Remove focusTransferTarget from host. Host will gain focus. hostWindow->editInfo()->focusTransferTarget = nullptr; - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ embeddedWindowToken, /*to*/ hostWindowToken); // Set invalid token for focusTransferTarget. Host will remain focus hostWindow->editInfo()->focusTransferTarget = sp<BBinder>::make(); - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FALSE(changes); } @@ -415,16 +416,16 @@ TEST(FocusResolverTest, FocusRequestsAreClearedWhenWindowIsRemoved) { std::optional<FocusResolver::FocusChanges> changes = focusResolver.setFocusedWindow(request, windows); ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken); - ASSERT_EQ(request.displayId, changes->displayId); + ASSERT_EQ(ui::LogicalDisplayId{request.displayId}, changes->displayId); // When a display is removed, all windows are removed from the display // and our focused window loses focus - changes = focusResolver.setInputWindows(request.displayId, {}); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, {}); ASSERT_FOCUS_CHANGE(changes, /*from*/ windowToken, /*to*/ nullptr); - focusResolver.displayRemoved(request.displayId); + focusResolver.displayRemoved(ui::LogicalDisplayId{request.displayId}); // When a display is re-added, the window does not get focus since the request was cleared. - changes = focusResolver.setInputWindows(request.displayId, windows); + changes = focusResolver.setInputWindows(ui::LogicalDisplayId{request.displayId}, windows); ASSERT_FALSE(changes); } diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index f50f5173b8..1132e9284c 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -20,7 +20,6 @@ #include <flag_macros.h> #include <gestures/GestureConverter.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include "FakeEventHub.h" #include "FakeInputReaderPolicy.h" @@ -46,6 +45,7 @@ const auto TOUCHPAD_PALM_REJECTION_V2 = } // namespace +using android::ui::ADISPLAY_ID_DEFAULT; using testing::AllOf; using testing::Each; using testing::ElementsAre; @@ -93,7 +93,7 @@ protected: TEST_F(GestureConverterTest, Move) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list<NotifyArgs> args = @@ -125,7 +125,7 @@ TEST_F(GestureConverterTest, Move_Rotated) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); converter.setOrientation(ui::ROTATION_90); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list<NotifyArgs> args = @@ -147,7 +147,7 @@ TEST_F(GestureConverterTest, Move_Rotated) { TEST_F(GestureConverterTest, ButtonsChange) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); // Press left and right buttons at once Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -172,7 +172,7 @@ TEST_F(GestureConverterTest, ButtonsChange) { ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); // Then release the left button Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -203,13 +203,13 @@ TEST_F(GestureConverterTest, ButtonsChange) { ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list<NotifyArgs> args = @@ -229,7 +229,7 @@ TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) { TEST_F(GestureConverterTest, DragWithButton) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); // Press the button Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -248,7 +248,7 @@ TEST_F(GestureConverterTest, DragWithButton) { ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); // Move Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); @@ -258,7 +258,7 @@ TEST_F(GestureConverterTest, DragWithButton) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0), WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); // Release the button Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -276,14 +276,14 @@ TEST_F(GestureConverterTest, DragWithButton) { ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Scroll) { const nsecs_t downTime = 12345; InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list<NotifyArgs> args = @@ -303,7 +303,7 @@ TEST_F(GestureConverterTest, Scroll) { AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); @@ -314,7 +314,7 @@ TEST_F(GestureConverterTest, Scroll) { WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, GESTURES_FLING_START); @@ -333,7 +333,7 @@ TEST_F(GestureConverterTest, Scroll) { WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Scroll_Rotated) { @@ -341,7 +341,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); converter.setOrientation(ui::ROTATION_90); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list<NotifyArgs> args = @@ -360,7 +360,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { Each(VariantWith<NotifyMotionArgs>( AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); @@ -388,13 +388,13 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list<NotifyArgs> args = @@ -412,13 +412,13 @@ TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionClassification(MotionClassification::NONE), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list<NotifyArgs> args = @@ -443,7 +443,7 @@ TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, /*dy=*/0); @@ -464,7 +464,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, /*dy=*/5); @@ -491,7 +491,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { // only checks movement in one dimension. InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, /* dy= */ 10); @@ -502,7 +502,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { Each(VariantWith<NotifyMotionArgs>( AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); // Three fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. @@ -548,7 +548,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); @@ -590,21 +590,21 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); converter.setOrientation(ui::ROTATION_90); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, /* dy= */ 10); std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(4u, args.size()); - ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT)))); + ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::ADISPLAY_ID_DEFAULT)))); // Three fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. @@ -648,7 +648,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); @@ -680,7 +680,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 10, /* dy= */ 0); @@ -691,7 +691,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { Each(VariantWith<NotifyMotionArgs>( AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); // Four fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. @@ -746,7 +746,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), WithPointerCount(4u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); @@ -799,13 +799,13 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Pinch_Inwards) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_START); @@ -825,7 +825,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { AllOf(WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); @@ -837,7 +837,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithGesturePinchScaleFactor(0.8f, EPSILON), WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0), WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_END); @@ -923,13 +923,13 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, GESTURES_ZOOM_START); @@ -954,7 +954,7 @@ TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, GESTURES_ZOOM_START); @@ -981,7 +981,7 @@ TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { TEST_F(GestureConverterTest, ResetWithButtonPressed) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, @@ -1007,13 +1007,13 @@ TEST_F(GestureConverterTest, ResetWithButtonPressed) { ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringScroll) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); @@ -1033,13 +1033,13 @@ TEST_F(GestureConverterTest, ResetDuringScroll) { WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, /*dy=*/10); @@ -1074,13 +1074,13 @@ TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringPinch) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, GESTURES_ZOOM_START); @@ -1106,13 +1106,13 @@ TEST_F(GestureConverterTest, ResetDuringPinch) { WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, FlingTapDown) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); @@ -1129,7 +1129,7 @@ TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); input_flags::enable_touchpad_fling_stop(true); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list<NotifyArgs> args = @@ -1161,7 +1161,7 @@ TEST_F(GestureConverterTest, Tap) { // Tap should produce button press/release events InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1201,14 +1201,14 @@ TEST_F(GestureConverterTest, Tap) { Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Click) { // Click should produce button press/release events InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1238,7 +1238,7 @@ TEST_F(GestureConverterTest, Click) { Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* down= */ GESTURES_BUTTON_NONE, @@ -1273,7 +1273,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1302,7 +1302,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay, InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1384,7 +1384,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1414,7 +1414,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* down= */ GESTURES_BUTTON_NONE, @@ -1452,7 +1452,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick, InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list<NotifyArgs> args = @@ -1468,7 +1468,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove, const nsecs_t gestureStartTime = 1000; InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); // Start a move gesture at gestureStartTime Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10); diff --git a/services/inputflinger/tests/InputDeviceMetricsCollector_test.cpp b/services/inputflinger/tests/InputDeviceMetricsCollector_test.cpp index 85e055d98e..029414b23d 100644 --- a/services/inputflinger/tests/InputDeviceMetricsCollector_test.cpp +++ b/services/inputflinger/tests/InputDeviceMetricsCollector_test.cpp @@ -18,7 +18,6 @@ #include <NotifyArgsBuilders.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <input/InputEventBuilders.h> #include <linux/input.h> @@ -64,7 +63,7 @@ InputDeviceInfo generateTestDeviceInfo(int32_t id = DEVICE_ID, uint32_t sources = TOUCHSCREEN | STYLUS) { auto info = InputDeviceInfo(); info.initialize(id, /*generation=*/1, /*controllerNumber=*/1, generateTestIdentifier(id), - "alias", /*isExternal=*/false, /*hasMic=*/false, ADISPLAY_ID_NONE); + "alias", /*isExternal=*/false, /*hasMic=*/false, ui::ADISPLAY_ID_NONE); info.addSource(sources); return info; } diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 09b358afe5..184659df0d 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -53,6 +53,7 @@ using android::gui::WindowInfo; using android::gui::WindowInfoHandle; using android::os::InputEventInjectionResult; using android::os::InputEventInjectionSync; +using android::ui::ADISPLAY_ID_DEFAULT; namespace android::inputdispatcher { @@ -72,8 +73,8 @@ static constexpr int32_t DEVICE_ID = DEFAULT_DEVICE_ID; static constexpr int32_t SECOND_DEVICE_ID = 2; // An arbitrary display id. -static constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; -static constexpr int32_t SECOND_DISPLAY_ID = 1; +constexpr ui::LogicalDisplayId DISPLAY_ID = ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId SECOND_DISPLAY_ID = ui::LogicalDisplayId{1}; // Ensure common actions are interchangeable between keys and motions for convenience. static_assert(AMOTION_EVENT_ACTION_DOWN == AKEY_EVENT_ACTION_DOWN); @@ -128,7 +129,7 @@ using ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID; static KeyEvent getTestKeyEvent() { KeyEvent event; - event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE, + event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_NONE, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, 0, AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); return event; @@ -243,7 +244,7 @@ protected: request.token = window->getToken(); request.windowName = window->getName(); request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); - request.displayId = window->getInfo()->displayId; + request.displayId = window->getInfo()->displayId.val(); mDispatcher->setFocusedWindow(request); } }; @@ -252,7 +253,7 @@ TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) { KeyEvent event; // Rejects undefined key actions. - event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE, + event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_NONE, INVALID_HMAC, /*action=*/-1, 0, AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); @@ -262,7 +263,7 @@ TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) { << "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, + event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ui::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, @@ -438,12 +439,13 @@ static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 500ms; class FakeMonitorReceiver { public: - FakeMonitorReceiver(InputDispatcher& dispatcher, const std::string name, int32_t displayId) + FakeMonitorReceiver(InputDispatcher& dispatcher, const std::string name, + ui::LogicalDisplayId displayId) : mInputReceiver(*dispatcher.createInputMonitor(displayId, name, MONITOR_PID), name) {} sp<IBinder> getToken() { return mInputReceiver.getToken(); } - void consumeKeyDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) { + void consumeKeyDown(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { mInputReceiver.consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId, expectedFlags); } @@ -455,22 +457,22 @@ public: void finishEvent(uint32_t consumeSeq) { return mInputReceiver.finishEvent(consumeSeq); } - void consumeMotionDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) { + void consumeMotionDown(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { mInputReceiver.consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_DOWN, expectedDisplayId, expectedFlags); } - void consumeMotionMove(int32_t expectedDisplayId, int32_t expectedFlags = 0) { + void consumeMotionMove(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { mInputReceiver.consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_MOVE, expectedDisplayId, expectedFlags); } - void consumeMotionUp(int32_t expectedDisplayId, int32_t expectedFlags = 0) { + void consumeMotionUp(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { mInputReceiver.consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_UP, expectedDisplayId, expectedFlags); } - void consumeMotionCancel(int32_t expectedDisplayId, int32_t expectedFlags = 0) { + void consumeMotionCancel(ui::LogicalDisplayId expectedDisplayId, int32_t expectedFlags = 0) { mInputReceiver.consumeMotionEvent( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), WithDisplayId(expectedDisplayId), @@ -498,7 +500,7 @@ private: static InputEventInjectionResult injectKey( InputDispatcher& dispatcher, int32_t action, int32_t repeatCount, - int32_t displayId = ADISPLAY_ID_NONE, + ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE, InputEventInjectionSync syncMode = InputEventInjectionSync::WAIT_FOR_RESULT, std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT, bool allowKeyRepeat = true, std::optional<gui::Uid> targetUid = {}, @@ -520,30 +522,30 @@ static InputEventInjectionResult injectKey( static void assertInjectedKeyTimesOut(InputDispatcher& dispatcher) { InputEventInjectionResult result = - injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_NONE, + injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ui::ADISPLAY_ID_NONE, InputEventInjectionSync::WAIT_FOR_RESULT, CONSUME_TIMEOUT_NO_EVENT_EXPECTED); if (result != InputEventInjectionResult::TIMED_OUT) { FAIL() << "Injection should have timed out, but got " << ftl::enum_string(result); } } -static InputEventInjectionResult injectKeyDown(InputDispatcher& dispatcher, - int32_t displayId = ADISPLAY_ID_NONE) { +static InputEventInjectionResult injectKeyDown( + InputDispatcher& dispatcher, ui::LogicalDisplayId displayId = ui::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(InputDispatcher& dispatcher, - int32_t displayId = ADISPLAY_ID_NONE) { +static InputEventInjectionResult injectKeyDownNoRepeat( + InputDispatcher& dispatcher, ui::LogicalDisplayId displayId = ui::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(InputDispatcher& dispatcher, - int32_t displayId = ADISPLAY_ID_NONE) { +static InputEventInjectionResult injectKeyUp( + InputDispatcher& dispatcher, ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { return injectKey(dispatcher, AKEY_EVENT_ACTION_UP, /*repeatCount=*/0, displayId); } @@ -557,7 +559,7 @@ static InputEventInjectionResult injectMotionEvent( } static InputEventInjectionResult injectMotionEvent( - InputDispatcher& dispatcher, int32_t action, int32_t source, int32_t displayId, + InputDispatcher& dispatcher, int32_t action, int32_t source, ui::LogicalDisplayId displayId, const PointF& position = {100, 200}, const PointF& cursorPosition = {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION}, @@ -583,18 +585,19 @@ static InputEventInjectionResult injectMotionEvent( } static InputEventInjectionResult injectMotionDown(InputDispatcher& dispatcher, int32_t source, - int32_t displayId, + ui::LogicalDisplayId displayId, const PointF& location = {100, 200}) { return injectMotionEvent(dispatcher, AMOTION_EVENT_ACTION_DOWN, source, displayId, location); } static InputEventInjectionResult injectMotionUp(InputDispatcher& dispatcher, int32_t source, - int32_t displayId, + ui::LogicalDisplayId 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) { +static NotifyKeyArgs generateKeyArgs(int32_t action, + ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); // Define a valid key event. NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, @@ -604,8 +607,8 @@ static NotifyKeyArgs generateKeyArgs(int32_t action, int32_t displayId = ADISPLA return args; } -static NotifyKeyArgs generateSystemShortcutArgs(int32_t action, - int32_t displayId = ADISPLAY_ID_NONE) { +static NotifyKeyArgs generateSystemShortcutArgs( + int32_t action, ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); // Define a valid key event. NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, @@ -615,8 +618,8 @@ static NotifyKeyArgs generateSystemShortcutArgs(int32_t action, return args; } -static NotifyKeyArgs generateAssistantKeyArgs(int32_t action, - int32_t displayId = ADISPLAY_ID_NONE) { +static NotifyKeyArgs generateAssistantKeyArgs( + int32_t action, ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); // Define a valid key event. NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, @@ -627,7 +630,7 @@ static NotifyKeyArgs generateAssistantKeyArgs(int32_t action, } [[nodiscard]] static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, - int32_t displayId, + ui::LogicalDisplayId displayId, const std::vector<PointF>& points) { size_t pointerCount = points.size(); if (action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_UP) { @@ -664,7 +667,8 @@ static NotifyMotionArgs generateTouchArgs(int32_t action, const std::vector<Poin return generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID, points); } -static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, int32_t displayId) { +static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, + ui::LogicalDisplayId displayId) { return generateMotionArgs(action, source, displayId, {PointF{100, 200}}); } @@ -733,7 +737,7 @@ TEST_F(InputDispatcherTest, WhenDisplayNotSpecified_InjectMotionToDefaultDisplay mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); // Inject a MotionEvent to an unknown display. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_NONE)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::ADISPLAY_ID_NONE)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Window should receive motion event. @@ -1267,7 +1271,6 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, InputEventInjectionSync::WAIT_FOR_RESULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - foregroundWindow->consumeMotionPointerDown(/*pointerIndex=*/1); wallpaperWindow->consumeMotionPointerDown(/*pointerIndex=*/1, ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); @@ -5567,8 +5570,8 @@ TEST_F(InputDispatcherTest, WhenMultiDisplayWindowSameToken_DispatchCancelToTarg ASSERT_NE(nullptr, event); EXPECT_EQ(AMOTION_EVENT_ACTION_CANCEL, event->getAction()); - // The cancel event is sent to windowDefaultDisplay of the ADISPLAY_ID_DEFAULT display, so the - // coordinates of the cancel are converted by windowDefaultDisplay's transform, the x and y + // The cancel event is sent to windowDefaultDisplay of the ADISPLAY_ID_DEFAULT display, so + // the coordinates of the cancel are converted by windowDefaultDisplay's transform, the x and y // coordinates are both 100, otherwise if the cancel event is sent to windowSecondDisplay of // SECOND_DISPLAY_ID, the x and y coordinates are 200 EXPECT_EQ(100, event->getX(0)); @@ -5589,7 +5592,7 @@ public: removeAllWindowsAndDisplays(); } - void addDisplayInfo(int displayId, const ui::Transform& transform) { + void addDisplayInfo(ui::LogicalDisplayId displayId, const ui::Transform& transform) { gui::DisplayInfo info; info.displayId = displayId; info.transform = transform; @@ -7278,7 +7281,7 @@ TEST_F(InputDispatcherTest, GeneratedHmac_ChangesWhenFieldsChange) { verifiedEvent.eventTimeNanos += 1; ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); - verifiedEvent.displayId += 1; + verifiedEvent.displayId = ui::LogicalDisplayId{verifiedEvent.displayId.val() + 1}; ASSERT_NE(initialHmac, mDispatcher->sign(verifiedEvent)); verifiedEvent.action += 1; @@ -7323,7 +7326,7 @@ TEST_F(InputDispatcherTest, SetFocusedWindow) { << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; // Focused window should receive event. - windowSecond->consumeKeyDown(ADISPLAY_ID_NONE); + windowSecond->consumeKeyDown(ui::ADISPLAY_ID_NONE); windowTop->assertNoEvents(); } @@ -7388,7 +7391,7 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) { << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; // Focused window should receive event. - windowSecond->consumeKeyDown(ADISPLAY_ID_NONE); + windowSecond->consumeKeyDown(ui::ADISPLAY_ID_NONE); } TEST_F(InputDispatcherTest, SetFocusedWindow_TransferFocusTokenNotFocusable) { @@ -7411,7 +7414,7 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_TransferFocusTokenNotFocusable) { << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; // Event should be dropped. - windowTop->consumeKeyDown(ADISPLAY_ID_NONE); + windowTop->consumeKeyDown(ui::ADISPLAY_ID_NONE); windowSecond->assertNoEvents(); } @@ -8516,13 +8519,13 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus) ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDownNoRepeat(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; windowInPrimary->assertNoEvents(); - windowInSecondary->consumeKeyDown(ADISPLAY_ID_NONE); + windowInSecondary->consumeKeyDown(ui::ADISPLAY_ID_NONE); // Remove all windows in secondary display. mDispatcher->onWindowInfosChanged({{*windowInPrimary->getInfo()}, {}, 0, 0}); // Old focus should receive a cancel event. - windowInSecondary->consumeKeyUp(ADISPLAY_ID_NONE, AKEY_EVENT_FLAG_CANCELED); + windowInSecondary->consumeKeyUp(ui::ADISPLAY_ID_NONE, AKEY_EVENT_FLAG_CANCELED); // Test inject a key down, should timeout because of no target window. ASSERT_NO_FATAL_FAILURE(assertInjectedKeyTimesOut(*mDispatcher)); @@ -8567,12 +8570,12 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) { // 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)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TRACKBALL, ui::ADISPLAY_ID_NONE)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; windowInPrimary->assertNoEvents(); monitorInPrimary.assertNoEvents(); - windowInSecondary->consumeMotionDown(ADISPLAY_ID_NONE); - monitorInSecondary.consumeMotionDown(ADISPLAY_ID_NONE); + windowInSecondary->consumeMotionDown(ui::ADISPLAY_ID_NONE); + monitorInSecondary.consumeMotionDown(ui::ADISPLAY_ID_NONE); } // Test per-display input monitors for key event. @@ -8588,8 +8591,8 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorKeyEvent_MultiDisplay) { << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; windowInPrimary->assertNoEvents(); monitorInPrimary.assertNoEvents(); - windowInSecondary->consumeKeyDown(ADISPLAY_ID_NONE); - monitorInSecondary.consumeKeyDown(ADISPLAY_ID_NONE); + windowInSecondary->consumeKeyDown(ui::ADISPLAY_ID_NONE); + monitorInSecondary.consumeKeyDown(ui::ADISPLAY_ID_NONE); } TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CanFocusWindowOnUnfocusedDisplay) { @@ -8748,7 +8751,7 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropMotionEvent_OnlyCancelCorr class InputFilterTest : public InputDispatcherTest { protected: - void testNotifyMotion(int32_t displayId, bool expectToBeFiltered, + void testNotifyMotion(ui::LogicalDisplayId displayId, bool expectToBeFiltered, const ui::Transform& transform = ui::Transform()) { NotifyMotionArgs motionArgs; @@ -8873,7 +8876,7 @@ protected: 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, + ui::ADISPLAY_ID_NONE, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, 0, AKEYCODE_A, KEY_A, AMETA_NONE, /*repeatCount=*/0, eventTime, eventTime); const int32_t additionalPolicyFlags = POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_DISABLE_KEY_REPEAT; @@ -8967,7 +8970,7 @@ protected: mWindow->consumeFocusEvent(true); } - void notifyAndConsumeMotion(int32_t action, uint32_t source, int32_t displayId, + void notifyAndConsumeMotion(int32_t action, uint32_t source, ui::LogicalDisplayId displayId, nsecs_t eventTime) { mDispatcher->notifyMotion(MotionArgsBuilder(action, source) .displayId(displayId) @@ -9482,7 +9485,7 @@ 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)); - mWindow->consumeKeyDown(ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertNotifyAnrWasNotCalled(); } @@ -9558,7 +9561,8 @@ TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_NoFocusedWindow) { // injection times out (instead of failing). const InputEventInjectionResult result = injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::WAIT_FOR_RESULT, 50ms, /*allowKeyRepeat=*/false); + InputEventInjectionSync::WAIT_FOR_RESULT, 50ms, + /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result); const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT); mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(timeout, mApplication); @@ -9581,7 +9585,7 @@ TEST_F(InputDispatcherSingleWindowAnr, StaleKeyEventDoesNotAnr) { std::chrono::nanoseconds(STALE_EVENT_TIMEOUT).count(); // Define a valid key down event that is stale (too old). - event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE, + event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_NONE, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, /*flags=*/0, AKEYCODE_A, KEY_A, AMETA_NONE, /*repeatCount=*/0, eventTime, eventTime); @@ -10262,7 +10266,8 @@ TEST_F(InputDispatcherMultiWindowAnr, PendingKey_GoesToNewlyFocusedWindow) { InputEventInjectionResult result = injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::NONE, /*injectionTimeout=*/100ms); + InputEventInjectionSync::NONE, + /*injectionTimeout=*/100ms); ASSERT_EQ(InputEventInjectionResult::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. @@ -10365,7 +10370,8 @@ TEST_F(InputDispatcherMultiWindowAnr, FocusedWindowWithoutSetFocusedApplication_ // Key will not be sent anywhere because we have no focused window. It will remain pending. InputEventInjectionResult result = injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::NONE, /*injectionTimeout=*/100ms, + InputEventInjectionSync::NONE, + /*injectionTimeout=*/100ms, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); @@ -10467,7 +10473,8 @@ TEST_F(InputDispatcherMultiWindowAnr, PruningInputQueueShouldNotDropPointerEvent // Pretend we are injecting KEYCODE_BACK, but it doesn't actually matter what key it is. InputEventInjectionResult result = injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::NONE, /*injectionTimeout=*/100ms, + InputEventInjectionSync::NONE, + /*injectionTimeout=*/100ms, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); @@ -10476,7 +10483,8 @@ TEST_F(InputDispatcherMultiWindowAnr, PruningInputQueueShouldNotDropPointerEvent .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) .build()); result = injectKey(*mDispatcher, AKEY_EVENT_ACTION_UP, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::NONE, /*injectionTimeout=*/100ms, + InputEventInjectionSync::NONE, + /*injectionTimeout=*/100ms, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); // The key that was injected is blocking the dispatcher, so the navigation bar shouldn't be @@ -10598,7 +10606,7 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, CanGetFocus) { mWindow->consumeFocusEvent(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); } // A focused & mirrored window remains focused only if the window and its mirror are both @@ -10610,10 +10618,10 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedIfAllWindowsFocusable) { mWindow->consumeFocusEvent(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyUp(ADISPLAY_ID_NONE); + mWindow->consumeKeyUp(ui::ADISPLAY_ID_NONE); mMirror->setFocusable(false); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); @@ -10635,20 +10643,20 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedIfAnyWindowVisible) { mWindow->consumeFocusEvent(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyUp(ADISPLAY_ID_NONE); + mWindow->consumeKeyUp(ui::ADISPLAY_ID_NONE); mMirror->setVisible(false); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyUp(ADISPLAY_ID_NONE); + mWindow->consumeKeyUp(ui::ADISPLAY_ID_NONE); mWindow->setVisible(false); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); @@ -10669,20 +10677,20 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedWhileWindowsAlive) { mWindow->consumeFocusEvent(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyUp(ADISPLAY_ID_NONE); + mWindow->consumeKeyUp(ui::ADISPLAY_ID_NONE); // single window is removed but the window token remains focused mDispatcher->onWindowInfosChanged({{*mMirror->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mMirror->consumeKeyDown(ADISPLAY_ID_NONE); + mMirror->consumeKeyDown(ui::ADISPLAY_ID_NONE); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mMirror->consumeKeyUp(ADISPLAY_ID_NONE); + mMirror->consumeKeyUp(ui::ADISPLAY_ID_NONE); // Both windows are removed mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); @@ -12489,11 +12497,11 @@ TEST_F(InputDispatcherSpyWindowTest, UnfocusableSpyDoesNotReceiveKeyEvents) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeKeyDown(ADISPLAY_ID_NONE); + window->consumeKeyDown(ui::ADISPLAY_ID_NONE); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeKeyUp(ADISPLAY_ID_NONE); + window->consumeKeyUp(ui::ADISPLAY_ID_NONE); spy->assertNoEvents(); } @@ -13073,7 +13081,8 @@ struct User { } InputEventInjectionResult injectTargetedKey(int32_t action) const { - return inputdispatcher::injectKey(*mDispatcher, action, /*repeatCount=*/0, ADISPLAY_ID_NONE, + return inputdispatcher::injectKey(*mDispatcher, action, /*repeatCount=*/0, + ui::ADISPLAY_ID_NONE, InputEventInjectionSync::WAIT_FOR_RESULT, INJECT_EVENT_TIMEOUT, /*allowKeyRepeat=*/false, {mUid}, mPolicyFlags); @@ -13105,7 +13114,7 @@ TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoOwnedWindow) { EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, owner.injectTargetedKey(AKEY_EVENT_ACTION_DOWN)); - window->consumeKeyDown(ADISPLAY_ID_NONE); + window->consumeKeyDown(ui::ADISPLAY_ID_NONE); } TEST_F(InputDispatcherTargetedInjectionTest, CannotInjectIntoUnownedWindow) { @@ -13178,7 +13187,7 @@ TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoAnyWindowWhenNotTarget randosSpy->consumeFocusEvent(true); EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)); - randosSpy->consumeKeyDown(ADISPLAY_ID_NONE); + randosSpy->consumeKeyDown(ui::ADISPLAY_ID_NONE); window->assertNoEvents(); } diff --git a/services/inputflinger/tests/InputMapperTest.cpp b/services/inputflinger/tests/InputMapperTest.cpp index ae6c849f14..fea1349b88 100644 --- a/services/inputflinger/tests/InputMapperTest.cpp +++ b/services/inputflinger/tests/InputMapperTest.cpp @@ -172,8 +172,8 @@ std::shared_ptr<InputDevice> InputMapperTest::newDevice(int32_t deviceId, const return device; } -void InputMapperTest::setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, - ui::Rotation orientation, +void InputMapperTest::setDisplayInfoAndReconfigure(ui::LogicalDisplayId displayId, int32_t width, + int32_t height, ui::Rotation orientation, const std::string& uniqueId, std::optional<uint8_t> physicalPort, ViewportType viewportType) { diff --git a/services/inputflinger/tests/InputMapperTest.h b/services/inputflinger/tests/InputMapperTest.h index 509a5937a7..5bd8cda976 100644 --- a/services/inputflinger/tests/InputMapperTest.h +++ b/services/inputflinger/tests/InputMapperTest.h @@ -128,7 +128,7 @@ protected: args...); } - void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, + void setDisplayInfoAndReconfigure(ui::LogicalDisplayId displayId, int32_t width, int32_t height, ui::Rotation orientation, const std::string& uniqueId, std::optional<uint8_t> physicalPort, ViewportType viewportType); diff --git a/services/inputflinger/tests/InputProcessorConverter_test.cpp b/services/inputflinger/tests/InputProcessorConverter_test.cpp index 4b42f4b141..15565326b1 100644 --- a/services/inputflinger/tests/InputProcessorConverter_test.cpp +++ b/services/inputflinger/tests/InputProcessorConverter_test.cpp @@ -17,7 +17,6 @@ #include "../InputCommonConverter.h" #include <gtest/gtest.h> -#include <gui/constants.h> #include <utils/BitSet.h> using namespace aidl::android::hardware::input; @@ -39,7 +38,7 @@ static NotifyMotionArgs generateBasicMotionArgs() { coords.setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.5); static constexpr nsecs_t downTime = 2; NotifyMotionArgs motionArgs(/*sequenceNum=*/1, /*eventTime=*/downTime, /*readTime=*/2, - /*deviceId=*/3, AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT, + /*deviceId=*/3, AINPUT_SOURCE_ANY, ui::ADISPLAY_ID_DEFAULT, /*policyFlags=*/4, AMOTION_EVENT_ACTION_DOWN, /*actionButton=*/0, /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, diff --git a/services/inputflinger/tests/InputProcessor_test.cpp b/services/inputflinger/tests/InputProcessor_test.cpp index 3b7cbfac5c..5606a91a0b 100644 --- a/services/inputflinger/tests/InputProcessor_test.cpp +++ b/services/inputflinger/tests/InputProcessor_test.cpp @@ -16,7 +16,6 @@ #include "../InputProcessor.h" #include <gtest/gtest.h> -#include <gui/constants.h> #include "TestInputListener.h" @@ -45,7 +44,7 @@ static NotifyMotionArgs generateBasicMotionArgs() { coords.setAxisValue(AMOTION_EVENT_AXIS_Y, 1); static constexpr nsecs_t downTime = 2; NotifyMotionArgs motionArgs(/*sequenceNum=*/1, /*eventTime=*/downTime, /*readTime=*/2, - /*deviceId=*/3, AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT, + /*deviceId=*/3, AINPUT_SOURCE_ANY, ui::ADISPLAY_ID_DEFAULT, /*policyFlags=*/4, AMOTION_EVENT_ACTION_DOWN, /*actionButton=*/0, /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, @@ -81,7 +80,7 @@ TEST_F(InputProcessorTest, SendToNextStage_NotifyConfigurationChangedArgs) { TEST_F(InputProcessorTest, SendToNextStage_NotifyKeyArgs) { // Create a basic key event and send to processor NotifyKeyArgs args(/*sequenceNum=*/1, /*eventTime=*/2, /*readTime=*/21, /*deviceId=*/3, - AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_DEFAULT, /*policyFlags=*/0, + AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_DEFAULT, /*policyFlags=*/0, AKEY_EVENT_ACTION_DOWN, /*flags=*/4, AKEYCODE_HOME, /*scanCode=*/5, AMETA_NONE, /*downTime=*/6); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 92489aec8d..fcc52a8f31 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -40,7 +40,6 @@ #include <com_android_input_flags.h> #include <ftl/enum.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <ui/Rotation.h> #include <thread> @@ -60,13 +59,14 @@ using std::chrono_literals::operator""ms; using std::chrono_literals::operator""s; // Arbitrary display properties. -static constexpr int32_t DISPLAY_ID = 0; +static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; static const std::string DISPLAY_UNIQUE_ID = "local:1"; -static constexpr int32_t SECONDARY_DISPLAY_ID = DISPLAY_ID + 1; +static constexpr ui::LogicalDisplayId SECONDARY_DISPLAY_ID = + ui::LogicalDisplayId{DISPLAY_ID.val() + 1}; static const std::string SECONDARY_DISPLAY_UNIQUE_ID = "local:2"; static constexpr int32_t DISPLAY_WIDTH = 480; static constexpr int32_t DISPLAY_HEIGHT = 800; -static constexpr int32_t VIRTUAL_DISPLAY_ID = 1; +static constexpr ui::LogicalDisplayId VIRTUAL_DISPLAY_ID = ui::LogicalDisplayId{1}; static constexpr int32_t VIRTUAL_DISPLAY_WIDTH = 400; static constexpr int32_t VIRTUAL_DISPLAY_HEIGHT = 500; static const char* VIRTUAL_DISPLAY_UNIQUE_ID = "virtual:1"; @@ -358,7 +358,7 @@ private: virtual void fadePointer() { } - virtual std::optional<int32_t> getAssociatedDisplay() { + virtual std::optional<ui::LogicalDisplayId> getAssociatedDisplay() { if (mViewport) { return std::make_optional(mViewport->displayId); } @@ -417,8 +417,8 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByType) { const std::string externalUniqueId = "local:1"; const std::string virtualUniqueId1 = "virtual:2"; const std::string virtualUniqueId2 = "virtual:3"; - constexpr int32_t virtualDisplayId1 = 2; - constexpr int32_t virtualDisplayId2 = 3; + constexpr ui::LogicalDisplayId virtualDisplayId1 = ui::LogicalDisplayId{2}; + constexpr ui::LogicalDisplayId virtualDisplayId2 = ui::LogicalDisplayId{3}; // Add an internal viewport mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, @@ -475,8 +475,8 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByType) { TEST_F(InputReaderPolicyTest, Viewports_TwoOfSameType) { const std::string uniqueId1 = "uniqueId1"; const std::string uniqueId2 = "uniqueId2"; - constexpr int32_t displayId1 = 2; - constexpr int32_t displayId2 = 3; + constexpr ui::LogicalDisplayId displayId1 = ui::LogicalDisplayId{2}; + constexpr ui::LogicalDisplayId displayId2 = ui::LogicalDisplayId{3}; std::vector<ViewportType> types = {ViewportType::INTERNAL, ViewportType::EXTERNAL, ViewportType::VIRTUAL}; @@ -520,13 +520,13 @@ TEST_F(InputReaderPolicyTest, Viewports_TwoOfSameType) { 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"); + constexpr ui::LogicalDisplayId nonDefaultDisplayId = ui::LogicalDisplayId{2}; + ASSERT_NE(nonDefaultDisplayId, ui::ADISPLAY_ID_DEFAULT) + << "Test display ID should not be ui::ADISPLAY_ID_DEFAULT "; // Add the default display first and ensure it gets returned. mFakePolicy->clearViewports(); - mFakePolicy->addDisplayViewport(ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, + mFakePolicy->addDisplayViewport(ui::ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, /*isActive=*/true, uniqueId1, NO_PORT, ViewportType::INTERNAL); mFakePolicy->addDisplayViewport(nonDefaultDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, @@ -536,7 +536,7 @@ TEST_F(InputReaderPolicyTest, Viewports_ByTypeReturnsDefaultForInternal) { std::optional<DisplayViewport> viewport = mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL); ASSERT_TRUE(viewport); - ASSERT_EQ(ADISPLAY_ID_DEFAULT, viewport->displayId); + ASSERT_EQ(ui::ADISPLAY_ID_DEFAULT, viewport->displayId); ASSERT_EQ(ViewportType::INTERNAL, viewport->type); // Add the default display second to make sure order doesn't matter. @@ -544,13 +544,13 @@ TEST_F(InputReaderPolicyTest, Viewports_ByTypeReturnsDefaultForInternal) { mFakePolicy->addDisplayViewport(nonDefaultDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, /*isActive=*/true, uniqueId2, NO_PORT, ViewportType::INTERNAL); - mFakePolicy->addDisplayViewport(ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, + mFakePolicy->addDisplayViewport(ui::ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, /*isActive=*/true, uniqueId1, NO_PORT, ViewportType::INTERNAL); viewport = mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL); ASSERT_TRUE(viewport); - ASSERT_EQ(ADISPLAY_ID_DEFAULT, viewport->displayId); + ASSERT_EQ(ui::ADISPLAY_ID_DEFAULT, viewport->displayId); ASSERT_EQ(ViewportType::INTERNAL, viewport->type); } @@ -561,8 +561,8 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByPort) { constexpr ViewportType type = ViewportType::EXTERNAL; const std::string uniqueId1 = "uniqueId1"; const std::string uniqueId2 = "uniqueId2"; - constexpr int32_t displayId1 = 1; - constexpr int32_t displayId2 = 2; + constexpr ui::LogicalDisplayId displayId1 = ui::LogicalDisplayId{1}; + constexpr ui::LogicalDisplayId displayId2 = ui::LogicalDisplayId{2}; const uint8_t hdmi1 = 0; const uint8_t hdmi2 = 1; const uint8_t hdmi3 = 2; @@ -1598,7 +1598,7 @@ protected: mDeviceInfo = *info; } - void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, + void setDisplayInfoAndReconfigure(ui::LogicalDisplayId displayId, int32_t width, int32_t height, ui::Rotation orientation, const std::string& uniqueId, std::optional<uint8_t> physicalPort, ViewportType viewportType) { @@ -3244,7 +3244,7 @@ protected: void testDPadKeyRotation(KeyboardInputMapper& mapper, int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode, - int32_t displayId = ADISPLAY_ID_NONE); + ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE); }; /* Similar to setDisplayInfoAndReconfigure, but pre-populates all parameters except for the @@ -3257,7 +3257,8 @@ void KeyboardInputMapperTest::prepareDisplay(ui::Rotation orientation) { void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper& mapper, int32_t originalScanCode, int32_t originalKeyCode, - int32_t rotatedKeyCode, int32_t displayId) { + int32_t rotatedKeyCode, + ui::LogicalDisplayId displayId) { NotifyKeyArgs args; process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, originalScanCode, 1); @@ -3583,14 +3584,14 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_NotOrientationAware ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); - ASSERT_EQ(ADISPLAY_ID_NONE, args.displayId); + ASSERT_EQ(ui::ADISPLAY_ID_NONE, args.displayId); prepareDisplay(ui::ROTATION_0); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); - ASSERT_EQ(ADISPLAY_ID_NONE, args.displayId); + ASSERT_EQ(ui::ADISPLAY_ID_NONE, args.displayId); } TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_OrientationAware) { @@ -3615,7 +3616,7 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_OrientationAware) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(DISPLAY_ID, args.displayId); - constexpr int32_t newDisplayId = 2; + constexpr ui::LogicalDisplayId newDisplayId = ui::LogicalDisplayId{2}; clearViewports(); setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); @@ -3830,7 +3831,7 @@ TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) { ASSERT_FALSE(device2->isEnabled()); // Prepare second display. - constexpr int32_t newDisplayId = 2; + constexpr ui::LogicalDisplayId newDisplayId = ui::LogicalDisplayId{2}; setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, UNIQUE_ID, hdmi1, ViewportType::INTERNAL); setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, @@ -8674,7 +8675,7 @@ TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShouldHandleDisplayId) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); - ASSERT_EQ(ADISPLAY_ID_NONE, motionArgs.displayId); + ASSERT_EQ(ui::ADISPLAY_ID_NONE, motionArgs.displayId); } /** @@ -9571,7 +9572,7 @@ TEST_F(MultiTouchInputMapperTest_ExternalDevice, Viewports_Fallback) { processPosition(mapper, 100, 100); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); - ASSERT_EQ(ADISPLAY_ID_DEFAULT, motionArgs.displayId); + ASSERT_EQ(ui::ADISPLAY_ID_DEFAULT, motionArgs.displayId); // Expect the event to be sent to the external viewport if it is present. prepareSecondaryDisplay(ViewportType::EXTERNAL); diff --git a/services/inputflinger/tests/InputTracingTest.cpp b/services/inputflinger/tests/InputTracingTest.cpp index 0404d6d4ed..dfbbce3b1a 100644 --- a/services/inputflinger/tests/InputTracingTest.cpp +++ b/services/inputflinger/tests/InputTracingTest.cpp @@ -41,7 +41,7 @@ using perfetto::protos::pbzero::AndroidInputEventConfig; namespace { -constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; // Ensure common actions are interchangeable between keys and motions for convenience. static_assert(static_cast<int32_t>(AMOTION_EVENT_ACTION_DOWN) == @@ -127,7 +127,7 @@ protected: request.token = window->getToken(); request.windowName = window->getName(); request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); - request.displayId = window->getInfo()->displayId; + request.displayId = window->getInfo()->displayId.val(); mDispatcher->setFocusedWindow(request); } diff --git a/services/inputflinger/tests/LatencyTracker_test.cpp b/services/inputflinger/tests/LatencyTracker_test.cpp index 6606de896b..01fd03e874 100644 --- a/services/inputflinger/tests/LatencyTracker_test.cpp +++ b/services/inputflinger/tests/LatencyTracker_test.cpp @@ -20,7 +20,6 @@ #include <android-base/properties.h> #include <binder/Binder.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <inttypes.h> #include <linux/input.h> #include <log/log.h> @@ -44,7 +43,7 @@ static InputDeviceInfo generateTestDeviceInfo(uint16_t vendorId, uint16_t produc identifier.product = productId; auto info = InputDeviceInfo(); info.initialize(deviceId, /*generation=*/1, /*controllerNumber=*/1, identifier, "Test Device", - /*isExternal=*/false, /*hasMic=*/false, ADISPLAY_ID_NONE); + /*isExternal=*/false, /*hasMic=*/false, ui::ADISPLAY_ID_NONE); return info; } diff --git a/services/inputflinger/tests/MultiTouchInputMapper_test.cpp b/services/inputflinger/tests/MultiTouchInputMapper_test.cpp index d726385240..437020f48a 100644 --- a/services/inputflinger/tests/MultiTouchInputMapper_test.cpp +++ b/services/inputflinger/tests/MultiTouchInputMapper_test.cpp @@ -35,7 +35,7 @@ using testing::Return; using testing::SetArgPointee; using testing::VariantWith; -static constexpr int32_t DISPLAY_ID = 0; +static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; static constexpr int32_t DISPLAY_WIDTH = 480; static constexpr int32_t DISPLAY_HEIGHT = 800; static constexpr std::optional<uint8_t> NO_PORT = std::nullopt; // no physical port is specified diff --git a/services/inputflinger/tests/NotifyArgs_test.cpp b/services/inputflinger/tests/NotifyArgs_test.cpp index 15367568ab..2e5ecc3350 100644 --- a/services/inputflinger/tests/NotifyArgs_test.cpp +++ b/services/inputflinger/tests/NotifyArgs_test.cpp @@ -36,7 +36,7 @@ TEST(NotifyMotionArgsTest, TestCopyAssignmentOperator) { nsecs_t readTime = downTime++; int32_t deviceId = 7; uint32_t source = AINPUT_SOURCE_TOUCHSCREEN; - int32_t displayId = 42; + ui::LogicalDisplayId displayId = ui::LogicalDisplayId{42}; uint32_t policyFlags = POLICY_FLAG_GESTURE; int32_t action = AMOTION_EVENT_ACTION_HOVER_MOVE; int32_t actionButton = AMOTION_EVENT_BUTTON_PRIMARY; diff --git a/services/inputflinger/tests/PointerChoreographer_test.cpp b/services/inputflinger/tests/PointerChoreographer_test.cpp index d81f8a0280..33e7277034 100644 --- a/services/inputflinger/tests/PointerChoreographer_test.cpp +++ b/services/inputflinger/tests/PointerChoreographer_test.cpp @@ -46,8 +46,8 @@ Visitor(V...) -> Visitor<V...>; constexpr int32_t DEVICE_ID = 3; constexpr int32_t SECOND_DEVICE_ID = DEVICE_ID + 1; constexpr int32_t THIRD_DEVICE_ID = SECOND_DEVICE_ID + 1; -constexpr int32_t DISPLAY_ID = 5; -constexpr int32_t ANOTHER_DISPLAY_ID = 10; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId{5}; +constexpr ui::LogicalDisplayId ANOTHER_DISPLAY_ID = ui::LogicalDisplayId{10}; constexpr int32_t DISPLAY_WIDTH = 480; constexpr int32_t DISPLAY_HEIGHT = 800; constexpr auto DRAWING_TABLET_SOURCE = AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS; @@ -63,7 +63,7 @@ const auto TOUCHPAD_POINTER = PointerBuilder(/*id=*/0, ToolType::FINGER) .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20); static InputDeviceInfo generateTestDeviceInfo(int32_t deviceId, uint32_t source, - int32_t associatedDisplayId) { + ui::LogicalDisplayId associatedDisplayId) { InputDeviceIdentifier identifier; auto info = InputDeviceInfo(); @@ -73,7 +73,7 @@ static InputDeviceInfo generateTestDeviceInfo(int32_t deviceId, uint32_t source, return info; } -static std::vector<DisplayViewport> createViewports(std::vector<int32_t> displayIds) { +static std::vector<DisplayViewport> createViewports(std::vector<ui::LogicalDisplayId> displayIds) { std::vector<DisplayViewport> viewports; for (auto displayId : displayIds) { DisplayViewport viewport; @@ -124,7 +124,7 @@ protected: "reference to this PointerController"; } - void assertPointerDisplayIdNotified(int32_t displayId) { + void assertPointerDisplayIdNotified(ui::LogicalDisplayId displayId) { ASSERT_EQ(displayId, mPointerDisplayIdNotified); mPointerDisplayIdNotified.reset(); } @@ -134,7 +134,7 @@ protected: private: std::deque<std::pair<ControllerType, std::shared_ptr<FakePointerController>>> mCreatedControllers; - std::optional<int32_t> mPointerDisplayIdNotified; + std::optional<ui::LogicalDisplayId> mPointerDisplayIdNotified; std::shared_ptr<PointerControllerInterface> createPointerController( ControllerType type) override { @@ -144,7 +144,8 @@ private: return pc; } - void notifyPointerDisplayIdChanged(int32_t displayId, const FloatPoint& position) override { + void notifyPointerDisplayIdChanged(ui::LogicalDisplayId displayId, + const FloatPoint& position) override { mPointerDisplayIdNotified = displayId; } }; @@ -201,13 +202,15 @@ TEST_F(PointerChoreographerTest, ForwardsArgsToInnerListener) { TEST_F(PointerChoreographerTest, WhenMouseIsAddedCreatesPointerController) { mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); assertPointerControllerCreated(ControllerType::MOUSE); } TEST_F(PointerChoreographerTest, WhenMouseIsRemovedRemovesPointerController) { mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); // Remove the mouse. @@ -218,7 +221,7 @@ TEST_F(PointerChoreographerTest, WhenMouseIsRemovedRemovesPointerController) { TEST_F(PointerChoreographerTest, WhenKeyboardIsAddedDoesNotCreatePointerController) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_NONE)}}); assertPointerControllerNotCreated(); } @@ -252,7 +255,8 @@ TEST_F(PointerChoreographerTest, SetsDefaultMouseViewportForPointerController) { // For a mouse event without a target display, default viewport should be set for // the PointerController. mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertViewportSet(DISPLAY_ID); ASSERT_TRUE(pc->isPointerShown()); @@ -264,7 +268,8 @@ TEST_F(PointerChoreographerTest, mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID, ANOTHER_DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto firstDisplayPc = assertPointerControllerCreated(ControllerType::MOUSE); firstDisplayPc->assertViewportSet(DISPLAY_ID); ASSERT_TRUE(firstDisplayPc->isPointerShown()); @@ -283,7 +288,8 @@ TEST_F(PointerChoreographerTest, CallsNotifyPointerDisplayIdChanged) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); @@ -292,7 +298,8 @@ TEST_F(PointerChoreographerTest, CallsNotifyPointerDisplayIdChanged) { TEST_F(PointerChoreographerTest, WhenViewportIsSetLaterCallsNotifyPointerDisplayIdChanged) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotNotified(); @@ -304,12 +311,13 @@ TEST_F(PointerChoreographerTest, WhenMouseIsRemovedCallsNotifyPointerDisplayIdCh mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged({/*id=*/1, {}}); - assertPointerDisplayIdNotified(ADISPLAY_ID_NONE); + assertPointerDisplayIdNotified(ui::ADISPLAY_ID_NONE); assertPointerControllerRemoved(pc); } @@ -320,7 +328,8 @@ TEST_F(PointerChoreographerTest, WhenDefaultMouseDisplayChangesCallsNotifyPointe // Set one viewport as a default mouse display ID. mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto firstDisplayPc = assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); @@ -336,7 +345,8 @@ TEST_F(PointerChoreographerTest, MouseMovesPointerAndReturnsNewArgs) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -348,7 +358,7 @@ TEST_F(PointerChoreographerTest, MouseMovesPointerAndReturnsNewArgs) { MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .pointer(MOUSE_POINTER) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); // Check that the PointerController updated the position and the pointer is shown. @@ -364,7 +374,8 @@ TEST_F(PointerChoreographerTest, AbsoluteMouseMovesPointerAndReturnsNewArgs) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -379,7 +390,7 @@ TEST_F(PointerChoreographerTest, AbsoluteMouseMovesPointerAndReturnsNewArgs) { MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .pointer(absoluteMousePointer) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); // Check that the PointerController updated the position and the pointer is shown. @@ -401,7 +412,7 @@ TEST_F(PointerChoreographerTest, // Add two devices, one unassociated and the other associated with non-default mouse display. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ANOTHER_DISPLAY_ID)}}); auto unassociatedMousePc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, unassociatedMousePc->getDisplayId()); @@ -437,7 +448,8 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForMouseRelativeSource) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -447,7 +459,8 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForMouseRelativeSource) { // Assume that pointer capture is enabled. mChoreographer.notifyInputDevicesChanged( {/*id=*/1, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE_RELATIVE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE_RELATIVE, + ui::ADISPLAY_ID_NONE)}}); mChoreographer.notifyPointerCaptureChanged( NotifyPointerCaptureChangedArgs(/*id=*/2, systemTime(SYSTEM_TIME_MONOTONIC), PointerCaptureRequest(/*window=*/sp<BBinder>::make(), @@ -462,7 +475,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForMouseRelativeSource) { .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10) .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20)) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); // Check that there's no update on the PointerController. @@ -471,7 +484,8 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForMouseRelativeSource) { // Check x-y coordinates, displayId and cursor position are not changed. mTestListener.assertNotifyMotionWasCalled( - AllOf(WithCoords(10, 20), WithRelativeMotion(10, 20), WithDisplayId(ADISPLAY_ID_NONE), + AllOf(WithCoords(10, 20), WithRelativeMotion(10, 20), + WithDisplayId(ui::ADISPLAY_ID_NONE), WithCursorPosition(AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION))); } @@ -480,7 +494,8 @@ TEST_F(PointerChoreographerTest, WhenPointerCaptureEnabledHidesPointer) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); ASSERT_TRUE(pc->isPointerShown()); @@ -499,7 +514,8 @@ TEST_F(PointerChoreographerTest, MultipleMiceConnectionAndRemoval) { // A mouse is connected, and the pointer is shown. mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); @@ -509,15 +525,17 @@ TEST_F(PointerChoreographerTest, MultipleMiceConnectionAndRemoval) { // Add a second mouse is added, the pointer is shown again. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE), - generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), + generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::ADISPLAY_ID_NONE)}}); ASSERT_TRUE(pc->isPointerShown()); // One of the mice is removed, and it does not cause the mouse pointer to fade, because // we have one more mouse connected. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::ADISPLAY_ID_NONE)}}); assertPointerControllerNotRemoved(pc); ASSERT_TRUE(pc->isPointerShown()); @@ -530,7 +548,8 @@ TEST_F(PointerChoreographerTest, UnrelatedChangeDoesNotUnfadePointer) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); @@ -540,7 +559,7 @@ TEST_F(PointerChoreographerTest, UnrelatedChangeDoesNotUnfadePointer) { // Adding a touchscreen device does not unfade the mouse pointer. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, DISPLAY_ID)}}); @@ -557,7 +576,7 @@ TEST_F(PointerChoreographerTest, DisabledMouseConnected) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo mouseDeviceInfo = - generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); + generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); // Disable this mouse device. mouseDeviceInfo.setEnabled(false); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); @@ -570,7 +589,7 @@ TEST_F(PointerChoreographerTest, MouseDeviceDisableLater) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo mouseDeviceInfo = - generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); + generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); @@ -589,14 +608,14 @@ TEST_F(PointerChoreographerTest, MultipleEnabledAndDisabledMiceConnectionAndRemo mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo disabledMouseDeviceInfo = - generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); + generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); disabledMouseDeviceInfo.setEnabled(false); InputDeviceInfo enabledMouseDeviceInfo = - generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); + generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); InputDeviceInfo anotherEnabledMouseDeviceInfo = - generateTestDeviceInfo(THIRD_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE); + generateTestDeviceInfo(THIRD_DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, @@ -1158,7 +1177,7 @@ TEST_F(PointerChoreographerTest, WhenTouchpadIsAddedCreatesPointerController) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); assertPointerControllerCreated(ControllerType::MOUSE); } @@ -1166,7 +1185,7 @@ TEST_F(PointerChoreographerTest, WhenTouchpadIsRemovedRemovesPointerController) mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); // Remove the touchpad. @@ -1207,7 +1226,8 @@ TEST_F(PointerChoreographerTest, SetsDefaultTouchpadViewportForPointerController // For a touchpad event without a target display, default viewport should be set for // the PointerController. mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertViewportSet(DISPLAY_ID); } @@ -1220,7 +1240,7 @@ TEST_F(PointerChoreographerTest, mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto firstDisplayPc = assertPointerControllerCreated(ControllerType::MOUSE); firstDisplayPc->assertViewportSet(DISPLAY_ID); @@ -1238,7 +1258,7 @@ TEST_F(PointerChoreographerTest, TouchpadCallsNotifyPointerDisplayIdChanged) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); @@ -1249,7 +1269,7 @@ TEST_F(PointerChoreographerTest, WhenViewportIsSetLaterTouchpadCallsNotifyPointe mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotNotified(); @@ -1263,12 +1283,12 @@ TEST_F(PointerChoreographerTest, WhenTouchpadIsRemovedCallsNotifyPointerDisplayI mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged({/*id=*/1, {}}); - assertPointerDisplayIdNotified(ADISPLAY_ID_NONE); + assertPointerDisplayIdNotified(ui::ADISPLAY_ID_NONE); assertPointerControllerRemoved(pc); } @@ -1282,11 +1302,11 @@ TEST_F(PointerChoreographerTest, mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto firstDisplayPc = assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); - // Set another viewport as a default mouse display ID. ADISPLAY_ID_NONE will be notified + // Set another viewport as a default mouse display ID. ui::ADISPLAY_ID_NONE will be notified // before a touchpad event. mChoreographer.setDefaultMouseDisplayId(ANOTHER_DISPLAY_ID); assertPointerControllerRemoved(firstDisplayPc); @@ -1301,7 +1321,7 @@ TEST_F(PointerChoreographerTest, TouchpadMovesPointerAndReturnsNewArgs) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -1313,7 +1333,7 @@ TEST_F(PointerChoreographerTest, TouchpadMovesPointerAndReturnsNewArgs) { MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .pointer(TOUCHPAD_POINTER) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); // Check that the PointerController updated the position and the pointer is shown. @@ -1331,7 +1351,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -1345,7 +1365,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(-100).y(0)) .classification(MotionClassification::MULTI_FINGER_SWIPE) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), @@ -1359,7 +1379,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(0).y(0)) .classification(MotionClassification::MULTI_FINGER_SWIPE) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | @@ -1376,7 +1396,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(100).y(0)) .classification(MotionClassification::MULTI_FINGER_SWIPE) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | @@ -1391,7 +1411,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(110).y(10)) .classification(MotionClassification::MULTI_FINGER_SWIPE) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), @@ -1410,7 +1430,7 @@ TEST_F(PointerChoreographerTest, mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE), + ui::ADISPLAY_ID_NONE), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, ANOTHER_DISPLAY_ID)}}); auto unassociatedMousePc = assertPointerControllerCreated(ControllerType::MOUSE); @@ -1449,7 +1469,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForTouchpadSource) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -1466,7 +1486,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForTouchpadSource) { mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHPAD) .pointer(FIRST_TOUCH_POINTER) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); // Check that there's no update on the PointerController. @@ -1475,7 +1495,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForTouchpadSource) { // Check x-y coordinates, displayId and cursor position are not changed. mTestListener.assertNotifyMotionWasCalled( - AllOf(WithCoords(100, 200), WithDisplayId(ADISPLAY_ID_NONE), + AllOf(WithCoords(100, 200), WithDisplayId(ui::ADISPLAY_ID_NONE), WithCursorPosition(AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION))); } @@ -1486,7 +1506,7 @@ TEST_F(PointerChoreographerTest, WhenPointerCaptureEnabledTouchpadHidesPointer) mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); ASSERT_TRUE(pc->isPointerShown()); @@ -1504,7 +1524,8 @@ TEST_F(PointerChoreographerTest, SetsPointerIconForMouse) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertPointerIconNotSet(); @@ -1518,7 +1539,8 @@ TEST_F(PointerChoreographerTest, DoesNotSetMousePointerIconForWrongDisplayId) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertPointerIconNotSet(); @@ -1533,7 +1555,8 @@ TEST_F(PointerChoreographerTest, DoesNotSetPointerIconForWrongDeviceId) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertPointerIconNotSet(); @@ -1548,7 +1571,8 @@ TEST_F(PointerChoreographerTest, SetsCustomPointerIconForMouse) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertCustomPointerIconNotSet(); @@ -1571,7 +1595,7 @@ TEST_F(PointerChoreographerTest, SetsPointerIconForMouseOnTwoDisplays) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ANOTHER_DISPLAY_ID)}}); auto firstMousePc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, firstMousePc->getDisplayId()); @@ -1766,14 +1790,14 @@ TEST_P(StylusTestFixture, SetsPointerIconForMouseAndStylus) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), generateTestDeviceInfo(SECOND_DEVICE_ID, source, DISPLAY_ID)}}); mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.notifyMotion( MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .pointer(MOUSE_POINTER) .deviceId(DEVICE_ID) - .displayId(ADISPLAY_ID_NONE) + .displayId(ui::ADISPLAY_ID_NONE) .build()); auto mousePc = assertPointerControllerCreated(ControllerType::MOUSE); mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, source) @@ -1801,7 +1825,7 @@ TEST_F(PointerChoreographerTest, SetPointerIconVisibilityHidesPointerOnDisplay) mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ANOTHER_DISPLAY_ID)}}); auto firstMousePc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, firstMousePc->getDisplayId()); @@ -1857,7 +1881,8 @@ TEST_F(PointerChoreographerTest, SetPointerIconVisibilityHidesPointerWhenDeviceC // Hide the pointer on the display, and then connect the mouse. mChoreographer.setPointerIconVisibility(DISPLAY_ID, false); mChoreographer.notifyInputDevicesChanged( - {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {/*id=*/0, + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); auto mousePc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, mousePc->getDisplayId()); @@ -1875,7 +1900,7 @@ TEST_F(PointerChoreographerTest, SetPointerIconVisibilityHidesPointerForTouchpad mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ADISPLAY_ID_NONE)}}); + ui::ADISPLAY_ID_NONE)}}); auto touchpadPc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, touchpadPc->getDisplayId()); @@ -1920,7 +1945,7 @@ TEST_F(PointerChoreographerTest, DrawingTabletCanReportMouseEvent) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE)}}); // There should be no controller created when a drawing tablet is connected assertPointerControllerNotCreated(); @@ -1947,7 +1972,7 @@ TEST_F(PointerChoreographerTest, MultipleDrawingTabletsReportMouseEvents) { // First drawing tablet is added mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE)}}); assertPointerControllerNotCreated(); mChoreographer.notifyMotion( @@ -1962,8 +1987,9 @@ TEST_F(PointerChoreographerTest, MultipleDrawingTabletsReportMouseEvents) { // Second drawing tablet is added mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ADISPLAY_ID_NONE), - generateTestDeviceInfo(SECOND_DEVICE_ID, DRAWING_TABLET_SOURCE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE), + generateTestDeviceInfo(SECOND_DEVICE_ID, DRAWING_TABLET_SOURCE, + ui::ADISPLAY_ID_NONE)}}); assertPointerControllerNotRemoved(pc); mChoreographer.notifyMotion( @@ -1976,7 +2002,7 @@ TEST_F(PointerChoreographerTest, MultipleDrawingTabletsReportMouseEvents) { // First drawing tablet is removed mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE)}}); assertPointerControllerNotRemoved(pc); // Second drawing tablet is removed @@ -1991,8 +2017,9 @@ TEST_F(PointerChoreographerTest, MouseAndDrawingTabletReportMouseEvents) { // Mouse and drawing tablet connected mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ADISPLAY_ID_NONE), - generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE), + generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::ADISPLAY_ID_NONE)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); @@ -2007,7 +2034,7 @@ TEST_F(PointerChoreographerTest, MouseAndDrawingTabletReportMouseEvents) { // Remove the mouse device mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE)}}); // The mouse controller should not be removed, because the drawing tablet has produced a // mouse event, so we are treating it as a mouse too. diff --git a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp index 9818176cb0..c273e92de6 100644 --- a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp +++ b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp @@ -15,7 +15,6 @@ */ #include <gtest/gtest.h> -#include <gui/constants.h> #include "../PreferStylusOverTouchBlocker.h" namespace android { @@ -64,8 +63,9 @@ static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, } // Define a valid motion event. - NotifyMotionArgs args(/*id=*/0, eventTime, /*readTime=*/0, deviceId, source, /*displayId=*/0, - POLICY_FLAG_PASS_TO_USER, action, /* actionButton */ 0, + NotifyMotionArgs args(/*id=*/0, eventTime, /*readTime=*/0, deviceId, source, + /*displayId=*/ui::ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER, action, + /* actionButton */ 0, /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, pointerProperties, pointerCoords, /*xPrecision=*/0, /*yPrecision=*/0, @@ -439,7 +439,7 @@ TEST_F(PreferStylusOverTouchTest, MixedStylusAndTouchDeviceIsCanceledAtFirst) { InputDeviceInfo stylusDevice; stylusDevice.initialize(STYLUS_DEVICE_ID, /*generation=*/1, /*controllerNumber=*/1, /*identifier=*/{}, "stylus device", /*external=*/false, - /*hasMic=*/false, ADISPLAY_ID_NONE); + /*hasMic=*/false, ui::ADISPLAY_ID_NONE); notifyInputDevicesChanged({stylusDevice}); // The touchscreen device was removed, so we no longer remember anything about it. We should // again start blocking touch events from it. diff --git a/services/inputflinger/tests/TestEventMatchers.h b/services/inputflinger/tests/TestEventMatchers.h index a3e8eafea3..65fb9c6659 100644 --- a/services/inputflinger/tests/TestEventMatchers.h +++ b/services/inputflinger/tests/TestEventMatchers.h @@ -145,7 +145,7 @@ inline WithMotionActionMatcher WithMotionAction(int32_t action) { class WithDisplayIdMatcher { public: using is_gtest_matcher = void; - explicit WithDisplayIdMatcher(int32_t displayId) : mDisplayId(displayId) {} + explicit WithDisplayIdMatcher(ui::LogicalDisplayId displayId) : mDisplayId(displayId) {} bool MatchAndExplain(const NotifyMotionArgs& args, std::ostream*) const { return mDisplayId == args.displayId; @@ -164,10 +164,10 @@ public: void DescribeNegationTo(std::ostream* os) const { *os << "wrong display id"; } private: - const int32_t mDisplayId; + const ui::LogicalDisplayId mDisplayId; }; -inline WithDisplayIdMatcher WithDisplayId(int32_t displayId) { +inline WithDisplayIdMatcher WithDisplayId(ui::LogicalDisplayId displayId) { return WithDisplayIdMatcher(displayId); } diff --git a/services/inputflinger/tests/TouchpadInputMapper_test.cpp b/services/inputflinger/tests/TouchpadInputMapper_test.cpp index 402654c7ac..245497ca4c 100644 --- a/services/inputflinger/tests/TouchpadInputMapper_test.cpp +++ b/services/inputflinger/tests/TouchpadInputMapper_test.cpp @@ -37,7 +37,7 @@ constexpr auto BUTTON_RELEASE = AMOTION_EVENT_ACTION_BUTTON_RELEASE; constexpr auto HOVER_MOVE = AMOTION_EVENT_ACTION_HOVER_MOVE; constexpr auto HOVER_ENTER = AMOTION_EVENT_ACTION_HOVER_ENTER; constexpr auto HOVER_EXIT = AMOTION_EVENT_ACTION_HOVER_EXIT; -constexpr int32_t DISPLAY_ID = 0; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; constexpr int32_t DISPLAY_WIDTH = 480; constexpr int32_t DISPLAY_HEIGHT = 800; constexpr std::optional<uint8_t> NO_PORT = std::nullopt; // no physical port is specified diff --git a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp index 78f7291243..80430d1d22 100644 --- a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp +++ b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp @@ -18,7 +18,6 @@ #include <android-base/silent_death_test.h> #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <gui/constants.h> #include <linux/input.h> #include <thread> #include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h" @@ -89,7 +88,8 @@ static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, // Define a valid motion event. NotifyMotionArgs args(/*id=*/0, eventTime, /*readTime=*/0, DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, - /*displayId=*/0, POLICY_FLAG_PASS_TO_USER, action, /*actionButton=*/0, + /*displayId=*/ui::ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER, action, + /*actionButton=*/0, /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, pointerProperties, pointerCoords, /*xPrecision=*/0, /*yPrecision=*/0, @@ -104,7 +104,7 @@ static InputDeviceInfo generateTestDeviceInfo() { auto info = InputDeviceInfo(); info.initialize(DEVICE_ID, /*generation=*/1, /*controllerNumber=*/1, identifier, "alias", - /*isExternal=*/false, /*hasMic=*/false, ADISPLAY_ID_NONE); + /*isExternal=*/false, /*hasMic=*/false, ui::ADISPLAY_ID_NONE); info.addSource(AINPUT_SOURCE_TOUCHSCREEN); info.addMotionRange(AMOTION_EVENT_AXIS_X, AINPUT_SOURCE_TOUCHSCREEN, 0, 1599, /*flat=*/0, /*fuzz=*/0, X_RESOLUTION); @@ -434,7 +434,7 @@ TEST_F(UnwantedInteractionBlockerTest, ConfigurationChangedIsPassedToNextListene TEST_F(UnwantedInteractionBlockerTest, KeyIsPassedToNextListener) { // Create a basic key event and send to blocker NotifyKeyArgs args(/*sequenceNum=*/1, /*eventTime=*/2, /*readTime=*/21, /*deviceId=*/3, - AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_DEFAULT, /*policyFlags=*/0, + AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_DEFAULT, /*policyFlags=*/0, AKEY_EVENT_ACTION_DOWN, /*flags=*/4, AKEYCODE_HOME, /*scanCode=*/5, AMETA_NONE, /*downTime=*/6); diff --git a/services/inputflinger/tests/fuzzers/FuzzedInputStream.h b/services/inputflinger/tests/fuzzers/FuzzedInputStream.h index 885820fafb..812969bb33 100644 --- a/services/inputflinger/tests/fuzzers/FuzzedInputStream.h +++ b/services/inputflinger/tests/fuzzers/FuzzedInputStream.h @@ -178,7 +178,7 @@ NotifyMotionArgs generateFuzzedMotionArgs(IdGenerator& idGenerator, FuzzedDataPr pointerCoords.push_back(coords); } - const int32_t displayId = fdp.ConsumeIntegralInRange<int32_t>(0, maxDisplays - 1); + const ui::LogicalDisplayId displayId{fdp.ConsumeIntegralInRange<int32_t>(0, maxDisplays - 1)}; const int32_t deviceId = fdp.ConsumeIntegralInRange<int32_t>(0, MAX_RANDOM_DEVICES - 1); // Current time +- 5 seconds diff --git a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp index deb811d1ca..0446d76218 100644 --- a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp @@ -54,7 +54,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) { mClassifier->notifyKey({/*sequenceNum=*/fdp.ConsumeIntegral<int32_t>(), eventTime, readTime, /*deviceId=*/fdp.ConsumeIntegral<int32_t>(), - AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_DEFAULT, + AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_DEFAULT, /*policyFlags=*/fdp.ConsumeIntegral<uint32_t>(), AKEY_EVENT_ACTION_DOWN, /*flags=*/fdp.ConsumeIntegral<int32_t>(), AKEYCODE_HOME, diff --git a/services/inputflinger/tests/fuzzers/InputDispatcherFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputDispatcherFuzzer.cpp index 7335fb7500..79a5ff6e5f 100644 --- a/services/inputflinger/tests/fuzzers/InputDispatcherFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/InputDispatcherFuzzer.cpp @@ -90,7 +90,7 @@ void scrambleWindow(FuzzedDataProvider& fdp, FakeWindowHandle& window) { sp<FakeWindowHandle> generateFuzzedWindow(FuzzedDataProvider& fdp, std::unique_ptr<InputDispatcher>& dispatcher, - int32_t displayId) { + ui::LogicalDisplayId displayId) { static size_t windowNumber = 0; std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); std::string windowName = android::base::StringPrintf("Win") + std::to_string(windowNumber++); @@ -101,10 +101,11 @@ sp<FakeWindowHandle> generateFuzzedWindow(FuzzedDataProvider& fdp, return window; } -void randomizeWindows( - std::unordered_map<int32_t, std::vector<sp<FakeWindowHandle>>>& windowsPerDisplay, - FuzzedDataProvider& fdp, std::unique_ptr<InputDispatcher>& dispatcher) { - const int32_t displayId = fdp.ConsumeIntegralInRange<int32_t>(0, MAX_RANDOM_DISPLAYS - 1); +void randomizeWindows(std::unordered_map<ui::LogicalDisplayId, std::vector<sp<FakeWindowHandle>>>& + windowsPerDisplay, + FuzzedDataProvider& fdp, std::unique_ptr<InputDispatcher>& dispatcher) { + const ui::LogicalDisplayId displayId{ + fdp.ConsumeIntegralInRange<int32_t>(0, MAX_RANDOM_DISPLAYS - 1)}; std::vector<sp<FakeWindowHandle>>& windows = windowsPerDisplay[displayId]; fdp.PickValueInArray<std::function<void()>>({ @@ -148,7 +149,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { // Start InputDispatcher thread dispatcher->start(); - std::unordered_map<int32_t, std::vector<sp<FakeWindowHandle>>> windowsPerDisplay; + std::unordered_map<ui::LogicalDisplayId, std::vector<sp<FakeWindowHandle>>> windowsPerDisplay; // Randomly invoke InputDispatcher api's until randomness is exhausted. while (fdp.remaining_bytes() > 0) { diff --git a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp index 9223287114..34ea54ca4b 100644 --- a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp @@ -119,7 +119,7 @@ public: return reader->getSensors(deviceId); } - bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) { + bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) { return reader->canDispatchToDisplay(deviceId, displayId); } @@ -241,7 +241,8 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { }, [&]() -> void { reader->canDispatchToDisplay(fdp->ConsumeIntegral<int32_t>(), - fdp->ConsumeIntegral<int32_t>()); + ui::LogicalDisplayId{ + fdp->ConsumeIntegral<int32_t>()}); }, [&]() -> void { reader->getKeyCodeForKeyLocation(fdp->ConsumeIntegral<int32_t>(), diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h index e020ca9d62..25f2f2ec76 100644 --- a/services/inputflinger/tests/fuzzers/MapperHelpers.h +++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h @@ -285,7 +285,7 @@ public: void notifyStylusGestureStarted(int32_t, nsecs_t) {} bool isInputMethodConnectionActive() override { return mFdp->ConsumeBool(); } std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay( - int32_t associatedDisplayId) override { + ui::LogicalDisplayId associatedDisplayId) override { return {}; } }; diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 45ab7ddc4d..3bf0eaa0f1 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -137,7 +137,7 @@ void DisplayDevice::setDisplayName(const std::string& displayName) { auto DisplayDevice::getFrontEndInfo() const -> frontend::DisplayInfo { gui::DisplayInfo info; - info.displayId = getLayerStack().id; + info.displayId = ui::LogicalDisplayId{static_cast<int32_t>(getLayerStack().id)}; // The physical orientation is set when the orientation of the display panel is // different than the default orientation of the device. Other services like diff --git a/services/surfaceflinger/FrontEnd/DisplayInfo.h b/services/surfaceflinger/FrontEnd/DisplayInfo.h index 6502f36f70..ea51e92e7b 100644 --- a/services/surfaceflinger/FrontEnd/DisplayInfo.h +++ b/services/surfaceflinger/FrontEnd/DisplayInfo.h @@ -21,6 +21,7 @@ #include <gui/DisplayInfo.h> #include <ui/DisplayMap.h> #include <ui/LayerStack.h> +#include <ui/LogicalDisplayId.h> #include <ui/Transform.h> namespace android::surfaceflinger::frontend { diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp index 2ff0facdba..e40c79cf62 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp @@ -1044,7 +1044,8 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot, snapshot.touchCropId = requested.touchCropId; snapshot.inputInfo.id = static_cast<int32_t>(snapshot.uniqueSequence); - snapshot.inputInfo.displayId = static_cast<int32_t>(snapshot.outputFilter.layerStack.id); + snapshot.inputInfo.displayId = + ui::LogicalDisplayId{static_cast<int32_t>(snapshot.outputFilter.layerStack.id)}; snapshot.inputInfo.touchOcclusionMode = requested.hasInputInfo() ? requested.windowInfoHandle->getInfo()->touchOcclusionMode : parentSnapshot.inputInfo.touchOcclusionMode; diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 0137a7bc50..363b35c4f3 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -90,6 +90,10 @@ constexpr int kDumpTableRowLength = 159; const ui::Transform kIdentityTransform; +ui::LogicalDisplayId toLogicalDisplayId(const ui::LayerStack& layerStack) { + return ui::LogicalDisplayId{static_cast<int32_t>(layerStack.id)}; +} + bool assignTransform(ui::Transform* dst, ui::Transform& from) { if (*dst == from) { return false; @@ -2465,7 +2469,7 @@ WindowInfo Layer::fillInputInfo(const InputDisplayArgs& displayArgs) { mDrawingState.inputInfo.ownerUid = gui::Uid{mOwnerUid}; mDrawingState.inputInfo.ownerPid = gui::Pid{mOwnerPid}; mDrawingState.inputInfo.inputConfig |= WindowInfo::InputConfig::NO_INPUT_CHANNEL; - mDrawingState.inputInfo.displayId = getLayerStack().id; + mDrawingState.inputInfo.displayId = toLogicalDisplayId(getLayerStack()); } const ui::Transform& displayTransform = @@ -2473,7 +2477,7 @@ WindowInfo Layer::fillInputInfo(const InputDisplayArgs& displayArgs) { WindowInfo info = mDrawingState.inputInfo; info.id = sequence; - info.displayId = getLayerStack().id; + info.displayId = toLogicalDisplayId(getLayerStack()); fillInputFrameInfo(info, displayTransform); diff --git a/services/surfaceflinger/LayerProtoHelper.cpp b/services/surfaceflinger/LayerProtoHelper.cpp index 513c943f61..753886ad24 100644 --- a/services/surfaceflinger/LayerProtoHelper.cpp +++ b/services/surfaceflinger/LayerProtoHelper.cpp @@ -465,7 +465,7 @@ LayerProtoHelper::writeDisplayInfoToProto(const frontend::DisplayInfos& displayI displays.Reserve(displayInfos.size()); for (const auto& [layerStack, displayInfo] : displayInfos) { auto displayProto = displays.Add(); - displayProto->set_id(displayInfo.info.displayId); + displayProto->set_id(displayInfo.info.displayId.val()); displayProto->set_layer_stack(layerStack.id); displayProto->mutable_size()->set_w(displayInfo.info.logicalWidth); displayProto->mutable_size()->set_h(displayInfo.info.logicalHeight); diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp index 2dc89b55ba..b3e9fab261 100644 --- a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp +++ b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp @@ -566,7 +566,7 @@ perfetto::protos::DisplayInfo TransactionProtoParser::toProto( const frontend::DisplayInfo& displayInfo, uint32_t layerStack) { perfetto::protos::DisplayInfo proto; proto.set_layer_stack(layerStack); - proto.set_display_id(displayInfo.info.displayId); + proto.set_display_id(displayInfo.info.displayId.val()); proto.set_logical_width(displayInfo.info.logicalWidth); proto.set_logical_height(displayInfo.info.logicalHeight); asProto(proto.mutable_transform_inverse(), displayInfo.info.transform); @@ -588,7 +588,7 @@ void fromProto2(ui::Transform& outTransform, const perfetto::protos::Transform& frontend::DisplayInfo TransactionProtoParser::fromProto( const perfetto::protos::DisplayInfo& proto) { frontend::DisplayInfo displayInfo; - displayInfo.info.displayId = proto.display_id(); + displayInfo.info.displayId = ui::LogicalDisplayId{proto.display_id()}; displayInfo.info.logicalWidth = proto.logical_width(); displayInfo.info.logicalHeight = proto.logical_height(); fromProto2(displayInfo.info.transform, proto.transform_inverse()); diff --git a/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp b/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp index cbb597af69..af0233063e 100644 --- a/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp +++ b/services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp @@ -106,7 +106,7 @@ TEST(TransactionProtoParserTest, parse) { TEST(TransactionProtoParserTest, parseDisplayInfo) { frontend::DisplayInfo d1; - d1.info.displayId = 42; + d1.info.displayId = ui::LogicalDisplayId{42}; d1.info.logicalWidth = 43; d1.info.logicalHeight = 44; d1.info.transform.set(1, 2, 3, 4); |