Use ColorDisplayManager for night display
Bug: 111215474 Test: make ROBOTEST_FILTER="(Night*)" RunSettingsRoboTests -j48 Change-Id: I8b92407470446ef86e460985fc64cf2467eb3e5c
This commit is contained in:
@@ -67,8 +67,7 @@ public class NightDisplayActivationPreferenceController extends TogglePreference
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
final LayoutPreference preference = (LayoutPreference) screen.findPreference(
|
||||
getPreferenceKey());
|
||||
final LayoutPreference preference = screen.findPreference(getPreferenceKey());
|
||||
mTurnOnButton = preference.findViewById(R.id.night_display_turn_on_button);
|
||||
mTurnOnButton.setOnClickListener(mListener);
|
||||
mTurnOffButton = preference.findViewById(R.id.night_display_turn_off_button);
|
||||
@@ -106,14 +105,14 @@ public class NightDisplayActivationPreferenceController extends TogglePreference
|
||||
final int autoMode = mController.getAutoMode();
|
||||
|
||||
String buttonText;
|
||||
if (autoMode == ColorDisplayController.AUTO_MODE_CUSTOM) {
|
||||
if (autoMode == ColorDisplayManager.AUTO_MODE_CUSTOM_TIME) {
|
||||
buttonText = mContext.getString(isActivated
|
||||
? R.string.night_display_activation_off_custom
|
||||
: R.string.night_display_activation_on_custom,
|
||||
mTimeFormatter.getFormattedTimeString(isActivated
|
||||
? mController.getCustomStartTime()
|
||||
: mController.getCustomEndTime()));
|
||||
} else if (autoMode == ColorDisplayController.AUTO_MODE_TWILIGHT) {
|
||||
} else if (autoMode == ColorDisplayManager.AUTO_MODE_TWILIGHT) {
|
||||
buttonText = mContext.getString(isActivated
|
||||
? R.string.night_display_activation_off_twilight
|
||||
: R.string.night_display_activation_on_twilight);
|
||||
|
@@ -23,7 +23,6 @@ import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
@@ -31,11 +30,11 @@ public class NightDisplayAutoModePreferenceController extends BasePreferenceCont
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private DropDownPreference mPreference;
|
||||
private ColorDisplayController mController;
|
||||
private ColorDisplayManager mManager;
|
||||
|
||||
public NightDisplayAutoModePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mController = new ColorDisplayController(context);
|
||||
mManager = context.getSystemService(ColorDisplayManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +47,7 @@ public class NightDisplayAutoModePreferenceController extends BasePreferenceCont
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mPreference = (DropDownPreference) screen.findPreference(getPreferenceKey());
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
|
||||
mPreference.setEntries(new CharSequence[]{
|
||||
mContext.getString(R.string.night_display_auto_mode_never),
|
||||
@@ -56,19 +55,19 @@ public class NightDisplayAutoModePreferenceController extends BasePreferenceCont
|
||||
mContext.getString(R.string.night_display_auto_mode_twilight)
|
||||
});
|
||||
mPreference.setEntryValues(new CharSequence[]{
|
||||
String.valueOf(ColorDisplayController.AUTO_MODE_DISABLED),
|
||||
String.valueOf(ColorDisplayController.AUTO_MODE_CUSTOM),
|
||||
String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT)
|
||||
String.valueOf(ColorDisplayManager.AUTO_MODE_DISABLED),
|
||||
String.valueOf(ColorDisplayManager.AUTO_MODE_CUSTOM_TIME),
|
||||
String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT)
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void updateState(Preference preference) {
|
||||
mPreference.setValue(String.valueOf(mController.getAutoMode()));
|
||||
mPreference.setValue(String.valueOf(mManager.getNightDisplayAutoMode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return mController.setAutoMode(Integer.parseInt((String) newValue));
|
||||
return mManager.setNightDisplayAutoMode(Integer.parseInt((String) newValue));
|
||||
}
|
||||
}
|
||||
|
@@ -18,9 +18,7 @@ package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
@@ -44,7 +42,8 @@ public class NightDisplayCustomEndTimePreferenceController extends BasePreferenc
|
||||
|
||||
@Override
|
||||
public final void updateState(Preference preference) {
|
||||
preference.setVisible(mController.getAutoMode() == ColorDisplayController.AUTO_MODE_CUSTOM);
|
||||
preference
|
||||
.setVisible(mController.getAutoMode() == ColorDisplayManager.AUTO_MODE_CUSTOM_TIME);
|
||||
preference.setSummary(mTimeFormatter.getFormattedTimeString(
|
||||
mController.getCustomEndTime()));
|
||||
}
|
||||
|
@@ -18,9 +18,7 @@ package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
@@ -44,7 +42,8 @@ public class NightDisplayCustomStartTimePreferenceController extends BasePrefere
|
||||
|
||||
@Override
|
||||
public final void updateState(Preference preference) {
|
||||
preference.setVisible(mController.getAutoMode() == ColorDisplayController.AUTO_MODE_CUSTOM);
|
||||
preference
|
||||
.setVisible(mController.getAutoMode() == ColorDisplayManager.AUTO_MODE_CUSTOM_TIME);
|
||||
preference.setSummary(mTimeFormatter.getFormattedTimeString(
|
||||
mController.getCustomStartTime()));
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.settings.core.SliderPreferenceController;
|
||||
@@ -54,8 +55,7 @@ public class NightDisplayIntensityPreferenceController extends SliderPreferenceC
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
final SeekBarPreference preference = (SeekBarPreference) screen.findPreference(
|
||||
getPreferenceKey());
|
||||
final SeekBarPreference preference = screen.findPreference(getPreferenceKey());
|
||||
preference.setContinuousUpdates(true);
|
||||
preference.setMax(getMaxSteps());
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ public class NightDisplayPreferenceController extends AbstractPreferenceControll
|
||||
return true;
|
||||
}
|
||||
final ColorDisplayController controller = new ColorDisplayController(context);
|
||||
return controller.getAutoMode() != ColorDisplayController.AUTO_MODE_DISABLED;
|
||||
return controller.getAutoMode() != ColorDisplayManager.AUTO_MODE_DISABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.settings.R;
|
||||
|
||||
@@ -54,7 +55,7 @@ public class NightDisplayTimeFormatter {
|
||||
private String getAutoModeSummary(Context context, ColorDisplayController controller) {
|
||||
final boolean isActivated = controller.isActivated();
|
||||
final int autoMode = controller.getAutoMode();
|
||||
if (autoMode == ColorDisplayController.AUTO_MODE_CUSTOM) {
|
||||
if (autoMode == ColorDisplayManager.AUTO_MODE_CUSTOM_TIME) {
|
||||
if (isActivated) {
|
||||
return context.getString(R.string.night_display_summary_on_auto_mode_custom,
|
||||
getFormattedTimeString(controller.getCustomEndTime()));
|
||||
@@ -62,7 +63,7 @@ public class NightDisplayTimeFormatter {
|
||||
return context.getString(R.string.night_display_summary_off_auto_mode_custom,
|
||||
getFormattedTimeString(controller.getCustomStartTime()));
|
||||
}
|
||||
} else if (autoMode == ColorDisplayController.AUTO_MODE_TWILIGHT) {
|
||||
} else if (autoMode == ColorDisplayManager.AUTO_MODE_TWILIGHT) {
|
||||
return context.getString(isActivated
|
||||
? R.string.night_display_summary_on_auto_mode_twilight
|
||||
: R.string.night_display_summary_off_auto_mode_twilight);
|
||||
|
@@ -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;
|
||||
@@ -34,12 +33,12 @@ import org.robolectric.annotation.Config;
|
||||
public class NightDisplayIntensityPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private NightDisplayIntensityPreferenceController mController;
|
||||
private NightDisplayIntensityPreferenceController mPreferenceController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new NightDisplayIntensityPreferenceController(mContext,
|
||||
mPreferenceController = new NightDisplayIntensityPreferenceController(mContext,
|
||||
"night_display_temperature");
|
||||
}
|
||||
|
||||
@@ -53,7 +52,7 @@ public class NightDisplayIntensityPreferenceControllerTest {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, true);
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 1);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,14 +60,14 @@ public class NightDisplayIntensityPreferenceControllerTest {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, true);
|
||||
Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 0);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configuredUnavailable_unavailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_nightDisplayAvailable, false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mPreferenceController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,17 +77,17 @@ public class NightDisplayIntensityPreferenceControllerTest {
|
||||
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);
|
||||
mPreferenceController.onPreferenceChange(null, 20);
|
||||
|
||||
assertThat(Secure.getInt(mContext.getContentResolver(),
|
||||
Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE, -1))
|
||||
assertThat(
|
||||
mContext.getSystemService(ColorDisplayManager.class).getNightDisplayColorTemperature())
|
||||
.isEqualTo(3030);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceableCorrectKey_returnsTrue() {
|
||||
final NightDisplayIntensityPreferenceController controller =
|
||||
new NightDisplayIntensityPreferenceController(mContext,"night_display_temperature");
|
||||
new NightDisplayIntensityPreferenceController(mContext, "night_display_temperature");
|
||||
assertThat(controller.isSliceable()).isTrue();
|
||||
}
|
||||
|
||||
|
@@ -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