2 * Copyright 2015 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "widget_instance.h"
20 #include <uuid/uuid.h>
27 #include <sys/types.h>
31 #include <aul_app_com.h>
32 #include <aul_widget.h>
33 #include <aul_debug_info.h>
34 #include <widget_service.h>
35 #include <widget_service_internal.h>
36 #include <bundle_internal.h>
37 #include "widget_errno.h"
39 #define USER_UID_MIN 5000
40 #define MAX_INSTANCE_ID_LEN 256
41 #define WIDGET_CLASS_DELIMITER "@"
42 #define QUERY_MAX_LEN 8192
44 #define DLP_K_DEBUG_ARG "__DLP_DEBUG_ARG__"
45 #define DLP_K_GDBSERVER_PATH "__DLP_GDBSERVER_PATH__"
46 #define DLP_K_VALGRIND_ARG "__DLP_VALGRIND_ARG__"
47 #define DLP_K_VALGRIND_PATH "__DLP_VALGRIND_PATH__"
48 #define SDK_DEBUG "DEBUG"
49 #define SDK_VALGRIND "VALGRIND"
51 #ifndef TIZEN_PATH_MAX
52 #define TIZEN_PATH_MAX 1024
56 WIDGET_INSTANCE_CREATED,
57 WIDGET_INSTANCE_RUNNING,
58 WIDGET_INSTANCE_TERMINATED,
59 WIDGET_INSTANCE_DELETED
62 struct _widget_instance {
87 static GList *_widget_instances = NULL;
88 static GList *_widget_apps = NULL;
90 static char *viewer_appid = NULL;
91 static aul_app_com_connection_h conn_viewer;
92 static aul_app_com_connection_h conn_status;
94 static GHashTable *lifecycle_tbl;
95 static int is_status_handler_connected;
97 static struct _sdk_util sdk_util;
99 static char *package_id;
101 struct lifecycle_local_s {
103 widget_instance_event_cb cb;
107 static GList *event_cbs;
109 widget_instance_event_cb cb;
113 static int __fault_handler(int pid);
115 extern int widget_service_get_update_period(const char *widget_id, double *period);
117 static struct _widget_instance *__pick_instance(const char *instance_id)
119 GList *instances = _widget_instances;
120 struct _widget_instance *instance = NULL;
123 instance = (struct _widget_instance *)instances->data;
124 if (instance && g_strcmp0(instance_id, instance->id) == 0)
127 instances = instances->next;
133 static struct widget_app *__pick_app(const char *widget_id)
135 GList *apps = _widget_apps;
136 struct widget_app *app = NULL;
140 if (app && app->widget_id && g_strcmp0(widget_id, app->widget_id) == 0)
149 static struct widget_app *__add_app(const char *widget_id, const char *viewer_id)
151 struct widget_app *app = NULL;
153 app = (struct widget_app *)malloc(sizeof(struct widget_app));
159 app->viewer_id = strdup(viewer_id);
160 app->widget_id = strdup(widget_id);
161 app->instances = NULL;
163 _widget_apps = g_list_append(_widget_apps, app);
168 static char *__create_instance_id(const char *widget_id)
171 char instance_id[MAX_INSTANCE_ID_LEN];
173 struct widget_app *app = NULL;
175 if (widget_id == NULL)
178 app = __pick_app(widget_id);
181 app = __add_app(widget_id, viewer_appid);
187 uuid_unparse(u, uuid);
189 snprintf(instance_id, MAX_INSTANCE_ID_LEN, "%s:%s", uuid, widget_id);
191 _D("new instance: %s", instance_id);
193 return strdup(instance_id);
196 static struct _widget_instance *__add_instance(const char *id, const char *widget_id)
198 struct _widget_instance *instance = NULL;
199 struct widget_app *app = NULL;
202 if (widget_service_get_update_period(widget_id, &period) != WIDGET_ERROR_NONE) {
203 _E("Can't get update-period");
207 instance = (struct _widget_instance *)malloc(sizeof(struct _widget_instance));
208 if (instance == NULL) {
213 instance->status = WIDGET_INSTANCE_CREATED;
214 instance->id = strdup(id);
216 instance->stored = 0;
217 instance->widget_id = strdup(widget_id);
218 instance->content_info = NULL;
220 instance->period = period;
223 _widget_instances = g_list_append(_widget_instances, instance);
225 app = __pick_app(widget_id);
227 app = __add_app(widget_id, viewer_appid);
230 app->instances = g_list_append(app->instances, instance);
232 _E("failed to find app: %s", widget_id);
237 static void __remove_instance(struct _widget_instance *instance)
239 struct widget_app *app = NULL;
241 if (instance == NULL) {
242 _E("invalid argument");
246 if (instance->widget_id)
247 app = __pick_app(instance->widget_id);
250 app->instances = g_list_remove(app->instances, instance);
251 if (app->instances == NULL) {
252 _widget_apps = g_list_remove(_widget_apps, app);
254 free(app->widget_id);
256 free(app->viewer_id);
261 _widget_instances = g_list_remove(_widget_instances, instance);
263 if (instance->widget_id) {
264 free(instance->widget_id);
265 instance->widget_id = NULL;
273 if (instance->content_info) {
274 free(instance->content_info);
275 instance->content_info = NULL;
281 EAPI int widget_instance_create(const char *widget_id, char **instance_id)
284 struct _widget_instance *instance = NULL;
286 _D("create: %s", widget_id);
288 id = __create_instance_id(widget_id);
290 _E("failed to get instance id for %s", widget_id);
294 instance = __add_instance(id, widget_id);
299 *instance_id = instance->id;
309 static int __convert_aul_error(int res)
314 case AUL_R_EREJECTED:
316 ret = WIDGET_ERROR_NOT_EXIST;
319 ret = WIDGET_ERROR_PERMISSION_DENIED;
322 ret = WIDGET_ERROR_TIMED_OUT;
324 case AUL_R_ECANCELED:
325 ret = WIDGET_ERROR_CANCELED;
328 ret = WIDGET_ERROR_INVALID_PARAMETER;
331 ret = WIDGET_ERROR_FAULT;
338 static int __launch(const char *widget_id, const char *instance_id, bundle *extra)
342 const char *classid = widget_id;
345 appid = g_strstr_len(widget_id, strlen(widget_id), WIDGET_CLASS_DELIMITER) + 1;
346 if (appid != (const char *)1) { /* move pointer next to delimiter */
347 if (appid > widget_id + (sizeof(char) * strlen(widget_id)))
348 return -1; /* bad ptr */
357 bundle_add_str(b, AUL_K_WIDGET_INSTANCE_ID, instance_id);
359 bundle_add_str(b, WIDGET_K_CLASS, classid);
360 bundle_add_str(b, AUL_K_WIDGET_VIEWER, viewer_appid);
362 aul_svc_set_operation(b, AUL_SVC_OPERATION_LAUNCH_WIDGET);
364 ret = aul_launch_app_async(appid, b);
366 ret = __convert_aul_error(ret);
376 static int __send_aul_cmd(widget_instance_h instance, const char *command, bundle *extra)
381 if (!instance || !command) {
382 _E("inavlid parameter");
394 bundle_del(b, WIDGET_K_OPERATION);
395 bundle_add_str(b, WIDGET_K_OPERATION, command);
397 ret = __launch(instance->widget_id, instance->id, b);
405 _E("failed to launch %s (%s:%d)", instance->id, command, ret);
407 } else if (ret != instance->pid) {
408 _E("pid has been changed. new process detected. %s (%d to %d)",
409 instance->id, instance->pid, ret);
416 static int __set_width(bundle *content_info, int w)
419 if (content_info == NULL || w < 0)
422 snprintf(wbuf, 11, "%d", w);
423 bundle_add_str(content_info, WIDGET_K_WIDTH, wbuf);
428 static int __set_height(bundle *content_info, int h)
431 if (content_info == NULL || h < 0)
434 snprintf(hbuf, 11, "%d", h);
435 bundle_add_str(content_info, WIDGET_K_HEIGHT, hbuf);
440 EAPI int widget_instance_launch(const char *instance_id, char *content_info, int w, int h)
445 widget_instance_h instance;
447 _D("launch: %s", instance_id);
449 if (instance_id == NULL) {
450 _E("wrong arguments");
454 instance = __pick_instance(instance_id);
456 if (instance == NULL) {
457 _E("unknown instance: %s", instance_id);
472 snprintf(pid_buf, sizeof(pid_buf), "%d", getpid());
473 bundle_add_str(b, WIDGET_K_CALLER, pid_buf);
474 bundle_add_str(b, WIDGET_K_OPERATION, "create");
475 bundle_add_byte(b, WIDGET_K_PERIOD, &(instance->period), sizeof(double));
478 bundle_add_str(b, WIDGET_K_CONTENT_INFO, content_info);
479 instance->content_info = strdup(content_info);
485 ret = __launch(instance->widget_id, instance_id, b);
486 aul_widget_write_log(LOG_TAG, "[%s:%d] %s, launched : %d",
487 __FUNCTION__, __LINE__, instance_id, ret);
497 EAPI int widget_instance_terminate(const char *instance_id)
500 struct _widget_instance *instance;
502 if (instance_id == NULL)
505 instance = __pick_instance(instance_id);
507 _E("illegal operation: termiante (instance not yet initialized: %s)", instance_id);
511 ret = __send_aul_cmd(instance, "terminate", NULL);
516 EAPI int widget_instance_destroy(const char *instance_id)
519 struct _widget_instance *instance;
521 if (instance_id == NULL)
524 instance = __pick_instance(instance_id);
526 _E("illegal operation: destroy (instance not yet initialized: %s)", instance_id);
530 if (instance->pid > 0) {
531 ret = __send_aul_cmd(instance, "destroy", NULL);
532 } else { /* uninitialized */
533 __remove_instance(instance);
539 EAPI int widget_instance_resume(const char *instance_id)
542 struct _widget_instance *instance;
544 if (instance_id == NULL)
547 instance = __pick_instance(instance_id);
549 _E("illegal operation: resume (instance not yet initialized: %s)", instance_id);
553 ret = __send_aul_cmd(instance, "resume", NULL);
558 EAPI int widget_instance_pause(const char *instance_id)
561 struct _widget_instance *instance;
563 if (instance_id == NULL)
566 instance = __pick_instance(instance_id);
568 _E("illegal operation: pause (instance not yet initialized: %s)", instance_id);
572 ret = __send_aul_cmd(instance, "pause", NULL);
577 EAPI int widget_instance_resize(const char *instance_id, int w, int h)
581 struct _widget_instance *instance;
583 if (instance_id == NULL)
586 instance = __pick_instance(instance_id);
588 _E("illegal operation: resize (instance not yet initialized: %s)", instance_id);
599 ret = __send_aul_cmd(instance, "resize", b);
606 EAPI int widget_instance_foreach(const char *widget_id, widget_instance_foreach_cb cb, void *data)
608 GList *apps = _widget_apps;
609 GList *instances = NULL;
610 struct widget_app *app = NULL;
611 struct _widget_instance *instance = NULL;
613 if (widget_id == NULL || cb == NULL)
618 if (app && g_strcmp0(app->widget_id, widget_id) == 0) {
619 instances = app->instances;
621 instance = instances->data;
622 if (instance && cb(instance, data) < 0)
625 instances = instances->next;
634 static void __notify_event(int event, const char *widget_id, const char *instance_id)
636 struct event_cb_s *cb_info;
637 GList *iter = event_cbs;
640 cb_info = (struct event_cb_s *)iter->data;
641 if (cb_info && cb_info->cb)
642 cb_info->cb(widget_id, instance_id, event, cb_info->data);
648 static int __check_valid_sender(char *widget_id, int pid)
650 struct widget_app *app = NULL;
651 widget_instance_h instance;
654 app = __pick_app(widget_id);
656 head = app->instances;
658 instance = (widget_instance_h)head->data;
659 if (instance->pid == -1 || instance->pid == pid)
661 _E("instance->pid (%d), pid (%d)", instance->pid, pid);
667 /* LCOV_EXCL_START */
668 static int __check_valid_sender_v2(const char *sender_pkgid)
670 char pkgid[256] = {0, };
673 if (sender_pkgid == NULL)
676 if (package_id == NULL) {
677 ret = aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid));
678 if (ret != AUL_R_OK) {
679 _E("Failed to get pkgid");
683 package_id = strdup(pkgid);
684 if (package_id == NULL) {
690 _D("sender_pkgid: %s, pkgid: %s", sender_pkgid, package_id);
691 if (strcmp(package_id, sender_pkgid) == 0)
698 static int __status_handler(const char *endpoint, aul_app_com_result_e e, bundle *envelope, void *user_data)
700 char *widget_id = NULL;
701 char *instance_id = NULL;
702 char *sender_pkgid = NULL;
703 char *is_faulted = NULL;
705 size_t status_sz = 0;
706 struct lifecycle_local_s *cb_info;
707 char *sender_pid_str;
710 bundle_get_str(envelope, AUL_K_WIDGET_ID, &widget_id);
711 bundle_get_str(envelope, AUL_K_WIDGET_INSTANCE_ID, &instance_id);
712 bundle_get_byte(envelope, AUL_K_WIDGET_STATUS, (void **)&status, &status_sz);
713 bundle_get_str(envelope, AUL_K_COM_SENDER_PID, &sender_pid_str);
714 bundle_get_str(envelope, AUL_K_PKGID, &sender_pkgid);
715 bundle_get_str(envelope, AUL_K_IS_FAULT, &is_faulted);
717 if (widget_id == NULL || status == NULL) {
718 _E("undefined class or instance %s of %s", instance_id, widget_id);
720 _E("status: %d", *status);
725 sender_pid = atoi(sender_pid_str);
726 if (__check_valid_sender(widget_id, sender_pid) == -1) {
727 bundle_get_str(envelope, AUL_K_PKGID, &sender_pkgid);
728 LOGW("It's not my widget(%s), let's check package", widget_id);
729 if (__check_valid_sender_v2(sender_pkgid) < 0) {
730 LOGW("My package do not have widget_id %s", widget_id);
735 if (*status == AUL_WIDGET_LIFE_CYCLE_EVENT_APP_DEAD &&
736 is_faulted && !strcmp(is_faulted, "true")) {
737 LOGW("handle dead widget instances, %s", instance_id);
738 aul_widget_write_log(LOG_TAG, "[%s:%d] %s sender(%d)",
739 __FUNCTION__, __LINE__, instance_id, sender_pid);
740 __fault_handler(sender_pid);
743 cb_info = (struct lifecycle_local_s *)g_hash_table_lookup(lifecycle_tbl, "NULL");
745 cb_info->cb(widget_id, instance_id, *status, cb_info->data);
747 cb_info = (struct lifecycle_local_s *)g_hash_table_lookup(lifecycle_tbl, widget_id);
749 cb_info->cb(widget_id, instance_id, *status, cb_info->data);
754 static int __connect_status_handler()
756 if (is_status_handler_connected)
759 if (aul_app_com_create("widget.status", NULL, __status_handler, NULL, &conn_status) < 0) {
760 _E("failed to create status");
764 is_status_handler_connected = 1;
769 static int __widget_instance_handler(int status, char *widget_id,
770 char *instance_id, char *content_info, int err)
773 struct _widget_instance *instance;
775 if (instance_id == NULL) {
776 _E("undefined class or instance of %s", widget_id);
780 _D("update status %s on %d", instance_id, status);
782 instance = __pick_instance(instance_id);
784 if (instance == NULL) {
785 _E("undefined instance id: %s of %s", instance_id, widget_id);
790 case WIDGET_INSTANCE_EVENT_CREATE:
791 instance->status = WIDGET_INSTANCE_RUNNING;
793 case WIDGET_INSTANCE_EVENT_TERMINATE:
794 instance->status = WIDGET_INSTANCE_TERMINATED;
796 case WIDGET_INSTANCE_EVENT_DESTROY:
797 instance->status = WIDGET_INSTANCE_DELETED;
799 case WIDGET_INSTANCE_EVENT_PAUSE:
801 case WIDGET_INSTANCE_EVENT_RESUME:
803 case WIDGET_INSTANCE_EVENT_UPDATE:
805 case WIDGET_INSTANCE_EVENT_EXTRA_UPDATED:
807 if (instance->content_info)
808 free(instance->content_info);
810 instance->content_info = strdup(content_info);
813 case WIDGET_INSTANCE_EVENT_FAULT:
815 case WIDGET_INSTANCE_EVENT_CREATE_ABORTED:
820 _E("unknown status: %d", status);
824 __notify_event(status, widget_id, instance_id);
826 if (instance->status == WIDGET_INSTANCE_DELETED)
827 widget_instance_unref(instance);
832 static int __widget_handler(const char *viewer_id, aul_app_com_result_e e, bundle *envelope, void *user_data)
834 char *widget_id = NULL;
835 char *instance_id = NULL;
836 char *error_code = NULL;
838 size_t status_sz = 0;
839 char *content_info = NULL;
840 char *sender_pid_str = NULL;
845 bundle_get_str(envelope, AUL_K_WIDGET_ID, &widget_id);
846 bundle_get_byte(envelope, AUL_K_WIDGET_STATUS, (void **)&status, &status_sz);
848 if (widget_id == NULL) {
849 LOGE("undefined widget_id");
853 if (*status == WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST) {
854 LOGW("WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST notify");
855 bundle_get_str(envelope, AUL_K_COM_SENDER_PID, &sender_pid_str);
856 if (sender_pid_str == NULL) {
857 LOGE("Failed to get sender pid of %s", widget_id);
860 sender_pid = atoi(sender_pid_str);
861 ret = __check_valid_sender(widget_id, sender_pid);
863 __notify_event(*status, widget_id, "");
865 bundle_get_str(envelope, AUL_K_WIDGET_INSTANCE_ID, &instance_id);
866 bundle_get_str(envelope, WIDGET_K_CONTENT_INFO, &content_info);
867 bundle_get_str(envelope, AUL_K_WIDGET_ERROR_CODE, &error_code);
869 err = atoi(error_code);
871 __widget_instance_handler(*status, widget_id, instance_id,
878 /* LCOV_EXCL_START */
879 static int __fault_handler(int pid)
882 struct _widget_instance *instance;
884 iter = _widget_instances;
887 instance = (struct _widget_instance *)iter->data;
888 if (instance && instance->pid == pid) {
890 instance->status = WIDGET_INSTANCE_TERMINATED;
891 __notify_event(WIDGET_INSTANCE_EVENT_FAULT, instance->widget_id, instance->id);
900 EAPI int widget_instance_init(const char *viewer_id)
902 if (viewer_id == NULL)
905 viewer_appid = strdup(viewer_id);
907 __connect_status_handler();
909 _D("widget_instance_init %s", viewer_id);
910 if (aul_app_com_create(viewer_id, NULL, __widget_handler, NULL, &conn_viewer) < 0) {
911 _E("failed to create app com endpoint");
918 EAPI int widget_instance_fini()
920 if (sdk_util.initialized) {
921 aul_debug_info_fini();
922 sdk_util.initialized = false;
926 bundle_free(sdk_util.b);
931 g_hash_table_destroy(lifecycle_tbl);
932 lifecycle_tbl = NULL;
936 if (aul_app_com_leave(conn_viewer) < 0)
937 _E("failed to leave app com endpoint viewer");
942 if (aul_app_com_leave(conn_status) < 0)
943 _E("failed to leave app com endpoint status");
960 EAPI int widget_instance_get_error_code(widget_instance_h instance, int *err)
962 if (instance == NULL || err == NULL)
965 *err = instance->err;
970 EAPI int widget_instance_get_id(widget_instance_h instance, char **id)
972 if (instance == NULL || id == NULL)
975 *id = (char *)instance->id;
979 EAPI int widget_instance_get_content(widget_instance_h instance, char **content)
981 if (instance == NULL || content == NULL)
984 *content = instance->content_info;
988 EAPI int widget_instance_get_width(widget_instance_h instance, int *w)
990 if (instance == NULL || w == NULL)
997 EAPI int widget_instance_get_height(widget_instance_h instance, int *h)
999 if (instance == NULL || h == NULL)
1006 EAPI int widget_instance_get_period(widget_instance_h instance, double *period)
1008 if (instance == NULL || period == NULL)
1011 *period = instance->period;
1015 EAPI int widget_instance_change_period(const char *widget_id, const char *instance_id, double period)
1020 b = bundle_create();
1022 _E("out of memory"); /* LCOV_EXCL_LINE */
1023 return -1; /* LCOV_EXCL_LINE */
1026 bundle_add_byte(b, WIDGET_K_PERIOD, &period, sizeof(double));
1027 bundle_add_str(b, WIDGET_K_OPERATION, "period");
1028 ret = aul_widget_instance_update(widget_id, instance_id, b);
1034 EAPI int widget_instance_trigger_update(widget_instance_h instance, const char *content_info, int force)
1039 return widget_instance_trigger_update_v2(instance->widget_id, instance->id, content_info, force);
1042 EAPI int widget_instance_trigger_update_v2(const char *widget_id,
1043 const char *instance_id, const char *content_info, int force)
1049 kb = bundle_create();
1051 _E("out of memory"); /* LCOV_EXCL_LINE */
1052 return -1; /* LCOV_EXCL_LINE */
1055 bundle_add_str(kb, WIDGET_K_OPERATION, "update");
1058 bundle_add_str(kb, WIDGET_K_FORCE, "true");
1061 bundle_add_str(kb, WIDGET_K_CONTENT_INFO, content_info);
1063 ret = aul_widget_instance_update(widget_id, instance_id, kb);
1068 return WIDGET_ERROR_NONE;
1072 ret = WIDGET_ERROR_NOT_EXIST;
1075 ret = WIDGET_ERROR_PERMISSION_DENIED;
1078 ret = WIDGET_ERROR_INVALID_PARAMETER;
1080 case AUL_R_ECANCELED:
1081 ret = WIDGET_ERROR_CANCELED;
1084 ret = WIDGET_ERROR_FAULT;
1090 EAPI widget_instance_h widget_instance_get_instance(const char *widget_id, const char *instance_id)
1092 widget_instance_h instance;
1094 if (widget_id == NULL || instance_id == NULL)
1097 if (_widget_apps && _widget_instances) {
1098 instance = __pick_instance(instance_id);
1099 return widget_instance_ref(instance);
1105 EAPI int widget_instance_get_instance_list(const char *widget_id, widget_instance_list_cb cb, void *data)
1107 widget_instance_h instance;
1108 struct widget_app *app;
1111 if (widget_id == NULL)
1115 app = __pick_app(widget_id);
1120 head = app->instances;
1123 instance = (widget_instance_h)head->data;
1124 if (cb(instance->widget_id, instance->id, data) != 0)
1134 EAPI void widget_instance_unref(widget_instance_h instance)
1136 if (instance == NULL)
1141 if (instance->ref > -1)
1144 __remove_instance(instance);
1147 EAPI widget_instance_h widget_instance_ref(widget_instance_h instance)
1155 EAPI int widget_instance_listen_event(widget_instance_event_cb cb, void *data)
1157 struct event_cb_s *cb_info;
1159 cb_info = (struct event_cb_s *)malloc(sizeof(struct event_cb_s));
1161 _E("out of memory"); /* LCOV_EXCL_LINE */
1162 return -1; /* LCOV_EXCL_LINE */
1166 cb_info->data = data;
1168 event_cbs = g_list_append(event_cbs, cb_info);
1170 _E("out of memory"); /* LCOV_EXCL_LINE */
1171 return -1; /* LCOV_EXCL_LINE */
1177 EAPI int widget_instance_unlisten_event(widget_instance_event_cb cb)
1179 struct event_cb_s *cb_info;
1180 GList *iter = event_cbs;
1183 _E("invalid parameter");
1188 cb_info = (struct event_cb_s *)iter->data;
1189 if (cb_info && cb_info->cb == cb) {
1190 event_cbs = g_list_remove_link(event_cbs, iter);
1198 _E("wrong argument");
1202 static void __destroy_lifecycle_local(gpointer data)
1204 struct lifecycle_local_s *cb_info = (struct lifecycle_local_s *)data;
1206 if (cb_info == NULL)
1209 if (cb_info->widget_id)
1210 free(cb_info->widget_id);
1214 /* within package only */
1215 EAPI int widget_instance_listen_status(const char *widget_id, widget_instance_event_cb cb, void *data)
1217 struct lifecycle_local_s *cb_info;
1220 widget_id = "NULL"; /* listen all widget */
1222 cb_info = (struct lifecycle_local_s *)malloc(sizeof(struct lifecycle_local_s));
1224 _E("out of memory"); /* LCOV_EXCL_LINE */
1225 return -1; /* LCOV_EXCL_LINE */
1228 cb_info->widget_id = strdup(widget_id);
1230 cb_info->data = data;
1231 if (!lifecycle_tbl) {
1232 lifecycle_tbl = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1233 __destroy_lifecycle_local);
1234 if (!lifecycle_tbl) {
1240 g_hash_table_insert(lifecycle_tbl, cb_info->widget_id, cb_info);
1242 __connect_status_handler();
1247 EAPI int widget_instance_unlisten_status(const char *widget_id)
1249 struct lifecycle_local_s *cb_info;
1254 cb_info = (struct lifecycle_local_s *)g_hash_table_lookup(lifecycle_tbl, widget_id);
1258 g_hash_table_remove(lifecycle_tbl, widget_id);
1263 EAPI int widget_service_set_sdk_util(bundle *data)
1268 val = bundle_get_val(data, AUL_K_SDK);
1272 if (!sdk_util.initialized) {
1273 r = aul_debug_info_init();
1274 if (r != AUL_R_OK) {
1275 _E("Failed to initialize debug info");
1281 bundle_free(sdk_util.b);
1283 sdk_util.b = bundle_create();
1284 if (sdk_util.b == NULL) {
1285 _E("Failed to create bundle");
1289 r = aul_debug_info_set(data, sdk_util.b);
1290 if (r != AUL_R_OK) {
1291 _E("Failed to set debug info");
1292 bundle_free(sdk_util.b);