Add additional call state PRE_DIAL_WAIT for selection of account

If an account default is not set, the incall ui will display a dialog to
allow the user to select an account for that particular call.

Bug: 16243703

Change-Id: If1beaf60a92b4446adaaace2a72c3e0f70e61f21
diff --git a/src/com/android/telecomm/InCallAdapter.java b/src/com/android/telecomm/InCallAdapter.java
index 7db9325..161d4a4 100644
--- a/src/com/android/telecomm/InCallAdapter.java
+++ b/src/com/android/telecomm/InCallAdapter.java
@@ -18,6 +18,7 @@
 
 import android.os.Handler;
 import android.os.Message;
+import android.telecomm.PhoneAccount;
 
 import com.android.internal.os.SomeArgs;
 import com.android.internal.telecomm.IInCallAdapter;
@@ -42,6 +43,7 @@
     private static final int MSG_CONFERENCE = 11;
     private static final int MSG_SPLIT_FROM_CONFERENCE = 12;
     private static final int MSG_SWAP_WITH_BACKGROUND_CALL = 13;
+    private static final int MSG_PHONE_ACCOUNT_SELECTED = 14;
 
     private final class InCallAdapterHandler extends Handler {
         @Override
@@ -56,7 +58,7 @@
                         Log.w(this, "answerCall, unknown call id: %s", msg.obj);
                     }
                     break;
-                case MSG_REJECT_CALL:
+                case MSG_REJECT_CALL: {
                     SomeArgs args = (SomeArgs) msg.obj;
                     try {
                         call = mCallIdMapper.getCall(args.arg1);
@@ -71,6 +73,7 @@
                         args.recycle();
                     }
                     break;
+                }
                 case MSG_PLAY_DTMF_TONE:
                     call = mCallIdMapper.getCall(msg.obj);
                     if (call != null) {
@@ -129,6 +132,20 @@
                         Log.w(this, "phoneAccountClicked, unknown call id: %s", msg.obj);
                     }
                     break;
+                case MSG_PHONE_ACCOUNT_SELECTED: {
+                    SomeArgs args = (SomeArgs) msg.obj;
+                    try {
+                        call = mCallIdMapper.getCall(args.arg1);
+                        if (call != null) {
+                            mCallsManager.phoneAccountSelected(call, (PhoneAccount) args.arg2);
+                        } else {
+                            Log.w(this, "phoneAccountSelected, unknown call id: %s", args.arg1);
+                        }
+                    } finally {
+                        args.recycle();
+                    }
+                    break;
+                }
                 case MSG_MUTE:
                     mCallsManager.mute(msg.arg1 == 1);
                     break;
@@ -142,7 +159,6 @@
                     } else {
                         Log.w(this, "conference, unknown call id: %s", msg.obj);
                     }
-
                     break;
                 case MSG_SPLIT_FROM_CONFERENCE:
                     call = mCallIdMapper.getCall(msg.obj);
@@ -240,6 +256,15 @@
     }
 
     @Override
+    public void phoneAccountSelected(String callId, PhoneAccount account) {
+        mCallIdMapper.checkValidCallId(callId);
+        SomeArgs args = SomeArgs.obtain();
+        args.arg1 = callId;
+        args.arg2 = account;
+        mHandler.obtainMessage(MSG_PHONE_ACCOUNT_SELECTED, args).sendToTarget();
+    }
+
+    @Override
     public void mute(boolean shouldMute) {
         mHandler.obtainMessage(MSG_MUTE, shouldMute ? 1 : 0, 0).sendToTarget();
     }