summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Bishoy Gendy <bishoygendy@google.com> 2023-10-25 15:05:32 +0000
committer Bishoy Gendy <bishoygendy@google.com> 2023-10-27 09:11:08 +0000
commit03bf111bd86751488fbb75ee18422b96f058d8d7 (patch)
tree53db7918967f7fd2054ff9856b06fbc17ccb7936
parentddedd72a9920d3cffddf5e3da87f6ba41513d52d (diff)
Introduce waiting state for session create in SysMediaRoute2Provider
Bug: 307723189 Bug: 304816922 Test: Manually using the steps in b/304816922 Change-Id: Icc69463d11ce2320b8ce735e94c96076f3ab24ba
-rw-r--r--media/java/android/media/flags/media_better_together.aconfig7
-rw-r--r--services/core/java/com/android/server/media/SystemMediaRoute2Provider.java71
2 files changed, 63 insertions, 15 deletions
diff --git a/media/java/android/media/flags/media_better_together.aconfig b/media/java/android/media/flags/media_better_together.aconfig
index c9cfa670cf02..386534b80925 100644
--- a/media/java/android/media/flags/media_better_together.aconfig
+++ b/media/java/android/media/flags/media_better_together.aconfig
@@ -34,3 +34,10 @@ flag {
description: "Fallbacks to the default handling for volume adjustment when media session has fixed volume handling and its app is in the foreground and setting a media controller."
bug: "293743975"
}
+
+flag {
+ namespace: "media_solutions"
+ name: "enable_waiting_state_for_system_session_creation_request"
+ description: "Introduces a waiting state for the session creation request and prevents it from early failing when the selectedRoute from the bluetooth stack doesn't match the pending request route id."
+ bug: "307723189"
+}
diff --git a/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java b/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
index 67a1ccd17835..78077a831622 100644
--- a/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
+++ b/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
@@ -40,6 +40,7 @@ import android.util.Log;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
+import com.android.media.flags.Flags;
import java.util.List;
import java.util.Objects;
@@ -358,21 +359,8 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
RoutingSessionInfo newSessionInfo = builder.setProviderId(mUniqueId).build();
- if (mPendingSessionCreationRequest != null) {
- SessionCreationRequest sessionCreationRequest;
- synchronized (mRequestLock) {
- sessionCreationRequest = mPendingSessionCreationRequest;
- mPendingSessionCreationRequest = null;
- }
- if (sessionCreationRequest != null) {
- if (TextUtils.equals(mSelectedRouteId, sessionCreationRequest.mRouteId)) {
- mCallback.onSessionCreated(this,
- sessionCreationRequest.mRequestId, newSessionInfo);
- } else {
- mCallback.onRequestFailed(this, sessionCreationRequest.mRequestId,
- MediaRoute2ProviderService.REASON_UNKNOWN_ERROR);
- }
- }
+ synchronized (mRequestLock) {
+ reportPendingSessionRequestResultLockedIfNeeded(newSessionInfo);
}
if (Objects.equals(oldSessionInfo, newSessionInfo)) {
@@ -395,6 +383,59 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
}
}
+ @GuardedBy("mRequestLock")
+ private void reportPendingSessionRequestResultLockedIfNeeded(
+ RoutingSessionInfo newSessionInfo) {
+ if (mPendingSessionCreationRequest == null) {
+ // No pending request, nothing to report.
+ return;
+ }
+
+ long pendingRequestId = mPendingSessionCreationRequest.mRequestId;
+ if (TextUtils.equals(mSelectedRouteId, mPendingSessionCreationRequest.mRouteId)) {
+ if (DEBUG) {
+ Slog.w(
+ TAG,
+ "Session creation success to route "
+ + mPendingSessionCreationRequest.mRouteId);
+ }
+ mPendingSessionCreationRequest = null;
+ mCallback.onSessionCreated(this, pendingRequestId, newSessionInfo);
+ } else {
+ boolean isRequestedRouteConnectedBtRoute = isRequestedRouteConnectedBtRoute();
+ if (!Flags.enableWaitingStateForSystemSessionCreationRequest()
+ || !isRequestedRouteConnectedBtRoute) {
+ if (DEBUG) {
+ Slog.w(
+ TAG,
+ "Session creation failed to route "
+ + mPendingSessionCreationRequest.mRouteId);
+ }
+ mPendingSessionCreationRequest = null;
+ mCallback.onRequestFailed(
+ this, pendingRequestId, MediaRoute2ProviderService.REASON_UNKNOWN_ERROR);
+ } else if (DEBUG) {
+ Slog.w(
+ TAG,
+ "Session creation waiting state to route "
+ + mPendingSessionCreationRequest.mRouteId);
+ }
+ }
+ }
+
+ @GuardedBy("mRequestLock")
+ private boolean isRequestedRouteConnectedBtRoute() {
+ // Using AllRoutes instead of TransferableRoutes as BT Stack sends an intermediate update
+ // where two BT routes are active so the transferable routes list is empty.
+ // See b/307723189 for context
+ for (MediaRoute2Info btRoute : mBluetoothRouteController.getAllBluetoothRoutes()) {
+ if (TextUtils.equals(btRoute.getId(), mPendingSessionCreationRequest.mRouteId)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
void publishProviderState() {
updateProviderState();
notifyProviderState();