Merge "Vibra: Add loading of the vibrator hardware module."
am: 5603eca33c
* commit '5603eca33c8e322997029d3101fd2442df3c274e':
Vibra: Add loading of the vibrator hardware module.
This commit is contained in:
@@ -88,6 +88,7 @@ public class VibratorService extends IVibratorService.Stub
|
|||||||
private SettingsObserver mSettingObserver;
|
private SettingsObserver mSettingObserver;
|
||||||
|
|
||||||
native static boolean vibratorExists();
|
native static boolean vibratorExists();
|
||||||
|
native static void vibratorInit();
|
||||||
native static void vibratorOn(long milliseconds);
|
native static void vibratorOn(long milliseconds);
|
||||||
native static void vibratorOff();
|
native static void vibratorOff();
|
||||||
|
|
||||||
@@ -195,6 +196,7 @@ public class VibratorService extends IVibratorService.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
VibratorService(Context context) {
|
VibratorService(Context context) {
|
||||||
|
vibratorInit();
|
||||||
// Reset the hardware to a default state, in case this is a runtime
|
// Reset the hardware to a default state, in case this is a runtime
|
||||||
// restart instead of a fresh boot.
|
// restart instead of a fresh boot.
|
||||||
vibratorOff();
|
vibratorOff();
|
||||||
|
|||||||
@@ -22,32 +22,69 @@
|
|||||||
|
|
||||||
#include <utils/misc.h>
|
#include <utils/misc.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <hardware_legacy/vibrator.h>
|
#include <hardware/vibrator.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
namespace android
|
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 */)
|
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)
|
static void vibratorOn(JNIEnv* /* env */, jobject /* clazz */, jlong timeout_ms)
|
||||||
{
|
{
|
||||||
// ALOGI("vibratorOn\n");
|
if (gVibraDevice) {
|
||||||
vibrator_on(timeout_ms);
|
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 */)
|
static void vibratorOff(JNIEnv* /* env */, jobject /* clazz */)
|
||||||
{
|
{
|
||||||
// ALOGI("vibratorOff\n");
|
if (gVibraDevice) {
|
||||||
vibrator_off();
|
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 const JNINativeMethod method_table[] = {
|
static const JNINativeMethod method_table[] = {
|
||||||
{ "vibratorExists", "()Z", (void*)vibratorExists },
|
{ "vibratorExists", "()Z", (void*)vibratorExists },
|
||||||
|
{ "vibratorInit", "()V", (void*)vibratorInit },
|
||||||
{ "vibratorOn", "(J)V", (void*)vibratorOn },
|
{ "vibratorOn", "(J)V", (void*)vibratorOn },
|
||||||
{ "vibratorOff", "()V", (void*)vibratorOff }
|
{ "vibratorOff", "()V", (void*)vibratorOff }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user