From 825a2828831f47ceab74d4cab6ec4d98ac0c91e7 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 27 Nov 2024 17:18:40 +0900 Subject: [PATCH] power: Support power lock for headless profile The functions below have become operational on headless profile. - device_power_request_lock() - device_power_release_lock() In addition, the functions below have become working properly as well on headless profile associated with the functions aboves. - device_power_get_lock_count() - device_power_add_lock_count_changed_callback() - device_power_remove_lock_count_changed_callback() Note that, device_power_change_state() bypasses power locks. This policy stands valid on both headed and headless profile. So it is encouraged that checking POWER_LOCK_CPU count using device_power_get_lock_count() before calling device_power_change_state() for DEVICE_POWER_STATE_SLEEP. Change-Id: Iaf4d4cdd0aa02dbd6fabea2096a3a011574f97a3 Signed-off-by: Youngjae Cho --- include/power-internal.h | 16 ++++++++++++++++ include/power.h | 8 ++++++-- src/power.c | 22 ---------------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/include/power-internal.h b/include/power-internal.h index 852cbb9..f08cbfb 100644 --- a/include/power-internal.h +++ b/include/power-internal.h @@ -503,6 +503,8 @@ typedef void (*device_power_change_state_callback) (device_power_state_e state, * @return @c 0 on success, otherwise a negative error value * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @remarks It is strongly encouraged that checking power lock count when it comes + * to changing state to DEVICE_POWER_STATE_SLEEP as it bypasses POWER_LOCK_CPU. * @code * #include * ... @@ -514,6 +516,19 @@ typedef void (*device_power_change_state_callback) (device_power_state_e state, * int main(void) * { * int ret = 0; + * int count = 0; + * + * ret = device_power_get_lock_count(POWER_LOCK_CPU , &count); + * if (ret != DEVICE_ERROR_NONE) { + * ... + * return 0; + * } + * + * if (count > 0) { + * ... + * return 0; + * } + * * ret = device_power_change_state(DEVICE_POWER_STATE_SLEEP, 3, power_state_change_cb, NULL); * if (ret != DEVICE_ERROR_NONE) { * ... @@ -521,6 +536,7 @@ typedef void (*device_power_change_state_callback) (device_power_state_e state, * } * ... * @endcode + * @see device_power_get_lock_count() * @see device_power_change_state_callback() * @see device_power_state_e */ diff --git a/include/power.h b/include/power.h index 8576ab8..53c46e2 100644 --- a/include/power.h +++ b/include/power.h @@ -63,7 +63,9 @@ typedef enum { * @privlevel public * @privilege %http://tizen.org/privilege/display * @remarks If the process dies after success request lock, then every lock will be removed. - * The display state feature(http://tizen.org/feature/display.state) also should be checked. + * If display feature(http://tizen.org/feature/display) is false, then only the type POWER_LOCK_CPU is effective, + * and the other type returns DEVICE_ERROR_NOT_SUPPORTED. And even thoguh the display feature is false, it requires + * display privilege(http://tizen.org/privilege/display). * @param[in] type The power type to request lock * @param[in] timeout_ms The positive number in milliseconds or @c 0 for permanent lock \n * So you must release the permanent lock of power state with #device_power_release_lock() if @a timeout_ms is zero @@ -94,7 +96,9 @@ int device_power_request_lock(power_lock_e type, int timeout_ms); * @since_tizen 2.3 * @privlevel public * @privilege %http://tizen.org/privilege/display - * @remarks The display state feature(http://tizen.org/feature/display.state) also should be checked. + * @remarks If display feature(http://tizen.org/feature/display) is false, then only the type POWER_LOCK_CPU is effective, + * and the other type returns DEVICE_ERROR_NOT_SUPPORTED. And even thoguh the display feature is false, it requires + * display privilege(http://tizen.org/privilege/display). * @param[in] type The power type to release lock * @return @c 0 on success, otherwise a negative error value * @retval #DEVICE_ERROR_NONE Successful diff --git a/src/power.c b/src/power.c index b957300..9128114 100644 --- a/src/power.c +++ b/src/power.c @@ -448,17 +448,6 @@ int device_power_request_lock(power_lock_e type, int timeout_ms) if (!is_feature_display_supported() || !is_feature_display_state_supported()) { if ((type == POWER_LOCK_DISPLAY) || (type == POWER_LOCK_DISPLAY_DIM)) { return DEVICE_ERROR_NOT_SUPPORTED; - } else if (type == POWER_LOCK_CPU) { - /* in case of headless, request for cpu lock is handled - * in power module of deviced, not in display module */ - - /* In current policy, headless doesn't support cpulock. Disable it. - ret = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, - DEVICED_PATH_POWER, DEVICED_INTERFACE_POWER, - "LockCpu", g_variant_new("(i)", timeout_ms), NULL); - return errno_to_device_error(ret); - */ - return DEVICE_ERROR_NONE; } } @@ -502,17 +491,6 @@ int device_power_release_lock(power_lock_e type) if (!is_feature_display_supported() || !is_feature_display_state_supported()) { if ((type == POWER_LOCK_DISPLAY) || (type == POWER_LOCK_DISPLAY_DIM)) { return DEVICE_ERROR_NOT_SUPPORTED; - } else if (type == POWER_LOCK_CPU) { - /* in case of headless, request for cpu unlock is handled - * in power module of deviced, not in display module */ - - /* In current policy, headless doesn't support cpulock. Disable it. - ret_val = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, - DEVICED_PATH_POWER, DEVICED_INTERFACE_POWER, - "UnlockCpu", NULL, NULL); - return errno_to_device_error(ret_val); - */ - return DEVICE_ERROR_NONE; } } -- 2.34.1