Adjust the timing of toolkit creation 37/144437/2 accepted/tizen/3.0/ivi/20170818.001257 accepted/tizen/3.0/mobile/20170818.001227 accepted/tizen/3.0/wearable/20170818.001239 submit/tizen_3.0/20170817.063913
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 17 Aug 2017 00:18:57 +0000 (09:18 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 17 Aug 2017 02:38:34 +0000 (11:38 +0900)
After this patch is applided, the toolkit handle of watch control
will be created when getting watch launch signal from the amd.

Change-Id: Id21e23e7e0391e5e2267fa9ff1b60e997c242800
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
watch-control/src/control.c

index c255829..6196420 100644 (file)
@@ -88,6 +88,10 @@ static int __change_viewer_visibility(int visibility, bool update_cur_state);
 static int __change_visibility(int visibility);
 static GDBusConnection *__gdbus_conn;
 static guint __lcd_subscribe_id;
+static aul_app_com_connection_h __conn_launch_signal;
+
+static int __listen_launch_signal(void);
+static void __ignore_launch_signal(void);
 
 static void __process_pending_status(int status, unsigned int surf)
 {
@@ -328,6 +332,7 @@ static void __watch_viewer_fini()
 API int watch_manager_init(Evas_Object *win)
 {
        __watch_viewer_init(win);
+       __listen_launch_signal();
        return 0;
 }
 
@@ -465,7 +470,6 @@ API int watch_manager_get_app_control(const char *app_id, app_control_h *app_con
 {
        char buf[10];
        bundle *b = NULL;
-       screen_connector_toolkit_evas_ops ops;
 
        if (app_id == NULL) {
                _E("Invalid param");
@@ -482,17 +486,6 @@ API int watch_manager_get_app_control(const char *app_id, app_control_h *app_con
 
        app_control_set_operation(*app_control, APP_CONTROL_OPERATION_MAIN);
 
-       _D("cur %s, new %s", __watch_appid, app_id);
-       if (screen_connector_toolkit_is_exist((char *)__watch_appid,
-                       SCREEN_CONNECTOR_SCREEEN_TYPE_WATCH))
-               screen_connector_toolkit_evas_remove(__toolkit);
-       ops.added_cb = __screen_connector_toolkit_evas_added_cb;
-       ops.removed_cb = __screen_connector_toolkit_evas_removed_cb;
-       ops.updated_cb = __screen_connector_toolkit_evas_updated_cb;
-       __toolkit = screen_connector_toolkit_evas_add(&ops,
-                       (char *)app_id,
-                       SCREEN_CONNECTOR_SCREEEN_TYPE_WATCH, NULL);
-
        app_control_to_bundle(*app_control, &b);
        if (b) {
                if (!viewer_appid)
@@ -501,13 +494,6 @@ API int watch_manager_get_app_control(const char *app_id, app_control_h *app_con
                bundle_add_str(b, AUL_K_WIDGET_VIEWER, viewer_appid);
        }
 
-       if (__watch_appid)
-               free(__watch_appid);
-
-       __watch_appid = strdup(app_id);
-       if (__watch_appid == NULL)
-               _E("Out of memory");
-
        return 0;
 }
 
@@ -531,6 +517,8 @@ API int watch_manager_fini()
                __conn_dead_signal = NULL;
        }
 
+       __ignore_launch_signal();
+
        return 0;
 }
 
@@ -898,3 +886,75 @@ API int watch_manager_remove_dead_signal_listener(watch_dead_signal_cb cb)
        _E("wrong argument");
        return -1;
 }
+
+static int __launch_signal_handler(const char *endpoint,
+               aul_app_com_result_e res, bundle *envelope, void *user_data)
+{
+       char *appid = NULL;
+       char *viewer = NULL;
+       char *pid_str = NULL;
+       screen_connector_toolkit_evas_ops ops;
+       bool exist;
+
+       bundle_get_str(envelope, AUL_K_WIDGET_VIEWER, &viewer);
+       if (viewer == NULL)
+               return -1;
+
+       if (strcmp(viewer, viewer_appid) != 0)
+               return 0;
+
+       bundle_get_str(envelope, AUL_K_APPID, &appid);
+       if (appid == NULL)
+               return -1;
+
+       bundle_get_str(envelope, AUL_K_PID, &pid_str);
+
+       _D("cur appid(%s), new appid(%s), pid(%s)",
+                       __watch_appid, appid, pid_str);
+
+       exist = screen_connector_toolkit_is_exist(appid,
+                       SCREEN_CONNECTOR_SCREEEN_TYPE_WATCH);
+       if (exist)
+               screen_connector_toolkit_evas_remove(__toolkit);
+
+       ops.added_cb = __screen_connector_toolkit_evas_added_cb;
+       ops.removed_cb = __screen_connector_toolkit_evas_removed_cb;
+       ops.updated_cb = __screen_connector_toolkit_evas_updated_cb;
+       __toolkit = screen_connector_toolkit_evas_add(&ops, appid,
+                       SCREEN_CONNECTOR_SCREEEN_TYPE_WATCH, NULL);
+
+       if (__watch_appid)
+               free(__watch_appid);
+
+       __watch_appid = strdup(appid);
+       if (__watch_appid == NULL)
+               _E("Out of memory");
+
+       return 0;
+}
+
+static int __listen_launch_signal(void)
+{
+       int r;
+
+       if (__conn_launch_signal)
+               return 0;
+
+       r = aul_app_com_create("watch.launch", NULL, __launch_signal_handler,
+                       NULL, &__conn_launch_signal);
+       if (r < 0) {
+               _E("Failed to listen watch.launch signal");
+               return -1;
+       }
+
+       return 0;
+}
+
+static void __ignore_launch_signal(void)
+{
+       if (!__conn_launch_signal)
+               return;
+
+       aul_app_com_leave(__conn_launch_signal);
+       __conn_launch_signal = NULL;
+}