/**
   * Restore the properties associated with this preference on boot
   *
   * @param ctx A valid context
   */
  public static void restore(final Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    // Start the Lto Service
    if (LongTermOrbits.isSupported() && prefs.getBoolean(KEY_LOCATION_TOGGLE, false)) {
      saveDownloadDataWifiOnlyPref(context);

      // Starts the LtoService, but delayed 2 minutes after boot (this should give a
      // proper time to start all device services)
      AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      Intent intent = new Intent(context, LtoService.class);
      PendingIntent pi =
          PendingIntent.getService(
              context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
      long nextLtoDownload = System.currentTimeMillis() + (1000 * 60 * 2L);
      am.set(AlarmManager.RTC, nextLtoDownload, pi);
    }
  }
  private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
      root.removeAll();
    }
    addPreferencesFromResource(R.xml.location_settings);
    root = getPreferenceScreen();

    mLocationAccess = (SwitchPreference) root.findPreference(KEY_LOCATION_TOGGLE);
    mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
    mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
    mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
    mGpsDownloadDataWifiOnly =
        (CheckBoxPreference) root.findPreference(KEY_GPS_DOWNLOAD_DATA_WIFI_ONLY);

    // Only enable these controls if this user is allowed to change location
    // sharing settings.
    final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    boolean isToggleAllowed = !um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
    if (mLocationAccess != null) mLocationAccess.setEnabled(isToggleAllowed);
    if (mNetwork != null) mNetwork.setEnabled(isToggleAllowed);
    if (mGps != null) mGps.setEnabled(isToggleAllowed);
    if (mAssistedGps != null) mAssistedGps.setEnabled(isToggleAllowed);
    if (mGpsDownloadDataWifiOnly != null) mGpsDownloadDataWifiOnly.setEnabled(isToggleAllowed);

    if (!LongTermOrbits.isSupported()) {
      root.removePreference(mGpsDownloadDataWifiOnly);
      mGpsDownloadDataWifiOnly = null;
    } else {
      if (saveDownloadDataWifiOnlyPref(getActivity())) {
        root.removePreference(mGpsDownloadDataWifiOnly);
        mGpsDownloadDataWifiOnly = null;
      }
    }

    mLocationAccess.setOnPreferenceChangeListener(this);
    return root;
  }