Remove location_modes_previous references

1. Remove reference to LOCATION_MODE_PREVIOUS.

2. Add setLocationEnabled method in LocationEnabler. When turning location
ON/OFF from Settings app or Quick Settings, use
LocationEnabler.setLocationEnabled() instead of setLocationMode().

3. Change unit tests accordingly.

Bug: 70990911
Test: Robolectric
Test: Manual
Change-Id: Ic02ef3cd02f9aa7d2ef18697b19b507575aaf5c2
This commit is contained in:
Maggie
2018-01-04 15:35:49 -08:00
parent aaf307e71d
commit 85e2f61b2d
6 changed files with 73 additions and 40 deletions

View File

@@ -43,6 +43,7 @@ import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.wrapper.LocationManagerWrapper;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
@@ -53,11 +54,15 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {ShadowSecureSettings.class})
shadows = {
ShadowSecureSettings.class,
LocationEnablerTest.ShadowLocationManagerWrapper.class})
public class LocationEnablerTest {
@Mock
@@ -124,7 +129,7 @@ public class LocationEnablerTest {
}
@Test
public void isEnabled_locationONotRestricted_shouldReturnTrue() {
public void isEnabled_locationNotRestricted_shouldReturnTrue() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
assertThat(mEnabler.isEnabled(Settings.Secure.LOCATION_MODE_BATTERY_SAVING)).isTrue();
@@ -178,14 +183,35 @@ public class LocationEnablerTest {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
verify(mContext).sendBroadcastAsUser(
argThat(actionMatches(LocationManager.MODE_CHANGING_ACTION)),
eq(UserHandle.of(ActivityManager.getCurrentUser())),
eq(WRITE_SECURE_SETTINGS));
}
@Test
public void setLocationEnabled_notRestricted_shouldRefreshLocation() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
mEnabler.setLocationEnabled(true);
verify(mEnabler).refreshLocationMode();
}
@Test
public void setLocationEnabled_notRestricted_shouldBroadcastUpdate() {
when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
mEnabler.setLocationEnabled(true);
verify(mContext).sendBroadcastAsUser(
argThat(actionMatches(LocationManager.MODE_CHANGING_ACTION)),
eq(UserHandle.of(ActivityManager.getCurrentUser())),
eq(WRITE_SECURE_SETTINGS));
}
@Test
@@ -241,5 +267,12 @@ public class LocationEnablerTest {
return intent -> TextUtils.equals(expected, intent.getAction());
}
@Implements(value = LocationManagerWrapper.class)
public static class ShadowLocationManagerWrapper {
@Implementation
public void setLocationEnabledForUser(boolean enabled, UserHandle userHandle) {
// Do nothing
}
}
}