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

Commit 8851ac83 authored by Christine Franks's avatar Christine Franks
Browse files

Set exact night display last activated time

For automatic changes occuring precisely at a specific time, being
a few milliseconds off could lead to the system interpreting that
as a manual change.

This is most apparent when a time update occurs after restarting
the device.

Bug: 132844043
Test: atest FrameworksServicesTest:ColorDisplayServiceTest
Change-Id: I8de63f174a7e2f37623e04647bc55172a33730b8
parent f9b3b8e0
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -935,7 +935,7 @@ public final class ColorDisplayService extends SystemService {

            if (mNightDisplayTintController.isActivatedStateNotSet()
                    || (mNightDisplayTintController.isActivated() != activate)) {
                mNightDisplayTintController.setActivated(activate);
                mNightDisplayTintController.setActivated(activate, activate ? start : end);
            }

            updateNextAlarm(mNightDisplayTintController.isActivated(), now);
@@ -1131,6 +1131,14 @@ public final class ColorDisplayService extends SystemService {

        @Override
        public void setActivated(Boolean activated) {
            setActivated(activated, LocalDateTime.now());
        }

        /**
         * Use directly when it is important that the last activation time be exact (for example, an
         * automatic change). Otherwise use {@link #setActivated(Boolean)}.
         */
        public void setActivated(Boolean activated, @NonNull LocalDateTime lastActivationTime) {
            if (activated == null) {
                super.setActivated(null);
                return;
@@ -1142,7 +1150,7 @@ public final class ColorDisplayService extends SystemService {
                // This is a true state change, so set this as the last activation time.
                Secure.putStringForUser(getContext().getContentResolver(),
                        Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME,
                        LocalDateTime.now().toString(),
                        lastActivationTime.toString(),
                        mCurrentUser);
            }