diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index a1d38ba0720db..a7d1c628b3c26 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -363,6 +363,7 @@ private void restoreSystemChromeSystemUIOverlays() { updateSystemUiOverlays(); } + @SuppressWarnings("deprecation") private void setSystemChromeSystemUIOverlayStyle( PlatformChannel.SystemChromeStyle systemChromeStyle) { Window window = activity.getWindow(); @@ -370,6 +371,20 @@ private void setSystemChromeSystemUIOverlayStyle( WindowInsetsControllerCompat windowInsetsControllerCompat = new WindowInsetsControllerCompat(window, view); + if (Build.VERSION.SDK_INT < 30) { + // Flag set to specify that this window is responsible for drawing the background for the + // system bars. Must be set for all operations on API < 30 excluding enforcing system + // bar contrasts. Deprecated in API 30. + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + + // Flag set to dismiss any requests for translucent system bars to be provided in lieu of what + // is specified by systemChromeStyle. Must be set for all operations on API < 30 operations + // excluding enforcing system bar contrasts. Deprecated in API 30. + window.clearFlags( + WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS + | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + } + // SYSTEM STATUS BAR ------------------------------------------------------------------- // You can't change the color of the system status bar until SDK 21, and you can't change the // color of the status icons until SDK 23. We only allow both starting at 23 to ensure buttons @@ -433,8 +448,6 @@ private void setSystemChromeSystemUIOverlayStyle( } // You can't change the color of the navigation bar divider color until SDK 28. if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) { - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor); } diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java index 2a04684aa6ab2..f6c005660b89c 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -23,6 +23,7 @@ import android.view.View; import android.view.Window; import android.view.WindowInsetsController; +import android.view.WindowManager; import androidx.activity.OnBackPressedCallback; import androidx.fragment.app.FragmentActivity; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -387,6 +388,29 @@ public void doNotEnableEdgeToEdgeOnOlderSdk() { | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } + @Config(sdk = 29) + @Test + public void verifyWindowFlagsSetToStyleOverlays() { + View fakeDecorView = mock(View.class); + Window fakeWindow = mock(Window.class); + when(fakeWindow.getDecorView()).thenReturn(fakeDecorView); + Activity fakeActivity = mock(Activity.class); + when(fakeActivity.getWindow()).thenReturn(fakeWindow); + PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); + PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel); + + SystemChromeStyle style = + new SystemChromeStyle( + 0XFF000000, Brightness.LIGHT, true, 0XFFC70039, Brightness.LIGHT, 0XFF006DB3, true); + + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); + verify(fakeWindow).addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + verify(fakeWindow) + .clearFlags( + WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS + | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + } + @Test public void popSystemNavigatorFlutterActivity() { Activity mockActivity = mock(Activity.class);