Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1aa6a1d authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "Minor logging changes to input dispatcher to help with debugging." into gingerbread

parents db193288 2806e381
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -181,6 +181,8 @@ public:
     */
     */
    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
            uint8_t* outFlags) const = 0;
            uint8_t* outFlags) const = 0;

    virtual void dump(String8& dump) = 0;
};
};


class EventHub : public EventHubInterface
class EventHub : public EventHubInterface
@@ -211,6 +213,8 @@ public:


    virtual bool getEvent(RawEvent* outEvent);
    virtual bool getEvent(RawEvent* outEvent);


    virtual void dump(String8& dump);

protected:
protected:
    virtual ~EventHub();
    virtual ~EventHub();
    
    
@@ -239,8 +243,8 @@ private:
        ~device_t();
        ~device_t();
    };
    };


    device_t* getDevice(int32_t deviceId) const;
    device_t* getDeviceLocked(int32_t deviceId) const;
    bool hasKeycode(device_t* device, int keycode) const;
    bool hasKeycodeLocked(device_t* device, int keycode) const;
    
    
    int32_t getScanCodeStateLocked(device_t* device, int32_t scanCode) const;
    int32_t getScanCodeStateLocked(device_t* device, int32_t scanCode) const;
    int32_t getKeyCodeStateLocked(device_t* device, int32_t keyCode) const;
    int32_t getKeyCodeStateLocked(device_t* device, int32_t keyCode) const;
+56 −18
Original line number Original line Diff line number Diff line
@@ -73,6 +73,10 @@
#define ABS_MT_POSITION_Y       0x36    /* Center Y ellipse position */
#define ABS_MT_POSITION_Y       0x36    /* Center Y ellipse position */
#endif
#endif


#define INDENT "  "
#define INDENT2 "    "
#define INDENT3 "      "

namespace android {
namespace android {


static const char *WAKE_LOCK_ID = "KeyEvents";
static const char *WAKE_LOCK_ID = "KeyEvents";
@@ -84,6 +88,10 @@ static inline int max(int v1, int v2)
    return (v1 > v2) ? v1 : v2;
    return (v1 > v2) ? v1 : v2;
}
}


static inline const char* toString(bool value) {
    return value ? "true" : "false";
}

