Merge "Update insets position after rotation change is done" into 24D1-dev
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java
index 96aaf02..ea59715 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java
@@ -474,11 +474,16 @@
 
         mDisplayController.addDisplayChangingController(
                 (displayId, fromRotation, toRotation, newDisplayAreaInfo, t) -> {
-                    // This is triggered right before the rotation is applied
-                    if (fromRotation != toRotation) {
+                    Rect newScreenBounds = new Rect();
+                    if (newDisplayAreaInfo != null) {
+                        newScreenBounds =
+                                newDisplayAreaInfo.configuration.windowConfiguration.getBounds();
+                    }
+                    // This is triggered right before the rotation or new screen size is applied
+                    if (fromRotation != toRotation || !newScreenBounds.equals(mScreenBounds)) {
                         if (mStackView != null) {
                             // Layout listener set on stackView will update the positioner
-                            // once the rotation is applied
+                            // once the rotation or screen change is applied
                             mStackView.onOrientationChanged();
                         }
                     }
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepositoryTest.kt
index 44e312d..ddde681 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepositoryTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepositoryTest.kt
@@ -1070,6 +1070,25 @@
             faceAuthenticateIsCalled()
         }
 
+    @Test
+    fun retryFaceAuthAfterCancel() =
+        testScope.runTest {
+            initCollectors()
+            allPreconditionsToRunFaceAuthAreTrue()
+            val isAuthRunning by collectLastValue(underTest.isAuthRunning)
+
+            underTest.requestAuthenticate(FaceAuthUiEvent.FACE_AUTH_CAMERA_AVAILABLE_CHANGED)
+            underTest.cancel()
+            clearInvocations(faceManager)
+            underTest.requestAuthenticate(FaceAuthUiEvent.FACE_AUTH_CAMERA_AVAILABLE_CHANGED)
+
+            advanceTimeBy(DeviceEntryFaceAuthRepositoryImpl.DEFAULT_CANCEL_SIGNAL_TIMEOUT)
+            runCurrent()
+
+            assertThat(isAuthRunning).isEqualTo(true)
+            faceAuthenticateIsCalled()
+        }
+
     private suspend fun TestScope.testGatingCheckForFaceAuth(
         gatingCheckModifier: suspend () -> Unit
     ) {
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java
index 400f652..49728e7 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java
@@ -77,6 +77,7 @@
  * Contains logic that deals with showing a rotate suggestion button with animation.
  */
 public class RotationButtonController {
+    public static final boolean DEBUG_ROTATION = false;
 
     private static final String TAG = "RotationButtonController";
     private static final int BUTTON_FADE_IN_OUT_DURATION_MS = 100;
diff --git a/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepository.kt b/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepository.kt
index 8a25e41..52027db 100644
--- a/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepository.kt
@@ -517,9 +517,12 @@
 
     private fun onFaceAuthRequestCompleted() {
         cancelNotReceivedHandlerJob?.cancel()
-        cancellationInProgress.value = false
         _isAuthRunning.value = false
         authCancellationSignal = null
+        // Updates to "cancellationInProgress" may re-trigger face auth
+        // (see processPendingAuthRequests()), so we must update this after setting _isAuthRunning
+        // to false.
+        cancellationInProgress.value = false
     }
 
     private val detectionCallback =
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
index 13ba9c3..d711162 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
@@ -39,6 +39,7 @@
 import static com.android.systemui.navigationbar.NavBarHelper.transitionMode;
 import static com.android.systemui.recents.OverviewProxyService.OverviewProxyListener;
 import static com.android.systemui.shared.recents.utilities.Utilities.isLargeScreen;
+import static com.android.systemui.shared.rotation.RotationButtonController.DEBUG_ROTATION;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_CLICKABLE;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_ALLOW_GESTURE_IGNORING_BAR_VISIBILITY;
@@ -120,7 +121,6 @@
 import com.android.systemui.navigationbar.buttons.ButtonDispatcher;
 import com.android.systemui.navigationbar.buttons.DeadZone;
 import com.android.systemui.navigationbar.buttons.KeyButtonView;
-import com.android.systemui.navigationbar.buttons.RotationContextButton;
 import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
 import com.android.systemui.navigationbar.gestural.QuickswitchOrientedNavHandle;
 import com.android.systemui.plugins.statusbar.StatusBarStateController;
@@ -133,7 +133,6 @@
 import com.android.systemui.shade.ShadeViewController;
 import com.android.systemui.shared.navigationbar.RegionSamplingHelper;
 import com.android.systemui.shared.recents.utilities.Utilities;
-import com.android.systemui.shared.rotation.RotationButton;
 import com.android.systemui.shared.rotation.RotationButtonController;
 import com.android.systemui.shared.system.QuickStepContract;
 import com.android.systemui.shared.system.SysUiStatsLog;
@@ -627,8 +626,8 @@
             // When in gestural and the IME is showing, don't use the nearest region since it will
             // take gesture space away from the IME
             info.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
-            info.touchableRegion.set(getButtonLocations(false /* includeFloatingButtons */,
-                    false /* inScreen */, false /* useNearestRegion */));
+            info.touchableRegion.set(
+                    getButtonLocations(false /* inScreen */, false /* useNearestRegion */));
         };
 
         mRegionSamplingHelper = new RegionSamplingHelper(mView,
@@ -764,10 +763,7 @@
         repositionNavigationBar(mCurrentRotation);
         mView.setUpdateActiveTouchRegionsCallback(
                 () -> mOverviewProxyService.onActiveNavBarRegionChanges(
-                        getButtonLocations(
-                                true /* includeFloatingButtons */,
-                                true /* inScreen */,
-                                true /* useNearestRegion */)));
+                        getButtonLocations(true /* inScreen */, true /* useNearestRegion */)));
 
         mView.getViewTreeObserver().addOnComputeInternalInsetsListener(
                 mOnComputeInternalInsetsListener);
@@ -1096,16 +1092,14 @@
                 .hasDisable2RotateSuggestionFlag(mDisabledFlags2);
         final RotationButtonController rotationButtonController =
                 mView.getRotationButtonController();
-        final RotationButton rotationButton = rotationButtonController.getRotationButton();
-
-        if (RotationContextButton.DEBUG_ROTATION) {
+        if (DEBUG_ROTATION) {
             Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation)
                     + ", isValid=" + isValid + ", mNavBarWindowState="
                     + StatusBarManager.windowStateToString(mNavigationBarWindowState)
                     + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled
-                    + ", isRotateButtonVisible=" + rotationButton.isVisible());
+                    + ", isRotateButtonVisible="
+                    + rotationButtonController.getRotationButton().isVisible());
         }
