power: Support power lock for headless profile 89/315389/1 accepted/tizen/7.0/unified/20241204.185042
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 27 Nov 2024 08:18:40 +0000 (17:18 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 2 Dec 2024 01:38:45 +0000 (10:38 +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
src/power.c

index b769ed5eeefaf3ed09b3e78b45afa4be11994e0b..8453d4618e7209c8a9df2190ebab76f54bbc84a1 100644 (file)
@@ -247,6 +247,42 @@ typedef void (*device_power_change_state_callback) (device_power_state_e state,
  *         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>
+ * ...
+ * static void power_state_change_cb(device_power_state_e state, int retval, void *user_data)
+ * {
+ *     ...
+ * }
+ * ...
+ * 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) {
+ *         ...
+ *     }
+ * }
+ * ...
+ * @endcode
+ * @see device_power_get_lock_count()
+ * @see device_power_change_state_callback()
+ * @see device_power_state_e
  */
 int device_power_change_state(device_power_state_e state, int timeout_sec, device_power_change_state_callback cb, void *user_data);
 
index 9776517e4c213c8df749d18b06ec46958e6fb745..215b030b4e755dfa485abb8c4b19f83f568163b5 100644 (file)
@@ -449,23 +449,6 @@ int device_power_request_lock(power_lock_e type, int timeout_ms)
 
        _I("power_lock_e = %d", 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 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;
-               }
-       }
-
        if (check_async_call_rate(&num_calls) < 0) {
 //LCOV_EXCL_START System Error
                _E("Rejected by too frequent calls; %d (calls per sec.) limit is violated."
@@ -503,23 +486,6 @@ int device_power_release_lock(power_lock_e type)
 
        _I("power_lock_e = %d", 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;
-               }
-       }
-
        if (type == POWER_LOCK_CPU && power_locked_CPU) {
                ret_val = unlock_state(DISPLAY_STATE_SCREEN_OFF, PM_SLEEP_MARGIN);
                if (ret_val == 0) {