/**
   * Restore the properties associated with this preference on boot
   *
   * @param ctx A valid context
   */
  public static void restore(Context ctx) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    CMHardwareManager hardware = CMHardwareManager.getInstance(ctx);
    if (hardware.isSupported(FEATURE_TAP_TO_WAKE)) {
      final boolean enabled = prefs.getBoolean(KEY_TAP_TO_WAKE, hardware.get(FEATURE_TAP_TO_WAKE));

      if (!hardware.set(FEATURE_TAP_TO_WAKE, enabled)) {
        Log.e(TAG, "Failed to restore tap-to-wake settings.");
      } else {
        Log.d(TAG, "Tap-to-wake settings restored.");
      }
    }
  }
  @Override
  public void onResume() {
    super.onResume();
    updateDisplayRotationPreferenceDescription();

    if (mTapToWake != null) {
      mTapToWake.setChecked(mHardware.get(FEATURE_TAP_TO_WAKE));
    }

    RotationPolicy.registerRotationPolicyListener(getActivity(), mRotationPolicyListener);

    final ContentResolver resolver = getContentResolver();

    boolean dozeEnabled =
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.DOZE_ENABLED, 1) != 0;
    if (mDozeFragement != null) {
      mDozeFragement.setSummary(
          dozeEnabled ? R.string.summary_doze_enabled : R.string.summary_doze_disabled);
    }

    // Display rotation observer
    resolver.registerContentObserver(
        Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
        true,
        mAccelerometerRotationObserver);

    // Default value for wake-on-plug behavior from config.xml
    boolean wakeUpWhenPluggedOrUnpluggedConfig =
        getResources().getBoolean(com.android.internal.R.bool.config_unplugTurnsOnScreen);

    mWakeWhenPluggedOrUnplugged.setChecked(
        Settings.Global.getInt(
                getContentResolver(),
                Settings.Global.WAKE_WHEN_PLUGGED_OR_UNPLUGGED,
                (wakeUpWhenPluggedOrUnpluggedConfig ? 1 : 0))
            == 1);

    updateState();
  }