From c2ddab59dc41366fe520dc4e8abcfea257ecf0b8 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 18 Feb 2026 11:32:34 -0500 Subject: [PATCH] xrt: address easy clang-tidy android fixes Part-of: --- .../android/org.freedesktop.monado.auxiliary.impl.hpp | 5 +---- src/xrt/auxiliary/ogl/ogl_helpers.c | 3 ++- src/xrt/auxiliary/util/u_extension_list.cpp | 4 ++-- src/xrt/compositor/main/comp_compositor.c | 5 +++++ src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp | 4 ++++ src/xrt/drivers/remote/r_hub.c | 6 +++++- src/xrt/ipc/server/ipc_server_mainloop_android.c | 2 +- src/xrt/targets/ctl/main.c | 4 ++++ src/xrt/targets/service-lib/service_target.cpp | 2 ++ 9 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/xrt/auxiliary/android/org.freedesktop.monado.auxiliary.impl.hpp b/src/xrt/auxiliary/android/org.freedesktop.monado.auxiliary.impl.hpp index ffe42dd67..fcfc0fac5 100644 --- a/src/xrt/auxiliary/android/org.freedesktop.monado.auxiliary.impl.hpp +++ b/src/xrt/auxiliary/android/org.freedesktop.monado.auxiliary.impl.hpp @@ -72,10 +72,7 @@ namespace org::freedesktop::monado::auxiliary { jfloat *refreshRates = (jfloat *)jni::env()->GetFloatArrayElements((jfloatArray)refreshRateArray.getHandle(), 0); jsize length = jni::env()->GetArrayLength((jfloatArray)refreshRateArray.getHandle()); - std::vector refreshRateVector; - for (int i = 0; i < length; i++) { - refreshRateVector.push_back(refreshRates[i]); - } + std::vector refreshRateVector(refreshRates, refreshRates + length); return refreshRateVector; } diff --git a/src/xrt/auxiliary/ogl/ogl_helpers.c b/src/xrt/auxiliary/ogl/ogl_helpers.c index 16cd9d0ab..abfdcd32d 100644 --- a/src/xrt/auxiliary/ogl/ogl_helpers.c +++ b/src/xrt/auxiliary/ogl/ogl_helpers.c @@ -102,7 +102,7 @@ ogl_import_from_native(struct xrt_image_native *natives, // Function is disabled for AHardwareBuffer, glImportMemoryFdEXT requires an actual FD and requires more work // to handle AHardwareBuffer. return false; -#endif +#else // Setup fields. results->width = info->width; @@ -167,4 +167,5 @@ ogl_import_from_native(struct xrt_image_native *natives, } return true; +#endif } diff --git a/src/xrt/auxiliary/util/u_extension_list.cpp b/src/xrt/auxiliary/util/u_extension_list.cpp index 20366073d..8fd61d344 100644 --- a/src/xrt/auxiliary/util/u_extension_list.cpp +++ b/src/xrt/auxiliary/util/u_extension_list.cpp @@ -131,7 +131,7 @@ is_experimental_vendor(std::string_view vendor) * Returns an ExtensionSortKey for comparison. */ static ExtensionSortKey -get_extension_sort_key(std::string_view name) +get_extension_sort_key(const std::string_view name) { // Find the first underscore to separate API prefix (e.g., "VK", "XR") size_t first_underscore = name.find('_'); @@ -269,7 +269,7 @@ ExtensionListBuilder::sortForExtensions() } // Sort using our custom comparison function that works with std::string - auto cmp = [](const std::string &a, const std::string &b) { + auto cmp = [](const std::string_view a, const std::string_view b) { return get_extension_sort_key(a) < get_extension_sort_key(b); }; std::sort(strings.begin(), strings.end(), cmp); diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index b6c4947bf..3364aaead 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -356,6 +356,11 @@ compositor_request_display_refresh_rate(struct xrt_compositor *xc, float display // Note that this will just increment the reference count, rather than actually load it again, // since we are linked for other symbols too. void *android_handle = dlopen("libandroid.so", RTLD_NOW); + if (android_handle == NULL) { + U_LOG_E("failed to open libandroid.so"); + return XRT_SUCCESS; + } + PF_SETFRAMERATE set_frame_rate = (PF_SETFRAMERATE)dlsym(android_handle, "ANativeWindow_setFrameRate"); if (!set_frame_rate) { U_LOG_E("ANativeWindow_setFrameRate not found"); diff --git a/src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp b/src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp index 230d5e32d..c5dac99b2 100644 --- a/src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp +++ b/src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp @@ -487,6 +487,10 @@ cemu_devices_create(struct xrt_device *head, struct xrt_device *hands, struct xr struct cemu_device *cemud[2]; struct cemu_system *system = U_TYPED_CALLOC(struct cemu_system); + if (system == NULL) { + return 0; + } + system->in_hand = hands; system->in_head = head; diff --git a/src/xrt/drivers/remote/r_hub.c b/src/xrt/drivers/remote/r_hub.c index 21436f3f4..17c1f6d4f 100644 --- a/src/xrt/drivers/remote/r_hub.c +++ b/src/xrt/drivers/remote/r_hub.c @@ -120,7 +120,7 @@ socket_close(r_socket_t id) static inline r_socket_t socket_create(void) { - return socket(AF_INET, SOCK_STREAM, 0); + return socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); } static inline int @@ -248,7 +248,11 @@ do_accept(struct r_hub *r) } socklen_t addr_length = (socklen_t)sizeof(addr); +#ifdef SOCK_CLOEXEC + ret = accept4(r->accept_fd, (struct sockaddr *)&addr, &addr_length, SOCK_CLOEXEC); +#else ret = accept(r->accept_fd, (struct sockaddr *)&addr, &addr_length); +#endif if (ret < 0) { R_ERROR(r, "accept: " R_SOCKET_FMT, ret); return ret; diff --git a/src/xrt/ipc/server/ipc_server_mainloop_android.c b/src/xrt/ipc/server/ipc_server_mainloop_android.c index 96a04f6bc..e6dc7e086 100644 --- a/src/xrt/ipc/server/ipc_server_mainloop_android.c +++ b/src/xrt/ipc/server/ipc_server_mainloop_android.c @@ -44,7 +44,7 @@ static int init_pipe(struct ipc_server_mainloop *ml) { int pipefd[2]; - int ret = pipe(pipefd); + int ret = pipe2(pipefd, O_CLOEXEC); if (ret < 0) { U_LOG_E("pipe2() failed '%i'", ret); return ret; diff --git a/src/xrt/targets/ctl/main.c b/src/xrt/targets/ctl/main.c index 079b0f110..10319e605 100644 --- a/src/xrt/targets/ctl/main.c +++ b/src/xrt/targets/ctl/main.c @@ -256,6 +256,10 @@ get_brightness(struct ipc_connection *ipc_c, int device_id) int set_brightness(struct ipc_connection *ipc_c, int device_id, const char *value) { + if (value == NULL) { + return 1; + } + const int length = strlen(value); if (length == 0) { return 1; diff --git a/src/xrt/targets/service-lib/service_target.cpp b/src/xrt/targets/service-lib/service_target.cpp index 839e87c9f..a9fdb3455 100644 --- a/src/xrt/targets/service-lib/service_target.cpp +++ b/src/xrt/targets/service-lib/service_target.cpp @@ -146,6 +146,8 @@ private: .window_title = "Monado Android Service", .open = U_DEBUG_GUI_OPEN_NEVER, }, + .exit_on_disconnect = false, + .no_stdin = false, }; const struct ipc_server_callbacks callbacks = { -- 2.51.2