Merge "Use ColorDisplayManager for night display"
This commit is contained in:
committed by
Android (Google) Code Review
commit
17e1190606
@@ -15,12 +15,11 @@
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -47,17 +46,19 @@ public class NightDisplayActivationPreferenceControllerTest {
|
||||
private PreferenceScreen mScreen;
|
||||
private LayoutPreference mPreference;
|
||||
private Context mContext;
|
||||
private NightDisplayActivationPreferenceController mController;
|
||||
private ColorDisplayManager mColorDisplayManager;
|
||||
private NightDisplayActivationPreferenceController mPreferenceController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class);
|
||||
mPreference = new LayoutPreference(mContext, R.layout.night_display_activation_button);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
mController = new NightDisplayActivationPreferenceController(mContext,
|
||||
mPreferenceController = new NightDisplayActivationPreferenceController(mContext,
|
||||
"night_display_activation");
|
||||
mController.displayPreference(mScreen);
|
||||
mPreferenceController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -69,14 +70,14 @@ public class NightDisplayActivationPreferenceControllerTest {
|
||||
public void isAvailable_configuredAvailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, true);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configuredUnavailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,25 +96,23 @@ public class NightDisplayActivationPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onClick_activates() {
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 0);
|
||||
mColorDisplayManager.setNightDisplayActivated(false);
|
||||
|
||||
final View view = mPreference.findViewById(R.id.night_display_turn_on_button);
|
||||
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
view.performClick();
|
||||
|
||||
assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, -1))
|
||||
.isEqualTo(1);
|
||||
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_deactivates() {
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 1);
|
||||
mColorDisplayManager.setNightDisplayActivated(true);
|
||||
|
||||
final View view = mPreference.findViewById(R.id.night_display_turn_on_button);
|
||||
final View view = mPreference.findViewById(R.id.night_display_turn_off_button);
|
||||
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
view.performClick();
|
||||
|
||||
assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, -1))
|
||||
.isEqualTo(0);
|
||||
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(false);
|
||||
}
|
||||
}
|
||||
|
@@ -17,9 +17,9 @@ package com.android.settings.display;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
import android.provider.Settings.Secure;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -66,8 +66,8 @@ public class NightDisplayAutoModePreferenceControllerTest {
|
||||
@Test
|
||||
public void onPreferenceChange_changesAutoMode() {
|
||||
mController.onPreferenceChange(null,
|
||||
String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT));
|
||||
assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, -1))
|
||||
.isEqualTo(ColorDisplayController.AUTO_MODE_TWILIGHT);
|
||||
String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT));
|
||||
assertThat(mContext.getSystemService(ColorDisplayManager.class).getNightDisplayAutoMode())
|
||||
.isEqualTo(ColorDisplayManager.AUTO_MODE_TWILIGHT);
|
||||
}
|
||||
}
|
||||
|
@@ -17,10 +17,9 @@ package com.android.settings.display;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
import android.provider.Settings.Secure;
|
||||
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -33,69 +32,69 @@ import org.robolectric.annotation.Config;
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public class NightDisplayIntensityPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private NightDisplayIntensityPreferenceController mController;
|
||||
private Context mContext;
|
||||
private NightDisplayIntensityPreferenceController mPreferenceController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new NightDisplayIntensityPreferenceController(mContext,
|
||||
"night_display_temperature");
|
||||
}
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreferenceController = new NightDisplayIntensityPreferenceController(mContext,
|
||||
"night_display_temperature");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configuredAvailable_isActivated_available() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, true);
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 1);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
@Test
|
||||
public void isAvailable_configuredAvailable_isActivated_available() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, true);
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 1);
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configuredAvailable_isNotActivated_available() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, true);
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 0);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
@Test
|
||||
public void isAvailable_configuredAvailable_isNotActivated_available() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, true);
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 0);
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configuredUnavailable_unavailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
@Test
|
||||
public void isAvailable_configuredUnavailable_unavailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, false);
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_changesTemperature() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.integer.config_nightDisplayColorTemperatureMin, 2950);
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.integer.config_nightDisplayColorTemperatureMax, 3050);
|
||||
// A slider-adjusted "20" here would be 1/5 from the left / least-intense, i.e. 3030.
|
||||
mController.onPreferenceChange(null, 20);
|
||||
@Test
|
||||
public void onPreferenceChange_changesTemperature() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.integer.config_nightDisplayColorTemperatureMin, 2950);
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.integer.config_nightDisplayColorTemperatureMax, 3050);
|
||||
// A slider-adjusted "20" here would be 1/5 from the left / least-intense, i.e. 3030.
|
||||
mPreferenceController.onPreferenceChange(null, 20);
|
||||
|
||||
assertThat(Secure.getInt(mContext.getContentResolver(),
|
||||
Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE, -1))
|
||||
.isEqualTo(3030);
|
||||
}
|
||||
assertThat(
|
||||
mContext.getSystemService(ColorDisplayManager.class).getNightDisplayColorTemperature())
|
||||
.isEqualTo(3030);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceableCorrectKey_returnsTrue() {
|
||||
final NightDisplayIntensityPreferenceController controller =
|
||||
new NightDisplayIntensityPreferenceController(mContext,"night_display_temperature");
|
||||
assertThat(controller.isSliceable()).isTrue();
|
||||
}
|
||||
@Test
|
||||
public void isSliceableCorrectKey_returnsTrue() {
|
||||
final NightDisplayIntensityPreferenceController controller =
|
||||
new NightDisplayIntensityPreferenceController(mContext, "night_display_temperature");
|
||||
assertThat(controller.isSliceable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceableIncorrectKey_returnsFalse() {
|
||||
final NightDisplayIntensityPreferenceController controller =
|
||||
new NightDisplayIntensityPreferenceController(mContext, "bad_key");
|
||||
assertThat(controller.isSliceable()).isFalse();
|
||||
}
|
||||
@Test
|
||||
public void isSliceableIncorrectKey_returnsFalse() {
|
||||
final NightDisplayIntensityPreferenceController controller =
|
||||
new NightDisplayIntensityPreferenceController(mContext, "bad_key");
|
||||
assertThat(controller.isSliceable()).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -3,12 +3,9 @@ package com.android.settings.display;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Application;
|
||||
import android.provider.Settings.Secure;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -28,32 +25,32 @@ public class NightDisplayPreferenceControllerTest {
|
||||
@Test
|
||||
public void nightDisplaySuggestion_isNotCompleted_ifAutoModeDisabled() {
|
||||
final Application context = RuntimeEnvironment.application;
|
||||
Secure.putInt(context.getContentResolver(),
|
||||
Secure.NIGHT_DISPLAY_AUTO_MODE, ColorDisplayController.AUTO_MODE_DISABLED);
|
||||
context.getSystemService(ColorDisplayManager.class)
|
||||
.setNightDisplayAutoMode(ColorDisplayManager.AUTO_MODE_DISABLED);
|
||||
assertThat(NightDisplayPreferenceController.isSuggestionComplete(context)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightDisplaySuggestion_isCompleted_ifAutoModeCustom() {
|
||||
final Application context = RuntimeEnvironment.application;
|
||||
Secure.putInt(context.getContentResolver(),
|
||||
Secure.NIGHT_DISPLAY_AUTO_MODE, ColorDisplayController.AUTO_MODE_CUSTOM);
|
||||
context.getSystemService(ColorDisplayManager.class)
|
||||
.setNightDisplayAutoMode(ColorDisplayManager.AUTO_MODE_CUSTOM_TIME);
|
||||
assertThat(NightDisplayPreferenceController.isSuggestionComplete(context)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightDisplaySuggestion_isCompleted_ifAutoModeTwilight() {
|
||||
final Application context = RuntimeEnvironment.application;
|
||||
Secure.putInt(context.getContentResolver(),
|
||||
Secure.NIGHT_DISPLAY_AUTO_MODE, ColorDisplayController.AUTO_MODE_TWILIGHT);
|
||||
context.getSystemService(ColorDisplayManager.class)
|
||||
.setNightDisplayAutoMode(ColorDisplayManager.AUTO_MODE_TWILIGHT);
|
||||
assertThat(NightDisplayPreferenceController.isSuggestionComplete(context)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightDisplaySuggestion_isCompleted_ifDisabled() {
|
||||
public void nightDisplaySuggestion_isCompleted_ifSuggestionDisabled() {
|
||||
final Application context = RuntimeEnvironment.application;
|
||||
Secure.putInt(context.getContentResolver(),
|
||||
Secure.NIGHT_DISPLAY_AUTO_MODE, ColorDisplayController.AUTO_MODE_DISABLED);
|
||||
context.getSystemService(ColorDisplayManager.class)
|
||||
.setNightDisplayAutoMode(ColorDisplayManager.AUTO_MODE_DISABLED);
|
||||
SettingsShadowResources.overrideResource(R.bool.config_night_light_suggestion_enabled, false);
|
||||
assertThat(NightDisplayPreferenceController.isSuggestionComplete(context)).isTrue();
|
||||
}
|
||||
|
Reference in New Issue
Block a user