Fix widget_service_get_icon bug 43/108943/3 accepted/tizen_3.0.m2_common accepted/tizen_3.0.m2_mobile accepted/tizen_3.0.m2_tv accepted/tizen_3.0.m2_wearable tizen_3.0.m2 accepted/tizen/3.0.m2/common/20170110.181743 accepted/tizen/3.0.m2/mobile/20170110.084052 accepted/tizen/3.0.m2/tv/20170110.084104 accepted/tizen/3.0.m2/wearable/20170110.084115 accepted/tizen/3.0/common/20170109.200423 accepted/tizen/3.0/ivi/20170109.074242 accepted/tizen/3.0/mobile/20170109.074147 accepted/tizen/3.0/tv/20170109.074207 accepted/tizen/3.0/wearable/20170109.074226 submit/tizen_3.0.m2/20170109.005227 submit/tizen_3.0/20170109.003313
authorHyunho Kang <hhstark.kang@samsung.com>
Fri, 6 Jan 2017 08:36:02 +0000 (17:36 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Mon, 9 Jan 2017 00:23:36 +0000 (09:23 +0900)
Api should get icon info with pkgid

Change-Id: I6de807bcdc57f4b71b8ec8c58292a03b5c1ecfe2
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/widget_service.c

index 3354471..2b3600f 100644 (file)
@@ -1196,6 +1196,59 @@ EAPI char *widget_service_get_preview_image_path(const char *widget_id,
        return path;
 }
 
+
+static char *_get_main_widget_id(const char *pkg_id, uid_t uid)
+{
+       static const char query[] =
+               "SELECT classid FROM widget_class "
+               "WHERE pkgid=? and prime=1 ";
+       int ret;
+       sqlite3 *db;
+       sqlite3_stmt *stmt;
+       char *widget_id;
+
+       db = _open_db(uid);
+       if (db == NULL) {
+               set_last_result(WIDGET_ERROR_IO_ERROR);
+               return NULL;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               /* LCOV_EXCL_START */
+               _E("prepare error: %s", sqlite3_errmsg(db));
+               sqlite3_close_v2(db);
+               set_last_result(WIDGET_ERROR_FAULT);
+               return NULL;
+               /* LCOV_EXCL_STOP */
+       }
+
+       sqlite3_bind_text(stmt, 1, pkg_id, -1, SQLITE_STATIC);
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               if (ret == SQLITE_DONE)
+                       _E("cannot find widget_id for pkg_id %s", pkg_id);
+               else
+                       _E("step error: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               /* TODO: which error should be set? */
+               set_last_result(ret == SQLITE_DONE ? WIDGET_ERROR_NOT_EXIST :
+                               WIDGET_ERROR_FAULT);
+               return NULL;
+       }
+
+       _get_column_str(stmt, 0, &widget_id);
+
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
+
+       set_last_result(WIDGET_ERROR_NONE);
+
+       return widget_id;
+}
+
 static char *_get_icon(const char *widget_id, const char *lang, uid_t uid)
 {
        static const char query[] =
@@ -1253,9 +1306,10 @@ static char *_get_icon(const char *widget_id, const char *lang, uid_t uid)
        return icon;
 }
 
-EAPI char *widget_service_get_icon(const char *widget_id, const char *lang)
+EAPI char *widget_service_get_icon(const char *pkgid, const char *lang)
 {
        char *icon;
+       char *widget_id;
 
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
@@ -1263,7 +1317,7 @@ EAPI char *widget_service_get_icon(const char *widget_id, const char *lang)
                return NULL;
        }
 
-       if (widget_id == NULL) {
+       if (pkgid == NULL) {
                _E("invalid parameter");
                set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
                return NULL;
@@ -1274,6 +1328,10 @@ EAPI char *widget_service_get_icon(const char *widget_id, const char *lang)
                return NULL;
        }
 
+       widget_id = _get_main_widget_id(pkgid, getuid());
+       if (widget_id == NULL && get_last_result() == WIDGET_ERROR_NOT_EXIST)
+               widget_id = _get_main_widget_id(pkgid, GLOBALAPP_USER);
+
        icon = _get_icon(widget_id, lang, getuid());
        if (icon == NULL && get_last_result() == WIDGET_ERROR_NOT_EXIST)
                icon = _get_icon(widget_id, lang, GLOBALAPP_USER);