~dandrader/mir/acceptReject

« back to all changes in this revision

Viewing changes to 3rd_party/android-input/android/frameworks/base/services/input/InputDispatcher.cpp

  • Committer: Daniel d'Andrada
  • Date: 2013-10-24 21:20:59 UTC
  • Revision ID: daniel.dandrada@canonical.com-20131024212059-gzijb7o9cxk5cy1x
WIP - general housekeeping and first steps towards tests for InputDispatcher

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
//#define LOG_NDEBUG 0
21
21
 
22
22
// Log detailed debug messages about each inbound event notification to the dispatcher.
23
 
#define DEBUG_INBOUND_EVENT_DETAILS 0
 
23
#define DEBUG_INBOUND_EVENT_DETAILS 1
24
24
 
25
25
// Log detailed debug messages about each outbound event processed by the dispatcher.
26
 
#define DEBUG_OUTBOUND_EVENT_DETAILS 0
 
26
#define DEBUG_OUTBOUND_EVENT_DETAILS 1
27
27
 
28
28
// Log debug messages about the dispatch cycle.
29
 
#define DEBUG_DISPATCH_CYCLE 0
 
29
#define DEBUG_DISPATCH_CYCLE 1
30
30
 
31
31
// Log debug messages about registrations.
32
 
#define DEBUG_REGISTRATION 0
 
32
#define DEBUG_REGISTRATION 1
33
33
 
34
34
// Log debug messages about input event injection.
35
35
#define DEBUG_INJECTION 0
87
87
// Log a warning when an event takes longer than this to process, even if an ANR does not occur.
88
88
const nsecs_t SLOW_EVENT_PROCESSING_WARNING_TIMEOUT = 2000 * 1000000LL; // 2sec
89
89
 
90
 
 
91
 
static inline nsecs_t now() {
92
 
    return systemTime(SYSTEM_TIME_MONOTONIC);
93
 
}
 
90
class DefaultTimeSource : public TimeSourceInterface {
 
91
public:
 
92
    nsecs_t now() override {
 
93
        return systemTime(SYSTEM_TIME_MONOTONIC);
 
94
    }
 
95
};
94
96
 
95
97
static inline const char* toString(bool value) {
96
98
    return value ? "true" : "false";
148
150
        return false;
149
151
    }
