summaryrefslogtreecommitdiff
path: root/services/inputflinger/dispatcher/InputDispatcher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/inputflinger/dispatcher/InputDispatcher.cpp')
-rw-r--r--services/inputflinger/dispatcher/InputDispatcher.cpp83
1 files changed, 48 insertions, 35 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 1899c5f29d..ce1f266cfb 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -523,7 +523,6 @@ InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& polic
mInTouchMode(true),
mMaximumObscuringOpacityForTouch(1.0f),
mFocusedDisplayId(ADISPLAY_ID_DEFAULT),
- mFocusedWindowRequestedPointerCapture(false),
mWindowTokenWithPointerCapture(nullptr),
mLatencyAggregator(),
mLatencyTracker(&mLatencyAggregator),
@@ -1306,36 +1305,51 @@ void InputDispatcher::dispatchFocusLocked(nsecs_t currentTime, std::shared_ptr<F
void InputDispatcher::dispatchPointerCaptureChangedLocked(
nsecs_t currentTime, const std::shared_ptr<PointerCaptureChangedEntry>& entry,
DropReason& dropReason) {
- const bool haveWindowWithPointerCapture = mWindowTokenWithPointerCapture != nullptr;
- if (entry->pointerCaptureEnabled && haveWindowWithPointerCapture) {
- LOG_ALWAYS_FATAL("Pointer Capture has already been enabled for the window.");
- }
- if (!entry->pointerCaptureEnabled && !haveWindowWithPointerCapture) {
- // Pointer capture was already forcefully disabled because of focus change.
- dropReason = DropReason::NOT_DROPPED;
- return;
- }
-
- // Set drop reason for early returns
- dropReason = DropReason::NO_POINTER_CAPTURE;
+ dropReason = DropReason::NOT_DROPPED;
+ const bool haveWindowWithPointerCapture = mWindowTokenWithPointerCapture != nullptr;
sp<IBinder> token;
- if (entry->pointerCaptureEnabled) {
- // Enable Pointer Capture
- if (!mFocusedWindowRequestedPointerCapture) {
+
+ if (entry->pointerCaptureRequest.enable) {
+ // Enable Pointer Capture.
+ if (haveWindowWithPointerCapture &&
+ (entry->pointerCaptureRequest == mCurrentPointerCaptureRequest)) {
+ LOG_ALWAYS_FATAL("This request to enable Pointer Capture has already been dispatched "
+ "to the window.");
+ }
+ if (!mCurrentPointerCaptureRequest.enable) {
// This can happen if a window requests capture and immediately releases capture.
ALOGW("No window requested Pointer Capture.");
+ dropReason = DropReason::NO_POINTER_CAPTURE;
+ return;
+ }
+ if (entry->pointerCaptureRequest.seq != mCurrentPointerCaptureRequest.seq) {
+ ALOGI("Skipping dispatch of Pointer Capture being enabled: sequence number mismatch.");
return;
}
+
token = mFocusResolver.getFocusedWindowToken(mFocusedDisplayId);
LOG_ALWAYS_FATAL_IF(!token, "Cannot find focused window for Pointer Capture.");
mWindowTokenWithPointerCapture = token;
} else {
- // Disable Pointer Capture
+ // Disable Pointer Capture.
+ // We do not check if the sequence number matches for requests to disable Pointer Capture
+ // for two reasons:
+ // 1. Pointer Capture can be disabled by a focus change, which means we can get two entries
+ // to disable capture with the same sequence number: one generated by
+ // disablePointerCaptureForcedLocked() and another as an acknowledgement of Pointer
+ // Capture being disabled in InputReader.
+ // 2. We respect any request to disable Pointer Capture generated by InputReader, since the
+ // actual Pointer Capture state that affects events being generated by input devices is
+ // in InputReader.
+ if (!haveWindowWithPointerCapture) {
+ // Pointer capture was already forcefully disabled because of focus change.
+ dropReason = DropReason::NOT_DROPPED;
+ return;
+ }
token = mWindowTokenWithPointerCapture;
mWindowTokenWithPointerCapture = nullptr;
- if (mFocusedWindowRequestedPointerCapture) {
- mFocusedWindowRequestedPointerCapture = false;
+ if (mCurrentPointerCaptureRequest.enable) {
setPointerCaptureLocked(false);
}
}
@@ -1344,8 +1358,7 @@ void InputDispatcher::dispatchPointerCaptureChangedLocked(
if (channel == nullptr) {
// Window has gone away, clean up Pointer Capture state.
mWindowTokenWithPointerCapture = nullptr;
- if (mFocusedWindowRequestedPointerCapture) {
- mFocusedWindowRequestedPointerCapture = false;
+ if (mCurrentPointerCaptureRequest.enable) {
setPointerCaptureLocked(false);
}
return;
@@ -3180,7 +3193,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
static_cast<const PointerCaptureChangedEntry&>(eventEntry);
status = connection->inputPublisher
.publishCaptureEvent(dispatchEntry->seq, captureEntry.id,
- captureEntry.pointerCaptureEnabled);
+ captureEntry.pointerCaptureRequest.enable);
break;
}
@@ -3978,14 +3991,14 @@ void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
void InputDispatcher::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) {
#if DEBUG_INBOUND_EVENT_DETAILS
ALOGD("notifyPointerCaptureChanged - eventTime=%" PRId64 ", enabled=%s", args->eventTime,
- args->enabled ? "true" : "false");
+ args->request.enable ? "true" : "false");
#endif
bool needWake;
{ // acquire lock
std::scoped_lock _l(mLock);
auto entry = std::make_unique<PointerCaptureChangedEntry>(args->id, args->eventTime,
- args->enabled);
+ args->request);
needWake = enqueueInboundEventLocked(std::move(entry));
} // release lock
@@ -4929,8 +4942,8 @@ void InputDispatcher::logDispatchStateLocked() {
std::string InputDispatcher::dumpPointerCaptureStateLocked() {
std::string dump;
- dump += StringPrintf(INDENT "FocusedWindowRequestedPointerCapture: %s\n",
- toString(mFocusedWindowRequestedPointerCapture));
+ dump += StringPrintf(INDENT "Pointer Capture Requested: %s\n",
+ toString(mCurrentPointerCaptureRequest.enable));
std::string windowName = "None";
if (mWindowTokenWithPointerCapture) {
@@ -4939,7 +4952,7 @@ std::string InputDispatcher::dumpPointerCaptureStateLocked() {
windowName = captureWindowHandle ? captureWindowHandle->getName().c_str()
: "token has capture without window";
}
- dump += StringPrintf(INDENT "CurrentWindowWithPointerCapture: %s\n", windowName.c_str());
+ dump += StringPrintf(INDENT "Current Window with Pointer Capture: %s\n", windowName.c_str());
return dump;
}
@@ -5407,14 +5420,13 @@ void InputDispatcher::requestPointerCapture(const sp<IBinder>& windowToken, bool
return;
}
- if (enabled == mFocusedWindowRequestedPointerCapture) {
+ if (enabled == mCurrentPointerCaptureRequest.enable) {
ALOGW("Ignoring request to %s Pointer Capture: "
"window has %s requested pointer capture.",
enabled ? "enable" : "disable", enabled ? "already" : "not");
return;
}
- mFocusedWindowRequestedPointerCapture = enabled;
setPointerCaptureLocked(enabled);
} // release lock
@@ -6173,14 +6185,13 @@ void InputDispatcher::onFocusChangedLocked(const FocusResolver::FocusChanges& ch
}
void InputDispatcher::disablePointerCaptureForcedLocked() {
- if (!mFocusedWindowRequestedPointerCapture && !mWindowTokenWithPointerCapture) {
+ if (!mCurrentPointerCaptureRequest.enable && !mWindowTokenWithPointerCapture) {
return;
}
ALOGD_IF(DEBUG_FOCUS, "Disabling Pointer Capture because the window lost focus.");
- if (mFocusedWindowRequestedPointerCapture) {
- mFocusedWindowRequestedPointerCapture = false;
+ if (mCurrentPointerCaptureRequest.enable) {
setPointerCaptureLocked(false);
}
@@ -6197,14 +6208,16 @@ void InputDispatcher::disablePointerCaptureForcedLocked() {
}
auto entry = std::make_unique<PointerCaptureChangedEntry>(mIdGenerator.nextId(), now(),
- false /* hasCapture */);
+ mCurrentPointerCaptureRequest);
mInboundQueue.push_front(std::move(entry));
}
void InputDispatcher::setPointerCaptureLocked(bool enabled) {
+ mCurrentPointerCaptureRequest.enable = enabled;
+ mCurrentPointerCaptureRequest.seq++;
std::unique_ptr<CommandEntry> commandEntry = std::make_unique<CommandEntry>(
&InputDispatcher::doSetPointerCaptureLockedInterruptible);
- commandEntry->enabled = enabled;
+ commandEntry->pointerCaptureRequest = mCurrentPointerCaptureRequest;
postCommandLocked(std::move(commandEntry));
}
@@ -6212,7 +6225,7 @@ void InputDispatcher::doSetPointerCaptureLockedInterruptible(
android::inputdispatcher::CommandEntry* commandEntry) {
mLock.unlock();
- mPolicy->setPointerCapture(commandEntry->enabled);
+ mPolicy->setPointerCapture(commandEntry->pointerCaptureRequest);
mLock.lock();
}