display: add function for broadcasting pmlock state 67/287867/1
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 6 Feb 2023 05:14:50 +0000 (14:14 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 7 Feb 2023 07:34:16 +0000 (16:34 +0900)
Add functions to inform/get pmlock state.
When the pmlock node is changed(locked or unlocked), signal will be emitted.
Also, It is possible to get pmlock state with below dbus method.

1. Get pmlock lock state
path: /Org/Tizen/System/DeviceD/Display
interface: org.tizen.system.deviced.display
member: PmlockGetLockState
parameter: "(i)", power lock type to get lock status of pmlock state
return: "(i)", value which means locked or unlocked of pmlock state

Change-Id: I35fe5e882cc22616190a56d18155fcde7aa1b968
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/display/display-dbus.c
src/display/display-lock.c
src/display/display-lock.h

index 5f530e54177b4abecd79e4e5b020e1e41bd69061..c181d0f11526daa1973a5a8e3b48eb2a874b1d64 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdbool.h>
 #include <libsyscommon/libgdbus.h>
 #include <device/display.h>
+#include <device/power.h>
 
 #include "ambient-mode.h"
 #include "core/log.h"
@@ -1279,6 +1280,30 @@ static GVariant *dbus_setrotationangle(GDBusConnection *conn,
        return g_variant_new("(i)", ret);
 }
 
+static GVariant *dbus_pmlockgetlockstate(GDBusConnection *conn,
+       const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+       GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       power_lock_e power_lock_type;
+       bool pmlock_state = false;
+       enum state_t pmlock_type;
+       pid_t pid;
+
+       g_variant_get(param, "(i)", &power_lock_type);
+
+       if (power_lock_type < POWER_LOCK_CPU || power_lock_type > POWER_LOCK_DISPLAY_DIM)
+               _W("Invalid parameter power lock type=(%d)", power_lock_type);
+
+       pmlock_type = power_lock_type_to_pmlock(power_lock_type);
+
+       pmlock_state = pmlock_get_lock_state(pmlock_type);
+
+       pid = gdbus_connection_get_sender_pid(conn, sender);
+       _D("Pmlock get lock state pid=%d power lock state=%d", pid, pmlock_state);
+
+       return g_variant_new("(i)", (int)pmlock_state);
+}
+
 static const dbus_method_s dbus_methods[] = {
        { "start",           NULL,  NULL, dbus_start },
        { "stop",            NULL,  NULL, dbus_stop },
@@ -1319,7 +1344,8 @@ static const dbus_method_s dbus_methods[] = {
        { "SetWhiteBalance", "ii", "i", dbus_setwhitebalance},
        { "GetWhiteBalance", "i", "i", dbus_getwhitebalance},
        { "GetRotationAngle", "i", "iii", dbus_getrotationangle},
-       { "SetRotationAngle", "iii", "i", dbus_setrotationangle}
+       { "SetRotationAngle", "iii", "i", dbus_setrotationangle},
+       { "PmlockGetLockState", "i", "i", dbus_pmlockgetlockstate},
        /* Add methods here */
 };
 
index b866a664d77d074e451c3c9880bbfb03ed68bc24..265fd09e0cc54419f334435dd4ca7e1744ceed90 100644 (file)
@@ -57,6 +57,25 @@ bool check_lock_state(int state)
        return false;
 }
 
+bool pmlock_get_lock_state(enum state_t state)
+{
+       return (bool)SYS_G_LIST_LENGTH(cond_head[state]);
+}
+
+enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type)
+{
+       switch(power_lock_type) {
+       case POWER_LOCK_CPU:
+               return S_LCDOFF;
+       case POWER_LOCK_DISPLAY:
+               return S_LCDON;
+       case POWER_LOCK_DISPLAY_DIM:
+               return S_LCDDIM;
+       default:
+               return S_END;
+       }
+}
+
 static void refresh_app_cond(void)
 {
        trans_condition = 0;
@@ -69,6 +88,30 @@ static void refresh_app_cond(void)
                trans_condition |= MASK_OFF;
 }
 
+static void broadcast_pmlock_state_changed(enum state_t state)
+{
+       int num_of_pmlock;
+
+       switch(state) {
+       case S_LCDON:
+       case S_LCDDIM:
+       case S_LCDOFF:
+               break;
+       default:
+               return;
+       }
+
+       num_of_pmlock = g_list_length(cond_head[state]);
+       if (num_of_pmlock > 1)
+               return;
+
+       gdbus_signal_emit(NULL,
+               DEVICED_PATH_DISPLAY,
+               DEVICED_INTERFACE_DISPLAY,
+               DEVICED_SIGNAL_POWER_LOCK_STATE_CHANGED,
+               g_variant_new("(ii)", state, num_of_pmlock));
+}
+
 static void broadcast_pmlock_expired(pid_t pid, enum state_t state, const char* appid, time_t locktime)
 {
        time_t now;
@@ -243,6 +286,9 @@ PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id,
        SYS_G_LIST_APPEND(cond_head[s_index], n);
 
        refresh_app_cond();
+
+       broadcast_pmlock_state_changed(s_index);
+
        return n;
 }
 
@@ -267,6 +313,8 @@ int del_node(enum state_t s_index, PmLockNode *n)
                n->warning_param = NULL;
        }
 
+       broadcast_pmlock_state_changed(s_index);
+
        free(n);
        refresh_app_cond();
        return 0;
@@ -341,6 +389,8 @@ int delete_condition(enum state_t state)
        SYS_G_LIST_FREE_LIST(cond_head[state]);
        cond_head[state] = NULL;
 
+       broadcast_pmlock_state_changed(state);
+
        return 0;
 }
 
index 3bc271bf6c99e6189860b1c73a24c3a35cdd40bd..98e3376d2461cea67c1e497b869b566496e3081b 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef __DISPLAY_LOCK_H__
 #define __DISPLAY_LOCK_H__
 
+#include <device/power.h>
+
 #include "core.h"
 
 typedef struct _pm_lock_node {
@@ -51,6 +53,8 @@ typedef struct _pm_lock_node {
 } PmLockNode;
 
 bool check_lock_state(int state);
+bool pmlock_get_lock_state(enum state_t state);
+enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type);
 PmLockNode *find_node(enum state_t s_index, pid_t pid);
 PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, bool holdkey_block);
 int del_node(enum state_t s_index, PmLockNode *n);