Unregister callback from binder when vibration is removed
When creating new vibration pattern, a callback is registered
in case binding to caller goes away, by linkToDeath().
Need to unregister this callback when we throw away the vibration.
Change-Id: Ibdf0bd415a539054ac7a66f49b33a864f729c546
diff --git a/services/java/com/android/server/VibratorService.java b/services/java/com/android/server/VibratorService.java
index f0b5955..86c30f8 100755
--- a/services/java/com/android/server/VibratorService.java
+++ b/services/java/com/android/server/VibratorService.java
@@ -243,6 +243,7 @@
// Lock held on mVibrations
private void startNextVibrationLocked() {
if (mVibrations.size() <= 0) {
+ mCurrentVibration = null;
return;
}
mCurrentVibration = mVibrations.getFirst();
@@ -269,17 +270,27 @@
Vibration vib = iter.next();
if (vib.mToken == token) {
iter.remove();
+ unlinkVibration(vib);
return vib;
}
}
// We might be looking for a simple vibration which is only stored in
// mCurrentVibration.
if (mCurrentVibration != null && mCurrentVibration.mToken == token) {
+ unlinkVibration(mCurrentVibration);
return mCurrentVibration;
}
return null;
}
+ private void unlinkVibration(Vibration vib) {
+ if (vib.mPattern != null) {
+ // If Vibration object has a pattern,
+ // the Vibration object has also been linkedToDeath.
+ vib.mToken.unlinkToDeath(vib, 0);
+ }
+ }
+
private class VibrateThread extends Thread {
final Vibration mVibration;
boolean mDone;
@@ -356,6 +367,7 @@
// If this vibration finished naturally, start the next
// vibration.
mVibrations.remove(mVibration);
+ unlinkVibration(mVibration);
startNextVibrationLocked();
}
}