summaryrefslogtreecommitdiffstats
path: root/minui
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-01-26 07:46:11 +0100
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-01-26 07:46:11 +0100
commitf1ac4dacd2e09aa787e85fe948f679d78d534a35 (patch)
tree8fe48a742d12436e855165534f0ac989a08c9cb4 /minui
parentMerge "minui: Add support for multiple connectors" am: 80a9dcad35 am: f8d4273171 am: b1090a47f4 am: 530cd6d0a7 (diff)
parentMerge "minui: add hall sensor event" am: 13c721f330 am: 3a012a971a am: cdebb47048 (diff)
downloadandroid_bootable_recovery-f1ac4dacd2e09aa787e85fe948f679d78d534a35.tar
android_bootable_recovery-f1ac4dacd2e09aa787e85fe948f679d78d534a35.tar.gz
android_bootable_recovery-f1ac4dacd2e09aa787e85fe948f679d78d534a35.tar.bz2
android_bootable_recovery-f1ac4dacd2e09aa787e85fe948f679d78d534a35.tar.lz
android_bootable_recovery-f1ac4dacd2e09aa787e85fe948f679d78d534a35.tar.xz
android_bootable_recovery-f1ac4dacd2e09aa787e85fe948f679d78d534a35.tar.zst
android_bootable_recovery-f1ac4dacd2e09aa787e85fe948f679d78d534a35.zip
Diffstat (limited to 'minui')
-rw-r--r--minui/events.cpp29
-rw-r--r--minui/include/minui/minui.h2
2 files changed, 31 insertions, 0 deletions
diff --git a/minui/events.cpp b/minui/events.cpp
index 863ac7474..b307a4977 100644
--- a/minui/events.cpp
+++ b/minui/events.cpp
@@ -267,6 +267,35 @@ int ev_get_input(int fd, uint32_t epevents, input_event* ev) {
return -1;
}
+int ev_sync_sw_state(const ev_set_sw_callback& set_sw_cb) {
+ // Use unsigned long to match ioctl's parameter type.
+ unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT
+ unsigned long sw_bits[BITS_TO_LONGS(SW_MAX)]; // NOLINT
+
+ for (size_t i = 0; i < g_ev_dev_count; ++i) {
+ memset(ev_bits, 0, sizeof(ev_bits));
+ memset(sw_bits, 0, sizeof(sw_bits));
+
+ if (ioctl(ev_fdinfo[i].fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) {
+ continue;
+ }
+ if (!test_bit(EV_SW, ev_bits)) {
+ continue;
+ }
+ if (ioctl(ev_fdinfo[i].fd, EVIOCGSW(sizeof(sw_bits)), sw_bits) == -1) {
+ continue;
+ }
+
+ for (int code = 0; code <= SW_MAX; code++) {
+ if (test_bit(code, sw_bits)) {
+ set_sw_cb(code, 1);
+ }
+ }
+ }
+
+ return 0;
+}
+
int ev_sync_key_state(const ev_set_key_callback& set_key_cb) {
// Use unsigned long to match ioctl's parameter type.
unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT
diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h
index 19a14ceb7..f9be82f52 100644
--- a/minui/include/minui/minui.h
+++ b/minui/include/minui/minui.h
@@ -163,6 +163,7 @@ struct input_event;
using ev_callback = std::function<int(int fd, uint32_t epevents)>;
using ev_set_key_callback = std::function<int(int code, int value)>;
+using ev_set_sw_callback = std::function<int(int code, int value)>;
int ev_init(ev_callback input_cb, bool allow_touch_inputs = false);
void ev_exit();
@@ -170,6 +171,7 @@ int ev_add_fd(android::base::unique_fd&& fd, ev_callback cb);
void ev_iterate_available_keys(const std::function<void(int)>& f);
void ev_iterate_touch_inputs(const std::function<void(int)>& action);
int ev_sync_key_state(const ev_set_key_callback& set_key_cb);
+int ev_sync_sw_state(const ev_set_sw_callback& set_sw_cb);
// 'timeout' has the same semantics as poll(2).
// 0 : don't block