merge onReject into onDisconnect, propagate cause

bug: 268107048
Test: CTS
Change-Id: I16e51ab8e9c3cd7f3ad7d17ebf7ab1cdff019253
diff --git a/core/api/current.txt b/core/api/current.txt
index 2f1d81d..554a9e1 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -42065,8 +42065,7 @@
   public interface CallControlCallback {
     method public void onAnswer(int, @NonNull java.util.function.Consumer<java.lang.Boolean>);
     method public void onCallStreamingStarted(@NonNull java.util.function.Consumer<java.lang.Boolean>);
-    method public void onDisconnect(@NonNull java.util.function.Consumer<java.lang.Boolean>);
-    method public void onReject(@NonNull java.util.function.Consumer<java.lang.Boolean>);
+    method public void onDisconnect(@NonNull android.telecom.DisconnectCause, @NonNull java.util.function.Consumer<java.lang.Boolean>);
     method public void onSetActive(@NonNull java.util.function.Consumer<java.lang.Boolean>);
     method public void onSetInactive(@NonNull java.util.function.Consumer<java.lang.Boolean>);
   }
diff --git a/telecomm/java/android/telecom/CallControlCallback.java b/telecomm/java/android/telecom/CallControlCallback.java
index aadf337..35e2fd4 100644
--- a/telecomm/java/android/telecom/CallControlCallback.java
+++ b/telecomm/java/android/telecom/CallControlCallback.java
@@ -75,24 +75,17 @@
             @NonNull Consumer<Boolean> wasCompleted);
 
     /**
-     * Telecom is informing the client to reject the incoming call
-     *
-     * @param wasCompleted The {@link Consumer} to be completed. If the client can reject the
-     *                     incoming call, {@link Consumer#accept(Object)} should be called with
-     *                     {@link Boolean#TRUE}. Otherwise, {@link Consumer#accept(Object)}
-     *                     should  be called with {@link Boolean#FALSE}.
-     */
-    void onReject(@NonNull Consumer<Boolean> wasCompleted);
-
-    /**
      * Telecom is informing the client to disconnect the call
      *
-     * @param wasCompleted The {@link Consumer} to be completed. If the client can disconnect the
-     *                     call on their end, {@link Consumer#accept(Object)} should be called with
-     *                     {@link Boolean#TRUE}. Otherwise, {@link Consumer#accept(Object)}
-     *                     should  be called with {@link Boolean#FALSE}.
+     * @param disconnectCause represents the cause for disconnecting the call.
+     * @param wasCompleted    The {@link Consumer} to be completed. If the client can disconnect
+     *                        the call on their end, {@link Consumer#accept(Object)} should be
+     *                        called with {@link Boolean#TRUE}. Otherwise,
+     *                        {@link Consumer#accept(Object)} should  be called with
+     *                        {@link Boolean#FALSE}.
      */
