Merge "MediaSession: Remove pending callback messages when setCallback(null) is called."
diff --git a/media/java/android/media/session/MediaSession.java b/media/java/android/media/session/MediaSession.java
index 1291dfb..b8184a0 100644
--- a/media/java/android/media/session/MediaSession.java
+++ b/media/java/android/media/session/MediaSession.java
@@ -119,7 +119,7 @@
private final ISession mBinder;
private final CallbackStub mCbStub;
- private CallbackMessageHandler mCallback;
+ private CallbackMessageHandler mCallbackHandler;
private VolumeProvider mVolumeProvider;
private PlaybackState mPlaybackState;
@@ -194,16 +194,14 @@
*/
public void setCallback(@Nullable Callback callback, @Nullable Handler handler) {
synchronized (mLock) {
- if (callback == null) {
- if (mCallback != null) {
- mCallback.mCallback.mSession = null;
- }
- mCallback = null;
- return;
- }
- if (mCallback != null) {
+ if (mCallbackHandler != null) {
// We're updating the callback, clear the session from the old one.
- mCallback.mCallback.mSession = null;
+ mCallbackHandler.mCallback.mSession = null;
+ mCallbackHandler.removeCallbacksAndMessages(null);
+ }
+ if (callback == null) {
+ mCallbackHandler = null;
+ return;
}
if (handler == null) {
handler = new Handler();
@@ -211,7 +209,7 @@
callback.mSession = this;
CallbackMessageHandler msgHandler = new CallbackMessageHandler(handler.getLooper(),
callback);
- mCallback = msgHandler;
+ mCallbackHandler = msgHandler;
}
}
@@ -636,8 +634,8 @@
private void postToCallback(int what, Object obj, Bundle extras) {
synchronized (mLock) {
- if (mCallback != null) {
- mCallback.post(what, obj, extras);
+ if (mCallbackHandler != null) {
+ mCallbackHandler.post(what, obj, extras);
}
}
}