-
         // Respect the disabled flag, no need for action as flag change callback will handle hiding
         if (rotateSuggestionsDisabled) return;
 
@@ -1823,14 +1817,11 @@
     }
 
     /**
-     * @param includeFloatingButtons Whether to include the floating rotation and overlay button in
-     *                               the region for all the buttons
      * @param inScreenSpace Whether to return values in screen space or window space
      * @param useNearestRegion Whether to use the nearest region instead of the actual button bounds
      * @return
      */
-    Region getButtonLocations(boolean includeFloatingButtons, boolean inScreenSpace,
-            boolean useNearestRegion) {
+    Region getButtonLocations(boolean inScreenSpace, boolean useNearestRegion) {
         if (useNearestRegion && !inScreenSpace) {
             // We currently don't support getting the nearest region in anything but screen space
             useNearestRegion = false;
@@ -1848,13 +1839,10 @@
         updateButtonLocation(
                 region, touchRegionCache, mView.getAccessibilityButton(), inScreenSpace,
                 useNearestRegion);
-        if (includeFloatingButtons && mView.getFloatingRotationButton().isVisible()) {
+        if (mView.getFloatingRotationButton().isVisible()) {
             // Note: this button is floating so the nearest region doesn't apply
             updateButtonLocation(
                     region, mView.getFloatingRotationButton().getCurrentView(), inScreenSpace);
-        } else {
-            updateButtonLocation(region, touchRegionCache, mView.getRotateSuggestionButton(),
-                    inScreenSpace, useNearestRegion);
         }
         return region;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
index bc0a1da..c1e1e94 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
@@ -69,7 +69,6 @@
 import com.android.systemui.navigationbar.buttons.DeadZone;
 import com.android.systemui.navigationbar.buttons.KeyButtonDrawable;
 import com.android.systemui.navigationbar.buttons.NearestTouchFrame;
-import com.android.systemui.navigationbar.buttons.RotationContextButton;
 import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
 import com.android.systemui.recents.Recents;
 import com.android.systemui.res.R;
@@ -150,7 +149,6 @@
     private Optional<Recents> mRecentsOptional = Optional.empty();
     @Nullable
     private ShadeViewController mPanelView;
-    private RotationContextButton mRotationContextButton;
     private FloatingRotationButton mFloatingRotationButton;
     private RotationButtonController mRotationButtonController;
 
@@ -290,8 +288,6 @@
                         R.drawable.ic_sysbar_accessibility_button);
         mContextualButtonGroup.addButton(imeSwitcherButton);
         mContextualButtonGroup.addButton(accessibilityButton);
-        mRotationContextButton = new RotationContextButton(R.id.rotate_suggestion,
-                mLightContext, R.drawable.ic_sysbar_rotate_button_ccw_start_0);
         mFloatingRotationButton = new FloatingRotationButton(mContext,
                 R.string.accessibility_rotate_button,
                 R.layout.rotate_suggestion,
@@ -429,10 +425,6 @@
         return mButtonDispatchers.get(R.id.accessibility_button);
     }
 
-    public RotationContextButton getRotateSuggestionButton() {
-        return (RotationContextButton) mButtonDispatchers.get(R.id.rotate_suggestion);
-    }
-
     public ButtonDispatcher getHomeHandle() {
         return mButtonDispatchers.get(R.id.home_handle);
     }
@@ -479,18 +471,8 @@
      * Updates the rotation button based on the current navigation mode.
      */
     void updateRotationButton() {
-        if (isGesturalMode(mNavBarMode)) {
-            mContextualButtonGroup.removeButton(R.id.rotate_suggestion);
-            mButtonDispatchers.remove(R.id.rotate_suggestion);
-            mRotationButtonController.setRotationButton(mFloatingRotationButton,
-                    mRotationButtonListener);
-        } else if (mContextualButtonGroup.getContextButton(R.id.rotate_suggestion) == null) {
-            mContextualButtonGroup.addButton(mRotationContextButton);
-            mButtonDispatchers.put(R.id.rotate_suggestion, mRotationContextButton);
-            mRotationButtonController.setRotationButton(mRotationContextButton,
-                    mRotationButtonListener);
-        }
-        mNavigationInflaterView.setButtonDispatchers(mButtonDispatchers);
+        mRotationButtonController.setRotationButton(mFloatingRotationButton,
+                mRotationButtonListener);
     }
 
     public KeyButtonDrawable getBackDrawable() {
@@ -1138,7 +1120,6 @@
         dumpButton(pw, "home", getHomeButton());
         dumpButton(pw, "handle", getHomeHandle());
         dumpButton(pw, "rcnt", getRecentsButton());
-        dumpButton(pw, "rota", getRotateSuggestionButton());
         dumpButton(pw, "a11y", getAccessibilityButton());
         dumpButton(pw, "ime", getImeSwitchButton());
 
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/buttons/RotationContextButton.java b/packages/SystemUI/src/com/android/systemui/navigationbar/buttons/RotationContextButton.java
deleted file mode 100644
index ac014b5..0000000
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/buttons/RotationContextButton.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2020 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.
- */
-
-package com.android.systemui.navigationbar.buttons;
-
-import android.annotation.DrawableRes;
-import android.annotation.IdRes;
-import android.content.Context;
-import android.view.View;
-
-import com.android.systemui.shared.rotation.RotationButton;
-import com.android.systemui.shared.rotation.RotationButtonController;
-
-/** Containing logic for the rotation button in nav bar. */
-public class RotationContextButton extends ContextualButton implements RotationButton {
-    public static final boolean DEBUG_ROTATION = false;
-
-    private RotationButtonController mRotationButtonController;
-
-    /**
-     * @param lightContext the context to use to load the icon resource
-     */
-    public RotationContextButton(@IdRes int buttonResId, Context lightContext,
-            @DrawableRes int iconResId) {
-        super(buttonResId, lightContext, iconResId);
-    }
-
-    @Override
-    public void setRotationButtonController(RotationButtonController rotationButtonController) {
-        mRotationButtonController = rotationButtonController;
-    }
-
-    @Override
-    public void setUpdatesCallback(RotationButtonUpdatesCallback updatesCallback) {
-        setListener((button, visible) -> {
-            if (updatesCallback != null) {
-                updatesCallback.onVisibilityChanged(visible);
-            }
-        });
-    }
-
-    @Override
-    public void setVisibility(int visibility) {
-        super.setVisibility(visibility);
-
-        // Start the rotation animation once it becomes visible
-        final KeyButtonDrawable currentDrawable = getImageDrawable();
-        if (visibility == View.VISIBLE && currentDrawable != null) {
-            currentDrawable.resetAnimation();
-            currentDrawable.startAnimation();
-        }
-    }
-
-    @Override
-    protected KeyButtonDrawable getNewDrawable(int lightIconColor, int darkIconColor) {
-        return KeyButtonDrawable.create(mRotationButtonController.getContext(),
-                lightIconColor, darkIconColor, mRotationButtonController.getIconResId(),
-                false /* shadow */, null /* ovalBackgroundColor */);
-    }
-
-    @Override
-    public boolean acceptRotationProposal() {
-        View currentView = getCurrentView();
-        return currentView != null && currentView.isAttachedToWindow();
-    }
-}
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index b8e09cc..24eba4a 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -3696,7 +3696,9 @@
             // is not "now". Compute the time from "now" when starting the anr timer.
             final long anrTime = sr.getEarliestStopTypeAndTime().second
                     + mAm.mConstants.mFgsAnrExtraWaitDuration - SystemClock.uptimeMillis();
-            mFGSAnrTimer.start(sr, anrTime);
+            if (android.app.Flags.introduceNewServiceOntimeoutCallback()) {
+                mFGSAnrTimer.start(sr, anrTime);
+            }
         }
     }