Merge "Select correct system audio route in updateAudioRoutes" into oc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
43d5d86cda
@@ -28,7 +28,6 @@ interface IMediaRouterService {
|
|||||||
|
|
||||||
MediaRouterClientState getState(IMediaRouterClient client);
|
MediaRouterClientState getState(IMediaRouterClient client);
|
||||||
boolean isPlaybackActive(IMediaRouterClient client);
|
boolean isPlaybackActive(IMediaRouterClient client);
|
||||||
boolean isGlobalBluetoothA2doOn();
|
|
||||||
|
|
||||||
void setDiscoveryRequest(IMediaRouterClient client, int routeTypes, boolean activeScan);
|
void setDiscoveryRequest(IMediaRouterClient client, int routeTypes, boolean activeScan);
|
||||||
void setSelectedRoute(IMediaRouterClient client, String routeId, boolean explicit);
|
void setSelectedRoute(IMediaRouterClient client, String routeId, boolean explicit);
|
||||||
|
|||||||
@@ -184,25 +184,33 @@ public class MediaRouter {
|
|||||||
|
|
||||||
void updateAudioRoutes(AudioRoutesInfo newRoutes) {
|
void updateAudioRoutes(AudioRoutesInfo newRoutes) {
|
||||||
boolean audioRoutesChanged = false;
|
boolean audioRoutesChanged = false;
|
||||||
|
boolean forceUseDefaultRoute = false;
|
||||||
|
|
||||||
if (newRoutes.mainType != mCurAudioRoutesInfo.mainType) {
|
if (newRoutes.mainType != mCurAudioRoutesInfo.mainType) {
|
||||||
mCurAudioRoutesInfo.mainType = newRoutes.mainType;
|
mCurAudioRoutesInfo.mainType = newRoutes.mainType;
|
||||||
int name;
|
int name;
|
||||||
if ((newRoutes.mainType&AudioRoutesInfo.MAIN_HEADPHONES) != 0
|
if ((newRoutes.mainType & AudioRoutesInfo.MAIN_HEADPHONES) != 0
|
||||||
|| (newRoutes.mainType&AudioRoutesInfo.MAIN_HEADSET) != 0) {
|
|| (newRoutes.mainType & AudioRoutesInfo.MAIN_HEADSET) != 0) {
|
||||||
name = com.android.internal.R.string.default_audio_route_name_headphones;
|
name = com.android.internal.R.string.default_audio_route_name_headphones;
|
||||||
} else if ((newRoutes.mainType&AudioRoutesInfo.MAIN_DOCK_SPEAKERS) != 0) {
|
} else if ((newRoutes.mainType & AudioRoutesInfo.MAIN_DOCK_SPEAKERS) != 0) {
|
||||||
name = com.android.internal.R.string.default_audio_route_name_dock_speakers;
|
name = com.android.internal.R.string.default_audio_route_name_dock_speakers;
|
||||||
} else if ((newRoutes.mainType&AudioRoutesInfo.MAIN_HDMI) != 0) {
|
} else if ((newRoutes.mainType & AudioRoutesInfo.MAIN_HDMI) != 0) {
|
||||||
name = com.android.internal.R.string.default_media_route_name_hdmi;
|
name = com.android.internal.R.string.default_media_route_name_hdmi;
|
||||||
} else {
|
} else {
|
||||||
name = com.android.internal.R.string.default_audio_route_name;
|
name = com.android.internal.R.string.default_audio_route_name;
|
||||||
}
|
}
|
||||||
mDefaultAudioVideo.mNameResId = name;
|
mDefaultAudioVideo.mNameResId = name;
|
||||||
dispatchRouteChanged(mDefaultAudioVideo);
|
dispatchRouteChanged(mDefaultAudioVideo);
|
||||||
|
|
||||||
|
if ((newRoutes.mainType & (AudioRoutesInfo.MAIN_HEADSET
|
||||||
|
| AudioRoutesInfo.MAIN_HEADPHONES | AudioRoutesInfo.MAIN_USB)) != 0) {
|
||||||
|
forceUseDefaultRoute = true;
|
||||||
|
}
|
||||||
audioRoutesChanged = true;
|
audioRoutesChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TextUtils.equals(newRoutes.bluetoothName, mCurAudioRoutesInfo.bluetoothName)) {
|
if (!TextUtils.equals(newRoutes.bluetoothName, mCurAudioRoutesInfo.bluetoothName)) {
|
||||||
|
forceUseDefaultRoute = false;
|
||||||
mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName;
|
mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName;
|
||||||
if (mCurAudioRoutesInfo.bluetoothName != null) {
|
if (mCurAudioRoutesInfo.bluetoothName != null) {
|
||||||
if (mBluetoothA2dpRoute == null) {
|
if (mBluetoothA2dpRoute == null) {
|
||||||
@@ -231,30 +239,18 @@ public class MediaRouter {
|
|||||||
Log.v(TAG, "Audio routes updated: " + newRoutes + ", a2dp=" + isBluetoothA2dpOn());
|
Log.v(TAG, "Audio routes updated: " + newRoutes + ", a2dp=" + isBluetoothA2dpOn());
|
||||||
if (mSelectedRoute == null || mSelectedRoute == mDefaultAudioVideo
|
if (mSelectedRoute == null || mSelectedRoute == mDefaultAudioVideo
|
||||||
|| mSelectedRoute == mBluetoothA2dpRoute) {
|
|| mSelectedRoute == mBluetoothA2dpRoute) {
|
||||||
selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, getDefaultSystemAudioRoute(), false);
|
if (forceUseDefaultRoute || mBluetoothA2dpRoute == null) {
|
||||||
|
selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mDefaultAudioVideo, false);
|
||||||
|
} else {
|
||||||
|
selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mBluetoothA2dpRoute, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RouteInfo getDefaultSystemAudioRoute() {
|
|
||||||
boolean globalBluetoothA2doOn = false;
|
|
||||||
try {
|
|
||||||
globalBluetoothA2doOn = mMediaRouterService.isGlobalBluetoothA2doOn();
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
Log.e(TAG, "Unable to call isSystemBluetoothA2doOn.", ex);
|
|
||||||
}
|
|
||||||
return (globalBluetoothA2doOn && mBluetoothA2dpRoute != null)
|
|
||||||
? mBluetoothA2dpRoute : mDefaultAudioVideo;
|
|
||||||
}
|
|
||||||
|
|
||||||
RouteInfo getCurrentSystemAudioRoute() {
|
|
||||||
return (isBluetoothA2dpOn() && mBluetoothA2dpRoute != null)
|
|
||||||
? mBluetoothA2dpRoute : mDefaultAudioVideo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isBluetoothA2dpOn() {
|
boolean isBluetoothA2dpOn() {
|
||||||
try {
|
try {
|
||||||
return mAudioService.isBluetoothA2dpOn();
|
return mBluetoothA2dpRoute != null && 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);
|
||||||
return false;
|
return false;
|
||||||
@@ -608,6 +604,7 @@ public class MediaRouter {
|
|||||||
|| mSelectedRoute == null) {
|
|| mSelectedRoute == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Log.v(TAG, "onRestoreRoute() : a2dp=" + isBluetoothA2dpOn());
|
||||||
mSelectedRoute.select();
|
mSelectedRoute.select();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -940,10 +937,12 @@ public class MediaRouter {
|
|||||||
Log.v(TAG, "Selecting route: " + route);
|
Log.v(TAG, "Selecting route: " + route);
|
||||||
assert(route != null);
|
assert(route != null);
|
||||||
final RouteInfo oldRoute = sStatic.mSelectedRoute;
|
final RouteInfo oldRoute = sStatic.mSelectedRoute;
|
||||||
|
final RouteInfo currentSystemRoute = sStatic.isBluetoothA2dpOn()
|
||||||
|
? sStatic.mBluetoothA2dpRoute : sStatic.mDefaultAudioVideo;
|
||||||
boolean wasDefaultOrBluetoothRoute = (oldRoute == sStatic.mDefaultAudioVideo
|
boolean wasDefaultOrBluetoothRoute = (oldRoute == sStatic.mDefaultAudioVideo
|
||||||
|| oldRoute == sStatic.mBluetoothA2dpRoute);
|
|| oldRoute == sStatic.mBluetoothA2dpRoute);
|
||||||
if (oldRoute == route
|
if (oldRoute == route
|
||||||
&& (!wasDefaultOrBluetoothRoute || route == sStatic.getCurrentSystemAudioRoute())) {
|
&& (!wasDefaultOrBluetoothRoute || route == currentSystemRoute)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!route.matchesTypes(types)) {
|
if (!route.matchesTypes(types)) {
|
||||||
@@ -1014,8 +1013,7 @@ public class MediaRouter {
|
|||||||
|
|
||||||
static void selectDefaultRouteStatic() {
|
static void selectDefaultRouteStatic() {
|
||||||
// TODO: Be smarter about the route types here; this selects for all valid.
|
// TODO: Be smarter about the route types here; this selects for all valid.
|
||||||
if (sStatic.mSelectedRoute != sStatic.mBluetoothA2dpRoute
|
if (sStatic.mSelectedRoute != sStatic.mBluetoothA2dpRoute && sStatic.isBluetoothA2dpOn()) {
|
||||||
&& sStatic.mBluetoothA2dpRoute != null && sStatic.isBluetoothA2dpOn()) {
|
|
||||||
selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mBluetoothA2dpRoute, false);
|
selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mBluetoothA2dpRoute, false);
|
||||||
} else {
|
} else {
|
||||||
selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mDefaultAudioVideo, false);
|
selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mDefaultAudioVideo, false);
|
||||||
|
|||||||
@@ -269,14 +269,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binder call
|
|
||||||
@Override
|
|
||||||
public boolean isGlobalBluetoothA2doOn() {
|
|
||||||
synchronized (mLock) {
|
|
||||||
return mGlobalBluetoothA2dpOn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Binder call
|
// Binder call
|
||||||
@Override
|
@Override
|
||||||
public void setDiscoveryRequest(IMediaRouterClient client,
|
public void setDiscoveryRequest(IMediaRouterClient client,
|
||||||
@@ -383,7 +375,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
a2dpOn = mGlobalBluetoothA2dpOn;
|
a2dpOn = mGlobalBluetoothA2dpOn;
|
||||||
}
|
}
|
||||||
Slog.v(TAG, "restoreBluetoothA2dp( " + a2dpOn + ")");
|
Slog.v(TAG, "restoreBluetoothA2dp(" + a2dpOn + ")");
|
||||||
mAudioService.setBluetoothA2dpOn(a2dpOn);
|
mAudioService.setBluetoothA2dpOn(a2dpOn);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.w(TAG, "RemoteException while calling setBluetoothA2dpOn.");
|
Slog.w(TAG, "RemoteException while calling setBluetoothA2dpOn.");
|
||||||
|
|||||||
Reference in New Issue
Block a user