ScreenOrientation.AutoRotation ignores autorotateToX values

I’m trying to work with screen rotations in our app. What I’m trying to achieve is this:
When “entering a page” (prefab is loaded), I’m setting the allowed autorotateToX values according to that page’s settings and I expect the screen to rotate to be within the allowed rotations.

For this example let’s say the device is in portrait mode currently, and I then set it to allow landscape left and right only.

Just setting the allowed rotations does not force the screen to rotate. If you then rotate the device to landscape, the screen orientation rotates as it should, after which point the restrictions seem to kick in, and you can no longer go back to portrait.

To get the screen to rotate to respect the allowed autorotations, the first thing I tried was setting the current orientation to auto after setting the allowed autorotations:

Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;
Screen.orientation = ScreenOrientation.AutoRotation;

This had no effect.

Then, as further workaround/test, I tried setting the current orientation to LandscapeLeft, wait 3s and then set it to Auto:

Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;
Screen.orientation = ScreenOrientation.LandscapeLeft;
await UniTask.Delay(3000);
Screen.orientation = ScreenOrientation.AutoRotation;

This caused the screen to rotate to LandscapeLeft as expected, but after the 3 seconds, the AutoRotation rotated it back to portrait. (The real physical rotation was portrait at all times)
Again, if I manually rotated the real device to landscape, I could no longer go back to portrait. i.e. It then respected the allowed rotation values.

So in conclusion, AutoRotation seems to rotate to the real physical rotation ignoring autorotateToX values, until the physical real orientation change triggers something, after which it respects the autorotateToX values.

Any ideas?

Edit:
I also reproduced the problem in an empty scene with a single canvas, button and script, just to rule out outside interference by my other scripts.
Also, I should mention that the problem happens on a real device (Honor 8, Android 7.0), but not on the Unity Device simulator in Play mode.

I confirm this bug for Unity 2020.3.9f1 Android Huawei P30.
There are multiple bug reports about this for different unity versions in Postponed state.

Workaround is running custom AutoRotate function in LateUpdate, that checks Input.deviceOrientation, Screen.orientation, Screen.autorotateToX values and sets Screen.orientation to correct value.

I confirm this bug for Unity 2020.3.12f1 LTS Android.

Any updates or solutions?

I think this may be the same issue that you’re experiencing, Unity Issue Tracker - [Android] Switching to Portrait from Landscape by script doesn't work when device is in landscape.

If that is the case then we have it fixed but not yet back ported to all releases that were affected. Of course you can follow along with the status on that page.

Sorry to necro this thread, but was this really fixed? I can repro the exact same issue on 2022.3.19f1 is there something specific to do to force the orientation to the current settings?
Everything works as expected on iOS

I should note I tested it with both User and Sensor auto rotation behaviors, both have the same issue

I have a similar issue:

default rotation set to: auto rotation.

I wanted to disable upside down portrait, the rest of possible auto rotations are enabled.

yet, on the device, im still able to rotate it upside down