150
152
    if (pointerCount < 1 || pointerCount > MAX_POINTERS) {
151
 
        ALOGE("Motion event has invalid pointer count %d; value must be between 1 and %d.",
 
153
        ALOGE("Motion event has invalid pointer count %zd; value must be between 1 and %d.",
152
154
                pointerCount, MAX_POINTERS);
153
155
        return false;
154
156
    }
178
180
        mPendingEvent(NULL), mAppSwitchSawKeyDown(false), mAppSwitchDueTime(LONG_LONG_MAX),
179
181
        mNextUnblockedEvent(NULL),
180
182
        mDispatchEnabled(false), mDispatchFrozen(false), mInputFilterEnabled(false),
181
 
        mInputTargetWaitCause(INPUT_TARGET_WAIT_CAUSE_NONE) {
 
183
        mInputTargetWaitCause(INPUT_TARGET_WAIT_CAUSE_NONE),
 
184
        mTimeSource(new DefaultTimeSource) {
182
185
    mLooper = new Looper(false);
183
186
 
184
187
    mKeyRepeatState.lastKeyEntry = NULL;
631
634
bool InputDispatcher::dispatchConfigurationChangedLocked(
632
635
        nsecs_t currentTime, ConfigurationChangedEntry* entry) {
633
636
#if DEBUG_OUTBOUND_EVENT_DETAILS
634
 
    ALOGD("dispatchConfigurationChanged - eventTime=%lld", entry->eventTime);
 
637
    ALOGD("dispatchConfigurationChanged - eventTime=%" PRINSECS, entry->eventTime);
635
638
#endif
636
639
 
637
640
    // Reset key repeating in case a keyboard device was added or removed or something.
647
650
bool InputDispatcher::dispatchDeviceResetLocked(
648
651
        nsecs_t currentTime, DeviceResetEntry* entry) {
649
652
#if DEBUG_OUTBOUND_EVENT_DETAILS
650
 
    ALOGD("dispatchDeviceReset - eventTime=%lld, deviceId=%d", entry->eventTime, entry->deviceId);
 
653
    ALOGD("dispatchDeviceReset - eventTime=%" PRINSECS ", deviceId=%d", entry->eventTime, entry->deviceId);
651
654
#endif
652
655
 
653
656
    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS,
757
760
 
758
761
void InputDispatcher::logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry) {
759
762
#if DEBUG_OUTBOUND_EVENT_DETAILS
760
 
    ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
 
763
    ALOGD("%seventTime=%" PRINSECS ", deviceId=%d, source=0x%x, policyFlags=0x%x, "
761
764
            "action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, "
762
 
            "repeatCount=%d, downTime=%lld",
 
765
            "repeatCount=%d, downTime=%" PRINSECS,
763
766
            prefix,
764
767
            entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
765
768
            entry->action, entry->flags, entry->keyCode, entry->scanCode, entry->metaState,
823
826
 
824
827
void InputDispatcher::logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry) {
825
828
#if DEBUG_OUTBOUND_EVENT_DETAILS
826
 
    ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
 
829
    ALOGD("%seventTime=%" PRINSECS ", deviceId=%d, source=0x%x, policyFlags=0x%x, "
827
830
            "action=0x%x, flags=0x%x, "
828
831
            "metaState=0x%x, buttonState=0x%x, "
829
 
            "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%lld",
 
832
            "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%" PRINSECS,
830
833
            prefix,
831
834
            entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
832
835
            entry->action, entry->flags,
1696
1699
    std::string pointerIdsString = inputTarget->pointerIds.toString();
1697
1700
    ALOGD("channel '%s' ~ prepareDispatchCycle - flags=0x%08x, "
1698
1701
            "xOffset=%f, yOffset=%f, scaleFactor=%f, "
1699
 
            "pointerIds=%s",
 
1702
            "pointerIds=(%s)",
1700
1703
            connection->getInputChannelName(), inputTarget->flags,
1701
1704
            inputTarget->xOffset, inputTarget->yOffset,
1702
1705
            inputTarget->scaleFactor, pointerIdsString.c_str());
2046
2049
                return 1;
2047
2050
            }
2048
2051
 
2049
 
            nsecs_t currentTime = now();
 
2052
            nsecs_t currentTime = d->now();
2050
2053
            bool gotOneFinished = false;
2051
2054
            status_t status;
2052
2055
            for (;;) {
2127
2130
 
2128
2131
    if (!cancelationEvents.isEmpty()) {
2129
2132
#if DEBUG_OUTBOUND_EVENT_DETAILS
2130
 
        ALOGD("channel '%s' ~ Synthesized %d cancelation events to bring channel back in sync "
 
2133
        ALOGD("channel '%s' ~ Synthesized %zu cancelation events to bring channel back in sync "
2131
2134
                "with reality: %s, mode=%d.",
2132
2135
                connection->getInputChannelName(), cancelationEvents.size(),
2133
2136
                options.reason, options.mode);
2202
2205
        // or ACTION_POINTER_DOWN events that caused us to decide to split the pointers
2203
2206
        // in this way.
2204
2207
        ALOGW("Dropping split motion event because the pointer count is %d but "
2205
 
                "we expected there to be %d pointers.  This probably means we received "
 
2208
                "we expected there to be %zu pointers.  This probably means we received "
2206
2209
                "a broken sequence of pointer ids from the input device.",
2207
2210
                splitPointerCount, pointerIds.count());
2208
2211
        return NULL;
2261
2264
 
2262
2265
void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
2263
2266
#if DEBUG_INBOUND_EVENT_DETAILS
2264
 
    ALOGD("notifyConfigurationChanged - eventTime=%lld", args->eventTime);
 
2267
    ALOGD("notifyConfigurationChanged - eventTime=%" PRINSECS, args->eventTime);
2265
2268
#endif
2266
2269
 
2267
2270
    bool needWake;
2279
2282
 
2280
2283
void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {
2281
2284
#if DEBUG_INBOUND_EVENT_DETAILS
2282
 
    ALOGD("notifyKey - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, action=0x%x, "
2283
 
            "flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%lld",
 
2285
    ALOGD("notifyKey - eventTime=%" PRINSECS ", deviceId=%d, source=0x%x, policyFlags=0x%x, action=0x%x, "
 
2286
            "flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%" PRINSECS,
2284
2287
            args->eventTime, args->deviceId, args->source, args->policyFlags,
2285
2288
            args->action, args->flags, args->keyCode, args->scanCode,
2286
2289
            args->metaState, args->downTime);
2357
2360
 
2358
2361
void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) {
2359
2362
#if DEBUG_INBOUND_EVENT_DETAILS
2360
 
    ALOGD("notifyMotion - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
 
2363
    ALOGD("notifyMotion - eventTime=%" PRINSECS ", deviceId=%d, source=0x%x, policyFlags=0x%x, "
2361
2364
            "action=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x, edgeFlags=0x%x, "
2362
 
            "xPrecision=%f, yPrecision=%f, downTime=%lld",
 
2365
            "xPrecision=%f, yPrecision=%f, downTime=%" PRINSECS,
2363
2366
            args->eventTime, args->deviceId, args->source, args->policyFlags,
2364
2367
            args->action, args->flags, args->metaState, args->buttonState,
2365
2368
            args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime);
2429
2432
 
2430
2433
void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) {
2431
2434
#if DEBUG_INBOUND_EVENT_DETAILS
2432
 
    ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchCode=%d, switchValue=%d",
 
2435
    ALOGD("notifySwitch - eventTime=%" PRINSECS ", policyFlags=0x%x, switchCode=%d, switchValue=%d",
2433
2436
            args->eventTime, args->policyFlags,
2434
2437
            args->switchCode, args->switchValue);
2435
2438
#endif
2442
2445
 
2443
2446
void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
2444
2447
#if DEBUG_INBOUND_EVENT_DETAILS
2445
 
    ALOGD("notifyDeviceReset - eventTime=%lld, deviceId=%d",
 
2448
    ALOGD("notifyDeviceReset - eventTime=%" PRINSECS ", deviceId=%d",
2446
2449
            args->eventTime, args->deviceId);
2447
2450
#endif
2448
2451
 
3026
3029
    mEnumerator->for_each([&](sp<InputWindowHandle> const& windowHandle){
3027
3030
        const InputWindowInfo* windowInfo = windowHandle->getInfo();
3028
3031
 
3029
 
        appendFormat(dump, INDENT2 "name='%s', paused=%s, hasFocus=%s, hasWallpaper=%s, "
 
3032
        appendFormat(dump, INDENT2 "name='%s', paused=%s, hasWallpaper=%s, "
3030
3033
                "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, "
3031
3034
                "frame=[%d,%d][%d,%d], scale=%f, "
3032
3035
                "touchableRegion=[%d,%d][%d,%d]",
3033
3036
                c_str(windowInfo->name),
3034
3037
                toString(windowInfo->paused),
3035
 
                toString(windowInfo->hasFocus),
3036
3038
                toString(windowInfo->hasWallpaper),
3037
3039
                toString(windowInfo->visible),
3038
3040
                toString(windowInfo->canReceiveKeys),
3533
3535
                    appendFormat(msg, ", %d->%d", fallbackKeys.keyAt(i),
3534
3536
                            fallbackKeys.valueAt(i));
3535
3537
                }
3536
 
                ALOGD("Unhandled key event: %d currently tracked fallback keys%s.",
 
3538
                ALOGD("Unhandled key event: %zu currently tracked fallback keys%s.",
3537
3539
                        fallbackKeys.size(), c_str(msg));
3538
3540
            }
3539
3541
#endif