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

Commit 5e45ca09 authored by Christine Franks's avatar Christine Franks Committed by android-build-merger
Browse files

Merge "Fix night display activation behavior after reboot" into oc-dev am: bd75ee00

am: 16c9c94e

Change-Id: I6806c3bde4a4739b2e8387840f706e753029d82b
parents 4447098b 16c9c94e
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -109,16 +109,38 @@ public final class NightDisplayController {
    }

    /**
     * Sets whether Night display should be activated.
     * Sets whether Night display should be activated. This also sets the last activated time.
     *
     * @param activated {@code true} if Night display should be activated
     * @return {@code true} if the activated value was set successfully
     */
    public boolean setActivated(boolean activated) {
        if (isActivated() != activated) {
            Secure.putLongForUser(mContext.getContentResolver(),
                    Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, System.currentTimeMillis(),
                    mUserId);
        }
        return Secure.putIntForUser(mContext.getContentResolver(),
                Secure.NIGHT_DISPLAY_ACTIVATED, activated ? 1 : 0, mUserId);
    }

    /**
     * Returns the time when Night display's activation state last changed, or {@code null} if it
     * has never been changed.
     */
    public Calendar getLastActivatedTime() {
        final ContentResolver cr = mContext.getContentResolver();
        final long lastActivatedTimeMillis = Secure.getLongForUser(
                cr, Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, -1, mUserId);
        if (lastActivatedTimeMillis < 0) {
            return null;
        }

        final Calendar lastActivatedTime = Calendar.getInstance();
        lastActivatedTime.setTimeInMillis(lastActivatedTimeMillis);
        return lastActivatedTime;
    }

    /**
     * Returns the current auto mode value controlling when Night display will be automatically
     * activated. One of {@link #AUTO_MODE_DISABLED}, {@link #AUTO_MODE_CUSTOM}, or
+3 −22
Original line number Diff line number Diff line
@@ -285,12 +285,6 @@ public final class NightDisplayService extends SystemService
        if (mIsActivated == null || mIsActivated != activated) {
            Slog.i(TAG, activated ? "Turning on night display" : "Turning off night display");

            if (mIsActivated != null) {
                Secure.putLongForUser(getContext().getContentResolver(),
                        Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, System.currentTimeMillis(),
                        mCurrentUser);
            }

            mIsActivated = activated;

            if (mAutoMode != null) {
@@ -430,19 +424,6 @@ public final class NightDisplayService extends SystemService
        outTemp[10] = blue;
    }

    private Calendar getLastActivatedTime() {
        final ContentResolver cr = getContext().getContentResolver();
        final long lastActivatedTimeMillis = Secure.getLongForUser(
                cr, Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, -1, mCurrentUser);
        if (lastActivatedTimeMillis < 0) {
            return null;
        }

        final Calendar lastActivatedTime = Calendar.getInstance();
        lastActivatedTime.setTimeInMillis(lastActivatedTimeMillis);
        return lastActivatedTime;
    }

    private abstract class AutoMode implements NightDisplayController.Callback {
        public abstract void onStart();

@@ -522,7 +503,7 @@ public final class NightDisplayService extends SystemService
            mStartTime = mController.getCustomStartTime();
            mEndTime = mController.getCustomEndTime();

            mLastActivatedTime = getLastActivatedTime();
            mLastActivatedTime = mController.getLastActivatedTime();

            // Force an update to initialize state.
            updateActivated();
@@ -538,7 +519,7 @@ public final class NightDisplayService extends SystemService

        @Override
        public void onActivated(boolean activated) {
            mLastActivatedTime = getLastActivatedTime();
            mLastActivatedTime = mController.getLastActivatedTime();
            updateNextAlarm(activated, Calendar.getInstance());
        }

@@ -579,7 +560,7 @@ public final class NightDisplayService extends SystemService
            }

            boolean activate = state.isNight();
            final Calendar lastActivatedTime = getLastActivatedTime();
            final Calendar lastActivatedTime = mController.getLastActivatedTime();
            if (lastActivatedTime != null) {
                final Calendar now = Calendar.getInstance();
                final Calendar sunrise = state.sunrise();