Fix pause & unpause requests if stopTransmission has not completed

The request to stop transmission can be in-flight at the time Dialer goes into the background so the pause request will still include Rx. This happens because pausing previously just gets the current video state and adds pause.

Bug: 62990728
Test: ImsVideoTechTest
PiperOrigin-RevId: 160210111
Change-Id: Ie9134c285a73d4348036f6bbb847abae53a1d373
diff --git a/java/com/android/incallui/videotech/ims/ImsVideoTech.java b/java/com/android/incallui/videotech/ims/ImsVideoTech.java
index 99d812a..8fa983a 100644
--- a/java/com/android/incallui/videotech/ims/ImsVideoTech.java
+++ b/java/com/android/incallui/videotech/ims/ImsVideoTech.java
@@ -19,7 +19,6 @@
 import android.content.Context;
 import android.os.Build;
 import android.support.annotation.Nullable;
-import android.support.annotation.VisibleForTesting;
 import android.telecom.Call;
 import android.telecom.Call.Details;
 import android.telecom.VideoProfile;
@@ -42,8 +41,13 @@
   private @SessionModificationState int sessionModificationState =
       SessionModificationState.NO_REQUEST;
   private int previousVideoState = VideoProfile.STATE_AUDIO_ONLY;
+  private boolean paused = false;
 
-  @VisibleForTesting boolean paused = false;
+  // Hold onto a flag of whether or not stopTransmission was called but resumeTransmission has not
+  // been. This is needed because there is time between calling stopTransmission and
+  // call.getDetails().getVideoState() reflecting the change. During that time, pause() and
+  // unpause() will send the incorrect VideoProfile.
+  private boolean transmissionStopped = false;
 
   public ImsVideoTech(LoggingBindings logger, VideoTechListener listener, Call call) {
     this.logger = logger;
@@ -209,6 +213,8 @@
   public void stopTransmission() {
     LogUtil.enterBlock("ImsVideoTech.stopTransmission");
 
+    transmissionStopped = true;
+
     int unpausedVideoState = getUnpausedVideoState(call.getDetails().getVideoState());
     call.getVideoCall()
         .sendSessionModifyRequest(
@@ -219,6 +225,8 @@
   public void resumeTransmission() {
     LogUtil.enterBlock("ImsVideoTech.resumeTransmission");
 
+    transmissionStopped = false;
+
     int unpausedVideoState = getUnpausedVideoState(call.getDetails().getVideoState());
     call.getVideoCall()
         .sendSessionModifyRequest(
@@ -232,6 +240,10 @@
       LogUtil.i("ImsVideoTech.pause", "sending pause request");
       paused = true;
       int pausedVideoState = call.getDetails().getVideoState() | VideoProfile.STATE_PAUSED;
+      if (transmissionStopped && VideoProfile.isTransmissionEnabled(pausedVideoState)) {
+        LogUtil.i("ImsVideoTech.pause", "overriding TX to false due to user request");
+        pausedVideoState &= ~VideoProfile.STATE_TX_ENABLED;
+      }
       call.getVideoCall().sendSessionModifyRequest(new VideoProfile(pausedVideoState));
     } else {
       LogUtil.i(
@@ -248,6 +260,10 @@
       LogUtil.i("ImsVideoTech.unpause", "sending unpause request");
       paused = false;
       int unpausedVideoState = getUnpausedVideoState(call.getDetails().getVideoState());
+      if (transmissionStopped && VideoProfile.isTransmissionEnabled(unpausedVideoState)) {
+        LogUtil.i("ImsVideoTech.unpause", "overriding TX to false due to user request");
+        unpausedVideoState &= ~VideoProfile.STATE_TX_ENABLED;
+      }
       call.getVideoCall().sendSessionModifyRequest(new VideoProfile(unpausedVideoState));
     } else {
       LogUtil.i(