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

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

Merge "Wait for initial device scan to finish before updating config." into gingerbread

parents f1aa6a1d 1ad00e96
Loading
Loading
Loading
Loading
+11 −5
Original line number Original line Diff line number Diff line
@@ -142,8 +142,13 @@ protected:
public:
public:
    // Synthetic raw event type codes produced when devices are added or removed.
    // Synthetic raw event type codes produced when devices are added or removed.
    enum {
    enum {
        // Sent when a device is added.
        DEVICE_ADDED = 0x10000000,
        DEVICE_ADDED = 0x10000000,
        DEVICE_REMOVED = 0x20000000
        // Sent when a device is removed.
        DEVICE_REMOVED = 0x20000000,
        // Sent when all added/removed devices from the most recent scan have been reported.
        // This event is always sent at least once.
        FINISHED_DEVICE_SCAN = 0x30000000,
    };
    };


    virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0;
    virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0;
@@ -221,10 +226,10 @@ protected:
private:
private:
    bool openPlatformInput(void);
    bool openPlatformInput(void);


    int open_device(const char *device);
    int openDevice(const char *device);
    int close_device(const char *device);
    int closeDevice(const char *device);
    int scan_dir(const char *dirname);
    int scanDir(const char *dirname);
    int read_notify(int nfd);
    int readNotify(int nfd);


    status_t mError;
    status_t mError;


@@ -273,6 +278,7 @@ private:
    int             mFDCount;
    int             mFDCount;


    bool            mOpened;
    bool            mOpened;
    bool            mNeedToSendFinishedDeviceScan;
    List<String8>   mExcludedDevices;
    List<String8>   mExcludedDevices;


    // device ids that report particular switches.
    // device ids that report particular switches.
+3 −3
Original line number Original line Diff line number Diff line
@@ -279,14 +279,14 @@ private:
    // low-level input event decoding and device management
    // low-level input event decoding and device management
    void process(const RawEvent* rawEvent);
    void process(const RawEvent* rawEvent);


    void addDevice(nsecs_t when, int32_t deviceId);
    void addDevice(int32_t deviceId);
    void removeDevice(nsecs_t when, int32_t deviceId);
    void removeDevice(int32_t deviceId);
    InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes);
    InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes);
    void configureExcludedDevices();
    void configureExcludedDevices();


    void consumeEvent(const RawEvent* rawEvent);
    void consumeEvent(const RawEvent* rawEvent);


    void handleConfigurationChanged(nsecs_t when);
    void handleConfigurationChanged();


    // state management for all devices
    // state management for all devices
    Mutex mStateLock;
    Mutex mStateLock;
+22 −17
Original line number Original line Diff line number Diff line
@@ -106,7 +106,7 @@ EventHub::EventHub(void)
    : mError(NO_INIT), mHaveFirstKeyboard(false), mFirstKeyboardId(0)
    : mError(NO_INIT), mHaveFirstKeyboard(false), mFirstKeyboardId(0)
    , mDevicesById(0), mNumDevicesById(0)
    , mDevicesById(0), mNumDevicesById(0)
    , mOpeningDevices(0), mClosingDevices(0)
    , mOpeningDevices(0), mClosingDevices(0)
    , mDevices(0), mFDs(0), mFDCount(0), mOpened(false)
    , mDevices(0), mFDs(0), mFDCount(0), mOpened(false), mNeedToSendFinishedDeviceScan(false)
    , mInputBufferIndex(0), mInputBufferCount(0), mInputDeviceIndex(0)
    , mInputBufferIndex(0), mInputBufferCount(0), mInputDeviceIndex(0)
{
{
    acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
    acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
@@ -354,6 +354,7 @@ bool EventHub::getEvent(RawEvent* outEvent)
    if (!mOpened) {
    if (!mOpened) {
        mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR;
        mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR;
        mOpened = true;
        mOpened = true;
        mNeedToSendFinishedDeviceScan = true;
    }
    }


    for (;;) {
    for (;;) {
@@ -370,6 +371,7 @@ bool EventHub::getEvent(RawEvent* outEvent)
            }
            }
            outEvent->type = DEVICE_REMOVED;
            outEvent->type = DEVICE_REMOVED;
            delete device;
            delete device;
            mNeedToSendFinishedDeviceScan = true;
            return true;
            return true;
        }
        }


