Add test to verify no crash on multiple DialerCall#onRemovedFromCallList.

This change also add a null check for RttCall when saving RTT transcript.

Test: DialerCallTest
PiperOrigin-RevId: 195293823
Change-Id: I67cf3410480ac106933486d9d31f0fbb3183b074
diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java
index 9e1e17e..77e2ea3 100644
--- a/java/com/android/incallui/call/DialerCall.java
+++ b/java/com/android/incallui/call/DialerCall.java
@@ -1058,6 +1058,7 @@
   }
 
   @TargetApi(28)
+  @Nullable
   public RttCall getRttCall() {
     if (!isActiveRttCall()) {
       return null;
@@ -1111,16 +1112,18 @@
     if (!BuildCompat.isAtLeastP()) {
       return;
     }
-    // Save any remaining text in the buffer that's not shown by UI yet.
-    // This may happen when the call is switched to background before disconnect.
-    try {
-      String messageLeft = getRttCall().readImmediately();
-      if (!TextUtils.isEmpty(messageLeft)) {
-        rttTranscript =
-            RttChatMessage.getRttTranscriptWithNewRemoteMessage(rttTranscript, messageLeft);
+    if (getRttCall() != null) {
+      // Save any remaining text in the buffer that's not shown by UI yet.
+      // This may happen when the call is switched to background before disconnect.
+      try {
+        String messageLeft = getRttCall().readImmediately();
+        if (!TextUtils.isEmpty(messageLeft)) {
+          rttTranscript =
+              RttChatMessage.getRttTranscriptWithNewRemoteMessage(rttTranscript, messageLeft);
+        }
+      } catch (IOException e) {
+        LogUtil.e("DialerCall.saveRttTranscript", "error when reading remaining message", e);
       }
-    } catch (IOException e) {
-      LogUtil.e("DialerCall.saveRttTranscript", "error when reading remaining message", e);
     }
     // Don't save transcript if it's empty.
     if (rttTranscript.getMessagesCount() == 0) {
@@ -1662,7 +1665,6 @@
     if (videoTechManager != null) {
       videoTechManager.dispatchRemovedFromCallList();
     }
-    // TODO(a bug): Add tests for it to make sure no crash on subsequent call to this method.
     // TODO(wangqi): Consider moving this to a DialerCallListener.
     if (rttTranscript != null && !isCallRemoved) {
       saveRttTranscript();