Let RCS Video Share take over Duo as the active video tech for a call

Bug: 67005309
Test: VideoTechManagerTest
PiperOrigin-RevId: 181368613
Change-Id: I8a13bd04d3ac342a06febb7437a0e0dd3d25affd
diff --git a/java/com/android/dialer/app/res/values-v27/styles.xml b/java/com/android/dialer/app/res/values-v27/styles.xml
new file mode 100644
index 0000000..5a946b6
--- /dev/null
+++ b/java/com/android/dialer/app/res/values-v27/styles.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+<resources>
+  <style name="DialtactsTheme" parent="DialtactsThemeBase">
+    <item name="android:windowLightNavigationBar">true</item>
+    <item name="android:navigationBarColor">?android:windowBackground</item>
+    <item name="android:navigationBarDividerColor">#E0E0E0</item>
+  </style>
+</resources>
diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java
index 5d71d0a..dd7535e 100644
--- a/java/com/android/incallui/call/DialerCall.java
+++ b/java/com/android/incallui/call/DialerCall.java
@@ -1635,13 +1635,17 @@
     }
   }
 
-  private static class VideoTechManager {
+  /** Coordinates the available VideoTech implementations for a call. */
+  @VisibleForTesting
+  public static class VideoTechManager {
     private final Context context;
     private final EmptyVideoTech emptyVideoTech = new EmptyVideoTech();
+    private final VideoTech rcsVideoShare;
     private final List<VideoTech> videoTechs;
     private VideoTech savedTech;
 
-    VideoTechManager(DialerCall call) {
+    @VisibleForTesting
+    public VideoTechManager(DialerCall call) {
       this.context = call.context;
 
       String phoneNumber = call.getNumber();
@@ -1653,40 +1657,47 @@
 
       videoTechs.add(new ImsVideoTech(Logger.get(call.context), call, call.telecomCall));
 
-      VideoTech rcsVideoTech =
+      rcsVideoShare =
           EnrichedCallComponent.get(call.context)
               .getRcsVideoShareFactory()
               .newRcsVideoShare(
                   EnrichedCallComponent.get(call.context).getEnrichedCallManager(),
                   call,
                   phoneNumber);
-      if (rcsVideoTech != null) {
-        videoTechs.add(rcsVideoTech);
+      if (rcsVideoShare != null) {
+        videoTechs.add(rcsVideoShare);
       }
 
       videoTechs.add(
           new DuoVideoTech(
               DuoComponent.get(call.context).getDuo(), call, call.telecomCall, phoneNumber));
+
+      savedTech = emptyVideoTech;
     }
 
-    VideoTech getVideoTech() {
-      if (savedTech != null) {
-        return savedTech;
-      }
-
-      for (VideoTech tech : videoTechs) {
-        if (tech.isAvailable(context)) {
-          // Remember the first VideoTech that becomes available and always use it
-          savedTech = tech;
-          savedTech.becomePrimary();
-          return savedTech;
+    @VisibleForTesting
+    public VideoTech getVideoTech() {
+      if (savedTech == emptyVideoTech) {
+        for (VideoTech tech : videoTechs) {
+          if (tech.isAvailable(context)) {
+            savedTech = tech;
+            savedTech.becomePrimary();
+            break;
+          }
         }
+      } else if (savedTech instanceof DuoVideoTech && rcsVideoShare.isAvailable(context)) {
+        // RCS Video Share will become available after the capability exchange which is slower than
+        // Duo reading local contacts for reachability. If Video Share becomes available and we are
+        // not in the middle of any session changes, let it take over.
+        savedTech = rcsVideoShare;
+        rcsVideoShare.becomePrimary();
       }
 
-      return emptyVideoTech;
+      return savedTech;
     }
 
-    void dispatchCallStateChanged(int newState) {
+    @VisibleForTesting
+    public void dispatchCallStateChanged(int newState) {
       for (VideoTech videoTech : videoTechs) {
         videoTech.onCallStateChanged(context, newState);
       }