power-mode.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <sys/stat.h>
  11. #define SET_CUR_VALUE 0
  12. #define TOUCH_DOUBLETAP_MODE 14
  13. #define TOUCH_MAGIC 't'
  14. #define TOUCH_IOC_SETMODE _IO(TOUCH_MAGIC, SET_CUR_VALUE)
  15. #define TOUCH_DEV_PATH "/dev/xiaomi-touch"
  16. #define TOUCH_ID_PRIMARY 0
  17. #define TOUCH_ID_SECONDARY 1
  18. #define MI_DISP_SECONDARY "/sys/devices/virtual/mi_display/disp_feature/disp-DSI-1"
  19. namespace aidl {
  20. namespace android {
  21. namespace hardware {
  22. namespace power {
  23. namespace impl {
  24. using ::aidl::android::hardware::power::Mode;
  25. bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) {
  26. switch (type) {
  27. case Mode::DOUBLE_TAP_TO_WAKE:
  28. *_aidl_return = true;
  29. return true;
  30. default:
  31. return false;
  32. }
  33. }
  34. bool setDeviceSpecificMode(Mode type, bool enabled) {
  35. switch (type) {
  36. case Mode::DOUBLE_TAP_TO_WAKE: {
  37. int fd = open(TOUCH_DEV_PATH, O_RDWR);
  38. int arg_primary[3] = {TOUCH_ID_PRIMARY, TOUCH_DOUBLETAP_MODE, enabled ? 1 : 0};
  39. ioctl(fd, TOUCH_IOC_SETMODE, &arg_primary);
  40. struct stat buffer;
  41. if (stat(MI_DISP_SECONDARY, &buffer) == 0) {
  42. int arg_secondary[3] = {TOUCH_ID_SECONDARY, TOUCH_DOUBLETAP_MODE, enabled ? 1 : 0};
  43. ioctl(fd, TOUCH_IOC_SETMODE, &arg_secondary);
  44. }
  45. close(fd);
  46. return true;
  47. }
  48. default:
  49. return false;
  50. }
  51. }
  52. } // namespace impl
  53. } // namespace power
  54. } // namespace hardware
  55. } // namespace android
  56. } // namespace aidl