Merge "Track conference start in system elapsed time." am: 3b166fba8a am: 49042dc67c
am: 55967b462c

Change-Id: I5a7561dd09405bcdc38926bd331f5ffd8019ec2f
diff --git a/api/current.txt b/api/current.txt
index 5ea7909..eb6cc4d 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -38991,6 +38991,7 @@
     method public final void setActive();
     method public final void setConferenceableConnections(java.util.List<android.telecom.Connection>);
     method public final void setConnectionCapabilities(int);
+    method public final void setConnectionElapsedTime(long);
     method public final void setConnectionProperties(int);
     method public final void setConnectionTime(long);
     method public final void setDialing();
diff --git a/api/system-current.txt b/api/system-current.txt
index 1550b10..e1f59a3 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -42241,6 +42241,7 @@
     method public final void setConferenceableConnections(java.util.List<android.telecom.Connection>);
     method public final deprecated void setConnectTimeMillis(long);
     method public final void setConnectionCapabilities(int);
+    method public final void setConnectionElapsedTime(long);
     method public final void setConnectionProperties(int);
     method public final void setConnectionTime(long);
     method public final void setDialing();
diff --git a/api/test-current.txt b/api/test-current.txt
index 9a16d27..574788c 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -39234,6 +39234,7 @@
     method public final void setActive();
     method public final void setConferenceableConnections(java.util.List<android.telecom.Connection>);
     method public final void setConnectionCapabilities(int);
+    method public final void setConnectionElapsedTime(long);
     method public final void setConnectionProperties(int);
     method public final void setConnectionTime(long);
     method public final void setDialing();
diff --git a/telecomm/java/android/telecom/Conference.java b/telecomm/java/android/telecom/Conference.java
index db49391..5fcff18 100644
--- a/telecomm/java/android/telecom/Conference.java
+++ b/telecomm/java/android/telecom/Conference.java
@@ -20,6 +20,7 @@
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
 import android.os.Bundle;
+import android.os.SystemClock;
 import android.telecom.Connection.VideoProvider;
 import android.util.ArraySet;
 
@@ -81,6 +82,7 @@
     private int mConnectionProperties;
     private String mDisconnectMessage;
     private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
+    private long mConnectElapsedTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
     private StatusHints mStatusHints;
     private Bundle mExtras;
     private Set<String> mPreviousExtraKeys;
@@ -582,7 +584,11 @@
     }
 
     /**
-     * Sets the connection start time of the {@code Conference}.
+     * Sets the connection start time of the {@code Conference}.  Should be specified in wall-clock
+     * time returned by {@link System#currentTimeMillis()}.
+     * <p>
+     * When setting the connection time, you should always set the connection elapsed time via
+     * {@link #setConnectionElapsedTime(long)}.
      *
      * @param connectionTimeMillis The connection time, in milliseconds.
      */
@@ -591,6 +597,20 @@
     }
 
     /**
+     * Sets the elapsed time since system boot when the {@link Conference} was connected.
+     * This is used to determine the duration of the {@link Conference}.
+     * <p>
+     * When setting the connection elapsed time, you should always set the connection time via
+     * {@link #setConnectionTime(long)}.
+     *
+     * @param connectionElapsedTime The connection time, as measured by
+     * {@link SystemClock#elapsedRealtime()}.
+     */
+    public final void setConnectionElapsedTime(long connectionElapsedTime) {
+        mConnectElapsedTimeMillis = connectionElapsedTime;
+    }
+
+    /**
      * @hide
      * @deprecated Use {@link #getConnectionTime}.
      */
