Update Dialer source to latest internal Google revision.

Previously, Android's Dialer app was developed in an internal Google
source control system and only exported to public during AOSP drops.

The Dialer team is now switching to a public development model similar
to the telephony team.

This CL represents all internal Google changes that were committed to
Dialer between the public O release and today's tip of tree on internal
master. This CL squashes those changes into a single commit.
In subsequent changes, changes will be exported on a per-commit basis.

Test: make, flash install, run
Merged-In: I45270eaa8ce732d71a1bd84b08c7fa0e99af3160
Change-Id: I529aaeb88535b9533c0ae4ef4e6c1222d4e0f1c8
PiperOrigin-RevId: 167068436
diff --git a/java/com/android/incallui/InCallActivity.java b/java/com/android/incallui/InCallActivity.java
index cc9a8e4..178a404 100644
--- a/java/com/android/incallui/InCallActivity.java
+++ b/java/com/android/incallui/InCallActivity.java
@@ -21,6 +21,7 @@
 import android.graphics.drawable.GradientDrawable;
 import android.graphics.drawable.GradientDrawable.Orientation;
 import android.os.Bundle;
+import android.os.Trace;
 import android.support.annotation.ColorInt;
 import android.support.annotation.FloatRange;
 import android.support.annotation.NonNull;
@@ -28,16 +29,16 @@
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v4.graphics.ColorUtils;
-import android.telecom.DisconnectCause;
 import android.telephony.TelephonyManager;
 import android.view.KeyEvent;
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
 import com.android.dialer.common.Assert;
-import com.android.dialer.common.ConfigProviderBindings;
 import com.android.dialer.common.LogUtil;
 import com.android.dialer.compat.ActivityCompat;
+import com.android.dialer.configprovider.ConfigProviderBindings;
+import com.android.dialer.logging.DialerImpression;
 import com.android.dialer.logging.Logger;
 import com.android.dialer.logging.ScreenEvent;
 import com.android.incallui.answer.bindings.AnswerBindings;
@@ -48,6 +49,8 @@
 import com.android.incallui.call.CallList;
 import com.android.incallui.call.DialerCall;
 import com.android.incallui.call.DialerCall.State;
+import com.android.incallui.callpending.CallPendingActivity;
+import com.android.incallui.disconnectdialog.DisconnectMessage;
 import com.android.incallui.incall.bindings.InCallBindings;
 import com.android.incallui.incall.protocol.InCallButtonUiDelegate;
 import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory;
@@ -67,6 +70,10 @@
         VideoCallScreenDelegateFactory,
         PseudoScreenState.StateChangedListener {
 
+  public static final int PENDING_INTENT_REQUEST_CODE_NON_FULL_SCREEN = 0;
+  public static final int PENDING_INTENT_REQUEST_CODE_FULL_SCREEN = 1;
+  public static final int PENDING_INTENT_REQUEST_CODE_BUBBLE = 2;
+
   private static final String TAG_IN_CALL_SCREEN = "tag_in_call_screen";
   private static final String TAG_ANSWER_SCREEN = "tag_answer_screen";
   private static final String TAG_VIDEO_CALL_SCREEN = "tag_video_call_screen";
@@ -112,9 +119,15 @@
 
   @Override
   protected void onCreate(Bundle icicle) {
+    Trace.beginSection("InCallActivity.onCreate");
     LogUtil.i("InCallActivity.onCreate", "");
     super.onCreate(icicle);
 
+    if (getIntent().getBooleanExtra(ReturnToCallController.RETURN_TO_CALL_EXTRA_KEY, false)) {
+      Logger.get(this).logImpression(DialerImpression.Type.BUBBLE_PRIMARY_BUTTON_RETURN_TO_CALL);
+      getIntent().removeExtra(ReturnToCallController.RETURN_TO_CALL_EXTRA_KEY);
+    }
+
     if (icicle != null) {
       didShowAnswerScreen = icicle.getBoolean(DID_SHOW_ANSWER_SCREEN_KEY);
       didShowInCallScreen = icicle.getBoolean(DID_SHOW_IN_CALL_SCREEN_KEY);
@@ -129,6 +142,8 @@
             View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
 
     pseudoBlackScreenOverlay = findViewById(R.id.psuedo_black_screen_overlay);
+    sendBroadcast(CallPendingActivity.getFinishBroadcast());
+    Trace.endSection();
   }
 
   @Override
@@ -144,6 +159,7 @@
 
   @Override
   protected void onStart() {
+    Trace.beginSection("InCallActivity.onStart");
     LogUtil.i("InCallActivity.onStart", "");
     super.onStart();
     isVisible = true;
@@ -154,40 +170,49 @@
       // Hide the dialpad because there may not be enough room
       showDialpadFragment(false, false);
     }
+    Trace.endSection();
   }
 
   @Override
   protected void onResume() {
+    Trace.beginSection("InCallActivity.onResume");
     LogUtil.i("InCallActivity.onResume", "");
     super.onResume();
     common.onResume();
     PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState();
     pseudoScreenState.addListener(this);
     onPseudoScreenStateChanged(pseudoScreenState.isOn());
+    Trace.endSection();
   }
 
   /** onPause is guaranteed to be called when the InCallActivity goes in the background. */
   @Override
   protected void onPause() {
+    Trace.beginSection("InCallActivity.onPause");
     LogUtil.i("InCallActivity.onPause", "");
     super.onPause();
     common.onPause();
     InCallPresenter.getInstance().getPseudoScreenState().removeListener(this);
+    Trace.endSection();
   }
 
   @Override
   protected void onStop() {
+    Trace.beginSection("InCallActivity.onStop");
     LogUtil.i("InCallActivity.onStop", "");
     super.onStop();
     common.onStop();
     isVisible = false;
+    Trace.endSection();
   }
 
   @Override
   protected void onDestroy() {
+    Trace.beginSection("InCallActivity.onDestroy");
     LogUtil.i("InCallActivity.onDestroy", "");
     super.onDestroy();
     common.onDestroy();
+    Trace.endSection();
   }
 
   @Override
@@ -393,8 +418,8 @@
     common.showPostCharWaitDialog(callId, chars);
   }
 
