Add QS tile for Night Display when first used
Bug: 30994985
Test: runtest systemui, and manual - verify that the quick settings
panel does not have a Night Display quick settings tile, then turn
Night Display on and verify that the tile has appeared. Multiuser
does NOT work and is tracked separately.
Change-Id: I997b4ca7952016fc703a6bb777e500f4eccce189
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index 8f9358f..bb7e19d 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -23,6 +23,7 @@
import android.util.ArrayMap;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.app.NightDisplayController;
import com.android.internal.util.Preconditions;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.fragments.FragmentService;
@@ -180,6 +181,9 @@
mProviders.put(BatteryController.class, () ->
new BatteryControllerImpl(mContext));
+ mProviders.put(NightDisplayController.class, () ->
+ new NightDisplayController(mContext));
+
mProviders.put(ManagedProfileController.class, () ->
new ManagedProfileControllerImpl(mContext));
diff --git a/packages/SystemUI/src/com/android/systemui/Prefs.java b/packages/SystemUI/src/com/android/systemui/Prefs.java
index b9ae585..e1aaaa3 100644
--- a/packages/SystemUI/src/com/android/systemui/Prefs.java
+++ b/packages/SystemUI/src/com/android/systemui/Prefs.java
@@ -47,6 +47,7 @@
Key.QS_DATA_SAVER_DIALOG_SHOWN,
Key.QS_INVERT_COLORS_ADDED,
Key.QS_WORK_ADDED,
+ Key.QS_NIGHTDISPLAY_ADDED,
})
public @interface Key {
@Deprecated
@@ -67,6 +68,7 @@
String QS_DATA_SAVER_DIALOG_SHOWN = "QsDataSaverDialogShown";
String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded";
String QS_WORK_ADDED = "QsWorkAdded";
+ String QS_NIGHTDISPLAY_ADDED = "QsNightDisplayAdded";
}
public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
index 31cfa66..cd9a49d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
@@ -19,6 +19,8 @@
import android.os.Looper;
import android.provider.Settings.Secure;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.app.NightDisplayController;
import com.android.systemui.Dependency;
import com.android.systemui.Prefs;
import com.android.systemui.Prefs.Key;
@@ -64,6 +66,11 @@
if (!Prefs.getBoolean(context, Key.QS_WORK_ADDED, false)) {
Dependency.get(ManagedProfileController.class).addCallback(mProfileCallback);
}
+
+ if (!Prefs.getBoolean(context, Key.QS_NIGHTDISPLAY_ADDED, false)
+ && NightDisplayController.isAvailable(mContext)) {
+ Dependency.get(NightDisplayController.class).setListener(mNightDisplayCallback);
+ }
}
public void destroy() {
@@ -71,6 +78,7 @@
Dependency.get(HotspotController.class).removeCallback(mHotspotCallback);
Dependency.get(DataSaverController.class).removeCallback(mDataSaverListener);
Dependency.get(ManagedProfileController.class).removeCallback(mProfileCallback);
+ Dependency.get(NightDisplayController.class).setListener(null);
}
private final ManagedProfileController.Callback mProfileCallback =
@@ -115,4 +123,30 @@
}
}
};
+
+ @VisibleForTesting
+ final NightDisplayController.Callback mNightDisplayCallback =
+ new NightDisplayController.Callback() {
+ @Override
+ public void onActivated(boolean activated) {
+ if (activated) {
+ addNightTile();
+ }
+ }
+
+ @Override
+ public void onAutoModeChanged(int autoMode) {
+ if (autoMode == NightDisplayController.AUTO_MODE_CUSTOM
+ || autoMode == NightDisplayController.AUTO_MODE_TWILIGHT) {
+ addNightTile();
+ }
+ }
+
+ private void addNightTile() {
+ mHost.addTile("night");
+ Prefs.putBoolean(mContext, Key.QS_NIGHTDISPLAY_ADDED, true);
+ mHandler.post(() -> Dependency.get(NightDisplayController.class)
+ .setListener(null));
+ }
+ };
}