Activate dark theme when the UiMode is UI_MODE_NIGHT_YES.
This change also activates night mode when the device enters
battery saver (saving substantial power on OLED screens).
Bug: 80307398
Test: adb shell service call uimode 4 i32 1 # nightfall
adb shell service call uimode 4 i32 2 # morningtide
Change-Id: I9c08a749d4cd99ab7231363b045949eb2e830dfa
This commit is contained in:
committed by
Daniel Sandler
parent
694b4ae846
commit
a5c846c3fa
@@ -52,6 +52,7 @@ import android.app.NotificationManager;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.StatusBarManager;
|
import android.app.StatusBarManager;
|
||||||
import android.app.TaskStackBuilder;
|
import android.app.TaskStackBuilder;
|
||||||
|
import android.app.UiModeManager;
|
||||||
import android.app.WallpaperColors;
|
import android.app.WallpaperColors;
|
||||||
import android.app.WallpaperInfo;
|
import android.app.WallpaperInfo;
|
||||||
import android.app.WallpaperManager;
|
import android.app.WallpaperManager;
|
||||||
@@ -326,6 +327,12 @@ public class StatusBar extends SystemUI implements DemoMode,
|
|||||||
/** If true, the lockscreen will show a distinct wallpaper */
|
/** If true, the lockscreen will show a distinct wallpaper */
|
||||||
private static final boolean ENABLE_LOCKSCREEN_WALLPAPER = true;
|
private static final boolean ENABLE_LOCKSCREEN_WALLPAPER = true;
|
||||||
|
|
||||||
|
/** Whether to force dark theme if Configuration.UI_MODE_NIGHT_YES. */
|
||||||
|
private static final boolean DARK_THEME_IN_NIGHT_MODE = true;
|
||||||
|
|
||||||
|
/** Whether to switch the device into night mode in battery saver. */
|
||||||
|
private static final boolean NIGHT_MODE_IN_BATTERY_SAVER = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Never let the alpha become zero for surfaces that draw with SRC - otherwise the RenderNode
|
* Never let the alpha become zero for surfaces that draw with SRC - otherwise the RenderNode
|
||||||
* won't draw anything and uninitialized memory will show through
|
* won't draw anything and uninitialized memory will show through
|
||||||
@@ -931,6 +938,10 @@ public class StatusBar extends SystemUI implements DemoMode,
|
|||||||
if (mDozeServiceHost != null) {
|
if (mDozeServiceHost != null) {
|
||||||
mDozeServiceHost.firePowerSaveChanged(isPowerSave);
|
mDozeServiceHost.firePowerSaveChanged(isPowerSave);
|
||||||
}
|
}
|
||||||
|
if (NIGHT_MODE_IN_BATTERY_SAVER) {
|
||||||
|
mContext.getSystemService(UiModeManager.class).setNightMode(
|
||||||
|
isPowerSave ? UiModeManager.MODE_NIGHT_YES : UiModeManager.MODE_NIGHT_NO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -3128,6 +3139,7 @@ public class StatusBar extends SystemUI implements DemoMode,
|
|||||||
public void onConfigChanged(Configuration newConfig) {
|
public void onConfigChanged(Configuration newConfig) {
|
||||||
updateResources();
|
updateResources();
|
||||||
updateDisplaySize(); // populates mDisplayMetrics
|
updateDisplaySize(); // populates mDisplayMetrics
|
||||||
|
updateTheme();
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, "configuration changed: " + mContext.getResources().getConfiguration());
|
Log.v(TAG, "configuration changed: " + mContext.getResources().getConfiguration());
|
||||||
@@ -3867,8 +3879,13 @@ public class StatusBar extends SystemUI implements DemoMode,
|
|||||||
// The system wallpaper defines if QS should be light or dark.
|
// The system wallpaper defines if QS should be light or dark.
|
||||||
WallpaperColors systemColors = mColorExtractor
|
WallpaperColors systemColors = mColorExtractor
|
||||||
.getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
|
.getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
|
||||||
final boolean useDarkTheme = systemColors != null
|
final boolean wallpaperWantsDarkTheme = systemColors != null
|
||||||
&& (systemColors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_THEME) != 0;
|
&& (systemColors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_THEME) != 0;
|
||||||
|
final Configuration config = mContext.getResources().getConfiguration();
|
||||||
|
final boolean nightModeWantsDarkTheme = DARK_THEME_IN_NIGHT_MODE
|
||||||
|
&& (config.uiMode & Configuration.UI_MODE_NIGHT_MASK)
|
||||||
|
== Configuration.UI_MODE_NIGHT_YES;
|
||||||
|
final boolean useDarkTheme = wallpaperWantsDarkTheme || nightModeWantsDarkTheme;
|
||||||
if (isUsingDarkTheme() != useDarkTheme) {
|
if (isUsingDarkTheme() != useDarkTheme) {
|
||||||
mUiOffloadThread.submit(() -> {
|
mUiOffloadThread.submit(() -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user