Issue with rendering on Android Pie phones with cutout

Hi, when I tested a build of my game on my friend’s Xiaomi Mi 2 Lite with cutout I noticed a very strange behavior that I was able to reproduce on emulator too. With default settings - so without changing Window.Attributes.LayoutInDisplayCutoutMode attribute that’s what I got (screen taken straight from device):

I see two issues:

  1. Everything is moved to the right. Sure, that’s because there’s a cutout on the left side. I guess the issue is that I can’t get proper width that would take into account the size of the cutout. I get the screen resolution using GetRealMetrics() method from DisplayMetrics class.

  2. Whole screen is shifted down. I have no idea why this happens - again, on phones without cutout this doesn’t occur. My UI settings are:

    var uiOptions =
    SystemUiFlags.HideNavigation |
    SystemUiFlags.Fullscreen |
    SystemUiFlags.ImmersiveSticky |
    SystemUiFlags.LowProfile;
    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
    Window.AddFlags(WindowManagerFlags.TranslucentStatus);

After some testing I think that’s status bar, but it is set to translucent here.
Do you have any idea how to fix this behavior?

Ok, time to answer my own question. If you happen to have this issue carefully read this article: https://developer.android.com/guide/topics/display-cutout/
The issue I described is actually the default behavior for phones with cutout! The fix is to change the LayoutInDisplayCutoutMode attribute.