Merge "Allow for event dispatching when in non-interactive states." into lmp-dev
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index b7b12a8..2ed125d 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -770,7 +770,8 @@
public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
/**
- * Called from the input reader thread before a motion is enqueued when the screen is off.
+ * Called from the input reader thread before a motion is enqueued when the device is in a
+ * non-interactive state.
*
* <p>There are some actions that need to be handled here because they
* affect the power state of the device, for example, waking on motions.
@@ -780,7 +781,7 @@
*
* @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
*/
- public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags);
+ public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags);
/**
* Called from the input dispatcher thread before a key is dispatched to a window.
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 834cdd5..cd3eab5 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -4240,8 +4240,12 @@
int result;
boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
|| event.isWakeKey();
- if (interactive || (isInjected && !isWakeKey)) {
- // When the screen is on or if the key is injected pass the key to the application.
+ if (interactive
+ || (isInjected && !isWakeKey)
+ || (!interactive && shouldDispatchInputWhenNonInteractive())) {
+ // When the device is interactive, the key is injected, or we're currently dozing in a
+ // non-interactive state with the screen on and the keyguard showing, pass the key to
+ // the application.
result = ACTION_PASS_TO_USER;
isWakeKey = false;
} else {
@@ -4548,14 +4552,22 @@
/** {@inheritDoc} */
@Override
- public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
- // We already know this is a wake motion so just wake up.
- // Note that we would observe policyFlags containing
- // FLAG_WAKE and FLAG_INTERACTIVE here.
- mPowerManager.wakeUp(whenNanos / 1000000);
+ public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
+ if ((policyFlags & FLAG_WAKE) != 0) {
+ mPowerManager.wakeUp(whenNanos / 1000000);
+ return 0;
+ }
+ if (shouldDispatchInputWhenNonInteractive()) {
+ return ACTION_PASS_TO_USER;
+ }
return 0;
}
+ private boolean shouldDispatchInputWhenNonInteractive() {
+ return keyguardIsShowingTq() && mDisplay != null &&
+ mDisplay.getState() != Display.STATE_OFF;
+ }
+
void dispatchMediaKeyWithWakeLock(KeyEvent event) {
if (DEBUG_INPUT) {
Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 023f627..6ddad41 100755
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -9945,7 +9945,7 @@
}
private void updateEventDispatchingLocked() {
- mWindowManager.setEventDispatching(mBooted && !mWentToSleep && !mShuttingDown);
+ mWindowManager.setEventDispatching(mBooted && !mShuttingDown);
}
public void setLockScreenShown(boolean shown) {
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 9e81149..bbb8371 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -1429,8 +1429,8 @@
}
// Native callback.
- private int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
- return mWindowManagerCallbacks.interceptWakeMotionBeforeQueueing(
+ private int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
+ return mWindowManagerCallbacks.interceptMotionBeforeQueueingNonInteractive(
whenNanos, policyFlags);
}
@@ -1593,7 +1593,7 @@
public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
- public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags);
+ public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags);
public long interceptKeyBeforeDispatching(InputWindowHandle focus,
KeyEvent event, int policyFlags);
diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java
index d0f00d4..46aefb6 100644
--- a/services/core/java/com/android/server/wm/InputMonitor.java
+++ b/services/core/java/com/android/server/wm/InputMonitor.java
@@ -365,12 +365,13 @@
return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags);
}
- /* Provides an opportunity for the window manager policy to intercept early
- * motion event processing when the screen is off since these events are normally
+ /* Provides an opportunity for the window manager policy to intercept early motion event
+ * processing when the device is in a non-interactive state since these events are normally
* dropped. */
@Override
- public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
- return mService.mPolicy.interceptWakeMotionBeforeQueueing(whenNanos, policyFlags);
+ public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
+ return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive(
+ whenNanos, policyFlags);
}
/* Provides an opportunity for the window manager policy to process a key before
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index 8ed74be..cddca92 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -71,7 +71,7 @@
jmethodID notifyANR;
jmethodID filterInputEvent;
jmethodID interceptKeyBeforeQueueing;
- jmethodID interceptWakeMotionBeforeQueueing;
+ jmethodID interceptMotionBeforeQueueingNonInteractive;
jmethodID interceptKeyBeforeDispatching;
jmethodID dispatchUnhandledKey;
jmethodID checkInjectEventsPermission;
@@ -854,7 +854,9 @@
handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
} else {
- policyFlags |= POLICY_FLAG_PASS_TO_USER;
+ if (mInteractive) {
+ policyFlags |= POLICY_FLAG_PASS_TO_USER;
+ }
}
}
@@ -870,20 +872,22 @@
if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
if (policyFlags & POLICY_FLAG_INTERACTIVE) {
policyFlags |= POLICY_FLAG_PASS_TO_USER;
- } else if (policyFlags & POLICY_FLAG_WAKE) {
+ } else {
JNIEnv* env = jniEnv();
jint wmActions = env->CallIntMethod(mServiceObj,
- gServiceClassInfo.interceptWakeMotionBeforeQueueing,
+ gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive,
when, policyFlags);
if (checkAndClearExceptionFromCallback(env,
- "interceptWakeMotionBeforeQueueing")) {
+ "interceptMotionBeforeQueueingNonInteractive")) {
wmActions = 0;
}
handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
}
} else {
- policyFlags |= POLICY_FLAG_PASS_TO_USER;
+ if (mInteractive) {
+ policyFlags |= POLICY_FLAG_PASS_TO_USER;
+ }
}
}
@@ -1441,8 +1445,8 @@
GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
"interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;I)I");
- GET_METHOD_ID(gServiceClassInfo.interceptWakeMotionBeforeQueueing, clazz,
- "interceptWakeMotionBeforeQueueing", "(JI)I");
+ GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive, clazz,
+ "interceptMotionBeforeQueueingNonInteractive", "(JI)I");
GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
"interceptKeyBeforeDispatching",