Listen LCD ON event to handle pre resume event 06/175106/6
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 9 Apr 2018 00:25:31 +0000 (09:25 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 9 Apr 2018 04:41:12 +0000 (13:41 +0900)
Change-Id: I00d8f28762522acc6a174b571cc7ad26dedf02cc
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/appcore-watch-signal.c
src/appcore-watch-signal.h
src/watch_app_main.c

index ba64b4b..1d3408f 100755 (executable)
 #define MAX_BUFFER_SIZE                512
 
 static GDBusConnection *conn;
+static unsigned int __conn_ref;
 static guint s_id;
 static int (*_deviced_signal_alpm_handler)(int ambient, void *data);
 static void *_deviced_signal_alpm_data;
+static guint __lcd_sid;
+static void (*__deviced_signal_lcd_handler)(void *data);
+static void *__deviced_signal_lcd_data;
 
 /* LCOV_EXCL_START */
 static void __dbus_signal_filter(GDBusConnection *connection,
@@ -80,10 +84,23 @@ static int __dbus_init(void)
        }
 
        g_clear_error(&err);
+       __conn_ref++;
 
        return 0;
 }
 
+static void __dbus_fini(void)
+{
+       if (__conn_ref == 0)
+               return;
+
+       __conn_ref--;
+       if (__conn_ref == 0) {
+               g_object_unref(conn);
+               conn = NULL;
+       }
+}
+
 static int __dbus_signal_handler_init(const char *path, const char *interface)
 {
        s_id = g_dbus_connection_signal_subscribe(conn,
@@ -158,3 +175,60 @@ int _watch_core_send_alpm_update_done(void)
 }
 /* LCOV_EXCL_STOP */
 
+/* LCOV_EXCL_START */
+static void __lcd_on_signal_handler(GDBusConnection *connection,
+               const gchar *sender_name,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data)
+{
+       _I("LCD ON");
+       if (__deviced_signal_lcd_handler)
+               __deviced_signal_lcd_handler(__deviced_signal_lcd_data);
+}
+/* LCOV_EXCL_STOP */
+
+int _watch_core_listen_lcd_status_signal(void (*func)(void *), void *data)
+{
+       if (__dbus_init() < 0)
+               return -1;
+
+       __lcd_sid = g_dbus_connection_signal_subscribe(conn,
+                       NULL,
+                       DEVICED_INTERFACE_DISPLAY,
+                       LCD_ON,
+                       DEVICED_PATH_DISPLAY,
+                       NULL,
+                       G_DBUS_SIGNAL_FLAGS_NONE,
+                       __lcd_on_signal_handler,
+                       NULL,
+                       NULL);
+       if (!__lcd_sid) {
+               _E("Failed to subscribe LCD status signal");
+               return -1;
+       }
+
+       __deviced_signal_lcd_handler = func;
+       __deviced_signal_lcd_data = data;
+
+       _D("Listen LCD status signal");
+
+       return 0;
+}
+
+void _watch_core_ignore_lcd_status_signal(void)
+{
+       __deviced_signal_lcd_handler = NULL;
+       __deviced_signal_lcd_data = NULL;
+
+       if (__lcd_sid) {
+               g_dbus_connection_signal_unsubscribe(conn, __lcd_sid);
+               __lcd_sid = 0;
+       }
+
+       __dbus_fini();
+
+       _D("Ignore LCD status signal");
+}
index 69c54a5..662fc8b 100755 (executable)
@@ -31,8 +31,14 @@ extern "C" {
 #define CLOCK_START "clockbegin"
 #define CLOCK_STOP "clockstop"
 
+#define DEVICED_PATH_DISPLAY            "/Org/Tizen/System/DeviceD/Display"
+#define DEVICED_INTERFACE_DISPLAY       "org.tizen.system.deviced.display"
+#define LCD_ON                         "LCDOn"
+
 int _watch_core_listen_alpm_handler(int (*func)(int, void *), void *data);
 int _watch_core_send_alpm_update_done(void);
+int _watch_core_listen_lcd_status_signal(void (*func)(void *), void *data);
+void _watch_core_ignore_lcd_status_signal(void);
 
 #ifdef __cplusplus
 }
index af5f6e9..6c99053 100755 (executable)
@@ -866,6 +866,15 @@ static int __viewer_state_handler(const char *widget_id, aul_app_com_result_e e,
        return 0;
 }
 
+static void __lcd_on_handler(void *user_data)
+{
+       if (__pre_resume_called == 0) {
+               _D("Call pre resume tick");
+               __on_pre_resume(NULL);
+               __pre_resume_called = 1;
+       }
+}
+
 EXPORT_API int watch_app_main(int argc, char **argv,
                watch_app_lifecycle_callback_s *callback, void *user_data)
 {
@@ -948,6 +957,7 @@ EXPORT_API int watch_app_main(int argc, char **argv,
        __context.ambient_mode_skip_resume = false;
        __context.data = user_data;
        __context.state = WATCH_APP_STATE_CREATING;
+       _watch_core_listen_lcd_status_signal(__lcd_on_handler, NULL);
 
        ret = appcore_efl_base_init(ops, argc, argv, NULL, 0);
        free(__context.appid);
@@ -960,6 +970,7 @@ EXPORT_API int watch_app_main(int argc, char **argv,
                return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
        }
 
+       _watch_core_ignore_lcd_status_signal();
        appcore_efl_base_fini();
        __context.state = WATCH_APP_STATE_NOT_RUNNING;