Initialize color mode if set

ColorDisplayService doesn't start listening for changes until the end
of user setup, and color mode was previously unintialized at service
setup, so restored settings were ignored.

Bug: 79591550
Test: atest FrameworksServicesTest:ColorDisplayServiceTest
Change-Id: I00baed15e1248572d3dfd8f251dee7dc5a355a6c
diff --git a/services/core/java/com/android/server/display/ColorDisplayService.java b/services/core/java/com/android/server/display/ColorDisplayService.java
index 213ec36..0b6786c 100644
--- a/services/core/java/com/android/server/display/ColorDisplayService.java
+++ b/services/core/java/com/android/server/display/ColorDisplayService.java
@@ -189,6 +189,13 @@
         mController = new ColorDisplayController(getContext(), mCurrentUser);
         mController.setListener(this);
 
+        // Set the color mode, if valid, and immediately apply the updated tint matrix based on the
+        // existing activated state. This ensures consistency of tint across the color mode change.
+        onDisplayColorModeChanged(mController.getColorMode());
+
+        // Reset the activated state.
+        mIsActivated = null;
+
         setCoefficientMatrix(getContext(), DisplayTransformManager.needsLinearColorMatrix());
 
         // Prepare color transformation matrix.
@@ -201,9 +208,6 @@
         if (mIsActivated == null) {
             onActivated(mController.isActivated());
         }
-
-        // Transition the screen to the current temperature.
-        applyTint(false);
     }
 
     private void tearDown() {
@@ -223,8 +227,6 @@
             mColorMatrixAnimator.end();
             mColorMatrixAnimator = null;
         }
-
-        mIsActivated = null;
     }
 
     @Override
@@ -288,6 +290,10 @@
 
     @Override
     public void onDisplayColorModeChanged(int mode) {
+        if (mode == -1) {
+            return;
+        }
+
         // Cancel the night display tint animator if it's running.
         if (mColorMatrixAnimator != null) {
             mColorMatrixAnimator.cancel();
@@ -297,7 +303,8 @@
         setMatrix(mController.getColorTemperature(), mMatrixNight);
 
         final DisplayTransformManager dtm = getLocalService(DisplayTransformManager.class);
-        dtm.setColorMode(mode, mIsActivated ? mMatrixNight : MATRIX_IDENTITY);
+        dtm.setColorMode(mode, (mIsActivated != null && mIsActivated) ? mMatrixNight
+                : MATRIX_IDENTITY);
     }
 
     @Override