From 0a5dbbe5228d8175e8b74f46822d8ee55dae9be1 Mon Sep 17 00:00:00 2001 From: Wyte Krongapiradee Date: Fri, 12 Nov 2021 04:29:31 +0800 Subject: [PATCH] Do not update system UI overlays when the SDK version condition is not met (flutter/engine#29643) --- .../plugin/platform/PlatformPlugin.java | 9 ++++----- .../plugin/platform/PlatformPluginTest.java | 20 +++++++++++++++++++ 2 files changed, 24 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 46d0aecf0b..1496253a25 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 @@ -238,11 +238,7 @@ public class PlatformPlugin { } private void setSystemChromeEnabledSystemUIMode(PlatformChannel.SystemUiMode systemUiMode) { - int enabledOverlays = - DEFAULT_SYSTEM_UI - | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; + int enabledOverlays; if (systemUiMode == PlatformChannel.SystemUiMode.LEAN_BACK && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { @@ -301,6 +297,9 @@ public class PlatformPlugin { View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + } else { + // When none of the conditions are matched, return without updating the system UI overlays. + return; } mEnabledOverlays = enabledOverlays; 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 06917e01f4..3800ddfbff 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 @@ -367,6 +367,26 @@ public class PlatformPluginTest { } } + @Config(sdk = 28) + @Test + public void doNotEnableEdgeToEdgeOnOlderSdk() { + 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); + + platformPlugin.mPlatformMessageHandler.showSystemUiMode( + PlatformChannel.SystemUiMode.EDGE_TO_EDGE); + verify(fakeDecorView, never()) + .setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } + @Test public void popSystemNavigatorFlutterActivity() { Activity mockActivity = mock(Activity.class);