Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 17 | #define LOG_TAG "InputDispatcher" |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | // Log detailed debug messages about each inbound event notification to the dispatcher. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 22 | #define DEBUG_INBOUND_EVENT_DETAILS 0 |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 23 | |
| 24 | // Log detailed debug messages about each outbound event processed by the dispatcher. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 25 | #define DEBUG_OUTBOUND_EVENT_DETAILS 0 |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 26 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 27 | // Log debug messages about the dispatch cycle. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 28 | #define DEBUG_DISPATCH_CYCLE 0 |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 29 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 30 | // Log debug messages about registrations. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 31 | #define DEBUG_REGISTRATION 0 |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 32 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 33 | // Log debug messages about input event injection. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 34 | #define DEBUG_INJECTION 0 |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 35 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 36 | // Log debug messages about input focus tracking. |
| 37 | #define DEBUG_FOCUS 0 |
| 38 | |
| 39 | // Log debug messages about the app switch latency optimization. |
| 40 | #define DEBUG_APP_SWITCH 0 |
| 41 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 42 | // Log debug messages about hover events. |
| 43 | #define DEBUG_HOVER 0 |
| 44 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 45 | #include "InputDispatcher.h" |
| 46 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 47 | #include <cutils/log.h> |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 48 | #include <ui/PowerManager.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 49 | |
| 50 | #include <stddef.h> |
| 51 | #include <unistd.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 52 | #include <errno.h> |
| 53 | #include <limits.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 54 | |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 55 | #define INDENT " " |
| 56 | #define INDENT2 " " |
| 57 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 58 | namespace android { |
| 59 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 60 | // Default input dispatching timeout if there is no focused application or paused window |
| 61 | // from which to determine an appropriate dispatching timeout. |
| 62 | const nsecs_t DEFAULT_INPUT_DISPATCHING_TIMEOUT = 5000 * 1000000LL; // 5 sec |
| 63 | |
| 64 | // Amount of time to allow for all pending events to be processed when an app switch |
| 65 | // key is on the way. This is used to preempt input dispatch and drop input events |
| 66 | // when an application takes too long to respond and the user has pressed an app switch key. |
| 67 | const nsecs_t APP_SWITCH_TIMEOUT = 500 * 1000000LL; // 0.5sec |
| 68 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 69 | // Amount of time to allow for an event to be dispatched (measured since its eventTime) |
| 70 | // before considering it stale and dropping it. |
| 71 | const nsecs_t STALE_EVENT_TIMEOUT = 10000 * 1000000LL; // 10sec |
| 72 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 73 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 74 | static inline nsecs_t now() { |
| 75 | return systemTime(SYSTEM_TIME_MONOTONIC); |
| 76 | } |
| 77 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 78 | static inline const char* toString(bool value) { |
| 79 | return value ? "true" : "false"; |
| 80 | } |
| 81 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 82 | static inline int32_t getMotionEventActionPointerIndex(int32_t action) { |
| 83 | return (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) |
| 84 | >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; |
| 85 | } |
| 86 | |
| 87 | static bool isValidKeyAction(int32_t action) { |
| 88 | switch (action) { |
| 89 | case AKEY_EVENT_ACTION_DOWN: |
| 90 | case AKEY_EVENT_ACTION_UP: |
| 91 | return true; |
| 92 | default: |
| 93 | return false; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | static bool validateKeyEvent(int32_t action) { |
| 98 | if (! isValidKeyAction(action)) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 99 | ALOGE("Key event has invalid action code 0x%x", action); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | return true; |
| 103 | } |
| 104 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 105 | static bool isValidMotionAction(int32_t action, size_t pointerCount) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 106 | switch (action & AMOTION_EVENT_ACTION_MASK) { |
| 107 | case AMOTION_EVENT_ACTION_DOWN: |
| 108 | case AMOTION_EVENT_ACTION_UP: |
| 109 | case AMOTION_EVENT_ACTION_CANCEL: |
| 110 | case AMOTION_EVENT_ACTION_MOVE: |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 111 | case AMOTION_EVENT_ACTION_OUTSIDE: |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 112 | case AMOTION_EVENT_ACTION_HOVER_ENTER: |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 113 | case AMOTION_EVENT_ACTION_HOVER_MOVE: |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 114 | case AMOTION_EVENT_ACTION_HOVER_EXIT: |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 115 | case AMOTION_EVENT_ACTION_SCROLL: |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 116 | return true; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 117 | case AMOTION_EVENT_ACTION_POINTER_DOWN: |
| 118 | case AMOTION_EVENT_ACTION_POINTER_UP: { |
| 119 | int32_t index = getMotionEventActionPointerIndex(action); |
| 120 | return index >= 0 && size_t(index) < pointerCount; |
| 121 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 122 | default: |
| 123 | return false; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | static bool validateMotionEvent(int32_t action, size_t pointerCount, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 128 | const PointerProperties* pointerProperties) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 129 | if (! isValidMotionAction(action, pointerCount)) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 130 | ALOGE("Motion event has invalid action code 0x%x", action); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 131 | return false; |
| 132 | } |
| 133 | if (pointerCount < 1 || pointerCount > MAX_POINTERS) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 134 | ALOGE("Motion event has invalid pointer count %d; value must be between 1 and %d.", |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 135 | pointerCount, MAX_POINTERS); |
| 136 | return false; |
| 137 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 138 | BitSet32 pointerIdBits; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 139 | for (size_t i = 0; i < pointerCount; i++) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 140 | int32_t id = pointerProperties[i].id; |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 141 | if (id < 0 || id > MAX_POINTER_ID) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 142 | ALOGE("Motion event has invalid pointer id %d; value must be between 0 and %d", |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 143 | id, MAX_POINTER_ID); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 144 | return false; |
| 145 | } |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 146 | if (pointerIdBits.hasBit(id)) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 147 | ALOGE("Motion event has duplicate pointer id %d", id); |
Jeff Brown | c3db858 | 2010-10-20 15:33:38 -0700 | [diff] [blame] | 148 | return false; |
| 149 | } |
| 150 | pointerIdBits.markBit(id); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 151 | } |
| 152 | return true; |
| 153 | } |
| 154 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 155 | static void dumpRegion(String8& dump, const SkRegion& region) { |
| 156 | if (region.isEmpty()) { |
| 157 | dump.append("<empty>"); |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | bool first = true; |
| 162 | for (SkRegion::Iterator it(region); !it.done(); it.next()) { |
| 163 | if (first) { |
| 164 | first = false; |
| 165 | } else { |
| 166 | dump.append("|"); |
| 167 | } |
| 168 | const SkIRect& rect = it.rect(); |
| 169 | dump.appendFormat("[%d,%d][%d,%d]", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 170 | } |
| 171 | } |
| 172 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 173 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 174 | // --- InputDispatcher --- |
| 175 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 176 | InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy) : |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 177 | mPolicy(policy), |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 178 | mPendingEvent(NULL), mAppSwitchSawKeyDown(false), mAppSwitchDueTime(LONG_LONG_MAX), |
| 179 | mNextUnblockedEvent(NULL), |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 180 | mDispatchEnabled(true), mDispatchFrozen(false), mInputFilterEnabled(false), |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 181 | mInputTargetWaitCause(INPUT_TARGET_WAIT_CAUSE_NONE) { |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 182 | mLooper = new Looper(false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 183 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 184 | mKeyRepeatState.lastKeyEntry = NULL; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 185 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 186 | policy->getDispatcherConfiguration(&mConfig); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | InputDispatcher::~InputDispatcher() { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 190 | { // acquire lock |
| 191 | AutoMutex _l(mLock); |
| 192 | |
| 193 | resetKeyRepeatLocked(); |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 194 | releasePendingEventLocked(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 195 | drainInboundQueueLocked(); |
| 196 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 197 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 198 | while (mConnectionsByFd.size() != 0) { |
| 199 | unregisterInputChannel(mConnectionsByFd.valueAt(0)->inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 200 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | void InputDispatcher::dispatchOnce() { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 204 | nsecs_t nextWakeupTime = LONG_LONG_MAX; |
| 205 | { // acquire lock |
| 206 | AutoMutex _l(mLock); |
Jeff Brown | 112b5f5 | 2012-01-27 17:32:06 -0800 | [diff] [blame] | 207 | mDispatcherIsAliveCondition.broadcast(); |
| 208 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 209 | dispatchOnceInnerLocked(&nextWakeupTime); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 210 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 211 | if (runCommandsLockedInterruptible()) { |
| 212 | nextWakeupTime = LONG_LONG_MIN; // force next poll to wake up immediately |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 213 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 214 | } // release lock |
| 215 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 216 | // Wait for callback or timeout or wake. (make sure we round up, not down) |
| 217 | nsecs_t currentTime = now(); |
Jeff Brown | aa3855d | 2011-03-17 01:34:19 -0700 | [diff] [blame] | 218 | int timeoutMillis = toMillisecondTimeoutDelay(currentTime, nextWakeupTime); |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 219 | mLooper->pollOnce(timeoutMillis); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 222 | void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 223 | nsecs_t currentTime = now(); |
| 224 | |
| 225 | // Reset the key repeat timer whenever we disallow key events, even if the next event |
| 226 | // is not a key. This is to ensure that we abort a key repeat if the device is just coming |
| 227 | // out of sleep. |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 228 | if (!mPolicy->isKeyRepeatEnabled()) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 229 | resetKeyRepeatLocked(); |
| 230 | } |
| 231 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 232 | // If dispatching is frozen, do not process timeouts or try to deliver any new events. |
| 233 | if (mDispatchFrozen) { |
| 234 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 235 | ALOGD("Dispatch frozen. Waiting some more."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 236 | #endif |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | // Optimize latency of app switches. |
| 241 | // Essentially we start a short timeout when an app switch key (HOME / ENDCALL) has |
| 242 | // been pressed. When it expires, we preempt dispatch and drop all other pending events. |
| 243 | bool isAppSwitchDue = mAppSwitchDueTime <= currentTime; |
| 244 | if (mAppSwitchDueTime < *nextWakeupTime) { |
| 245 | *nextWakeupTime = mAppSwitchDueTime; |
| 246 | } |
| 247 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 248 | // Ready to start a new event. |
| 249 | // If we don't already have a pending event, go grab one. |
| 250 | if (! mPendingEvent) { |
| 251 | if (mInboundQueue.isEmpty()) { |
| 252 | if (isAppSwitchDue) { |
| 253 | // The inbound queue is empty so the app switch key we were waiting |
| 254 | // for will never arrive. Stop waiting for it. |
| 255 | resetPendingAppSwitchLocked(false); |
| 256 | isAppSwitchDue = false; |
| 257 | } |
| 258 | |
| 259 | // Synthesize a key repeat if appropriate. |
| 260 | if (mKeyRepeatState.lastKeyEntry) { |
| 261 | if (currentTime >= mKeyRepeatState.nextRepeatTime) { |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 262 | mPendingEvent = synthesizeKeyRepeatLocked(currentTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 263 | } else { |
| 264 | if (mKeyRepeatState.nextRepeatTime < *nextWakeupTime) { |
| 265 | *nextWakeupTime = mKeyRepeatState.nextRepeatTime; |
| 266 | } |
| 267 | } |
| 268 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 269 | |
| 270 | // Nothing to do if there is no pending event. |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 271 | if (!mPendingEvent) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | } else { |
| 275 | // Inbound queue has at least one entry. |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 276 | mPendingEvent = mInboundQueue.dequeueAtHead(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 277 | } |
Jeff Brown | e2fe69e | 2010-10-18 13:21:23 -0700 | [diff] [blame] | 278 | |
| 279 | // Poke user activity for this event. |
| 280 | if (mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER) { |
| 281 | pokeUserActivityLocked(mPendingEvent); |
| 282 | } |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 283 | |
| 284 | // Get ready to dispatch the event. |
| 285 | resetANRTimeoutsLocked(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | // Now we have an event to dispatch. |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 289 | // All events are eventually dequeued and processed this way, even if we intend to drop them. |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 290 | ALOG_ASSERT(mPendingEvent != NULL); |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 291 | bool done = false; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 292 | DropReason dropReason = DROP_REASON_NOT_DROPPED; |
| 293 | if (!(mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER)) { |
| 294 | dropReason = DROP_REASON_POLICY; |
| 295 | } else if (!mDispatchEnabled) { |
| 296 | dropReason = DROP_REASON_DISABLED; |
| 297 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 298 | |
| 299 | if (mNextUnblockedEvent == mPendingEvent) { |
| 300 | mNextUnblockedEvent = NULL; |
| 301 | } |
| 302 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 303 | switch (mPendingEvent->type) { |
| 304 | case EventEntry::TYPE_CONFIGURATION_CHANGED: { |
| 305 | ConfigurationChangedEntry* typedEntry = |
| 306 | static_cast<ConfigurationChangedEntry*>(mPendingEvent); |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 307 | done = dispatchConfigurationChangedLocked(currentTime, typedEntry); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 308 | dropReason = DROP_REASON_NOT_DROPPED; // configuration changes are never dropped |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 309 | break; |
| 310 | } |
| 311 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 312 | case EventEntry::TYPE_DEVICE_RESET: { |
| 313 | DeviceResetEntry* typedEntry = |
| 314 | static_cast<DeviceResetEntry*>(mPendingEvent); |
| 315 | done = dispatchDeviceResetLocked(currentTime, typedEntry); |
| 316 | dropReason = DROP_REASON_NOT_DROPPED; // device resets are never dropped |
| 317 | break; |
| 318 | } |
| 319 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 320 | case EventEntry::TYPE_KEY: { |
| 321 | KeyEntry* typedEntry = static_cast<KeyEntry*>(mPendingEvent); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 322 | if (isAppSwitchDue) { |
| 323 | if (isAppSwitchKeyEventLocked(typedEntry)) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 324 | resetPendingAppSwitchLocked(true); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 325 | isAppSwitchDue = false; |
| 326 | } else if (dropReason == DROP_REASON_NOT_DROPPED) { |
| 327 | dropReason = DROP_REASON_APP_SWITCH; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 330 | if (dropReason == DROP_REASON_NOT_DROPPED |
| 331 | && isStaleEventLocked(currentTime, typedEntry)) { |
| 332 | dropReason = DROP_REASON_STALE; |
| 333 | } |
| 334 | if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) { |
| 335 | dropReason = DROP_REASON_BLOCKED; |
| 336 | } |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 337 | done = dispatchKeyLocked(currentTime, typedEntry, &dropReason, nextWakeupTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 338 | break; |
| 339 | } |
| 340 | |
| 341 | case EventEntry::TYPE_MOTION: { |
| 342 | MotionEntry* typedEntry = static_cast<MotionEntry*>(mPendingEvent); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 343 | if (dropReason == DROP_REASON_NOT_DROPPED && isAppSwitchDue) { |
| 344 | dropReason = DROP_REASON_APP_SWITCH; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 345 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 346 | if (dropReason == DROP_REASON_NOT_DROPPED |
| 347 | && isStaleEventLocked(currentTime, typedEntry)) { |
| 348 | dropReason = DROP_REASON_STALE; |
| 349 | } |
| 350 | if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) { |
| 351 | dropReason = DROP_REASON_BLOCKED; |
| 352 | } |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 353 | done = dispatchMotionLocked(currentTime, typedEntry, |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 354 | &dropReason, nextWakeupTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 355 | break; |
| 356 | } |
| 357 | |
| 358 | default: |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 359 | ALOG_ASSERT(false); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 360 | break; |
| 361 | } |
| 362 | |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 363 | if (done) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 364 | if (dropReason != DROP_REASON_NOT_DROPPED) { |
| 365 | dropInboundEventLocked(mPendingEvent, dropReason); |
| 366 | } |
| 367 | |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 368 | releasePendingEventLocked(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 369 | *nextWakeupTime = LONG_LONG_MIN; // force next poll to wake up immediately |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) { |
| 374 | bool needWake = mInboundQueue.isEmpty(); |
| 375 | mInboundQueue.enqueueAtTail(entry); |
| 376 | |
| 377 | switch (entry->type) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 378 | case EventEntry::TYPE_KEY: { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 379 | // Optimize app switch latency. |
| 380 | // If the application takes too long to catch up then we drop all events preceding |
| 381 | // the app switch key. |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 382 | KeyEntry* keyEntry = static_cast<KeyEntry*>(entry); |
| 383 | if (isAppSwitchKeyEventLocked(keyEntry)) { |
| 384 | if (keyEntry->action == AKEY_EVENT_ACTION_DOWN) { |
| 385 | mAppSwitchSawKeyDown = true; |
| 386 | } else if (keyEntry->action == AKEY_EVENT_ACTION_UP) { |
| 387 | if (mAppSwitchSawKeyDown) { |
| 388 | #if DEBUG_APP_SWITCH |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 389 | ALOGD("App switch is pending!"); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 390 | #endif |
| 391 | mAppSwitchDueTime = keyEntry->eventTime + APP_SWITCH_TIMEOUT; |
| 392 | mAppSwitchSawKeyDown = false; |
| 393 | needWake = true; |
| 394 | } |
| 395 | } |
| 396 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 397 | break; |
| 398 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 399 | |
| 400 | case EventEntry::TYPE_MOTION: { |
| 401 | // Optimize case where the current application is unresponsive and the user |
| 402 | // decides to touch a window in a different application. |
| 403 | // If the application takes too long to catch up then we drop all events preceding |
| 404 | // the touch into the other window. |
| 405 | MotionEntry* motionEntry = static_cast<MotionEntry*>(entry); |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 406 | if (motionEntry->action == AMOTION_EVENT_ACTION_DOWN |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 407 | && (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) |
| 408 | && mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 409 | && mInputTargetWaitApplicationHandle != NULL) { |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 410 | int32_t x = int32_t(motionEntry->pointerCoords[0]. |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 411 | getAxisValue(AMOTION_EVENT_AXIS_X)); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 412 | int32_t y = int32_t(motionEntry->pointerCoords[0]. |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 413 | getAxisValue(AMOTION_EVENT_AXIS_Y)); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 414 | sp<InputWindowHandle> touchedWindowHandle = findTouchedWindowAtLocked(x, y); |
| 415 | if (touchedWindowHandle != NULL |
| 416 | && touchedWindowHandle->inputApplicationHandle |
| 417 | != mInputTargetWaitApplicationHandle) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 418 | // User touched a different application than the one we are waiting on. |
| 419 | // Flag the event, and start pruning the input queue. |
| 420 | mNextUnblockedEvent = motionEntry; |
| 421 | needWake = true; |
| 422 | } |
| 423 | } |
| 424 | break; |
| 425 | } |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 426 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 427 | |
| 428 | return needWake; |
| 429 | } |
| 430 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 431 | sp<InputWindowHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t x, int32_t y) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 432 | // Traverse windows from front to back to find touched window. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 433 | size_t numWindows = mWindowHandles.size(); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 434 | for (size_t i = 0; i < numWindows; i++) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 435 | sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 436 | const InputWindowInfo* windowInfo = windowHandle->getInfo(); |
| 437 | int32_t flags = windowInfo->layoutParamsFlags; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 438 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 439 | if (windowInfo->visible) { |
| 440 | if (!(flags & InputWindowInfo::FLAG_NOT_TOUCHABLE)) { |
| 441 | bool isTouchModal = (flags & (InputWindowInfo::FLAG_NOT_FOCUSABLE |
| 442 | | InputWindowInfo::FLAG_NOT_TOUCH_MODAL)) == 0; |
| 443 | if (isTouchModal || windowInfo->touchableRegionContainsPoint(x, y)) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 444 | // Found window. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 445 | return windowHandle; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 450 | if (flags & InputWindowInfo::FLAG_SYSTEM_ERROR) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 451 | // Error window is on top but not visible, so touch is dropped. |
| 452 | return NULL; |
| 453 | } |
| 454 | } |
| 455 | return NULL; |
| 456 | } |
| 457 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 458 | void InputDispatcher::dropInboundEventLocked(EventEntry* entry, DropReason dropReason) { |
| 459 | const char* reason; |
| 460 | switch (dropReason) { |
| 461 | case DROP_REASON_POLICY: |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 462 | #if DEBUG_INBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 463 | ALOGD("Dropped event because policy consumed it."); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 464 | #endif |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 465 | reason = "inbound event was dropped because the policy consumed it"; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 466 | break; |
| 467 | case DROP_REASON_DISABLED: |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 468 | ALOGI("Dropped event because input dispatch is disabled."); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 469 | reason = "inbound event was dropped because input dispatch is disabled"; |
| 470 | break; |
| 471 | case DROP_REASON_APP_SWITCH: |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 472 | ALOGI("Dropped event because of pending overdue app switch."); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 473 | reason = "inbound event was dropped because of pending overdue app switch"; |
| 474 | break; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 475 | case DROP_REASON_BLOCKED: |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 476 | ALOGI("Dropped event because the current application is not responding and the user " |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 477 | "has started interacting with a different application."); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 478 | reason = "inbound event was dropped because the current application is not responding " |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 479 | "and the user has started interacting with a different application"; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 480 | break; |
| 481 | case DROP_REASON_STALE: |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 482 | ALOGI("Dropped event because it is stale."); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 483 | reason = "inbound event was dropped because it is stale"; |
| 484 | break; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 485 | default: |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 486 | ALOG_ASSERT(false); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 487 | return; |
| 488 | } |
| 489 | |
| 490 | switch (entry->type) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 491 | case EventEntry::TYPE_KEY: { |
| 492 | CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS, reason); |
| 493 | synthesizeCancelationEventsForAllConnectionsLocked(options); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 494 | break; |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 495 | } |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 496 | case EventEntry::TYPE_MOTION: { |
| 497 | MotionEntry* motionEntry = static_cast<MotionEntry*>(entry); |
| 498 | if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 499 | CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS, reason); |
| 500 | synthesizeCancelationEventsForAllConnectionsLocked(options); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 501 | } else { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 502 | CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS, reason); |
| 503 | synthesizeCancelationEventsForAllConnectionsLocked(options); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 504 | } |
| 505 | break; |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | bool InputDispatcher::isAppSwitchKeyCode(int32_t keyCode) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 511 | return keyCode == AKEYCODE_HOME || keyCode == AKEYCODE_ENDCALL; |
| 512 | } |
| 513 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 514 | bool InputDispatcher::isAppSwitchKeyEventLocked(KeyEntry* keyEntry) { |
| 515 | return ! (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) |
| 516 | && isAppSwitchKeyCode(keyEntry->keyCode) |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 517 | && (keyEntry->policyFlags & POLICY_FLAG_TRUSTED) |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 518 | && (keyEntry->policyFlags & POLICY_FLAG_PASS_TO_USER); |
| 519 | } |
| 520 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 521 | bool InputDispatcher::isAppSwitchPendingLocked() { |
| 522 | return mAppSwitchDueTime != LONG_LONG_MAX; |
| 523 | } |
| 524 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 525 | void InputDispatcher::resetPendingAppSwitchLocked(bool handled) { |
| 526 | mAppSwitchDueTime = LONG_LONG_MAX; |
| 527 | |
| 528 | #if DEBUG_APP_SWITCH |
| 529 | if (handled) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 530 | ALOGD("App switch has arrived."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 531 | } else { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 532 | ALOGD("App switch was abandoned."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 533 | } |
| 534 | #endif |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 537 | bool InputDispatcher::isStaleEventLocked(nsecs_t currentTime, EventEntry* entry) { |
| 538 | return currentTime - entry->eventTime >= STALE_EVENT_TIMEOUT; |
| 539 | } |
| 540 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 541 | bool InputDispatcher::runCommandsLockedInterruptible() { |
| 542 | if (mCommandQueue.isEmpty()) { |
| 543 | return false; |
| 544 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 545 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 546 | do { |
| 547 | CommandEntry* commandEntry = mCommandQueue.dequeueAtHead(); |
| 548 | |
| 549 | Command command = commandEntry->command; |
| 550 | (this->*command)(commandEntry); // commands are implicitly 'LockedInterruptible' |
| 551 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 552 | commandEntry->connection.clear(); |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 553 | delete commandEntry; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 554 | } while (! mCommandQueue.isEmpty()); |
| 555 | return true; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 558 | InputDispatcher::CommandEntry* InputDispatcher::postCommandLocked(Command command) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 559 | CommandEntry* commandEntry = new CommandEntry(command); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 560 | mCommandQueue.enqueueAtTail(commandEntry); |
| 561 | return commandEntry; |
| 562 | } |
| 563 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 564 | void InputDispatcher::drainInboundQueueLocked() { |
| 565 | while (! mInboundQueue.isEmpty()) { |
| 566 | EventEntry* entry = mInboundQueue.dequeueAtHead(); |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 567 | releaseInboundEventLocked(entry); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 568 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 571 | void InputDispatcher::releasePendingEventLocked() { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 572 | if (mPendingEvent) { |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 573 | resetANRTimeoutsLocked(); |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 574 | releaseInboundEventLocked(mPendingEvent); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 575 | mPendingEvent = NULL; |
| 576 | } |
| 577 | } |
| 578 | |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 579 | void InputDispatcher::releaseInboundEventLocked(EventEntry* entry) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 580 | InjectionState* injectionState = entry->injectionState; |
| 581 | if (injectionState && injectionState->injectionResult == INPUT_EVENT_INJECTION_PENDING) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 582 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 583 | ALOGD("Injected inbound event was dropped."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 584 | #endif |
| 585 | setInjectionResultLocked(entry, INPUT_EVENT_INJECTION_FAILED); |
| 586 | } |
Jeff Brown | abb4d44 | 2011-08-15 12:55:32 -0700 | [diff] [blame] | 587 | if (entry == mNextUnblockedEvent) { |
| 588 | mNextUnblockedEvent = NULL; |
| 589 | } |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 590 | entry->release(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 593 | void InputDispatcher::resetKeyRepeatLocked() { |
| 594 | if (mKeyRepeatState.lastKeyEntry) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 595 | mKeyRepeatState.lastKeyEntry->release(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 596 | mKeyRepeatState.lastKeyEntry = NULL; |
| 597 | } |
| 598 | } |
| 599 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 600 | InputDispatcher::KeyEntry* InputDispatcher::synthesizeKeyRepeatLocked(nsecs_t currentTime) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 601 | KeyEntry* entry = mKeyRepeatState.lastKeyEntry; |
| 602 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 603 | // Reuse the repeated key entry if it is otherwise unreferenced. |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 604 | uint32_t policyFlags = (entry->policyFlags & POLICY_FLAG_RAW_MASK) |
| 605 | | POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_TRUSTED; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 606 | if (entry->refCount == 1) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 607 | entry->recycle(); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 608 | entry->eventTime = currentTime; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 609 | entry->policyFlags = policyFlags; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 610 | entry->repeatCount += 1; |
| 611 | } else { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 612 | KeyEntry* newEntry = new KeyEntry(currentTime, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 613 | entry->deviceId, entry->source, policyFlags, |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 614 | entry->action, entry->flags, entry->keyCode, entry->scanCode, |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 615 | entry->metaState, entry->repeatCount + 1, entry->downTime); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 616 | |
| 617 | mKeyRepeatState.lastKeyEntry = newEntry; |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 618 | entry->release(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 619 | |
| 620 | entry = newEntry; |
| 621 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 622 | entry->syntheticRepeat = true; |
| 623 | |
| 624 | // Increment reference count since we keep a reference to the event in |
| 625 | // mKeyRepeatState.lastKeyEntry in addition to the one we return. |
| 626 | entry->refCount += 1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 627 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 628 | mKeyRepeatState.nextRepeatTime = currentTime + mConfig.keyRepeatDelay; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 629 | return entry; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 632 | bool InputDispatcher::dispatchConfigurationChangedLocked( |
| 633 | nsecs_t currentTime, ConfigurationChangedEntry* entry) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 634 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 635 | ALOGD("dispatchConfigurationChanged - eventTime=%lld", entry->eventTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 636 | #endif |
| 637 | |
| 638 | // Reset key repeating in case a keyboard device was added or removed or something. |
| 639 | resetKeyRepeatLocked(); |
| 640 | |
| 641 | // Enqueue a command to run outside the lock to tell the policy that the configuration changed. |
| 642 | CommandEntry* commandEntry = postCommandLocked( |
| 643 | & InputDispatcher::doNotifyConfigurationChangedInterruptible); |
| 644 | commandEntry->eventTime = entry->eventTime; |
| 645 | return true; |
| 646 | } |
| 647 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 648 | bool InputDispatcher::dispatchDeviceResetLocked( |
| 649 | nsecs_t currentTime, DeviceResetEntry* entry) { |
| 650 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 651 | ALOGD("dispatchDeviceReset - eventTime=%lld, deviceId=%d", entry->eventTime, entry->deviceId); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 652 | #endif |
| 653 | |
| 654 | CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS, |
| 655 | "device was reset"); |
| 656 | options.deviceId = entry->deviceId; |
| 657 | synthesizeCancelationEventsForAllConnectionsLocked(options); |
| 658 | return true; |
| 659 | } |
| 660 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 661 | bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry, |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 662 | DropReason* dropReason, nsecs_t* nextWakeupTime) { |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 663 | // Preprocessing. |
| 664 | if (! entry->dispatchInProgress) { |
| 665 | if (entry->repeatCount == 0 |
| 666 | && entry->action == AKEY_EVENT_ACTION_DOWN |
| 667 | && (entry->policyFlags & POLICY_FLAG_TRUSTED) |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 668 | && (!(entry->policyFlags & POLICY_FLAG_DISABLE_KEY_REPEAT))) { |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 669 | if (mKeyRepeatState.lastKeyEntry |
| 670 | && mKeyRepeatState.lastKeyEntry->keyCode == entry->keyCode) { |
| 671 | // We have seen two identical key downs in a row which indicates that the device |
| 672 | // driver is automatically generating key repeats itself. We take note of the |
| 673 | // repeat here, but we disable our own next key repeat timer since it is clear that |
| 674 | // we will not need to synthesize key repeats ourselves. |
| 675 | entry->repeatCount = mKeyRepeatState.lastKeyEntry->repeatCount + 1; |
| 676 | resetKeyRepeatLocked(); |
| 677 | mKeyRepeatState.nextRepeatTime = LONG_LONG_MAX; // don't generate repeats ourselves |
| 678 | } else { |
| 679 | // Not a repeat. Save key down state in case we do see a repeat later. |
| 680 | resetKeyRepeatLocked(); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 681 | mKeyRepeatState.nextRepeatTime = entry->eventTime + mConfig.keyRepeatTimeout; |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 682 | } |
| 683 | mKeyRepeatState.lastKeyEntry = entry; |
| 684 | entry->refCount += 1; |
| 685 | } else if (! entry->syntheticRepeat) { |
| 686 | resetKeyRepeatLocked(); |
| 687 | } |
| 688 | |
Jeff Brown | e2e0126 | 2011-03-02 20:34:30 -0800 | [diff] [blame] | 689 | if (entry->repeatCount == 1) { |
| 690 | entry->flags |= AKEY_EVENT_FLAG_LONG_PRESS; |
| 691 | } else { |
| 692 | entry->flags &= ~AKEY_EVENT_FLAG_LONG_PRESS; |
| 693 | } |
| 694 | |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 695 | entry->dispatchInProgress = true; |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 696 | |
| 697 | logOutboundKeyDetailsLocked("dispatchKey - ", entry); |
| 698 | } |
| 699 | |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 700 | // Handle case where the policy asked us to try again later last time. |
| 701 | if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER) { |
| 702 | if (currentTime < entry->interceptKeyWakeupTime) { |
| 703 | if (entry->interceptKeyWakeupTime < *nextWakeupTime) { |
| 704 | *nextWakeupTime = entry->interceptKeyWakeupTime; |
| 705 | } |
| 706 | return false; // wait until next wakeup |
| 707 | } |
| 708 | entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN; |
| 709 | entry->interceptKeyWakeupTime = 0; |
| 710 | } |
| 711 | |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 712 | // Give the policy a chance to intercept the key. |
| 713 | if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN) { |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 714 | if (entry->policyFlags & POLICY_FLAG_PASS_TO_USER) { |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 715 | CommandEntry* commandEntry = postCommandLocked( |
| 716 | & InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 717 | if (mFocusedWindowHandle != NULL) { |
| 718 | commandEntry->inputWindowHandle = mFocusedWindowHandle; |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 719 | } |
| 720 | commandEntry->keyEntry = entry; |
| 721 | entry->refCount += 1; |
| 722 | return false; // wait for the command to run |
| 723 | } else { |
| 724 | entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_CONTINUE; |
| 725 | } |
| 726 | } else if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_SKIP) { |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 727 | if (*dropReason == DROP_REASON_NOT_DROPPED) { |
| 728 | *dropReason = DROP_REASON_POLICY; |
| 729 | } |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | // Clean up if dropping the event. |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 733 | if (*dropReason != DROP_REASON_NOT_DROPPED) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 734 | setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY |
| 735 | ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED); |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 736 | return true; |
| 737 | } |
| 738 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 739 | // Identify targets. |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 740 | Vector<InputTarget> inputTargets; |
| 741 | int32_t injectionResult = findFocusedWindowTargetsLocked(currentTime, |
| 742 | entry, inputTargets, nextWakeupTime); |
| 743 | if (injectionResult == INPUT_EVENT_INJECTION_PENDING) { |
| 744 | return false; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 747 | setInjectionResultLocked(entry, injectionResult); |
| 748 | if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) { |
| 749 | return true; |
| 750 | } |
| 751 | |
| 752 | addMonitoringTargetsLocked(inputTargets); |
| 753 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 754 | // Dispatch the key. |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 755 | dispatchEventLocked(currentTime, entry, inputTargets); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 756 | return true; |
| 757 | } |
| 758 | |
| 759 | void InputDispatcher::logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry) { |
| 760 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 761 | ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, " |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 762 | "action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, " |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 763 | "repeatCount=%d, downTime=%lld", |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 764 | prefix, |
| 765 | entry->eventTime, entry->deviceId, entry->source, entry->policyFlags, |
| 766 | entry->action, entry->flags, entry->keyCode, entry->scanCode, entry->metaState, |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 767 | entry->repeatCount, entry->downTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 768 | #endif |
| 769 | } |
| 770 | |
| 771 | bool InputDispatcher::dispatchMotionLocked( |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 772 | nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, nsecs_t* nextWakeupTime) { |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 773 | // Preprocessing. |
| 774 | if (! entry->dispatchInProgress) { |
| 775 | entry->dispatchInProgress = true; |
Jeff Brown | e46a0a4 | 2010-11-02 17:58:22 -0700 | [diff] [blame] | 776 | |
| 777 | logOutboundMotionDetailsLocked("dispatchMotion - ", entry); |
| 778 | } |
| 779 | |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 780 | // Clean up if dropping the event. |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 781 | if (*dropReason != DROP_REASON_NOT_DROPPED) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 782 | setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY |
| 783 | ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED); |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 784 | return true; |
| 785 | } |
| 786 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 787 | bool isPointerEvent = entry->source & AINPUT_SOURCE_CLASS_POINTER; |
| 788 | |
| 789 | // Identify targets. |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 790 | Vector<InputTarget> inputTargets; |
| 791 | |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 792 | bool conflictingPointerActions = false; |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 793 | int32_t injectionResult; |
| 794 | if (isPointerEvent) { |
| 795 | // Pointer event. (eg. touchscreen) |
| 796 | injectionResult = findTouchedWindowTargetsLocked(currentTime, |
| 797 | entry, inputTargets, nextWakeupTime, &conflictingPointerActions); |
| 798 | } else { |
| 799 | // Non touch event. (eg. trackball) |
| 800 | injectionResult = findFocusedWindowTargetsLocked(currentTime, |
| 801 | entry, inputTargets, nextWakeupTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 802 | } |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 803 | if (injectionResult == INPUT_EVENT_INJECTION_PENDING) { |
| 804 | return false; |
| 805 | } |
| 806 | |
| 807 | setInjectionResultLocked(entry, injectionResult); |
| 808 | if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) { |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | addMonitoringTargetsLocked(inputTargets); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 813 | |
| 814 | // Dispatch the motion. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 815 | if (conflictingPointerActions) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 816 | CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS, |
| 817 | "conflicting pointer actions"); |
| 818 | synthesizeCancelationEventsForAllConnectionsLocked(options); |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 819 | } |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 820 | dispatchEventLocked(currentTime, entry, inputTargets); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 821 | return true; |
| 822 | } |
| 823 | |
| 824 | |
| 825 | void InputDispatcher::logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry) { |
| 826 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 827 | ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, " |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 828 | "action=0x%x, flags=0x%x, " |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 829 | "metaState=0x%x, buttonState=0x%x, " |
| 830 | "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%lld", |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 831 | prefix, |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 832 | entry->eventTime, entry->deviceId, entry->source, entry->policyFlags, |
| 833 | entry->action, entry->flags, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 834 | entry->metaState, entry->buttonState, |
| 835 | entry->edgeFlags, entry->xPrecision, entry->yPrecision, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 836 | entry->downTime); |
| 837 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 838 | for (uint32_t i = 0; i < entry->pointerCount; i++) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 839 | ALOGD(" Pointer %d: id=%d, toolType=%d, " |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 840 | "x=%f, y=%f, pressure=%f, size=%f, " |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 841 | "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, " |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 842 | "orientation=%f", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 843 | i, entry->pointerProperties[i].id, |
| 844 | entry->pointerProperties[i].toolType, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 845 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X), |
| 846 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y), |
| 847 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), |
| 848 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE), |
| 849 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), |
| 850 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), |
| 851 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), |
| 852 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), |
| 853 | entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION)); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 854 | } |
| 855 | #endif |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 858 | void InputDispatcher::dispatchEventLocked(nsecs_t currentTime, |
| 859 | EventEntry* eventEntry, const Vector<InputTarget>& inputTargets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 860 | #if DEBUG_DISPATCH_CYCLE |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 861 | ALOGD("dispatchEventToCurrentInputTargets"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 862 | #endif |
| 863 | |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 864 | ALOG_ASSERT(eventEntry->dispatchInProgress); // should already have been set to true |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 865 | |
Jeff Brown | e2fe69e | 2010-10-18 13:21:23 -0700 | [diff] [blame] | 866 | pokeUserActivityLocked(eventEntry); |
| 867 | |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 868 | for (size_t i = 0; i < inputTargets.size(); i++) { |
| 869 | const InputTarget& inputTarget = inputTargets.itemAt(i); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 870 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 871 | ssize_t connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 872 | if (connectionIndex >= 0) { |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 873 | sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 874 | prepareDispatchCycleLocked(currentTime, connection, eventEntry, &inputTarget); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 875 | } else { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 876 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 877 | ALOGD("Dropping event delivery to target with channel '%s' because it " |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 878 | "is no longer registered with the input dispatcher.", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 879 | inputTarget.inputChannel->getName().string()); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 880 | #endif |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 885 | int32_t InputDispatcher::handleTargetsNotReadyLocked(nsecs_t currentTime, |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 886 | const EventEntry* entry, |
| 887 | const sp<InputApplicationHandle>& applicationHandle, |
| 888 | const sp<InputWindowHandle>& windowHandle, |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 889 | nsecs_t* nextWakeupTime) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 890 | if (applicationHandle == NULL && windowHandle == NULL) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 891 | if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY) { |
| 892 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 893 | ALOGD("Waiting for system to become ready for input."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 894 | #endif |
| 895 | mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY; |
| 896 | mInputTargetWaitStartTime = currentTime; |
| 897 | mInputTargetWaitTimeoutTime = LONG_LONG_MAX; |
| 898 | mInputTargetWaitTimeoutExpired = false; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 899 | mInputTargetWaitApplicationHandle.clear(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 900 | } |
| 901 | } else { |
| 902 | if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) { |
| 903 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 904 | ALOGD("Waiting for application to become ready for input: %s", |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 905 | getApplicationWindowLabelLocked(applicationHandle, windowHandle).string()); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 906 | #endif |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 907 | nsecs_t timeout; |
| 908 | if (windowHandle != NULL) { |
| 909 | timeout = windowHandle->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT); |
| 910 | } else if (applicationHandle != NULL) { |
| 911 | timeout = applicationHandle->getDispatchingTimeout( |
| 912 | DEFAULT_INPUT_DISPATCHING_TIMEOUT); |
| 913 | } else { |
| 914 | timeout = DEFAULT_INPUT_DISPATCHING_TIMEOUT; |
| 915 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 916 | |
| 917 | mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY; |
| 918 | mInputTargetWaitStartTime = currentTime; |
| 919 | mInputTargetWaitTimeoutTime = currentTime + timeout; |
| 920 | mInputTargetWaitTimeoutExpired = false; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 921 | mInputTargetWaitApplicationHandle.clear(); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 922 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 923 | if (windowHandle != NULL) { |
| 924 | mInputTargetWaitApplicationHandle = windowHandle->inputApplicationHandle; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 925 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 926 | if (mInputTargetWaitApplicationHandle == NULL && applicationHandle != NULL) { |
| 927 | mInputTargetWaitApplicationHandle = applicationHandle; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 928 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | |
| 932 | if (mInputTargetWaitTimeoutExpired) { |
| 933 | return INPUT_EVENT_INJECTION_TIMED_OUT; |
| 934 | } |
| 935 | |
| 936 | if (currentTime >= mInputTargetWaitTimeoutTime) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 937 | onANRLocked(currentTime, applicationHandle, windowHandle, |
| 938 | entry->eventTime, mInputTargetWaitStartTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 939 | |
| 940 | // Force poll loop to wake up immediately on next iteration once we get the |
| 941 | // ANR response back from the policy. |
| 942 | *nextWakeupTime = LONG_LONG_MIN; |
| 943 | return INPUT_EVENT_INJECTION_PENDING; |
| 944 | } else { |
| 945 | // Force poll loop to wake up when timeout is due. |
| 946 | if (mInputTargetWaitTimeoutTime < *nextWakeupTime) { |
| 947 | *nextWakeupTime = mInputTargetWaitTimeoutTime; |
| 948 | } |
| 949 | return INPUT_EVENT_INJECTION_PENDING; |
| 950 | } |
| 951 | } |
| 952 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 953 | void InputDispatcher::resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout, |
| 954 | const sp<InputChannel>& inputChannel) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 955 | if (newTimeout > 0) { |
| 956 | // Extend the timeout. |
| 957 | mInputTargetWaitTimeoutTime = now() + newTimeout; |
| 958 | } else { |
| 959 | // Give up. |
| 960 | mInputTargetWaitTimeoutExpired = true; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 961 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 962 | // Release the touch targets. |
| 963 | mTouchState.reset(); |
Jeff Brown | 2a95c2a | 2010-09-16 12:31:46 -0700 | [diff] [blame] | 964 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 965 | // Input state will not be realistic. Mark it out of sync. |
Jeff Brown | dc3e005 | 2010-09-16 11:02:16 -0700 | [diff] [blame] | 966 | if (inputChannel.get()) { |
| 967 | ssize_t connectionIndex = getConnectionIndexLocked(inputChannel); |
| 968 | if (connectionIndex >= 0) { |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 969 | sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex); |
Jeff Brown | 00045a7 | 2010-12-09 18:10:30 -0800 | [diff] [blame] | 970 | if (connection->status == Connection::STATUS_NORMAL) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 971 | CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS, |
Jeff Brown | 00045a7 | 2010-12-09 18:10:30 -0800 | [diff] [blame] | 972 | "application not responding"); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 973 | synthesizeCancelationEventsForConnectionLocked(connection, options); |
Jeff Brown | 00045a7 | 2010-12-09 18:10:30 -0800 | [diff] [blame] | 974 | } |
Jeff Brown | dc3e005 | 2010-09-16 11:02:16 -0700 | [diff] [blame] | 975 | } |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 976 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 977 | } |
| 978 | } |
| 979 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 980 | nsecs_t InputDispatcher::getTimeSpentWaitingForApplicationLocked( |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 981 | nsecs_t currentTime) { |
| 982 | if (mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) { |
| 983 | return currentTime - mInputTargetWaitStartTime; |
| 984 | } |
| 985 | return 0; |
| 986 | } |
| 987 | |
| 988 | void InputDispatcher::resetANRTimeoutsLocked() { |
| 989 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 990 | ALOGD("Resetting ANR timeouts."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 991 | #endif |
| 992 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 993 | // Reset input target wait timeout. |
| 994 | mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_NONE; |
Jeff Brown | 5ea29ab | 2011-07-27 11:50:51 -0700 | [diff] [blame] | 995 | mInputTargetWaitApplicationHandle.clear(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 998 | int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime, |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 999 | const EventEntry* entry, Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1000 | int32_t injectionResult; |
| 1001 | |
| 1002 | // If there is no currently focused window and no focused application |
| 1003 | // then drop the event. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1004 | if (mFocusedWindowHandle == NULL) { |
| 1005 | if (mFocusedApplicationHandle != NULL) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1006 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1007 | ALOGD("Waiting because there is no focused window but there is a " |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1008 | "focused application that may eventually add a window: %s.", |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1009 | getApplicationWindowLabelLocked(mFocusedApplicationHandle, NULL).string()); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1010 | #endif |
| 1011 | injectionResult = handleTargetsNotReadyLocked(currentTime, entry, |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1012 | mFocusedApplicationHandle, NULL, nextWakeupTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1013 | goto Unresponsive; |
| 1014 | } |
| 1015 | |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 1016 | ALOGI("Dropping event because there is no focused window or focused application."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1017 | injectionResult = INPUT_EVENT_INJECTION_FAILED; |
| 1018 | goto Failed; |
| 1019 | } |
| 1020 | |
| 1021 | // Check permissions. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1022 | if (! checkInjectionPermission(mFocusedWindowHandle, entry->injectionState)) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1023 | injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED; |
| 1024 | goto Failed; |
| 1025 | } |
| 1026 | |
| 1027 | // If the currently focused window is paused then keep waiting. |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1028 | if (mFocusedWindowHandle->getInfo()->paused) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1029 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1030 | ALOGD("Waiting because focused window is paused."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1031 | #endif |
| 1032 | injectionResult = handleTargetsNotReadyLocked(currentTime, entry, |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1033 | mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1034 | goto Unresponsive; |
| 1035 | } |
| 1036 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1037 | // If the currently focused window is still working on previous events then keep waiting. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1038 | if (! isWindowFinishedWithPreviousInputLocked(mFocusedWindowHandle)) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1039 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1040 | ALOGD("Waiting because focused window still processing previous input."); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1041 | #endif |
| 1042 | injectionResult = handleTargetsNotReadyLocked(currentTime, entry, |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1043 | mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1044 | goto Unresponsive; |
| 1045 | } |
| 1046 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1047 | // Success! Output targets. |
| 1048 | injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1049 | addWindowTargetLocked(mFocusedWindowHandle, |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 1050 | InputTarget::FLAG_FOREGROUND | InputTarget::FLAG_DISPATCH_AS_IS, BitSet32(0), |
| 1051 | inputTargets); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1052 | |
| 1053 | // Done. |
| 1054 | Failed: |
| 1055 | Unresponsive: |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1056 | nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime); |
| 1057 | updateDispatchStatisticsLocked(currentTime, entry, |
| 1058 | injectionResult, timeSpentWaitingForApplication); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1059 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1060 | ALOGD("findFocusedWindow finished: injectionResult=%d, " |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1061 | "timeSpendWaitingForApplication=%0.1fms", |
| 1062 | injectionResult, timeSpentWaitingForApplication / 1000000.0); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1063 | #endif |
| 1064 | return injectionResult; |
| 1065 | } |
| 1066 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1067 | int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 1068 | const MotionEntry* entry, Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime, |
| 1069 | bool* outConflictingPointerActions) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1070 | enum InjectionPermission { |
| 1071 | INJECTION_PERMISSION_UNKNOWN, |
| 1072 | INJECTION_PERMISSION_GRANTED, |
| 1073 | INJECTION_PERMISSION_DENIED |
| 1074 | }; |
| 1075 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1076 | nsecs_t startTime = now(); |
| 1077 | |
| 1078 | // For security reasons, we defer updating the touch state until we are sure that |
| 1079 | // event injection will be allowed. |
| 1080 | // |
| 1081 | // FIXME In the original code, screenWasOff could never be set to true. |
| 1082 | // The reason is that the POLICY_FLAG_WOKE_HERE |
| 1083 | // and POLICY_FLAG_BRIGHT_HERE flags were set only when preprocessing raw |
| 1084 | // EV_KEY, EV_REL and EV_ABS events. As it happens, the touch event was |
| 1085 | // actually enqueued using the policyFlags that appeared in the final EV_SYN |
| 1086 | // events upon which no preprocessing took place. So policyFlags was always 0. |
| 1087 | // In the new native input dispatcher we're a bit more careful about event |
| 1088 | // preprocessing so the touches we receive can actually have non-zero policyFlags. |
| 1089 | // Unfortunately we obtain undesirable behavior. |
| 1090 | // |
| 1091 | // Here's what happens: |
| 1092 | // |
| 1093 | // When the device dims in anticipation of going to sleep, touches |
| 1094 | // in windows which have FLAG_TOUCHABLE_WHEN_WAKING cause |
| 1095 | // the device to brighten and reset the user activity timer. |
| 1096 | // Touches on other windows (such as the launcher window) |
| 1097 | // are dropped. Then after a moment, the device goes to sleep. Oops. |
| 1098 | // |
| 1099 | // Also notice how screenWasOff was being initialized using POLICY_FLAG_BRIGHT_HERE |
| 1100 | // instead of POLICY_FLAG_WOKE_HERE... |
| 1101 | // |
| 1102 | bool screenWasOff = false; // original policy: policyFlags & POLICY_FLAG_BRIGHT_HERE; |
| 1103 | |
| 1104 | int32_t action = entry->action; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1105 | int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1106 | |
| 1107 | // Update the touch state as needed based on the properties of the touch event. |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1108 | int32_t injectionResult = INPUT_EVENT_INJECTION_PENDING; |
| 1109 | InjectionPermission injectionPermission = INJECTION_PERMISSION_UNKNOWN; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1110 | sp<InputWindowHandle> newHoverWindowHandle; |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1111 | |
| 1112 | bool isSplit = mTouchState.split; |
Jeff Brown | 2717eff | 2011-06-30 23:53:07 -0700 | [diff] [blame] | 1113 | bool switchedDevice = mTouchState.deviceId >= 0 |
| 1114 | && (mTouchState.deviceId != entry->deviceId |
| 1115 | || mTouchState.source != entry->source); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1116 | bool isHoverAction = (maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE |
| 1117 | || maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER |
| 1118 | || maskedAction == AMOTION_EVENT_ACTION_HOVER_EXIT); |
| 1119 | bool newGesture = (maskedAction == AMOTION_EVENT_ACTION_DOWN |
| 1120 | || maskedAction == AMOTION_EVENT_ACTION_SCROLL |
| 1121 | || isHoverAction); |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1122 | bool wrongDevice = false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1123 | if (newGesture) { |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1124 | bool down = maskedAction == AMOTION_EVENT_ACTION_DOWN; |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1125 | if (switchedDevice && mTouchState.down && !down) { |
| 1126 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1127 | ALOGD("Dropping event because a pointer for a different device is already down."); |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1128 | #endif |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1129 | mTempTouchState.copyFrom(mTouchState); |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1130 | injectionResult = INPUT_EVENT_INJECTION_FAILED; |
| 1131 | switchedDevice = false; |
| 1132 | wrongDevice = true; |
| 1133 | goto Failed; |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1134 | } |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1135 | mTempTouchState.reset(); |
| 1136 | mTempTouchState.down = down; |
| 1137 | mTempTouchState.deviceId = entry->deviceId; |
| 1138 | mTempTouchState.source = entry->source; |
| 1139 | isSplit = false; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1140 | } else { |
| 1141 | mTempTouchState.copyFrom(mTouchState); |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1142 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1143 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1144 | if (newGesture || (isSplit && maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1145 | /* Case 1: New splittable pointer going down, or need target for hover or scroll. */ |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1146 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1147 | int32_t pointerIndex = getMotionEventActionPointerIndex(action); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1148 | int32_t x = int32_t(entry->pointerCoords[pointerIndex]. |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 1149 | getAxisValue(AMOTION_EVENT_AXIS_X)); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1150 | int32_t y = int32_t(entry->pointerCoords[pointerIndex]. |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 1151 | getAxisValue(AMOTION_EVENT_AXIS_Y)); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1152 | sp<InputWindowHandle> newTouchedWindowHandle; |
| 1153 | sp<InputWindowHandle> topErrorWindowHandle; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1154 | bool isTouchModal = false; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1155 | |
| 1156 | // Traverse windows from front to back to find touched window and outside targets. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1157 | size_t numWindows = mWindowHandles.size(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1158 | for (size_t i = 0; i < numWindows; i++) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1159 | sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1160 | const InputWindowInfo* windowInfo = windowHandle->getInfo(); |
| 1161 | int32_t flags = windowInfo->layoutParamsFlags; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1162 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1163 | if (flags & InputWindowInfo::FLAG_SYSTEM_ERROR) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1164 | if (topErrorWindowHandle == NULL) { |
| 1165 | topErrorWindowHandle = windowHandle; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1169 | if (windowInfo->visible) { |
| 1170 | if (! (flags & InputWindowInfo::FLAG_NOT_TOUCHABLE)) { |
| 1171 | isTouchModal = (flags & (InputWindowInfo::FLAG_NOT_FOCUSABLE |
| 1172 | | InputWindowInfo::FLAG_NOT_TOUCH_MODAL)) == 0; |
| 1173 | if (isTouchModal || windowInfo->touchableRegionContainsPoint(x, y)) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1174 | if (! screenWasOff |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1175 | || (flags & InputWindowInfo::FLAG_TOUCHABLE_WHEN_WAKING)) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1176 | newTouchedWindowHandle = windowHandle; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1177 | } |
| 1178 | break; // found touched window, exit window loop |
| 1179 | } |
| 1180 | } |
| 1181 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1182 | if (maskedAction == AMOTION_EVENT_ACTION_DOWN |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1183 | && (flags & InputWindowInfo::FLAG_WATCH_OUTSIDE_TOUCH)) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1184 | int32_t outsideTargetFlags = InputTarget::FLAG_DISPATCH_AS_OUTSIDE; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1185 | if (isWindowObscuredAtPointLocked(windowHandle, x, y)) { |
Jeff Brown | 19dfc83 | 2010-10-05 12:26:23 -0700 | [diff] [blame] | 1186 | outsideTargetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED; |
| 1187 | } |
| 1188 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1189 | mTempTouchState.addOrUpdateWindow( |
| 1190 | windowHandle, outsideTargetFlags, BitSet32(0)); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | // If there is an error window but it is not taking focus (typically because |
| 1196 | // it is invisible) then wait for it. Any other focused window may in |
| 1197 | // fact be in ANR state. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1198 | if (topErrorWindowHandle != NULL && newTouchedWindowHandle != topErrorWindowHandle) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1199 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1200 | ALOGD("Waiting because system error window is pending."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1201 | #endif |
| 1202 | injectionResult = handleTargetsNotReadyLocked(currentTime, entry, |
| 1203 | NULL, NULL, nextWakeupTime); |
| 1204 | injectionPermission = INJECTION_PERMISSION_UNKNOWN; |
| 1205 | goto Unresponsive; |
| 1206 | } |
| 1207 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1208 | // Figure out whether splitting will be allowed for this window. |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1209 | if (newTouchedWindowHandle != NULL |
| 1210 | && newTouchedWindowHandle->getInfo()->supportsSplitTouch()) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1211 | // New window supports splitting. |
| 1212 | isSplit = true; |
| 1213 | } else if (isSplit) { |
| 1214 | // New window does not support splitting but we have already split events. |
| 1215 | // Assign the pointer to the first foreground window we find. |
| 1216 | // (May be NULL which is why we put this code block before the next check.) |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1217 | newTouchedWindowHandle = mTempTouchState.getFirstForegroundWindowHandle(); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1218 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1219 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1220 | // If we did not find a touched window then fail. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1221 | if (newTouchedWindowHandle == NULL) { |
| 1222 | if (mFocusedApplicationHandle != NULL) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1223 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1224 | ALOGD("Waiting because there is no touched window but there is a " |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1225 | "focused application that may eventually add a new window: %s.", |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1226 | getApplicationWindowLabelLocked(mFocusedApplicationHandle, NULL).string()); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1227 | #endif |
| 1228 | injectionResult = handleTargetsNotReadyLocked(currentTime, entry, |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1229 | mFocusedApplicationHandle, NULL, nextWakeupTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1230 | goto Unresponsive; |
| 1231 | } |
| 1232 | |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 1233 | ALOGI("Dropping event because there is no touched window or focused application."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1234 | injectionResult = INPUT_EVENT_INJECTION_FAILED; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1235 | goto Failed; |
| 1236 | } |
| 1237 | |
Jeff Brown | 19dfc83 | 2010-10-05 12:26:23 -0700 | [diff] [blame] | 1238 | // Set target flags. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1239 | int32_t targetFlags = InputTarget::FLAG_FOREGROUND | InputTarget::FLAG_DISPATCH_AS_IS; |
Jeff Brown | 19dfc83 | 2010-10-05 12:26:23 -0700 | [diff] [blame] | 1240 | if (isSplit) { |
| 1241 | targetFlags |= InputTarget::FLAG_SPLIT; |
| 1242 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1243 | if (isWindowObscuredAtPointLocked(newTouchedWindowHandle, x, y)) { |
Jeff Brown | 19dfc83 | 2010-10-05 12:26:23 -0700 | [diff] [blame] | 1244 | targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED; |
| 1245 | } |
| 1246 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1247 | // Update hover state. |
| 1248 | if (isHoverAction) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1249 | newHoverWindowHandle = newTouchedWindowHandle; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1250 | } else if (maskedAction == AMOTION_EVENT_ACTION_SCROLL) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1251 | newHoverWindowHandle = mLastHoverWindowHandle; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1252 | } |
| 1253 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1254 | // Update the temporary touch state. |
| 1255 | BitSet32 pointerIds; |
| 1256 | if (isSplit) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1257 | uint32_t pointerId = entry->pointerProperties[pointerIndex].id; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1258 | pointerIds.markBit(pointerId); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1259 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1260 | mTempTouchState.addOrUpdateWindow(newTouchedWindowHandle, targetFlags, pointerIds); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1261 | } else { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1262 | /* Case 2: Pointer move, up, cancel or non-splittable pointer down. */ |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1263 | |
| 1264 | // If the pointer is not currently down, then ignore the event. |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1265 | if (! mTempTouchState.down) { |
Jeff Brown | a2cc28d | 2011-03-25 11:58:46 -0700 | [diff] [blame] | 1266 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1267 | ALOGD("Dropping event because the pointer is not down or we previously " |
Jeff Brown | 76860e3 | 2010-10-25 17:37:46 -0700 | [diff] [blame] | 1268 | "dropped the pointer down event."); |
| 1269 | #endif |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1270 | injectionResult = INPUT_EVENT_INJECTION_FAILED; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1271 | goto Failed; |
| 1272 | } |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1273 | |
| 1274 | // Check whether touches should slip outside of the current foreground window. |
| 1275 | if (maskedAction == AMOTION_EVENT_ACTION_MOVE |
| 1276 | && entry->pointerCount == 1 |
| 1277 | && mTempTouchState.isSlippery()) { |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1278 | int32_t x = int32_t(entry->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X)); |
| 1279 | int32_t y = int32_t(entry->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y)); |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1280 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1281 | sp<InputWindowHandle> oldTouchedWindowHandle = |
| 1282 | mTempTouchState.getFirstForegroundWindowHandle(); |
| 1283 | sp<InputWindowHandle> newTouchedWindowHandle = findTouchedWindowAtLocked(x, y); |
| 1284 | if (oldTouchedWindowHandle != newTouchedWindowHandle |
| 1285 | && newTouchedWindowHandle != NULL) { |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1286 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1287 | ALOGD("Touch is slipping out of window %s into window %s.", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1288 | oldTouchedWindowHandle->getName().string(), |
| 1289 | newTouchedWindowHandle->getName().string()); |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1290 | #endif |
| 1291 | // Make a slippery exit from the old window. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1292 | mTempTouchState.addOrUpdateWindow(oldTouchedWindowHandle, |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1293 | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT, BitSet32(0)); |
| 1294 | |
| 1295 | // Make a slippery entrance into the new window. |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1296 | if (newTouchedWindowHandle->getInfo()->supportsSplitTouch()) { |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1297 | isSplit = true; |
| 1298 | } |
| 1299 | |
| 1300 | int32_t targetFlags = InputTarget::FLAG_FOREGROUND |
| 1301 | | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER; |
| 1302 | if (isSplit) { |
| 1303 | targetFlags |= InputTarget::FLAG_SPLIT; |
| 1304 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1305 | if (isWindowObscuredAtPointLocked(newTouchedWindowHandle, x, y)) { |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1306 | targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED; |
| 1307 | } |
| 1308 | |
| 1309 | BitSet32 pointerIds; |
| 1310 | if (isSplit) { |
| 1311 | pointerIds.markBit(entry->pointerProperties[0].id); |
| 1312 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1313 | mTempTouchState.addOrUpdateWindow(newTouchedWindowHandle, targetFlags, pointerIds); |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1314 | } |
| 1315 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1316 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1317 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1318 | if (newHoverWindowHandle != mLastHoverWindowHandle) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1319 | // Let the previous window know that the hover sequence is over. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1320 | if (mLastHoverWindowHandle != NULL) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1321 | #if DEBUG_HOVER |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1322 | ALOGD("Sending hover exit event to window %s.", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1323 | mLastHoverWindowHandle->getName().string()); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1324 | #endif |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1325 | mTempTouchState.addOrUpdateWindow(mLastHoverWindowHandle, |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1326 | InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT, BitSet32(0)); |
| 1327 | } |
| 1328 | |
| 1329 | // Let the new window know that the hover sequence is starting. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1330 | if (newHoverWindowHandle != NULL) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1331 | #if DEBUG_HOVER |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1332 | ALOGD("Sending hover enter event to window %s.", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1333 | newHoverWindowHandle->getName().string()); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1334 | #endif |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1335 | mTempTouchState.addOrUpdateWindow(newHoverWindowHandle, |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1336 | InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER, BitSet32(0)); |
| 1337 | } |
| 1338 | } |
| 1339 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1340 | // Check permission to inject into all touched foreground windows and ensure there |
| 1341 | // is at least one touched foreground window. |
| 1342 | { |
| 1343 | bool haveForegroundWindow = false; |
| 1344 | for (size_t i = 0; i < mTempTouchState.windows.size(); i++) { |
| 1345 | const TouchedWindow& touchedWindow = mTempTouchState.windows[i]; |
| 1346 | if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) { |
| 1347 | haveForegroundWindow = true; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1348 | if (! checkInjectionPermission(touchedWindow.windowHandle, |
| 1349 | entry->injectionState)) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1350 | injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED; |
| 1351 | injectionPermission = INJECTION_PERMISSION_DENIED; |
| 1352 | goto Failed; |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | if (! haveForegroundWindow) { |
Jeff Brown | a2cc28d | 2011-03-25 11:58:46 -0700 | [diff] [blame] | 1357 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1358 | ALOGD("Dropping event because there is no touched foreground window to receive it."); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1359 | #endif |
| 1360 | injectionResult = INPUT_EVENT_INJECTION_FAILED; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1361 | goto Failed; |
| 1362 | } |
| 1363 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1364 | // Permission granted to injection into all touched foreground windows. |
| 1365 | injectionPermission = INJECTION_PERMISSION_GRANTED; |
| 1366 | } |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1367 | |
Kenny Root | 7a9db18 | 2011-06-02 15:16:05 -0700 | [diff] [blame] | 1368 | // Check whether windows listening for outside touches are owned by the same UID. If it is |
| 1369 | // set the policy flag that we will not reveal coordinate information to this window. |
| 1370 | if (maskedAction == AMOTION_EVENT_ACTION_DOWN) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1371 | sp<InputWindowHandle> foregroundWindowHandle = |
| 1372 | mTempTouchState.getFirstForegroundWindowHandle(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1373 | const int32_t foregroundWindowUid = foregroundWindowHandle->getInfo()->ownerUid; |
Kenny Root | 7a9db18 | 2011-06-02 15:16:05 -0700 | [diff] [blame] | 1374 | for (size_t i = 0; i < mTempTouchState.windows.size(); i++) { |
| 1375 | const TouchedWindow& touchedWindow = mTempTouchState.windows[i]; |
| 1376 | if (touchedWindow.targetFlags & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1377 | sp<InputWindowHandle> inputWindowHandle = touchedWindow.windowHandle; |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1378 | if (inputWindowHandle->getInfo()->ownerUid != foregroundWindowUid) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1379 | mTempTouchState.addOrUpdateWindow(inputWindowHandle, |
Kenny Root | 7a9db18 | 2011-06-02 15:16:05 -0700 | [diff] [blame] | 1380 | InputTarget::FLAG_ZERO_COORDS, BitSet32(0)); |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1386 | // Ensure all touched foreground windows are ready for new input. |
| 1387 | for (size_t i = 0; i < mTempTouchState.windows.size(); i++) { |
| 1388 | const TouchedWindow& touchedWindow = mTempTouchState.windows[i]; |
| 1389 | if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) { |
| 1390 | // If the touched window is paused then keep waiting. |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1391 | if (touchedWindow.windowHandle->getInfo()->paused) { |
Jeff Brown | a2cc28d | 2011-03-25 11:58:46 -0700 | [diff] [blame] | 1392 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1393 | ALOGD("Waiting because touched window is paused."); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1394 | #endif |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1395 | injectionResult = handleTargetsNotReadyLocked(currentTime, entry, |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1396 | NULL, touchedWindow.windowHandle, nextWakeupTime); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1397 | goto Unresponsive; |
| 1398 | } |
| 1399 | |
| 1400 | // If the touched window is still working on previous events then keep waiting. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1401 | if (! isWindowFinishedWithPreviousInputLocked(touchedWindow.windowHandle)) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1402 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1403 | ALOGD("Waiting because touched window still processing previous input."); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1404 | #endif |
| 1405 | injectionResult = handleTargetsNotReadyLocked(currentTime, entry, |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1406 | NULL, touchedWindow.windowHandle, nextWakeupTime); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1407 | goto Unresponsive; |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | // If this is the first pointer going down and the touched window has a wallpaper |
| 1413 | // then also add the touched wallpaper windows so they are locked in for the duration |
| 1414 | // of the touch gesture. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1415 | // We do not collect wallpapers during HOVER_MOVE or SCROLL because the wallpaper |
| 1416 | // engine only supports touch events. We would need to add a mechanism similar |
| 1417 | // to View.onGenericMotionEvent to enable wallpapers to handle these events. |
| 1418 | if (maskedAction == AMOTION_EVENT_ACTION_DOWN) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1419 | sp<InputWindowHandle> foregroundWindowHandle = |
| 1420 | mTempTouchState.getFirstForegroundWindowHandle(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1421 | if (foregroundWindowHandle->getInfo()->hasWallpaper) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1422 | for (size_t i = 0; i < mWindowHandles.size(); i++) { |
| 1423 | sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1424 | if (windowHandle->getInfo()->layoutParamsType |
| 1425 | == InputWindowInfo::TYPE_WALLPAPER) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1426 | mTempTouchState.addOrUpdateWindow(windowHandle, |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1427 | InputTarget::FLAG_WINDOW_IS_OBSCURED |
| 1428 | | InputTarget::FLAG_DISPATCH_AS_IS, |
| 1429 | BitSet32(0)); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1435 | // Success! Output targets. |
| 1436 | injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1437 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1438 | for (size_t i = 0; i < mTempTouchState.windows.size(); i++) { |
| 1439 | const TouchedWindow& touchedWindow = mTempTouchState.windows.itemAt(i); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1440 | addWindowTargetLocked(touchedWindow.windowHandle, touchedWindow.targetFlags, |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 1441 | touchedWindow.pointerIds, inputTargets); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1444 | // Drop the outside or hover touch windows since we will not care about them |
| 1445 | // in the next iteration. |
| 1446 | mTempTouchState.filterNonAsIsTouchWindows(); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1447 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1448 | Failed: |
| 1449 | // Check injection permission once and for all. |
| 1450 | if (injectionPermission == INJECTION_PERMISSION_UNKNOWN) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1451 | if (checkInjectionPermission(NULL, entry->injectionState)) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1452 | injectionPermission = INJECTION_PERMISSION_GRANTED; |
| 1453 | } else { |
| 1454 | injectionPermission = INJECTION_PERMISSION_DENIED; |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | // Update final pieces of touch state if the injector had permission. |
| 1459 | if (injectionPermission == INJECTION_PERMISSION_GRANTED) { |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 1460 | if (!wrongDevice) { |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1461 | if (switchedDevice) { |
| 1462 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1463 | ALOGD("Conflicting pointer actions: Switched to a different device."); |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1464 | #endif |
| 1465 | *outConflictingPointerActions = true; |
| 1466 | } |
| 1467 | |
| 1468 | if (isHoverAction) { |
| 1469 | // Started hovering, therefore no longer down. |
| 1470 | if (mTouchState.down) { |
| 1471 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1472 | ALOGD("Conflicting pointer actions: Hover received while pointer was down."); |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1473 | #endif |
| 1474 | *outConflictingPointerActions = true; |
| 1475 | } |
| 1476 | mTouchState.reset(); |
| 1477 | if (maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER |
| 1478 | || maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE) { |
| 1479 | mTouchState.deviceId = entry->deviceId; |
| 1480 | mTouchState.source = entry->source; |
| 1481 | } |
| 1482 | } else if (maskedAction == AMOTION_EVENT_ACTION_UP |
| 1483 | || maskedAction == AMOTION_EVENT_ACTION_CANCEL) { |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 1484 | // All pointers up or canceled. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1485 | mTouchState.reset(); |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 1486 | } else if (maskedAction == AMOTION_EVENT_ACTION_DOWN) { |
| 1487 | // First pointer went down. |
| 1488 | if (mTouchState.down) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1489 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1490 | ALOGD("Conflicting pointer actions: Down received while already down."); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1491 | #endif |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1492 | *outConflictingPointerActions = true; |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 1493 | } |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1494 | mTouchState.copyFrom(mTempTouchState); |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 1495 | } else if (maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) { |
| 1496 | // One pointer went up. |
| 1497 | if (isSplit) { |
| 1498 | int32_t pointerIndex = getMotionEventActionPointerIndex(action); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1499 | uint32_t pointerId = entry->pointerProperties[pointerIndex].id; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1500 | |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 1501 | for (size_t i = 0; i < mTempTouchState.windows.size(); ) { |
| 1502 | TouchedWindow& touchedWindow = mTempTouchState.windows.editItemAt(i); |
| 1503 | if (touchedWindow.targetFlags & InputTarget::FLAG_SPLIT) { |
| 1504 | touchedWindow.pointerIds.clearBit(pointerId); |
| 1505 | if (touchedWindow.pointerIds.isEmpty()) { |
| 1506 | mTempTouchState.windows.removeAt(i); |
| 1507 | continue; |
| 1508 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1509 | } |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 1510 | i += 1; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1511 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1512 | } |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1513 | mTouchState.copyFrom(mTempTouchState); |
| 1514 | } else if (maskedAction == AMOTION_EVENT_ACTION_SCROLL) { |
| 1515 | // Discard temporary touch state since it was only valid for this action. |
| 1516 | } else { |
| 1517 | // Save changes to touch state as-is for all other actions. |
| 1518 | mTouchState.copyFrom(mTempTouchState); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1519 | } |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1520 | |
| 1521 | // Update hover state. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1522 | mLastHoverWindowHandle = newHoverWindowHandle; |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 1523 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1524 | } else { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1525 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1526 | ALOGD("Not updating touch focus because injection was denied."); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1527 | #endif |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | Unresponsive: |
Jeff Brown | 120a459 | 2010-10-27 18:43:51 -0700 | [diff] [blame] | 1531 | // Reset temporary touch state to ensure we release unnecessary references to input channels. |
| 1532 | mTempTouchState.reset(); |
| 1533 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1534 | nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime); |
| 1535 | updateDispatchStatisticsLocked(currentTime, entry, |
| 1536 | injectionResult, timeSpentWaitingForApplication); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1537 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1538 | ALOGD("findTouchedWindow finished: injectionResult=%d, injectionPermission=%d, " |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1539 | "timeSpentWaitingForApplication=%0.1fms", |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1540 | injectionResult, injectionPermission, timeSpentWaitingForApplication / 1000000.0); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1541 | #endif |
| 1542 | return injectionResult; |
| 1543 | } |
| 1544 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1545 | void InputDispatcher::addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle, |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 1546 | int32_t targetFlags, BitSet32 pointerIds, Vector<InputTarget>& inputTargets) { |
| 1547 | inputTargets.push(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1548 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1549 | const InputWindowInfo* windowInfo = windowHandle->getInfo(); |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 1550 | InputTarget& target = inputTargets.editTop(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1551 | target.inputChannel = windowInfo->inputChannel; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1552 | target.flags = targetFlags; |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1553 | target.xOffset = - windowInfo->frameLeft; |
| 1554 | target.yOffset = - windowInfo->frameTop; |
| 1555 | target.scaleFactor = windowInfo->scaleFactor; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1556 | target.pointerIds = pointerIds; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 1559 | void InputDispatcher::addMonitoringTargetsLocked(Vector<InputTarget>& inputTargets) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1560 | for (size_t i = 0; i < mMonitoringChannels.size(); i++) { |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 1561 | inputTargets.push(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1562 | |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 1563 | InputTarget& target = inputTargets.editTop(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1564 | target.inputChannel = mMonitoringChannels[i]; |
Jeff Brown | b6110c2 | 2011-04-01 16:15:13 -0700 | [diff] [blame] | 1565 | target.flags = InputTarget::FLAG_DISPATCH_AS_IS; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1566 | target.xOffset = 0; |
| 1567 | target.yOffset = 0; |
Jeff Brown | b6110c2 | 2011-04-01 16:15:13 -0700 | [diff] [blame] | 1568 | target.pointerIds.clear(); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1569 | target.scaleFactor = 1.0f; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1573 | bool InputDispatcher::checkInjectionPermission(const sp<InputWindowHandle>& windowHandle, |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1574 | const InjectionState* injectionState) { |
| 1575 | if (injectionState |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1576 | && (windowHandle == NULL |
| 1577 | || windowHandle->getInfo()->ownerUid != injectionState->injectorUid) |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1578 | && !hasInjectionPermission(injectionState->injectorPid, injectionState->injectorUid)) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1579 | if (windowHandle != NULL) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1580 | ALOGW("Permission denied: injecting event from pid %d uid %d to window %s " |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1581 | "owned by uid %d", |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1582 | injectionState->injectorPid, injectionState->injectorUid, |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1583 | windowHandle->getName().string(), |
| 1584 | windowHandle->getInfo()->ownerUid); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1585 | } else { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1586 | ALOGW("Permission denied: injecting event from pid %d uid %d", |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1587 | injectionState->injectorPid, injectionState->injectorUid); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1588 | } |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1589 | return false; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1590 | } |
| 1591 | return true; |
| 1592 | } |
| 1593 | |
Jeff Brown | 19dfc83 | 2010-10-05 12:26:23 -0700 | [diff] [blame] | 1594 | bool InputDispatcher::isWindowObscuredAtPointLocked( |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1595 | const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const { |
| 1596 | size_t numWindows = mWindowHandles.size(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1597 | for (size_t i = 0; i < numWindows; i++) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1598 | sp<InputWindowHandle> otherHandle = mWindowHandles.itemAt(i); |
| 1599 | if (otherHandle == windowHandle) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1600 | break; |
| 1601 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1602 | |
| 1603 | const InputWindowInfo* otherInfo = otherHandle->getInfo(); |
| 1604 | if (otherInfo->visible && ! otherInfo->isTrustedOverlay() |
| 1605 | && otherInfo->frameContainsPoint(x, y)) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1606 | return true; |
| 1607 | } |
| 1608 | } |
| 1609 | return false; |
| 1610 | } |
| 1611 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1612 | bool InputDispatcher::isWindowFinishedWithPreviousInputLocked( |
| 1613 | const sp<InputWindowHandle>& windowHandle) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1614 | ssize_t connectionIndex = getConnectionIndexLocked(windowHandle->getInputChannel()); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1615 | if (connectionIndex >= 0) { |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 1616 | sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1617 | return connection->outboundQueue.isEmpty(); |
| 1618 | } else { |
| 1619 | return true; |
| 1620 | } |
| 1621 | } |
| 1622 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1623 | String8 InputDispatcher::getApplicationWindowLabelLocked( |
| 1624 | const sp<InputApplicationHandle>& applicationHandle, |
| 1625 | const sp<InputWindowHandle>& windowHandle) { |
| 1626 | if (applicationHandle != NULL) { |
| 1627 | if (windowHandle != NULL) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1628 | String8 label(applicationHandle->getName()); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1629 | label.append(" - "); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1630 | label.append(windowHandle->getName()); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1631 | return label; |
| 1632 | } else { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1633 | return applicationHandle->getName(); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1634 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1635 | } else if (windowHandle != NULL) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1636 | return windowHandle->getName(); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1637 | } else { |
| 1638 | return String8("<unknown application or window>"); |
| 1639 | } |
| 1640 | } |
| 1641 | |
Jeff Brown | e2fe69e | 2010-10-18 13:21:23 -0700 | [diff] [blame] | 1642 | void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 1643 | int32_t eventType = POWER_MANAGER_OTHER_EVENT; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1644 | switch (eventEntry->type) { |
| 1645 | case EventEntry::TYPE_MOTION: { |
Jeff Brown | e2fe69e | 2010-10-18 13:21:23 -0700 | [diff] [blame] | 1646 | const MotionEntry* motionEntry = static_cast<const MotionEntry*>(eventEntry); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1647 | if (motionEntry->action == AMOTION_EVENT_ACTION_CANCEL) { |
| 1648 | return; |
| 1649 | } |
| 1650 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 1651 | if (MotionEvent::isTouchEvent(motionEntry->source, motionEntry->action)) { |
Joe Onorato | 1a542c7 | 2010-11-08 09:48:20 -0800 | [diff] [blame] | 1652 | eventType = POWER_MANAGER_TOUCH_EVENT; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1653 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1654 | break; |
| 1655 | } |
| 1656 | case EventEntry::TYPE_KEY: { |
| 1657 | const KeyEntry* keyEntry = static_cast<const KeyEntry*>(eventEntry); |
| 1658 | if (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) { |
| 1659 | return; |
| 1660 | } |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 1661 | eventType = POWER_MANAGER_BUTTON_EVENT; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1662 | break; |
| 1663 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1664 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1665 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1666 | CommandEntry* commandEntry = postCommandLocked( |
| 1667 | & InputDispatcher::doPokeUserActivityLockedInterruptible); |
Jeff Brown | e2fe69e | 2010-10-18 13:21:23 -0700 | [diff] [blame] | 1668 | commandEntry->eventTime = eventEntry->eventTime; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1669 | commandEntry->userActivityEventType = eventType; |
| 1670 | } |
| 1671 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1672 | void InputDispatcher::prepareDispatchCycleLocked(nsecs_t currentTime, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1673 | const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1674 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1675 | ALOGD("channel '%s' ~ prepareDispatchCycle - flags=0x%08x, " |
Jeff Brown | 9cc695c | 2011-08-23 18:35:04 -0700 | [diff] [blame] | 1676 | "xOffset=%f, yOffset=%f, scaleFactor=%f, " |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1677 | "pointerIds=0x%x", |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1678 | connection->getInputChannelName(), inputTarget->flags, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1679 | inputTarget->xOffset, inputTarget->yOffset, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1680 | inputTarget->scaleFactor, inputTarget->pointerIds.value); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1681 | #endif |
| 1682 | |
| 1683 | // Skip this event if the connection status is not normal. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1684 | // We don't want to enqueue additional outbound events if the connection is broken. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1685 | if (connection->status != Connection::STATUS_NORMAL) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1686 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1687 | ALOGD("channel '%s' ~ Dropping event because the channel status is %s", |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1688 | connection->getInputChannelName(), connection->getStatusLabel()); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1689 | #endif |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1690 | return; |
| 1691 | } |
| 1692 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1693 | // Split a motion event if needed. |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1694 | if (inputTarget->flags & InputTarget::FLAG_SPLIT) { |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 1695 | ALOG_ASSERT(eventEntry->type == EventEntry::TYPE_MOTION); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1696 | |
| 1697 | MotionEntry* originalMotionEntry = static_cast<MotionEntry*>(eventEntry); |
| 1698 | if (inputTarget->pointerIds.count() != originalMotionEntry->pointerCount) { |
| 1699 | MotionEntry* splitMotionEntry = splitMotionEvent( |
| 1700 | originalMotionEntry, inputTarget->pointerIds); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 1701 | if (!splitMotionEntry) { |
| 1702 | return; // split event was dropped |
| 1703 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1704 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1705 | ALOGD("channel '%s' ~ Split motion event.", |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1706 | connection->getInputChannelName()); |
| 1707 | logOutboundMotionDetailsLocked(" ", splitMotionEntry); |
| 1708 | #endif |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 1709 | enqueueDispatchEntriesLocked(currentTime, connection, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1710 | splitMotionEntry, inputTarget); |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 1711 | splitMotionEntry->release(); |
| 1712 | return; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1713 | } |
| 1714 | } |
| 1715 | |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 1716 | // Not splitting. Enqueue dispatch entries for the event as is. |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1717 | enqueueDispatchEntriesLocked(currentTime, connection, eventEntry, inputTarget); |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1721 | const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1722 | bool wasEmpty = connection->outboundQueue.isEmpty(); |
| 1723 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1724 | // Enqueue dispatch entries for the requested modes. |
| 1725 | enqueueDispatchEntryLocked(connection, eventEntry, inputTarget, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1726 | InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1727 | enqueueDispatchEntryLocked(connection, eventEntry, inputTarget, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1728 | InputTarget::FLAG_DISPATCH_AS_OUTSIDE); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1729 | enqueueDispatchEntryLocked(connection, eventEntry, inputTarget, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1730 | InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1731 | enqueueDispatchEntryLocked(connection, eventEntry, inputTarget, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1732 | InputTarget::FLAG_DISPATCH_AS_IS); |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1733 | enqueueDispatchEntryLocked(connection, eventEntry, inputTarget, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1734 | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT); |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 1735 | enqueueDispatchEntryLocked(connection, eventEntry, inputTarget, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1736 | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1737 | |
| 1738 | // If the outbound queue was previously empty, start the dispatch cycle going. |
Jeff Brown | b6110c2 | 2011-04-01 16:15:13 -0700 | [diff] [blame] | 1739 | if (wasEmpty && !connection->outboundQueue.isEmpty()) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1740 | activateConnectionLocked(connection.get()); |
| 1741 | startDispatchCycleLocked(currentTime, connection); |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | void InputDispatcher::enqueueDispatchEntryLocked( |
| 1746 | const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1747 | int32_t dispatchMode) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1748 | int32_t inputTargetFlags = inputTarget->flags; |
| 1749 | if (!(inputTargetFlags & dispatchMode)) { |
| 1750 | return; |
| 1751 | } |
| 1752 | inputTargetFlags = (inputTargetFlags & ~InputTarget::FLAG_DISPATCH_MASK) | dispatchMode; |
| 1753 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1754 | // This is a new event. |
| 1755 | // Enqueue a new dispatch entry onto the outbound queue for this connection. |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 1756 | DispatchEntry* dispatchEntry = new DispatchEntry(eventEntry, // increments ref |
Dianne Hackborn | aa9d84c | 2011-05-09 19:00:59 -0700 | [diff] [blame] | 1757 | inputTargetFlags, inputTarget->xOffset, inputTarget->yOffset, |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1758 | inputTarget->scaleFactor); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1759 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1760 | // Apply target flags and update the connection's input state. |
| 1761 | switch (eventEntry->type) { |
| 1762 | case EventEntry::TYPE_KEY: { |
| 1763 | KeyEntry* keyEntry = static_cast<KeyEntry*>(eventEntry); |
| 1764 | dispatchEntry->resolvedAction = keyEntry->action; |
| 1765 | dispatchEntry->resolvedFlags = keyEntry->flags; |
| 1766 | |
| 1767 | if (!connection->inputState.trackKey(keyEntry, |
| 1768 | dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags)) { |
| 1769 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1770 | ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent key event", |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1771 | connection->getInputChannelName()); |
| 1772 | #endif |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 1773 | delete dispatchEntry; |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1774 | return; // skip the inconsistent event |
| 1775 | } |
| 1776 | break; |
| 1777 | } |
| 1778 | |
| 1779 | case EventEntry::TYPE_MOTION: { |
| 1780 | MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry); |
| 1781 | if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) { |
| 1782 | dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_OUTSIDE; |
| 1783 | } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT) { |
| 1784 | dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_EXIT; |
| 1785 | } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER) { |
| 1786 | dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_ENTER; |
| 1787 | } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) { |
| 1788 | dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_CANCEL; |
| 1789 | } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER) { |
| 1790 | dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_DOWN; |
| 1791 | } else { |
| 1792 | dispatchEntry->resolvedAction = motionEntry->action; |
| 1793 | } |
| 1794 | if (dispatchEntry->resolvedAction == AMOTION_EVENT_ACTION_HOVER_MOVE |
| 1795 | && !connection->inputState.isHovering( |
| 1796 | motionEntry->deviceId, motionEntry->source)) { |
| 1797 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1798 | ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: filling in missing hover enter event", |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1799 | connection->getInputChannelName()); |
| 1800 | #endif |
| 1801 | dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_ENTER; |
| 1802 | } |
| 1803 | |
| 1804 | dispatchEntry->resolvedFlags = motionEntry->flags; |
| 1805 | if (dispatchEntry->targetFlags & InputTarget::FLAG_WINDOW_IS_OBSCURED) { |
| 1806 | dispatchEntry->resolvedFlags |= AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; |
| 1807 | } |
| 1808 | |
| 1809 | if (!connection->inputState.trackMotion(motionEntry, |
| 1810 | dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags)) { |
| 1811 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1812 | ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent motion event", |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1813 | connection->getInputChannelName()); |
| 1814 | #endif |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 1815 | delete dispatchEntry; |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1816 | return; // skip the inconsistent event |
| 1817 | } |
| 1818 | break; |
| 1819 | } |
| 1820 | } |
| 1821 | |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 1822 | // Remember that we are waiting for this dispatch to complete. |
| 1823 | if (dispatchEntry->hasForegroundTarget()) { |
| 1824 | incrementPendingForegroundDispatchesLocked(eventEntry); |
| 1825 | } |
| 1826 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1827 | // Enqueue the dispatch entry. |
| 1828 | connection->outboundQueue.enqueueAtTail(dispatchEntry); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1831 | void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime, |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1832 | const sp<Connection>& connection) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1833 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1834 | ALOGD("channel '%s' ~ startDispatchCycle", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1835 | connection->getInputChannelName()); |
| 1836 | #endif |
| 1837 | |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 1838 | ALOG_ASSERT(connection->status == Connection::STATUS_NORMAL); |
| 1839 | ALOG_ASSERT(! connection->outboundQueue.isEmpty()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1840 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 1841 | DispatchEntry* dispatchEntry = connection->outboundQueue.head; |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 1842 | ALOG_ASSERT(! dispatchEntry->inProgress); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1843 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1844 | // Mark the dispatch entry as in progress. |
| 1845 | dispatchEntry->inProgress = true; |
| 1846 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1847 | // Publish the event. |
| 1848 | status_t status; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1849 | EventEntry* eventEntry = dispatchEntry->eventEntry; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1850 | switch (eventEntry->type) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1851 | case EventEntry::TYPE_KEY: { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1852 | KeyEntry* keyEntry = static_cast<KeyEntry*>(eventEntry); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1853 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1854 | // Publish the key event. |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1855 | status = connection->inputPublisher.publishKeyEvent( |
| 1856 | keyEntry->deviceId, keyEntry->source, |
| 1857 | dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags, |
| 1858 | keyEntry->keyCode, keyEntry->scanCode, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1859 | keyEntry->metaState, keyEntry->repeatCount, keyEntry->downTime, |
| 1860 | keyEntry->eventTime); |
| 1861 | |
| 1862 | if (status) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1863 | ALOGE("channel '%s' ~ Could not publish key event, " |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1864 | "status=%d", connection->getInputChannelName(), status); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1865 | abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1866 | return; |
| 1867 | } |
| 1868 | break; |
| 1869 | } |
| 1870 | |
| 1871 | case EventEntry::TYPE_MOTION: { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1872 | MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1873 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1874 | PointerCoords scaledCoords[MAX_POINTERS]; |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1875 | const PointerCoords* usingCoords = motionEntry->pointerCoords; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1876 | |
Jeff Brown | d361659 | 2010-07-16 17:21:06 -0700 | [diff] [blame] | 1877 | // Set the X and Y offset depending on the input source. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1878 | float xOffset, yOffset, scaleFactor; |
Kenny Root | 7a9db18 | 2011-06-02 15:16:05 -0700 | [diff] [blame] | 1879 | if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER |
| 1880 | && !(dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS)) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1881 | scaleFactor = dispatchEntry->scaleFactor; |
| 1882 | xOffset = dispatchEntry->xOffset * scaleFactor; |
| 1883 | yOffset = dispatchEntry->yOffset * scaleFactor; |
| 1884 | if (scaleFactor != 1.0f) { |
| 1885 | for (size_t i = 0; i < motionEntry->pointerCount; i++) { |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1886 | scaledCoords[i] = motionEntry->pointerCoords[i]; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1887 | scaledCoords[i].scale(scaleFactor); |
| 1888 | } |
| 1889 | usingCoords = scaledCoords; |
| 1890 | } |
Jeff Brown | d361659 | 2010-07-16 17:21:06 -0700 | [diff] [blame] | 1891 | } else { |
| 1892 | xOffset = 0.0f; |
| 1893 | yOffset = 0.0f; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1894 | scaleFactor = 1.0f; |
Kenny Root | 7a9db18 | 2011-06-02 15:16:05 -0700 | [diff] [blame] | 1895 | |
| 1896 | // We don't want the dispatch target to know. |
| 1897 | if (dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS) { |
| 1898 | for (size_t i = 0; i < motionEntry->pointerCount; i++) { |
| 1899 | scaledCoords[i].clear(); |
| 1900 | } |
| 1901 | usingCoords = scaledCoords; |
| 1902 | } |
Jeff Brown | d361659 | 2010-07-16 17:21:06 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1905 | // Publish the motion event. |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 1906 | status = connection->inputPublisher.publishMotionEvent( |
| 1907 | motionEntry->deviceId, motionEntry->source, |
| 1908 | dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags, |
| 1909 | motionEntry->edgeFlags, motionEntry->metaState, motionEntry->buttonState, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1910 | xOffset, yOffset, |
| 1911 | motionEntry->xPrecision, motionEntry->yPrecision, |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 1912 | motionEntry->downTime, motionEntry->eventTime, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1913 | motionEntry->pointerCount, motionEntry->pointerProperties, |
| 1914 | usingCoords); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1915 | |
| 1916 | if (status) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1917 | ALOGE("channel '%s' ~ Could not publish motion event, " |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1918 | "status=%d", connection->getInputChannelName(), status); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1919 | abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1920 | return; |
| 1921 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1922 | break; |
| 1923 | } |
| 1924 | |
| 1925 | default: { |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 1926 | ALOG_ASSERT(false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1930 | // Record information about the newly started dispatch cycle. |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1931 | connection->lastEventTime = eventEntry->eventTime; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1932 | connection->lastDispatchTime = currentTime; |
| 1933 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1934 | // Notify other system components. |
| 1935 | onDispatchCycleStartedLocked(currentTime, connection); |
| 1936 | } |
| 1937 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1938 | void InputDispatcher::finishDispatchCycleLocked(nsecs_t currentTime, |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1939 | const sp<Connection>& connection, bool handled) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1940 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1941 | ALOGD("channel '%s' ~ finishDispatchCycle - %01.1fms since event, " |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1942 | "%01.1fms since dispatch, handled=%s", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1943 | connection->getInputChannelName(), |
| 1944 | connection->getEventLatencyMillis(currentTime), |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1945 | connection->getDispatchLatencyMillis(currentTime), |
| 1946 | toString(handled)); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1947 | #endif |
| 1948 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1949 | if (connection->status == Connection::STATUS_BROKEN |
| 1950 | || connection->status == Connection::STATUS_ZOMBIE) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1951 | return; |
| 1952 | } |
| 1953 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1954 | // Notify other system components and prepare to start the next dispatch cycle. |
| 1955 | onDispatchCycleFinishedLocked(currentTime, connection, handled); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void InputDispatcher::startNextDispatchCycleLocked(nsecs_t currentTime, |
| 1959 | const sp<Connection>& connection) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1960 | // Start the next dispatch cycle for this connection. |
| 1961 | while (! connection->outboundQueue.isEmpty()) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 1962 | DispatchEntry* dispatchEntry = connection->outboundQueue.head; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1963 | if (dispatchEntry->inProgress) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1964 | // Finished. |
| 1965 | connection->outboundQueue.dequeueAtHead(); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1966 | if (dispatchEntry->hasForegroundTarget()) { |
| 1967 | decrementPendingForegroundDispatchesLocked(dispatchEntry->eventEntry); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1968 | } |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 1969 | delete dispatchEntry; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1970 | } else { |
| 1971 | // If the head is not in progress, then we must have already dequeued the in |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1972 | // progress event, which means we actually aborted it. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1973 | // So just start the next event for this connection. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1974 | startDispatchCycleLocked(currentTime, connection); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1975 | return; |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | // Outbound queue is empty, deactivate the connection. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1980 | deactivateConnectionLocked(connection.get()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1983 | void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime, |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1984 | const sp<Connection>& connection, bool notify) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1985 | #if DEBUG_DISPATCH_CYCLE |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1986 | ALOGD("channel '%s' ~ abortBrokenDispatchCycle - notify=%s", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1987 | connection->getInputChannelName(), toString(notify)); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1988 | #endif |
| 1989 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1990 | // Clear the outbound queue. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1991 | drainOutboundQueueLocked(connection.get()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1992 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1993 | // The connection appears to be unrecoverably broken. |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1994 | // Ignore already broken or zombie connections. |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 1995 | if (connection->status == Connection::STATUS_NORMAL) { |
| 1996 | connection->status = Connection::STATUS_BROKEN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1997 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1998 | if (notify) { |
| 1999 | // Notify other system components. |
| 2000 | onDispatchCycleBrokenLocked(currentTime, connection); |
| 2001 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2002 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 2005 | void InputDispatcher::drainOutboundQueueLocked(Connection* connection) { |
| 2006 | while (! connection->outboundQueue.isEmpty()) { |
| 2007 | DispatchEntry* dispatchEntry = connection->outboundQueue.dequeueAtHead(); |
| 2008 | if (dispatchEntry->hasForegroundTarget()) { |
| 2009 | decrementPendingForegroundDispatchesLocked(dispatchEntry->eventEntry); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2010 | } |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 2011 | delete dispatchEntry; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 2014 | deactivateConnectionLocked(connection); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 2017 | int InputDispatcher::handleReceiveCallback(int fd, int events, void* data) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2018 | InputDispatcher* d = static_cast<InputDispatcher*>(data); |
| 2019 | |
| 2020 | { // acquire lock |
| 2021 | AutoMutex _l(d->mLock); |
| 2022 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 2023 | ssize_t connectionIndex = d->mConnectionsByFd.indexOfKey(fd); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2024 | if (connectionIndex < 0) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 2025 | ALOGE("Received spurious receive callback for unknown input channel. " |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 2026 | "fd=%d, events=0x%x", fd, events); |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 2027 | return 0; // remove the callback |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2030 | bool notify; |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 2031 | sp<Connection> connection = d->mConnectionsByFd.valueAt(connectionIndex); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2032 | if (!(events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP))) { |
| 2033 | if (!(events & ALOOPER_EVENT_INPUT)) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2034 | ALOGW("channel '%s' ~ Received spurious callback for unhandled poll event. " |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2035 | "events=0x%x", connection->getInputChannelName(), events); |
| 2036 | return 1; |
| 2037 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2038 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2039 | bool handled = false; |
| 2040 | status_t status = connection->inputPublisher.receiveFinishedSignal(&handled); |
| 2041 | if (!status) { |
| 2042 | nsecs_t currentTime = now(); |
| 2043 | d->finishDispatchCycleLocked(currentTime, connection, handled); |
| 2044 | d->runCommandsLockedInterruptible(); |
| 2045 | return 1; |
| 2046 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2047 | |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 2048 | ALOGE("channel '%s' ~ Failed to receive finished signal. status=%d", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2049 | connection->getInputChannelName(), status); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2050 | notify = true; |
| 2051 | } else { |
| 2052 | // Monitor channels are never explicitly unregistered. |
| 2053 | // We do it automatically when the remote endpoint is closed so don't warn |
| 2054 | // about them. |
| 2055 | notify = !connection->monitor; |
| 2056 | if (notify) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2057 | ALOGW("channel '%s' ~ Consumer closed input channel or an error occurred. " |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2058 | "events=0x%x", connection->getInputChannelName(), events); |
| 2059 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2062 | // Unregister the channel. |
| 2063 | d->unregisterInputChannelLocked(connection->inputChannel, notify); |
| 2064 | return 0; // remove the callback |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2065 | } // release lock |
| 2066 | } |
| 2067 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2068 | void InputDispatcher::synthesizeCancelationEventsForAllConnectionsLocked( |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 2069 | const CancelationOptions& options) { |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 2070 | for (size_t i = 0; i < mConnectionsByFd.size(); i++) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2071 | synthesizeCancelationEventsForConnectionLocked( |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 2072 | mConnectionsByFd.valueAt(i), options); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | void InputDispatcher::synthesizeCancelationEventsForInputChannelLocked( |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 2077 | const sp<InputChannel>& channel, const CancelationOptions& options) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2078 | ssize_t index = getConnectionIndexLocked(channel); |
| 2079 | if (index >= 0) { |
| 2080 | synthesizeCancelationEventsForConnectionLocked( |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 2081 | mConnectionsByFd.valueAt(index), options); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | void InputDispatcher::synthesizeCancelationEventsForConnectionLocked( |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 2086 | const sp<Connection>& connection, const CancelationOptions& options) { |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 2087 | if (connection->status == Connection::STATUS_BROKEN) { |
| 2088 | return; |
| 2089 | } |
| 2090 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2091 | nsecs_t currentTime = now(); |
| 2092 | |
| 2093 | mTempCancelationEvents.clear(); |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 2094 | connection->inputState.synthesizeCancelationEvents(currentTime, |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2095 | mTempCancelationEvents, options); |
| 2096 | |
Jeff Brown | c0cb3dc | 2012-01-12 18:30:12 -0800 | [diff] [blame] | 2097 | if (!mTempCancelationEvents.isEmpty()) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2098 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2099 | ALOGD("channel '%s' ~ Synthesized %d cancelation events to bring channel back in sync " |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 2100 | "with reality: %s, mode=%d.", |
| 2101 | connection->getInputChannelName(), mTempCancelationEvents.size(), |
| 2102 | options.reason, options.mode); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2103 | #endif |
| 2104 | for (size_t i = 0; i < mTempCancelationEvents.size(); i++) { |
| 2105 | EventEntry* cancelationEventEntry = mTempCancelationEvents.itemAt(i); |
| 2106 | switch (cancelationEventEntry->type) { |
| 2107 | case EventEntry::TYPE_KEY: |
| 2108 | logOutboundKeyDetailsLocked("cancel - ", |
| 2109 | static_cast<KeyEntry*>(cancelationEventEntry)); |
| 2110 | break; |
| 2111 | case EventEntry::TYPE_MOTION: |
| 2112 | logOutboundMotionDetailsLocked("cancel - ", |
| 2113 | static_cast<MotionEntry*>(cancelationEventEntry)); |
| 2114 | break; |
| 2115 | } |
| 2116 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 2117 | InputTarget target; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2118 | sp<InputWindowHandle> windowHandle = getWindowHandleLocked(connection->inputChannel); |
| 2119 | if (windowHandle != NULL) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2120 | const InputWindowInfo* windowInfo = windowHandle->getInfo(); |
| 2121 | target.xOffset = -windowInfo->frameLeft; |
| 2122 | target.yOffset = -windowInfo->frameTop; |
| 2123 | target.scaleFactor = windowInfo->scaleFactor; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2124 | } else { |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 2125 | target.xOffset = 0; |
| 2126 | target.yOffset = 0; |
| 2127 | target.scaleFactor = 1.0f; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2128 | } |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 2129 | target.inputChannel = connection->inputChannel; |
| 2130 | target.flags = InputTarget::FLAG_DISPATCH_AS_IS; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2131 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 2132 | enqueueDispatchEntryLocked(connection, cancelationEventEntry, // increments ref |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2133 | &target, InputTarget::FLAG_DISPATCH_AS_IS); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2134 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 2135 | cancelationEventEntry->release(); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 2138 | if (!connection->outboundQueue.head->inProgress) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2139 | startDispatchCycleLocked(currentTime, connection); |
| 2140 | } |
| 2141 | } |
| 2142 | } |
| 2143 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2144 | InputDispatcher::MotionEntry* |
| 2145 | InputDispatcher::splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds) { |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 2146 | ALOG_ASSERT(pointerIds.value != 0); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2147 | |
| 2148 | uint32_t splitPointerIndexMap[MAX_POINTERS]; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2149 | PointerProperties splitPointerProperties[MAX_POINTERS]; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2150 | PointerCoords splitPointerCoords[MAX_POINTERS]; |
| 2151 | |
| 2152 | uint32_t originalPointerCount = originalMotionEntry->pointerCount; |
| 2153 | uint32_t splitPointerCount = 0; |
| 2154 | |
| 2155 | for (uint32_t originalPointerIndex = 0; originalPointerIndex < originalPointerCount; |
| 2156 | originalPointerIndex++) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2157 | const PointerProperties& pointerProperties = |
| 2158 | originalMotionEntry->pointerProperties[originalPointerIndex]; |
| 2159 | uint32_t pointerId = uint32_t(pointerProperties.id); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2160 | if (pointerIds.hasBit(pointerId)) { |
| 2161 | splitPointerIndexMap[splitPointerCount] = originalPointerIndex; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2162 | splitPointerProperties[splitPointerCount].copyFrom(pointerProperties); |
Jeff Brown | ace13b1 | 2011-03-09 17:39:48 -0800 | [diff] [blame] | 2163 | splitPointerCoords[splitPointerCount].copyFrom( |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2164 | originalMotionEntry->pointerCoords[originalPointerIndex]); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2165 | splitPointerCount += 1; |
| 2166 | } |
| 2167 | } |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2168 | |
| 2169 | if (splitPointerCount != pointerIds.count()) { |
| 2170 | // This is bad. We are missing some of the pointers that we expected to deliver. |
| 2171 | // Most likely this indicates that we received an ACTION_MOVE events that has |
| 2172 | // different pointer ids than we expected based on the previous ACTION_DOWN |
| 2173 | // or ACTION_POINTER_DOWN events that caused us to decide to split the pointers |
| 2174 | // in this way. |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2175 | ALOGW("Dropping split motion event because the pointer count is %d but " |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2176 | "we expected there to be %d pointers. This probably means we received " |
| 2177 | "a broken sequence of pointer ids from the input device.", |
| 2178 | splitPointerCount, pointerIds.count()); |
| 2179 | return NULL; |
| 2180 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2181 | |
| 2182 | int32_t action = originalMotionEntry->action; |
| 2183 | int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK; |
| 2184 | if (maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN |
| 2185 | || maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) { |
| 2186 | int32_t originalPointerIndex = getMotionEventActionPointerIndex(action); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2187 | const PointerProperties& pointerProperties = |
| 2188 | originalMotionEntry->pointerProperties[originalPointerIndex]; |
| 2189 | uint32_t pointerId = uint32_t(pointerProperties.id); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2190 | if (pointerIds.hasBit(pointerId)) { |
| 2191 | if (pointerIds.count() == 1) { |
| 2192 | // The first/last pointer went down/up. |
| 2193 | action = maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN |
| 2194 | ? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP; |
Jeff Brown | 9a01d05 | 2010-09-27 16:35:11 -0700 | [diff] [blame] | 2195 | } else { |
| 2196 | // A secondary pointer went down/up. |
| 2197 | uint32_t splitPointerIndex = 0; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2198 | while (pointerId != uint32_t(splitPointerProperties[splitPointerIndex].id)) { |
Jeff Brown | 9a01d05 | 2010-09-27 16:35:11 -0700 | [diff] [blame] | 2199 | splitPointerIndex += 1; |
| 2200 | } |
| 2201 | action = maskedAction | (splitPointerIndex |
| 2202 | << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2203 | } |
| 2204 | } else { |
| 2205 | // An unrelated pointer changed. |
| 2206 | action = AMOTION_EVENT_ACTION_MOVE; |
| 2207 | } |
| 2208 | } |
| 2209 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 2210 | MotionEntry* splitMotionEntry = new MotionEntry( |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2211 | originalMotionEntry->eventTime, |
| 2212 | originalMotionEntry->deviceId, |
| 2213 | originalMotionEntry->source, |
| 2214 | originalMotionEntry->policyFlags, |
| 2215 | action, |
| 2216 | originalMotionEntry->flags, |
| 2217 | originalMotionEntry->metaState, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2218 | originalMotionEntry->buttonState, |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2219 | originalMotionEntry->edgeFlags, |
| 2220 | originalMotionEntry->xPrecision, |
| 2221 | originalMotionEntry->yPrecision, |
| 2222 | originalMotionEntry->downTime, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2223 | splitPointerCount, splitPointerProperties, splitPointerCoords); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2224 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2225 | if (originalMotionEntry->injectionState) { |
| 2226 | splitMotionEntry->injectionState = originalMotionEntry->injectionState; |
| 2227 | splitMotionEntry->injectionState->refCount += 1; |
| 2228 | } |
| 2229 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2230 | return splitMotionEntry; |
| 2231 | } |
| 2232 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2233 | void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2234 | #if DEBUG_INBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2235 | ALOGD("notifyConfigurationChanged - eventTime=%lld", args->eventTime); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2236 | #endif |
| 2237 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2238 | bool needWake; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2239 | { // acquire lock |
| 2240 | AutoMutex _l(mLock); |
| 2241 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2242 | ConfigurationChangedEntry* newEntry = new ConfigurationChangedEntry(args->eventTime); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2243 | needWake = enqueueInboundEventLocked(newEntry); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2244 | } // release lock |
| 2245 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2246 | if (needWake) { |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 2247 | mLooper->wake(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2251 | void InputDispatcher::notifyKey(const NotifyKeyArgs* args) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2252 | #if DEBUG_INBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2253 | ALOGD("notifyKey - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, action=0x%x, " |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2254 | "flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%lld", |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2255 | args->eventTime, args->deviceId, args->source, args->policyFlags, |
| 2256 | args->action, args->flags, args->keyCode, args->scanCode, |
| 2257 | args->metaState, args->downTime); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2258 | #endif |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2259 | if (!validateKeyEvent(args->action)) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2260 | return; |
| 2261 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2262 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2263 | uint32_t policyFlags = args->policyFlags; |
| 2264 | int32_t flags = args->flags; |
| 2265 | int32_t metaState = args->metaState; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2266 | if ((policyFlags & POLICY_FLAG_VIRTUAL) || (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY)) { |
| 2267 | policyFlags |= POLICY_FLAG_VIRTUAL; |
| 2268 | flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY; |
| 2269 | } |
Jeff Brown | 924c4d4 | 2011-03-07 16:40:47 -0800 | [diff] [blame] | 2270 | if (policyFlags & POLICY_FLAG_ALT) { |
| 2271 | metaState |= AMETA_ALT_ON | AMETA_ALT_LEFT_ON; |
| 2272 | } |
| 2273 | if (policyFlags & POLICY_FLAG_ALT_GR) { |
| 2274 | metaState |= AMETA_ALT_ON | AMETA_ALT_RIGHT_ON; |
| 2275 | } |
| 2276 | if (policyFlags & POLICY_FLAG_SHIFT) { |
| 2277 | metaState |= AMETA_SHIFT_ON | AMETA_SHIFT_LEFT_ON; |
| 2278 | } |
| 2279 | if (policyFlags & POLICY_FLAG_CAPS_LOCK) { |
| 2280 | metaState |= AMETA_CAPS_LOCK_ON; |
| 2281 | } |
| 2282 | if (policyFlags & POLICY_FLAG_FUNCTION) { |
| 2283 | metaState |= AMETA_FUNCTION_ON; |
| 2284 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2285 | |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 2286 | policyFlags |= POLICY_FLAG_TRUSTED; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2287 | |
| 2288 | KeyEvent event; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2289 | event.initialize(args->deviceId, args->source, args->action, |
| 2290 | flags, args->keyCode, args->scanCode, metaState, 0, |
| 2291 | args->downTime, args->eventTime); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2292 | |
| 2293 | mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags); |
| 2294 | |
| 2295 | if (policyFlags & POLICY_FLAG_WOKE_HERE) { |
| 2296 | flags |= AKEY_EVENT_FLAG_WOKE_HERE; |
| 2297 | } |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2298 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2299 | bool needWake; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2300 | { // acquire lock |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2301 | mLock.lock(); |
| 2302 | |
| 2303 | if (mInputFilterEnabled) { |
| 2304 | mLock.unlock(); |
| 2305 | |
| 2306 | policyFlags |= POLICY_FLAG_FILTERED; |
| 2307 | if (!mPolicy->filterInputEvent(&event, policyFlags)) { |
| 2308 | return; // event was consumed by the filter |
| 2309 | } |
| 2310 | |
| 2311 | mLock.lock(); |
| 2312 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2313 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2314 | int32_t repeatCount = 0; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2315 | KeyEntry* newEntry = new KeyEntry(args->eventTime, |
| 2316 | args->deviceId, args->source, policyFlags, |
| 2317 | args->action, flags, args->keyCode, args->scanCode, |
| 2318 | metaState, repeatCount, args->downTime); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2319 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2320 | needWake = enqueueInboundEventLocked(newEntry); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2321 | mLock.unlock(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2322 | } // release lock |
| 2323 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2324 | if (needWake) { |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 2325 | mLooper->wake(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2326 | } |
| 2327 | } |
| 2328 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2329 | void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2330 | #if DEBUG_INBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2331 | ALOGD("notifyMotion - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, " |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2332 | "action=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x, edgeFlags=0x%x, " |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 2333 | "xPrecision=%f, yPrecision=%f, downTime=%lld", |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2334 | args->eventTime, args->deviceId, args->source, args->policyFlags, |
| 2335 | args->action, args->flags, args->metaState, args->buttonState, |
| 2336 | args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime); |
| 2337 | for (uint32_t i = 0; i < args->pointerCount; i++) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2338 | ALOGD(" Pointer %d: id=%d, toolType=%d, " |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2339 | "x=%f, y=%f, pressure=%f, size=%f, " |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 2340 | "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, " |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 2341 | "orientation=%f", |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2342 | i, args->pointerProperties[i].id, |
| 2343 | args->pointerProperties[i].toolType, |
| 2344 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X), |
| 2345 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y), |
| 2346 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), |
| 2347 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE), |
| 2348 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), |
| 2349 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), |
| 2350 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), |
| 2351 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), |
| 2352 | args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION)); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2353 | } |
| 2354 | #endif |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2355 | if (!validateMotionEvent(args->action, args->pointerCount, args->pointerProperties)) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2356 | return; |
| 2357 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2358 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2359 | uint32_t policyFlags = args->policyFlags; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 2360 | policyFlags |= POLICY_FLAG_TRUSTED; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2361 | mPolicy->interceptMotionBeforeQueueing(args->eventTime, /*byref*/ policyFlags); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2362 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2363 | bool needWake; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2364 | { // acquire lock |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2365 | mLock.lock(); |
| 2366 | |
| 2367 | if (mInputFilterEnabled) { |
| 2368 | mLock.unlock(); |
| 2369 | |
| 2370 | MotionEvent event; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2371 | event.initialize(args->deviceId, args->source, args->action, args->flags, |
| 2372 | args->edgeFlags, args->metaState, args->buttonState, 0, 0, |
| 2373 | args->xPrecision, args->yPrecision, |
| 2374 | args->downTime, args->eventTime, |
| 2375 | args->pointerCount, args->pointerProperties, args->pointerCoords); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2376 | |
| 2377 | policyFlags |= POLICY_FLAG_FILTERED; |
| 2378 | if (!mPolicy->filterInputEvent(&event, policyFlags)) { |
| 2379 | return; // event was consumed by the filter |
| 2380 | } |
| 2381 | |
| 2382 | mLock.lock(); |
| 2383 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2384 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2385 | // Just enqueue a new motion event. |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2386 | MotionEntry* newEntry = new MotionEntry(args->eventTime, |
| 2387 | args->deviceId, args->source, policyFlags, |
| 2388 | args->action, args->flags, args->metaState, args->buttonState, |
| 2389 | args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime, |
| 2390 | args->pointerCount, args->pointerProperties, args->pointerCoords); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2391 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2392 | needWake = enqueueInboundEventLocked(newEntry); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2393 | mLock.unlock(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2394 | } // release lock |
| 2395 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2396 | if (needWake) { |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 2397 | mLooper->wake(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2398 | } |
| 2399 | } |
| 2400 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2401 | void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2402 | #if DEBUG_INBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2403 | ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchCode=%d, switchValue=%d", |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2404 | args->eventTime, args->policyFlags, |
| 2405 | args->switchCode, args->switchValue); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2406 | #endif |
| 2407 | |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2408 | uint32_t policyFlags = args->policyFlags; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 2409 | policyFlags |= POLICY_FLAG_TRUSTED; |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 2410 | mPolicy->notifySwitch(args->eventTime, |
| 2411 | args->switchCode, args->switchValue, policyFlags); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2414 | void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) { |
| 2415 | #if DEBUG_INBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2416 | ALOGD("notifyDeviceReset - eventTime=%lld, deviceId=%d", |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 2417 | args->eventTime, args->deviceId); |
| 2418 | #endif |
| 2419 | |
| 2420 | bool needWake; |
| 2421 | { // acquire lock |
| 2422 | AutoMutex _l(mLock); |
| 2423 | |
| 2424 | DeviceResetEntry* newEntry = new DeviceResetEntry(args->eventTime, args->deviceId); |
| 2425 | needWake = enqueueInboundEventLocked(newEntry); |
| 2426 | } // release lock |
| 2427 | |
| 2428 | if (needWake) { |
| 2429 | mLooper->wake(); |
| 2430 | } |
| 2431 | } |
| 2432 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2433 | int32_t InputDispatcher::injectInputEvent(const InputEvent* event, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2434 | int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis, |
| 2435 | uint32_t policyFlags) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2436 | #if DEBUG_INBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2437 | ALOGD("injectInputEvent - eventType=%d, injectorPid=%d, injectorUid=%d, " |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2438 | "syncMode=%d, timeoutMillis=%d, policyFlags=0x%08x", |
| 2439 | event->getType(), injectorPid, injectorUid, syncMode, timeoutMillis, policyFlags); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2440 | #endif |
| 2441 | |
| 2442 | nsecs_t endTime = now() + milliseconds_to_nanoseconds(timeoutMillis); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 2443 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2444 | policyFlags |= POLICY_FLAG_INJECTED; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 2445 | if (hasInjectionPermission(injectorPid, injectorUid)) { |
| 2446 | policyFlags |= POLICY_FLAG_TRUSTED; |
| 2447 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2448 | |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2449 | EventEntry* firstInjectedEntry; |
| 2450 | EventEntry* lastInjectedEntry; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2451 | switch (event->getType()) { |
| 2452 | case AINPUT_EVENT_TYPE_KEY: { |
| 2453 | const KeyEvent* keyEvent = static_cast<const KeyEvent*>(event); |
| 2454 | int32_t action = keyEvent->getAction(); |
| 2455 | if (! validateKeyEvent(action)) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2456 | return INPUT_EVENT_INJECTION_FAILED; |
| 2457 | } |
| 2458 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2459 | int32_t flags = keyEvent->getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2460 | if (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY) { |
| 2461 | policyFlags |= POLICY_FLAG_VIRTUAL; |
| 2462 | } |
| 2463 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2464 | if (!(policyFlags & POLICY_FLAG_FILTERED)) { |
| 2465 | mPolicy->interceptKeyBeforeQueueing(keyEvent, /*byref*/ policyFlags); |
| 2466 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2467 | |
| 2468 | if (policyFlags & POLICY_FLAG_WOKE_HERE) { |
| 2469 | flags |= AKEY_EVENT_FLAG_WOKE_HERE; |
| 2470 | } |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2471 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2472 | mLock.lock(); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2473 | firstInjectedEntry = new KeyEntry(keyEvent->getEventTime(), |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2474 | keyEvent->getDeviceId(), keyEvent->getSource(), |
| 2475 | policyFlags, action, flags, |
| 2476 | keyEvent->getKeyCode(), keyEvent->getScanCode(), keyEvent->getMetaState(), |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2477 | keyEvent->getRepeatCount(), keyEvent->getDownTime()); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2478 | lastInjectedEntry = firstInjectedEntry; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2479 | break; |
| 2480 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2481 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2482 | case AINPUT_EVENT_TYPE_MOTION: { |
| 2483 | const MotionEvent* motionEvent = static_cast<const MotionEvent*>(event); |
| 2484 | int32_t action = motionEvent->getAction(); |
| 2485 | size_t pointerCount = motionEvent->getPointerCount(); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2486 | const PointerProperties* pointerProperties = motionEvent->getPointerProperties(); |
| 2487 | if (! validateMotionEvent(action, pointerCount, pointerProperties)) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2488 | return INPUT_EVENT_INJECTION_FAILED; |
| 2489 | } |
| 2490 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2491 | if (!(policyFlags & POLICY_FLAG_FILTERED)) { |
| 2492 | nsecs_t eventTime = motionEvent->getEventTime(); |
| 2493 | mPolicy->interceptMotionBeforeQueueing(eventTime, /*byref*/ policyFlags); |
| 2494 | } |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2495 | |
| 2496 | mLock.lock(); |
| 2497 | const nsecs_t* sampleEventTimes = motionEvent->getSampleEventTimes(); |
| 2498 | const PointerCoords* samplePointerCoords = motionEvent->getSamplePointerCoords(); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2499 | firstInjectedEntry = new MotionEntry(*sampleEventTimes, |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2500 | motionEvent->getDeviceId(), motionEvent->getSource(), policyFlags, |
| 2501 | action, motionEvent->getFlags(), |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2502 | motionEvent->getMetaState(), motionEvent->getButtonState(), |
| 2503 | motionEvent->getEdgeFlags(), |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2504 | motionEvent->getXPrecision(), motionEvent->getYPrecision(), |
| 2505 | motionEvent->getDownTime(), uint32_t(pointerCount), |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2506 | pointerProperties, samplePointerCoords); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2507 | lastInjectedEntry = firstInjectedEntry; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2508 | for (size_t i = motionEvent->getHistorySize(); i > 0; i--) { |
| 2509 | sampleEventTimes += 1; |
| 2510 | samplePointerCoords += pointerCount; |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2511 | MotionEntry* nextInjectedEntry = new MotionEntry(*sampleEventTimes, |
| 2512 | motionEvent->getDeviceId(), motionEvent->getSource(), policyFlags, |
| 2513 | action, motionEvent->getFlags(), |
| 2514 | motionEvent->getMetaState(), motionEvent->getButtonState(), |
| 2515 | motionEvent->getEdgeFlags(), |
| 2516 | motionEvent->getXPrecision(), motionEvent->getYPrecision(), |
| 2517 | motionEvent->getDownTime(), uint32_t(pointerCount), |
| 2518 | pointerProperties, samplePointerCoords); |
| 2519 | lastInjectedEntry->next = nextInjectedEntry; |
| 2520 | lastInjectedEntry = nextInjectedEntry; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2521 | } |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2522 | break; |
| 2523 | } |
| 2524 | |
| 2525 | default: |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2526 | ALOGW("Cannot inject event of type %d", event->getType()); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2527 | return INPUT_EVENT_INJECTION_FAILED; |
| 2528 | } |
| 2529 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 2530 | InjectionState* injectionState = new InjectionState(injectorPid, injectorUid); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2531 | if (syncMode == INPUT_EVENT_INJECTION_SYNC_NONE) { |
| 2532 | injectionState->injectionIsAsync = true; |
| 2533 | } |
| 2534 | |
| 2535 | injectionState->refCount += 1; |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2536 | lastInjectedEntry->injectionState = injectionState; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2537 | |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 2538 | bool needWake = false; |
| 2539 | for (EventEntry* entry = firstInjectedEntry; entry != NULL; ) { |
| 2540 | EventEntry* nextEntry = entry->next; |
| 2541 | needWake |= enqueueInboundEventLocked(entry); |
| 2542 | entry = nextEntry; |
| 2543 | } |
| 2544 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2545 | mLock.unlock(); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2546 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2547 | if (needWake) { |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 2548 | mLooper->wake(); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | int32_t injectionResult; |
| 2552 | { // acquire lock |
| 2553 | AutoMutex _l(mLock); |
| 2554 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2555 | if (syncMode == INPUT_EVENT_INJECTION_SYNC_NONE) { |
| 2556 | injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED; |
| 2557 | } else { |
| 2558 | for (;;) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2559 | injectionResult = injectionState->injectionResult; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2560 | if (injectionResult != INPUT_EVENT_INJECTION_PENDING) { |
| 2561 | break; |
| 2562 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2563 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2564 | nsecs_t remainingTimeout = endTime - now(); |
| 2565 | if (remainingTimeout <= 0) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2566 | #if DEBUG_INJECTION |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2567 | ALOGD("injectInputEvent - Timed out waiting for injection result " |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2568 | "to become available."); |
| 2569 | #endif |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2570 | injectionResult = INPUT_EVENT_INJECTION_TIMED_OUT; |
| 2571 | break; |
| 2572 | } |
| 2573 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2574 | mInjectionResultAvailableCondition.waitRelative(mLock, remainingTimeout); |
| 2575 | } |
| 2576 | |
| 2577 | if (injectionResult == INPUT_EVENT_INJECTION_SUCCEEDED |
| 2578 | && syncMode == INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISHED) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2579 | while (injectionState->pendingForegroundDispatches != 0) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2580 | #if DEBUG_INJECTION |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2581 | ALOGD("injectInputEvent - Waiting for %d pending foreground dispatches.", |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2582 | injectionState->pendingForegroundDispatches); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2583 | #endif |
| 2584 | nsecs_t remainingTimeout = endTime - now(); |
| 2585 | if (remainingTimeout <= 0) { |
| 2586 | #if DEBUG_INJECTION |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2587 | ALOGD("injectInputEvent - Timed out waiting for pending foreground " |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2588 | "dispatches to finish."); |
| 2589 | #endif |
| 2590 | injectionResult = INPUT_EVENT_INJECTION_TIMED_OUT; |
| 2591 | break; |
| 2592 | } |
| 2593 | |
| 2594 | mInjectionSyncFinishedCondition.waitRelative(mLock, remainingTimeout); |
| 2595 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 2599 | injectionState->release(); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2600 | } // release lock |
| 2601 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2602 | #if DEBUG_INJECTION |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2603 | ALOGD("injectInputEvent - Finished with result %d. " |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2604 | "injectorPid=%d, injectorUid=%d", |
| 2605 | injectionResult, injectorPid, injectorUid); |
| 2606 | #endif |
| 2607 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2608 | return injectionResult; |
| 2609 | } |
| 2610 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2611 | bool InputDispatcher::hasInjectionPermission(int32_t injectorPid, int32_t injectorUid) { |
| 2612 | return injectorUid == 0 |
| 2613 | || mPolicy->checkInjectEventsPermissionNonReentrant(injectorPid, injectorUid); |
| 2614 | } |
| 2615 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2616 | void InputDispatcher::setInjectionResultLocked(EventEntry* entry, int32_t injectionResult) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2617 | InjectionState* injectionState = entry->injectionState; |
| 2618 | if (injectionState) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2619 | #if DEBUG_INJECTION |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2620 | ALOGD("Setting input event injection result to %d. " |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2621 | "injectorPid=%d, injectorUid=%d", |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2622 | injectionResult, injectionState->injectorPid, injectionState->injectorUid); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2623 | #endif |
| 2624 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2625 | if (injectionState->injectionIsAsync |
| 2626 | && !(entry->policyFlags & POLICY_FLAG_FILTERED)) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2627 | // Log the outcome since the injector did not wait for the injection result. |
| 2628 | switch (injectionResult) { |
| 2629 | case INPUT_EVENT_INJECTION_SUCCEEDED: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2630 | ALOGV("Asynchronous input event injection succeeded."); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2631 | break; |
| 2632 | case INPUT_EVENT_INJECTION_FAILED: |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2633 | ALOGW("Asynchronous input event injection failed."); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2634 | break; |
| 2635 | case INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2636 | ALOGW("Asynchronous input event injection permission denied."); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2637 | break; |
| 2638 | case INPUT_EVENT_INJECTION_TIMED_OUT: |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2639 | ALOGW("Asynchronous input event injection timed out."); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2640 | break; |
| 2641 | } |
| 2642 | } |
| 2643 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2644 | injectionState->injectionResult = injectionResult; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 2645 | mInjectionResultAvailableCondition.broadcast(); |
| 2646 | } |
| 2647 | } |
| 2648 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2649 | void InputDispatcher::incrementPendingForegroundDispatchesLocked(EventEntry* entry) { |
| 2650 | InjectionState* injectionState = entry->injectionState; |
| 2651 | if (injectionState) { |
| 2652 | injectionState->pendingForegroundDispatches += 1; |
| 2653 | } |
| 2654 | } |
| 2655 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 2656 | void InputDispatcher::decrementPendingForegroundDispatchesLocked(EventEntry* entry) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2657 | InjectionState* injectionState = entry->injectionState; |
| 2658 | if (injectionState) { |
| 2659 | injectionState->pendingForegroundDispatches -= 1; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2660 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2661 | if (injectionState->pendingForegroundDispatches == 0) { |
| 2662 | mInjectionSyncFinishedCondition.broadcast(); |
| 2663 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2664 | } |
| 2665 | } |
| 2666 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2667 | sp<InputWindowHandle> InputDispatcher::getWindowHandleLocked( |
| 2668 | const sp<InputChannel>& inputChannel) const { |
| 2669 | size_t numWindows = mWindowHandles.size(); |
| 2670 | for (size_t i = 0; i < numWindows; i++) { |
| 2671 | const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2672 | if (windowHandle->getInputChannel() == inputChannel) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2673 | return windowHandle; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | return NULL; |
| 2677 | } |
| 2678 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2679 | bool InputDispatcher::hasWindowHandleLocked( |
| 2680 | const sp<InputWindowHandle>& windowHandle) const { |
| 2681 | size_t numWindows = mWindowHandles.size(); |
| 2682 | for (size_t i = 0; i < numWindows; i++) { |
| 2683 | if (mWindowHandles.itemAt(i) == windowHandle) { |
| 2684 | return true; |
| 2685 | } |
| 2686 | } |
| 2687 | return false; |
| 2688 | } |
| 2689 | |
| 2690 | void InputDispatcher::setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2691 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2692 | ALOGD("setInputWindows"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2693 | #endif |
| 2694 | { // acquire lock |
| 2695 | AutoMutex _l(mLock); |
| 2696 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2697 | Vector<sp<InputWindowHandle> > oldWindowHandles = mWindowHandles; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2698 | mWindowHandles = inputWindowHandles; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2699 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2700 | sp<InputWindowHandle> newFocusedWindowHandle; |
| 2701 | bool foundHoveredWindow = false; |
| 2702 | for (size_t i = 0; i < mWindowHandles.size(); i++) { |
| 2703 | const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2704 | if (!windowHandle->updateInfo() || windowHandle->getInputChannel() == NULL) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2705 | mWindowHandles.removeAt(i--); |
| 2706 | continue; |
| 2707 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2708 | if (windowHandle->getInfo()->hasFocus) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2709 | newFocusedWindowHandle = windowHandle; |
| 2710 | } |
| 2711 | if (windowHandle == mLastHoverWindowHandle) { |
| 2712 | foundHoveredWindow = true; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2713 | } |
| 2714 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2715 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2716 | if (!foundHoveredWindow) { |
| 2717 | mLastHoverWindowHandle = NULL; |
| 2718 | } |
| 2719 | |
| 2720 | if (mFocusedWindowHandle != newFocusedWindowHandle) { |
| 2721 | if (mFocusedWindowHandle != NULL) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2722 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2723 | ALOGD("Focus left window: %s", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2724 | mFocusedWindowHandle->getName().string()); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2725 | #endif |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2726 | sp<InputChannel> focusedInputChannel = mFocusedWindowHandle->getInputChannel(); |
| 2727 | if (focusedInputChannel != NULL) { |
Christopher Tate | d9be36c | 2011-08-16 16:09:33 -0700 | [diff] [blame] | 2728 | CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS, |
| 2729 | "focus left window"); |
| 2730 | synthesizeCancelationEventsForInputChannelLocked( |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2731 | focusedInputChannel, options); |
Christopher Tate | d9be36c | 2011-08-16 16:09:33 -0700 | [diff] [blame] | 2732 | } |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2733 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2734 | if (newFocusedWindowHandle != NULL) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2735 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2736 | ALOGD("Focus entered window: %s", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2737 | newFocusedWindowHandle->getName().string()); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2738 | #endif |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2739 | } |
| 2740 | mFocusedWindowHandle = newFocusedWindowHandle; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2743 | for (size_t i = 0; i < mTouchState.windows.size(); i++) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2744 | TouchedWindow& touchedWindow = mTouchState.windows.editItemAt(i); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2745 | if (!hasWindowHandleLocked(touchedWindow.windowHandle)) { |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2746 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2747 | ALOGD("Touched window was removed: %s", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2748 | touchedWindow.windowHandle->getName().string()); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2749 | #endif |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2750 | sp<InputChannel> touchedInputChannel = |
| 2751 | touchedWindow.windowHandle->getInputChannel(); |
| 2752 | if (touchedInputChannel != NULL) { |
Christopher Tate | d9be36c | 2011-08-16 16:09:33 -0700 | [diff] [blame] | 2753 | CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS, |
| 2754 | "touched window was removed"); |
| 2755 | synthesizeCancelationEventsForInputChannelLocked( |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2756 | touchedInputChannel, options); |
Christopher Tate | d9be36c | 2011-08-16 16:09:33 -0700 | [diff] [blame] | 2757 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2758 | mTouchState.windows.removeAt(i--); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 2759 | } |
| 2760 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2761 | |
| 2762 | // Release information for windows that are no longer present. |
| 2763 | // This ensures that unused input channels are released promptly. |
| 2764 | // Otherwise, they might stick around until the window handle is destroyed |
| 2765 | // which might not happen until the next GC. |
| 2766 | for (size_t i = 0; i < oldWindowHandles.size(); i++) { |
| 2767 | const sp<InputWindowHandle>& oldWindowHandle = oldWindowHandles.itemAt(i); |
| 2768 | if (!hasWindowHandleLocked(oldWindowHandle)) { |
| 2769 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2770 | ALOGD("Window went away: %s", oldWindowHandle->getName().string()); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2771 | #endif |
| 2772 | oldWindowHandle->releaseInfo(); |
| 2773 | } |
| 2774 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2775 | } // release lock |
| 2776 | |
| 2777 | // Wake up poll loop since it may need to make new input dispatching choices. |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 2778 | mLooper->wake(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2781 | void InputDispatcher::setFocusedApplication( |
| 2782 | const sp<InputApplicationHandle>& inputApplicationHandle) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2783 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2784 | ALOGD("setFocusedApplication"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2785 | #endif |
| 2786 | { // acquire lock |
| 2787 | AutoMutex _l(mLock); |
| 2788 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2789 | if (inputApplicationHandle != NULL && inputApplicationHandle->updateInfo()) { |
Jeff Brown | 5ea29ab | 2011-07-27 11:50:51 -0700 | [diff] [blame] | 2790 | if (mFocusedApplicationHandle != inputApplicationHandle) { |
| 2791 | if (mFocusedApplicationHandle != NULL) { |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 2792 | resetANRTimeoutsLocked(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2793 | mFocusedApplicationHandle->releaseInfo(); |
Jeff Brown | 5ea29ab | 2011-07-27 11:50:51 -0700 | [diff] [blame] | 2794 | } |
| 2795 | mFocusedApplicationHandle = inputApplicationHandle; |
| 2796 | } |
| 2797 | } else if (mFocusedApplicationHandle != NULL) { |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 2798 | resetANRTimeoutsLocked(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2799 | mFocusedApplicationHandle->releaseInfo(); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2800 | mFocusedApplicationHandle.clear(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | #if DEBUG_FOCUS |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2804 | //logDispatchStateLocked(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2805 | #endif |
| 2806 | } // release lock |
| 2807 | |
| 2808 | // Wake up poll loop since it may need to make new input dispatching choices. |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 2809 | mLooper->wake(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2810 | } |
| 2811 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2812 | void InputDispatcher::setInputDispatchMode(bool enabled, bool frozen) { |
| 2813 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2814 | ALOGD("setInputDispatchMode: enabled=%d, frozen=%d", enabled, frozen); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2815 | #endif |
| 2816 | |
| 2817 | bool changed; |
| 2818 | { // acquire lock |
| 2819 | AutoMutex _l(mLock); |
| 2820 | |
| 2821 | if (mDispatchEnabled != enabled || mDispatchFrozen != frozen) { |
Jeff Brown | 120a459 | 2010-10-27 18:43:51 -0700 | [diff] [blame] | 2822 | if (mDispatchFrozen && !frozen) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2823 | resetANRTimeoutsLocked(); |
| 2824 | } |
| 2825 | |
Jeff Brown | 120a459 | 2010-10-27 18:43:51 -0700 | [diff] [blame] | 2826 | if (mDispatchEnabled && !enabled) { |
| 2827 | resetAndDropEverythingLocked("dispatcher is being disabled"); |
| 2828 | } |
| 2829 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2830 | mDispatchEnabled = enabled; |
| 2831 | mDispatchFrozen = frozen; |
| 2832 | changed = true; |
| 2833 | } else { |
| 2834 | changed = false; |
| 2835 | } |
| 2836 | |
| 2837 | #if DEBUG_FOCUS |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 2838 | //logDispatchStateLocked(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2839 | #endif |
| 2840 | } // release lock |
| 2841 | |
| 2842 | if (changed) { |
| 2843 | // Wake up poll loop since it may need to make new input dispatching choices. |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 2844 | mLooper->wake(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2845 | } |
| 2846 | } |
| 2847 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2848 | void InputDispatcher::setInputFilterEnabled(bool enabled) { |
| 2849 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2850 | ALOGD("setInputFilterEnabled: enabled=%d", enabled); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 2851 | #endif |
| 2852 | |
| 2853 | { // acquire lock |
| 2854 | AutoMutex _l(mLock); |
| 2855 | |
| 2856 | if (mInputFilterEnabled == enabled) { |
| 2857 | return; |
| 2858 | } |
| 2859 | |
| 2860 | mInputFilterEnabled = enabled; |
| 2861 | resetAndDropEverythingLocked("input filter is being enabled or disabled"); |
| 2862 | } // release lock |
| 2863 | |
| 2864 | // Wake up poll loop since there might be work to do to drop everything. |
| 2865 | mLooper->wake(); |
| 2866 | } |
| 2867 | |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2868 | bool InputDispatcher::transferTouchFocus(const sp<InputChannel>& fromChannel, |
| 2869 | const sp<InputChannel>& toChannel) { |
| 2870 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2871 | ALOGD("transferTouchFocus: fromChannel=%s, toChannel=%s", |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2872 | fromChannel->getName().string(), toChannel->getName().string()); |
| 2873 | #endif |
| 2874 | { // acquire lock |
| 2875 | AutoMutex _l(mLock); |
| 2876 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2877 | sp<InputWindowHandle> fromWindowHandle = getWindowHandleLocked(fromChannel); |
| 2878 | sp<InputWindowHandle> toWindowHandle = getWindowHandleLocked(toChannel); |
| 2879 | if (fromWindowHandle == NULL || toWindowHandle == NULL) { |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2880 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2881 | ALOGD("Cannot transfer focus because from or to window not found."); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2882 | #endif |
| 2883 | return false; |
| 2884 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2885 | if (fromWindowHandle == toWindowHandle) { |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2886 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2887 | ALOGD("Trivial transfer to same window."); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2888 | #endif |
| 2889 | return true; |
| 2890 | } |
| 2891 | |
| 2892 | bool found = false; |
| 2893 | for (size_t i = 0; i < mTouchState.windows.size(); i++) { |
| 2894 | const TouchedWindow& touchedWindow = mTouchState.windows[i]; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2895 | if (touchedWindow.windowHandle == fromWindowHandle) { |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2896 | int32_t oldTargetFlags = touchedWindow.targetFlags; |
| 2897 | BitSet32 pointerIds = touchedWindow.pointerIds; |
| 2898 | |
| 2899 | mTouchState.windows.removeAt(i); |
| 2900 | |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame] | 2901 | int32_t newTargetFlags = oldTargetFlags |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2902 | & (InputTarget::FLAG_FOREGROUND |
| 2903 | | InputTarget::FLAG_SPLIT | InputTarget::FLAG_DISPATCH_AS_IS); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2904 | mTouchState.addOrUpdateWindow(toWindowHandle, newTargetFlags, pointerIds); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2905 | |
| 2906 | found = true; |
| 2907 | break; |
| 2908 | } |
| 2909 | } |
| 2910 | |
| 2911 | if (! found) { |
| 2912 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2913 | ALOGD("Focus transfer failed because from window did not have focus."); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2914 | #endif |
| 2915 | return false; |
| 2916 | } |
| 2917 | |
Jeff Brown | 9c9f1a3 | 2010-10-11 18:32:20 -0700 | [diff] [blame] | 2918 | ssize_t fromConnectionIndex = getConnectionIndexLocked(fromChannel); |
| 2919 | ssize_t toConnectionIndex = getConnectionIndexLocked(toChannel); |
| 2920 | if (fromConnectionIndex >= 0 && toConnectionIndex >= 0) { |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 2921 | sp<Connection> fromConnection = mConnectionsByFd.valueAt(fromConnectionIndex); |
| 2922 | sp<Connection> toConnection = mConnectionsByFd.valueAt(toConnectionIndex); |
Jeff Brown | 9c9f1a3 | 2010-10-11 18:32:20 -0700 | [diff] [blame] | 2923 | |
| 2924 | fromConnection->inputState.copyPointerStateTo(toConnection->inputState); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 2925 | CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS, |
Jeff Brown | 9c9f1a3 | 2010-10-11 18:32:20 -0700 | [diff] [blame] | 2926 | "transferring touch focus from this window to another window"); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 2927 | synthesizeCancelationEventsForConnectionLocked(fromConnection, options); |
Jeff Brown | 9c9f1a3 | 2010-10-11 18:32:20 -0700 | [diff] [blame] | 2928 | } |
| 2929 | |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 2930 | #if DEBUG_FOCUS |
| 2931 | logDispatchStateLocked(); |
| 2932 | #endif |
| 2933 | } // release lock |
| 2934 | |
| 2935 | // Wake up poll loop since it may need to make new input dispatching choices. |
| 2936 | mLooper->wake(); |
| 2937 | return true; |
| 2938 | } |
| 2939 | |
Jeff Brown | 120a459 | 2010-10-27 18:43:51 -0700 | [diff] [blame] | 2940 | void InputDispatcher::resetAndDropEverythingLocked(const char* reason) { |
| 2941 | #if DEBUG_FOCUS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2942 | ALOGD("Resetting and dropping all events (%s).", reason); |
Jeff Brown | 120a459 | 2010-10-27 18:43:51 -0700 | [diff] [blame] | 2943 | #endif |
| 2944 | |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 2945 | CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS, reason); |
| 2946 | synthesizeCancelationEventsForAllConnectionsLocked(options); |
Jeff Brown | 120a459 | 2010-10-27 18:43:51 -0700 | [diff] [blame] | 2947 | |
| 2948 | resetKeyRepeatLocked(); |
| 2949 | releasePendingEventLocked(); |
| 2950 | drainInboundQueueLocked(); |
Jeff Brown | e9bb9be | 2012-02-06 15:47:55 -0800 | [diff] [blame^] | 2951 | resetANRTimeoutsLocked(); |
Jeff Brown | 120a459 | 2010-10-27 18:43:51 -0700 | [diff] [blame] | 2952 | |
| 2953 | mTouchState.reset(); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2954 | mLastHoverWindowHandle.clear(); |
Jeff Brown | 120a459 | 2010-10-27 18:43:51 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2957 | void InputDispatcher::logDispatchStateLocked() { |
| 2958 | String8 dump; |
| 2959 | dumpDispatchStateLocked(dump); |
Jeff Brown | 2a95c2a | 2010-09-16 12:31:46 -0700 | [diff] [blame] | 2960 | |
| 2961 | char* text = dump.lockBuffer(dump.size()); |
| 2962 | char* start = text; |
| 2963 | while (*start != '\0') { |
| 2964 | char* end = strchr(start, '\n'); |
| 2965 | if (*end == '\n') { |
| 2966 | *(end++) = '\0'; |
| 2967 | } |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 2968 | ALOGD("%s", start); |
Jeff Brown | 2a95c2a | 2010-09-16 12:31:46 -0700 | [diff] [blame] | 2969 | start = end; |
| 2970 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | void InputDispatcher::dumpDispatchStateLocked(String8& dump) { |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 2974 | dump.appendFormat(INDENT "DispatchEnabled: %d\n", mDispatchEnabled); |
| 2975 | dump.appendFormat(INDENT "DispatchFrozen: %d\n", mDispatchFrozen); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2976 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 2977 | if (mFocusedApplicationHandle != NULL) { |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 2978 | dump.appendFormat(INDENT "FocusedApplication: name='%s', dispatchingTimeout=%0.3fms\n", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2979 | mFocusedApplicationHandle->getName().string(), |
| 2980 | mFocusedApplicationHandle->getDispatchingTimeout( |
| 2981 | DEFAULT_INPUT_DISPATCHING_TIMEOUT) / 1000000.0); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2982 | } else { |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 2983 | dump.append(INDENT "FocusedApplication: <null>\n"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2984 | } |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 2985 | dump.appendFormat(INDENT "FocusedWindow: name='%s'\n", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2986 | mFocusedWindowHandle != NULL ? mFocusedWindowHandle->getName().string() : "<null>"); |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 2987 | |
| 2988 | dump.appendFormat(INDENT "TouchDown: %s\n", toString(mTouchState.down)); |
| 2989 | dump.appendFormat(INDENT "TouchSplit: %s\n", toString(mTouchState.split)); |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 2990 | dump.appendFormat(INDENT "TouchDeviceId: %d\n", mTouchState.deviceId); |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 2991 | dump.appendFormat(INDENT "TouchSource: 0x%08x\n", mTouchState.source); |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 2992 | if (!mTouchState.windows.isEmpty()) { |
| 2993 | dump.append(INDENT "TouchedWindows:\n"); |
| 2994 | for (size_t i = 0; i < mTouchState.windows.size(); i++) { |
| 2995 | const TouchedWindow& touchedWindow = mTouchState.windows[i]; |
| 2996 | dump.appendFormat(INDENT2 "%d: name='%s', pointerIds=0x%0x, targetFlags=0x%x\n", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2997 | i, touchedWindow.windowHandle->getName().string(), |
| 2998 | touchedWindow.pointerIds.value, |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 2999 | touchedWindow.targetFlags); |
| 3000 | } |
| 3001 | } else { |
| 3002 | dump.append(INDENT "TouchedWindows: <none>\n"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3003 | } |
| 3004 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 3005 | if (!mWindowHandles.isEmpty()) { |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3006 | dump.append(INDENT "Windows:\n"); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 3007 | for (size_t i = 0; i < mWindowHandles.size(); i++) { |
| 3008 | const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3009 | const InputWindowInfo* windowInfo = windowHandle->getInfo(); |
| 3010 | |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3011 | dump.appendFormat(INDENT2 "%d: name='%s', paused=%s, hasFocus=%s, hasWallpaper=%s, " |
| 3012 | "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, " |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3013 | "frame=[%d,%d][%d,%d], scale=%f, " |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 3014 | "touchableRegion=", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3015 | i, windowInfo->name.string(), |
| 3016 | toString(windowInfo->paused), |
| 3017 | toString(windowInfo->hasFocus), |
| 3018 | toString(windowInfo->hasWallpaper), |
| 3019 | toString(windowInfo->visible), |
| 3020 | toString(windowInfo->canReceiveKeys), |
| 3021 | windowInfo->layoutParamsFlags, windowInfo->layoutParamsType, |
| 3022 | windowInfo->layer, |
| 3023 | windowInfo->frameLeft, windowInfo->frameTop, |
| 3024 | windowInfo->frameRight, windowInfo->frameBottom, |
| 3025 | windowInfo->scaleFactor); |
| 3026 | dumpRegion(dump, windowInfo->touchableRegion); |
| 3027 | dump.appendFormat(", inputFeatures=0x%08x", windowInfo->inputFeatures); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 3028 | dump.appendFormat(", ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3029 | windowInfo->ownerPid, windowInfo->ownerUid, |
| 3030 | windowInfo->dispatchingTimeout / 1000000.0); |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3031 | } |
| 3032 | } else { |
| 3033 | dump.append(INDENT "Windows: <none>\n"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3036 | if (!mMonitoringChannels.isEmpty()) { |
| 3037 | dump.append(INDENT "MonitoringChannels:\n"); |
| 3038 | for (size_t i = 0; i < mMonitoringChannels.size(); i++) { |
| 3039 | const sp<InputChannel>& channel = mMonitoringChannels[i]; |
| 3040 | dump.appendFormat(INDENT2 "%d: '%s'\n", i, channel->getName().string()); |
| 3041 | } |
| 3042 | } else { |
| 3043 | dump.append(INDENT "MonitoringChannels: <none>\n"); |
| 3044 | } |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3045 | |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3046 | dump.appendFormat(INDENT "InboundQueue: length=%u\n", mInboundQueue.count()); |
| 3047 | |
| 3048 | if (!mActiveConnections.isEmpty()) { |
| 3049 | dump.append(INDENT "ActiveConnections:\n"); |
| 3050 | for (size_t i = 0; i < mActiveConnections.size(); i++) { |
| 3051 | const Connection* connection = mActiveConnections[i]; |
Jeff Brown | 76860e3 | 2010-10-25 17:37:46 -0700 | [diff] [blame] | 3052 | dump.appendFormat(INDENT2 "%d: '%s', status=%s, outboundQueueLength=%u, " |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3053 | "inputState.isNeutral=%s\n", |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3054 | i, connection->getInputChannelName(), connection->getStatusLabel(), |
| 3055 | connection->outboundQueue.count(), |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3056 | toString(connection->inputState.isNeutral())); |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3057 | } |
| 3058 | } else { |
| 3059 | dump.append(INDENT "ActiveConnections: <none>\n"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | if (isAppSwitchPendingLocked()) { |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3063 | dump.appendFormat(INDENT "AppSwitch: pending, due in %01.1fms\n", |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3064 | (mAppSwitchDueTime - now()) / 1000000.0); |
| 3065 | } else { |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3066 | dump.append(INDENT "AppSwitch: not pending\n"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3067 | } |
| 3068 | } |
| 3069 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 3070 | status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChannel, |
| 3071 | const sp<InputWindowHandle>& inputWindowHandle, bool monitor) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3072 | #if DEBUG_REGISTRATION |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3073 | ALOGD("channel '%s' ~ registerInputChannel - monitor=%s", inputChannel->getName().string(), |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3074 | toString(monitor)); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3075 | #endif |
| 3076 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3077 | { // acquire lock |
| 3078 | AutoMutex _l(mLock); |
| 3079 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3080 | if (getConnectionIndexLocked(inputChannel) >= 0) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 3081 | ALOGW("Attempted to register already registered input channel '%s'", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3082 | inputChannel->getName().string()); |
| 3083 | return BAD_VALUE; |
| 3084 | } |
| 3085 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3086 | sp<Connection> connection = new Connection(inputChannel, inputWindowHandle, monitor); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3087 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 3088 | int32_t fd = inputChannel->getFd(); |
| 3089 | mConnectionsByFd.add(fd, connection); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3090 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3091 | if (monitor) { |
| 3092 | mMonitoringChannels.push(inputChannel); |
| 3093 | } |
| 3094 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 3095 | mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, handleReceiveCallback, this); |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 3096 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3097 | runCommandsLockedInterruptible(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3098 | } // release lock |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3099 | return OK; |
| 3100 | } |
| 3101 | |
| 3102 | status_t InputDispatcher::unregisterInputChannel(const sp<InputChannel>& inputChannel) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3103 | #if DEBUG_REGISTRATION |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3104 | ALOGD("channel '%s' ~ unregisterInputChannel", inputChannel->getName().string()); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3105 | #endif |
| 3106 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3107 | { // acquire lock |
| 3108 | AutoMutex _l(mLock); |
| 3109 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3110 | status_t status = unregisterInputChannelLocked(inputChannel, false /*notify*/); |
| 3111 | if (status) { |
| 3112 | return status; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3113 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3114 | } // release lock |
| 3115 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3116 | // Wake the poll loop because removing the connection may have changed the current |
| 3117 | // synchronization state. |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 3118 | mLooper->wake(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3119 | return OK; |
| 3120 | } |
| 3121 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3122 | status_t InputDispatcher::unregisterInputChannelLocked(const sp<InputChannel>& inputChannel, |
| 3123 | bool notify) { |
| 3124 | ssize_t connectionIndex = getConnectionIndexLocked(inputChannel); |
| 3125 | if (connectionIndex < 0) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 3126 | ALOGW("Attempted to unregister already unregistered input channel '%s'", |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3127 | inputChannel->getName().string()); |
| 3128 | return BAD_VALUE; |
| 3129 | } |
| 3130 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 3131 | sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex); |
| 3132 | mConnectionsByFd.removeItemsAt(connectionIndex); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3133 | |
| 3134 | if (connection->monitor) { |
| 3135 | removeMonitorChannelLocked(inputChannel); |
| 3136 | } |
| 3137 | |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 3138 | mLooper->removeFd(inputChannel->getFd()); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3139 | |
| 3140 | nsecs_t currentTime = now(); |
| 3141 | abortBrokenDispatchCycleLocked(currentTime, connection, notify); |
| 3142 | |
| 3143 | runCommandsLockedInterruptible(); |
| 3144 | |
| 3145 | connection->status = Connection::STATUS_ZOMBIE; |
| 3146 | return OK; |
| 3147 | } |
| 3148 | |
| 3149 | void InputDispatcher::removeMonitorChannelLocked(const sp<InputChannel>& inputChannel) { |
| 3150 | for (size_t i = 0; i < mMonitoringChannels.size(); i++) { |
| 3151 | if (mMonitoringChannels[i] == inputChannel) { |
| 3152 | mMonitoringChannels.removeAt(i); |
| 3153 | break; |
| 3154 | } |
| 3155 | } |
| 3156 | } |
| 3157 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3158 | ssize_t InputDispatcher::getConnectionIndexLocked(const sp<InputChannel>& inputChannel) { |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 3159 | ssize_t connectionIndex = mConnectionsByFd.indexOfKey(inputChannel->getFd()); |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 3160 | if (connectionIndex >= 0) { |
Jeff Brown | cbee6d6 | 2012-02-03 20:11:27 -0800 | [diff] [blame] | 3161 | sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex); |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 3162 | if (connection->inputChannel.get() == inputChannel.get()) { |
| 3163 | return connectionIndex; |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | return -1; |
| 3168 | } |
| 3169 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3170 | void InputDispatcher::activateConnectionLocked(Connection* connection) { |
| 3171 | for (size_t i = 0; i < mActiveConnections.size(); i++) { |
| 3172 | if (mActiveConnections.itemAt(i) == connection) { |
| 3173 | return; |
| 3174 | } |
| 3175 | } |
| 3176 | mActiveConnections.add(connection); |
| 3177 | } |
| 3178 | |
| 3179 | void InputDispatcher::deactivateConnectionLocked(Connection* connection) { |
| 3180 | for (size_t i = 0; i < mActiveConnections.size(); i++) { |
| 3181 | if (mActiveConnections.itemAt(i) == connection) { |
| 3182 | mActiveConnections.removeAt(i); |
| 3183 | return; |
| 3184 | } |
| 3185 | } |
| 3186 | } |
| 3187 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3188 | void InputDispatcher::onDispatchCycleStartedLocked( |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3189 | nsecs_t currentTime, const sp<Connection>& connection) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3190 | } |
| 3191 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3192 | void InputDispatcher::onDispatchCycleFinishedLocked( |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3193 | nsecs_t currentTime, const sp<Connection>& connection, bool handled) { |
| 3194 | CommandEntry* commandEntry = postCommandLocked( |
| 3195 | & InputDispatcher::doDispatchCycleFinishedLockedInterruptible); |
| 3196 | commandEntry->connection = connection; |
| 3197 | commandEntry->handled = handled; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3198 | } |
| 3199 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3200 | void InputDispatcher::onDispatchCycleBrokenLocked( |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3201 | nsecs_t currentTime, const sp<Connection>& connection) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 3202 | ALOGE("channel '%s' ~ Channel is unrecoverably broken and will be disposed!", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3203 | connection->getInputChannelName()); |
| 3204 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3205 | CommandEntry* commandEntry = postCommandLocked( |
| 3206 | & InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3207 | commandEntry->connection = connection; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3208 | } |
| 3209 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3210 | void InputDispatcher::onANRLocked( |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 3211 | nsecs_t currentTime, const sp<InputApplicationHandle>& applicationHandle, |
| 3212 | const sp<InputWindowHandle>& windowHandle, |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3213 | nsecs_t eventTime, nsecs_t waitStartTime) { |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 3214 | ALOGI("Application is not responding: %s. " |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3215 | "%01.1fms since event, %01.1fms since wait started", |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 3216 | getApplicationWindowLabelLocked(applicationHandle, windowHandle).string(), |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3217 | (currentTime - eventTime) / 1000000.0, |
| 3218 | (currentTime - waitStartTime) / 1000000.0); |
| 3219 | |
| 3220 | CommandEntry* commandEntry = postCommandLocked( |
| 3221 | & InputDispatcher::doNotifyANRLockedInterruptible); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 3222 | commandEntry->inputApplicationHandle = applicationHandle; |
| 3223 | commandEntry->inputWindowHandle = windowHandle; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3226 | void InputDispatcher::doNotifyConfigurationChangedInterruptible( |
| 3227 | CommandEntry* commandEntry) { |
| 3228 | mLock.unlock(); |
| 3229 | |
| 3230 | mPolicy->notifyConfigurationChanged(commandEntry->eventTime); |
| 3231 | |
| 3232 | mLock.lock(); |
| 3233 | } |
| 3234 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3235 | void InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible( |
| 3236 | CommandEntry* commandEntry) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3237 | sp<Connection> connection = commandEntry->connection; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3238 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3239 | if (connection->status != Connection::STATUS_ZOMBIE) { |
| 3240 | mLock.unlock(); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3241 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 3242 | mPolicy->notifyInputChannelBroken(connection->inputWindowHandle); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3243 | |
| 3244 | mLock.lock(); |
| 3245 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3246 | } |
| 3247 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3248 | void InputDispatcher::doNotifyANRLockedInterruptible( |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3249 | CommandEntry* commandEntry) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3250 | mLock.unlock(); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3251 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3252 | nsecs_t newTimeout = mPolicy->notifyANR( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 3253 | commandEntry->inputApplicationHandle, commandEntry->inputWindowHandle); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3254 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3255 | mLock.lock(); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3256 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 3257 | resumeAfterTargetsNotReadyTimeoutLocked(newTimeout, |
| 3258 | commandEntry->inputWindowHandle != NULL |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3259 | ? commandEntry->inputWindowHandle->getInputChannel() : NULL); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3262 | void InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible( |
| 3263 | CommandEntry* commandEntry) { |
| 3264 | KeyEntry* entry = commandEntry->keyEntry; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3265 | |
| 3266 | KeyEvent event; |
| 3267 | initializeKeyEvent(&event, entry); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3268 | |
| 3269 | mLock.unlock(); |
| 3270 | |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3271 | nsecs_t delay = mPolicy->interceptKeyBeforeDispatching(commandEntry->inputWindowHandle, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3272 | &event, entry->policyFlags); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3273 | |
| 3274 | mLock.lock(); |
| 3275 | |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3276 | if (delay < 0) { |
| 3277 | entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_SKIP; |
| 3278 | } else if (!delay) { |
| 3279 | entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_CONTINUE; |
| 3280 | } else { |
| 3281 | entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER; |
| 3282 | entry->interceptKeyWakeupTime = now() + delay; |
| 3283 | } |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3284 | entry->release(); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3287 | void InputDispatcher::doDispatchCycleFinishedLockedInterruptible( |
| 3288 | CommandEntry* commandEntry) { |
| 3289 | sp<Connection> connection = commandEntry->connection; |
| 3290 | bool handled = commandEntry->handled; |
| 3291 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3292 | bool skipNext = false; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3293 | if (!connection->outboundQueue.isEmpty()) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3294 | DispatchEntry* dispatchEntry = connection->outboundQueue.head; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3295 | if (dispatchEntry->inProgress) { |
| 3296 | if (dispatchEntry->eventEntry->type == EventEntry::TYPE_KEY) { |
| 3297 | KeyEntry* keyEntry = static_cast<KeyEntry*>(dispatchEntry->eventEntry); |
| 3298 | skipNext = afterKeyEventLockedInterruptible(connection, |
| 3299 | dispatchEntry, keyEntry, handled); |
| 3300 | } else if (dispatchEntry->eventEntry->type == EventEntry::TYPE_MOTION) { |
| 3301 | MotionEntry* motionEntry = static_cast<MotionEntry*>(dispatchEntry->eventEntry); |
| 3302 | skipNext = afterMotionEventLockedInterruptible(connection, |
| 3303 | dispatchEntry, motionEntry, handled); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3304 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3305 | } |
| 3306 | } |
| 3307 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3308 | if (!skipNext) { |
| 3309 | startNextDispatchCycleLocked(now(), connection); |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | bool InputDispatcher::afterKeyEventLockedInterruptible(const sp<Connection>& connection, |
| 3314 | DispatchEntry* dispatchEntry, KeyEntry* keyEntry, bool handled) { |
| 3315 | if (!(keyEntry->flags & AKEY_EVENT_FLAG_FALLBACK)) { |
| 3316 | // Get the fallback key state. |
| 3317 | // Clear it out after dispatching the UP. |
| 3318 | int32_t originalKeyCode = keyEntry->keyCode; |
| 3319 | int32_t fallbackKeyCode = connection->inputState.getFallbackKey(originalKeyCode); |
| 3320 | if (keyEntry->action == AKEY_EVENT_ACTION_UP) { |
| 3321 | connection->inputState.removeFallbackKey(originalKeyCode); |
| 3322 | } |
| 3323 | |
| 3324 | if (handled || !dispatchEntry->hasForegroundTarget()) { |
| 3325 | // If the application handles the original key for which we previously |
| 3326 | // generated a fallback or if the window is not a foreground window, |
| 3327 | // then cancel the associated fallback key, if any. |
| 3328 | if (fallbackKeyCode != -1) { |
| 3329 | if (fallbackKeyCode != AKEYCODE_UNKNOWN) { |
| 3330 | CancelationOptions options(CancelationOptions::CANCEL_FALLBACK_EVENTS, |
| 3331 | "application handled the original non-fallback key " |
| 3332 | "or is no longer a foreground target, " |
| 3333 | "canceling previously dispatched fallback key"); |
| 3334 | options.keyCode = fallbackKeyCode; |
| 3335 | synthesizeCancelationEventsForConnectionLocked(connection, options); |
| 3336 | } |
| 3337 | connection->inputState.removeFallbackKey(originalKeyCode); |
| 3338 | } |
| 3339 | } else { |
| 3340 | // If the application did not handle a non-fallback key, first check |
| 3341 | // that we are in a good state to perform unhandled key event processing |
| 3342 | // Then ask the policy what to do with it. |
| 3343 | bool initialDown = keyEntry->action == AKEY_EVENT_ACTION_DOWN |
| 3344 | && keyEntry->repeatCount == 0; |
| 3345 | if (fallbackKeyCode == -1 && !initialDown) { |
| 3346 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3347 | ALOGD("Unhandled key event: Skipping unhandled key event processing " |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3348 | "since this is not an initial down. " |
| 3349 | "keyCode=%d, action=%d, repeatCount=%d", |
| 3350 | originalKeyCode, keyEntry->action, keyEntry->repeatCount); |
| 3351 | #endif |
| 3352 | return false; |
| 3353 | } |
| 3354 | |
| 3355 | // Dispatch the unhandled key to the policy. |
| 3356 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3357 | ALOGD("Unhandled key event: Asking policy to perform fallback action. " |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3358 | "keyCode=%d, action=%d, repeatCount=%d", |
| 3359 | keyEntry->keyCode, keyEntry->action, keyEntry->repeatCount); |
| 3360 | #endif |
| 3361 | KeyEvent event; |
| 3362 | initializeKeyEvent(&event, keyEntry); |
| 3363 | |
| 3364 | mLock.unlock(); |
| 3365 | |
| 3366 | bool fallback = mPolicy->dispatchUnhandledKey(connection->inputWindowHandle, |
| 3367 | &event, keyEntry->policyFlags, &event); |
| 3368 | |
| 3369 | mLock.lock(); |
| 3370 | |
| 3371 | if (connection->status != Connection::STATUS_NORMAL) { |
| 3372 | connection->inputState.removeFallbackKey(originalKeyCode); |
| 3373 | return true; // skip next cycle |
| 3374 | } |
| 3375 | |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 3376 | ALOG_ASSERT(connection->outboundQueue.head == dispatchEntry); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3377 | |
| 3378 | // Latch the fallback keycode for this key on an initial down. |
| 3379 | // The fallback keycode cannot change at any other point in the lifecycle. |
| 3380 | if (initialDown) { |
| 3381 | if (fallback) { |
| 3382 | fallbackKeyCode = event.getKeyCode(); |
| 3383 | } else { |
| 3384 | fallbackKeyCode = AKEYCODE_UNKNOWN; |
| 3385 | } |
| 3386 | connection->inputState.setFallbackKey(originalKeyCode, fallbackKeyCode); |
| 3387 | } |
| 3388 | |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 3389 | ALOG_ASSERT(fallbackKeyCode != -1); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3390 | |
| 3391 | // Cancel the fallback key if the policy decides not to send it anymore. |
| 3392 | // We will continue to dispatch the key to the policy but we will no |
| 3393 | // longer dispatch a fallback key to the application. |
| 3394 | if (fallbackKeyCode != AKEYCODE_UNKNOWN |
| 3395 | && (!fallback || fallbackKeyCode != event.getKeyCode())) { |
| 3396 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
| 3397 | if (fallback) { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3398 | ALOGD("Unhandled key event: Policy requested to send key %d" |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3399 | "as a fallback for %d, but on the DOWN it had requested " |
| 3400 | "to send %d instead. Fallback canceled.", |
| 3401 | event.getKeyCode(), originalKeyCode, fallbackKeyCode); |
| 3402 | } else { |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3403 | ALOGD("Unhandled key event: Policy did not request fallback for %d," |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3404 | "but on the DOWN it had requested to send %d. " |
| 3405 | "Fallback canceled.", |
| 3406 | originalKeyCode, fallbackKeyCode); |
| 3407 | } |
| 3408 | #endif |
| 3409 | |
| 3410 | CancelationOptions options(CancelationOptions::CANCEL_FALLBACK_EVENTS, |
| 3411 | "canceling fallback, policy no longer desires it"); |
| 3412 | options.keyCode = fallbackKeyCode; |
| 3413 | synthesizeCancelationEventsForConnectionLocked(connection, options); |
| 3414 | |
| 3415 | fallback = false; |
| 3416 | fallbackKeyCode = AKEYCODE_UNKNOWN; |
| 3417 | if (keyEntry->action != AKEY_EVENT_ACTION_UP) { |
| 3418 | connection->inputState.setFallbackKey(originalKeyCode, |
| 3419 | fallbackKeyCode); |
| 3420 | } |
| 3421 | } |
| 3422 | |
| 3423 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
| 3424 | { |
| 3425 | String8 msg; |
| 3426 | const KeyedVector<int32_t, int32_t>& fallbackKeys = |
| 3427 | connection->inputState.getFallbackKeys(); |
| 3428 | for (size_t i = 0; i < fallbackKeys.size(); i++) { |
| 3429 | msg.appendFormat(", %d->%d", fallbackKeys.keyAt(i), |
| 3430 | fallbackKeys.valueAt(i)); |
| 3431 | } |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3432 | ALOGD("Unhandled key event: %d currently tracked fallback keys%s.", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3433 | fallbackKeys.size(), msg.string()); |
| 3434 | } |
| 3435 | #endif |
| 3436 | |
| 3437 | if (fallback) { |
| 3438 | // Restart the dispatch cycle using the fallback key. |
| 3439 | keyEntry->eventTime = event.getEventTime(); |
| 3440 | keyEntry->deviceId = event.getDeviceId(); |
| 3441 | keyEntry->source = event.getSource(); |
| 3442 | keyEntry->flags = event.getFlags() | AKEY_EVENT_FLAG_FALLBACK; |
| 3443 | keyEntry->keyCode = fallbackKeyCode; |
| 3444 | keyEntry->scanCode = event.getScanCode(); |
| 3445 | keyEntry->metaState = event.getMetaState(); |
| 3446 | keyEntry->repeatCount = event.getRepeatCount(); |
| 3447 | keyEntry->downTime = event.getDownTime(); |
| 3448 | keyEntry->syntheticRepeat = false; |
| 3449 | |
| 3450 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3451 | ALOGD("Unhandled key event: Dispatching fallback key. " |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3452 | "originalKeyCode=%d, fallbackKeyCode=%d, fallbackMetaState=%08x", |
| 3453 | originalKeyCode, fallbackKeyCode, keyEntry->metaState); |
| 3454 | #endif |
| 3455 | |
| 3456 | dispatchEntry->inProgress = false; |
| 3457 | startDispatchCycleLocked(now(), connection); |
| 3458 | return true; // already started next cycle |
| 3459 | } else { |
| 3460 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3461 | ALOGD("Unhandled key event: No fallback key."); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3462 | #endif |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | return false; |
| 3467 | } |
| 3468 | |
| 3469 | bool InputDispatcher::afterMotionEventLockedInterruptible(const sp<Connection>& connection, |
| 3470 | DispatchEntry* dispatchEntry, MotionEntry* motionEntry, bool handled) { |
| 3471 | return false; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3472 | } |
| 3473 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3474 | void InputDispatcher::doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) { |
| 3475 | mLock.unlock(); |
| 3476 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 3477 | mPolicy->pokeUserActivity(commandEntry->eventTime, commandEntry->userActivityEventType); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3478 | |
| 3479 | mLock.lock(); |
| 3480 | } |
| 3481 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3482 | void InputDispatcher::initializeKeyEvent(KeyEvent* event, const KeyEntry* entry) { |
| 3483 | event->initialize(entry->deviceId, entry->source, entry->action, entry->flags, |
| 3484 | entry->keyCode, entry->scanCode, entry->metaState, entry->repeatCount, |
| 3485 | entry->downTime, entry->eventTime); |
| 3486 | } |
| 3487 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3488 | void InputDispatcher::updateDispatchStatisticsLocked(nsecs_t currentTime, const EventEntry* entry, |
| 3489 | int32_t injectionResult, nsecs_t timeSpentWaitingForApplication) { |
| 3490 | // TODO Write some statistics about how long we spend waiting. |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | void InputDispatcher::dump(String8& dump) { |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 3494 | AutoMutex _l(mLock); |
| 3495 | |
Jeff Brown | f2f4871 | 2010-10-01 17:46:21 -0700 | [diff] [blame] | 3496 | dump.append("Input Dispatcher State:\n"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3497 | dumpDispatchStateLocked(dump); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 3498 | |
| 3499 | dump.append(INDENT "Configuration:\n"); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 3500 | dump.appendFormat(INDENT2 "KeyRepeatDelay: %0.1fms\n", mConfig.keyRepeatDelay * 0.000001f); |
| 3501 | dump.appendFormat(INDENT2 "KeyRepeatTimeout: %0.1fms\n", mConfig.keyRepeatTimeout * 0.000001f); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 3504 | void InputDispatcher::monitor() { |
| 3505 | // Acquire and release the lock to ensure that the dispatcher has not deadlocked. |
| 3506 | mLock.lock(); |
Jeff Brown | 112b5f5 | 2012-01-27 17:32:06 -0800 | [diff] [blame] | 3507 | mLooper->wake(); |
| 3508 | mDispatcherIsAliveCondition.wait(mLock); |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 3509 | mLock.unlock(); |
| 3510 | } |
| 3511 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3512 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3513 | // --- InputDispatcher::Queue --- |
| 3514 | |
| 3515 | template <typename T> |
| 3516 | uint32_t InputDispatcher::Queue<T>::count() const { |
| 3517 | uint32_t result = 0; |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3518 | for (const T* entry = head; entry; entry = entry->next) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 3519 | result += 1; |
| 3520 | } |
| 3521 | return result; |
| 3522 | } |
| 3523 | |
| 3524 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3525 | // --- InputDispatcher::InjectionState --- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3526 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3527 | InputDispatcher::InjectionState::InjectionState(int32_t injectorPid, int32_t injectorUid) : |
| 3528 | refCount(1), |
| 3529 | injectorPid(injectorPid), injectorUid(injectorUid), |
| 3530 | injectionResult(INPUT_EVENT_INJECTION_PENDING), injectionIsAsync(false), |
| 3531 | pendingForegroundDispatches(0) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3534 | InputDispatcher::InjectionState::~InjectionState() { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3537 | void InputDispatcher::InjectionState::release() { |
| 3538 | refCount -= 1; |
| 3539 | if (refCount == 0) { |
| 3540 | delete this; |
| 3541 | } else { |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 3542 | ALOG_ASSERT(refCount > 0); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 3543 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3544 | } |
| 3545 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3546 | |
| 3547 | // --- InputDispatcher::EventEntry --- |
| 3548 | |
| 3549 | InputDispatcher::EventEntry::EventEntry(int32_t type, nsecs_t eventTime, uint32_t policyFlags) : |
| 3550 | refCount(1), type(type), eventTime(eventTime), policyFlags(policyFlags), |
| 3551 | injectionState(NULL), dispatchInProgress(false) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3554 | InputDispatcher::EventEntry::~EventEntry() { |
| 3555 | releaseInjectionState(); |
| 3556 | } |
| 3557 | |
| 3558 | void InputDispatcher::EventEntry::release() { |
| 3559 | refCount -= 1; |
| 3560 | if (refCount == 0) { |
| 3561 | delete this; |
| 3562 | } else { |
Steve Block | ec193de | 2012-01-09 18:35:44 +0000 | [diff] [blame] | 3563 | ALOG_ASSERT(refCount > 0); |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3564 | } |
| 3565 | } |
| 3566 | |
| 3567 | void InputDispatcher::EventEntry::releaseInjectionState() { |
| 3568 | if (injectionState) { |
| 3569 | injectionState->release(); |
| 3570 | injectionState = NULL; |
| 3571 | } |
| 3572 | } |
| 3573 | |
| 3574 | |
| 3575 | // --- InputDispatcher::ConfigurationChangedEntry --- |
| 3576 | |
| 3577 | InputDispatcher::ConfigurationChangedEntry::ConfigurationChangedEntry(nsecs_t eventTime) : |
| 3578 | EventEntry(TYPE_CONFIGURATION_CHANGED, eventTime, 0) { |
| 3579 | } |
| 3580 | |
| 3581 | InputDispatcher::ConfigurationChangedEntry::~ConfigurationChangedEntry() { |
| 3582 | } |
| 3583 | |
| 3584 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3585 | // --- InputDispatcher::DeviceResetEntry --- |
| 3586 | |
| 3587 | InputDispatcher::DeviceResetEntry::DeviceResetEntry(nsecs_t eventTime, int32_t deviceId) : |
| 3588 | EventEntry(TYPE_DEVICE_RESET, eventTime, 0), |
| 3589 | deviceId(deviceId) { |
| 3590 | } |
| 3591 | |
| 3592 | InputDispatcher::DeviceResetEntry::~DeviceResetEntry() { |
| 3593 | } |
| 3594 | |
| 3595 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3596 | // --- InputDispatcher::KeyEntry --- |
| 3597 | |
| 3598 | InputDispatcher::KeyEntry::KeyEntry(nsecs_t eventTime, |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 3599 | int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action, |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3600 | int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3601 | int32_t repeatCount, nsecs_t downTime) : |
| 3602 | EventEntry(TYPE_KEY, eventTime, policyFlags), |
| 3603 | deviceId(deviceId), source(source), action(action), flags(flags), |
| 3604 | keyCode(keyCode), scanCode(scanCode), metaState(metaState), |
| 3605 | repeatCount(repeatCount), downTime(downTime), |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3606 | syntheticRepeat(false), interceptKeyResult(KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN), |
| 3607 | interceptKeyWakeupTime(0) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3610 | InputDispatcher::KeyEntry::~KeyEntry() { |
| 3611 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 3612 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3613 | void InputDispatcher::KeyEntry::recycle() { |
| 3614 | releaseInjectionState(); |
| 3615 | |
| 3616 | dispatchInProgress = false; |
| 3617 | syntheticRepeat = false; |
| 3618 | interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN; |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3619 | interceptKeyWakeupTime = 0; |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 3623 | // --- InputDispatcher::MotionEntry --- |
| 3624 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3625 | InputDispatcher::MotionEntry::MotionEntry(nsecs_t eventTime, |
| 3626 | int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action, int32_t flags, |
| 3627 | int32_t metaState, int32_t buttonState, |
| 3628 | int32_t edgeFlags, float xPrecision, float yPrecision, |
| 3629 | nsecs_t downTime, uint32_t pointerCount, |
| 3630 | const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) : |
| 3631 | EventEntry(TYPE_MOTION, eventTime, policyFlags), |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 3632 | eventTime(eventTime), |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3633 | deviceId(deviceId), source(source), action(action), flags(flags), |
| 3634 | metaState(metaState), buttonState(buttonState), edgeFlags(edgeFlags), |
| 3635 | xPrecision(xPrecision), yPrecision(yPrecision), |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 3636 | downTime(downTime), pointerCount(pointerCount) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3637 | for (uint32_t i = 0; i < pointerCount; i++) { |
| 3638 | this->pointerProperties[i].copyFrom(pointerProperties[i]); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 3639 | this->pointerCoords[i].copyFrom(pointerCoords[i]); |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3640 | } |
| 3641 | } |
| 3642 | |
| 3643 | InputDispatcher::MotionEntry::~MotionEntry() { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | |
| 3647 | // --- InputDispatcher::DispatchEntry --- |
| 3648 | |
| 3649 | InputDispatcher::DispatchEntry::DispatchEntry(EventEntry* eventEntry, |
| 3650 | int32_t targetFlags, float xOffset, float yOffset, float scaleFactor) : |
| 3651 | eventEntry(eventEntry), targetFlags(targetFlags), |
| 3652 | xOffset(xOffset), yOffset(yOffset), scaleFactor(scaleFactor), |
| 3653 | inProgress(false), |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 3654 | resolvedAction(0), resolvedFlags(0) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3655 | eventEntry->refCount += 1; |
| 3656 | } |
| 3657 | |
| 3658 | InputDispatcher::DispatchEntry::~DispatchEntry() { |
| 3659 | eventEntry->release(); |
| 3660 | } |
| 3661 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3662 | |
| 3663 | // --- InputDispatcher::InputState --- |
| 3664 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3665 | InputDispatcher::InputState::InputState() { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | InputDispatcher::InputState::~InputState() { |
| 3669 | } |
| 3670 | |
| 3671 | bool InputDispatcher::InputState::isNeutral() const { |
| 3672 | return mKeyMementos.isEmpty() && mMotionMementos.isEmpty(); |
| 3673 | } |
| 3674 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3675 | bool InputDispatcher::InputState::isHovering(int32_t deviceId, uint32_t source) const { |
| 3676 | for (size_t i = 0; i < mMotionMementos.size(); i++) { |
| 3677 | const MotionMemento& memento = mMotionMementos.itemAt(i); |
| 3678 | if (memento.deviceId == deviceId |
| 3679 | && memento.source == source |
| 3680 | && memento.hovering) { |
| 3681 | return true; |
| 3682 | } |
| 3683 | } |
| 3684 | return false; |
| 3685 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3686 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3687 | bool InputDispatcher::InputState::trackKey(const KeyEntry* entry, |
| 3688 | int32_t action, int32_t flags) { |
| 3689 | switch (action) { |
| 3690 | case AKEY_EVENT_ACTION_UP: { |
| 3691 | if (entry->flags & AKEY_EVENT_FLAG_FALLBACK) { |
| 3692 | for (size_t i = 0; i < mFallbackKeys.size(); ) { |
| 3693 | if (mFallbackKeys.valueAt(i) == entry->keyCode) { |
| 3694 | mFallbackKeys.removeItemsAt(i); |
| 3695 | } else { |
| 3696 | i += 1; |
| 3697 | } |
| 3698 | } |
| 3699 | } |
| 3700 | ssize_t index = findKeyMemento(entry); |
| 3701 | if (index >= 0) { |
| 3702 | mKeyMementos.removeAt(index); |
| 3703 | return true; |
| 3704 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3705 | /* FIXME: We can't just drop the key up event because that prevents creating |
| 3706 | * popup windows that are automatically shown when a key is held and then |
| 3707 | * dismissed when the key is released. The problem is that the popup will |
| 3708 | * not have received the original key down, so the key up will be considered |
| 3709 | * to be inconsistent with its observed state. We could perhaps handle this |
| 3710 | * by synthesizing a key down but that will cause other problems. |
| 3711 | * |
| 3712 | * So for now, allow inconsistent key up events to be dispatched. |
| 3713 | * |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3714 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3715 | ALOGD("Dropping inconsistent key up event: deviceId=%d, source=%08x, " |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3716 | "keyCode=%d, scanCode=%d", |
| 3717 | entry->deviceId, entry->source, entry->keyCode, entry->scanCode); |
| 3718 | #endif |
| 3719 | return false; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3720 | */ |
| 3721 | return true; |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | case AKEY_EVENT_ACTION_DOWN: { |
| 3725 | ssize_t index = findKeyMemento(entry); |
| 3726 | if (index >= 0) { |
| 3727 | mKeyMementos.removeAt(index); |
| 3728 | } |
| 3729 | addKeyMemento(entry, flags); |
| 3730 | return true; |
| 3731 | } |
| 3732 | |
| 3733 | default: |
| 3734 | return true; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3735 | } |
| 3736 | } |
| 3737 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3738 | bool InputDispatcher::InputState::trackMotion(const MotionEntry* entry, |
| 3739 | int32_t action, int32_t flags) { |
| 3740 | int32_t actionMasked = action & AMOTION_EVENT_ACTION_MASK; |
| 3741 | switch (actionMasked) { |
| 3742 | case AMOTION_EVENT_ACTION_UP: |
| 3743 | case AMOTION_EVENT_ACTION_CANCEL: { |
| 3744 | ssize_t index = findMotionMemento(entry, false /*hovering*/); |
| 3745 | if (index >= 0) { |
| 3746 | mMotionMementos.removeAt(index); |
| 3747 | return true; |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3748 | } |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3749 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3750 | ALOGD("Dropping inconsistent motion up or cancel event: deviceId=%d, source=%08x, " |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3751 | "actionMasked=%d", |
| 3752 | entry->deviceId, entry->source, actionMasked); |
| 3753 | #endif |
| 3754 | return false; |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3757 | case AMOTION_EVENT_ACTION_DOWN: { |
| 3758 | ssize_t index = findMotionMemento(entry, false /*hovering*/); |
| 3759 | if (index >= 0) { |
| 3760 | mMotionMementos.removeAt(index); |
| 3761 | } |
| 3762 | addMotionMemento(entry, flags, false /*hovering*/); |
| 3763 | return true; |
| 3764 | } |
| 3765 | |
| 3766 | case AMOTION_EVENT_ACTION_POINTER_UP: |
| 3767 | case AMOTION_EVENT_ACTION_POINTER_DOWN: |
| 3768 | case AMOTION_EVENT_ACTION_MOVE: { |
| 3769 | ssize_t index = findMotionMemento(entry, false /*hovering*/); |
| 3770 | if (index >= 0) { |
| 3771 | MotionMemento& memento = mMotionMementos.editItemAt(index); |
| 3772 | memento.setPointers(entry); |
| 3773 | return true; |
| 3774 | } |
Jeff Brown | 2e45fb6 | 2011-06-29 21:19:05 -0700 | [diff] [blame] | 3775 | if (actionMasked == AMOTION_EVENT_ACTION_MOVE |
| 3776 | && (entry->source & (AINPUT_SOURCE_CLASS_JOYSTICK |
| 3777 | | AINPUT_SOURCE_CLASS_NAVIGATION))) { |
| 3778 | // Joysticks and trackballs can send MOVE events without corresponding DOWN or UP. |
| 3779 | return true; |
| 3780 | } |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3781 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3782 | ALOGD("Dropping inconsistent motion pointer up/down or move event: " |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3783 | "deviceId=%d, source=%08x, actionMasked=%d", |
| 3784 | entry->deviceId, entry->source, actionMasked); |
| 3785 | #endif |
| 3786 | return false; |
| 3787 | } |
| 3788 | |
| 3789 | case AMOTION_EVENT_ACTION_HOVER_EXIT: { |
| 3790 | ssize_t index = findMotionMemento(entry, true /*hovering*/); |
| 3791 | if (index >= 0) { |
| 3792 | mMotionMementos.removeAt(index); |
| 3793 | return true; |
| 3794 | } |
| 3795 | #if DEBUG_OUTBOUND_EVENT_DETAILS |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 3796 | ALOGD("Dropping inconsistent motion hover exit event: deviceId=%d, source=%08x", |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3797 | entry->deviceId, entry->source); |
| 3798 | #endif |
| 3799 | return false; |
| 3800 | } |
| 3801 | |
| 3802 | case AMOTION_EVENT_ACTION_HOVER_ENTER: |
| 3803 | case AMOTION_EVENT_ACTION_HOVER_MOVE: { |
| 3804 | ssize_t index = findMotionMemento(entry, true /*hovering*/); |
| 3805 | if (index >= 0) { |
| 3806 | mMotionMementos.removeAt(index); |
| 3807 | } |
| 3808 | addMotionMemento(entry, flags, true /*hovering*/); |
| 3809 | return true; |
| 3810 | } |
| 3811 | |
| 3812 | default: |
| 3813 | return true; |
| 3814 | } |
| 3815 | } |
| 3816 | |
| 3817 | ssize_t InputDispatcher::InputState::findKeyMemento(const KeyEntry* entry) const { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3818 | for (size_t i = 0; i < mKeyMementos.size(); i++) { |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3819 | const KeyMemento& memento = mKeyMementos.itemAt(i); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3820 | if (memento.deviceId == entry->deviceId |
| 3821 | && memento.source == entry->source |
| 3822 | && memento.keyCode == entry->keyCode |
| 3823 | && memento.scanCode == entry->scanCode) { |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3824 | return i; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3825 | } |
| 3826 | } |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3827 | return -1; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3830 | ssize_t InputDispatcher::InputState::findMotionMemento(const MotionEntry* entry, |
| 3831 | bool hovering) const { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3832 | for (size_t i = 0; i < mMotionMementos.size(); i++) { |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3833 | const MotionMemento& memento = mMotionMementos.itemAt(i); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3834 | if (memento.deviceId == entry->deviceId |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3835 | && memento.source == entry->source |
| 3836 | && memento.hovering == hovering) { |
| 3837 | return i; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3838 | } |
| 3839 | } |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3840 | return -1; |
| 3841 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3842 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3843 | void InputDispatcher::InputState::addKeyMemento(const KeyEntry* entry, int32_t flags) { |
| 3844 | mKeyMementos.push(); |
| 3845 | KeyMemento& memento = mKeyMementos.editTop(); |
| 3846 | memento.deviceId = entry->deviceId; |
| 3847 | memento.source = entry->source; |
| 3848 | memento.keyCode = entry->keyCode; |
| 3849 | memento.scanCode = entry->scanCode; |
| 3850 | memento.flags = flags; |
| 3851 | memento.downTime = entry->downTime; |
| 3852 | } |
| 3853 | |
| 3854 | void InputDispatcher::InputState::addMotionMemento(const MotionEntry* entry, |
| 3855 | int32_t flags, bool hovering) { |
| 3856 | mMotionMementos.push(); |
| 3857 | MotionMemento& memento = mMotionMementos.editTop(); |
| 3858 | memento.deviceId = entry->deviceId; |
| 3859 | memento.source = entry->source; |
| 3860 | memento.flags = flags; |
| 3861 | memento.xPrecision = entry->xPrecision; |
| 3862 | memento.yPrecision = entry->yPrecision; |
| 3863 | memento.downTime = entry->downTime; |
| 3864 | memento.setPointers(entry); |
| 3865 | memento.hovering = hovering; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | void InputDispatcher::InputState::MotionMemento::setPointers(const MotionEntry* entry) { |
| 3869 | pointerCount = entry->pointerCount; |
| 3870 | for (uint32_t i = 0; i < entry->pointerCount; i++) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3871 | pointerProperties[i].copyFrom(entry->pointerProperties[i]); |
Jeff Brown | 3241b6b | 2012-02-03 15:08:02 -0800 | [diff] [blame] | 3872 | pointerCoords[i].copyFrom(entry->pointerCoords[i]); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3873 | } |
| 3874 | } |
| 3875 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3876 | void InputDispatcher::InputState::synthesizeCancelationEvents(nsecs_t currentTime, |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3877 | Vector<EventEntry*>& outEvents, const CancelationOptions& options) { |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3878 | for (size_t i = 0; i < mKeyMementos.size(); i++) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3879 | const KeyMemento& memento = mKeyMementos.itemAt(i); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3880 | if (shouldCancelKey(memento, options)) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3881 | outEvents.push(new KeyEntry(currentTime, |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3882 | memento.deviceId, memento.source, 0, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3883 | AKEY_EVENT_ACTION_UP, memento.flags | AKEY_EVENT_FLAG_CANCELED, |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3884 | memento.keyCode, memento.scanCode, 0, 0, memento.downTime)); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3885 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3888 | for (size_t i = 0; i < mMotionMementos.size(); i++) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3889 | const MotionMemento& memento = mMotionMementos.itemAt(i); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3890 | if (shouldCancelMotion(memento, options)) { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 3891 | outEvents.push(new MotionEntry(currentTime, |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3892 | memento.deviceId, memento.source, 0, |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 3893 | memento.hovering |
| 3894 | ? AMOTION_EVENT_ACTION_HOVER_EXIT |
| 3895 | : AMOTION_EVENT_ACTION_CANCEL, |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3896 | memento.flags, 0, 0, 0, |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3897 | memento.xPrecision, memento.yPrecision, memento.downTime, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3898 | memento.pointerCount, memento.pointerProperties, memento.pointerCoords)); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3899 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3900 | } |
| 3901 | } |
| 3902 | |
| 3903 | void InputDispatcher::InputState::clear() { |
| 3904 | mKeyMementos.clear(); |
| 3905 | mMotionMementos.clear(); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3906 | mFallbackKeys.clear(); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Jeff Brown | 9c9f1a3 | 2010-10-11 18:32:20 -0700 | [diff] [blame] | 3909 | void InputDispatcher::InputState::copyPointerStateTo(InputState& other) const { |
| 3910 | for (size_t i = 0; i < mMotionMementos.size(); i++) { |
| 3911 | const MotionMemento& memento = mMotionMementos.itemAt(i); |
| 3912 | if (memento.source & AINPUT_SOURCE_CLASS_POINTER) { |
| 3913 | for (size_t j = 0; j < other.mMotionMementos.size(); ) { |
| 3914 | const MotionMemento& otherMemento = other.mMotionMementos.itemAt(j); |
| 3915 | if (memento.deviceId == otherMemento.deviceId |
| 3916 | && memento.source == otherMemento.source) { |
| 3917 | other.mMotionMementos.removeAt(j); |
| 3918 | } else { |
| 3919 | j += 1; |
| 3920 | } |
| 3921 | } |
| 3922 | other.mMotionMementos.push(memento); |
| 3923 | } |
| 3924 | } |
| 3925 | } |
| 3926 | |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3927 | int32_t InputDispatcher::InputState::getFallbackKey(int32_t originalKeyCode) { |
| 3928 | ssize_t index = mFallbackKeys.indexOfKey(originalKeyCode); |
| 3929 | return index >= 0 ? mFallbackKeys.valueAt(index) : -1; |
| 3930 | } |
| 3931 | |
| 3932 | void InputDispatcher::InputState::setFallbackKey(int32_t originalKeyCode, |
| 3933 | int32_t fallbackKeyCode) { |
| 3934 | ssize_t index = mFallbackKeys.indexOfKey(originalKeyCode); |
| 3935 | if (index >= 0) { |
| 3936 | mFallbackKeys.replaceValueAt(index, fallbackKeyCode); |
| 3937 | } else { |
| 3938 | mFallbackKeys.add(originalKeyCode, fallbackKeyCode); |
| 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | void InputDispatcher::InputState::removeFallbackKey(int32_t originalKeyCode) { |
| 3943 | mFallbackKeys.removeItem(originalKeyCode); |
| 3944 | } |
| 3945 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3946 | bool InputDispatcher::InputState::shouldCancelKey(const KeyMemento& memento, |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3947 | const CancelationOptions& options) { |
| 3948 | if (options.keyCode != -1 && memento.keyCode != options.keyCode) { |
| 3949 | return false; |
| 3950 | } |
| 3951 | |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3952 | if (options.deviceId != -1 && memento.deviceId != options.deviceId) { |
| 3953 | return false; |
| 3954 | } |
| 3955 | |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3956 | switch (options.mode) { |
| 3957 | case CancelationOptions::CANCEL_ALL_EVENTS: |
| 3958 | case CancelationOptions::CANCEL_NON_POINTER_EVENTS: |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3959 | return true; |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3960 | case CancelationOptions::CANCEL_FALLBACK_EVENTS: |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3961 | return memento.flags & AKEY_EVENT_FLAG_FALLBACK; |
| 3962 | default: |
| 3963 | return false; |
| 3964 | } |
| 3965 | } |
| 3966 | |
| 3967 | bool InputDispatcher::InputState::shouldCancelMotion(const MotionMemento& memento, |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3968 | const CancelationOptions& options) { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 3969 | if (options.deviceId != -1 && memento.deviceId != options.deviceId) { |
| 3970 | return false; |
| 3971 | } |
| 3972 | |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3973 | switch (options.mode) { |
| 3974 | case CancelationOptions::CANCEL_ALL_EVENTS: |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3975 | return true; |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3976 | case CancelationOptions::CANCEL_POINTER_EVENTS: |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3977 | return memento.source & AINPUT_SOURCE_CLASS_POINTER; |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3978 | case CancelationOptions::CANCEL_NON_POINTER_EVENTS: |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3979 | return !(memento.source & AINPUT_SOURCE_CLASS_POINTER); |
| 3980 | default: |
| 3981 | return false; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 3982 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3986 | // --- InputDispatcher::Connection --- |
| 3987 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 3988 | InputDispatcher::Connection::Connection(const sp<InputChannel>& inputChannel, |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3989 | const sp<InputWindowHandle>& inputWindowHandle, bool monitor) : |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 3990 | status(STATUS_NORMAL), inputChannel(inputChannel), inputWindowHandle(inputWindowHandle), |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3991 | monitor(monitor), |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 3992 | inputPublisher(inputChannel), |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 3993 | lastEventTime(LONG_LONG_MAX), lastDispatchTime(LONG_LONG_MAX) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | InputDispatcher::Connection::~Connection() { |
| 3997 | } |
| 3998 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 3999 | const char* InputDispatcher::Connection::getStatusLabel() const { |
| 4000 | switch (status) { |
| 4001 | case STATUS_NORMAL: |
| 4002 | return "NORMAL"; |
| 4003 | |
| 4004 | case STATUS_BROKEN: |
| 4005 | return "BROKEN"; |
| 4006 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 4007 | case STATUS_ZOMBIE: |
| 4008 | return "ZOMBIE"; |
| 4009 | |
| 4010 | default: |
| 4011 | return "UNKNOWN"; |
| 4012 | } |
| 4013 | } |
| 4014 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4015 | InputDispatcher::DispatchEntry* InputDispatcher::Connection::findQueuedDispatchEntryForEvent( |
| 4016 | const EventEntry* eventEntry) const { |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 4017 | for (DispatchEntry* dispatchEntry = outboundQueue.tail; dispatchEntry; |
| 4018 | dispatchEntry = dispatchEntry->prev) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4019 | if (dispatchEntry->eventEntry == eventEntry) { |
| 4020 | return dispatchEntry; |
| 4021 | } |
| 4022 | } |
| 4023 | return NULL; |
| 4024 | } |
| 4025 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4026 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 4027 | // --- InputDispatcher::CommandEntry --- |
| 4028 | |
Jeff Brown | ac38607 | 2011-07-20 15:19:50 -0700 | [diff] [blame] | 4029 | InputDispatcher::CommandEntry::CommandEntry(Command command) : |
| 4030 | command(command), eventTime(0), keyEntry(NULL), userActivityEventType(0), handled(false) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | InputDispatcher::CommandEntry::~CommandEntry() { |
| 4034 | } |
| 4035 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4036 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4037 | // --- InputDispatcher::TouchState --- |
| 4038 | |
| 4039 | InputDispatcher::TouchState::TouchState() : |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 4040 | down(false), split(false), deviceId(-1), source(0) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | InputDispatcher::TouchState::~TouchState() { |
| 4044 | } |
| 4045 | |
| 4046 | void InputDispatcher::TouchState::reset() { |
| 4047 | down = false; |
| 4048 | split = false; |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 4049 | deviceId = -1; |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 4050 | source = 0; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4051 | windows.clear(); |
| 4052 | } |
| 4053 | |
| 4054 | void InputDispatcher::TouchState::copyFrom(const TouchState& other) { |
| 4055 | down = other.down; |
| 4056 | split = other.split; |
Jeff Brown | 9571285 | 2011-01-04 19:41:59 -0800 | [diff] [blame] | 4057 | deviceId = other.deviceId; |
Jeff Brown | 58a2da8 | 2011-01-25 16:02:22 -0800 | [diff] [blame] | 4058 | source = other.source; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 4059 | windows = other.windows; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 4062 | void InputDispatcher::TouchState::addOrUpdateWindow(const sp<InputWindowHandle>& windowHandle, |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4063 | int32_t targetFlags, BitSet32 pointerIds) { |
| 4064 | if (targetFlags & InputTarget::FLAG_SPLIT) { |
| 4065 | split = true; |
| 4066 | } |
| 4067 | |
| 4068 | for (size_t i = 0; i < windows.size(); i++) { |
| 4069 | TouchedWindow& touchedWindow = windows.editItemAt(i); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 4070 | if (touchedWindow.windowHandle == windowHandle) { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4071 | touchedWindow.targetFlags |= targetFlags; |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 4072 | if (targetFlags & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) { |
| 4073 | touchedWindow.targetFlags &= ~InputTarget::FLAG_DISPATCH_AS_IS; |
| 4074 | } |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4075 | touchedWindow.pointerIds.value |= pointerIds.value; |
| 4076 | return; |
| 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | windows.push(); |
| 4081 | |
| 4082 | TouchedWindow& touchedWindow = windows.editTop(); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 4083 | touchedWindow.windowHandle = windowHandle; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4084 | touchedWindow.targetFlags = targetFlags; |
| 4085 | touchedWindow.pointerIds = pointerIds; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 4088 | void InputDispatcher::TouchState::filterNonAsIsTouchWindows() { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4089 | for (size_t i = 0 ; i < windows.size(); ) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 4090 | TouchedWindow& window = windows.editItemAt(i); |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 4091 | if (window.targetFlags & (InputTarget::FLAG_DISPATCH_AS_IS |
| 4092 | | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER)) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 4093 | window.targetFlags &= ~InputTarget::FLAG_DISPATCH_MASK; |
| 4094 | window.targetFlags |= InputTarget::FLAG_DISPATCH_AS_IS; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4095 | i += 1; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 4096 | } else { |
| 4097 | windows.removeAt(i); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4098 | } |
| 4099 | } |
| 4100 | } |
| 4101 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 4102 | sp<InputWindowHandle> InputDispatcher::TouchState::getFirstForegroundWindowHandle() const { |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4103 | for (size_t i = 0; i < windows.size(); i++) { |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 4104 | const TouchedWindow& window = windows.itemAt(i); |
| 4105 | if (window.targetFlags & InputTarget::FLAG_FOREGROUND) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 4106 | return window.windowHandle; |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4107 | } |
| 4108 | } |
| 4109 | return NULL; |
| 4110 | } |
| 4111 | |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 4112 | bool InputDispatcher::TouchState::isSlippery() const { |
| 4113 | // Must have exactly one foreground window. |
| 4114 | bool haveSlipperyForegroundWindow = false; |
| 4115 | for (size_t i = 0; i < windows.size(); i++) { |
| 4116 | const TouchedWindow& window = windows.itemAt(i); |
| 4117 | if (window.targetFlags & InputTarget::FLAG_FOREGROUND) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 4118 | if (haveSlipperyForegroundWindow |
| 4119 | || !(window.windowHandle->getInfo()->layoutParamsFlags |
| 4120 | & InputWindowInfo::FLAG_SLIPPERY)) { |
Jeff Brown | 98db5fa | 2011-06-08 15:37:10 -0700 | [diff] [blame] | 4121 | return false; |
| 4122 | } |
| 4123 | haveSlipperyForegroundWindow = true; |
| 4124 | } |
| 4125 | } |
| 4126 | return haveSlipperyForegroundWindow; |
| 4127 | } |
| 4128 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 4129 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4130 | // --- InputDispatcherThread --- |
| 4131 | |
| 4132 | InputDispatcherThread::InputDispatcherThread(const sp<InputDispatcherInterface>& dispatcher) : |
| 4133 | Thread(/*canCallJava*/ true), mDispatcher(dispatcher) { |
| 4134 | } |
| 4135 | |
| 4136 | InputDispatcherThread::~InputDispatcherThread() { |
| 4137 | } |
| 4138 | |
| 4139 | bool InputDispatcherThread::threadLoop() { |
| 4140 | mDispatcher->dispatchOnce(); |
| 4141 | return true; |
| 4142 | } |
| 4143 | |
| 4144 | } // namespace android |