From a47425a13c19f95057df78b8bb65bb25657e8753 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Fri, 13 Apr 2012 04:09:27 -0700 Subject: Add support for input devices that have vibrators. Added a getVibrator() method to InputDevice which returns a Vibrator associated with that input device. Its uses the same API as the system vibrator which makes it easy for applications to be modified to use one or the other. Bug: 6334179 Change-Id: Ifc7f13dbcb778670f3f1c07ccc562334e6109d2e --- ...om_android_server_input_InputManagerService.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'services/jni') diff --git a/services/jni/com_android_server_input_InputManagerService.cpp b/services/jni/com_android_server_input_InputManagerService.cpp index f1536fd..3795074 100644 --- a/services/jni/com_android_server_input_InputManagerService.cpp +++ b/services/jni/com_android_server_input_InputManagerService.cpp @@ -1226,6 +1226,38 @@ static void nativeSetShowTouches(JNIEnv* env, im->setShowTouches(enabled); } +static void nativeVibrate(JNIEnv* env, + jclass clazz, jint ptr, jint deviceId, jlongArray patternObj, + jint repeat, jint token) { + NativeInputManager* im = reinterpret_cast(ptr); + + size_t patternSize = env->GetArrayLength(patternObj); + if (patternSize > MAX_VIBRATE_PATTERN_SIZE) { + ALOGI("Skipped requested vibration because the pattern size is %d " + "which is more than the maximum supported size of %d.", + patternSize, MAX_VIBRATE_PATTERN_SIZE); + return; // limit to reasonable size + } + + jlong* patternMillis = static_cast(env->GetPrimitiveArrayCritical( + patternObj, NULL)); + nsecs_t pattern[patternSize]; + for (size_t i = 0; i < patternSize; i++) { + pattern[i] = max(jlong(0), min(patternMillis[i], + MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL; + } + env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT); + + im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token); +} + +static void nativeCancelVibrate(JNIEnv* env, + jclass clazz, jint ptr, jint deviceId, jint token) { + NativeInputManager* im = reinterpret_cast(ptr); + + im->getInputManager()->getReader()->cancelVibrate(deviceId, token); +} + static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) { NativeInputManager* im = reinterpret_cast(ptr); @@ -1287,6 +1319,10 @@ static JNINativeMethod gInputManagerMethods[] = { (void*) nativeSetPointerSpeed }, { "nativeSetShowTouches", "(IZ)V", (void*) nativeSetShowTouches }, + { "nativeVibrate", "(II[JII)V", + (void*) nativeVibrate }, + { "nativeCancelVibrate", "(III)V", + (void*) nativeCancelVibrate }, { "nativeDump", "(I)Ljava/lang/String;", (void*) nativeDump }, { "nativeMonitor", "(I)V", -- cgit v1.1