diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 13dacbee2c9ef..f5ab23c18a412 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -374,15 +374,17 @@ private void setSystemChromeSystemUIOverlayStyle( // 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 @@ private void setSystemChromeSystemUIOverlayStyle( // 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/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java index e67769cef904e..fea6db961e248 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -162,15 +162,41 @@ public void setNavigationBarDividerColor() { 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()); } }