@@ -143,6 +143,7 @@ public void run() {
143143 public static void init (final AppCompatActivity activity ) {
144144 sActivity = activity ;
145145 AxmolEngine .sAxmolEngineListener = (AxmolEngineListener )activity ;
146+
146147 if (!sInited ) {
147148
148149 PackageManager pm = activity .getPackageManager ();
@@ -634,8 +635,9 @@ public static boolean isCutoutEnabled() {
634635 public static int [] getSafeInsets () {
635636 final int [] safeInsets = new int []{0 , 0 , 0 , 0 };
636637 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
637- Window cocosWindow = sActivity .getWindow ();
638- DisplayCutout displayCutout = cocosWindow .getDecorView ().getRootWindowInsets ().getDisplayCutout ();
638+ Window window = sActivity .getWindow ();
639+ WindowInsets rootWindowInsets = window .getDecorView ().getRootWindowInsets ();
640+ DisplayCutout displayCutout = rootWindowInsets != null ? rootWindowInsets .getDisplayCutout () : null ;
639641 // Judge whether it is cutouts (aka notch) screen phone by judge cutout equle to null
640642 if (displayCutout != null ) {
641643 List <Rect > rects = displayCutout .getBoundingRects ();
@@ -661,9 +663,10 @@ public static int[] getSafeInsets() {
661663 public static int [] getDeviceCornerRadii () {
662664 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
663665 final int [] radii = new int []{0 , 0 , 0 , 0 };
664- Window cocosWindow = sActivity .getWindow ();
665- View view = cocosWindow .getDecorView ();
666+ Window window = sActivity .getWindow ();
667+ View view = window .getDecorView ();
666668 WindowInsets insets = view .getRootWindowInsets ();
669+ if (insets == null ) return radii ;
667670 android .view .RoundedCorner topLeft = insets .getRoundedCorner (android .view .RoundedCorner .POSITION_TOP_LEFT );
668671 android .view .RoundedCorner topRight = insets .getRoundedCorner (android .view .RoundedCorner .POSITION_TOP_RIGHT );
669672 android .view .RoundedCorner bottomLeft = insets .getRoundedCorner (android .view .RoundedCorner .POSITION_BOTTOM_LEFT );
0 commit comments