diff options
author | Dianne Hackborn <hackbod@google.com> | 2011-06-03 12:13:24 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2011-06-03 12:26:54 -0700 |
commit | f3b57def9345d6d3cac3604d6a970f6d48f345ec (patch) | |
tree | e4a0926992c2ed61953a07f329693dd0e6590b25 /services/jni | |
parent | 201e6606e78c67e8d94b131f43789c5d8aaf3beb (diff) | |
parent | 7e193916c033bc952222ca808916b2dc4b4b557d (diff) | |
download | frameworks_base-f3b57def9345d6d3cac3604d6a970f6d48f345ec.zip frameworks_base-f3b57def9345d6d3cac3604d6a970f6d48f345ec.tar.gz frameworks_base-f3b57def9345d6d3cac3604d6a970f6d48f345ec.tar.bz2 |
resolved conflicts for merge of 7e193916 to master
Change-Id: If06892419319c3a2d4ab6b03dd3ceb99b83803b5
Diffstat (limited to 'services/jni')
-rw-r--r-- | services/jni/com_android_server_InputManager.cpp | 215 |
1 files changed, 97 insertions, 118 deletions
diff --git a/services/jni/com_android_server_InputManager.cpp b/services/jni/com_android_server_InputManager.cpp index 1f10d9c..0ee3217 100644 --- a/services/jni/com_android_server_InputManager.cpp +++ b/services/jni/com_android_server_InputManager.cpp @@ -71,6 +71,10 @@ static struct { jmethodID getKeyRepeatTimeout; jmethodID getKeyRepeatDelay; jmethodID getMaxEventsPerSecond; + jmethodID getTapTimeout; + jmethodID getDoubleTapTimeout; + jmethodID getLongPressTimeout; + jmethodID getTouchSlop; jmethodID getPointerLayer; jmethodID getPointerIcon; } gCallbacksClassInfo; @@ -104,6 +108,16 @@ static struct { // --- Global functions --- +template<typename T> +inline static T min(const T& a, const T& b) { + return a < b ? a : b; +} + +template<typename T> +inline static T max(const T& a, const T& b) { + return a > b ? a : b; +} + static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env, const sp<InputApplicationHandle>& inputApplicationHandle) { if (inputApplicationHandle == NULL) { @@ -167,10 +181,7 @@ public: virtual bool getDisplayInfo(int32_t displayId, int32_t* width, int32_t* height, int32_t* orientation); - virtual bool filterTouchEvents(); - virtual bool filterJumpyTouchEvents(); - virtual nsecs_t getVirtualKeyQuietTime(); - virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames); + virtual void getReaderConfiguration(InputReaderConfiguration* outConfig); virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId); /* --- InputDispatcherPolicyInterface implementation --- */ @@ -181,10 +192,9 @@ public: virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, const sp<InputWindowHandle>& inputWindowHandle); virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle); - virtual nsecs_t getKeyRepeatTimeout(); - virtual nsecs_t getKeyRepeatDelay(); - virtual int32_t getMaxEventsPerSecond(); virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags); + virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig); + virtual bool isKeyRepeatEnabled(); virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags); virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags); virtual bool interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle, @@ -206,18 +216,6 @@ private: jobject mCallbacksObj; sp<Looper> mLooper; - // Cached filtering policies. - int32_t mFilterTouchEvents; - int32_t mFilterJumpyTouchEvents; - nsecs_t mVirtualKeyQuietTime; - - // Cached key repeat policy. - nsecs_t mKeyRepeatTimeout; - nsecs_t mKeyRepeatDelay; - - // Cached throttling policy. - int32_t mMaxEventsPerSecond; - Mutex mLock; struct Locked { // Display size information. @@ -253,10 +251,7 @@ private: NativeInputManager::NativeInputManager(jobject contextObj, jobject callbacksObj, const sp<Looper>& looper) : - mLooper(looper), - mFilterTouchEvents(-1), mFilterJumpyTouchEvents(-1), mVirtualKeyQuietTime(-1), - mKeyRepeatTimeout(-1), mKeyRepeatDelay(-1), - mMaxEventsPerSecond(-1) { + mLooper(looper) { JNIEnv* env = jniEnv(); mContextObj = env->NewGlobalRef(contextObj); @@ -369,73 +364,68 @@ bool NativeInputManager::getDisplayInfo(int32_t displayId, return result; } -bool NativeInputManager::filterTouchEvents() { - if (mFilterTouchEvents < 0) { - JNIEnv* env = jniEnv(); - - jboolean result = env->CallBooleanMethod(mCallbacksObj, - gCallbacksClassInfo.filterTouchEvents); - if (checkAndClearExceptionFromCallback(env, "filterTouchEvents")) { - result = false; - } +void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) { + JNIEnv* env = jniEnv(); - mFilterTouchEvents = result ? 1 : 0; + jboolean filterTouchEvents = env->CallBooleanMethod(mCallbacksObj, + gCallbacksClassInfo.filterTouchEvents); + if (!checkAndClearExceptionFromCallback(env, "filterTouchEvents")) { + outConfig->filterTouchEvents = filterTouchEvents; } - return mFilterTouchEvents; -} - -bool NativeInputManager::filterJumpyTouchEvents() { - if (mFilterJumpyTouchEvents < 0) { - JNIEnv* env = jniEnv(); - - jboolean result = env->CallBooleanMethod(mCallbacksObj, - gCallbacksClassInfo.filterJumpyTouchEvents); - if (checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) { - result = false; - } - mFilterJumpyTouchEvents = result ? 1 : 0; + jboolean filterJumpyTouchEvents = env->CallBooleanMethod(mCallbacksObj, + gCallbacksClassInfo.filterJumpyTouchEvents); + if (!checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) { + outConfig->filterJumpyTouchEvents = filterJumpyTouchEvents; } - return mFilterJumpyTouchEvents; -} -nsecs_t NativeInputManager::getVirtualKeyQuietTime() { - if (mVirtualKeyQuietTime < 0) { - JNIEnv* env = jniEnv(); - - jint result = env->CallIntMethod(mCallbacksObj, - gCallbacksClassInfo.getVirtualKeyQuietTimeMillis); - if (checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) { - result = 0; - } - if (result < 0) { - result = 0; - } - - mVirtualKeyQuietTime = milliseconds_to_nanoseconds(result); + jint virtualKeyQuietTime = env->CallIntMethod(mCallbacksObj, + gCallbacksClassInfo.getVirtualKeyQuietTimeMillis); + if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) { + outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime); } - return mVirtualKeyQuietTime; -} - -void NativeInputManager::getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) { - outExcludedDeviceNames.clear(); - - JNIEnv* env = jniEnv(); - jobjectArray result = jobjectArray(env->CallObjectMethod(mCallbacksObj, + outConfig->excludedDeviceNames.clear(); + jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mCallbacksObj, gCallbacksClassInfo.getExcludedDeviceNames)); - if (! checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && result) { - jsize length = env->GetArrayLength(result); + if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) { + jsize length = env->GetArrayLength(excludedDeviceNames); for (jsize i = 0; i < length; i++) { - jstring item = jstring(env->GetObjectArrayElement(result, i)); - + jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i)); const char* deviceNameChars = env->GetStringUTFChars(item, NULL); - outExcludedDeviceNames.add(String8(deviceNameChars)); + outConfig->excludedDeviceNames.add(String8(deviceNameChars)); env->ReleaseStringUTFChars(item, deviceNameChars); - env->DeleteLocalRef(item); } - env->DeleteLocalRef(result); + env->DeleteLocalRef(excludedDeviceNames); + } + + jint tapTimeout = env->CallIntMethod(mCallbacksObj, + gCallbacksClassInfo.getTapTimeout); + if (!checkAndClearExceptionFromCallback(env, "getTapTimeout")) { + jint doubleTapTimeout = env->CallIntMethod(mCallbacksObj, + gCallbacksClassInfo.getDoubleTapTimeout); + if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) { + jint longPressTimeout = env->CallIntMethod(mCallbacksObj, + gCallbacksClassInfo.getLongPressTimeout); + if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) { + outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(tapTimeout); + + // We must ensure that the tap-drag interval is significantly shorter than + // the long-press timeout because the tap is held down for the entire duration + // of the double-tap timeout. + jint tapDragInterval = max(min(longPressTimeout - 100, + doubleTapTimeout), tapTimeout); + outConfig->pointerGestureTapDragInterval = + milliseconds_to_nanoseconds(tapDragInterval); + } + } + } + + jint touchSlop = env->CallIntMethod(mCallbacksObj, + gCallbacksClassInfo.getTouchSlop); + if (!checkAndClearExceptionFromCallback(env, "getTouchSlop")) { + outConfig->pointerGestureTapSlop = touchSlop; } } @@ -557,54 +547,31 @@ void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& i } } -nsecs_t NativeInputManager::getKeyRepeatTimeout() { - if (! isScreenOn()) { - // Disable key repeat when the screen is off. - return -1; - } else { - if (mKeyRepeatTimeout < 0) { - JNIEnv* env = jniEnv(); - - jint result = env->CallIntMethod(mCallbacksObj, - gCallbacksClassInfo.getKeyRepeatTimeout); - if (checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) { - result = 500; - } +void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) { + JNIEnv* env = jniEnv(); - mKeyRepeatTimeout = milliseconds_to_nanoseconds(result); - } - return mKeyRepeatTimeout; + jint keyRepeatTimeout = env->CallIntMethod(mCallbacksObj, + gCallbacksClassInfo.getKeyRepeatTimeout); + if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) { + outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout); } -} -nsecs_t NativeInputManager::getKeyRepeatDelay() { - if (mKeyRepeatDelay < 0) { - JNIEnv* env = jniEnv(); - - jint result = env->CallIntMethod(mCallbacksObj, - gCallbacksClassInfo.getKeyRepeatDelay); - if (checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) { - result = 50; - } + jint keyRepeatDelay = env->CallIntMethod(mCallbacksObj, + gCallbacksClassInfo.getKeyRepeatDelay); + if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) { + outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay); + } - mKeyRepeatDelay = milliseconds_to_nanoseconds(result); + jint maxEventsPerSecond = env->CallIntMethod(mCallbacksObj, + gCallbacksClassInfo.getMaxEventsPerSecond); + if (!checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) { + outConfig->maxEventsPerSecond = maxEventsPerSecond; } - return mKeyRepeatDelay; } -int32_t NativeInputManager::getMaxEventsPerSecond() { - if (mMaxEventsPerSecond < 0) { - JNIEnv* env = jniEnv(); - - jint result = env->CallIntMethod(mCallbacksObj, - gCallbacksClassInfo.getMaxEventsPerSecond); - if (checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) { - result = 60; - } - - mMaxEventsPerSecond = result; - } - return mMaxEventsPerSecond; +bool NativeInputManager::isKeyRepeatEnabled() { + // Only enable automatic key repeating when the screen is on. + return isScreenOn(); } void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) { @@ -1388,6 +1355,18 @@ int register_android_server_InputManager(JNIEnv* env) { GET_METHOD_ID(gCallbacksClassInfo.getKeyRepeatDelay, clazz, "getKeyRepeatDelay", "()I"); + GET_METHOD_ID(gCallbacksClassInfo.getTapTimeout, clazz, + "getTapTimeout", "()I"); + + GET_METHOD_ID(gCallbacksClassInfo.getDoubleTapTimeout, clazz, + "getDoubleTapTimeout", "()I"); + + GET_METHOD_ID(gCallbacksClassInfo.getLongPressTimeout, clazz, + "getLongPressTimeout", "()I"); + + GET_METHOD_ID(gCallbacksClassInfo.getTouchSlop, clazz, + "getTouchSlop", "()I"); + GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, clazz, "getMaxEventsPerSecond", "()I"); |