diff options
| author | TheKit <thekit@disroot.org> | 2026-07-28 13:15:00 +0300 |
|---|---|---|
| committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2026-10-12 22:19:59 +0200 |
| commit | 7b3161b8ac511cf0dcc18aded00171f8cc07ae9a (patch) | |
| tree | a725573453e0f4bc85916d73688150844a60e3b2 /src/flashlight.c | |
| parent | ce800c1e2012bf0d6cced36ec6ea8e1b9e9ddf38 (diff) | |
| download | ayatana-indicator-power-7b3161b8ac511cf0dcc18aded00171f8cc07ae9a.tar.gz ayatana-indicator-power-7b3161b8ac511cf0dcc18aded00171f8cc07ae9a.tar.bz2 ayatana-indicator-power-7b3161b8ac511cf0dcc18aded00171f8cc07ae9a.zip | |
flashlight: add a camera HAL backend
Some flash drivers expose a sysfs node that only toggles the LED and leaves
the duty and the flash safety timeout unset, so the LED goes out by itself.
Drive the torch through the AIDL camera provider instead, which programs all
three.
Select it with "FlashlightBackend: camera-hal" in the device yaml. Needs
libgbinder, so it is behind the ENABLE_LIBGBINDER build option.
Diffstat (limited to 'src/flashlight.c')
| -rw-r--r-- | src/flashlight.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/flashlight.c b/src/flashlight.c index 337c01c..4a9e40c 100644 --- a/src/flashlight.c +++ b/src/flashlight.c @@ -23,6 +23,8 @@ #include <gio/gio.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <fcntl.h> #include <unistd.h> @@ -36,6 +38,7 @@ extern char* flashlight_path(); extern char* flashlight_switch_path(); extern char* flashlight_simple_enable_value(); extern char* flashlight_simple_disable_value(); +extern char* flashlight_backend(); #endif const size_t qcom_sysfs_size = 7; @@ -61,8 +64,19 @@ enum TorchType torch_type = SIMPLE; gboolean activated = 0; int -set_sysfs_path() +probe_flashlight() { +# if defined(ENABLE_LIBDEVICEINFO) && defined(ENABLE_LIBGBINDER) + char* backend = flashlight_backend(); + int use_camera_hal = !strcmp(backend, "camera-hal"); + + free(backend); + + if (use_camera_hal) { + torch_type = CAMERA_HAL; + return flashlight_camera_hal_supported(); + } +# endif # ifdef ENABLE_LIBDEVICEINFO if (strcmp(flashlight_path(), "")) { if (access(flashlight_path(), F_OK) != -1) { @@ -176,13 +190,18 @@ toggle_flashlight_action(GAction *action, GVariant *state; int toggled; - if (!set_sysfs_path()) + if (!probe_flashlight()) return; state = g_action_get_state(action); activated = g_variant_get_boolean(state); g_variant_unref(state); +# ifdef ENABLE_LIBGBINDER + if (torch_type == CAMERA_HAL) + toggled = flashlight_camera_hal_set(!activated); + else +# endif if (torch_type == QCOM) toggled = toggle_flashlight_action_qcom(); else @@ -195,5 +214,5 @@ toggle_flashlight_action(GAction *action, int flashlight_supported() { - return set_sysfs_path(); + return probe_flashlight(); } |
