Disallows setting when user restriction applies
- Fix b/10116533 Change-Id: Ib171f9545c1651fb36c408decefa47b3d82ba3ab
This commit is contained in:
@@ -110,7 +110,7 @@ public class LocationMode extends LocationSettingsBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModeChanged(int mode) {
|
public void onModeChanged(int mode, boolean restricted) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case Settings.Secure.LOCATION_MODE_OFF:
|
case Settings.Secure.LOCATION_MODE_OFF:
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
@@ -129,7 +129,8 @@ public class LocationMode extends LocationSettingsBase
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
|
|
||||||
|
boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF) && !restricted;
|
||||||
mHighAccuracy.setEnabled(enabled);
|
mHighAccuracy.setEnabled(enabled);
|
||||||
mBatterySaving.setEnabled(enabled);
|
mBatterySaving.setEnabled(enabled);
|
||||||
mSensorsOnly.setEnabled(enabled);
|
mSensorsOnly.setEnabled(enabled);
|
||||||
|
@@ -28,7 +28,6 @@ import android.preference.Preference;
|
|||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -216,7 +215,7 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModeChanged(int mode) {
|
public void onModeChanged(int mode, boolean restricted) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case Settings.Secure.LOCATION_MODE_OFF:
|
case Settings.Secure.LOCATION_MODE_OFF:
|
||||||
mLocationMode.setSummary(R.string.location_mode_location_off_title);
|
mLocationMode.setSummary(R.string.location_mode_location_off_title);
|
||||||
@@ -234,7 +233,8 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
|
boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF) && !restricted;
|
||||||
|
mSwitch.setEnabled(!restricted);
|
||||||
mLocationMode.setEnabled(enabled);
|
mLocationMode.setEnabled(enabled);
|
||||||
|
|
||||||
if (enabled != mSwitch.isChecked()) {
|
if (enabled != mSwitch.isChecked()) {
|
||||||
|
@@ -71,11 +71,20 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Called when location mode has changed. */
|
/** Called when location mode has changed. */
|
||||||
public abstract void onModeChanged(int mode);
|
public abstract void onModeChanged(int mode, boolean restricted);
|
||||||
|
|
||||||
|
private boolean isRestricted() {
|
||||||
|
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
|
return um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
|
||||||
|
}
|
||||||
|
|
||||||
public void setLocationMode(int mode) {
|
public void setLocationMode(int mode) {
|
||||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
if (isRestricted()) {
|
||||||
if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, mode);
|
Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, mode);
|
||||||
@@ -85,6 +94,6 @@ public abstract class LocationSettingsBase extends SettingsPreferenceFragment {
|
|||||||
public void refreshLocationMode() {
|
public void refreshLocationMode() {
|
||||||
int mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
|
int mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE,
|
||||||
Settings.Secure.LOCATION_MODE_OFF);
|
Settings.Secure.LOCATION_MODE_OFF);
|
||||||
onModeChanged(mode);
|
onModeChanged(mode, isRestricted());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user