@@ -612,6 +632,21 @@
     }
 
     /**
+     * Retrieves the connection start time of the {@link Conference}, if specified.  A value of
+     * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
+     * of the conference.
+     *
+     * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
+     * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
+     *
+     * @return The elapsed time at which the {@link Conference} was connected.
+     * @hide
+     */
+    public final long getConnectElapsedTime() {
+        return mConnectElapsedTimeMillis;
+    }
+
+    /**
      * Inform this Conference that the state of its audio output has been changed externally.
      *
      * @param state The new audio state.
diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java
index f5d37bb..ef760a05 100644
--- a/telecomm/java/android/telecom/Connection.java
+++ b/telecomm/java/android/telecom/Connection.java
@@ -20,7 +20,6 @@
 import com.android.internal.telecom.IVideoCallback;
 import com.android.internal.telecom.IVideoProvider;
 
-import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
@@ -37,14 +36,13 @@
 import android.os.Message;
 import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
+import android.os.SystemClock;
 import android.util.ArraySet;
 import android.view.Surface;
 
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -1696,6 +1694,7 @@
     private VideoProvider mVideoProvider;
     private boolean mAudioModeIsVoip;
     private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
+    private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
     private StatusHints mStatusHints;
     private int mVideoState;
     private DisconnectCause mDisconnectCause;
@@ -1840,6 +1839,22 @@
     }
 
     /**
+     * Retrieves the connection start time of the {@link Connection}, if specified.  A value of
+     * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
+     * start time of the conference.
+     *
+     * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
+     * changes do not impact the call duration.
+     *
+     * @return The time at which the {@link Connection} was connected.
+     *
+     * @hide
+     */
+    public final long getConnectElapsedTimeMillis() {
+        return mConnectElapsedTimeMillis;
+    }
+
+    /**
      * @return The status hints for this connection.
      */
     public final StatusHints getStatusHints() {
@@ -2250,7 +2265,8 @@
      * Sets the time at which a call became active on this Connection. This is set only
      * when a conference call becomes active on this connection.
      *
-     * @param connectionTimeMillis The connection time, in milliseconds.
+     * @param connectTimeMillis The connection time, in milliseconds.  Should be set using a value
+     *                          obtained from {@link System#currentTimeMillis()}.
      *
      * @hide
      */
@@ -2259,6 +2275,19 @@
     }
 
     /**
+     * Sets the time at which a call became active on this Connection. This is set only
+     * when a conference call becomes active on this connection.
+     *
+     * @param connectElapsedTimeMillis The connection time, in milliseconds.  Stored in the format
+     *                              {@link SystemClock#elapsedRealtime()}.
+     *
+     * @hide
+     */
+    public final void setConnectElapsedTimeMillis(long connectElapsedTimeMillis) {
+        mConnectElapsedTimeMillis = connectElapsedTimeMillis;
+    }
+
+    /**
      * Sets the label and icon status to display in the in-call UI.
      *
      * @param statusHints The status label and icon to set.
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index f78e4276..e814d02 100644
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -1405,6 +1405,7 @@
                         connection.isRingbackRequested(),
                         connection.getAudioModeIsVoip(),
                         connection.getConnectTimeMillis(),
+                        connection.getConnectElapsedTimeMillis(),
                         connection.getStatusHints(),
                         connection.getDisconnectCause(),
                         createIdList(connection.getConferenceables()),
@@ -1822,6 +1823,7 @@
                             null : conference.getVideoProvider().getInterface(),
                     conference.getVideoState(),
                     conference.getConnectTimeMillis(),
+                    conference.getConnectElapsedTime(),
                     conference.getStatusHints(),
                     conference.getExtras());
 
@@ -1887,6 +1889,7 @@
                     connection.isRingbackRequested(),
                     connection.getAudioModeIsVoip(),
                     connection.getConnectTimeMillis(),
+                    connection.getConnectElapsedTimeMillis(),
                     connection.getStatusHints(),
                     connection.getDisconnectCause(),
                     emptyList,
diff --git a/telecomm/java/android/telecom/ParcelableConference.java b/telecomm/java/android/telecom/ParcelableConference.java
index f5689d8..a6221d4 100644
--- a/telecomm/java/android/telecom/ParcelableConference.java
+++ b/telecomm/java/android/telecom/ParcelableConference.java
@@ -41,6 +41,7 @@
     private final int mVideoState;
     private StatusHints mStatusHints;
     private Bundle mExtras;
+    private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
 
     public ParcelableConference(
             PhoneAccountHandle phoneAccount,
@@ -51,6 +52,7 @@
             IVideoProvider videoProvider,
             int videoState,
             long connectTimeMillis,
+            long connectElapsedTimeMillis,
             StatusHints statusHints,
             Bundle extras) {
         mPhoneAccount = phoneAccount;
@@ -58,12 +60,12 @@
         mConnectionCapabilities = connectionCapabilities;
         mConnectionProperties = connectionProperties;
         mConnectionIds = connectionIds;
-        mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
         mVideoProvider = videoProvider;
         mVideoState = videoState;
         mConnectTimeMillis = connectTimeMillis;
         mStatusHints = statusHints;
         mExtras = extras;
+        mConnectElapsedTimeMillis = connectElapsedTimeMillis;
     }
 
     @Override
@@ -111,6 +113,11 @@
     public long getConnectTimeMillis() {
         return mConnectTimeMillis;
     }
+
+    public long getConnectElapsedTimeMillis() {
+        return mConnectElapsedTimeMillis;
+    }
+
     public IVideoProvider getVideoProvider() {
         return mVideoProvider;
     }
@@ -144,10 +151,11 @@
             StatusHints statusHints = source.readParcelable(classLoader);
             Bundle extras = source.readBundle(classLoader);
             int properties = source.readInt();
+            long connectElapsedTimeMillis = source.readLong();
 
             return new ParcelableConference(phoneAccount, state, capabilities, properties,
-                    connectionIds, videoCallProvider, videoState, connectTimeMillis, statusHints,
-                    extras);
+                    connectionIds, videoCallProvider, videoState, connectTimeMillis,
+                    connectElapsedTimeMillis, statusHints, extras);
         }
 
         @Override
@@ -176,5 +184,6 @@
         destination.writeParcelable(mStatusHints, 0);
         destination.writeBundle(mExtras);
         destination.writeInt(mConnectionProperties);
+        destination.writeLong(mConnectElapsedTimeMillis);
     }
 }
diff --git a/telecomm/java/android/telecom/ParcelableConnection.java b/telecomm/java/android/telecom/ParcelableConnection.java
index 434abf5..61d5a12 100644
--- a/telecomm/java/android/telecom/ParcelableConnection.java
+++ b/telecomm/java/android/telecom/ParcelableConnection.java
@@ -47,6 +47,7 @@
     private final boolean mRingbackRequested;
     private final boolean mIsVoipAudioMode;
     private final long mConnectTimeMillis;
+    private final long mConnectElapsedTimeMillis;
     private final StatusHints mStatusHints;
     private final DisconnectCause mDisconnectCause;
     private final List<String> mConferenceableConnectionIds;
@@ -69,6 +70,7 @@
             boolean ringbackRequested,
             boolean isVoipAudioMode,
             long connectTimeMillis,
+            long connectElapsedTimeMillis,
             StatusHints statusHints,
             DisconnectCause disconnectCause,
             List<String> conferenceableConnectionIds,
@@ -77,7 +79,8 @@
         this(phoneAccount, state, capabilities, properties, supportedAudioRoutes, address,
                 addressPresentation, callerDisplayName, callerDisplayNamePresentation,
                 videoProvider, videoState, ringbackRequested, isVoipAudioMode, connectTimeMillis,
-                statusHints, disconnectCause, conferenceableConnectionIds, extras);
+                connectElapsedTimeMillis, statusHints, disconnectCause, conferenceableConnectionIds,
+                extras);
         mParentCallId = parentCallId;
     }
 
@@ -97,6 +100,7 @@
             boolean ringbackRequested,
             boolean isVoipAudioMode,
             long connectTimeMillis,
+            long connectElapsedTimeMillis,
             StatusHints statusHints,
             DisconnectCause disconnectCause,
             List<String> conferenceableConnectionIds,
@@ -115,6 +119,7 @@
         mRingbackRequested = ringbackRequested;
         mIsVoipAudioMode = isVoipAudioMode;
         mConnectTimeMillis = connectTimeMillis;
+        mConnectElapsedTimeMillis = connectElapsedTimeMillis;
         mStatusHints = statusHints;
         mDisconnectCause = disconnectCause;
         mConferenceableConnectionIds = conferenceableConnectionIds;
@@ -190,6 +195,10 @@
         return mConnectTimeMillis;
     }
 
+    public long getConnectElapsedTimeMillis() {
+        return mConnectElapsedTimeMillis;
+    }
+
     public final StatusHints getStatusHints() {
         return mStatusHints;
     }
@@ -255,6 +264,7 @@
             int properties = source.readInt();
             int supportedAudioRoutes = source.readInt();
             String parentCallId = source.readString();
+            long connectElapsedTimeMillis = source.readLong();
 
             return new ParcelableConnection(
                     phoneAccount,
@@ -271,6 +281,7 @@
                     ringbackRequested,
                     audioModeIsVoip,
                     connectTimeMillis,
+                    connectElapsedTimeMillis,
                     statusHints,
                     disconnectCause,
                     conferenceableConnectionIds,
@@ -313,5 +324,6 @@
         destination.writeInt(mConnectionProperties);
         destination.writeInt(mSupportedAudioRoutes);
         destination.writeString(mParentCallId);
+        destination.writeLong(mConnectElapsedTimeMillis);
     }
 }