Merge "Fix injection of specially intercepted keys like HOME." into gingerbread
This commit is contained in:
@@ -87,9 +87,6 @@ enum {
|
|||||||
// Indicates that the screen was dim when the event was received and the event
|
// Indicates that the screen was dim when the event was received and the event
|
||||||
// should brighten the device.
|
// should brighten the device.
|
||||||
POLICY_FLAG_BRIGHT_HERE = 0x20000000,
|
POLICY_FLAG_BRIGHT_HERE = 0x20000000,
|
||||||
|
|
||||||
// Indicates that the dispatcher should call back into the policy before dispatching. */
|
|
||||||
POLICY_FLAG_INTERCEPT_DISPATCH = 0x40000000,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -371,10 +371,6 @@ public:
|
|||||||
// The input dispatcher should add POLICY_FLAG_BRIGHT_HERE to the policy flags it
|
// The input dispatcher should add POLICY_FLAG_BRIGHT_HERE to the policy flags it
|
||||||
// passes through the dispatch pipeline.
|
// passes through the dispatch pipeline.
|
||||||
ACTION_BRIGHT_HERE = 0x00000008,
|
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. */
|
/* Describes a virtual key. */
|
||||||
|
|||||||
@@ -1639,10 +1639,6 @@ bool InputReader::applyStandardInputDispatchPolicyActions(nsecs_t when,
|
|||||||
*policyFlags |= POLICY_FLAG_BRIGHT_HERE;
|
*policyFlags |= POLICY_FLAG_BRIGHT_HERE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (policyActions & InputReaderPolicyInterface::ACTION_INTERCEPT_DISPATCH) {
|
|
||||||
*policyFlags |= POLICY_FLAG_INTERCEPT_DISPATCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
return policyActions & InputReaderPolicyInterface::ACTION_DISPATCH;
|
return policyActions & InputReaderPolicyInterface::ACTION_DISPATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -374,6 +374,9 @@ private:
|
|||||||
int32_t identifyTouchEventTargets(MotionEvent* motionEvent, uint32_t policyFlags,
|
int32_t identifyTouchEventTargets(MotionEvent* motionEvent, uint32_t policyFlags,
|
||||||
int32_t injectorPid, int32_t injectorUid, Vector<InputTarget>& outTargets);
|
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 pokeUserActivityIfNeeded(int32_t windowType, int32_t eventType);
|
||||||
void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
|
void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
|
||||||
bool checkInjectionPermission(const InputWindow* window,
|
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;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1530,34 +1531,11 @@ int32_t NativeInputManager::waitForKeyEventTargets(KeyEvent* keyEvent, uint32_t
|
|||||||
windowType = focusedWindow->layoutParamsType;
|
windowType = focusedWindow->layoutParamsType;
|
||||||
} // release lock
|
} // release lock
|
||||||
|
|
||||||
if (policyFlags & POLICY_FLAG_INTERCEPT_DISPATCH) {
|
const InputTarget& target = outTargets.top();
|
||||||
const InputTarget& target = outTargets.top();
|
bool consumed = interceptKeyBeforeDispatching(target, keyEvent, policyFlags);
|
||||||
|
if (consumed) {
|
||||||
JNIEnv* env = jniEnv();
|
outTargets.clear();
|
||||||
|
return INPUT_EVENT_INJECTION_SUCCEEDED;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
pokeUserActivityIfNeeded(windowType, POWER_MANAGER_BUTTON_EVENT);
|
||||||
@@ -1656,6 +1634,29 @@ int32_t NativeInputManager::identifyTouchEventTargets(MotionEvent* motionEvent,
|
|||||||
return INPUT_EVENT_INJECTION_SUCCEEDED;
|
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) {
|
void NativeInputManager::pokeUserActivityIfNeeded(int32_t windowType, int32_t eventType) {
|
||||||
if (windowType != TYPE_KEYGUARD) {
|
if (windowType != TYPE_KEYGUARD) {
|
||||||
nsecs_t eventTime = now();
|
nsecs_t eventTime = now();
|
||||||
|
|||||||
Reference in New Issue
Block a user