+ switch (status) {
+ case WIDGET_INSTANCE_EVENT_CREATE:
+ lifecycle = WIDGET_LIFE_CYCLE_EVENT_CREATE;
+ break;
+ case WIDGET_INSTANCE_EVENT_DESTROY:
+ lifecycle = WIDGET_LIFE_CYCLE_EVENT_DESTROY;
+ break;
+ case WIDGET_INSTANCE_EVENT_PAUSE:
+ lifecycle = WIDGET_LIFE_CYCLE_EVENT_PAUSE;
+ break;
+ case WIDGET_INSTANCE_EVENT_RESUME:
+ lifecycle = WIDGET_LIFE_CYCLE_EVENT_RESUME;
+ break;
+ }
+
+ if (lifecycle > -1)
+ __send_lifecycle_event(class_id, instance_id, lifecycle);
+
+ bundle_free(b);
+ if (raw)
+ free(raw);
+
+ return 0;
+}
+
+static int __instance_resume(widget_class_h handle, const char *id, int send_update)
+{
+ widget_context_s *wc = __find_context_by_id(id);
+ int ret;
+
+ if (!wc) {
+ _E("context not found: %s", id); /* LCOV_EXCL_LINE */
+ return -1; /* LCOV_EXCL_LINE */
+ }
+
+ if (wc->state == WC_RUNNING) {
+ _D("%s is already in running state", id); /* LCOV_EXCL_LINE */
+ return 0; /* LCOV_EXCL_LINE */
+ }
+
+ if (wc->state == WC_TERMINATED) {
+ _D("%s is in terminated state", id); /* LCOV_EXCL_LINE */
+ return 0; /* LCOV_EXCL_LINE */
+ }
+
+ if (handle->ops.resume)
+ handle->ops.resume(wc, handle->user_data);
+
+ wc->state = WC_RUNNING;
+ _D("%s is resumed", id);
+ if (send_update) {
+ ret = __send_update_status(handle->classid, wc->id,
+ WIDGET_INSTANCE_EVENT_RESUME, NULL);
+ if (!fg_signal) {
+ _D("Send fg signal to resourceD");
+ aul_send_app_status_change_signal(getpid(),
+ appid,
+ package_id,
+ STATUS_FOREGROUND,
+ APP_TYPE_WIDGET);
+ fg_signal = true;
+ }
+ } else {
+ ret = 0;
+ }
+
+ return ret;
+}
+
+static int __instance_pause(widget_class_h handle, const char *id, int send_update)
+{
+ widget_context_s *wc = __find_context_by_id(id);
+ int ret;
+
+ if (!wc) {
+ _E("context not found: %s", id); /* LCOV_EXCL_LINE */
+ return -1; /* LCOV_EXCL_LINE */
+ }
+
+ if (wc->state == WC_PAUSED) {
+ _D("%s is already in paused state", id); /* LCOV_EXCL_LINE */
+ return 0; /* LCOV_EXCL_LINE */
+ }
+
+ if (wc->state == WC_TERMINATED) {
+ _D("%s is in terminated state", id); /* LCOV_EXCL_LINE */
+ return 0; /* LCOV_EXCL_LINE */
+ }
+
+ if (handle->ops.pause)
+ handle->ops.pause(wc, handle->user_data);
+
+ wc->state = WC_PAUSED;
+ _D("%s is paused", id);
+ if (send_update) {
+ ret = __send_update_status(handle->classid, wc->id,
+ WIDGET_INSTANCE_EVENT_PAUSE, NULL);
+ wc = __find_context_by_state(WC_RUNNING);
+ if (!wc && fg_signal) {
+ _D("Send bg signal to resourceD");
+ aul_send_app_status_change_signal(getpid(),
+ appid,
+ package_id,
+ STATUS_BACKGROUND,
+ APP_TYPE_WIDGET);
+ fg_signal = false;
+ }
+ } else {
+ ret = 0;
+ }
+
+ return ret;
+}
+
+static int __instance_resize(widget_class_h handle, const char *id, int w, int h)
+{
+ widget_context_s *wc = __find_context_by_id(id);
+ int ret;
+
+ if (!wc) {
+ _E("context not found: %s", id); /* LCOV_EXCL_LINE */
+ return -1; /* LCOV_EXCL_LINE */
+ }
+
+ if (handle->ops.resize)
+ handle->ops.resize(wc, w, h, handle->user_data);
+
+ _D("%s is resized to %dx%d", id, w, h);
+ ret = __send_update_status(handle->classid, wc->id,
+ WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL);
+
+ return ret;
+}
+
+/* LCOV_EXCL_START */
+static int __instance_update_all(widget_class_h handle, int force, const char *content)
+{
+ widget_context_s *wc;
+ int ret = 0;
+ bundle *b = NULL;
+ GList *context = _widget_app_get_contexts();
+
+ if (content)
+ b = bundle_decode((const bundle_raw *)content, strlen(content));
+
+ if (handle->ops.update) {
+ while (context) {
+ wc = (widget_context_s *)context->data;
+ handle->ops.update(wc, b, force, handle->user_data);
+ ret = __send_update_status(handle->classid, wc->id,
+ WIDGET_INSTANCE_EVENT_UPDATE, NULL);
+ _D("updated:%s", wc->id);
+ context = context->next;
+ }
+ }
+
+ if (b)
+ bundle_free(b);
+
+ return ret;
+}
+/* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
+static int __instance_update(widget_class_h handle, const char *id, int force, const char *content)
+{
+ widget_context_s *wc = __find_context_by_id(id);
+ int ret = 0;
+ bundle *b = NULL;
+ if (!wc) {
+ _E("context not found: %s", id);
+ return -1;
+ }
+
+ if (content)
+ b = bundle_decode((const bundle_raw *)content, strlen(content));
+
+ if (handle->ops.update) {
+ handle->ops.update(wc, b, force, handle->user_data);
+ ret = __send_update_status(handle->classid, wc->id,
+ WIDGET_INSTANCE_EVENT_UPDATE, NULL);
+ _D("updated:%s", id);
+ }
+
+ if (b)