• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define LOG_TAG "InputListener"
18 
19 //#define LOG_NDEBUG 0
20 
21 #include "InputListener.h"
22 
23 #include <android/log.h>
24 
25 namespace android {
26 
27 // --- NotifyConfigurationChangedArgs ---
28 
NotifyConfigurationChangedArgs(uint32_t sequenceNum,nsecs_t eventTime)29 NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(
30         uint32_t sequenceNum, nsecs_t eventTime) :
31         NotifyArgs(sequenceNum, eventTime) {
32 }
33 
NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs & other)34 NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(
35         const NotifyConfigurationChangedArgs& other) :
36         NotifyArgs(other.sequenceNum, other.eventTime) {
37 }
38 
operator ==(const NotifyConfigurationChangedArgs & rhs) const39 bool NotifyConfigurationChangedArgs::operator==(const NotifyConfigurationChangedArgs& rhs) const {
40     return sequenceNum == rhs.sequenceNum && eventTime == rhs.eventTime;
41 }
42 
notify(const sp<InputListenerInterface> & listener) const43 void NotifyConfigurationChangedArgs::notify(const sp<InputListenerInterface>& listener) const {
44     listener->notifyConfigurationChanged(this);
45 }
46 
47 
48 // --- NotifyKeyArgs ---
49 
NotifyKeyArgs(uint32_t sequenceNum,nsecs_t eventTime,int32_t deviceId,uint32_t source,int32_t displayId,uint32_t policyFlags,int32_t action,int32_t flags,int32_t keyCode,int32_t scanCode,int32_t metaState,nsecs_t downTime)50 NotifyKeyArgs::NotifyKeyArgs(uint32_t sequenceNum, nsecs_t eventTime, int32_t deviceId,
51         uint32_t source, int32_t displayId, uint32_t policyFlags,
52         int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
53         int32_t metaState, nsecs_t downTime) :
54         NotifyArgs(sequenceNum, eventTime), deviceId(deviceId), source(source),
55         displayId(displayId), policyFlags(policyFlags),
56         action(action), flags(flags), keyCode(keyCode), scanCode(scanCode),
57         metaState(metaState), downTime(downTime) {
58 }
59 
NotifyKeyArgs(const NotifyKeyArgs & other)60 NotifyKeyArgs::NotifyKeyArgs(const NotifyKeyArgs& other) :
61         NotifyArgs(other.sequenceNum, other.eventTime), deviceId(other.deviceId),
62         source(other.source), displayId(other.displayId), policyFlags(other.policyFlags),
63         action(other.action), flags(other.flags),
64         keyCode(other.keyCode), scanCode(other.scanCode),
65         metaState(other.metaState), downTime(other.downTime) {
66 }
67 
operator ==(const NotifyKeyArgs & rhs) const68 bool NotifyKeyArgs::operator==(const NotifyKeyArgs& rhs) const {
69     return sequenceNum == rhs.sequenceNum
70             && eventTime == rhs.eventTime
71             && deviceId == rhs.deviceId
72             && source == rhs.source
73             && displayId == rhs.displayId
74             && policyFlags == rhs.policyFlags
75             && action == rhs.action
76             && flags == rhs.flags
77             && keyCode == rhs.keyCode
78             && scanCode == rhs.scanCode
79             && metaState == rhs.metaState
80             && downTime == rhs.downTime;
81 }
82 
notify(const sp<InputListenerInterface> & listener) const83 void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const {
84     listener->notifyKey(this);
85 }
86 
87 
88 // --- NotifyMotionArgs ---
89 
NotifyMotionArgs(uint32_t sequenceNum,nsecs_t eventTime,int32_t deviceId,uint32_t source,int32_t displayId,uint32_t policyFlags,int32_t action,int32_t actionButton,int32_t flags,int32_t metaState,int32_t buttonState,MotionClassification classification,int32_t edgeFlags,uint32_t deviceTimestamp,uint32_t pointerCount,const PointerProperties * pointerProperties,const PointerCoords * pointerCoords,float xPrecision,float yPrecision,nsecs_t downTime,const std::vector<TouchVideoFrame> & videoFrames)90 NotifyMotionArgs::NotifyMotionArgs(uint32_t sequenceNum, nsecs_t eventTime, int32_t deviceId,
91         uint32_t source, int32_t displayId, uint32_t policyFlags,
92         int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
93         int32_t buttonState, MotionClassification classification,
94         int32_t edgeFlags, uint32_t deviceTimestamp, uint32_t pointerCount,
95         const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
96         float xPrecision, float yPrecision, nsecs_t downTime,
97         const std::vector<TouchVideoFrame>& videoFrames) :
98         NotifyArgs(sequenceNum, eventTime), deviceId(deviceId), source(source),
99         displayId(displayId), policyFlags(policyFlags),
100         action(action), actionButton(actionButton),
101         flags(flags), metaState(metaState), buttonState(buttonState),
102         classification(classification), edgeFlags(edgeFlags), deviceTimestamp(deviceTimestamp),
103         pointerCount(pointerCount),
104         xPrecision(xPrecision), yPrecision(yPrecision), downTime(downTime),
105         videoFrames(videoFrames) {
106     for (uint32_t i = 0; i < pointerCount; i++) {
107         this->pointerProperties[i].copyFrom(pointerProperties[i]);
108         this->pointerCoords[i].copyFrom(pointerCoords[i]);
109     }
110 }
111 
NotifyMotionArgs(const NotifyMotionArgs & other)112 NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other) :
113         NotifyArgs(other.sequenceNum, other.eventTime), deviceId(other.deviceId),
114         source(other.source), displayId(other.displayId), policyFlags(other.policyFlags),
115         action(other.action), actionButton(other.actionButton), flags(other.flags),
116         metaState(other.metaState), buttonState(other.buttonState),
117         classification(other.classification), edgeFlags(other.edgeFlags),
118         deviceTimestamp(other.deviceTimestamp), pointerCount(other.pointerCount),
119         xPrecision(other.xPrecision), yPrecision(other.yPrecision), downTime(other.downTime),
120         videoFrames(other.videoFrames) {
121     for (uint32_t i = 0; i < pointerCount; i++) {
122         pointerProperties[i].copyFrom(other.pointerProperties[i]);
123         pointerCoords[i].copyFrom(other.pointerCoords[i]);
124     }
125 }
126 
operator ==(const NotifyMotionArgs & rhs) const127 bool NotifyMotionArgs::operator==(const NotifyMotionArgs& rhs) const {
128     bool equal =
129             sequenceNum == rhs.sequenceNum
130             && eventTime == rhs.eventTime
131             && deviceId == rhs.deviceId
132             && source == rhs.source
133             && displayId == rhs.displayId
134             && policyFlags == rhs.policyFlags
135             && action == rhs.action
136             && actionButton == rhs.actionButton
137             && flags == rhs.flags
138             && metaState == rhs.metaState
139             && buttonState == rhs.buttonState
140             && classification == rhs.classification
141             && edgeFlags == rhs.edgeFlags
142             && deviceTimestamp == rhs.deviceTimestamp
143             && pointerCount == rhs.pointerCount
144             // PointerProperties and PointerCoords are compared separately below
145             && xPrecision == rhs.xPrecision
146             && yPrecision == rhs.yPrecision
147             && downTime == rhs.downTime
148             && videoFrames == rhs.videoFrames;
149     if (!equal) {
150         return false;
151     }
152 
153     for (size_t i = 0; i < pointerCount; i++) {
154         equal =
155                 pointerProperties[i] == rhs.pointerProperties[i]
156                 && pointerCoords[i] == rhs.pointerCoords[i];
157         if (!equal) {
158             return false;
159         }
160     }
161     return true;
162 }
163 
notify(const sp<InputListenerInterface> & listener) const164 void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const {
165     listener->notifyMotion(this);
166 }
167 
168 
169 // --- NotifySwitchArgs ---
170 
NotifySwitchArgs(uint32_t sequenceNum,nsecs_t eventTime,uint32_t policyFlags,uint32_t switchValues,uint32_t switchMask)171 NotifySwitchArgs::NotifySwitchArgs(uint32_t sequenceNum, nsecs_t eventTime, uint32_t policyFlags,
172         uint32_t switchValues, uint32_t switchMask) :
173         NotifyArgs(sequenceNum, eventTime), policyFlags(policyFlags),
174         switchValues(switchValues), switchMask(switchMask) {
175 }
176 
NotifySwitchArgs(const NotifySwitchArgs & other)177 NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) :
178         NotifyArgs(other.sequenceNum, other.eventTime), policyFlags(other.policyFlags),
179         switchValues(other.switchValues), switchMask(other.switchMask) {
180 }
181 
operator ==(const NotifySwitchArgs rhs) const182 bool NotifySwitchArgs::operator==(const NotifySwitchArgs rhs) const {
183     return sequenceNum == rhs.sequenceNum
184             && eventTime == rhs.eventTime
185             && policyFlags == rhs.policyFlags
186             && switchValues == rhs.switchValues
187             && switchMask == rhs.switchMask;
188 }
189 
notify(const sp<InputListenerInterface> & listener) const190 void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const {
191     listener->notifySwitch(this);
192 }
193 
194 
195 // --- NotifyDeviceResetArgs ---
196 
NotifyDeviceResetArgs(uint32_t sequenceNum,nsecs_t eventTime,int32_t deviceId)197 NotifyDeviceResetArgs::NotifyDeviceResetArgs(
198         uint32_t sequenceNum, nsecs_t eventTime, int32_t deviceId) :
199         NotifyArgs(sequenceNum, eventTime), deviceId(deviceId) {
200 }
201 
NotifyDeviceResetArgs(const NotifyDeviceResetArgs & other)202 NotifyDeviceResetArgs::NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) :
203         NotifyArgs(other.sequenceNum, other.eventTime), deviceId(other.deviceId) {
204 }
205 
operator ==(const NotifyDeviceResetArgs & rhs) const206 bool NotifyDeviceResetArgs::operator==(const NotifyDeviceResetArgs& rhs) const {
207     return sequenceNum == rhs.sequenceNum
208             && eventTime == rhs.eventTime
209             && deviceId == rhs.deviceId;
210 }
211 
notify(const sp<InputListenerInterface> & listener) const212 void NotifyDeviceResetArgs::notify(const sp<InputListenerInterface>& listener) const {
213     listener->notifyDeviceReset(this);
214 }
215 
216 
217 // --- QueuedInputListener ---
218 
QueuedInputListener(const sp<InputListenerInterface> & innerListener)219 QueuedInputListener::QueuedInputListener(const sp<InputListenerInterface>& innerListener) :
220         mInnerListener(innerListener) {
221 }
222 
~QueuedInputListener()223 QueuedInputListener::~QueuedInputListener() {
224     size_t count = mArgsQueue.size();
225     for (size_t i = 0; i < count; i++) {
226         delete mArgsQueue[i];
227     }
228 }
229 
notifyConfigurationChanged(const NotifyConfigurationChangedArgs * args)230 void QueuedInputListener::notifyConfigurationChanged(
231         const NotifyConfigurationChangedArgs* args) {
232     mArgsQueue.push_back(new NotifyConfigurationChangedArgs(*args));
233 }
234 
notifyKey(const NotifyKeyArgs * args)235 void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) {
236     mArgsQueue.push_back(new NotifyKeyArgs(*args));
237 }
238 
notifyMotion(const NotifyMotionArgs * args)239 void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) {
240     mArgsQueue.push_back(new NotifyMotionArgs(*args));
241 }
242 
notifySwitch(const NotifySwitchArgs * args)243 void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
244     mArgsQueue.push_back(new NotifySwitchArgs(*args));
245 }
246 
notifyDeviceReset(const NotifyDeviceResetArgs * args)247 void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
248     mArgsQueue.push_back(new NotifyDeviceResetArgs(*args));
249 }
250 
flush()251 void QueuedInputListener::flush() {
252     size_t count = mArgsQueue.size();
253     for (size_t i = 0; i < count; i++) {
254         NotifyArgs* args = mArgsQueue[i];
255         args->notify(mInnerListener);
256         delete args;
257     }
258     mArgsQueue.clear();
259 }
260 
261 
262 } // namespace android
263