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:
@@ -34,8 +34,10 @@ import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import static com.android.settingslib.Utils.updateLocationMode;
|
||||
import static com.android.settingslib.Utils.updateLocationEnabled;
|
||||
import static com.android.settingslib.RestrictedLockUtils.checkIfRestrictionEnforced;
|
||||
|
||||
|
||||
/**
|
||||
* A class that listens to location settings change and modifies location settings
|
||||
* settings.
|
||||
@@ -106,6 +108,25 @@ public class LocationEnabler implements LifecycleObserver, OnResume, OnPause {
|
||||
}
|
||||
}
|
||||
|
||||
void setLocationEnabled(boolean enabled) {
|
||||
final int currentMode = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
|
||||
|
||||
if (isRestricted()) {
|
||||
// Location toggling disabled by user restriction. Read the current location mode to
|
||||
// update the location master switch.
|
||||
if (Log.isLoggable(TAG, Log.INFO)) {
|
||||
Log.i(TAG, "Restricted user, not setting location mode");
|
||||
}
|
||||
if (mListener != null) {
|
||||
mListener.onLocationModeChanged(currentMode, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
updateLocationEnabled(mContext, enabled, UserHandle.myUserId());
|
||||
refreshLocationMode();
|
||||
}
|
||||
|
||||
void setLocationMode(int mode) {
|
||||
final int currentMode = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
|
||||
|
||||
@@ -47,15 +47,8 @@ import java.util.List;
|
||||
* <ul>
|
||||
* <li>Platform location controls</li>
|
||||
* <ul>
|
||||
* <li>In switch bar: location master switch. Used to toggle
|
||||
* {@link android.provider.Settings.Secure#LOCATION_MODE} between
|
||||
* {@link android.provider.Settings.Secure#LOCATION_MODE_OFF} and another location mode.
|
||||
* <li>In switch bar: location master switch. Used to toggle location on and off.
|
||||
* </li>
|
||||
* <li>Mode preference: only available if the master switch is on, selects between
|
||||
* {@link android.provider.Settings.Secure#LOCATION_MODE} of
|
||||
* {@link android.provider.Settings.Secure#LOCATION_MODE_HIGH_ACCURACY},
|
||||
* {@link android.provider.Settings.Secure#LOCATION_MODE_BATTERY_SAVING}, or
|
||||
* {@link android.provider.Settings.Secure#LOCATION_MODE_SENSORS_ONLY}.</li>
|
||||
* </ul>
|
||||
* <li>Recent location requests: automatically populated by {@link RecentLocationApps}</li>
|
||||
* <li>Location services: multi-app settings provided from outside the Android framework. Each
|
||||
|
||||
@@ -96,9 +96,6 @@ public class LocationSwitchBarController implements SwitchBar.OnSwitchChangeList
|
||||
*/
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
mLocationEnabler.setLocationMode(isChecked
|
||||
? android.provider.Settings.Secure.LOCATION_MODE_PREVIOUS
|
||||
: android.provider.Settings.Secure.LOCATION_MODE_OFF);
|
||||
mLocationEnabler.setLocationEnabled(isChecked);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user