Reset app routes when global a2dp state changed
Bug: 156549746 Test: manual Change-Id: I8985136220c9cb96bd4da013653a69f12bfbb6b1
This commit is contained in:
@@ -23,4 +23,5 @@ oneway interface IMediaRouterClient {
|
||||
void onStateChanged();
|
||||
void onRestoreRoute();
|
||||
void onSelectedRouteChanged(String routeId);
|
||||
void onGlobalA2dpChanged(boolean a2dpOn);
|
||||
}
|
||||
|
||||
@@ -621,33 +621,27 @@ public class MediaRouter {
|
||||
final class Client extends IMediaRouterClient.Stub {
|
||||
@Override
|
||||
public void onStateChanged() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (Client.this == mClient) {
|
||||
updateClientState();
|
||||
}
|
||||
mHandler.post(() -> {
|
||||
if (Client.this == mClient) {
|
||||
updateClientState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreRoute() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Skip restoring route if the selected route is not a system audio route,
|
||||
// MediaRouter is initializing, or mClient was changed.
|
||||
if (Client.this != mClient || mSelectedRoute == null
|
||||
|| (mSelectedRoute != mDefaultAudioVideo
|
||||
&& mSelectedRoute != mBluetoothA2dpRoute)) {
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onRestoreRoute() : route=" + mSelectedRoute);
|
||||
}
|
||||
mSelectedRoute.select();
|
||||
mHandler.post(() -> {
|
||||
// Skip restoring route if the selected route is not a system audio route,
|
||||
// MediaRouter is initializing, or mClient was changed.
|
||||
if (Client.this != mClient || mSelectedRoute == null
|
||||
|| (mSelectedRoute != mDefaultAudioVideo
|
||||
&& mSelectedRoute != mBluetoothA2dpRoute)) {
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onRestoreRoute() : route=" + mSelectedRoute);
|
||||
}
|
||||
mSelectedRoute.select();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -659,6 +653,19 @@ public class MediaRouter {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Called when the selection of a connected device (phone speaker or BT devices)
|
||||
// is changed.
|
||||
@Override
|
||||
public void onGlobalA2dpChanged(boolean a2dpOn) {
|
||||
mHandler.post(() -> {
|
||||
if (mSelectedRoute == mDefaultAudioVideo && a2dpOn) {
|
||||
setSelectedRoute(mBluetoothA2dpRoute, false);
|
||||
} else if (mSelectedRoute == mBluetoothA2dpRoute && !a2dpOn) {
|
||||
setSelectedRoute(mDefaultAudioVideo, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -891,8 +891,24 @@ public final class MediaRouterService extends IMediaRouterService.Stub
|
||||
if (intent.getAction().equals(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED)) {
|
||||
BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
synchronized (mLock) {
|
||||
boolean wasA2dpOn = mGlobalBluetoothA2dpOn;
|
||||
mActiveBluetoothDevice = btDevice;
|
||||
mGlobalBluetoothA2dpOn = btDevice != null;
|
||||
if (wasA2dpOn != mGlobalBluetoothA2dpOn) {
|
||||
UserRecord userRecord = mUserRecords.get(mCurrentUserId);
|
||||
if (userRecord != null) {
|
||||
for (ClientRecord cr : userRecord.mClientRecords) {
|
||||
// mSelectedRouteId will be null for BT and phone speaker.
|
||||
if (cr.mSelectedRouteId == null) {
|
||||
try {
|
||||
cr.mClient.onGlobalA2dpChanged(mGlobalBluetoothA2dpOn);
|
||||
} catch (RemoteException e) {
|
||||
// Ignore exception
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user