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

Commit bfad288a authored by Santiago Seifert's avatar Santiago Seifert Committed by Android (Google) Code Review
Browse files

Merge "Refactor out rebindIfDisconnected" into main

parents 39744f26 093fc5d6
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ final class MediaRoute2ProviderServiceProxy extends MediaRoute2Provider
                && mComponentName.getClassName().equals(className);
    }

    public void start() {
    public void start(boolean rebindIfDisconnected) {
        if (!mRunning) {
            if (DEBUG) {
                Slog.d(TAG, this + ": Starting");
@@ -202,6 +202,10 @@ final class MediaRoute2ProviderServiceProxy extends MediaRoute2Provider
            mRunning = true;
            updateBinding();
        }
        if (rebindIfDisconnected && mActiveConnection == null && shouldBind()) {
            unbind();
            bind();
        }
    }

    public void stop() {
@@ -214,15 +218,6 @@ final class MediaRoute2ProviderServiceProxy extends MediaRoute2Provider
        }
    }

    public void rebindIfDisconnected() {
        //TODO: When we are connecting to the service, calling this will unbind and bind again.
        // We'd better not unbind if we are connecting.
        if (mActiveConnection == null && shouldBind()) {
            unbind();
            bind();
        }
    }

    private void updateBinding() {
        if (shouldBind()) {
            bind();
+2 −3
Original line number Diff line number Diff line
@@ -145,13 +145,12 @@ final class MediaRoute2ProviderWatcher {
                                    new ComponentName(serviceInfo.packageName, serviceInfo.name),
                                    isSelfScanOnlyProvider,
                                    mUserId);
                    proxy.start();
                    proxy.start(/* rebindIfDisconnected= */ false);
                    mProxies.add(targetIndex++, proxy);
                    mCallback.onAddProviderService(proxy);
                } else if (sourceIndex >= targetIndex) {
                    MediaRoute2ProviderServiceProxy proxy = mProxies.get(sourceIndex);
                    proxy.start(); // restart the proxy if needed
                    proxy.rebindIfDisconnected();
                    proxy.start(/* rebindIfDisconnected= */ true); // restart the proxy if needed
                    Collections.swap(mProxies, sourceIndex, targetIndex++);
                }
            }