Merge "MediaRouter: Refactor methods for selecting group route." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8a49089585
@@ -22,6 +22,6 @@ package android.media;
|
||||
oneway interface IMediaRouterClient {
|
||||
void onStateChanged();
|
||||
void onRestoreRoute();
|
||||
void onSelectedRouteChanged(String routeId);
|
||||
void onGroupRouteSelected(String routeId);
|
||||
void onGlobalA2dpChanged(boolean a2dpOn);
|
||||
}
|
||||
|
||||
@@ -122,6 +122,8 @@ public class MediaRouter {
|
||||
mIsBluetoothA2dpOn = mAudioService.isBluetoothA2dpOn();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error querying Bluetooth A2DP state", e);
|
||||
//TODO: When we reach here, mIsBluetoothA2dpOn may not be synced with
|
||||
// mBluetoothA2dpRoute.
|
||||
}
|
||||
mHandler.post(new Runnable() {
|
||||
@Override public void run() {
|
||||
@@ -403,18 +405,18 @@ public class MediaRouter {
|
||||
}
|
||||
}
|
||||
|
||||
void updateSelectedRouteForId(String routeId) {
|
||||
RouteInfo selectedRoute = isBluetoothA2dpOn()
|
||||
void handleGroupRouteSelected(String routeId) {
|
||||
RouteInfo routeToSelect = isBluetoothA2dpOn()
|
||||
? mBluetoothA2dpRoute : mDefaultAudioVideo;
|
||||
final int count = mRoutes.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final RouteInfo route = mRoutes.get(i);
|
||||
if (TextUtils.equals(route.mGlobalRouteId, routeId)) {
|
||||
selectedRoute = route;
|
||||
routeToSelect = route;
|
||||
}
|
||||
}
|
||||
if (selectedRoute != mSelectedRoute) {
|
||||
selectRouteStatic(selectedRoute.mSupportedTypes, selectedRoute, false);
|
||||
if (routeToSelect != mSelectedRoute) {
|
||||
selectRouteStatic(routeToSelect.mSupportedTypes, routeToSelect, /*explicit=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,10 +677,10 @@ public class MediaRouter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectedRouteChanged(String routeId) {
|
||||
public void onGroupRouteSelected(String groupRouteId) {
|
||||
mHandler.post(() -> {
|
||||
if (Client.this == mClient) {
|
||||
updateSelectedRouteForId(routeId);
|
||||
handleGroupRouteSelected(groupRouteId);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -689,9 +691,9 @@ public class MediaRouter {
|
||||
public void onGlobalA2dpChanged(boolean a2dpOn) {
|
||||
mHandler.post(() -> {
|
||||
if (mSelectedRoute == mDefaultAudioVideo && a2dpOn) {
|
||||
setSelectedRoute(mBluetoothA2dpRoute, false);
|
||||
setSelectedRoute(mBluetoothA2dpRoute, /*explicit=*/false);
|
||||
} else if (mSelectedRoute == mBluetoothA2dpRoute && !a2dpOn) {
|
||||
setSelectedRoute(mDefaultAudioVideo, false);
|
||||
setSelectedRoute(mDefaultAudioVideo, /*explicit=*/false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -728,7 +728,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
||||
clientRecord.mGroupId = groupId;
|
||||
if (groupId != null) {
|
||||
userRecord.addToGroup(groupId, clientRecord);
|
||||
userRecord.mHandler.obtainMessage(UserHandler.MSG_UPDATE_SELECTED_ROUTE, groupId)
|
||||
userRecord.mHandler.obtainMessage(UserHandler.MSG_NOTIFY_GROUP_ROUTE_SELECTED, groupId)
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
@@ -809,7 +809,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
||||
if (group != null) {
|
||||
group.mSelectedRouteId = routeId;
|
||||
clientRecord.mUserRecord.mHandler.obtainMessage(
|
||||
UserHandler.MSG_UPDATE_SELECTED_ROUTE, clientRecord.mGroupId)
|
||||
UserHandler.MSG_NOTIFY_GROUP_ROUTE_SELECTED, clientRecord.mGroupId)
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
@@ -1079,7 +1079,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
||||
public static final int MSG_REQUEST_UPDATE_VOLUME = 7;
|
||||
private static final int MSG_UPDATE_CLIENT_STATE = 8;
|
||||
private static final int MSG_CONNECTION_TIMED_OUT = 9;
|
||||
private static final int MSG_UPDATE_SELECTED_ROUTE = 10;
|
||||
private static final int MSG_NOTIFY_GROUP_ROUTE_SELECTED = 10;
|
||||
|
||||
private static final int TIMEOUT_REASON_NOT_AVAILABLE = 1;
|
||||
private static final int TIMEOUT_REASON_CONNECTION_LOST = 2;
|
||||
@@ -1156,8 +1156,8 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
||||
connectionTimedOut();
|
||||
break;
|
||||
}
|
||||
case MSG_UPDATE_SELECTED_ROUTE: {
|
||||
updateSelectedRoute((String) msg.obj);
|
||||
case MSG_NOTIFY_GROUP_ROUTE_SELECTED: {
|
||||
notifyGroupRouteSelected((String) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1483,9 +1483,9 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSelectedRoute(String groupId) {
|
||||
private void notifyGroupRouteSelected(String groupId) {
|
||||
try {
|
||||
String selectedRouteId = null;
|
||||
String selectedRouteId;
|
||||
synchronized (mService.mLock) {
|
||||
ClientGroup group = mUserRecord.mClientGroupMap.get(groupId);
|
||||
if (group == null) {
|
||||
@@ -1504,7 +1504,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
||||
final int count = mTempClients.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
try {
|
||||
mTempClients.get(i).onSelectedRouteChanged(selectedRouteId);
|
||||
mTempClients.get(i).onGroupRouteSelected(selectedRouteId);
|
||||
} catch (RemoteException ex) {
|
||||
Slog.w(TAG, "Failed to call onSelectedRouteChanged. Client probably died.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user