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

Commit 701dc006 authored by Andrew Lee's avatar Andrew Lee
Browse files

Use telecomm DiconnectCause in services/Telecomm.

+ Some of this is straightforward replacing the old disconnect cause
code/message with the new DisconnectCause object.
+ Replace codes in some instances; most maps straightforwardly to the
newer generic set of disconnect causes.
+ InCallToneMonitor can no longer rely on the specific telephony
DisconnectCauses. Now, instead, they map from a tone (which is
specified on the new telecomm DisconnectCauses) to the type of tone
which should be played in InCall. Most of these are just taking
unique matches from InCallTonePlayer. It is a little redundant, as
the conversion just flips, but it seemed like the easiest way to
accomplish this given current constraints.

+ Behavior is unchanged, but now DisconnectCause.OUT_OF_SERVICE
will invoke InCallTonePlayer.TONE_CDMA_DROP.
+ Now play TONE_PROP_PROMPT regardless of whether there is precisely
one remaining call; this is because we can't distinguish between
telephony DisconnectCause.ERROR_UNSPECIFIED/NORMAL/LOCAL. I figured
this would be a relatively minor change in scenario, and it wouldn't
hurt for a tone to be played even in a disconnect in that scenario.

Bug: 17329632
Change-Id: I85767d424bcfd59b3929819c9c6de46fc4a8629e
parent e425e060
Loading
Loading
Loading
Loading
+14 −25
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract.Contacts;
import android.telecom.CallState;
import android.telecom.DisconnectCause;
import android.telecom.Connection;
import android.telecom.GatewayInfo;
import android.telecom.ParcelableConnection;
@@ -33,7 +34,6 @@ import android.telecom.Response;
import android.telecom.StatusHints;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;

