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

Commit 093fc5d6 authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Refactor out rebindIfDisconnected

In preparation for flagged changes to prevent that mechanism.

Flag: NONE
Bug: b/263520343
Test: atest MediaRouter2HostSideTest
Change-Id: I62f707132efce2c5e40f10e7d0cf723201c7f0e2
parent 5946e673
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++);
                }
            }