power-mode.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 2021 The LineageOS Project
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <aidl/android/hardware/power/BnPower.h>
  7. #include <android-base/file.h>
  8. #include <android-base/logging.h>
  9. #include <sys/ioctl.h>
  10. #define SET_CUR_VALUE 0
  11. #define TOUCH_DOUBLETAP_MODE 14
  12. #define TOUCH_MAGIC 't'
  13. #define TOUCH_IOC_SETMODE _IO(TOUCH_MAGIC, SET_CUR_VALUE)
  14. #define TOUCH_DEV_PATH "/dev/xiaomi-touch"
  15. #define TOUCH_ID 0
  16. namespace aidl {
  17. namespace android {
  18. namespace hardware {
  19. namespace power {
  20. namespace impl {
  21. using ::aidl::android::hardware::power::Mode;
  22. bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) {
  23. switch (type) {
  24. case Mode::DOUBLE_TAP_TO_WAKE:
  25. *_aidl_return = true;
  26. return true;
  27. default:
  28. return false;
  29. }
  30. }
  31. bool setDeviceSpecificMode(Mode type, bool enabled) {
  32. switch (type) {
  33. case Mode::DOUBLE_TAP_TO_WAKE: {
  34. int fd = open(TOUCH_DEV_PATH, O_RDWR);
  35. int arg[3] = {TOUCH_ID, TOUCH_DOUBLETAP_MODE, enabled ? 1 : 0};
  36. ioctl(fd, TOUCH_IOC_SETMODE, &arg);
  37. close(fd);
  38. return true;
  39. }
  40. default:
  41. return false;
  42. }
  43. }
  44. } // namespace impl
  45. } // namespace power
  46. } // namespace hardware
  47. } // namespace android
  48. } // namespace aidl