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

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

Merge "Fix injection of specially intercepted keys like HOME." into gingerbread

parents c8525edc d0097871
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -87,9 +87,6 @@ enum {
    // Indicates that the screen was dim when the event was received and the event
    // should brighten the device.
    POLICY_FLAG_BRIGHT_HERE = 0x20000000,

    // Indicates that the dispatcher should call back into the policy before dispatching. */
    POLICY_FLAG_INTERCEPT_DISPATCH = 0x40000000,
};

/*
+0 −4
Original line number Diff line number Diff line
@@ -371,10 +371,6 @@ public:
        // The input dispatcher should add POLICY_FLAG_BRIGHT_HERE to the policy flags it
        // passes through the dispatch pipeline.
        ACTION_BRIGHT_HERE = 0x00000008,

        // The input dispatcher should add POLICY_FLAG_INTERCEPT_DISPATCH to the policy flags
        // it passed through the dispatch pipeline.
        ACTION_INTERCEPT_DISPATCH = 0x00000010
    };

    /* Describes a virtual key. */
+0 −4
Original line number Diff line number Diff line
@@ -1639,10 +1639,6 @@ bool InputReader::applyStandardInputDispatchPolicyActions(nsecs_t when,
        *policyFlags |= POLICY_FLAG_BRIGHT_HERE;
    }

    if (policyActions & InputReaderPolicyInterface::ACTION_INTERCEPT_DISPATCH) {
        *policyFlags |= POLICY_FLAG_INTERCEPT_DISPATCH;
    }

    return policyActions & InputReaderPolicyInterface::ACTION_DISPATCH;
}

+31 −30
Original line number Diff line number Diff line
@@ -374,6 +374,9 @@ private:
    int32_t identifyTouchEventTargets(MotionEvent* motionEvent, uint32_t policyFlags,
            int32_t injectorPid, int32_t injectorUid, Vector<InputTarget>& outTargets);

    bool interceptKeyBeforeDispatching(const InputTarget& target,
            const KeyEvent* keyEvent, uint32_t policyFlags);

    void pokeUserActivityIfNeeded(int32_t windowType, int32_t eventType);
    void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
    bool checkInjectionPermission(const InputWindow* window,
@@ -633,8 +636,6 @@ int32_t NativeInputManager::interceptKey(nsecs_t when,
        }
    }

    // TODO Be smarter about which keys cause us to request interception during dispatch.
    actions |= InputReaderPolicyInterface::ACTION_INTERCEPT_DISPATCH;
    return actions;
}

@@ -1530,35 +1531,12 @@ int32_t NativeInputManager::waitForKeyEventTargets(KeyEvent* keyEvent, uint32_t
        windowType = focusedWindow->layoutParamsType;
    } // release lock

    if (policyFlags & POLICY_FLAG_INTERCEPT_DISPATCH) {
    const InputTarget& target = outTargets.top();

        JNIEnv* env = jniEnv();

        jobject inputChannelObj = getInputChannelObjLocal(env, target.inputChannel);
        if (inputChannelObj) {
            jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
                    gCallbacksClassInfo.interceptKeyBeforeDispatching,
                    inputChannelObj, keyEvent->getKeyCode(), keyEvent->getMetaState(),
                    keyEvent->getAction() == KEY_EVENT_ACTION_DOWN,
                    keyEvent->getRepeatCount(), policyFlags);
            bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatch");

            env->DeleteLocalRef(inputChannelObj);

            if (error) {
                return INPUT_EVENT_INJECTION_FAILED;
            }

    bool consumed = interceptKeyBeforeDispatching(target, keyEvent, policyFlags);
    if (consumed) {
        outTargets.clear();
        return INPUT_EVENT_INJECTION_SUCCEEDED;
    }
        } else {
            LOGW("Could not apply key dispatch policy because input channel '%s' is "
                    "no longer valid.", target.inputChannel->getName().string());
        }
    }

    pokeUserActivityIfNeeded(windowType, POWER_MANAGER_BUTTON_EVENT);
    return INPUT_EVENT_INJECTION_SUCCEEDED;
@@ -1656,6 +1634,29 @@ int32_t NativeInputManager::identifyTouchEventTargets(MotionEvent* motionEvent,
    return INPUT_EVENT_INJECTION_SUCCEEDED;
}

bool NativeInputManager::interceptKeyBeforeDispatching(const InputTarget& target,
        const KeyEvent* keyEvent, uint32_t policyFlags) {
    JNIEnv* env = jniEnv();

    jobject inputChannelObj = getInputChannelObjLocal(env, target.inputChannel);
    if (inputChannelObj) {
        jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
                gCallbacksClassInfo.interceptKeyBeforeDispatching,
                inputChannelObj, keyEvent->getKeyCode(), keyEvent->getMetaState(),
                keyEvent->getAction() == KEY_EVENT_ACTION_DOWN,
                keyEvent->getRepeatCount(), policyFlags);
        bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");

        env->DeleteLocalRef(inputChannelObj);

        return consumed && ! error;
    } else {
        LOGW("Could not apply key dispatch policy because input channel '%s' is "
                "no longer valid.", target.inputChannel->getName().string());
        return false;
    }
}

void NativeInputManager::pokeUserActivityIfNeeded(int32_t windowType, int32_t eventType) {
    if (windowType != TYPE_KEYGUARD) {
        nsecs_t eventTime = now();