Misc Telecomm API changes - impl

This CL contains plumbing for Telecomm API changes made in
ag/501321.

As a cleanup I also made InCallController listen to changes
to calls directly instead of using CallsManager.

Change-Id: Iaffe0b84cea6003f2a9b9d8b30676743d2b236d4
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index f5229cc..d91ee11 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -23,6 +23,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.provider.ContactsContract.Contacts;
+import android.telecomm.CallPropertyPresentation;
 import android.telecomm.CallServiceDescriptor;
 import android.telecomm.CallState;
 import android.telecomm.ConnectionRequest;
@@ -48,6 +49,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
+import java.util.Objects;
 import java.util.Set;
 
 /**
@@ -74,10 +76,11 @@
         void onChildrenChanged(Call call);
         void onCannedSmsResponsesLoaded(Call call);
         void onCallVideoProviderChanged(Call call);
-        void onFeaturesChanged(Call call);
         void onCallerInfoChanged(Call call);
         void onAudioModeIsVoipChanged(Call call);
         void onStatusHintsChanged(Call call);
+        void onHandleChanged(Call call);
+        void onCallerDisplayNameChanged(Call call);
     }
 
     abstract static class ListenerBase implements Listener {
@@ -110,13 +113,15 @@
         @Override
         public void onCallVideoProviderChanged(Call call) {}
         @Override
-        public void onFeaturesChanged(Call call) {}
-        @Override
         public void onCallerInfoChanged(Call call) {}
         @Override
         public void onAudioModeIsVoipChanged(Call call) {}
         @Override
         public void onStatusHintsChanged(Call call) {}
+        @Override
+        public void onHandleChanged(Call call) {}
+        @Override
+        public void onCallerDisplayNameChanged(Call call) {}
     }
 
     private static final OnQueryCompleteListener sCallerInfoQueryListener =
@@ -171,6 +176,15 @@
     /** The handle with which to establish this call. */
     private Uri mHandle;
 
+    /** The {@link CallPropertyPresentation} that controls how the handle is shown. */
+    private int mHandlePresentation;
+
+    /** The caller display name (CNAP) set by the connection service. */
+    private String mCallerDisplayName;
+
+    /** The {@link CallPropertyPresentation} that controls how the caller display name is shown. */
+    private int mCallerDisplayNamePresentation;
+
     /**
      * The connection service which is attempted or already connecting this call.
      */
@@ -232,9 +246,6 @@
 
     private ICallVideoProvider mCallVideoProvider;
 
-    /** Features associated with the call which the InCall UI may wish to show icons for. */
-    private int mFeatures;
-
     private boolean mAudioModeIsVoip;
     private StatusHints mStatusHints;
 
@@ -258,7 +269,7 @@
     Call(Uri handle, GatewayInfo gatewayInfo, PhoneAccount account,
             boolean isIncoming, boolean isConference) {
         mState = isConference ? CallState.ACTIVE : CallState.NEW;
-        setHandle(handle);
+        setHandle(handle, CallPropertyPresentation.ALLOWED);
         mGatewayInfo = gatewayInfo;
         mPhoneAccount = account;
         mIsIncoming = isIncoming;
@@ -326,12 +337,39 @@
         return mHandle;
     }
 
-    void setHandle(Uri handle) {
-        if ((mHandle == null && handle != null) || (mHandle != null && !mHandle.equals(handle))) {
+    int getHandlePresentation() {
+        return mHandlePresentation;
+    }
+
+    void setHandle(Uri handle, int presentation) {
+        if (!Objects.equals(handle, mHandle) || presentation != mHandlePresentation) {
             mHandle = handle;
+            mHandlePresentation = presentation;
             mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber(
                     TelecommApp.getInstance(), mHandle.getSchemeSpecificPart());
             startCallerInfoLookup();
+            for (Listener l : mListeners) {
+                l.onHandleChanged(this);
+            }
+        }
+    }
+
+    String getCallerDisplayName() {
+        return mCallerDisplayName;
+    }
+
+    int getCallerDisplayNamePresentation() {
+        return mCallerDisplayNamePresentation;
+    }
+
+    void setCallerDisplayName(String callerDisplayName, int presentation) {
+        if (!TextUtils.equals(callerDisplayName, mCallerDisplayName) ||
+                presentation != mCallerDisplayNamePresentation) {
+            mCallerDisplayName = callerDisplayName;
+            mCallerDisplayNamePresentation = presentation;
+            for (Listener l : mListeners) {
+                l.onCallerDisplayNameChanged(this);
+            }
         }
     }
 
@@ -501,7 +539,7 @@
         mDirectToVoicemailQueryPending = true;
 
         // Setting the handle triggers the caller info lookup code.
-        setHandle(request.getHandle());
+        setHandle(request.getHandle(), CallPropertyPresentation.ALLOWED);
 
         // Timeout the direct-to-voicemail lookup execution so that we dont wait too long before
         // showing the user the incoming call screen.
@@ -772,6 +810,10 @@
         // TODO(santoscordon): todo
     }
 
+    void swapWithBackgroundCall() {
+        mConnectionService.swapWithBackgroundCall(this);
+    }
+
     void setParentCall(Call parentCall) {
         if (parentCall == this) {
             Log.e(this, new Exception(), "setting the parent to self");
@@ -1024,28 +1066,6 @@
     }
 
     /**
-     * Returns the features of this call.
-     *
-     * @return The features of this call.
-     */
-    public int getFeatures() {
-        return mFeatures;
-    }
-
-    /**
-     * Set the features associated with the call and notify any listeners of the change.
-     *
-     * @param features The features.
-     */
-    public void setFeatures(int features) {
-        Log.d(this, "setFeatures: %d", features);
-        mFeatures = features;
-        for (Listener l : mListeners) {
-            l.onFeaturesChanged(Call.this);
-        }
-    }
-
-    /**
      * The current video state for the call.
      * Valid values: {@link android.telecomm.VideoCallProfile#VIDEO_STATE_AUDIO_ONLY},
      * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_BIDIRECTIONAL},