Update dark theme slice for new display criteria

- Add "dark theme scheduling is off" as a new display creteria.

Fixes: 142476879
Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.homepage
Change-Id: Ib88edd0bd9d4b776cdf8ec93bac4e199e0da41de
This commit is contained in:
Sunny Shao
2020-01-31 10:49:03 +08:00
parent f38bff9e0b
commit 1f3429a25d
2 changed files with 44 additions and 3 deletions

View File

@@ -162,11 +162,10 @@ public class DarkThemeSlice implements CustomSliceable {
@VisibleForTesting
boolean isAvailable(Context context) {
// checking dark theme mode.
if (isDarkThemeMode(context)) {
// check if dark theme mode is enabled or if dark theme scheduling is on.
if (isDarkThemeMode(context) || isNightModeScheduled()) {
return false;
}
// checking the current battery level
final BatteryManager batteryManager = context.getSystemService(BatteryManager.class);
final int level = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
@@ -186,6 +185,18 @@ public class DarkThemeSlice implements CustomSliceable {
sSliceClicked = clicked;
}
private boolean isNightModeScheduled() {
final int mode = mUiModeManager.getNightMode();
if (DEBUG) {
Log.d(TAG, "night mode : " + mode);
}
// Turn on from sunset to sunrise or turn on at custom time
if (mode == UiModeManager.MODE_NIGHT_AUTO || mode == UiModeManager.MODE_NIGHT_CUSTOM) {
return true;
}
return false;
}
public static class DarkThemeWorker extends SliceBackgroundWorker<Void> {
private final Context mContext;
private final ContentObserver mContentObserver =