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

Commit 16c9c94e 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

Change-Id: I6c8002fc4ac63f27343a27148c6a18e349a6b883
parents cd020cc6 bd75ee00
Loading
Loading
Loading
Loading
+23 −1
Original line number Original line 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
     * @param activated {@code true} if Night display should be activated
     * @return {@code true} if the activated value was set successfully
     * @return {@code true} if the activated value was set successfully
     */
     */
    public boolean setActivated(boolean activated) {
    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(),
        return Secure.putIntForUser(mContext.getContentResolver(),
                Secure.NIGHT_DISPLAY_ACTIVATED, activated ? 1 : 0, mUserId);
                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
     * 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
     * activated. One of {@link #AUTO_MODE_DISABLED}, {@link #AUTO_MODE_CUSTOM}, or
+3 −22
Original line number Original line Diff line number Diff line
@@ -285,12 +285,6 @@ public final class NightDisplayService extends SystemService
        if (mIsActivated == null || mIsActivated != activated) {
        if (mIsActivated == null || mIsActivated != activated) {
            Slog.i(TAG, activated ? "Turning on night display" : "Turning off night display");
            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;
            mIsActivated = activated;


            if (mAutoMode != null) {
            if (mAutoMode != null) {
@@ -430,19 +424,6 @@ public final class NightDisplayService extends SystemService
        outTemp[10] = blue;
        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 {
    private abstract class AutoMode implements NightDisplayController.Callback {
        public abstract void onStart();
        public abstract void onStart();


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


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


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


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


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


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