private void updateFromPreference() {
    Logger.d("Service updateFromPreference called");
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    try {
      powerManager.setBatteryThresh(
          Integer.parseInt(
              prefs.getString(
                  getString(R.string.batteryMinThresPrefKey),
                  String.valueOf(Config.DEFAULT_BATTERY_THRESH_PRECENT))));

      this.setCheckinInterval(
          Integer.parseInt(
                  prefs.getString(
                      getString(R.string.checkinIntervalPrefKey),
                      String.valueOf(Config.DEFAULT_CHECKIN_INTERVAL_SEC / 3600)))
              * 3600);

      updateStatus();

      Logger.i(
          "Preference set from SharedPreference: "
              + "checkinInterval="
              + checkinIntervalSec
              + ", minBatThres= "
              + powerManager.getBatteryThresh());
    } catch (ClassCastException e) {
      Logger.e("exception when casting preference values", e);
    }
  }
  /** Perform a checkin operation. */
  public void handleCheckin(boolean force) {
    if (!userConsented()) {
      Logger.i("Skipping checkin - User has not consented");
      return;
    }

    if (!force && isPauseRequested()) {
      sendStringMsg("Skipping checkin - app is paused");
      return;
    }
    if (!force && !powerManager.canScheduleExperiment()) {
      sendStringMsg("Skipping checkin - below battery threshold");
      return;
    }
    /* The CPU can go back to sleep immediately after onReceive() returns. Acquire
     * the wake lock for the new thread here and release the lock when the thread finishes
     */
    PhoneUtils.getPhoneUtils().acquireWakeLock();
    new Thread(checkinTask).start();
  }
 public boolean hasBatteryToScheduleExperiment() {
   return powerManager.canScheduleExperiment();
 }