Merge "Reset app routes when global a2dp state changed" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
70b9d348eb
@@ -23,4 +23,5 @@ oneway interface IMediaRouterClient {
|
|||||||
void onStateChanged();
|
void onStateChanged();
|
||||||
void onRestoreRoute();
|
void onRestoreRoute();
|
||||||
void onSelectedRouteChanged(String routeId);
|
void onSelectedRouteChanged(String routeId);
|
||||||
|
void onGlobalA2dpChanged(boolean a2dpOn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -621,21 +621,16 @@ public class MediaRouter {
|
|||||||
final class Client extends IMediaRouterClient.Stub {
|
final class Client extends IMediaRouterClient.Stub {
|
||||||
@Override
|
@Override
|
||||||
public void onStateChanged() {
|
public void onStateChanged() {
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (Client.this == mClient) {
|
if (Client.this == mClient) {
|
||||||
updateClientState();
|
updateClientState();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRestoreRoute() {
|
public void onRestoreRoute() {
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Skip restoring route if the selected route is not a system audio route,
|
// Skip restoring route if the selected route is not a system audio route,
|
||||||
// MediaRouter is initializing, or mClient was changed.
|
// MediaRouter is initializing, or mClient was changed.
|
||||||
if (Client.this != mClient || mSelectedRoute == null
|
if (Client.this != mClient || mSelectedRoute == null
|
||||||
@@ -647,7 +642,6 @@ public class MediaRouter {
|
|||||||
Log.d(TAG, "onRestoreRoute() : route=" + mSelectedRoute);
|
Log.d(TAG, "onRestoreRoute() : route=" + mSelectedRoute);
|
||||||
}
|
}
|
||||||
mSelectedRoute.select();
|
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)) {
|
if (intent.getAction().equals(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED)) {
|
||||||
BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
|
boolean wasA2dpOn = mGlobalBluetoothA2dpOn;
|
||||||
mActiveBluetoothDevice = btDevice;
|
mActiveBluetoothDevice = btDevice;
|
||||||
mGlobalBluetoothA2dpOn = btDevice != null;
|
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