From 4d820c060da4c38cc2dc8fa21b57103c3eb69fb2 Mon Sep 17 00:00:00 2001 From: Bardia Moshiri Date: Mon, 15 Jan 2024 19:01:40 -0500 Subject: [PATCH] treewide: implement batman-vr Signed-off-by: Bardia Moshiri --- Makefile | 12 +++++-- debian/batman-vr.install | 1 + debian/control | 7 ++++ debian/rules | 5 +-- src/batman-vr.c | 75 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 debian/batman-vr.install create mode 100644 src/batman-vr.c diff --git a/Makefile b/Makefile index b518979..c63e841 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ LDFLAGS = -lwayland-client `pkg-config --libs upower-glib gtk4 libadwaita-1` CFLAGS_NFCD = -fPIC -DNFC_PLUGIN_EXTERNAL `pkg-config --cflags nfcd-plugin libglibutil gobject-2.0 glib-2.0` LDFLAGS_NFCD = -fPIC -shared `pkg-config --libs libglibutil gobject-2.0 glib-2.0` -lwayland-client LDFLAGS_LIBPOWER = `pkg-config --libs --cflags libgbinder` +LDFLAGS_VR = `pkg-config --libs --cflags libgbinder` CFLAGS_WMT = `pkg-config --cflags glib-2.0 libnl-3.0 libnl-genl-3.0 libnl-route-3.0` LDFLAGS_WMT = `pkg-config --libs glib-2.0 libnl-3.0 libnl-genl-3.0 libnl-route-3.0` @@ -13,6 +14,7 @@ TARGET_GUI = batman-gui TARGET_GOVERNOR = governor TARGET_LIB = libbatman-wrappers.so TARGET_LIBPOWER = batman-libpower +TARGET_VR = batman-vr TARGET_NFCD = batman.so TARGET_WMT = batman-wmt @@ -21,6 +23,7 @@ SRC_GUI = src/batman-gui.c src/configcontrol.c src/getinfo.c SRC_GOVERNOR = src/governor.c src/wlrdisplay.c SRC_LIB = src/batman-wrappers.c src/wlrdisplay.c src/getinfo.c SRC_LIBPOWER = src/batman-libpower.c +SRC_VR = src/batman-vr.c SRC_NFCD = src/nfcd-batman-plugin.c src/wlrdisplay.c SRC_WMT = src/batman-wmt.c HEADERS = src/batman-wrappers.h src/getinfo.h src/governor.h @@ -34,7 +37,7 @@ ICON_DIR = /usr/share/icons INCLUDE_DIR = /usr/include/batman .PHONY: all -all: $(TARGET) $(TARGET_LIBPOWER) $(TARGET_WMT) $(TARGET_NFCD) +all: $(TARGET) $(TARGET_LIBPOWER) $(TARGET_VR) $(TARGET_WMT) $(TARGET_NFCD) $(TARGET): $(SRC) $(CC) $(CFLAGS) $(SRC_HELPER) $(LDFLAGS) -o $(TARGET_HELPER) @@ -43,7 +46,10 @@ $(TARGET): $(SRC) $(CC) -fPIC -shared $(CFLAGS) $(SRC_LIB) $(LDFLAGS) -o $(TARGET_LIB) $(TARGET_LIBPOWER): - gcc $(SRC_LIBPOWER) -o $(TARGET_LIBPOWER) $(LDFLAGS_LIBPOWER) + $(CC) $(SRC_LIBPOWER) -o $(TARGET_LIBPOWER) $(LDFLAGS_LIBPOWER) + +$(TARGET_VR): + $(CC) $(SRC_VR) -o $(TARGET_VR) $(LDFLAGS_VR) $(TARGET_WMT): $(CC) $(SRC_WMT) -o $(TARGET_WMT) $(CFLAGS_WMT) $(LDFLAGS_WMT) @@ -65,6 +71,7 @@ install: $(TARGET) cp $(TARGET_GOVERNOR) $(BINDIR) cp $(TARGET_LIB) /usr/lib cp $(TARGET_LIBPOWER) $(BINDIR) + cp $(TARGET_VR) $(BINDIR) cp $(TARGET_WMT) $(BINDIR) cp data/batman-gui.desktop $(DESKTOP_DIR) @@ -92,6 +99,7 @@ clean: rm -f $(TARGET_GOVERNOR) rm -f $(TARGET_LIB) rm -f $(TARGET_LIBPOWER) + rm -f $(TARGET_VR) rm -f $(TARGET_NFCD) rm -f $(TARGET_WMT) rm -f nfcd-batman-plugin.o wlrdisplay.o diff --git a/debian/batman-vr.install b/debian/batman-vr.install new file mode 100644 index 0000000..6d973c7 --- /dev/null +++ b/debian/batman-vr.install @@ -0,0 +1 @@ +usr/bin/batman-vr diff --git a/debian/control b/debian/control index 6eff430..44ffbac 100644 --- a/debian/control +++ b/debian/control @@ -89,3 +89,10 @@ Architecture: any Depends: ${misc:Depends} Description: batman-wmt A battery management service for Linux phones - wmt suspend + +Package: batman-vr +Section: misc +Architecture: any +Depends: ${misc:Depends} +Description: batman-vr + A battery management service for Linux phones - vr boost diff --git a/debian/rules b/debian/rules index b833ba3..48871a4 100755 --- a/debian/rules +++ b/debian/rules @@ -9,20 +9,21 @@ override_dh_auto_build: gcc src/batman-gui.c src/configcontrol.c src/getinfo.c -o batman-gui `pkg-config --cflags --libs gtk4 libadwaita-1` gcc src/governor.c src/wlrdisplay.c -o governor -lwayland-client + gcc src/batman-vr.c -o batman-vr `pkg-config --libs --cflags libgbinder` gcc src/batman-libpower.c -o batman-libpower `pkg-config --libs --cflags libgbinder` + gcc src/batman-wmt.c `pkg-config --cflags glib-2.0 libnl-3.0 libnl-genl-3.0 libnl-route-3.0` `pkg-config --libs glib-2.0 libnl-3.0 libnl-genl-3.0 libnl-route-3.0` -o batman-wmt gcc -c src/nfcd-batman-plugin.c -fPIC -DNFC_PLUGIN_EXTERNAL `pkg-config --cflags nfcd-plugin libglibutil gobject-2.0 glib-2.0` -O2 -o nfcd-batman-plugin.o gcc -c src/wlrdisplay.c -fPIC -DNFC_PLUGIN_EXTERNAL `pkg-config --cflags nfcd-plugin libglibutil gobject-2.0 glib-2.0` -O2 -o wlrdisplay.o gcc nfcd-batman-plugin.o wlrdisplay.o -fPIC -shared `pkg-config --libs libglibutil gobject-2.0 glib-2.0` -lwayland-client -o batman.so - gcc src/batman-wmt.c `pkg-config --cflags glib-2.0 libnl-3.0 libnl-genl-3.0 libnl-route-3.0` `pkg-config --libs glib-2.0 libnl-3.0 libnl-genl-3.0 libnl-route-3.0` -o batman-wmt - override_dh_auto_install: install -D -m 0755 src/batman debian/tmp/usr/bin/batman install -D -m 0755 batman-helper debian/tmp/usr/bin/batman-helper install -D -m 0755 governor debian/tmp/usr/bin/governor install -D -m 0755 batman-gui debian/tmp/usr/bin/batman-gui + install -D -m 0755 batman-vr debian/tmp/usr/bin/batman-vr install -D -m 0755 batman-libpower debian/tmp/usr/bin/batman-libpower install -D -m 0755 batman-wmt debian/tmp/usr/bin/batman-wmt diff --git a/src/batman-vr.c b/src/batman-vr.c new file mode 100644 index 0000000..981819d --- /dev/null +++ b/src/batman-vr.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2023 Bardia Moshiri + +#include +#include +#include +#include + +void set_modes_hidl(GBinderClient* client, const int enabled) { + int status; + GBinderLocalRequest* req = gbinder_client_new_request(client); + GBinderWriter writer; + + // init + gbinder_local_request_init_writer(req, &writer); + gbinder_client_transact_sync_reply(client, 1, req, &status); + gbinder_local_request_unref(req); + + // setVrMode + req = gbinder_client_new_request(client); + gbinder_local_request_init_writer(req, &writer); + gbinder_writer_append_bool(&writer, enabled); + gbinder_client_transact_sync_reply(client, 2, req, &status); + gbinder_local_request_unref(req); +} + +int init_hidl(const int mode) { + GBinderServiceManager* sm = gbinder_servicemanager_new("/dev/hwbinder"); + if (!sm) return 1; + + GBinderRemoteObject* remote = gbinder_servicemanager_get_service_sync(sm, "android.hardware.vr@1.0::IVr/default", NULL); + if (!remote) { + gbinder_servicemanager_unref(sm); + return 1; + } + + GBinderClient* client = gbinder_client_new(remote, "android.hardware.vr@1.0::IVr"); + if (!client) { + gbinder_remote_object_unref(remote); + gbinder_servicemanager_unref(sm); + return 1; + } + + set_modes_hidl(client, mode); + + gbinder_client_unref(client); + gbinder_remote_object_unref(remote); + + return 0; +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + printf("Usage: %s <0|1> (0 for vr mode off, 1 for vr mode on)\n", argv[0]); + return 1; + } + + int choice = atoi(argv[1]); + + if (choice == 0 || choice == 1) { + int ret = init_hidl(choice); + + if (ret != 0) { + printf("None of the backends are available. exiting\n"); + return 1; + } else { + printf("Using HIDL backend\n"); + } + } else { + printf("Invalid argument. Use 0 for vr mode off or 1 for vr mode on\n"); + return 1; + } + + return 0; +}