Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea9020e0 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Add API to find out if there is a vibrator.

Change-Id: If29f6ee19448222433cad9fad325d0095a8e5737
parent d8d7b555
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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"
+1 −0
Original line number Diff line number Diff line
@@ -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);
+16 −0
Original line number Diff line number Diff line
@@ -37,6 +37,22 @@ public class Vibrator
                ServiceManager.getService("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.
     *
+5 −0
Original line number Diff line number Diff line
@@ -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();
}
+6 −0
Original line number Diff line number Diff line
@@ -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 }
};