EventHub::device_t::device_t(int32_t _id, const char* _path, const char* name)
EventHub::device_t::device_t(int32_t _id, const char* _path, const char* name)
    : id(_id), path(_path), name(name), classes(0)
    : id(_id), path(_path), name(name), classes(0)
    , keyBitmask(NULL), layoutMap(new KeyLayoutMap()), fd(-1), next(NULL) {
    , keyBitmask(NULL), layoutMap(new KeyLayoutMap()), fd(-1), next(NULL) {
@@ -124,7 +132,7 @@ status_t EventHub::errorCheck() const
String8 EventHub::getDeviceName(int32_t deviceId) const
String8 EventHub::getDeviceName(int32_t deviceId) const
{
{
    AutoMutex _l(mLock);
    AutoMutex _l(mLock);
    device_t* device = getDevice(deviceId);
    device_t* device = getDeviceLocked(deviceId);
    if (device == NULL) return String8();
    if (device == NULL) return String8();
    return device->name;
    return device->name;
}
}
@@ -132,7 +140,7 @@ String8 EventHub::getDeviceName(int32_t deviceId) const
uint32_t EventHub::getDeviceClasses(int32_t deviceId) const
uint32_t EventHub::getDeviceClasses(int32_t deviceId) const
{
{
    AutoMutex _l(mLock);
    AutoMutex _l(mLock);
    device_t* device = getDevice(deviceId);
    device_t* device = getDeviceLocked(deviceId);
    if (device == NULL) return 0;
    if (device == NULL) return 0;
    return device->classes;
    return device->classes;
}
}
@@ -142,7 +150,7 @@ status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
    outAxisInfo->clear();
    outAxisInfo->clear();


    AutoMutex _l(mLock);
    AutoMutex _l(mLock);
    device_t* device = getDevice(deviceId);
    device_t* device = getDeviceLocked(deviceId);
    if (device == NULL) return -1;
    if (device == NULL) return -1;


    struct input_absinfo info;
    struct input_absinfo info;
@@ -167,7 +175,7 @@ int32_t EventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const {
    if (scanCode >= 0 && scanCode <= KEY_MAX) {
    if (scanCode >= 0 && scanCode <= KEY_MAX) {
        AutoMutex _l(mLock);
        AutoMutex _l(mLock);


        device_t* device = getDevice(deviceId);
        device_t* device = getDeviceLocked(deviceId);
        if (device != NULL) {
        if (device != NULL) {
            return getScanCodeStateLocked(device, scanCode);
            return getScanCodeStateLocked(device, scanCode);
        }
        }
@@ -188,7 +196,7 @@ int32_t EventHub::getScanCodeStateLocked(device_t* device, int32_t scanCode) con
int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
    AutoMutex _l(mLock);
    AutoMutex _l(mLock);


    device_t* device = getDevice(deviceId);
    device_t* device = getDeviceLocked(deviceId);
    if (device != NULL) {
    if (device != NULL) {
        return getKeyCodeStateLocked(device, keyCode);
        return getKeyCodeStateLocked(device, keyCode);
    }
    }
@@ -225,7 +233,7 @@ int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const {
    if (sw >= 0 && sw <= SW_MAX) {
    if (sw >= 0 && sw <= SW_MAX) {
        AutoMutex _l(mLock);
        AutoMutex _l(mLock);


        device_t* device = getDevice(deviceId);
        device_t* device = getDeviceLocked(deviceId);
        if (device != NULL) {
        if (device != NULL) {
            return getSwitchStateLocked(device, sw);
            return getSwitchStateLocked(device, sw);
        }
        }
@@ -248,7 +256,7 @@ bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
        const int32_t* keyCodes, uint8_t* outFlags) const {
        const int32_t* keyCodes, uint8_t* outFlags) const {
    AutoMutex _l(mLock);
    AutoMutex _l(mLock);


    device_t* device = getDevice(deviceId);
    device_t* device = getDeviceLocked(deviceId);
    if (device != NULL) {
    if (device != NULL) {
        return markSupportedKeyCodesLocked(device, numCodes, keyCodes, outFlags);
        return markSupportedKeyCodesLocked(device, numCodes, keyCodes, outFlags);
    }
    }
@@ -284,7 +292,7 @@ status_t EventHub::scancodeToKeycode(int32_t deviceId, int scancode,
        int32_t* outKeycode, uint32_t* outFlags) const
        int32_t* outKeycode, uint32_t* outFlags) const
{
{
    AutoMutex _l(mLock);
    AutoMutex _l(mLock);
    device_t* device = getDevice(deviceId);
    device_t* device = getDeviceLocked(deviceId);
    
    
    if (device != NULL && device->layoutMap != NULL) {
    if (device != NULL && device->layoutMap != NULL) {
        status_t err = device->layoutMap->map(scancode, outKeycode, outFlags);
        status_t err = device->layoutMap->map(scancode, outKeycode, outFlags);
@@ -294,7 +302,7 @@ status_t EventHub::scancodeToKeycode(int32_t deviceId, int scancode,
    }
    }
    
    
    if (mHaveFirstKeyboard) {
    if (mHaveFirstKeyboard) {
        device = getDevice(mFirstKeyboardId);
        device = getDeviceLocked(mFirstKeyboardId);
        
        
        if (device != NULL && device->layoutMap != NULL) {
        if (device != NULL && device->layoutMap != NULL) {
            status_t err = device->layoutMap->map(scancode, outKeycode, outFlags);
            status_t err = device->layoutMap->map(scancode, outKeycode, outFlags);
@@ -311,11 +319,13 @@ status_t EventHub::scancodeToKeycode(int32_t deviceId, int scancode,


void EventHub::addExcludedDevice(const char* deviceName)
void EventHub::addExcludedDevice(const char* deviceName)
{
{
    AutoMutex _l(mLock);

    String8 name(deviceName);
    String8 name(deviceName);
    mExcludedDevices.push_back(name);
    mExcludedDevices.push_back(name);
}
}


EventHub::device_t* EventHub::getDevice(int32_t deviceId) const
EventHub::device_t* EventHub::getDeviceLocked(int32_t deviceId) const
{
{
    if (deviceId == 0) deviceId = mFirstKeyboardId;
    if (deviceId == 0) deviceId = mFirstKeyboardId;
    int32_t id = deviceId & ID_MASK;
    int32_t id = deviceId & ID_MASK;
@@ -782,22 +792,22 @@ int EventHub::open_device(const char *deviceName)
        property_set(propName, name);
        property_set(propName, name);


        // 'Q' key support = cheap test of whether this is an alpha-capable kbd
        // 'Q' key support = cheap test of whether this is an alpha-capable kbd
        if (hasKeycode(device, AKEYCODE_Q)) {
        if (hasKeycodeLocked(device, AKEYCODE_Q)) {
            device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
            device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
        }
        }
        
        
        // See if this device has a DPAD.
        // See if this device has a DPAD.
        if (hasKeycode(device, AKEYCODE_DPAD_UP) &&
        if (hasKeycodeLocked(device, AKEYCODE_DPAD_UP) &&
                hasKeycode(device, AKEYCODE_DPAD_DOWN) &&
                hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) &&
                hasKeycode(device, AKEYCODE_DPAD_LEFT) &&
                hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) &&
                hasKeycode(device, AKEYCODE_DPAD_RIGHT) &&
                hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) &&
                hasKeycode(device, AKEYCODE_DPAD_CENTER)) {
                hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) {
            device->classes |= INPUT_DEVICE_CLASS_DPAD;
            device->classes |= INPUT_DEVICE_CLASS_DPAD;
        }
        }
        
        
        // See if this device has a gamepad.
        // See if this device has a gamepad.
        for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES); i++) {
        for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES); i++) {
            if (hasKeycode(device, GAMEPAD_KEYCODES[i])) {
            if (hasKeycodeLocked(device, GAMEPAD_KEYCODES[i])) {
                device->classes |= INPUT_DEVICE_CLASS_GAMEPAD;
                device->classes |= INPUT_DEVICE_CLASS_GAMEPAD;
                break;
                break;
            }
            }
@@ -830,7 +840,7 @@ int EventHub::open_device(const char *deviceName)
    return 0;
    return 0;
}
}


bool EventHub::hasKeycode(device_t* device, int keycode) const
bool EventHub::hasKeycodeLocked(device_t* device, int keycode) const
{
{
    if (device->keyBitmask == NULL || device->layoutMap == NULL) {
    if (device->keyBitmask == NULL || device->layoutMap == NULL) {
        return false;
        return false;
@@ -972,4 +982,32 @@ int EventHub::scan_dir(const char *dirname)
    return 0;
    return 0;
}
}


void EventHub::dump(String8& dump) {
    dump.append("Event Hub State:\n");

    { // acquire lock
        AutoMutex _l(mLock);

        dump.appendFormat(INDENT "HaveFirstKeyboard: %s\n", toString(mHaveFirstKeyboard));
        dump.appendFormat(INDENT "FirstKeyboardId: 0x%x\n", mFirstKeyboardId);

        dump.append(INDENT "Devices:\n");

        for (int i = 0; i < mNumDevicesById; i++) {
            const device_t* device = mDevicesById[i].device;
            if (device) {
                if (mFirstKeyboardId == device->id) {
                    dump.appendFormat(INDENT2 "0x%x: %s (aka device 0 - first keyboard)\n",
                            device->id, device->name.string());
                } else {
                    dump.appendFormat(INDENT2 "0x%x: %s\n", device->id, device->name.string());
                }
                dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes);
                dump.appendFormat(INDENT3 "Path: %s\n", device->path.string());
                dump.appendFormat(INDENT3 "KeyLayoutFile: %s\n", device->keylayoutFilename.string());
            }
        }
    } // release lock
}

}; // namespace android
}; // namespace android
+77 −51
Original line number Original line Diff line number Diff line
@@ -46,6 +46,9 @@
#include <errno.h>
#include <errno.h>
#include <limits.h>
#include <limits.h>


#define INDENT "  "
#define INDENT2 "    "

namespace android {
namespace android {


// Delay between reporting long touch events to the power manager.
// Delay between reporting long touch events to the power manager.
@@ -2490,74 +2493,96 @@ void InputDispatcher::logDispatchStateLocked() {
}
}


void InputDispatcher::dumpDispatchStateLocked(String8& dump) {
void InputDispatcher::dumpDispatchStateLocked(String8& dump) {
    dump.appendFormat("  dispatchEnabled: %d\n", mDispatchEnabled);
    dump.appendFormat(INDENT "DispatchEnabled: %d\n", mDispatchEnabled);
    dump.appendFormat("  dispatchFrozen: %d\n", mDispatchFrozen);
    dump.appendFormat(INDENT "DispatchFrozen: %d\n", mDispatchFrozen);


    if (mFocusedApplication) {
    if (mFocusedApplication) {
        dump.appendFormat("  focusedApplication: name='%s', dispatchingTimeout=%0.3fms\n",
        dump.appendFormat(INDENT "FocusedApplication: name='%s', dispatchingTimeout=%0.3fms\n",
                mFocusedApplication->name.string(),
                mFocusedApplication->name.string(),
                mFocusedApplication->dispatchingTimeout / 1000000.0);
                mFocusedApplication->dispatchingTimeout / 1000000.0);
    } else {
    } else {
        dump.append("  focusedApplication: <null>\n");
        dump.append(INDENT "FocusedApplication: <null>\n");
    }
    }
    dump.appendFormat("  focusedWindow: name='%s'\n",
    dump.appendFormat(INDENT "FocusedWindow: name='%s'\n",
            mFocusedWindow != NULL ? mFocusedWindow->name.string() : "<null>");
            mFocusedWindow != NULL ? mFocusedWindow->name.string() : "<null>");
    dump.appendFormat("  touchState: down=%s, split=%s\n", toString(mTouchState.down),

            toString(mTouchState.split));
    dump.appendFormat(INDENT "TouchDown: %s\n", toString(mTouchState.down));
    dump.appendFormat(INDENT "TouchSplit: %s\n", toString(mTouchState.split));
    if (!mTouchState.windows.isEmpty()) {
        dump.append(INDENT "TouchedWindows:\n");
        for (size_t i = 0; i < mTouchState.windows.size(); i++) {
        for (size_t i = 0; i < mTouchState.windows.size(); i++) {
            const TouchedWindow& touchedWindow = mTouchState.windows[i];
            const TouchedWindow& touchedWindow = mTouchState.windows[i];
        dump.appendFormat("  touchedWindow[%d]: name='%s', pointerIds=0x%0x, targetFlags=0x%x\n",
            dump.appendFormat(INDENT2 "%d: name='%s', pointerIds=0x%0x, targetFlags=0x%x\n",
                    i, touchedWindow.window->name.string(), touchedWindow.pointerIds.value,
                    i, touchedWindow.window->name.string(), touchedWindow.pointerIds.value,
                    touchedWindow.targetFlags);
                    touchedWindow.targetFlags);
        }
        }
    } else {
        dump.append(INDENT "TouchedWindows: <none>\n");
    }

    if (!mWindows.isEmpty()) {
        dump.append(INDENT "Windows:\n");
        for (size_t i = 0; i < mWindows.size(); i++) {
        for (size_t i = 0; i < mWindows.size(); i++) {
        dump.appendFormat("  windows[%d]: name='%s', paused=%s, hasFocus=%s, hasWallpaper=%s, "
            const InputWindow& window = mWindows[i];
            dump.appendFormat(INDENT2 "%d: name='%s', paused=%s, hasFocus=%s, hasWallpaper=%s, "
                    "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, "
                    "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, "
                    "frame=[%d,%d][%d,%d], "
                    "frame=[%d,%d][%d,%d], "
                    "visibleFrame=[%d,%d][%d,%d], "
                    "visibleFrame=[%d,%d][%d,%d], "
                    "touchableArea=[%d,%d][%d,%d], "
                    "touchableArea=[%d,%d][%d,%d], "
                    "ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n",
                    "ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n",
                i, mWindows[i].name.string(),
                    i, window.name.string(),
                toString(mWindows[i].paused),
                    toString(window.paused),
                toString(mWindows[i].hasFocus),
                    toString(window.hasFocus),
                toString(mWindows[i].hasWallpaper),
                    toString(window.hasWallpaper),
                toString(mWindows[i].visible),
                    toString(window.visible),
                toString(mWindows[i].canReceiveKeys),
                    toString(window.canReceiveKeys),
                mWindows[i].layoutParamsFlags, mWindows[i].layoutParamsType,
                    window.layoutParamsFlags, window.layoutParamsType,
                mWindows[i].layer,
                    window.layer,
                mWindows[i].frameLeft, mWindows[i].frameTop,
                    window.frameLeft, window.frameTop,
                mWindows[i].frameRight, mWindows[i].frameBottom,
                    window.frameRight, window.frameBottom,
                mWindows[i].visibleFrameLeft, mWindows[i].visibleFrameTop,
                    window.visibleFrameLeft, window.visibleFrameTop,
                mWindows[i].visibleFrameRight, mWindows[i].visibleFrameBottom,
                    window.visibleFrameRight, window.visibleFrameBottom,
                mWindows[i].touchableAreaLeft, mWindows[i].touchableAreaTop,
                    window.touchableAreaLeft, window.touchableAreaTop,
                mWindows[i].touchableAreaRight, mWindows[i].touchableAreaBottom,
                    window.touchableAreaRight, window.touchableAreaBottom,
                mWindows[i].ownerPid, mWindows[i].ownerUid,
                    window.ownerPid, window.ownerUid,
                mWindows[i].dispatchingTimeout / 1000000.0);
                    window.dispatchingTimeout / 1000000.0);
        }
    } else {
        dump.append(INDENT "Windows: <none>\n");
    }
    }


    if (!mMonitoringChannels.isEmpty()) {
        dump.append(INDENT "MonitoringChannels:\n");
        for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
        for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
            const sp<InputChannel>& channel = mMonitoringChannels[i];
            const sp<InputChannel>& channel = mMonitoringChannels[i];
        dump.appendFormat("  monitoringChannel[%d]: '%s'\n",
            dump.appendFormat(INDENT2 "%d: '%s'\n", i, channel->getName().string());
                i, channel->getName().string());
        }
    } else {
        dump.append(INDENT "MonitoringChannels: <none>\n");
    }
    }


    dump.appendFormat("  inboundQueue: length=%u", mInboundQueue.count());
    dump.appendFormat(INDENT "InboundQueue: length=%u\n", mInboundQueue.count());


    if (!mActiveConnections.isEmpty()) {
        dump.append(INDENT "ActiveConnections:\n");
        for (size_t i = 0; i < mActiveConnections.size(); i++) {
        for (size_t i = 0; i < mActiveConnections.size(); i++) {
            const Connection* connection = mActiveConnections[i];
            const Connection* connection = mActiveConnections[i];
        dump.appendFormat("  activeConnection[%d]: '%s', status=%s, outboundQueueLength=%u"
            dump.appendFormat(INDENT2 "%d: '%s', status=%s, outboundQueueLength=%u"
                    "inputState.isNeutral=%s, inputState.isOutOfSync=%s\n",
                    "inputState.isNeutral=%s, inputState.isOutOfSync=%s\n",
                    i, connection->getInputChannelName(), connection->getStatusLabel(),
                    i, connection->getInputChannelName(), connection->getStatusLabel(),
                    connection->outboundQueue.count(),
                    connection->outboundQueue.count(),
                    toString(connection->inputState.isNeutral()),
                    toString(connection->inputState.isNeutral()),
                    toString(connection->inputState.isOutOfSync()));
                    toString(connection->inputState.isOutOfSync()));
        }
        }
    } else {
        dump.append(INDENT "ActiveConnections: <none>\n");
    }


    if (isAppSwitchPendingLocked()) {
    if (isAppSwitchPendingLocked()) {
        dump.appendFormat("  appSwitch: pending, due in %01.1fms\n",
        dump.appendFormat(INDENT "AppSwitch: pending, due in %01.1fms\n",
                (mAppSwitchDueTime - now()) / 1000000.0);
                (mAppSwitchDueTime - now()) / 1000000.0);
    } else {
    } else {
        dump.append("  appSwitch: not pending\n");
        dump.append(INDENT "AppSwitch: not pending\n");
    }
    }
}
}


@@ -2774,6 +2799,7 @@ void InputDispatcher::updateDispatchStatisticsLocked(nsecs_t currentTime, const
}
}


void InputDispatcher::dump(String8& dump) {
void InputDispatcher::dump(String8& dump) {
    dump.append("Input Dispatcher State:\n");
    dumpDispatchStateLocked(dump);
    dumpDispatchStateLocked(dump);
}
}


+5 −1
Original line number Original line Diff line number Diff line
@@ -575,6 +575,11 @@ bool InputReader::markSupportedKeyCodes(int32_t deviceId, uint32_t sourceMask, s
}
}


void InputReader::dump(String8& dump) {
void InputReader::dump(String8& dump) {
    mEventHub->dump(dump);
    dump.append("\n");

    dump.append("Input Reader State:\n");

    { // acquire device registry reader lock
    { // acquire device registry reader lock
        RWLock::AutoRLock _rl(mDeviceRegistryLock);
        RWLock::AutoRLock _rl(mDeviceRegistryLock);


@@ -861,7 +866,6 @@ void KeyboardInputMapper::dump(String8& dump) {
        AutoMutex _l(mLock);
        AutoMutex _l(mLock);
        dump.append(INDENT2 "Keyboard Input Mapper:\n");
        dump.append(INDENT2 "Keyboard Input Mapper:\n");
        dump.appendFormat(INDENT3 "AssociatedDisplayId: %d\n", mAssociatedDisplayId);
        dump.appendFormat(INDENT3 "AssociatedDisplayId: %d\n", mAssociatedDisplayId);
        dump.appendFormat(INDENT3 "Sources: 0x%x\n", mSources);
        dump.appendFormat(INDENT3 "KeyboardType: %d\n", mKeyboardType);
        dump.appendFormat(INDENT3 "KeyboardType: %d\n", mKeyboardType);
        dump.appendFormat(INDENT3 "KeyDowns: %d keys currently down\n", mLocked.keyDowns.size());
        dump.appendFormat(INDENT3 "KeyDowns: %d keys currently down\n", mLocked.keyDowns.size());
        dump.appendFormat(INDENT3 "MetaState: 0x%0x\n", mLocked.metaState);
        dump.appendFormat(INDENT3 "MetaState: 0x%0x\n", mLocked.metaState);