Turn on location dialog when using twilight scheduling

Night light and Dark theme scheduling does not work when in
twiligth mode. For the reason, we added a dialog to inform the user
that they need to turn on location services first.

Fixes: 153115618
Fixes: 153115261
Test: manual
Change-Id: Iea51018a7caba5c0ec93e058ee047d067bc03867
This commit is contained in:
Jay Aliomer
2020-04-02 21:32:32 -04:00
parent 5a950b763f
commit 59c03c23b7
5 changed files with 83 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
import android.app.UiModeManager;
import android.content.Context;
import android.location.LocationManager;
import android.os.PowerManager;
import androidx.preference.DropDownPreference;
@@ -55,6 +56,8 @@ public class DarkModeScheduleSelectorControllerTest {
@Mock
private UiModeManager mUiService;
@Mock
private LocationManager mLocationManager;
@Mock
private PowerManager mPM;
@Before
@@ -63,6 +66,7 @@ public class DarkModeScheduleSelectorControllerTest {
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mUiService);
when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM);
when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager);
when(mContext.getString(R.string.dark_ui_auto_mode_never)).thenReturn("never");
when(mContext.getString(R.string.dark_ui_auto_mode_auto)).thenReturn("auto");
when(mContext.getString(R.string.dark_ui_auto_mode_custom)).thenReturn("custom");
@@ -72,6 +76,7 @@ public class DarkModeScheduleSelectorControllerTest {
mContext.getString(R.string.dark_ui_auto_mode_auto)
});
doNothing().when(mPreference).setValueIndex(anyInt());
when(mLocationManager.isLocationEnabled()).thenReturn(true);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
when(mUiService.setNightModeActivated(anyBoolean())).thenReturn(true);
mController = new DarkModeScheduleSelectorController(mContext, mPreferenceKey);
@@ -96,6 +101,15 @@ public class DarkModeScheduleSelectorControllerTest {
verify(mPreference).setValueIndex(0);
}
@Test
public void nightMode_selectNightMode_locationOff() {
when(mLocationManager.isLocationEnabled()).thenReturn(false);
mController.onPreferenceChange(mPreference,
mContext.getString(R.string.dark_ui_auto_mode_never));
assertFalse(mController.onPreferenceChange(mPreference,
mContext.getString(R.string.dark_ui_auto_mode_auto)));
}
@Test
public void nightMode_updateStateNone_dropDownValueChangedToAuto() {
when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO);