diff options
| -rw-r--r-- | libs/gui/WindowInfo.cpp | 8 | ||||
| -rw-r--r-- | libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp | 2 | ||||
| -rw-r--r-- | libs/gui/include/gui/PidUid.h (renamed from libs/gui/include/gui/Uid.h) | 15 | ||||
| -rw-r--r-- | libs/gui/include/gui/WindowInfo.h | 4 | ||||
| -rw-r--r-- | libs/gui/tests/WindowInfo_test.cpp | 2 | ||||
| -rw-r--r-- | services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp | 6 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 34 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.h | 14 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/Monitor.cpp | 2 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/Monitor.h | 5 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/include/InputDispatcherInterface.h | 4 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h | 4 | ||||
| -rw-r--r-- | services/inputflinger/tests/InputDispatcher_test.cpp | 95 | ||||
| -rw-r--r-- | services/surfaceflinger/FrontEnd/LayerSnapshot.cpp | 2 | ||||
| -rw-r--r-- | services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp | 2 | ||||
| -rw-r--r-- | services/surfaceflinger/Layer.cpp | 2 |
16 files changed, 110 insertions, 91 deletions
diff --git a/libs/gui/WindowInfo.cpp b/libs/gui/WindowInfo.cpp index cd9b424e13..52af9d5114 100644 --- a/libs/gui/WindowInfo.cpp +++ b/libs/gui/WindowInfo.cpp @@ -92,6 +92,7 @@ status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { // Ensure that the size of custom types are what we expect for writing into the parcel. static_assert(sizeof(inputConfig) == 4u); + static_assert(sizeof(ownerPid.val()) == 4u); static_assert(sizeof(ownerUid.val()) == 4u); // clang-format off @@ -116,7 +117,7 @@ status_t WindowInfo::writeToParcel(android::Parcel* parcel) const { parcel->writeFloat(transform.dsdy()) ?: parcel->writeFloat(transform.ty()) ?: parcel->writeInt32(static_cast<int32_t>(touchOcclusionMode)) ?: - parcel->writeInt32(ownerPid) ?: + parcel->writeInt32(ownerPid.val()) ?: parcel->writeInt32(ownerUid.val()) ?: parcel->writeUtf8AsUtf16(packageName) ?: parcel->writeInt32(inputConfig.get()) ?: @@ -148,7 +149,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { } float dsdx, dtdx, tx, dtdy, dsdy, ty; - int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerUidInt; + int32_t lpFlags, lpType, touchOcclusionModeInt, inputConfigInt, ownerPidInt, ownerUidInt; sp<IBinder> touchableRegionCropHandleSp; // clang-format off @@ -168,7 +169,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { parcel->readFloat(&dsdy) ?: parcel->readFloat(&ty) ?: parcel->readInt32(&touchOcclusionModeInt) ?: - parcel->readInt32(&ownerPid) ?: + parcel->readInt32(&ownerPidInt) ?: parcel->readInt32(&ownerUidInt) ?: parcel->readUtf8FromUtf16(&packageName) ?: parcel->readInt32(&inputConfigInt) ?: @@ -191,6 +192,7 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt); inputConfig = ftl::Flags<InputConfig>(inputConfigInt); + ownerPid = Pid{ownerPidInt}; ownerUid = Uid{static_cast<uid_t>(ownerUidInt)}; touchableRegionCropHandle = touchableRegionCropHandleSp; diff --git a/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp b/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp index 7268e6483a..95b7f39c11 100644 --- a/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp +++ b/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp @@ -186,7 +186,7 @@ void SurfaceComposerClientFuzzer::getWindowInfo(gui::WindowInfo* windowInfo) { windowInfo->touchableRegion = Region(getRect(&mFdp)); windowInfo->replaceTouchableRegionWithCrop = mFdp.ConsumeBool(); windowInfo->touchOcclusionMode = mFdp.PickValueInArray(kMode); - windowInfo->ownerPid = mFdp.ConsumeIntegral<int32_t>(); + windowInfo->ownerPid = gui::Pid{mFdp.ConsumeIntegral<pid_t>()}; windowInfo->ownerUid = gui::Uid{mFdp.ConsumeIntegral<uid_t>()}; windowInfo->packageName = mFdp.ConsumeRandomLengthString(kRandomStringMaxBytes); windowInfo->inputConfig = mFdp.PickValueInArray(kFeatures); diff --git a/libs/gui/include/gui/Uid.h b/libs/gui/include/gui/PidUid.h index 8e45ef53da..7930942882 100644 --- a/libs/gui/include/gui/Uid.h +++ b/libs/gui/include/gui/PidUid.h @@ -22,6 +22,21 @@ namespace android::gui { +// Type-safe wrapper for a PID. +struct Pid : ftl::Constructible<Pid, pid_t>, ftl::Equatable<Pid>, ftl::Orderable<Pid> { + using Constructible::Constructible; + + const static Pid INVALID; + + 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()); } +}; + +const inline Pid Pid::INVALID{-1}; + // Type-safe wrapper for a UID. // We treat the unsigned equivalent of -1 as a singular invalid value. struct Uid : ftl::Constructible<Uid, uid_t>, ftl::Equatable<Uid>, ftl::Orderable<Uid> { diff --git a/libs/gui/include/gui/WindowInfo.h b/libs/gui/include/gui/WindowInfo.h index 666101eace..7ff73874ae 100644 --- a/libs/gui/include/gui/WindowInfo.h +++ b/libs/gui/include/gui/WindowInfo.h @@ -22,7 +22,7 @@ #include <binder/Parcelable.h> #include <ftl/flags.h> #include <ftl/mixins.h> -#include <gui/Uid.h> +#include <gui/PidUid.h> #include <gui/constants.h> #include <ui/Rect.h> #include <ui/Region.h> @@ -225,7 +225,7 @@ struct WindowInfo : public Parcelable { Region touchableRegion; TouchOcclusionMode touchOcclusionMode = TouchOcclusionMode::BLOCK_UNTRUSTED; - int32_t ownerPid = -1; + Pid ownerPid = Pid::INVALID; Uid ownerUid = Uid::INVALID; std::string packageName; ftl::Flags<InputConfig> inputConfig; diff --git a/libs/gui/tests/WindowInfo_test.cpp b/libs/gui/tests/WindowInfo_test.cpp index e3a629e1cb..461fe4a4ce 100644 --- a/libs/gui/tests/WindowInfo_test.cpp +++ b/libs/gui/tests/WindowInfo_test.cpp @@ -61,7 +61,7 @@ TEST(WindowInfo, Parcelling) { i.alpha = 0.7; i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1}); i.touchOcclusionMode = TouchOcclusionMode::ALLOW; - i.ownerPid = 19; + i.ownerPid = gui::Pid{19}; i.ownerUid = gui::Uid{24}; i.packageName = "com.example.package"; i.inputConfig = WindowInfo::InputConfig::NOT_FOCUSABLE; diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index c5cf0833a8..b2e274d832 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -36,7 +36,7 @@ namespace { constexpr int32_t DEVICE_ID = 1; // The default pid and uid for windows created by the test. -constexpr int32_t WINDOW_PID = 999; +constexpr gui::Pid WINDOW_PID{999}; constexpr gui::Uid WINDOW_UID{1001}; static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 5s; @@ -61,13 +61,13 @@ private: ALOGE("There is no focused window for %s", applicationHandle->getName().c_str()); } - void notifyWindowUnresponsive(const sp<IBinder>& connectionToken, std::optional<int32_t> pid, + void notifyWindowUnresponsive(const sp<IBinder>& connectionToken, std::optional<gui::Pid> pid, const std::string& reason) override { ALOGE("Window is not responding: %s", reason.c_str()); } void notifyWindowResponsive(const sp<IBinder>& connectionToken, - std::optional<int32_t> pid) override {} + std::optional<gui::Pid> pid) override {} void notifyInputChannelBroken(const sp<IBinder>&) override {} diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 6f0f022dfe..6f2464b41b 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -561,7 +561,7 @@ bool canReceiveForegroundTouches(const WindowInfo& info) { return !info.inputConfig.test(gui::WindowInfo::InputConfig::NOT_TOUCHABLE) && !info.isSpy(); } -bool isWindowOwnedBy(const sp<WindowInfoHandle>& windowHandle, int32_t pid, gui::Uid uid) { +bool isWindowOwnedBy(const sp<WindowInfoHandle>& windowHandle, gui::Pid pid, gui::Uid uid) { if (windowHandle == nullptr) { return false; } @@ -5358,16 +5358,16 @@ void InputDispatcher::setInputFilterEnabled(bool enabled) { mLooper->wake(); } -bool InputDispatcher::setInTouchMode(bool inTouchMode, int32_t pid, gui::Uid uid, +bool InputDispatcher::setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission, int32_t displayId) { bool needWake = false; { std::scoped_lock lock(mLock); ALOGD_IF(DEBUG_TOUCH_MODE, - "Request to change touch mode to %s (calling pid=%d, uid=%s, " + "Request to change touch mode to %s (calling pid=%s, uid=%s, " "hasPermission=%s, target displayId=%d, mTouchModePerDisplay[displayId]=%s)", - toString(inTouchMode), pid, uid.toString().c_str(), toString(hasPermission), - displayId, + toString(inTouchMode), pid.toString().c_str(), uid.toString().c_str(), + toString(hasPermission), displayId, mTouchModePerDisplay.count(displayId) == 0 ? "not set" : std::to_string(mTouchModePerDisplay[displayId]).c_str()); @@ -5379,9 +5379,9 @@ bool InputDispatcher::setInTouchMode(bool inTouchMode, int32_t pid, gui::Uid uid if (!hasPermission) { if (!focusedWindowIsOwnedByLocked(pid, uid) && !recentWindowsAreOwnedByLocked(pid, uid)) { - ALOGD("Touch mode switch rejected, caller (pid=%d, uid=%s) doesn't own the focused " + ALOGD("Touch mode switch rejected, caller (pid=%s, uid=%s) doesn't own the focused " "window nor none of the previously interacted window", - pid, uid.toString().c_str()); + pid.toString().c_str(), uid.toString().c_str()); return false; } } @@ -5397,7 +5397,7 @@ bool InputDispatcher::setInTouchMode(bool inTouchMode, int32_t pid, gui::Uid uid return true; } -bool InputDispatcher::focusedWindowIsOwnedByLocked(int32_t pid, gui::Uid uid) { +bool InputDispatcher::focusedWindowIsOwnedByLocked(gui::Pid pid, gui::Uid uid) { const sp<IBinder> focusedToken = mFocusResolver.getFocusedWindowToken(mFocusedDisplayId); if (focusedToken == nullptr) { return false; @@ -5406,7 +5406,7 @@ bool InputDispatcher::focusedWindowIsOwnedByLocked(int32_t pid, gui::Uid uid) { return isWindowOwnedBy(windowHandle, pid, uid); } -bool InputDispatcher::recentWindowsAreOwnedByLocked(int32_t pid, gui::Uid uid) { +bool InputDispatcher::recentWindowsAreOwnedByLocked(gui::Pid pid, gui::Uid uid) { return std::find_if(mInteractionConnectionTokens.begin(), mInteractionConnectionTokens.end(), [&](const sp<IBinder>& connectionToken) REQUIRES(mLock) { const sp<WindowInfoHandle> windowHandle = @@ -5691,10 +5691,10 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) const { windowInfo->applicationInfo.name.c_str(), binderToString(windowInfo->applicationInfo.token).c_str()); dump += dumpRegion(windowInfo->touchableRegion); - dump += StringPrintf(", ownerPid=%d, ownerUid=%s, dispatchingTimeout=%" PRId64 + dump += StringPrintf(", ownerPid=%s, ownerUid=%s, dispatchingTimeout=%" PRId64 "ms, hasToken=%s, " "touchOcclusionMode=%s\n", - windowInfo->ownerPid, + windowInfo->ownerPid.toString().c_str(), windowInfo->ownerUid.toString().c_str(), millis(windowInfo->dispatchingTimeout), binderToString(windowInfo->token).c_str(), @@ -5887,7 +5887,7 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputChannel(const Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(int32_t displayId, const std::string& name, - int32_t pid) { + gui::Pid pid) { std::shared_ptr<InputChannel> serverChannel; std::unique_ptr<InputChannel> clientChannel; status_t result = openInputChannelPair(name, serverChannel, clientChannel); @@ -6079,7 +6079,7 @@ void InputDispatcher::setDisplayEligibilityForPointerCapture(int32_t displayId, } // release lock } -std::optional<int32_t> InputDispatcher::findMonitorPidByTokenLocked(const sp<IBinder>& token) { +std::optional<gui::Pid> InputDispatcher::findMonitorPidByTokenLocked(const sp<IBinder>& token) { for (const auto& [_, monitors] : mGlobalMonitorsByDisplay) { for (const Monitor& monitor : monitors) { if (monitor.inputChannel->getConnectionToken() == token) { @@ -6299,7 +6299,7 @@ void InputDispatcher::doInterceptKeyBeforeDispatchingCommand(const sp<IBinder>& } void InputDispatcher::sendWindowUnresponsiveCommandLocked(const sp<IBinder>& token, - std::optional<int32_t> pid, + std::optional<gui::Pid> pid, std::string reason) { auto command = [this, token, pid, reason = std::move(reason)]() REQUIRES(mLock) { scoped_unlock unlock(mLock); @@ -6309,7 +6309,7 @@ void InputDispatcher::sendWindowUnresponsiveCommandLocked(const sp<IBinder>& tok } void InputDispatcher::sendWindowResponsiveCommandLocked(const sp<IBinder>& token, - std::optional<int32_t> pid) { + std::optional<gui::Pid> pid) { auto command = [this, token, pid]() REQUIRES(mLock) { scoped_unlock unlock(mLock); mPolicy.notifyWindowResponsive(token, pid); @@ -6325,7 +6325,7 @@ void InputDispatcher::sendWindowResponsiveCommandLocked(const sp<IBinder>& token void InputDispatcher::processConnectionUnresponsiveLocked(const Connection& connection, std::string reason) { const sp<IBinder>& connectionToken = connection.inputChannel->getConnectionToken(); - std::optional<int32_t> pid; + std::optional<gui::Pid> pid; if (connection.monitor) { ALOGW("Monitor %s is unresponsive: %s", connection.inputChannel->getName().c_str(), reason.c_str()); @@ -6347,7 +6347,7 @@ void InputDispatcher::processConnectionUnresponsiveLocked(const Connection& conn */ void InputDispatcher::processConnectionResponsiveLocked(const Connection& connection) { const sp<IBinder>& connectionToken = connection.inputChannel->getConnectionToken(); - std::optional<int32_t> pid; + std::optional<gui::Pid> pid; if (connection.monitor) { pid = findMonitorPidByTokenLocked(connectionToken); } else { diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index 2038bb8916..cdce49214b 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -119,7 +119,7 @@ public: void setFocusedDisplay(int32_t displayId) override; void setInputDispatchMode(bool enabled, bool frozen) override; void setInputFilterEnabled(bool enabled) override; - bool setInTouchMode(bool inTouchMode, int32_t pid, gui::Uid uid, bool hasPermission, + bool setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission, int32_t displayId) override; void setMaximumObscuringOpacityForTouch(float opacity) override; @@ -132,7 +132,7 @@ public: void setFocusedWindow(const android::gui::FocusRequest&) override; base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId, const std::string& name, - int32_t pid) override; + gui::Pid pid) override; status_t removeInputChannel(const sp<IBinder>& connectionToken) override; status_t pilferPointers(const sp<IBinder>& token) override; void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) override; @@ -271,7 +271,7 @@ private: mConnectionsByToken GUARDED_BY(mLock); // Find a monitor pid by the provided token. - std::optional<int32_t> findMonitorPidByTokenLocked(const sp<IBinder>& token) REQUIRES(mLock); + std::optional<gui::Pid> findMonitorPidByTokenLocked(const sp<IBinder>& token) REQUIRES(mLock); // Input channels that will receive a copy of all input events sent to the provided display. std::unordered_map<int32_t, std::vector<Monitor>> mGlobalMonitorsByDisplay GUARDED_BY(mLock); @@ -522,10 +522,10 @@ private: void processConnectionResponsiveLocked(const Connection& connection) REQUIRES(mLock); void sendWindowUnresponsiveCommandLocked(const sp<IBinder>& connectionToken, - std::optional<int32_t> pid, std::string reason) + std::optional<gui::Pid> pid, std::string reason) REQUIRES(mLock); void sendWindowResponsiveCommandLocked(const sp<IBinder>& connectionToken, - std::optional<int32_t> pid) REQUIRES(mLock); + std::optional<gui::Pid> pid) REQUIRES(mLock); // Optimization: AnrTracker is used to quickly find which connection is due for a timeout next. // AnrTracker must be kept in-sync with all responsive connection.waitQueues. @@ -703,8 +703,8 @@ private: void traceWaitQueueLength(const Connection& connection); // Check window ownership - bool focusedWindowIsOwnedByLocked(int32_t pid, gui::Uid uid) REQUIRES(mLock); - bool recentWindowsAreOwnedByLocked(int32_t pid, gui::Uid uid) REQUIRES(mLock); + bool focusedWindowIsOwnedByLocked(gui::Pid pid, gui::Uid uid) REQUIRES(mLock); + bool recentWindowsAreOwnedByLocked(gui::Pid pid, gui::Uid uid) REQUIRES(mLock); sp<InputReporterInterface> mReporter; diff --git a/services/inputflinger/dispatcher/Monitor.cpp b/services/inputflinger/dispatcher/Monitor.cpp index 43a82d5cca..204791eb03 100644 --- a/services/inputflinger/dispatcher/Monitor.cpp +++ b/services/inputflinger/dispatcher/Monitor.cpp @@ -19,7 +19,7 @@ namespace android::inputdispatcher { // --- Monitor --- -Monitor::Monitor(const std::shared_ptr<InputChannel>& inputChannel, int32_t pid) +Monitor::Monitor(const std::shared_ptr<InputChannel>& inputChannel, gui::Pid pid) : inputChannel(inputChannel), pid(pid) {} } // namespace android::inputdispatcher diff --git a/services/inputflinger/dispatcher/Monitor.h b/services/inputflinger/dispatcher/Monitor.h index 7b511915d0..1b1eb3a593 100644 --- a/services/inputflinger/dispatcher/Monitor.h +++ b/services/inputflinger/dispatcher/Monitor.h @@ -16,6 +16,7 @@ #pragma once +#include <gui/PidUid.h> #include <input/InputTransport.h> namespace android::inputdispatcher { @@ -23,9 +24,9 @@ namespace android::inputdispatcher { struct Monitor { std::shared_ptr<InputChannel> inputChannel; // never null - int32_t pid; + gui::Pid pid; - explicit Monitor(const std::shared_ptr<InputChannel>& inputChannel, int32_t pid); + explicit Monitor(const std::shared_ptr<InputChannel>& inputChannel, gui::Pid pid); }; } // namespace android::inputdispatcher diff --git a/services/inputflinger/dispatcher/include/InputDispatcherInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherInterface.h index e8c95c61d3..49597e2101 100644 --- a/services/inputflinger/dispatcher/include/InputDispatcherInterface.h +++ b/services/inputflinger/dispatcher/include/InputDispatcherInterface.h @@ -134,7 +134,7 @@ public: * * Returns true when changing touch mode state. */ - virtual bool setInTouchMode(bool inTouchMode, int32_t pid, gui::Uid uid, bool hasPermission, + virtual bool setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission, int32_t displayId) = 0; /** @@ -182,7 +182,7 @@ public: */ virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId, const std::string& name, - int32_t pid) = 0; + gui::Pid pid) = 0; /* Removes input channels that will no longer receive input events. * diff --git a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h index ec15b8d20b..d50f74d5c5 100644 --- a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h +++ b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h @@ -54,7 +54,7 @@ public: * pid of the owner. The string reason contains information about the input event that we * haven't received a response for. */ - virtual void notifyWindowUnresponsive(const sp<IBinder>& token, std::optional<int32_t> pid, + virtual void notifyWindowUnresponsive(const sp<IBinder>& token, std::optional<gui::Pid> pid, const std::string& reason) = 0; /* Notifies the system that a window just became responsive. This is only called after the @@ -62,7 +62,7 @@ public: * no longer should be shown to the user. The window is eligible to cause a new ANR in the * future. */ - virtual void notifyWindowResponsive(const sp<IBinder>& token, std::optional<int32_t> pid) = 0; + virtual void notifyWindowResponsive(const sp<IBinder>& token, std::optional<gui::Pid> pid) = 0; /* Notifies the system that an input channel is unrecoverably broken. */ virtual void notifyInputChannelBroken(const sp<IBinder>& token) = 0; diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 499d944b00..3aec02c1e8 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -95,15 +95,15 @@ static constexpr int32_t POINTER_2_UP = AMOTION_EVENT_ACTION_POINTER_UP | (2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); // The default pid and uid for windows created on the primary display by the test. -static constexpr int32_t WINDOW_PID = 999; +static constexpr gui::Pid WINDOW_PID{999}; static constexpr gui::Uid WINDOW_UID{1001}; // The default pid and uid for the windows created on the secondary display by the test. -static constexpr int32_t SECONDARY_WINDOW_PID = 1010; +static constexpr gui::Pid SECONDARY_WINDOW_PID{1010}; static constexpr gui::Uid SECONDARY_WINDOW_UID{1012}; // An arbitrary pid of the gesture monitor window -static constexpr int32_t MONITOR_PID = 2001; +static constexpr gui::Pid MONITOR_PID{2001}; static constexpr std::chrono::duration STALE_EVENT_TIMEOUT = 1000ms; @@ -208,7 +208,10 @@ MATCHER_P(WithPointers, pointers, "MotionEvent with specified pointers") { class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface { InputDispatcherConfiguration mConfig; - using AnrResult = std::pair<sp<IBinder>, int32_t /*pid*/>; + struct AnrResult { + sp<IBinder> token{}; + gui::Pid pid{-1}; + }; public: FakeInputDispatcherPolicy() = default; @@ -298,15 +301,14 @@ public: void assertNotifyWindowUnresponsiveWasCalled(std::chrono::nanoseconds timeout, const sp<IBinder>& expectedToken, - int32_t expectedPid) { + gui::Pid expectedPid) { std::unique_lock lock(mLock); android::base::ScopedLockAssertion assumeLocked(mLock); AnrResult result; ASSERT_NO_FATAL_FAILURE(result = getAnrTokenLockedInterruptible(timeout, mAnrWindows, lock)); - const auto& [token, pid] = result; - ASSERT_EQ(expectedToken, token); - ASSERT_EQ(expectedPid, pid); + ASSERT_EQ(expectedToken, result.token); + ASSERT_EQ(expectedPid, result.pid); } /** Wrap call with ASSERT_NO_FATAL_FAILURE() to ensure the return value is valid. */ @@ -319,15 +321,14 @@ public: } void assertNotifyWindowResponsiveWasCalled(const sp<IBinder>& expectedToken, - int32_t expectedPid) { + gui::Pid expectedPid) { std::unique_lock lock(mLock); android::base::ScopedLockAssertion assumeLocked(mLock); AnrResult result; ASSERT_NO_FATAL_FAILURE( result = getAnrTokenLockedInterruptible(0s, mResponsiveWindows, lock)); - const auto& [token, pid] = result; - ASSERT_EQ(expectedToken, token); - ASSERT_EQ(expectedPid, pid); + ASSERT_EQ(expectedToken, result.token); + ASSERT_EQ(expectedPid, result.pid); } /** Wrap call with ASSERT_NO_FATAL_FAILURE() to ensure the return value is valid. */ @@ -509,7 +510,7 @@ private: mConfigurationChangedTime = when; } - void notifyWindowUnresponsive(const sp<IBinder>& connectionToken, std::optional<int32_t> pid, + void notifyWindowUnresponsive(const sp<IBinder>& connectionToken, std::optional<gui::Pid> pid, const std::string&) override { std::scoped_lock lock(mLock); ASSERT_TRUE(pid.has_value()); @@ -518,7 +519,7 @@ private: } void notifyWindowResponsive(const sp<IBinder>& connectionToken, - std::optional<int32_t> pid) override { + std::optional<gui::Pid> pid) override { std::scoped_lock lock(mLock); ASSERT_TRUE(pid.has_value()); mResponsiveWindows.push({connectionToken, *pid}); @@ -1445,12 +1446,12 @@ public: const std::string& getName() { return mName; } - void setOwnerInfo(int32_t ownerPid, gui::Uid ownerUid) { + void setOwnerInfo(gui::Pid ownerPid, gui::Uid ownerUid) { mInfo.ownerPid = ownerPid; mInfo.ownerUid = ownerUid; } - int32_t getPid() const { return mInfo.ownerPid; } + gui::Pid getPid() const { return mInfo.ownerPid; } void destroyReceiver() { mInputReceiver = nullptr; } @@ -5510,7 +5511,7 @@ TEST_F(InputDispatcherTest, DisplayRemoved) { * FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */ TEST_F(InputDispatcherTest, SlipperyWindow_SetsFlagPartiallyObscured) { - constexpr int32_t SLIPPERY_PID = WINDOW_PID + 1; + constexpr gui::Pid SLIPPERY_PID{WINDOW_PID.val() + 1}; constexpr gui::Uid SLIPPERY_UID{WINDOW_UID.val() + 1}; std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); @@ -5598,19 +5599,19 @@ TEST_F(InputDispatcherTest, NotifiesDeviceInteractionsWithMotions) { sp<FakeWindowHandle> leftWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); leftWindow->setFrame(Rect(0, 0, 100, 100)); - leftWindow->setOwnerInfo(1, Uid{101}); + leftWindow->setOwnerInfo(gui::Pid{1}, Uid{101}); sp<FakeWindowHandle> rightSpy = sp<FakeWindowHandle>::make(application, mDispatcher, "Right spy", ADISPLAY_ID_DEFAULT); rightSpy->setFrame(Rect(100, 0, 200, 100)); - rightSpy->setOwnerInfo(2, Uid{102}); + rightSpy->setOwnerInfo(gui::Pid{2}, Uid{102}); rightSpy->setSpy(true); rightSpy->setTrustedOverlay(true); sp<FakeWindowHandle> rightWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); rightWindow->setFrame(Rect(100, 0, 200, 100)); - rightWindow->setOwnerInfo(3, Uid{103}); + rightWindow->setOwnerInfo(gui::Pid{3}, Uid{103}); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {rightSpy, rightWindow, leftWindow}}}); @@ -5675,7 +5676,7 @@ TEST_F(InputDispatcherTest, NotifiesDeviceInteractionsWithKeys) { sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); - window->setOwnerInfo(1, gui::Uid{101}); + window->setOwnerInfo(gui::Pid{1}, gui::Uid{101}); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); setFocusedWindow(window); @@ -7913,7 +7914,7 @@ protected: sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(app, mDispatcher, name, ADISPLAY_ID_DEFAULT); // Generate an arbitrary PID based on the UID - window->setOwnerInfo(1777 + (uid.val() % 10000), uid); + window->setOwnerInfo(gui::Pid{static_cast<pid_t>(1777 + (uid.val() % 10000))}, uid); return window; } @@ -8759,13 +8760,13 @@ TEST_F(InputDispatcherDropInputFeatureTest, ObscuredWindowDropsInput) { sp<FakeWindowHandle>::make(obscuringApplication, mDispatcher, "obscuringWindow", ADISPLAY_ID_DEFAULT); obscuringWindow->setFrame(Rect(0, 0, 50, 50)); - obscuringWindow->setOwnerInfo(111, gui::Uid{111}); + obscuringWindow->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); obscuringWindow->setTouchable(false); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT); window->setDropInputIfObscured(true); - window->setOwnerInfo(222, gui::Uid{222}); + window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); window->setFocusable(true); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {obscuringWindow, window}}}); @@ -8802,13 +8803,13 @@ TEST_F(InputDispatcherDropInputFeatureTest, UnobscuredWindowGetsInput) { sp<FakeWindowHandle>::make(obscuringApplication, mDispatcher, "obscuringWindow", ADISPLAY_ID_DEFAULT); obscuringWindow->setFrame(Rect(0, 0, 50, 50)); - obscuringWindow->setOwnerInfo(111, gui::Uid{111}); + obscuringWindow->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); obscuringWindow->setTouchable(false); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT); window->setDropInputIfObscured(true); - window->setOwnerInfo(222, gui::Uid{222}); + window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); window->setFocusable(true); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {obscuringWindow, window}}}); @@ -8885,7 +8886,7 @@ protected: } } - void changeAndVerifyTouchModeInMainDisplayOnly(bool inTouchMode, int32_t pid, gui::Uid uid, + void changeAndVerifyTouchModeInMainDisplayOnly(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission) { ASSERT_TRUE(mDispatcher->setInTouchMode(inTouchMode, pid, uid, hasPermission, ADISPLAY_ID_DEFAULT)); @@ -8904,9 +8905,9 @@ TEST_F(InputDispatcherTouchModeChangedTests, FocusedWindowCanChangeTouchMode) { TEST_F(InputDispatcherTouchModeChangedTests, NonFocusedWindowOwnerCannotChangeTouchMode) { const WindowInfo& windowInfo = *mWindow->getInfo(); - int32_t ownerPid = windowInfo.ownerPid; + gui::Pid ownerPid = windowInfo.ownerPid; gui::Uid ownerUid = windowInfo.ownerUid; - mWindow->setOwnerInfo(/*pid=*/-1, gui::Uid::INVALID); + mWindow->setOwnerInfo(gui::Pid::INVALID, gui::Uid::INVALID); ASSERT_FALSE(mDispatcher->setInTouchMode(InputDispatcher::kDefaultInTouchMode, ownerPid, ownerUid, /*hasPermission=*/false, ADISPLAY_ID_DEFAULT)); @@ -8916,9 +8917,9 @@ TEST_F(InputDispatcherTouchModeChangedTests, NonFocusedWindowOwnerCannotChangeTo TEST_F(InputDispatcherTouchModeChangedTests, NonWindowOwnerMayChangeTouchModeOnPermissionGranted) { const WindowInfo& windowInfo = *mWindow->getInfo(); - int32_t ownerPid = windowInfo.ownerPid; + gui::Pid ownerPid = windowInfo.ownerPid; gui::Uid ownerUid = windowInfo.ownerUid; - mWindow->setOwnerInfo(/*pid=*/-1, gui::Uid::INVALID); + mWindow->setOwnerInfo(gui::Pid::INVALID, gui::Uid::INVALID); changeAndVerifyTouchModeInMainDisplayOnly(!InputDispatcher::kDefaultInTouchMode, ownerPid, ownerUid, /*hasPermission=*/true); } @@ -9129,10 +9130,10 @@ TEST_F(InputDispatcherSpyWindowTest, TouchableRegion) { */ TEST_F(InputDispatcherSpyWindowTest, WatchOutsideTouches) { auto window = createForeground(); - window->setOwnerInfo(12, gui::Uid{34}); + window->setOwnerInfo(gui::Pid{12}, gui::Uid{34}); auto spy = createSpy(); spy->setWatchOutsideTouch(true); - spy->setOwnerInfo(56, gui::Uid{78}); + spy->setOwnerInfo(gui::Pid{56}, gui::Uid{78}); spy->setFrame(Rect{0, 0, 20, 20}); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {spy, window}}}); @@ -9545,7 +9546,7 @@ public: sp<FakeWindowHandle>::make(overlayApplication, mDispatcher, "Stylus interceptor window", ADISPLAY_ID_DEFAULT); overlay->setFocusable(false); - overlay->setOwnerInfo(111, gui::Uid{111}); + overlay->setOwnerInfo(gui::Pid{111}, gui::Uid{111}); overlay->setTouchable(false); overlay->setInterceptsStylus(true); overlay->setTrustedOverlay(true); @@ -9556,7 +9557,7 @@ public: sp<FakeWindowHandle>::make(application, mDispatcher, "Application window", ADISPLAY_ID_DEFAULT); window->setFocusable(true); - window->setOwnerInfo(222, gui::Uid{222}); + window->setOwnerInfo(gui::Pid{222}, gui::Uid{222}); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {overlay, window}}}); @@ -9666,12 +9667,12 @@ TEST_F(InputDispatcherStylusInterceptorTest, StylusHandwritingScenario) { } struct User { - int32_t mPid; + gui::Pid mPid; gui::Uid mUid; uint32_t mPolicyFlags{DEFAULT_POLICY_FLAGS}; std::unique_ptr<InputDispatcher>& mDispatcher; - User(std::unique_ptr<InputDispatcher>& dispatcher, int32_t pid, gui::Uid uid) + User(std::unique_ptr<InputDispatcher>& dispatcher, gui::Pid pid, gui::Uid uid) : mPid(pid), mUid(uid), mDispatcher(dispatcher) {} InputEventInjectionResult injectTargetedMotion(int32_t action) const { @@ -9704,7 +9705,7 @@ struct User { using InputDispatcherTargetedInjectionTest = InputDispatcherTest; TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoOwnedWindow) { - auto owner = User(mDispatcher, 10, gui::Uid{11}); + auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); auto window = owner.createWindow(); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -9721,11 +9722,11 @@ TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoOwnedWindow) { } TEST_F(InputDispatcherTargetedInjectionTest, CannotInjectIntoUnownedWindow) { - auto owner = User(mDispatcher, 10, gui::Uid{11}); + auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); auto window = owner.createWindow(); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); - auto rando = User(mDispatcher, 20, gui::Uid{21}); + auto rando = User(mDispatcher, gui::Pid{20}, gui::Uid{21}); EXPECT_EQ(InputEventInjectionResult::TARGET_MISMATCH, rando.injectTargetedMotion(AMOTION_EVENT_ACTION_DOWN)); @@ -9738,7 +9739,7 @@ TEST_F(InputDispatcherTargetedInjectionTest, CannotInjectIntoUnownedWindow) { } TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoOwnedSpyWindow) { - auto owner = User(mDispatcher, 10, gui::Uid{11}); + auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); auto window = owner.createWindow(); auto spy = owner.createWindow(); spy->setSpy(true); @@ -9752,10 +9753,10 @@ TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoOwnedSpyWindow) { } TEST_F(InputDispatcherTargetedInjectionTest, CannotInjectIntoUnownedSpyWindow) { - auto owner = User(mDispatcher, 10, gui::Uid{11}); + auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); auto window = owner.createWindow(); - auto rando = User(mDispatcher, 20, gui::Uid{21}); + auto rando = User(mDispatcher, gui::Pid{20}, gui::Uid{21}); auto randosSpy = rando.createWindow(); randosSpy->setSpy(true); randosSpy->setTrustedOverlay(true); @@ -9770,10 +9771,10 @@ TEST_F(InputDispatcherTargetedInjectionTest, CannotInjectIntoUnownedSpyWindow) { } TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoAnyWindowWhenNotTargeting) { - auto owner = User(mDispatcher, 10, gui::Uid{11}); + auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); auto window = owner.createWindow(); - auto rando = User(mDispatcher, 20, gui::Uid{21}); + auto rando = User(mDispatcher, gui::Pid{20}, gui::Uid{21}); auto randosSpy = rando.createWindow(); randosSpy->setSpy(true); randosSpy->setTrustedOverlay(true); @@ -9795,10 +9796,10 @@ TEST_F(InputDispatcherTargetedInjectionTest, CanInjectIntoAnyWindowWhenNotTarget } TEST_F(InputDispatcherTargetedInjectionTest, CannotGenerateActionOutsideToOtherUids) { - auto owner = User(mDispatcher, 10, gui::Uid{11}); + auto owner = User(mDispatcher, gui::Pid{10}, gui::Uid{11}); auto window = owner.createWindow(); - auto rando = User(mDispatcher, 20, gui::Uid{21}); + auto rando = User(mDispatcher, gui::Pid{20}, gui::Uid{21}); auto randosWindow = rando.createWindow(); randosWindow->setFrame(Rect{-10, -10, -5, -5}); randosWindow->setWatchOutsideTouch(true); diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp index f469a1f624..3caeebec2a 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp @@ -47,7 +47,7 @@ LayerSnapshot::LayerSnapshot(const RequestedLayerState& state, inputInfo.name = state.name; inputInfo.id = static_cast<int32_t>(uniqueSequence); inputInfo.ownerUid = gui::Uid{state.ownerUid}; - inputInfo.ownerPid = state.ownerPid; + inputInfo.ownerPid = gui::Pid{state.ownerPid}; uid = state.ownerUid; pid = state.ownerPid; changes = RequestedLayerState::Changes::Created; diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp index 806b5024fe..a266493c38 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp @@ -1008,7 +1008,7 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot, // b/271132344 revisit this and see if we can always use the layers uid/pid snapshot.inputInfo.name = requested.name; snapshot.inputInfo.ownerUid = gui::Uid{requested.ownerUid}; - snapshot.inputInfo.ownerPid = requested.ownerPid; + snapshot.inputInfo.ownerPid = gui::Pid{requested.ownerPid}; } snapshot.touchCropId = requested.touchCropId; diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index a5d7ce7966..5a010e8af6 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -2453,7 +2453,7 @@ WindowInfo Layer::fillInputInfo(const InputDisplayArgs& displayArgs) { if (!hasInputInfo()) { mDrawingState.inputInfo.name = getName(); mDrawingState.inputInfo.ownerUid = gui::Uid{mOwnerUid}; - mDrawingState.inputInfo.ownerPid = mOwnerPid; + mDrawingState.inputInfo.ownerPid = gui::Pid{mOwnerPid}; mDrawingState.inputInfo.inputConfig |= WindowInfo::InputConfig::NO_INPUT_CHANNEL; mDrawingState.inputInfo.displayId = getLayerStack().id; } |