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

Commit 86baa82d authored by Kai Wang's avatar Kai Wang Committed by android-build-merger
Browse files

Merge "MediaBrowserService: Clean up ConnectionRecord when browser is dead" into oc-mr1-dev

am: bbf55bb7

Change-Id: I4e14e80a31c0eed3c897e35720bff1f694f7a007
parents 75a75eb9 bbf55bb7
Loading
Loading
Loading
Loading
+13 −2
Original line number Original line Diff line number Diff line
@@ -110,12 +110,22 @@ public abstract class MediaBrowserService extends Service {
    /**
    /**
     * All the info about a connection.
     * All the info about a connection.
     */
     */
    private class ConnectionRecord {
    private class ConnectionRecord implements IBinder.DeathRecipient {
        String pkg;
        String pkg;
        Bundle rootHints;
        Bundle rootHints;
        IMediaBrowserServiceCallbacks callbacks;
        IMediaBrowserServiceCallbacks callbacks;
        BrowserRoot root;
        BrowserRoot root;
        HashMap<String, List<Pair<IBinder, Bundle>>> subscriptions = new HashMap<>();
        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.pkg = pkg;
                        connection.rootHints = rootHints;
                        connection.rootHints = rootHints;
                        connection.callbacks = callbacks;
                        connection.callbacks = callbacks;

                        connection.root = MediaBrowserService.this.onGetRoot(pkg, uid, rootHints);
                        connection.root = MediaBrowserService.this.onGetRoot(pkg, uid, rootHints);


                        // If they didn't return something, don't allow this client.
                        // If they didn't return something, don't allow this client.
@@ -223,6 +232,7 @@ public abstract class MediaBrowserService extends Service {
                        } else {
                        } else {
                            try {
                            try {
                                mConnections.put(b, connection);
                                mConnections.put(b, connection);
                                b.linkToDeath(connection, 0);
                                if (mSession != null) {
                                if (mSession != null) {
                                    callbacks.onConnect(connection.root.getRootId(),
                                    callbacks.onConnect(connection.root.getRootId(),
                                            mSession, connection.root.getExtras());
                                            mSession, connection.root.getExtras());
@@ -248,6 +258,7 @@ public abstract class MediaBrowserService extends Service {
                        final ConnectionRecord old = mConnections.remove(b);
                        final ConnectionRecord old = mConnections.remove(b);
                        if (old != null) {
                        if (old != null) {
                            // TODO
                            // TODO
                            old.callbacks.asBinder().unlinkToDeath(old, 0);
                        }
                        }
                    }
                    }
                });
                });