Misc Telecomm API changes: InCallUI

This CL hooks up the new APIs introduced in ag/501321 to the
InCallUI.

Change-Id: Iaffe0b84cea6003f2a9b9d8b30676743d2b236d4
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java
index d844d8e..c8a21e9 100644
--- a/InCallUI/src/com/android/incallui/Call.java
+++ b/InCallUI/src/com/android/incallui/Call.java
@@ -19,7 +19,7 @@
 import android.net.Uri;
 import android.os.RemoteException;
 import android.telecomm.CallCapabilities;
-import android.telecomm.CallNumberPresentation;
+import android.telecomm.CallPropertyPresentation;
 import android.telecomm.CallServiceDescriptor;
 import android.telecomm.PhoneAccount;
 import android.telecomm.RemoteCallVideoProvider;
@@ -107,13 +107,15 @@
     private int mCapabilities;
     private long mConnectTimeMillis = 0;
     private Uri mHandle;
+    private int mNumberPresentation;
+    private String mCnapName;
+    private int mCnapNamePresentation;
     private GatewayInfo mGatewayInfo;
     private PhoneAccount mAccount;
     private CallServiceDescriptor mCurrentCallServiceDescriptor;
     private RemoteCallVideoProvider mCallVideoProvider;
     private String mParentCallId;
     private List<String> mChildCallIds;
-    private int mFeatures;
 
     private InCallVideoClient mCallVideoClient;
 
@@ -140,6 +142,18 @@
         mHandle = handle;
     }
 
