Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d732210b authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Refine the error message about the cutout mode" into main

parents e00ceb38 296f5c42
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -5871,7 +5871,10 @@ public interface WindowManager extends ViewManager {
                    && height == WindowManager.LayoutParams.MATCH_PARENT;
        }

        private static String layoutInDisplayCutoutModeToString(
        /**
         * @hide
         */
        public static String layoutInDisplayCutoutModeToString(
                @LayoutInDisplayCutoutMode int mode) {
            switch (mode) {
                case LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT:
+23 −11
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ import android.view.InsetsState;
import android.view.Surface;
import android.view.View;
import android.view.ViewDebug;
import android.view.WindowInsets;
import android.view.WindowInsets.Type;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowLayout;
@@ -969,19 +970,30 @@ public class DisplayPolicy {
                break;

            case TYPE_BASE_APPLICATION:

                // A non-translucent main app window isn't allowed to fit insets or display cutouts,
                // as it would create a hole on the display!
                if (attrs.isFullscreen() && win.mActivityRecord != null
                        && win.mActivityRecord.fillsParent()
                        && (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) != 0
                        && (attrs.getFitInsetsTypes() != 0
                                || (attrs.privateFlags & PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED) != 0
                        && (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS) != 0) {
                    if (attrs.getFitInsetsTypes() != 0) {
                        // A non-translucent main app window isn't allowed to fit insets,
                        // as it would create a hole on the display!
                        throw new IllegalArgumentException("Illegal attributes: Main window of "
                                + win.mActivityRecord.getName() + " that isn't translucent trying"
                                + " to fit insets. fitInsetsTypes=" + WindowInsets.Type.toString(
                                        attrs.getFitInsetsTypes()));
                    }
                    if ((attrs.privateFlags & PRIVATE_FLAG_EDGE_TO_EDGE_ENFORCED) != 0
                            && attrs.layoutInDisplayCutoutMode
                                                != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS)) {
                    throw new IllegalArgumentException("Illegal attributes: Main activity window"
                            + " that isn't translucent trying to fit insets or display cutouts."
                            + " attrs=" + attrs);
                                    != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
                        // A non-translucent main window of the app enforced to go edge-to-edge
                        // isn't allowed to fit display cutout, or it will cause software bezels.
                        throw new IllegalArgumentException("Illegal attributes: Main window of "
                                + win.mActivityRecord.getName() + " that isn't translucent and"
                                + " targets SDK level " + win.mActivityRecord.mTargetSdk
                                + " (>= 35) trying to specify layoutInDisplayCutoutMode as '"
                                + WindowManager.LayoutParams.layoutInDisplayCutoutModeToString(
                                        attrs.layoutInDisplayCutoutMode)
                                + "' instead of 'always'");
                    }
                }
                break;
        }