From 3bd8cba78754d63f6379f073649a89baae82b837 Mon Sep 17 00:00:00 2001 From: Sharvil Nanavati Date: Fri, 30 May 2014 16:43:38 -0700 Subject: Add callouts for bluedroid to acquire wake locks and set wake alarms. Since bluedroid is running outside of system_server, it does not have the necessary Linux capabilities or filesystem permissions to access /sys/power/wake_* and /dev/alarm (or any other wake alarm). This change provides a mechanism by which bluedroid can call back up into Java code and use the standard Android APIs to get wake locks / wake alarms. Change-Id: I714fd394224d38da5ff0f82de5559599d522010b Conflicts: include/hardware/bluetooth.h --- include/hardware/bluetooth.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/hardware/bluetooth.h b/include/hardware/bluetooth.h index 41a1167..56b7367 100644 --- a/include/hardware/bluetooth.h +++ b/include/hardware/bluetooth.h @@ -17,6 +17,7 @@ #ifndef ANDROID_INCLUDE_BLUETOOTH_H #define ANDROID_INCLUDE_BLUETOOTH_H +#include #include #include #include @@ -360,6 +361,24 @@ typedef struct { le_test_mode_callback le_test_mode_cb; } bt_callbacks_t; +typedef void (*alarm_cb)(void *data); +typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data); +typedef int (*acquire_wake_lock_callout)(const char *lock_name); +typedef int (*release_wake_lock_callout)(const char *lock_name); + +/** The set of functions required by bluedroid to set wake alarms and + * grab wake locks. This struct is passed into the stack through the + * |set_os_callouts| function on |bt_interface_t|. + */ +typedef struct { + /* set to sizeof(bt_os_callouts_t) */ + size_t size; + + set_wake_alarm_callout set_wake_alarm; + acquire_wake_lock_callout acquire_wake_lock; + release_wake_lock_callout release_wake_lock; +} bt_os_callouts_t; + /** NOTE: By default, no profiles are initialized at the time of init/enable. * Whenever the application invokes the 'init' API of a profile, then one of * the following shall occur: @@ -471,6 +490,11 @@ typedef struct { /* enable or disable bluetooth HCI snoop log */ int (*config_hci_snoop_log)(uint8_t enable); + + /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks. + * This should be called immediately after a successful |init|. + */ + int (*set_os_callouts)(bt_os_callouts_t *callouts); } bt_interface_t; /** TODO: Need to add APIs for Service Discovery, Service authorization and -- cgit v1.1