am 28d3c245: Merge "Cancel or drop key events if activity is stopped." into lmp-mr1-dev

* commit '28d3c245a1dde4aa5294192bec9980d8a93b0489':
  Cancel or drop key events if activity is stopped.
This commit is contained in:
Wale Ogunwale
2014-11-13 19:07:19 +00:00
committed by Android Git Automerger
4 changed files with 36 additions and 6 deletions

View File

@@ -195,6 +195,13 @@ public abstract class InputEvent implements Parcelable {
*/ */
public abstract long getEventTimeNano(); public abstract long getEventTimeNano();
/**
* Marks the input event as being canceled.
*
* @hide
*/
public abstract void cancel();
/** /**
* Gets the unique sequence number of this event. * Gets the unique sequence number of this event.
* Every input event that is created or received by a process has a * Every input event that is created or received by a process has a

View File

@@ -2303,6 +2303,16 @@ public class KeyEvent extends InputEvent implements Parcelable {
return (mFlags&FLAG_CANCELED) != 0; return (mFlags&FLAG_CANCELED) != 0;
} }
/**
* Set {@link #FLAG_CANCELED} flag for the key event.
*
* @hide
*/
@Override
public final void cancel() {
mFlags |= FLAG_CANCELED;
}
/** /**
* Call this during {@link Callback#onKeyDown} to have the system track * Call this during {@link Callback#onKeyDown} to have the system track
* the key through its final up (possibly including a long press). Note * the key through its final up (possibly including a long press). Note

View File

@@ -3168,6 +3168,12 @@ public final class MotionEvent extends InputEvent implements Parcelable {
return ev; return ev;
} }
/** @hide */
@Override
public final void cancel() {
setAction(ACTION_CANCEL);
}
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeInt(PARCEL_TOKEN_MOTION_EVENT); out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
nativeWriteToParcel(mNativePtr, out); nativeWriteToParcel(mNativePtr, out);

View File

@@ -3596,12 +3596,19 @@ public final class ViewRootImpl implements ViewParent,
if (mView == null || !mAdded) { if (mView == null || !mAdded) {
Slog.w(TAG, "Dropping event due to root view being removed: " + q.mEvent); Slog.w(TAG, "Dropping event due to root view being removed: " + q.mEvent);
return true; return true;
} else if (!mAttachInfo.mHasWindowFocus && } else if ((!mAttachInfo.mHasWindowFocus || mStopped)
!q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER) && && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
!isTerminalInputEvent(q.mEvent)) { // This is a focus event and the window doesn't currently have input focus or
// If this is a focused event and the window doesn't currently have input focus, // has stopped. This could be an event that came back from the previous stage
// then drop this event. This could be an event that came back from the previous // but the window has lost focus or stopped in the meantime.
// stage but the window has lost focus in the meantime. if (isTerminalInputEvent(q.mEvent)) {
// Don't drop terminal input events, however mark them as canceled.
q.mEvent.cancel();
Slog.w(TAG, "Cancelling event due to no window focus: " + q.mEvent);
return false;
}
// Drop non-terminal input events.
Slog.w(TAG, "Dropping event due to no window focus: " + q.mEvent); Slog.w(TAG, "Dropping event due to no window focus: " + q.mEvent);
return true; return true;
} }