Improve the Vibrator service by keeping track of multiple vibration requests.

There are 2 types of vibrations: simple and repeated. Simple vibrations run for
a given length of time while repeated patterns run until canceled or the calling
process dies.

If a vibration is currently running and another request is issued, the newer
request always takes precedence unless the current vibration is a simple one and
the time left is longer than the new request.

If a repeating vibration is running and a new request overrides that vibration,
the current vibration is pushed onto a stack. Once the new vibration completes,
the previous vibration resumes. IBinder tokens are used to identify Vibration
requests which means that multiple calls to Vibrator.vibrate with the same
Vibrator object will override previous vibrations on that object.
This commit is contained in:
Patrick Scott
2009-07-02 11:31:12 -04:00
parent f8e3ba5bfa
commit 18dd5f0d25
4 changed files with 182 additions and 82 deletions

View File

@@ -20,9 +20,9 @@ package android.os;
interface IHardwareService
{
// Vibrator support
void vibrate(long milliseconds);
void vibrate(long milliseconds, IBinder token);
void vibratePattern(in long[] pattern, int repeat, IBinder token);
void cancelVibrate();
void cancelVibrate(IBinder token);
// flashlight support
boolean getFlashlightEnabled();

View File

@@ -24,6 +24,7 @@ package android.os;
public class Vibrator
{
IHardwareService mService;
private final Binder mToken = new Binder();
/** @hide */
public Vibrator()
@@ -40,7 +41,7 @@ public class Vibrator
public void vibrate(long milliseconds)
{
try {
mService.vibrate(milliseconds);
mService.vibrate(milliseconds, mToken);
} catch (RemoteException e) {
}
}
@@ -65,7 +66,7 @@ public class Vibrator
// anyway
if (repeat < pattern.length) {
try {
mService.vibratePattern(pattern, repeat, new Binder());
mService.vibratePattern(pattern, repeat, mToken);
} catch (RemoteException e) {
}
} else {
@@ -79,7 +80,7 @@ public class Vibrator
public void cancel()
{
try {
mService.cancelVibrate();
mService.cancelVibrate(mToken);
} catch (RemoteException e) {
}
}