diff options
| -rw-r--r-- | api/current.xml | 11 | ||||
| -rwxr-xr-x | core/java/android/os/IVibratorService.aidl | 1 | ||||
| -rw-r--r-- | core/java/android/os/Vibrator.java | 16 | ||||
| -rwxr-xr-x | services/java/com/android/server/VibratorService.java | 5 | ||||
| -rw-r--r-- | services/jni/com_android_server_VibratorService.cpp | 6 |
5 files changed, 39 insertions, 0 deletions
diff --git a/api/current.xml b/api/current.xml index 0df3891..c7cddac 100644 --- a/api/current.xml +++ b/api/current.xml @@ -142511,6 +142511,17 @@ visibility="public" > </method> +<method name="hasVibrator" + return="boolean" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="vibrate" return="void" abstract="false" diff --git a/core/java/android/os/IVibratorService.aidl b/core/java/android/os/IVibratorService.aidl index c98fb56..2c2fe8a 100755 --- a/core/java/android/os/IVibratorService.aidl +++ b/core/java/android/os/IVibratorService.aidl @@ -19,6 +19,7 @@ package android.os; /** {@hide} */ interface IVibratorService { + boolean hasVibrator(); void vibrate(long milliseconds, IBinder token); void vibratePattern(in long[] pattern, int repeat, IBinder token); void cancelVibrate(IBinder token); diff --git a/core/java/android/os/Vibrator.java b/core/java/android/os/Vibrator.java index be818da..e9428f7 100644 --- a/core/java/android/os/Vibrator.java +++ b/core/java/android/os/Vibrator.java @@ -38,6 +38,22 @@ public class Vibrator } /** + * Check whether the hardware has a vibrator. Returns true if a vibrator + * exists, else false. + */ + public boolean hasVibrator() { + if (mService == null) { + Log.w(TAG, "Failed to vibrate; no vibrator service."); + return false; + } + try { + return mService.hasVibrator(); + } catch (RemoteException e) { + } + return false; + } + + /** * Turn the vibrator on. * * @param milliseconds How long to vibrate for. diff --git a/services/java/com/android/server/VibratorService.java b/services/java/com/android/server/VibratorService.java index f0b5955..2fcdb5d 100755 --- a/services/java/com/android/server/VibratorService.java +++ b/services/java/com/android/server/VibratorService.java @@ -112,6 +112,10 @@ public class VibratorService extends IVibratorService.Stub { context.registerReceiver(mIntentReceiver, filter); } + public boolean hasVibrator() { + return vibratorExists(); + } + public void vibrate(long milliseconds, IBinder token) { if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED) { @@ -380,6 +384,7 @@ public class VibratorService extends IVibratorService.Stub { volatile VibrateThread mThread; + native static boolean vibratorExists(); native static void vibratorOn(long milliseconds); native static void vibratorOff(); } diff --git a/services/jni/com_android_server_VibratorService.cpp b/services/jni/com_android_server_VibratorService.cpp index 6ec5c07..0912d43 100644 --- a/services/jni/com_android_server_VibratorService.cpp +++ b/services/jni/com_android_server_VibratorService.cpp @@ -29,6 +29,11 @@ namespace android { +static jboolean vibratorExists(JNIEnv *env, jobject clazz) +{ + return vibrator_exists() > 0 ? JNI_TRUE : JNI_FALSE; +} + static void vibratorOn(JNIEnv *env, jobject clazz, jlong timeout_ms) { // LOGI("vibratorOn\n"); @@ -42,6 +47,7 @@ static void vibratorOff(JNIEnv *env, jobject clazz) } static JNINativeMethod method_table[] = { + { "vibratorExists", "()Z", (void*)vibratorExists }, { "vibratorOn", "(J)V", (void*)vibratorOn }, { "vibratorOff", "()V", (void*)vibratorOff } }; |
