Move onUiShowing() call from onResume/onPause to onStart/onStop.

It makes sure bubble doesn't appear on split screen when in-call UI is not showing. Although bubble still shows in recents screen.

It also make sure the same onUiShowing() is not called multiple times.

Bug: 67605985,71746139
Test: InCallActivityTest
PiperOrigin-RevId: 182280886
Change-Id: I2a28d0258c722d530000729a89751c6d6b1ee6fd
diff --git a/java/com/android/incallui/InCallActivity.java b/java/com/android/incallui/InCallActivity.java
index 0a56666..9905606 100644
--- a/java/com/android/incallui/InCallActivity.java
+++ b/java/com/android/incallui/InCallActivity.java
@@ -406,6 +406,10 @@
             == InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
     InCallPresenter.getInstance().onActivityStarted();
 
+    if (!isRecreating) {
+      InCallPresenter.getInstance().onUiShowing(true);
+    }
+
     if (ActivityCompat.isInMultiWindowMode(this)
         && !getResources().getBoolean(R.bool.incall_dialpad_allowed)) {
       // Hide the dialpad because there may not be enough room
@@ -422,7 +426,7 @@
 
     if (!InCallPresenter.getInstance().isReadyForTearDown()) {
       updateTaskDescription();
-      InCallPresenter.getInstance().onUiShowing(true);
+      InCallPresenter.getInstance().updateNotification();
     }
 
     // If there is a pending request to show or hide the dialpad, handle that now.
@@ -479,12 +483,7 @@
       dialpadFragment.onDialerKeyUp(null);
     }
 
-    if (!isRecreating) {
-      InCallPresenter.getInstance().onUiShowing(false);
-    }
-    if (isFinishing()) {
-      InCallPresenter.getInstance().unsetActivity(this);
-    }
+    InCallPresenter.getInstance().updateNotification();
 
     InCallPresenter.getInstance().getPseudoScreenState().removeListener(this);
     Trace.endSection();
@@ -513,11 +512,16 @@
     InCallPresenter.getInstance().updateIsChangingConfigurations();
     InCallPresenter.getInstance().onActivityStopped();
     if (!isRecreating) {
+      InCallPresenter.getInstance().onUiShowing(false);
       if (errorDialog != null) {
         errorDialog.dismiss();
       }
     }
 
+    if (isFinishing()) {
+      InCallPresenter.getInstance().unsetActivity(this);
+    }
+
     Trace.endSection();
   }
 
diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java
index f0d3adc..558ca33 100644
--- a/java/com/android/incallui/InCallPresenter.java
+++ b/java/com/android/incallui/InCallPresenter.java
@@ -1044,14 +1044,16 @@
         "updateIsChangingConfigurations = " + isChangingConfigurations);
   }
 
-  /** Called when the activity goes in/out of the foreground. */
-  public void onUiShowing(boolean showing) {
+  void updateNotification() {
     // We need to update the notification bar when we leave the UI because that
     // could trigger it to show again.
     if (statusBarNotifier != null) {
       statusBarNotifier.updateNotification();
     }
+  }
 
+  /** Called when the activity goes in/out of the foreground. */
+  public void onUiShowing(boolean showing) {
     if (proximitySensor != null) {
       proximitySensor.onInCallShowing(showing);
     }
diff --git a/java/com/android/newbubble/NewBubble.java b/java/com/android/newbubble/NewBubble.java
index 65f7a0a..09634b5 100644
--- a/java/com/android/newbubble/NewBubble.java
+++ b/java/com/android/newbubble/NewBubble.java
@@ -926,13 +926,7 @@
       root.setOnConfigurationChangedListener(
           (configuration) -> {
             if (expanded) {
-              // Collapse immediately without animation
-              if (collapseAnimatorSet != null) {
-                collapseAnimatorSet.removeAllListeners();
-                collapseAnimatorSet.cancel();
-              }
-              setDrawerVisibility(View.GONE);
-              expanded = false;
+              startCollapse(CollapseEnd.NOTHING, false /* shouldRecoverYPosition */);
             }
             // The values in the current MoveHandler may be stale, so replace it. Then ensure the
             // Window is in bounds