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

Commit 92f7794d authored by Christine Franks's avatar Christine Franks Committed by android-build-merger
Browse files

Merge "Handle night display state when timezone changes" into oc-mr1-dev

am: cb52e803

Change-Id: I16968b7e1572cb91afc2345a16437194b243a955
parents b4b65717 cb52e803
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -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;
    }
}
+6 −5
Original line number Diff line number Diff line
@@ -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;

@@ -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());
@@ -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();
    }
}
+9 −9
Original line number Diff line number Diff line
@@ -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;

@@ -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 {
@@ -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);
    }
@@ -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());
@@ -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));
    }

+25 −3
Original line number Diff line number Diff line
@@ -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;
@@ -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();
+5 −1
Original line number Diff line number Diff line
@@ -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;
        }
    }