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

Commit bcc046af authored by Jeff Brown's avatar Jeff Brown
Browse files

Bundle correlated switch changes atomically.

This is a prerequisite for headset jack detection on Manta.

Bug: 6548391
Change-Id: I549a194344511c0cee578b00f6a9ab5fdbdfb99c
parent 580ee8b0
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -2485,15 +2485,15 @@ bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs


void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) {
void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) {
#if DEBUG_INBOUND_EVENT_DETAILS
#if DEBUG_INBOUND_EVENT_DETAILS
    ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchCode=%d, switchValue=%d",
    ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchValues=0x%08x, switchMask=0x%08x",
            args->eventTime, args->policyFlags,
            args->eventTime, args->policyFlags,
            args->switchCode, args->switchValue);
            args->switchValues, args->switchMask);
#endif
#endif


    uint32_t policyFlags = args->policyFlags;
    uint32_t policyFlags = args->policyFlags;
    policyFlags |= POLICY_FLAG_TRUSTED;
    policyFlags |= POLICY_FLAG_TRUSTED;
    mPolicy->notifySwitch(args->eventTime,
    mPolicy->notifySwitch(args->eventTime,
            args->switchCode, args->switchValue, policyFlags);
            args->switchValues, args->switchMask, policyFlags);
}
}


void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -248,7 +248,7 @@ public:
    /* Notifies the policy about switch events.
    /* Notifies the policy about switch events.
     */
     */
    virtual void notifySwitch(nsecs_t when,
    virtual void notifySwitch(nsecs_t when,
            int32_t switchCode, int32_t switchValue, uint32_t policyFlags) = 0;
            uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) = 0;


    /* Poke user activity for an event dispatched to a window. */
    /* Poke user activity for an event dispatched to a window. */
    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0;
    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0;
+3 −3
Original line number Original line Diff line number Diff line
@@ -104,14 +104,14 @@ void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const
// --- NotifySwitchArgs ---
// --- NotifySwitchArgs ---


NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
        int32_t switchCode, int32_t switchValue) :
        uint32_t switchValues, uint32_t switchMask) :
        eventTime(eventTime), policyFlags(policyFlags),
        eventTime(eventTime), policyFlags(policyFlags),
        switchCode(switchCode), switchValue(switchValue) {
        switchValues(switchValues), switchMask(switchMask) {
}
}


NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) :
NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) :
        eventTime(other.eventTime), policyFlags(other.policyFlags),
        eventTime(other.eventTime), policyFlags(other.policyFlags),
        switchCode(other.switchCode), switchValue(other.switchValue) {
        switchValues(other.switchValues), switchMask(other.switchMask) {
}
}


void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const {
void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const {
+3 −3
Original line number Original line Diff line number Diff line
@@ -116,13 +116,13 @@ struct NotifyMotionArgs : public NotifyArgs {
struct NotifySwitchArgs : public NotifyArgs {
struct NotifySwitchArgs : public NotifyArgs {
    nsecs_t eventTime;
    nsecs_t eventTime;
    uint32_t policyFlags;
    uint32_t policyFlags;
    int32_t switchCode;
    uint32_t switchValues;
    int32_t switchValue;
    uint32_t switchMask;


    inline NotifySwitchArgs() { }
    inline NotifySwitchArgs() { }


    NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
    NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
            int32_t switchCode, int32_t switchValue);
            uint32_t switchValues, uint32_t switchMask);


    NotifySwitchArgs(const NotifySwitchArgs& other);
    NotifySwitchArgs(const NotifySwitchArgs& other);


+24 −5
Original line number Original line Diff line number Diff line
@@ -1800,7 +1800,7 @@ void InputMapper::dumpRawAbsoluteAxisInfo(String8& dump,
// --- SwitchInputMapper ---
// --- SwitchInputMapper ---


SwitchInputMapper::SwitchInputMapper(InputDevice* device) :
SwitchInputMapper::SwitchInputMapper(InputDevice* device) :
        InputMapper(device) {
        InputMapper(device), mUpdatedSwitchValues(0), mUpdatedSwitchMask(0) {
}
}


SwitchInputMapper::~SwitchInputMapper() {
SwitchInputMapper::~SwitchInputMapper() {
@@ -1813,14 +1813,33 @@ uint32_t SwitchInputMapper::getSources() {
void SwitchInputMapper::process(const RawEvent* rawEvent) {
void SwitchInputMapper::process(const RawEvent* rawEvent) {
    switch (rawEvent->type) {
    switch (rawEvent->type) {
    case EV_SW:
    case EV_SW:
        processSwitch(rawEvent->when, rawEvent->code, rawEvent->value);
        processSwitch(rawEvent->code, rawEvent->value);
        break;
        break;

    case EV_SYN:
        if (rawEvent->code == SYN_REPORT) {
            sync(rawEvent->when);
        }
    }
    }
}
}


void SwitchInputMapper::processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue) {
void SwitchInputMapper::processSwitch(int32_t switchCode, int32_t switchValue) {
    NotifySwitchArgs args(when, 0, switchCode, switchValue);
    if (switchCode >= 0 && switchCode < 32) {
        if (switchValue) {
            mUpdatedSwitchValues |= 1 << switchCode;
        }
        mUpdatedSwitchMask |= 1 << switchCode;
    }
}

void SwitchInputMapper::sync(nsecs_t when) {
    if (mUpdatedSwitchMask) {
        NotifySwitchArgs args(when, 0, mUpdatedSwitchValues, mUpdatedSwitchMask);
        getListener()->notifySwitch(&args);
        getListener()->notifySwitch(&args);

        mUpdatedSwitchValues = 0;
        mUpdatedSwitchMask = 0;
    }
}
}


int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
Loading