Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf388c2e authored by Christine Franks's avatar Christine Franks
Browse files

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
parent 1561bb41
Loading
Loading
Loading
Loading
+22 −18
Original line number Diff line number Diff line
@@ -367,7 +367,7 @@ public final class ColorDisplayController {
     * See com.android.server.display.DisplayTransformManager.
     */
    private @ColorMode int getCurrentColorModeFromSystemProperties() {
        int displayColorSetting = SystemProperties.getInt("persist.sys.sf.native_mode", 0);
        final int displayColorSetting = SystemProperties.getInt("persist.sys.sf.native_mode", 0);
        if (displayColorSetting == 0) {
            return "1.0".equals(SystemProperties.get("persist.sys.sf.color_saturation"))
                    ? COLOR_MODE_NATURAL : COLOR_MODE_BOOSTED;
@@ -381,18 +381,15 @@ public final class ColorDisplayController {
    }

    private boolean isColorModeAvailable(@ColorMode int colorMode) {
        // SATURATED is always allowed
        if (colorMode == COLOR_MODE_SATURATED) {
            return true;
        }

        final int[] availableColorModes = mContext.getResources().getIntArray(
                R.array.config_availableColorModes);
        if (availableColorModes != null) {
            for (int mode : availableColorModes) {
                if (mode == colorMode) {
                    return true;
                }
            }
        }
        return false;
    }

@@ -401,14 +398,18 @@ public final class ColorDisplayController {
     */
    public int getColorMode() {
        if (getAccessibilityTransformActivated()) {
            if (isColorModeAvailable(COLOR_MODE_SATURATED)) {
                return COLOR_MODE_SATURATED;
            } else if (isColorModeAvailable(COLOR_MODE_AUTOMATIC)) {
                return COLOR_MODE_AUTOMATIC;
            }
        }

        int colorMode = System.getIntForUser(mContext.getContentResolver(),
                System.DISPLAY_COLOR_MODE, -1, mUserId);
        if (colorMode == -1) {
            // There still might be a legacy system property controlling color mode that we need to
            // respect.
            // There might be a system property controlling color mode that we need to respect; if
            // not, this will set a suitable default.
            colorMode = getCurrentColorModeFromSystemProperties();
        }

@@ -420,8 +421,11 @@ public final class ColorDisplayController {
            } else if (colorMode == COLOR_MODE_SATURATED
                    && isColorModeAvailable(COLOR_MODE_AUTOMATIC)) {
                colorMode = COLOR_MODE_AUTOMATIC;
            } else {
            } else if (colorMode == COLOR_MODE_AUTOMATIC
                    && isColorModeAvailable(COLOR_MODE_SATURATED)) {
                colorMode = COLOR_MODE_SATURATED;
            } else {
                colorMode = -1;
            }
        }

+13 −6
Original line number Diff line number Diff line
@@ -189,6 +189,13 @@ public final class ColorDisplayService extends SystemService
        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 @@ public final class ColorDisplayService extends SystemService
        if (mIsActivated == null) {
            onActivated(mController.isActivated());
        }

        // Transition the screen to the current temperature.
        applyTint(false);
    }

    private void tearDown() {
@@ -223,8 +227,6 @@ public final class ColorDisplayService extends SystemService
            mColorMatrixAnimator.end();
            mColorMatrixAnimator = null;
        }

        mIsActivated = null;
    }

    @Override
@@ -288,6 +290,10 @@ public final class ColorDisplayService extends SystemService

    @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 @@ public final class ColorDisplayService extends SystemService
        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
+3 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.server;
package com.android.server.display;

import android.annotation.NonNull;
import android.app.ActivityManager;
@@ -32,8 +32,8 @@ import android.test.mock.MockContentResolver;

import com.android.internal.app.ColorDisplayController;
import com.android.internal.util.test.FakeSettingsProvider;
import com.android.server.display.DisplayTransformManager;
import com.android.server.display.ColorDisplayService;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.twilight.TwilightListener;
import com.android.server.twilight.TwilightManager;
import com.android.server.twilight.TwilightState;