Replace ColorDisplayController references
with ColorDisplayManager, where possible
Bug: 123352608
Test: atest FrameworksServicesTests:ColorDisplayServiceTest
Change-Id: I4feb67197462d49002582931aee285abe85054e6
diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java
index fece94e..c3f61ee 100644
--- a/packages/SystemUI/src/com/android/systemui/Dependency.java
+++ b/packages/SystemUI/src/com/android/systemui/Dependency.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.hardware.SensorPrivacyManager;
+import android.hardware.display.NightDisplayListener;
import android.os.Handler;
import android.os.Looper;
import android.util.ArrayMap;
@@ -25,7 +26,6 @@
import android.view.IWindowManager;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.Preconditions;
@@ -206,7 +206,7 @@
@Inject Lazy<UserInfoController> mUserInfoController;
@Inject Lazy<KeyguardMonitor> mKeyguardMonitor;
@Inject Lazy<BatteryController> mBatteryController;
- @Inject Lazy<ColorDisplayController> mColorDisplayController;
+ @Inject Lazy<NightDisplayListener> mNightDisplayListener;
@Inject Lazy<ManagedProfileController> mManagedProfileController;
@Inject Lazy<NextAlarmController> mNextAlarmController;
@Inject Lazy<DataSaverController> mDataSaverController;
@@ -330,7 +330,7 @@
mProviders.put(BatteryController.class, mBatteryController::get);
- mProviders.put(ColorDisplayController.class, mColorDisplayController::get);
+ mProviders.put(NightDisplayListener.class, mNightDisplayListener::get);
mProviders.put(ManagedProfileController.class, mManagedProfileController::get);
diff --git a/packages/SystemUI/src/com/android/systemui/DependencyProvider.java b/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
index 88e32cb..a517d7c 100644
--- a/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/DependencyProvider.java
@@ -24,6 +24,7 @@
import android.annotation.Nullable;
import android.content.Context;
import android.hardware.SensorPrivacyManager;
+import android.hardware.display.NightDisplayListener;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
@@ -34,7 +35,6 @@
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
-import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -152,8 +152,8 @@
@Singleton
@Provides
- public ColorDisplayController provideColorDisplayController(Context context) {
- return new ColorDisplayController(context);
+ public NightDisplayListener provideNightDisplayListener(Context context) {
+ return new NightDisplayListener(context);
}
@Singleton
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java
index de78d33..effa935 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java
@@ -22,6 +22,7 @@
import android.app.ActivityManager;
import android.content.Intent;
import android.hardware.display.ColorDisplayManager;
+import android.hardware.display.NightDisplayListener;
import android.metrics.LogMaker;
import android.provider.Settings;
import android.service.quicksettings.Tile;
@@ -31,7 +32,6 @@
import androidx.annotation.StringRes;
-import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSTile.BooleanState;
@@ -46,8 +46,9 @@
import javax.inject.Inject;
-public class NightDisplayTile extends QSTileImpl<BooleanState>
- implements ColorDisplayController.Callback {
+/** Quick settings tile: Night display **/
+public class NightDisplayTile extends QSTileImpl<BooleanState> implements
+ NightDisplayListener.Callback {
/**
* Pattern for {@link java.time.format.DateTimeFormatter} used to approximate the time to the
@@ -57,13 +58,15 @@
private static final String PATTERN_HOUR_MINUTE = "h:mm a";
private static final String PATTERN_HOUR_NINUTE_24 = "HH:mm";
- private ColorDisplayController mController;
+ private final ColorDisplayManager mManager;
+ private NightDisplayListener mListener;
private boolean mIsListening;
@Inject
public NightDisplayTile(QSHost host) {
super(host);
- mController = new ColorDisplayController(mContext, ActivityManager.getCurrentUser());
+ mManager = mContext.getSystemService(ColorDisplayManager.class);
+ mListener = new NightDisplayListener(mContext, ActivityManager.getCurrentUser());
}
@Override
@@ -81,27 +84,27 @@
// Enroll in forced auto mode if eligible.
if ("1".equals(Settings.Global.getString(mContext.getContentResolver(),
Settings.Global.NIGHT_DISPLAY_FORCED_AUTO_MODE_AVAILABLE))
- && mController.getAutoModeRaw() == -1) {
- mController.setAutoMode(ColorDisplayManager.AUTO_MODE_CUSTOM_TIME);
+ && mManager.getNightDisplayAutoModeRaw() == -1) {
+ mManager.setNightDisplayAutoMode(ColorDisplayManager.AUTO_MODE_CUSTOM_TIME);
Log.i("NightDisplayTile", "Enrolled in forced night display auto mode");
}
// Change current activation state.
final boolean activated = !mState.value;
- mController.setActivated(activated);
+ mManager.setNightDisplayActivated(activated);
}
@Override
protected void handleUserSwitch(int newUserId) {
// Stop listening to the old controller.
if (mIsListening) {
- mController.setListener(null);
+ mListener.setCallback(null);
}
// Make a new controller for the new user.
- mController = new ColorDisplayController(mContext, newUserId);
+ mListener = new NightDisplayListener(mContext, newUserId);
if (mIsListening) {
- mController.setListener(this);
+ mListener.setCallback(this);
}
super.handleUserSwitch(newUserId);
@@ -109,7 +112,7 @@
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
- state.value = mController.isActivated();
+ state.value = mManager.isNightDisplayActivated();
state.label = mContext.getString(R.string.quick_settings_night_display_label);
state.icon = ResourceIcon.get(com.android.internal.R.drawable.ic_qs_night_display_on);
state.expandedAccessibilityClassName = Switch.class.getName();
@@ -121,12 +124,12 @@
}
/**
- * Returns a {@link String} for the secondary label that reflects when the light will be turned
- * on or off based on the current auto mode and night light activated status.
+ * Returns a String for the secondary label that reflects when the light will be turned on or
+ * off based on the current auto mode and night light activated status.
*/
@Nullable
private String getSecondaryLabel(boolean isNightLightActivated) {
- switch(mController.getAutoMode()) {
+ switch (mManager.getNightDisplayAutoMode()) {
case ColorDisplayManager.AUTO_MODE_TWILIGHT:
// Auto mode related to sunrise & sunset. If the light is on, it's guaranteed to be
// turned off at sunrise. If it's off, it's guaranteed to be turned on at sunset.
@@ -143,10 +146,10 @@
final DateTimeFormatter toggleTimeFormat;
if (isNightLightActivated) {
- toggleTime = mController.getCustomEndTime();
+ toggleTime = mManager.getNightDisplayCustomEndTime();
toggleTimeStringRes = R.string.quick_settings_secondary_label_until;
} else {
- toggleTime = mController.getCustomStartTime();
+ toggleTime = mManager.getNightDisplayCustomStartTime();
toggleTimeStringRes = R.string.quick_settings_night_secondary_label_on_at;
}
@@ -175,7 +178,8 @@
@Override
public LogMaker populate(LogMaker logMaker) {
- return super.populate(logMaker).addTaggedData(FIELD_QS_MODE, mController.getAutoModeRaw());
+ return super.populate(logMaker)
+ .addTaggedData(FIELD_QS_MODE, mManager.getNightDisplayAutoModeRaw());
}
@Override
@@ -187,10 +191,10 @@
protected void handleSetListening(boolean listening) {
mIsListening = listening;
if (listening) {
- mController.setListener(this);
+ mListener.setCallback(this);
refreshState();
} else {
- mController.setListener(null);
+ mListener.setCallback(null);
}
}
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 b96c55b..c9be2c8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java
@@ -16,11 +16,11 @@
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
+import android.hardware.display.NightDisplayListener;
import android.os.Handler;
import android.provider.Settings.Secure;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.app.ColorDisplayController;
import com.android.systemui.Dependency;
import com.android.systemui.qs.AutoAddTracker;
import com.android.systemui.qs.QSTileHost;
@@ -50,7 +50,7 @@
private final HotspotController mHotspotController;
private final DataSaverController mDataSaverController;
private final ManagedProfileController mManagedProfileController;
- private final ColorDisplayController mColorDisplayController;
+ private final NightDisplayListener mNightDisplayListener;
@Inject
public AutoTileManager(Context context, AutoAddTracker autoAddTracker, QSTileHost host,
@@ -58,7 +58,7 @@
HotspotController hotspotController,
DataSaverController dataSaverController,
ManagedProfileController managedProfileController,
- ColorDisplayController colorDisplayController) {
+ NightDisplayListener nightDisplayListener) {
mAutoTracker = autoAddTracker;
mContext = context;
mHost = host;
@@ -66,7 +66,7 @@
mHotspotController = hotspotController;
mDataSaverController = dataSaverController;
mManagedProfileController = managedProfileController;
- mColorDisplayController = colorDisplayController;
+ mNightDisplayListener = nightDisplayListener;
if (!mAutoTracker.isAdded(HOTSPOT)) {
hotspotController.addCallback(mHotspotCallback);
}
@@ -93,7 +93,7 @@
}
if (!mAutoTracker.isAdded(NIGHT)
&& ColorDisplayManager.isNightDisplayAvailable(mContext)) {
- colorDisplayController.setListener(mColorDisplayCallback);
+ nightDisplayListener.setCallback(mNightDisplayCallback);
}
}
@@ -106,7 +106,7 @@
mDataSaverController.removeCallback(mDataSaverListener);
mManagedProfileController.removeCallback(mProfileCallback);
if (ColorDisplayManager.isNightDisplayAvailable(mContext)) {
- mColorDisplayController.setListener(null);
+ mNightDisplayListener.setCallback(null);
}
}
@@ -157,8 +157,8 @@
};
@VisibleForTesting
- final ColorDisplayController.Callback mColorDisplayCallback =
- new ColorDisplayController.Callback() {
+ final NightDisplayListener.Callback mNightDisplayCallback =
+ new NightDisplayListener.Callback() {
@Override
public void onActivated(boolean activated) {
if (activated) {
@@ -178,7 +178,7 @@
if (mAutoTracker.isAdded(NIGHT)) return;
mHost.addTile(NIGHT);
mAutoTracker.setTileAdded(NIGHT);
- mHandler.post(() -> mColorDisplayController.setListener(null));
+ mHandler.post(() -> mNightDisplayListener.setCallback(null));
}
};
}