Wait for unknown vis to resolve before forcing keyguard orientation

If TRANSIT_UNOCCLUDE is set it may only be so because we are
starting another activity that occludes the Keyguard.
UnknownVisibilityController knows about this, so ask it and wait
with forcing Keyguard orientation if needed.

Test: Take image from secure camera in landscape, press on the
photo, ensure no rotations
Test: Dismiss alarm in landscape, observe no rotations
Fixes: 68819499

Change-Id: If143ce43f620d77d62f5812950a040e531cc0a02
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index 0771b53..79eb2c9 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -3728,8 +3728,12 @@
 
             mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
 
-            if (policy.isKeyguardShowingAndNotOccluded()
-                    || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
+            // Only allow force setting the orientation when all unknown visibilities have been
+            // resolved, as otherwise we just may be starting another occluding activity.
+            final boolean isUnoccluding =
+                    mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
+                            && mService.mUnknownAppVisibilityController.allResolved();
+            if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
                 return mLastKeyguardForcedOrientation;
             }