Change codes for CPU lock 80/135580/7
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 23 Jun 2017 07:25:16 +0000 (16:25 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 28 Jun 2017 03:46:17 +0000 (03:46 +0000)
- APIs used in previous implementation are not included in some profile
  So change methods of locking CPU by using dbus directly

Change-Id: I7a8898040856e69fd2f4b48da1883b49ef145585
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
CMakeLists.txt
packaging/pkgmgr-server.spec
src/pkgmgr-server.c

index a4396a8..0334e36 100644 (file)
@@ -26,7 +26,7 @@ SET(PKGMGR_SERVER "pkgmgr-server")
 AUX_SOURCE_DIRECTORY(src SRCS)
 
 SET(SERVER_CHECK_MODULES gio-2.0 glib-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul
-minizip deviced)
+minizip)
 
 pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES})
 
index f4f53e3..b900d3f 100644 (file)
@@ -23,7 +23,6 @@ BuildRequires:  pkgconfig(libgum)
 BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(libsystemd)
 BuildRequires:  pkgconfig(minizip)
-BuildRequires:  pkgconfig(deviced)
 BuildRequires:  fdupes
 
 %description
index 197ad3d..89338ea 100644 (file)
@@ -44,7 +44,6 @@
 #include <pkgmgr-info.h>
 #include <pkgmgr/pkgmgr_parser_db.h>
 #include <tzplatform_config.h>
-#include <dd-display.h>
 
 #include "pkgmgr_installer.h"
 #include "pkgmgr-server.h"
@@ -94,6 +93,7 @@ static GIOChannel *sio;
 static guint swid;
 static GHashTable *backend_info_table;
 static GMainLoop *mainloop;
+static GDBusConnection *system_conn;
 
 static int (*_drm_tizen_register_license)
                (const char *pRespBuf, unsigned int respBufLen);
@@ -130,22 +130,105 @@ static void __set_backend_free(int position)
        backend_busy = backend_busy & ~(1 << position);
 }
 
+static GDBusConnection *_get_system_conn(void)
+{
+       GError *err = NULL;
+
+       if (system_conn)
+               return system_conn;
+
+       system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (system_conn == NULL) {
+               ERR("Failed to get system bus: %s", err->message);
+               g_error_free(err);
+               return NULL;
+       }
+
+       return system_conn;
+}
+
+#define DEVICED_DBUS_PATH "org.tizen.system.deviced"
+#define DEVICED_DBUS_OBJECT_PATH "/Org/Tizen/System/DeviceD/Display"
+#define DEVICED_DBUS_INTERFACE_NAME "org.tizen.system.deviced.display"
+
 static void __set_power_lock(void)
 {
+       GDBusConnection *conn;
+       GDBusMessage *msg;
+       GError *err = NULL;
+       int ret = 0;
+
        if (is_lock_set)
                return;
 
-       if (display_lock_state(LCD_OFF, STAY_CUR_STATE, 0) == 0)
+       conn = _get_system_conn();
+       if (conn == NULL)
+               return;
+
+       msg = g_dbus_message_new_method_call(DEVICED_DBUS_PATH,
+                       DEVICED_DBUS_OBJECT_PATH,
+                       DEVICED_DBUS_INTERFACE_NAME,
+                       "lockstate");
+       if (msg == NULL) {
+               ERR("g_dbus_message_new_method_call() has failed");
+               return;
+       }
+
+       g_dbus_message_set_body(msg, g_variant_new("(sssi)", "lcdoff",
+                       "staycurstate", "NULL", 0));
+       if (!g_dbus_connection_send_message(conn, msg,
+                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err)) {
+               ERR("Unable to send dbus message for acquring lock as  %s",
+                               err->message);
+               ret = -1;
+       }
+
+       if (ret == 0)
                is_lock_set = true;
+       g_object_unref(msg);
+       g_dbus_connection_flush_sync(conn, NULL, NULL);
+       g_clear_error(&err);
 }
 
 static void __release_power_lock(void)
 {
+       GError *err = NULL;
+       GDBusConnection *conn;
+       GDBusMessage *msg;
+       int ret = 0;
+
        if (!is_lock_set)
                return;
 
-       if (display_unlock_state(LCD_OFF, PM_SLEEP_MARGIN) == 0)
+       conn = _get_system_conn();
+       if (conn == NULL)
+               return;
+
+       msg = g_dbus_message_new_method_call(DEVICED_DBUS_PATH,
+                       DEVICED_DBUS_OBJECT_PATH,
+                       DEVICED_DBUS_INTERFACE_NAME,
+                       "unlockstate");
+       if (msg == NULL) {
+               ERR("g_dbus_message_new_method_call() is failed");
+               return;
+       }
+
+       g_dbus_message_set_body(msg, g_variant_new("(ss)", "lcdoff",
+                       "sleepmargin"));
+       if (!g_dbus_connection_send_message(conn, msg,
+                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err)) {
+               ERR("Unable to send dbus message for releasing lock as  %s",
+                       err->message);
+               ret = -1;
+       }
+
+       if (ret == 0)
                is_lock_set = false;
+       g_object_unref(msg);
+       g_dbus_connection_flush_sync(conn, NULL, NULL);
+       g_clear_error(&err);
+
+       return;
 }
 
 static gboolean getsize_io_handler(GIOChannel *io, GIOCondition cond,