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
diff --git a/src/com/android/server/telecom/Call.java b/src/com/android/server/telecom/Call.java
index 9eeaa7f..906be74 100644
--- a/src/com/android/server/telecom/Call.java
+++ b/src/com/android/server/telecom/Call.java
@@ -23,6 +23,7 @@
 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.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 @@
      */
     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 @@
         @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 @@
 
     /**
      * 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 @@
     }
 
     /**
-     * @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 @@
     }
 
     @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 @@
             }
         } else {
             for (Listener listener : mListeners) {
-                listener.onFailedOutgoingCall(this, code, msg);
+                listener.onFailedOutgoingCall(this, disconnectCause);
             }
         }
     }
@@ -725,7 +714,7 @@
             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");
         }
diff --git a/src/com/android/server/telecom/CallLogManager.java b/src/com/android/server/telecom/CallLogManager.java
index 060c33b..4704647 100644
--- a/src/com/android/server/telecom/CallLogManager.java
+++ b/src/com/android/server/telecom/CallLogManager.java
@@ -21,9 +21,9 @@
 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 @@
         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
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 2636c2f..8238ec7 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -22,11 +22,11 @@
 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 @@
     }
 
     @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 @@
      * 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 @@
         if (service != null) {
             for (Call call : mCalls) {
                 if (call.getConnectionService() == service) {
-                    markCallAsDisconnected(call, DisconnectCause.ERROR_UNSPECIFIED, null);
+                    markCallAsDisconnected(call, new DisconnectCause(DisconnectCause.ERROR));
                 }
             }
         }
diff --git a/src/com/android/server/telecom/ConnectionServiceWrapper.java b/src/com/android/server/telecom/ConnectionServiceWrapper.java
index 669f9a5..7719c0e 100644
--- a/src/com/android/server/telecom/ConnectionServiceWrapper.java
+++ b/src/com/android/server/telecom/ConnectionServiceWrapper.java
@@ -27,6 +27,7 @@
 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.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 @@
                     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 @@
                     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 @@
         }
 
         @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 @@
                 } 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 @@
             }
         }
 
-        removeCall(call, DisconnectCause.LOCAL, null);
+        removeCall(call, new DisconnectCause(DisconnectCause.LOCAL));
     }
 
     /** @see ConnectionService#hold(String) */
@@ -778,22 +774,22 @@
     }
 
     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 @@
         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 @@
                     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();
diff --git a/src/com/android/server/telecom/CreateConnectionProcessor.java b/src/com/android/server/telecom/CreateConnectionProcessor.java
index 11623b0..c019881 100644
--- a/src/com/android/server/telecom/CreateConnectionProcessor.java
+++ b/src/com/android/server/telecom/CreateConnectionProcessor.java
@@ -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 @@
     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 @@
             mCall.clearConnectionService();
         }
         if (response != null) {
-            response.handleCreateConnectionFailure(DisconnectCause.OUTGOING_CANCELED, null);
+            response.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.LOCAL));
         }
     }
 
@@ -168,7 +167,7 @@
         } 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 @@
         }
 
         @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();
         }
     }
diff --git a/src/com/android/server/telecom/CreateConnectionResponse.java b/src/com/android/server/telecom/CreateConnectionResponse.java
index a1ffa38..08c0cfc 100644
--- a/src/com/android/server/telecom/CreateConnectionResponse.java
+++ b/src/com/android/server/telecom/CreateConnectionResponse.java
@@ -16,6 +16,7 @@
 
 package com.android.server.telecom;
 
+import android.telecom.DisconnectCause;
 import android.telecom.ParcelableConnection;
 
 /**
@@ -23,5 +24,5 @@
  */
 interface CreateConnectionResponse {
     void handleCreateConnectionSuccess(CallIdMapper idMapper, ParcelableConnection connection);
-    void handleCreateConnectionFailure(int code, String message);
+    void handleCreateConnectionFailure(DisconnectCause disconnectCaused);
 }
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index 9f5736e..a80d9af 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -483,7 +483,6 @@
                 callId,
                 state,
                 call.getDisconnectCause(),
-                call.getDisconnectMessage(),
                 call.getCannedSmsResponses(),
                 capabilities,
                 properties,
