private void updateHardKeyboards() {
    mHardKeyboardPreferenceList.clear();
    if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY) {
      final int[] devices = InputDevice.getDeviceIds();
      for (int i = 0; i < devices.length; i++) {
        InputDevice device = InputDevice.getDevice(devices[i]);
        if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
          final String inputDeviceDescriptor = device.getDescriptor();
          final String keyboardLayoutDescriptor =
              mIm.getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor);
          final KeyboardLayout keyboardLayout =
              keyboardLayoutDescriptor != null
                  ? mIm.getKeyboardLayout(keyboardLayoutDescriptor)
                  : null;

          final PreferenceScreen pref = new PreferenceScreen(getActivity(), null);
          pref.setTitle(device.getName());
          if (keyboardLayout != null) {
            pref.setSummary(keyboardLayout.toString());
          } else {
            pref.setSummary(R.string.keyboard_layout_default_label);
          }
          pref.setOnPreferenceClickListener(
              new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                  showKeyboardLayoutDialog(inputDeviceDescriptor);
                  return true;
                }
              });
          mHardKeyboardPreferenceList.add(pref);
        }
      }
    }

    if (!mHardKeyboardPreferenceList.isEmpty()) {
      for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
        final Preference pref = mHardKeyboardCategory.getPreference(i);
        if (pref.getOrder() < 1000) {
          mHardKeyboardCategory.removePreference(pref);
        }
      }

      Collections.sort(mHardKeyboardPreferenceList);
      final int count = mHardKeyboardPreferenceList.size();
      for (int i = 0; i < count; i++) {
        final Preference pref = mHardKeyboardPreferenceList.get(i);
        pref.setOrder(i);
        mHardKeyboardCategory.addPreference(pref);
      }

      getPreferenceScreen().addPreference(mHardKeyboardCategory);
    } else {
      getPreferenceScreen().removePreference(mHardKeyboardCategory);
    }
  }
 private boolean haveInputDeviceWithVibrator() {
   final int[] devices = InputDevice.getDeviceIds();
   for (int i = 0; i < devices.length; i++) {
     InputDevice device = InputDevice.getDevice(devices[i]);
     if (device != null && !device.isVirtual() && device.getVibrator().hasVibrator()) {
       return true;
     }
   }
   return false;
 }