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

Commit 40c60527 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Support communication device APIs for TYPE_BUS

Audio fwk team has agreed to allow list TYPE_BUS as a valid
communication device. Modify the existing code so that TYPE_BUS uses the
set/clear communication device logic and ensure that retrieval of the
audio route is done via AudioManager#getAvailableCommunicationDevices.

Bug: 365612739
Bug: 367798741
Test: atest CallAudioRouteControllerTest
Test: atest ExtendedInCallServiceTest#testSwitchCallEndpoint
Flag: com.android.server.telecom.flags.use_refactored_audio_route_switching
Change-Id: I920c45e9e22b4489c6cae5d88ff39689be0ab75f
parent 63705494
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -251,10 +251,6 @@ public class AudioRoute {
            BluetoothRouteManager bluetoothRouteManager, boolean isScoAudioConnected) {
        Log.i(this, "onDestRouteAsPendingRoute: active (%b), type (%s)", active,
                DEVICE_TYPE_STRINGS.get(mAudioRouteType));
        if (mAudioRouteType == TYPE_BUS) {
            Log.i(this, "onDestRouteAsPendingRoute: Ignore processing dest route for TYPE_BUS");
            return;
        }
        if (pendingAudioRoute.isActive() && !active) {
            clearCommunicationDevice(pendingAudioRoute, bluetoothRouteManager, audioManager);
        } else if (active) {
@@ -316,10 +312,6 @@ public class AudioRoute {
    void onOrigRouteAsPendingRoute(boolean active, PendingAudioRoute pendingAudioRoute,
            AudioManager audioManager, BluetoothRouteManager bluetoothRouteManager) {
        Log.i(this, "onOrigRouteAsPendingRoute: active (%b), type (%d)", active, mAudioRouteType);
        if (mAudioRouteType == TYPE_BUS) {
            Log.i(this, "onOrigRouteAsPendingRoute: Ignore processing dest route for TYPE_BUS");
            return;
        }
        if (active) {
            if (mAudioRouteType == TYPE_SPEAKER) {
                pendingAudioRoute.addMessage(SPEAKER_OFF, null);
+10 −28
Original line number Diff line number Diff line
@@ -357,18 +357,19 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
            // Create speaker routes
            mSpeakerDockRoute = mAudioRouteFactory.create(AudioRoute.TYPE_SPEAKER, null,
                    mAudioManager);
            // Todo(b/364562758): Represent TYPE_BUS as CallAudioState.ROUTE_SPEAKER (moving
            // forward, we may rework this if audio fwk team decides to allow list this as a
            // valid communication device.
            if (mSpeakerDockRoute != null || hasBusAudioDevice()) {
            if (mSpeakerDockRoute == null){
                    mSpeakerDockRoute = new AudioRoute(AudioRoute.TYPE_BUS, null, null);
                Log.i(this, "Can't find available audio device info for route TYPE_SPEAKER, trying"
                        + " for TYPE_BUS");
                mSpeakerDockRoute = mAudioRouteFactory.create(AudioRoute.TYPE_BUS, null,
                        mAudioManager);
                audioRouteType = AudioRoute.TYPE_BUS;
            }
            if (mSpeakerDockRoute != null) {
                mTypeRoutes.put(audioRouteType, mSpeakerDockRoute);
                updateAvailableRoutes(mSpeakerDockRoute, true);
            } else {
                Log.w(this, "Can't find available audio device info for route TYPE_SPEAKER");
                Log.w(this, "Can't find available audio device info for route TYPE_SPEAKER "
                        + "or TYPE_BUS.");
            }
        }

@@ -1129,25 +1130,6 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
        return mAudioManager.getPreferredDeviceForStrategy(strategy);
    }

    /**
     * For auto, there is no earpiece or speakerphone routes available. The audio is routed to the
     * bus but because this isn't a valid communication device,
     * {@link AudioManager#getCommunicationDevice()} will not provide this device even if audio fwk
     * reports it as the active communication device (refer to
     * AudioDeviceBroker#getCommunicationDeviceInt()}. Check if the device is the preferred device
     * for strategy instead.
     */
    private boolean hasBusAudioDevice() {
        AudioDeviceAttributes deviceAttr = getPreferredDeviceForStrategy();
        if (deviceAttr == null) {
            return false;
        }
        // Get corresponding audio route mapping
        @AudioRoute.AudioRouteType int type = AudioRoute.DEVICE_INFO_TYPE_TO_AUDIO_ROUTE_TYPE.get(
                deviceAttr.getType());
        return type == AudioRoute.TYPE_BUS;
    }

    private AudioRoute getPreferredAudioRouteFromDefault(boolean includeBluetooth,
            String btAddressToExclude) {
        boolean skipEarpiece;