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