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

Commit a8a1e989 authored by Sungsoo Lim's avatar Sungsoo Lim Committed by android-build-merger
Browse files

Merge "Select correct system audio route in updateAudioRoutes" into oc-mr1-dev

am: 43d5d86c

Change-Id: I5bab35f229bbedeba548a43e078a500f5cd2a4b0
parents 28eec9e4 43d5d86c
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ interface IMediaRouterService {

    MediaRouterClientState getState(IMediaRouterClient client);
    boolean isPlaybackActive(IMediaRouterClient client);
    boolean isGlobalBluetoothA2doOn();

    void setDiscoveryRequest(IMediaRouterClient client, int routeTypes, boolean activeScan);
    void setSelectedRoute(IMediaRouterClient client, String routeId, boolean explicit);
+23 −25
Original line number Diff line number Diff line
@@ -184,6 +184,8 @@ public class MediaRouter {

        void updateAudioRoutes(AudioRoutesInfo newRoutes) {
            boolean audioRoutesChanged = false;
            boolean forceUseDefaultRoute = false;

            if (newRoutes.mainType != mCurAudioRoutesInfo.mainType) {
                mCurAudioRoutesInfo.mainType = newRoutes.mainType;
                int name;
@@ -199,10 +201,16 @@ public class MediaRouter {
                }
                mDefaultAudioVideo.mNameResId = name;
                dispatchRouteChanged(mDefaultAudioVideo);

                if ((newRoutes.mainType & (AudioRoutesInfo.MAIN_HEADSET
                        | AudioRoutesInfo.MAIN_HEADPHONES | AudioRoutesInfo.MAIN_USB)) != 0) {
                    forceUseDefaultRoute = true;
                }
                audioRoutesChanged = true;
            }

            if (!TextUtils.equals(newRoutes.bluetoothName, mCurAudioRoutesInfo.bluetoothName)) {
                forceUseDefaultRoute = false;
                mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName;
                if (mCurAudioRoutesInfo.bluetoothName != null) {
                    if (mBluetoothA2dpRoute == null) {
@@ -231,30 +239,18 @@ public class MediaRouter {
                Log.v(TAG, "Audio routes updated: " + newRoutes + ", a2dp=" + isBluetoothA2dpOn());
                if (mSelectedRoute == null || mSelectedRoute == mDefaultAudioVideo
                        || 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() {
            try {
                return mAudioService.isBluetoothA2dpOn();
                return mBluetoothA2dpRoute != null && mAudioService.isBluetoothA2dpOn();
            } catch (RemoteException e) {
                Log.e(TAG, "Error querying Bluetooth A2DP state", e);
                return false;
@@ -608,6 +604,7 @@ public class MediaRouter {
                        || mSelectedRoute == null) {
                    return;
                }
                Log.v(TAG, "onRestoreRoute() : a2dp=" + isBluetoothA2dpOn());
                mSelectedRoute.select();
            }
        }
@@ -940,10 +937,12 @@ public class MediaRouter {
        Log.v(TAG, "Selecting route: " + route);
        assert(route != null);
        final RouteInfo oldRoute = sStatic.mSelectedRoute;
        final RouteInfo currentSystemRoute = sStatic.isBluetoothA2dpOn()
                ? sStatic.mBluetoothA2dpRoute : sStatic.mDefaultAudioVideo;
        boolean wasDefaultOrBluetoothRoute = (oldRoute == sStatic.mDefaultAudioVideo
                || oldRoute == sStatic.mBluetoothA2dpRoute);
        if (oldRoute == route
                && (!wasDefaultOrBluetoothRoute || route == sStatic.getCurrentSystemAudioRoute())) {
                && (!wasDefaultOrBluetoothRoute || route == currentSystemRoute)) {
            return;
        }
        if (!route.matchesTypes(types)) {
@@ -1014,8 +1013,7 @@ public class MediaRouter {

    static void selectDefaultRouteStatic() {
        // TODO: Be smarter about the route types here; this selects for all valid.
        if (sStatic.mSelectedRoute != sStatic.mBluetoothA2dpRoute
                && sStatic.mBluetoothA2dpRoute != null && sStatic.isBluetoothA2dpOn()) {
        if (sStatic.mSelectedRoute != sStatic.mBluetoothA2dpRoute && sStatic.isBluetoothA2dpOn()) {
            selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mBluetoothA2dpRoute, false);
        } else {
            selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mDefaultAudioVideo, false);
+1 −9
Original line number Diff line number Diff line
@@ -269,14 +269,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
        }
    }

    // Binder call
    @Override
    public boolean isGlobalBluetoothA2doOn() {
        synchronized (mLock) {
            return mGlobalBluetoothA2dpOn;
        }
    }

    // Binder call
    @Override
    public void setDiscoveryRequest(IMediaRouterClient client,