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

Commit 296f5c42 authored by Tiger's avatar Tiger Committed by Tiger Huang
Browse files

Refine the error message about the cutout mode

This CL separates the error message from the error caused by
fitInsetsTypes and refine both messages.

Improvements:
1. The activity name will be printed.
2. The actual value and the expected one will be printed.
3. Stop printing the entire LayoutParams which can confuse the reader
   because it contains much unrelated information, and the 'default'
   cutout mode won't be printed within it.

Fix: 328308830
Bug: 309578419
Test: Open an app which violates the edge-to-edge enforcement, and see
      if the error message is printed as expected.
Change-Id: Ide9d42f51cfdb215bc0efd9ded6720f1baf07329
parent 260d9c9e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -5870,7 +5870,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
@@ -116,6 +116,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;
@@ -968,19 +969,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;
        }