From 0eb56cb3595889b46496ded1cc6532118a85ce76 Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Thu, 1 Jul 2021 22:57:35 +0800 Subject: [PATCH] Remove the light flag if the bar isn't specified light in theme Previously, PhoneWindow will add the light flag for the bar if it is specified light in theme. It won't remove the light flag if the theme is not light. The previous logic in PhoneWindow#generateLayout assumes the decor view was newly created. However, the decor view can be reused from the preserved window. This happens if the activity is recreated. So if the previous activity was in a light theme and the newly created activity is in a dark theme, we should clear the light bar flags added in the previous activity. Fix: 174502412 Test: 1. Set Dialer (Phone) to dark theme from Dialer's display options. 2. Clear app data from Dialer's app info. 3. Open Dialer again and see if the color of system bars are normal. Change-Id: I3ea61322e4c3cfe26981e23792f42ab0b9a1e217 --- .../android/internal/policy/PhoneWindow.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index 1a23cc11fca8d..4cf53504f4667 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -70,12 +70,12 @@ import android.transition.TransitionInflater; import android.transition.TransitionManager; import android.transition.TransitionSet; import android.util.AndroidRuntimeException; -import android.view.AttachedSurfaceControl; import android.util.EventLog; import android.util.Log; import android.util.Pair; import android.util.SparseArray; import android.util.TypedValue; +import android.view.AttachedSurfaceControl; import android.view.ContextThemeWrapper; import android.view.CrossWindowBlurListeners; import android.view.Gravity; @@ -2512,14 +2512,15 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } params.privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION; } - if (a.getBoolean(R.styleable.Window_windowLightStatusBar, false)) { - decor.setSystemUiVisibility( - decor.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); - } - if (a.getBoolean(R.styleable.Window_windowLightNavigationBar, false)) { - decor.setSystemUiVisibility( - decor.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } + final int sysUiVis = decor.getSystemUiVisibility(); + final int statusLightFlag = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + final int statusFlag = a.getBoolean(R.styleable.Window_windowLightStatusBar, false) + ? statusLightFlag : 0; + final int navLightFlag = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + final int navFlag = a.getBoolean(R.styleable.Window_windowLightNavigationBar, false) + ? navLightFlag : 0; + decor.setSystemUiVisibility( + (sysUiVis & ~(statusLightFlag | navLightFlag)) | (statusFlag | navFlag)); if (a.hasValue(R.styleable.Window_windowLayoutInDisplayCutoutMode)) { int mode = a.getInt(R.styleable.Window_windowLayoutInDisplayCutoutMode, -1); if (mode < LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT