Share watch viewer visibility to AMD 36/137136/4
authorHyunho Kang <hhstark.kang@samsung.com>
Tue, 4 Jul 2017 12:22:03 +0000 (21:22 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Thu, 6 Jul 2017 02:34:57 +0000 (02:34 +0000)
Requires:
 - https://review.tizen.org/gerrit/#/c/137133/ (aul-1)
 - https://review.tizen.org/gerrit/#/c/137134/ (amd)
 - https://review.tizen.org/gerrit/#/c/137136/ (widget-viewer)
 - https://review.tizen.org/gerrit/#/c/137437/ (appcore-watch)

Change-Id: I863ad830c7a43c0463d39560b188ad5b3a1d7507
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
watch-control/include/watch_control.h
watch-control/src/control.c

index 22007fe97b5170dced20dcb58c6ca22aad3743c4..735a2dcdbc6c3627aebed2f9e07f939c5b2bb4cc 100644 (file)
@@ -33,13 +33,6 @@ typedef enum {
 #define WATCH_SMART_SIGNAL_ADDED "watch,added"
 #define WATCH_SMART_SIGNAL_REMOVED "watch,removed"
 #define WATCH_SMART_SIGNAL_UPDATED "watch,updated"
-#define WATCH_CONTROL_STATE "watch,state"
-
-typedef enum {
-       WATCH_CONTROL_UNKNOWN,
-       WATCH_CONTROL_PAUSE,
-       WATCH_CONTROL_RESUME
-} watch_control_event;
 
 typedef void (*watch_dead_signal_cb)(const char *appid, int pid, bool is_faulted, void *data);
 extern int watch_manager_init(Evas_Object *win);
index 62b4acb0681f5908d2b732c471b8f06d602cafb0..3da4c273d3b33741ba95318a74a1dd99aa726a3c 100644 (file)
 #include <tbm_surface.h>
 #include <pkgmgr-info.h>
 #include <aul_app_com.h>
+#include <aul.h>
+#include <aul_screen_connector.h>
 
 #define API __attribute__((visibility("default")))
 
 #undef LOG_TAG
 #define LOG_TAG "WATCH_CONTROL"
 
-#ifdef LOGE
+#ifndef _E
 #define _E LOGE
 #endif
 
-#ifdef LOGD
+#ifndef _D
 #define _D LOGD
 #endif
 
+#ifndef _W
+#define _W LOGW
+#endif
+
 #define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle"
 #define METADATA_SETUP_APPID   "http://tizen.org/metadata/watch/setup-appid"
 
@@ -56,6 +62,7 @@ static screen_connector_toolkit_evas_h __toolkit;
 
 static Evas_Object *__win;
 static char *__watch_appid;
+static char *__watch_instance_id;
 static char *viewer_appid;
 static int __is_dead_signal_connected;
 static aul_app_com_connection_h __conn_dead_signal;
@@ -144,6 +151,12 @@ static void __screen_connector_toolkit_evas_added_cb(const char *appid, const ch
        _D("w: %d, h: %d, x: %d y: %d", w, h, x, y);
        evas_object_smart_callback_call(__win, WATCH_SMART_SIGNAL_ADDED, image);
        evas_object_data_set(__win, "tbm,watch", image);
+
+       if (__watch_instance_id)
+               free(__watch_instance_id);
+       __watch_instance_id = strdup(instance_id);
+       if (__watch_instance_id == NULL)
+               _W("Out of memory");
 }
 
 static void __screen_connector_toolkit_evas_removed_cb(const char *appid, const char *instance_id, int pid,
@@ -164,30 +177,47 @@ API int watch_manager_set_resource_id(int resource_id)
 {
        screen_connector_toolkit_evas_ops ops;
        screen_connector_toolkit_evas_h handle;
-       char *appid = NULL;
        int ret;
 
        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;
-       handle = screen_connector_toolkit_evas_add_by_rid(&ops, resource_id, SCREEN_CONNECTOR_SCREEEN_TYPE_WATCH, NULL);
+       handle = screen_connector_toolkit_evas_add_by_rid(&ops, resource_id,
+                       SCREEN_CONNECTOR_SCREEEN_TYPE_WATCH, NULL);
        if (handle == NULL) {
                _E("Fail screen_connector_toolkit_evas_add_by_rid");
                return -1;
        }
 
-       ret = aul_screen_connector_get_appid_by_surface_id_request(resource_id,
-               &appid);
-       if (ret == AUL_R_OK) {
-               if (__watch_appid)
-                       free(__watch_appid);
-               __watch_appid = appid;
-       } else {
-               screen_connector_toolkit_evas_remove(handle);
+       if (__watch_appid) {
+               free(__watch_appid);
+               __watch_appid = NULL;
+       }
+
+       ret = aul_screen_connector_get_appid_by_surface_id(resource_id,
+               &__watch_appid);
+       if (ret != AUL_R_OK) {
                _E("Fail to get appid of %d", resource_id);
+               screen_connector_toolkit_evas_remove(handle);
                return -1;
        }
 
+       if (__watch_instance_id) {
+               free(__watch_instance_id);
+               __watch_instance_id = NULL;
+       }
+
+       ret = aul_screen_connector_get_instance_id_by_surface_id(resource_id,
+                       &__watch_instance_id);
+       if (ret != AUL_R_OK) {
+               _E("Failed to get instance id by surface id(%d)", resource_id);
+               screen_connector_toolkit_evas_remove(handle);
+               return -1;
+       }
+
+       _D("appid(%s), instance_id(%s), rid(%d)",
+                       __watch_appid, __watch_instance_id, resource_id);
+
        return 0;
 }
 
@@ -265,6 +295,8 @@ API int watch_manager_get_app_control(const char *app_id, app_control_h *app_con
                free(__watch_appid);
 
        __watch_appid = strdup(app_id);
+       if (__watch_appid == NULL)
+               _E("Out of memory");
 
        return 0;
 }
@@ -431,29 +463,28 @@ API int watch_manager_change_auto_visibility(bool enable)
 
 static int __change_viewer_visibility(bool visible)
 {
-       int state;
-       bundle *b = bundle_create();
-
-       if (b == NULL) {
-               _E("out of memory");
-               return -1;
-       }
+       int status;
+       int r;
 
-       if (__watch_appid == NULL) {
+       if (__watch_appid == NULL || __watch_instance_id == NULL) {
                _E("watch is not added");
                return -1;
        }
 
        if (visible)
-               state = WATCH_CONTROL_RESUME;
+               status = AUL_SCREEN_STATUS_RESUME;
        else
-               state = WATCH_CONTROL_PAUSE;
+               status = AUL_SCREEN_STATUS_PAUSE;
 
-       bundle_add_byte(b, WATCH_CONTROL_STATE, &state, sizeof(int));
+       r = aul_screen_connector_update_screen_viewer_status(status,
+                       __watch_instance_id);
+       if (r < 0) {
+               _E("Failed to update screen viewer status");
+               return -1;
+       }
 
-       _D("send watch control state to %s(%d)", __watch_appid, state);
-       aul_app_com_send(__watch_appid, b);
-       bundle_free(b);
+       _D("send watch control status to %s:%s:%d",
+                       __watch_appid, __watch_instance_id, status);
 
        return 0;
 }