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

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

Merge "Revert "Implement new external audio route."" into tm-dev

parents 9e89612f dcb98c82
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
@@ -156,7 +156,6 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        void onCallSwitchFailed(Call call);
        void onConnectionEvent(Call call, String event, Bundle extras);
        void onExternalCallChanged(Call call, boolean isExternalCall);
        void onTetheredCallChanged(Call call, boolean isTetheredCall);
        void onRttInitiationFailure(Call call, int reason);
        void onRemoteRttRequest(Call call, int requestId);
        void onHandoverRequested(Call call, PhoneAccountHandle handoverTo, int videoState,
@@ -243,10 +242,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        @Override
        public void onConnectionEvent(Call call, String event, Bundle extras) {}
        @Override
        public void onExternalCallChanged(Call call, boolean isExternalCall)
        {}
        @Override
        public void onTetheredCallChanged(Call call, boolean isTetheredCall) {}
        public void onExternalCallChanged(Call call, boolean isExternalCall) {}
        @Override
        public void onRttInitiationFailure(Call call, int reason) {}
        @Override
@@ -1920,7 +1916,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
        return stripUnsupportedCapabilities(mConnectionCapabilities);
    }

    public int getConnectionProperties() {
    int getConnectionProperties() {
        return mConnectionProperties;
    }

@@ -2019,12 +2015,8 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                    == Connection.PROPERTY_IS_EXTERNAL_CALL;
            boolean isExternal = (connectionProperties & Connection.PROPERTY_IS_EXTERNAL_CALL)
                    == Connection.PROPERTY_IS_EXTERNAL_CALL;
            boolean wasTethered = (previousProperties & Connection.PROPERTY_TETHERED_CALL)
                    == Connection.PROPERTY_TETHERED_CALL;
            boolean isTethered = (connectionProperties & Connection.PROPERTY_TETHERED_CALL)
                    == Connection.PROPERTY_TETHERED_CALL;
            if (wasExternal != isExternal) {
                Log.v(this, "setConnectionProperties: external call changed isExternal = %b, ",
                Log.v(this, "setConnectionProperties: external call changed isExternal = %b",
                        isExternal);
                Log.addEvent(this, LogUtils.Events.IS_EXTERNAL, isExternal);
                if (isExternal) {
@@ -2037,14 +2029,6 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
                    l.onExternalCallChanged(this, isExternal);
                }
            }
            if (wasTethered != isTethered) {
                Log.v(this, "setConnectionProperties: tethered call changed isTethered = %b, ",
                        isTethered);
                Log.addEvent(this, LogUtils.Events.IS_TETHERED, isTethered);
                for (Listener l : mListeners) {
                    l.onTetheredCallChanged(this, isTethered);
                }
            }

            boolean wasDowngradedConference =
                    (previousProperties & Connection.PROPERTY_IS_DOWNGRADED_CONFERENCE) != 0;
+13 −43
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ public class CallAudioManager extends CallsManagerListenerBase {
    private final LinkedHashSet<Call> mRingingCalls;
    private final LinkedHashSet<Call> mHoldingCalls;
    private final LinkedHashSet<Call> mAudioProcessingCalls;
    private final LinkedHashSet<Call> mTetheredCalls;
    private final Set<Call> mCalls;
    private final SparseArray<LinkedHashSet<Call>> mCallStateToCalls;

@@ -76,7 +75,6 @@ public class CallAudioManager extends CallsManagerListenerBase {
        mRingingCalls = new LinkedHashSet<>(1);
        mHoldingCalls = new LinkedHashSet<>(1);
        mAudioProcessingCalls = new LinkedHashSet<>(1);
        mTetheredCalls = new LinkedHashSet<>(1);
        mCalls = new HashSet<>();
        mCallStateToCalls = new SparseArray<LinkedHashSet<Call>>() {{
            put(CallState.CONNECTING, mActiveDialingOrConnectingCalls);
@@ -192,25 +190,23 @@ public class CallAudioManager extends CallsManagerListenerBase {
    /**
     * Handles changes to the external state of a call.  External calls which become regular calls
     * should be tracked, and regular calls which become external should no longer be tracked.
     *
     * @param call The call.
     * @param isExternalCall {@code True} if the call is now external, {@code false} if it is not
     * @param isExternalCall {@code True} if the call is now external, {@code false} if it is now
     *      a regular call.
     */
    @Override
    public void onExternalCallChanged(Call call, boolean isExternalCall) {
        Log.d(LOG_TAG, "Exit external route because call %s is no longer a tethered "
                + "external call.", call.getId());
        if (isExternalCall) {
            Log.d(LOG_TAG, "Removing call which became untethered external ID %s",
                    call.getId());
            Log.d(LOG_TAG, "Removing call which became external ID %s", call.getId());
            removeCall(call);
        } else {
        } else if (!isExternalCall) {
            Log.d(LOG_TAG, "Adding external call which was pulled with ID %s", call.getId());
            addCall(call);

            if (mCallsManager.isSpeakerphoneAutoEnabledForVideoCalls(call.getVideoState())) {
                // When pulling a video call, automatically enable the speakerphone.
                Log.d(LOG_TAG,
                        "Switching to speaker because external video call %s was pulled." +
                Log.d(LOG_TAG, "Switching to speaker because external video call %s was pulled." +
                        call.getId());
                mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                        CallAudioRouteStateMachine.SWITCH_SPEAKER);
@@ -218,31 +214,6 @@ public class CallAudioManager extends CallsManagerListenerBase {
        }
    }

    /**
     * Handles changes to the tethered state of a call.
     * @param call The call.
     * @param isTetheredCall {@code True} if the call is tethered call, {@code false} otherwise
     */
    @Override
    public void onTetheredCallChanged(Call call, boolean isTetheredCall) {
        if (isTetheredCall) {
            Log.d(LOG_TAG, "Switching to external route because call %s became tethered "
                    + " external call.", call.getId());
            removeCall(call);
            mTetheredCalls.add(call);
            mCallAudioModeStateMachine.sendMessageWithArgs(
                    CallAudioModeStateMachine.NEW_TETHERED_EXTERNAL_CALL,
                    makeArgsForModeStateMachine());
        } else {
            mTetheredCalls.remove(call);
            if (mTetheredCalls.size() == 0) {
                mCallAudioModeStateMachine.sendMessageWithArgs(
                        CallAudioModeStateMachine.NO_MORE_TETHERED_CALLS,
                        makeArgsForModeStateMachine());
            }
        }
    }

    /**
     * Determines if {@link CallAudioManager} should do any audio routing operations for a call.
     * We ignore child calls of a conference and external calls for audio routing purposes.
@@ -756,7 +727,6 @@ public class CallAudioManager extends CallsManagerListenerBase {
                .setHasHoldingCalls(mHoldingCalls.size() > 0)
                .setHasAudioProcessingCalls(mAudioProcessingCalls.size() > 0)
                .setIsTonePlaying(mIsTonePlaying)
                .setHasTetheredCalls(mTetheredCalls.size() > 0)
                .setForegroundCallIsVoip(
                        mForegroundCall != null && mForegroundCall.getIsVoipAudioMode())
                .setSession(Log.createSubsession()).build();
+7 −118
Original line number Diff line number Diff line
@@ -44,19 +44,17 @@ public class CallAudioModeStateMachine extends StateMachine {
        public boolean hasAudioProcessingCalls;
        public boolean isTonePlaying;
        public boolean foregroundCallIsVoip;
        public boolean hasTetheredCalls;
        public Session session;

        private MessageArgs(boolean hasActiveOrDialingCalls, boolean hasRingingCalls,
                boolean hasHoldingCalls, boolean hasAudioProcessingCalls, boolean isTonePlaying,
                boolean foregroundCallIsVoip, boolean hasTetheredCalls, Session session) {
                boolean foregroundCallIsVoip, Session session) {
            this.hasActiveOrDialingCalls = hasActiveOrDialingCalls;
            this.hasRingingCalls = hasRingingCalls;
            this.hasHoldingCalls = hasHoldingCalls;
            this.hasAudioProcessingCalls = hasAudioProcessingCalls;
            this.isTonePlaying = isTonePlaying;
            this.foregroundCallIsVoip = foregroundCallIsVoip;
            this.hasTetheredCalls = hasTetheredCalls;
            this.session = session;
        }

@@ -67,7 +65,6 @@ public class CallAudioModeStateMachine extends StateMachine {
                    ", hasRingingCalls=" + hasRingingCalls +
                    ", hasHoldingCalls=" + hasHoldingCalls +
                    ", hasAudioProcessingCalls=" + hasAudioProcessingCalls +
                    ", hasTetheredCalls=" + hasTetheredCalls +
                    ", isTonePlaying=" + isTonePlaying +
                    ", foregroundCallIsVoip=" + foregroundCallIsVoip +
                    ", session=" + session +
@@ -81,7 +78,6 @@ public class CallAudioModeStateMachine extends StateMachine {
            private boolean mHasAudioProcessingCalls;
            private boolean mIsTonePlaying;
            private boolean mForegroundCallIsVoip;
            private boolean mHasTetheredCalls;
            private Session mSession;

            public Builder setHasActiveOrDialingCalls(boolean hasActiveOrDialingCalls) {
@@ -114,11 +110,6 @@ public class CallAudioModeStateMachine extends StateMachine {
                return this;
            }

            public Builder setHasTetheredCalls(boolean hasTetheredCalls) {
                mHasTetheredCalls = hasTetheredCalls;
                return this;
            }

            public Builder setSession(Session session) {
                mSession = session;
                return this;
@@ -126,8 +117,7 @@ public class CallAudioModeStateMachine extends StateMachine {

            public MessageArgs build() {
                return new MessageArgs(mHasActiveOrDialingCalls, mHasRingingCalls, mHasHoldingCalls,
                        mHasAudioProcessingCalls, mIsTonePlaying, mForegroundCallIsVoip,
                        mHasTetheredCalls, mSession);
                        mHasAudioProcessingCalls, mIsTonePlaying, mForegroundCallIsVoip, mSession);
            }
        }
    }
@@ -142,20 +132,17 @@ public class CallAudioModeStateMachine extends StateMachine {
    public static final int ENTER_RING_FOCUS_FOR_TESTING = 4;
    public static final int ENTER_TONE_OR_HOLD_FOCUS_FOR_TESTING = 5;
    public static final int ENTER_AUDIO_PROCESSING_FOCUS_FOR_TESTING = 6;
    public static final int ENTER_TETHERED_EXTERNAL_FOR_TESTING = 7;
    public static final int ABANDON_FOCUS_FOR_TESTING = 8;
    public static final int ABANDON_FOCUS_FOR_TESTING = 7;

    public static final int NO_MORE_ACTIVE_OR_DIALING_CALLS = 1001;
    public static final int NO_MORE_RINGING_CALLS = 1002;
    public static final int NO_MORE_HOLDING_CALLS = 1003;
    public static final int NO_MORE_AUDIO_PROCESSING_CALLS = 1004;
    public static final int NO_MORE_TETHERED_CALLS = 1005;

    public static final int NEW_ACTIVE_OR_DIALING_CALL = 2001;
    public static final int NEW_RINGING_CALL = 2002;
    public static final int NEW_HOLDING_CALL = 2003;
    public static final int NEW_AUDIO_PROCESSING_CALL = 2004;
    public static final int NEW_TETHERED_EXTERNAL_CALL = 2005;

    public static final int TONE_STARTED_PLAYING = 3001;
    public static final int TONE_STOPPED_PLAYING = 3002;
@@ -176,18 +163,15 @@ public class CallAudioModeStateMachine extends StateMachine {
        put(ENTER_RING_FOCUS_FOR_TESTING, "ENTER_RING_FOCUS_FOR_TESTING");
        put(ENTER_AUDIO_PROCESSING_FOCUS_FOR_TESTING, "ENTER_AUDIO_PROCESSING_FOCUS_FOR_TESTING");
        put(ENTER_TONE_OR_HOLD_FOCUS_FOR_TESTING, "ENTER_TONE_OR_HOLD_FOCUS_FOR_TESTING");
        put(ENTER_TETHERED_EXTERNAL_FOR_TESTING, "ENTER_TETHERED_EXTERNAL_FOR_TESTING");
        put(ABANDON_FOCUS_FOR_TESTING, "ABANDON_FOCUS_FOR_TESTING");
        put(NO_MORE_ACTIVE_OR_DIALING_CALLS, "NO_MORE_ACTIVE_OR_DIALING_CALLS");
        put(NO_MORE_RINGING_CALLS, "NO_MORE_RINGING_CALLS");
        put(NO_MORE_HOLDING_CALLS, "NO_MORE_HOLDING_CALLS");
        put(NO_MORE_AUDIO_PROCESSING_CALLS, "NO_MORE_AUDIO_PROCESSING_CALLS");
        put(NO_MORE_TETHERED_CALLS, "NO_MORE_TETHERED_CALLS");
        put(NEW_ACTIVE_OR_DIALING_CALL, "NEW_ACTIVE_OR_DIALING_CALL");
        put(NEW_RINGING_CALL, "NEW_RINGING_CALL");
        put(NEW_HOLDING_CALL, "NEW_HOLDING_CALL");
        put(NEW_AUDIO_PROCESSING_CALL, "NEW_AUDIO_PROCESSING_CALL");
        put(NEW_TETHERED_EXTERNAL_CALL, "NEW_TETHERED_EXTERNAL_CALL");
        put(TONE_STARTED_PLAYING, "TONE_STARTED_PLAYING");
        put(TONE_STOPPED_PLAYING, "TONE_STOPPED_PLAYING");
        put(FOREGROUND_VOIP_MODE_CHANGE, "FOREGROUND_VOIP_MODE_CHANGE");
@@ -204,7 +188,6 @@ public class CallAudioModeStateMachine extends StateMachine {
    public static final String CALL_STATE_NAME = SimCallFocusState.class.getSimpleName();
    public static final String RING_STATE_NAME = RingingFocusState.class.getSimpleName();
    public static final String COMMS_STATE_NAME = VoipCallFocusState.class.getSimpleName();
    public static final String TETHERED_STATE_NAME = TetheredCallState.class.getSimpleName();

    private class BaseState extends State {
        @Override
@@ -225,9 +208,6 @@ public class CallAudioModeStateMachine extends StateMachine {
                case ENTER_AUDIO_PROCESSING_FOCUS_FOR_TESTING:
                    transitionTo(mAudioProcessingFocusState);
                    return HANDLED;
                case ENTER_TETHERED_EXTERNAL_FOR_TESTING:
                    transitionTo(mTetheredCallState);
                    return HANDLED;
                case ABANDON_FOCUS_FOR_TESTING:
                    transitionTo(mUnfocusedState);
                    return HANDLED;
@@ -251,6 +231,8 @@ public class CallAudioModeStateMachine extends StateMachine {
                mCallAudioManager.setCallAudioRouteFocusState(CallAudioRouteStateMachine.NO_FOCUS);
                mAudioManager.setMode(AudioManager.MODE_NORMAL);
                mMostRecentMode = AudioManager.MODE_NORMAL;
                // Don't release focus here -- wait until we get a signal that any other audio
                // operations triggered by this are done before releasing focus.
            }
        }

@@ -273,9 +255,6 @@ public class CallAudioModeStateMachine extends StateMachine {
                case NO_MORE_AUDIO_PROCESSING_CALLS:
                    // Do nothing.
                    return HANDLED;
                case NO_MORE_TETHERED_CALLS:
                    // Do nothing.
                    return HANDLED;
                case NEW_ACTIVE_OR_DIALING_CALL:
                    transitionTo(args.foregroundCallIsVoip
                            ? mVoipCallFocusState : mSimCallFocusState);
@@ -292,9 +271,6 @@ public class CallAudioModeStateMachine extends StateMachine {
                            " Args are: \n" + args.toString());
                    transitionTo(mOtherFocusState);
                    return HANDLED;
                case NEW_TETHERED_EXTERNAL_CALL:
                    transitionTo(mTetheredCallState);
                    return HANDLED;
                case TONE_STARTED_PLAYING:
                    // This shouldn't happen either, but perform the action anyway.
                    Log.w(LOG_TAG, "Tone started playing unexpectedly. Args are: \n"
@@ -344,9 +320,6 @@ public class CallAudioModeStateMachine extends StateMachine {
                    }
                    transitionTo(destState);
                    return HANDLED;
                case NO_MORE_TETHERED_CALLS:
                    // Do nothing.
                    return HANDLED;
                case NEW_ACTIVE_OR_DIALING_CALL:
                    transitionTo(args.foregroundCallIsVoip
                            ? mVoipCallFocusState : mSimCallFocusState);
@@ -363,9 +336,6 @@ public class CallAudioModeStateMachine extends StateMachine {
                case NEW_AUDIO_PROCESSING_CALL:
                    // Can happen as a duplicate message
                    return HANDLED;
                case NEW_TETHERED_EXTERNAL_CALL:
                    transitionTo(mTetheredCallState);
                    return HANDLED;
                case TONE_STARTED_PLAYING:
                    // This shouldn't happen either, but perform the action anyway.
                    Log.w(LOG_TAG, "Tone started playing unexpectedly. Args are: \n"
@@ -703,81 +673,6 @@ public class CallAudioModeStateMachine extends StateMachine {
        }
    }

    private class TetheredCallState extends BaseState {
        @Override
        public void enter() {
            Log.i(LOG_TAG, "Audio focus entering tethered external state");
            // TODO: change MODE_CALL_SCREENING to MODE_EXTERNAL when available
            mAudioManager.setMode(AudioManager.MODE_CALL_SCREENING);
            mMostRecentMode = AudioManager.MODE_NORMAL;
            mCallAudioManager.setCallAudioRouteFocusState(CallAudioRouteStateMachine.NO_FOCUS);
            mCallAudioManager.getCallAudioRouteStateMachine().sendMessageWithSessionInfo(
                    CallAudioRouteStateMachine.EXTERNAL_FORCE_ENABLED);
        }

        private void preExit() {
            mCallAudioManager.getCallAudioRouteStateMachine().sendMessageWithSessionInfo(
                    CallAudioRouteStateMachine.EXTERNAL_FORCE_DISABLED);
        }

        @Override
        public boolean processMessage(Message msg) {
            if (super.processMessage(msg) == HANDLED) {
                return HANDLED;
            }
            MessageArgs args = (MessageArgs) msg.obj;
            switch (msg.what) {
                case NO_MORE_ACTIVE_OR_DIALING_CALLS:
                    // Do nothing.
                    return HANDLED;
                case NO_MORE_RINGING_CALLS:
                    // Do nothing.
                    return HANDLED;
                case NO_MORE_HOLDING_CALLS:
                    // Do nothing.
                    return HANDLED;
                case NO_MORE_AUDIO_PROCESSING_CALLS:
                    // Do nothing.
                    return HANDLED;
                case NEW_ACTIVE_OR_DIALING_CALL:
                    BaseState destState = calculateProperStateFromArgs(args);
                    if (destState != this) {
                        preExit();
                        transitionTo(destState);
                    }
                    return HANDLED;
                case NEW_RINGING_CALL:
                    preExit();
                    transitionTo(mRingingFocusState);
                    return HANDLED;
                case NEW_HOLDING_CALL:
                    // This really shouldn't happen, but recalculate from args and do the transition
                    Log.w(LOG_TAG, "Call was surprisingly put into hold from an unknown state." +
                            " Args are: \n" + args.toString());
                    preExit();
                    transitionTo(mOtherFocusState);
                    return HANDLED;
                case NEW_AUDIO_PROCESSING_CALL:
                    // Do nothing.
                    return HANDLED;
                case NEW_TETHERED_EXTERNAL_CALL:
                    // Can happen as a duplicate message
                    return HANDLED;
                case TONE_STARTED_PLAYING:
                    // This shouldn't happen either, but perform the action anyway.
                    Log.w(LOG_TAG, "Tone started playing unexpectedly. Args are: \n"
                            + args.toString());
                    return HANDLED;
                case NO_MORE_TETHERED_CALLS:
                    transitionTo(calculateProperStateFromArgs(args));
                    return HANDLED;
                default:
                    // The forced focus switch commands are handled by BaseState.
                    return NOT_HANDLED;
            }
        }
    }

    private static final String LOG_TAG = CallAudioModeStateMachine.class.getSimpleName();

    private final BaseState mUnfocusedState = new UnfocusedState();
@@ -786,7 +681,6 @@ public class CallAudioModeStateMachine extends StateMachine {
    private final BaseState mVoipCallFocusState = new VoipCallFocusState();
    private final BaseState mAudioProcessingFocusState = new AudioProcessingFocusState();
    private final BaseState mOtherFocusState = new OtherFocusState();
    private final BaseState mTetheredCallState = new TetheredCallState();

    private final AudioManager mAudioManager;
    private final SystemStateHelper mSystemStateHelper;
@@ -825,7 +719,6 @@ public class CallAudioModeStateMachine extends StateMachine {
        addState(mVoipCallFocusState);
        addState(mAudioProcessingFocusState);
        addState(mOtherFocusState);
        addState(mTetheredCallState);
        setInitialState(mUnfocusedState);
        start();
        sendMessage(INITIALIZE, new MessageArgs.Builder()
@@ -834,7 +727,6 @@ public class CallAudioModeStateMachine extends StateMachine {
                .setHasHoldingCalls(false)
                .setIsTonePlaying(false)
                .setForegroundCallIsVoip(false)
                .setHasTetheredCalls(false)
                .setSession(Log.createSubsession())
                .build());
    }
@@ -881,15 +773,12 @@ public class CallAudioModeStateMachine extends StateMachine {
        // switch to the appropriate focus.
        // Otherwise abandon focus.

        // The order matters here. If there are tethered external calls, holding external route for
        // then takes priority. After that, holding focus for active calls takes priority.
        // The order matters here. If there are active calls, holding focus for them takes priority.
        // After that, we want to prioritize holding calls over ringing calls so that when a
        // call-waiting call gets answered, there's no transition in and out of the ringing focus
        // state. After that, we want tones since we actually hold focus during them, then the
        // audio processing state because that will release focus.
        if (args.hasTetheredCalls) {
            return mTetheredCallState;
        } else if (args.hasActiveOrDialingCalls) {
        if (args.hasActiveOrDialingCalls) {
            if (args.foregroundCallIsVoip) {
                return mVoipCallFocusState;
            } else {
+0 −138

File changed.

Preview size limit exceeded, changes collapsed.

+1 −12
Original line number Diff line number Diff line
@@ -175,7 +175,6 @@ public class CallsManager extends Call.ListenerBase
        void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile);
        void onHoldToneRequested(Call call);
        void onExternalCallChanged(Call call, boolean isExternalCall);
        void onTetheredCallChanged(Call call, boolean isTetheredCall);
        void onDisconnectedTonePlaying(boolean isTonePlaying);
        void onConnectionTimeChanged(Call call);
        void onConferenceStateChanged(Call call, boolean isConference);
@@ -2893,25 +2892,15 @@ public class CallsManager extends Call.ListenerBase
     * .
     * @param call The call whose external property changed.
     * @param isExternalCall {@code True} if the call is now external, {@code false} otherwise.
     * @param isTethered {@code True} if the call is now a tethered external call, {@false}
     *                              otherwise.
     */
    @Override
    public void onExternalCallChanged(Call call, boolean isExternalCall) {
        Log.v(this, "onExternalCallChanged: %b", isExternalCall);
        Log.v(this, "onConnectionPropertiesChanged: %b", isExternalCall);
        for (CallsManagerListener listener : mListeners) {
            listener.onExternalCallChanged(call, isExternalCall);
        }
    }

    @Override
    public void onTetheredCallChanged(Call call, boolean isTetheredCall) {
        Log.v(this, "onTetheredCallChanged: %b", isTetheredCall);
        for (CallsManagerListener listener : mListeners) {
            listener.onTetheredCallChanged(call, isTetheredCall);
        }
    }

    private void handleCallTechnologyChange(Call call) {
        if (call.getExtras() != null
                && call.getExtras().containsKey(TelecomManager.EXTRA_CALL_TECHNOLOGY_TYPE)) {
Loading