From 093fc5d6387446fe2fab2b910f54fd3a670c4c38 Mon Sep 17 00:00:00 2001 From: Santiago Seifert Date: Fri, 9 Feb 2024 10:57:40 +0000 Subject: Refactor out rebindIfDisconnected In preparation for flagged changes to prevent that mechanism. Flag: NONE Bug: b/263520343 Test: atest MediaRouter2HostSideTest Change-Id: I62f707132efce2c5e40f10e7d0cf723201c7f0e2 --- .../server/media/MediaRoute2ProviderServiceProxy.java | 15 +++++---------- .../android/server/media/MediaRoute2ProviderWatcher.java | 5 ++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/services/core/java/com/android/server/media/MediaRoute2ProviderServiceProxy.java b/services/core/java/com/android/server/media/MediaRoute2ProviderServiceProxy.java index 0ae60360883d..cec7a79cdada 100644 --- a/services/core/java/com/android/server/media/MediaRoute2ProviderServiceProxy.java +++ b/services/core/java/com/android/server/media/MediaRoute2ProviderServiceProxy.java @@ -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(); diff --git a/services/core/java/com/android/server/media/MediaRoute2ProviderWatcher.java b/services/core/java/com/android/server/media/MediaRoute2ProviderWatcher.java index 3d717a871cf1..233a3ab4a4ea 100644 --- a/services/core/java/com/android/server/media/MediaRoute2ProviderWatcher.java +++ b/services/core/java/com/android/server/media/MediaRoute2ProviderWatcher.java @@ -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++); } } -- cgit v1.2.3-59-g8ed1b