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

Commit 6ec402b5 authored by Jeff Brown's avatar Jeff Brown
Browse files

DO NOT MERGE: Fix input event injection ANRs on UI thread.

Added a new asynchronous injection mode and made the existing
synchronization mechanism more robust.

Change-Id: Ia4aa04fd9b75ea2461a844c5b7933c831c1027e6
parent 6dea6f4e
Loading
Loading
Loading
Loading
+21 −22
Original line number Diff line number Diff line
@@ -174217,6 +174217,17 @@
>
<implements name="android.os.Parcelable">
</implements>
<method name="describeContents"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getDevice"
 return="android.view.InputDevice"
 abstract="false"
@@ -174250,6 +174261,16 @@
 visibility="public"
>
</method>
<field name="CREATOR"
 type="android.os.Parcelable.Creator"
 transient="false"
 volatile="false"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="mDeviceId"
 type="int"
 transient="false"
@@ -174893,17 +174914,6 @@
<parameter name="newFlags" type="int">
</parameter>
</method>
<method name="describeContents"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="dispatch"
 return="boolean"
 abstract="false"
@@ -178103,17 +178113,6 @@
<parameter name="metaState" type="int">
</parameter>
</method>
<method name="describeContents"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="findPointerIndex"
 return="int"
 abstract="false"
+5 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.view.IOnKeyguardExitResult;
import android.view.IRotationWatcher;
import android.view.IWindowSession;
import android.view.KeyEvent;
import android.view.InputEvent;
import android.view.MotionEvent;

/**
@@ -50,10 +51,13 @@ interface IWindowManager
    boolean inputMethodClientHasFocus(IInputMethodClient client);
    
    // These can only be called when injecting events to your own window,
    // or by holding the INJECT_EVENTS permission.
    // or by holding the INJECT_EVENTS permission.  These methods may block
    // until pending input events are finished being dispatched even when 'sync' is false.
    // Avoid calling these methods on your UI thread or use the 'NoWait' version instead.
    boolean injectKeyEvent(in KeyEvent ev, boolean sync);
    boolean injectPointerEvent(in MotionEvent ev, boolean sync);
    boolean injectTrackballEvent(in MotionEvent ev, boolean sync);
    boolean injectInputEventNoWait(in InputEvent ev);
    
    // These can only be called when holding the MANAGE_APP_TOKENS permission.
    void pauseKeyDispatching(IBinder token);
+20 −0
Original line number Diff line number Diff line
/* //device/java/android/android.view.InputEvent.aidl
**
** Copyright 2007, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

package android.view;

parcelable InputEvent;
+40 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import android.os.Parcel;
import android.os.Parcelable;

/**
@@ -25,6 +26,11 @@ public abstract class InputEvent implements Parcelable {
    protected int mDeviceId;
    protected int mSource;
    
    /** @hide */
    protected static final int PARCEL_TOKEN_MOTION_EVENT = 1;
    /** @hide */
    protected static final int PARCEL_TOKEN_KEY_EVENT = 2;
    
    /*package*/ InputEvent() {
    }

@@ -69,4 +75,38 @@ public abstract class InputEvent implements Parcelable {
    public final void setSource(int source) {
        mSource = source;
    }
    
    public final int describeContents() {
        return 0;
    }
    
    /** @hide */
    protected final void readBaseFromParcel(Parcel in) {
        mDeviceId = in.readInt();
        mSource = in.readInt();
    }
    
    /** @hide */
    protected final void writeBaseToParcel(Parcel out) {
        out.writeInt(mDeviceId);
        out.writeInt(mSource);
    }
    
    public static final Parcelable.Creator<InputEvent> CREATOR
            = new Parcelable.Creator<InputEvent>() {
        public InputEvent createFromParcel(Parcel in) {
            int token = in.readInt();
            if (token == PARCEL_TOKEN_KEY_EVENT) {
                return KeyEvent.createFromParcelBody(in);
            } else if (token == PARCEL_TOKEN_MOTION_EVENT) {
                return MotionEvent.createFromParcelBody(in);
            } else {
                throw new IllegalStateException("Unexpected input event type token in parcel.");
            }
        }
        
        public InputEvent[] newArray(int size) {
            return new InputEvent[size];
        }
    };
}
+23 −19
Original line number Diff line number Diff line
@@ -1211,7 +1211,8 @@ public class KeyEvent extends InputEvent implements Parcelable {
    public static final Parcelable.Creator<KeyEvent> CREATOR
            = new Parcelable.Creator<KeyEvent>() {
        public KeyEvent createFromParcel(Parcel in) {
            return new KeyEvent(in);
            in.readInt(); // skip token, we already know this is a KeyEvent
            return KeyEvent.createFromParcelBody(in);
        }

        public KeyEvent[] newArray(int size) {
@@ -1219,36 +1220,39 @@ public class KeyEvent extends InputEvent implements Parcelable {
        }
    };
    
    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mAction);
        out.writeInt(mKeyCode);
        out.writeInt(mRepeatCount);
        out.writeInt(mMetaState);
        out.writeInt(mDeviceId);
        out.writeInt(mSource);
        out.writeInt(mScanCode);
        out.writeInt(mFlags);
        out.writeLong(mDownTime);
        out.writeLong(mEventTime);
    /** @hide */
    public static KeyEvent createFromParcelBody(Parcel in) {
        return new KeyEvent(in);
    }
    
    private KeyEvent(Parcel in) {
        readBaseFromParcel(in);
        
        mAction = in.readInt();
        mKeyCode = in.readInt();
        mRepeatCount = in.readInt();
        mMetaState = in.readInt();
        mDeviceId = in.readInt();
        mSource = in.readInt();
        mScanCode = in.readInt();
        mFlags = in.readInt();
        mDownTime = in.readLong();
        mEventTime = in.readLong();
    }

    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(PARCEL_TOKEN_KEY_EVENT);
        
        writeBaseToParcel(out);
        
        out.writeInt(mAction);
        out.writeInt(mKeyCode);
        out.writeInt(mRepeatCount);
        out.writeInt(mMetaState);
        out.writeInt(mScanCode);
        out.writeInt(mFlags);
        out.writeLong(mDownTime);
        out.writeLong(mEventTime);
    }

    private native boolean native_isSystemKey(int keyCode);
    private native boolean native_hasDefaultAction(int keyCode);
}
Loading