Merge "Fix error throwing by calling getCount before closing the cursor." into 24D1-dev
diff --git a/core/java/android/app/AppCompatTaskInfo.java b/core/java/android/app/AppCompatTaskInfo.java
index 0bae5e6..8e950c6 100644
--- a/core/java/android/app/AppCompatTaskInfo.java
+++ b/core/java/android/app/AppCompatTaskInfo.java
@@ -76,6 +76,11 @@
     public boolean topActivityEligibleForLetterboxEducation;
 
     /**
+     * Whether the letterbox education is enabled
+     */
+    public boolean isLetterboxEducationEnabled;
+
+    /**
      * Whether the direct top activity is in size compat mode on foreground.
      */
     public boolean topActivityInSizeCompat;
@@ -224,6 +229,7 @@
                     == that.topActivityEligibleForUserAspectRatioButton
                 && topActivityEligibleForLetterboxEducation
                     == that.topActivityEligibleForLetterboxEducation
+                && isLetterboxEducationEnabled == that.isLetterboxEducationEnabled
                 && topActivityLetterboxVerticalPosition == that.topActivityLetterboxVerticalPosition
                 && topActivityLetterboxHorizontalPosition
                     == that.topActivityLetterboxHorizontalPosition
@@ -238,6 +244,7 @@
      * Reads the TaskInfo from a parcel.
      */
     void readFromParcel(Parcel source) {
+        isLetterboxEducationEnabled = source.readBoolean();
         topActivityInSizeCompat = source.readBoolean();
         topActivityEligibleForLetterboxEducation = source.readBoolean();
         cameraCompatControlState = source.readInt();
@@ -258,6 +265,7 @@
      */
     @Override
     public void writeToParcel(Parcel dest, int flags) {
+        dest.writeBoolean(isLetterboxEducationEnabled);
         dest.writeBoolean(topActivityInSizeCompat);
         dest.writeBoolean(topActivityEligibleForLetterboxEducation);
         dest.writeInt(cameraCompatControlState);
@@ -278,6 +286,7 @@
         return "AppCompatTaskInfo { topActivityInSizeCompat=" + topActivityInSizeCompat
                 + " topActivityEligibleForLetterboxEducation= "
                 + topActivityEligibleForLetterboxEducation
+                + "isLetterboxEducationEnabled= " + isLetterboxEducationEnabled
                 + " isLetterboxDoubleTapEnabled= " + isLetterboxDoubleTapEnabled
                 + " topActivityEligibleForUserAspectRatioButton= "
                 + topActivityEligibleForUserAspectRatioButton
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java
index 86571cf..5359e9f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java
@@ -188,6 +188,11 @@
      */
     private boolean mHasShownUserAspectRatioSettingsButton = false;
 
+    /**
+     * This is true when the rechability education is displayed for the first time.
+     */
+    private boolean mIsFirstReachabilityEducationRunning;
+
     public CompatUIController(@NonNull Context context,
             @NonNull ShellInit shellInit,
             @NonNull ShellController shellController,
@@ -252,9 +257,35 @@
             removeLayouts(taskInfo.taskId);
             return;
         }
-
+        // We're showing the first reachability education so we ignore incoming TaskInfo
+        // until the education flow has completed or we double tap.
+        if (mIsFirstReachabilityEducationRunning) {
+            return;
+        }
+        if (taskInfo.appCompatTaskInfo.topActivityBoundsLetterboxed) {
+            if (taskInfo.appCompatTaskInfo.isLetterboxEducationEnabled) {
+                createOrUpdateLetterboxEduLayout(taskInfo, taskListener);
+            } else if (!taskInfo.appCompatTaskInfo.isFromLetterboxDoubleTap) {
+                // In this case the app is letterboxed and the letterbox education
+                // is disabled. In this case we need to understand if it's the first
+                // time we show the reachability education. When this is happening
+                // we need to ignore all the incoming TaskInfo until the education
+                // completes. If we come from a double tap we follow the normal flow.
+                final boolean topActivityPillarboxed =
+                        taskInfo.appCompatTaskInfo.isTopActivityPillarboxed();
+                final boolean isFirstTimeHorizontalReachabilityEdu = topActivityPillarboxed
+                        && !mCompatUIConfiguration.hasSeenHorizontalReachabilityEducation(taskInfo);
+                final boolean isFirstTimeVerticalReachabilityEdu = !topActivityPillarboxed
+                        && !mCompatUIConfiguration.hasSeenVerticalReachabilityEducation(taskInfo);
+                if (isFirstTimeHorizontalReachabilityEdu || isFirstTimeVerticalReachabilityEdu) {
+                    mIsFirstReachabilityEducationRunning = true;
+                    mCompatUIConfiguration.setSeenLetterboxEducation(taskInfo.userId);
+                    createOrUpdateReachabilityEduLayout(taskInfo, taskListener);
+                    return;
+                }
+            }
+        }
         createOrUpdateCompatLayout(taskInfo, taskListener);
-        createOrUpdateLetterboxEduLayout(taskInfo, taskListener);
         createOrUpdateRestartDialogLayout(taskInfo, taskListener);
         if (mCompatUIConfiguration.getHasSeenLetterboxEducation(taskInfo.userId)) {
             createOrUpdateReachabilityEduLayout(taskInfo, taskListener);
@@ -589,6 +620,7 @@
     private void onInitialReachabilityEduDismissed(@NonNull TaskInfo taskInfo,
             @NonNull ShellTaskOrganizer.TaskListener taskListener) {
         // We need to update the UI otherwise it will not be shown until the user relaunches the app
+        mIsFirstReachabilityEducationRunning = false;
         createOrUpdateUserAspectRatioSettingsLayout(taskInfo, taskListener);
     }
 
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java
index fef81af..2c85495 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java
@@ -668,6 +668,18 @@
         Assert.assertTrue(mController.hasShownUserAspectRatioSettingsButton());
     }
 
+    @Test
+    public void testLetterboxEduLayout_notCreatedWhenLetterboxEducationIsDisabled() {
+        TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ true,
+                CAMERA_COMPAT_CONTROL_HIDDEN);
+        taskInfo.appCompatTaskInfo.isLetterboxEducationEnabled = false;
+
+        mController.onCompatInfoChanged(taskInfo, mMockTaskListener);
+
+        verify(mController, never()).createLetterboxEduWindowManager(any(), eq(taskInfo),
+                eq(mMockTaskListener));
+    }
+
     private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat,
             @CameraCompatControlState int cameraCompatControlState) {
         return createTaskInfo(displayId, taskId, hasSizeCompat, cameraCompatControlState,
@@ -693,6 +705,8 @@
         taskInfo.isVisible = isVisible;
         taskInfo.isFocused = isFocused;
         taskInfo.isTopActivityTransparent = isTopActivityTransparent;
+        taskInfo.appCompatTaskInfo.isLetterboxEducationEnabled = true;
+        taskInfo.appCompatTaskInfo.topActivityBoundsLetterboxed = true;
         return taskInfo;
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt
index bd93226..969cf48 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt
@@ -22,6 +22,8 @@
 import android.graphics.Rect
 import android.graphics.Region
 import android.util.AttributeSet
+import android.view.GestureDetector
+import android.view.GestureDetector.SimpleOnGestureListener
 import android.view.MotionEvent
 import android.view.View
 import android.view.ViewGroup
@@ -43,13 +45,43 @@
     private val displayMetrics = context.resources.displayMetrics
     private val tmpRect = Rect()
     private lateinit var actionsContainerBackground: View
+    private lateinit var actionsContainer: View
     private lateinit var dismissButton: View
 
+    // Prepare an internal `GestureDetector` to determine when we can initiate a touch-interception
+    // session (with the client's provided `onTouchInterceptListener`). We delegate out to their
+    // listener only for gestures that can't be handled by scrolling our `actionsContainer`.
+    private val gestureDetector =
+        GestureDetector(
+            context,
+            object : SimpleOnGestureListener() {
+                override fun onScroll(
+                    ev1: MotionEvent?,
+                    ev2: MotionEvent,
+                    distanceX: Float,
+                    distanceY: Float
+                ): Boolean {
+                    actionsContainer.getBoundsOnScreen(tmpRect)
+                    val touchedInActionsContainer =
+                        tmpRect.contains(ev2.rawX.toInt(), ev2.rawY.toInt())
+                    val canHandleInternallyByScrolling =
+                        touchedInActionsContainer
+                        && actionsContainer.canScrollHorizontally(distanceX.toInt())
+                    return !canHandleInternallyByScrolling
+                }
+            }
+        )
+
     init {
-        setOnTouchListener({ _: View, _: MotionEvent ->
+
+        // Delegate to the client-provided `onTouchInterceptListener` if we've already initiated
+        // touch-interception.
+        setOnTouchListener({ _: View, ev: MotionEvent ->
             userInteractionCallback?.invoke()
-            true
+            onTouchInterceptListener?.invoke(ev) ?: false
         })
+
+        gestureDetector.setIsLongpressEnabled(false)
     }
 
     override fun onFinishInflate() {
@@ -60,7 +92,15 @@
         blurredScreenshotPreview = requireViewById(R.id.screenshot_preview_blur)
         screenshotStatic = requireViewById(R.id.screenshot_static)
         actionsContainerBackground = requireViewById(R.id.actions_container_background)
+        actionsContainer = requireViewById(R.id.actions_container)
         dismissButton = requireViewById(R.id.screenshot_dismiss_button)
+
+        // Configure to extend the timeout during ongoing gestures (i.e. scrolls) that are already
+        // being handled by our child views.
+        actionsContainer.setOnTouchListener({ _: View, ev: MotionEvent ->
+            userInteractionCallback?.invoke()
+            false
+        })
     }
 
     fun getTouchRegion(gestureInsets: Insets): Region {
@@ -171,9 +211,16 @@
     override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
         userInteractionCallback?.invoke()
 
-        if (onTouchInterceptListener?.invoke(ev) == true) {
-            return true
+        // Let the client-provided listener see all `DOWN` events so that they'll be able to
+        // interpret the remainder of the gesture, even if interception starts partway-through.
+        // TODO: is this really necessary? And if we don't go on to start interception, should we
+        // follow up with `ACTION_CANCEL`?
+        if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
+            onTouchInterceptListener?.invoke(ev)
         }
-        return super.onInterceptTouchEvent(ev)
+
+        // Only allow the client-provided touch interceptor to take over the gesture if our
+        // top-level `GestureDetector` decides not to scroll the action container.
+        return gestureDetector.onTouchEvent(ev)
     }
 }
diff --git a/services/core/java/com/android/server/wm/BackNavigationController.java b/services/core/java/com/android/server/wm/BackNavigationController.java
index e155126..cd7f73c 100644
--- a/services/core/java/com/android/server/wm/BackNavigationController.java
+++ b/services/core/java/com/android/server/wm/BackNavigationController.java
@@ -423,7 +423,6 @@
         // Searching previous
         final ActivityRecord prevActivity = currentTask.getActivity((below) -> !below.finishing,
                 currentActivity, false /*includeBoundary*/, true /*traverseTopToBottom*/);
-
         final TaskFragment currTF = currentActivity.getTaskFragment();
         if (currTF != null && currTF.asTask() == null) {
             // The currentActivity is embedded, search for the candidate previous activities.
@@ -432,13 +431,34 @@
                 outPrevActivities.add(prevActivity);
                 return true;
             }
-            if (currTF.getAdjacentTaskFragment() != null) {
-                // The two TFs are adjacent (visually displayed side-by-side), search if any
-                // activity below the lowest one
-                // If companion, those two TF will be closed together.
-                if (currTF.getCompanionTaskFragment() != null) {
+            if (currTF.getAdjacentTaskFragment() == null) {
+                final TaskFragment nextTF = findNextTaskFragment(currentTask, currTF);
+                if (isSecondCompanionToFirst(currTF, nextTF)) {
+                    // TF is isStacked, search bottom activity from companion TF.
+                    //
+                    // Sample hierarchy: search for underPrevious if any.
+                    //     Current TF
+                    //     Companion TF (bottomActivityInCompanion)
+                    //     Bottom Activity not inside companion TF (underPrevious)
+                    // find bottom activity in Companion TF.
+                    final ActivityRecord bottomActivityInCompanion = nextTF.getActivity(
+                            (below) -> !below.finishing, false /* traverseTopToBottom */);
+                    final ActivityRecord underPrevious = currentTask.getActivity(
+                            (below) -> !below.finishing, bottomActivityInCompanion,
+                            false /*includeBoundary*/, true /*traverseTopToBottom*/);
+                    if (underPrevious != null) {
+                        outPrevActivities.add(underPrevious);
+                        addPreviousAdjacentActivityIfExist(underPrevious, outPrevActivities);
+                    }
+                    return true;
+                }
+            } else {
+                // If adjacent TF has companion to current TF, those two TF will be closed together.
+                final TaskFragment adjacentTF = currTF.getAdjacentTaskFragment();
+                if (isSecondCompanionToFirst(currTF, adjacentTF)) {
+                    // The two TFs are adjacent (visually displayed side-by-side), search if any
+                    // activity below the lowest one.
                     final WindowContainer commonParent = currTF.getParent();
-                    final TaskFragment adjacentTF = currTF.getAdjacentTaskFragment();
                     final TaskFragment lowerTF = commonParent.mChildren.indexOf(currTF)
                             < commonParent.mChildren.indexOf(adjacentTF)
                             ? currTF : adjacentTF;
@@ -452,25 +472,6 @@
                 // Unable to predict if no companion, it can only close current activity and make
                 // prev Activity full screened.
                 return false;
-            } else if (currTF.getCompanionTaskFragment() != null) {
-                // TF is isStacked, search bottom activity from companion TF.
-                //
-                // Sample hierarchy: search for underPrevious if any.
-                //     Current TF
-                //     Companion TF (bottomActivityInCompanion)
-                //     Bottom Activity not inside companion TF (underPrevious)
-                final TaskFragment companionTF = currTF.getCompanionTaskFragment();
-                // find bottom activity in Companion TF.
-                final ActivityRecord bottomActivityInCompanion = companionTF.getActivity(
-                        (below) -> !below.finishing, false /* traverseTopToBottom */);
-                final ActivityRecord underPrevious = currentTask.getActivity(
-                        (below) -> !below.finishing, bottomActivityInCompanion,
-                        false /*includeBoundary*/, true /*traverseTopToBottom*/);
-                if (underPrevious != null) {
-                    outPrevActivities.add(underPrevious);
-                    addPreviousAdjacentActivityIfExist(underPrevious, outPrevActivities);
-                }
-                return true;
             }
         }
 
@@ -485,6 +486,24 @@
         return true;
     }
 
+    private static TaskFragment findNextTaskFragment(@NonNull Task currentTask,
+            @NonNull TaskFragment topTF) {
+        final int topIndex = currentTask.mChildren.indexOf(topTF);
+        if (topIndex <= 0) {
+            return null;
+        }
+        final WindowContainer next = currentTask.mChildren.get(topIndex - 1);
+        return next.asTaskFragment();
+    }
+
+    /**
+     * Whether the second TF has set companion to first TF.
+     * When set, the second TF will be removed by organizer if the first TF is removed.
+     */
+    private static boolean isSecondCompanionToFirst(TaskFragment first, TaskFragment second) {
+        return second != null && second.getCompanionTaskFragment() == first;
+    }
+
     private static void addPreviousAdjacentActivityIfExist(@NonNull ActivityRecord prevActivity,
             @NonNull ArrayList<ActivityRecord> outPrevActivities) {
         final TaskFragment prevTF = prevActivity.getTaskFragment();
diff --git a/services/core/java/com/android/server/wm/LetterboxUiController.java b/services/core/java/com/android/server/wm/LetterboxUiController.java
index b75869c..eea8b6a 100644
--- a/services/core/java/com/android/server/wm/LetterboxUiController.java
+++ b/services/core/java/com/android/server/wm/LetterboxUiController.java
@@ -970,6 +970,10 @@
         }
     }
 
+    boolean isLetterboxEducationEnabled() {
+        return mLetterboxConfiguration.getIsEducationEnabled();
+    }
+
     /**
      * Whether we use split screen aspect ratio for the activity when camera compat treatment
      * is active because the corresponding config is enabled and activity supports resizing.
@@ -1373,7 +1377,8 @@
         }
 
         final boolean shouldShowLetterboxUi =
-                (mActivityRecord.isInLetterboxAnimation() || isSurfaceVisible(mainWindow))
+                (mActivityRecord.isInLetterboxAnimation() || mActivityRecord.isVisible()
+                        || mActivityRecord.isVisibleRequested())
                 && mainWindow.areAppWindowBoundsLetterboxed()
                 // Check for FLAG_SHOW_WALLPAPER explicitly instead of using
                 // WindowContainer#showWallpaper because the later will return true when this
@@ -1385,12 +1390,6 @@
         return shouldShowLetterboxUi;
     }
 
-    @VisibleForTesting
-    boolean isSurfaceVisible(WindowState mainWindow) {
-        return mainWindow.isOnScreen() && (mActivityRecord.isVisible()
-                || mActivityRecord.isVisibleRequested());
-    }
-
     private Color getLetterboxBackgroundColor() {
         final WindowState w = mActivityRecord.findMainWindow();
         if (w == null || w.isLetterboxedForDisplayCutout()) {
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 94d6930..b6760c5 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -3541,6 +3541,8 @@
         // Whether the direct top activity is eligible for letterbox education.
         appCompatTaskInfo.topActivityEligibleForLetterboxEducation = isTopActivityResumed
                 && top.isEligibleForLetterboxEducation();
+        appCompatTaskInfo.isLetterboxEducationEnabled = top != null
+                && top.mLetterboxUiController.isLetterboxEducationEnabled();
         // Whether the direct top activity requested showing camera compat control.
         appCompatTaskInfo.cameraCompatControlState = isTopActivityResumed
                 ? top.getCameraCompatControlState()
diff --git a/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java
index c29547f..9b2a880 100644
--- a/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/BackNavigationControllerTests.java
@@ -291,13 +291,22 @@
         assertTrue(predictable);
         outPrevActivities.clear();
 
-        // Stacked + companion => predict for previous task
+        // Stacked + top companion to bottom but bottom didn't => predict for previous activity
         tf2.setCompanionTaskFragment(tf1);
         predictable = BackNavigationController.getAnimatablePrevActivities(task, topAr,
                 outPrevActivities);
+        assertTrue(outPrevActivities.contains(prevAr));
+        assertTrue(predictable);
+        tf2.setCompanionTaskFragment(null);
+        outPrevActivities.clear();
+
+        // Stacked + next companion to top => predict for previous task
+        tf1.setCompanionTaskFragment(tf2);
+        predictable = BackNavigationController.getAnimatablePrevActivities(task, topAr,
+                outPrevActivities);
         assertTrue(outPrevActivities.isEmpty());
         assertTrue(predictable);
-        tf2.setCompanionTaskFragment(null);
+        tf1.setCompanionTaskFragment(null);
 
         // Adjacent + no companion => unable to predict
         // TF1 | TF2
@@ -314,11 +323,13 @@
 
         // Adjacent + companion => predict for previous task
         tf1.setCompanionTaskFragment(tf2);
-        tf2.setCompanionTaskFragment(tf1);
         predictable = BackNavigationController.getAnimatablePrevActivities(task, topAr,
                 outPrevActivities);
         assertTrue(outPrevActivities.isEmpty());
         assertTrue(predictable);
+        tf1.setCompanionTaskFragment(null);
+
+        tf2.setCompanionTaskFragment(tf1);
         predictable = BackNavigationController.getAnimatablePrevActivities(task, prevAr,
                 outPrevActivities);
         assertTrue(outPrevActivities.isEmpty());
@@ -361,18 +372,27 @@
         tf3.setAdjacentTaskFragment(null);
 
         final TaskFragment tf4 = createTaskFragmentWithActivity(task);
-        // Stacked + companion => predict for previous activity below companion.
+        // Stacked + next companion to top => predict for previous activity below companion.
         // Tf4
         // TF3
         // TF2
         // TF1
-        tf4.setCompanionTaskFragment(tf3);
         tf3.setCompanionTaskFragment(tf4);
         topAr = tf4.getTopMostActivity();
         predictable = BackNavigationController.getAnimatablePrevActivities(task, topAr,
                 outPrevActivities);
         assertTrue(outPrevActivities.contains(tf2.getTopMostActivity()));
         assertTrue(predictable);
+        outPrevActivities.clear();
+        tf3.setCompanionTaskFragment(null);
+
+        // Stacked +  top companion to next but next one didn't => predict for previous activity.
+        tf4.setCompanionTaskFragment(tf3);
+        topAr = tf4.getTopMostActivity();
+        predictable = BackNavigationController.getAnimatablePrevActivities(task, topAr,
+                outPrevActivities);
+        assertTrue(outPrevActivities.contains(tf3.getTopMostActivity()));
+        assertTrue(predictable);
     }
 
     @Test
diff --git a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java
index 6806f6a..ed205a5 100644
--- a/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/LetterboxUiControllerTest.java
@@ -609,7 +609,8 @@
         doReturn(false).when(mActivity).isInLetterboxAnimation();
         assertEquals(expectedRadius, mController.getRoundedCornersRadius(mainWindow));
 
-        doReturn(false).when(mainWindow).isOnScreen();
+        doReturn(false).when(mActivity).isVisibleRequested();
+        doReturn(false).when(mActivity).isVisible();
         assertEquals(0, mController.getRoundedCornersRadius(mainWindow));
 
         doReturn(true).when(mActivity).isInLetterboxAnimation();
@@ -1581,6 +1582,12 @@
         assertTrue(mController.allowHorizontalReachabilityForThinLetterbox());
     }
 
+    @Test
+    public void testIsLetterboxEducationEnabled() {
+        mController.isLetterboxEducationEnabled();
+        verify(mLetterboxConfiguration).getIsEducationEnabled();
+    }
+
     private void mockThatProperty(String propertyName, boolean value) throws Exception {
         Property property = new Property(propertyName, /* value */ value, /* packageName */ "",
                  /* className */ "");
diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
index 36c1c8c..bf15bc8 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java
@@ -909,8 +909,7 @@
         assertEquals(window, mActivity.findMainWindow());
 
         spyOn(mActivity.mLetterboxUiController);
-        doReturn(true).when(mActivity.mLetterboxUiController)
-                .isSurfaceVisible(any());
+        doReturn(true).when(mActivity).isVisibleRequested();
 
         assertTrue(mActivity.mLetterboxUiController.shouldShowLetterboxUi(
                 mActivity.findMainWindow()));