From 2e404ea083b78082ef0f6c249c88fcac5fb28234 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Tue, 20 Sep 2022 23:37:11 +0800 Subject: [PATCH] Fix inverted setSystemUIChangeCallback (flutter/engine#36248) --- .../plugin/platform/PlatformPlugin.java | 4 +-- .../plugin/platform/PlatformPluginTest.java | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index bafd79c363..55af0485bf 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -239,12 +239,12 @@ public class PlatformPlugin { // controls. Another common action is to set a timer to dismiss // the system bars and restore the fullscreen mode that was // previously enabled. - platformChannel.systemChromeChanged(false); + platformChannel.systemChromeChanged(true); } else { // The system bars are NOT visible. Make any desired adjustments // to your UI, such as hiding the action bar or other // navigational controls. - platformChannel.systemChromeChanged(true); + platformChannel.systemChromeChanged(false); } }); } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java index ec4c76850b..2aa09af6c8 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -372,7 +372,36 @@ public class PlatformPluginTest { } @Test - public void setSystemUiModeListener() { + public void setSystemUiModeListener_overlaysAreHidden() { + ActivityController controller = Robolectric.buildActivity(Activity.class); + controller.setup(); + Activity fakeActivity = controller.get(); + + PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); + PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel); + + // Subscribe to system UI visibility events. + platformPlugin.mPlatformMessageHandler.setSystemUiChangeListener(); + + // Simulate system UI changed to full screen. + fakeActivity + .getWindow() + .getDecorView() + .dispatchSystemUiVisibilityChanged(View.SYSTEM_UI_FLAG_FULLSCREEN); + + // No events should have been sent to the platform channel yet. They are scheduled for + // the next frame. + verify(fakePlatformChannel, never()).systemChromeChanged(anyBoolean()); + + // Simulate the next frame. + ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); + + // Now the platform channel should receive the event. + verify(fakePlatformChannel).systemChromeChanged(false); + } + + @Test + public void setSystemUiModeListener_overlaysAreVisible() { ActivityController controller = Robolectric.buildActivity(Activity.class); controller.setup(); Activity fakeActivity = controller.get(); @@ -383,7 +412,7 @@ public class PlatformPluginTest { // Subscribe to system Ui visibility events. platformPlugin.mPlatformMessageHandler.setSystemUiChangeListener(); - // Simulate changing of the system ui visibility. + // Simulate system UI changed to *not* full screen. fakeActivity.getWindow().getDecorView().dispatchSystemUiVisibilityChanged(0); // No events should have been sent to the platform channel yet. They are scheduled for @@ -394,7 +423,7 @@ public class PlatformPluginTest { ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); // Now the platform channel should receive the event. - verify(fakePlatformChannel).systemChromeChanged(anyBoolean()); + verify(fakePlatformChannel).systemChromeChanged(true); } @Config(sdk = 28)