From 7447d36921df489a87e38631c5f3032f70e3e1c4 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 24 Feb 2022 11:06:46 -0800 Subject: [PATCH 1/5] Add back line --- .../android/io/flutter/plugin/platform/PlatformPlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 16084fb879e87..7678933409b7a 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() { From b73357452d97307ca92365aa5ce15f21632813cc Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 24 Feb 2022 11:07:35 -0800 Subject: [PATCH 2/5] Formatting: --- .../android/io/flutter/plugin/platform/PlatformPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 7678933409b7a..a46213c0f777f 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -445,7 +445,7 @@ public void updateSystemUiOverlays() { } } } - + if (currentTheme != null) { setSystemChromeSystemUIOverlayStyle(currentTheme); } From e8397b77c5066f42b5b774534dae2d9f873ac479 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 24 Feb 2022 16:02:54 -0800 Subject: [PATCH 3/5] Add test --- .../plugin/platform/PlatformPlugin.java | 4 ++-- .../plugin/platform/PlatformPluginTest.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index a46213c0f777f..a04defa1a3464 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -455,8 +455,8 @@ private void restoreSystemChromeSystemUIOverlays() { updateSystemUiOverlays(); } - private void setSystemChromeSystemUIOverlayStyle( - PlatformChannel.SystemChromeStyle systemChromeStyle) { + @VisibleForTesting + void setSystemChromeSystemUIOverlayStyle(PlatformChannel.SystemChromeStyle systemChromeStyle) { Window window = activity.getWindow(); View view = window.getDecorView(); WindowInsetsControllerCompat windowInsetsControllerCompat = 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..c9bfd7bda4674 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -505,6 +505,30 @@ public void showSystemOverlays() { verify(fakeWindowInsetsController).show(WindowInsetsCompat.Type.navigationBars()); } + @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 = mock(PlatformPlugin.class); + WindowInsetsController fakeWindowInsetsController = mock(WindowInsetsController.class); + when(fakeWindow.getInsetsController()).thenReturn(fakeWindowInsetsController); + + SystemChromeStyle testStyle = + new SystemChromeStyle( + 0XFF000000, Brightness.LIGHT, true, 0XFFC70039, Brightness.LIGHT, 0XFF006DB3, true); + + platformPlugin.updateSystemUiOverlays(); + verify(platformPlugin, never()).setSystemChromeSystemUIOverlayStyle(testStyle); + + platformPlugin.setSystemChromeSystemUIOverlayStyle(testStyle); + platformPlugin.updateSystemUiOverlays(); + verify(platformPlugin).setSystemChromeSystemUIOverlayStyle(testStyle); + } + @Config(sdk = 28) @Test public void doNotEnableEdgeToEdgeOnOlderSdk() { From afe5e3fba8f6240bef014848150c785ae4144eae Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 25 Feb 2022 12:40:19 -0800 Subject: [PATCH 4/5] Test APIs --- .../plugin/platform/PlatformPluginTest.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 c9bfd7bda4674..26b10c746bfeb 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,7 @@ public void showSystemOverlays() { verify(fakeWindowInsetsController).show(WindowInsetsCompat.Type.navigationBars()); } + @Config(sdk = 30) @Test public void verifyUpdateSystemUiOverlaysAppliesCurrentTheme() { View fakeDecorView = mock(View.class); @@ -513,20 +516,32 @@ public void verifyUpdateSystemUiOverlaysAppliesCurrentTheme() { Activity fakeActivity = mock(Activity.class); when(fakeActivity.getWindow()).thenReturn(fakeWindow); PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); - PlatformPlugin platformPlugin = mock(PlatformPlugin.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(platformPlugin, never()).setSystemChromeSystemUIOverlayStyle(testStyle); + + 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.setSystemChromeSystemUIOverlayStyle(testStyle); platformPlugin.updateSystemUiOverlays(); - verify(platformPlugin).setSystemChromeSystemUIOverlayStyle(testStyle); + + 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) From e64c720c47cc5d68aba62b654d36d40eeb8a6671 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 25 Feb 2022 14:32:34 -0800 Subject: [PATCH 5/5] Fix test --- .../android/io/flutter/plugin/platform/PlatformPlugin.java | 4 ++-- .../test/io/flutter/plugin/platform/PlatformPluginTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index a04defa1a3464..a46213c0f777f 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -455,8 +455,8 @@ private void restoreSystemChromeSystemUIOverlays() { updateSystemUiOverlays(); } - @VisibleForTesting - void setSystemChromeSystemUIOverlayStyle(PlatformChannel.SystemChromeStyle systemChromeStyle) { + private void setSystemChromeSystemUIOverlayStyle( + PlatformChannel.SystemChromeStyle systemChromeStyle) { Window window = activity.getWindow(); View view = window.getDecorView(); WindowInsetsControllerCompat windowInsetsControllerCompat = 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 26b10c746bfeb..b44d67011d919 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -534,7 +534,7 @@ public void verifyUpdateSystemUiOverlaysAppliesCurrentTheme() { verify(fakeWindow, never()).setStatusBarContrastEnforced(anyBoolean()); verify(fakeWindow, never()).setNavigationBarContrastEnforced(anyBoolean()); - platformPlugin.setSystemChromeSystemUIOverlayStyle(testStyle); + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(testStyle); platformPlugin.updateSystemUiOverlays(); verify(fakeWindow, times(2)).setStatusBarColor(0xFF000000);