Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70b9d348 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Reset app routes when global a2dp state changed" into rvc-dev

parents 49ded461 07e40316
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23,4 +23,5 @@ oneway interface IMediaRouterClient {
    void onStateChanged();
    void onRestoreRoute();
    void onSelectedRouteChanged(String routeId);
    void onGlobalA2dpChanged(boolean a2dpOn);
}
+27 −20
Original line number Diff line number Diff line
@@ -621,21 +621,16 @@ public class MediaRouter {
        final class Client extends IMediaRouterClient.Stub {
            @Override
            public void onStateChanged() {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                mHandler.post(() -> {
                    if (Client.this == mClient) {
                        updateClientState();
                    }
                    }
                });
            }

            @Override
            public void onRestoreRoute() {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                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
@@ -647,7 +642,6 @@ public class MediaRouter {
                        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);
                    }
                });
            }
        }
    }

+16 −0
Original line number Diff line number Diff line
@@ -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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }