Telecom: Reset the duration after the CDMA call is accepted

In android original design, the duration of CDMA MO call is started from
the dial command sent, so it is not the real duration of the active time.

In this patch, CallsManager receive a new message to
reset the connection time for this call.

CRs-Fixed: 754497

Change-Id: Ib90283a3b5bbc7e8fa1d1e7ef09342ac19302f9c
diff --git a/src/com/android/server/telecom/Call.java b/src/com/android/server/telecom/Call.java
index 7b933db..eb9e114 100644
--- a/src/com/android/server/telecom/Call.java
+++ b/src/com/android/server/telecom/Call.java
@@ -782,6 +782,10 @@
         return mConnectTimeMillis;
     }
 
+    public void setConnectTimeMillis(long connectTimeMillis) {
+        mConnectTimeMillis = connectTimeMillis;
+    }
+
     int getConnectionCapabilities() {
         return mConnectionCapabilities;
     }
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index e4531b7..69a4ab7 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -2280,4 +2280,14 @@
             removeFromLch.setLocalCallHold(false);
         }
     }
+
+    void resetCdmaConnectionTime(Call call) {
+        call.setConnectTimeMillis(System.currentTimeMillis());
+        if (mCalls.contains(call)) {
+            for (CallsManagerListener listener : mListeners) {
+                listener.onCallStateChanged(call, CallState.ACTIVE, CallState.ACTIVE);
+            }
+            updateForegroundCall();
+        }
+    }
 }
diff --git a/src/com/android/server/telecom/ConnectionServiceWrapper.java b/src/com/android/server/telecom/ConnectionServiceWrapper.java
index 674f3e7..dbdc234 100644
--- a/src/com/android/server/telecom/ConnectionServiceWrapper.java
+++ b/src/com/android/server/telecom/ConnectionServiceWrapper.java
@@ -122,6 +122,27 @@
         }
 
         @Override
+        public void resetCdmaConnectionTime(String callId) {
+            long token = Binder.clearCallingIdentity();
+            try {
+                synchronized (mLock) {
+                    logIncoming("resetCdmaConnectionTime %s", callId);
+                    if (mCallIdMapper.isValidCallId(callId) ||
+                            mCallIdMapper.isValidConferenceId(callId)) {
+                        Call call = mCallIdMapper.getCall(callId);
+                        if (call != null) {
+                            mCallsManager.resetCdmaConnectionTime(call);
+                        } else {
+                            // Log.w(this, "resetCdmaConnectionTime, unknown call id: %s", msg.obj);
+                        }
+                    }
+                }
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override
         public void setVideoProvider(String callId, IVideoProvider videoProvider) {
             long token = Binder.clearCallingIdentity();
             try {