@@ -384,6 +386,13 @@ bool EventHub::getEvent(RawEvent* outEvent)
                outEvent->deviceId = device->id;
                outEvent->deviceId = device->id;
            }
            }
            outEvent->type = DEVICE_ADDED;
            outEvent->type = DEVICE_ADDED;
            mNeedToSendFinishedDeviceScan = true;
            return true;
        }

        if (mNeedToSendFinishedDeviceScan) {
            mNeedToSendFinishedDeviceScan = false;
            outEvent->type = FINISHED_DEVICE_SCAN;
            return true;
            return true;
        }
        }


@@ -451,10 +460,10 @@ bool EventHub::getEvent(RawEvent* outEvent)
            }
            }
        }
        }


        // read_notify() will modify mFDs and mFDCount, so this must be done after
        // readNotify() will modify mFDs and mFDCount, so this must be done after
        // processing all other events.
        // processing all other events.
        if(mFDs[0].revents & POLLIN) {
        if(mFDs[0].revents & POLLIN) {
            read_notify(mFDs[0].fd);
            readNotify(mFDs[0].fd);
        }
        }


        // Poll for events.  Mind the wake lock dance!
        // Poll for events.  Mind the wake lock dance!
@@ -510,10 +519,9 @@ bool EventHub::openPlatformInput(void)
    mFDs[0].fd = -1;
    mFDs[0].fd = -1;
#endif
#endif


    res = scan_dir(device_path);
    res = scanDir(device_path);
    if(res < 0) {
    if(res < 0) {
        LOGE("scan dir failed for %s\n", device_path);
        LOGE("scan dir failed for %s\n", device_path);
        //open_device("/dev/input/event0");
    }
    }


    return true;
    return true;
@@ -541,8 +549,7 @@ static const int32_t GAMEPAD_KEYCODES[] = {
        AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE
        AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE
};
};


int EventHub::open_device(const char *deviceName)
int EventHub::openDevice(const char *deviceName) {
{
    int version;
    int version;
    int fd;
    int fd;
    struct pollfd *new_mFDs;
    struct pollfd *new_mFDs;
@@ -859,8 +866,7 @@ bool EventHub::hasKeycodeLocked(device_t* device, int keycode) const
    return false;
    return false;
}
}


int EventHub::close_device(const char *deviceName)
int EventHub::closeDevice(const char *deviceName) {
{
    AutoMutex _l(mLock);
    AutoMutex _l(mLock);


    int i;
    int i;
@@ -912,8 +918,7 @@ int EventHub::close_device(const char *deviceName)
    return -1;
    return -1;
}
}


int EventHub::read_notify(int nfd)
int EventHub::readNotify(int nfd) {
{
#ifdef HAVE_INOTIFY
#ifdef HAVE_INOTIFY
    int res;
    int res;
    char devname[PATH_MAX];
    char devname[PATH_MAX];
@@ -923,7 +928,7 @@ int EventHub::read_notify(int nfd)
    int event_pos = 0;
    int event_pos = 0;
    struct inotify_event *event;
    struct inotify_event *event;


    LOGV("EventHub::read_notify nfd: %d\n", nfd);
    LOGV("EventHub::readNotify nfd: %d\n", nfd);
    res = read(nfd, event_buf, sizeof(event_buf));
    res = read(nfd, event_buf, sizeof(event_buf));
    if(res < (int)sizeof(*event)) {
    if(res < (int)sizeof(*event)) {
        if(errno == EINTR)
        if(errno == EINTR)
@@ -943,10 +948,10 @@ int EventHub::read_notify(int nfd)
        if(event->len) {
        if(event->len) {
            strcpy(filename, event->name);
            strcpy(filename, event->name);
            if(event->mask & IN_CREATE) {
            if(event->mask & IN_CREATE) {
                open_device(devname);
                openDevice(devname);
            }
            }
            else {
            else {
                close_device(devname);
                closeDevice(devname);
            }
            }
        }
        }
        event_size = sizeof(*event) + event->len;
        event_size = sizeof(*event) + event->len;
@@ -958,7 +963,7 @@ int EventHub::read_notify(int nfd)
}
}




int EventHub::scan_dir(const char *dirname)
int EventHub::scanDir(const char *dirname)
{
{
    char devname[PATH_MAX];
    char devname[PATH_MAX];
    char *filename;
    char *filename;
@@ -976,7 +981,7 @@ int EventHub::scan_dir(const char *dirname)
            (de->d_name[1] == '.' && de->d_name[2] == '\0')))
            (de->d_name[1] == '.' && de->d_name[2] == '\0')))
            continue;
            continue;
        strcpy(filename, de->d_name);
        strcpy(filename, de->d_name);
        open_device(devname);
        openDevice(devname);
    }
    }
    closedir(dir);
    closedir(dir);
    return 0;
    return 0;
