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

Commit 00fa7bdd authored by Jeff Brown's avatar Jeff Brown
Browse files

More native input dispatch work.

Removed old input dispatch code.
Refactored the policy callbacks.
Pushed a tiny bit of the power manager state down to native.
Fixed long press on MENU.
Made the virtual key detection and cancelation a bit more precise.

Change-Id: I5d8c1062f7ea0ab3b54c6fadb058c4d5f5a9e02e
parent 8ecfb60a
Loading
Loading
Loading
Loading
+27 −50
Original line number Diff line number Diff line
@@ -216,20 +216,7 @@ public abstract class WallpaperService extends Service {
            @Override
            public void handleTouch(MotionEvent event, Runnable finishedCallback) {
                try {
                    synchronized (mLock) {
                        if (event.getAction() == MotionEvent.ACTION_MOVE) {
                            if (mPendingMove != null) {
                                mCaller.removeMessages(MSG_TOUCH_EVENT, mPendingMove);
                                mPendingMove.recycle();
                            }
                            mPendingMove = event;
                        } else {
                            mPendingMove = null;
                        }
                        Message msg = mCaller.obtainMessageO(MSG_TOUCH_EVENT,
                                event);
                        mCaller.sendMessage(msg);
                    }
                    dispatchPointer(event);
                } finally {
                    finishedCallback.run();
                }
@@ -237,26 +224,6 @@ public abstract class WallpaperService extends Service {
        };
        
        final BaseIWindow mWindow = new BaseIWindow() {
            @Override
            public boolean onDispatchPointer(MotionEvent event, long eventTime,
                    boolean callWhenDone) {
                synchronized (mLock) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE) {
                        if (mPendingMove != null) {
                            mCaller.removeMessages(MSG_TOUCH_EVENT, mPendingMove);
                            mPendingMove.recycle();
                        }
                        mPendingMove = event;
                    } else {
                        mPendingMove = null;
                    }
                    Message msg = mCaller.obtainMessageO(MSG_TOUCH_EVENT,
                            event);
                    mCaller.sendMessage(msg);
                }
                return false;
            }
            
            @Override
            public void resized(int w, int h, Rect coveredInsets,
                    Rect visibleInsets, boolean reportDraw, Configuration newConfig) {
@@ -467,6 +434,22 @@ public abstract class WallpaperService extends Service {
        public void onSurfaceDestroyed(SurfaceHolder holder) {
        }
        
        private void dispatchPointer(MotionEvent event) {
            synchronized (mLock) {
                if (event.getAction() == MotionEvent.ACTION_MOVE) {
                    if (mPendingMove != null) {
                        mCaller.removeMessages(MSG_TOUCH_EVENT, mPendingMove);
                        mPendingMove.recycle();
                    }
                    mPendingMove = event;
                } else {
                    mPendingMove = null;
                }
                Message msg = mCaller.obtainMessageO(MSG_TOUCH_EVENT, event);
                mCaller.sendMessage(msg);
            }
        }

        void updateSurface(boolean forceRelayout, boolean forceReport) {
            if (mDestroyed) {
                Log.w(TAG, "Ignoring updateSurface: destroyed");
@@ -523,11 +506,9 @@ public abstract class WallpaperService extends Service {
                                mInputChannel);
                        mCreated = true;

                        if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) {
                        InputQueue.registerInputChannel(mInputChannel, mInputHandler,
                                Looper.myQueue());
                    }
                    }
                    
                    mSurfaceHolder.mSurfaceLock.lock();
                    mDrawingAllowed = true;
@@ -770,11 +751,9 @@ public abstract class WallpaperService extends Service {
                    if (DEBUG) Log.v(TAG, "Removing window and destroying surface "
                            + mSurfaceHolder.getSurface() + " of: " + this);
                    
                    if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) {
                    if (mInputChannel != null) {
                        InputQueue.unregisterInputChannel(mInputChannel);
                    }
                    }
                    
                    mSession.remove(mWindow);
                } catch (RemoteException e) {
@@ -782,7 +761,6 @@ public abstract class WallpaperService extends Service {
                mSurfaceHolder.mSurface.release();
                mCreated = false;
                
                if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) {
                // Dispose the input channel after removing the window so the Window Manager
                // doesn't interpret the input channel being closed as an abnormal termination.
                if (mInputChannel != null) {
@@ -792,7 +770,6 @@ public abstract class WallpaperService extends Service {
            }
        }
    }
    }
    
    class IWallpaperEngineWrapper extends IWallpaperEngine.Stub
            implements HandlerCaller.Callback {
@@ -841,7 +818,7 @@ public abstract class WallpaperService extends Service {

        public void dispatchPointer(MotionEvent event) {
            if (mEngine != null) {
                mEngine.mWindow.onDispatchPointer(event, event.getEventTime(), false);
                mEngine.dispatchPointer(event);
            }
        }
        
+0 −3
Original line number Diff line number Diff line
@@ -46,9 +46,6 @@ oneway interface IWindow {

    void resized(int w, int h, in Rect coveredInsets, in Rect visibleInsets,
            boolean reportDraw, in Configuration newConfig);
    void dispatchKey(in KeyEvent event);
    void dispatchPointer(in MotionEvent event, long eventTime, boolean callWhenDone);
    void dispatchTrackball(in MotionEvent event, long eventTime, boolean callWhenDone);
    void dispatchAppVisibility(boolean visible);
    void dispatchGetNewSurface();

+0 −4
Original line number Diff line number Diff line
@@ -110,10 +110,6 @@ interface IWindowSession {
    
    void finishDrawing(IWindow window);
    
    void finishKey(IWindow window);
    MotionEvent getPendingPointerMove(IWindow window);
    MotionEvent getPendingTrackballMove(IWindow window);
    
    void setInTouchMode(boolean showFocus);
    boolean getInTouchMode();
    
+0 −201
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 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;

/**
 * @hide
 * This really belongs in services.jar; WindowManagerPolicy should go there too.
 */
public class RawInputEvent {
    // Event class as defined by EventHub.
    public static final int CLASS_KEYBOARD = 0x00000001;
    public static final int CLASS_ALPHAKEY = 0x00000002;
    public static final int CLASS_TOUCHSCREEN = 0x00000004;
    public static final int CLASS_TRACKBALL = 0x00000008;
    public static final int CLASS_TOUCHSCREEN_MT = 0x00000010;
    public static final int CLASS_DPAD = 0x00000020;
    
    // More special classes for QueuedEvent below.
    public static final int CLASS_CONFIGURATION_CHANGED = 0x10000000;
    
    // Event types.

    public static final int EV_SYN = 0x00;
    public static final int EV_KEY = 0x01;
    public static final int EV_REL = 0x02;
    public static final int EV_ABS = 0x03;
    public static final int EV_MSC = 0x04;
    public static final int EV_SW = 0x05;
    public static final int EV_LED = 0x11;
    public static final int EV_SND = 0x12;
    public static final int EV_REP = 0x14;
    public static final int EV_FF = 0x15;
    public static final int EV_PWR = 0x16;
    public static final int EV_FF_STATUS = 0x17;

    // Platform-specific event types.
    
    public static final int EV_DEVICE_ADDED = 0x10000000;
    public static final int EV_DEVICE_REMOVED = 0x20000000;
    
    // Special key (EV_KEY) scan codes for pointer buttons.

    public static final int BTN_FIRST = 0x100;

    public static final int BTN_MISC = 0x100;
    public static final int BTN_0 = 0x100;
    public static final int BTN_1 = 0x101;
    public static final int BTN_2 = 0x102;
    public static final int BTN_3 = 0x103;
    public static final int BTN_4 = 0x104;
    public static final int BTN_5 = 0x105;
    public static final int BTN_6 = 0x106;
    public static final int BTN_7 = 0x107;
    public static final int BTN_8 = 0x108;
    public static final int BTN_9 = 0x109;

    public static final int BTN_MOUSE = 0x110;
    public static final int BTN_LEFT = 0x110;
    public static final int BTN_RIGHT = 0x111;
    public static final int BTN_MIDDLE = 0x112;
    public static final int BTN_SIDE = 0x113;
    public static final int BTN_EXTRA = 0x114;
    public static final int BTN_FORWARD = 0x115;
    public static final int BTN_BACK = 0x116;
    public static final int BTN_TASK = 0x117;

    public static final int BTN_JOYSTICK = 0x120;
    public static final int BTN_TRIGGER = 0x120;
    public static final int BTN_THUMB = 0x121;
    public static final int BTN_THUMB2 = 0x122;
    public static final int BTN_TOP = 0x123;
    public static final int BTN_TOP2 = 0x124;
    public static final int BTN_PINKIE = 0x125;
    public static final int BTN_BASE = 0x126;
    public static final int BTN_BASE2 = 0x127;
    public static final int BTN_BASE3 = 0x128;
    public static final int BTN_BASE4 = 0x129;
    public static final int BTN_BASE5 = 0x12a;
    public static final int BTN_BASE6 = 0x12b;
    public static final int BTN_DEAD = 0x12f;

    public static final int BTN_GAMEPAD = 0x130;
    public static final int BTN_A = 0x130;
    public static final int BTN_B = 0x131;
    public static final int BTN_C = 0x132;
    public static final int BTN_X = 0x133;
    public static final int BTN_Y = 0x134;
    public static final int BTN_Z = 0x135;
    public static final int BTN_TL = 0x136;
    public static final int BTN_TR = 0x137;
    public static final int BTN_TL2 = 0x138;
    public static final int BTN_TR2 = 0x139;
    public static final int BTN_SELECT = 0x13a;
    public static final int BTN_START = 0x13b;
    public static final int BTN_MODE = 0x13c;
    public static final int BTN_THUMBL = 0x13d;
    public static final int BTN_THUMBR = 0x13e;

    public static final int BTN_DIGI = 0x140;
    public static final int BTN_TOOL_PEN = 0x140;
    public static final int BTN_TOOL_RUBBER = 0x141;
    public static final int BTN_TOOL_BRUSH = 0x142;
    public static final int BTN_TOOL_PENCIL = 0x143;
    public static final int BTN_TOOL_AIRBRUSH = 0x144;
    public static final int BTN_TOOL_FINGER = 0x145;
    public static final int BTN_TOOL_MOUSE = 0x146;
    public static final int BTN_TOOL_LENS = 0x147;
    public static final int BTN_TOUCH = 0x14a;
    public static final int BTN_STYLUS = 0x14b;
    public static final int BTN_STYLUS2 = 0x14c;
    public static final int BTN_TOOL_DOUBLETAP = 0x14d;
    public static final int BTN_TOOL_TRIPLETAP = 0x14e;

    public static final int BTN_WHEEL = 0x150;
    public static final int BTN_GEAR_DOWN = 0x150;
    public static final int BTN_GEAR_UP = 0x151;

    public static final int BTN_LAST = 0x15f;

    // Relative axes (EV_REL) scan codes.

    public static final int REL_X = 0x00;
    public static final int REL_Y = 0x01;
    public static final int REL_Z = 0x02;
    public static final int REL_RX = 0x03;
    public static final int REL_RY = 0x04;
    public static final int REL_RZ = 0x05;
    public static final int REL_HWHEEL = 0x06;
    public static final int REL_DIAL = 0x07;
    public static final int REL_WHEEL = 0x08;
    public static final int REL_MISC = 0x09;
    public static final int REL_MAX = 0x0f;

    // Absolute axes (EV_ABS) scan codes.

    public static final int ABS_X = 0x00;
    public static final int ABS_Y = 0x01;
    public static final int ABS_Z = 0x02;
    public static final int ABS_RX = 0x03;
    public static final int ABS_RY = 0x04;
    public static final int ABS_RZ = 0x05;
    public static final int ABS_THROTTLE = 0x06;
    public static final int ABS_RUDDER = 0x07;
    public static final int ABS_WHEEL = 0x08;
    public static final int ABS_GAS = 0x09;
    public static final int ABS_BRAKE = 0x0a;
    public static final int ABS_HAT0X = 0x10;
    public static final int ABS_HAT0Y = 0x11;
    public static final int ABS_HAT1X = 0x12;
    public static final int ABS_HAT1Y = 0x13;
    public static final int ABS_HAT2X = 0x14;
    public static final int ABS_HAT2Y = 0x15;
    public static final int ABS_HAT3X = 0x16;
    public static final int ABS_HAT3Y = 0x17;
    public static final int ABS_PRESSURE = 0x18;
    public static final int ABS_DISTANCE = 0x19;
    public static final int ABS_TILT_X = 0x1a;
    public static final int ABS_TILT_Y = 0x1b;
    public static final int ABS_TOOL_WIDTH = 0x1c;
    public static final int ABS_VOLUME = 0x20;
    public static final int ABS_MISC = 0x28;
    public static final int ABS_MT_TOUCH_MAJOR = 0x30;
    public static final int ABS_MT_TOUCH_MINOR = 0x31;
    public static final int ABS_MT_WIDTH_MAJOR = 0x32;
    public static final int ABS_MT_WIDTH_MINOR = 0x33;
    public static final int ABS_MT_ORIENTATION = 0x34;
    public static final int ABS_MT_POSITION_X = 0x35;
    public static final int ABS_MT_POSITION_Y = 0x36;
    public static final int ABS_MT_TOOL_TYPE = 0x37;
    public static final int ABS_MT_BLOB_ID = 0x38;
    public static final int ABS_MAX = 0x3f;

    // Switch events
    public static final int SW_LID = 0x00;

    public static final int SYN_REPORT = 0;
    public static final int SYN_CONFIG = 1;
    public static final int SYN_MT_REPORT = 2;
    
    public int deviceId;
    public int type;
    public int scancode;
    public int keycode;
    public int flags;
    public int value;
    public long when;
}
+0 −36
Original line number Diff line number Diff line
@@ -625,41 +625,6 @@ public class SurfaceView extends View {
            }
        }

        public void dispatchKey(KeyEvent event) {
            SurfaceView surfaceView = mSurfaceView.get();
            if (surfaceView != null) {
                //Log.w("SurfaceView", "Unexpected key event in surface: " + event);
                if (surfaceView.mSession != null && surfaceView.mSurface != null) {
                    try {
                        surfaceView.mSession.finishKey(surfaceView.mWindow);
                    } catch (RemoteException ex) {
                    }
                }
            }
        }

        public void dispatchPointer(MotionEvent event, long eventTime,
                boolean callWhenDone) {
            Log.w("SurfaceView", "Unexpected pointer event in surface: " + event);
            //if (mSession != null && mSurface != null) {
            //    try {
            //        //mSession.finishKey(mWindow);
            //    } catch (RemoteException ex) {
            //    }
            //}
        }

        public void dispatchTrackball(MotionEvent event, long eventTime,
                boolean callWhenDone) {
            Log.w("SurfaceView", "Unexpected trackball event in surface: " + event);
            //if (mSession != null && mSurface != null) {
            //    try {
            //        //mSession.finishKey(mWindow);
            //    } catch (RemoteException ex) {
            //    }
            //}
        }

        public void dispatchAppVisibility(boolean visible) {
            // The point of SurfaceView is to let the app control the surface.
        }
@@ -686,7 +651,6 @@ public class SurfaceView extends View {
    private SurfaceHolder mSurfaceHolder = new SurfaceHolder() {
        
        private static final String LOG_TAG = "SurfaceHolder";
        private int mSaveCount;
        
        public boolean isCreating() {
            return mIsCreating;
Loading