|
29 | 29 | import android.graphics.Rect;
|
30 | 30 | import android.graphics.Region;
|
31 | 31 | import android.hardware.HardwareBuffer;
|
| 32 | +import android.hardware.display.DisplayManager; |
32 | 33 | import android.media.Image;
|
33 | 34 | import android.media.Image.Plane;
|
34 | 35 | import android.media.ImageReader;
|
|
39 | 40 | import android.view.Surface;
|
40 | 41 | import android.view.View;
|
41 | 42 | import android.view.WindowInsets;
|
42 |
| -import android.view.WindowManager; |
43 | 43 | import android.widget.FrameLayout;
|
44 | 44 | import androidx.core.util.Consumer;
|
45 | 45 | import androidx.test.core.app.ApplicationProvider;
|
46 | 46 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
47 | 47 | import androidx.window.layout.FoldingFeature;
|
48 | 48 | import androidx.window.layout.WindowLayoutInfo;
|
| 49 | +import io.flutter.Build.API_LEVELS; |
49 | 50 | import io.flutter.embedding.engine.FlutterEngine;
|
50 | 51 | import io.flutter.embedding.engine.FlutterJNI;
|
51 | 52 | import io.flutter.embedding.engine.loader.FlutterLoader;
|
@@ -438,6 +439,48 @@ public void systemInsetHandlesFullscreenNavbarRightBelowSDK23() {
|
438 | 439 | validateViewportMetricPadding(viewportMetricsCaptor, 100, 0, 0, 0);
|
439 | 440 | }
|
440 | 441 |
|
| 442 | + @Test |
| 443 | + @Config(minSdk = API_LEVELS.FLUTTER_MIN, maxSdk = API_LEVELS.API_29, qualifiers = "port") |
| 444 | + public void calculateShouldZeroSidesInPortrait() { |
| 445 | + FlutterView flutterView = spy(new FlutterView(ctx)); |
| 446 | + assertEquals(FlutterView.ZeroSides.NONE, flutterView.calculateShouldZeroSides()); |
| 447 | + } |
| 448 | + |
| 449 | + @Test |
| 450 | + @Config(minSdk = API_LEVELS.FLUTTER_MIN, maxSdk = API_LEVELS.API_29, qualifiers = "land") |
| 451 | + public void calculateShouldZeroSidesInLandscapeNeutralRotation() { |
| 452 | + FlutterView flutterView = spy(new FlutterView(ctx)); |
| 453 | + setExpectedDisplayRotation(Surface.ROTATION_0); |
| 454 | + assertEquals(FlutterView.ZeroSides.BOTH, flutterView.calculateShouldZeroSides()); |
| 455 | + |
| 456 | + setExpectedDisplayRotation(Surface.ROTATION_180); |
| 457 | + assertEquals(FlutterView.ZeroSides.BOTH, flutterView.calculateShouldZeroSides()); |
| 458 | + } |
| 459 | + |
| 460 | + @Test |
| 461 | + @Config(minSdk = API_LEVELS.FLUTTER_MIN, maxSdk = API_LEVELS.API_29, qualifiers = "land") |
| 462 | + public void calculateShouldZeroSidesInLandscapeRotation90() { |
| 463 | + FlutterView flutterView = spy(new FlutterView(ctx)); |
| 464 | + setExpectedDisplayRotation(Surface.ROTATION_90); |
| 465 | + assertEquals(FlutterView.ZeroSides.RIGHT, flutterView.calculateShouldZeroSides()); |
| 466 | + } |
| 467 | + |
| 468 | + @Test |
| 469 | + @Config(minSdk = API_LEVELS.API_21, maxSdk = API_LEVELS.API_22, qualifiers = "land") |
| 470 | + public void calculateShouldZeroSidesInLandscapeRotation270API22() { |
| 471 | + FlutterView flutterView = spy(new FlutterView(ctx)); |
| 472 | + setExpectedDisplayRotation(Surface.ROTATION_270); |
| 473 | + assertEquals(FlutterView.ZeroSides.RIGHT, flutterView.calculateShouldZeroSides()); |
| 474 | + } |
| 475 | + |
| 476 | + @Test |
| 477 | + @Config(minSdk = API_LEVELS.API_23, maxSdk = API_LEVELS.API_29, qualifiers = "land") |
| 478 | + public void calculateShouldZeroSidesInLandscapeRotation270API23Plus() { |
| 479 | + FlutterView flutterView = spy(new FlutterView(ctx)); |
| 480 | + setExpectedDisplayRotation(Surface.ROTATION_270); |
| 481 | + assertEquals(FlutterView.ZeroSides.LEFT, flutterView.calculateShouldZeroSides()); |
| 482 | + } |
| 483 | + |
441 | 484 | @SuppressWarnings("deprecation")
|
442 | 485 | // getSystemUiVisibility, getWindowSystemUiVisibility required to test pre api 30 behavior.
|
443 | 486 | @Test
|
@@ -615,9 +658,6 @@ public void systemInsetDisplayCutoutSimple() {
|
615 | 658 | public void itRegistersAndUnregistersToWindowManager() {
|
616 | 659 | Context context = Robolectric.setupActivity(Activity.class);
|
617 | 660 | FlutterView flutterView = spy(new FlutterView(context));
|
618 |
| - ShadowDisplay display = |
619 |
| - Shadows.shadowOf( |
620 |
| - ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()); |
621 | 661 | WindowInfoRepositoryCallbackAdapterWrapper windowInfoRepo =
|
622 | 662 | mock(WindowInfoRepositoryCallbackAdapterWrapper.class);
|
623 | 663 | // For reasoning behing using doReturn instead of when, read "Important gotcha" at
|
@@ -646,9 +686,6 @@ public void itRegistersAndUnregistersToWindowManager() {
|
646 | 686 | public void itSendsHingeDisplayFeatureToFlutter() {
|
647 | 687 | Context context = Robolectric.setupActivity(Activity.class);
|
648 | 688 | FlutterView flutterView = spy(new FlutterView(context));
|
649 |
| - ShadowDisplay display = |
650 |
| - Shadows.shadowOf( |
651 |
| - ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()); |
652 | 689 | when(flutterView.getContext()).thenReturn(context);
|
653 | 690 | WindowInfoRepositoryCallbackAdapterWrapper windowInfoRepo =
|
654 | 691 | mock(WindowInfoRepositoryCallbackAdapterWrapper.class);
|
@@ -1102,10 +1139,10 @@ public SettingsChannel.MessageBuilder answer(InvocationOnMock invocation)
|
1102 | 1139 |
|
1103 | 1140 | @SuppressWarnings("deprecation")
|
1104 | 1141 | private void setExpectedDisplayRotation(int rotation) {
|
1105 |
| - ShadowDisplay display = |
| 1142 | + ShadowDisplay myDisplay = |
1106 | 1143 | Shadows.shadowOf(
|
1107 |
| - ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()); |
1108 |
| - display.setRotation(rotation); |
| 1144 | + ((DisplayManager) ctx.getSystemService(Context.DISPLAY_SERVICE)).getDisplay(0)); |
| 1145 | + myDisplay.setRotation(rotation); |
1109 | 1146 | }
|
1110 | 1147 |
|
1111 | 1148 | private void validateViewportMetricPadding(
|
|
0 commit comments