Handle night display state when timezone changes

Bug: 64458884
Test: make RunSettingsRoboTests -j100

Change-Id: I1f0c073b796aa6826c236757e19c6ff6d5cb7602
This commit is contained in:
Christine Franks
2017-08-25 14:02:42 -07:00
parent 6361c9d851
commit c6c299bdbb
5 changed files with 47 additions and 21 deletions

View File

@@ -56,6 +56,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;
@@ -391,14 +392,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();

View File

@@ -36,7 +36,11 @@ public class ShadowSecureSettings {
int userHandle) {
final Table<Integer, String, Object> userTable = getUserTable(resolver);
synchronized (userTable) {
userTable.put(userHandle, name, value);
if (value != null) {
userTable.put(userHandle, name, value);
} else {
userTable.remove(userHandle, name);
}
return true;
}
}