Pass through video state when answering a call.

Bug: 16013878
Bug: 16015750
Change-Id: I26af541c30cc296bb3b3f85c06a2e097d0b58547
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index 5dfba52..b06b043 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -669,8 +669,10 @@
 
     /**
      * Answers the call if it is ringing.
+     *
+     * @param videoState The video state in which to answer the call.
      */
-    void answer() {
+    void answer(int videoState) {
         Preconditions.checkNotNull(mConnectionService);
 
         // Check to verify that the call is still in the ringing state. A call can change states
@@ -680,7 +682,7 @@
             // that it will work. Instead, we wait until confirmation from the connectino service
             // that the call is in a non-RINGING state before changing the UI. See
             // {@link ConnectionServiceAdapter#setActive} and other set* methods.
-            mConnectionService.answer(this);
+            mConnectionService.answer(this, videoState);
         }
     }
 
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 8265b20..c752625 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -344,8 +344,11 @@
      * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
      * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
      * the user opting to answer said call.
+     *
+     * @param call The call to answer.
+     * @param videoState The video state in which to answer the call.
      */
-    void answerCall(Call call) {
+    void answerCall(Call call, int videoState) {
         if (!mCalls.contains(call)) {
             Log.i(this, "Request to answer a non-existent call %s", call);
         } else {
@@ -368,7 +371,7 @@
 
             // We do not update the UI until we get confirmation of the answer() through
             // {@link #markCallAsActive}.
-            call.answer();
+            call.answer(videoState);
         }
     }
 
@@ -577,7 +580,7 @@
                     mCallAudioManager.toggleMute();
                     return true;
                 } else {
-                    ringingCall.answer();
+                    ringingCall.answer(ringingCall.getVideoState());
                     return true;
                 }
             } else if (HeadsetMediaButton.LONG_PRESS == type) {
diff --git a/src/com/android/telecomm/ConnectionServiceWrapper.java b/src/com/android/telecomm/ConnectionServiceWrapper.java
index 870d61c..a47dc09 100644
--- a/src/com/android/telecomm/ConnectionServiceWrapper.java
+++ b/src/com/android/telecomm/ConnectionServiceWrapper.java
@@ -632,11 +632,11 @@
     }
 
     /** @see ConnectionService#answer(String) */
-    void answer(Call call) {
+    void answer(Call call, int videoState) {
         if (isServiceValid("answer")) {
             try {
-                logOutgoing("answer %s", mCallIdMapper.getCallId(call));
-                mServiceInterface.answer(mCallIdMapper.getCallId(call));
+                logOutgoing("answer %s %d", mCallIdMapper.getCallId(call), videoState);
+                mServiceInterface.answer(mCallIdMapper.getCallId(call), videoState);
             } catch (RemoteException e) {
             }
         }
diff --git a/src/com/android/telecomm/InCallAdapter.java b/src/com/android/telecomm/InCallAdapter.java
index 161d4a4..0822dc4 100644
--- a/src/com/android/telecomm/InCallAdapter.java
+++ b/src/com/android/telecomm/InCallAdapter.java
@@ -50,14 +50,21 @@
         public void handleMessage(Message msg) {
             Call call;
             switch (msg.what) {
-                case MSG_ANSWER_CALL:
-                    call = mCallIdMapper.getCall(msg.obj);
-                    if (call != null) {
-                        mCallsManager.answerCall(call);
-                    } else {
-                        Log.w(this, "answerCall, unknown call id: %s", msg.obj);
+                case MSG_ANSWER_CALL: {
+                    SomeArgs args = (SomeArgs) msg.obj;
+                    try {
+                        call = mCallIdMapper.getCall(args.arg1);
+                        int videoState = (int) args.arg2;
+                        if (call != null) {
+                            mCallsManager.answerCall(call, videoState);
+                        } else {
+                            Log.w(this, "answerCall, unknown call id: %s", msg.obj);
+                        }
+                    } finally {
+                        args.recycle();
                     }
                     break;
+                }
                 case MSG_REJECT_CALL: {
                     SomeArgs args = (SomeArgs) msg.obj;
                     try {
@@ -192,10 +199,13 @@
     }
 
     @Override
-    public void answerCall(String callId) {
-        Log.d(this, "answerCall(%s)", callId);
+    public void answerCall(String callId, int videoState) {
+        Log.d(this, "answerCall(%s,%d)", callId, videoState);
         mCallIdMapper.checkValidCallId(callId);
-        mHandler.obtainMessage(MSG_ANSWER_CALL, callId).sendToTarget();
+        SomeArgs args = SomeArgs.obtain();
+        args.arg1 = callId;
+        args.arg2 = videoState;
+        mHandler.obtainMessage(MSG_ANSWER_CALL, args).sendToTarget();
     }
 
     @Override
diff --git a/src/com/android/telecomm/TelecommServiceImpl.java b/src/com/android/telecomm/TelecommServiceImpl.java
index d848029..f93a7a7 100644
--- a/src/com/android/telecomm/TelecommServiceImpl.java
+++ b/src/com/android/telecomm/TelecommServiceImpl.java
@@ -298,7 +298,7 @@
     private void acceptRingingCallInternal() {
         Call call = mCallsManager.getFirstCallWithState(CallState.RINGING);
         if (call != null) {
-            call.answer();
+            call.answer(call.getVideoState());
         }
     }