Fix input dispatcher regression on launcher drag&drop.

Change-Id: I40e937bd712cd2ed6cceac95dfd1b8c8e070724f
This commit is contained in:
Jeff Brown 2010-09-16 12:31:46 -07:00
parent 4fe5434b2d
commit 405a1d32e9

View File

@ -776,6 +776,9 @@ void InputDispatcher::resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout
// Give up. // Give up.
mInputTargetWaitTimeoutExpired = true; mInputTargetWaitTimeoutExpired = true;
// Release the touch target.
releaseTouchedWindowLocked();
// Input state will not be realistic. Mark it out of sync. // Input state will not be realistic. Mark it out of sync.
if (inputChannel.get()) { if (inputChannel.get()) {
ssize_t connectionIndex = getConnectionIndexLocked(inputChannel); ssize_t connectionIndex = getConnectionIndexLocked(inputChannel);
@ -2159,9 +2162,8 @@ void InputDispatcher::setInputWindows(const Vector<InputWindow>& inputWindows) {
{ // acquire lock { // acquire lock
AutoMutex _l(mLock); AutoMutex _l(mLock);
sp<InputChannel> oldFocusedWindowChannel = mFocusedWindow // Clear old window pointers but remember their associated channels.
? mFocusedWindow->inputChannel : NULL; mFocusedWindow = NULL;
int32_t oldFocusedWindowLayer = mFocusedWindow ? mFocusedWindow->layer : -1;
sp<InputChannel> touchedWindowChannel; sp<InputChannel> touchedWindowChannel;
if (mTouchedWindow) { if (mTouchedWindow) {
@ -2175,11 +2177,11 @@ void InputDispatcher::setInputWindows(const Vector<InputWindow>& inputWindows) {
} }
mTouchedWallpaperWindows.clear(); mTouchedWallpaperWindows.clear();
} }
mFocusedWindow = NULL;
mWallpaperWindows.clear(); mWallpaperWindows.clear();
mWindows.clear(); mWindows.clear();
// Loop over new windows and rebuild the necessary window pointers for
// tracking focus and touch.
mWindows.appendVector(inputWindows); mWindows.appendVector(inputWindows);
size_t numWindows = mWindows.size(); size_t numWindows = mWindows.size();
@ -2203,41 +2205,8 @@ void InputDispatcher::setInputWindows(const Vector<InputWindow>& inputWindows) {
mTouchedWindow = window; mTouchedWindow = window;
} }
} }
mTempTouchedWallpaperChannels.clear(); mTempTouchedWallpaperChannels.clear();
bool preempt = false;
if (mFocusedWindow
&& mFocusedWindow->inputChannel != oldFocusedWindowChannel
&& mFocusedWindow->canReceiveKeys) {
// If the new input focus is an error window or appears above the current
// input focus, drop the current touched window so that we can start
// delivering events to the new input focus as soon as possible.
if (mFocusedWindow->layoutParamsFlags & InputWindow::FLAG_SYSTEM_ERROR) {
#if DEBUG_FOCUS
LOGD("Preempting: New SYSTEM_ERROR window; resetting state");
#endif
preempt = true;
} else if (oldFocusedWindowChannel.get() != NULL
&& mFocusedWindow->layer > oldFocusedWindowLayer) {
#if DEBUG_FOCUS
LOGD("Preempting: Transferring focus to new window at higher layer: "
"old win layer=%d, new win layer=%d",
oldFocusedWindowLayer, mFocusedWindow->layer);
#endif
preempt = true;
}
}
if (mTouchedWindow && ! mTouchedWindow->visible) {
#if DEBUG_FOCUS
LOGD("Preempting: Touched window became invisible.");
#endif
preempt = true;
}
if (preempt) {
releaseTouchedWindowLocked();
}
#if DEBUG_FOCUS #if DEBUG_FOCUS
logDispatchStateLocked(); logDispatchStateLocked();
#endif #endif
@ -2312,7 +2281,17 @@ void InputDispatcher::setInputDispatchMode(bool enabled, bool frozen) {
void InputDispatcher::logDispatchStateLocked() { void InputDispatcher::logDispatchStateLocked() {
String8 dump; String8 dump;
dumpDispatchStateLocked(dump); dumpDispatchStateLocked(dump);
LOGD("%s", dump.string());
char* text = dump.lockBuffer(dump.size());
char* start = text;
while (*start != '\0') {
char* end = strchr(start, '\n');
if (*end == '\n') {
*(end++) = '\0';
}
LOGD("%s", start);
start = end;
}
} }
void InputDispatcher::dumpDispatchStateLocked(String8& dump) { void InputDispatcher::dumpDispatchStateLocked(String8& dump) {
@ -2326,28 +2305,30 @@ void InputDispatcher::dumpDispatchStateLocked(String8& dump) {
} else { } else {
dump.append(" focusedApplication: <null>\n"); dump.append(" focusedApplication: <null>\n");
} }
dump.appendFormat(" focusedWindow: '%s'\n", dump.appendFormat(" focusedWindow: name='%s'\n",
mFocusedWindow != NULL ? mFocusedWindow->inputChannel->getName().string() : "<null>"); mFocusedWindow != NULL ? mFocusedWindow->name.string() : "<null>");
dump.appendFormat(" touchedWindow: '%s', touchDown=%d\n", dump.appendFormat(" touchedWindow: name='%s', touchDown=%d\n",
mTouchedWindow != NULL ? mTouchedWindow->inputChannel->getName().string() : "<null>", mTouchedWindow != NULL ? mTouchedWindow->name.string() : "<null>",
mTouchDown); mTouchDown);
for (size_t i = 0; i < mTouchedWallpaperWindows.size(); i++) { for (size_t i = 0; i < mTouchedWallpaperWindows.size(); i++) {
dump.appendFormat(" touchedWallpaperWindows[%d]: '%s'\n", dump.appendFormat(" touchedWallpaperWindows[%d]: name='%s'\n",
i, mTouchedWallpaperWindows[i]->inputChannel->getName().string()); i, mTouchedWallpaperWindows[i]->name.string());
} }
for (size_t i = 0; i < mWindows.size(); i++) { for (size_t i = 0; i < mWindows.size(); i++) {
dump.appendFormat(" windows[%d]: '%s', paused=%s, hasFocus=%s, hasWallpaper=%s, " dump.appendFormat(" windows[%d]: name='%s', paused=%s, hasFocus=%s, hasWallpaper=%s, "
"visible=%s, flags=0x%08x, type=0x%08x, " "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, "
"frame=[%d,%d][%d,%d], " "frame=[%d,%d][%d,%d], "
"visibleFrame=[%d,%d][%d,%d], " "visibleFrame=[%d,%d][%d,%d], "
"touchableArea=[%d,%d][%d,%d], " "touchableArea=[%d,%d][%d,%d], "
"ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n", "ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n",
i, mWindows[i].inputChannel->getName().string(), i, mWindows[i].name.string(),
toString(mWindows[i].paused), toString(mWindows[i].paused),
toString(mWindows[i].hasFocus), toString(mWindows[i].hasFocus),
toString(mWindows[i].hasWallpaper), toString(mWindows[i].hasWallpaper),
toString(mWindows[i].visible), toString(mWindows[i].visible),
toString(mWindows[i].canReceiveKeys),
mWindows[i].layoutParamsFlags, mWindows[i].layoutParamsType, mWindows[i].layoutParamsFlags, mWindows[i].layoutParamsType,
mWindows[i].layer,
mWindows[i].frameLeft, mWindows[i].frameTop, mWindows[i].frameLeft, mWindows[i].frameTop,
mWindows[i].frameRight, mWindows[i].frameBottom, mWindows[i].frameRight, mWindows[i].frameBottom,
mWindows[i].visibleFrameLeft, mWindows[i].visibleFrameTop, mWindows[i].visibleFrameLeft, mWindows[i].visibleFrameTop,