diff --git a/src/com/android/server/telecom/InCallToneMonitor.java b/src/com/android/server/telecom/InCallToneMonitor.java
index 2ffb499..d25c42a 100644
--- a/src/com/android/server/telecom/InCallToneMonitor.java
+++ b/src/com/android/server/telecom/InCallToneMonitor.java
@@ -16,8 +16,8 @@
 
 package com.android.server.telecom;
 
+import android.media.ToneGenerator;
 import android.telecom.CallState;
-import android.telephony.DisconnectCause;
 
 import java.util.Collection;
 
@@ -47,43 +47,28 @@
 
             Log.v(this, "Disconnect cause: %d.", call.getDisconnectCause());
 
-            switch(call.getDisconnectCause()) {
-                case DisconnectCause.BUSY:
+            switch(call.getDisconnectCause().getTone()) {
+                case ToneGenerator.TONE_SUP_BUSY:
                     toneToPlay = InCallTonePlayer.TONE_BUSY;
                     break;
-                case DisconnectCause.CONGESTION:
+                case ToneGenerator.TONE_SUP_CONGESTION:
                     toneToPlay = InCallTonePlayer.TONE_CONGESTION;
                     break;
-                case DisconnectCause.CDMA_REORDER:
+                case ToneGenerator.TONE_CDMA_REORDER:
                     toneToPlay = InCallTonePlayer.TONE_REORDER;
                     break;
-                case DisconnectCause.CDMA_INTERCEPT:
+                case ToneGenerator.TONE_CDMA_ABBR_INTERCEPT:
                     toneToPlay = InCallTonePlayer.TONE_INTERCEPT;
                     break;
-                case DisconnectCause.CDMA_DROP:
+                case ToneGenerator.TONE_CDMA_CALLDROP_LITE:
                     toneToPlay = InCallTonePlayer.TONE_CDMA_DROP;
                     break;
-                case DisconnectCause.OUT_OF_SERVICE:
-                    toneToPlay = InCallTonePlayer.TONE_OUT_OF_SERVICE;
-                    break;
-                case DisconnectCause.UNOBTAINABLE_NUMBER:
+                case ToneGenerator.TONE_SUP_ERROR:
                     toneToPlay = InCallTonePlayer.TONE_UNOBTAINABLE_NUMBER;
                     break;
-                case DisconnectCause.ERROR_UNSPECIFIED:
+                case ToneGenerator.TONE_PROP_PROMPT:
                     toneToPlay = InCallTonePlayer.TONE_CALL_ENDED;
                     break;
-                case DisconnectCause.NORMAL:
-                case DisconnectCause.LOCAL:
-                    // Only play the disconnect sound on normal disconnects if there are no other
-                    // calls present beyond the one that is currently disconnected.
-                    Collection<Call> allCalls = mCallsManager.getCalls();
-                    if (allCalls.size() == 1) {
-                        if (!allCalls.contains(call)) {
-                            Log.wtf(this, "Disconnecting call not found %s.", call);
-                        }
-                        toneToPlay = InCallTonePlayer.TONE_CALL_ENDED;
-                    }
-                    break;
             }
 
             Log.d(this, "Found a disconnected call with tone to play %d.", toneToPlay);
diff --git a/src/com/android/server/telecom/MissedCallNotifier.java b/src/com/android/server/telecom/MissedCallNotifier.java
index d9ab3b9..de6a423 100644
--- a/src/com/android/server/telecom/MissedCallNotifier.java
+++ b/src/com/android/server/telecom/MissedCallNotifier.java
@@ -32,7 +32,7 @@
 import android.provider.CallLog;
 import android.provider.CallLog.Calls;
 import android.telecom.CallState;
-import android.telephony.DisconnectCause;
+import android.telecom.DisconnectCause;
 import android.text.BidiFormatter;
 import android.text.TextDirectionHeuristics;
 import android.text.TextUtils;
@@ -72,7 +72,7 @@
     @Override
     public void onCallStateChanged(Call call, int oldState, int newState) {
         if (oldState == CallState.RINGING && newState == CallState.DISCONNECTED &&
-                call.getDisconnectCause() == DisconnectCause.INCOMING_MISSED) {
+                call.getDisconnectCause().getCode() == DisconnectCause.MISSED) {
             showMissedCallNotification(call);
         }
     }
@@ -285,7 +285,7 @@
 
                             // Convert the data to a call object
                             Call call = new Call(null, null, null, null, null, true, false);
-                            call.setDisconnectCause(DisconnectCause.INCOMING_MISSED, "");
+                            call.setDisconnectCause(new DisconnectCause(DisconnectCause.MISSED));
                             call.setState(CallState.DISCONNECTED);
 
                             // Listen for the update to the caller information before posting the
diff --git a/tests/src/com/android/server/telecom/testapps/TestConnectionManager.java b/tests/src/com/android/server/telecom/testapps/TestConnectionManager.java
index 2c086d9..47381a9 100644
--- a/tests/src/com/android/server/telecom/testapps/TestConnectionManager.java
+++ b/tests/src/com/android/server/telecom/testapps/TestConnectionManager.java
@@ -22,6 +22,7 @@
 import android.telecom.Connection;
 import android.telecom.ConnectionRequest;
 import android.telecom.ConnectionService;
+import android.telecom.DisconnectCause;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.RemoteConference;
 import android.telecom.RemoteConnection;
@@ -47,8 +48,9 @@
             }
 
             @Override
