Add a new call direction parameter to conferences for multiparty

1) Refactor ParcelableConference - too many optional params
2) Add a new call direction parameter for external multiparty
call scenarios, where a conference is assigned a direction.

Bug: 153595501
Fixes: 154246448
Test: atest TelecomUnitTests TeleServiceTests
Merged-In: Icb576a07b9a7a81e228babfea53474be83da7593
Change-Id: Icb576a07b9a7a81e228babfea53474be83da7593
diff --git a/telecomm/java/android/telecom/Conference.java b/telecomm/java/android/telecom/Conference.java
index f019a9d..37611eb 100644
--- a/telecomm/java/android/telecom/Conference.java
+++ b/telecomm/java/android/telecom/Conference.java
@@ -1071,16 +1071,16 @@
      * This is applicable in two cases:
      * <ol>
      *     <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
-     *     temporarily "not a conference"; we need to present the correct address in the in-call
-     *     UI.</li>
+     *     temporarily "not a conference"; we need to present the correct address presentation in
+     *     the in-call UI.</li>
      *     <li>When the conference is not hosted on the current device, we need to know the address
-     *     information for the purpose of showing the original address to the user, as well as for
-     *     logging to the call log.</li>
+     *     presentation information for the purpose of showing the original address to the user, as
+     *     well as for logging to the call log.</li>
      * </ol>
-     * @return The address of the conference, or {@code null} if not applicable.
+     * @return The address presentation of the conference.
      * @hide
      */
-    public final int getAddressPresentation() {
+    public final @TelecomManager.Presentation int getAddressPresentation() {
         return mAddressPresentation;
     }
 
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index 0dca006..01ff12e 100755
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -1857,25 +1857,23 @@
         mConferenceById.put(callId, conference);
         mIdByConference.put(conference, callId);
         conference.addListener(mConferenceListener);
-        ParcelableConference parcelableConference = new ParcelableConference(
-                request.getAccountHandle(),
-                conference.getState(),
-                conference.getConnectionCapabilities(),
-                conference.getConnectionProperties(),
-                Collections.<String>emptyList(), //connectionIds
-                conference.getVideoProvider() == null ?
-                        null : conference.getVideoProvider().getInterface(),
-                conference.getVideoState(),
-                conference.getConnectTimeMillis(),
-                conference.getConnectionStartElapsedRealtimeMillis(),
-                conference.getStatusHints(),
-                conference.getExtras(),
-                conference.getAddress(),
-                conference.getAddressPresentation(),
-                conference.getCallerDisplayName(),
-                conference.getCallerDisplayNamePresentation(),
-                conference.getDisconnectCause(),
-                conference.isRingbackRequested());
+        ParcelableConference parcelableConference = new ParcelableConference.Builder(
+                request.getAccountHandle(), conference.getState())
+                .setConnectionCapabilities(conference.getConnectionCapabilities())
+                .setConnectionProperties(conference.getConnectionProperties())
+                .setVideoAttributes(conference.getVideoProvider() == null
+                                ? null : conference.getVideoProvider().getInterface(),
+                        conference.getVideoState())
+                .setConnectTimeMillis(conference.getConnectTimeMillis(),
+                        conference.getConnectionStartElapsedRealtimeMillis())
+                .setStatusHints(conference.getStatusHints())
+                .setExtras(conference.getExtras())
+                .setAddress(conference.getAddress(), conference.getAddressPresentation())
+                .setCallerDisplayName(conference.getCallerDisplayName(),
+                        conference.getCallerDisplayNamePresentation())
+                .setDisconnectCause(conference.getDisconnectCause())
+                .setRingbackRequested(conference.isRingbackRequested())
+                .build();
         if (conference.getState() != Connection.STATE_DISCONNECTED) {
             conference.setTelecomCallId(callId);
             mAdapter.setVideoProvider(callId, conference.getVideoProvider());
@@ -2476,23 +2474,25 @@
                 }
             }
             conference.setTelecomCallId(id);
