blob: 8cd95788553c49e3965b5cbe9ab383e8511ddcc9 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
17package com.android.server;
18
19import android.content.Context;
20import android.content.res.Configuration;
Adam Powellf5bcc6a2010-03-02 10:42:16 -080021import android.content.res.Resources;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -040022import android.os.Environment;
Michael Chan53071d62009-05-13 17:29:48 -070023import android.os.LatencyTimer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.os.PowerManager;
Michael Chan53071d62009-05-13 17:29:48 -070025import android.os.SystemClock;
Dianne Hackborna2e92262010-03-02 17:19:29 -080026import android.os.SystemProperties;
Joe Onorato8a9b2202010-02-26 18:56:32 -080027import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.util.SparseArray;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -040029import android.util.Xml;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.view.Display;
31import android.view.KeyEvent;
32import android.view.MotionEvent;
33import android.view.RawInputEvent;
34import android.view.Surface;
35import android.view.WindowManagerPolicy;
36
Dianne Hackborn2269d1572010-02-24 19:54:22 -080037import com.android.internal.util.XmlUtils;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -040038
39import org.xmlpull.v1.XmlPullParser;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -040040
Dianne Hackborne3dd8842009-07-14 12:06:54 -070041import java.io.BufferedReader;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -040042import java.io.File;
Dianne Hackborne3dd8842009-07-14 12:06:54 -070043import java.io.FileInputStream;
44import java.io.FileNotFoundException;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -040045import java.io.FileReader;
Dianne Hackborne3dd8842009-07-14 12:06:54 -070046import java.io.IOException;
47import java.io.InputStreamReader;
Dianne Hackborna2e92262010-03-02 17:19:29 -080048import java.io.PrintWriter;
Dianne Hackborne3dd8842009-07-14 12:06:54 -070049import java.util.ArrayList;
50
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051public abstract class KeyInputQueue {
52 static final String TAG = "KeyInputQueue";
53
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -070054 static final boolean DEBUG = false;
Dianne Hackborne3dd8842009-07-14 12:06:54 -070055 static final boolean DEBUG_VIRTUAL_KEYS = false;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -070056 static final boolean DEBUG_POINTERS = false;
Dianne Hackborne3dd8842009-07-14 12:06:54 -070057
Dianne Hackborn1411d1c2009-10-12 23:21:18 -070058 /**
59 * Turn on some hacks we have to improve the touch interaction with a
60 * certain device whose screen currently is not all that good.
61 */
Dianne Hackborn65cb6052009-11-10 17:06:22 -080062 static boolean BAD_TOUCH_HACK = false;
Dianne Hackborn1411d1c2009-10-12 23:21:18 -070063
Adam Powellf5bcc6a2010-03-02 10:42:16 -080064 /**
65 * Turn on some hacks to improve touch interaction with another device
66 * where touch coordinate data can get corrupted.
67 */
68 static boolean JUMPY_TOUCH_HACK = false;
69
Mike Lockwood1d9dfc52009-07-16 11:11:18 -040070 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
71
Dianne Hackborne3dd8842009-07-14 12:06:54 -070072 final SparseArray<InputDevice> mDevices = new SparseArray<InputDevice>();
Dianne Hackborna8f60182009-09-01 19:01:50 -070073 final SparseArray<InputDevice> mIgnoredDevices = new SparseArray<InputDevice>();
Dianne Hackborne3dd8842009-07-14 12:06:54 -070074 final ArrayList<VirtualKey> mVirtualKeys = new ArrayList<VirtualKey>();
Dianne Hackbornddca3ee2009-07-23 19:01:31 -070075 final HapticFeedbackCallback mHapticFeedbackCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
77 int mGlobalMetaState = 0;
78 boolean mHaveGlobalMetaState = false;
79
80 final QueuedEvent mFirst;
81 final QueuedEvent mLast;
82 QueuedEvent mCache;
83 int mCacheCount;
84
85 Display mDisplay = null;
Dianne Hackborne3dd8842009-07-14 12:06:54 -070086 int mDisplayWidth;
87 int mDisplayHeight;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
89 int mOrientation = Surface.ROTATION_0;
90 int[] mKeyRotationMap = null;
91
Dianne Hackborne3dd8842009-07-14 12:06:54 -070092 VirtualKey mPressedVirtualKey = null;
93
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 PowerManager.WakeLock mWakeLock;
95
96 static final int[] KEY_90_MAP = new int[] {
97 KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT,
98 KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_UP,
99 KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_LEFT,
100 KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_DOWN,
101 };
102
103 static final int[] KEY_180_MAP = new int[] {
104 KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_UP,
105 KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_LEFT,
106 KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN,
107 KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT,
108 };
109
110 static final int[] KEY_270_MAP = new int[] {
111 KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_LEFT,
112 KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_UP,
113 KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_RIGHT,
114 KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_DOWN,
115 };
116
117 public static final int FILTER_REMOVE = 0;
118 public static final int FILTER_KEEP = 1;
119 public static final int FILTER_ABORT = -1;
Michael Chan53071d62009-05-13 17:29:48 -0700120
121 private static final boolean MEASURE_LATENCY = false;
122 private LatencyTimer lt;
123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 public interface FilterCallback {
125 int filterEvent(QueuedEvent ev);
126 }
127
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700128 public interface HapticFeedbackCallback {
129 void virtualKeyFeedback(KeyEvent event);
130 }
131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 static class QueuedEvent {
133 InputDevice inputDevice;
Michael Chan53071d62009-05-13 17:29:48 -0700134 long whenNano;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 int flags; // From the raw event
136 int classType; // One of the class constants in InputEvent
137 Object event;
138 boolean inQueue;
139
140 void copyFrom(QueuedEvent that) {
141 this.inputDevice = that.inputDevice;
Michael Chan53071d62009-05-13 17:29:48 -0700142 this.whenNano = that.whenNano;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 this.flags = that.flags;
144 this.classType = that.classType;
145 this.event = that.event;
146 }
147
148 @Override
149 public String toString() {
150 return "QueuedEvent{"
151 + Integer.toHexString(System.identityHashCode(this))
152 + " " + event + "}";
153 }
154
155 // not copied
156 QueuedEvent prev;
157 QueuedEvent next;
158 }
159
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700160 /**
161 * A key that exists as a part of the touch-screen, outside of the normal
162 * display area of the screen.
163 */
164 static class VirtualKey {
165 int scancode;
166 int centerx;
167 int centery;
168 int width;
169 int height;
170
171 int hitLeft;
172 int hitTop;
173 int hitRight;
174 int hitBottom;
175
176 InputDevice lastDevice;
177 int lastKeycode;
178
179 boolean checkHit(int x, int y) {
180 return (x >= hitLeft && x <= hitRight
181 && y >= hitTop && y <= hitBottom);
182 }
183
184 void computeHitRect(InputDevice dev, int dw, int dh) {
185 if (dev == lastDevice) {
186 return;
187 }
188
Joe Onorato8a9b2202010-02-26 18:56:32 -0800189 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "computeHitRect for " + scancode
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700190 + ": dev=" + dev + " absX=" + dev.absX + " absY=" + dev.absY);
191
192 lastDevice = dev;
193
194 int minx = dev.absX.minValue;
195 int maxx = dev.absX.maxValue;
196
197 int halfw = width/2;
198 int left = centerx - halfw;
199 int right = centerx + halfw;
200 hitLeft = minx + ((left*maxx-minx)/dw);
201 hitRight = minx + ((right*maxx-minx)/dw);
202
203 int miny = dev.absY.minValue;
204 int maxy = dev.absY.maxValue;
205
206 int halfh = height/2;
207 int top = centery - halfh;
208 int bottom = centery + halfh;
209 hitTop = miny + ((top*maxy-miny)/dh);
210 hitBottom = miny + ((bottom*maxy-miny)/dh);
211 }
212 }
Michael Chan53071d62009-05-13 17:29:48 -0700213
Iliyan Malchev75b2aed2009-08-06 14:50:57 -0700214 private void readVirtualKeys(String deviceName) {
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700215 try {
216 FileInputStream fis = new FileInputStream(
Iliyan Malchev75b2aed2009-08-06 14:50:57 -0700217 "/sys/board_properties/virtualkeys." + deviceName);
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700218 InputStreamReader isr = new InputStreamReader(fis);
Dianne Hackbornbd0a81f2009-10-04 13:30:50 -0700219 BufferedReader br = new BufferedReader(isr, 2048);
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700220 String str = br.readLine();
221 if (str != null) {
222 String[] it = str.split(":");
Joe Onorato8a9b2202010-02-26 18:56:32 -0800223 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "***** VIRTUAL KEYS: " + it);
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700224 final int N = it.length-6;
225 for (int i=0; i<=N; i+=6) {
226 if (!"0x01".equals(it[i])) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800227 Slog.w(TAG, "Unknown virtual key type at elem #" + i
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700228 + ": " + it[i]);
229 continue;
230 }
231 try {
232 VirtualKey sb = new VirtualKey();
233 sb.scancode = Integer.parseInt(it[i+1]);
234 sb.centerx = Integer.parseInt(it[i+2]);
235 sb.centery = Integer.parseInt(it[i+3]);
236 sb.width = Integer.parseInt(it[i+4]);
237 sb.height = Integer.parseInt(it[i+5]);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800238 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Virtual key "
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700239 + sb.scancode + ": center=" + sb.centerx + ","
240 + sb.centery + " size=" + sb.width + "x"
241 + sb.height);
242 mVirtualKeys.add(sb);
243 } catch (NumberFormatException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800244 Slog.w(TAG, "Bad number at region " + i + " in: "
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700245 + str, e);
246 }
247 }
248 }
249 br.close();
250 } catch (FileNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800251 Slog.i(TAG, "No virtual keys found");
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700252 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800253 Slog.w(TAG, "Error reading virtual keys", e);
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700254 }
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400255 }
256
257 private void readExcludedDevices() {
258 // Read partner-provided list of excluded input devices
259 XmlPullParser parser = null;
260 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
261 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
262 FileReader confreader = null;
263 try {
264 confreader = new FileReader(confFile);
265 parser = Xml.newPullParser();
266 parser.setInput(confreader);
267 XmlUtils.beginDocument(parser, "devices");
268
269 while (true) {
270 XmlUtils.nextElement(parser);
271 if (!"device".equals(parser.getName())) {
272 break;
273 }
274 String name = parser.getAttributeValue(null, "name");
275 if (name != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800276 if (DEBUG) Slog.v(TAG, "addExcludedDevice " + name);
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400277 addExcludedDevice(name);
278 }
279 }
280 } catch (FileNotFoundException e) {
281 // It's ok if the file does not exist.
282 } catch (Exception e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800283 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400284 } finally {
285 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
286 }
287 }
288
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700289 KeyInputQueue(Context context, HapticFeedbackCallback hapticFeedbackCallback) {
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400290 if (MEASURE_LATENCY) {
291 lt = new LatencyTimer(100, 1000);
292 }
293
Adam Powellf5bcc6a2010-03-02 10:42:16 -0800294 Resources r = context.getResources();
295 BAD_TOUCH_HACK = r.getBoolean(com.android.internal.R.bool.config_filterTouchEvents);
296
297 JUMPY_TOUCH_HACK = r.getBoolean(com.android.internal.R.bool.config_filterJumpyTouchEvents);
Dianne Hackborn65cb6052009-11-10 17:06:22 -0800298
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700299 mHapticFeedbackCallback = hapticFeedbackCallback;
300
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400301 readExcludedDevices();
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 PowerManager pm = (PowerManager)context.getSystemService(
304 Context.POWER_SERVICE);
305 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
306 "KeyInputQueue");
307 mWakeLock.setReferenceCounted(false);
308
309 mFirst = new QueuedEvent();
310 mLast = new QueuedEvent();
311 mFirst.next = mLast;
312 mLast.prev = mFirst;
313
314 mThread.start();
315 }
316
317 public void setDisplay(Display display) {
318 mDisplay = display;
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700319
320 // We assume at this point that the display dimensions reflect the
321 // natural, unrotated display. We will perform hit tests for soft
322 // buttons based on that display.
323 mDisplayWidth = display.getWidth();
324 mDisplayHeight = display.getHeight();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 }
326
327 public void getInputConfiguration(Configuration config) {
328 synchronized (mFirst) {
329 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
330 config.keyboard = Configuration.KEYBOARD_NOKEYS;
331 config.navigation = Configuration.NAVIGATION_NONAV;
332
333 final int N = mDevices.size();
334 for (int i=0; i<N; i++) {
335 InputDevice d = mDevices.valueAt(i);
336 if (d != null) {
337 if ((d.classes&RawInputEvent.CLASS_TOUCHSCREEN) != 0) {
338 config.touchscreen
339 = Configuration.TOUCHSCREEN_FINGER;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800340 //Slog.i("foo", "***** HAVE TOUCHSCREEN!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 }
342 if ((d.classes&RawInputEvent.CLASS_ALPHAKEY) != 0) {
343 config.keyboard
344 = Configuration.KEYBOARD_QWERTY;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800345 //Slog.i("foo", "***** HAVE QWERTY!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 }
347 if ((d.classes&RawInputEvent.CLASS_TRACKBALL) != 0) {
348 config.navigation
349 = Configuration.NAVIGATION_TRACKBALL;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800350 //Slog.i("foo", "***** HAVE TRACKBALL!");
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700351 } else if ((d.classes&RawInputEvent.CLASS_DPAD) != 0) {
352 config.navigation
353 = Configuration.NAVIGATION_DPAD;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800354 //Slog.i("foo", "***** HAVE DPAD!");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 }
356 }
357 }
358 }
359 }
360
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700361 public int getScancodeState(int code) {
362 synchronized (mFirst) {
363 VirtualKey vk = mPressedVirtualKey;
364 if (vk != null) {
365 if (vk.scancode == code) {
366 return 2;
367 }
368 }
369 return nativeGetScancodeState(code);
370 }
371 }
372
373 public int getScancodeState(int deviceId, int code) {
374 synchronized (mFirst) {
375 VirtualKey vk = mPressedVirtualKey;
376 if (vk != null) {
377 if (vk.scancode == code) {
378 return 2;
379 }
380 }
381 return nativeGetScancodeState(deviceId, code);
382 }
383 }
384
Dianne Hackborn1d62ea92009-11-17 12:49:50 -0800385 public int getTrackballScancodeState(int code) {
386 synchronized (mFirst) {
387 final int N = mDevices.size();
388 for (int i=0; i<N; i++) {
389 InputDevice dev = mDevices.valueAt(i);
390 if ((dev.classes&RawInputEvent.CLASS_TRACKBALL) != 0) {
391 int res = nativeGetScancodeState(dev.id, code);
392 if (res > 0) {
393 return res;
394 }
395 }
396 }
397 }
398
399 return 0;
400 }
401
402 public int getDPadScancodeState(int code) {
403 synchronized (mFirst) {
404 final int N = mDevices.size();
405 for (int i=0; i<N; i++) {
406 InputDevice dev = mDevices.valueAt(i);
407 if ((dev.classes&RawInputEvent.CLASS_DPAD) != 0) {
408 int res = nativeGetScancodeState(dev.id, code);
409 if (res > 0) {
410 return res;
411 }
412 }
413 }
414 }
415
416 return 0;
417 }
418
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700419 public int getKeycodeState(int code) {
420 synchronized (mFirst) {
421 VirtualKey vk = mPressedVirtualKey;
422 if (vk != null) {
423 if (vk.lastKeycode == code) {
424 return 2;
425 }
426 }
427 return nativeGetKeycodeState(code);
428 }
429 }
430
431 public int getKeycodeState(int deviceId, int code) {
432 synchronized (mFirst) {
433 VirtualKey vk = mPressedVirtualKey;
434 if (vk != null) {
435 if (vk.lastKeycode == code) {
436 return 2;
437 }
438 }
439 return nativeGetKeycodeState(deviceId, code);
440 }
441 }
442
Dianne Hackborn1d62ea92009-11-17 12:49:50 -0800443 public int getTrackballKeycodeState(int code) {
444 synchronized (mFirst) {
445 final int N = mDevices.size();
446 for (int i=0; i<N; i++) {
447 InputDevice dev = mDevices.valueAt(i);
448 if ((dev.classes&RawInputEvent.CLASS_TRACKBALL) != 0) {
449 int res = nativeGetKeycodeState(dev.id, code);
450 if (res > 0) {
451 return res;
452 }
453 }
454 }
455 }
456
457 return 0;
458 }
459
460 public int getDPadKeycodeState(int code) {
461 synchronized (mFirst) {
462 final int N = mDevices.size();
463 for (int i=0; i<N; i++) {
464 InputDevice dev = mDevices.valueAt(i);
465 if ((dev.classes&RawInputEvent.CLASS_DPAD) != 0) {
466 int res = nativeGetKeycodeState(dev.id, code);
467 if (res > 0) {
468 return res;
469 }
470 }
471 }
472 }
473
474 return 0;
475 }
476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 public static native String getDeviceName(int deviceId);
478 public static native int getDeviceClasses(int deviceId);
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400479 public static native void addExcludedDevice(String deviceName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 public static native boolean getAbsoluteInfo(int deviceId, int axis,
481 InputDevice.AbsoluteInfo outInfo);
482 public static native int getSwitchState(int sw);
483 public static native int getSwitchState(int deviceId, int sw);
Dianne Hackborn6af0d502009-09-28 13:25:46 -0700484 public static native int nativeGetScancodeState(int code);
485 public static native int nativeGetScancodeState(int deviceId, int code);
486 public static native int nativeGetKeycodeState(int code);
487 public static native int nativeGetKeycodeState(int deviceId, int code);
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700488 public static native int scancodeToKeycode(int deviceId, int scancode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 public static native boolean hasKeys(int[] keycodes, boolean[] keyExists);
490
491 public static KeyEvent newKeyEvent(InputDevice device, long downTime,
492 long eventTime, boolean down, int keycode, int repeatCount,
493 int scancode, int flags) {
494 return new KeyEvent(
495 downTime, eventTime,
496 down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP,
497 keycode, repeatCount,
498 device != null ? device.mMetaKeysState : 0,
499 device != null ? device.id : -1, scancode,
The Android Open Source Project10592532009-03-18 17:39:46 -0700500 flags | KeyEvent.FLAG_FROM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 }
502
503 Thread mThread = new Thread("InputDeviceReader") {
504 public void run() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800505 if (DEBUG) Slog.v(TAG, "InputDeviceReader.run()");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 android.os.Process.setThreadPriority(
507 android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
508
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700509 RawInputEvent ev = new RawInputEvent();
510 while (true) {
511 try {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 InputDevice di;
513
514 // block, doesn't release the monitor
515 readEvent(ev);
516
517 boolean send = false;
518 boolean configChanged = false;
519
520 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800521 Slog.i(TAG, "Input event: dev=0x"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 + Integer.toHexString(ev.deviceId)
523 + " type=0x" + Integer.toHexString(ev.type)
524 + " scancode=" + ev.scancode
525 + " keycode=" + ev.keycode
526 + " value=" + ev.value);
527 }
528
529 if (ev.type == RawInputEvent.EV_DEVICE_ADDED) {
530 synchronized (mFirst) {
531 di = newInputDevice(ev.deviceId);
Dianne Hackborna8f60182009-09-01 19:01:50 -0700532 if (di.classes != 0) {
533 // If this device is some kind of input class,
534 // we care about it.
535 mDevices.put(ev.deviceId, di);
536 if ((di.classes & RawInputEvent.CLASS_TOUCHSCREEN) != 0) {
537 readVirtualKeys(di.name);
538 }
539 // The configuration may have changed because
540 // of this device.
541 configChanged = true;
542 } else {
543 // We won't do anything with this device.
544 mIgnoredDevices.put(ev.deviceId, di);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800545 Slog.i(TAG, "Ignoring non-input device: id=0x"
Dianne Hackborna8f60182009-09-01 19:01:50 -0700546 + Integer.toHexString(di.id)
547 + ", name=" + di.name);
Iliyan Malchev75b2aed2009-08-06 14:50:57 -0700548 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 }
550 } else if (ev.type == RawInputEvent.EV_DEVICE_REMOVED) {
551 synchronized (mFirst) {
Dianne Hackborna8f60182009-09-01 19:01:50 -0700552 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800553 Slog.i(TAG, "Device removed: id=0x"
Dianne Hackborna8f60182009-09-01 19:01:50 -0700554 + Integer.toHexString(ev.deviceId));
555 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 di = mDevices.get(ev.deviceId);
557 if (di != null) {
558 mDevices.delete(ev.deviceId);
Dianne Hackborna8f60182009-09-01 19:01:50 -0700559 // The configuration may have changed because
560 // of this device.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 configChanged = true;
Dianne Hackborna8f60182009-09-01 19:01:50 -0700562 } else if ((di=mIgnoredDevices.get(ev.deviceId)) != null) {
563 mIgnoredDevices.remove(ev.deviceId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800565 Slog.w(TAG, "Removing bad device id: "
Dianne Hackborna8f60182009-09-01 19:01:50 -0700566 + Integer.toHexString(ev.deviceId));
567 continue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 }
569 }
570 } else {
571 di = getInputDevice(ev.deviceId);
Dianne Hackborna8f60182009-09-01 19:01:50 -0700572 if (di == null) {
573 // This may be some junk from an ignored device.
574 continue;
575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576
577 // first crack at it
578 send = preprocessEvent(di, ev);
579
580 if (ev.type == RawInputEvent.EV_KEY) {
581 di.mMetaKeysState = makeMetaState(ev.keycode,
582 ev.value != 0, di.mMetaKeysState);
583 mHaveGlobalMetaState = false;
584 }
585 }
586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 if (configChanged) {
588 synchronized (mFirst) {
Michael Chan53071d62009-05-13 17:29:48 -0700589 addLocked(di, System.nanoTime(), 0,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 RawInputEvent.CLASS_CONFIGURATION_CHANGED,
591 null);
592 }
593 }
594
595 if (!send) {
596 continue;
597 }
598
599 synchronized (mFirst) {
600 // NOTE: The event timebase absolutely must be the same
601 // timebase as SystemClock.uptimeMillis().
602 //curTime = gotOne ? ev.when : SystemClock.uptimeMillis();
603 final long curTime = SystemClock.uptimeMillis();
Michael Chan53071d62009-05-13 17:29:48 -0700604 final long curTimeNano = System.nanoTime();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800605 //Slog.i(TAG, "curTime=" + curTime + ", systemClock=" + SystemClock.uptimeMillis());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606
607 final int classes = di.classes;
608 final int type = ev.type;
609 final int scancode = ev.scancode;
610 send = false;
611
612 // Is it a key event?
613 if (type == RawInputEvent.EV_KEY &&
614 (classes&RawInputEvent.CLASS_KEYBOARD) != 0 &&
615 (scancode < RawInputEvent.BTN_FIRST ||
616 scancode > RawInputEvent.BTN_LAST)) {
617 boolean down;
618 if (ev.value != 0) {
619 down = true;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700620 di.mKeyDownTime = curTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 } else {
622 down = false;
623 }
624 int keycode = rotateKeyCodeLocked(ev.keycode);
Michael Chan53071d62009-05-13 17:29:48 -0700625 addLocked(di, curTimeNano, ev.flags,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 RawInputEvent.CLASS_KEYBOARD,
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700627 newKeyEvent(di, di.mKeyDownTime, curTime, down,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 keycode, 0, scancode,
629 ((ev.flags & WindowManagerPolicy.FLAG_WOKE_HERE) != 0)
630 ? KeyEvent.FLAG_WOKE_HERE : 0));
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 } else if (ev.type == RawInputEvent.EV_KEY) {
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700633 // Single touch protocol: touch going down or up.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 if (ev.scancode == RawInputEvent.BTN_TOUCH &&
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700635 (classes&(RawInputEvent.CLASS_TOUCHSCREEN
636 |RawInputEvent.CLASS_TOUCHSCREEN_MT))
637 == RawInputEvent.CLASS_TOUCHSCREEN) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 di.mAbs.changed = true;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700639 di.mAbs.mDown[0] = ev.value != 0;
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700640
641 // Trackball (mouse) protocol: press down or up.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700642 } else if (ev.scancode == RawInputEvent.BTN_MOUSE &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 (classes&RawInputEvent.CLASS_TRACKBALL) != 0) {
644 di.mRel.changed = true;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700645 di.mRel.mNextNumPointers = ev.value != 0 ? 1 : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 send = true;
647 }
648
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700649 // Process position events from multitouch protocol.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 } else if (ev.type == RawInputEvent.EV_ABS &&
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700651 (classes&RawInputEvent.CLASS_TOUCHSCREEN_MT) != 0) {
652 if (ev.scancode == RawInputEvent.ABS_MT_TOUCH_MAJOR) {
653 di.mAbs.changed = true;
654 di.mAbs.mNextData[di.mAbs.mAddingPointerOffset
655 + MotionEvent.SAMPLE_PRESSURE] = ev.value;
656 } else if (ev.scancode == RawInputEvent.ABS_MT_POSITION_X) {
657 di.mAbs.changed = true;
658 di.mAbs.mNextData[di.mAbs.mAddingPointerOffset
659 + MotionEvent.SAMPLE_X] = ev.value;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800660 if (DEBUG_POINTERS) Slog.v(TAG, "MT @"
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700661 + di.mAbs.mAddingPointerOffset
662 + " X:" + ev.value);
663 } else if (ev.scancode == RawInputEvent.ABS_MT_POSITION_Y) {
664 di.mAbs.changed = true;
665 di.mAbs.mNextData[di.mAbs.mAddingPointerOffset
666 + MotionEvent.SAMPLE_Y] = ev.value;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800667 if (DEBUG_POINTERS) Slog.v(TAG, "MT @"
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700668 + di.mAbs.mAddingPointerOffset
669 + " Y:" + ev.value);
670 } else if (ev.scancode == RawInputEvent.ABS_MT_WIDTH_MAJOR) {
671 di.mAbs.changed = true;
672 di.mAbs.mNextData[di.mAbs.mAddingPointerOffset
673 + MotionEvent.SAMPLE_SIZE] = ev.value;
674 }
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700675
676 // Process position events from single touch protocol.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700677 } else if (ev.type == RawInputEvent.EV_ABS &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 (classes&RawInputEvent.CLASS_TOUCHSCREEN) != 0) {
679 if (ev.scancode == RawInputEvent.ABS_X) {
680 di.mAbs.changed = true;
Dianne Hackborn2a2b34432009-08-12 17:13:55 -0700681 di.curTouchVals[MotionEvent.SAMPLE_X] = ev.value;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 } else if (ev.scancode == RawInputEvent.ABS_Y) {
683 di.mAbs.changed = true;
Dianne Hackborn2a2b34432009-08-12 17:13:55 -0700684 di.curTouchVals[MotionEvent.SAMPLE_Y] = ev.value;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 } else if (ev.scancode == RawInputEvent.ABS_PRESSURE) {
686 di.mAbs.changed = true;
Dianne Hackborn2a2b34432009-08-12 17:13:55 -0700687 di.curTouchVals[MotionEvent.SAMPLE_PRESSURE] = ev.value;
688 di.curTouchVals[MotionEvent.NUM_SAMPLE_DATA
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700689 + MotionEvent.SAMPLE_PRESSURE] = ev.value;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 } else if (ev.scancode == RawInputEvent.ABS_TOOL_WIDTH) {
691 di.mAbs.changed = true;
Dianne Hackborn2a2b34432009-08-12 17:13:55 -0700692 di.curTouchVals[MotionEvent.SAMPLE_SIZE] = ev.value;
693 di.curTouchVals[MotionEvent.NUM_SAMPLE_DATA
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700694 + MotionEvent.SAMPLE_SIZE] = ev.value;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 }
696
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700697 // Process movement events from trackball (mouse) protocol.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 } else if (ev.type == RawInputEvent.EV_REL &&
699 (classes&RawInputEvent.CLASS_TRACKBALL) != 0) {
700 // Add this relative movement into our totals.
701 if (ev.scancode == RawInputEvent.REL_X) {
702 di.mRel.changed = true;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700703 di.mRel.mNextData[MotionEvent.SAMPLE_X] += ev.value;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 } else if (ev.scancode == RawInputEvent.REL_Y) {
705 di.mRel.changed = true;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700706 di.mRel.mNextData[MotionEvent.SAMPLE_Y] += ev.value;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 }
708 }
709
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700710 // Handle multitouch protocol sync: tells us that the
711 // driver has returned all data for -one- of the pointers
712 // that is currently down.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700713 if (ev.type == RawInputEvent.EV_SYN
714 && ev.scancode == RawInputEvent.SYN_MT_REPORT
715 && di.mAbs != null) {
716 di.mAbs.changed = true;
717 if (di.mAbs.mNextData[MotionEvent.SAMPLE_PRESSURE] > 0) {
718 // If the value is <= 0, the pointer is not
719 // down, so keep it in the count.
720
721 if (di.mAbs.mNextData[di.mAbs.mAddingPointerOffset
722 + MotionEvent.SAMPLE_PRESSURE] != 0) {
723 final int num = di.mAbs.mNextNumPointers+1;
724 di.mAbs.mNextNumPointers = num;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800725 if (DEBUG_POINTERS) Slog.v(TAG,
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700726 "MT_REPORT: now have " + num + " pointers");
727 final int newOffset = (num <= InputDevice.MAX_POINTERS)
728 ? (num * MotionEvent.NUM_SAMPLE_DATA)
729 : (InputDevice.MAX_POINTERS *
730 MotionEvent.NUM_SAMPLE_DATA);
731 di.mAbs.mAddingPointerOffset = newOffset;
732 di.mAbs.mNextData[newOffset
733 + MotionEvent.SAMPLE_PRESSURE] = 0;
734 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800735 if (DEBUG_POINTERS) Slog.v(TAG, "MT_REPORT: no pointer");
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700736 }
737 }
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700738
739 // Handle general event sync: all data for the current
740 // event update has been delivered.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700741 } else if (send || (ev.type == RawInputEvent.EV_SYN
742 && ev.scancode == RawInputEvent.SYN_REPORT)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 if (mDisplay != null) {
744 if (!mHaveGlobalMetaState) {
745 computeGlobalMetaStateLocked();
746 }
747
748 MotionEvent me;
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700749
750 InputDevice.MotionState ms = di.mAbs;
751 if (ms.changed) {
Dianne Hackborna2e92262010-03-02 17:19:29 -0800752 ms.everChanged = true;
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700753 ms.changed = false;
754
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700755 if ((classes&(RawInputEvent.CLASS_TOUCHSCREEN
756 |RawInputEvent.CLASS_TOUCHSCREEN_MT))
757 == RawInputEvent.CLASS_TOUCHSCREEN) {
758 ms.mNextNumPointers = 0;
Dianne Hackborn2a2b34432009-08-12 17:13:55 -0700759 if (ms.mDown[0]) {
760 System.arraycopy(di.curTouchVals, 0,
761 ms.mNextData, 0,
762 MotionEvent.NUM_SAMPLE_DATA);
763 ms.mNextNumPointers++;
764 }
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700765 }
766
767 if (BAD_TOUCH_HACK) {
768 ms.dropBadPoint(di);
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700769 }
Adam Powellf5bcc6a2010-03-02 10:42:16 -0800770 if (JUMPY_TOUCH_HACK) {
771 ms.dropJumpyPoint(di);
772 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700773
774 boolean doMotion = !monitorVirtualKey(di,
775 ev, curTime, curTimeNano);
776
777 if (doMotion && ms.mNextNumPointers > 0
Dianne Hackborndc953722009-10-19 11:24:39 -0700778 && (ms.mLastNumPointers == 0
779 || ms.mSkipLastPointers)) {
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700780 doMotion = !generateVirtualKeyDown(di,
781 ev, curTime, curTimeNano);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 }
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700783
784 if (doMotion) {
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700785 // XXX Need to be able to generate
786 // multiple events here, for example
787 // if two fingers change up/down state
788 // at the same time.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700789 do {
790 me = ms.generateAbsMotion(di, curTime,
791 curTimeNano, mDisplay,
792 mOrientation, mGlobalMetaState);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800793 if (DEBUG_POINTERS) Slog.v(TAG, "Absolute: x="
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700794 + di.mAbs.mNextData[MotionEvent.SAMPLE_X]
795 + " y="
796 + di.mAbs.mNextData[MotionEvent.SAMPLE_Y]
797 + " ev=" + me);
798 if (me != null) {
799 if (WindowManagerPolicy.WATCH_POINTER) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800800 Slog.i(TAG, "Enqueueing: " + me);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700801 }
802 addLocked(di, curTimeNano, ev.flags,
803 RawInputEvent.CLASS_TOUCHSCREEN, me);
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700804 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700805 } while (ms.hasMore());
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700806 } else {
807 // We are consuming movement in the
808 // virtual key area... but still
809 // propagate this to the previous
810 // data for comparisons.
Dianne Hackbornf2ddfb12009-10-13 22:43:33 -0700811 int num = ms.mNextNumPointers;
812 if (num > InputDevice.MAX_POINTERS) {
813 num = InputDevice.MAX_POINTERS;
814 }
Dianne Hackborn1411d1c2009-10-12 23:21:18 -0700815 System.arraycopy(ms.mNextData, 0,
816 ms.mLastData, 0,
Dianne Hackbornf2ddfb12009-10-13 22:43:33 -0700817 num * MotionEvent.NUM_SAMPLE_DATA);
818 ms.mLastNumPointers = num;
Dianne Hackborndc953722009-10-19 11:24:39 -0700819 ms.mSkipLastPointers = true;
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700820 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700821
822 ms.finish();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 }
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700824
825 ms = di.mRel;
826 if (ms.changed) {
Dianne Hackborna2e92262010-03-02 17:19:29 -0800827 ms.everChanged = true;
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700828 ms.changed = false;
829
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700830 me = ms.generateRelMotion(di, curTime,
831 curTimeNano,
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700832 mOrientation, mGlobalMetaState);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800833 if (false) Slog.v(TAG, "Relative: x="
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700834 + di.mRel.mNextData[MotionEvent.SAMPLE_X]
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700835 + " y="
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700836 + di.mRel.mNextData[MotionEvent.SAMPLE_Y]
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700837 + " ev=" + me);
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700838 if (me != null) {
839 addLocked(di, curTimeNano, ev.flags,
840 RawInputEvent.CLASS_TRACKBALL, me);
841 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700842
843 ms.finish();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 }
845 }
846 }
847 }
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700848
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700849 } catch (RuntimeException exc) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800850 Slog.e(TAG, "InputReaderThread uncaught exception", exc);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
853 }
854 };
855
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700856 private boolean isInsideDisplay(InputDevice dev) {
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700857 final InputDevice.AbsoluteInfo absx = dev.absX;
858 final InputDevice.AbsoluteInfo absy = dev.absY;
859 final InputDevice.MotionState absm = dev.mAbs;
860 if (absx == null || absy == null || absm == null) {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700861 return true;
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700862 }
863
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700864 if (absm.mNextData[MotionEvent.SAMPLE_X] >= absx.minValue
865 && absm.mNextData[MotionEvent.SAMPLE_X] <= absx.maxValue
866 && absm.mNextData[MotionEvent.SAMPLE_Y] >= absy.minValue
867 && absm.mNextData[MotionEvent.SAMPLE_Y] <= absy.maxValue) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800868 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Input ("
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700869 + absm.mNextData[MotionEvent.SAMPLE_X]
870 + "," + absm.mNextData[MotionEvent.SAMPLE_Y]
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700871 + ") inside of display");
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700872 return true;
873 }
874
875 return false;
876 }
877
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700878 private VirtualKey findVirtualKey(InputDevice dev) {
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700879 final int N = mVirtualKeys.size();
880 if (N <= 0) {
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700881 return null;
882 }
883
Dianne Hackbornddca3ee2009-07-23 19:01:31 -0700884 final InputDevice.MotionState absm = dev.mAbs;
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700885 for (int i=0; i<N; i++) {
886 VirtualKey sb = mVirtualKeys.get(i);
887 sb.computeHitRect(dev, mDisplayWidth, mDisplayHeight);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800888 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Hit test ("
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700889 + absm.mNextData[MotionEvent.SAMPLE_X] + ","
890 + absm.mNextData[MotionEvent.SAMPLE_Y] + ") in code "
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700891 + sb.scancode + " - (" + sb.hitLeft
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700892 + "," + sb.hitTop + ")-(" + sb.hitRight + ","
893 + sb.hitBottom + ")");
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700894 if (sb.checkHit(absm.mNextData[MotionEvent.SAMPLE_X],
895 absm.mNextData[MotionEvent.SAMPLE_Y])) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800896 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Hit!");
Dianne Hackborne3dd8842009-07-14 12:06:54 -0700897 return sb;
898 }
899 }
900
901 return null;
902 }
903
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700904 private boolean generateVirtualKeyDown(InputDevice di, RawInputEvent ev,
905 long curTime, long curTimeNano) {
906 if (isInsideDisplay(di)) {
907 // Didn't consume event.
908 return false;
909 }
910
911
912 VirtualKey vk = findVirtualKey(di);
913 if (vk != null) {
914 final InputDevice.MotionState ms = di.mAbs;
915 mPressedVirtualKey = vk;
916 vk.lastKeycode = scancodeToKeycode(di.id, vk.scancode);
917 ms.mLastNumPointers = ms.mNextNumPointers;
918 di.mKeyDownTime = curTime;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800919 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG,
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700920 "Generate key down for: " + vk.scancode
921 + " (keycode=" + vk.lastKeycode + ")");
922 KeyEvent event = newKeyEvent(di, di.mKeyDownTime, curTime, true,
923 vk.lastKeycode, 0, vk.scancode,
924 KeyEvent.FLAG_VIRTUAL_HARD_KEY);
925 mHapticFeedbackCallback.virtualKeyFeedback(event);
926 addLocked(di, curTimeNano, ev.flags, RawInputEvent.CLASS_KEYBOARD,
927 event);
928 }
929
930 // We always consume the event, even if we didn't
931 // generate a key event. There are two reasons for
932 // this: to avoid spurious touches when holding
933 // the edges of the device near the touchscreen,
934 // and to avoid reporting events if there are virtual
935 // keys on the touchscreen outside of the display
936 // area.
937 // Note that for all of this we are only looking at the
938 // first pointer, since what we are handling here is the
939 // first pointer going down, and this is the coordinate
940 // that will be used to dispatch the event.
941 if (false) {
942 final InputDevice.AbsoluteInfo absx = di.absX;
943 final InputDevice.AbsoluteInfo absy = di.absY;
944 final InputDevice.MotionState absm = di.mAbs;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800945 Slog.v(TAG, "Rejecting ("
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700946 + absm.mNextData[MotionEvent.SAMPLE_X] + ","
947 + absm.mNextData[MotionEvent.SAMPLE_Y] + "): outside of ("
948 + absx.minValue + "," + absy.minValue
949 + ")-(" + absx.maxValue + ","
950 + absx.maxValue + ")");
951 }
952 return true;
953 }
954
955 private boolean monitorVirtualKey(InputDevice di, RawInputEvent ev,
956 long curTime, long curTimeNano) {
957 VirtualKey vk = mPressedVirtualKey;
958 if (vk == null) {
959 return false;
960 }
961
962 final InputDevice.MotionState ms = di.mAbs;
963 if (ms.mNextNumPointers <= 0) {
964 mPressedVirtualKey = null;
965 ms.mLastNumPointers = 0;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800966 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Generate key up for: " + vk.scancode);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700967 KeyEvent event = newKeyEvent(di, di.mKeyDownTime, curTime, false,
968 vk.lastKeycode, 0, vk.scancode,
969 KeyEvent.FLAG_VIRTUAL_HARD_KEY);
970 mHapticFeedbackCallback.virtualKeyFeedback(event);
971 addLocked(di, curTimeNano, ev.flags, RawInputEvent.CLASS_KEYBOARD,
972 event);
973 return true;
974
975 } else if (isInsideDisplay(di)) {
976 // Whoops the pointer has moved into
977 // the display area! Cancel the
978 // virtual key and start a pointer
979 // motion.
980 mPressedVirtualKey = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800981 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Cancel key up for: " + vk.scancode);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700982 KeyEvent event = newKeyEvent(di, di.mKeyDownTime, curTime, false,
983 vk.lastKeycode, 0, vk.scancode,
984 KeyEvent.FLAG_CANCELED | KeyEvent.FLAG_VIRTUAL_HARD_KEY);
985 mHapticFeedbackCallback.virtualKeyFeedback(event);
986 addLocked(di, curTimeNano, ev.flags, RawInputEvent.CLASS_KEYBOARD,
987 event);
988 ms.mLastNumPointers = 0;
989 return false;
990 }
991
992 return true;
993 }
994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 /**
996 * Returns a new meta state for the given keys and old state.
997 */
998 private static final int makeMetaState(int keycode, boolean down, int old) {
999 int mask;
1000 switch (keycode) {
1001 case KeyEvent.KEYCODE_ALT_LEFT:
1002 mask = KeyEvent.META_ALT_LEFT_ON;
1003 break;
1004 case KeyEvent.KEYCODE_ALT_RIGHT:
1005 mask = KeyEvent.META_ALT_RIGHT_ON;
1006 break;
1007 case KeyEvent.KEYCODE_SHIFT_LEFT:
1008 mask = KeyEvent.META_SHIFT_LEFT_ON;
1009 break;
1010 case KeyEvent.KEYCODE_SHIFT_RIGHT:
1011 mask = KeyEvent.META_SHIFT_RIGHT_ON;
1012 break;
1013 case KeyEvent.KEYCODE_SYM:
1014 mask = KeyEvent.META_SYM_ON;
1015 break;
1016 default:
1017 return old;
1018 }
1019 int result = ~(KeyEvent.META_ALT_ON | KeyEvent.META_SHIFT_ON)
1020 & (down ? (old | mask) : (old & ~mask));
1021 if (0 != (result & (KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_RIGHT_ON))) {
1022 result |= KeyEvent.META_ALT_ON;
1023 }
1024 if (0 != (result & (KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_RIGHT_ON))) {
1025 result |= KeyEvent.META_SHIFT_ON;
1026 }
1027 return result;
1028 }
1029
1030 private void computeGlobalMetaStateLocked() {
1031 int i = mDevices.size();
1032 mGlobalMetaState = 0;
1033 while ((--i) >= 0) {
1034 mGlobalMetaState |= mDevices.valueAt(i).mMetaKeysState;
1035 }
1036 mHaveGlobalMetaState = true;
1037 }
1038
1039 /*
1040 * Return true if you want the event to get passed on to the
1041 * rest of the system, and false if you've handled it and want
1042 * it dropped.
1043 */
1044 abstract boolean preprocessEvent(InputDevice device, RawInputEvent event);
1045
1046 InputDevice getInputDevice(int deviceId) {
1047 synchronized (mFirst) {
1048 return getInputDeviceLocked(deviceId);
1049 }
1050 }
1051
1052 private InputDevice getInputDeviceLocked(int deviceId) {
1053 return mDevices.get(deviceId);
1054 }
1055
1056 public void setOrientation(int orientation) {
1057 synchronized(mFirst) {
1058 mOrientation = orientation;
1059 switch (orientation) {
1060 case Surface.ROTATION_90:
1061 mKeyRotationMap = KEY_90_MAP;
1062 break;
1063 case Surface.ROTATION_180:
1064 mKeyRotationMap = KEY_180_MAP;
1065 break;
1066 case Surface.ROTATION_270:
1067 mKeyRotationMap = KEY_270_MAP;
1068 break;
1069 default:
1070 mKeyRotationMap = null;
1071 break;
1072 }
1073 }
1074 }
1075
1076 public int rotateKeyCode(int keyCode) {
1077 synchronized(mFirst) {
1078 return rotateKeyCodeLocked(keyCode);
1079 }
1080 }
1081
1082 private int rotateKeyCodeLocked(int keyCode) {
1083 int[] map = mKeyRotationMap;
1084 if (map != null) {
1085 final int N = map.length;
1086 for (int i=0; i<N; i+=2) {
1087 if (map[i] == keyCode) {
1088 return map[i+1];
1089 }
1090 }
1091 }
1092 return keyCode;
1093 }
1094
1095 boolean hasEvents() {
1096 synchronized (mFirst) {
1097 return mFirst.next != mLast;
1098 }
1099 }
1100
1101 /*
1102 * returns true if we returned an event, and false if we timed out
1103 */
1104 QueuedEvent getEvent(long timeoutMS) {
1105 long begin = SystemClock.uptimeMillis();
1106 final long end = begin+timeoutMS;
1107 long now = begin;
1108 synchronized (mFirst) {
1109 while (mFirst.next == mLast && end > now) {
1110 try {
1111 mWakeLock.release();
1112 mFirst.wait(end-now);
1113 }
1114 catch (InterruptedException e) {
1115 }
1116 now = SystemClock.uptimeMillis();
1117 if (begin > now) {
1118 begin = now;
1119 }
1120 }
1121 if (mFirst.next == mLast) {
1122 return null;
1123 }
1124 QueuedEvent p = mFirst.next;
1125 mFirst.next = p.next;
1126 mFirst.next.prev = mFirst;
1127 p.inQueue = false;
1128 return p;
1129 }
1130 }
1131
Dianne Hackborn83fe3f52009-09-12 23:38:30 -07001132 /**
1133 * Return true if the queue has an up event pending that corresponds
1134 * to the same key as the given key event.
1135 */
1136 boolean hasKeyUpEvent(KeyEvent origEvent) {
1137 synchronized (mFirst) {
1138 final int keyCode = origEvent.getKeyCode();
1139 QueuedEvent cur = mLast.prev;
1140 while (cur.prev != null) {
1141 if (cur.classType == RawInputEvent.CLASS_KEYBOARD) {
1142 KeyEvent ke = (KeyEvent)cur.event;
1143 if (ke.getAction() == KeyEvent.ACTION_UP
1144 && ke.getKeyCode() == keyCode) {
1145 return true;
1146 }
1147 }
1148 cur = cur.prev;
1149 }
1150 }
1151
1152 return false;
1153 }
1154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 void recycleEvent(QueuedEvent ev) {
1156 synchronized (mFirst) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001157 //Slog.i(TAG, "Recycle event: " + ev);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158 if (ev.event == ev.inputDevice.mAbs.currentMove) {
1159 ev.inputDevice.mAbs.currentMove = null;
1160 }
1161 if (ev.event == ev.inputDevice.mRel.currentMove) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001162 if (false) Slog.i(TAG, "Detach rel " + ev.event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001163 ev.inputDevice.mRel.currentMove = null;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001164 ev.inputDevice.mRel.mNextData[MotionEvent.SAMPLE_X] = 0;
1165 ev.inputDevice.mRel.mNextData[MotionEvent.SAMPLE_Y] = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 }
1167 recycleLocked(ev);
1168 }
1169 }
1170
1171 void filterQueue(FilterCallback cb) {
1172 synchronized (mFirst) {
1173 QueuedEvent cur = mLast.prev;
1174 while (cur.prev != null) {
1175 switch (cb.filterEvent(cur)) {
1176 case FILTER_REMOVE:
1177 cur.prev.next = cur.next;
1178 cur.next.prev = cur.prev;
1179 break;
1180 case FILTER_ABORT:
1181 return;
1182 }
1183 cur = cur.prev;
1184 }
1185 }
1186 }
1187
Michael Chan53071d62009-05-13 17:29:48 -07001188 private QueuedEvent obtainLocked(InputDevice device, long whenNano,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 int flags, int classType, Object event) {
1190 QueuedEvent ev;
1191 if (mCacheCount == 0) {
1192 ev = new QueuedEvent();
1193 } else {
1194 ev = mCache;
1195 ev.inQueue = false;
1196 mCache = ev.next;
1197 mCacheCount--;
1198 }
1199 ev.inputDevice = device;
Michael Chan53071d62009-05-13 17:29:48 -07001200 ev.whenNano = whenNano;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 ev.flags = flags;
1202 ev.classType = classType;
1203 ev.event = event;
1204 return ev;
1205 }
1206
1207 private void recycleLocked(QueuedEvent ev) {
1208 if (ev.inQueue) {
1209 throw new RuntimeException("Event already in queue!");
1210 }
1211 if (mCacheCount < 10) {
1212 mCacheCount++;
1213 ev.next = mCache;
1214 mCache = ev;
1215 ev.inQueue = true;
1216 }
1217 }
1218
Michael Chan53071d62009-05-13 17:29:48 -07001219 private void addLocked(InputDevice device, long whenNano, int flags,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 int classType, Object event) {
1221 boolean poke = mFirst.next == mLast;
1222
Michael Chan53071d62009-05-13 17:29:48 -07001223 QueuedEvent ev = obtainLocked(device, whenNano, flags, classType, event);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 QueuedEvent p = mLast.prev;
Michael Chan53071d62009-05-13 17:29:48 -07001225 while (p != mFirst && ev.whenNano < p.whenNano) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 p = p.prev;
1227 }
1228
1229 ev.next = p.next;
1230 ev.prev = p;
1231 p.next = ev;
1232 ev.next.prev = ev;
1233 ev.inQueue = true;
1234
1235 if (poke) {
Michael Chan53071d62009-05-13 17:29:48 -07001236 long time;
1237 if (MEASURE_LATENCY) {
1238 time = System.nanoTime();
1239 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001240 mFirst.notify();
1241 mWakeLock.acquire();
Michael Chan53071d62009-05-13 17:29:48 -07001242 if (MEASURE_LATENCY) {
1243 lt.sample("1 addLocked-queued event ", System.nanoTime() - time);
1244 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 }
1246 }
1247
1248 private InputDevice newInputDevice(int deviceId) {
1249 int classes = getDeviceClasses(deviceId);
1250 String name = getDeviceName(deviceId);
Dianne Hackborna8f60182009-09-01 19:01:50 -07001251 InputDevice.AbsoluteInfo absX = null;
1252 InputDevice.AbsoluteInfo absY = null;
1253 InputDevice.AbsoluteInfo absPressure = null;
1254 InputDevice.AbsoluteInfo absSize = null;
1255 if (classes != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001256 Slog.i(TAG, "Device added: id=0x" + Integer.toHexString(deviceId)
Dianne Hackborna8f60182009-09-01 19:01:50 -07001257 + ", name=" + name
1258 + ", classes=" + Integer.toHexString(classes));
1259 if ((classes&RawInputEvent.CLASS_TOUCHSCREEN_MT) != 0) {
1260 absX = loadAbsoluteInfo(deviceId,
1261 RawInputEvent.ABS_MT_POSITION_X, "X");
1262 absY = loadAbsoluteInfo(deviceId,
1263 RawInputEvent.ABS_MT_POSITION_Y, "Y");
1264 absPressure = loadAbsoluteInfo(deviceId,
1265 RawInputEvent.ABS_MT_TOUCH_MAJOR, "Pressure");
1266 absSize = loadAbsoluteInfo(deviceId,
1267 RawInputEvent.ABS_MT_WIDTH_MAJOR, "Size");
1268 } else if ((classes&RawInputEvent.CLASS_TOUCHSCREEN) != 0) {
1269 absX = loadAbsoluteInfo(deviceId,
1270 RawInputEvent.ABS_X, "X");
1271 absY = loadAbsoluteInfo(deviceId,
1272 RawInputEvent.ABS_Y, "Y");
1273 absPressure = loadAbsoluteInfo(deviceId,
1274 RawInputEvent.ABS_PRESSURE, "Pressure");
1275 absSize = loadAbsoluteInfo(deviceId,
1276 RawInputEvent.ABS_TOOL_WIDTH, "Size");
1277 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 }
1279
1280 return new InputDevice(deviceId, classes, name, absX, absY, absPressure, absSize);
1281 }
1282
1283 private InputDevice.AbsoluteInfo loadAbsoluteInfo(int id, int channel,
1284 String name) {
1285 InputDevice.AbsoluteInfo info = new InputDevice.AbsoluteInfo();
1286 if (getAbsoluteInfo(id, channel, info)
1287 && info.minValue != info.maxValue) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001288 Slog.i(TAG, " " + name + ": min=" + info.minValue
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 + " max=" + info.maxValue
1290 + " flat=" + info.flat
1291 + " fuzz=" + info.fuzz);
1292 info.range = info.maxValue-info.minValue;
1293 return info;
1294 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001295 Slog.i(TAG, " " + name + ": unknown values");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 return null;
1297 }
1298 private static native boolean readEvent(RawInputEvent outEvent);
Dianne Hackborna2e92262010-03-02 17:19:29 -08001299
1300 void dump(PrintWriter pw, String prefix) {
1301 synchronized (mFirst) {
1302 for (int i=0; i<mDevices.size(); i++) {
1303 InputDevice dev = mDevices.valueAt(i);
1304 pw.print(prefix); pw.print("Device #");
1305 pw.print(mDevices.keyAt(i)); pw.print(" ");
1306 pw.print(dev.name); pw.print(" (classes=0x");
1307 pw.print(Integer.toHexString(dev.classes));
1308 pw.println("):");
1309 pw.print(prefix); pw.print(" mKeyDownTime=");
1310 pw.print(dev.mKeyDownTime); pw.print(" mMetaKeysState=");
1311 pw.println(dev.mMetaKeysState);
1312 if (dev.absX != null) {
1313 pw.print(prefix); pw.print(" absX: "); dev.absX.dump(pw);
1314 pw.println("");
1315 }
1316 if (dev.absY != null) {
1317 pw.print(prefix); pw.print(" absY: "); dev.absY.dump(pw);
1318 pw.println("");
1319 }
1320 if (dev.absPressure != null) {
1321 pw.print(prefix); pw.print(" absPressure: ");
1322 dev.absPressure.dump(pw); pw.println("");
1323 }
1324 if (dev.absSize != null) {
1325 pw.print(prefix); pw.print(" absSize: ");
1326 dev.absSize.dump(pw); pw.println("");
1327 }
1328 if (dev.mAbs.everChanged) {
1329 pw.print(prefix); pw.println(" mAbs:");
1330 dev.mAbs.dump(pw, prefix + " ");
1331 }
1332 if (dev.mRel.everChanged) {
1333 pw.print(prefix); pw.println(" mRel:");
1334 dev.mRel.dump(pw, prefix + " ");
1335 }
1336 }
1337 pw.println(" ");
1338 for (int i=0; i<mIgnoredDevices.size(); i++) {
1339 InputDevice dev = mIgnoredDevices.valueAt(i);
1340 pw.print(prefix); pw.print("Ignored Device #");
1341 pw.print(mIgnoredDevices.keyAt(i)); pw.print(" ");
1342 pw.print(dev.name); pw.print(" (classes=0x");
1343 pw.print(Integer.toHexString(dev.classes));
1344 pw.println(")");
1345 }
1346 pw.println(" ");
1347 for (int i=0; i<mVirtualKeys.size(); i++) {
1348 VirtualKey vk = mVirtualKeys.get(i);
1349 pw.print(prefix); pw.print("Virtual Key #");
1350 pw.print(i); pw.println(":");
1351 pw.print(prefix); pw.print(" scancode="); pw.println(vk.scancode);
1352 pw.print(prefix); pw.print(" centerx="); pw.print(vk.centerx);
1353 pw.print(" centery="); pw.print(vk.centery);
1354 pw.print(" width="); pw.print(vk.width);
1355 pw.print(" height="); pw.println(vk.height);
1356 pw.print(prefix); pw.print(" hitLeft="); pw.print(vk.hitLeft);
1357 pw.print(" hitTop="); pw.print(vk.hitTop);
1358 pw.print(" hitRight="); pw.print(vk.hitRight);
1359 pw.print(" hitBottom="); pw.println(vk.hitBottom);
1360 if (vk.lastDevice != null) {
1361 pw.print(prefix); pw.print(" lastDevice=#");
1362 pw.println(vk.lastDevice.id);
1363 }
1364 if (vk.lastKeycode != 0) {
1365 pw.print(prefix); pw.print(" lastKeycode=");
1366 pw.println(vk.lastKeycode);
1367 }
1368 }
1369 pw.println(" ");
1370 pw.print(prefix); pw.print(" Default keyboard: ");
1371 pw.println(SystemProperties.get("hw.keyboards.0.devname"));
1372 pw.print(prefix); pw.print(" mGlobalMetaState=");
1373 pw.print(mGlobalMetaState); pw.print(" mHaveGlobalMetaState=");
1374 pw.println(mHaveGlobalMetaState);
1375 pw.print(prefix); pw.print(" mDisplayWidth=");
1376 pw.print(mDisplayWidth); pw.print(" mDisplayHeight=");
1377 pw.println(mDisplayHeight);
1378 pw.print(prefix); pw.print(" mOrientation=");
1379 pw.println(mOrientation);
1380 if (mPressedVirtualKey != null) {
1381 pw.print(prefix); pw.print(" mPressedVirtualKey.scancode=");
1382 pw.println(mPressedVirtualKey.scancode);
1383 }
1384 }
1385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386}