power: Support power lock for headless profile 86/317186/2 accepted/tizen_unified_x_asan accepted/tizen/unified/20250115.124138 accepted/tizen/unified/x/20250115.142718 accepted/tizen/unified/x/asan/20250211.003213
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 27 Nov 2024 08:18:40 +0000 (17:18 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Fri, 10 Jan 2025 04:55:37 +0000 (13:55 +0900)
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 <y0.cho@samsung.com>
include/power-internal.h
include/power.h
src/power.c

index 8aa12375af7b1b9dd3fe013f2d2cc5d7978aa26f..cfc5e974316c91cd0ab3d3f46d551e244f170066 100644 (file)
@@ -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 <device/power-internal.h>
  * ...
@@ -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
  */
index 8576ab806fb7955198e7bf3a24b2eaf0990864e1..53c46e2bb857c6ef5d7fe845b0c06fd2d3cb981f 100644 (file)
@@ -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
index b95730033fd3acf27b13532d891ff622887b349a..91281147aee6486a6ca66d8ee5a4daf15cfe3f61 100644 (file)
@@ -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;
                }
        }