From 761409f61e33ddb5e35fd4a94108803cb538d9e9 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Thu, 19 Aug 2021 23:42:02 -0400 Subject: [PATCH] Fix regression in system UI colors (flutter/engine#28206) --- .../plugin/platform/PlatformPlugin.java | 41 ++++++++++--------- .../plugin/platform/PlatformPluginTest.java | 28 ++++++++++++- 2 files changed, 49 insertions(+), 20 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 13dacbee2c..f5ab23c18a 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 @@ -374,15 +374,17 @@ public class PlatformPlugin { // If transparent, SDK 29 and higher may apply a translucent scrim behind the bar to ensure // proper contrast. This can be overridden with // SystemChromeStyle.systemStatusBarContrastEnforced. - if (systemChromeStyle.statusBarIconBrightness != null && Build.VERSION.SDK_INT >= 23) { - switch (systemChromeStyle.statusBarIconBrightness) { - case DARK: - // View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - flags |= 0x2000; - break; - case LIGHT: - flags &= ~0x2000; - break; + if (Build.VERSION.SDK_INT >= 23) { + if (systemChromeStyle.statusBarIconBrightness != null) { + switch (systemChromeStyle.statusBarIconBrightness) { + case DARK: + // View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + flags |= 0x2000; + break; + case LIGHT: + flags &= ~0x2000; + break; + } } if (systemChromeStyle.statusBarColor != null) { @@ -403,16 +405,17 @@ public class PlatformPlugin { // If transparent, SDK 29 and higher may apply a translucent scrim behind 2/3 button navigation // bars to ensure proper contrast. This can be overridden with // SystemChromeStyle.systemNavigationBarContrastEnforced. - if (systemChromeStyle.systemNavigationBarIconBrightness != null - && Build.VERSION.SDK_INT >= 26) { - switch (systemChromeStyle.systemNavigationBarIconBrightness) { - case DARK: - // View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - flags |= 0x10; - break; - case LIGHT: - flags &= ~0x10; - break; + if (Build.VERSION.SDK_INT >= 26) { + if (systemChromeStyle.systemNavigationBarIconBrightness != null) { + switch (systemChromeStyle.systemNavigationBarIconBrightness) { + case DARK: + // View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + flags |= 0x10; + break; + case LIGHT: + flags &= ~0x10; + break; + } } if (systemChromeStyle.systemNavigationBarColor != null) { 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 e67769cef9..fea6db961e 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 @@ -162,15 +162,41 @@ public class PlatformPluginTest { when(fakeActivity.getWindow()).thenReturn(fakeWindow); PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel); + // Default style test SystemChromeStyle style = - new SystemChromeStyle(0XFF000000, null, true, 0XFFC70039, null, 0XFF006DB3, true); + new SystemChromeStyle( + 0XFF000000, // statusBarColor + null, // statusBarIconBrightness + true, // systemStatusBarContrastEnforced + 0XFFC70039, // systemNavigationBarColor + null, // systemNavigationBarIconBrightness + 0XFF006DB3, // systemNavigationBarDividerColor + true); // systemNavigationBarContrastEnforced if (Build.VERSION.SDK_INT >= 28) { platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); + assertEquals(0XFF000000, fakeActivity.getWindow().getStatusBarColor()); + assertEquals(0XFFC70039, fakeActivity.getWindow().getNavigationBarColor()); assertEquals(0XFF006DB3, fakeActivity.getWindow().getNavigationBarDividerColor()); + + // Regression test for https://github.com/flutter/flutter/issues/88431 + // A null brightness should not affect changing color settings. + style = + new SystemChromeStyle( + 0XFF006DB3, // statusBarColor + null, // statusBarIconBrightness + true, // systemStatusBarContrastEnforced + 0XFF000000, // systemNavigationBarColor + null, // systemNavigationBarIconBrightness + 0XFF006DB3, // systemNavigationBarDividerColor + true); // systemNavigationBarContrastEnforced + + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); + assertEquals(0XFFC70039, fakeActivity.getWindow().getStatusBarColor()); assertEquals(0XFF000000, fakeActivity.getWindow().getNavigationBarColor()); + assertEquals(0XFF006DB3, fakeActivity.getWindow().getNavigationBarDividerColor()); } }