+10 −9
Original line number Original line Diff line number Diff line
@@ -226,11 +226,15 @@ void InputReader::loopOnce() {
void InputReader::process(const RawEvent* rawEvent) {
void InputReader::process(const RawEvent* rawEvent) {
    switch (rawEvent->type) {
    switch (rawEvent->type) {
    case EventHubInterface::DEVICE_ADDED:
    case EventHubInterface::DEVICE_ADDED:
        addDevice(rawEvent->when, rawEvent->deviceId);
        addDevice(rawEvent->deviceId);
        break;
        break;


    case EventHubInterface::DEVICE_REMOVED:
    case EventHubInterface::DEVICE_REMOVED:
        removeDevice(rawEvent->when, rawEvent->deviceId);
        removeDevice(rawEvent->deviceId);
        break;

    case EventHubInterface::FINISHED_DEVICE_SCAN:
        handleConfigurationChanged();
        break;
        break;


    default:
    default:
@@ -239,7 +243,7 @@ void InputReader::process(const RawEvent* rawEvent) {
    }
    }
}
}


void InputReader::addDevice(nsecs_t when, int32_t deviceId) {
void InputReader::addDevice(int32_t deviceId) {
    String8 name = mEventHub->getDeviceName(deviceId);
    String8 name = mEventHub->getDeviceName(deviceId);
    uint32_t classes = mEventHub->getDeviceClasses(deviceId);
    uint32_t classes = mEventHub->getDeviceClasses(deviceId);


@@ -269,11 +273,9 @@ void InputReader::addDevice(nsecs_t when, int32_t deviceId) {
        delete device;
        delete device;
        return;
        return;
    }
    }

    handleConfigurationChanged(when);
}
}


void InputReader::removeDevice(nsecs_t when, int32_t deviceId) {
void InputReader::removeDevice(int32_t deviceId) {
    bool removed = false;
    bool removed = false;
    InputDevice* device = NULL;
    InputDevice* device = NULL;
    { // acquire device registry writer lock
    { // acquire device registry writer lock
@@ -303,8 +305,6 @@ void InputReader::removeDevice(nsecs_t when, int32_t deviceId) {
    device->reset();
    device->reset();


    delete device;
    delete device;

    handleConfigurationChanged(when);
}
}


InputDevice* InputReader::createDevice(int32_t deviceId, const String8& name, uint32_t classes) {
InputDevice* InputReader::createDevice(int32_t deviceId, const String8& name, uint32_t classes) {
@@ -372,7 +372,7 @@ void InputReader::consumeEvent(const RawEvent* rawEvent) {
    } // release device registry reader lock
    } // release device registry reader lock
}
}


void InputReader::handleConfigurationChanged(nsecs_t when) {
void InputReader::handleConfigurationChanged() {
    // Reset global meta state because it depends on the list of all configured devices.
    // Reset global meta state because it depends on the list of all configured devices.
    updateGlobalMetaState();
    updateGlobalMetaState();


@@ -380,6 +380,7 @@ void InputReader::handleConfigurationChanged(nsecs_t when) {
    updateInputConfiguration();
    updateInputConfiguration();


    // Enqueue configuration changed.
    // Enqueue configuration changed.
    nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC);
    mDispatcher->notifyConfigurationChanged(when);
    mDispatcher->notifyConfigurationChanged(when);
}
}