Loading src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java +2 −3 Original line number Diff line number Diff line Loading @@ -166,8 +166,7 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider @VisibleForTesting boolean hasUsedNightDisplay(Context context) { final ContentResolver cr = context.getContentResolver(); final long lastActivatedTimeMillis = Secure.getLong(cr, Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, -1); return lastActivatedTimeMillis > 0; return Secure.getInt(cr, Secure.NIGHT_DISPLAY_AUTO_MODE, 0) != 0 || Secure.getString(cr, Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME) != null; } } src/com/android/settings/display/NightDisplayPreference.java +6 −5 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.internal.app.NightDisplayController; import com.android.settings.R; import java.text.DateFormat; import java.time.LocalTime; import java.util.Calendar; import java.util.TimeZone; Loading Loading @@ -58,11 +59,11 @@ public class NightDisplayPreference extends SwitchPreference mController.setListener(null); } private String getFormattedTimeString(NightDisplayController.LocalTime localTime) { private String getFormattedTimeString(LocalTime localTime) { final Calendar c = Calendar.getInstance(); c.setTimeZone(mTimeFormatter.getTimeZone()); c.set(Calendar.HOUR_OF_DAY, localTime.hourOfDay); c.set(Calendar.MINUTE, localTime.minute); c.set(Calendar.HOUR_OF_DAY, localTime.getHour()); c.set(Calendar.MINUTE, localTime.getMinute()); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return mTimeFormatter.format(c.getTime()); Loading Loading @@ -116,12 +117,12 @@ public class NightDisplayPreference extends SwitchPreference } @Override public void onCustomStartTimeChanged(NightDisplayController.LocalTime startTime) { public void onCustomStartTimeChanged(LocalTime startTime) { updateSummary(); } @Override public void onCustomEndTimeChanged(NightDisplayController.LocalTime endTime) { public void onCustomEndTimeChanged(LocalTime endTime) { updateSummary(); } } src/com/android/settings/display/NightDisplaySettings.java +9 −9 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.settings.widget.SeekBarPreference; import com.android.settings.SettingsPreferenceFragment; import java.text.DateFormat; import java.time.LocalTime; import java.util.Calendar; import java.util.TimeZone; Loading Loading @@ -144,7 +145,7 @@ public class NightDisplaySettings extends SettingsPreferenceFragment @Override public Dialog onCreateDialog(final int dialogId) { if (dialogId == DIALOG_START_TIME || dialogId == DIALOG_END_TIME) { final NightDisplayController.LocalTime initialTime; final LocalTime initialTime; if (dialogId == DIALOG_START_TIME) { initialTime = mController.getCustomStartTime(); } else { Loading @@ -156,15 +157,14 @@ public class NightDisplaySettings extends SettingsPreferenceFragment return new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { final NightDisplayController.LocalTime time = new NightDisplayController.LocalTime(hourOfDay, minute); final LocalTime time = LocalTime.of(hourOfDay, minute); if (dialogId == DIALOG_START_TIME) { mController.setCustomStartTime(time); } else { mController.setCustomEndTime(time); } } }, initialTime.hourOfDay, initialTime.minute, use24HourFormat); }, initialTime.getHour(), initialTime.getMinute(), use24HourFormat); } return super.onCreateDialog(dialogId); } Loading Loading @@ -201,11 +201,11 @@ public class NightDisplaySettings extends SettingsPreferenceFragment mTemperaturePreference.setProgress(convertTemperature(colorTemperature)); } private String getFormattedTimeString(NightDisplayController.LocalTime localTime) { private String getFormattedTimeString(LocalTime localTime) { final Calendar c = Calendar.getInstance(); c.setTimeZone(mTimeFormatter.getTimeZone()); c.set(Calendar.HOUR_OF_DAY, localTime.hourOfDay); c.set(Calendar.MINUTE, localTime.minute); c.set(Calendar.HOUR_OF_DAY, localTime.getHour()); c.set(Calendar.MINUTE, localTime.getMinute()); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return mTimeFormatter.format(c.getTime()); Loading @@ -221,12 +221,12 @@ public class NightDisplaySettings extends SettingsPreferenceFragment } @Override public void onCustomStartTimeChanged(NightDisplayController.LocalTime startTime) { public void onCustomStartTimeChanged(LocalTime startTime) { mStartTimePreference.setSummary(getFormattedTimeString(startTime)); } @Override public void onCustomEndTimeChanged(NightDisplayController.LocalTime endTime) { public void onCustomEndTimeChanged(LocalTime endTime) { mEndTimePreference.setSummary(getFormattedTimeString(endTime)); } Loading tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java +25 −3 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ import com.android.settings.testutils.shadow.ShadowSecureSettings; import com.android.settingslib.drawer.Tile; import com.android.settingslib.suggestions.SuggestionParser; import java.time.LocalDateTime; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -402,14 +403,35 @@ public class SuggestionFeatureProviderImplTest { } @Test public void hasUsedNightDisplay_returnsTrue_ifPreviouslyActivated() { Secure.putLong(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, 1L); public void hasUsedNightDisplay_returnsTrue_ifPreviouslyActivatedAndManual() { Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, LocalDateTime.now().toString()); Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1); assertThat(mProvider.hasUsedNightDisplay(mContext)).isTrue(); } @Test public void nightDisplaySuggestion_isCompleted_ifPreviouslyActivated() { Secure.putLong(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, 1L); Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, LocalDateTime.now().toString()); final ComponentName componentName = new ComponentName(mContext, NightDisplaySuggestionActivity.class); assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue(); } @Test public void nightDisplaySuggestion_isCompleted_ifNonManualMode() { Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1); final ComponentName componentName = new ComponentName(mContext, NightDisplaySuggestionActivity.class); assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue(); } @Test public void nightDisplaySuggestion_isCompleted_ifPreviouslyCleared() { Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, null); Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1); final ComponentName componentName = new ComponentName(mContext, NightDisplaySuggestionActivity.class); assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue(); Loading tests/robotests/src/com/android/settings/testutils/shadow/ShadowSecureSettings.java +5 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,11 @@ public class ShadowSecureSettings { int userHandle) { final Table<Integer, String, Object> userTable = getUserTable(resolver); synchronized (userTable) { if (value != null) { userTable.put(userHandle, name, value); } else { userTable.remove(userHandle, name); } return true; } } Loading Loading
src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java +2 −3 Original line number Diff line number Diff line Loading @@ -166,8 +166,7 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider @VisibleForTesting boolean hasUsedNightDisplay(Context context) { final ContentResolver cr = context.getContentResolver(); final long lastActivatedTimeMillis = Secure.getLong(cr, Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, -1); return lastActivatedTimeMillis > 0; return Secure.getInt(cr, Secure.NIGHT_DISPLAY_AUTO_MODE, 0) != 0 || Secure.getString(cr, Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME) != null; } }
src/com/android/settings/display/NightDisplayPreference.java +6 −5 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.internal.app.NightDisplayController; import com.android.settings.R; import java.text.DateFormat; import java.time.LocalTime; import java.util.Calendar; import java.util.TimeZone; Loading Loading @@ -58,11 +59,11 @@ public class NightDisplayPreference extends SwitchPreference mController.setListener(null); } private String getFormattedTimeString(NightDisplayController.LocalTime localTime) { private String getFormattedTimeString(LocalTime localTime) { final Calendar c = Calendar.getInstance(); c.setTimeZone(mTimeFormatter.getTimeZone()); c.set(Calendar.HOUR_OF_DAY, localTime.hourOfDay); c.set(Calendar.MINUTE, localTime.minute); c.set(Calendar.HOUR_OF_DAY, localTime.getHour()); c.set(Calendar.MINUTE, localTime.getMinute()); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return mTimeFormatter.format(c.getTime()); Loading Loading @@ -116,12 +117,12 @@ public class NightDisplayPreference extends SwitchPreference } @Override public void onCustomStartTimeChanged(NightDisplayController.LocalTime startTime) { public void onCustomStartTimeChanged(LocalTime startTime) { updateSummary(); } @Override public void onCustomEndTimeChanged(NightDisplayController.LocalTime endTime) { public void onCustomEndTimeChanged(LocalTime endTime) { updateSummary(); } }
src/com/android/settings/display/NightDisplaySettings.java +9 −9 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.settings.widget.SeekBarPreference; import com.android.settings.SettingsPreferenceFragment; import java.text.DateFormat; import java.time.LocalTime; import java.util.Calendar; import java.util.TimeZone; Loading Loading @@ -144,7 +145,7 @@ public class NightDisplaySettings extends SettingsPreferenceFragment @Override public Dialog onCreateDialog(final int dialogId) { if (dialogId == DIALOG_START_TIME || dialogId == DIALOG_END_TIME) { final NightDisplayController.LocalTime initialTime; final LocalTime initialTime; if (dialogId == DIALOG_START_TIME) { initialTime = mController.getCustomStartTime(); } else { Loading @@ -156,15 +157,14 @@ public class NightDisplaySettings extends SettingsPreferenceFragment return new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { final NightDisplayController.LocalTime time = new NightDisplayController.LocalTime(hourOfDay, minute); final LocalTime time = LocalTime.of(hourOfDay, minute); if (dialogId == DIALOG_START_TIME) { mController.setCustomStartTime(time); } else { mController.setCustomEndTime(time); } } }, initialTime.hourOfDay, initialTime.minute, use24HourFormat); }, initialTime.getHour(), initialTime.getMinute(), use24HourFormat); } return super.onCreateDialog(dialogId); } Loading Loading @@ -201,11 +201,11 @@ public class NightDisplaySettings extends SettingsPreferenceFragment mTemperaturePreference.setProgress(convertTemperature(colorTemperature)); } private String getFormattedTimeString(NightDisplayController.LocalTime localTime) { private String getFormattedTimeString(LocalTime localTime) { final Calendar c = Calendar.getInstance(); c.setTimeZone(mTimeFormatter.getTimeZone()); c.set(Calendar.HOUR_OF_DAY, localTime.hourOfDay); c.set(Calendar.MINUTE, localTime.minute); c.set(Calendar.HOUR_OF_DAY, localTime.getHour()); c.set(Calendar.MINUTE, localTime.getMinute()); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return mTimeFormatter.format(c.getTime()); Loading @@ -221,12 +221,12 @@ public class NightDisplaySettings extends SettingsPreferenceFragment } @Override public void onCustomStartTimeChanged(NightDisplayController.LocalTime startTime) { public void onCustomStartTimeChanged(LocalTime startTime) { mStartTimePreference.setSummary(getFormattedTimeString(startTime)); } @Override public void onCustomEndTimeChanged(NightDisplayController.LocalTime endTime) { public void onCustomEndTimeChanged(LocalTime endTime) { mEndTimePreference.setSummary(getFormattedTimeString(endTime)); } Loading
tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java +25 −3 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ import com.android.settings.testutils.shadow.ShadowSecureSettings; import com.android.settingslib.drawer.Tile; import com.android.settingslib.suggestions.SuggestionParser; import java.time.LocalDateTime; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -402,14 +403,35 @@ public class SuggestionFeatureProviderImplTest { } @Test public void hasUsedNightDisplay_returnsTrue_ifPreviouslyActivated() { Secure.putLong(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, 1L); public void hasUsedNightDisplay_returnsTrue_ifPreviouslyActivatedAndManual() { Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, LocalDateTime.now().toString()); Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1); assertThat(mProvider.hasUsedNightDisplay(mContext)).isTrue(); } @Test public void nightDisplaySuggestion_isCompleted_ifPreviouslyActivated() { Secure.putLong(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, 1L); Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, LocalDateTime.now().toString()); final ComponentName componentName = new ComponentName(mContext, NightDisplaySuggestionActivity.class); assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue(); } @Test public void nightDisplaySuggestion_isCompleted_ifNonManualMode() { Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1); final ComponentName componentName = new ComponentName(mContext, NightDisplaySuggestionActivity.class); assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue(); } @Test public void nightDisplaySuggestion_isCompleted_ifPreviouslyCleared() { Secure.putString(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME, null); Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, 1); final ComponentName componentName = new ComponentName(mContext, NightDisplaySuggestionActivity.class); assertThat(mProvider.isSuggestionCompleted(mContext, componentName)).isTrue(); Loading
tests/robotests/src/com/android/settings/testutils/shadow/ShadowSecureSettings.java +5 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,11 @@ public class ShadowSecureSettings { int userHandle) { final Table<Integer, String, Object> userTable = getUserTable(resolver); synchronized (userTable) { if (value != null) { userTable.put(userHandle, name, value); } else { userTable.remove(userHandle, name); } return true; } } Loading