From e4ef87f02e22a40daafe508e98d9aa8e061fc5ff Mon Sep 17 00:00:00 2001 From: Melody Hsu Date: Tue, 26 Mar 2024 23:54:45 +0000 Subject: Track the last release fence per layer stack Merging fences prior to calling CompositionEngine#present results in occassional missed frames in Surfaceflinger. Merging fences here was originally needed to relieve memory pressure. Instead, we can track each layer stack's future release fence with a map between a layer stack and its last fence, as it can be assumed that multiple fences for the same layer stack can be be dropped. Fixes: b/330841053 Test: SurfaceFlinger_test Test: presubmit Change-Id: I7ca3a226ff77bc31d93fdb4708c3e9089f423803 --- libs/ui/include/ui/LayerStack.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libs/ui') diff --git a/libs/ui/include/ui/LayerStack.h b/libs/ui/include/ui/LayerStack.h index d6ffeb7fad..f4c8ba250e 100644 --- a/libs/ui/include/ui/LayerStack.h +++ b/libs/ui/include/ui/LayerStack.h @@ -55,6 +55,10 @@ inline bool operator>(LayerStack lhs, LayerStack rhs) { return lhs.id > rhs.id; } +inline bool operator<(LayerStack lhs, LayerStack rhs) { + return lhs.id < rhs.id; +} + // A LayerFilter determines if a layer is included for output to a display. struct LayerFilter { LayerStack layerStack; -- cgit v1.2.3-59-g8ed1b From 254ef492808de1875f6be7e4a5c6732264d042b3 Mon Sep 17 00:00:00 2001 From: Sally Qi Date: Mon, 8 Apr 2024 15:01:28 -0700 Subject: Dump OverlayProperties Bug: 333403150 Test: dump SF Change-Id: I754c4de3246b440de0cf3d202a75eeffa347fd61 --- libs/ui/DebugUtils.cpp | 113 +++++++++++---------- libs/ui/include/ui/DebugUtils.h | 3 + .../CompositionEngine/tests/MockHWComposer.h | 1 + .../surfaceflinger/DisplayHardware/HWComposer.cpp | 39 ++++++- .../surfaceflinger/DisplayHardware/HWComposer.h | 3 + 5 files changed, 106 insertions(+), 53 deletions(-) (limited to 'libs/ui') diff --git a/libs/ui/DebugUtils.cpp b/libs/ui/DebugUtils.cpp index 8675f14d43..bee58e548a 100644 --- a/libs/ui/DebugUtils.cpp +++ b/libs/ui/DebugUtils.cpp @@ -22,14 +22,12 @@ #include #include -using android::base::StringAppendF; using android::base::StringPrintf; using android::ui::ColorMode; using android::ui::RenderIntent; -std::string decodeStandard(android_dataspace dataspace) { - const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); - switch (dataspaceSelect) { +std::string decodeStandardOnly(uint32_t dataspaceStandard) { + switch (dataspaceStandard) { case HAL_DATASPACE_STANDARD_BT709: return std::string("BT709"); @@ -62,63 +60,44 @@ std::string decodeStandard(android_dataspace dataspace) { case HAL_DATASPACE_STANDARD_ADOBE_RGB: return std::string("AdobeRGB"); - - case 0: - switch (dataspace & 0xffff) { - case HAL_DATASPACE_JFIF: - return std::string("(deprecated) JFIF (BT601_625)"); - - case HAL_DATASPACE_BT601_625: - return std::string("(deprecated) BT601_625"); - - case HAL_DATASPACE_BT601_525: - return std::string("(deprecated) BT601_525"); - - case HAL_DATASPACE_SRGB_LINEAR: - case HAL_DATASPACE_SRGB: - return std::string("(deprecated) sRGB"); - - case HAL_DATASPACE_BT709: - return std::string("(deprecated) BT709"); - - case HAL_DATASPACE_ARBITRARY: - return std::string("ARBITRARY"); - - case HAL_DATASPACE_UNKNOWN: - // Fallthrough - default: - return StringPrintf("Unknown deprecated dataspace code %d", dataspace); - } } - return StringPrintf("Unknown dataspace code %d", dataspaceSelect); + return StringPrintf("Unknown dataspace code %d", dataspaceStandard); } -std::string decodeTransfer(android_dataspace dataspace) { - const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); - if (dataspaceSelect == 0) { +std::string decodeStandard(android_dataspace dataspace) { + const uint32_t dataspaceStandard = (dataspace & HAL_DATASPACE_STANDARD_MASK); + if (dataspaceStandard == 0) { switch (dataspace & 0xffff) { case HAL_DATASPACE_JFIF: + return std::string("(deprecated) JFIF (BT601_625)"); + case HAL_DATASPACE_BT601_625: + return std::string("(deprecated) BT601_625"); + case HAL_DATASPACE_BT601_525: - case HAL_DATASPACE_BT709: - return std::string("SMPTE_170M"); + return std::string("(deprecated) BT601_525"); case HAL_DATASPACE_SRGB_LINEAR: - case HAL_DATASPACE_ARBITRARY: - return std::string("Linear"); - case HAL_DATASPACE_SRGB: - return std::string("sRGB"); + return std::string("(deprecated) sRGB"); + + case HAL_DATASPACE_BT709: + return std::string("(deprecated) BT709"); + + case HAL_DATASPACE_ARBITRARY: + return std::string("ARBITRARY"); case HAL_DATASPACE_UNKNOWN: // Fallthrough default: - return std::string(""); + return StringPrintf("Unknown deprecated dataspace code %d", dataspace); } } + return decodeStandardOnly(dataspaceStandard); +} - const uint32_t dataspaceTransfer = (dataspace & HAL_DATASPACE_TRANSFER_MASK); +std::string decodeTransferOnly(uint32_t dataspaceTransfer) { switch (dataspaceTransfer) { case HAL_DATASPACE_TRANSFER_UNSPECIFIED: return std::string("Unspecified"); @@ -151,29 +130,35 @@ std::string decodeTransfer(android_dataspace dataspace) { return StringPrintf("Unknown dataspace transfer %d", dataspaceTransfer); } -std::string decodeRange(android_dataspace dataspace) { +std::string decodeTransfer(android_dataspace dataspace) { const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); if (dataspaceSelect == 0) { switch (dataspace & 0xffff) { case HAL_DATASPACE_JFIF: - case HAL_DATASPACE_SRGB_LINEAR: - case HAL_DATASPACE_SRGB: - return std::string("Full range"); - case HAL_DATASPACE_BT601_625: case HAL_DATASPACE_BT601_525: case HAL_DATASPACE_BT709: - return std::string("Limited range"); + return std::string("SMPTE_170M"); + case HAL_DATASPACE_SRGB_LINEAR: case HAL_DATASPACE_ARBITRARY: + return std::string("Linear"); + + case HAL_DATASPACE_SRGB: + return std::string("sRGB"); + case HAL_DATASPACE_UNKNOWN: // Fallthrough default: - return std::string("unspecified range"); + return std::string(""); } } - const uint32_t dataspaceRange = (dataspace & HAL_DATASPACE_RANGE_MASK); + const uint32_t dataspaceTransfer = (dataspace & HAL_DATASPACE_TRANSFER_MASK); + return decodeTransferOnly(dataspaceTransfer); +} + +std::string decodeRangeOnly(uint32_t dataspaceRange) { switch (dataspaceRange) { case HAL_DATASPACE_RANGE_UNSPECIFIED: return std::string("Range Unspecified"); @@ -191,6 +176,32 @@ std::string decodeRange(android_dataspace dataspace) { return StringPrintf("Unknown dataspace range %d", dataspaceRange); } +std::string decodeRange(android_dataspace dataspace) { + const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); + if (dataspaceSelect == 0) { + switch (dataspace & 0xffff) { + case HAL_DATASPACE_JFIF: + case HAL_DATASPACE_SRGB_LINEAR: + case HAL_DATASPACE_SRGB: + return std::string("Full range"); + + case HAL_DATASPACE_BT601_625: + case HAL_DATASPACE_BT601_525: + case HAL_DATASPACE_BT709: + return std::string("Limited range"); + + case HAL_DATASPACE_ARBITRARY: + case HAL_DATASPACE_UNKNOWN: + // Fallthrough + default: + return std::string("unspecified range"); + } + } + + const uint32_t dataspaceRange = (dataspace & HAL_DATASPACE_RANGE_MASK); + return decodeRangeOnly(dataspaceRange); +} + std::string dataspaceDetails(android_dataspace dataspace) { if (dataspace == 0) { return "Default"; diff --git a/libs/ui/include/ui/DebugUtils.h b/libs/ui/include/ui/DebugUtils.h index 18cd487b8f..7c4ac426c1 100644 --- a/libs/ui/include/ui/DebugUtils.h +++ b/libs/ui/include/ui/DebugUtils.h @@ -27,8 +27,11 @@ struct DeviceProductInfo; } std::string decodeStandard(android_dataspace dataspace); +std::string decodeStandardOnly(uint32_t dataspaceStandard); std::string decodeTransfer(android_dataspace dataspace); +std::string decodeTransferOnly(uint32_t dataspaceTransfer); std::string decodeRange(android_dataspace dataspace); +std::string decodeRangeOnly(uint32_t dataspaceRange); std::string dataspaceDetails(android_dataspace dataspace); std::string decodeColorMode(android::ui::ColorMode colormode); std::string decodeColorTransform(android_color_transform colorTransform); diff --git a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h index 575a30e522..46121174e1 100644 --- a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h +++ b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h @@ -126,6 +126,7 @@ public: const std::unordered_map&()); MOCK_CONST_METHOD1(dump, void(std::string&)); + MOCK_CONST_METHOD1(dumpOverlayProperties, void(std::string&)); MOCK_CONST_METHOD0(getComposer, android::Hwc2::Composer*()); MOCK_METHOD(hal::HWDisplayId, getPrimaryHwcDisplayId, (), (const, override)); diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 776bcd3e32..21d49f88a5 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -77,9 +77,7 @@ using aidl::android::hardware::graphics::common::HdrConversionCapability; using aidl::android::hardware::graphics::common::HdrConversionStrategy; using aidl::android::hardware::graphics::composer3::Capability; using aidl::android::hardware::graphics::composer3::DisplayCapability; -using aidl::android::hardware::graphics::composer3::VrrConfig; using namespace std::string_literals; -namespace hal = android::hardware::graphics::composer::hal; namespace android { @@ -964,8 +962,45 @@ const std::unordered_map& HWComposer::getSupportedLayerGeneri return mSupportedLayerGenericMetadata; } +void HWComposer::dumpOverlayProperties(std::string& result) const { + // dump overlay properties + result.append("OverlayProperties:\n"); + base::StringAppendF(&result, "supportMixedColorSpaces: %d\n", + mOverlayProperties.supportMixedColorSpaces); + base::StringAppendF(&result, "SupportedBufferCombinations(%zu entries)\n", + mOverlayProperties.combinations.size()); + for (const auto& combination : mOverlayProperties.combinations) { + result.append(" pixelFormats=\n"); + for (const auto& pixelFormat : combination.pixelFormats) { + base::StringAppendF(&result, " %s (%d)\n", + decodePixelFormat(static_cast(pixelFormat)).c_str(), + static_cast(pixelFormat)); + } + result.append(" standards=\n"); + for (const auto& standard : combination.standards) { + base::StringAppendF(&result, " %s (%d)\n", + decodeStandard(static_cast(standard)).c_str(), + static_cast(standard)); + } + result.append(" transfers=\n"); + for (const auto& transfer : combination.transfers) { + base::StringAppendF(&result, " %s (%d)\n", + decodeTransferOnly(static_cast(transfer)).c_str(), + static_cast(transfer)); + } + result.append(" ranges=\n"); + for (const auto& range : combination.ranges) { + base::StringAppendF(&result, " %s (%d)\n", + decodeRangeOnly(static_cast(range)).c_str(), + static_cast(range)); + } + result.append("\n"); + } +} + void HWComposer::dump(std::string& result) const { result.append(mComposer->dumpDebugInfo()); + dumpOverlayProperties(result); } std::optional HWComposer::toPhysicalDisplayId( diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index 7fbbb1a672..bc32cda059 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -269,6 +269,8 @@ public: virtual void dump(std::string& out) const = 0; + virtual void dumpOverlayProperties(std::string& out) const = 0; + virtual Hwc2::Composer* getComposer() const = 0; // Returns the first display connected at boot. Its connection via HWComposer::onHotplug, @@ -468,6 +470,7 @@ public: // for debugging ---------------------------------------------------------- void dump(std::string& out) const override; + void dumpOverlayProperties(std::string& out) const override; Hwc2::Composer* getComposer() const override { return mComposer.get(); } -- cgit v1.2.3-59-g8ed1b From 5b850a7d99c87cfbaea827c7e04105adcfcae55f Mon Sep 17 00:00:00 2001 From: Jerome Gaillard Date: Wed, 10 Apr 2024 18:35:57 +0100 Subject: Delete unneeded filegroup The libui_host_common file group was created to be able to include certain files from libui into a host build without having to make the entire library host compatible. This is exactly what libui-types has done, so that can be used instead of this filegroup. Bug: 322360037 Test: build libhostgraphics Change-Id: I6b347980d393b48afddfc97058ab189811e2e640 --- libs/ui/Android.bp | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'libs/ui') diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 312a1e68b3..12230f99d2 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -277,13 +277,3 @@ subdirs = [ "tests", "tools", ] - -filegroup { - name: "libui_host_common", - srcs: [ - "Rect.cpp", - "Region.cpp", - "PixelFormat.cpp", - "Transform.cpp", - ], -} -- cgit v1.2.3-59-g8ed1b From db164ff4e1caccc86654a39ac0def4c51e94d1c0 Mon Sep 17 00:00:00 2001 From: John Reck Date: Wed, 3 Apr 2024 16:59:28 -0400 Subject: Add allocator-v2 extended options to BufferQueue Bug: 268382490 Test: libgui_test Change-Id: If43b31eede87cddfcbfe4b24b53c1bafb453ebf2 --- libs/gui/BufferQueueProducer.cpp | 122 ++++++++++++++++++++++++-- libs/gui/IGraphicBufferProducer.cpp | 49 +++++++++++ libs/gui/Surface.cpp | 32 +++++++ libs/gui/include/gui/AdditionalOptions.h | 32 +++++++ libs/gui/include/gui/BufferQueueCore.h | 11 +++ libs/gui/include/gui/BufferQueueProducer.h | 5 ++ libs/gui/include/gui/BufferSlot.h | 7 ++ libs/gui/include/gui/IGraphicBufferProducer.h | 5 ++ libs/gui/include/gui/Surface.h | 11 +++ libs/gui/libgui_flags.aconfig | 8 ++ libs/gui/tests/Android.bp | 1 + libs/gui/tests/BufferQueue_test.cpp | 57 ++++++++++++ libs/nativewindow/include/system/window.h | 23 +++++ libs/ui/GraphicBufferAllocator.cpp | 4 + libs/ui/include/ui/Gralloc.h | 2 + libs/ui/include/ui/Gralloc5.h | 2 + libs/ui/include/ui/GraphicBufferAllocator.h | 2 + 17 files changed, 365 insertions(+), 8 deletions(-) create mode 100644 libs/gui/include/gui/AdditionalOptions.h (limited to 'libs/ui') diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index fb69fda32d..69345a971e 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -423,6 +423,11 @@ status_t BufferQueueProducer::dequeueBuffer(int* outSlot, sp* ou sp listener; bool callOnFrameDequeued = false; uint64_t bufferId = 0; // Only used if callOnFrameDequeued == true +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + std::vector allocOptions; + uint32_t allocOptionsGenId = 0; +#endif + { // Autolock scope std::unique_lock lock(mCore->mMutex); @@ -486,11 +491,17 @@ status_t BufferQueueProducer::dequeueBuffer(int* outSlot, sp* ou } const sp& buffer(mSlots[found].mGraphicBuffer); - if (mCore->mSharedBufferSlot == found && - buffer->needsReallocation(width, height, format, BQ_LAYER_COUNT, usage)) { - BQ_LOGE("dequeueBuffer: cannot re-allocate a shared" - "buffer"); + bool needsReallocation = buffer == nullptr || + buffer->needsReallocation(width, height, format, BQ_LAYER_COUNT, usage); + +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + needsReallocation |= mSlots[found].mAdditionalOptionsGenerationId != + mCore->mAdditionalOptionsGenerationId; +#endif + + if (mCore->mSharedBufferSlot == found && needsReallocation) { + BQ_LOGE("dequeueBuffer: cannot re-allocate a shared buffer"); return BAD_VALUE; } @@ -505,9 +516,7 @@ status_t BufferQueueProducer::dequeueBuffer(int* outSlot, sp* ou mSlots[found].mBufferState.dequeue(); - if ((buffer == nullptr) || - buffer->needsReallocation(width, height, format, BQ_LAYER_COUNT, usage)) - { + if (needsReallocation) { if (CC_UNLIKELY(ATRACE_ENABLED())) { if (buffer == nullptr) { ATRACE_FORMAT_INSTANT("%s buffer reallocation: null", mConsumerName.c_str()); @@ -530,6 +539,10 @@ status_t BufferQueueProducer::dequeueBuffer(int* outSlot, sp* ou mSlots[found].mFence = Fence::NO_FENCE; mCore->mBufferAge = 0; mCore->mIsAllocating = true; +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + allocOptions = mCore->mAdditionalOptions; + allocOptionsGenId = mCore->mAdditionalOptionsGenerationId; +#endif returnFlags |= BUFFER_NEEDS_REALLOCATION; } else { @@ -575,9 +588,29 @@ status_t BufferQueueProducer::dequeueBuffer(int* outSlot, sp* ou if (returnFlags & BUFFER_NEEDS_REALLOCATION) { BQ_LOGV("dequeueBuffer: allocating a new buffer for slot %d", *outSlot); + +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + std::vector tempOptions; + tempOptions.reserve(allocOptions.size()); + for (const auto& it : allocOptions) { + tempOptions.emplace_back(it.name.c_str(), it.value); + } + const GraphicBufferAllocator::AllocationRequest allocRequest = { + .importBuffer = true, + .width = width, + .height = height, + .format = format, + .layerCount = BQ_LAYER_COUNT, + .usage = usage, + .requestorName = {mConsumerName.c_str(), mConsumerName.size()}, + .extras = std::move(tempOptions), + }; + sp graphicBuffer = new GraphicBuffer(allocRequest); +#else sp graphicBuffer = new GraphicBuffer(width, height, format, BQ_LAYER_COUNT, usage, {mConsumerName.c_str(), mConsumerName.size()}); +#endif status_t error = graphicBuffer->initCheck(); @@ -587,6 +620,9 @@ status_t BufferQueueProducer::dequeueBuffer(int* outSlot, sp* ou if (error == NO_ERROR && !mCore->mIsAbandoned) { graphicBuffer->setGenerationNumber(mCore->mGenerationNumber); mSlots[*outSlot].mGraphicBuffer = graphicBuffer; +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + mSlots[*outSlot].mAdditionalOptionsGenerationId = allocOptionsGenId; +#endif callOnFrameDequeued = true; bufferId = mSlots[*outSlot].mGraphicBuffer->getId(); } @@ -1342,6 +1378,9 @@ status_t BufferQueueProducer::connect(const sp& listener, } mCore->mAllowAllocation = true; +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + mCore->mAdditionalOptions.clear(); +#endif VALIDATE_CONSISTENCY(); return status; } @@ -1410,6 +1449,9 @@ status_t BufferQueueProducer::disconnect(int api, DisconnectMode mode) { mCore->mSidebandStream.clear(); mCore->mDequeueCondition.notify_all(); mCore->mAutoPrerotation = false; +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + mCore->mAdditionalOptions.clear(); +#endif listener = mCore->mConsumerListener; } else if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) { BQ_LOGE("disconnect: not connected (req=%d)", api); @@ -1462,6 +1504,10 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, PixelFormat allocFormat = PIXEL_FORMAT_UNKNOWN; uint64_t allocUsage = 0; std::string allocName; +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + std::vector allocOptions; + uint32_t allocOptionsGenId = 0; +#endif { // Autolock scope std::unique_lock lock(mCore->mMutex); mCore->waitWhileAllocatingLocked(lock); @@ -1490,14 +1536,42 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, allocUsage = usage | mCore->mConsumerUsageBits; allocName.assign(mCore->mConsumerName.c_str(), mCore->mConsumerName.size()); +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + allocOptions = mCore->mAdditionalOptions; + allocOptionsGenId = mCore->mAdditionalOptionsGenerationId; +#endif + mCore->mIsAllocating = true; + } // Autolock scope +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + std::vector tempOptions; + tempOptions.reserve(allocOptions.size()); + for (const auto& it : allocOptions) { + tempOptions.emplace_back(it.name.c_str(), it.value); + } + const GraphicBufferAllocator::AllocationRequest allocRequest = { + .importBuffer = true, + .width = allocWidth, + .height = allocHeight, + .format = allocFormat, + .layerCount = BQ_LAYER_COUNT, + .usage = allocUsage, + .requestorName = allocName, + .extras = std::move(tempOptions), + }; +#endif + Vector> buffers; for (size_t i = 0; i < newBufferCount; ++i) { +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + sp graphicBuffer = new GraphicBuffer(allocRequest); +#else sp graphicBuffer = new GraphicBuffer( allocWidth, allocHeight, allocFormat, BQ_LAYER_COUNT, allocUsage, allocName); +#endif status_t result = graphicBuffer->initCheck(); @@ -1524,8 +1598,12 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, PixelFormat checkFormat = format != 0 ? format : mCore->mDefaultBufferFormat; uint64_t checkUsage = usage | mCore->mConsumerUsageBits; + bool allocOptionsChanged = false; +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + allocOptionsChanged = allocOptionsGenId != mCore->mAdditionalOptionsGenerationId; +#endif if (checkWidth != allocWidth || checkHeight != allocHeight || - checkFormat != allocFormat || checkUsage != allocUsage) { + checkFormat != allocFormat || checkUsage != allocUsage || allocOptionsChanged) { // Something changed while we released the lock. Retry. BQ_LOGV("allocateBuffers: size/format/usage changed while allocating. Retrying."); mCore->mIsAllocating = false; @@ -1543,6 +1621,9 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, mCore->clearBufferSlotLocked(*slot); // Clean up the slot first mSlots[*slot].mGraphicBuffer = buffers[i]; mSlots[*slot].mFence = Fence::NO_FENCE; +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + mSlots[*slot].mAdditionalOptionsGenerationId = allocOptionsGenId; +#endif // freeBufferLocked puts this slot on the free slots list. Since // we then attached a buffer, move the slot to free buffer list. @@ -1778,4 +1859,29 @@ status_t BufferQueueProducer::setFrameRate(float frameRate, int8_t compatibility } #endif +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) +status_t BufferQueueProducer::setAdditionalOptions( + const std::vector& options) { + ATRACE_CALL(); + BQ_LOGV("setAdditionalOptions, size = %zu", options.size()); + + if (!GraphicBufferAllocator::get().supportsAdditionalOptions()) { + return INVALID_OPERATION; + } + + std::lock_guard lock(mCore->mMutex); + + if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) { + BQ_LOGE("setAdditionalOptions: BufferQueue not connected, cannot set additional options"); + return NO_INIT; + } + + if (mCore->mAdditionalOptions != options) { + mCore->mAdditionalOptions = options; + mCore->mAdditionalOptionsGenerationId++; + } + return NO_ERROR; +} +#endif + } // namespace android diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index e81c098b85..09144806ee 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -80,6 +80,7 @@ enum { QUERY_MULTIPLE, GET_LAST_QUEUED_BUFFER2, SET_FRAME_RATE, + SET_ADDITIONAL_OPTIONS, }; class BpGraphicBufferProducer : public BpInterface @@ -778,6 +779,25 @@ public: return result; } #endif +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + virtual status_t setAdditionalOptions(const std::vector& options) { + Parcel data, reply; + data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); + if (options.size() > 100) { + return BAD_VALUE; + } + data.writeInt32(options.size()); + for (const auto& it : options) { + data.writeCString(it.name.c_str()); + data.writeInt64(it.value); + } + status_t result = remote()->transact(SET_ADDITIONAL_OPTIONS, data, &reply); + if (result == NO_ERROR) { + result = reply.readInt32(); + } + return result; + } +#endif }; // Out-of-line virtual method definition to trigger vtable emission in this @@ -981,6 +1001,13 @@ status_t IGraphicBufferProducer::setFrameRate(float /*frameRate*/, int8_t /*comp } #endif +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) +status_t IGraphicBufferProducer::setAdditionalOptions(const std::vector&) { + // No-op for IGBP other than BufferQueue. + return INVALID_OPERATION; +} +#endif + status_t IGraphicBufferProducer::exportToParcel(Parcel* parcel) { status_t res = OK; res = parcel->writeUint32(USE_BUFFER_QUEUE); @@ -1532,6 +1559,28 @@ status_t BnGraphicBufferProducer::onTransact( reply->writeInt32(result); return NO_ERROR; } +#endif +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + case SET_ADDITIONAL_OPTIONS: { + CHECK_INTERFACE(IGraphicBuffer, data, reply); + int optionCount = data.readInt32(); + if (optionCount < 0 || optionCount > 100) { + return BAD_VALUE; + } + std::vector opts; + opts.reserve(optionCount); + for (int i = 0; i < optionCount; i++) { + const char* name = data.readCString(); + int64_t value = 0; + if (name == nullptr || data.readInt64(&value) != NO_ERROR) { + return BAD_VALUE; + } + opts.emplace_back(name, value); + } + status_t result = setAdditionalOptions(opts); + reply->writeInt32(result); + return NO_ERROR; + } #endif } return BBinder::onTransact(code, data, reply, flags); diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 086544e48a..87fd448f0c 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1475,6 +1475,9 @@ int Surface::perform(int operation, va_list args) case NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO: res = dispatchSetFrameTimelineInfo(args); break; + case NATIVE_WINDOW_SET_BUFFERS_ADDITIONAL_OPTIONS: + res = dispatchSetAdditionalOptions(args); + break; default: res = NAME_NOT_FOUND; break; @@ -1833,6 +1836,24 @@ int Surface::dispatchSetFrameTimelineInfo(va_list args) { return setFrameTimelineInfo(nativeWindowFtlInfo.frameNumber, ftlInfo); } +int Surface::dispatchSetAdditionalOptions(va_list args) { + ATRACE_CALL(); + +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + const AHardwareBufferLongOptions* opts = va_arg(args, const AHardwareBufferLongOptions*); + const size_t optsSize = va_arg(args, size_t); + std::vector convertedOpts; + convertedOpts.reserve(optsSize); + for (size_t i = 0; i < optsSize; i++) { + convertedOpts.emplace_back(opts[i].name, opts[i].value); + } + return setAdditionalOptions(convertedOpts); +#else + (void)args; + return INVALID_OPERATION; +#endif +} + bool Surface::transformToDisplayInverse() const { return (mTransform & NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) == NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; @@ -2619,6 +2640,17 @@ status_t Surface::setFrameTimelineInfo(uint64_t /*frameNumber*/, return BAD_VALUE; } +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) +status_t Surface::setAdditionalOptions(const std::vector& options) { + if (!GraphicBufferAllocator::get().supportsAdditionalOptions()) { + return INVALID_OPERATION; + } + + Mutex::Autolock lock(mMutex); + return mGraphicBufferProducer->setAdditionalOptions(options); +} +#endif + sp Surface::getSurfaceControlHandle() const { Mutex::Autolock lock(mMutex); return mSurfaceControlHandle; diff --git a/libs/gui/include/gui/AdditionalOptions.h b/libs/gui/include/gui/AdditionalOptions.h new file mode 100644 index 0000000000..87cb913675 --- /dev/null +++ b/libs/gui/include/gui/AdditionalOptions.h @@ -0,0 +1,32 @@ +/* + * 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 + +namespace android::gui { +// Additional options to pass to AHardwareBuffer_allocateWithOptions. +// See also allocator-v2's BufferDescriptorInfo.aidl +struct AdditionalOptions { + std::string name; + int64_t value; + + bool operator==(const AdditionalOptions& other) const { + return value == other.value && name == other.name; + } +}; +} // namespace android::gui diff --git a/libs/gui/include/gui/BufferQueueCore.h b/libs/gui/include/gui/BufferQueueCore.h index 22c2be7bc7..bb52c8ec88 100644 --- a/libs/gui/include/gui/BufferQueueCore.h +++ b/libs/gui/include/gui/BufferQueueCore.h @@ -17,6 +17,9 @@ #ifndef ANDROID_GUI_BUFFERQUEUECORE_H #define ANDROID_GUI_BUFFERQUEUECORE_H +#include + +#include #include #include #include @@ -357,6 +360,14 @@ private: // This allows the consumer to acquire an additional buffer if that buffer is not droppable and // will eventually be released or acquired by the consumer. bool mAllowExtraAcquire = false; + +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + // Additional options to pass when allocating GraphicBuffers. + // GenerationID changes when the options change, indicating reallocation is required + uint32_t mAdditionalOptionsGenerationId = 0; + std::vector mAdditionalOptions; +#endif + }; // class BufferQueueCore } // namespace android diff --git a/libs/gui/include/gui/BufferQueueProducer.h b/libs/gui/include/gui/BufferQueueProducer.h index de47483dca..37a960708c 100644 --- a/libs/gui/include/gui/BufferQueueProducer.h +++ b/libs/gui/include/gui/BufferQueueProducer.h @@ -17,6 +17,7 @@ #ifndef ANDROID_GUI_BUFFERQUEUEPRODUCER_H #define ANDROID_GUI_BUFFERQUEUEPRODUCER_H +#include #include #include @@ -208,6 +209,10 @@ public: int8_t changeFrameRateStrategy) override; #endif +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + status_t setAdditionalOptions(const std::vector& options) override; +#endif + protected: // see IGraphicsBufferProducer::setMaxDequeuedBufferCount, but with the ability to retrieve the // total maximum buffer count for the buffer queue (dequeued AND acquired) diff --git a/libs/gui/include/gui/BufferSlot.h b/libs/gui/include/gui/BufferSlot.h index 57704b1d09..5b32710135 100644 --- a/libs/gui/include/gui/BufferSlot.h +++ b/libs/gui/include/gui/BufferSlot.h @@ -17,6 +17,8 @@ #ifndef ANDROID_GUI_BUFFERSLOT_H #define ANDROID_GUI_BUFFERSLOT_H +#include + #include #include @@ -230,6 +232,11 @@ struct BufferSlot { // producer. If so, it needs to set the BUFFER_NEEDS_REALLOCATION flag when // dequeued to prevent the producer from using a stale cached buffer. bool mNeedsReallocation; + +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + // The generation id of the additional options that mGraphicBuffer was allocated with + uint32_t mAdditionalOptionsGenerationId = 0; +#endif }; } // namespace android diff --git a/libs/gui/include/gui/IGraphicBufferProducer.h b/libs/gui/include/gui/IGraphicBufferProducer.h index 7639e709ca..8fca9460aa 100644 --- a/libs/gui/include/gui/IGraphicBufferProducer.h +++ b/libs/gui/include/gui/IGraphicBufferProducer.h @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -684,6 +685,10 @@ public: int8_t changeFrameRateStrategy); #endif +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + virtual status_t setAdditionalOptions(const std::vector& options); +#endif + struct RequestBufferOutput : public Flattenable { RequestBufferOutput() = default; diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 39a59e42aa..bdcaaf2866 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -215,6 +215,16 @@ public: int8_t changeFrameRateStrategy); virtual status_t setFrameTimelineInfo(uint64_t frameNumber, const FrameTimelineInfo& info); +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) + /** + * Set additional options to be passed when allocating a buffer. Only valid if IAllocator-V2 + * or newer is available, otherwise will return INVALID_OPERATION. Only allowed to be called + * after connect and options are cleared when disconnect happens. Returns NO_INIT if not + * connected + */ + status_t setAdditionalOptions(const std::vector& options); +#endif + protected: virtual ~Surface(); @@ -302,6 +312,7 @@ private: int dispatchGetLastQueuedBuffer(va_list args); int dispatchGetLastQueuedBuffer2(va_list args); int dispatchSetFrameTimelineInfo(va_list args); + int dispatchSetAdditionalOptions(va_list args); std::mutex mNameMutex; std::string mName; diff --git a/libs/gui/libgui_flags.aconfig b/libs/gui/libgui_flags.aconfig index 38646992da..a902a8c5cb 100644 --- a/libs/gui/libgui_flags.aconfig +++ b/libs/gui/libgui_flags.aconfig @@ -16,3 +16,11 @@ flag { bug: "310927247" is_fixed_read_only: true } + +flag { + name: "bq_extendedallocate" + namespace: "core_graphics" + description: "Add BQ support for allocate with extended options" + bug: "268382490" + is_fixed_read_only: true +} diff --git a/libs/gui/tests/Android.bp b/libs/gui/tests/Android.bp index 2faa330426..ea8acbbb72 100644 --- a/libs/gui/tests/Android.bp +++ b/libs/gui/tests/Android.bp @@ -24,6 +24,7 @@ cc_test { "-Wextra", "-Wthread-safety", "-DCOM_ANDROID_GRAPHICS_LIBGUI_FLAGS_BQ_SETFRAMERATE=true", + "-DCOM_ANDROID_GRAPHICS_LIBGUI_FLAGS_BQ_EXTENDEDALLOCATE=true", ], srcs: [ diff --git a/libs/gui/tests/BufferQueue_test.cpp b/libs/gui/tests/BufferQueue_test.cpp index 1ec6f915f7..272c5ed2b4 100644 --- a/libs/gui/tests/BufferQueue_test.cpp +++ b/libs/gui/tests/BufferQueue_test.cpp @@ -28,6 +28,8 @@ #include +#include + #include #include #include @@ -47,6 +49,10 @@ using namespace std::chrono_literals; +static bool IsCuttlefish() { + return ::android::base::GetProperty("ro.product.board", "") == "cutf"; +} + namespace android { using namespace com::android::graphics::libgui; @@ -1439,4 +1445,55 @@ TEST(BufferQueueThreading, TestProducerDequeueConsumerDestroy) { EXPECT_EQ(nullptr, bufferConsumer.get()); } +TEST_F(BufferQueueTest, TestAdditionalOptions) { + sp producer; + sp consumer; + BufferQueue::createBufferQueue(&producer, &consumer); + + sp bufferConsumer = + sp::make(consumer, GRALLOC_USAGE_SW_READ_OFTEN, 2); + ASSERT_NE(nullptr, bufferConsumer.get()); + sp surface = sp::make(producer); + native_window_set_buffers_format(surface.get(), PIXEL_FORMAT_RGBA_8888); + native_window_set_buffers_dimensions(surface.get(), 100, 100); + + std::array extras = {{ + {.name = "android.hardware.graphics.common.Dataspace", ADATASPACE_DISPLAY_P3}, + }}; + + ASSERT_EQ(NO_INIT, + native_window_set_buffers_additional_options(surface.get(), extras.data(), + extras.size())); + + if (!IsCuttlefish()) { + GTEST_SKIP() << "Not cuttlefish"; + } + + ASSERT_EQ(OK, native_window_api_connect(surface.get(), NATIVE_WINDOW_API_CPU)); + ASSERT_EQ(OK, + native_window_set_buffers_additional_options(surface.get(), extras.data(), + extras.size())); + + ANativeWindowBuffer* windowBuffer = nullptr; + int fence = -1; + ASSERT_EQ(OK, ANativeWindow_dequeueBuffer(surface.get(), &windowBuffer, &fence)); + + AHardwareBuffer* buffer = ANativeWindowBuffer_getHardwareBuffer(windowBuffer); + ASSERT_TRUE(buffer); + ADataSpace dataSpace = AHardwareBuffer_getDataSpace(buffer); + EXPECT_EQ(ADATASPACE_DISPLAY_P3, dataSpace); + + ANativeWindow_cancelBuffer(surface.get(), windowBuffer, -1); + + // Check that reconnecting properly clears the options + ASSERT_EQ(OK, native_window_api_disconnect(surface.get(), NATIVE_WINDOW_API_CPU)); + ASSERT_EQ(OK, native_window_api_connect(surface.get(), NATIVE_WINDOW_API_CPU)); + + ASSERT_EQ(OK, ANativeWindow_dequeueBuffer(surface.get(), &windowBuffer, &fence)); + buffer = ANativeWindowBuffer_getHardwareBuffer(windowBuffer); + ASSERT_TRUE(buffer); + dataSpace = AHardwareBuffer_getDataSpace(buffer); + EXPECT_EQ(ADATASPACE_UNKNOWN, dataSpace); +} + } // namespace android diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h index 969a5cff05..33c303ae71 100644 --- a/libs/nativewindow/include/system/window.h +++ b/libs/nativewindow/include/system/window.h @@ -41,6 +41,8 @@ #include #include +#include + // system/window.h is a superset of the vndk and apex apis #include #include @@ -257,6 +259,7 @@ enum { NATIVE_WINDOW_SET_QUERY_INTERCEPTOR = 47, /* private */ NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO = 48, /* private */ NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2 = 49, /* private */ + NATIVE_WINDOW_SET_BUFFERS_ADDITIONAL_OPTIONS = 50, // clang-format on }; @@ -1182,6 +1185,26 @@ static inline int native_window_set_frame_timeline_info( return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO, frameTimelineInfo); } +/** + * native_window_set_buffers_additional_options(..., ExtendableType* additionalOptions, size_t size) + * All buffers dequeued after this call will have the additionalOptions specified. + * + * This must only be called after api_connect, otherwise NO_INIT is returned. The options are + * cleared in api_disconnect & api_connect + * + * If IAllocator is not v2 or newer this method returns INVALID_OPERATION + * + * \return NO_ERROR on success. + * \return NO_INIT if no api is connected + * \return INVALID_OPERATION if additional option support is not available + */ +static inline int native_window_set_buffers_additional_options( + struct ANativeWindow* window, const AHardwareBufferLongOptions* additionalOptions, + size_t additionalOptionsSize) { + return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_ADDITIONAL_OPTIONS, additionalOptions, + additionalOptionsSize); +} + // ------------------------------------------------------------------------------------------------ // Candidates for APEX visibility // These functions are planned to be made stable for APEX modules, but have not diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp index 98082fb81e..1ebe5973fa 100644 --- a/libs/ui/GraphicBufferAllocator.cpp +++ b/libs/ui/GraphicBufferAllocator.cpp @@ -291,5 +291,9 @@ status_t GraphicBufferAllocator::free(buffer_handle_t handle) return NO_ERROR; } +bool GraphicBufferAllocator::supportsAdditionalOptions() const { + return mAllocator->supportsAdditionalOptions(); +} + // --------------------------------------------------------------------------- }; // namespace android diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index e6015e0b5e..4167dcbab1 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -226,6 +226,8 @@ public: const GraphicBufferAllocator::AllocationRequest&) const { return GraphicBufferAllocator::AllocationResult(UNKNOWN_TRANSACTION); } + + virtual bool supportsAdditionalOptions() const { return false; } }; } // namespace android diff --git a/libs/ui/include/ui/Gralloc5.h b/libs/ui/include/ui/Gralloc5.h index f9e8f5e9fd..5aa5019603 100644 --- a/libs/ui/include/ui/Gralloc5.h +++ b/libs/ui/include/ui/Gralloc5.h @@ -178,6 +178,8 @@ public: [[nodiscard]] GraphicBufferAllocator::AllocationResult allocate( const GraphicBufferAllocator::AllocationRequest&) const override; + bool supportsAdditionalOptions() const override { return true; } + private: const Gralloc5Mapper &mMapper; std::shared_ptr mAllocator; diff --git a/libs/ui/include/ui/GraphicBufferAllocator.h b/libs/ui/include/ui/GraphicBufferAllocator.h index 8f461e193b..bbb2d77058 100644 --- a/libs/ui/include/ui/GraphicBufferAllocator.h +++ b/libs/ui/include/ui/GraphicBufferAllocator.h @@ -107,6 +107,8 @@ public: void dump(std::string& res, bool less = true) const; static void dumpToSystemLog(bool less = true); + bool supportsAdditionalOptions() const; + protected: struct alloc_rec_t { uint32_t width; -- cgit v1.2.3-59-g8ed1b From c3ccff19603c0778781fd18e0e38e55950420780 Mon Sep 17 00:00:00 2001 From: Alan Ding Date: Mon, 29 Apr 2024 00:44:31 -0700 Subject: ui: Refactor DisplayIdentification to use ftl::stable_hash Replace cityHash64Len0To16 with ftl::stable_hash which can handle up to 64 bytes string instead of just up to 16. Bug: 185536303 Bug: 194863377 Test: DisplayIdentification_test Change-Id: I90056145033ed5798dd5f5d99884028749d5d879 --- libs/ui/DisplayIdentification.cpp | 67 +--------------------------- libs/ui/include/ui/DisplayIdentification.h | 3 -- libs/ui/tests/DisplayIdentification_test.cpp | 11 ++++- 3 files changed, 11 insertions(+), 70 deletions(-) (limited to 'libs/ui') diff --git a/libs/ui/DisplayIdentification.cpp b/libs/ui/DisplayIdentification.cpp index 82e5427317..0908ae85a8 100644 --- a/libs/ui/DisplayIdentification.cpp +++ b/libs/ui/DisplayIdentification.cpp @@ -23,67 +23,13 @@ #include #include +#include #include - #include namespace android { namespace { -template -inline T load(const void* p) { - static_assert(std::is_integral::value, "T must be integral"); - - T r; - std::memcpy(&r, p, sizeof(r)); - return r; -} - -uint64_t rotateByAtLeast1(uint64_t val, uint8_t shift) { - return (val >> shift) | (val << (64 - shift)); -} - -uint64_t shiftMix(uint64_t val) { - return val ^ (val >> 47); -} - -__attribute__((no_sanitize("unsigned-integer-overflow"))) -uint64_t hash64Len16(uint64_t u, uint64_t v) { - constexpr uint64_t kMul = 0x9ddfea08eb382d69; - uint64_t a = (u ^ v) * kMul; - a ^= (a >> 47); - uint64_t b = (v ^ a) * kMul; - b ^= (b >> 47); - b *= kMul; - return b; -} - -__attribute__((no_sanitize("unsigned-integer-overflow"))) -uint64_t hash64Len0To16(const char* s, uint64_t len) { - constexpr uint64_t k2 = 0x9ae16a3b2f90404f; - constexpr uint64_t k3 = 0xc949d7c7509e6557; - - if (len > 8) { - const uint64_t a = load(s); - const uint64_t b = load(s + len - 8); - return hash64Len16(a, rotateByAtLeast1(b + len, static_cast(len))) ^ b; - } - if (len >= 4) { - const uint32_t a = load(s); - const uint32_t b = load(s + len - 4); - return hash64Len16(len + (a << 3), b); - } - if (len > 0) { - const unsigned char a = static_cast(s[0]); - const unsigned char b = static_cast(s[len >> 1]); - const unsigned char c = static_cast(s[len - 1]); - const uint32_t y = static_cast(a) + (static_cast(b) << 8); - const uint32_t z = static_cast(len) + (static_cast(c) << 2); - return shiftMix(y * k2 ^ z * k3) * k2; - } - return k2; -} - using byte_view = std::span; constexpr size_t kEdidBlockSize = 128; @@ -320,7 +266,7 @@ std::optional parseEdid(const DisplayIdentificationData& edid) { // Hash model string instead of using product code or (integer) serial number, since the latter // have been observed to change on some displays with multiple inputs. Use a stable hash instead // of std::hash which is only required to be same within a single execution of a program. - const uint32_t modelHash = static_cast(cityHash64Len0To16(modelString)); + const uint32_t modelHash = static_cast(*ftl::stable_hash(modelString)); // Parse extension blocks. std::optional cea861Block; @@ -394,13 +340,4 @@ PhysicalDisplayId getVirtualDisplayId(uint32_t id) { return PhysicalDisplayId::fromEdid(0, kVirtualEdidManufacturerId, id); } -uint64_t cityHash64Len0To16(std::string_view sv) { - auto len = sv.length(); - if (len > 16) { - ALOGE("%s called with length %zu. Only hashing the first 16 chars", __FUNCTION__, len); - len = 16; - } - return hash64Len0To16(sv.data(), len); -} - } // namespace android diff --git a/libs/ui/include/ui/DisplayIdentification.h b/libs/ui/include/ui/DisplayIdentification.h index fc9c0f491b..8bc2017b55 100644 --- a/libs/ui/include/ui/DisplayIdentification.h +++ b/libs/ui/include/ui/DisplayIdentification.h @@ -80,7 +80,4 @@ std::optional parseDisplayIdentificationData( PhysicalDisplayId getVirtualDisplayId(uint32_t id); -// CityHash64 implementation that only hashes at most the first 16 characters of the given string. -uint64_t cityHash64Len0To16(std::string_view sv); - } // namespace android diff --git a/libs/ui/tests/DisplayIdentification_test.cpp b/libs/ui/tests/DisplayIdentification_test.cpp index 736979a7c5..721b46688e 100644 --- a/libs/ui/tests/DisplayIdentification_test.cpp +++ b/libs/ui/tests/DisplayIdentification_test.cpp @@ -21,9 +21,9 @@ #include #include +#include #include #include - #include using ::testing::ElementsAre; @@ -135,7 +135,7 @@ DisplayIdentificationData asDisplayIdentificationData(const unsigned char (&byte } uint32_t hash(const char* str) { - return static_cast(cityHash64Len0To16(str)); + return static_cast(*ftl::stable_hash(str)); } } // namespace @@ -188,6 +188,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_STREQ("SEC", edid->pnpId.data()); // ASCII text should be used as fallback if display name and serial number are missing. EXPECT_EQ(hash("121AT11-801"), edid->modelHash); + EXPECT_EQ(hash("121AT11-801"), 626564263); EXPECT_TRUE(edid->displayName.empty()); EXPECT_EQ(12610, edid->productId); EXPECT_EQ(21, edid->manufactureOrModelYear); @@ -199,6 +200,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(0x22f0u, edid->manufacturerId); EXPECT_STREQ("HWP", edid->pnpId.data()); EXPECT_EQ(hash("HP ZR30w"), edid->modelHash); + EXPECT_EQ(hash("HP ZR30w"), 918492362); EXPECT_EQ("HP ZR30w", edid->displayName); EXPECT_EQ(10348, edid->productId); EXPECT_EQ(22, edid->manufactureOrModelYear); @@ -210,6 +212,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(0x4c2du, edid->manufacturerId); EXPECT_STREQ("SAM", edid->pnpId.data()); EXPECT_EQ(hash("SAMSUNG"), edid->modelHash); + EXPECT_EQ(hash("SAMSUNG"), 1201368132); EXPECT_EQ("SAMSUNG", edid->displayName); EXPECT_EQ(2302, edid->productId); EXPECT_EQ(21, edid->manufactureOrModelYear); @@ -227,6 +230,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(13481, edid->manufacturerId); EXPECT_STREQ("MEI", edid->pnpId.data()); EXPECT_EQ(hash("Panasonic-TV"), edid->modelHash); + EXPECT_EQ(hash("Panasonic-TV"), 3876373262); EXPECT_EQ("Panasonic-TV", edid->displayName); EXPECT_EQ(41622, edid->productId); EXPECT_EQ(29, edid->manufactureOrModelYear); @@ -244,6 +248,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(8355, edid->manufacturerId); EXPECT_STREQ("HEC", edid->pnpId.data()); EXPECT_EQ(hash("Hisense"), edid->modelHash); + EXPECT_EQ(hash("Hisense"), 2859844809); EXPECT_EQ("Hisense", edid->displayName); EXPECT_EQ(0, edid->productId); EXPECT_EQ(29, edid->manufactureOrModelYear); @@ -261,6 +266,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(3724, edid->manufacturerId); EXPECT_STREQ("CTL", edid->pnpId.data()); EXPECT_EQ(hash("LP2361"), edid->modelHash); + EXPECT_EQ(hash("LP2361"), 1523181158); EXPECT_EQ("LP2361", edid->displayName); EXPECT_EQ(9373, edid->productId); EXPECT_EQ(23, edid->manufactureOrModelYear); @@ -281,6 +287,7 @@ TEST(DisplayIdentificationTest, parseInvalidEdid) { // Serial number should be used as fallback if display name is invalid. const auto modelHash = hash("CN4202137Q"); EXPECT_EQ(modelHash, edid->modelHash); + EXPECT_EQ(modelHash, 3582951527); EXPECT_TRUE(edid->displayName.empty()); // Parsing should succeed even if EDID is truncated. -- cgit v1.2.3-59-g8ed1b From 13bf76a87d9113d60f39e645c5453bf18d0a158d Mon Sep 17 00:00:00 2001 From: Linnan Li Date: Sun, 5 May 2024 19:18:02 +0800 Subject: Use a strongly typed LogicalDisplayId for displayId(2/n) Currently, we use int32_t for displayId, which is not a safe type, and it may also lead to misdefinition of types. Here, we introduce LogicalDisplayId as a strong type for displayId and move all contents of constants.h into LogicalDisplayId.h. Bug: 339106983 Test: atest inputflinger_tests Test: atest InputTests Test: m checkinput Test: m libsurfaceflinger_unittest Test: presubmit Change-Id: If44e56f69553d095af5adb59b595e4a852ab32ce Signed-off-by: Linnan Li --- include/input/DisplayViewport.h | 16 +- include/input/Input.h | 15 +- include/input/InputDevice.h | 6 +- include/input/InputEventBuilders.h | 9 +- include/input/InputTransport.h | 13 +- libs/gui/DisplayInfo.cpp | 8 +- libs/gui/WindowInfo.cpp | 8 +- libs/gui/include/gui/DisplayInfo.h | 4 +- libs/gui/include/gui/WindowInfo.h | 4 +- libs/gui/include/gui/constants.h | 37 ---- libs/gui/tests/DisplayInfo_test.cpp | 2 +- libs/gui/tests/EndToEndNativeInputTest.cpp | 198 +++++++++-------- libs/gui/tests/WindowInfo_test.cpp | 2 +- libs/input/Input.cpp | 43 ++-- libs/input/InputConsumer.cpp | 23 +- libs/input/InputConsumerNoResampling.cpp | 12 +- libs/input/InputDevice.cpp | 6 +- libs/input/InputTransport.cpp | 20 +- libs/input/KeyCharacterMap.cpp | 7 +- libs/input/tests/InputEvent_test.cpp | 9 +- .../InputPublisherAndConsumerNoResampling_test.cpp | 26 ++- .../input/tests/InputPublisherAndConsumer_test.cpp | 37 ++-- libs/input/tests/MotionPredictor_test.cpp | 5 +- libs/input/tests/TouchResampling_test.cpp | 3 +- libs/input/tests/VelocityTracker_test.cpp | 5 +- libs/input/tests/VerifiedInputEvent_test.cpp | 12 +- libs/ui/include/ui/LogicalDisplayId.h | 56 +++++ services/inputflinger/InputCommonConverter.cpp | 2 +- services/inputflinger/InputFilter.cpp | 2 +- services/inputflinger/InputFilterCallbacks.cpp | 6 +- services/inputflinger/InputReaderBase.cpp | 4 +- services/inputflinger/NotifyArgs.cpp | 4 +- services/inputflinger/PointerChoreographer.cpp | 74 ++++--- services/inputflinger/PointerChoreographer.h | 52 +++-- .../benchmarks/InputDispatcher_benchmarks.cpp | 7 +- .../inputflinger/dispatcher/CancelationOptions.h | 2 +- services/inputflinger/dispatcher/Entry.cpp | 46 ++-- services/inputflinger/dispatcher/Entry.h | 25 ++- services/inputflinger/dispatcher/FocusResolver.cpp | 26 +-- services/inputflinger/dispatcher/FocusResolver.h | 22 +- .../inputflinger/dispatcher/InputDispatcher.cpp | 243 +++++++++++---------- services/inputflinger/dispatcher/InputDispatcher.h | 83 +++---- services/inputflinger/dispatcher/InputState.cpp | 3 +- services/inputflinger/dispatcher/InputState.h | 6 +- services/inputflinger/dispatcher/InputTarget.h | 1 - .../dispatcher/include/InputDispatcherInterface.h | 23 +- .../include/InputDispatcherPolicyInterface.h | 8 +- .../trace/AndroidInputEventProtoConverter.cpp | 4 +- .../trace/InputTracingBackendInterface.h | 4 +- services/inputflinger/include/InputReaderBase.h | 11 +- services/inputflinger/include/NotifyArgs.h | 22 +- services/inputflinger/include/NotifyArgsBuilders.h | 9 +- .../include/PointerChoreographerPolicyInterface.h | 3 +- .../include/PointerControllerInterface.h | 6 +- services/inputflinger/reader/InputDevice.cpp | 6 +- services/inputflinger/reader/InputReader.cpp | 7 +- services/inputflinger/reader/include/InputDevice.h | 2 +- services/inputflinger/reader/include/InputReader.h | 2 +- .../mapper/CapturedTouchpadEventConverter.cpp | 3 +- .../reader/mapper/CursorInputMapper.cpp | 13 +- .../inputflinger/reader/mapper/CursorInputMapper.h | 4 +- services/inputflinger/reader/mapper/InputMapper.h | 2 +- .../reader/mapper/JoystickInputMapper.cpp | 2 +- .../reader/mapper/KeyboardInputMapper.cpp | 6 +- .../reader/mapper/KeyboardInputMapper.h | 4 +- .../reader/mapper/RotaryEncoderInputMapper.cpp | 2 +- .../reader/mapper/TouchCursorInputMapperCommon.cpp | 4 +- .../reader/mapper/TouchCursorInputMapperCommon.h | 2 +- .../reader/mapper/TouchInputMapper.cpp | 23 +- .../inputflinger/reader/mapper/TouchInputMapper.h | 12 +- .../reader/mapper/TouchpadInputMapper.cpp | 9 +- .../reader/mapper/TouchpadInputMapper.h | 4 +- .../reader/mapper/gestures/GestureConverter.h | 4 +- .../inputflinger/tests/CursorInputMapper_test.cpp | 6 +- .../tests/FakeInputDispatcherPolicy.cpp | 6 +- .../inputflinger/tests/FakeInputDispatcherPolicy.h | 8 +- .../inputflinger/tests/FakeInputReaderPolicy.cpp | 12 +- .../inputflinger/tests/FakeInputReaderPolicy.h | 6 +- .../inputflinger/tests/FakePointerController.cpp | 17 +- .../inputflinger/tests/FakePointerController.h | 21 +- services/inputflinger/tests/FakeWindows.cpp | 14 +- services/inputflinger/tests/FakeWindows.h | 44 ++-- services/inputflinger/tests/FocusResolver_test.cpp | 45 ++-- .../inputflinger/tests/GestureConverter_test.cpp | 120 +++++----- .../tests/InputDeviceMetricsCollector_test.cpp | 3 +- .../inputflinger/tests/InputDispatcher_test.cpp | 153 +++++++------ services/inputflinger/tests/InputMapperTest.cpp | 4 +- services/inputflinger/tests/InputMapperTest.h | 2 +- .../tests/InputProcessorConverter_test.cpp | 3 +- .../inputflinger/tests/InputProcessor_test.cpp | 5 +- services/inputflinger/tests/InputReader_test.cpp | 55 ++--- services/inputflinger/tests/InputTracingTest.cpp | 4 +- .../inputflinger/tests/LatencyTracker_test.cpp | 3 +- .../tests/MultiTouchInputMapper_test.cpp | 2 +- services/inputflinger/tests/NotifyArgs_test.cpp | 2 +- .../tests/PointerChoreographer_test.cpp | 183 +++++++++------- .../tests/PreferStylusOverTouch_test.cpp | 8 +- services/inputflinger/tests/TestEventMatchers.h | 6 +- .../tests/TouchpadInputMapper_test.cpp | 2 +- .../tests/UnwantedInteractionBlocker_test.cpp | 8 +- .../inputflinger/tests/fuzzers/FuzzedInputStream.h | 2 +- .../tests/fuzzers/InputClassifierFuzzer.cpp | 2 +- .../tests/fuzzers/InputDispatcherFuzzer.cpp | 13 +- .../tests/fuzzers/InputReaderFuzzer.cpp | 5 +- .../inputflinger/tests/fuzzers/MapperHelpers.h | 2 +- services/surfaceflinger/DisplayDevice.cpp | 2 +- services/surfaceflinger/FrontEnd/DisplayInfo.h | 1 + .../FrontEnd/LayerSnapshotBuilder.cpp | 3 +- services/surfaceflinger/Layer.cpp | 8 +- services/surfaceflinger/LayerProtoHelper.cpp | 2 +- .../Tracing/TransactionProtoParser.cpp | 4 +- .../tests/unittests/TransactionProtoParserTest.cpp | 2 +- 112 files changed, 1147 insertions(+), 1036 deletions(-) delete mode 100644 libs/gui/include/gui/constants.h create mode 100644 libs/ui/include/ui/LogicalDisplayId.h (limited to 'libs/ui') 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 #include #include -#include #include #include @@ -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() : "", static_cast(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 #include #include +#include #include #include #include @@ -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 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 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 mHmac; }; @@ -602,7 +603,7 @@ public: static const char* getLabel(int32_t keyCode); static std::optional 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 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 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 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 mKeyCharacterMap; std::optional 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 #include -#include #include #include // 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 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 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 hmac, int32_t action, - int32_t actionButton, int32_t flags, int32_t edgeFlags, - int32_t metaState, int32_t buttonState, + ui::LogicalDisplayId displayId, std::array 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 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(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 #include -#include +#include #include 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 #include #include -#include +#include #include #include #include @@ -234,7 +234,7 @@ struct WindowInfo : public Parcelable { Uid ownerUid = Uid::INVALID; std::string packageName; ftl::Flags inputConfig; - int32_t displayId = ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; InputApplicationInfo applicationInfo; bool replaceTouchableRegionWithCrop = false; wp 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 - -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(layerStack.id)}; +} +} // namespace +namespace test { using Transaction = SurfaceComposerClient::Transaction; @@ -68,7 +76,9 @@ sp getInputFlinger() { sp 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(input); } @@ -99,7 +109,7 @@ private: class InputSurface { public: - InputSurface(const sp &sc, int width, int height, bool noInputChannel = false) { + InputSurface(const sp& sc, int width, int height, bool noInputChannel = false) { mSurfaceControl = sc; mInputFlinger = getInputFlinger(); @@ -130,7 +140,7 @@ public: mInputInfo.applicationInfo = aInfo; } - static std::unique_ptr makeColorInputSurface(const sp &scc, + static std::unique_ptr makeColorInputSurface(const sp& scc, int width, int height) { sp surfaceControl = scc->createSurface(String8("Test Surface"), 0 /* bufHeight */, 0 /* bufWidth */, @@ -140,7 +150,7 @@ public: } static std::unique_ptr makeBufferInputSurface( - const sp &scc, int width, int height) { + const sp& scc, int width, int height) { sp surfaceControl = scc->createSurface(String8("Test Buffer Surface"), width, height, PIXEL_FORMAT_RGBA_8888, 0 /* flags */); @@ -148,7 +158,7 @@ public: } static std::unique_ptr makeContainerInputSurface( - const sp &scc, int width, int height) { + const sp& scc, int width, int height) { sp surfaceControl = scc->createSurface(String8("Test Container Surface"), 0 /* bufHeight */, 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, @@ -157,7 +167,7 @@ public: } static std::unique_ptr makeContainerInputSurfaceNoInputChannel( - const sp &scc, int width, int height) { + const sp& scc, int width, int height) { sp surfaceControl = scc->createSurface(String8("Test Container Surface"), 100 /* height */, 100 /* width */, PIXEL_FORMAT_RGBA_8888, @@ -167,7 +177,7 @@ public: } static std::unique_ptr makeCursorInputSurface( - const sp &scc, int width, int height) { + const sp& scc, int width, int height) { sp 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(ev); + FocusEvent* focusEvent = static_cast(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(ev); + MotionEvent* mev = static_cast(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(ev); + mev = static_cast(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(ev); + MotionEvent* mev = static_cast(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(ev); + mev = static_cast(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(ev); + KeyEvent* keyEvent = static_cast(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(ev); + keyEvent = static_cast(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 &)> + std::function&)> 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 &sc, const sp &parentSc, int width, + BlastInputSurface(const sp& sc, const sp& parentSc, int width, int height) : InputSurface(sc, width, height) { mParentSurfaceControl = parentSc; @@ -336,7 +346,7 @@ public: ~BlastInputSurface() = default; static std::unique_ptr makeBlastInputSurface( - const sp &scc, int width, int height) { + const sp& scc, int width, int height) { sp parentSc = scc->createSurface(String8("Test Parent Surface"), 0 /* bufHeight */, 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888, @@ -351,7 +361,7 @@ public: } void doTransaction( - std::function &)> + std::function&)> 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(1e6 / mode.peakRefreshRate) * 3; } - void TearDown() { - mComposerClient->dispose(); - } + void TearDown() { mComposerClient->dispose(); } std::unique_ptr makeSurface(int width, int height) { return InputSurface::makeColorInputSurface(mComposerClient, width, height); } - void postBuffer(const sp &layer, int32_t w, int32_t h) { + void postBuffer(const sp& 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 #include #include -#include #include #include #include @@ -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 hmac) { +void InputEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, + ui::LogicalDisplayId displayId, std::array hmac) { mId = id; mDeviceId = deviceId; mSource = source; @@ -356,10 +355,11 @@ std::optional 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 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 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 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 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 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 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 createKeyEvent(const InputMessage& msg) { std::unique_ptr event = std::make_unique(); 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 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 #include #include -#include #include #include @@ -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 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 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 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 #include -#include #include #include #include @@ -496,11 +495,11 @@ bool KeyCharacterMap::findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMeta return false; } -void KeyCharacterMap::addKey(Vector& outEvents, - int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time) { +void KeyCharacterMap::addKey(Vector& 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 #include #include -#include #include #include 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 #include #include -#include #include #include #include @@ -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 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 #include -#include #include #include @@ -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 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 #include #include -#include #include #include @@ -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 #include #include -#include #include 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 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 #include -#include #include 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 +#include +#include + +#include + +namespace android::ui { + +// Type-safe wrapper for a logical display id. +struct LogicalDisplayId : ftl::Constructible, + ftl::Equatable, + ftl::Orderable { + 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 { + size_t operator()(const android::ui::LogicalDisplayId& displayId) const { + return hash()(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(args.source); - event.displayId = args.displayId; + event.displayId = args.displayId.val(); event.policyFlags = args.policyFlags; event.action = static_cast(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(event.source), event.displayId, event.policyFlags, - static_cast(event.action), event.flags, event.keyCode, - event.scanCode, event.metaState, event.downTime); + static_cast(event.source), ui::LogicalDisplayId{event.displayId}, + event.policyFlags, static_cast(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 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 InputReaderConfiguration::getDisplayViewportByPor } std::optional 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> change, - PointerChoreographerPolicyInterface& policy) { +inline void notifyPointerDisplayChange( + std::optional> 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 PointerChoreographer::ensureMouseControllerLocked( - int32_t associatedDisplayId) { - const int32_t displayId = getTargetMouseDisplayLocked(associatedDisplayId); +std::pair +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 mouseDisplaysToKeep; + std::set mouseDisplaysToKeep; std::set touchDevicesToKeep; std::set stylusDevicesToKeep; std::set 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::vectorsecond->setDisplayViewport(viewport); @@ -616,18 +620,18 @@ void PointerChoreographer::setDisplayViewports(const std::vector 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, PointerIconStyle> icon, int32_t displayId, - DeviceId deviceId) { + std::variant, 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& windowInfos) { // Mark all spot controllers secure on displays containing secure windows and // remove secure flag from others if required - std::unordered_set privacySensitiveDisplays; - std::unordered_set allDisplayIds; + std::unordered_set privacySensitiveDisplays; + std::unordered_set 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()> 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()> 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& viewports) = 0; virtual std::optional 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, 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& viewports) override; std::optional 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, 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>; + using PointerDisplayChange = std::optional< + std::tuple>; [[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 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 + 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()>>; 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> mMousePointersByDisplay - GUARDED_BY(mLock); + std::map> + mMousePointersByDisplay GUARDED_BY(mLock); std::map> mTouchPointersByDevice GUARDED_BY(mLock); std::map> mStylusPointersByDevice @@ -168,14 +172,14 @@ private: std::map> 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 mInputDeviceInfos GUARDED_BY(mLock); std::set mMouseDevices GUARDED_BY(mLock); std::vector mViewports GUARDED_BY(mLock); bool mShowTouchesEnabled GUARDED_BY(mLock); bool mStylusPointerIconEnabled GUARDED_BY(mLock); - std::set mDisplaysWithPointersHidden; + std::set 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 #include -#include #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 deviceId = std::nullopt; // The specific display id of events to cancel, or nullopt to cancel events on any display. - std::optional displayId = std::nullopt; + std::optional displayId = std::nullopt; // The specific pointers to cancel, or nullopt to cancel all pointer events std::optional> 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, 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, - 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, + 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, const std::vector& 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, 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, 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, + 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, const std::vector& 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& k) const { return std::hash()(k.get()); } }; -sp FocusResolver::getFocusedWindowToken(int32_t displayId) const { +sp FocusResolver::getFocusedWindowToken(ui::LogicalDisplayId displayId) const { auto it = mFocusedWindowTokenByDisplay.find(displayId); return it != mFocusedWindowTokenByDisplay.end() ? it->second.second : nullptr; } -std::optional FocusResolver::getFocusRequest(int32_t displayId) { +std::optional 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 FocusResolver::getFocusRequest(int32_t displayId) { * we will check if the previous focus request is eligible to receive focus. */ std::optional FocusResolver::setInputWindows( - int32_t displayId, const std::vector>& windows) { + ui::LogicalDisplayId displayId, const std::vector>& windows) { std::string removeFocusReason; const std::optional request = getFocusRequest(displayId); @@ -94,12 +94,11 @@ std::optional FocusResolver::setInputWindows( std::optional FocusResolver::setFocusedWindow( const FocusRequest& request, const std::vector>& windows) { - const int32_t displayId = request.displayId; + const ui::LogicalDisplayId displayId = ui::LogicalDisplayId{request.displayId}; const sp 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::updateFocusedWindow( - int32_t displayId, const std::string& reason, const sp& newFocus, + ui::LogicalDisplayId displayId, const std::string& reason, const sp& newFocus, const std::string& tokenName) { sp 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 getFocusedWindowToken(int32_t displayId) const; + sp getFocusedWindowToken(ui::LogicalDisplayId displayId) const; struct FocusChanges { sp oldFocus; sp newFocus; - int32_t displayId; + ui::LogicalDisplayId displayId; std::string reason; }; std::optional setInputWindows( - int32_t displayId, const std::vector>& windows); + ui::LogicalDisplayId displayId, + const std::vector>& windows); std::optional setFocusedWindow( const android::gui::FocusRequest& request, const std::vector>& 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> NamedToken; - std::unordered_map mFocusedWindowTokenByDisplay; + std::unordered_map + 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 mFocusRequestByDisplay; + std::unordered_map + mFocusRequestByDisplay; // Last reason for not granting a focus request. This is used to add more debug information // in the event logs. - std::unordered_map mLastFocusResultByDisplay; + std::unordered_map + mLastFocusResultByDisplay; std::optional updateFocusedWindow( - int32_t displayId, const std::string& reason, const sp& token, + ui::LogicalDisplayId displayId, const std::string& reason, const sp& token, const std::string& tokenName = ""); - std::optional getFocusRequest(int32_t displayId); + std::optional 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& touchStatesByDisplay) { +bool isStylusActiveInDisplay(ui::LogicalDisplayId displayId, + const std::unordered_map& 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::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 ent } } -sp InputDispatcher::findTouchedWindowAtLocked(int32_t displayId, float x, float y, - bool isStylus, +sp 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 InputDispatcher::findTouchedWindowAtLocked(int32_t displayI } std::vector InputDispatcher::findOutsideTargetsLocked( - int32_t displayId, const sp& touchedWindow, int32_t pointerId) const { + ui::LogicalDisplayId displayId, const sp& touchedWindow, + int32_t pointerId) const { if (touchedWindow == nullptr) { return {}; } @@ -1458,7 +1460,7 @@ std::vector InputDispatcher::findOutsideTargetsLocked( } std::vector> 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> spyWindows; const auto& windowHandles = getWindowHandlesLocked(displayId); @@ -1951,12 +1953,12 @@ bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr(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 InputDispatcher::findFocusedWindowTargetLocked( InputEventInjectionResult& outInjectionResult) { outInjectionResult = InputEventInjectionResult::FAILED; // Default result - int32_t displayId = getTargetDisplayId(entry); + ui::LogicalDisplayId displayId = getTargetDisplayId(entry); sp focusedWindowHandle = getFocusedWindowHandleLocked(displayId); std::shared_ptr focusedApplicationHandle = getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); @@ -2271,8 +2272,8 @@ sp 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 InputDispatcher::findTouchedWindowTargetsLocked( std::vector 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 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 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 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 pointerIds; @@ -2827,7 +2829,7 @@ std::vector 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 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& 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& windowHandle, InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLocked( const sp& windowHandle, float x, float y) const { const WindowInfo* windowInfo = windowHandle->getInfo(); - int32_t displayId = windowInfo->displayId; + ui::LogicalDisplayId displayId = windowInfo->displayId; const std::vector>& windowHandles = getWindowHandlesLocked(displayId); TouchOcclusionInfo info; info.hasBlockingOcclusion = false; @@ -3215,7 +3217,7 @@ bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionIn bool InputDispatcher::isWindowObscuredAtPointLocked(const sp& windowHandle, float x, float y) const { - int32_t displayId = windowHandle->getInfo()->displayId; + ui::LogicalDisplayId displayId = windowHandle->getInfo()->displayId; const std::vector>& windowHandles = getWindowHandlesLocked(displayId); for (const sp& otherHandle : windowHandles) { if (windowHandle == otherHandle) { @@ -3231,7 +3233,7 @@ bool InputDispatcher::isWindowObscuredAtPointLocked(const sp& } bool InputDispatcher::isWindowObscuredLocked(const sp& windowHandle) const { - int32_t displayId = windowHandle->getInfo()->displayId; + ui::LogicalDisplayId displayId = windowHandle->getInfo()->displayId; const std::vector>& windowHandles = getWindowHandlesLocked(displayId); const WindowInfo* windowInfo = windowHandle->getInfo(); for (const sp& otherHandle : windowHandles) { @@ -3239,8 +3241,7 @@ bool InputDispatcher::isWindowObscuredLocked(const sp& 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 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 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 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>& InputDispatcher::getWindowHandlesLocked( - int32_t displayId) const { + ui::LogicalDisplayId displayId) const { static const std::vector> EMPTY_WINDOW_HANDLES; auto it = mWindowHandlesByDisplay.find(displayId); return it != mWindowHandlesByDisplay.end() ? it->second : EMPTY_WINDOW_HANDLES; } sp InputDispatcher::getWindowHandleLocked( - const sp& windowHandleToken, std::optional displayId) const { + const sp& windowHandleToken, std::optional displayId) const { if (windowHandleToken == nullptr) { return nullptr; } if (!displayId) { // Look through all displays. - for (auto& it : mWindowHandlesByDisplay) { - const std::vector>& windowHandles = it.second; + for (const auto& [_, windowHandles] : mWindowHandlesByDisplay) { for (const sp& windowHandle : windowHandles) { if (windowHandle->getToken() == windowHandleToken) { return windowHandle; @@ -5161,16 +5164,15 @@ sp InputDispatcher::getWindowHandleLocked( sp InputDispatcher::getWindowHandleLocked( const sp& windowHandle) const { - for (auto& it : mWindowHandlesByDisplay) { - const std::vector>& windowHandles = it.second; + for (const auto& [displayId, windowHandles] : mWindowHandlesByDisplay) { for (const sp& 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 InputDispatcher::getWindowHandleLocked( return nullptr; } -sp InputDispatcher::getFocusedWindowHandleLocked(int displayId) const { +sp InputDispatcher::getFocusedWindowHandleLocked( + ui::LogicalDisplayId displayId) const { sp 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& w } void InputDispatcher::updateWindowHandlesForDisplayLocked( - const std::vector>& windowInfoHandles, int32_t displayId) { + const std::vector>& 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& 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>& windowInfoHandles, int32_t displayId) { + const std::vector>& windowInfoHandles, + ui::LogicalDisplayId displayId) { if (DEBUG_FOCUS) { std::string windowList; for (const sp& iwh : windowInfoHandles) { @@ -5417,9 +5423,10 @@ void InputDispatcher::setInputWindowsLocked( } void InputDispatcher::setFocusedApplication( - int32_t displayId, const std::shared_ptr& inputApplicationHandle) { + ui::LogicalDisplayId displayId, + const std::shared_ptr& inputApplicationHandle) { if (DEBUG_FOCUS) { - ALOGD("setFocusedApplication displayId=%" PRId32 " %s", displayId, + ALOGD("setFocusedApplication displayId=%s %s", displayId.toString().c_str(), inputApplicationHandle ? inputApplicationHandle->getName().c_str() : ""); } { // acquire lock @@ -5432,7 +5439,8 @@ void InputDispatcher::setFocusedApplication( } void InputDispatcher::setFocusedApplicationLocked( - int32_t displayId, const std::shared_ptr& inputApplicationHandle) { + ui::LogicalDisplayId displayId, + const std::shared_ptr& inputApplicationHandle) { std::shared_ptr 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 +std::tuple InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp& token) { for (auto& [displayId, state] : mTouchStatesByDisplay) { for (TouchedWindow& w : state.windows) { @@ -5641,7 +5650,7 @@ InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp& 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& fromToken, const sp& toToken, @@ -5748,10 +5757,11 @@ bool InputDispatcher::transferTouchGesture(const sp& 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 InputDispatcher::findTouchedForegroundWindowLocked(int32_t displayId) const { +sp 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 InputDispatcher::findTouchedForegroundWindowLocked(int32_t // Binder call bool InputDispatcher::transferTouchOnDisplay(const sp& destChannelToken, - int32_t displayId) { + ui::LogicalDisplayId displayId) { sp fromToken; { // acquire lock std::scoped_lock _l(mLock); sp 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& 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: \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: \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: \n"; @@ -6076,9 +6088,8 @@ Result> InputDispatcher::createInputChannel(const return clientChannel; } -Result> InputDispatcher::createInputMonitor(int32_t displayId, - const std::string& name, - gui::Pid pid) { +Result> InputDispatcher::createInputMonitor( + ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid) { std::unique_ptr serverChannel; std::unique_ptr clientChannel; status_t result = InputChannel::openInputChannelPair(name, serverChannel, clientChannel); @@ -6089,7 +6100,7 @@ Result> 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& 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 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& 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>> handlesPerDisplay; + std::unordered_map>> handlesPerDisplay; for (const auto& info : update.windowInfos) { handlesPerDisplay.emplace(info.displayId, std::vector>()); handlesPerDisplay[info.displayId].push_back(sp::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& token, int32_t displayId, - DeviceId deviceId, int32_t pointerId) { +bool InputDispatcher::isPointerInWindow(const sp& 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 verifyInputEvent(const InputEvent& event) override; void setFocusedApplication( - int32_t displayId, + ui::LogicalDisplayId displayId, const std::shared_ptr& 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& fromToken, const sp& toToken, bool isDragDrop = false) override; - bool transferTouchOnDisplay(const sp& destChannelToken, int32_t displayId) override; + bool transferTouchOnDisplay(const sp& destChannelToken, + ui::LogicalDisplayId displayId) override; base::Result> createInputChannel( const std::string& name) override; void setFocusedWindow(const android::gui::FocusRequest&) override; - base::Result> createInputMonitor(int32_t displayId, + base::Result> createInputMonitor(ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid) override; status_t removeInputChannel(const sp& connectionToken) override; status_t pilferPointers(const sp& token) override; void requestPointerCapture(const sp& 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 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& token, int32_t displayId, DeviceId deviceId, - int32_t pointerId) override; + bool isPointerInWindow(const sp& token, ui::LogicalDisplayId displayId, + DeviceId deviceId, int32_t pointerId) override; void setInputMethodConnectionIsActive(bool isActive) override; @@ -249,17 +251,17 @@ private: std::shared_ptr mNextUnblockedEvent GUARDED_BY(mLock); sp 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 findOutsideTargetsLocked( - int32_t displayId, const sp& touchedWindow, + ui::LogicalDisplayId displayId, const sp& touchedWindow, int32_t pointerId) const REQUIRES(mLock); std::vector> 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 findTouchedForegroundWindowLocked(int32_t displayId) const - REQUIRES(mLock); + sp findTouchedForegroundWindowLocked( + ui::LogicalDisplayId displayId) const REQUIRES(mLock); std::shared_ptr getConnectionLocked(const sp& inputConnectionToken) const REQUIRES(mLock); @@ -283,7 +285,8 @@ private: std::optional findMonitorPidByTokenLocked(const sp& token) REQUIRES(mLock); // Input channels that will receive a copy of all input events sent to the provided display. - std::unordered_map> mGlobalMonitorsByDisplay GUARDED_BY(mLock); + std::unordered_map> mGlobalMonitorsByDisplay + GUARDED_BY(mLock); const HmacKeyManager mHmacKeyManager; const std::array 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 mTouchModePerDisplay GUARDED_BY(mLock); + std::map mTouchModePerDisplay + GUARDED_BY(mLock); class DispatcherWindowListener : public gui::WindowInfosListener { public: @@ -354,25 +358,26 @@ private: }; sp mWindowInfoListener; - std::unordered_map>> + std::unordered_map>> mWindowHandlesByDisplay GUARDED_BY(mLock); - std::unordered_map mDisplayInfos + std::unordered_map mDisplayInfos GUARDED_BY(mLock); void setInputWindowsLocked( const std::vector>& 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>& 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 getWindowHandleLocked( - const sp& windowHandleToken, std::optional displayId = {}) const - REQUIRES(mLock); + const sp& windowHandleToken, + std::optional displayId = {}) const REQUIRES(mLock); sp getWindowHandleLocked( const sp& windowHandle) const REQUIRES(mLock); - sp getFocusedWindowHandleLocked(int displayId) const - REQUIRES(mLock); + sp getFocusedWindowHandleLocked( + ui::LogicalDisplayId displayId) const REQUIRES(mLock); bool canWindowReceiveMotionLocked(const sp& window, const MotionEntry& motionEntry) const REQUIRES(mLock); @@ -387,20 +392,21 @@ private: */ void updateWindowHandlesForDisplayLocked( const std::vector>& inputWindowHandles, - int32_t displayId) REQUIRES(mLock); + ui::LogicalDisplayId displayId) REQUIRES(mLock); - std::unordered_map mTouchStatesByDisplay GUARDED_BY(mLock); + std::unordered_map mTouchStatesByDisplay + GUARDED_BY(mLock); std::unique_ptr mDragState GUARDED_BY(mLock); void setFocusedApplicationLocked( - int32_t displayId, + ui::LogicalDisplayId displayId, const std::shared_ptr& inputApplicationHandle) REQUIRES(mLock); // Focused applications. - std::unordered_map> + std::unordered_map> 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 mIneligibleDisplaysForPointerCapture GUARDED_BY(mLock); + std::vector 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 findFocusedWindowTargetLocked( nsecs_t currentTime, const EventEntry& entry, nsecs_t& nextWakeupTime, android::os::InputEventInjectionResult& outInjectionResult) REQUIRES(mLock); @@ -551,13 +558,13 @@ private: std::bitset pointerIds, std::optional firstDownTimeInTarget, std::vector& inputTargets) const REQUIRES(mLock); - void addGlobalMonitoringTargetsLocked(std::vector& inputTargets, int32_t displayId) - REQUIRES(mLock); + void addGlobalMonitoringTargetsLocked(std::vector& 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 mVerifiersByDisplay; + std::map mVerifiersByDisplay; // Returns a fallback KeyEntry that should be sent to the connection, if required. std::unique_ptr afterKeyEventLockedInterruptable( const std::shared_ptr& connection, DispatchEntry& dispatchEntry, const KeyEntry& keyEntry, bool handled) REQUIRES(mLock); // Find touched state and touched window by token. - std::tuple + std::tuple findTouchStateWindowAndDisplayLocked(const sp& 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 #include -#include #include #include #include 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) = 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& destChannelToken, int32_t displayId) = 0; + virtual bool transferTouchOnDisplay(const sp& 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> createInputMonitor(int32_t displayId, - const std::string& name, - gui::Pid pid) = 0; + virtual base::Result> 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& token, int32_t displayId, DeviceId deviceId, - int32_t pointerId) = 0; + virtual bool isPointerInWindow(const sp& 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& 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(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 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 displaysWithMousePointerAccelerationDisabled; + std::set 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 getDisplayViewportByUniqueId(const std::string& uniqueDisplayId) const; std::optional getDisplayViewportByPort(uint8_t physicalPort) const; - std::optional getDisplayViewportById(int32_t displayId) const; + std::optional getDisplayViewportById(ui::LogicalDisplayId displayId) const; void setDisplayViewports(const std::vector& viewports); void dump(std::string& dump) const; @@ -366,7 +367,7 @@ public: virtual std::vector 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 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& 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 #include #include -#include #include #include #include // 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 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 InputDevice::getAssociatedDisplayId() { +std::optional 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( + return first_in_mappers( [](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 associatedDisplayId = device->getAssociatedDisplayId(); + std::optional 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 getAssociatedDisplayId(); + std::optional 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 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 #include -#include #include #include #include @@ -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 CursorInputMapper::getAssociatedDisplayId() { +std::optional 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 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 getAssociatedDisplayId() override; + virtual std::optional 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 mDisplayId; + std::optional 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 updateExternalStylusState(const StylusState& state); - virtual std::optional getAssociatedDisplayId() { return std::nullopt; } + virtual std::optional 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 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 KeyboardInputMapper::getKeyboardLayoutInfo() const { @@ -457,7 +457,7 @@ void KeyboardInputMapper::updateLedStateForModifier(LedState& ledState, int32_t } } -std::optional KeyboardInputMapper::getAssociatedDisplayId() { +std::optional 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 getAssociatedDisplayId() override; + std::optional 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 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 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 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 out; if ((action == AKEY_EVENT_ACTION_DOWN && !(lastButtonState & buttonState) && @@ -88,7 +88,7 @@ bool isPointerDown(int32_t buttonState) { [[nodiscard]] std::list 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 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 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 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 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 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 TouchInputMapper::abortPointerMouse(nsecs_t when, nsecs_t readTime, @@ -3491,7 +3491,8 @@ std::list TouchInputMapper::abortPointerMouse(nsecs_t when, nsecs_t std::list 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 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 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 TouchInputMapper::getAssociatedDisplayId() { +std::optional 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 #include -#include -#include #include #include #include #include #include +#include #include #include #include @@ -186,7 +185,7 @@ public: [[nodiscard]] std::list timeoutExpired(nsecs_t when) override; [[nodiscard]] std::list updateExternalStylusState( const StylusState& state) override; - std::optional getAssociatedDisplayId() override; + std::optional 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 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 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 TouchpadInputMapper::reconfigure(nsecs_t when, @@ -321,7 +322,7 @@ std::list 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 resolvedViewport; std::optional boundsInLogicalDisplay; if (auto assocViewport = mDeviceContext.getAssociatedViewport(); assocViewport) { @@ -334,7 +335,7 @@ std::list 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 TouchpadInputMapper::processGestures(nsecs_t when, nsecs_t return out; } -std::optional TouchpadInputMapper::getAssociatedDisplayId() { +std::optional 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; - std::optional getAssociatedDisplayId() override; + std::optional 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 mDisplayId; + std::optional 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 reset(nsecs_t when); - void setDisplayId(std::optional displayId) { mDisplayId = displayId; } + void setDisplayId(std::optional displayId) { mDisplayId = displayId; } void setBoundsInLogicalDisplay(FloatRect bounds) { mBoundsInLogicalDisplay = bounds; } @@ -100,7 +100,7 @@ private: InputReaderContext& mReaderContext; const bool mEnableFlingStop; - std::optional mDisplayId; + std::optional 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( 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&, 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&, const KeyEvent&, uint32_t) override; std::optional dispatchUnhandledKey(const sp&, 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& 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 physicalPort, ViewportType type) { const bool isRotated = orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270; @@ -178,7 +178,7 @@ PointerCaptureRequest FakeInputReaderPolicy::setPointerCapture(const sp 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 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 getDisplayViewportByType(ViewportType type) const; std::optional 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 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& 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 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>& FakePointerController::getSpots() { +const std::map>& 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(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 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 -#include #include #include #include @@ -38,26 +37,26 @@ public: void setBounds(float minX, float minY, float maxX, float maxY); void clearBounds(); - const std::map>& getSpots(); + const std::map>& 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 mDisplayId; + std::optional mDisplayId; bool mIsPointerShown{false}; std::optional mIconStyle; std::optional mCustomIconStyle; - std::map> mSpotsByDisplay; - std::unordered_set mDisplaysToSkipScreenshot; + std::map> mSpotsByDisplay; + std::unordered_set 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 expectedDisplayId, + std::optional expectedDisplayId, std::optional expectedFlags) { std::unique_ptr 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(*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(*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(*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(*event); EXPECT_EQ(inTouchMode, touchModeEvent.isInTouchMode()); @@ -244,7 +244,7 @@ std::atomic FakeWindowHandle::sId{1}; FakeWindowHandle::FakeWindowHandle( const std::shared_ptr& inputApplicationHandle, const std::unique_ptr& dispatcher, const std::string name, - int32_t displayId, bool createInputChannel) + ui::LogicalDisplayId displayId, bool createInputChannel) : mName(name) { sp token; if (createInputChannel) { @@ -272,7 +272,7 @@ FakeWindowHandle::FakeWindowHandle( mInfo.inputConfig = InputConfig::DEFAULT; } -sp FakeWindowHandle::clone(int32_t displayId) { +sp FakeWindowHandle::clone(ui::LogicalDisplayId displayId) { sp handle = sp::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 timeline); void consumeEvent(android::InputEventType expectedEventType, int32_t expectedAction, - std::optional expectedDisplayId, + std::optional expectedDisplayId, std::optional expectedFlags); std::unique_ptr consumeMotion(); @@ -119,9 +119,10 @@ public: FakeWindowHandle(const std::shared_ptr& inputApplicationHandle, const std::unique_ptr& dispatcher, - const std::string name, int32_t displayId, bool createInputChannel = true); + const std::string name, ui::LogicalDisplayId displayId, + bool createInputChannel = true); - sp clone(int32_t displayId); + sp 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 expectedDisplayId = std::nullopt, - std::optional expectedFlags = std::nullopt) { + inline void consumeAnyMotionDown( + std::optional expectedDisplayId = std::nullopt, + std::optional 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 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::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 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 #include #include -#include #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 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 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(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(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 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(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(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 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(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 args = @@ -360,7 +360,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { Each(VariantWith( 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(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 args = @@ -412,13 +412,13 @@ TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { ASSERT_THAT(args, ElementsAre(VariantWith( 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 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( 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(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 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(4u, args.size()); - ASSERT_THAT(args, Each(VariantWith(WithDisplayId(ADISPLAY_ID_DEFAULT)))); + ASSERT_THAT(args, Each(VariantWith(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( 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(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(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(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(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(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(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 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(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(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(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 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 #include -#include #include #include @@ -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 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 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& 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::vectoronWindowInfosChanged({{*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 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 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 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 -#include #include 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 -#include #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 #include #include -#include #include #include @@ -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 getAssociatedDisplay() { + virtual std::optional 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 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 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 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(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 #include #include -#include #include #include #include @@ -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 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; 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 createViewports(std::vector displayIds) { +static std::vector createViewports(std::vector displayIds) { std::vector 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>> mCreatedControllers; - std::optional mPointerDisplayIdNotified; + std::optional mPointerDisplayIdNotified; std::shared_ptr 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::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 -#include #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 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 #include #include -#include #include #include #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(0, maxDisplays - 1); + const ui::LogicalDisplayId displayId{fdp.ConsumeIntegralInRange(0, maxDisplays - 1)}; const int32_t deviceId = fdp.ConsumeIntegralInRange(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(), eventTime, readTime, /*deviceId=*/fdp.ConsumeIntegral(), - AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_DEFAULT, + AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_DEFAULT, /*policyFlags=*/fdp.ConsumeIntegral(), AKEY_EVENT_ACTION_DOWN, /*flags=*/fdp.ConsumeIntegral(), 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 generateFuzzedWindow(FuzzedDataProvider& fdp, std::unique_ptr& dispatcher, - int32_t displayId) { + ui::LogicalDisplayId displayId) { static size_t windowNumber = 0; std::shared_ptr application = std::make_shared(); std::string windowName = android::base::StringPrintf("Win") + std::to_string(windowNumber++); @@ -101,10 +101,11 @@ sp generateFuzzedWindow(FuzzedDataProvider& fdp, return window; } -void randomizeWindows( - std::unordered_map>>& windowsPerDisplay, - FuzzedDataProvider& fdp, std::unique_ptr& dispatcher) { - const int32_t displayId = fdp.ConsumeIntegralInRange(0, MAX_RANDOM_DISPLAYS - 1); +void randomizeWindows(std::unordered_map>>& + windowsPerDisplay, + FuzzedDataProvider& fdp, std::unique_ptr& dispatcher) { + const ui::LogicalDisplayId displayId{ + fdp.ConsumeIntegralInRange(0, MAX_RANDOM_DISPLAYS - 1)}; std::vector>& windows = windowsPerDisplay[displayId]; fdp.PickValueInArray>({ @@ -148,7 +149,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { // Start InputDispatcher thread dispatcher->start(); - std::unordered_map>> windowsPerDisplay; + std::unordered_map>> 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(), - fdp->ConsumeIntegral()); + ui::LogicalDisplayId{ + fdp->ConsumeIntegral()}); }, [&]() -> void { reader->getKeyCodeForKeyLocation(fdp->ConsumeIntegral(), 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 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(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 #include #include +#include #include 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(snapshot.uniqueSequence); - snapshot.inputInfo.displayId = static_cast(snapshot.outputFilter.layerStack.id); + snapshot.inputInfo.displayId = + ui::LogicalDisplayId{static_cast(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(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); -- cgit v1.2.3-59-g8ed1b From cfbee5304f8fa7210e6f0816ca2ef2b6ab22c689 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 10 May 2024 13:41:35 -0700 Subject: Move ADISPLAY_ID_ definitions into LogicalDisplayId These will eventually replace the existing definitions as follows: ADISPLAY_ID_NONE -->> LogicalDisplayId::INVALID ADISPLAY_ID_DEFAULT -->> LogicalDisplayId::DEFAULT We are keeping the old definitions for now, to reduce the merge conflicts. These will be removed in subsequent CLs, after the frameworks/base and other repository patches go in. The constant "NONE" was renamed to "INVALID" to make it consistent with the Java definitions. Bug: 339106983 Test: m checkinput Change-Id: I0274be345159c85cb51fcea743d8acd3d298cd07 --- include/input/DisplayViewport.h | 6 +- include/input/Input.h | 2 +- include/input/InputDevice.h | 2 +- include/input/InputEventBuilders.h | 4 +- libs/gui/include/gui/DisplayInfo.h | 2 +- libs/gui/include/gui/WindowInfo.h | 2 +- libs/gui/tests/EndToEndNativeInputTest.cpp | 8 +- libs/input/Input.cpp | 8 +- libs/input/InputDevice.cpp | 2 +- libs/input/KeyCharacterMap.cpp | 7 +- libs/input/tests/InputEvent_test.cpp | 6 +- .../InputPublisherAndConsumerNoResampling_test.cpp | 28 +- .../input/tests/InputPublisherAndConsumer_test.cpp | 28 +- libs/input/tests/MotionPredictor_test.cpp | 7 +- libs/input/tests/TouchResampling_test.cpp | 10 +- libs/input/tests/VelocityTracker_test.cpp | 4 +- libs/input/tests/VerifiedInputEvent_test.cpp | 4 +- libs/ui/include/ui/LogicalDisplayId.h | 14 +- services/inputflinger/InputReaderBase.cpp | 2 +- services/inputflinger/PointerChoreographer.cpp | 8 +- services/inputflinger/PointerChoreographer.h | 2 +- .../benchmarks/InputDispatcher_benchmarks.cpp | 6 +- .../inputflinger/dispatcher/InputDispatcher.cpp | 28 +- services/inputflinger/dispatcher/InputState.h | 4 +- services/inputflinger/include/InputReaderBase.h | 4 +- services/inputflinger/include/NotifyArgs.h | 4 +- services/inputflinger/include/NotifyArgsBuilders.h | 4 +- services/inputflinger/reader/InputDevice.cpp | 3 +- .../mapper/CapturedTouchpadEventConverter.cpp | 2 +- .../reader/mapper/CursorInputMapper.cpp | 9 +- .../inputflinger/reader/mapper/CursorInputMapper.h | 2 +- .../reader/mapper/JoystickInputMapper.cpp | 2 +- .../reader/mapper/KeyboardInputMapper.cpp | 2 +- .../reader/mapper/RotaryEncoderInputMapper.cpp | 2 +- .../reader/mapper/TouchInputMapper.cpp | 10 +- .../inputflinger/reader/mapper/TouchInputMapper.h | 4 +- .../reader/mapper/TouchpadInputMapper.cpp | 5 +- .../reader/mapper/TouchpadInputMapper.h | 2 +- .../inputflinger/tests/CursorInputMapper_test.cpp | 5 +- .../inputflinger/tests/FakePointerController.cpp | 2 +- services/inputflinger/tests/FakeWindows.cpp | 8 +- services/inputflinger/tests/FakeWindows.h | 25 +- .../inputflinger/tests/GestureConverter_test.cpp | 237 +- .../tests/InputDeviceMetricsCollector_test.cpp | 2 +- .../inputflinger/tests/InputDispatcher_test.cpp | 2484 +++++++++++--------- .../tests/InputProcessorConverter_test.cpp | 2 +- .../inputflinger/tests/InputProcessor_test.cpp | 4 +- services/inputflinger/tests/InputReader_test.cpp | 29 +- services/inputflinger/tests/InputTracingTest.cpp | 2 +- .../inputflinger/tests/LatencyTracker_test.cpp | 2 +- .../tests/MultiTouchInputMapper_test.cpp | 2 +- .../tests/PointerChoreographer_test.cpp | 173 +- .../tests/PreferStylusOverTouch_test.cpp | 4 +- .../tests/TouchpadInputMapper_test.cpp | 2 +- .../tests/UnwantedInteractionBlocker_test.cpp | 6 +- .../tests/fuzzers/InputClassifierFuzzer.cpp | 2 +- 56 files changed, 1763 insertions(+), 1477 deletions(-) (limited to 'libs/ui') diff --git a/include/input/DisplayViewport.h b/include/input/DisplayViewport.h index 97c2ab8451..56294dd91a 100644 --- a/include/input/DisplayViewport.h +++ b/include/input/DisplayViewport.h @@ -46,7 +46,7 @@ enum class ViewportType : int32_t { * See com.android.server.display.DisplayViewport. */ struct DisplayViewport { - ui::LogicalDisplayId displayId; // ADISPLAY_ID_NONE if invalid + ui::LogicalDisplayId displayId; ui::Rotation orientation; int32_t logicalLeft; int32_t logicalTop; @@ -66,7 +66,7 @@ struct DisplayViewport { ViewportType type; DisplayViewport() - : displayId(ui::ADISPLAY_ID_NONE), + : displayId(ui::LogicalDisplayId::INVALID), orientation(ui::ROTATION_0), logicalLeft(0), logicalTop(0), @@ -101,7 +101,7 @@ struct DisplayViewport { inline bool isValid() const { return displayId.isValid(); } void setNonDisplayViewport(int32_t width, int32_t height) { - displayId = ui::ADISPLAY_ID_NONE; + displayId = ui::LogicalDisplayId::INVALID; orientation = ui::ROTATION_0; logicalLeft = 0; logicalTop = 0; diff --git a/include/input/Input.h b/include/input/Input.h index e939145bbf..3ca9c19876 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -553,7 +553,7 @@ protected: int32_t mId; DeviceId mDeviceId; uint32_t mSource; - ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_NONE}; + ui::LogicalDisplayId mDisplayId{ui::LogicalDisplayId::INVALID}; std::array mHmac; }; diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h index 8783d9c192..7d8c19e702 100644 --- a/include/input/InputDevice.h +++ b/include/input/InputDevice.h @@ -366,7 +366,7 @@ private: int32_t mKeyboardType; std::shared_ptr mKeyCharacterMap; std::optional mUsiVersion; - ui::LogicalDisplayId mAssociatedDisplayId{ui::ADISPLAY_ID_NONE}; + ui::LogicalDisplayId mAssociatedDisplayId{ui::LogicalDisplayId::INVALID}; bool mEnabled; bool mHasVibrator; diff --git a/include/input/InputEventBuilders.h b/include/input/InputEventBuilders.h index 837e70e114..25d35e9fe7 100644 --- a/include/input/InputEventBuilders.h +++ b/include/input/InputEventBuilders.h @@ -158,7 +158,7 @@ private: int32_t mSource; nsecs_t mDownTime; nsecs_t mEventTime; - ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId mDisplayId{ui::LogicalDisplayId::DEFAULT}; int32_t mActionButton{0}; int32_t mButtonState{0}; int32_t mFlags{0}; @@ -247,7 +247,7 @@ private: uint32_t mSource; nsecs_t mDownTime; nsecs_t mEventTime; - ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId mDisplayId{ui::LogicalDisplayId::DEFAULT}; uint32_t mPolicyFlags = DEFAULT_POLICY_FLAGS; int32_t mFlags{0}; int32_t mKeyCode{AKEYCODE_UNKNOWN}; diff --git a/libs/gui/include/gui/DisplayInfo.h b/libs/gui/include/gui/DisplayInfo.h index 7282b807a4..7094658379 100644 --- a/libs/gui/include/gui/DisplayInfo.h +++ b/libs/gui/include/gui/DisplayInfo.h @@ -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 { - ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID; // Logical display dimensions. int32_t logicalWidth = 0; diff --git a/libs/gui/include/gui/WindowInfo.h b/libs/gui/include/gui/WindowInfo.h index 3ea3f67bd8..eb3be5588a 100644 --- a/libs/gui/include/gui/WindowInfo.h +++ b/libs/gui/include/gui/WindowInfo.h @@ -234,7 +234,7 @@ struct WindowInfo : public Parcelable { Uid ownerUid = Uid::INVALID; std::string packageName; ftl::Flags inputConfig; - ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID; InputApplicationInfo applicationInfo; bool replaceTouchableRegionWithCrop = false; wp touchableRegionCropHandle; diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp index c0e79655f8..45e33902c7 100644 --- a/libs/gui/tests/EndToEndNativeInputTest.cpp +++ b/libs/gui/tests/EndToEndNativeInputTest.cpp @@ -59,8 +59,6 @@ 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 { namespace { @@ -313,7 +311,7 @@ public: reportedListener->wait(); } - void requestFocus(ui::LogicalDisplayId displayId = ADISPLAY_ID_DEFAULT) { + void requestFocus(ui::LogicalDisplayId displayId = ui::LogicalDisplayId::DEFAULT) { SurfaceComposerClient::Transaction t; FocusRequest request; request.token = mInputInfo.token; @@ -438,7 +436,7 @@ void injectTapOnDisplay(int x, int y, ui::LogicalDisplayId displayId) { } void injectTap(int x, int y) { - injectTapOnDisplay(x, y, ADISPLAY_ID_DEFAULT); + injectTapOnDisplay(x, y, ui::LogicalDisplayId::DEFAULT); } void injectKeyOnDisplay(uint32_t keycode, ui::LogicalDisplayId displayId) { @@ -451,7 +449,7 @@ void injectKeyOnDisplay(uint32_t keycode, ui::LogicalDisplayId displayId) { } void injectKey(uint32_t keycode) { - injectKeyOnDisplay(keycode, ADISPLAY_ID_NONE); + injectKeyOnDisplay(keycode, ui::LogicalDisplayId::INVALID); } TEST_F(InputSurfacesTest, can_receive_input) { diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 1178d02510..ee121d53fe 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -1198,7 +1198,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, - ui::ADISPLAY_ID_NONE, INVALID_HMAC); + ui::LogicalDisplayId::INVALID, INVALID_HMAC); mHasFocus = hasFocus; } @@ -1211,7 +1211,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, - ui::ADISPLAY_ID_NONE, INVALID_HMAC); + ui::LogicalDisplayId::INVALID, INVALID_HMAC); mPointerCaptureEnabled = pointerCaptureEnabled; } @@ -1224,7 +1224,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, - ui::ADISPLAY_ID_NONE, INVALID_HMAC); + ui::LogicalDisplayId::INVALID, INVALID_HMAC); mIsExiting = isExiting; mX = x; mY = y; @@ -1241,7 +1241,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, - ui::ADISPLAY_ID_NONE, INVALID_HMAC); + ui::LogicalDisplayId::INVALID, INVALID_HMAC); mIsInTouchMode = isInTouchMode; } diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp index 50239a1f9f..bc678103c2 100644 --- a/libs/input/InputDevice.cpp +++ b/libs/input/InputDevice.cpp @@ -169,7 +169,7 @@ std::string InputDeviceIdentifier::getCanonicalName() const { // --- InputDeviceInfo --- InputDeviceInfo::InputDeviceInfo() { - initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false, ui::ADISPLAY_ID_NONE); + initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false, ui::LogicalDisplayId::INVALID); } InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) diff --git a/libs/input/KeyCharacterMap.cpp b/libs/input/KeyCharacterMap.cpp index f75bf410f2..1cf5612d45 100644 --- a/libs/input/KeyCharacterMap.cpp +++ b/libs/input/KeyCharacterMap.cpp @@ -497,9 +497,10 @@ void KeyCharacterMap::addKey(Vector& outEvents, int32_t deviceId, int3 int32_t metaState, bool down, nsecs_t time) { outEvents.push(); KeyEvent& event = outEvents.editTop(); - 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); + event.initialize(InputEvent::nextId(), deviceId, AINPUT_SOURCE_KEYBOARD, + ui::LogicalDisplayId::INVALID, INVALID_HMAC, + down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP, 0, keyCode, 0, metaState, + 0, time, time); } void KeyCharacterMap::addMetaKeys(Vector& outEvents, diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index cc2574de9a..704ea46fe9 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -27,7 +27,7 @@ namespace android { // Default display id. -static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; +static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; static constexpr float EPSILON = MotionEvent::ROUNDING_PRECISION; @@ -858,8 +858,8 @@ MotionEvent createMotionEvent(int32_t source, uint32_t action, float x, float y, pointerCoords.back().setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, dy); nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC); MotionEvent event; - event.initialize(InputEvent::nextId(), /* deviceId */ 1, source, - /* displayId */ ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, action, + event.initialize(InputEvent::nextId(), /* deviceId */ 1, source, ui::LogicalDisplayId::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 7ae1cd8444..70529bbd39 100644 --- a/libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp @@ -55,7 +55,7 @@ struct PublishMotionArgs { const int32_t eventId; const int32_t deviceId = 1; const uint32_t source = AINPUT_SOURCE_TOUCHSCREEN; - const ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT; + const ui::LogicalDisplayId displayId = ui::LogicalDisplayId::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; @@ -445,7 +445,7 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeKeyEvent() { int32_t eventId = InputEvent::nextId(); constexpr int32_t deviceId = 1; constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD; - constexpr ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT; + constexpr ui::LogicalDisplayId displayId = ui::LogicalDisplayId::DEFAULT; constexpr std::array 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}; @@ -737,10 +737,10 @@ TEST_F(InputPublisherAndConsumerNoResamplingTest, ui::Transform identityTransform; status = - 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, + mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, + ui::LogicalDisplayId::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,10 +755,10 @@ TEST_F(InputPublisherAndConsumerNoResamplingTest, ui::Transform identityTransform; status = - 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, + mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, + ui::LogicalDisplayId::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"; @@ -777,10 +777,10 @@ TEST_F(InputPublisherAndConsumerNoResamplingTest, ui::Transform identityTransform; status = - 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, + mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, + ui::LogicalDisplayId::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 d0dbe2ad31..48512f7c6e 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -48,7 +48,7 @@ struct PublishMotionArgs { const int32_t eventId; const int32_t deviceId = 1; const uint32_t source = AINPUT_SOURCE_TOUCHSCREEN; - const ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT; + const ui::LogicalDisplayId displayId = ui::LogicalDisplayId::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; @@ -262,7 +262,7 @@ void InputPublisherAndConsumerTest::publishAndConsumeKeyEvent() { int32_t eventId = InputEvent::nextId(); constexpr int32_t deviceId = 1; constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD; - constexpr ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_DEFAULT; + constexpr ui::LogicalDisplayId displayId = ui::LogicalDisplayId::DEFAULT; constexpr std::array 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}; @@ -622,10 +622,10 @@ TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZer ui::Transform identityTransform; status = - 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, + mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, + ui::LogicalDisplayId::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"; @@ -639,10 +639,10 @@ TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessTha ui::Transform identityTransform; status = - 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, + mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, + ui::LogicalDisplayId::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"; @@ -661,10 +661,10 @@ TEST_F(InputPublisherAndConsumerTest, ui::Transform identityTransform; status = - 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, + mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, + ui::LogicalDisplayId::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/MotionPredictor_test.cpp b/libs/input/tests/MotionPredictor_test.cpp index 1c9f0c7399..d077760757 100644 --- a/libs/input/tests/MotionPredictor_test.cpp +++ b/libs/input/tests/MotionPredictor_test.cpp @@ -58,9 +58,10 @@ static MotionEvent getMotionEvent(int32_t action, float x, float y, } ui::Transform identityTransform; - 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, + event.initialize(InputEvent::nextId(), deviceId, AINPUT_SOURCE_STYLUS, + ui::LogicalDisplayId::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, identityTransform, /*downTime=*/100, eventTime.count(), pointerCount, diff --git a/libs/input/tests/TouchResampling_test.cpp b/libs/input/tests/TouchResampling_test.cpp index 1694cadfbe..2dc9fdb7f1 100644 --- a/libs/input/tests/TouchResampling_test.cpp +++ b/libs/input/tests/TouchResampling_test.cpp @@ -84,11 +84,11 @@ 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=*/ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, - action, /*actionButton=*/0, /*flags=*/0, /*edgeFlags=*/0, - AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, - identityTransform, /*xPrecision=*/0, /*yPrecision=*/0, + AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, + INVALID_HMAC, action, /*actionButton=*/0, /*flags=*/0, + /*edgeFlags=*/0, AMETA_NONE, /*buttonState=*/0, + MotionClassification::NONE, identityTransform, + /*xPrecision=*/0, /*yPrecision=*/0, AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, downTime, eventTime, properties.size(), properties.data(), diff --git a/libs/input/tests/VelocityTracker_test.cpp b/libs/input/tests/VelocityTracker_test.cpp index b4c4e1286d..f50a3cdb99 100644 --- a/libs/input/tests/VelocityTracker_test.cpp +++ b/libs/input/tests/VelocityTracker_test.cpp @@ -33,7 +33,7 @@ using android::base::StringPrintf; namespace android { -constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; // default display id +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; // default display id constexpr int32_t DEFAULT_POINTER_ID = 0; // pointer ID used for manually defined tests @@ -155,7 +155,7 @@ static std::vector createAxisScrollMotionEventStream( MotionEvent event; ui::Transform identityTransform; event.initialize(InputEvent::nextId(), /*deviceId=*/5, AINPUT_SOURCE_ROTARY_ENCODER, - ui::ADISPLAY_ID_NONE, INVALID_HMAC, AMOTION_EVENT_ACTION_SCROLL, + ui::LogicalDisplayId::INVALID, 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 40cfaaeb05..df5fe9d2d0 100644 --- a/libs/input/tests/VerifiedInputEvent_test.cpp +++ b/libs/input/tests/VerifiedInputEvent_test.cpp @@ -23,7 +23,7 @@ namespace android { static KeyEvent getKeyEventWithFlags(int32_t flags) { KeyEvent event; event.initialize(InputEvent::nextId(), /*deviceId=*/2, AINPUT_SOURCE_GAMEPAD, - ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, flags, + ui::LogicalDisplayId::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,7 +44,7 @@ static MotionEvent getMotionEventWithFlags(int32_t flags) { transform.set({2, 0, 4, 0, 3, 5, 0, 0, 1}); ui::Transform identity; event.initialize(InputEvent::nextId(), /*deviceId=*/0, AINPUT_SOURCE_MOUSE, - ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, + ui::LogicalDisplayId::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, diff --git a/libs/ui/include/ui/LogicalDisplayId.h b/libs/ui/include/ui/LogicalDisplayId.h index 3e504e7101..d745758f0c 100644 --- a/libs/ui/include/ui/LogicalDisplayId.h +++ b/libs/ui/include/ui/LogicalDisplayId.h @@ -35,10 +35,20 @@ struct LogicalDisplayId : ftl::Constructible, constexpr bool isValid() const { return val() >= 0; } std::string toString() const { return std::to_string(val()); } + + static const LogicalDisplayId INVALID; + static const LogicalDisplayId DEFAULT; }; -constexpr LogicalDisplayId ADISPLAY_ID_NONE{-1}; -constexpr LogicalDisplayId ADISPLAY_ID_DEFAULT{0}; +constexpr inline LogicalDisplayId LogicalDisplayId::INVALID{-1}; +constexpr inline LogicalDisplayId LogicalDisplayId::DEFAULT{0}; + +/** + * Deprecated! Use LogicalDisplayId::INVALID / LogicalDisplayId::DEFAULT instead. + * TODO(b/339106983): remove these. + */ +[[deprecated]] constexpr LogicalDisplayId ADISPLAY_ID_NONE{-1}; +[[deprecated]] constexpr LogicalDisplayId ADISPLAY_ID_DEFAULT{0}; inline std::ostream& operator<<(std::ostream& stream, LogicalDisplayId displayId) { return stream << displayId.val(); diff --git a/services/inputflinger/InputReaderBase.cpp b/services/inputflinger/InputReaderBase.cpp index 29b487f1d2..6b2627ce96 100644 --- a/services/inputflinger/InputReaderBase.cpp +++ b/services/inputflinger/InputReaderBase.cpp @@ -68,7 +68,7 @@ std::optional InputReaderConfiguration::getDisplayViewportByTyp if (currentViewport.type == type) { if (!result || (type == ViewportType::INTERNAL && - currentViewport.displayId == ui::ADISPLAY_ID_DEFAULT)) { + currentViewport.displayId == ui::LogicalDisplayId::DEFAULT)) { result = std::make_optional(currentViewport); } count++; diff --git a/services/inputflinger/PointerChoreographer.cpp b/services/inputflinger/PointerChoreographer.cpp index d6c6f938d4..8a1eed603f 100644 --- a/services/inputflinger/PointerChoreographer.cpp +++ b/services/inputflinger/PointerChoreographer.cpp @@ -101,8 +101,8 @@ PointerChoreographer::PointerChoreographer(InputListenerInterface& listener, }), mNextListener(listener), mPolicy(policy), - mDefaultMouseDisplayId(ui::ADISPLAY_ID_DEFAULT), - mNotifiedPointerDisplayId(ui::ADISPLAY_ID_NONE), + mDefaultMouseDisplayId(ui::LogicalDisplayId::DEFAULT), + mNotifiedPointerDisplayId(ui::LogicalDisplayId::INVALID), mShowTouchesEnabled(false), mStylusPointerIconEnabled(false) {} @@ -236,7 +236,7 @@ NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMo } void PointerChoreographer::processDrawingTabletEventLocked(const android::NotifyMotionArgs& args) { - if (args.displayId == ui::ADISPLAY_ID_NONE) { + if (args.displayId == ui::LogicalDisplayId::INVALID) { return; } @@ -557,7 +557,7 @@ PointerChoreographer::PointerDisplayChange PointerChoreographer::updatePointerCo PointerChoreographer::PointerDisplayChange PointerChoreographer::calculatePointerDisplayChangeToNotify() { - ui::LogicalDisplayId displayIdToNotify = ui::ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayIdToNotify = ui::LogicalDisplayId::INVALID; FloatPoint cursorPosition = {0, 0}; if (const auto it = mMousePointersByDisplay.find(mDefaultMouseDisplayId); it != mMousePointersByDisplay.end()) { diff --git a/services/inputflinger/PointerChoreographer.h b/services/inputflinger/PointerChoreographer.h index fda5f5231e..12316c0427 100644 --- a/services/inputflinger/PointerChoreographer.h +++ b/services/inputflinger/PointerChoreographer.h @@ -57,7 +57,7 @@ public: virtual void setDefaultMouseDisplayId(ui::LogicalDisplayId displayId) = 0; virtual void setDisplayViewports(const std::vector& viewports) = 0; virtual std::optional getViewportForPointerDevice( - ui::LogicalDisplayId associatedDisplayId = ui::ADISPLAY_ID_NONE) = 0; + ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0; virtual FloatPoint getMouseCursorPosition(ui::LogicalDisplayId displayId) = 0; virtual void setShowTouchesEnabled(bool enabled) = 0; virtual void setStylusPointerIconEnabled(bool enabled) = 0; diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index 66e4a297dd..96c8640e2f 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -37,7 +37,7 @@ namespace { constexpr DeviceId DEVICE_ID = 1; // An arbitrary display id -constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 5s; @@ -62,7 +62,7 @@ static MotionEvent generateMotionEvent() { ui::Transform identityTransform; MotionEvent event; event.initialize(IInputConstants::INVALID_INPUT_EVENT_ID, DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, - ui::ADISPLAY_ID_DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, + ui::LogicalDisplayId::DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, /* actionButton */ 0, /* flags */ 0, /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, identityTransform, /* xPrecision */ 0, @@ -88,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, ui::ADISPLAY_ID_DEFAULT, + DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::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/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 8e0da1470e..dae2b6119c 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -918,9 +918,9 @@ InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy, mDispatchFrozen(false), mInputFilterEnabled(false), mMaximumObscuringOpacityForTouch(1.0f), - mFocusedDisplayId(ui::ADISPLAY_ID_DEFAULT), + mFocusedDisplayId(ui::LogicalDisplayId::DEFAULT), mWindowTokenWithPointerCapture(nullptr), - mAwaitedApplicationDisplayId(ui::ADISPLAY_ID_NONE), + mAwaitedApplicationDisplayId(ui::LogicalDisplayId::INVALID), mLatencyAggregator(), mLatencyTracker(&mLatencyAggregator) { mLooper = sp::make(false); @@ -2201,7 +2201,7 @@ void InputDispatcher::resetNoFocusedWindowTimeoutLocked() { * Focused display is the display that the user most recently interacted with. */ ui::LogicalDisplayId InputDispatcher::getTargetDisplayId(const EventEntry& entry) { - ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; + ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID}; switch (entry.type) { case EventEntry::Type::KEY: { const KeyEntry& keyEntry = static_cast(entry); @@ -2221,10 +2221,10 @@ ui::LogicalDisplayId 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 ui::ADISPLAY_ID_NONE; + return ui::LogicalDisplayId::INVALID; } } - return displayId == ui::ADISPLAY_ID_NONE ? mFocusedDisplayId : displayId; + return displayId == ui::LogicalDisplayId::INVALID ? mFocusedDisplayId : displayId; } bool InputDispatcher::shouldWaitToSendKeyLocked(nsecs_t currentTime, @@ -2829,7 +2829,7 @@ std::vector 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 >= ui::ADISPLAY_ID_DEFAULT) { + if (displayId >= ui::LogicalDisplayId::DEFAULT) { tempTouchState.clearWindowsWithoutPointers(); mTouchStatesByDisplay[displayId] = tempTouchState; } else { @@ -4862,8 +4862,8 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev isFromSource(event->getSource(), AINPUT_SOURCE_CLASS_POINTER); // If a pointer event has no displayId specified, inject it to the default display. const ui::LogicalDisplayId displayId = - isPointerEvent && (event->getDisplayId() == ui::ADISPLAY_ID_NONE) - ? ui::ADISPLAY_ID_DEFAULT + isPointerEvent && (event->getDisplayId() == ui::LogicalDisplayId::INVALID) + ? ui::LogicalDisplayId::DEFAULT : event->getDisplayId(); int32_t flags = motionEvent.getFlags(); @@ -4890,9 +4890,9 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev // events for consistency and print an error. An inconsistent event sent from // InputFilter could cause a crash in the later stages of dispatching pipeline. auto [it, _] = - mInputFilterVerifiersByDisplay - .try_emplace(displayId, - StringPrintf("Injection on %" PRId32, displayId)); + mInputFilterVerifiersByDisplay.try_emplace(displayId, + std::string("Injection on ") + + displayId.toString()); InputVerifier& verifier = it->second; Result result = @@ -5523,7 +5523,7 @@ void InputDispatcher::setFocusedDisplay(ui::LogicalDisplayId displayId) { options(CancelationOptions::Mode::CANCEL_NON_POINTER_EVENTS, "The display which contains this window no longer has focus.", traceContext.getTracker()); - options.displayId = ui::ADISPLAY_ID_NONE; + options.displayId = ui::LogicalDisplayId::INVALID; synthesizeCancelationEventsForWindowLocked(windowHandle, options); } mFocusedDisplayId = displayId; @@ -5675,7 +5675,7 @@ InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp& token) } } } - return std::make_tuple(nullptr, nullptr, ui::ADISPLAY_ID_DEFAULT); + return std::make_tuple(nullptr, nullptr, ui::LogicalDisplayId::DEFAULT); } bool InputDispatcher::transferTouchGesture(const sp& fromToken, const sp& toToken, @@ -6125,7 +6125,7 @@ Result> InputDispatcher::createInputMonitor( { // acquire lock std::scoped_lock _l(mLock); - if (displayId < ui::ADISPLAY_ID_DEFAULT) { + if (displayId < ui::LogicalDisplayId::DEFAULT) { return base::Error(BAD_VALUE) << "Attempted to create input monitor with name " << name << " without a specified display."; } diff --git a/services/inputflinger/dispatcher/InputState.h b/services/inputflinger/dispatcher/InputState.h index ab83ef911d..2808ba71bd 100644 --- a/services/inputflinger/dispatcher/InputState.h +++ b/services/inputflinger/dispatcher/InputState.h @@ -90,7 +90,7 @@ private: struct KeyMemento { DeviceId deviceId; uint32_t source; - ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; + ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID}; int32_t keyCode; int32_t scanCode; int32_t metaState; @@ -102,7 +102,7 @@ private: struct MotionMemento { DeviceId deviceId; uint32_t source; - ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; + ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID}; int32_t flags; float xPrecision; float yPrecision; diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h index e5c3aa08d1..c62fc7d98e 100644 --- a/services/inputflinger/include/InputReaderBase.h +++ b/services/inputflinger/include/InputReaderBase.h @@ -243,7 +243,7 @@ struct InputReaderConfiguration { InputReaderConfiguration() : virtualKeyQuietTime(0), - defaultPointerDisplayId(ui::ADISPLAY_ID_DEFAULT), + defaultPointerDisplayId(ui::LogicalDisplayId::DEFAULT), mousePointerSpeed(0), displaysWithMousePointerAccelerationDisabled(), pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, @@ -472,7 +472,7 @@ public: * be used as the range of possible values for pointing devices, like mice and touchpads. */ virtual std::optional getPointerViewportForAssociatedDisplay( - ui::LogicalDisplayId associatedDisplayId = ui::ADISPLAY_ID_NONE) = 0; + ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0; }; } // namespace android diff --git a/services/inputflinger/include/NotifyArgs.h b/services/inputflinger/include/NotifyArgs.h index 865f3d0302..db417cf830 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; - ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; + ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID}; uint32_t policyFlags; int32_t action; int32_t flags; @@ -91,7 +91,7 @@ struct NotifyMotionArgs { int32_t deviceId; uint32_t source; - ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; + ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID}; uint32_t policyFlags; int32_t action; int32_t actionButton; diff --git a/services/inputflinger/include/NotifyArgsBuilders.h b/services/inputflinger/include/NotifyArgsBuilders.h index 1ba0cfd20a..cae638f7bf 100644 --- a/services/inputflinger/include/NotifyArgsBuilders.h +++ b/services/inputflinger/include/NotifyArgsBuilders.h @@ -150,7 +150,7 @@ private: uint32_t mSource; nsecs_t mDownTime; nsecs_t mEventTime; - ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId mDisplayId{ui::LogicalDisplayId::DEFAULT}; uint32_t mPolicyFlags = DEFAULT_POLICY_FLAGS; int32_t mActionButton{0}; int32_t mButtonState{0}; @@ -229,7 +229,7 @@ private: uint32_t mSource; nsecs_t mDownTime; nsecs_t mEventTime; - ui::LogicalDisplayId mDisplayId{ui::ADISPLAY_ID_DEFAULT}; + ui::LogicalDisplayId mDisplayId{ui::LogicalDisplayId::DEFAULT}; uint32_t mPolicyFlags = DEFAULT_POLICY_FLAGS; int32_t mFlags{0}; int32_t mKeyCode{AKEYCODE_UNKNOWN}; diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index 15586e2c4b..956484c931 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -442,7 +442,8 @@ std::list InputDevice::updateExternalStylusState(const StylusState& InputDeviceInfo InputDevice::getDeviceInfo() { InputDeviceInfo outDeviceInfo; outDeviceInfo.initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias, mIsExternal, - mHasMic, getAssociatedDisplayId().value_or(ui::ADISPLAY_ID_NONE), + mHasMic, + getAssociatedDisplayId().value_or(ui::LogicalDisplayId::INVALID), {mShouldSmoothScroll}, isEnabled()); for_each_mapper( diff --git a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp index 21dec6ffa6..09a5f08a23 100644 --- a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp +++ b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp @@ -278,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, - ui::ADISPLAY_ID_NONE, /*policyFlags=*/POLICY_FLAG_WAKE, action, + ui::LogicalDisplayId::INVALID, /*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 d5fe0400b2..c67314dbcf 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -488,13 +488,13 @@ void CursorInputMapper::configureOnChangePointerSpeed(const InputReaderConfigura if (mEnableNewMousePointerBallistics) { mNewPointerVelocityControl.setAccelerationEnabled( config.displaysWithMousePointerAccelerationDisabled.count( - mDisplayId.value_or(ui::ADISPLAY_ID_NONE)) == 0); + mDisplayId.value_or(ui::LogicalDisplayId::INVALID)) == 0); mNewPointerVelocityControl.setCurve( createAccelerationCurveForPointerSensitivity(config.mousePointerSpeed)); } else { mOldPointerVelocityControl.setParameters( (config.displaysWithMousePointerAccelerationDisabled.count( - mDisplayId.value_or(ui::ADISPLAY_ID_NONE)) == 0) + mDisplayId.value_or(ui::LogicalDisplayId::INVALID)) == 0) ? config.pointerVelocityControlParameters : FLAT_VELOCITY_CONTROL_PARAMS); } @@ -506,7 +506,7 @@ void CursorInputMapper::configureOnChangePointerSpeed(const InputReaderConfigura void CursorInputMapper::configureOnChangeDisplayInfo(const InputReaderConfiguration& config) { const bool isPointer = mParameters.mode == Parameters::Mode::POINTER; - mDisplayId = ui::ADISPLAY_ID_NONE; + mDisplayId = ui::LogicalDisplayId::INVALID; std::optional resolvedViewport; if (auto assocViewport = mDeviceContext.getAssociatedViewport(); assocViewport) { // This InputDevice is associated with a viewport. @@ -518,7 +518,8 @@ 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(ui::ADISPLAY_ID_NONE) : std::nullopt; + mDisplayId = + resolvedViewport ? std::make_optional(ui::LogicalDisplayId::INVALID) : std::nullopt; } mOrientation = (mParameters.orientationAware && mParameters.hasAssociatedDisplay) || diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h index e45105ad3a..75ca9c00a8 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.h +++ b/services/inputflinger/reader/mapper/CursorInputMapper.h @@ -113,7 +113,7 @@ private: SimpleVelocityControl mWheelYVelocityControl; // 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. + // LogicalDisplayId::INVALID to target the focused display. If there is no display target (i.e. // std::nullopt), all events will be ignored. std::optional mDisplayId; ui::Rotation mOrientation{ui::ROTATION_0}; diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp index 7fcff951b0..5ce4d30bb3 100644 --- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp +++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp @@ -341,7 +341,7 @@ std::list 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; - ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID; if (getDeviceContext().getAssociatedViewport()) { displayId = getDeviceContext().getAssociatedViewport()->displayId; } diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp index be8d183215..21245555a2 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp @@ -114,7 +114,7 @@ ui::LogicalDisplayId KeyboardInputMapper::getDisplayId() { if (mViewport) { return mViewport->displayId; } - return ui::ADISPLAY_ID_NONE; + return ui::LogicalDisplayId::INVALID; } std::optional KeyboardInputMapper::getKeyboardLayoutInfo() const { diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp index a3206c2844..0ddbc06890 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp @@ -125,7 +125,7 @@ std::list 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. - ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE; + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID; if (mOrientation == ui::ROTATION_180) { scroll = -scroll; diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index 489bea8959..8b4b691a45 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -2646,7 +2646,7 @@ std::list TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns PointerCoords pointerCoords; pointerCoords.clear(); out.push_back(NotifyMotionArgs(getContext()->getNextId(), when, readTime, getDeviceId(), - mSource, ui::ADISPLAY_ID_NONE, policyFlags, + mSource, ui::LogicalDisplayId::INVALID, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, flags, metaState, buttonState, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties, @@ -3477,7 +3477,8 @@ std::list TouchInputMapper::dispatchPointerMouse(nsecs_t when, nsecs hovering = false; } - return dispatchPointerSimple(when, readTime, policyFlags, down, hovering, ui::ADISPLAY_ID_NONE); + return dispatchPointerSimple(when, readTime, policyFlags, down, hovering, + ui::LogicalDisplayId::INVALID); } std::list TouchInputMapper::abortPointerMouse(nsecs_t when, nsecs_t readTime, @@ -3684,7 +3685,8 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion( source |= AINPUT_SOURCE_BLUETOOTH_STYLUS; } - const ui::LogicalDisplayId displayId = getAssociatedDisplayId().value_or(ui::ADISPLAY_ID_NONE); + const ui::LogicalDisplayId displayId = + getAssociatedDisplayId().value_or(ui::LogicalDisplayId::INVALID); float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION; @@ -3961,7 +3963,7 @@ bool TouchInputMapper::markSupportedKeyCodes(uint32_t sourceMask, std::optional TouchInputMapper::getAssociatedDisplayId() { if (mParameters.hasAssociatedDisplay) { if (mDeviceMode == DeviceMode::POINTER) { - return ui::ADISPLAY_ID_NONE; + return ui::LogicalDisplayId::INVALID; } else { return std::make_optional(mViewport.displayId); } diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index 0c9ffa24d0..b24f2ff8da 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -705,7 +705,7 @@ private: // Values reported for the last pointer event. uint32_t source; - ui::LogicalDisplayId displayId{ui::ADISPLAY_ID_NONE}; + ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID}; float lastCursorX; float lastCursorY; @@ -718,7 +718,7 @@ private: hovering = false; downTime = 0; source = 0; - displayId = ui::ADISPLAY_ID_NONE; + displayId = ui::LogicalDisplayId::INVALID; lastCursorX = 0.f; lastCursorY = 0.f; } diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp index e157862f85..2a580c9e4f 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp @@ -322,7 +322,7 @@ std::list TouchpadInputMapper::reconfigure(nsecs_t when, } if (!changes.any() || changes.test(InputReaderConfiguration::Change::DISPLAY_INFO)) { - mDisplayId = ui::ADISPLAY_ID_NONE; + mDisplayId = ui::LogicalDisplayId::INVALID; std::optional resolvedViewport; std::optional boundsInLogicalDisplay; if (auto assocViewport = mDeviceContext.getAssociatedViewport(); assocViewport) { @@ -335,7 +335,8 @@ std::list 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(ui::ADISPLAY_ID_NONE) : std::nullopt; + mDisplayId = resolvedViewport ? std::make_optional(ui::LogicalDisplayId::INVALID) + : std::nullopt; } mGestureConverter.setDisplayId(mDisplayId); diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h index f27895fd9c..546fa5bb9c 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h @@ -107,7 +107,7 @@ private: std::set mPalmTrackingIds; // 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. + // LogicalDisplayId::INVALID to target the focused display. If there is no display target (i.e. // std::nullopt), all events will be ignored. std::optional mDisplayId; diff --git a/services/inputflinger/tests/CursorInputMapper_test.cpp b/services/inputflinger/tests/CursorInputMapper_test.cpp index 72b5573047..83074ff899 100644 --- a/services/inputflinger/tests/CursorInputMapper_test.cpp +++ b/services/inputflinger/tests/CursorInputMapper_test.cpp @@ -50,7 +50,7 @@ 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 ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::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,8 @@ TEST_F(CursorInputMapperUnitTest, ConfigureDisplayIdNoAssociatedViewport) { EXPECT_THAT(args, ElementsAre(VariantWith( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), - WithSource(AINPUT_SOURCE_MOUSE), WithDisplayId(ui::ADISPLAY_ID_NONE), + WithSource(AINPUT_SOURCE_MOUSE), + WithDisplayId(ui::LogicalDisplayId::INVALID), WithCoords(0.0f, 0.0f))))); } diff --git a/services/inputflinger/tests/FakePointerController.cpp b/services/inputflinger/tests/FakePointerController.cpp index 731a28668f..2bb57b3e81 100644 --- a/services/inputflinger/tests/FakePointerController.cpp +++ b/services/inputflinger/tests/FakePointerController.cpp @@ -53,7 +53,7 @@ FloatPoint FakePointerController::getPosition() const { ui::LogicalDisplayId FakePointerController::getDisplayId() const { if (!mEnabled || !mDisplayId) { - return ui::ADISPLAY_ID_NONE; + return ui::LogicalDisplayId::INVALID; } return *mDisplayId; } diff --git a/services/inputflinger/tests/FakeWindows.cpp b/services/inputflinger/tests/FakeWindows.cpp index c800d6ad4e..b116521155 100644 --- a/services/inputflinger/tests/FakeWindows.cpp +++ b/services/inputflinger/tests/FakeWindows.cpp @@ -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(ui::ADISPLAY_ID_NONE, event->getDisplayId()) + ASSERT_EQ(ui::LogicalDisplayId::INVALID, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; FocusEvent& focusEvent = static_cast(*event); @@ -165,7 +165,7 @@ void FakeInputReceiver::consumeCaptureEvent(bool hasCapture) { ASSERT_EQ(InputEventType::CAPTURE, event->getType()) << "Instead of CaptureEvent, got " << *event; - ASSERT_EQ(ui::ADISPLAY_ID_NONE, event->getDisplayId()) + ASSERT_EQ(ui::LogicalDisplayId::INVALID, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; const auto& captureEvent = static_cast(*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(ui::ADISPLAY_ID_NONE, event->getDisplayId()) + EXPECT_EQ(ui::LogicalDisplayId::INVALID, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; const auto& dragEvent = static_cast(*event); @@ -192,7 +192,7 @@ void FakeInputReceiver::consumeTouchModeEvent(bool inTouchMode) { ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType()) << "Instead of TouchModeEvent, got " << *event; - ASSERT_EQ(ui::ADISPLAY_ID_NONE, event->getDisplayId()) + ASSERT_EQ(ui::LogicalDisplayId::INVALID, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; const auto& touchModeEvent = static_cast(*event); EXPECT_EQ(inTouchMode, touchModeEvent.isInTouchMode()); diff --git a/services/inputflinger/tests/FakeWindows.h b/services/inputflinger/tests/FakeWindows.h index 8a40337db4..36a8f0066e 100644 --- a/services/inputflinger/tests/FakeWindows.h +++ b/services/inputflinger/tests/FakeWindows.h @@ -261,22 +261,24 @@ public: } inline void consumeMotionCancel( - ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId expectedDisplayId = ui::LogicalDisplayId::DEFAULT, int32_t expectedFlags = 0) { consumeMotionEvent(testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags | AMOTION_EVENT_FLAG_CANCELED))); } - inline void consumeMotionMove(ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, - int32_t expectedFlags = 0) { + inline void consumeMotionMove( + ui::LogicalDisplayId expectedDisplayId = ui::LogicalDisplayId::DEFAULT, + int32_t expectedFlags = 0) { consumeMotionEvent(testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags))); } - inline void consumeMotionDown(ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, - int32_t expectedFlags = 0) { + inline void consumeMotionDown( + ui::LogicalDisplayId expectedDisplayId = ui::LogicalDisplayId::DEFAULT, + int32_t expectedFlags = 0) { consumeAnyMotionDown(expectedDisplayId, expectedFlags); } @@ -292,7 +294,8 @@ public: } inline void consumeMotionPointerDown( - int32_t pointerIdx, ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, + int32_t pointerIdx, + ui::LogicalDisplayId expectedDisplayId = ui::LogicalDisplayId::DEFAULT, int32_t expectedFlags = 0) { const int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); @@ -302,7 +305,8 @@ public: } inline void consumeMotionPointerUp( - int32_t pointerIdx, ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, + int32_t pointerIdx, + ui::LogicalDisplayId expectedDisplayId = ui::LogicalDisplayId::DEFAULT, int32_t expectedFlags = 0) { const int32_t action = AMOTION_EVENT_ACTION_POINTER_UP | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); @@ -311,15 +315,16 @@ public: WithFlags(expectedFlags))); } - inline void consumeMotionUp(ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, - int32_t expectedFlags = 0) { + inline void consumeMotionUp( + ui::LogicalDisplayId expectedDisplayId = ui::LogicalDisplayId::DEFAULT, + int32_t expectedFlags = 0) { consumeMotionEvent(testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithDisplayId(expectedDisplayId), WithFlags(expectedFlags))); } inline void consumeMotionOutside( - ui::LogicalDisplayId expectedDisplayId = ui::ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId expectedDisplayId = ui::LogicalDisplayId::DEFAULT, int32_t expectedFlags = 0) { consumeMotionEvent(testing::AllOf(WithMotionAction(AMOTION_EVENT_ACTION_OUTSIDE), WithDisplayId(expectedDisplayId), diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index 1132e9284c..2f9036f2b4 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -45,7 +45,6 @@ const auto TOUCHPAD_PALM_REJECTION_V2 = } // namespace -using android::ui::ADISPLAY_ID_DEFAULT; using testing::AllOf; using testing::Each; using testing::ElementsAre; @@ -93,7 +92,7 @@ protected: TEST_F(GestureConverterTest, Move) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list args = @@ -107,9 +106,9 @@ TEST_F(GestureConverterTest, Move) { WithRelativeMotion(-5, 10), WithButtonState(0), WithPressure(0.0f))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER. args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); @@ -118,14 +117,14 @@ TEST_F(GestureConverterTest, Move) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0), WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, Move_Rotated) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); converter.setOrientation(ui::ROTATION_90); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list args = @@ -139,15 +138,15 @@ TEST_F(GestureConverterTest, Move_Rotated) { WithRelativeMotion(10, 5), WithButtonState(0), WithPressure(0.0f))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, ButtonsChange) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); // Press left and right buttons at once Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -170,9 +169,9 @@ TEST_F(GestureConverterTest, ButtonsChange) { WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); // Then release the left button Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -185,7 +184,7 @@ TEST_F(GestureConverterTest, ButtonsChange) { WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); // Finally release the right button Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -201,15 +200,15 @@ TEST_F(GestureConverterTest, ButtonsChange) { VariantWith( WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list args = @@ -223,13 +222,13 @@ TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) { VariantWith( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT)))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); } TEST_F(GestureConverterTest, DragWithButton) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); // Press the button Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -246,9 +245,9 @@ TEST_F(GestureConverterTest, DragWithButton) { WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); // Move Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); @@ -258,7 +257,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(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); // Release the button Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -274,16 +273,16 @@ TEST_F(GestureConverterTest, DragWithButton) { VariantWith( WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, Scroll) { const nsecs_t downTime = 12345; InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list args = @@ -303,7 +302,7 @@ TEST_F(GestureConverterTest, Scroll) { AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); @@ -314,7 +313,7 @@ TEST_F(GestureConverterTest, Scroll) { WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, GESTURES_FLING_START); @@ -332,8 +331,9 @@ TEST_F(GestureConverterTest, Scroll) { WithCoords(0, 0), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list args = @@ -360,7 +360,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { Each(VariantWith( AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); @@ -370,7 +370,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { WithGestureScrollDistance(0, 5, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, GESTURES_FLING_START); @@ -387,14 +387,15 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { WithCoords(0, 0), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list args = @@ -412,13 +413,13 @@ TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { ASSERT_THAT(args, ElementsAre(VariantWith( AllOf(WithMotionClassification(MotionClassification::NONE), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list args = @@ -443,7 +444,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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, /*dy=*/0); @@ -464,7 +465,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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, /*dy=*/5); @@ -491,7 +492,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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, /* dy= */ 10); @@ -502,7 +503,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { Each(VariantWith( AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); // Three fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. @@ -548,7 +549,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))); + WithDisplayId(ui::LogicalDisplayId::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()); @@ -589,22 +590,24 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { WithCoords(0, 0), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, /* dy= */ 10); std::list args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(4u, args.size()); - ASSERT_THAT(args, Each(VariantWith(WithDisplayId(ui::ADISPLAY_ID_DEFAULT)))); + ASSERT_THAT(args, + Each(VariantWith(WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); // Three fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. @@ -648,7 +651,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))); + WithDisplayId(ui::LogicalDisplayId::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); @@ -674,13 +677,14 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))), VariantWith( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))))); - ASSERT_THAT(args, Each(VariantWith(WithDisplayId(ADISPLAY_ID_DEFAULT)))); + ASSERT_THAT(args, + Each(VariantWith(WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); } TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 10, /* dy= */ 0); @@ -691,7 +695,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { Each(VariantWith( AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); // Four fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. @@ -746,7 +750,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), WithPointerCount(4u), WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))); + WithDisplayId(ui::LogicalDisplayId::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); @@ -798,14 +802,15 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { WithCoords(0, 0), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, Pinch_Inwards) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_START); @@ -825,7 +830,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { AllOf(WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); @@ -837,7 +842,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithGesturePinchScaleFactor(0.8f, EPSILON), WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0), WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_END); @@ -860,14 +865,15 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithCoords(0, 0), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, Pinch_Outwards) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_START); @@ -887,7 +893,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { AllOf(WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1.1, GESTURES_ZOOM_UPDATE); @@ -899,7 +905,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithGesturePinchScaleFactor(1.1f, EPSILON), WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0), WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_END); @@ -922,14 +928,15 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithCoords(0, 0), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, GESTURES_ZOOM_START); @@ -954,7 +961,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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, GESTURES_ZOOM_START); @@ -981,7 +988,7 @@ TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { TEST_F(GestureConverterTest, ResetWithButtonPressed) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, @@ -1005,15 +1012,15 @@ TEST_F(GestureConverterTest, ResetWithButtonPressed) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithButtonState(0))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringScroll) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); @@ -1032,14 +1039,15 @@ TEST_F(GestureConverterTest, ResetDuringScroll) { WithCoords(0, 0), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, /*dy=*/10); @@ -1073,14 +1081,15 @@ TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringPinch) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, GESTURES_ZOOM_START); @@ -1105,14 +1114,15 @@ TEST_F(GestureConverterTest, ResetDuringPinch) { WithCoords(0, 0), WithMotionClassification(MotionClassification::NONE))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F(GestureConverterTest, FlingTapDown) { InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); @@ -1122,14 +1132,15 @@ TEST_F(GestureConverterTest, FlingTapDown) { ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), - WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithButtonState(0), WithPressure(0.0f), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))); } 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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); std::list args = @@ -1153,7 +1164,7 @@ TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) { ASSERT_THAT(args, Each(VariantWith( AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT), + WithDisplayId(ui::LogicalDisplayId::DEFAULT), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE))))); } @@ -1161,7 +1172,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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1198,17 +1209,17 @@ TEST_F(GestureConverterTest, Tap) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithButtonState(0), WithPressure(0.0f))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithCoords(0, 0), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1235,10 +1246,10 @@ TEST_F(GestureConverterTest, Click) { WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithCoords(0, 0), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* down= */ GESTURES_BUTTON_NONE, @@ -1257,10 +1268,10 @@ TEST_F(GestureConverterTest, Click) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithPressure(0.0f))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithButtonState(0), WithCoords(0, 0), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithButtonState(0), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); } TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, @@ -1273,7 +1284,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1302,7 +1313,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay, InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1384,7 +1395,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, /* vy= */ 0, GESTURES_FLING_TAP_DOWN); @@ -1411,10 +1422,10 @@ TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f))))); ASSERT_THAT(args, - Each(VariantWith(AllOf(WithCoords(0, 0), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithDisplayId(ui::ADISPLAY_ID_DEFAULT))))); + Each(VariantWith( + AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* down= */ GESTURES_BUTTON_NONE, @@ -1428,18 +1439,20 @@ TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, WithButtonState(0), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))), VariantWith( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(0.0f), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))), VariantWith( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); // Future taps should be re-enabled ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); @@ -1452,7 +1465,7 @@ TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick, InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); - converter.setDisplayId(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list args = @@ -1468,7 +1481,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(ui::ADISPLAY_ID_DEFAULT); + converter.setDisplayId(ui::LogicalDisplayId::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 029414b23d..28699b8518 100644 --- a/services/inputflinger/tests/InputDeviceMetricsCollector_test.cpp +++ b/services/inputflinger/tests/InputDeviceMetricsCollector_test.cpp @@ -63,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, ui::ADISPLAY_ID_NONE); + "alias", /*isExternal=*/false, /*hasMic=*/false, ui::LogicalDisplayId::INVALID); info.addSource(sources); return info; } diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 184659df0d..8ad235f3a3 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -53,7 +53,6 @@ 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 { @@ -73,7 +72,7 @@ static constexpr int32_t DEVICE_ID = DEFAULT_DEVICE_ID; static constexpr int32_t SECOND_DEVICE_ID = 2; // An arbitrary display id. -constexpr ui::LogicalDisplayId DISPLAY_ID = ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; constexpr ui::LogicalDisplayId SECOND_DISPLAY_ID = ui::LogicalDisplayId{1}; // Ensure common actions are interchangeable between keys and motions for convenience. @@ -129,9 +128,9 @@ using ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID; static KeyEvent getTestKeyEvent() { KeyEvent event; - 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); + event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, + ui::LogicalDisplayId::INVALID, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, 0, + AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); return event; } @@ -253,8 +252,8 @@ TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) { KeyEvent event; // Rejects undefined key actions. - event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_NONE, - INVALID_HMAC, + event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, + ui::LogicalDisplayId::INVALID, INVALID_HMAC, /*action=*/-1, 0, AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); ASSERT_EQ(InputEventInjectionResult::FAILED, @@ -263,9 +262,9 @@ 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, ui::ADISPLAY_ID_NONE, - INVALID_HMAC, AKEY_EVENT_ACTION_MULTIPLE, 0, AKEYCODE_A, KEY_A, AMETA_NONE, 0, - ARBITRARY_TIME, ARBITRARY_TIME); + event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, + ui::LogicalDisplayId::INVALID, INVALID_HMAC, AKEY_EVENT_ACTION_MULTIPLE, 0, + AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); ASSERT_EQ(InputEventInjectionResult::FAILED, mDispatcher->injectInputEvent(&event, /*targetUid=*/{}, InputEventInjectionSync::NONE, 0ms, 0)) @@ -482,7 +481,7 @@ public: void consumeMotionPointerDown(int32_t pointerIdx) { int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); - mInputReceiver.consumeEvent(InputEventType::MOTION, action, ADISPLAY_ID_DEFAULT, + mInputReceiver.consumeEvent(InputEventType::MOTION, action, ui::LogicalDisplayId::DEFAULT, /*expectedFlags=*/0); } @@ -500,7 +499,7 @@ private: static InputEventInjectionResult injectKey( InputDispatcher& dispatcher, int32_t action, int32_t repeatCount, - ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE, + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID, InputEventInjectionSync syncMode = InputEventInjectionSync::WAIT_FOR_RESULT, std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT, bool allowKeyRepeat = true, std::optional targetUid = {}, @@ -522,15 +521,17 @@ static InputEventInjectionResult injectKey( static void assertInjectedKeyTimesOut(InputDispatcher& dispatcher) { InputEventInjectionResult result = - injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ui::ADISPLAY_ID_NONE, - InputEventInjectionSync::WAIT_FOR_RESULT, CONSUME_TIMEOUT_NO_EVENT_EXPECTED); + injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, + ui::LogicalDisplayId::INVALID, 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, ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { + InputDispatcher& dispatcher, + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { return injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, displayId); } @@ -538,14 +539,16 @@ static InputEventInjectionResult injectKeyDown( // 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, ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { + InputDispatcher& dispatcher, + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { return injectKey(dispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, displayId, InputEventInjectionSync::WAIT_FOR_RESULT, INJECT_EVENT_TIMEOUT, /*allowKeyRepeat=*/false); } static InputEventInjectionResult injectKeyUp( - InputDispatcher& dispatcher, ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { + InputDispatcher& dispatcher, + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { return injectKey(dispatcher, AKEY_EVENT_ACTION_UP, /*repeatCount=*/0, displayId); } @@ -596,8 +599,8 @@ static InputEventInjectionResult injectMotionUp(InputDispatcher& dispatcher, int return injectMotionEvent(dispatcher, AMOTION_EVENT_ACTION_UP, source, displayId, location); } -static NotifyKeyArgs generateKeyArgs(int32_t action, - ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { +static NotifyKeyArgs generateKeyArgs( + int32_t action, ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); // Define a valid key event. NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, @@ -608,7 +611,7 @@ static NotifyKeyArgs generateKeyArgs(int32_t action, } static NotifyKeyArgs generateSystemShortcutArgs( - int32_t action, ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { + int32_t action, ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); // Define a valid key event. NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, @@ -619,7 +622,7 @@ static NotifyKeyArgs generateSystemShortcutArgs( } static NotifyKeyArgs generateAssistantKeyArgs( - int32_t action, ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE) { + int32_t action, ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID) { nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); // Define a valid key event. NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, @@ -686,9 +689,9 @@ static NotifyPointerCaptureChangedArgs generatePointerCaptureChangedArgs( */ TEST_F(InputDispatcherTest, WhenInputChannelBreaks_PolicyIsNotified) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, - "Window that breaks its input channel", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, + "Window that breaks its input channel", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -699,16 +702,18 @@ TEST_F(InputDispatcherTest, WhenInputChannelBreaks_PolicyIsNotified) { TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Window should receive motion event. - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); } using InputDispatcherDeathTest = InputDispatcherTest; @@ -722,8 +727,9 @@ TEST_F(InputDispatcherDeathTest, DuplicateWindowInfosAbortDispatcher) { ScopedSilentDeath _silentDeath; std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); ASSERT_DEATH(mDispatcher->onWindowInfosChanged( {{*window->getInfo(), *window->getInfo()}, {}, 0, 0}), "Incorrect WindowInfosUpdate provided"); @@ -731,17 +737,19 @@ TEST_F(InputDispatcherDeathTest, DuplicateWindowInfosAbortDispatcher) { TEST_F(InputDispatcherTest, WhenDisplayNotSpecified_InjectMotionToDefaultDisplay) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); // Inject a MotionEvent to an unknown display. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::ADISPLAY_ID_NONE)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::INVALID)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Window should receive motion event. - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); } /** @@ -751,18 +759,19 @@ TEST_F(InputDispatcherTest, WhenDisplayNotSpecified_InjectMotionToDefaultDisplay */ TEST_F(InputDispatcherTest, SetInputWindowOnceWithSingleTouchWindow) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {50, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Window should receive motion event. - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); } /** @@ -770,37 +779,40 @@ TEST_F(InputDispatcherTest, SetInputWindowOnceWithSingleTouchWindow) { */ TEST_F(InputDispatcherTest, SetInputWindowTwice_SingleWindowTouch) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {50, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Window should receive motion event. - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); } // The foreground window should receive the first touch down event. TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) { std::shared_ptr application = std::make_shared(); - sp windowTop = - sp::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp windowTop = sp::make(application, mDispatcher, "Top", + ui::LogicalDisplayId::DEFAULT); sp windowSecond = - sp::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Second", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged( {{*windowTop->getInfo(), *windowSecond->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Top window should receive the touch down event. Second window should not receive anything. - windowTop->consumeMotionDown(ADISPLAY_ID_DEFAULT); + windowTop->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); windowSecond->assertNoEvents(); } @@ -814,10 +826,12 @@ TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) { TEST_F(InputDispatcherTest, WhenForegroundWindowDisappears_WallpaperTouchIsCanceled) { std::shared_ptr application = std::make_shared(); sp foregroundWindow = - sp::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Foreground", + ui::LogicalDisplayId::DEFAULT); foregroundWindow->setDupTouchToWallpaper(true); sp wallpaperWindow = - sp::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Wallpaper", + ui::LogicalDisplayId::DEFAULT); wallpaperWindow->setIsWallpaper(true); mDispatcher->onWindowInfosChanged( @@ -831,7 +845,7 @@ TEST_F(InputDispatcherTest, WhenForegroundWindowDisappears_WallpaperTouchIsCance // Both foreground window and its wallpaper should receive the touch down foregroundWindow->consumeMotionDown(); - wallpaperWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, @@ -841,13 +855,13 @@ TEST_F(InputDispatcherTest, WhenForegroundWindowDisappears_WallpaperTouchIsCance << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; foregroundWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); - wallpaperWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // Now the foreground window goes away, but the wallpaper stays mDispatcher->onWindowInfosChanged({{*wallpaperWindow->getInfo()}, {}, 0, 0}); foregroundWindow->consumeMotionCancel(); // Since the "parent" window of the wallpaper is gone, wallpaper should receive cancel, too. - wallpaperWindow->consumeMotionCancel(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); } /** @@ -857,8 +871,8 @@ TEST_F(InputDispatcherTest, WhenForegroundWindowDisappears_WallpaperTouchIsCance */ TEST_F(InputDispatcherTest, CancelAfterPointer0Up) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); // First touch pointer down on right window @@ -897,30 +911,32 @@ TEST_F(InputDispatcherTest, CancelAfterPointer0Up) { TEST_F(InputDispatcherTest, WhenWallpaperDisappears_NoCrash) { std::shared_ptr application = std::make_shared(); sp foregroundWindow = - sp::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Foreground", + ui::LogicalDisplayId::DEFAULT); foregroundWindow->setDupTouchToWallpaper(true); sp wallpaperWindow = - sp::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Wallpaper", + ui::LogicalDisplayId::DEFAULT); wallpaperWindow->setIsWallpaper(true); mDispatcher->onWindowInfosChanged( {{*foregroundWindow->getInfo(), *wallpaperWindow->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 200})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 200})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Both foreground window and its wallpaper should receive the touch down foregroundWindow->consumeMotionDown(); - wallpaperWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {110, 200})) + ui::LogicalDisplayId::DEFAULT, {110, 200})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; foregroundWindow->consumeMotionMove(); - wallpaperWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // Wallpaper closes its channel, but the window remains. wallpaperWindow->destroyReceiver(); @@ -942,23 +958,23 @@ TEST_F(InputDispatcherTest, MultiDeviceDisappearingWindowWithWallpaperWindows) { std::shared_ptr application = std::make_shared(); sp leftForegroundWindow = sp::make(application, mDispatcher, "Left foreground window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftForegroundWindow->setFrame(Rect(0, 0, 100, 100)); leftForegroundWindow->setDupTouchToWallpaper(true); sp leftWallpaperWindow = sp::make(application, mDispatcher, "Left wallpaper window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWallpaperWindow->setFrame(Rect(0, 0, 100, 100)); leftWallpaperWindow->setIsWallpaper(true); sp rightForegroundWindow = sp::make(application, mDispatcher, "Right foreground window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightForegroundWindow->setFrame(Rect(100, 0, 200, 100)); rightForegroundWindow->setDupTouchToWallpaper(true); sp rightWallpaperWindow = sp::make(application, mDispatcher, "Right wallpaper window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightWallpaperWindow->setFrame(Rect(100, 0, 200, 100)); rightWallpaperWindow->setIsWallpaper(true); @@ -1026,35 +1042,35 @@ TEST_F(InputDispatcherTest, MultiDeviceSlipperyTouchWithWallpaperWindow) { std::shared_ptr application = std::make_shared(); sp leftForegroundWindow = sp::make(application, mDispatcher, "Left foreground window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftForegroundWindow->setFrame(Rect(0, 0, 100, 100)); leftForegroundWindow->setDupTouchToWallpaper(true); sp leftWallpaperWindow = sp::make(application, mDispatcher, "Left wallpaper window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWallpaperWindow->setFrame(Rect(0, 0, 100, 100)); leftWallpaperWindow->setIsWallpaper(true); sp middleForegroundWindow = sp::make(application, mDispatcher, "Middle foreground window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); middleForegroundWindow->setFrame(Rect(100, 0, 200, 100)); middleForegroundWindow->setDupTouchToWallpaper(true); middleForegroundWindow->setSlippery(true); sp middleWallpaperWindow = sp::make(application, mDispatcher, "Middle wallpaper window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); middleWallpaperWindow->setFrame(Rect(100, 0, 200, 100)); middleWallpaperWindow->setIsWallpaper(true); sp rightForegroundWindow = sp::make(application, mDispatcher, "Right foreground window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightForegroundWindow->setFrame(Rect(200, 0, 300, 100)); rightForegroundWindow->setDupTouchToWallpaper(true); sp rightWallpaperWindow = sp::make(application, mDispatcher, "Right wallpaper window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightWallpaperWindow->setFrame(Rect(200, 0, 300, 100)); rightWallpaperWindow->setIsWallpaper(true); @@ -1132,34 +1148,34 @@ TEST_F(InputDispatcherTest, MultiDeviceTouchTransferWithWallpaperWindows) { std::shared_ptr application = std::make_shared(); sp leftForegroundWindow = sp::make(application, mDispatcher, "Left foreground window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftForegroundWindow->setFrame(Rect(0, 0, 100, 100)); leftForegroundWindow->setDupTouchToWallpaper(true); sp leftWallpaperWindow = sp::make(application, mDispatcher, "Left wallpaper window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWallpaperWindow->setFrame(Rect(0, 0, 100, 100)); leftWallpaperWindow->setIsWallpaper(true); sp middleForegroundWindow = sp::make(application, mDispatcher, "Middle foreground window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); middleForegroundWindow->setFrame(Rect(100, 0, 200, 100)); middleForegroundWindow->setDupTouchToWallpaper(true); sp middleWallpaperWindow = sp::make(application, mDispatcher, "Middle wallpaper window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); middleWallpaperWindow->setFrame(Rect(100, 0, 200, 100)); middleWallpaperWindow->setIsWallpaper(true); sp rightForegroundWindow = sp::make(application, mDispatcher, "Right foreground window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightForegroundWindow->setFrame(Rect(200, 0, 300, 100)); rightForegroundWindow->setDupTouchToWallpaper(true); sp rightWallpaperWindow = sp::make(application, mDispatcher, "Right wallpaper window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightWallpaperWindow->setFrame(Rect(200, 0, 300, 100)); rightWallpaperWindow->setIsWallpaper(true); @@ -1239,12 +1255,14 @@ INSTANTIATE_TEST_SUITE_P(InputDispatcherTest, ShouldSplitTouchFixture, TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { std::shared_ptr application = std::make_shared(); sp foregroundWindow = - sp::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Foreground", + ui::LogicalDisplayId::DEFAULT); foregroundWindow->setDupTouchToWallpaper(true); foregroundWindow->setPreventSplitting(GetParam()); sp wallpaperWindow = - sp::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Wallpaper", + ui::LogicalDisplayId::DEFAULT); wallpaperWindow->setIsWallpaper(true); mDispatcher->onWindowInfosChanged( @@ -1252,13 +1270,13 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { // Touch down on top window ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 100})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 100})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Both top window and its wallpaper should receive the touch down foregroundWindow->consumeMotionDown(); - wallpaperWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // Second finger down on the top window const MotionEvent secondFingerDownEvent = @@ -1272,12 +1290,12 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { InputEventInjectionSync::WAIT_FOR_RESULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; foregroundWindow->consumeMotionPointerDown(/*pointerIndex=*/1); - wallpaperWindow->consumeMotionPointerDown(/*pointerIndex=*/1, ADISPLAY_ID_DEFAULT, + wallpaperWindow->consumeMotionPointerDown(/*pointerIndex=*/1, ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); const MotionEvent secondFingerUpEvent = MotionEventBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) @@ -1287,13 +1305,14 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { InputEventInjectionSync::WAIT_FOR_RESULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; foregroundWindow->consumeMotionPointerUp(0); - wallpaperWindow->consumeMotionPointerUp(0, ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionPointerUp(0, ui::LogicalDisplayId::DEFAULT, + EXPECTED_WALLPAPER_FLAGS); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER) .x(100) @@ -1301,8 +1320,8 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { .build(), INJECT_EVENT_TIMEOUT, InputEventInjectionSync::WAIT_FOR_RESULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - foregroundWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT); - wallpaperWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + foregroundWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); + wallpaperWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); } /** @@ -1315,18 +1334,19 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { */ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); leftWindow->setDupTouchToWallpaper(true); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); rightWindow->setDupTouchToWallpaper(true); sp wallpaperWindow = - sp::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Wallpaper", + ui::LogicalDisplayId::DEFAULT); wallpaperWindow->setFrame(Rect(0, 0, 400, 200)); wallpaperWindow->setIsWallpaper(true); @@ -1338,13 +1358,13 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { // Touch down on left window ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 100})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 100})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Both foreground window and its wallpaper should receive the touch down leftWindow->consumeMotionDown(); - wallpaperWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // Second finger down on the right window const MotionEvent secondFingerDownEvent = @@ -1360,8 +1380,8 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { leftWindow->consumeMotionMove(); // Since the touch is split, right window gets ACTION_DOWN - rightWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); - wallpaperWindow->consumeMotionPointerDown(/*pointerIndex=*/1, ADISPLAY_ID_DEFAULT, + rightWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + wallpaperWindow->consumeMotionPointerDown(/*pointerIndex=*/1, ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // Now, leftWindow, which received the first finger, disappears. @@ -1369,7 +1389,7 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { {{*rightWindow->getInfo(), *wallpaperWindow->getInfo()}, {}, 0, 0}); leftWindow->consumeMotionCancel(); // Since a "parent" window of the wallpaper is gone, wallpaper should receive cancel, too. - wallpaperWindow->consumeMotionCancel(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // The pointer that's still down on the right window moves, and goes to the right window only. // As far as the dispatcher's concerned though, both pointers are still present. @@ -1396,18 +1416,19 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { */ TEST_F(InputDispatcherTest, WallpaperWindowWhenSlippery) { std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); leftWindow->setDupTouchToWallpaper(true); leftWindow->setSlippery(true); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); sp wallpaperWindow = - sp::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Wallpaper", + ui::LogicalDisplayId::DEFAULT); wallpaperWindow->setIsWallpaper(true); mDispatcher->onWindowInfosChanged( @@ -1418,23 +1439,23 @@ TEST_F(InputDispatcherTest, WallpaperWindowWhenSlippery) { // Touch down on left window ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 100})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 100})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Both foreground window and its wallpaper should receive the touch down leftWindow->consumeMotionDown(); - wallpaperWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaperWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // Move to right window, the left window should receive cancel. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {201, 100})) + ui::LogicalDisplayId::DEFAULT, {201, 100})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; leftWindow->consumeMotionCancel(); - rightWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); - wallpaperWindow->consumeMotionCancel(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + rightWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + wallpaperWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); } /** @@ -1455,14 +1476,14 @@ TEST_F(InputDispatcherTest, WallpaperWindowWhenSlippery) { */ TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 200, 200)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); @@ -1533,8 +1554,8 @@ TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { TEST_F(InputDispatcherTest, HoverEventInconsistentPolicy) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 300, 300)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -1595,12 +1616,12 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -1703,12 +1724,12 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -1792,8 +1813,8 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { */ TEST_F(InputDispatcherTest, HoverWhileWindowAppears) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); // Only a single window is present at first @@ -1808,7 +1829,7 @@ TEST_F(InputDispatcherTest, HoverWhileWindowAppears) { // Now, an obscuring window appears! sp obscuringWindow = sp::make(application, mDispatcher, "Obscuring window", - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, /*createInputChannel=*/false); obscuringWindow->setFrame(Rect(0, 0, 200, 200)); obscuringWindow->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED); @@ -1841,8 +1862,8 @@ TEST_F(InputDispatcherTest, HoverWhileWindowAppears) { */ TEST_F(InputDispatcherTest, HoverMoveWhileWindowAppears) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); // Only a single window is present at first @@ -1857,7 +1878,7 @@ TEST_F(InputDispatcherTest, HoverMoveWhileWindowAppears) { // Now, an obscuring window appears! sp obscuringWindow = sp::make(application, mDispatcher, "Obscuring window", - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, /*createInputChannel=*/false); obscuringWindow->setFrame(Rect(0, 0, 200, 200)); obscuringWindow->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED); @@ -1899,8 +1920,8 @@ TEST_F(InputDispatcherTest, HoverMoveWhileWindowAppears) { */ TEST_F(InputDispatcherTest, HoverMoveAndScroll) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -1931,8 +1952,8 @@ using InputDispatcherMultiDeviceTest = InputDispatcherTest; TEST_F(InputDispatcherMultiDeviceTest, StylusDownBlocksTouchDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -1978,8 +1999,8 @@ TEST_F(InputDispatcherMultiDeviceTest, StylusDownBlocksTouchDown) { TEST_F(InputDispatcherMultiDeviceTest, StylusDownDoesNotBlockTouchDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2027,10 +2048,10 @@ TEST_F(InputDispatcherMultiDeviceTest, StylusDownDoesNotBlockTouchDown) { TEST_F(InputDispatcherMultiDeviceTest, StylusDownWithSpyBlocksTouchDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 200, 200)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); @@ -2086,10 +2107,10 @@ TEST_F(InputDispatcherMultiDeviceTest, StylusDownWithSpyBlocksTouchDown) { TEST_F(InputDispatcherMultiDeviceTest, StylusDownWithSpyDoesNotBlockTouchDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 200, 200)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); @@ -2148,8 +2169,8 @@ TEST_F(InputDispatcherMultiDeviceTest, StylusDownWithSpyDoesNotBlockTouchDown) { TEST_F(InputDispatcherMultiDeviceTest, StylusHoverBlocksTouchDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2200,8 +2221,8 @@ TEST_F(InputDispatcherMultiDeviceTest, StylusHoverBlocksTouchDown) { TEST_F(InputDispatcherMultiDeviceTest, StylusHoverDoesNotBlockTouchDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2254,8 +2275,8 @@ TEST_F(InputDispatcherMultiDeviceTest, StylusHoverDoesNotBlockTouchDown) { TEST_F(InputDispatcherMultiDeviceTest, TouchIsCanceledByStylusHover) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2308,8 +2329,8 @@ TEST_F(InputDispatcherMultiDeviceTest, TouchIsCanceledByStylusHover) { TEST_F(InputDispatcherMultiDeviceTest, TouchIsNotCanceledByStylusHover) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2363,8 +2384,8 @@ TEST_F(InputDispatcherMultiDeviceTest, TouchIsNotCanceledByStylusHover) { TEST_F(InputDispatcherMultiDeviceTest, LatestStylusWins) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2415,8 +2436,8 @@ TEST_F(InputDispatcherMultiDeviceTest, LatestStylusWins) { TEST_F(InputDispatcherMultiDeviceTest, TwoStylusDevicesActiveAtTheSameTime) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2463,8 +2484,8 @@ TEST_F(InputDispatcherMultiDeviceTest, TwoStylusDevicesActiveAtTheSameTime) { TEST_F(InputDispatcherMultiDeviceTest, TouchIsCanceledByStylusDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2508,8 +2529,8 @@ TEST_F(InputDispatcherMultiDeviceTest, TouchIsCanceledByStylusDown) { TEST_F(InputDispatcherMultiDeviceTest, TouchIsNotCanceledByStylusDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -2562,12 +2583,12 @@ TEST_F(InputDispatcherMultiDeviceTest, TouchIsNotCanceledByStylusDown) { TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceSplitTouch_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -2647,12 +2668,12 @@ TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceSplitTouch_legacy) { TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceSplitTouch) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -2725,12 +2746,12 @@ TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceSplitTouch) { */ TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceHover) { std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -2784,18 +2805,18 @@ TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceWithSpy_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 400, 400)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); @@ -2860,18 +2881,18 @@ TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceWithSpy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 400, 400)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); @@ -2939,18 +2960,18 @@ TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceHoverBlocksTouchWithSpy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 400, 400)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -3015,18 +3036,18 @@ TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceHoverDoesNotBlockTouchWithSpy) SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 400, 400)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -3092,8 +3113,8 @@ TEST_F(InputDispatcherMultiDeviceTest, MultiDeviceHoverDoesNotBlockTouchWithSpy) TEST_F(InputDispatcherMultiDeviceTest, MixedTouchAndMouseWithPointerDown_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 400, 400)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -3172,8 +3193,8 @@ TEST_F(InputDispatcherMultiDeviceTest, MixedTouchAndMouseWithPointerDown_legacy) TEST_F(InputDispatcherMultiDeviceTest, MixedTouchAndMouseWithPointerDown) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 400, 400)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -3247,8 +3268,8 @@ TEST_F(InputDispatcherMultiDeviceTest, MixedTouchAndMouseWithPointerDown) { TEST_F(InputDispatcherMultiDeviceTest, UnfinishedInjectedEvent_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 400, 400)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -3284,8 +3305,8 @@ TEST_F(InputDispatcherMultiDeviceTest, UnfinishedInjectedEvent_legacy) { TEST_F(InputDispatcherMultiDeviceTest, UnfinishedInjectedEvent) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 400, 400)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -3328,12 +3349,12 @@ TEST_F(InputDispatcherMultiDeviceTest, UnfinishedInjectedEvent) { TEST_F(InputDispatcherMultiDeviceTest, HoverTapAndSplitTouch_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -3414,12 +3435,12 @@ TEST_F(InputDispatcherMultiDeviceTest, HoverTapAndSplitTouch_legacy) { TEST_F(InputDispatcherMultiDeviceTest, HoverTapAndSplitTouch) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); mDispatcher->onWindowInfosChanged( @@ -3481,8 +3502,8 @@ TEST_F(InputDispatcherMultiDeviceTest, HoverTapAndSplitTouch) { TEST_F(InputDispatcherMultiDeviceTest, StylusHoverIgnoresTouchTap) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -3548,8 +3569,8 @@ TEST_F(InputDispatcherMultiDeviceTest, StylusHoverIgnoresTouchTap) { TEST_F(InputDispatcherMultiDeviceTest, StylusHoverWithTouchTap) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -3608,12 +3629,13 @@ TEST_F(InputDispatcherMultiDeviceTest, GlobalStylusDownBlocksTouch) { std::shared_ptr application = std::make_shared(); sp leftWindow = sp::make(application, mDispatcher, "Left window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 100, 100)); sp sbtRightWindow = sp::make(application, mDispatcher, - "Stylus blocks touch (right) window", ADISPLAY_ID_DEFAULT); + "Stylus blocks touch (right) window", + ui::LogicalDisplayId::DEFAULT); sbtRightWindow->setFrame(Rect(100, 100, 200, 200)); sbtRightWindow->setGlobalStylusBlocksTouch(true); @@ -3680,12 +3702,13 @@ TEST_F(InputDispatcherMultiDeviceTest, GlobalStylusHoverBlocksTouch) { std::shared_ptr application = std::make_shared(); sp leftWindow = sp::make(application, mDispatcher, "Left window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 100, 100)); sp sbtRightWindow = sp::make(application, mDispatcher, - "Stylus blocks touch (right) window", ADISPLAY_ID_DEFAULT); + "Stylus blocks touch (right) window", + ui::LogicalDisplayId::DEFAULT); sbtRightWindow->setFrame(Rect(100, 100, 200, 200)); sbtRightWindow->setGlobalStylusBlocksTouch(true); @@ -3746,13 +3769,13 @@ TEST_F(InputDispatcherMultiDeviceTest, GlobalStylusHoverBlocksTouch) { */ TEST_F(InputDispatcherTest, StylusHoverAndDownNoInputChannel) { std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 200, 200)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setNoInputChannel(true); window->setFrame(Rect(0, 0, 200, 200)); @@ -3805,8 +3828,8 @@ TEST_F(InputDispatcherTest, StylusHoverAndDownNoInputChannel) { TEST_F(InputDispatcherTest, StaleStylusHoverGestureIsComplete) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -3844,13 +3867,13 @@ TEST_F(InputDispatcherTest, StaleStylusHoverGestureIsComplete) { TEST_F(InputDispatcherTest, TouchPilferAndMouseMove_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 200, 200)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); @@ -3947,13 +3970,13 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove_legacy) { TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 200, 200)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); @@ -4171,14 +4194,14 @@ TEST_F(InputDispatcherTest, SplitTouchesSendCorrectActionDownTime) { TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { std::shared_ptr application = std::make_shared(); - sp windowLeft = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp windowLeft = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); windowLeft->setFrame(Rect(0, 0, 600, 800)); - sp windowRight = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp windowRight = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); windowRight->setFrame(Rect(600, 0, 1200, 800)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged( {{*windowLeft->getInfo(), *windowRight->getInfo()}, {}, 0, 0}); @@ -4238,7 +4261,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { .buttonState(0) .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); - windowLeft->consumeMotionUp(ADISPLAY_ID_DEFAULT); + windowLeft->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); // Move mouse cursor back to right window ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, @@ -4262,8 +4285,8 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { TEST_F(InputDispatcherTest, TwoPointersDownMouseClick_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 600, 800)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4322,8 +4345,8 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick_legacy) { TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 600, 800)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4376,16 +4399,16 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { TEST_F(InputDispatcherTest, HoverWithSpyWindows) { std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 600, 800)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 600, 800)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); // Send mouse cursor to the window @@ -4409,16 +4432,16 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 600, 800)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 600, 800)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); // Send mouse cursor to the window @@ -4516,16 +4539,16 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(0, 0, 600, 800)); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 600, 800)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*spyWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); // Send mouse cursor to the window @@ -4612,11 +4635,11 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { // directly in this test. TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 1200, 800)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4663,7 +4686,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { .buttonState(0) .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); - window->consumeMotionUp(ADISPLAY_ID_DEFAULT); + window->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); // We already canceled the hovering implicitly by injecting the "DOWN" event without lifting the // hover first. Therefore, injection of HOVER_EXIT is inconsistent, and should fail. @@ -4682,11 +4705,11 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { */ TEST_F(InputDispatcherTest, HoverExitIsSentToRemovedWindow) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 1200, 800)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4710,11 +4733,11 @@ TEST_F_WITH_FLAGS(InputDispatcherTest, InvalidA11yHoverStreamDoesNotCrash, REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(com::android::input::flags, a11y_crash_on_inconsistent_event_stream))) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 1200, 800)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4736,8 +4759,8 @@ TEST_F_WITH_FLAGS(InputDispatcherTest, InvalidA11yHoverStreamDoesNotCrash, TEST_F(InputDispatcherTest, TouchDownAfterMouseHover_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4770,8 +4793,8 @@ TEST_F(InputDispatcherTest, TouchDownAfterMouseHover_legacy) { TEST_F(InputDispatcherTest, TouchDownAfterMouseHover) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4803,8 +4826,8 @@ TEST_F(InputDispatcherTest, TouchDownAfterMouseHover) { TEST_F(InputDispatcherTest, MouseHoverAndTouchTap_legacy) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, false); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4843,8 +4866,8 @@ TEST_F(InputDispatcherTest, MouseHoverAndTouchTap_legacy) { TEST_F(InputDispatcherTest, MouseHoverAndTouchTap) { SCOPED_FLAG_OVERRIDE(enable_multi_device_same_window_stream, true); std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4878,7 +4901,7 @@ TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { std::shared_ptr application = std::make_shared(); sp windowDefaultDisplay = sp::make(application, mDispatcher, "DefaultDisplay", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); windowDefaultDisplay->setFrame(Rect(0, 0, 600, 800)); sp windowSecondDisplay = sp::make(application, mDispatcher, "SecondDisplay", @@ -4894,7 +4917,7 @@ TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { injectMotionEvent(*mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(600)) .build())); windowDefaultDisplay->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); @@ -4913,7 +4936,7 @@ TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { injectMotionEvent(*mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .pointer(PointerBuilder(0, ToolType::MOUSE).x(400).y(700)) .build())); windowDefaultDisplay->consumeMotionEvent( @@ -4925,14 +4948,14 @@ TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) { std::shared_ptr application = std::make_shared(); - sp windowLeft = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp windowLeft = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); windowLeft->setFrame(Rect(0, 0, 600, 800)); - sp windowRight = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp windowRight = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); windowRight->setFrame(Rect(600, 0, 1200, 800)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged( {{*windowLeft->getInfo(), *windowRight->getInfo()}, {}, 0, 0}); @@ -4941,15 +4964,16 @@ TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) { // left window. This event should be dispatched to the left window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE, - ADISPLAY_ID_DEFAULT, {610, 400}, {599, 400})); - windowLeft->consumeMotionDown(ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT, {610, 400}, {599, 400})); + windowLeft->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); windowRight->assertNoEvents(); } TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsKeyStream) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -4957,41 +4981,44 @@ TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsKeyStream) { window->consumeFocusEvent(true); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); // Window should receive key down event. - window->consumeKeyDown(ADISPLAY_ID_DEFAULT); + window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); // When device reset happens, that key stream should be terminated with FLAG_CANCELED // on the app side. mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID}); - window->consumeKeyUp(ADISPLAY_ID_DEFAULT, AKEY_EVENT_FLAG_CANCELED); + window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT, AKEY_EVENT_FLAG_CANCELED); } TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsMotionStream) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); // Window should receive motion down event. - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); // When device reset happens, that motion stream should be terminated with ACTION_CANCEL // on the app side. mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID}); window->consumeMotionEvent( - AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ADISPLAY_ID_DEFAULT))); + AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); } TEST_F(InputDispatcherTest, NotifyDeviceResetCancelsHoveringStream) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -5014,8 +5041,9 @@ TEST_F(InputDispatcherTest, NotifyDeviceResetCancelsHoveringStream) { TEST_F(InputDispatcherTest, InterceptKeyByPolicy) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -5023,13 +5051,14 @@ TEST_F(InputDispatcherTest, InterceptKeyByPolicy) { window->consumeFocusEvent(true); - const NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT); + const NotifyKeyArgs keyArgs = + generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT); const std::chrono::milliseconds interceptKeyTimeout = 50ms; const nsecs_t injectTime = keyArgs.eventTime; mFakePolicy->setInterceptKeyTimeout(interceptKeyTimeout); mDispatcher->notifyKey(keyArgs); // The dispatching time should be always greater than or equal to intercept key timeout. - window->consumeKeyDown(ADISPLAY_ID_DEFAULT); + window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); ASSERT_TRUE((systemTime(SYSTEM_TIME_MONOTONIC) - injectTime) >= std::chrono::nanoseconds(interceptKeyTimeout).count()); } @@ -5039,8 +5068,9 @@ TEST_F(InputDispatcherTest, InterceptKeyByPolicy) { */ TEST_F(InputDispatcherTest, InterceptKeyIfKeyUp) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -5048,15 +5078,15 @@ TEST_F(InputDispatcherTest, InterceptKeyIfKeyUp) { window->consumeFocusEvent(true); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); - window->consumeKeyDown(ADISPLAY_ID_DEFAULT); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); + window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); // Set a value that's significantly larger than the default consumption timeout. If the // implementation is correct, the actual value doesn't matter; it won't slow down the test. mFakePolicy->setInterceptKeyTimeout(600ms); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT)); // Window should receive key event immediately when same key up. - window->consumeKeyUp(ADISPLAY_ID_DEFAULT); + window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); } /** @@ -5068,13 +5098,13 @@ TEST_F(InputDispatcherTest, InterceptKeyIfKeyUp) { */ TEST_F(InputDispatcherTest, ActionOutsideForOwnedWindowHasValidCoordinates) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect{0, 0, 100, 100}); sp outsideWindow = sp::make(application, mDispatcher, "Outside Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); outsideWindow->setFrame(Rect{100, 100, 200, 200}); outsideWindow->setWatchOutsideTouch(true); // outsideWindow must be above 'window' to receive ACTION_OUTSIDE events when 'window' is tapped @@ -5082,8 +5112,8 @@ TEST_F(InputDispatcherTest, ActionOutsideForOwnedWindowHasValidCoordinates) { // Tap on first window. mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {PointF{50, 50}})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {PointF{50, 50}})); window->consumeMotionDown(); // The coordinates of the tap in 'outsideWindow' are relative to its top left corner. // Therefore, we should offset them by (100, 100) relative to the screen's top left corner. @@ -5092,7 +5122,7 @@ TEST_F(InputDispatcherTest, ActionOutsideForOwnedWindowHasValidCoordinates) { // Ensure outsideWindow doesn't get any more events for the gesture. mDispatcher->notifyMotion(generateMotionArgs(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {PointF{51, 51}})); + ui::LogicalDisplayId::DEFAULT, {PointF{51, 51}})); window->consumeMotionMove(); outsideWindow->assertNoEvents(); } @@ -5116,13 +5146,13 @@ TEST_F(InputDispatcherTest, ActionOutsideForOwnedWindowHasValidCoordinatesWhenMu std::shared_ptr application = std::make_shared(); sp leftWindow = sp::make(application, mDispatcher, "Left Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect{0, 0, 100, 100}); leftWindow->setOwnerInfo(gui::Pid{1}, gui::Uid{101}); sp outsideWindow = sp::make(application, mDispatcher, "Outside Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); outsideWindow->setFrame(Rect{100, 100, 200, 200}); outsideWindow->setOwnerInfo(gui::Pid{1}, gui::Uid{101}); outsideWindow->setWatchOutsideTouch(true); @@ -5131,7 +5161,7 @@ TEST_F(InputDispatcherTest, ActionOutsideForOwnedWindowHasValidCoordinatesWhenMu std::make_shared(); sp rightWindow = sp::make(anotherApplication, mDispatcher, "Right Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect{100, 0, 200, 100}); rightWindow->setOwnerInfo(gui::Pid{2}, gui::Uid{202}); @@ -5195,32 +5225,33 @@ TEST_F(InputDispatcherTest, ActionOutsideForOwnedWindowHasValidCoordinatesWhenMu TEST_F(InputDispatcherTest, ActionOutsideSentOnlyWhenAWindowIsTouched) { // There are three windows that do not overlap. `window` wants to WATCH_OUTSIDE_TOUCH. std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "First Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "First Window", + ui::LogicalDisplayId::DEFAULT); window->setWatchOutsideTouch(true); window->setFrame(Rect{0, 0, 100, 100}); sp secondWindow = sp::make(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); secondWindow->setFrame(Rect{100, 100, 200, 200}); sp thirdWindow = sp::make(application, mDispatcher, "Third Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); thirdWindow->setFrame(Rect{200, 200, 300, 300}); mDispatcher->onWindowInfosChanged( {{*window->getInfo(), *secondWindow->getInfo(), *thirdWindow->getInfo()}, {}, 0, 0}); // First pointer lands outside all windows. `window` does not get ACTION_OUTSIDE. - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {PointF{-10, -10}})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {PointF{-10, -10}})); window->assertNoEvents(); secondWindow->assertNoEvents(); // The second pointer lands inside `secondWindow`, which should receive a DOWN event. // Now, `window` should get ACTION_OUTSIDE. mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, {PointF{-10, -10}, PointF{105, 105}})); const std::map expectedPointers{{0, PointF{-10, -10}}, {1, PointF{105, 105}}}; window->consumeMotionEvent( @@ -5231,7 +5262,8 @@ TEST_F(InputDispatcherTest, ActionOutsideSentOnlyWhenAWindowIsTouched) { // The third pointer lands inside `thirdWindow`, which should receive a DOWN event. There is // no ACTION_OUTSIDE sent to `window` because one has already been sent for this gesture. mDispatcher->notifyMotion( - generateMotionArgs(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + generateMotionArgs(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {PointF{-10, -10}, PointF{105, 105}, PointF{205, 205}})); window->assertNoEvents(); secondWindow->consumeMotionMove(); @@ -5240,8 +5272,9 @@ TEST_F(InputDispatcherTest, ActionOutsideSentOnlyWhenAWindowIsTouched) { TEST_F(InputDispatcherTest, OnWindowInfosChanged_RemoveAllWindowsOnDisplay) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -5249,13 +5282,15 @@ TEST_F(InputDispatcherTest, OnWindowInfosChanged_RemoveAllWindowsOnDisplay) { window->consumeFocusEvent(true); - const NotifyKeyArgs keyDown = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT); - const NotifyKeyArgs keyUp = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT); + const NotifyKeyArgs keyDown = + generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT); + const NotifyKeyArgs keyUp = + generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT); mDispatcher->notifyKey(keyDown); mDispatcher->notifyKey(keyUp); - window->consumeKeyDown(ADISPLAY_ID_DEFAULT); - window->consumeKeyUp(ADISPLAY_ID_DEFAULT); + window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); + window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); // All windows are removed from the display. Ensure that we can no longer dispatch to it. mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); @@ -5269,22 +5304,23 @@ TEST_F(InputDispatcherTest, OnWindowInfosChanged_RemoveAllWindowsOnDisplay) { TEST_F(InputDispatcherTest, NonSplitTouchableWindowReceivesMultiTouch) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); // Ensure window is non-split and have some transform. window->setPreventSplitting(true); window->setWindowOffset(20, 40); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {50, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(-30).y(-50)) @@ -5315,12 +5351,12 @@ TEST_F(InputDispatcherTest, SplittableAndNonSplittableWindows) { std::shared_ptr application = std::make_shared(); sp leftWindow = sp::make(application, mDispatcher, "Left splittable Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWindow->setPreventSplitting(false); leftWindow->setFrame(Rect(0, 0, 100, 100)); sp rightWindow = sp::make(application, mDispatcher, "Right non-splittable Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightWindow->setPreventSplitting(true); rightWindow->setFrame(Rect(100, 100, 200, 200)); mDispatcher->onWindowInfosChanged( @@ -5343,12 +5379,12 @@ TEST_F(InputDispatcherTest, SplittableAndNonSplittableWindows) { TEST_F(InputDispatcherTest, TouchpadThreeFingerSwipeOnlySentToTrustedOverlays) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 400, 400)); sp trustedOverlay = sp::make(application, mDispatcher, "Trusted Overlay", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); trustedOverlay->setSpy(true); trustedOverlay->setTrustedOverlay(true); @@ -5411,8 +5447,8 @@ TEST_F(InputDispatcherTest, TouchpadThreeFingerSwipeOnlySentToTrustedOverlays) { TEST_F(InputDispatcherTest, TouchpadThreeFingerSwipeNotSentToSingleWindow) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 400, 400)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -5468,8 +5504,8 @@ TEST_F(InputDispatcherTest, TouchpadThreeFingerSwipeNotSentToSingleWindow) { */ TEST_F(InputDispatcherTest, MultiplePointersWithRotatingWindow) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 400, 400)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -5534,13 +5570,14 @@ TEST_F(InputDispatcherTest, WhenMultiDisplayWindowSameToken_DispatchCancelToTarg std::shared_ptr application = std::make_shared(); sp spyWindowDefaultDisplay = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindowDefaultDisplay->setTrustedOverlay(true); spyWindowDefaultDisplay->setSpy(true); sp windowDefaultDisplay = sp::make(application, mDispatcher, "DefaultDisplay", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); windowDefaultDisplay->setWindowTransform(1, 0, 0, 1); sp windowSecondDisplay = windowDefaultDisplay->clone(SECOND_DISPLAY_ID); @@ -5554,10 +5591,10 @@ TEST_F(InputDispatcherTest, WhenMultiDisplayWindowSameToken_DispatchCancelToTarg 0, 0}); - // Send down to ADISPLAY_ID_DEFAULT + // Send down to ui::LogicalDisplayId::DEFAULT ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 100})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 100})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; spyWindowDefaultDisplay->consumeMotionDown(); @@ -5570,10 +5607,10 @@ 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 - // coordinates are both 100, otherwise if the cancel event is sent to windowSecondDisplay of - // SECOND_DISPLAY_ID, the x and y coordinates are 200 + // The cancel event is sent to windowDefaultDisplay of the ui::LogicalDisplayId::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)); EXPECT_EQ(100, event->getY(0)); } @@ -5617,7 +5654,7 @@ public: // respectively. ui::Transform displayTransform; displayTransform.set(2, 0, 0, 4); - addDisplayInfo(ADISPLAY_ID_DEFAULT, displayTransform); + addDisplayInfo(ui::LogicalDisplayId::DEFAULT, displayTransform); std::shared_ptr application = std::make_shared(); @@ -5625,13 +5662,13 @@ public: // Add two windows to the display. Their frames are represented in the display space. sp firstWindow = sp::make(application, mDispatcher, "First Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); firstWindow->setFrame(Rect(0, 0, 100, 200), displayTransform); addWindow(firstWindow); sp secondWindow = sp::make(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); secondWindow->setFrame(Rect(100, 200, 200, 400), displayTransform); addWindow(secondWindow); return {std::move(firstWindow), std::move(secondWindow)}; @@ -5648,8 +5685,8 @@ TEST_F(InputDispatcherDisplayProjectionTest, HitTestCoordinateSpaceConsistency) // selected so that if the hit test was performed with the point and the bounds being in // different coordinate spaces, the event would end up in the incorrect window. mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {PointF{75, 55}})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {PointF{75, 55}})); firstWindow->consumeMotionDown(); secondWindow->assertNoEvents(); @@ -5662,7 +5699,7 @@ TEST_F(InputDispatcherDisplayProjectionTest, InjectionInLogicalDisplaySpace) { // Send down to the first window. The point is represented in the logical display space. The // point is selected so that if the hit test was done in logical display space, then it would // end up in the incorrect window. - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, PointF{75 * 2, 55 * 4}); firstWindow->consumeMotionDown(); @@ -5681,7 +5718,7 @@ TEST_F(InputDispatcherDisplayProjectionTest, InjectionWithTransformInLogicalDisp const vec2 untransformedPoint = injectedEventTransform.inverse().transform(expectedPoint); MotionEvent event = MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER) .x(untransformedPoint.x) @@ -5700,9 +5737,9 @@ TEST_F(InputDispatcherDisplayProjectionTest, WindowGetsEventsInCorrectCoordinate auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); // Send down to the second window. - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {PointF{150, 220}})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {PointF{150, 220}})); firstWindow->assertNoEvents(); std::unique_ptr event = secondWindow->consumeMotionEvent(); @@ -5724,17 +5761,17 @@ TEST_F(InputDispatcherDisplayProjectionTest, CancelMotionWithCorrectCoordinates) auto [firstWindow, secondWindow] = setupScaledDisplayScenario(); // The monitor will always receive events in the logical display's coordinate space, because // it does not have a window. - FakeMonitorReceiver monitor{*mDispatcher, "Monitor", ADISPLAY_ID_DEFAULT}; + FakeMonitorReceiver monitor{*mDispatcher, "Monitor", ui::LogicalDisplayId::DEFAULT}; // Send down to the first window. mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {PointF{50, 100}})); + ui::LogicalDisplayId::DEFAULT, {PointF{50, 100}})); firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 400))); monitor.consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 400))); // Second pointer goes down on second window. mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, {PointF{50, 100}, PointF{150, 220}})); secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 80))); const std::map expectedMonitorPointers{{0, PointF{100, 400}}, @@ -5755,7 +5792,7 @@ TEST_F(InputDispatcherDisplayProjectionTest, SynthesizeDownWithCorrectCoordinate // Send down to the first window. mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {PointF{50, 100}})); + ui::LogicalDisplayId::DEFAULT, {PointF{50, 100}})); firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 400))); // The pointer is transferred to the second window, and the second window receives it in the @@ -5770,13 +5807,15 @@ TEST_F(InputDispatcherDisplayProjectionTest, SynthesizeHoverEnterExitWithCorrect // Send hover move to the second window, and ensure it shows up as hover enter. mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{150, 220}})); + ui::LogicalDisplayId::DEFAULT, + {PointF{150, 220}})); secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithCoords(100, 80), WithRawCoords(300, 880))); // Touch down at the same location and ensure a hover exit is synthesized. mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{150, 220}})); + ui::LogicalDisplayId::DEFAULT, + {PointF{150, 220}})); secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithCoords(100, 80), WithRawCoords(300, 880))); secondWindow->consumeMotionEvent( @@ -5801,14 +5840,16 @@ TEST_F(InputDispatcherDisplayProjectionTest, // Send hover move to the second window, and ensure it shows up as hover enter. mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{150, 220}})); + ui::LogicalDisplayId::DEFAULT, + {PointF{150, 220}})); secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithCoords(100, 80), WithRawCoords(300, 880))); // Touch down at the same location and ensure a hover exit is synthesized for the correct // display. mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{150, 220}})); + ui::LogicalDisplayId::DEFAULT, + {PointF{150, 220}})); secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithCoords(100, 80), WithRawCoords(300, 880))); secondWindow->consumeMotionEvent( @@ -5822,7 +5863,8 @@ TEST_F(InputDispatcherDisplayProjectionTest, SynthesizeHoverCancelationWithCorre // Send hover enter to second window mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{150, 220}})); + ui::LogicalDisplayId::DEFAULT, + {PointF{150, 220}})); secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithCoords(100, 80), WithRawCoords(300, 880))); @@ -5850,17 +5892,18 @@ TEST_F(InputDispatcherDisplayProjectionTest, // Send hover enter to second window mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{150, 220}})); + ui::LogicalDisplayId::DEFAULT, + {PointF{150, 220}})); secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithCoords(100, 80), WithRawCoords(300, 880), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))); mDispatcher->cancelCurrentTouch(); // Ensure the cancelation happens with the correct displayId and the correct coordinates. secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithCoords(100, 80), WithRawCoords(300, 880), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithDisplayId(ui::LogicalDisplayId::DEFAULT))); secondWindow->assertNoEvents(); firstWindow->assertNoEvents(); } @@ -5887,13 +5930,13 @@ TEST_P(InputDispatcherDisplayOrientationFixture, HitTestInDifferentOrientations) const int32_t logicalDisplayHeight = isRotated ? displayWidth : displayHeight; const ui::Transform displayTransform(ui::Transform::toRotationFlags(rotation), logicalDisplayWidth, logicalDisplayHeight); - addDisplayInfo(ADISPLAY_ID_DEFAULT, displayTransform); + addDisplayInfo(ui::LogicalDisplayId::DEFAULT, displayTransform); // Create a window with its bounds determined in the logical display. const Rect frameInLogicalDisplay(100, 100, 200, 300); const Rect frameInDisplay = displayTransform.inverse().transform(frameInLogicalDisplay); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(frameInDisplay, displayTransform); addWindow(window); @@ -5903,14 +5946,14 @@ TEST_P(InputDispatcherDisplayOrientationFixture, HitTestInDifferentOrientations) for (const auto pointInsideWindow : insidePoints) { const vec2 p = displayTransform.inverse().transform(pointInsideWindow); const PointF pointInDisplaySpace{p.x, p.y}; - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInDisplaySpace})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); window->consumeMotionDown(); - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInDisplaySpace})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); window->consumeMotionUp(); } @@ -5920,13 +5963,13 @@ TEST_P(InputDispatcherDisplayOrientationFixture, HitTestInDifferentOrientations) for (const auto pointOutsideWindow : outsidePoints) { const vec2 p = displayTransform.inverse().transform(pointOutsideWindow); const PointF pointInDisplaySpace{p.x, p.y}; - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInDisplaySpace})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInDisplaySpace})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); } window->assertNoEvents(); } @@ -5950,7 +5993,7 @@ TEST_P(InputDispatcherDisplayOrientationFixture, BlockUntrustClickInDifferentOri const int32_t logicalDisplayHeight = isRotated ? displayWidth : displayHeight; const ui::Transform displayTransform(ui::Transform::toRotationFlags(rotation), logicalDisplayWidth, logicalDisplayHeight); - addDisplayInfo(ADISPLAY_ID_DEFAULT, displayTransform); + addDisplayInfo(ui::LogicalDisplayId::DEFAULT, displayTransform); // Create a window that not trusted. const Rect untrustedWindowFrameInLogicalDisplay(100, 100, 200, 300); @@ -5960,7 +6003,7 @@ TEST_P(InputDispatcherDisplayOrientationFixture, BlockUntrustClickInDifferentOri sp untrustedWindow = sp::make(untrustedWindowApplication, mDispatcher, "UntrustedWindow", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); untrustedWindow->setFrame(untrustedWindowFrameInDisplay, displayTransform); untrustedWindow->setTrustedOverlay(false); untrustedWindow->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED); @@ -5976,7 +6019,7 @@ TEST_P(InputDispatcherDisplayOrientationFixture, BlockUntrustClickInDifferentOri sp simpleAppWindow = sp::make(application, mDispatcher, "SimpleAppWindow", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); simpleAppWindow->setFrame(simpleAppWindowFrameInDisplay, displayTransform); simpleAppWindow->setOwnerInfo(gui::Pid{2}, gui::Uid{202}); addWindow(simpleAppWindow); @@ -5989,12 +6032,12 @@ TEST_P(InputDispatcherDisplayOrientationFixture, BlockUntrustClickInDifferentOri for (const auto untrustedPoint : untrustedPoints) { const vec2 p = displayTransform.inverse().transform(untrustedPoint); const PointF pointInDisplaySpace{p.x, p.y}; - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInDisplaySpace})); - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInDisplaySpace})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); } untrustedWindow->assertNoEvents(); simpleAppWindow->assertNoEvents(); @@ -6005,15 +6048,15 @@ TEST_P(InputDispatcherDisplayOrientationFixture, BlockUntrustClickInDifferentOri for (const auto trustedPoint : trustedPoints) { const vec2 p = displayTransform.inverse().transform(trustedPoint); const PointF pointInDisplaySpace{p.x, p.y}; - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInDisplaySpace})); - simpleAppWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); + simpleAppWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInDisplaySpace})); - simpleAppWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInDisplaySpace})); + simpleAppWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); } untrustedWindow->assertNoEvents(); @@ -6040,13 +6083,14 @@ TEST_P(TransferTouchFixture, TransferTouch_OnePointer) { // Create a couple of windows sp firstWindow = sp::make(application, mDispatcher, "First Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); firstWindow->setDupTouchToWallpaper(true); sp secondWindow = sp::make(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); sp wallpaper = - sp::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Wallpaper", + ui::LogicalDisplayId::DEFAULT); wallpaper->setIsWallpaper(true); // Add the windows to the dispatcher, and ensure the first window is focused mDispatcher->onWindowInfosChanged( @@ -6056,12 +6100,13 @@ TEST_P(TransferTouchFixture, TransferTouch_OnePointer) { // Send down to the first window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); // Only the first window should get the down event firstWindow->consumeMotionDown(); secondWindow->assertNoEvents(); - wallpaper->consumeMotionDown(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaper->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // Dispatcher reports pointer down outside focus for the wallpaper mFakePolicy->assertOnPointerDownEquals(wallpaper->getToken()); @@ -6071,17 +6116,19 @@ TEST_P(TransferTouchFixture, TransferTouch_OnePointer) { ASSERT_TRUE(success); // The first window gets cancel and the second gets down firstWindow->consumeMotionCancel(); - secondWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); - wallpaper->consumeMotionCancel(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + secondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + wallpaper->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); // There should not be any changes to the focused window when transferring touch ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertOnPointerDownWasNotCalled()); // Send up event to the second window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); // The first window gets no events and the second gets up firstWindow->assertNoEvents(); - secondWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); wallpaper->assertNoEvents(); } @@ -6101,14 +6148,15 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWindowsWithSpy) { std::shared_ptr application = std::make_shared(); // Create a couple of windows + a spy window - sp spyWindow = - sp::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spyWindow = sp::make(application, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); - sp firstWindow = - sp::make(application, mDispatcher, "First", ADISPLAY_ID_DEFAULT); + sp firstWindow = sp::make(application, mDispatcher, "First", + ui::LogicalDisplayId::DEFAULT); sp secondWindow = - sp::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Second", + ui::LogicalDisplayId::DEFAULT); // Add the windows to the dispatcher mDispatcher->onWindowInfosChanged( @@ -6116,7 +6164,8 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWindowsWithSpy) { // Send down to the first window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); // Only the first window and spy should get the down event spyWindow->consumeMotionDown(); firstWindow->consumeMotionDown(); @@ -6128,15 +6177,17 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWindowsWithSpy) { ASSERT_TRUE(success); // The first window gets cancel and the second gets down firstWindow->consumeMotionCancel(); - secondWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + secondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); // Send up event to the second window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); // The first window gets no events and the second+spy get up firstWindow->assertNoEvents(); spyWindow->consumeMotionUp(); - secondWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); } TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) { @@ -6147,11 +6198,11 @@ TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) { // Create a couple of windows sp firstWindow = sp::make(application, mDispatcher, "First Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); firstWindow->setPreventSplitting(true); sp secondWindow = sp::make(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); secondWindow->setPreventSplitting(true); // Add the windows to the dispatcher @@ -6160,15 +6211,16 @@ TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) { // Send down to the first window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {touchPoint})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {touchPoint})); // Only the first window should get the down event firstWindow->consumeMotionDown(); secondWindow->assertNoEvents(); // Send pointer down to the first window mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {touchPoint, touchPoint})); + ui::LogicalDisplayId::DEFAULT, + {touchPoint, touchPoint})); // Only the first window should get the pointer down event firstWindow->consumeMotionPointerDown(1); secondWindow->assertNoEvents(); @@ -6179,24 +6231,27 @@ TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) { ASSERT_TRUE(success); // The first window gets cancel and the second gets down and pointer down firstWindow->consumeMotionCancel(); - secondWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); - secondWindow->consumeMotionPointerDown(1, ADISPLAY_ID_DEFAULT, + secondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + secondWindow->consumeMotionPointerDown(1, ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); // Send pointer up to the second window mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {touchPoint, touchPoint})); + ui::LogicalDisplayId::DEFAULT, + {touchPoint, touchPoint})); // The first window gets nothing and the second gets pointer up firstWindow->assertNoEvents(); - secondWindow->consumeMotionPointerUp(1, ADISPLAY_ID_DEFAULT, + secondWindow->consumeMotionPointerUp(1, ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); // Send up event to the second window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); // The first window gets nothing and the second gets up firstWindow->assertNoEvents(); - secondWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); } TEST_P(TransferTouchFixture, TransferTouch_MultipleWallpapers) { @@ -6205,19 +6260,21 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWallpapers) { // Create a couple of windows sp firstWindow = sp::make(application, mDispatcher, "First Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); firstWindow->setDupTouchToWallpaper(true); sp secondWindow = sp::make(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); secondWindow->setDupTouchToWallpaper(true); sp wallpaper1 = - sp::make(application, mDispatcher, "Wallpaper1", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Wallpaper1", + ui::LogicalDisplayId::DEFAULT); wallpaper1->setIsWallpaper(true); sp wallpaper2 = - sp::make(application, mDispatcher, "Wallpaper2", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Wallpaper2", + ui::LogicalDisplayId::DEFAULT); wallpaper2->setIsWallpaper(true); // Add the windows to the dispatcher mDispatcher->onWindowInfosChanged({{*firstWindow->getInfo(), *wallpaper1->getInfo(), @@ -6228,12 +6285,13 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWallpapers) { // Send down to the first window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); // Only the first window should get the down event firstWindow->consumeMotionDown(); secondWindow->assertNoEvents(); - wallpaper1->consumeMotionDown(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaper1->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); wallpaper2->assertNoEvents(); // Transfer touch focus to the second window @@ -6243,19 +6301,21 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWallpapers) { // The first window gets cancel and the second gets down firstWindow->consumeMotionCancel(); - secondWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); - wallpaper1->consumeMotionCancel(ADISPLAY_ID_DEFAULT, EXPECTED_WALLPAPER_FLAGS); - wallpaper2->consumeMotionDown(ADISPLAY_ID_DEFAULT, + secondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + wallpaper1->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS); + wallpaper2->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); // Send up event to the second window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); // The first window gets no events and the second gets up firstWindow->assertNoEvents(); - secondWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); wallpaper1->assertNoEvents(); - wallpaper2->consumeMotionUp(ADISPLAY_ID_DEFAULT, + wallpaper2->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, EXPECTED_WALLPAPER_FLAGS | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); } @@ -6268,7 +6328,7 @@ INSTANTIATE_TEST_SUITE_P( [&](const std::unique_ptr& dispatcher, sp /*ignored*/, sp destChannelToken) { return dispatcher->transferTouchOnDisplay(destChannelToken, - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); }, [&](const std::unique_ptr& dispatcher, sp from, sp to) { @@ -6281,12 +6341,12 @@ TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) { sp firstWindow = sp::make(application, mDispatcher, "First Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); firstWindow->setFrame(Rect(0, 0, 600, 400)); sp secondWindow = sp::make(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); secondWindow->setFrame(Rect(0, 400, 600, 800)); // Add the windows to the dispatcher @@ -6298,15 +6358,15 @@ TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) { // Send down to the first window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInFirst})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInFirst})); // Only the first window should get the down event firstWindow->consumeMotionDown(); secondWindow->assertNoEvents(); // Send down to the second window mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, {pointInFirst, pointInSecond})); // The first window gets a move and the second a down firstWindow->consumeMotionMove(); @@ -6316,24 +6376,25 @@ TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) { mDispatcher->transferTouchGesture(firstWindow->getToken(), secondWindow->getToken()); // The first window gets cancel and the new gets pointer down (it already saw down) firstWindow->consumeMotionCancel(); - secondWindow->consumeMotionPointerDown(1, ADISPLAY_ID_DEFAULT, + secondWindow->consumeMotionPointerDown(1, ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); // Send pointer up to the second window mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, {pointInFirst, pointInSecond})); // The first window gets nothing and the second gets pointer up firstWindow->assertNoEvents(); - secondWindow->consumeMotionPointerUp(1, ADISPLAY_ID_DEFAULT, + secondWindow->consumeMotionPointerUp(1, ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); // Send up event to the second window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); // The first window gets nothing and the second gets up firstWindow->assertNoEvents(); - secondWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + secondWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); } // Same as TransferTouch_TwoPointersSplitTouch, but using 'transferTouchOnDisplay' api. @@ -6345,12 +6406,12 @@ TEST_F(InputDispatcherTest, TransferTouchOnDisplay_TwoPointersSplitTouch) { sp firstWindow = sp::make(application, mDispatcher, "First Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); firstWindow->setFrame(Rect(0, 0, 600, 400)); sp secondWindow = sp::make(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); secondWindow->setFrame(Rect(0, 400, 600, 800)); // Add the windows to the dispatcher @@ -6362,23 +6423,23 @@ TEST_F(InputDispatcherTest, TransferTouchOnDisplay_TwoPointersSplitTouch) { // Send down to the first window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInFirst})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInFirst})); // Only the first window should get the down event firstWindow->consumeMotionDown(); secondWindow->assertNoEvents(); // Send down to the second window mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, {pointInFirst, pointInSecond})); // The first window gets a move and the second a down firstWindow->consumeMotionMove(); secondWindow->consumeMotionDown(); // Transfer touch focus to the second window - const bool transferred = - mDispatcher->transferTouchOnDisplay(secondWindow->getToken(), ADISPLAY_ID_DEFAULT); + const bool transferred = mDispatcher->transferTouchOnDisplay(secondWindow->getToken(), + ui::LogicalDisplayId::DEFAULT); // The 'transferTouchOnDisplay' call should not succeed, because there are 2 touched windows ASSERT_FALSE(transferred); firstWindow->assertNoEvents(); @@ -6387,7 +6448,7 @@ TEST_F(InputDispatcherTest, TransferTouchOnDisplay_TwoPointersSplitTouch) { // The rest of the dispatch should proceed as normal // Send pointer up to the second window mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, {pointInFirst, pointInSecond})); // The first window gets MOVE and the second gets pointer up firstWindow->consumeMotionMove(); @@ -6395,7 +6456,7 @@ TEST_F(InputDispatcherTest, TransferTouchOnDisplay_TwoPointersSplitTouch) { // Send up event to the first window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); // The first window gets nothing and the second gets up firstWindow->consumeMotionUp(); secondWindow->assertNoEvents(); @@ -6407,13 +6468,16 @@ TEST_F(InputDispatcherTest, TransferTouchOnDisplay_TwoPointersSplitTouch) { TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) { std::shared_ptr application = std::make_shared(); sp firstWindowInPrimary = - sp::make(application, mDispatcher, "D_1_W1", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "D_1_W1", + ui::LogicalDisplayId::DEFAULT); firstWindowInPrimary->setFrame(Rect(0, 0, 100, 100)); sp secondWindowInPrimary = - sp::make(application, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "D_1_W2", + ui::LogicalDisplayId::DEFAULT); secondWindowInPrimary->setFrame(Rect(100, 0, 200, 100)); - sp mirrorWindowInPrimary = firstWindowInPrimary->clone(ADISPLAY_ID_DEFAULT); + sp mirrorWindowInPrimary = + firstWindowInPrimary->clone(ui::LogicalDisplayId::DEFAULT); mirrorWindowInPrimary->setFrame(Rect(0, 100, 100, 200)); sp firstWindowInSecondary = firstWindowInPrimary->clone(SECOND_DISPLAY_ID); @@ -6432,35 +6496,36 @@ TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) { 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {50, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Window should receive motion event. - firstWindowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT); + firstWindowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); // Transfer touch ASSERT_TRUE(mDispatcher->transferTouchGesture(firstWindowInPrimary->getToken(), secondWindowInPrimary->getToken())); // The first window gets cancel. firstWindowInPrimary->consumeMotionCancel(); - secondWindowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT, + secondWindowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {150, 50})) + ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; firstWindowInPrimary->assertNoEvents(); - secondWindowInPrimary->consumeMotionMove(ADISPLAY_ID_DEFAULT, + secondWindowInPrimary->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; firstWindowInPrimary->assertNoEvents(); - secondWindowInPrimary->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + secondWindowInPrimary->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); } // Same as TransferTouch_CloneSurface, but this touch on the secondary display and use @@ -6468,13 +6533,16 @@ TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) { TEST_F(InputDispatcherTest, TransferTouchOnDisplay_CloneSurface) { std::shared_ptr application = std::make_shared(); sp firstWindowInPrimary = - sp::make(application, mDispatcher, "D_1_W1", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "D_1_W1", + ui::LogicalDisplayId::DEFAULT); firstWindowInPrimary->setFrame(Rect(0, 0, 100, 100)); sp secondWindowInPrimary = - sp::make(application, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "D_1_W2", + ui::LogicalDisplayId::DEFAULT); secondWindowInPrimary->setFrame(Rect(100, 0, 200, 100)); - sp mirrorWindowInPrimary = firstWindowInPrimary->clone(ADISPLAY_ID_DEFAULT); + sp mirrorWindowInPrimary = + firstWindowInPrimary->clone(ui::LogicalDisplayId::DEFAULT); mirrorWindowInPrimary->setFrame(Rect(0, 100, 100, 200)); sp firstWindowInSecondary = firstWindowInPrimary->clone(SECOND_DISPLAY_ID); @@ -6527,8 +6595,9 @@ TEST_F(InputDispatcherTest, TransferTouchOnDisplay_CloneSurface) { TEST_F(InputDispatcherTest, FocusedWindow_ReceivesFocusEventAndKeyEvent) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -6536,10 +6605,10 @@ TEST_F(InputDispatcherTest, FocusedWindow_ReceivesFocusEventAndKeyEvent) { window->consumeFocusEvent(true); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); // Window should receive key down event. - window->consumeKeyDown(ADISPLAY_ID_DEFAULT); + window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); // Should have poked user activity mDispatcher->waitForIdle(); @@ -6548,8 +6617,9 @@ TEST_F(InputDispatcherTest, FocusedWindow_ReceivesFocusEventAndKeyEvent) { TEST_F(InputDispatcherTest, FocusedWindow_DisableUserActivity) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setDisableUserActivity(true); window->setFocusable(true); @@ -6558,10 +6628,10 @@ TEST_F(InputDispatcherTest, FocusedWindow_DisableUserActivity) { window->consumeFocusEvent(true); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); // Window should receive key down event. - window->consumeKeyDown(ADISPLAY_ID_DEFAULT); + window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); // Should have poked user activity mDispatcher->waitForIdle(); @@ -6570,8 +6640,9 @@ TEST_F(InputDispatcherTest, FocusedWindow_DisableUserActivity) { TEST_F(InputDispatcherTest, FocusedWindow_DoesNotReceiveSystemShortcut) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -6579,7 +6650,8 @@ TEST_F(InputDispatcherTest, FocusedWindow_DoesNotReceiveSystemShortcut) { window->consumeFocusEvent(true); - mDispatcher->notifyKey(generateSystemShortcutArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey( + generateSystemShortcutArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); mDispatcher->waitForIdle(); // System key is not passed down @@ -6591,8 +6663,9 @@ TEST_F(InputDispatcherTest, FocusedWindow_DoesNotReceiveSystemShortcut) { TEST_F(InputDispatcherTest, FocusedWindow_DoesNotReceiveAssistantKey) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -6600,7 +6673,8 @@ TEST_F(InputDispatcherTest, FocusedWindow_DoesNotReceiveAssistantKey) { window->consumeFocusEvent(true); - mDispatcher->notifyKey(generateAssistantKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey( + generateAssistantKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); mDispatcher->waitForIdle(); // System key is not passed down @@ -6612,8 +6686,9 @@ TEST_F(InputDispatcherTest, FocusedWindow_DoesNotReceiveAssistantKey) { TEST_F(InputDispatcherTest, FocusedWindow_SystemKeyIgnoresDisableUserActivity) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); window->setDisableUserActivity(true); window->setFocusable(true); @@ -6622,7 +6697,8 @@ TEST_F(InputDispatcherTest, FocusedWindow_SystemKeyIgnoresDisableUserActivity) { window->consumeFocusEvent(true); - mDispatcher->notifyKey(generateSystemShortcutArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey( + generateSystemShortcutArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); mDispatcher->waitForIdle(); // System key is not passed down @@ -6634,18 +6710,19 @@ TEST_F(InputDispatcherTest, FocusedWindow_SystemKeyIgnoresDisableUserActivity) { TEST_F(InputDispatcherTest, InjectedTouchesPokeUserActivity) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {100, 100})) + ui::LogicalDisplayId::DEFAULT, {100, 100})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionEvent( - AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(ADISPLAY_ID_DEFAULT))); + AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); // Should have poked user activity mDispatcher->waitForIdle(); @@ -6654,12 +6731,13 @@ TEST_F(InputDispatcherTest, InjectedTouchesPokeUserActivity) { TEST_F(InputDispatcherTest, UnfocusedWindow_DoesNotReceiveFocusEventOrKeyEvent) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); mDispatcher->waitForIdle(); window->assertNoEvents(); @@ -6668,19 +6746,21 @@ TEST_F(InputDispatcherTest, UnfocusedWindow_DoesNotReceiveFocusEventOrKeyEvent) // If a window is touchable, but does not have focus, it should receive motion events, but not keys TEST_F(InputDispatcherTest, UnfocusedWindow_ReceivesMotionsButNotKeys) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); // Send key - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); // Send motion mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); // Window should receive only the motion event - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); window->assertNoEvents(); // Key event or focus event will not be received } @@ -6689,12 +6769,12 @@ TEST_F(InputDispatcherTest, PointerCancel_SendCancelWhenSplitTouch) { sp firstWindow = sp::make(application, mDispatcher, "First Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); firstWindow->setFrame(Rect(0, 0, 600, 400)); sp secondWindow = sp::make(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); secondWindow->setFrame(Rect(0, 400, 600, 800)); // Add the windows to the dispatcher @@ -6706,15 +6786,15 @@ TEST_F(InputDispatcherTest, PointerCancel_SendCancelWhenSplitTouch) { // Send down to the first window mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInFirst})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInFirst})); // Only the first window should get the down event firstWindow->consumeMotionDown(); secondWindow->assertNoEvents(); // Send down to the second window mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, + ui::LogicalDisplayId::DEFAULT, {pointInFirst, pointInSecond})); // The first window gets a move and the second a down firstWindow->consumeMotionMove(); @@ -6722,17 +6802,17 @@ TEST_F(InputDispatcherTest, PointerCancel_SendCancelWhenSplitTouch) { // Send pointer cancel to the second window NotifyMotionArgs pointerUpMotionArgs = - generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {pointInFirst, pointInSecond}); + generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {pointInFirst, pointInSecond}); pointerUpMotionArgs.flags |= AMOTION_EVENT_FLAG_CANCELED; mDispatcher->notifyMotion(pointerUpMotionArgs); // The first window gets move and the second gets cancel. - firstWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_CANCELED); - secondWindow->consumeMotionCancel(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_CANCELED); + firstWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_CANCELED); + secondWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_CANCELED); // Send up event. mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); // The first window gets up and the second gets nothing. firstWindow->consumeMotionUp(); secondWindow->assertNoEvents(); @@ -6741,8 +6821,8 @@ TEST_F(InputDispatcherTest, PointerCancel_SendCancelWhenSplitTouch) { TEST_F(InputDispatcherTest, SendTimeline_DoesNotCrashDispatcher) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); std::array graphicsTimeline; graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 2; @@ -6765,28 +6845,29 @@ using InputDispatcherMonitorTest = InputDispatcherTest; */ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsCanceledWhenForegroundWindowDisappears) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Foreground", + ui::LogicalDisplayId::DEFAULT); - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 200})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 200})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; // Both the foreground window and the global monitor should receive the touch down window->consumeMotionDown(); - monitor.consumeMotionDown(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {110, 200})) + ui::LogicalDisplayId::DEFAULT, {110, 200})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionMove(); - monitor.consumeMotionMove(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionMove(ui::LogicalDisplayId::DEFAULT); // Now the foreground window goes away mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); @@ -6797,41 +6878,47 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsCanceledWhenForegroundWindowDis // cause a cancel for the monitor, as well. ASSERT_EQ(InputEventInjectionResult::FAILED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {120, 200})) + ui::LogicalDisplayId::DEFAULT, {120, 200})) << "Injection should fail because the window was removed"; window->assertNoEvents(); // Global monitor now gets the cancel - monitor.consumeMotionCancel(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionCancel(ui::LogicalDisplayId::DEFAULT); } TEST_F(InputDispatcherMonitorTest, ReceivesMotionEvents) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); - monitor.consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); } TEST_F(InputDispatcherMonitorTest, MonitorCannotPilferPointers) { - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - monitor.consumeMotionDown(ADISPLAY_ID_DEFAULT); - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); // Pilfer pointers from the monitor. // This should not do anything and the window should continue to receive events. @@ -6839,27 +6926,30 @@ TEST_F(InputDispatcherMonitorTest, MonitorCannotPilferPointers) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)) + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - monitor.consumeMotionMove(ADISPLAY_ID_DEFAULT); - window->consumeMotionMove(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionMove(ui::LogicalDisplayId::DEFAULT); + window->consumeMotionMove(ui::LogicalDisplayId::DEFAULT); } TEST_F(InputDispatcherMonitorTest, NoWindowTransform) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); window->setWindowOffset(20, 40); window->setWindowTransform(0, 1, -1, 0); - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); std::unique_ptr event = monitor.consumeMotion(); ASSERT_NE(nullptr, event); // Even though window has transform, gesture monitor must not. @@ -6868,10 +6958,12 @@ TEST_F(InputDispatcherMonitorTest, NoWindowTransform) { TEST_F(InputDispatcherMonitorTest, InjectionFailsWithNoWindow) { std::shared_ptr application = std::make_shared(); - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::FAILED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Injection should fail if there is a monitor, but no touchable window"; monitor.assertNoEvents(); } @@ -6889,20 +6981,21 @@ TEST_F(InputDispatcherMonitorTest, InjectionFailsWithNoWindow) { */ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCanceledWhenAnotherEmptyDisplayReceiveEvents) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Foreground", + ui::LogicalDisplayId::DEFAULT); - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); FakeMonitorReceiver secondMonitor = FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 200})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 200})) << "The down event injected into the first display should succeed"; window->consumeMotionDown(); - monitor.consumeMotionDown(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::FAILED, injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID, @@ -6913,19 +7006,19 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCanceledWhenAnotherEmptyDisp // Continue to inject event to first display. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {110, 220})) + ui::LogicalDisplayId::DEFAULT, {110, 220})) << "The move event injected into the first display should succeed"; window->consumeMotionMove(); - monitor.consumeMotionMove(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionMove(ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, {110, 220})) << "The up event injected into the first display should succeed"; window->consumeMotionUp(); - monitor.consumeMotionUp(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionUp(ui::LogicalDisplayId::DEFAULT); window->assertNoEvents(); monitor.assertNoEvents(); @@ -6949,24 +7042,25 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCanceledWhenAnotherEmptyDisp */ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCancelWhenAnotherDisplayMonitorTouchCanceled) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Foreground", + ui::LogicalDisplayId::DEFAULT); sp secondWindow = sp::make(application, mDispatcher, "SecondForeground", SECOND_DISPLAY_ID); - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); FakeMonitorReceiver secondMonitor = FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); // There is a foreground window on both displays. mDispatcher->onWindowInfosChanged({{*window->getInfo(), *secondWindow->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 200})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 200})) << "The down event injected into the first display should succeed"; - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); - monitor.consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + monitor.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID, @@ -6994,11 +7088,11 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCancelWhenAnotherDisplayMoni ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {110, 200})) + ui::LogicalDisplayId::DEFAULT, {110, 200})) << "The move event injected into the first display should succeed"; window->consumeMotionMove(); - monitor.consumeMotionMove(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionMove(ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::FAILED, injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID, @@ -7007,12 +7101,12 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCancelWhenAnotherDisplayMoni "touchable window"; ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, {110, 220})) << "The up event injected into the first display should succeed"; - window->consumeMotionUp(ADISPLAY_ID_DEFAULT); - monitor.consumeMotionUp(ADISPLAY_ID_DEFAULT); + window->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); + monitor.consumeMotionUp(ui::LogicalDisplayId::DEFAULT); window->assertNoEvents(); monitor.assertNoEvents(); @@ -7030,22 +7124,23 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsNotCancelWhenAnotherDisplayMoni */ TEST_F(InputDispatcherMonitorTest, MonitorTouchCancelEventWithDisplayTransform) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Foreground", + ui::LogicalDisplayId::DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); ui::Transform transform; transform.set({1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0, 0, 1}); gui::DisplayInfo displayInfo; - displayInfo.displayId = ADISPLAY_ID_DEFAULT; + displayInfo.displayId = ui::LogicalDisplayId::DEFAULT; displayInfo.transform = transform; mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {displayInfo}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 200})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 200})) << "The down event injected should succeed"; window->consumeMotionDown(); @@ -7055,7 +7150,7 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchCancelEventWithDisplayTransform) ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {110, 220})) + ui::LogicalDisplayId::DEFAULT, {110, 220})) << "The move event injected should succeed"; window->consumeMotionMove(); @@ -7071,19 +7166,19 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchCancelEventWithDisplayTransform) ASSERT_EQ(InputEventInjectionResult::FAILED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {110, 220})) + ui::LogicalDisplayId::DEFAULT, {110, 220})) << "The move event injected should failed"; // Now foreground should not receive any events, but monitor should receive a cancel event // with transform that same as display's display. std::unique_ptr cancelMotionEvent = monitor.consumeMotion(); EXPECT_EQ(transform, cancelMotionEvent->getTransform()); - EXPECT_EQ(ADISPLAY_ID_DEFAULT, cancelMotionEvent->getDisplayId()); + EXPECT_EQ(ui::LogicalDisplayId::DEFAULT, cancelMotionEvent->getDisplayId()); EXPECT_EQ(AMOTION_EVENT_ACTION_CANCEL, cancelMotionEvent->getAction()); // Other event inject to this display should fail. ASSERT_EQ(InputEventInjectionResult::FAILED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {110, 220})) + ui::LogicalDisplayId::DEFAULT, {110, 220})) << "The up event injected should fail because the touched window was removed"; window->assertNoEvents(); monitor.assertNoEvents(); @@ -7091,18 +7186,19 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchCancelEventWithDisplayTransform) TEST_F(InputDispatcherTest, TestMoveEvent) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Fake Window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); NotifyMotionArgs motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mDispatcher->notifyMotion(motionArgs); // Window should receive motion down event. - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); motionArgs.action = AMOTION_EVENT_ACTION_MOVE; motionArgs.id += 1; @@ -7111,7 +7207,7 @@ TEST_F(InputDispatcherTest, TestMoveEvent) { motionArgs.pointerCoords[0].getX() - 10); mDispatcher->notifyMotion(motionArgs); - window->consumeMotionMove(ADISPLAY_ID_DEFAULT, /*expectedFlags=*/0); + window->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, /*expectedFlags=*/0); } /** @@ -7121,12 +7217,13 @@ TEST_F(InputDispatcherTest, TestMoveEvent) { */ TEST_F(InputDispatcherTest, TouchModeState_IsSentToApps) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Test window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Test window", + ui::LogicalDisplayId::DEFAULT); const WindowInfo& windowInfo = *window->getInfo(); // Set focused application. - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); window->setFocusable(true); SCOPED_TRACE("Check default value of touch mode"); @@ -7141,7 +7238,7 @@ TEST_F(InputDispatcherTest, TouchModeState_IsSentToApps) { SCOPED_TRACE("Disable touch mode"); mDispatcher->setInTouchMode(false, windowInfo.ownerPid, windowInfo.ownerUid, - /*hasPermission=*/true, ADISPLAY_ID_DEFAULT); + /*hasPermission=*/true, ui::LogicalDisplayId::DEFAULT); window->consumeTouchModeEvent(false); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -7155,7 +7252,7 @@ TEST_F(InputDispatcherTest, TouchModeState_IsSentToApps) { SCOPED_TRACE("Enable touch mode again"); mDispatcher->setInTouchMode(true, windowInfo.ownerPid, windowInfo.ownerUid, - /*hasPermission=*/true, ADISPLAY_ID_DEFAULT); + /*hasPermission=*/true, ui::LogicalDisplayId::DEFAULT); window->consumeTouchModeEvent(true); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -7167,10 +7264,11 @@ TEST_F(InputDispatcherTest, TouchModeState_IsSentToApps) { TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Test window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Test window", + ui::LogicalDisplayId::DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -7205,23 +7303,24 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) { TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Test window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Test window", + ui::LogicalDisplayId::DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); ui::Transform transform; transform.set({1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0, 0, 1}); gui::DisplayInfo displayInfo; - displayInfo.displayId = ADISPLAY_ID_DEFAULT; + displayInfo.displayId = ui::LogicalDisplayId::DEFAULT; displayInfo.transform = transform; mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {displayInfo}, 0, 0}); const NotifyMotionArgs motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mDispatcher->notifyMotion(motionArgs); std::unique_ptr event = window->consumeMotionEvent(); @@ -7308,11 +7407,12 @@ TEST_F(InputDispatcherTest, GeneratedHmac_ChangesWhenFieldsChange) { TEST_F(InputDispatcherTest, SetFocusedWindow) { std::shared_ptr application = std::make_shared(); - sp windowTop = - sp::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp windowTop = sp::make(application, mDispatcher, "Top", + ui::LogicalDisplayId::DEFAULT); sp windowSecond = - sp::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + sp::make(application, mDispatcher, "Second", + ui::LogicalDisplayId::DEFAULT); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); // Top window is also focusable but is not granted focus. windowTop->setFocusable(true); @@ -7326,15 +7426,15 @@ TEST_F(InputDispatcherTest, SetFocusedWindow) { << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; // Focused window should receive event. - windowSecond->consumeKeyDown(ui::ADISPLAY_ID_NONE); + windowSecond->consumeKeyDown(ui::LogicalDisplayId::INVALID); windowTop->assertNoEvents(); } TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestInvalidChannel) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + sp window = sp::make(application, mDispatcher, "TestWindow", + ui::LogicalDisplayId::DEFAULT); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); window->setFocusable(true); // Release channel for window is no longer valid. @@ -7351,10 +7451,10 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestInvalidChannel) { TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestNoFocusableWindow) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "TestWindow", + ui::LogicalDisplayId::DEFAULT); window->setFocusable(false); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); setFocusedWindow(window); @@ -7368,11 +7468,12 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestNoFocusableWindow) { TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) { std::shared_ptr application = std::make_shared(); - sp windowTop = - sp::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp windowTop = sp::make(application, mDispatcher, "Top", + ui::LogicalDisplayId::DEFAULT); sp windowSecond = - sp::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + sp::make(application, mDispatcher, "Second", + ui::LogicalDisplayId::DEFAULT); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); windowTop->setFocusable(true); windowSecond->setFocusable(true); @@ -7391,16 +7492,17 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) { << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; // Focused window should receive event. - windowSecond->consumeKeyDown(ui::ADISPLAY_ID_NONE); + windowSecond->consumeKeyDown(ui::LogicalDisplayId::INVALID); } TEST_F(InputDispatcherTest, SetFocusedWindow_TransferFocusTokenNotFocusable) { std::shared_ptr application = std::make_shared(); - sp windowTop = - sp::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp windowTop = sp::make(application, mDispatcher, "Top", + ui::LogicalDisplayId::DEFAULT); sp windowSecond = - sp::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + sp::make(application, mDispatcher, "Second", + ui::LogicalDisplayId::DEFAULT); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); windowTop->setFocusable(true); windowSecond->setFocusable(false); @@ -7414,18 +7516,18 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_TransferFocusTokenNotFocusable) { << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; // Event should be dropped. - windowTop->consumeKeyDown(ui::ADISPLAY_ID_NONE); + windowTop->consumeKeyDown(ui::LogicalDisplayId::INVALID); windowSecond->assertNoEvents(); } TEST_F(InputDispatcherTest, SetFocusedWindow_DeferInvisibleWindow) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "TestWindow", + ui::LogicalDisplayId::DEFAULT); sp previousFocusedWindow = sp::make(application, mDispatcher, "previousFocusedWindow", - ADISPLAY_ID_DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + ui::LogicalDisplayId::DEFAULT); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); window->setFocusable(true); previousFocusedWindow->setFocusable(true); @@ -7442,7 +7544,7 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DeferInvisibleWindow) { // Injected key goes to pending queue. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, - ADISPLAY_ID_DEFAULT, InputEventInjectionSync::NONE)); + ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE)); // Window does not get focus event or key down. window->assertNoEvents(); @@ -7454,14 +7556,14 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DeferInvisibleWindow) { // Window receives focus event. window->consumeFocusEvent(true); // Focused window receives key down. - window->consumeKeyDown(ADISPLAY_ID_DEFAULT); + window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); } TEST_F(InputDispatcherTest, DisplayRemoved) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "window", ADISPLAY_ID_DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + sp window = sp::make(application, mDispatcher, "window", + ui::LogicalDisplayId::DEFAULT); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); // window is granted focus. window->setFocusable(true); @@ -7470,7 +7572,7 @@ TEST_F(InputDispatcherTest, DisplayRemoved) { window->consumeFocusEvent(true); // When a display is removed window loses focus. - mDispatcher->displayRemoved(ADISPLAY_ID_DEFAULT); + mDispatcher->displayRemoved(ui::LogicalDisplayId::DEFAULT); window->consumeFocusEvent(false); } @@ -7502,10 +7604,11 @@ TEST_F(InputDispatcherTest, SlipperyWindow_SetsFlagPartiallyObscured) { constexpr gui::Uid SLIPPERY_UID{WINDOW_UID.val() + 1}; std::shared_ptr application = std::make_shared(); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); sp slipperyExitWindow = - sp::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Top", + ui::LogicalDisplayId::DEFAULT); slipperyExitWindow->setSlippery(true); // Make sure this one overlaps the bottom window slipperyExitWindow->setFrame(Rect(25, 25, 75, 75)); @@ -7514,7 +7617,8 @@ TEST_F(InputDispatcherTest, SlipperyWindow_SetsFlagPartiallyObscured) { slipperyExitWindow->setOwnerInfo(SLIPPERY_PID, SLIPPERY_UID); sp slipperyEnterWindow = - sp::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Second", + ui::LogicalDisplayId::DEFAULT); slipperyExitWindow->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged( @@ -7522,20 +7626,20 @@ TEST_F(InputDispatcherTest, SlipperyWindow_SetsFlagPartiallyObscured) { // Use notifyMotion instead of injecting to avoid dealing with injection permissions mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {{50, 50}})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {{50, 50}})); slipperyExitWindow->consumeMotionDown(); slipperyExitWindow->setFrame(Rect(70, 70, 100, 100)); mDispatcher->onWindowInfosChanged( {{*slipperyExitWindow->getInfo(), *slipperyEnterWindow->getInfo()}, {}, 0, 0}); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {{51, 51}})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {{51, 51}})); slipperyExitWindow->consumeMotionCancel(); - slipperyEnterWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, + slipperyEnterWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); } @@ -7550,12 +7654,14 @@ TEST_F(InputDispatcherTest, TouchSlippingIntoWindowThatDropsTouches) { std::shared_ptr application = std::make_shared(); sp leftSlipperyWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftSlipperyWindow->setSlippery(true); leftSlipperyWindow->setFrame(Rect(0, 0, 100, 100)); sp rightDropTouchesWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightDropTouchesWindow->setFrame(Rect(100, 0, 200, 100)); rightDropTouchesWindow->setDropInput(true); @@ -7586,12 +7692,14 @@ TEST_F(InputDispatcherTest, TouchSlippingIntoWindowThatDropsTouches) { TEST_F(InputDispatcherTest, InjectedTouchSlips) { std::shared_ptr application = std::make_shared(); sp originalWindow = - sp::make(application, mDispatcher, "Original", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Original", + ui::LogicalDisplayId::DEFAULT); originalWindow->setFrame(Rect(0, 0, 200, 200)); originalWindow->setSlippery(true); sp appearingWindow = - sp::make(application, mDispatcher, "Appearing", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Appearing", + ui::LogicalDisplayId::DEFAULT); appearingWindow->setFrame(Rect(0, 0, 200, 200)); mDispatcher->onWindowInfosChanged({{*originalWindow->getInfo()}, {}, 0, 0}); @@ -7645,17 +7753,18 @@ TEST_F(InputDispatcherTest, MultiDeviceSpyWindowSlipTest) { std::shared_ptr application = std::make_shared(); sp leftWindow = sp::make(application, mDispatcher, "Left window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 100, 100)); leftWindow->setSlippery(true); sp rightWindow = sp::make(application, mDispatcher, "Right window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(100, 0, 200, 100)); sp spyWindow = - sp::make(application, mDispatcher, "Spy Window", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Spy Window", + ui::LogicalDisplayId::DEFAULT); spyWindow->setFrame(Rect(200, 0, 300, 100)); spyWindow->setSpy(true); spyWindow->setTrustedOverlay(true); @@ -7708,18 +7817,18 @@ TEST_F(InputDispatcherTest, MultiDeviceSlipperyWindowTest) { std::shared_ptr application = std::make_shared(); sp leftWindow = sp::make(application, mDispatcher, "Left window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 100, 100)); leftWindow->setSlippery(true); sp middleWindow = sp::make(application, mDispatcher, "middle window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); middleWindow->setFrame(Rect(100, 0, 200, 100)); sp rightWindow = sp::make(application, mDispatcher, "Right window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(200, 0, 300, 100)); rightWindow->setSlippery(true); @@ -7778,20 +7887,21 @@ TEST_F(InputDispatcherTest, NotifiesDeviceInteractionsWithMotions) { using Uid = gui::Uid; std::shared_ptr application = std::make_shared(); - sp leftWindow = - sp::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp leftWindow = sp::make(application, mDispatcher, "Left", + ui::LogicalDisplayId::DEFAULT); leftWindow->setFrame(Rect(0, 0, 100, 100)); leftWindow->setOwnerInfo(gui::Pid{1}, Uid{101}); sp rightSpy = - sp::make(application, mDispatcher, "Right spy", ADISPLAY_ID_DEFAULT); + sp::make(application, mDispatcher, "Right spy", + ui::LogicalDisplayId::DEFAULT); rightSpy->setFrame(Rect(100, 0, 200, 100)); rightSpy->setOwnerInfo(gui::Pid{2}, Uid{102}); rightSpy->setSpy(true); rightSpy->setTrustedOverlay(true); - sp rightWindow = - sp::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp rightWindow = sp::make(application, mDispatcher, "Right", + ui::LogicalDisplayId::DEFAULT); rightWindow->setFrame(Rect(100, 0, 200, 100)); rightWindow->setOwnerInfo(gui::Pid{3}, Uid{103}); @@ -7856,8 +7966,8 @@ TEST_F(InputDispatcherTest, NotifiesDeviceInteractionsWithMotions) { TEST_F(InputDispatcherTest, NotifiesDeviceInteractionsWithKeys) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); window->setOwnerInfo(gui::Pid{1}, gui::Uid{101}); @@ -7866,14 +7976,14 @@ TEST_F(InputDispatcherTest, NotifiesDeviceInteractionsWithKeys) { ASSERT_NO_FATAL_FAILURE(window->consumeFocusEvent(true)); mDispatcher->notifyKey(KeyArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_KEYBOARD).build()); - ASSERT_NO_FATAL_FAILURE(window->consumeKeyDown(ADISPLAY_ID_DEFAULT)); + ASSERT_NO_FATAL_FAILURE(window->consumeKeyDown(ui::LogicalDisplayId::DEFAULT)); mDispatcher->waitForIdle(); ASSERT_NO_FATAL_FAILURE( mFakePolicy->assertNotifyDeviceInteractionWasCalled(DEVICE_ID, {gui::Uid{101}})); // The UP actions are not treated as device interaction. mDispatcher->notifyKey(KeyArgsBuilder(ACTION_UP, AINPUT_SOURCE_KEYBOARD).build()); - ASSERT_NO_FATAL_FAILURE(window->consumeKeyUp(ADISPLAY_ID_DEFAULT)); + ASSERT_NO_FATAL_FAILURE(window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT)); mDispatcher->waitForIdle(); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertNotifyDeviceInteractionWasNotCalled()); } @@ -7882,13 +7992,14 @@ TEST_F(InputDispatcherTest, HoverEnterExitSynthesisUsesNewEventId) { std::shared_ptr application = std::make_shared(); sp left = sp::make(application, mDispatcher, "Left Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); left->setFrame(Rect(0, 0, 100, 100)); - sp right = sp::make(application, mDispatcher, - "Right Window", ADISPLAY_ID_DEFAULT); + sp right = + sp::make(application, mDispatcher, "Right Window", + ui::LogicalDisplayId::DEFAULT); right->setFrame(Rect(100, 0, 200, 100)); - sp spy = - sp::make(application, mDispatcher, "Spy Window", ADISPLAY_ID_DEFAULT); + sp spy = sp::make(application, mDispatcher, "Spy Window", + ui::LogicalDisplayId::DEFAULT); spy->setFrame(Rect(0, 0, 200, 100)); spy->setTrustedOverlay(true); spy->setSpy(true); @@ -7897,8 +8008,9 @@ TEST_F(InputDispatcherTest, HoverEnterExitSynthesisUsesNewEventId) { {{*spy->getInfo(), *left->getInfo(), *right->getInfo()}, {}, 0, 0}); // Send hover move to the left window, and ensure hover enter is synthesized with a new eventId. - NotifyMotionArgs notifyArgs = generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{50, 50}}); + NotifyMotionArgs notifyArgs = + generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, + ui::LogicalDisplayId::DEFAULT, {PointF{50, 50}}); mDispatcher->notifyMotion(notifyArgs); std::unique_ptr leftEnter = left->consumeMotionEvent( @@ -7911,8 +8023,8 @@ TEST_F(InputDispatcherTest, HoverEnterExitSynthesisUsesNewEventId) { WithEventIdSource(IdGenerator::Source::INPUT_DISPATCHER))); // Send move to the right window, and ensure hover exit and enter are synthesized with new ids. - notifyArgs = generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, ADISPLAY_ID_DEFAULT, - {PointF{150, 50}}); + notifyArgs = generateMotionArgs(ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS, + ui::LogicalDisplayId::DEFAULT, {PointF{150, 50}}); mDispatcher->notifyMotion(notifyArgs); std::unique_ptr leftExit = left->consumeMotionEvent( @@ -7934,8 +8046,8 @@ TEST_F(InputDispatcherTest, HoverEnterExitSynthesisUsesNewEventId) { */ TEST_F(InputDispatcherMultiDeviceTest, SingleDevicePointerDownEventRetentionWithoutWindowTarget) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -7960,8 +8072,8 @@ TEST_F(InputDispatcherMultiDeviceTest, SingleDevicePointerDownEventRetentionWith */ TEST_F(InputDispatcherMultiDeviceTest, SecondDeviceDownEventDroppedWithoutWindowTarget) { std::shared_ptr application = std::make_shared(); - sp window = - sp::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp window = sp::make(application, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); @@ -7991,7 +8103,8 @@ protected: mApp = std::make_shared(); - mWindow = sp::make(mApp, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + mWindow = sp::make(mApp, mDispatcher, "Window", + ui::LogicalDisplayId::DEFAULT); mWindow->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); @@ -8303,7 +8416,8 @@ protected: void setUpWindow() { mApp = std::make_shared(); - mWindow = sp::make(mApp, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + mWindow = sp::make(mApp, mDispatcher, "Fake Window", + ui::LogicalDisplayId::DEFAULT); mWindow->setFocusable(true); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); @@ -8312,13 +8426,14 @@ protected: } void sendAndConsumeKeyDown(int32_t deviceId) { - NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT); + NotifyKeyArgs keyArgs = + generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT); keyArgs.deviceId = deviceId; keyArgs.policyFlags |= POLICY_FLAG_TRUSTED; // Otherwise it won't generate repeat event mDispatcher->notifyKey(keyArgs); // Window should receive key down event. - mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); } void expectKeyRepeatOnce(int32_t repeatCount) { @@ -8328,19 +8443,21 @@ protected: } void sendAndConsumeKeyUp(int32_t deviceId) { - NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT); + NotifyKeyArgs keyArgs = + generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT); keyArgs.deviceId = deviceId; keyArgs.policyFlags |= POLICY_FLAG_TRUSTED; // Unless it won't generate repeat event mDispatcher->notifyKey(keyArgs); // Window should receive key down event. - mWindow->consumeKeyUp(ADISPLAY_ID_DEFAULT, + mWindow->consumeKeyUp(ui::LogicalDisplayId::DEFAULT, /*expectedFlags=*/0); } void injectKeyRepeat(int32_t repeatCount) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, repeatCount, ADISPLAY_ID_DEFAULT)) + injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, repeatCount, + ui::LogicalDisplayId::DEFAULT)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; } }; @@ -8401,7 +8518,7 @@ TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_StopsKeyRepeatAfterDisableInp sendAndConsumeKeyDown(DEVICE_ID); expectKeyRepeatOnce(/*repeatCount=*/1); mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID}); - mWindow->consumeKeyUp(ADISPLAY_ID_DEFAULT, + mWindow->consumeKeyUp(ui::LogicalDisplayId::DEFAULT, AKEY_EVENT_FLAG_CANCELED | AKEY_EVENT_FLAG_LONG_PRESS); mWindow->assertNoEvents(); } @@ -8433,7 +8550,7 @@ TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_RepeatKeyEventsUseUniqueEvent TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_CorrectRepeatCountWhenInjectKeyRepeat) { injectKeyRepeat(0); - mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); for (int32_t repeatCount = 1; repeatCount <= 2; ++repeatCount) { expectKeyRepeatOnce(repeatCount); } @@ -8449,11 +8566,11 @@ public: InputDispatcherTest::SetUp(); application1 = std::make_shared(); - windowInPrimary = - sp::make(application1, mDispatcher, "D_1", ADISPLAY_ID_DEFAULT); + windowInPrimary = sp::make(application1, mDispatcher, "D_1", + ui::LogicalDisplayId::DEFAULT); // Set focus window for primary display, but focused display would be second one. - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application1); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application1); windowInPrimary->setFocusable(true); mDispatcher->onWindowInfosChanged({{*windowInPrimary->getInfo()}, {}, 0, 0}); @@ -8494,9 +8611,10 @@ protected: TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayTouch) { // Test touch down on primary display. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - windowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT); + windowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); windowInSecondary->assertNoEvents(); // Test touch down on second display. @@ -8510,22 +8628,22 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayTouch) TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus) { // Test inject a key down with display id specified. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectKeyDownNoRepeat(*mDispatcher, ADISPLAY_ID_DEFAULT)) + injectKeyDownNoRepeat(*mDispatcher, ui::LogicalDisplayId::DEFAULT)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - windowInPrimary->consumeKeyDown(ADISPLAY_ID_DEFAULT); + windowInPrimary->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); windowInSecondary->assertNoEvents(); // Test inject a key down without display id specified. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDownNoRepeat(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; windowInPrimary->assertNoEvents(); - windowInSecondary->consumeKeyDown(ui::ADISPLAY_ID_NONE); + windowInSecondary->consumeKeyDown(ui::LogicalDisplayId::INVALID); // Remove all windows in secondary display. mDispatcher->onWindowInfosChanged({{*windowInPrimary->getInfo()}, {}, 0, 0}); // Old focus should receive a cancel event. - windowInSecondary->consumeKeyUp(ui::ADISPLAY_ID_NONE, AKEY_EVENT_FLAG_CANCELED); + windowInSecondary->consumeKeyUp(ui::LogicalDisplayId::INVALID, AKEY_EVENT_FLAG_CANCELED); // Test inject a key down, should timeout because of no target window. ASSERT_NO_FATAL_FAILURE(assertInjectedKeyTimesOut(*mDispatcher)); @@ -8537,16 +8655,17 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus) // Test per-display input monitors for motion event. TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) { FakeMonitorReceiver monitorInPrimary = - FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); FakeMonitorReceiver monitorInSecondary = FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); // Test touch down on primary display. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - windowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT); - monitorInPrimary.consumeMotionDown(ADISPLAY_ID_DEFAULT); + windowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + monitorInPrimary.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); windowInSecondary->assertNoEvents(); monitorInSecondary.assertNoEvents(); @@ -8570,19 +8689,20 @@ 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, ui::ADISPLAY_ID_NONE)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TRACKBALL, + ui::LogicalDisplayId::INVALID)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; windowInPrimary->assertNoEvents(); monitorInPrimary.assertNoEvents(); - windowInSecondary->consumeMotionDown(ui::ADISPLAY_ID_NONE); - monitorInSecondary.consumeMotionDown(ui::ADISPLAY_ID_NONE); + windowInSecondary->consumeMotionDown(ui::LogicalDisplayId::INVALID); + monitorInSecondary.consumeMotionDown(ui::LogicalDisplayId::INVALID); } // Test per-display input monitors for key event. TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorKeyEvent_MultiDisplay) { // Input monitor per display. FakeMonitorReceiver monitorInPrimary = - FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); FakeMonitorReceiver monitorInSecondary = FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); @@ -8591,13 +8711,14 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorKeyEvent_MultiDisplay) { << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; windowInPrimary->assertNoEvents(); monitorInPrimary.assertNoEvents(); - windowInSecondary->consumeKeyDown(ui::ADISPLAY_ID_NONE); - monitorInSecondary.consumeKeyDown(ui::ADISPLAY_ID_NONE); + windowInSecondary->consumeKeyDown(ui::LogicalDisplayId::INVALID); + monitorInSecondary.consumeKeyDown(ui::LogicalDisplayId::INVALID); } TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CanFocusWindowOnUnfocusedDisplay) { sp secondWindowInPrimary = - sp::make(application1, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); + sp::make(application1, mDispatcher, "D_1_W2", + ui::LogicalDisplayId::DEFAULT); secondWindowInPrimary->setFocusable(true); mDispatcher->onWindowInfosChanged( {{*windowInPrimary->getInfo(), *secondWindowInPrimary->getInfo(), @@ -8611,25 +8732,26 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CanFocusWindowOnUnfocusedDisplay) // Test inject a key down. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectKeyDown(*mDispatcher, ADISPLAY_ID_DEFAULT)) + injectKeyDown(*mDispatcher, ui::LogicalDisplayId::DEFAULT)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; windowInPrimary->assertNoEvents(); windowInSecondary->assertNoEvents(); - secondWindowInPrimary->consumeKeyDown(ADISPLAY_ID_DEFAULT); + secondWindowInPrimary->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); } TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CancelTouch_MultiDisplay) { FakeMonitorReceiver monitorInPrimary = - FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); FakeMonitorReceiver monitorInSecondary = FakeMonitorReceiver(*mDispatcher, "M_2", SECOND_DISPLAY_ID); // Test touch down on primary display. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - windowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT); - monitorInPrimary.consumeMotionDown(ADISPLAY_ID_DEFAULT); + windowInPrimary->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + monitorInPrimary.consumeMotionDown(ui::LogicalDisplayId::DEFAULT); // Test touch down on second display. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, @@ -8640,15 +8762,15 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CancelTouch_MultiDisplay) { // Trigger cancel touch. mDispatcher->cancelCurrentTouch(); - windowInPrimary->consumeMotionCancel(ADISPLAY_ID_DEFAULT); - monitorInPrimary.consumeMotionCancel(ADISPLAY_ID_DEFAULT); + windowInPrimary->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT); + monitorInPrimary.consumeMotionCancel(ui::LogicalDisplayId::DEFAULT); windowInSecondary->consumeMotionCancel(SECOND_DISPLAY_ID); monitorInSecondary.consumeMotionCancel(SECOND_DISPLAY_ID); // Test inject a move motion event, no window/monitor should receive the event. ASSERT_EQ(InputEventInjectionResult::FAILED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {110, 200})) + ui::LogicalDisplayId::DEFAULT, {110, 200})) << "Inject motion event should return InputEventInjectionResult::FAILED"; windowInPrimary->assertNoEvents(); monitorInPrimary.assertNoEvents(); @@ -8671,11 +8793,11 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropKeyEvent_OnlyCancelCorresp // Send a key down on primary display mDispatcher->notifyKey( KeyArgsBuilder(AKEY_EVENT_ACTION_DOWN, AINPUT_SOURCE_KEYBOARD) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT) .build()); - windowInPrimary->consumeKeyEvent( - AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), WithDisplayId(ADISPLAY_ID_DEFAULT))); + windowInPrimary->consumeKeyEvent(AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), + WithDisplayId(ui::LogicalDisplayId::DEFAULT))); windowInSecondary->assertNoEvents(); // Send a key down on second display @@ -8691,7 +8813,7 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropKeyEvent_OnlyCancelCorresp // Send a valid key up event on primary display that will be dropped because it is stale NotifyKeyArgs staleKeyUp = KeyArgsBuilder(AKEY_EVENT_ACTION_UP, AINPUT_SOURCE_KEYBOARD) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT) .build(); static constexpr std::chrono::duration STALE_EVENT_TIMEOUT = 10ms; @@ -8703,7 +8825,7 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropKeyEvent_OnlyCancelCorresp // Therefore, windowInPrimary should get the cancel event and windowInSecondary should not // receive any events. windowInPrimary->consumeKeyEvent(AllOf(WithKeyAction(AKEY_EVENT_ACTION_UP), - WithDisplayId(ADISPLAY_ID_DEFAULT), + WithDisplayId(ui::LogicalDisplayId::DEFAULT), WithFlags(AKEY_EVENT_FLAG_CANCELED))); windowInSecondary->assertNoEvents(); } @@ -8716,10 +8838,10 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropMotionEvent_OnlyCancelCorr mDispatcher->notifyMotion( MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .build()); windowInPrimary->consumeMotionEvent( - AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(ADISPLAY_ID_DEFAULT))); + AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); windowInSecondary->assertNoEvents(); // Send touch down on second display. @@ -8735,7 +8857,7 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropMotionEvent_OnlyCancelCorr // inject a valid MotionEvent on primary display that will be stale when it arrives. NotifyMotionArgs staleMotionUp = MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) .build(); static constexpr std::chrono::duration STALE_EVENT_TIMEOUT = 10ms; @@ -8790,19 +8912,19 @@ protected: // Test InputFilter for MotionEvent TEST_F(InputFilterTest, MotionEvent_InputFilter) { // Since the InputFilter is disabled by default, check if touch events aren't filtered. - testNotifyMotion(ADISPLAY_ID_DEFAULT, /*expectToBeFiltered=*/false); + testNotifyMotion(ui::LogicalDisplayId::DEFAULT, /*expectToBeFiltered=*/false); testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered=*/false); // Enable InputFilter mDispatcher->setInputFilterEnabled(true); // Test touch on both primary and second display, and check if both events are filtered. - testNotifyMotion(ADISPLAY_ID_DEFAULT, /*expectToBeFiltered=*/true); + testNotifyMotion(ui::LogicalDisplayId::DEFAULT, /*expectToBeFiltered=*/true); testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered=*/true); // Disable InputFilter mDispatcher->setInputFilterEnabled(false); // Test touch on both primary and second display, and check if both events aren't filtered. - testNotifyMotion(ADISPLAY_ID_DEFAULT, /*expectToBeFiltered=*/false); + testNotifyMotion(ui::LogicalDisplayId::DEFAULT, /*expectToBeFiltered=*/false); testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered=*/false); } @@ -8831,7 +8953,7 @@ TEST_F(InputFilterTest, MotionEvent_UsesLogicalDisplayCoordinates_notifyMotion) secondDisplayTransform.set({-6.6, -5.5, -4.4, -3.3, -2.2, -1.1, 0, 0, 1}); std::vector displayInfos(2); - displayInfos[0].displayId = ADISPLAY_ID_DEFAULT; + displayInfos[0].displayId = ui::LogicalDisplayId::DEFAULT; displayInfos[0].transform = firstDisplayTransform; displayInfos[1].displayId = SECOND_DISPLAY_ID; displayInfos[1].transform = secondDisplayTransform; @@ -8842,7 +8964,8 @@ TEST_F(InputFilterTest, MotionEvent_UsesLogicalDisplayCoordinates_notifyMotion) mDispatcher->setInputFilterEnabled(true); // Ensure the correct transforms are used for the displays. - testNotifyMotion(ADISPLAY_ID_DEFAULT, /*expectToBeFiltered=*/true, firstDisplayTransform); + testNotifyMotion(ui::LogicalDisplayId::DEFAULT, /*expectToBeFiltered=*/true, + firstDisplayTransform); testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered=*/true, secondDisplayTransform); } @@ -8861,9 +8984,9 @@ protected: std::shared_ptr application = std::make_shared(); mWindow = sp::make(application, mDispatcher, "Test Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mWindow->setFocusable(true); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); setFocusedWindow(mWindow); @@ -8876,8 +8999,8 @@ protected: const nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC); event.initialize(InputEvent::nextId(), injectedDeviceId, AINPUT_SOURCE_KEYBOARD, - ui::ADISPLAY_ID_NONE, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, 0, AKEYCODE_A, - KEY_A, AMETA_NONE, /*repeatCount=*/0, eventTime, eventTime); + ui::LogicalDisplayId::INVALID, 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; ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, @@ -8957,13 +9080,13 @@ protected: std::make_shared(); application->setDispatchingTimeout(100ms); mWindow = sp::make(application, mDispatcher, "TestWindow", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mWindow->setFrame(Rect(0, 0, 100, 100)); mWindow->setDispatchingTimeout(100ms); mWindow->setFocusable(true); // Set focused application. - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); setFocusedWindow(mWindow); @@ -8991,50 +9114,55 @@ TEST_F_WITH_FLAGS( mDispatcher->setMinTimeBetweenUserActivityPokes(50ms); // First event of type TOUCH. Should poke. - notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(50)); mFakePolicy->assertUserActivityPoked( - {{milliseconds_to_nanoseconds(50), USER_ACTIVITY_EVENT_TOUCH, ADISPLAY_ID_DEFAULT}}); + {{milliseconds_to_nanoseconds(50), USER_ACTIVITY_EVENT_TOUCH, + ui::LogicalDisplayId::DEFAULT}}); // 80ns > 50ns has passed since previous TOUCH event. Should poke. - notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(130)); mFakePolicy->assertUserActivityPoked( - {{milliseconds_to_nanoseconds(130), USER_ACTIVITY_EVENT_TOUCH, ADISPLAY_ID_DEFAULT}}); + {{milliseconds_to_nanoseconds(130), USER_ACTIVITY_EVENT_TOUCH, + ui::LogicalDisplayId::DEFAULT}}); // First event of type OTHER. Should poke (despite being within 50ns of previous TOUCH event). - notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, ADISPLAY_ID_DEFAULT, - milliseconds_to_nanoseconds(135)); + notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, + ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(135)); mFakePolicy->assertUserActivityPoked( - {{milliseconds_to_nanoseconds(135), USER_ACTIVITY_EVENT_OTHER, ADISPLAY_ID_DEFAULT}}); + {{milliseconds_to_nanoseconds(135), USER_ACTIVITY_EVENT_OTHER, + ui::LogicalDisplayId::DEFAULT}}); // Within 50ns of previous TOUCH event. Should NOT poke. - notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(140)); mFakePolicy->assertUserActivityNotPoked(); // Within 50ns of previous OTHER event. Should NOT poke. - notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, ADISPLAY_ID_DEFAULT, - milliseconds_to_nanoseconds(150)); + notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, + ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(150)); mFakePolicy->assertUserActivityNotPoked(); // Within 50ns of previous TOUCH event (which was at time 130). Should NOT poke. // Note that STYLUS is mapped to TOUCH user activity, since it's a pointer-type source. - notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_STYLUS, ADISPLAY_ID_DEFAULT, + notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(160)); mFakePolicy->assertUserActivityNotPoked(); // 65ns > 50ns has passed since previous OTHER event. Should poke. - notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, ADISPLAY_ID_DEFAULT, - milliseconds_to_nanoseconds(200)); + notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER, + ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(200)); mFakePolicy->assertUserActivityPoked( - {{milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_OTHER, ADISPLAY_ID_DEFAULT}}); + {{milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_OTHER, + ui::LogicalDisplayId::DEFAULT}}); // 170ns > 50ns has passed since previous TOUCH event. Should poke. - notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_STYLUS, ADISPLAY_ID_DEFAULT, + notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(300)); mFakePolicy->assertUserActivityPoked( - {{milliseconds_to_nanoseconds(300), USER_ACTIVITY_EVENT_TOUCH, ADISPLAY_ID_DEFAULT}}); + {{milliseconds_to_nanoseconds(300), USER_ACTIVITY_EVENT_TOUCH, + ui::LogicalDisplayId::DEFAULT}}); // Assert that there's no more user activity poke event. mFakePolicy->assertUserActivityNotPoked(); @@ -9044,19 +9172,21 @@ TEST_F_WITH_FLAGS( InputDispatcherUserActivityPokeTests, DefaultMinPokeTimeOf100MsUsed, REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags, rate_limit_user_activity_poke_in_dispatcher))) { - notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(200)); mFakePolicy->assertUserActivityPoked( - {{milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_TOUCH, ADISPLAY_ID_DEFAULT}}); + {{milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_TOUCH, + ui::LogicalDisplayId::DEFAULT}}); - notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(280)); mFakePolicy->assertUserActivityNotPoked(); - notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, milliseconds_to_nanoseconds(340)); mFakePolicy->assertUserActivityPoked( - {{milliseconds_to_nanoseconds(340), USER_ACTIVITY_EVENT_TOUCH, ADISPLAY_ID_DEFAULT}}); + {{milliseconds_to_nanoseconds(340), USER_ACTIVITY_EVENT_TOUCH, + ui::LogicalDisplayId::DEFAULT}}); } TEST_F_WITH_FLAGS( @@ -9065,10 +9195,12 @@ TEST_F_WITH_FLAGS( rate_limit_user_activity_poke_in_dispatcher))) { mDispatcher->setMinTimeBetweenUserActivityPokes(0ms); - notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, 20); + notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, + 20); mFakePolicy->assertUserActivityPoked(); - notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, 30); + notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, + 30); mFakePolicy->assertUserActivityPoked(); } @@ -9078,16 +9210,16 @@ class InputDispatcherOnPointerDownOutsideFocus : public InputDispatcherTest { std::shared_ptr application = std::make_shared(); - mUnfocusedWindow = - sp::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + mUnfocusedWindow = sp::make(application, mDispatcher, "Top", + ui::LogicalDisplayId::DEFAULT); mUnfocusedWindow->setFrame(Rect(0, 0, 30, 30)); - mFocusedWindow = - sp::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + mFocusedWindow = sp::make(application, mDispatcher, "Second", + ui::LogicalDisplayId::DEFAULT); mFocusedWindow->setFrame(Rect(50, 50, 100, 100)); // Set focused application. - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mFocusedWindow->setFocusable(true); // Expect one focus window exist in display. @@ -9115,8 +9247,8 @@ protected: // the onPointerDownOutsideFocus callback. TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_Success) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {20, 20})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {20, 20})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mUnfocusedWindow->consumeMotionDown(); @@ -9129,7 +9261,7 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_Succe // onPointerDownOutsideFocus callback. TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonPointerSource) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TRACKBALL, ADISPLAY_ID_DEFAULT, + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TRACKBALL, ui::LogicalDisplayId::DEFAULT, {20, 20})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mFocusedWindow->consumeMotionDown(); @@ -9142,9 +9274,9 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonPo // have focus. Ensure no window received the onPointerDownOutsideFocus callback. TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonMotionFailure) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectKeyDownNoRepeat(*mDispatcher, ADISPLAY_ID_DEFAULT)) + injectKeyDownNoRepeat(*mDispatcher, ui::LogicalDisplayId::DEFAULT)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mFocusedWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT); + mFocusedWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertOnPointerDownWasNotCalled(); @@ -9155,8 +9287,8 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonMo // onPointerDownOutsideFocus callback. TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_OnAlreadyFocusedWindow) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - FOCUSED_WINDOW_TOUCH_POINT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, FOCUSED_WINDOW_TOUCH_POINT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mFocusedWindow->consumeMotionDown(); @@ -9175,7 +9307,8 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, NoFocusChangeFlag) { .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, event)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mUnfocusedWindow->consumeAnyMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mUnfocusedWindow->consumeAnyMotionDown(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertOnPointerDownWasNotCalled(); @@ -9192,10 +9325,10 @@ class InputDispatcherMultiWindowSameTokenTests : public InputDispatcherTest { std::shared_ptr application = std::make_shared(); mWindow1 = sp::make(application, mDispatcher, "Fake Window 1", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mWindow1->setFrame(Rect(0, 0, 100, 100)); - mWindow2 = mWindow1->clone(ADISPLAY_ID_DEFAULT); + mWindow2 = mWindow1->clone(ui::LogicalDisplayId::DEFAULT); mWindow2->setFrame(Rect(100, 100, 200, 200)); mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0}); @@ -9236,7 +9369,7 @@ protected: const std::vector& touchedPoints, std::vector expectedPoints) { mDispatcher->notifyMotion(generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, touchedPoints)); + ui::LogicalDisplayId::DEFAULT, touchedPoints)); consumeMotionEvent(touchedWindow, action, expectedPoints); } @@ -9383,14 +9516,14 @@ TEST_F(InputDispatcherMultiWindowSameTokenTests, TouchDoesNotSlipEvenIfSlippery) // Touch down in window 1 mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {{50, 50}})); + ui::LogicalDisplayId::DEFAULT, {{50, 50}})); consumeMotionEvent(mWindow1, ACTION_DOWN, {{50, 50}}); // Move touch to be above window 2. Even though window 1 is slippery, touch should not slip. // That means the gesture should continue normally, without any ACTION_CANCEL or ACTION_DOWN // getting generated. mDispatcher->notifyMotion(generateMotionArgs(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {{150, 150}})); + ui::LogicalDisplayId::DEFAULT, {{150, 150}})); consumeMotionEvent(mWindow1, ACTION_MOVE, {{150, 150}}); } @@ -9425,13 +9558,13 @@ class InputDispatcherSingleWindowAnr : public InputDispatcherTest { mApplication = std::make_shared(); mApplication->setDispatchingTimeout(100ms); mWindow = sp::make(mApplication, mDispatcher, "TestWindow", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mWindow->setFrame(Rect(0, 0, 30, 30)); mWindow->setDispatchingTimeout(100ms); mWindow->setFocusable(true); // Set focused application. - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApplication); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApplication); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); setFocusedWindow(mWindow); @@ -9462,8 +9595,8 @@ protected: } sp addSpyWindow() { - sp spy = - sp::make(mApplication, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp spy = sp::make(mApplication, mDispatcher, "Spy", + ui::LogicalDisplayId::DEFAULT); spy->setTrustedOverlay(true); spy->setFocusable(false); spy->setSpy(true); @@ -9485,7 +9618,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(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertNotifyAnrWasNotCalled(); } @@ -9496,15 +9629,16 @@ TEST_F(InputDispatcherSingleWindowAnr, WhenFocusedApplicationChanges_NoAnr) { mWindow->consumeFocusEvent(false); InputEventInjectionResult result = - injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::NONE, CONSUME_TIMEOUT_EVENT_EXPECTED, + injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, + ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, + CONSUME_TIMEOUT_EVENT_EXPECTED, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); // Key will not go to window because we have no focused window. // The 'no focused window' ANR timer should start instead. // Now, the focused application goes away. - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, nullptr); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, nullptr); // The key should get dropped and there should be no ANR. ASSERT_TRUE(mDispatcher->waitForIdle()); @@ -9516,8 +9650,8 @@ TEST_F(InputDispatcherSingleWindowAnr, WhenFocusedApplicationChanges_NoAnr) { // So InputDispatcher will enqueue ACTION_CANCEL event as well. TEST_F(InputDispatcherSingleWindowAnr, OnPointerDown_BasicAnr) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - WINDOW_LOCATION)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); const auto [sequenceNum, _] = mWindow->receiveEvent(); // ACTION_DOWN ASSERT_TRUE(sequenceNum); @@ -9526,7 +9660,7 @@ TEST_F(InputDispatcherSingleWindowAnr, OnPointerDown_BasicAnr) { mWindow->finishEvent(*sequenceNum); mWindow->consumeMotionEvent( - AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ADISPLAY_ID_DEFAULT))); + AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); } @@ -9550,8 +9684,8 @@ TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_NoFocusedWindow) { // taps on the window work as normal ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - WINDOW_LOCATION)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionDown()); mDispatcher->waitForIdle(); mFakePolicy->assertNotifyAnrWasNotCalled(); @@ -9560,8 +9694,8 @@ TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_NoFocusedWindow) { // We specify the injection timeout to be smaller than the application timeout, to ensure that // 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, + injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, + ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::WAIT_FOR_RESULT, 50ms, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result); const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT); @@ -9585,9 +9719,10 @@ 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, ui::ADISPLAY_ID_NONE, - INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, /*flags=*/0, AKEYCODE_A, KEY_A, - AMETA_NONE, /*repeatCount=*/0, eventTime, eventTime); + event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_KEYBOARD, + ui::LogicalDisplayId::INVALID, INVALID_HMAC, AKEY_EVENT_ACTION_DOWN, + /*flags=*/0, AKEYCODE_A, KEY_A, AMETA_NONE, /*repeatCount=*/0, eventTime, + eventTime); const int32_t policyFlags = POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_DISABLE_KEY_REPEAT; @@ -9609,7 +9744,7 @@ TEST_F(InputDispatcherSingleWindowAnr, StaleKeyEventDoesNotAnr) { TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DoesNotSendDuplicateAnr) { const std::chrono::duration appTimeout = 400ms; mApplication->setDispatchingTimeout(appTimeout); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApplication); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApplication); mWindow->setFocusable(false); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo()}, {}, 0, 0}); @@ -9621,8 +9756,9 @@ TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DoesNotSendDuplicateAnr) const std::chrono::duration eventInjectionTimeout = 100ms; ASSERT_LT(eventInjectionTimeout, appTimeout); const InputEventInjectionResult result = - injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::WAIT_FOR_RESULT, eventInjectionTimeout, + injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, + ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::WAIT_FOR_RESULT, + eventInjectionTimeout, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result) << "result=" << ftl::enum_string(result); @@ -9670,20 +9806,20 @@ TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DropsFocusedEvents) { TEST_F(InputDispatcherSingleWindowAnr, Anr_HandlesEventsWithIdenticalTimestamps) { nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, WINDOW_LOCATION, + ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION, {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION}, 500ms, InputEventInjectionSync::WAIT_FOR_RESULT, currentTime); // Now send ACTION_UP, with identical timestamp injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, WINDOW_LOCATION, + ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION, {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION}, 500ms, InputEventInjectionSync::WAIT_FOR_RESULT, currentTime); // We have now sent down and up. Let's consume first event and then ANR on the second. - mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); } @@ -9693,8 +9829,8 @@ TEST_F(InputDispatcherSingleWindowAnr, SpyWindowAnr) { sp spy = addSpyWindow(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - WINDOW_LOCATION)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); mWindow->consumeMotionDown(); const auto [sequenceNum, _] = spy->receiveEvent(); // ACTION_DOWN @@ -9704,7 +9840,7 @@ TEST_F(InputDispatcherSingleWindowAnr, SpyWindowAnr) { spy->finishEvent(*sequenceNum); spy->consumeMotionEvent( - AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ADISPLAY_ID_DEFAULT))); + AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertNotifyWindowResponsiveWasCalled(spy->getToken(), mWindow->getPid()); } @@ -9715,9 +9851,10 @@ TEST_F(InputDispatcherSingleWindowAnr, SpyWindowReceivesEventsDuringAppAnrOnKey) sp spy = addSpyWindow(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectKeyDown(*mDispatcher, ADISPLAY_ID_DEFAULT)); - mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT); - ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher, ADISPLAY_ID_DEFAULT)); + injectKeyDown(*mDispatcher, ui::LogicalDisplayId::DEFAULT)); + mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); + ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, + injectKeyUp(*mDispatcher, ui::LogicalDisplayId::DEFAULT)); // Stuck on the ACTION_UP const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); @@ -9725,10 +9862,10 @@ TEST_F(InputDispatcherSingleWindowAnr, SpyWindowReceivesEventsDuringAppAnrOnKey) // New tap will go to the spy window, but not to the window tapOnWindow(); - spy->consumeMotionDown(ADISPLAY_ID_DEFAULT); - spy->consumeMotionUp(ADISPLAY_ID_DEFAULT); + spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + spy->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); - mWindow->consumeKeyUp(ADISPLAY_ID_DEFAULT); // still the previous motion + mWindow->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); // still the previous motion mDispatcher->waitForIdle(); mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); mWindow->assertNoEvents(); @@ -9741,8 +9878,8 @@ TEST_F(InputDispatcherSingleWindowAnr, SpyWindowReceivesEventsDuringAppAnrOnMoti sp spy = addSpyWindow(); tapOnWindow(); - spy->consumeMotionDown(ADISPLAY_ID_DEFAULT); - spy->consumeMotionUp(ADISPLAY_ID_DEFAULT); + spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + spy->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); mWindow->consumeMotionDown(); // Stuck on the ACTION_UP @@ -9751,10 +9888,10 @@ TEST_F(InputDispatcherSingleWindowAnr, SpyWindowReceivesEventsDuringAppAnrOnMoti // New tap will go to the spy window, but not to the window tapOnWindow(); - spy->consumeMotionDown(ADISPLAY_ID_DEFAULT); - spy->consumeMotionUp(ADISPLAY_ID_DEFAULT); + spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + spy->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); - mWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT); // still the previous motion + mWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); // still the previous motion mDispatcher->waitForIdle(); mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); mWindow->assertNoEvents(); @@ -9764,13 +9901,14 @@ TEST_F(InputDispatcherSingleWindowAnr, SpyWindowReceivesEventsDuringAppAnrOnMoti TEST_F(InputDispatcherSingleWindowAnr, UnresponsiveMonitorAnr) { mDispatcher->setMonitorDispatchingTimeoutForTest(SPY_TIMEOUT); - FakeMonitorReceiver monitor = FakeMonitorReceiver(*mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); + FakeMonitorReceiver monitor = + FakeMonitorReceiver(*mDispatcher, "M_1", ui::LogicalDisplayId::DEFAULT); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - WINDOW_LOCATION)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); - mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); const std::optional consumeSeq = monitor.receiveEvent(); ASSERT_TRUE(consumeSeq); @@ -9778,7 +9916,7 @@ TEST_F(InputDispatcherSingleWindowAnr, UnresponsiveMonitorAnr) { MONITOR_PID); monitor.finishEvent(*consumeSeq); - monitor.consumeMotionCancel(ADISPLAY_ID_DEFAULT); + monitor.consumeMotionCancel(ui::LogicalDisplayId::DEFAULT); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertNotifyWindowResponsiveWasCalled(monitor.getToken(), MONITOR_PID); @@ -9817,8 +9955,8 @@ TEST_F(InputDispatcherSingleWindowAnr, SameWindow_CanReceiveAnrTwice) { // it. TEST_F(InputDispatcherSingleWindowAnr, Policy_DoesNotGetDuplicateAnr) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - WINDOW_LOCATION)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, WINDOW_LOCATION)); const std::chrono::duration windowTimeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(windowTimeout, mWindow); @@ -9828,7 +9966,7 @@ TEST_F(InputDispatcherSingleWindowAnr, Policy_DoesNotGetDuplicateAnr) { // When the ANR happened, dispatcher should abort the current event stream via ACTION_CANCEL mWindow->consumeMotionDown(); mWindow->consumeMotionEvent( - AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ADISPLAY_ID_DEFAULT))); + AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); mWindow->assertNoEvents(); mDispatcher->waitForIdle(); mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), mWindow->getPid()); @@ -9865,7 +10003,7 @@ TEST_F(InputDispatcherSingleWindowAnr, Key_StaysPendingWhileMotionIsProcessed) { std::this_thread::sleep_for(400ms); // if we wait long enough though, dispatcher will give up, and still send the key // to the focused window, even though we have not yet finished the motion event - mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); mWindow->finishEvent(*downSequenceNum); mWindow->finishEvent(*upSequenceNum); } @@ -9969,8 +10107,8 @@ TEST_F(InputDispatcherSingleWindowAnr, TwoGesturesWithAnr) { // So InputDispatcher will enqueue ACTION_CANCEL event as well. TEST_F(InputDispatcherSingleWindowAnr, AnrAfterWindowRemoval) { mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {WINDOW_LOCATION})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {WINDOW_LOCATION})); const auto [sequenceNum, _] = mWindow->receiveEvent(); // ACTION_DOWN ASSERT_TRUE(sequenceNum); @@ -9987,7 +10125,7 @@ TEST_F(InputDispatcherSingleWindowAnr, AnrAfterWindowRemoval) { mWindow->finishEvent(*sequenceNum); // The cancellation was generated when the window was removed, along with the focus event. mWindow->consumeMotionEvent( - AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ADISPLAY_ID_DEFAULT))); + AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); mWindow->consumeFocusEvent(false); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertNotifyWindowResponsiveWasCalled(mWindow->getToken(), /*pid=*/std::nullopt); @@ -9997,8 +10135,8 @@ TEST_F(InputDispatcherSingleWindowAnr, AnrAfterWindowRemoval) { // notified of the unresponsive window, then remove the app window. TEST_F(InputDispatcherSingleWindowAnr, AnrFollowedByWindowRemoval) { mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {WINDOW_LOCATION})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {WINDOW_LOCATION})); const auto [sequenceNum, _] = mWindow->receiveEvent(); // ACTION_DOWN ASSERT_TRUE(sequenceNum); @@ -10011,7 +10149,7 @@ TEST_F(InputDispatcherSingleWindowAnr, AnrFollowedByWindowRemoval) { mWindow->finishEvent(*sequenceNum); // The cancellation was generated during the ANR, and the window lost focus when it was removed. mWindow->consumeMotionEvent( - AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ADISPLAY_ID_DEFAULT))); + AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ui::LogicalDisplayId::DEFAULT))); mWindow->consumeFocusEvent(false); ASSERT_TRUE(mDispatcher->waitForIdle()); // Since the window was removed, Dispatcher does not know the PID associated with the window @@ -10026,18 +10164,18 @@ class InputDispatcherMultiWindowAnr : public InputDispatcherTest { mApplication = std::make_shared(); mApplication->setDispatchingTimeout(100ms); mUnfocusedWindow = sp::make(mApplication, mDispatcher, "Unfocused", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mUnfocusedWindow->setFrame(Rect(0, 0, 30, 30)); // Adding FLAG_WATCH_OUTSIDE_TOUCH to receive ACTION_OUTSIDE when another window is tapped mUnfocusedWindow->setWatchOutsideTouch(true); mFocusedWindow = sp::make(mApplication, mDispatcher, "Focused", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mFocusedWindow->setDispatchingTimeout(100ms); mFocusedWindow->setFrame(Rect(50, 50, 100, 100)); // Set focused application. - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApplication); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApplication); mFocusedWindow->setFocusable(true); // Expect one focus window exist in display. @@ -10069,11 +10207,11 @@ protected: private: void tap(const PointF& location) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - location)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, location)); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - location)); + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, location)); } }; @@ -10098,7 +10236,7 @@ TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsive) { .build())); mFocusedWindow->consumeMotionDown(); mFocusedWindow->consumeMotionUp(); - mUnfocusedWindow->consumeMotionOutside(ADISPLAY_ID_DEFAULT, /*flags=*/0); + mUnfocusedWindow->consumeMotionOutside(ui::LogicalDisplayId::DEFAULT, /*flags=*/0); // We consumed all events, so no ANR ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertNotifyAnrWasNotCalled(); @@ -10174,7 +10312,7 @@ TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsiveWithSameTimeout // At the same time, FLAG_WATCH_OUTSIDE_TOUCH targets should not receive any events. TEST_F(InputDispatcherMultiWindowAnr, DuringAnr_SecondTapIsIgnored) { tapOnFocusedWindow(); - mUnfocusedWindow->consumeMotionOutside(ADISPLAY_ID_DEFAULT, /*flags=*/0); + mUnfocusedWindow->consumeMotionOutside(ui::LogicalDisplayId::DEFAULT, /*flags=*/0); // Receive the events, but don't respond const auto [downEventSequenceNum, downEvent] = mFocusedWindow->receiveEvent(); // ACTION_DOWN ASSERT_TRUE(downEventSequenceNum); @@ -10187,10 +10325,10 @@ TEST_F(InputDispatcherMultiWindowAnr, DuringAnr_SecondTapIsIgnored) { // Tap once again // We cannot use "tapOnFocusedWindow" because it asserts the injection result to be success ASSERT_EQ(InputEventInjectionResult::FAILED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - FOCUSED_WINDOW_LOCATION)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, FOCUSED_WINDOW_LOCATION)); ASSERT_EQ(InputEventInjectionResult::FAILED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, FOCUSED_WINDOW_LOCATION)); // Unfocused window does not receive ACTION_OUTSIDE because the tapped window is not a // valid touch target @@ -10211,8 +10349,8 @@ TEST_F(InputDispatcherMultiWindowAnr, DuringAnr_SecondTapIsIgnored) { // If you tap outside of all windows, there will not be ANR TEST_F(InputDispatcherMultiWindowAnr, TapOutsideAllWindows_DoesNotAnr) { ASSERT_EQ(InputEventInjectionResult::FAILED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - LOCATION_OUTSIDE_ALL_WINDOWS)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, LOCATION_OUTSIDE_ALL_WINDOWS)); ASSERT_TRUE(mDispatcher->waitForIdle()); mFakePolicy->assertNotifyAnrWasNotCalled(); } @@ -10224,8 +10362,8 @@ TEST_F(InputDispatcherMultiWindowAnr, Window_CanBePaused) { {{*mUnfocusedWindow->getInfo(), *mFocusedWindow->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::FAILED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - FOCUSED_WINDOW_LOCATION)); + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, FOCUSED_WINDOW_LOCATION)); std::this_thread::sleep_for(mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT)); ASSERT_TRUE(mDispatcher->waitForIdle()); @@ -10265,8 +10403,8 @@ TEST_F(InputDispatcherMultiWindowAnr, PendingKey_GoesToNewlyFocusedWindow) { // window even if motions are still being processed. InputEventInjectionResult result = - injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::NONE, + injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, + ui::LogicalDisplayId::DEFAULT, 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 @@ -10293,7 +10431,7 @@ TEST_F(InputDispatcherMultiWindowAnr, PendingKey_GoesToNewlyFocusedWindow) { // Now that all queues are cleared and no backlog in the connections, the key event // can finally go to the newly focused "mUnfocusedWindow". - mUnfocusedWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT); + mUnfocusedWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); mFocusedWindow->assertNoEvents(); mUnfocusedWindow->assertNoEvents(); mFakePolicy->assertNotifyAnrWasNotCalled(); @@ -10304,14 +10442,15 @@ TEST_F(InputDispatcherMultiWindowAnr, PendingKey_GoesToNewlyFocusedWindow) { // The other window should not be affected by that. TEST_F(InputDispatcherMultiWindowAnr, SplitTouch_SingleWindowAnr) { // Touch Window 1 - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {FOCUSED_WINDOW_LOCATION})); - mUnfocusedWindow->consumeMotionOutside(ADISPLAY_ID_DEFAULT, /*flags=*/0); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {FOCUSED_WINDOW_LOCATION})); + mUnfocusedWindow->consumeMotionOutside(ui::LogicalDisplayId::DEFAULT, /*flags=*/0); // Touch Window 2 mDispatcher->notifyMotion( - generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {FOCUSED_WINDOW_LOCATION, UNFOCUSED_WINDOW_LOCATION})); const std::chrono::duration timeout = @@ -10357,7 +10496,7 @@ TEST_F(InputDispatcherMultiWindowAnr, FocusedWindowWithoutSetFocusedApplication_ std::shared_ptr focusedApplication = std::make_shared(); focusedApplication->setDispatchingTimeout(300ms); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, focusedApplication); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, focusedApplication); // The application that owns 'mFocusedWindow' and 'mUnfocusedWindow' is not focused. mFocusedWindow->setFocusable(false); @@ -10369,8 +10508,8 @@ TEST_F(InputDispatcherMultiWindowAnr, FocusedWindowWithoutSetFocusedApplication_ // 'focusedApplication' will get blamed if this timer completes. // Key will not be sent anywhere because we have no focused window. It will remain pending. InputEventInjectionResult result = - injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::NONE, + injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, + ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, /*injectionTimeout=*/100ms, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); @@ -10385,9 +10524,9 @@ TEST_F(InputDispatcherMultiWindowAnr, FocusedWindowWithoutSetFocusedApplication_ std::this_thread::sleep_for(100ms); // Touch unfocused window. This should force the pending key to get dropped. - mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {UNFOCUSED_WINDOW_LOCATION})); + mDispatcher->notifyMotion( + generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {UNFOCUSED_WINDOW_LOCATION})); // We do not consume the motion right away, because that would require dispatcher to first // process (== drop) the key event, and by that time, ANR will be raised. @@ -10440,20 +10579,20 @@ TEST_F(InputDispatcherMultiWindowAnr, PruningInputQueueShouldNotDropPointerEvent mFakePolicy->setStaleEventTimeout(3000ms); sp navigationBar = sp::make(systemUiApplication, mDispatcher, "NavigationBar", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); navigationBar->setFocusable(false); navigationBar->setWatchOutsideTouch(true); navigationBar->setFrame(Rect(0, 0, 100, 100)); mApplication->setDispatchingTimeout(3000ms); // 'mApplication' is already focused, but we call it again here to make it explicit. - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApplication); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApplication); std::shared_ptr anotherApplication = std::make_shared(); sp appWindow = sp::make(anotherApplication, mDispatcher, "Another window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); appWindow->setFocusable(false); appWindow->setFrame(Rect(100, 100, 200, 200)); @@ -10472,8 +10611,8 @@ TEST_F(InputDispatcherMultiWindowAnr, PruningInputQueueShouldNotDropPointerEvent // Key will not be sent anywhere because we have no focused window. It will remain pending. // 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, + injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, + ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, /*injectionTimeout=*/100ms, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); @@ -10482,8 +10621,8 @@ TEST_F(InputDispatcherMultiWindowAnr, PruningInputQueueShouldNotDropPointerEvent mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) .build()); - result = injectKey(*mDispatcher, AKEY_EVENT_ACTION_UP, /*repeatCount=*/0, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::NONE, + result = injectKey(*mDispatcher, AKEY_EVENT_ACTION_UP, /*repeatCount=*/0, + ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE, /*injectionTimeout=*/100ms, /*allowKeyRepeat=*/false); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, result); @@ -10519,16 +10658,16 @@ class InputDispatcherMultiWindowOcclusionTests : public InputDispatcherTest { InputDispatcherTest::SetUp(); mApplication = std::make_shared(); - mNoInputWindow = - sp::make(mApplication, mDispatcher, - "Window without input channel", ADISPLAY_ID_DEFAULT, - /*createInputChannel=*/false); + mNoInputWindow = sp::make(mApplication, mDispatcher, + "Window without input channel", + ui::LogicalDisplayId::DEFAULT, + /*createInputChannel=*/false); mNoInputWindow->setNoInputChannel(true); mNoInputWindow->setFrame(Rect(0, 0, 100, 100)); // It's perfectly valid for this window to not have an associated input channel mBottomWindow = sp::make(mApplication, mDispatcher, "Bottom window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mBottomWindow->setFrame(Rect(0, 0, 100, 100)); mDispatcher->onWindowInfosChanged( @@ -10545,8 +10684,8 @@ TEST_F(InputDispatcherMultiWindowOcclusionTests, NoInputChannelFeature_DropsTouc PointF touchedPoint = {10, 10}; mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {touchedPoint})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {touchedPoint})); mNoInputWindow->assertNoEvents(); // Even though the window 'mNoInputWindow' positioned above 'mBottomWindow' does not have @@ -10563,7 +10702,7 @@ TEST_F(InputDispatcherMultiWindowOcclusionTests, NoInputChannelFeature_DropsTouchesWithValidChannel) { mNoInputWindow = sp::make(mApplication, mDispatcher, "Window with input channel and NO_INPUT_CHANNEL", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); mNoInputWindow->setNoInputChannel(true); mNoInputWindow->setFrame(Rect(0, 0, 100, 100)); @@ -10573,8 +10712,8 @@ TEST_F(InputDispatcherMultiWindowOcclusionTests, PointF touchedPoint = {10, 10}; mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {touchedPoint})); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {touchedPoint})); mNoInputWindow->assertNoEvents(); mBottomWindow->assertNoEvents(); @@ -10589,9 +10728,10 @@ protected: virtual void SetUp() override { InputDispatcherTest::SetUp(); mApp = std::make_shared(); - mWindow = sp::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); - mMirror = mWindow->clone(ADISPLAY_ID_DEFAULT); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp); + mWindow = sp::make(mApp, mDispatcher, "TestWindow", + ui::LogicalDisplayId::DEFAULT); + mMirror = mWindow->clone(ui::LogicalDisplayId::DEFAULT); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApp); mWindow->setFocusable(true); mMirror->setFocusable(true); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); @@ -10606,7 +10746,7 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, CanGetFocus) { mWindow->consumeFocusEvent(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); } // A focused & mirrored window remains focused only if the window and its mirror are both @@ -10618,10 +10758,10 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedIfAllWindowsFocusable) { mWindow->consumeFocusEvent(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyUp(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyUp(ui::LogicalDisplayId::INVALID); mMirror->setFocusable(false); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); @@ -10643,20 +10783,20 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedIfAnyWindowVisible) { mWindow->consumeFocusEvent(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyUp(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyUp(ui::LogicalDisplayId::INVALID); 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(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyUp(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyUp(ui::LogicalDisplayId::INVALID); mWindow->setVisible(false); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); @@ -10677,20 +10817,20 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, FocusedWhileWindowsAlive) { mWindow->consumeFocusEvent(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyDown(ui::LogicalDisplayId::INVALID); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyUp(ui::ADISPLAY_ID_NONE); + mWindow->consumeKeyUp(ui::LogicalDisplayId::INVALID); // 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(ui::ADISPLAY_ID_NONE); + mMirror->consumeKeyDown(ui::LogicalDisplayId::INVALID); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mMirror->consumeKeyUp(ui::ADISPLAY_ID_NONE); + mMirror->consumeKeyUp(ui::LogicalDisplayId::INVALID); // Both windows are removed mDispatcher->onWindowInfosChanged({{}, {}, 0, 0}); @@ -10712,7 +10852,7 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, DeferFocusWhenInvisible) { // Injected key goes to pending queue. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKey(*mDispatcher, AKEY_EVENT_ACTION_DOWN, /*repeatCount=*/0, - ADISPLAY_ID_DEFAULT, InputEventInjectionSync::NONE)); + ui::LogicalDisplayId::DEFAULT, InputEventInjectionSync::NONE)); mMirror->setVisible(true); mDispatcher->onWindowInfosChanged({{*mWindow->getInfo(), *mMirror->getInfo()}, {}, 0, 0}); @@ -10720,7 +10860,7 @@ TEST_F(InputDispatcherMirrorWindowFocusTests, DeferFocusWhenInvisible) { // window gets focused mWindow->consumeFocusEvent(true); // window gets the pending key event - mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); } class InputDispatcherPointerCaptureTests : public InputDispatcherTest { @@ -10732,13 +10872,14 @@ protected: void SetUp() override { InputDispatcherTest::SetUp(); mApp = std::make_shared(); - mWindow = sp::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + mWindow = sp::make(mApp, mDispatcher, "TestWindow", + ui::LogicalDisplayId::DEFAULT); mWindow->setFocusable(true); - mSecondWindow = - sp::make(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); + mSecondWindow = sp::make(mApp, mDispatcher, "TestWindow2", + ui::LogicalDisplayId::DEFAULT); mSecondWindow->setFocusable(true); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApp); mDispatcher->onWindowInfosChanged( {{*mWindow->getInfo(), *mSecondWindow->getInfo()}, {}, 0, 0}); @@ -10977,7 +11118,7 @@ protected: sp getWindow(gui::Uid uid, std::string name) { std::shared_ptr app = std::make_shared(); sp window = - sp::make(app, mDispatcher, name, ADISPLAY_ID_DEFAULT); + sp::make(app, mDispatcher, name, ui::LogicalDisplayId::DEFAULT); // Generate an arbitrary PID based on the UID window->setOwnerInfo(gui::Pid{static_cast(1777 + (uid.val() % 10000))}, uid); return window; @@ -10985,8 +11126,8 @@ protected: void touch(const std::vector& points = {PointF{100, 200}}) { mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - points)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, points)); } }; @@ -11351,20 +11492,21 @@ protected: void SetUp() override { InputDispatcherTest::SetUp(); mApp = std::make_shared(); - mWindow = sp::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + mWindow = sp::make(mApp, mDispatcher, "TestWindow", + ui::LogicalDisplayId::DEFAULT); mWindow->setFrame(Rect(0, 0, 100, 100)); - mSecondWindow = - sp::make(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); + mSecondWindow = sp::make(mApp, mDispatcher, "TestWindow2", + ui::LogicalDisplayId::DEFAULT); mSecondWindow->setFrame(Rect(100, 0, 200, 100)); - mSpyWindow = - sp::make(mApp, mDispatcher, "SpyWindow", ADISPLAY_ID_DEFAULT); + mSpyWindow = sp::make(mApp, mDispatcher, "SpyWindow", + ui::LogicalDisplayId::DEFAULT); mSpyWindow->setSpy(true); mSpyWindow->setTrustedOverlay(true); mSpyWindow->setFrame(Rect(0, 0, 200, 100)); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApp); mDispatcher->onWindowInfosChanged( {{*mSpyWindow->getInfo(), *mWindow->getInfo(), *mSecondWindow->getInfo()}, {}, @@ -11377,7 +11519,7 @@ protected: case AINPUT_SOURCE_TOUCHSCREEN: ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {50, 50})) + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; break; case AINPUT_SOURCE_STYLUS: @@ -11409,9 +11551,9 @@ protected: } // Window should receive motion event. - mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); // Spy window should also receive motion event - mSpyWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); + mSpyWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); } // Start performing drag, we will create a drag window and transfer touch to it. @@ -11423,8 +11565,8 @@ protected: } // The drag window covers the entire display - mDragWindow = - sp::make(mApp, mDispatcher, "DragWindow", ADISPLAY_ID_DEFAULT); + mDragWindow = sp::make(mApp, mDispatcher, "DragWindow", + ui::LogicalDisplayId::DEFAULT); mDragWindow->setTouchableRegion(Region{{0, 0, 0, 0}}); mDispatcher->onWindowInfosChanged({{*mDragWindow->getInfo(), *mSpyWindow->getInfo(), *mWindow->getInfo(), *mSecondWindow->getInfo()}, @@ -11438,7 +11580,8 @@ protected: /*isDragDrop=*/true); if (transferred) { mWindow->consumeMotionCancel(); - mDragWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); } return transferred; } @@ -11450,35 +11593,38 @@ TEST_F(InputDispatcherDragTests, DragEnterAndDragExit) { // Move on window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {50, 50})) + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(false, 50, 50); mSecondWindow->assertNoEvents(); // Move to another window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {150, 50})) + ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(true, 150, 50); mSecondWindow->consumeDragEvent(false, 50, 50); // Move back to original window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {50, 50})) + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(false, 50, 50); mSecondWindow->consumeDragEvent(true, -50, 50); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); } @@ -11513,27 +11659,29 @@ TEST_F(InputDispatcherDragTests, DragAndDrop) { // Move on window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {50, 50})) + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(false, 50, 50); mSecondWindow->assertNoEvents(); // Move to another window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {150, 50})) + ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(true, 150, 50); mSecondWindow->consumeDragEvent(false, 50, 50); // drop to another window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken()); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); @@ -11595,7 +11743,8 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(false, 50, 50); mSecondWindow->assertNoEvents(); @@ -11607,7 +11756,8 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { .pointer(PointerBuilder(0, ToolType::STYLUS).x(150).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken()); @@ -11620,7 +11770,7 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { .pointer(PointerBuilder(0, ToolType::STYLUS).x(150).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); } @@ -11636,27 +11786,29 @@ TEST_F(InputDispatcherDragTests, DragAndDropOnInvalidWindow) { // Move on window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {50, 50})) + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(false, 50, 50); mSecondWindow->assertNoEvents(); // Move to another window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {150, 50})) + ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(true, 150, 50); mSecondWindow->assertNoEvents(); // drop to another window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mFakePolicy->assertDropTargetEquals(*mDispatcher, nullptr); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); @@ -11667,14 +11819,14 @@ TEST_F(InputDispatcherDragTests, NoDragAndDropWhenMultiFingers) { mWindow->setPreventSplitting(true); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {50, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(75).y(50)) @@ -11692,16 +11844,16 @@ TEST_F(InputDispatcherDragTests, NoDragAndDropWhenMultiFingers) { TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { // First down on second window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {150, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mSecondWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); + mSecondWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); // Second down on first window. const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) @@ -11710,8 +11862,8 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { injectMotionEvent(*mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, InputEventInjectionSync::WAIT_FOR_RESULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT); - mSecondWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT); + mWindow->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + mSecondWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT); // Perform drag and drop from first window. ASSERT_TRUE(startDrag(false)); @@ -11726,7 +11878,8 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, secondFingerMoveEvent, INJECT_EVENT_TIMEOUT, InputEventInjectionSync::WAIT_FOR_RESULT)); - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(false, 50, 50); mSecondWindow->consumeMotionMove(); @@ -11740,7 +11893,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, secondFingerUpEvent, INJECT_EVENT_TIMEOUT, InputEventInjectionSync::WAIT_FOR_RESULT)); - mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mFakePolicy->assertDropTargetEquals(*mDispatcher, mWindow->getToken()); mWindow->assertNoEvents(); mSecondWindow->consumeMotionMove(); @@ -11779,27 +11932,29 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenMultiDisplays) { // Move on window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {50, 50})) + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(false, 50, 50); mSecondWindow->assertNoEvents(); // Move to another window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {150, 50})) + ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(true, 150, 50); mSecondWindow->consumeDragEvent(false, 50, 50); // drop to another window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken()); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); @@ -11817,7 +11972,8 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { .y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(false, 50, 50); mSecondWindow->assertNoEvents(); @@ -11831,7 +11987,8 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { .y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionMove(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mWindow->consumeDragEvent(true, 150, 50); mSecondWindow->consumeDragEvent(false, 50, 50); @@ -11845,7 +12002,7 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { .y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); + mDragWindow->consumeMotionUp(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE); mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken()); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); @@ -11858,8 +12015,8 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { TEST_F(InputDispatcherDragTests, DragAndDropFinishedWhenCancelCurrentTouch) { // Down on second window ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {150, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {150, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; ASSERT_NO_FATAL_FAILURE(mSecondWindow->consumeMotionDown()); @@ -11868,7 +12025,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropFinishedWhenCancelCurrentTouch) { // Down on first window const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); @@ -11886,7 +12043,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropFinishedWhenCancelCurrentTouch) { // Trigger cancel mDispatcher->cancelCurrentTouch(); ASSERT_NO_FATAL_FAILURE(mSecondWindow->consumeMotionCancel()); - ASSERT_NO_FATAL_FAILURE(mDragWindow->consumeMotionCancel(ADISPLAY_ID_DEFAULT, + ASSERT_NO_FATAL_FAILURE(mDragWindow->consumeMotionCancel(ui::LogicalDisplayId::DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)); ASSERT_NO_FATAL_FAILURE(mSpyWindow->consumeMotionCancel()); @@ -11899,14 +12056,14 @@ TEST_F(InputDispatcherDragTests, DragAndDropFinishedWhenCancelCurrentTouch) { // Inject a simple gesture, ensure dispatcher not crashed ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - PointF{50, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, PointF{50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionDown()); const MotionEvent moveEvent = MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, @@ -11916,7 +12073,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropFinishedWhenCancelCurrentTouch) { ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionMove()); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionUp()); @@ -11926,7 +12083,7 @@ TEST_F(InputDispatcherDragTests, NoDragAndDropWithHoveringPointer) { // Start hovering over the window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE, - ADISPLAY_ID_DEFAULT, {50, 50})); + ui::LogicalDisplayId::DEFAULT, {50, 50})); ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER))); ASSERT_NO_FATAL_FAILURE(mSpyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER))); @@ -11939,23 +12096,25 @@ class InputDispatcherDropInputFeatureTest : public InputDispatcherTest {}; TEST_F(InputDispatcherDropInputFeatureTest, WindowDropsInput) { std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Test window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Test window", + ui::LogicalDisplayId::DEFAULT); window->setDropInput(true); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); window->setFocusable(true); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); setFocusedWindow(window); window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); // With the flag set, window should not get any input - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); window->assertNoEvents(); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); mDispatcher->waitForIdle(); window->assertNoEvents(); @@ -11963,12 +12122,13 @@ TEST_F(InputDispatcherDropInputFeatureTest, WindowDropsInput) { window->setDropInput(false); mDispatcher->onWindowInfosChanged({{*window->getInfo()}, {}, 0, 0}); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT)); - window->consumeKeyUp(ADISPLAY_ID_DEFAULT); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT)); + window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); window->assertNoEvents(); } @@ -11977,16 +12137,17 @@ TEST_F(InputDispatcherDropInputFeatureTest, ObscuredWindowDropsInput) { std::make_shared(); sp obscuringWindow = sp::make(obscuringApplication, mDispatcher, "obscuringWindow", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); obscuringWindow->setFrame(Rect(0, 0, 50, 50)); obscuringWindow->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); obscuringWindow->setTouchable(false); std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Test window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Test window", + ui::LogicalDisplayId::DEFAULT); window->setDropInputIfObscured(true); window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); window->setFocusable(true); mDispatcher->onWindowInfosChanged( {{*obscuringWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); @@ -11994,13 +12155,14 @@ TEST_F(InputDispatcherDropInputFeatureTest, ObscuredWindowDropsInput) { window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); // With the flag set, window should not get any input - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); window->assertNoEvents(); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); window->assertNoEvents(); // With the flag cleared, the window should get input @@ -12008,12 +12170,14 @@ TEST_F(InputDispatcherDropInputFeatureTest, ObscuredWindowDropsInput) { mDispatcher->onWindowInfosChanged( {{*obscuringWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT)); - window->consumeKeyUp(ADISPLAY_ID_DEFAULT); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT)); + window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); - window->consumeMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED); window->assertNoEvents(); } @@ -12022,16 +12186,17 @@ TEST_F(InputDispatcherDropInputFeatureTest, UnobscuredWindowGetsInput) { std::make_shared(); sp obscuringWindow = sp::make(obscuringApplication, mDispatcher, "obscuringWindow", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); obscuringWindow->setFrame(Rect(0, 0, 50, 50)); obscuringWindow->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); obscuringWindow->setTouchable(false); std::shared_ptr application = std::make_shared(); - sp window = sp::make(application, mDispatcher, - "Test window", ADISPLAY_ID_DEFAULT); + sp window = + sp::make(application, mDispatcher, "Test window", + ui::LogicalDisplayId::DEFAULT); window->setDropInputIfObscured(true); window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); window->setFocusable(true); mDispatcher->onWindowInfosChanged( {{*obscuringWindow->getInfo(), *window->getInfo()}, {}, 0, 0}); @@ -12039,25 +12204,27 @@ TEST_F(InputDispatcherDropInputFeatureTest, UnobscuredWindowGetsInput) { window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); // With the flag set, window should not get any input - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT)); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ui::LogicalDisplayId::DEFAULT)); window->assertNoEvents(); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); window->assertNoEvents(); // When the window is no longer obscured because it went on top, it should get input mDispatcher->onWindowInfosChanged( {{*window->getInfo(), *obscuringWindow->getInfo()}, {}, 0, 0}); - mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT)); - window->consumeKeyUp(ADISPLAY_ID_DEFAULT); + mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ui::LogicalDisplayId::DEFAULT)); + window->consumeKeyUp(ui::LogicalDisplayId::DEFAULT); mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, - AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)); - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); window->assertNoEvents(); } @@ -12074,18 +12241,19 @@ protected: mApp = std::make_shared(); mSecondaryApp = std::make_shared(); - mWindow = sp::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + mWindow = sp::make(mApp, mDispatcher, "TestWindow", + ui::LogicalDisplayId::DEFAULT); mWindow->setFocusable(true); setFocusedWindow(mWindow); - mSecondWindow = - sp::make(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); + mSecondWindow = sp::make(mApp, mDispatcher, "TestWindow2", + ui::LogicalDisplayId::DEFAULT); mSecondWindow->setFocusable(true); mThirdWindow = sp::make(mSecondaryApp, mDispatcher, "TestWindow3_SecondaryDisplay", SECOND_DISPLAY_ID); mThirdWindow->setFocusable(true); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, mApp); mDispatcher->onWindowInfosChanged( {{*mWindow->getInfo(), *mSecondWindow->getInfo(), *mThirdWindow->getInfo()}, {}, @@ -12096,7 +12264,8 @@ protected: // Set main display initial touch mode to InputDispatcher::kDefaultInTouchMode. if (mDispatcher->setInTouchMode(InputDispatcher::kDefaultInTouchMode, WINDOW_PID, - WINDOW_UID, /*hasPermission=*/true, ADISPLAY_ID_DEFAULT)) { + WINDOW_UID, /*hasPermission=*/true, + ui::LogicalDisplayId::DEFAULT)) { mWindow->consumeTouchModeEvent(InputDispatcher::kDefaultInTouchMode); mSecondWindow->consumeTouchModeEvent(InputDispatcher::kDefaultInTouchMode); mThirdWindow->assertNoEvents(); @@ -12115,7 +12284,7 @@ protected: void changeAndVerifyTouchModeInMainDisplayOnly(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission) { ASSERT_TRUE(mDispatcher->setInTouchMode(inTouchMode, pid, uid, hasPermission, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); mWindow->consumeTouchModeEvent(inTouchMode); mSecondWindow->consumeTouchModeEvent(inTouchMode); mThirdWindow->assertNoEvents(); @@ -12136,7 +12305,7 @@ TEST_F(InputDispatcherTouchModeChangedTests, NonFocusedWindowOwnerCannotChangeTo mWindow->setOwnerInfo(gui::Pid::INVALID, gui::Uid::INVALID); ASSERT_FALSE(mDispatcher->setInTouchMode(InputDispatcher::kDefaultInTouchMode, ownerPid, ownerUid, /*hasPermission=*/false, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); } @@ -12154,7 +12323,8 @@ TEST_F(InputDispatcherTouchModeChangedTests, EventIsNotGeneratedIfNotChangingTou const WindowInfo& windowInfo = *mWindow->getInfo(); ASSERT_FALSE(mDispatcher->setInTouchMode(InputDispatcher::kDefaultInTouchMode, windowInfo.ownerPid, windowInfo.ownerUid, - /*hasPermission=*/true, ADISPLAY_ID_DEFAULT)); + /*hasPermission=*/true, + ui::LogicalDisplayId::DEFAULT)); mWindow->assertNoEvents(); mSecondWindow->assertNoEvents(); } @@ -12172,9 +12342,9 @@ TEST_F(InputDispatcherTouchModeChangedTests, ChangeTouchOnSecondaryDisplayOnly) TEST_F(InputDispatcherTouchModeChangedTests, CanChangeTouchModeWhenOwningLastInteractedWindow) { // Interact with the window first. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectKeyDown(*mDispatcher, ADISPLAY_ID_DEFAULT)) + injectKeyDown(*mDispatcher, ui::LogicalDisplayId::DEFAULT)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT); + mWindow->consumeKeyDown(ui::LogicalDisplayId::DEFAULT); // Then remove focus. mWindow->setFocusable(false); @@ -12184,7 +12354,8 @@ TEST_F(InputDispatcherTouchModeChangedTests, CanChangeTouchModeWhenOwningLastInt const WindowInfo& windowInfo = *mWindow->getInfo(); ASSERT_TRUE(mDispatcher->setInTouchMode(!InputDispatcher::kDefaultInTouchMode, windowInfo.ownerPid, windowInfo.ownerUid, - /*hasPermission=*/false, ADISPLAY_ID_DEFAULT)); + /*hasPermission=*/false, + ui::LogicalDisplayId::DEFAULT)); } class InputDispatcherSpyWindowTest : public InputDispatcherTest { @@ -12194,8 +12365,9 @@ public: std::make_shared(); std::string name = "Fake Spy "; name += std::to_string(mSpyCount++); - sp spy = sp::make(application, mDispatcher, - name.c_str(), ADISPLAY_ID_DEFAULT); + sp spy = + sp::make(application, mDispatcher, name.c_str(), + ui::LogicalDisplayId::DEFAULT); spy->setSpy(true); spy->setTrustedOverlay(true); return spy; @@ -12206,7 +12378,7 @@ public: std::make_shared(); sp window = sp::make(application, mDispatcher, "Fake Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); return window; } @@ -12237,9 +12409,10 @@ TEST_F(InputDispatcherSpyWindowTest, NoForegroundWindow) { mDispatcher->onWindowInfosChanged({{*spy->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - spy->consumeMotionDown(ADISPLAY_ID_DEFAULT); + spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); } /** @@ -12277,7 +12450,8 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesInputInOrder) { } ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; std::vector eventOrder; @@ -12315,9 +12489,10 @@ TEST_F(InputDispatcherSpyWindowTest, NotTouchable) { mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); spy->assertNoEvents(); } @@ -12334,20 +12509,22 @@ TEST_F(InputDispatcherSpyWindowTest, TouchableRegion) { // Inject an event outside the spy window's touchable region. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionDown(); spy->assertNoEvents(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionUp(); spy->assertNoEvents(); // Inject an event inside the spy window's touchable region. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {5, 10})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {5, 10})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionDown(); spy->consumeMotionDown(); @@ -12368,8 +12545,8 @@ TEST_F(InputDispatcherSpyWindowTest, WatchOutsideTouches) { // Inject an event outside the spy window's frame and touchable region. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 200})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 200})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionDown(); spy->consumeMotionOutsideWithZeroedCoords(); @@ -12390,8 +12567,8 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesMultiplePointers) { {{*spy->getInfo(), *windowLeft->getInfo(), *windowRight->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {50, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; windowLeft->consumeMotionDown(); spy->consumeMotionDown(); @@ -12422,8 +12599,8 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesSecondPointerAsDown) { mDispatcher->onWindowInfosChanged({{*spyRight->getInfo(), *window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {50, 50})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {50, 50})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionDown(); spyRight->assertNoEvents(); @@ -12459,16 +12636,16 @@ TEST_F(InputDispatcherSpyWindowTest, SplitIfNoForegroundWindowTouched) { // First finger down, no window touched. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 200})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 200})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - spy->consumeMotionDown(ADISPLAY_ID_DEFAULT); + spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); window->assertNoEvents(); // Second finger down on window, the window should receive touch down. const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) @@ -12478,7 +12655,7 @@ TEST_F(InputDispatcherSpyWindowTest, SplitIfNoForegroundWindowTouched) { InputEventInjectionSync::WAIT_FOR_RESULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); spy->consumeMotionPointerDown(/*pointerIndex=*/1); } @@ -12497,11 +12674,11 @@ TEST_F(InputDispatcherSpyWindowTest, UnfocusableSpyDoesNotReceiveKeyEvents) { ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeKeyDown(ui::ADISPLAY_ID_NONE); + window->consumeKeyDown(ui::LogicalDisplayId::INVALID); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyUp(*mDispatcher)) << "Inject key event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeKeyUp(ui::ADISPLAY_ID_NONE); + window->consumeKeyUp(ui::LogicalDisplayId::INVALID); spy->assertNoEvents(); } @@ -12520,7 +12697,8 @@ TEST_F(InputDispatcherPilferPointersTest, PilferPointers) { {{*spy1->getInfo(), *spy2->getInfo(), *window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionDown(); spy1->consumeMotionDown(); @@ -12535,7 +12713,7 @@ TEST_F(InputDispatcherPilferPointersTest, PilferPointers) { // The rest of the gesture should only be sent to the second spy window. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)) + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; spy2->consumeMotionMove(); spy1->assertNoEvents(); @@ -12552,19 +12730,21 @@ TEST_F(InputDispatcherPilferPointersTest, CanPilferAfterWindowIsRemovedMidStream mDispatcher->onWindowInfosChanged({{*spy->getInfo(), *window->getInfo()}, {}, 0, 0}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - window->consumeMotionDown(ADISPLAY_ID_DEFAULT); - spy->consumeMotionDown(ADISPLAY_ID_DEFAULT); + window->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); + spy->consumeMotionDown(ui::LogicalDisplayId::DEFAULT); window->releaseChannel(); EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) + injectMotionUp(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; - spy->consumeMotionUp(ADISPLAY_ID_DEFAULT); + spy->consumeMotionUp(ui::LogicalDisplayId::DEFAULT); } /** @@ -12579,8 +12759,8 @@ TEST_F(InputDispatcherPilferPointersTest, ContinuesToReceiveGestureAfterPilfer) // First finger down on the window and the spy. ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {100, 200})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {100, 200})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; spy->consumeMotionDown(); window->consumeMotionDown(); @@ -12592,7 +12772,7 @@ TEST_F(InputDispatcherPilferPointersTest, ContinuesToReceiveGestureAfterPilfer) // Second finger down on the window and spy, but the window should not receive the pointer down. const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) @@ -12607,7 +12787,7 @@ TEST_F(InputDispatcherPilferPointersTest, ContinuesToReceiveGestureAfterPilfer) // Third finger goes down outside all windows, so injection should fail. const MotionEvent thirdFingerDownEvent = MotionEventBuilder(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) @@ -12635,15 +12815,15 @@ TEST_F(InputDispatcherPilferPointersTest, PartiallyPilferRequiredPointers) { // First finger down on the window only ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {150, 150})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {150, 150})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionDown(); // Second finger down on the spy and window const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(150)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(10).y(10)) @@ -12658,7 +12838,7 @@ TEST_F(InputDispatcherPilferPointersTest, PartiallyPilferRequiredPointers) { // Third finger down on the spy and window const MotionEvent thirdFingerDownEvent = MotionEventBuilder(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(150)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(10).y(10)) @@ -12673,8 +12853,10 @@ TEST_F(InputDispatcherPilferPointersTest, PartiallyPilferRequiredPointers) { // Spy window pilfers the pointers. EXPECT_EQ(OK, mDispatcher->pilferPointers(spy->getToken())); - window->consumeMotionPointerUp(/*idx=*/2, ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_CANCELED); - window->consumeMotionPointerUp(/*idx=*/1, ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_CANCELED); + window->consumeMotionPointerUp(/*idx=*/2, ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_CANCELED); + window->consumeMotionPointerUp(/*idx=*/1, ui::LogicalDisplayId::DEFAULT, + AMOTION_EVENT_FLAG_CANCELED); spy->assertNoEvents(); window->assertNoEvents(); @@ -12695,8 +12877,8 @@ TEST_F(InputDispatcherPilferPointersTest, PilferAllRequiredPointers) { // First finger down on both spy and window ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {10, 10})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {10, 10})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionDown(); spy->consumeMotionDown(); @@ -12704,7 +12886,7 @@ TEST_F(InputDispatcherPilferPointersTest, PilferAllRequiredPointers) { // Second finger down on the spy and window const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(10).y(10)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) @@ -12738,8 +12920,8 @@ TEST_F(InputDispatcherPilferPointersTest, CanReceivePointersAfterPilfer) { // First finger down on both window and spy ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - {10, 10})) + injectMotionDown(*mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, + ui::LogicalDisplayId::DEFAULT, {10, 10})) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; window->consumeMotionDown(); spy->consumeMotionDown(); @@ -12751,7 +12933,7 @@ TEST_F(InputDispatcherPilferPointersTest, CanReceivePointersAfterPilfer) { // Second finger down on the window only const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .displayId(ADISPLAY_ID_DEFAULT) + .displayId(ui::LogicalDisplayId::DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(10).y(10)) .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) @@ -12936,9 +13118,9 @@ public: std::pair, sp> setupStylusOverlayScenario() { std::shared_ptr overlayApplication = std::make_shared(); - sp overlay = - sp::make(overlayApplication, mDispatcher, - "Stylus interceptor window", ADISPLAY_ID_DEFAULT); + sp overlay = sp::make(overlayApplication, mDispatcher, + "Stylus interceptor window", + ui::LogicalDisplayId::DEFAULT); overlay->setFocusable(false); overlay->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); overlay->setTouchable(false); @@ -12949,11 +13131,11 @@ public: std::make_shared(); sp window = sp::make(application, mDispatcher, "Application window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); window->setFocusable(true); window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); - mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); + mDispatcher->setFocusedApplication(ui::LogicalDisplayId::DEFAULT, application); mDispatcher->onWindowInfosChanged({{*overlay->getInfo(), *window->getInfo()}, {}, 0, 0}); setFocusedWindow(window); window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true); @@ -12963,13 +13145,13 @@ public: void sendFingerEvent(int32_t action) { mDispatcher->notifyMotion( generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{20, 20}})); + ui::LogicalDisplayId::DEFAULT, {PointF{20, 20}})); } void sendStylusEvent(int32_t action) { NotifyMotionArgs motionArgs = generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, - ADISPLAY_ID_DEFAULT, {PointF{30, 40}}); + ui::LogicalDisplayId::DEFAULT, {PointF{30, 40}}); motionArgs.pointerProperties[0].toolType = ToolType::STYLUS; mDispatcher->notifyMotion(motionArgs); } @@ -13073,7 +13255,7 @@ struct User { InputEventInjectionResult injectTargetedMotion(int32_t action) const { return injectMotionEvent(*mDispatcher, action, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, {100, 200}, + ui::LogicalDisplayId::DEFAULT, {100, 200}, {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION}, INJECT_EVENT_TIMEOUT, InputEventInjectionSync::WAIT_FOR_RESULT, @@ -13082,7 +13264,7 @@ struct User { InputEventInjectionResult injectTargetedKey(int32_t action) const { return inputdispatcher::injectKey(*mDispatcher, action, /*repeatCount=*/0, - ui::ADISPLAY_ID_NONE, + ui::LogicalDisplayId::INVALID, InputEventInjectionSync::WAIT_FOR_RESULT, INJECT_EVENT_TIMEOUT, /*allowKeyRepeat=*/false, {mUid}, mPolicyFlags); @@ -13091,8 +13273,9 @@ struct User { sp createWindow(const char* name) const { std::shared_ptr overlayApplication = std::make_shared(); - sp window = sp::make(overlayApplication, mDispatcher, - name, ADISPLAY_ID_DEFAULT); + sp window = + sp::make(overlayApplication, mDispatcher, name, + ui::LogicalDisplayId::DEFAULT); window->setOwnerInfo(mPid, mUid); return window; } @@ -13114,7 +13297,7 @@ TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoOwnedWindow) { EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, owner.injectTargetedKey(AKEY_EVENT_ACTION_DOWN)); - window->consumeKeyDown(ui::ADISPLAY_ID_NONE); + window->consumeKeyDown(ui::LogicalDisplayId::INVALID); } TEST_F(InputDispatcherTargetedInjectionTest, CannotInjectIntoUnownedWindow) { @@ -13179,7 +13362,7 @@ TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoAnyWindowWhenNotTarget // A user that has injection permission can inject into any window. EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(*mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT)); + ui::LogicalDisplayId::DEFAULT)); randosSpy->consumeMotionDown(); window->consumeMotionDown(); @@ -13187,7 +13370,7 @@ TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoAnyWindowWhenNotTarget randosSpy->consumeFocusEvent(true); EXPECT_EQ(InputEventInjectionResult::SUCCEEDED, injectKeyDown(*mDispatcher)); - randosSpy->consumeKeyDown(ui::ADISPLAY_ID_NONE); + randosSpy->consumeKeyDown(ui::LogicalDisplayId::INVALID); window->assertNoEvents(); } @@ -13214,13 +13397,14 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWhenHovering) { std::shared_ptr application = std::make_shared(); sp left = sp::make(application, mDispatcher, "Left Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); left->setFrame(Rect(0, 0, 100, 100)); - sp right = sp::make(application, mDispatcher, - "Right Window", ADISPLAY_ID_DEFAULT); + sp right = + sp::make(application, mDispatcher, "Right Window", + ui::LogicalDisplayId::DEFAULT); right->setFrame(Rect(100, 0, 200, 100)); - sp spy = - sp::make(application, mDispatcher, "Spy Window", ADISPLAY_ID_DEFAULT); + sp spy = sp::make(application, mDispatcher, "Spy Window", + ui::LogicalDisplayId::DEFAULT); spy->setFrame(Rect(0, 0, 200, 100)); spy->setTrustedOverlay(true); spy->setSpy(true); @@ -13237,11 +13421,14 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWhenHovering) { left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); spy->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); // Hover move to the right window. @@ -13254,11 +13441,14 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWhenHovering) { right->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); spy->consumeMotionEvent(WithMotionAction(ACTION_HOVER_MOVE)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); // Stop hovering. @@ -13270,11 +13460,14 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWhenHovering) { right->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); spy->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); } @@ -13282,13 +13475,14 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWithSplitTouch) { std::shared_ptr application = std::make_shared(); sp left = sp::make(application, mDispatcher, "Left Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); left->setFrame(Rect(0, 0, 100, 100)); - sp right = sp::make(application, mDispatcher, - "Right Window", ADISPLAY_ID_DEFAULT); + sp right = + sp::make(application, mDispatcher, "Right Window", + ui::LogicalDisplayId::DEFAULT); right->setFrame(Rect(100, 0, 200, 100)); - sp spy = - sp::make(application, mDispatcher, "Spy Window", ADISPLAY_ID_DEFAULT); + sp spy = sp::make(application, mDispatcher, "Spy Window", + ui::LogicalDisplayId::DEFAULT); spy->setFrame(Rect(0, 0, 200, 100)); spy->setTrustedOverlay(true); spy->setSpy(true); @@ -13305,11 +13499,14 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWithSplitTouch) { left->consumeMotionDown(); spy->consumeMotionDown(); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); // Second pointer down on right window. @@ -13323,17 +13520,23 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWithSplitTouch) { right->consumeMotionDown(); spy->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/1)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/1)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/1)); // Second pointer up. @@ -13347,17 +13550,23 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWithSplitTouch) { right->consumeMotionUp(); spy->consumeMotionEvent(WithMotionAction(POINTER_1_UP)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/1)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/1)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/1)); // First pointer up. @@ -13369,11 +13578,14 @@ TEST_F(InputDispatcherPointerInWindowTest, PointerInWindowWithSplitTouch) { left->consumeMotionUp(); spy->consumeMotionUp(); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(spy->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); } @@ -13382,17 +13594,20 @@ TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse_le std::shared_ptr application = std::make_shared(); sp left = sp::make(application, mDispatcher, "Left Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); left->setFrame(Rect(0, 0, 100, 100)); - sp right = sp::make(application, mDispatcher, - "Right Window", ADISPLAY_ID_DEFAULT); + sp right = + sp::make(application, mDispatcher, "Right Window", + ui::LogicalDisplayId::DEFAULT); right->setFrame(Rect(100, 0, 200, 100)); mDispatcher->onWindowInfosChanged({{*left->getInfo(), *right->getInfo()}, {}, 0, 0}); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); // Hover move into the window. @@ -13406,7 +13621,8 @@ TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse_le left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); // Move the mouse with another device. This cancels the hovering pointer from the first device. @@ -13423,9 +13639,10 @@ TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse_le // TODO(b/313689709): InputDispatcher's touch state is not updated, even though the window gets // a HOVER_EXIT from the first device. - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, SECOND_DEVICE_ID, /*pointerId=*/0)); @@ -13441,9 +13658,10 @@ TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse_le left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); right->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, SECOND_DEVICE_ID, /*pointerId=*/0)); } @@ -13457,17 +13675,20 @@ TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse) { std::shared_ptr application = std::make_shared(); sp left = sp::make(application, mDispatcher, "Left Window", - ADISPLAY_ID_DEFAULT); + ui::LogicalDisplayId::DEFAULT); left->setFrame(Rect(0, 0, 100, 100)); - sp right = sp::make(application, mDispatcher, - "Right Window", ADISPLAY_ID_DEFAULT); + sp right = + sp::make(application, mDispatcher, "Right Window", + ui::LogicalDisplayId::DEFAULT); right->setFrame(Rect(100, 0, 200, 100)); mDispatcher->onWindowInfosChanged({{*left->getInfo(), *right->getInfo()}, {}, 0, 0}); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_FALSE(mDispatcher->isPointerInWindow(right->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); // Hover move into the window. @@ -13481,7 +13702,8 @@ TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse) { left->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); // Move the mouse with another device @@ -13496,9 +13718,10 @@ TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse) { // TODO(b/313689709): InputDispatcher's touch state is not updated, even though the window gets // a HOVER_EXIT from the first device. - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, SECOND_DEVICE_ID, /*pointerId=*/0)); @@ -13513,9 +13736,10 @@ TEST_F(InputDispatcherPointerInWindowTest, MultipleDevicesControllingOneMouse) { .build()); right->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); - ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, DEVICE_ID, + ASSERT_TRUE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, + DEVICE_ID, /*pointerId=*/0)); - ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ADISPLAY_ID_DEFAULT, + ASSERT_FALSE(mDispatcher->isPointerInWindow(left->getToken(), ui::LogicalDisplayId::DEFAULT, SECOND_DEVICE_ID, /*pointerId=*/0)); } diff --git a/services/inputflinger/tests/InputProcessorConverter_test.cpp b/services/inputflinger/tests/InputProcessorConverter_test.cpp index 15565326b1..bdf156c49a 100644 --- a/services/inputflinger/tests/InputProcessorConverter_test.cpp +++ b/services/inputflinger/tests/InputProcessorConverter_test.cpp @@ -38,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, ui::ADISPLAY_ID_DEFAULT, + /*deviceId=*/3, AINPUT_SOURCE_ANY, ui::LogicalDisplayId::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 5606a91a0b..f7e5e6783b 100644 --- a/services/inputflinger/tests/InputProcessor_test.cpp +++ b/services/inputflinger/tests/InputProcessor_test.cpp @@ -44,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, ui::ADISPLAY_ID_DEFAULT, + /*deviceId=*/3, AINPUT_SOURCE_ANY, ui::LogicalDisplayId::DEFAULT, /*policyFlags=*/4, AMOTION_EVENT_ACTION_DOWN, /*actionButton=*/0, /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, @@ -80,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, ui::ADISPLAY_ID_DEFAULT, /*policyFlags=*/0, + AINPUT_SOURCE_KEYBOARD, ui::LogicalDisplayId::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 fcc52a8f31..a0abb61cdc 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -59,11 +59,10 @@ using std::chrono_literals::operator""ms; using std::chrono_literals::operator""s; // Arbitrary display properties. -static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; +static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; static const std::string DISPLAY_UNIQUE_ID = "local: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 ui::LogicalDisplayId VIRTUAL_DISPLAY_ID = ui::LogicalDisplayId{1}; @@ -521,12 +520,12 @@ TEST_F(InputReaderPolicyTest, Viewports_ByTypeReturnsDefaultForInternal) { const std::string uniqueId1 = "uniqueId1"; const std::string uniqueId2 = "uniqueId2"; constexpr ui::LogicalDisplayId nonDefaultDisplayId = ui::LogicalDisplayId{2}; - ASSERT_NE(nonDefaultDisplayId, ui::ADISPLAY_ID_DEFAULT) - << "Test display ID should not be ui::ADISPLAY_ID_DEFAULT "; + ASSERT_NE(nonDefaultDisplayId, ui::LogicalDisplayId::DEFAULT) + << "Test display ID should not be ui::LogicalDisplayId::DEFAULT "; // Add the default display first and ensure it gets returned. mFakePolicy->clearViewports(); - mFakePolicy->addDisplayViewport(ui::ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, + mFakePolicy->addDisplayViewport(ui::LogicalDisplayId::DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, /*isActive=*/true, uniqueId1, NO_PORT, ViewportType::INTERNAL); mFakePolicy->addDisplayViewport(nonDefaultDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, @@ -536,7 +535,7 @@ TEST_F(InputReaderPolicyTest, Viewports_ByTypeReturnsDefaultForInternal) { std::optional viewport = mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL); ASSERT_TRUE(viewport); - ASSERT_EQ(ui::ADISPLAY_ID_DEFAULT, viewport->displayId); + ASSERT_EQ(ui::LogicalDisplayId::DEFAULT, viewport->displayId); ASSERT_EQ(ViewportType::INTERNAL, viewport->type); // Add the default display second to make sure order doesn't matter. @@ -544,13 +543,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(ui::ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, + mFakePolicy->addDisplayViewport(ui::LogicalDisplayId::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(ui::ADISPLAY_ID_DEFAULT, viewport->displayId); + ASSERT_EQ(ui::LogicalDisplayId::DEFAULT, viewport->displayId); ASSERT_EQ(ViewportType::INTERNAL, viewport->type); } @@ -3244,7 +3243,7 @@ protected: void testDPadKeyRotation(KeyboardInputMapper& mapper, int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode, - ui::LogicalDisplayId displayId = ui::ADISPLAY_ID_NONE); + ui::LogicalDisplayId displayId = ui::LogicalDisplayId::INVALID); }; /* Similar to setDisplayInfoAndReconfigure, but pre-populates all parameters except for the @@ -3579,19 +3578,19 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_NotOrientationAware AINPUT_KEYBOARD_TYPE_ALPHABETIC); NotifyKeyArgs args; - // Display id should be ADISPLAY_ID_NONE without any display configuration. + // Display id should be LogicalDisplayId::INVALID without any display configuration. 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(ui::ADISPLAY_ID_NONE, args.displayId); + ASSERT_EQ(ui::LogicalDisplayId::INVALID, 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(ui::ADISPLAY_ID_NONE, args.displayId); + ASSERT_EQ(ui::LogicalDisplayId::INVALID, args.displayId); } TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_OrientationAware) { @@ -3605,7 +3604,7 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_OrientationAware) { AINPUT_KEYBOARD_TYPE_ALPHABETIC); NotifyKeyArgs args; - // Display id should be ADISPLAY_ID_NONE without any display configuration. + // Display id should be LogicalDisplayId::INVALID without any display configuration. // ^--- already checked by the previous test setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, @@ -8675,7 +8674,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(ui::ADISPLAY_ID_NONE, motionArgs.displayId); + ASSERT_EQ(ui::LogicalDisplayId::INVALID, motionArgs.displayId); } /** @@ -9572,7 +9571,7 @@ TEST_F(MultiTouchInputMapperTest_ExternalDevice, Viewports_Fallback) { processPosition(mapper, 100, 100); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); - ASSERT_EQ(ui::ADISPLAY_ID_DEFAULT, motionArgs.displayId); + ASSERT_EQ(ui::LogicalDisplayId::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 dfbbce3b1a..617d67f34d 100644 --- a/services/inputflinger/tests/InputTracingTest.cpp +++ b/services/inputflinger/tests/InputTracingTest.cpp @@ -41,7 +41,7 @@ using perfetto::protos::pbzero::AndroidInputEventConfig; namespace { -constexpr ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; // Ensure common actions are interchangeable between keys and motions for convenience. static_assert(static_cast(AMOTION_EVENT_ACTION_DOWN) == diff --git a/services/inputflinger/tests/LatencyTracker_test.cpp b/services/inputflinger/tests/LatencyTracker_test.cpp index 01fd03e874..4fcffddee2 100644 --- a/services/inputflinger/tests/LatencyTracker_test.cpp +++ b/services/inputflinger/tests/LatencyTracker_test.cpp @@ -43,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, ui::ADISPLAY_ID_NONE); + /*isExternal=*/false, /*hasMic=*/false, ui::LogicalDisplayId::INVALID); return info; } diff --git a/services/inputflinger/tests/MultiTouchInputMapper_test.cpp b/services/inputflinger/tests/MultiTouchInputMapper_test.cpp index 437020f48a..b5f897154b 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 ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; +static constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; static constexpr int32_t DISPLAY_WIDTH = 480; static constexpr int32_t DISPLAY_HEIGHT = 800; static constexpr std::optional NO_PORT = std::nullopt; // no physical port is specified diff --git a/services/inputflinger/tests/PointerChoreographer_test.cpp b/services/inputflinger/tests/PointerChoreographer_test.cpp index 33e7277034..1689b33fe5 100644 --- a/services/inputflinger/tests/PointerChoreographer_test.cpp +++ b/services/inputflinger/tests/PointerChoreographer_test.cpp @@ -203,14 +203,16 @@ TEST_F(PointerChoreographerTest, ForwardsArgsToInnerListener) { TEST_F(PointerChoreographerTest, WhenMouseIsAddedCreatesPointerController) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerCreated(ControllerType::MOUSE); } TEST_F(PointerChoreographerTest, WhenMouseIsRemovedRemovesPointerController) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); // Remove the mouse. @@ -221,7 +223,8 @@ TEST_F(PointerChoreographerTest, WhenMouseIsRemovedRemovesPointerController) { TEST_F(PointerChoreographerTest, WhenKeyboardIsAddedDoesNotCreatePointerController) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_KEYBOARD, + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerNotCreated(); } @@ -256,7 +259,8 @@ TEST_F(PointerChoreographerTest, SetsDefaultMouseViewportForPointerController) { // the PointerController. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertViewportSet(DISPLAY_ID); ASSERT_TRUE(pc->isPointerShown()); @@ -269,7 +273,8 @@ TEST_F(PointerChoreographerTest, mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto firstDisplayPc = assertPointerControllerCreated(ControllerType::MOUSE); firstDisplayPc->assertViewportSet(DISPLAY_ID); ASSERT_TRUE(firstDisplayPc->isPointerShown()); @@ -289,7 +294,8 @@ TEST_F(PointerChoreographerTest, CallsNotifyPointerDisplayIdChanged) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); @@ -299,7 +305,8 @@ TEST_F(PointerChoreographerTest, WhenViewportIsSetLaterCallsNotifyPointerDisplay mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotNotified(); @@ -312,12 +319,13 @@ TEST_F(PointerChoreographerTest, WhenMouseIsRemovedCallsNotifyPointerDisplayIdCh mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged({/*id=*/1, {}}); - assertPointerDisplayIdNotified(ui::ADISPLAY_ID_NONE); + assertPointerDisplayIdNotified(ui::LogicalDisplayId::INVALID); assertPointerControllerRemoved(pc); } @@ -329,7 +337,8 @@ TEST_F(PointerChoreographerTest, WhenDefaultMouseDisplayChangesCallsNotifyPointe mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto firstDisplayPc = assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); @@ -346,7 +355,8 @@ TEST_F(PointerChoreographerTest, MouseMovesPointerAndReturnsNewArgs) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -358,7 +368,7 @@ TEST_F(PointerChoreographerTest, MouseMovesPointerAndReturnsNewArgs) { MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .pointer(MOUSE_POINTER) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); // Check that the PointerController updated the position and the pointer is shown. @@ -375,7 +385,8 @@ TEST_F(PointerChoreographerTest, AbsoluteMouseMovesPointerAndReturnsNewArgs) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -390,7 +401,7 @@ TEST_F(PointerChoreographerTest, AbsoluteMouseMovesPointerAndReturnsNewArgs) { MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .pointer(absoluteMousePointer) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); // Check that the PointerController updated the position and the pointer is shown. @@ -412,7 +423,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, ui::ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ANOTHER_DISPLAY_ID)}}); auto unassociatedMousePc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, unassociatedMousePc->getDisplayId()); @@ -449,7 +460,8 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForMouseRelativeSource) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -460,7 +472,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForMouseRelativeSource) { mChoreographer.notifyInputDevicesChanged( {/*id=*/1, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE_RELATIVE, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); mChoreographer.notifyPointerCaptureChanged( NotifyPointerCaptureChangedArgs(/*id=*/2, systemTime(SYSTEM_TIME_MONOTONIC), PointerCaptureRequest(/*window=*/sp::make(), @@ -475,7 +487,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForMouseRelativeSource) { .axis(AMOTION_EVENT_AXIS_RELATIVE_X, 10) .axis(AMOTION_EVENT_AXIS_RELATIVE_Y, 20)) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); // Check that there's no update on the PointerController. @@ -485,7 +497,7 @@ 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(ui::ADISPLAY_ID_NONE), + WithDisplayId(ui::LogicalDisplayId::INVALID), WithCursorPosition(AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION))); } @@ -495,7 +507,8 @@ TEST_F(PointerChoreographerTest, WhenPointerCaptureEnabledHidesPointer) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); ASSERT_TRUE(pc->isPointerShown()); @@ -515,7 +528,8 @@ TEST_F(PointerChoreographerTest, MultipleMiceConnectionAndRemoval) { // A mouse is connected, and the pointer is shown. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); @@ -525,9 +539,9 @@ 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, ui::ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); ASSERT_TRUE(pc->isPointerShown()); // One of the mice is removed, and it does not cause the mouse pointer to fade, because @@ -535,7 +549,7 @@ TEST_F(PointerChoreographerTest, MultipleMiceConnectionAndRemoval) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerNotRemoved(pc); ASSERT_TRUE(pc->isPointerShown()); @@ -549,7 +563,8 @@ TEST_F(PointerChoreographerTest, UnrelatedChangeDoesNotUnfadePointer) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); @@ -559,7 +574,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, ui::ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, DISPLAY_ID)}}); @@ -576,7 +591,7 @@ TEST_F(PointerChoreographerTest, DisabledMouseConnected) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo mouseDeviceInfo = - generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); + generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID); // Disable this mouse device. mouseDeviceInfo.setEnabled(false); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); @@ -589,7 +604,7 @@ TEST_F(PointerChoreographerTest, MouseDeviceDisableLater) { mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo mouseDeviceInfo = - generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); + generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID); mChoreographer.notifyInputDevicesChanged({/*id=*/0, {mouseDeviceInfo}}); @@ -608,14 +623,16 @@ TEST_F(PointerChoreographerTest, MultipleEnabledAndDisabledMiceConnectionAndRemo mChoreographer.setDisplayViewports(createViewports({DISPLAY_ID})); mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); InputDeviceInfo disabledMouseDeviceInfo = - generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); + generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID); disabledMouseDeviceInfo.setEnabled(false); InputDeviceInfo enabledMouseDeviceInfo = - generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); + generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID); InputDeviceInfo anotherEnabledMouseDeviceInfo = - generateTestDeviceInfo(THIRD_DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE); + generateTestDeviceInfo(THIRD_DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, @@ -1177,7 +1194,7 @@ TEST_F(PointerChoreographerTest, WhenTouchpadIsAddedCreatesPointerController) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerCreated(ControllerType::MOUSE); } @@ -1185,7 +1202,7 @@ TEST_F(PointerChoreographerTest, WhenTouchpadIsRemovedRemovesPointerController) mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); // Remove the touchpad. @@ -1227,7 +1244,8 @@ TEST_F(PointerChoreographerTest, SetsDefaultTouchpadViewportForPointerController // the PointerController. mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertViewportSet(DISPLAY_ID); } @@ -1240,7 +1258,7 @@ TEST_F(PointerChoreographerTest, mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto firstDisplayPc = assertPointerControllerCreated(ControllerType::MOUSE); firstDisplayPc->assertViewportSet(DISPLAY_ID); @@ -1258,7 +1276,7 @@ TEST_F(PointerChoreographerTest, TouchpadCallsNotifyPointerDisplayIdChanged) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); @@ -1269,7 +1287,7 @@ TEST_F(PointerChoreographerTest, WhenViewportIsSetLaterTouchpadCallsNotifyPointe mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotNotified(); @@ -1283,12 +1301,12 @@ TEST_F(PointerChoreographerTest, WhenTouchpadIsRemovedCallsNotifyPointerDisplayI mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged({/*id=*/1, {}}); - assertPointerDisplayIdNotified(ui::ADISPLAY_ID_NONE); + assertPointerDisplayIdNotified(ui::LogicalDisplayId::INVALID); assertPointerControllerRemoved(pc); } @@ -1302,12 +1320,12 @@ TEST_F(PointerChoreographerTest, mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto firstDisplayPc = assertPointerControllerCreated(ControllerType::MOUSE); assertPointerDisplayIdNotified(DISPLAY_ID); - // Set another viewport as a default mouse display ID. ui::ADISPLAY_ID_NONE will be notified - // before a touchpad event. + // Set another viewport as a default mouse display ID. ui::LogicalDisplayId::INVALID will be + // notified before a touchpad event. mChoreographer.setDefaultMouseDisplayId(ANOTHER_DISPLAY_ID); assertPointerControllerRemoved(firstDisplayPc); @@ -1321,7 +1339,7 @@ TEST_F(PointerChoreographerTest, TouchpadMovesPointerAndReturnsNewArgs) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -1333,7 +1351,7 @@ TEST_F(PointerChoreographerTest, TouchpadMovesPointerAndReturnsNewArgs) { MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .pointer(TOUCHPAD_POINTER) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); // Check that the PointerController updated the position and the pointer is shown. @@ -1351,7 +1369,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -1365,7 +1383,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(-100).y(0)) .classification(MotionClassification::MULTI_FINGER_SWIPE) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), @@ -1379,7 +1397,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(0).y(0)) .classification(MotionClassification::MULTI_FINGER_SWIPE) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | @@ -1396,7 +1414,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(100).y(0)) .classification(MotionClassification::MULTI_FINGER_SWIPE) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | @@ -1411,7 +1429,7 @@ TEST_F(PointerChoreographerTest, TouchpadAddsPointerPositionToTheCoords) { .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(110).y(10)) .classification(MotionClassification::MULTI_FINGER_SWIPE) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), @@ -1430,7 +1448,7 @@ TEST_F(PointerChoreographerTest, mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE), + ui::LogicalDisplayId::INVALID), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, ANOTHER_DISPLAY_ID)}}); auto unassociatedMousePc = assertPointerControllerCreated(ControllerType::MOUSE); @@ -1469,7 +1487,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForTouchpadSource) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); @@ -1486,7 +1504,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForTouchpadSource) { mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHPAD) .pointer(FIRST_TOUCH_POINTER) .deviceId(DEVICE_ID) - .displayId(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); // Check that there's no update on the PointerController. @@ -1495,7 +1513,7 @@ TEST_F(PointerChoreographerTest, DoesNotMovePointerForTouchpadSource) { // Check x-y coordinates, displayId and cursor position are not changed. mTestListener.assertNotifyMotionWasCalled( - AllOf(WithCoords(100, 200), WithDisplayId(ui::ADISPLAY_ID_NONE), + AllOf(WithCoords(100, 200), WithDisplayId(ui::LogicalDisplayId::INVALID), WithCursorPosition(AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION))); } @@ -1506,7 +1524,7 @@ TEST_F(PointerChoreographerTest, WhenPointerCaptureEnabledTouchpadHidesPointer) mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, pc->getDisplayId()); ASSERT_TRUE(pc->isPointerShown()); @@ -1525,7 +1543,8 @@ TEST_F(PointerChoreographerTest, SetsPointerIconForMouse) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertPointerIconNotSet(); @@ -1540,7 +1559,8 @@ TEST_F(PointerChoreographerTest, DoesNotSetMousePointerIconForWrongDisplayId) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertPointerIconNotSet(); @@ -1556,7 +1576,8 @@ TEST_F(PointerChoreographerTest, DoesNotSetPointerIconForWrongDeviceId) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertPointerIconNotSet(); @@ -1572,7 +1593,8 @@ TEST_F(PointerChoreographerTest, SetsCustomPointerIconForMouse) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); pc->assertCustomPointerIconNotSet(); @@ -1595,7 +1617,7 @@ TEST_F(PointerChoreographerTest, SetsPointerIconForMouseOnTwoDisplays) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ANOTHER_DISPLAY_ID)}}); auto firstMousePc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, firstMousePc->getDisplayId()); @@ -1790,14 +1812,14 @@ TEST_P(StylusTestFixture, SetsPointerIconForMouseAndStylus) { mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID), 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(ui::ADISPLAY_ID_NONE) + .displayId(ui::LogicalDisplayId::INVALID) .build()); auto mousePc = assertPointerControllerCreated(ControllerType::MOUSE); mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, source) @@ -1825,7 +1847,7 @@ TEST_F(PointerChoreographerTest, SetPointerIconVisibilityHidesPointerOnDisplay) mChoreographer.setDefaultMouseDisplayId(DISPLAY_ID); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::LogicalDisplayId::INVALID), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, ANOTHER_DISPLAY_ID)}}); auto firstMousePc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, firstMousePc->getDisplayId()); @@ -1882,7 +1904,8 @@ TEST_F(PointerChoreographerTest, SetPointerIconVisibilityHidesPointerWhenDeviceC mChoreographer.setPointerIconVisibility(DISPLAY_ID, false); mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE, + ui::LogicalDisplayId::INVALID)}}); auto mousePc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, mousePc->getDisplayId()); @@ -1900,7 +1923,7 @@ TEST_F(PointerChoreographerTest, SetPointerIconVisibilityHidesPointerForTouchpad mChoreographer.notifyInputDevicesChanged( {/*id=*/0, {generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto touchpadPc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_EQ(DISPLAY_ID, touchpadPc->getDisplayId()); @@ -1945,7 +1968,8 @@ TEST_F(PointerChoreographerTest, DrawingTabletCanReportMouseEvent) { mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, + ui::LogicalDisplayId::INVALID)}}); // There should be no controller created when a drawing tablet is connected assertPointerControllerNotCreated(); @@ -1972,7 +1996,8 @@ TEST_F(PointerChoreographerTest, MultipleDrawingTabletsReportMouseEvents) { // First drawing tablet is added mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerNotCreated(); mChoreographer.notifyMotion( @@ -1987,9 +2012,10 @@ TEST_F(PointerChoreographerTest, MultipleDrawingTabletsReportMouseEvents) { // Second drawing tablet is added mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, + ui::LogicalDisplayId::INVALID), generateTestDeviceInfo(SECOND_DEVICE_ID, DRAWING_TABLET_SOURCE, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerNotRemoved(pc); mChoreographer.notifyMotion( @@ -2002,7 +2028,8 @@ TEST_F(PointerChoreographerTest, MultipleDrawingTabletsReportMouseEvents) { // First drawing tablet is removed mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, + ui::LogicalDisplayId::INVALID)}}); assertPointerControllerNotRemoved(pc); // Second drawing tablet is removed @@ -2017,9 +2044,10 @@ TEST_F(PointerChoreographerTest, MouseAndDrawingTabletReportMouseEvents) { // Mouse and drawing tablet connected mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE), + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, + ui::LogicalDisplayId::INVALID), generateTestDeviceInfo(SECOND_DEVICE_ID, AINPUT_SOURCE_MOUSE, - ui::ADISPLAY_ID_NONE)}}); + ui::LogicalDisplayId::INVALID)}}); auto pc = assertPointerControllerCreated(ControllerType::MOUSE); ASSERT_TRUE(pc->isPointerShown()); @@ -2034,7 +2062,8 @@ TEST_F(PointerChoreographerTest, MouseAndDrawingTabletReportMouseEvents) { // Remove the mouse device mChoreographer.notifyInputDevicesChanged( {/*id=*/0, - {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, ui::ADISPLAY_ID_NONE)}}); + {generateTestDeviceInfo(DEVICE_ID, DRAWING_TABLET_SOURCE, + ui::LogicalDisplayId::INVALID)}}); // 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 c273e92de6..a36d526913 100644 --- a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp +++ b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp @@ -64,7 +64,7 @@ static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, // Define a valid motion event. NotifyMotionArgs args(/*id=*/0, eventTime, /*readTime=*/0, deviceId, source, - /*displayId=*/ui::ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER, action, + ui::LogicalDisplayId::DEFAULT, POLICY_FLAG_PASS_TO_USER, action, /* actionButton */ 0, /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, pointerProperties, @@ -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, ui::ADISPLAY_ID_NONE); + /*hasMic=*/false, ui::LogicalDisplayId::INVALID); 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/TouchpadInputMapper_test.cpp b/services/inputflinger/tests/TouchpadInputMapper_test.cpp index 245497ca4c..2b62dd13ef 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 ui::LogicalDisplayId DISPLAY_ID = ui::ADISPLAY_ID_DEFAULT; +constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; constexpr int32_t DISPLAY_WIDTH = 480; constexpr int32_t DISPLAY_HEIGHT = 800; constexpr std::optional 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 80430d1d22..853f628a13 100644 --- a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp +++ b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp @@ -88,7 +88,7 @@ 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=*/ui::ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER, action, + ui::LogicalDisplayId::DEFAULT, POLICY_FLAG_PASS_TO_USER, action, /*actionButton=*/0, /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, pointerProperties, @@ -104,7 +104,7 @@ static InputDeviceInfo generateTestDeviceInfo() { auto info = InputDeviceInfo(); info.initialize(DEVICE_ID, /*generation=*/1, /*controllerNumber=*/1, identifier, "alias", - /*isExternal=*/false, /*hasMic=*/false, ui::ADISPLAY_ID_NONE); + /*isExternal=*/false, /*hasMic=*/false, ui::LogicalDisplayId::INVALID); 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, ui::ADISPLAY_ID_DEFAULT, /*policyFlags=*/0, + AINPUT_SOURCE_KEYBOARD, ui::LogicalDisplayId::DEFAULT, /*policyFlags=*/0, AKEY_EVENT_ACTION_DOWN, /*flags=*/4, AKEYCODE_HOME, /*scanCode=*/5, AMETA_NONE, /*downTime=*/6); diff --git a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp index 0446d76218..0b4ac1fe86 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(), eventTime, readTime, /*deviceId=*/fdp.ConsumeIntegral(), - AINPUT_SOURCE_KEYBOARD, ui::ADISPLAY_ID_DEFAULT, + AINPUT_SOURCE_KEYBOARD, ui::LogicalDisplayId::DEFAULT, /*policyFlags=*/fdp.ConsumeIntegral(), AKEY_EVENT_ACTION_DOWN, /*flags=*/fdp.ConsumeIntegral(), AKEYCODE_HOME, -- cgit v1.2.3-59-g8ed1b From 134c04db7eb04de2d37db16399e204b56fc64393 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Tue, 14 May 2024 11:12:25 -0700 Subject: Remove ADISPLAY_ID_ definitions These were replaced by LogicalDisplayId:: equivalents. Bug: 339106983 Test: presubmit Change-Id: Id4ed040c8e3a0d7fdfebbedfb1a7cafba592235d --- libs/ui/include/ui/LogicalDisplayId.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'libs/ui') diff --git a/libs/ui/include/ui/LogicalDisplayId.h b/libs/ui/include/ui/LogicalDisplayId.h index d745758f0c..fd84b12c22 100644 --- a/libs/ui/include/ui/LogicalDisplayId.h +++ b/libs/ui/include/ui/LogicalDisplayId.h @@ -43,13 +43,6 @@ struct LogicalDisplayId : ftl::Constructible, constexpr inline LogicalDisplayId LogicalDisplayId::INVALID{-1}; constexpr inline LogicalDisplayId LogicalDisplayId::DEFAULT{0}; -/** - * Deprecated! Use LogicalDisplayId::INVALID / LogicalDisplayId::DEFAULT instead. - * TODO(b/339106983): remove these. - */ -[[deprecated]] constexpr LogicalDisplayId ADISPLAY_ID_NONE{-1}; -[[deprecated]] constexpr LogicalDisplayId ADISPLAY_ID_DEFAULT{0}; - inline std::ostream& operator<<(std::ostream& stream, LogicalDisplayId displayId) { return stream << displayId.val(); } -- cgit v1.2.3-59-g8ed1b From 78c90af2224b43467d854e356492527db0f8eb70 Mon Sep 17 00:00:00 2001 From: Alan Ding Date: Fri, 17 May 2024 16:55:51 -0700 Subject: ui: Refactor stable ID generation for GPU virtual displays This is a partial port of http://ag/17832464 for main. Use ftl::stable_hash to generate stable ID from uniqueId for GPU virtual displays. This allows FLAG_STABLE consistent with PhysicalDisplayId that uses a unique EDID, as well as being stable across reboots when using hardcoded or static unique ID. Add DisplayId.isStable()/isVirtual() interfaces and refactor previous legacy usages. Bug: 339525838 Bug: 137375833 Bug: 194863377 Test: atest libsurfaceflinger_unittest Test: atest DisplayId_test Flag: EXEMPT refactor Change-Id: I54f4d3803c8c23266a3461660146af7ae017e4be --- libs/ui/include/ui/DisplayId.h | 42 ++++++++++++++-------- libs/ui/tests/DisplayId_test.cpp | 23 +++++++++--- .../CompositionEngine/src/Display.cpp | 2 +- services/surfaceflinger/DisplayDevice.h | 2 +- .../DisplayHardware/VirtualDisplaySurface.cpp | 4 +-- 5 files changed, 50 insertions(+), 23 deletions(-) (limited to 'libs/ui') diff --git a/libs/ui/include/ui/DisplayId.h b/libs/ui/include/ui/DisplayId.h index 3a31fa0848..8a14db8ffa 100644 --- a/libs/ui/include/ui/DisplayId.h +++ b/libs/ui/include/ui/DisplayId.h @@ -20,6 +20,7 @@ #include #include +#include #include namespace android { @@ -38,6 +39,9 @@ struct DisplayId { constexpr DisplayId(const DisplayId&) = default; DisplayId& operator=(const DisplayId&) = default; + constexpr bool isVirtual() const { return value & FLAG_VIRTUAL; } + constexpr bool isStable() const { return value & FLAG_STABLE; } + uint64_t value; // For deserialization. @@ -76,10 +80,10 @@ inline std::ostream& operator<<(std::ostream& stream, DisplayId displayId) { // DisplayId of a physical display, such as the internal display or externally connected display. struct PhysicalDisplayId : DisplayId { static constexpr ftl::Optional tryCast(DisplayId id) { - if (id.value & FLAG_VIRTUAL) { + if (id.isVirtual()) { return std::nullopt; } - return {PhysicalDisplayId(id)}; + return PhysicalDisplayId(id); } // Returns a stable ID based on EDID information. @@ -117,25 +121,23 @@ struct VirtualDisplayId : DisplayId { static constexpr uint64_t FLAG_GPU = 1ULL << 61; static constexpr std::optional tryCast(DisplayId id) { - if (id.value & FLAG_VIRTUAL) { - return {VirtualDisplayId(id)}; + if (id.isVirtual()) { + return VirtualDisplayId(id); } return std::nullopt; } protected: - constexpr VirtualDisplayId(uint64_t flags, BaseId baseId) - : DisplayId(DisplayId::FLAG_VIRTUAL | flags | baseId) {} - + explicit constexpr VirtualDisplayId(uint64_t value) : DisplayId(FLAG_VIRTUAL | value) {} explicit constexpr VirtualDisplayId(DisplayId other) : DisplayId(other) {} }; struct HalVirtualDisplayId : VirtualDisplayId { - explicit constexpr HalVirtualDisplayId(BaseId baseId) : VirtualDisplayId(0, baseId) {} + explicit constexpr HalVirtualDisplayId(BaseId baseId) : VirtualDisplayId(baseId) {} static constexpr std::optional tryCast(DisplayId id) { - if ((id.value & FLAG_VIRTUAL) && !(id.value & VirtualDisplayId::FLAG_GPU)) { - return {HalVirtualDisplayId(id)}; + if (id.isVirtual() && !(id.value & FLAG_GPU)) { + return HalVirtualDisplayId(id); } return std::nullopt; } @@ -145,17 +147,27 @@ private: }; struct GpuVirtualDisplayId : VirtualDisplayId { - explicit constexpr GpuVirtualDisplayId(BaseId baseId) - : VirtualDisplayId(VirtualDisplayId::FLAG_GPU, baseId) {} + explicit constexpr GpuVirtualDisplayId(BaseId baseId) : VirtualDisplayId(FLAG_GPU | baseId) {} + + static constexpr std::optional fromUniqueId(const std::string& uniqueId) { + if (const auto hashOpt = ftl::stable_hash(uniqueId)) { + return GpuVirtualDisplayId(HashTag{}, *hashOpt); + } + return {}; + } static constexpr std::optional tryCast(DisplayId id) { - if ((id.value & FLAG_VIRTUAL) && (id.value & VirtualDisplayId::FLAG_GPU)) { - return {GpuVirtualDisplayId(id)}; + if (id.isVirtual() && (id.value & FLAG_GPU)) { + return GpuVirtualDisplayId(id); } return std::nullopt; } private: + struct HashTag {}; // Disambiguate with BaseId constructor. + constexpr GpuVirtualDisplayId(HashTag, uint64_t hash) + : VirtualDisplayId(FLAG_STABLE | FLAG_GPU | hash) {} + explicit constexpr GpuVirtualDisplayId(DisplayId other) : VirtualDisplayId(other) {} }; @@ -169,7 +181,7 @@ struct HalDisplayId : DisplayId { if (GpuVirtualDisplayId::tryCast(id)) { return std::nullopt; } - return {HalDisplayId(id)}; + return HalDisplayId(id); } private: diff --git a/libs/ui/tests/DisplayId_test.cpp b/libs/ui/tests/DisplayId_test.cpp index 8ddee7e740..1115804954 100644 --- a/libs/ui/tests/DisplayId_test.cpp +++ b/libs/ui/tests/DisplayId_test.cpp @@ -24,7 +24,7 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { constexpr uint8_t port = 1; constexpr uint16_t manufacturerId = 13; constexpr uint32_t modelHash = 42; - PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); + const PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); EXPECT_EQ(port, id.getPort()); EXPECT_EQ(manufacturerId, id.getManufacturerId()); EXPECT_FALSE(VirtualDisplayId::tryCast(id)); @@ -39,7 +39,7 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { TEST(DisplayIdTest, createPhysicalIdFromPort) { constexpr uint8_t port = 3; - PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); + const PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); EXPECT_EQ(port, id.getPort()); EXPECT_FALSE(VirtualDisplayId::tryCast(id)); EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); @@ -52,7 +52,22 @@ TEST(DisplayIdTest, createPhysicalIdFromPort) { } TEST(DisplayIdTest, createGpuVirtualId) { - GpuVirtualDisplayId id(42); + const GpuVirtualDisplayId id(42); + EXPECT_TRUE(VirtualDisplayId::tryCast(id)); + EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); + EXPECT_FALSE(HalDisplayId::tryCast(id)); + + EXPECT_EQ(id, DisplayId::fromValue(id.value)); + EXPECT_EQ(id, DisplayId::fromValue(id.value)); +} + +TEST(DisplayIdTest, createGpuVirtualIdFromUniqueId) { + static const std::string kUniqueId("virtual:ui:DisplayId_test"); + const auto idOpt = GpuVirtualDisplayId::fromUniqueId(kUniqueId); + ASSERT_TRUE(idOpt.has_value()); + const GpuVirtualDisplayId id = idOpt.value(); EXPECT_TRUE(VirtualDisplayId::tryCast(id)); EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); @@ -64,7 +79,7 @@ TEST(DisplayIdTest, createGpuVirtualId) { } TEST(DisplayIdTest, createHalVirtualId) { - HalVirtualDisplayId id(42); + const HalVirtualDisplayId id(42); EXPECT_TRUE(VirtualDisplayId::tryCast(id)); EXPECT_TRUE(HalVirtualDisplayId::tryCast(id)); EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp index c18be7a8e8..83b1b68a17 100644 --- a/services/surfaceflinger/CompositionEngine/src/Display.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp @@ -79,7 +79,7 @@ void Display::setSecure(bool secure) { } bool Display::isVirtual() const { - return VirtualDisplayId::tryCast(mId).has_value(); + return mId.isVirtual(); } std::optional Display::getDisplayId() const { diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index c2d09c910d..ef3e77d4da 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -89,7 +89,7 @@ public: return mCompositionDisplay; } - bool isVirtual() const { return VirtualDisplayId::tryCast(getId()).has_value(); } + bool isVirtual() const { return getId().isVirtual(); } bool isPrimary() const { return mIsPrimary; } // isSecure indicates whether this display can be trusted to display diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp index 4b5a68cefa..d69bfafd2a 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp @@ -316,7 +316,7 @@ status_t VirtualDisplaySurface::setAsyncMode(bool async) { status_t VirtualDisplaySurface::dequeueBuffer(Source source, PixelFormat format, uint64_t usage, int* sslot, sp* fence) { - LOG_ALWAYS_FATAL_IF(GpuVirtualDisplayId::tryCast(mDisplayId).has_value()); + LOG_ALWAYS_FATAL_IF(mDisplayId.isVirtual()); status_t result = mSource[source]->dequeueBuffer(sslot, fence, mSinkBufferWidth, mSinkBufferHeight, @@ -616,7 +616,7 @@ void VirtualDisplaySurface::resetPerFrameState() { } status_t VirtualDisplaySurface::refreshOutputBuffer() { - LOG_ALWAYS_FATAL_IF(GpuVirtualDisplayId::tryCast(mDisplayId).has_value()); + LOG_ALWAYS_FATAL_IF(mDisplayId.isVirtual()); if (mOutputProducerSlot >= 0) { mSource[SOURCE_SINK]->cancelBuffer( -- cgit v1.2.3-59-g8ed1b From 5be0865b7bf1b21b3888c77339060f7dc7dd8018 Mon Sep 17 00:00:00 2001 From: Alan Ding Date: Fri, 24 May 2024 01:48:07 +0000 Subject: Revert "ui: Refactor stable ID generation for GPU virtual displays" This reverts commit 78c90af2224b43467d854e356492527db0f8eb70. Reason for revert: Causes assert for certain GPU virtual display Ids in VirtualDisplaySurface.cpp (https://paste.googleplex.com/6474098414977024) Change-Id: I743312bbab4fd9903e069c3ed4710f9d7901be8d --- libs/ui/include/ui/DisplayId.h | 42 ++++++++-------------- libs/ui/tests/DisplayId_test.cpp | 23 +++--------- .../CompositionEngine/src/Display.cpp | 2 +- services/surfaceflinger/DisplayDevice.h | 2 +- .../DisplayHardware/VirtualDisplaySurface.cpp | 4 +-- 5 files changed, 23 insertions(+), 50 deletions(-) (limited to 'libs/ui') diff --git a/libs/ui/include/ui/DisplayId.h b/libs/ui/include/ui/DisplayId.h index 8a14db8ffa..3a31fa0848 100644 --- a/libs/ui/include/ui/DisplayId.h +++ b/libs/ui/include/ui/DisplayId.h @@ -20,7 +20,6 @@ #include #include -#include #include namespace android { @@ -39,9 +38,6 @@ struct DisplayId { constexpr DisplayId(const DisplayId&) = default; DisplayId& operator=(const DisplayId&) = default; - constexpr bool isVirtual() const { return value & FLAG_VIRTUAL; } - constexpr bool isStable() const { return value & FLAG_STABLE; } - uint64_t value; // For deserialization. @@ -80,10 +76,10 @@ inline std::ostream& operator<<(std::ostream& stream, DisplayId displayId) { // DisplayId of a physical display, such as the internal display or externally connected display. struct PhysicalDisplayId : DisplayId { static constexpr ftl::Optional tryCast(DisplayId id) { - if (id.isVirtual()) { + if (id.value & FLAG_VIRTUAL) { return std::nullopt; } - return PhysicalDisplayId(id); + return {PhysicalDisplayId(id)}; } // Returns a stable ID based on EDID information. @@ -121,23 +117,25 @@ struct VirtualDisplayId : DisplayId { static constexpr uint64_t FLAG_GPU = 1ULL << 61; static constexpr std::optional tryCast(DisplayId id) { - if (id.isVirtual()) { - return VirtualDisplayId(id); + if (id.value & FLAG_VIRTUAL) { + return {VirtualDisplayId(id)}; } return std::nullopt; } protected: - explicit constexpr VirtualDisplayId(uint64_t value) : DisplayId(FLAG_VIRTUAL | value) {} + constexpr VirtualDisplayId(uint64_t flags, BaseId baseId) + : DisplayId(DisplayId::FLAG_VIRTUAL | flags | baseId) {} + explicit constexpr VirtualDisplayId(DisplayId other) : DisplayId(other) {} }; struct HalVirtualDisplayId : VirtualDisplayId { - explicit constexpr HalVirtualDisplayId(BaseId baseId) : VirtualDisplayId(baseId) {} + explicit constexpr HalVirtualDisplayId(BaseId baseId) : VirtualDisplayId(0, baseId) {} static constexpr std::optional tryCast(DisplayId id) { - if (id.isVirtual() && !(id.value & FLAG_GPU)) { - return HalVirtualDisplayId(id); + if ((id.value & FLAG_VIRTUAL) && !(id.value & VirtualDisplayId::FLAG_GPU)) { + return {HalVirtualDisplayId(id)}; } return std::nullopt; } @@ -147,27 +145,17 @@ private: }; struct GpuVirtualDisplayId : VirtualDisplayId { - explicit constexpr GpuVirtualDisplayId(BaseId baseId) : VirtualDisplayId(FLAG_GPU | baseId) {} - - static constexpr std::optional fromUniqueId(const std::string& uniqueId) { - if (const auto hashOpt = ftl::stable_hash(uniqueId)) { - return GpuVirtualDisplayId(HashTag{}, *hashOpt); - } - return {}; - } + explicit constexpr GpuVirtualDisplayId(BaseId baseId) + : VirtualDisplayId(VirtualDisplayId::FLAG_GPU, baseId) {} static constexpr std::optional tryCast(DisplayId id) { - if (id.isVirtual() && (id.value & FLAG_GPU)) { - return GpuVirtualDisplayId(id); + if ((id.value & FLAG_VIRTUAL) && (id.value & VirtualDisplayId::FLAG_GPU)) { + return {GpuVirtualDisplayId(id)}; } return std::nullopt; } private: - struct HashTag {}; // Disambiguate with BaseId constructor. - constexpr GpuVirtualDisplayId(HashTag, uint64_t hash) - : VirtualDisplayId(FLAG_STABLE | FLAG_GPU | hash) {} - explicit constexpr GpuVirtualDisplayId(DisplayId other) : VirtualDisplayId(other) {} }; @@ -181,7 +169,7 @@ struct HalDisplayId : DisplayId { if (GpuVirtualDisplayId::tryCast(id)) { return std::nullopt; } - return HalDisplayId(id); + return {HalDisplayId(id)}; } private: diff --git a/libs/ui/tests/DisplayId_test.cpp b/libs/ui/tests/DisplayId_test.cpp index 1115804954..8ddee7e740 100644 --- a/libs/ui/tests/DisplayId_test.cpp +++ b/libs/ui/tests/DisplayId_test.cpp @@ -24,7 +24,7 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { constexpr uint8_t port = 1; constexpr uint16_t manufacturerId = 13; constexpr uint32_t modelHash = 42; - const PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); + PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); EXPECT_EQ(port, id.getPort()); EXPECT_EQ(manufacturerId, id.getManufacturerId()); EXPECT_FALSE(VirtualDisplayId::tryCast(id)); @@ -39,7 +39,7 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { TEST(DisplayIdTest, createPhysicalIdFromPort) { constexpr uint8_t port = 3; - const PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); + PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); EXPECT_EQ(port, id.getPort()); EXPECT_FALSE(VirtualDisplayId::tryCast(id)); EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); @@ -52,22 +52,7 @@ TEST(DisplayIdTest, createPhysicalIdFromPort) { } TEST(DisplayIdTest, createGpuVirtualId) { - const GpuVirtualDisplayId id(42); - EXPECT_TRUE(VirtualDisplayId::tryCast(id)); - EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); - EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); - EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); - EXPECT_FALSE(HalDisplayId::tryCast(id)); - - EXPECT_EQ(id, DisplayId::fromValue(id.value)); - EXPECT_EQ(id, DisplayId::fromValue(id.value)); -} - -TEST(DisplayIdTest, createGpuVirtualIdFromUniqueId) { - static const std::string kUniqueId("virtual:ui:DisplayId_test"); - const auto idOpt = GpuVirtualDisplayId::fromUniqueId(kUniqueId); - ASSERT_TRUE(idOpt.has_value()); - const GpuVirtualDisplayId id = idOpt.value(); + GpuVirtualDisplayId id(42); EXPECT_TRUE(VirtualDisplayId::tryCast(id)); EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); @@ -79,7 +64,7 @@ TEST(DisplayIdTest, createGpuVirtualIdFromUniqueId) { } TEST(DisplayIdTest, createHalVirtualId) { - const HalVirtualDisplayId id(42); + HalVirtualDisplayId id(42); EXPECT_TRUE(VirtualDisplayId::tryCast(id)); EXPECT_TRUE(HalVirtualDisplayId::tryCast(id)); EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp index 83b1b68a17..c18be7a8e8 100644 --- a/services/surfaceflinger/CompositionEngine/src/Display.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp @@ -79,7 +79,7 @@ void Display::setSecure(bool secure) { } bool Display::isVirtual() const { - return mId.isVirtual(); + return VirtualDisplayId::tryCast(mId).has_value(); } std::optional Display::getDisplayId() const { diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index ef3e77d4da..c2d09c910d 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -89,7 +89,7 @@ public: return mCompositionDisplay; } - bool isVirtual() const { return getId().isVirtual(); } + bool isVirtual() const { return VirtualDisplayId::tryCast(getId()).has_value(); } bool isPrimary() const { return mIsPrimary; } // isSecure indicates whether this display can be trusted to display diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp index d69bfafd2a..4b5a68cefa 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp @@ -316,7 +316,7 @@ status_t VirtualDisplaySurface::setAsyncMode(bool async) { status_t VirtualDisplaySurface::dequeueBuffer(Source source, PixelFormat format, uint64_t usage, int* sslot, sp* fence) { - LOG_ALWAYS_FATAL_IF(mDisplayId.isVirtual()); + LOG_ALWAYS_FATAL_IF(GpuVirtualDisplayId::tryCast(mDisplayId).has_value()); status_t result = mSource[source]->dequeueBuffer(sslot, fence, mSinkBufferWidth, mSinkBufferHeight, @@ -616,7 +616,7 @@ void VirtualDisplaySurface::resetPerFrameState() { } status_t VirtualDisplaySurface::refreshOutputBuffer() { - LOG_ALWAYS_FATAL_IF(mDisplayId.isVirtual()); + LOG_ALWAYS_FATAL_IF(GpuVirtualDisplayId::tryCast(mDisplayId).has_value()); if (mOutputProducerSlot >= 0) { mSource[SOURCE_SINK]->cancelBuffer( -- cgit v1.2.3-59-g8ed1b From c9de92a5fe681ea689a876bbeaaec7ff69df2e48 Mon Sep 17 00:00:00 2001 From: Alan Ding Date: Fri, 24 May 2024 00:27:11 -0700 Subject: Reland "ui: Refactor stable ID generation for GPU virtual displays" This is a partial port of ag/17832464 for main with additional tests. Use ftl::stable_hash to generate stable ID from uniqueId for GPU virtual displays. This allows FLAG_STABLE consistent with PhysicalDisplayId that uses a unique EDID, as well as being stable across reboots when using hardcoded or static unique ID. Add DisplayId.isStable()/isVirtual() interfaces and refactor previous legacy usages. Bug: 339525838 Bug: 137375833 Bug: 194863377 Test: atest libsurfaceflinger_unittest Test: atest libcompositionengine_test Test: atest DisplayIdGeneratorTest Change-Id: I441046f95860bbcaf837468a3c3f5c944225adde --- libs/ui/include/ui/DisplayId.h | 42 ++++++++++++------- libs/ui/tests/DisplayId_test.cpp | 47 ++++++++++++++++++++-- .../CompositionEngine/src/Display.cpp | 2 +- services/surfaceflinger/DisplayDevice.h | 2 +- 4 files changed, 72 insertions(+), 21 deletions(-) (limited to 'libs/ui') diff --git a/libs/ui/include/ui/DisplayId.h b/libs/ui/include/ui/DisplayId.h index 3a31fa0848..8a14db8ffa 100644 --- a/libs/ui/include/ui/DisplayId.h +++ b/libs/ui/include/ui/DisplayId.h @@ -20,6 +20,7 @@ #include #include +#include #include namespace android { @@ -38,6 +39,9 @@ struct DisplayId { constexpr DisplayId(const DisplayId&) = default; DisplayId& operator=(const DisplayId&) = default; + constexpr bool isVirtual() const { return value & FLAG_VIRTUAL; } + constexpr bool isStable() const { return value & FLAG_STABLE; } + uint64_t value; // For deserialization. @@ -76,10 +80,10 @@ inline std::ostream& operator<<(std::ostream& stream, DisplayId displayId) { // DisplayId of a physical display, such as the internal display or externally connected display. struct PhysicalDisplayId : DisplayId { static constexpr ftl::Optional tryCast(DisplayId id) { - if (id.value & FLAG_VIRTUAL) { + if (id.isVirtual()) { return std::nullopt; } - return {PhysicalDisplayId(id)}; + return PhysicalDisplayId(id); } // Returns a stable ID based on EDID information. @@ -117,25 +121,23 @@ struct VirtualDisplayId : DisplayId { static constexpr uint64_t FLAG_GPU = 1ULL << 61; static constexpr std::optional tryCast(DisplayId id) { - if (id.value & FLAG_VIRTUAL) { - return {VirtualDisplayId(id)}; + if (id.isVirtual()) { + return VirtualDisplayId(id); } return std::nullopt; } protected: - constexpr VirtualDisplayId(uint64_t flags, BaseId baseId) - : DisplayId(DisplayId::FLAG_VIRTUAL | flags | baseId) {} - + explicit constexpr VirtualDisplayId(uint64_t value) : DisplayId(FLAG_VIRTUAL | value) {} explicit constexpr VirtualDisplayId(DisplayId other) : DisplayId(other) {} }; struct HalVirtualDisplayId : VirtualDisplayId { - explicit constexpr HalVirtualDisplayId(BaseId baseId) : VirtualDisplayId(0, baseId) {} + explicit constexpr HalVirtualDisplayId(BaseId baseId) : VirtualDisplayId(baseId) {} static constexpr std::optional tryCast(DisplayId id) { - if ((id.value & FLAG_VIRTUAL) && !(id.value & VirtualDisplayId::FLAG_GPU)) { - return {HalVirtualDisplayId(id)}; + if (id.isVirtual() && !(id.value & FLAG_GPU)) { + return HalVirtualDisplayId(id); } return std::nullopt; } @@ -145,17 +147,27 @@ private: }; struct GpuVirtualDisplayId : VirtualDisplayId { - explicit constexpr GpuVirtualDisplayId(BaseId baseId) - : VirtualDisplayId(VirtualDisplayId::FLAG_GPU, baseId) {} + explicit constexpr GpuVirtualDisplayId(BaseId baseId) : VirtualDisplayId(FLAG_GPU | baseId) {} + + static constexpr std::optional fromUniqueId(const std::string& uniqueId) { + if (const auto hashOpt = ftl::stable_hash(uniqueId)) { + return GpuVirtualDisplayId(HashTag{}, *hashOpt); + } + return {}; + } static constexpr std::optional tryCast(DisplayId id) { - if ((id.value & FLAG_VIRTUAL) && (id.value & VirtualDisplayId::FLAG_GPU)) { - return {GpuVirtualDisplayId(id)}; + if (id.isVirtual() && (id.value & FLAG_GPU)) { + return GpuVirtualDisplayId(id); } return std::nullopt; } private: + struct HashTag {}; // Disambiguate with BaseId constructor. + constexpr GpuVirtualDisplayId(HashTag, uint64_t hash) + : VirtualDisplayId(FLAG_STABLE | FLAG_GPU | hash) {} + explicit constexpr GpuVirtualDisplayId(DisplayId other) : VirtualDisplayId(other) {} }; @@ -169,7 +181,7 @@ struct HalDisplayId : DisplayId { if (GpuVirtualDisplayId::tryCast(id)) { return std::nullopt; } - return {HalDisplayId(id)}; + return HalDisplayId(id); } private: diff --git a/libs/ui/tests/DisplayId_test.cpp b/libs/ui/tests/DisplayId_test.cpp index 8ddee7e740..ef686dfc83 100644 --- a/libs/ui/tests/DisplayId_test.cpp +++ b/libs/ui/tests/DisplayId_test.cpp @@ -24,7 +24,7 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { constexpr uint8_t port = 1; constexpr uint16_t manufacturerId = 13; constexpr uint32_t modelHash = 42; - PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); + const PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); EXPECT_EQ(port, id.getPort()); EXPECT_EQ(manufacturerId, id.getManufacturerId()); EXPECT_FALSE(VirtualDisplayId::tryCast(id)); @@ -39,7 +39,7 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { TEST(DisplayIdTest, createPhysicalIdFromPort) { constexpr uint8_t port = 3; - PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); + const PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); EXPECT_EQ(port, id.getPort()); EXPECT_FALSE(VirtualDisplayId::tryCast(id)); EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); @@ -52,7 +52,34 @@ TEST(DisplayIdTest, createPhysicalIdFromPort) { } TEST(DisplayIdTest, createGpuVirtualId) { - GpuVirtualDisplayId id(42); + const GpuVirtualDisplayId id(42); + EXPECT_TRUE(VirtualDisplayId::tryCast(id)); + EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); + EXPECT_FALSE(HalDisplayId::tryCast(id)); + + EXPECT_EQ(id, DisplayId::fromValue(id.value)); + EXPECT_EQ(id, DisplayId::fromValue(id.value)); +} + +TEST(DisplayIdTest, createVirtualIdFromGpuVirtualId) { + const VirtualDisplayId id(GpuVirtualDisplayId(42)); + EXPECT_TRUE(VirtualDisplayId::tryCast(id)); + EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); + EXPECT_FALSE(HalDisplayId::tryCast(id)); + + const bool isGpuVirtualId = (id.value & VirtualDisplayId::FLAG_GPU); + EXPECT_EQ((id.isVirtual() && isGpuVirtualId), GpuVirtualDisplayId::tryCast(id).has_value()); +} + +TEST(DisplayIdTest, createGpuVirtualIdFromUniqueId) { + static const std::string kUniqueId("virtual:ui:DisplayId_test"); + const auto idOpt = GpuVirtualDisplayId::fromUniqueId(kUniqueId); + ASSERT_TRUE(idOpt.has_value()); + const GpuVirtualDisplayId id = idOpt.value(); EXPECT_TRUE(VirtualDisplayId::tryCast(id)); EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); @@ -64,7 +91,7 @@ TEST(DisplayIdTest, createGpuVirtualId) { } TEST(DisplayIdTest, createHalVirtualId) { - HalVirtualDisplayId id(42); + const HalVirtualDisplayId id(42); EXPECT_TRUE(VirtualDisplayId::tryCast(id)); EXPECT_TRUE(HalVirtualDisplayId::tryCast(id)); EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); @@ -75,4 +102,16 @@ TEST(DisplayIdTest, createHalVirtualId) { EXPECT_EQ(id, DisplayId::fromValue(id.value)); } +TEST(DisplayIdTest, createVirtualIdFromHalVirtualId) { + const VirtualDisplayId id(HalVirtualDisplayId(42)); + EXPECT_TRUE(VirtualDisplayId::tryCast(id)); + EXPECT_TRUE(HalVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); + EXPECT_TRUE(HalDisplayId::tryCast(id)); + + const bool isGpuVirtualId = (id.value & VirtualDisplayId::FLAG_GPU); + EXPECT_EQ((id.isVirtual() && !isGpuVirtualId), HalVirtualDisplayId::tryCast(id).has_value()); +} + } // namespace android::ui diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp index c18be7a8e8..83b1b68a17 100644 --- a/services/surfaceflinger/CompositionEngine/src/Display.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp @@ -79,7 +79,7 @@ void Display::setSecure(bool secure) { } bool Display::isVirtual() const { - return VirtualDisplayId::tryCast(mId).has_value(); + return mId.isVirtual(); } std::optional Display::getDisplayId() const { diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index b339bc6c70..a21559fb45 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -89,7 +89,7 @@ public: return mCompositionDisplay; } - bool isVirtual() const { return VirtualDisplayId::tryCast(getId()).has_value(); } + bool isVirtual() const { return getId().isVirtual(); } bool isPrimary() const { return mIsPrimary; } // isSecure indicates whether this display can be trusted to display -- cgit v1.2.3-59-g8ed1b