-            public void onDisconnected(RemoteConnection connection, int cause, String message) {
-                setDisconnected(cause, message);
+            public void onDisconnected(
+                    RemoteConnection connection, DisconnectCause disconnectCause) {
+                setDisconnected(disconnectCause);
                 destroy();
             }
 
@@ -214,8 +216,9 @@
             }
 
             @Override
-            public void onDisconnected(RemoteConference conference, int cause, String message) {
-                setDisconnected(cause, message);
+            public void onDisconnected(RemoteConference conference,
+                    DisconnectCause disconnectCause) {
+                setDisconnected(disconnectCause);
             }
 
             @Override
diff --git a/tests/src/com/android/server/telecom/testapps/TestConnectionService.java b/tests/src/com/android/server/telecom/testapps/TestConnectionService.java
index a20525b..b327462 100644
--- a/tests/src/com/android/server/telecom/testapps/TestConnectionService.java
+++ b/tests/src/com/android/server/telecom/testapps/TestConnectionService.java
@@ -25,6 +25,7 @@
 import android.telecom.AudioState;
 import android.telecom.Conference;
 import android.telecom.Connection;
+import android.telecom.DisconnectCause;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneCapabilities;
 import android.telecom.ConnectionRequest;
@@ -34,7 +35,6 @@
 import android.telecom.StatusHints;
 import android.telecom.TelecomManager;
 import android.telecom.VideoProfile;
-import android.telephony.DisconnectCause;
 import android.util.Log;
 
 import com.android.server.telecom.tests.R;
@@ -69,7 +69,7 @@
             public void onDestroyed(Connection c) {
                 removeConnection(c);
                 if (getConnections().size() == 0) {
-                    setDisconnected(DisconnectCause.NORMAL, null);
+                    setDisconnected(new DisconnectCause(DisconnectCause.REMOTE));
                     destroy();
                 }
             }
@@ -93,7 +93,7 @@
         @Override
         public void onDisconnect() {
             for (Connection c : getConnections()) {
-                c.setDisconnected(DisconnectCause.NORMAL, null);
+                c.setDisconnected(new DisconnectCause(DisconnectCause.REMOTE));
                 c.destroy();
             }
         }
@@ -184,7 +184,7 @@
         /** ${inheritDoc} */
         @Override
         public void onDisconnect() {
-            setDisconnected(DisconnectCause.LOCAL, null);
+            setDisconnected(new DisconnectCause(DisconnectCause.REMOTE));
             destroyCall(this);
             destroy();
         }
@@ -198,7 +198,7 @@
         /** ${inheritDoc} */
         @Override
         public void onReject() {
-            setDisconnected(DisconnectCause.INCOMING_REJECTED, null);
+            setDisconnected(new DisconnectCause(DisconnectCause.REJECTED));
             destroyCall(this);
             destroy();
         }
@@ -336,9 +336,8 @@
             connection.setVideoState(videoState);
             return connection;
         } else {
-            return Connection.createFailedConnection(
-                    DisconnectCause.NOT_VALID,
-                    "Invalid inputs: " + accountHandle + " " + componentName);
+            return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR,
+                    "Invalid inputs: " + accountHandle + " " + componentName));
         }
     }