Loading core/java/com/android/internal/app/NightDisplayController.java +23 −1 Original line number Diff line number Diff line Loading @@ -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 Loading services/core/java/com/android/server/display/NightDisplayService.java +3 −22 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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(); Loading Loading @@ -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(); Loading @@ -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()); } Loading Loading @@ -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(); Loading Loading
core/java/com/android/internal/app/NightDisplayController.java +23 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
services/core/java/com/android/server/display/NightDisplayService.java +3 −22 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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(); Loading Loading @@ -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(); Loading @@ -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()); } Loading Loading @@ -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(); Loading