-            ParcelableConference parcelableConference = new ParcelableConference(
-                    conference.getPhoneAccountHandle(),
-                    conference.getState(),
-                    conference.getConnectionCapabilities(),
-                    conference.getConnectionProperties(),
-                    connectionIds,
-                    conference.getVideoProvider() == null ?
-                            null : conference.getVideoProvider().getInterface(),
-                    conference.getVideoState(),
-                    conference.getConnectTimeMillis(),
-                    conference.getConnectionStartElapsedRealtimeMillis(),
-                    conference.getStatusHints(),
-                    conference.getExtras(),
-                    conference.getAddress(),
-                    conference.getAddressPresentation(),
-                    conference.getCallerDisplayName(),
-                    conference.getCallerDisplayNamePresentation());
+            ParcelableConference parcelableConference = new ParcelableConference.Builder(
+                    conference.getPhoneAccountHandle(), conference.getState())
+                    .setConnectionCapabilities(conference.getConnectionCapabilities())
+                    .setConnectionProperties(conference.getConnectionProperties())
+                    .setConnectionIds(connectionIds)
+                    .setVideoAttributes(conference.getVideoProvider() == null
+                                    ? null : conference.getVideoProvider().getInterface(),
+                            conference.getVideoState())
+                    .setConnectTimeMillis(conference.getConnectTimeMillis(),
+                            conference.getConnectionStartElapsedRealtimeMillis())
+                    .setStatusHints(conference.getStatusHints())
+                    .setExtras(conference.getExtras())
+                    .setAddress(conference.getAddress(), conference.getAddressPresentation())
+                    .setCallerDisplayName(conference.getCallerDisplayName(),
+                            conference.getCallerDisplayNamePresentation())
+                    .setDisconnectCause(conference.getDisconnectCause())
+                    .setRingbackRequested(conference.isRingbackRequested())
+                    .setCallDirection(conference.getCallDirection())
+                    .build();
 
             mAdapter.addConferenceCall(id, parcelableConference);
             mAdapter.setVideoProvider(id, conference.getVideoProvider());
diff --git a/telecomm/java/android/telecom/ParcelableConference.java b/telecomm/java/android/telecom/ParcelableConference.java
index 90b69a3..1f8aafb 100644
--- a/telecomm/java/android/telecom/ParcelableConference.java
+++ b/telecomm/java/android/telecom/ParcelableConference.java
@@ -22,6 +22,7 @@
 import android.os.Parcelable;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import com.android.internal.telecom.IVideoProvider;
