}
@Override
- public void onModeChanged(int mode) {
+ public void onModeChanged(int mode, boolean restricted) {
switch (mode) {
case Settings.Secure.LOCATION_MODE_OFF:
Intent intent = new Intent();
default:
break;
}
- boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
+
+ boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF) && !restricted;
mHighAccuracy.setEnabled(enabled);
mBatterySaving.setEnabled(enabled);
mSensorsOnly.setEnabled(enabled);
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
-import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.util.Log;
}
@Override
- public void onModeChanged(int mode) {
+ public void onModeChanged(int mode, boolean restricted) {
switch (mode) {
case Settings.Secure.LOCATION_MODE_OFF:
mLocationMode.setSummary(R.string.location_mode_location_off_title);
break;
}
- boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
+ boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF) && !restricted;
+ mSwitch.setEnabled(!restricted);
mLocationMode.setEnabled(enabled);
if (enabled != mSwitch.isChecked()) {
}
/** Called when location mode has changed. */
- public abstract void onModeChanged(int mode);
+ public abstract void onModeChanged(int mode, boolean restricted);
- public void setLocationMode(int mode) {
+ private boolean isRestricted() {
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
- if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
+ return um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
+ }
+
+ public void setLocationMode(int mode) {
+ if (isRestricted()) {
+ // Location toggling disabled by user restriction. Read the current location mode to
+ // update the location master switch.
+ mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
+ Settings.Secure.LOCATION_MODE_OFF);
+ onModeChanged(mode, true);
return;
}
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, mode);
public void refreshLocationMode() {
int mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
Settings.Secure.LOCATION_MODE_OFF);
- onModeChanged(mode);
+ onModeChanged(mode, isRestricted());
}
}