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

Commit 56194ebe authored by Jeff Brown's avatar Jeff Brown
Browse files

Wake screen from external HID peripherals.

Added some plumbing to enable the policy to intercept motion
events when the screen is off to handle wakeup if needed.

Added a basic concept of an external device to limit the scope
of the wakeup policy to external devices only.  The wakeup policy
for internal devices should be based on explicit rules such as
policy flags in key layout files.

Moved isTouchEvent to native.

Ensure the dispatcher sends the right event type to userActivity
for non-touch pointer events like HOVER_MOVE and SCROLL.

Bug: 3193114
Change-Id: I15dbd48a16810dfaf226ff7ad117d46908ca4f86
parent 05dc66ad
Loading
Loading
Loading
Loading
+2 −13
Original line number Diff line number Diff line
@@ -937,6 +937,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
    private static native int nativeSetSource(int nativePtr, int source);
    private static native int nativeGetAction(int nativePtr);
    private static native void nativeSetAction(int nativePtr, int action);
    private static native boolean nativeIsTouchEvent(int nativePtr);
    private static native int nativeGetFlags(int nativePtr);
    private static native int nativeGetEdgeFlags(int nativePtr);
    private static native void nativeSetEdgeFlags(int nativePtr, int action);
@@ -1275,19 +1276,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
     * @hide
     */
    public final boolean isTouchEvent() {
        if ((getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            switch (getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_MOVE:
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_POINTER_DOWN:
                case MotionEvent.ACTION_POINTER_UP:
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_OUTSIDE:
                    return true;
            }
        }
        return false;
        return nativeIsTouchEvent(mNativePtr);
    }

    /**
+15 −1
Original line number Diff line number Diff line
@@ -574,6 +574,20 @@ public interface WindowManagerPolicy {
     */
    public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn);

    /**
     * Called from the input reader thread before a motion is enqueued when the screen is off.
     *
     * <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.
     * Generally, it's best to keep as little as possible in the queue thread
     * because it's the most fragile.
     * @param policyFlags The policy flags associated with the motion.
     *
     * @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
     *          {@link #ACTION_POKE_USER_ACTIVITY} and {@link #ACTION_GO_TO_SLEEP} flags.
     */
    public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags);

    /**
     * Called from the input dispatcher thread before a key is dispatched to a window.
     *
+9 −0
Original line number Diff line number Diff line
@@ -429,6 +429,12 @@ static void android_view_MotionEvent_nativeSetAction(JNIEnv* env, jclass clazz,
    event->setAction(action);
}

static jboolean android_view_MotionEvent_nativeIsTouchEvent(JNIEnv* env, jclass clazz,
        jint nativePtr) {
    MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
    return event->isTouchEvent();
}

static jint android_view_MotionEvent_nativeGetFlags(JNIEnv* env, jclass clazz,
        jint nativePtr) {
    MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
@@ -661,6 +667,9 @@ static JNINativeMethod gMotionEventMethods[] = {
    { "nativeSetAction",
            "(II)V",
            (void*)android_view_MotionEvent_nativeSetAction },
    { "nativeIsTouchEvent",
            "(I)Z",
            (void*)android_view_MotionEvent_nativeIsTouchEvent },
    { "nativeGetFlags",
            "(I)I",
            (void*)android_view_MotionEvent_nativeGetFlags },
+5 −0
Original line number Diff line number Diff line
@@ -476,6 +476,11 @@ public:
    status_t writeToParcel(Parcel* parcel) const;
#endif

    static bool isTouchEvent(int32_t source, int32_t action);
    inline bool isTouchEvent() const {
        return isTouchEvent(mSource, mAction);
    }

    // Low-level accessors.
    inline const int32_t* getPointerIds() const { return mPointerIds.array(); }
    inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); }
+17 −0
Original line number Diff line number Diff line
@@ -616,6 +616,23 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const {
}
#endif

bool MotionEvent::isTouchEvent(int32_t source, int32_t action) {
    if (source & AINPUT_SOURCE_CLASS_POINTER) {
        // Specifically excludes HOVER_MOVE and SCROLL.
        switch (action & AMOTION_EVENT_ACTION_MASK) {
        case AMOTION_EVENT_ACTION_DOWN:
        case AMOTION_EVENT_ACTION_MOVE:
        case AMOTION_EVENT_ACTION_UP:
        case AMOTION_EVENT_ACTION_POINTER_DOWN:
        case AMOTION_EVENT_ACTION_POINTER_UP:
        case AMOTION_EVENT_ACTION_CANCEL:
        case AMOTION_EVENT_ACTION_OUTSIDE:
            return true;
        }
    }
    return false;
}


// --- InputDeviceInfo ---

Loading