-    void onDisconnect(@NonNull Consumer<Boolean> wasCompleted);
+    void onDisconnect(@NonNull DisconnectCause disconnectCause,
+            @NonNull Consumer<Boolean> wasCompleted);
 
     /**
      * Telecom is informing the client to set the call in streaming.
diff --git a/telecomm/java/com/android/internal/telecom/ClientTransactionalServiceWrapper.java b/telecomm/java/com/android/internal/telecom/ClientTransactionalServiceWrapper.java
index e44e2b3..71e9184 100644
--- a/telecomm/java/com/android/internal/telecom/ClientTransactionalServiceWrapper.java
+++ b/telecomm/java/com/android/internal/telecom/ClientTransactionalServiceWrapper.java
@@ -28,6 +28,7 @@
 import android.telecom.CallEndpoint;
 import android.telecom.CallEventCallback;
 import android.telecom.CallException;
+import android.telecom.DisconnectCause;
 import android.telecom.PhoneAccountHandle;
 import android.text.TextUtils;
 import android.util.Log;
@@ -142,7 +143,6 @@
         private static final String ON_SET_ACTIVE = "onSetActive";
         private static final String ON_SET_INACTIVE = "onSetInactive";
         private static final String ON_ANSWER = "onAnswer";
-        private static final String ON_REJECT = "onReject";
         private static final String ON_DISCONNECT = "onDisconnect";
         private static final String ON_STREAMING_STARTED = "onStreamingStarted";
         private static final String ON_REQ_ENDPOINT_CHANGE = "onRequestEndpointChange";
@@ -151,9 +151,9 @@
         private static final String ON_CALL_STREAMING_FAILED = "onCallStreamingFailed";
         private static final String ON_EVENT = "onEvent";
 
-        private void handleHandshakeCallback(String action, String callId, int code,
-                ResultReceiver ackResultReceiver) {
-            Log.i(TAG, TextUtils.formatSimple("hHC: id=[%s], action=[%s]", callId, action));
+        private void handleCallEventCallback(String action, String callId,
+                ResultReceiver ackResultReceiver, Object... args) {
+            Log.i(TAG, TextUtils.formatSimple("hCEC: id=[%s], action=[%s]", callId, action));
             // lookup the callEventCallback associated with the particular call
             TransactionalCall call = mCallIdToTransactionalCall.get(callId);
 
@@ -174,16 +174,13 @@
                             case ON_SET_INACTIVE:
                                 callback.onSetInactive(outcomeReceiverWrapper);
                                 break;
-                            case ON_REJECT:
-                                callback.onReject(outcomeReceiverWrapper);
-                                untrackCall(callId);
-                                break;
                             case ON_DISCONNECT:
-                                callback.onDisconnect(outcomeReceiverWrapper);
+                                callback.onDisconnect((DisconnectCause) args[0],
+                                        outcomeReceiverWrapper);
                                 untrackCall(callId);
                                 break;
                             case ON_ANSWER:
-                                callback.onAnswer(code, outcomeReceiverWrapper);
+                                callback.onAnswer((int) args[0], outcomeReceiverWrapper);
                                 break;
                             case ON_STREAMING_STARTED:
                                 callback.onCallStreamingStarted(outcomeReceiverWrapper);
@@ -231,28 +228,23 @@
 
         @Override
         public void onSetActive(String callId, ResultReceiver resultReceiver) {
-            handleHandshakeCallback(ON_SET_ACTIVE, callId, 0, resultReceiver);
+            handleCallEventCallback(ON_SET_ACTIVE, callId, resultReceiver);
         }
 
-
         @Override
         public void onSetInactive(String callId, ResultReceiver resultReceiver) {
-            handleHandshakeCallback(ON_SET_INACTIVE, callId, 0, resultReceiver);
+            handleCallEventCallback(ON_SET_INACTIVE, callId, resultReceiver);
         }
 
         @Override
         public void onAnswer(String callId, int videoState, ResultReceiver resultReceiver) {
-            handleHandshakeCallback(ON_ANSWER, callId, videoState, resultReceiver);
+            handleCallEventCallback(ON_ANSWER, callId, resultReceiver, videoState);
         }
 
         @Override
-        public void onReject(String callId, ResultReceiver resultReceiver) {
-            handleHandshakeCallback(ON_REJECT, callId, 0, resultReceiver);
-        }
-
-        @Override
-        public void onDisconnect(String callId, ResultReceiver resultReceiver) {
-            handleHandshakeCallback(ON_DISCONNECT, callId, 0, resultReceiver);
+        public void onDisconnect(String callId, DisconnectCause cause,
+                ResultReceiver resultReceiver) {
+            handleCallEventCallback(ON_DISCONNECT, callId, resultReceiver, cause);
         }
 
         @Override
@@ -308,7 +300,7 @@
 
         @Override
         public void onCallStreamingStarted(String callId, ResultReceiver resultReceiver) {
-            handleHandshakeCallback(ON_STREAMING_STARTED, callId, 0, resultReceiver);
+            handleCallEventCallback(ON_STREAMING_STARTED, callId, resultReceiver);
         }
 
         @Override
diff --git a/telecomm/java/com/android/internal/telecom/ICallEventCallback.aidl b/telecomm/java/com/android/internal/telecom/ICallEventCallback.aidl
index dd61d17..213cafb 100644
--- a/telecomm/java/com/android/internal/telecom/ICallEventCallback.aidl
+++ b/telecomm/java/com/android/internal/telecom/ICallEventCallback.aidl
@@ -23,6 +23,7 @@
 import android.os.ResultReceiver;
 import android.telecom.CallAudioState;
 import android.telecom.CallException;
+import android.telecom.DisconnectCause;
 import java.util.List;
 
 /**
@@ -36,8 +37,7 @@
     void onSetActive(String callId, in ResultReceiver callback);
     void onSetInactive(String callId, in ResultReceiver callback);
     void onAnswer(String callId, int videoState, in ResultReceiver callback);
-    void onReject(String callId, in ResultReceiver callback);
-    void onDisconnect(String callId, in ResultReceiver callback);
+    void onDisconnect(String callId, in DisconnectCause cause, in ResultReceiver callback);
     // -- Streaming related. Client registered call streaming capabilities should override
     void onCallStreamingStarted(String callId, in ResultReceiver callback);
     void onCallStreamingFailed(String callId, int reason);