MediaRouter: Refactor methods for selecting group route.
This CL renames methods to update selected route of apps sharing the same group ID. Bug: 184349580 Test: Build successful Change-Id: I71a7a13d95e6f39eb54326b5e402df8556c964eb
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -722,7 +722,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();
|
||||
}
|
||||
}
|
||||
@@ -803,7 +803,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();
|
||||
}
|
||||
}
|
||||
@@ -1073,7 +1073,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;
|
||||
@@ -1150,8 +1150,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;
|
||||
}
|
||||
}
|
||||
@@ -1477,9 +1477,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) {
|
||||
@@ -1498,7 +1498,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