@@ -149,6 +149,12 @@ static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t styl
149149 }
150150}
151151
152+ enum {
153+ WM_ACTION_PASS_TO_USER = 1 ,
154+ WM_ACTION_POKE_USER_ACTIVITY = 2 ,
155+ WM_ACTION_GO_TO_SLEEP = 4 ,
156+ };
157+
152158
153159// --- NativeInputManager ---
154160
@@ -199,7 +205,8 @@ class NativeInputManager : public virtual RefBase,
199205 virtual bool isKeyRepeatEnabled ();
200206 virtual void interceptKeyBeforeQueueing (const KeyEvent* keyEvent, uint32_t & policyFlags);
201207 virtual void interceptMotionBeforeQueueing (nsecs_t when, uint32_t & policyFlags);
202- virtual bool interceptKeyBeforeDispatching (const sp<InputWindowHandle>& inputWindowHandle,
208+ virtual nsecs_t interceptKeyBeforeDispatching (
209+ const sp<InputWindowHandle>& inputWindowHandle,
203210 const KeyEvent* keyEvent, uint32_t policyFlags);
204211 virtual bool dispatchUnhandledKey (const sp<InputWindowHandle>& inputWindowHandle,
205212 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
@@ -819,12 +826,6 @@ void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& p
819826
820827void NativeInputManager::handleInterceptActions (jint wmActions, nsecs_t when,
821828 uint32_t & policyFlags) {
822- enum {
823- WM_ACTION_PASS_TO_USER = 1 ,
824- WM_ACTION_POKE_USER_ACTIVITY = 2 ,
825- WM_ACTION_GO_TO_SLEEP = 4 ,
826- };
827-
828829 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
829830#if DEBUG_INPUT_DISPATCHER_POLICY
830831 LOGD (" handleInterceptActions: Going to sleep." );
@@ -848,28 +849,34 @@ void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
848849 }
849850}
850851
851- bool NativeInputManager::interceptKeyBeforeDispatching (
852+ nsecs_t NativeInputManager::interceptKeyBeforeDispatching (
852853 const sp<InputWindowHandle>& inputWindowHandle,
853854 const KeyEvent* keyEvent, uint32_t policyFlags) {
854855 // Policy:
855856 // - Ignore untrusted events and pass them along.
856857 // - Filter normal events and trusted injected events through the window manager policy to
857858 // handle the HOME key and the like.
858- bool result = false ;
859+ nsecs_t result = 0 ;
859860 if (policyFlags & POLICY_FLAG_TRUSTED) {
860861 JNIEnv* env = jniEnv ();
861862
862863 // Note: inputWindowHandle may be null.
863864 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef (env, inputWindowHandle);
864865 jobject keyEventObj = android_view_KeyEvent_fromNative (env, keyEvent);
865866 if (keyEventObj) {
866- jboolean consumed = env->CallBooleanMethod (mCallbacksObj ,
867+ jlong delayMillis = env->CallLongMethod (mCallbacksObj ,
867868 gCallbacksClassInfo .interceptKeyBeforeDispatching ,
868869 inputWindowHandleObj, keyEventObj, policyFlags);
869870 bool error = checkAndClearExceptionFromCallback (env, " interceptKeyBeforeDispatching" );
870871 android_view_KeyEvent_recycle (env, keyEventObj);
871872 env->DeleteLocalRef (keyEventObj);
872- result = consumed && !error;
873+ if (!error) {
874+ if (delayMillis < 0 ) {
875+ result = -1 ;
876+ } else if (delayMillis > 0 ) {
877+ result = milliseconds_to_nanoseconds (delayMillis);
878+ }
879+ }
873880 } else {
874881 LOGE (" Failed to obtain key event object for interceptKeyBeforeDispatching." );
875882 }
@@ -1433,7 +1440,7 @@ int register_android_server_InputManager(JNIEnv* env) {
14331440
14341441 GET_METHOD_ID (gCallbacksClassInfo .interceptKeyBeforeDispatching , clazz,
14351442 " interceptKeyBeforeDispatching" ,
1436- " (Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)Z " );
1443+ " (Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)J " );
14371444
14381445 GET_METHOD_ID (gCallbacksClassInfo .dispatchUnhandledKey , clazz,
14391446 " dispatchUnhandledKey" ,
0 commit comments