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

Commit 0da5fa4d authored by Bryce Lee's avatar Bryce Lee
Browse files

DO NOT MERGE ANYWHERE

Handle audio route restrictions set on calls.

When a call restricts audio routes, it will move the audio route to a
supported route if available. The supported routes are determined initially
and re-evaluated when the call becomes the foreground call.

Bug: 25485578
Change-Id: I54b9bf17495eb2b0dc73b822ad16485a4673a779
parent 6d962524
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -296,6 +296,8 @@ public class Call implements CreateConnectionResponse {

    private int mConnectionCapabilities;

    private int mSupportedAudioRoutes;

    private boolean mIsConference = false;

    private Call mParentCall = null;
@@ -808,6 +810,16 @@ public class Call implements CreateConnectionResponse {
        }
    }

    int getSupportedAudioRoutes() {
        return mSupportedAudioRoutes;
    }

    void setSupportedAudioRoutes(int audioRoutes) {
        if (mSupportedAudioRoutes != audioRoutes) {
            mSupportedAudioRoutes = audioRoutes;
        }
    }

    Call getParentCall() {
        return mParentCall;
    }
@@ -911,6 +923,7 @@ public class Call implements CreateConnectionResponse {
        setCallerDisplayName(
                connection.getCallerDisplayName(), connection.getCallerDisplayNamePresentation());
        setConnectionCapabilities(connection.getConnectionCapabilities());
        setSupportedAudioRoutes(connection.getSupportedAudioRoutes());
        setVideoProvider(connection.getVideoProvider());
        setVideoState(connection.getVideoState());
        setRingbackRequested(connection.isRingbackRequested());
+26 −2
Original line number Diff line number Diff line
@@ -253,6 +253,12 @@ final class CallAudioManager extends CallsManagerListenerBase
    @Override
    public void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall) {
        onCallUpdated(newForegroundCall);

        // Set the system audio state again in case the current route is not permitted by the new
        // foreground call.
        setSystemAudioState(mCallAudioState.isMuted(), mCallAudioState.getRoute(),
                calculateSupportedRoutes(newForegroundCall));

        // Ensure that the foreground call knows about the latest audio state.
        updateAudioForForegroundCall();
    }
