Handle race condition with CallComposerActivity.onBackPressed

For fast users/testing suites, it's possible to hit a race condition
where onBackPressed is called multiple times in a way that allows the
second call to endCallComposerSession to happen and crash.

This CL fixes the issue by checking that the session still exists prior
to calling endCallComposerSession.

I tried to write tests for this, but since the code guards against this
from happening, I wasn't able to get the code into a situation to cause
the crash.

Bug: 64136293
Test: none
PiperOrigin-RevId: 171758119
Change-Id: Ie12fd2f4390329b9bebb503fa3cf0f26d3bc1caf
diff --git a/java/com/android/dialer/callcomposer/CallComposerActivity.java b/java/com/android/dialer/callcomposer/CallComposerActivity.java
index b02e325..83fe2d9 100644
--- a/java/com/android/dialer/callcomposer/CallComposerActivity.java
+++ b/java/com/android/dialer/callcomposer/CallComposerActivity.java
@@ -528,12 +528,18 @@
 
   @Override
   public void onBackPressed() {
+    LogUtil.enterBlock("CallComposerActivity.onBackPressed");
     if (!isSendAndCallHidingOrHidden) {
       ((CallComposerFragment) adapter.instantiateItem(pager, currentIndex)).clearComposer();
     } else if (!runningExitAnimation) {
       // Unregister first to avoid receiving a callback when the session closes
       getEnrichedCallManager().unregisterStateChangedListener(this);
-      getEnrichedCallManager().endCallComposerSession(sessionId);
+
+      // If the user presses the back button when the session fails, there's a race condition here
+      // since we clean up failed sessions.
+      if (getEnrichedCallManager().getSession(sessionId) != null) {
+        getEnrichedCallManager().endCallComposerSession(sessionId);
+      }
       runExitAnimation();
     }
   }