@@ -32,25 +33,130 @@
  */
 public final class ParcelableConference implements Parcelable {
 
-    private PhoneAccountHandle mPhoneAccount;
-    private int mState;
-    private int mConnectionCapabilities;
-    private int mConnectionProperties;
-    private List<String> mConnectionIds;
-    private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
+    public static final class Builder {
+        private final PhoneAccountHandle mPhoneAccount;
+        private final int mState;
+        private int mConnectionCapabilities;
+        private int mConnectionProperties;
+        private List<String> mConnectionIds = Collections.emptyList();
+        private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
+        private IVideoProvider mVideoProvider;
+        private int mVideoState = VideoProfile.STATE_AUDIO_ONLY;
+        private StatusHints mStatusHints;
+        private Bundle mExtras;
+        private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
+        private Uri mAddress;
+        private int mAddressPresentation = TelecomManager.PRESENTATION_UNKNOWN;
+        private String mCallerDisplayName;
+        private int mCallerDisplayNamePresentation = TelecomManager.PRESENTATION_UNKNOWN;;
+        private DisconnectCause mDisconnectCause;
+        private boolean mRingbackRequested;
+        private int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
+
+        public Builder(
+                PhoneAccountHandle phoneAccount,
+                int state) {
+            mPhoneAccount = phoneAccount;
+            mState = state;
+        }
+
+        public Builder setDisconnectCause(DisconnectCause cause) {
+            mDisconnectCause = cause;
+            return this;
+        }
+
+        public Builder setRingbackRequested(boolean requested) {
+            mRingbackRequested = requested;
+            return this;
+        }
+
+        public Builder setCallerDisplayName(String callerDisplayName,
+                @TelecomManager.Presentation int callerDisplayNamePresentation) {
+            mCallerDisplayName = callerDisplayName;
+            mCallerDisplayNamePresentation = callerDisplayNamePresentation;
+            return this;
+        }
+
+        public Builder setAddress(Uri address,
+                @TelecomManager.Presentation int addressPresentation) {
+            mAddress = address;
+            mAddressPresentation = addressPresentation;
+            return this;
+        }
+
+        public Builder setExtras(Bundle extras) {
+            mExtras = extras;
+            return this;
+        }
+
+        public Builder setStatusHints(StatusHints hints) {
+            mStatusHints = hints;
+            return this;
+        }
+
+        public Builder setConnectTimeMillis(long connectTimeMillis, long connectElapsedTimeMillis) {
+            mConnectTimeMillis = connectTimeMillis;
+            mConnectElapsedTimeMillis = connectElapsedTimeMillis;
+            return this;
+        }
+
+        public Builder setVideoAttributes(IVideoProvider provider,
+                @VideoProfile.VideoState int videoState) {
+            mVideoProvider = provider;
+            mVideoState = videoState;
+            return this;
+        }
+
+        public Builder setConnectionIds(List<String> connectionIds) {
+            mConnectionIds = connectionIds;
+            return this;
+        }
+
+        public Builder setConnectionProperties(int properties) {
+            mConnectionProperties = properties;
+            return this;
+        }
+
+        public Builder setConnectionCapabilities(int capabilities) {
+            mConnectionCapabilities = capabilities;
+            return this;
+        }
+
+        public Builder setCallDirection(int callDirection) {
+            mCallDirection = callDirection;
+            return this;
+        }
+
+        public ParcelableConference build() {
+            return new ParcelableConference(mPhoneAccount, mState, mConnectionCapabilities,
+                    mConnectionProperties, mConnectionIds, mVideoProvider, mVideoState,
+                    mConnectTimeMillis, mConnectElapsedTimeMillis, mStatusHints, mExtras, mAddress,
+                    mAddressPresentation, mCallerDisplayName, mCallerDisplayNamePresentation,
+                    mDisconnectCause, mRingbackRequested, mCallDirection);
+        }
+    }
+
+
+    private final PhoneAccountHandle mPhoneAccount;
+    private final int mState;
+    private final int mConnectionCapabilities;
+    private final int mConnectionProperties;
+    private final List<String> mConnectionIds;
+    private final long mConnectTimeMillis;
     private final IVideoProvider mVideoProvider;
     private final int mVideoState;
-    private StatusHints mStatusHints;
-    private Bundle mExtras;
-    private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
+    private final StatusHints mStatusHints;
+    private final Bundle mExtras;
+    private final long mConnectElapsedTimeMillis;
     private final Uri mAddress;
     private final int mAddressPresentation;
     private final String mCallerDisplayName;
     private final int mCallerDisplayNamePresentation;
-    private DisconnectCause mDisconnectCause;
-    private boolean mRingbackRequested;
+    private final DisconnectCause mDisconnectCause;
+    private final boolean mRingbackRequested;
+    private final int mCallDirection;
 
-    public ParcelableConference(
+    private ParcelableConference(
             PhoneAccountHandle phoneAccount,
             int state,
             int connectionCapabilities,
@@ -67,31 +173,8 @@
             String callerDisplayName,
             int callerDisplayNamePresentation,
             DisconnectCause disconnectCause,
-            boolean ringbackRequested) {
-        this(phoneAccount, state, connectionCapabilities, connectionProperties, connectionIds,
-                videoProvider, videoState, connectTimeMillis, connectElapsedTimeMillis,
-                statusHints, extras, address, addressPresentation, callerDisplayName,
-                callerDisplayNamePresentation);
-        mDisconnectCause = disconnectCause;
-        mRingbackRequested = ringbackRequested;
-    }
-
-    public ParcelableConference(
-            PhoneAccountHandle phoneAccount,
-            int state,
-            int connectionCapabilities,
-            int connectionProperties,
-            List<String> connectionIds,
-            IVideoProvider videoProvider,
-            int videoState,
-            long connectTimeMillis,
-            long connectElapsedTimeMillis,
-            StatusHints statusHints,
-            Bundle extras,
-            Uri address,
-            int addressPresentation,
-            String callerDisplayName,
-            int callerDisplayNamePresentation) {
+            boolean ringbackRequested,
+            int callDirection) {
         mPhoneAccount = phoneAccount;
         mState = state;
         mConnectionCapabilities = connectionCapabilities;
@@ -107,8 +190,9 @@
         mAddressPresentation = addressPresentation;
         mCallerDisplayName = callerDisplayName;
         mCallerDisplayNamePresentation = callerDisplayNamePresentation;
-        mDisconnectCause = null;
-        mRingbackRequested = false;
+        mDisconnectCause = disconnectCause;
+        mRingbackRequested = ringbackRequested;
+        mCallDirection = callDirection;
     }
 
     @Override
@@ -134,6 +218,8 @@
                 .append(mRingbackRequested)
                 .append(", disconnectCause: ")
                 .append(mDisconnectCause)
+                .append(", callDirection: ")
+                .append(mCallDirection)
                 .toString();
     }
 
@@ -192,10 +278,15 @@
     public boolean isRingbackRequested() {
         return mRingbackRequested;
     }
+
     public int getHandlePresentation() {
         return mAddressPresentation;
     }
 
+    public int getCallDirection() {
+        return mCallDirection;
+    }
+
     public static final @android.annotation.NonNull Parcelable.Creator<ParcelableConference> CREATOR =
             new Parcelable.Creator<ParcelableConference> () {
         @Override
@@ -220,12 +311,13 @@
             int callerDisplayNamePresentation = source.readInt();
             DisconnectCause disconnectCause = source.readParcelable(classLoader);
             boolean isRingbackRequested = source.readInt() == 1;
+            int callDirection = source.readInt();
 
             return new ParcelableConference(phoneAccount, state, capabilities, properties,
                     connectionIds, videoCallProvider, videoState, connectTimeMillis,
                     connectElapsedTimeMillis, statusHints, extras, address, addressPresentation,
                     callerDisplayName, callerDisplayNamePresentation, disconnectCause,
-                    isRingbackRequested);
+                    isRingbackRequested, callDirection);
         }
 
         @Override
@@ -261,5 +353,6 @@
         destination.writeInt(mCallerDisplayNamePresentation);
         destination.writeParcelable(mDisconnectCause, 0);
         destination.writeInt(mRingbackRequested ? 1 : 0);
+        destination.writeInt(mCallDirection);
     }
 }