diff options
author | Kai Wang <kwangsudo@google.com> | 2017-09-05 23:21:07 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-09-05 23:21:07 +0000 |
commit | a8595bbfee687a56f1cb99a8652b54dcf83cda4c (patch) | |
tree | 84fc79fdbf1f3387655301c018fc223b0075dd48 | |
parent | f3e4749b82d072c4e8701a412c3d360309011af9 (diff) | |
parent | 86baa82d016ba069625da43a226aba9302eed98b (diff) |
Merge "MediaBrowserService: Clean up ConnectionRecord when browser is dead" into oc-mr1-dev am: bbf55bb7ae
am: 86baa82d01
Change-Id: I509f5d8ae4c8224ee1e7b8ceffd2a65f1da1254c
-rw-r--r-- | media/java/android/service/media/MediaBrowserService.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/media/java/android/service/media/MediaBrowserService.java b/media/java/android/service/media/MediaBrowserService.java index 4df645dc7b2f..4fc43ea78537 100644 --- a/media/java/android/service/media/MediaBrowserService.java +++ b/media/java/android/service/media/MediaBrowserService.java @@ -110,12 +110,22 @@ public abstract class MediaBrowserService extends Service { /** * All the info about a connection. */ - private class ConnectionRecord { + private class ConnectionRecord implements IBinder.DeathRecipient { String pkg; Bundle rootHints; IMediaBrowserServiceCallbacks callbacks; BrowserRoot root; HashMap<String, List<Pair<IBinder, Bundle>>> subscriptions = new HashMap<>(); + + @Override + public void binderDied() { + mHandler.post(new Runnable() { + @Override + public void run() { + mConnections.remove(callbacks.asBinder()); + } + }); + } } /** @@ -207,7 +217,6 @@ public abstract class MediaBrowserService extends Service { connection.pkg = pkg; connection.rootHints = rootHints; connection.callbacks = callbacks; - connection.root = MediaBrowserService.this.onGetRoot(pkg, uid, rootHints); // If they didn't return something, don't allow this client. @@ -223,6 +232,7 @@ public abstract class MediaBrowserService extends Service { } else { try { mConnections.put(b, connection); + b.linkToDeath(connection, 0); if (mSession != null) { callbacks.onConnect(connection.root.getRootId(), mSession, connection.root.getExtras()); @@ -248,6 +258,7 @@ public abstract class MediaBrowserService extends Service { final ConnectionRecord old = mConnections.remove(b); if (old != null) { // TODO + old.callbacks.asBinder().unlinkToDeath(old, 0); } } }); |