diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 16084fb879e87..a46213c0f777f 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -445,6 +445,10 @@ public void updateSystemUiOverlays() { } } } + + if (currentTheme != null) { + setSystemChromeSystemUIOverlayStyle(currentTheme); + } } private void restoreSystemChromeSystemUIOverlays() { 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 ea8448363ca23..b44d67011d919 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -6,6 +6,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.anyBoolean; +import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -505,6 +507,43 @@ public void showSystemOverlays() { verify(fakeWindowInsetsController).show(WindowInsetsCompat.Type.navigationBars()); } + @Config(sdk = 30) + @Test + public void verifyUpdateSystemUiOverlaysAppliesCurrentTheme() { + 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); + WindowInsetsController fakeWindowInsetsController = mock(WindowInsetsController.class); + when(fakeWindow.getInsetsController()).thenReturn(fakeWindowInsetsController); + + // Style that requires usage of all system bar APIs used in PlatformPlugin to update overlay + // style + SystemChromeStyle testStyle = + new SystemChromeStyle( + 0XFF000000, Brightness.LIGHT, true, 0XFFC70039, Brightness.LIGHT, 0XFF006DB3, true); + + platformPlugin.updateSystemUiOverlays(); + + verify(fakeWindow, never()).setStatusBarColor(anyInt()); + verify(fakeWindow, never()).setNavigationBarColor(anyInt()); + verify(fakeWindow, never()).setNavigationBarDividerColor(anyInt()); + verify(fakeWindow, never()).setStatusBarContrastEnforced(anyBoolean()); + verify(fakeWindow, never()).setNavigationBarContrastEnforced(anyBoolean()); + + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(testStyle); + platformPlugin.updateSystemUiOverlays(); + + verify(fakeWindow, times(2)).setStatusBarColor(0xFF000000); + verify(fakeWindow, times(2)).setNavigationBarColor(0XFFC70039); + verify(fakeWindow, times(2)).setNavigationBarDividerColor(0XFF006DB3); + verify(fakeWindow, times(2)).setStatusBarContrastEnforced(true); + verify(fakeWindow, times(2)).setNavigationBarContrastEnforced(true); + } + @Config(sdk = 28) @Test public void doNotEnableEdgeToEdgeOnOlderSdk() {