diff options
| author | 2012-08-10 14:17:33 +0200 | |
|---|---|---|
| committer | 2014-11-17 15:11:26 +0100 | |
| commit | e6904fbdf7976abbadf3e7e658e9416ca49402f9 (patch) | |
| tree | 329648430528189b2c0edf5fead1040281f70d28 | |
| parent | 34c495d2e9d873aeb7e3d86077f0ef4b8d8993b6 (diff) | |
Vibra: Add loading of the vibrator hardware module.
Vibrator HAL is now formed of two hardware modules: one is the default
AOSP and the other is the vendor implementation.
The vendor implementation will be loaded prior to the default one.
For that, the vibrator service has to load the module before
registering itself to the JNI.
This change is related to other changes in:
- hardware/libhardware
- hardware/libhardware_legacy
Change-Id: I844279f5535289f079d412fdc44c5cb3c9c1130c
Author: Vincent Becker <vincentx.becker@intel.com>
Signed-off-by: Vincent Becker <vincentx.becker@intel.com>
Signed-off-by: Shuo Gao <shuo.gao@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: David Wagner <david.wagner@intel.com>
Author-tracking-BZ: 49760 94611
| -rw-r--r-- | services/core/java/com/android/server/VibratorService.java | 2 | ||||
| -rw-r--r-- | services/core/jni/com_android_server_VibratorService.cpp | 49 |
2 files changed, 45 insertions, 6 deletions
diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 20f6f1ccffec..9557ebde794b 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -82,6 +82,7 @@ public class VibratorService extends IVibratorService.Stub private SettingsObserver mSettingObserver; native static boolean vibratorExists(); + native static void vibratorInit(); native static void vibratorOn(long milliseconds); native static void vibratorOff(); @@ -147,6 +148,7 @@ public class VibratorService extends IVibratorService.Stub } VibratorService(Context context) { + vibratorInit(); // Reset the hardware to a default state, in case this is a runtime // restart instead of a fresh boot. vibratorOff(); diff --git a/services/core/jni/com_android_server_VibratorService.cpp b/services/core/jni/com_android_server_VibratorService.cpp index fb1166b41d41..b8e004f06ee6 100644 --- a/services/core/jni/com_android_server_VibratorService.cpp +++ b/services/core/jni/com_android_server_VibratorService.cpp @@ -22,32 +22,69 @@ #include <utils/misc.h> #include <utils/Log.h> -#include <hardware_legacy/vibrator.h> +#include <hardware/vibrator.h> #include <stdio.h> namespace android { +static hw_module_t *gVibraModule = NULL; +static vibrator_device_t *gVibraDevice = NULL; + +static void vibratorInit(JNIEnv /* env */, jobject /* clazz */) +{ + if (gVibraModule != NULL) { + return; + } + + int err = hw_get_module(VIBRATOR_HARDWARE_MODULE_ID, (hw_module_t const**)&gVibraModule); + + if (err) { + ALOGE("Couldn't load %s module (%s)", VIBRATOR_HARDWARE_MODULE_ID, strerror(-err)); + } else { + if (gVibraModule) { + vibrator_open(gVibraModule, &gVibraDevice); + } + } +} + static jboolean vibratorExists(JNIEnv* /* env */, jobject /* clazz */) { - return vibrator_exists() > 0 ? JNI_TRUE : JNI_FALSE; + if (gVibraModule && gVibraDevice) { + return JNI_TRUE; + } else { + return JNI_FALSE; + } } static void vibratorOn(JNIEnv* /* env */, jobject /* clazz */, jlong timeout_ms) { - // ALOGI("vibratorOn\n"); - vibrator_on(timeout_ms); + if (gVibraDevice) { + int err = gVibraDevice->vibrator_on(gVibraDevice, timeout_ms); + if (err != 0) { + ALOGE("The hw module failed in vibrator_on: %s", strerror(-err)); + } + } else { + ALOGW("Tried to vibrate but there is no vibrator device."); + } } static void vibratorOff(JNIEnv* /* env */, jobject /* clazz */) { - // ALOGI("vibratorOff\n"); - vibrator_off(); + if (gVibraDevice) { + int err = gVibraDevice->vibrator_off(gVibraDevice); + if (err != 0) { + ALOGE("The hw module failed in vibrator_off(): %s", strerror(-err)); + } + } else { + ALOGW("Tried to stop vibrating but there is no vibrator device."); + } } static JNINativeMethod method_table[] = { { "vibratorExists", "()Z", (void*)vibratorExists }, + { "vibratorInit", "()V", (void*)vibratorInit }, { "vibratorOn", "(J)V", (void*)vibratorOn }, { "vibratorOff", "()V", (void*)vibratorOff } }; |