-  public void maybeShowErrorDialogOnDisconnect(DisconnectCause disconnectCause) {
-    common.maybeShowErrorDialogOnDisconnect(disconnectCause);
+  public void maybeShowErrorDialogOnDisconnect(DisconnectMessage disconnectMessage) {
+    common.maybeShowErrorDialogOnDisconnect(disconnectMessage);
   }
 
   public void dismissPendingDialogs() {
@@ -476,8 +501,10 @@
   }
 
   public void onPrimaryCallStateChanged() {
+    Trace.beginSection("InCallActivity.onPrimaryCallStateChanged");
     LogUtil.i("InCallActivity.onPrimaryCallStateChanged", "");
     showMainInCallFragment();
+    Trace.endSection();
   }
 
   public void onWiFiToLteHandover(DialerCall call) {
@@ -514,15 +541,18 @@
   }
 
   private void showMainInCallFragment() {
+    Trace.beginSection("InCallActivity.showMainInCallFragment");
     // If the activity's onStart method hasn't been called yet then defer doing any work.
     if (!isVisible) {
       LogUtil.i("InCallActivity.showMainInCallFragment", "not visible yet/anymore");
+      Trace.endSection();
       return;
     }
 
     // Don't let this be reentrant.
     if (isInShowMainInCallFragment) {
       LogUtil.i("InCallActivity.showMainInCallFragment", "already in method, bailing");
+      Trace.endSection();
       return;
     }
 
@@ -560,10 +590,13 @@
     }
 
     if (didChangeInCall || didChangeVideo || didChangeAnswer) {
+      Trace.beginSection("InCallActivity.commitTransaction");
       transaction.commitNow();
+      Trace.endSection();
       Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
     }
     isInShowMainInCallFragment = false;
+    Trace.endSection();
   }
 
   private ShouldShowUiResult getShouldShowAnswerUi() {
@@ -630,12 +663,22 @@
       AnswerScreen answerScreen = getAnswerScreen();
       if (answerScreen.getCallId().equals(call.getId())
           && answerScreen.isVideoCall() == call.isVideoCall()
-          && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest) {
+          && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest
+          && !answerScreen.isActionTimeout()) {
+        LogUtil.d(
+            "InCallActivity.showAnswerScreenFragment",
+            "answer fragment exists for same call and has NOT been accepted/rejected/timed out");
         return false;
       }
-      LogUtil.i(
-          "InCallActivity.showAnswerScreenFragment",
-          "answer fragment exists but arguments do not match");
+      if (answerScreen.isActionTimeout()) {
+        LogUtil.i(
+            "InCallActivity.showAnswerScreenFragment",
+            "answer fragment exists but has been accepted/rejected and timed out");
+      } else {
+        LogUtil.i(
+            "InCallActivity.showAnswerScreenFragment",
+            "answer fragment exists but arguments do not match");
+      }
       hideAnswerScreenFragment(transaction);
     }
 
@@ -694,13 +737,8 @@
     if (didShowInCallScreen) {
       return false;
     }
-    InCallScreen inCallScreen = getInCallScreen();
-    if (inCallScreen == null) {
-      inCallScreen = InCallBindings.createInCallScreen();
-      transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), TAG_IN_CALL_SCREEN);
-    } else {
-      transaction.show(inCallScreen.getInCallScreenFragment());
-    }
+    InCallScreen inCallScreen = InCallBindings.createInCallScreen();
+    transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), TAG_IN_CALL_SCREEN);
     Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
     didShowInCallScreen = true;
     return true;
@@ -712,7 +750,7 @@
     }
     InCallScreen inCallScreen = getInCallScreen();
     if (inCallScreen != null) {
-      transaction.hide(inCallScreen.getInCallScreenFragment());
+      transaction.remove(inCallScreen.getInCallScreenFragment());
     }
     didShowInCallScreen = false;
     return true;