Home | History | Annotate | Download | only in inputflinger
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _UI_INPUT_LISTENER_H
     18 #define _UI_INPUT_LISTENER_H
     19 
     20 #include <input/Input.h>
     21 #include <utils/RefBase.h>
     22 #include <utils/Vector.h>
     23 
     24 namespace android {
     25 
     26 class InputListenerInterface;
     27 
     28 
     29 /* Superclass of all input event argument objects */
     30 struct NotifyArgs {
     31     virtual ~NotifyArgs() { }
     32 
     33     virtual void notify(const sp<InputListenerInterface>& listener) const = 0;
     34 };
     35 
     36 
     37 /* Describes a configuration change event. */
     38 struct NotifyConfigurationChangedArgs : public NotifyArgs {
     39     nsecs_t eventTime;
     40 
     41     inline NotifyConfigurationChangedArgs() { }
     42 
     43     NotifyConfigurationChangedArgs(nsecs_t eventTime);
     44 
     45     NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other);
     46 
     47     virtual ~NotifyConfigurationChangedArgs() { }
     48 
     49     virtual void notify(const sp<InputListenerInterface>& listener) const;
     50 };
     51 
     52 
     53 /* Describes a key event. */
     54 struct NotifyKeyArgs : public NotifyArgs {
     55     nsecs_t eventTime;
     56     int32_t deviceId;
     57     uint32_t source;
     58     uint32_t policyFlags;
     59     int32_t action;
     60     int32_t flags;
     61     int32_t keyCode;
     62     int32_t scanCode;
     63     int32_t metaState;
     64     nsecs_t downTime;
     65 
     66     inline NotifyKeyArgs() { }
     67 
     68     NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
     69             int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
     70             int32_t metaState, nsecs_t downTime);
     71 
     72     NotifyKeyArgs(const NotifyKeyArgs& other);
     73 
     74     virtual ~NotifyKeyArgs() { }
     75 
     76     virtual void notify(const sp<InputListenerInterface>& listener) const;
     77 };
     78 
     79 
     80 /* Describes a motion event. */
     81 struct NotifyMotionArgs : public NotifyArgs {
     82     nsecs_t eventTime;
     83     int32_t deviceId;
     84     uint32_t source;
     85     uint32_t policyFlags;
     86     int32_t action;
     87     int32_t actionButton;
     88     int32_t flags;
     89     int32_t metaState;
     90     int32_t buttonState;
     91     int32_t edgeFlags;
     92     int32_t displayId;
     93     uint32_t pointerCount;
     94     PointerProperties pointerProperties[MAX_POINTERS];
     95     PointerCoords pointerCoords[MAX_POINTERS];
     96     float xPrecision;
     97     float yPrecision;
     98     nsecs_t downTime;
     99 
    100     inline NotifyMotionArgs() { }
    101 
    102     NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
    103             int32_t action, int32_t actionButton, int32_t flags,
    104             int32_t metaState, int32_t buttonState,
    105             int32_t edgeFlags, int32_t displayId, uint32_t pointerCount,
    106             const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
    107             float xPrecision, float yPrecision, nsecs_t downTime);
    108 
    109     NotifyMotionArgs(const NotifyMotionArgs& other);
    110 
    111     virtual ~NotifyMotionArgs() { }
    112 
    113     virtual void notify(const sp<InputListenerInterface>& listener) const;
    114 };
    115 
    116 
    117 /* Describes a switch event. */
    118 struct NotifySwitchArgs : public NotifyArgs {
    119     nsecs_t eventTime;
    120     uint32_t policyFlags;
    121     uint32_t switchValues;
    122     uint32_t switchMask;
    123 
    124     inline NotifySwitchArgs() { }
    125 
    126     NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
    127             uint32_t switchValues, uint32_t switchMask);
    128 
    129     NotifySwitchArgs(const NotifySwitchArgs& other);
    130 
    131     virtual ~NotifySwitchArgs() { }
    132 
    133     virtual void notify(const sp<InputListenerInterface>& listener) const;
    134 };
    135 
    136 
    137 /* Describes a device reset event, such as when a device is added,
    138  * reconfigured, or removed. */
    139 struct NotifyDeviceResetArgs : public NotifyArgs {
    140     nsecs_t eventTime;
    141     int32_t deviceId;
    142 
    143     inline NotifyDeviceResetArgs() { }
    144 
    145     NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId);
    146 
    147     NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other);
    148 
    149     virtual ~NotifyDeviceResetArgs() { }
    150 
    151     virtual void notify(const sp<InputListenerInterface>& listener) const;
    152 };
    153 
    154 
    155 /*
    156  * The interface used by the InputReader to notify the InputListener about input events.
    157  */
    158 class InputListenerInterface : public virtual RefBase {
    159 protected:
    160     InputListenerInterface() { }
    161     virtual ~InputListenerInterface() { }
    162 
    163 public:
    164     virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) = 0;
    165     virtual void notifyKey(const NotifyKeyArgs* args) = 0;
    166     virtual void notifyMotion(const NotifyMotionArgs* args) = 0;
    167     virtual void notifySwitch(const NotifySwitchArgs* args) = 0;
    168     virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0;
    169 };
    170 
    171 
    172 /*
    173  * An implementation of the listener interface that queues up and defers dispatch
    174  * of decoded events until flushed.
    175  */
    176 class QueuedInputListener : public InputListenerInterface {
    177 protected:
    178     virtual ~QueuedInputListener();
    179 
    180 public:
    181     QueuedInputListener(const sp<InputListenerInterface>& innerListener);
    182 
    183     virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args);
    184     virtual void notifyKey(const NotifyKeyArgs* args);
    185     virtual void notifyMotion(const NotifyMotionArgs* args);
    186     virtual void notifySwitch(const NotifySwitchArgs* args);
    187     virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
    188 
    189     void flush();
    190 
    191 private:
    192     sp<InputListenerInterface> mInnerListener;
    193     Vector<NotifyArgs*> mArgsQueue;
    194 };
    195 
    196 } // namespace android
    197 
    198 #endif // _UI_INPUT_LISTENER_H
    199