From 8630f836af3cad3156127b7b1a84b74d0d155dce Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Tue, 5 Jul 2016 22:52:44 +0900 Subject: Fix widget_service_trigger_update - Previously, some widget_service functions that allowed for the application in the same package with target widget application were not supported. - The patch uses aul_widget_instance_* functions to store/load widget_instance informations across the package. Change-Id: If92972d01213049f536fecb6bd4e90f6e90c5f63 Signed-off-by: Daehyeon Jung --- include/widget_instance.h | 8 +++++--- src/widget_instance.c | 39 ++++++++++++++++++++++++++++++++++----- src/widget_service.c | 43 +++++++++++++++++++++---------------------- 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/include/widget_instance.h b/include/widget_instance.h index cc4efa3..f2fb6f4 100644 --- a/include/widget_instance.h +++ b/include/widget_instance.h @@ -25,9 +25,9 @@ extern "C" { #endif -#define WIDGET_K_ID AUL_K_APPID -#define WIDGET_K_CLASS "__WIDGET_CLASS__" -#define WIDGET_K_INSTANCE "__WIDGET_INSTANCE__" +#define WIDGET_K_ID AUL_K_WIDGET_ID +#define WIDGET_K_CLASS AUL_K_WIDGET_ID +#define WIDGET_K_INSTANCE AUL_K_WIDGET_INSTANCE_ID #define WIDGET_K_STATUS "__WIDGET_STATUS__" #define WIDGET_K_ENDPOINT "__WIDGET_ENDPOINT__" @@ -87,6 +87,8 @@ int widget_instance_unlisten_event(widget_instance_event_cb cb); int widget_instance_listen_status(const char *widget_id, widget_instance_event_cb cb, void *data); int widget_instance_unlisten_status(const char *widget_id); +int widget_instance_trigger_update_v2(const char *widget_id, const char *instance_id, const char *content_info, int force); + #ifdef __cplusplus } #endif diff --git a/src/widget_instance.c b/src/widget_instance.c index 1326462..7a3e61e 100644 --- a/src/widget_instance.c +++ b/src/widget_instance.c @@ -31,6 +31,7 @@ #include #include #include +#include "widget_errno.h" #define USER_UID_MIN 5000 #define MAX_INSTANCE_ID_LEN 256 @@ -291,7 +292,9 @@ static int __launch(const char *widget_id, const char *instance_id, bundle *extr if (b == NULL) b = bundle_create(); - bundle_add_str(b, WIDGET_K_INSTANCE, instance_id); + if (instance_id) + bundle_add_str(b, WIDGET_K_INSTANCE, instance_id); + bundle_add_str(b, WIDGET_K_CLASS, classid); bundle_add_str(b, AUL_K_WIDGET_VIEWER, viewer_appid); @@ -842,28 +845,54 @@ EAPI int widget_instance_change_period(widget_instance_h instance, double period EAPI int widget_instance_trigger_update(widget_instance_h instance, const char *content_info, int force) { - int ret; - bundle *kb; - if (!instance) return -1; + return widget_instance_trigger_update_v2(instance->widget_id, instance->id, content_info, force); +} + +EAPI int widget_instance_trigger_update_v2(const char *widget_id, + const char *instance_id, const char *content_info, int force) +{ + int ret; + + bundle *kb; + kb = bundle_create(); if (!kb) { _E("out of memory"); return -1; } + bundle_add_str(kb, WIDGET_K_OPERATION, "update"); + if (force) bundle_add_str(kb, WIDGET_K_FORCE, "true"); if (content_info) bundle_add_str(kb, WIDGET_K_CONTENT_INFO, content_info); - ret = __send_aul_cmd(instance, "update", kb); + ret = aul_widget_instance_update(widget_id, instance_id, kb); bundle_free(kb); + if (ret > 0) + return WIDGET_ERROR_NONE; + + switch (ret) { + case AUL_R_ENOAPP: + ret = WIDGET_ERROR_NOT_EXIST; + break; + case AUL_R_EILLACC: + ret = WIDGET_ERROR_PERMISSION_DENIED; + break; + case AUL_R_EINVAL: + ret = WIDGET_ERROR_INVALID_PARAMETER; + break; + default: + ret = WIDGET_ERROR_FAULT; + } + return ret; } diff --git a/src/widget_service.c b/src/widget_service.c index 7c55769..85b4bbf 100644 --- a/src/widget_service.c +++ b/src/widget_service.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -371,7 +372,6 @@ EAPI int widget_service_change_period(const char *pkgname, const char *id, doubl EAPI int widget_service_trigger_update(const char *widget_id, const char *id, bundle *b, int force) { - widget_instance_h instance; int ret; bundle_raw *raw= NULL; int len; @@ -386,25 +386,14 @@ EAPI int widget_service_trigger_update(const char *widget_id, const char *id, bu return WIDGET_ERROR_INVALID_PARAMETER; } - instance = widget_instance_get_instance(widget_id, id); - if (!instance) { - _E("instance not exists or out of bound(package)"); - return WIDGET_ERROR_PERMISSION_DENIED; - } + if (b) + bundle_encode(b, &raw, &len); - bundle_encode(b, &raw, &len); - if (raw) { - ret = widget_instance_trigger_update(instance, (const char *)raw, force); - } else { - _E("invalid parameter"); - ret = WIDGET_ERROR_INVALID_PARAMETER; - } + ret = widget_instance_trigger_update_v2(widget_id, id, (const char *)raw, force); if (raw) free(raw); - widget_instance_unref(instance); - return ret; } @@ -1427,18 +1416,20 @@ EAPI int widget_service_get_content_of_widget_instance(const char *widget_id, co } struct instance_cb { + const char *widget_id; widget_instance_list_cb cb; void *data; + int cnt; }; -static int __instance_list_cb(const char *widget_id, const char *instance_id, void *data) +static void __instance_list_cb(const char *instance_id, void *user_data) { - struct instance_cb *cb_data = (struct instance_cb *)data; + struct instance_cb *cb_data = (struct instance_cb *)user_data; + cb_data->cnt++; + _D("instance list: %s %s", cb_data->widget_id, instance_id); if (cb_data && cb_data->cb) - return cb_data->cb(widget_id, instance_id, cb_data->data); - - return -1; + cb_data->cb(cb_data->widget_id, instance_id, cb_data->data); } EAPI int widget_service_get_widget_instance_list(const char *widget_id, widget_instance_list_cb cb, void *data) @@ -1446,8 +1437,10 @@ EAPI int widget_service_get_widget_instance_list(const char *widget_id, widget_i struct instance_cb cb_data; int ret = WIDGET_ERROR_NONE; + cb_data.widget_id = widget_id; cb_data.cb = cb; cb_data.data = data; + cb_data.cnt = 0; if (!_is_widget_feature_enabled()) { _E("not supported"); @@ -1459,9 +1452,15 @@ EAPI int widget_service_get_widget_instance_list(const char *widget_id, widget_i return WIDGET_ERROR_INVALID_PARAMETER; } - ret = widget_instance_get_instance_list(widget_id, __instance_list_cb, &cb_data); + ret = aul_widget_instance_foreach(widget_id, __instance_list_cb, &cb_data); + + if (ret == AUL_R_EILLACC) + return WIDGET_ERROR_PERMISSION_DENIED; + + if (ret == AUL_R_ENOAPP || cb_data.cnt == 0) + return WIDGET_ERROR_NOT_EXIST; - return ret < 0 ? (ret == -2 ? WIDGET_ERROR_PERMISSION_DENIED : WIDGET_ERROR_NOT_EXIST) : WIDGET_ERROR_NONE; + return cb_data.cnt; } struct lifecycle_s { -- cgit v1.2.3