@@ -66,7 +66,7 @@ final class Call implements CreateConnectionResponse {
     */
    interface Listener {
        void onSuccessfulOutgoingCall(Call call, int callState);
        void onFailedOutgoingCall(Call call, int errorCode, String errorMsg);
        void onFailedOutgoingCall(Call call, DisconnectCause disconnectCause);
        void onSuccessfulIncomingCall(Call call);
        void onFailedIncomingCall(Call call);
        void onRingbackRequested(Call call, boolean ringbackRequested);
@@ -92,7 +92,7 @@ final class Call implements CreateConnectionResponse {
        @Override
        public void onSuccessfulOutgoingCall(Call call, int callState) {}
        @Override
        public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {}
        public void onFailedOutgoingCall(Call call, DisconnectCause disconnectCause) {}
        @Override
        public void onSuccessfulIncomingCall(Call call) {}
        @Override
@@ -226,14 +226,9 @@ final class Call implements CreateConnectionResponse {

    /**
     * Disconnect cause for the call. Only valid if the state of the call is STATE_DISCONNECTED.
     * See {@link android.telephony.DisconnectCause}.
     * See {@link android.telecom.DisconnectCause}.
     */
    private int mDisconnectCause = DisconnectCause.NOT_VALID;

    /**
     * Additional disconnect information provided by the connection service.
     */
    private String mDisconnectMessage;
    private DisconnectCause mDisconnectCause = new DisconnectCause(DisconnectCause.UNKNOWN);

    /** Info used by the connection services. */
    private Bundle mExtras = Bundle.EMPTY;
@@ -430,25 +425,19 @@ final class Call implements CreateConnectionResponse {
    }

    /**
     * @param disconnectCause The reason for the disconnection, any of
     *         {@link android.telephony.DisconnectCause}.
     * @param disconnectMessage Optional message about the disconnect.
     * @param disconnectCause The reason for the disconnection, represented by
     *         {@link android.telecom.DisconnectCause}.
     */
    void setDisconnectCause(int disconnectCause, String disconnectMessage) {
    void setDisconnectCause(DisconnectCause disconnectCause) {
        // TODO: Consider combining this method with a setDisconnected() method that is totally
        // separate from setState.
        mDisconnectCause = disconnectCause;
        mDisconnectMessage = disconnectMessage;
    }

    int getDisconnectCause() {
    DisconnectCause getDisconnectCause() {
        return mDisconnectCause;
    }

    String getDisconnectMessage() {
        return mDisconnectMessage;
    }

    boolean isEmergencyCall() {
        return mIsEmergencyCall;
    }
@@ -656,11 +645,11 @@ final class Call implements CreateConnectionResponse {
    }

    @Override
    public void handleCreateConnectionFailure(int code, String msg) {
    public void handleCreateConnectionFailure(DisconnectCause disconnectCause) {
        mCreateConnectionProcessor = null;
        clearConnectionService();
        setDisconnectCause(code, msg);
        CallsManager.getInstance().markCallAsDisconnected(this, code, msg);
        setDisconnectCause(disconnectCause);
        CallsManager.getInstance().markCallAsDisconnected(this, disconnectCause);

        if (mIsIncoming) {
            for (Listener listener : mListeners) {
@@ -668,7 +657,7 @@ final class Call implements CreateConnectionResponse {
            }
        } else {
            for (Listener listener : mListeners) {
                listener.onFailedOutgoingCall(this, code, msg);
                listener.onFailedOutgoingCall(this, disconnectCause);
            }
        }
    }
@@ -725,7 +714,7 @@ final class Call implements CreateConnectionResponse {
            mCreateConnectionProcessor.abort();
        } else if (mState == CallState.NEW || mState == CallState.PRE_DIAL_WAIT
                || mState == CallState.CONNECTING) {
            handleCreateConnectionFailure(DisconnectCause.OUTGOING_CANCELED, null);
            handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.LOCAL));
        } else {
            Log.v(this, "Cannot abort a call which isn't either PRE_DIAL_WAIT or CONNECTING");
        }
+2 −2
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.provider.CallLog.Calls;
import android.telecom.CallState;
import android.telecom.DisconnectCause;
import android.telecom.PhoneAccountHandle;
import android.telecom.VideoProfile;
import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;

import com.android.internal.telephony.CallerInfo;
@@ -92,7 +92,7 @@ final class CallLogManager extends CallsManagerListenerBase {
        boolean isNewlyDisconnected =
                newState == CallState.DISCONNECTED || newState == CallState.ABORTED;
        boolean isCallCanceled = isNewlyDisconnected &&
                call.getDisconnectCause() == DisconnectCause.OUTGOING_CANCELED;
                call.getDisconnectCause().getCode() == DisconnectCause.CANCELED;

        // Log newly disconnected calls only if:
        // 1) It was not in the "choose account" phase when disconnected
+7 −8
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ import android.os.Bundle;
import android.provider.CallLog.Calls;
import android.telecom.AudioState;
import android.telecom.CallState;
import android.telecom.DisconnectCause;
import android.telecom.GatewayInfo;
import android.telecom.ParcelableConference;
import android.telecom.PhoneAccountHandle;
import android.telecom.PhoneCapabilities;
import android.telephony.DisconnectCause;
import android.telephony.TelephonyManager;

import com.android.internal.util.ArrayUtils;
@@ -172,11 +172,11 @@ public final class CallsManager extends Call.ListenerBase {
    }

    @Override
    public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {
    public void onFailedOutgoingCall(Call call, DisconnectCause disconnectCause) {
        Log.v(this, "onFailedOutgoingCall, call: %s", call);

        // TODO: Replace disconnect cause with more specific disconnect causes.
        markCallAsDisconnected(call, errorCode, errorMsg);
        markCallAsDisconnected(call, disconnectCause);
    }

    @Override
@@ -670,11 +670,10 @@ public final class CallsManager extends Call.ListenerBase {
     * Marks the specified call as STATE_DISCONNECTED and notifies the in-call app. If this was the
     * last live call, then also disconnect from the in-call controller.
     *
     * @param disconnectCause The disconnect reason, see {@link android.telephony.DisconnectCause}.
     * @param disconnectMessage Optional message about the disconnect.
     * @param disconnectCause The disconnect cause, see {@link android.telecomm.DisconnectCause}.
     */
    void markCallAsDisconnected(Call call, int disconnectCause, String disconnectMessage) {
        call.setDisconnectCause(disconnectCause, disconnectMessage);
    void markCallAsDisconnected(Call call, DisconnectCause disconnectCause) {
        call.setDisconnectCause(disconnectCause);
        setCallState(call, CallState.DISCONNECTED);
        removeCall(call);
    }
@@ -696,7 +695,7 @@ public final class CallsManager extends Call.ListenerBase {
        if (service != null) {
            for (Call call : mCalls) {
                if (call.getConnectionService() == service) {
                    markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null);
                    markCallAsDisconnected(call, new DisconnectCause(DisconnectCause.ERROR));
                }
            }
        }
+19 −22
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.telecom.AudioState;
import android.telecom.Connection;
import android.telecom.ConnectionRequest;
import android.telecom.ConnectionService;
import android.telecom.DisconnectCause;
import android.telecom.GatewayInfo;
import android.telecom.ParcelableConference;
import android.telecom.ParcelableConnection;
@@ -35,7 +36,6 @@ import android.telecom.PhoneAccountHandle;
import android.telecom.StatusHints;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.telephony.DisconnectCause;

import com.android.internal.os.SomeArgs;
import com.android.internal.telecom.IConnectionService;
@@ -125,12 +125,10 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
                    SomeArgs args = (SomeArgs) msg.obj;
                    try {
                        call = mCallIdMapper.getCall(args.arg1);
                        String disconnectMessage = (String) args.arg2;
                        int disconnectCause = args.argi1;
                        Log.d(this, "disconnect call %s %s", args.arg1, call);
                        DisconnectCause disconnectCause = (DisconnectCause) args.arg2;
                        Log.d(this, "disconnect call %s %s", disconnectCause, call);
                        if (call != null) {
                            mCallsManager.markCallAsDisconnected(call, disconnectCause,
                                    disconnectMessage);
                            mCallsManager.markCallAsDisconnected(call, disconnectCause);
                        } else {
                            //Log.w(this, "setDisconnected, unknown call id: %s", args.arg1);
                        }
@@ -224,7 +222,7 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
                    if (call != null) {
                        if (call.isActive()) {
                            mCallsManager.markCallAsDisconnected(
                                    call, DisconnectCause.NORMAL, null);
                                    call, new DisconnectCause(DisconnectCause.REMOTE));
                        } else {
                            mCallsManager.markCallAsRemoved(call);
                        }
@@ -394,15 +392,13 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
        }

        @Override
        public void setDisconnected(
                String callId, int disconnectCause, String disconnectMessage) {
            logIncoming("setDisconnected %s %d %s", callId, disconnectCause, disconnectMessage);
        public void setDisconnected(String callId, DisconnectCause disconnectCause) {
            logIncoming("setDisconnected %s %s", callId, disconnectCause);
            if (mCallIdMapper.isValidCallId(callId) || mCallIdMapper.isValidConferenceId(callId)) {
                Log.d(this, "disconnect call %s", callId);
                SomeArgs args = SomeArgs.obtain();
                args.arg1 = callId;
                args.arg2 = disconnectMessage;
                args.argi1 = disconnectCause;
                args.arg2 = disconnectCause;
                mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget();
            }
        }
@@ -632,14 +628,14 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
                } catch (RemoteException e) {
                    Log.e(this, e, "Failure to createConnection -- %s", getComponentName());
                    mPendingResponses.remove(callId).handleCreateConnectionFailure(
                            DisconnectCause.OUTGOING_FAILURE, e.toString());
                            new DisconnectCause(DisconnectCause.ERROR, e.toString()));
                }
            }

            @Override
            public void onFailure() {
                Log.e(this, new Exception(), "Failure to call %s", getComponentName());
                response.handleCreateConnectionFailure(DisconnectCause.OUTGOING_FAILURE, null);
                response.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.ERROR));
            }
        };

@@ -660,7 +656,7 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
            }
        }

        removeCall(call, DisconnectCause.LOCAL, null);
        removeCall(call, new DisconnectCause(DisconnectCause.LOCAL));
    }

    /** @see ConnectionService#hold(String) */
@@ -778,22 +774,22 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
    }

    void removeCall(Call call) {
        removeCall(call, DisconnectCause.ERROR_UNSPECIFIED, null);
        removeCall(call, new DisconnectCause(DisconnectCause.ERROR));
    }

    void removeCall(String callId, int disconnectCause, String disconnectMessage) {
    void removeCall(String callId, DisconnectCause disconnectCause) {
        CreateConnectionResponse response = mPendingResponses.remove(callId);
        if (response != null) {
            response.handleCreateConnectionFailure(disconnectCause, disconnectMessage);
            response.handleCreateConnectionFailure(disconnectCause);
        }

        mCallIdMapper.removeCall(callId);
    }

    void removeCall(Call call, int disconnectCause, String disconnectMessage) {
    void removeCall(Call call, DisconnectCause disconnectCause) {
        CreateConnectionResponse response = mPendingResponses.remove(mCallIdMapper.getCallId(call));
        if (response != null) {
            response.handleCreateConnectionFailure(disconnectCause, disconnectMessage);
            response.handleCreateConnectionFailure(disconnectCause);
        }

        mCallIdMapper.removeCall(call);
@@ -882,7 +878,7 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
        if (connection.getState() == Connection.STATE_DISCONNECTED) {
            // A connection that begins in the DISCONNECTED state is an indication of
            // failure to connect; we handle all failures uniformly
            removeCall(callId, connection.getDisconnectCause(), connection.getDisconnectMessage());
            removeCall(callId, connection.getDisconnectCause());
        } else {
            // Successful connection
            if (mPendingResponses.containsKey(callId)) {
@@ -901,7 +897,8 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
                    new CreateConnectionResponse[mPendingResponses.values().size()]);
            mPendingResponses.clear();
            for (int i = 0; i < responses.length; i++) {
                responses[i].handleCreateConnectionFailure(DisconnectCause.ERROR_UNSPECIFIED, null);
                responses[i].handleCreateConnectionFailure(
                        new DisconnectCause(DisconnectCause.ERROR));
            }
        }
        mCallIdMapper.clear();
+7 −9
Original line number Diff line number Diff line
@@ -16,10 +16,10 @@

package com.android.server.telecom;

import android.telecom.DisconnectCause;
import android.telecom.ParcelableConnection;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telephony.DisconnectCause;

import java.util.ArrayList;
import java.util.Iterator;
@@ -82,8 +82,7 @@ final class CreateConnectionProcessor {
    private List<CallAttemptRecord> mAttemptRecords;
    private Iterator<CallAttemptRecord> mAttemptRecordIterator;
    private CreateConnectionResponse mResponse;
    private int mLastErrorCode = DisconnectCause.OUTGOING_FAILURE;
    private String mLastErrorMsg;
    private DisconnectCause mLastErrorDisconnectCause;

    CreateConnectionProcessor(
            Call call, ConnectionServiceRepository repository, CreateConnectionResponse response) {
@@ -119,7 +118,7 @@ final class CreateConnectionProcessor {
            mCall.clearConnectionService();
        }
        if (response != null) {
            response.handleCreateConnectionFailure(DisconnectCause.OUTGOING_CANCELED, null);
            response.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.LOCAL));
        }
    }

@@ -168,7 +167,7 @@ final class CreateConnectionProcessor {
        } else {
            Log.v(this, "attemptNextPhoneAccount, no more accounts, failing");
            if (mResponse != null) {
                mResponse.handleCreateConnectionFailure(mLastErrorCode, mLastErrorMsg);
                mResponse.handleCreateConnectionFailure(mLastErrorDisconnectCause);
                mResponse = null;
                mCall.clearConnectionService();
            }
@@ -289,11 +288,10 @@ final class CreateConnectionProcessor {
        }

        @Override
        public void handleCreateConnectionFailure(int code, String msg) {
        public void handleCreateConnectionFailure(DisconnectCause errorDisconnectCause) {
            // Failure of some sort; record the reasons for failure and try again if possible
            Log.d(CreateConnectionProcessor.this, "Connection failed: %d (%s)", code, msg);
            mLastErrorCode = code;
            mLastErrorMsg = msg;
            Log.d(CreateConnectionProcessor.this, "Connection failed: (%s)", errorDisconnectCause);
            mLastErrorDisconnectCause = errorDisconnectCause;
            attemptNextPhoneAccount();
        }
    }
Loading