Show post char dialog without InCallActivity.

Bug: 74022483
Test: InCallPresenterTest
PiperOrigin-RevId: 194275941
Change-Id: If5a40a9778e3c0f5a05c7e33f365cb609bf6e74a
diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java
index 526cc64..6e7daf5 100644
--- a/java/com/android/incallui/InCallPresenter.java
+++ b/java/com/android/incallui/InCallPresenter.java
@@ -1271,8 +1271,22 @@
   }
 
   public void onPostDialCharWait(String callId, String chars) {
-    if (isActivityStarted()) {
+    // If not visible, inCallActivity is stopped. Starting from P, calling recreate() will destroy
+    // the old activity instance and create a new instance immediately. Previously, the old activity
+    // went through its lifecycle from create to destroy before creating a new instance.
+    // So this case doesn't work now: make a call with char WAIT, leave in call UI, call gets
+    // connected, and go back to in call UI to see the dialog.
+    // So we should show dialog in an empty activity if inCallActivity is not visible. And it also
+    // helps with background calling.
+    if (isActivityStarted() && inCallActivity.isVisible()) {
       inCallActivity.showDialogForPostCharWait(callId, chars);
+    } else {
+      Intent intent = new Intent(context, PostCharDialogActivity.class);
+      // Prevent showing MainActivity with PostCharDialogActivity on above
+      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+      intent.putExtra(PostCharDialogActivity.EXTRA_CALL_ID, callId);
+      intent.putExtra(PostCharDialogActivity.EXTRA_POST_DIAL_STRING, chars);
+      context.startActivity(intent);
     }
   }