+    public void setNumberPresentation(int presentation) {
+        mNumberPresentation = presentation;
+    }
+
+    public void setCnapName(String cnapName) {
+        mCnapName = cnapName;
+    }
+
+    public void setCnapNamePresentation(int presentation) {
+        mCnapNamePresentation = presentation;
+    }
+
     public int getState() {
         if (mParentCallId != null) {
             return State.CONFERENCED;
@@ -152,16 +166,16 @@
         mState = state;
     }
 
-    public CallNumberPresentation getNumberPresentation() {
-        return CallNumberPresentation.ALLOWED;
+    public int getNumberPresentation() {
+        return mNumberPresentation;
     }
 
-    public CallNumberPresentation getCnapNamePresentation() {
-        return CallNumberPresentation.ALLOWED;
+    public int getCnapNamePresentation() {
+        return mCnapNamePresentation;
     }
 
     public String getCnapName() {
-        return "";
+        return mCnapName;
     }
 
     /** Returns call disconnect cause; values are defined in {@link DisconnectCause}. */
@@ -271,14 +285,6 @@
         return mParentCallId;
     }
 
-    public int getFeatures() {
-        return mFeatures;
-    }
-
-    public void setFeatures(int features) {
-        mFeatures = features;
-    }
-
     @Override
     public String toString() {
         return String.format(Locale.US, "[%s, %s, %s, children:%s, parent:%s]",
diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java
index f0775e8..d9fee5f 100644
--- a/InCallUI/src/com/android/incallui/CallButtonPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallButtonPresenter.java
@@ -225,7 +225,7 @@
     }
 
     public void swapClicked() {
-        TelecommAdapter.getInstance().swap();
+        TelecommAdapter.getInstance().swap(mCall.getCallId());
     }
 
     public void showDialpadClicked(boolean checked) {
diff --git a/InCallUI/src/com/android/incallui/CallerInfo.java b/InCallUI/src/com/android/incallui/CallerInfo.java
index 2029ca6..8f68cf8 100644
--- a/InCallUI/src/com/android/incallui/CallerInfo.java
+++ b/InCallUI/src/com/android/incallui/CallerInfo.java
@@ -28,7 +28,7 @@
 import android.provider.ContactsContract.Data;
 import android.provider.ContactsContract.PhoneLookup;
 import android.provider.ContactsContract.RawContacts;
-import android.telecomm.CallNumberPresentation;
+import android.telecomm.CallPropertyPresentation;
 import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
 
@@ -81,8 +81,8 @@
     public String geoDescription;
 
     public String cnapName;
-    public CallNumberPresentation numberPresentation;
-    public CallNumberPresentation namePresentation;
+    public int numberPresentation;
+    public int namePresentation;
     public boolean contactExists;
 
     public String phoneLabel;
diff --git a/InCallUI/src/com/android/incallui/CallerInfoUtils.java b/InCallUI/src/com/android/incallui/CallerInfoUtils.java
index 857f71f..bc0ea78 100644
--- a/InCallUI/src/com/android/incallui/CallerInfoUtils.java
+++ b/InCallUI/src/com/android/incallui/CallerInfoUtils.java
@@ -3,7 +3,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
-import android.telecomm.CallNumberPresentation;
+import android.telecomm.CallPropertyPresentation;
 import android.text.TextUtils;
 
 import java.util.Arrays;
@@ -42,7 +42,7 @@
 
         // TODO: Have phoneapp send a Uri when it knows the contact that triggered this call.
 
-        if (info.numberPresentation == CallNumberPresentation.ALLOWED) {
+        if (info.numberPresentation == CallPropertyPresentation.ALLOWED) {
             // Start the query with the number provided from the call.
             Log.d(TAG, "==> Actually starting CallerInfoAsyncQuery.startQuery()...");
             CallerInfoAsyncQuery.startQuery(QUERY_TOKEN, context, number, listener, call);
@@ -83,7 +83,7 @@
      * @return the new String that should be used for the phone number
      */
     /* package */static String modifyForSpecialCnapCases(Context context, CallerInfo ci,
-            String number, CallNumberPresentation presentation) {
+            String number, int presentation) {
         // Obviously we return number if ci == null, but still return number if
         // number == null, because in these cases the correct string will still be
         // displayed/logged after this function returns based on the presentation value.
@@ -99,9 +99,9 @@
         final String[] absentNumberValues =
                 context.getResources().getStringArray(R.array.absent_num);
         if (Arrays.asList(absentNumberValues).contains(number)
-                && presentation == CallNumberPresentation.ALLOWED) {
+                && presentation == CallPropertyPresentation.ALLOWED) {
             number = context.getString(R.string.unknown);
-            ci.numberPresentation = CallNumberPresentation.UNKNOWN;
+            ci.numberPresentation = CallPropertyPresentation.UNKNOWN;
         }
 
         // Check for other special "corner cases" for CNAP and fix them similarly. Corner
@@ -109,16 +109,16 @@
         // if we think we have an allowed presentation, or if the CallerInfo presentation doesn't
         // match the presentation passed in for verification (meaning we changed it previously
         // because it's a corner case and we're being called from a different entry point).
-        if (ci.numberPresentation == CallNumberPresentation.ALLOWED
+        if (ci.numberPresentation == CallPropertyPresentation.ALLOWED
                 || (ci.numberPresentation != presentation
-                        && presentation == CallNumberPresentation.ALLOWED)) {
+                        && presentation == CallPropertyPresentation.ALLOWED)) {
             // For all special strings, change number & numberPrentation.
             if (isCnapSpecialCaseRestricted(number)) {
                 number = context.getString(R.string.private_num);
-                ci.numberPresentation = CallNumberPresentation.RESTRICTED;
+                ci.numberPresentation = CallPropertyPresentation.RESTRICTED;
             } else if (isCnapSpecialCaseUnknown(number)) {
                 number = context.getString(R.string.unknown);
-                ci.numberPresentation = CallNumberPresentation.UNKNOWN;
+                ci.numberPresentation = CallPropertyPresentation.UNKNOWN;
             }
             Log.d(TAG, "SpecialCnap: number=" + toLogSafePhoneNumber(number)
                     + "; presentation now=" + ci.numberPresentation);
diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java
index 22ca88e..19b0267 100644
--- a/InCallUI/src/com/android/incallui/ContactInfoCache.java
+++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java
@@ -24,7 +24,7 @@
 import android.os.Looper;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
-import android.telecomm.CallNumberPresentation;
+import android.telecomm.CallPropertyPresentation;
 import android.text.TextUtils;
 
 import com.android.contacts.common.util.PhoneNumberHelper;
@@ -150,10 +150,10 @@
     private void findInfoQueryComplete(Call call, CallerInfo callerInfo, boolean isIncoming,
             boolean didLocalLookup) {
         final String callId = call.getCallId();
-        CallNumberPresentation presentationMode = call.getNumberPresentation();
+        int presentationMode = call.getNumberPresentation();
         if (callerInfo.contactExists || callerInfo.isEmergencyNumber() ||
                 callerInfo.isVoiceMailNumber()) {
-            presentationMode = CallNumberPresentation.ALLOWED;
+            presentationMode = CallPropertyPresentation.ALLOWED;
         }
 
         final ContactCacheEntry cacheEntry = buildEntry(mContext, callId,
@@ -298,7 +298,7 @@
     }
 
     private ContactCacheEntry buildEntry(Context context, String callId,
-            CallerInfo info, CallNumberPresentation presentation, boolean isIncoming) {
+            CallerInfo info, int presentation, boolean isIncoming) {
         // The actual strings we're going to display onscreen:
         Drawable photo = null;
 
@@ -335,7 +335,7 @@
      * Populate a cache entry from a call (which got converted into a caller info).
      */
     public static void populateCacheEntry(Context context, CallerInfo info, ContactCacheEntry cce,
-            CallNumberPresentation presentation, boolean isIncoming) {
+            int presentation, boolean isIncoming) {
         Preconditions.checkNotNull(info);
         String displayName = null;
         String displayNumber = null;
@@ -385,7 +385,7 @@
                     // (or potentially some other default based on the presentation.)
                     displayName = getPresentationString(context, presentation);
                     Log.d(TAG, "  ==> no name *or* number! displayName = " + displayName);
-                } else if (presentation != CallNumberPresentation.ALLOWED) {
+                } else if (presentation != CallPropertyPresentation.ALLOWED) {
                     // This case should never happen since the network should never send a phone #
                     // AND a restricted presentation. However we leave it here in case of weird
                     // network behavior
@@ -422,7 +422,7 @@
             } else {
                 // We do have a valid "name" in the CallerInfo. Display that
                 // in the "name" slot, and the phone number in the "number" slot.
-                if (presentation != CallNumberPresentation.ALLOWED) {
+                if (presentation != CallPropertyPresentation.ALLOWED) {
                     // This case should never happen since the network should never send a name
                     // AND a restricted presentation. However we leave it here in case of weird
                     // network behavior
@@ -473,12 +473,11 @@
     /**
      * Gets name strings based on some special presentation modes.
      */
-    private static String getPresentationString(Context context,
-            CallNumberPresentation presentation) {
+    private static String getPresentationString(Context context, int presentation) {
         String name = context.getString(R.string.unknown);
-        if (presentation == CallNumberPresentation.RESTRICTED) {
+        if (presentation == CallPropertyPresentation.RESTRICTED) {
             name = context.getString(R.string.private_num);
-        } else if (presentation == CallNumberPresentation.PAYPHONE) {
+        } else if (presentation == CallPropertyPresentation.PAYPHONE) {
             name = context.getString(R.string.payphone);
         }
         return name;
diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java
index 29d0b19..5ef7c5a 100644
--- a/InCallUI/src/com/android/incallui/InCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/InCallPresenter.java
@@ -223,12 +223,6 @@
         InCallState newState = getPotentialStateFromCallList(callList);
         newState = startOrFinishUi(newState);
 
-        // Renable notification shade and soft navigation buttons, if we are no longer in the
-        // incoming call screen
-        if (!newState.isIncoming()) {
-            TelecommAdapter.getInstance().setSystemBarNavigationEnabled(true);
-        }
-
         // Set the new state before announcing it to the world
         Log.i(this, "Phone switching state: " + mInCallState + " -> " + newState);
         mInCallState = newState;
@@ -427,9 +421,6 @@
         if (showing) {
             mIsActivityPreviouslyStarted = true;
         }
-
-        final boolean shouldLockBars = showing && mInCallState.isIncoming();
-        TelecommAdapter.getInstance().setSystemBarNavigationEnabled(!shouldLockBars);
     }
 
     /**
@@ -496,14 +487,14 @@
                     TelecommAdapter.getInstance().merge(activeCall.getCallId());
                     return true;
                 } else if (canSwap) {
-                    TelecommAdapter.getInstance().swap();
+                    TelecommAdapter.getInstance().swap(activeCall.getCallId());
                     return true;
                 }
             }
 
             // (3) Swap calls
             if (canSwap) {
-                TelecommAdapter.getInstance().swap();
+                TelecommAdapter.getInstance().swap(activeCall.getCallId());
                 return true;
             }
         }
diff --git a/InCallUI/src/com/android/incallui/InCallServiceImpl.java b/InCallUI/src/com/android/incallui/InCallServiceImpl.java
index 123e981..9fed90c 100644
--- a/InCallUI/src/com/android/incallui/InCallServiceImpl.java
+++ b/InCallUI/src/com/android/incallui/InCallServiceImpl.java
@@ -119,6 +119,9 @@
 
     private void updateCall(Call call, InCallCall telecommCall) {
         call.setHandle(telecommCall.getHandle());
+        call.setNumberPresentation(telecommCall.getHandlePresentation());
+        call.setCnapName(telecommCall.getCallerDisplayName());
+        call.setCnapNamePresentation(telecommCall.getCallerDisplayNamePresentation());
         call.setDisconnectCause(telecommCall.getDisconnectCauseCode());
         call.setCannedSmsResponses(telecommCall.getCannedSmsResponses());
         call.setCapabilities(telecommCall.getCapabilities());
@@ -129,7 +132,6 @@
         call.setState(translateState(telecommCall.getState()));
         call.setParentId(telecommCall.getParentCallId());
         call.setChildCallIds(telecommCall.getChildCallIds());
-        call.setFeatures(telecommCall.getFeatures());
 
         try {
             call.setCallVideoProvider(telecommCall.getCallVideoProvider());
diff --git a/InCallUI/src/com/android/incallui/TelecommAdapter.java b/InCallUI/src/com/android/incallui/TelecommAdapter.java
index 620a9bd..d22cb15 100644
--- a/InCallUI/src/com/android/incallui/TelecommAdapter.java
+++ b/InCallUI/src/com/android/incallui/TelecommAdapter.java
@@ -123,8 +123,12 @@
         }
     }
 
-    void swap() {
-        Log.wtf(this, "swap not implemented");
+    void swap(String callId) {
+         if (mAdapter != null) {
+            mAdapter.swapWithBackgroundCall(callId);
+        } else {
+            Log.e(this, "error swapWithBackgroundCall, mAdapter is null.");
+        }
     }
 
     void addCall() {
@@ -179,8 +183,4 @@
             Log.e(this, "error phoneAccountClicked, mAdapter is null");
         }
     }
-
-    void setSystemBarNavigationEnabled(boolean enable) {
-        // TODO(sail): Implement this.
-    }
 }