diff options
| author | 2017-05-31 10:52:22 -0700 | |
|---|---|---|
| committer | 2017-05-31 18:34:40 -0700 | |
| commit | 1454eae75da9f775425b51c2cb573a2b4c33b7e7 (patch) | |
| tree | ddeec95fc06411ec1b19665b94f38c68c74f1834 | |
| parent | 388ceaa37ab04c01659b029f9066c4d8ce276188 (diff) | |
Fix night display activation behavior after reboot
Bug: 38469190
Test: runtest -c com.android.server.NightDisplayServiceTest \
frameworks-services
Change-Id: Ida17ba9c9389781b892bbe37f0a9eeec030baf1e
| -rw-r--r-- | core/java/com/android/internal/app/NightDisplayController.java | 24 | ||||
| -rw-r--r-- | services/core/java/com/android/server/display/NightDisplayService.java | 25 |
2 files changed, 26 insertions, 23 deletions
diff --git a/core/java/com/android/internal/app/NightDisplayController.java b/core/java/com/android/internal/app/NightDisplayController.java index d19f1ecfbd13..bb54085ac3bf 100644 --- a/core/java/com/android/internal/app/NightDisplayController.java +++ b/core/java/com/android/internal/app/NightDisplayController.java @@ -109,17 +109,39 @@ 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 * {@link #AUTO_MODE_TWILIGHT}. diff --git a/services/core/java/com/android/server/display/NightDisplayService.java b/services/core/java/com/android/server/display/NightDisplayService.java index d5742657c5e2..b3cf57b3564a 100644 --- a/services/core/java/com/android/server/display/NightDisplayService.java +++ b/services/core/java/com/android/server/display/NightDisplayService.java @@ -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(); |