From a2e92266b3f768f74ab7fcb42972a22d6c739b39 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 2 Mar 2010 17:19:29 -0800 Subject: Maybe fix issue #2482201: Paired bluetooth device looks like a qwerty keyboard We now only consider a device to be a default keyboard if its name has "-keypad". A hack, but whatever. Also add some debug logging for the input state to help identify such issues in the future. --- libs/ui/EventHub.cpp | 26 +++---- services/java/com/android/server/InputDevice.java | 61 +++++++++++++++ .../java/com/android/server/KeyInputQueue.java | 91 ++++++++++++++++++++++ .../com/android/server/WindowManagerService.java | 6 +- 4 files changed, 169 insertions(+), 15 deletions(-) diff --git a/libs/ui/EventHub.cpp b/libs/ui/EventHub.cpp index c4d4f99..57192a5 100644 --- a/libs/ui/EventHub.cpp +++ b/libs/ui/EventHub.cpp @@ -604,8 +604,11 @@ int EventHub::open_device(const char *deviceName) // figure out the kinds of events the device reports - // See if this is a keyboard, and classify it. - uint8_t key_bitmask[(KEY_MAX+1)/8]; + // See if this is a keyboard, and classify it. Note that we only + // consider up through the function keys; we don't want to include + // ones after that (play cd etc) so we don't mistakenly consider a + // controller to be a keyboard. + uint8_t key_bitmask[(KEY_PLAYCD+1)/8]; memset(key_bitmask, 0, sizeof(key_bitmask)); LOGV("Getting keys..."); if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) >= 0) { @@ -702,22 +705,20 @@ int EventHub::open_device(const char *deviceName) device->layoutMap->load(keylayoutFilename); // tell the world about the devname (the descriptive name) - int32_t publicID; - if (!mHaveFirstKeyboard && !defaultKeymap) { - publicID = 0; + if (!mHaveFirstKeyboard && !defaultKeymap && strstr(name, "-keypad")) { // the built-in keyboard has a well-known device ID of 0, // this device better not go away. mHaveFirstKeyboard = true; mFirstKeyboardId = device->id; + property_set("hw.keyboards.0.devname", name); } else { - publicID = device->id; // ensure mFirstKeyboardId is set to -something-. if (mFirstKeyboardId == 0) { mFirstKeyboardId = device->id; } } char propName[100]; - sprintf(propName, "hw.keyboards.%u.devname", publicID); + sprintf(propName, "hw.keyboards.%u.devname", device->id); property_set(propName, name); // 'Q' key support = cheap test of whether this is an alpha-capable kbd @@ -734,8 +735,8 @@ int EventHub::open_device(const char *deviceName) device->classes |= CLASS_DPAD; } - LOGI("New keyboard: publicID=%d device->id=0x%x devname='%s' propName='%s' keylayout='%s'\n", - publicID, device->id, name, propName, keylayoutFilename); + LOGI("New keyboard: device->id=0x%x devname='%s' propName='%s' keylayout='%s'\n", + device->id, name, propName, keylayoutFilename); } LOGI("New device: path=%s name=%s id=0x%x (of 0x%x) index=%d fd=%d classes=0x%x\n", @@ -808,18 +809,15 @@ int EventHub::close_device(const char *deviceName) device->next = mClosingDevices; mClosingDevices = device; - uint32_t publicID; if (device->id == mFirstKeyboardId) { LOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this", device->path.string(), mFirstKeyboardId); mFirstKeyboardId = 0; - publicID = 0; - } else { - publicID = device->id; + property_set("hw.keyboards.0.devname", NULL); } // clear the property char propName[100]; - sprintf(propName, "hw.keyboards.%u.devname", publicID); + sprintf(propName, "hw.keyboards.%u.devname", device->id); property_set(propName, NULL); return 0; } diff --git a/services/java/com/android/server/InputDevice.java b/services/java/com/android/server/InputDevice.java index 1c18d6f..d5e94ec 100644 --- a/services/java/com/android/server/InputDevice.java +++ b/services/java/com/android/server/InputDevice.java @@ -22,6 +22,8 @@ import android.view.MotionEvent; import android.view.Surface; import android.view.WindowManagerPolicy; +import java.io.PrintWriter; + public class InputDevice { static final boolean DEBUG_POINTERS = false; static final boolean DEBUG_HACKS = false; @@ -58,6 +60,7 @@ public class InputDevice { float yMoveScale; MotionEvent currentMove = null; boolean changed = false; + boolean everChanged = false; long mDownTime = 0; // The currently assigned pointer IDs, corresponding to the last data. @@ -103,6 +106,56 @@ public class InputDevice { int mAddingPointerOffset = 0; final boolean[] mDown = new boolean[MAX_POINTERS]; + void dumpIntArray(PrintWriter pw, int[] array) { + pw.print("["); + for (int i=0; i 0) pw.print(", "); + pw.print(array[i]); + } + pw.print("]"); + } + + void dumpBooleanArray(PrintWriter pw, boolean[] array) { + pw.print("["); + for (int i=0; i 0) pw.print(", "); + pw.print(array[i] ? "true" : "false"); + } + pw.print("]"); + } + + void dump(PrintWriter pw, String prefix) { + pw.print(prefix); pw.print("xPrecision="); pw.print(xPrecision); + pw.print(" yPrecision="); pw.println(yPrecision); + pw.print(prefix); pw.print("xMoveScale="); pw.print(xMoveScale); + pw.print(" yMoveScale="); pw.println(yMoveScale); + if (currentMove != null) { + pw.print(prefix); pw.print("currentMove="); pw.println(currentMove); + } + if (changed || mDownTime != 0) { + pw.print(prefix); pw.print("changed="); pw.print(changed); + pw.print(" mDownTime="); pw.println(mDownTime); + } + pw.print(prefix); pw.print("mPointerIds="); dumpIntArray(pw, mPointerIds); + pw.println(""); + if (mSkipLastPointers || mLastNumPointers != 0) { + pw.print(prefix); pw.print("mSkipLastPointers="); pw.print(mSkipLastPointers); + pw.print(" mLastNumPointers="); pw.println(mLastNumPointers); + pw.print(prefix); pw.print("mLastData="); dumpIntArray(pw, mLastData); + pw.println(""); + } + if (mNextNumPointers != 0) { + pw.print(prefix); pw.print("mNextNumPointers="); pw.println(mNextNumPointers); + pw.print(prefix); pw.print("mNextData="); dumpIntArray(pw, mNextData); + pw.println(""); + } + pw.print(prefix); pw.print("mDroppedBadPoint="); + dumpBooleanArray(pw, mDroppedBadPoint); pw.println(""); + pw.print(prefix); pw.print("mAddingPointerOffset="); pw.println(mAddingPointerOffset); + pw.print(prefix); pw.print("mDown="); + dumpBooleanArray(pw, mDown); pw.println(""); + } + MotionState(int mx, int my) { xPrecision = mx; yPrecision = my; @@ -775,6 +828,14 @@ public class InputDevice { int range; int flat; int fuzz; + + final void dump(PrintWriter pw) { + pw.print("minValue="); pw.print(minValue); + pw.print(" maxValue="); pw.print(maxValue); + pw.print(" range="); pw.print(range); + pw.print(" flat="); pw.print(flat); + pw.print(" fuzz="); pw.print(fuzz); + } }; InputDevice(int _id, int _classes, String _name, diff --git a/services/java/com/android/server/KeyInputQueue.java b/services/java/com/android/server/KeyInputQueue.java index 0535d4c..a08258a 100644 --- a/services/java/com/android/server/KeyInputQueue.java +++ b/services/java/com/android/server/KeyInputQueue.java @@ -22,6 +22,7 @@ import android.os.Environment; import android.os.LatencyTimer; import android.os.PowerManager; import android.os.SystemClock; +import android.os.SystemProperties; import android.util.Slog; import android.util.SparseArray; import android.util.Xml; @@ -43,6 +44,7 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.PrintWriter; import java.util.ArrayList; public abstract class KeyInputQueue { @@ -738,6 +740,7 @@ public abstract class KeyInputQueue { InputDevice.MotionState ms = di.mAbs; if (ms.changed) { + ms.everChanged = true; ms.changed = false; if ((classes&(RawInputEvent.CLASS_TOUCHSCREEN @@ -809,6 +812,7 @@ public abstract class KeyInputQueue { ms = di.mRel; if (ms.changed) { + ms.everChanged = true; ms.changed = false; me = ms.generateRelMotion(di, curTime, @@ -1280,4 +1284,91 @@ public abstract class KeyInputQueue { return null; } private static native boolean readEvent(RawInputEvent outEvent); + + void dump(PrintWriter pw, String prefix) { + synchronized (mFirst) { + for (int i=0; i=0; i--) { @@ -11014,7 +11018,7 @@ public class WindowManagerService extends IWindowManager.Stub if (mDimAnimator != null) { mDimAnimator.printTo(pw); } else { - pw.print( " no DimAnimator "); + pw.println( " no DimAnimator "); } pw.print(" mInputMethodAnimLayerAdjustment="); pw.print(mInputMethodAnimLayerAdjustment); -- cgit v1.1