@@ -472,6 +478,20 @@ final class CallAudioManager extends CallsManagerListenerBase
        }

        CallAudioState oldAudioState = mCallAudioState;

        // If the currently selected route is not supported, switch to another supported route
        if ((route & supportedRouteMask) == 0) {
            if ((CallAudioState.ROUTE_EARPIECE & supportedRouteMask) != 0) {
                route = CallAudioState.ROUTE_EARPIECE;
            } else if ((CallAudioState.ROUTE_WIRED_HEADSET & supportedRouteMask) != 0) {
                route = CallAudioState.ROUTE_WIRED_HEADSET;
            } else if ((CallAudioState.ROUTE_SPEAKER & supportedRouteMask) != 0) {
                route = CallAudioState.ROUTE_SPEAKER;
            } else if ((CallAudioState.ROUTE_BLUETOOTH & supportedRouteMask) != 0) {
                route = CallAudioState.ROUTE_BLUETOOTH;
            }
        }

        saveAudioState(new CallAudioState(isMuted, route, supportedRouteMask));
        if (!force && Objects.equals(oldAudioState, mCallAudioState)) {
            return;
@@ -645,6 +665,10 @@ final class CallAudioManager extends CallsManagerListenerBase
    }

    private int calculateSupportedRoutes() {
        return calculateSupportedRoutes(getForegroundCall());
    }

    private int calculateSupportedRoutes(Call call) {
        int routeMask = CallAudioState.ROUTE_SPEAKER;

        if (mWiredHeadsetManager.isPluggedIn()) {
@@ -657,11 +681,11 @@ final class CallAudioManager extends CallsManagerListenerBase
            routeMask |=  CallAudioState.ROUTE_BLUETOOTH;
        }

        return routeMask;
        return call != null ? routeMask & call.getSupportedAudioRoutes() : routeMask;
    }

    private CallAudioState getInitialAudioState(Call call) {
        int supportedRouteMask = calculateSupportedRoutes();
        int supportedRouteMask = calculateSupportedRoutes(call);
        int route = selectWiredOrEarpiece(
                CallAudioState.ROUTE_WIRED_OR_EARPIECE, supportedRouteMask);

+3 −0
Original line number Diff line number Diff line
@@ -590,6 +590,8 @@ public final class InCallController extends CallsManagerListenerBase {
        int state = getParcelableState(call);
        int capabilities = convertConnectionToCallCapabilities(call.getConnectionCapabilities());
        int properties = convertConnectionToCallProperties(call.getConnectionCapabilities());
        int supportedAudioRoutes = call.getSupportedAudioRoutes();

        if (call.isConference()) {
            properties |= android.telecom.Call.Details.PROPERTY_CONFERENCE;
        }
@@ -659,6 +661,7 @@ public final class InCallController extends CallsManagerListenerBase {
                call.getCannedSmsResponses(),
                capabilities,
                properties,
                supportedAudioRoutes,
                connectTimeMillis,
                handle,
                call.getHandlePresentation(),
+16 −2
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.telecom.CallAudioState;
import android.telecom.ConnectionService;
import android.telecom.DefaultDialerManager;
import android.telecom.PhoneAccount;
@@ -121,7 +122,7 @@ public final class PhoneAccountRegistrar {

    private static final String FILE_NAME = "phone-account-registrar-state.xml";
    @VisibleForTesting
    public static final int EXPECTED_STATE_VERSION = 8;
    public static final int EXPECTED_STATE_VERSION = 9;

    /** Keep in sync with the same in SipSettings.java */
    private static final String SIP_SHARED_PREFERENCES = "SIP_PREFERENCES";
@@ -1147,6 +1148,7 @@ public final class PhoneAccountRegistrar {
        private static final String ADDRESS = "handle";
        private static final String SUBSCRIPTION_ADDRESS = "subscription_number";
        private static final String CAPABILITIES = "capabilities";
        private static final String SUPPORTED_AUDIO_ROUTES = "supported_audio_routes";
        private static final String ICON_RES_ID = "icon_res_id";
        private static final String ICON_PACKAGE_NAME = "icon_package_name";
        private static final String ICON_BITMAP = "icon_bitmap";
@@ -1180,6 +1182,8 @@ public final class PhoneAccountRegistrar {
                writeTextIfNonNull(SHORT_DESCRIPTION, o.getShortDescription(), serializer);
                writeStringList(SUPPORTED_URI_SCHEMES, o.getSupportedUriSchemes(), serializer);
                writeTextIfNonNull(ENABLED, o.isEnabled() ? "true" : "false", serializer);
                writeTextIfNonNull(SUPPORTED_AUDIO_ROUTES, Integer.toString(
                                o.getSupportedAudioRoutes()), serializer);

                serializer.endTag(null, CLASS_PHONE_ACCOUNT);
            }
@@ -1193,6 +1197,7 @@ public final class PhoneAccountRegistrar {
                Uri address = null;
                Uri subscriptionAddress = null;
                int capabilities = 0;
                int supportedAudioRoutes = 0;
                int iconResId = PhoneAccount.NO_RESOURCE_ID;
                String iconPackageName = null;
                Bitmap iconBitmap = null;
@@ -1248,6 +1253,9 @@ public final class PhoneAccountRegistrar {
                    } else if (parser.getName().equals(ENABLED)) {
                        parser.next();
                        enabled = "true".equalsIgnoreCase(parser.getText());
                    } else if (parser.getName().equals(SUPPORTED_AUDIO_ROUTES)) {
                        parser.next();
                        supportedAudioRoutes = Integer.parseInt(parser.getText());
                    }
                }

@@ -1306,10 +1314,16 @@ public final class PhoneAccountRegistrar {
                    }
                }

                if (version < 9) {
                    // Set supported audio routes to all by default
                    supportedAudioRoutes = CallAudioState.ROUTE_ALL;
                }

                PhoneAccount.Builder builder = PhoneAccount.builder(accountHandle, label)
                        .setAddress(address)
                        .setSubscriptionAddress(subscriptionAddress)
                        .setCapabilities(capabilities)
                        .setSupportedAudioRoutes(supportedAudioRoutes)
                        .setShortDescription(shortDescription)
                        .setSupportedUriSchemes(supportedUriSchemes)
                        .setHighlightColor(highlightColor)
+2 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ public class ConnectionServiceFixture implements TestFixture<IConnectionService>
        int state;
        int addressPresentation;
        int capabilities;
        int supportedAudioRoutes;
        StatusHints statusHints;
        DisconnectCause disconnectCause;
        String conferenceId;
@@ -395,6 +396,7 @@ public class ConnectionServiceFixture implements TestFixture<IConnectionService>
                c.request.getAccountHandle(),
                c.state,
                c.capabilities,
                c.supportedAudioRoutes,
                c.request.getAddress(),
                c.addressPresentation,
                c.callerDisplayName,