@Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    final ContentResolver cr = getContentResolver();
    final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    if (preference == mNetwork) {
      if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
        Settings.Secure.setLocationProviderEnabled(
            cr, LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
      }
    } else if (preference == mGps) {
      boolean enabled = mGps.isChecked();
      if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
        Settings.Secure.setLocationProviderEnabled(cr, LocationManager.GPS_PROVIDER, enabled);
        if (mAssistedGps != null) {
          mAssistedGps.setEnabled(enabled);
        }
      }
    } else if (preference == mAssistedGps) {
      Settings.Global.putInt(
          cr, Settings.Global.ASSISTED_GPS_ENABLED, mAssistedGps.isChecked() ? 1 : 0);
    } else {
      // If we didn't handle it, let preferences handle it.
      return super.onPreferenceTreeClick(preferenceScreen, preference);
    }

    return true;
  }
 /** Enable or disable all providers when the master toggle is changed. */
 private void onToggleLocationAccess(boolean checked) {
   final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
   if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
     return;
   }
   final ContentResolver cr = getContentResolver();
   Settings.Secure.setLocationProviderEnabled(cr, LocationManager.GPS_PROVIDER, checked);
   Settings.Secure.setLocationProviderEnabled(cr, LocationManager.NETWORK_PROVIDER, checked);
   updateLocationToggles();
   updateLtoServiceStatus(getActivity(), checked);
 }