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

Commit 1a40c4f4 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Improvements to external call handling.

Add onExternalCallChanged listener in Call to report when a call switches
between being external and not.
In CallAudioManager, BluetoothPhoneServiceImpl, HeadsetMediaButton, and
PhoneStateBroadcaster, listen to changes in the external call state.

This ensures that when a call becomes external or a call becomes
non-external that the various modules updates themselves appropriately.

Bug: 28179159
Change-Id: I44bc0b94f185c66aeddb68549223533249bb0b62
parent a153e666
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -300,6 +300,22 @@ public class BluetoothPhoneServiceImpl {
            updateHeadsetWithCallState(false /* force */);
        }

        /**
         * Where a call which was external becomes a regular call, or a regular call becomes
         * external, treat as an add or remove, respectively.
         *
         * @param call The call.
         * @param isExternalCall {@code True} if the call became external, {@code false} otherwise.
         */
        @Override
        public void onExternalCallChanged(Call call, boolean isExternalCall) {
            if (isExternalCall) {
                onCallRemoved(call);
            } else {
                onCallAdded(call);
            }
        }

        @Override
        public void onCallStateChanged(Call call, int oldState, int newState) {
            // If a call is being put on hold because of a new connecting call, ignore the
+18 −2
Original line number Diff line number Diff line
@@ -43,9 +43,7 @@ import android.os.UserHandle;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telecom.IVideoProvider;
import com.android.internal.telephony.CallerInfo;
import com.android.internal.telephony.CallerInfoAsyncQuery;
import com.android.internal.telephony.SmsApplication;
import com.android.server.telecom.ContactsAsyncHelper.OnImageLoadCompleteListener;
import com.android.internal.util.Preconditions;

import java.lang.String;
@@ -113,6 +111,7 @@ public class Call implements CreateConnectionResponse {
        boolean onCanceledViaNewOutgoingCallBroadcast(Call call);
        void onHoldToneRequested(Call call);
        void onConnectionEvent(Call call, String event, Bundle extras);
        void onExternalCallChanged(Call call, boolean isExternalCall);
    }

    public abstract static class ListenerBase implements Listener {
@@ -179,6 +178,8 @@ public class Call implements CreateConnectionResponse {
        public void onHoldToneRequested(Call call) {}
        @Override
        public void onConnectionEvent(Call call, String event, Bundle extras) {}
        @Override
        public void onExternalCallChanged(Call call, boolean isExternalCall) {}
    }

    private final CallerInfoLookupHelper.OnQueryCompleteListener mCallerInfoQueryListener =
@@ -961,10 +962,25 @@ public class Call implements CreateConnectionResponse {
        Log.v(this, "setConnectionProperties: %s", Connection.propertiesToString(
                connectionProperties));
        if (mConnectionProperties != connectionProperties) {
            int previousProperties = mConnectionProperties;
            mConnectionProperties = connectionProperties;
            for (Listener l : mListeners) {
                l.onConnectionPropertiesChanged(this);
            }

            boolean wasExternal = (previousProperties & Connection.PROPERTY_IS_EXTERNAL_CALL)
                    == Connection.PROPERTY_IS_EXTERNAL_CALL;
            boolean isExternal = (connectionProperties & Connection.PROPERTY_IS_EXTERNAL_CALL)
                    == Connection.PROPERTY_IS_EXTERNAL_CALL;
            if (wasExternal != isExternal) {
                Log.v(this, "setConnectionProperties: external call changed isExternal = %b",
                        isExternal);

                for (Listener l : mListeners) {
                    l.onExternalCallChanged(this, isExternal);
                }

            }
        }
    }

+33 −6
Original line number Diff line number Diff line
@@ -119,6 +119,19 @@ public class CallAudioManager extends CallsManagerListenerBase {
            return; // Don't do audio handling for calls in a conference, or external calls.
        }

        addCall(call);
    }

    @Override
    public void onCallRemoved(Call call) {
        if (shouldIgnoreCallForAudio(call)) {
            return; // Don't do audio handling for calls in a conference, or external calls.
        }

        removeCall(call);
    }

    private void addCall(Call call) {
        if (mCalls.contains(call)) {
            Log.w(LOG_TAG, "Call TC@%s is being added twice.", call.getId());
            return; // No guarantees that the same call won't get added twice.
@@ -136,12 +149,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
        onCallEnteringState(call, call.getState());
    }

    @Override
    public void onCallRemoved(Call call) {
        if (shouldIgnoreCallForAudio(call)) {
            return; // Don't do audio handling for calls in a conference, or external calls.
        }

    private void removeCall(Call call) {
        if (!mCalls.contains(call)) {
            return; // No guarantees that the same call won't get removed twice.
        }
@@ -159,6 +167,25 @@ public class CallAudioManager extends CallsManagerListenerBase {
        onCallLeavingState(call, call.getState());
    }

    /**
     * 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 now
     *      a regular call.
     */
    @Override
    public void onExternalCallChanged(Call call, boolean isExternalCall) {
       if (isExternalCall) {
            Log.d(LOG_TAG, "Removing call which became external ID %s", call.getId());
            removeCall(call);
        } else if (!isExternalCall) {
            Log.d(LOG_TAG, "Adding external call which was pulled with ID %s", call.getId());
            addCall(call);
        }
    }

    /**
     * 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.
+31 −1
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ public class CallsManager extends Call.ListenerBase
        void onCanAddCallChanged(boolean canAddCall);
        void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile);
        void onHoldToneRequested(Call call);
        void onExternalCallChanged(Call call, boolean isExternalCall);
    }

    private static final String TAG = "CallsManager";
@@ -1214,6 +1215,21 @@ public class CallsManager extends Call.ListenerBase
        return allAccounts;
    }

    /**
     * Informs listeners (notably {@link CallAudioManager} of a change to the call's external
     * property.
     * .
     * @param call The call whose external property changed.
     * @param isExternalCall {@code True} if the call is now external, {@code false} otherwise.
     */
    @Override
    public void onExternalCallChanged(Call call, boolean isExternalCall) {
        Log.v(this, "onConnectionPropertiesChanged: %b", isExternalCall);
        for (CallsManagerListener listener : mListeners) {
            listener.onExternalCallChanged(call, isExternalCall);
        }
    }

    private void handleCallTechnologyChange(Call call) {
        if (call.getExtras() != null
                && call.getExtras().containsKey(TelecomManager.EXTRA_CALL_TECHNOLOGY_TYPE)) {
@@ -1360,8 +1376,22 @@ public class CallsManager extends Call.ListenerBase
        }
    }

    /**
     * Determines if the {@link CallsManager} has any non-external calls.
     *
     * @return {@code True} if there are any non-external calls, {@code false} otherwise.
     */
    boolean hasAnyCalls() {
        return !mCalls.isEmpty();
        if (mCalls.isEmpty()) {
            return false;
        }

        for (Call call : mCalls) {
            if (!call.isExternalCall()) {
                return true;
            }
        }
        return false;
    }

    boolean hasActiveOrHoldingCall() {
+4 −0
Original line number Diff line number Diff line
@@ -84,4 +84,8 @@ public class CallsManagerListenerBase implements CallsManager.CallsManagerListen
    @Override
    public void onHoldToneRequested(Call call) {
    }

    @Override
    public void onExternalCallChanged(Call call, boolean isExternalCall) {
    }
}
Loading