2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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.
19 #include <stdlib.h> /* malloc */
20 #include <string.h> /* strdup, strerror */
21 #include <sys/types.h>
29 #include <com-core_packet.h>
33 #include <package-manager.h>
35 #include <vconf-keys.h>
40 #include "livebox-service.h"
42 #define EAPI __attribute__((visibility("default")))
43 #define DEFAULT_TIMEOUT 2.0
46 static struct supported_size_list {
49 } SIZE_LIST[NR_OF_SIZE_LIST] = {
50 { 172, 172 }, /*!< 1x1 */
51 { 348, 172 }, /*!< 2x1 */
52 { 348, 348 }, /*!< 2x2 */
53 { 700, 172 }, /*!< 4x1 */
54 { 700, 348 }, /*!< 4x2 */
55 { 700, 520 }, /*!< 4x3 */
56 { 700, 700 }, /*!< 4x4 */
57 { 207, 207 }, /*!< 21x21 */
58 { 645, 207 }, /*!< 23x21 */
59 { 645, 645 }, /*!< 23x23 */
65 const char *conf_file;
70 .dbfile = "/opt/dbspace/.livebox.db",
71 .conf_file = "/usr/share/data-provider-master/resolution.ini",
76 static inline int update_info(int width_type, int height_type, int width, int height)
80 if (width_type == 1 && height_type == 1) {
81 DbgPrint("1x1 Updated to %dx%d\n", width, height);
83 } else if (width_type == 2 && height_type == 1) {
84 DbgPrint("2x1 Updated to %dx%d\n", width, height);
86 } else if (width_type == 2 && height_type == 2) {
87 DbgPrint("2x2 Updated to %dx%d\n", width, height);
89 } else if (width_type == 4 && height_type == 1) {
90 DbgPrint("4x1 Updated to %dx%d\n", width, height);
92 } else if (width_type == 4 && height_type == 2) {
93 DbgPrint("4x2 Updated to %dx%d\n", width, height);
95 } else if (width_type == 4 && height_type == 3) {
96 DbgPrint("4x3 Updated to %dx%d\n", width, height);
98 } else if (width_type == 4 && height_type == 4) {
99 DbgPrint("4x4 Updated to %dx%d\n", width, height);
101 } else if (width_type == 21 && height_type == 21) {
102 DbgPrint("Easy 1x1 Updated to %dx%d\n", width, height);
104 } else if (width_type == 23 && height_type == 21) {
105 DbgPrint("Easy 3x1 Updated to %dx%d\n", width, height);
107 } else if (width_type == 23 && height_type == 23) {
108 DbgPrint("Easy 3x3 Updated to %dx%d\n", width, height);
111 ErrPrint("Unknown size type: %dx%d (%dx%d)\n", width_type, height_type, width, height);
115 SIZE_LIST[idx].w = width;
116 SIZE_LIST[idx].h = height;
120 static inline int update_from_file(void)
128 char buffer[MAX_COLUMN];
142 fp = fopen(s_info.conf_file, "r");
144 ErrPrint("Open failed: %s\n", strerror(errno));
154 if (idx == MAX_COLUMN) {
155 ErrPrint("Buffer overflow. Too long line. LINE MUST BE SHOT THAN %d\n", MAX_COLUMN);
161 if (isspace(ch) || ch == EOF)
176 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
177 ErrPrint("Invalid syntax: [%s]\n", buffer);
181 } else if (ch == '=') {
184 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
185 ErrPrint("Invalid syntax: [%s]\n", buffer);
189 } else if (ch == EOF) {
190 ErrPrint("Invalid Syntax\n");
201 if (isspace(ch) || ch == EOF)
209 if (isspace(ch) || ch == EOF) {
213 if (sscanf(buffer, "%dx%d", &width, &height) != 2) {
214 ErrPrint("Invalid syntax: [%s]\n", buffer);
216 } else if (ch == EOF) {
217 updated += update_info(width_type, height_type, width, height);
224 updated += update_info(width_type, height_type, width, height);
229 if (ch == '\n' || ch == '\r' || ch == '\f')
233 if (ch == '\n' || ch == '\r' || ch == '\f')
237 ErrPrint("Unknown status. couldn't be reach to here\n");
243 return NR_OF_SIZE_LIST - updated;
246 static int update_resolution(void)
258 if (s_info.res_resolved)
261 disp = XOpenDisplay(NULL);
263 ErrPrint("Failed to open a display\n");
267 root = XDefaultRootWindow(disp);
268 if (!XGetGeometry(disp, root, &dummy, &x, &y, &width, &height, &border, &depth)) {
273 if (update_from_file() == 0)
274 DbgPrint("Resolution info is all updated by file\n");
276 DbgPrint("Screen resolution: %dx%d\n", width, height);
277 for (i = 0; i < NR_OF_SIZE_LIST; i++) {
278 SIZE_LIST[i].w = (unsigned int)((double)SIZE_LIST[i].w * (double)width / 720.0f);
279 SIZE_LIST[i].h = (unsigned int)((double)SIZE_LIST[i].h * (double)height / 1280.0f);
280 DbgPrint("(Ratio)Size is updated [%d] %dx%d\n", i, SIZE_LIST[i].w, SIZE_LIST[i].h);
284 s_info.res_resolved = 1;
288 static inline sqlite3 *open_db(void)
292 if (!s_info.handle) {
295 ret = db_util_open(s_info.dbfile, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
296 if (ret != SQLITE_OK) {
297 ErrPrint("Failed to open a DB\n");
301 handle = s_info.handle;
307 static inline void close_db(sqlite3 *handle)
310 db_util_close(handle);
313 static inline int convert_size_from_type(enum livebox_size_type type, int *width, int *height)
318 case LB_SIZE_TYPE_1x1: /*!< 172x172 */
321 case LB_SIZE_TYPE_2x1: /*!< 348x172 */
324 case LB_SIZE_TYPE_2x2: /*!< 348x348 */
327 case LB_SIZE_TYPE_4x1: /*!< 700x172 */
330 case LB_SIZE_TYPE_4x2: /*!< 700x348 */
333 case LB_SIZE_TYPE_4x3: /*!< 700x520 */
336 case LB_SIZE_TYPE_4x4: /*!< 700x700 */
339 case LB_SIZE_TYPE_EASY_1x1: /*< 207x207 */
342 case LB_SIZE_TYPE_EASY_3x1: /*!< 645x207 */
345 case LB_SIZE_TYPE_EASY_3x3: /*!< 645x645 */
352 if (update_resolution() < 0)
353 ErrPrint("Failed to update resolution\n");
355 *width = SIZE_LIST[idx].w;
356 *height = SIZE_LIST[idx].h;
360 EAPI int livebox_service_trigger_update(const char *pkgname, const char *cluster, const char *category)
362 struct packet *packet;
363 struct packet *result;
367 ErrPrint("Invalid argument\n");
371 if (access("/tmp/.live.paused", R_OK) == 0) {
372 DbgPrint("Provider is paused\n");
377 cluster = "user,created";
380 category = "default";
382 packet = packet_create("service_update", "sss", pkgname, cluster, category);
384 ErrPrint("Failed to create a packet for service_update\n");
388 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
389 packet_unref(packet);
392 if (packet_get(result, "i", &ret) != 1) {
393 ErrPrint("Failed to parse a result packet\n");
397 packet_unref(result);
399 ErrPrint("Failed to get result packet\n");
406 EAPI int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *pkgname, int is_prime, void *data), void *data)
422 ret = sqlite3_prepare_v2(handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL);
423 if (ret != SQLITE_OK) {
424 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
430 while (sqlite3_step(stmt) == SQLITE_ROW) {
431 appid = (char *)sqlite3_column_text(stmt, 0);
432 if (!appid || !strlen(appid)) {
433 ErrPrint("APPID is not valid\n");
437 pkgid = (char *)sqlite3_column_text(stmt, 1);
438 if (!pkgid || !strlen(pkgid)) {
439 ErrPrint("pkgid is not valid\n");
443 is_prime = sqlite3_column_int(stmt, 2);
447 if (cb(appid, pkgid, is_prime, data) < 0) {
448 DbgPrint("Callback stopped package crawling\n");
454 sqlite3_finalize(stmt);
461 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
468 if (!types || !cnt || !pkgid)
475 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
476 if (ret != SQLITE_OK) {
477 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
482 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
483 if (ret != SQLITE_OK) {
484 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
486 sqlite3_finalize(stmt);
491 if (*cnt > NR_OF_SIZE_LIST)
492 *cnt = NR_OF_SIZE_LIST;
495 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
496 size = sqlite3_column_int(stmt, 0);
503 sqlite3_finalize(stmt);
510 static inline char *cur_locale(void)
513 language = vconf_get_str(VCONFKEY_LANGSET);
530 language = strdup("en-us");
532 ErrPrint("Heap: %s\n", strerror(errno));
538 static inline char *get_default_name(const char *pkgid)
549 ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
550 if (ret != SQLITE_OK) {
551 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
556 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
557 if (ret != SQLITE_OK) {
558 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
562 ret = sqlite3_step(stmt);
563 if (ret == SQLITE_ROW) {
566 tmp = (const char *)sqlite3_column_text(stmt, 0);
567 if (tmp && strlen(tmp)) {
570 ErrPrint("Heap: %s\n", strerror(errno));
576 sqlite3_finalize(stmt);
581 static inline char *get_default_icon(const char *pkgid)
592 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
593 if (ret != SQLITE_OK) {
594 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
599 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
600 if (ret != SQLITE_OK) {
601 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
605 ret = sqlite3_step(stmt);
606 if (ret == SQLITE_ROW) {
609 tmp = (const char *)sqlite3_column_text(stmt, 0);
610 if (tmp && strlen(tmp)) {
613 ErrPrint("Heap: %s\n", strerror(errno));
619 sqlite3_finalize(stmt);
624 EAPI char *livebox_service_content(const char *pkgid)
628 char *content = NULL;
635 ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
636 if (ret != SQLITE_OK) {
637 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
642 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
643 if (ret != SQLITE_OK) {
644 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
648 ret = sqlite3_step(stmt);
649 if (ret == SQLITE_ROW) {
652 tmp = (const char *)sqlite3_column_text(stmt, 0);
653 if (tmp && strlen(tmp)) {
654 content = strdup(tmp);
656 ErrPrint("Heap: %s\n", strerror(errno));
662 sqlite3_finalize(stmt);
667 EAPI char *livebox_service_setup_appid(const char *lbid)
678 ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
679 if (ret != SQLITE_OK) {
680 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
686 ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
687 if (ret != SQLITE_OK) {
688 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
692 ret = sqlite3_step(stmt);
693 if (ret == SQLITE_ROW) {
696 tmp = (const char *)sqlite3_column_text(stmt, 0);
697 if (!tmp || !strlen(tmp))
702 ErrPrint("Error: %s\n", strerror(errno));
707 sqlite3_finalize(stmt);
712 EAPI int livebox_service_nodisplay(const char *pkgid)
722 ret = sqlite3_prepare_v2(handle, "SELECT nodisplay FROM client WHERE pkgid = ?", -1, &stmt, NULL);
723 if (ret != SQLITE_OK) {
724 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
729 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
730 if (ret != SQLITE_OK) {
731 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
736 ret = sqlite3_step(stmt);
737 if (ret == SQLITE_ROW)
738 ret = !!sqlite3_column_int(stmt, 0);
744 sqlite3_finalize(stmt);
749 EAPI int livebox_service_touch_effect(const char *pkgid)
759 ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM client WHERE pkgid = ?", -1, &stmt, NULL);
760 if (ret != SQLITE_OK) {
761 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
766 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
767 if (ret != SQLITE_OK) {
768 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
773 ret = sqlite3_step(stmt);
774 if (ret == SQLITE_ROW)
775 ret = !!sqlite3_column_int(stmt, 0);
781 sqlite3_finalize(stmt);
786 EAPI int livebox_service_mouse_event(const char *pkgid)
796 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
797 if (ret != SQLITE_OK) {
798 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
803 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
804 if (ret != SQLITE_OK) {
805 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
810 ret = sqlite3_step(stmt);
811 if (ret == SQLITE_ROW)
812 ret = !!sqlite3_column_int(stmt, 0);
818 sqlite3_finalize(stmt);
823 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
828 char *preview = NULL;
834 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
835 if (ret != SQLITE_OK) {
836 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
841 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
842 if (ret != SQLITE_OK) {
843 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
847 ret = sqlite3_bind_int(stmt, 2, size_type);
848 if (ret != SQLITE_OK) {
849 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
853 ret = sqlite3_step(stmt);
854 if (ret == SQLITE_ROW) {
856 tmp = (const char *)sqlite3_column_text(stmt, 0);
857 if (tmp && strlen(tmp)) {
858 preview = strdup(tmp);
860 ErrPrint("Heap: %s\n", strerror(errno));
866 sqlite3_finalize(stmt);
871 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
880 language = strdup(lang);
882 ErrPrint("Heap: %s\n", strerror(errno));
886 language = cur_locale();
897 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
898 if (ret != SQLITE_OK) {
899 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
905 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
906 if (ret != SQLITE_OK) {
907 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
911 ret = sqlite3_bind_text(stmt, 2, language, -1, NULL);
912 if (ret != SQLITE_OK) {
913 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
917 ret = sqlite3_step(stmt);
918 if (ret == SQLITE_ROW) {
920 tmp = (const char *)sqlite3_column_text(stmt, 0);
921 if (!tmp || !strlen(tmp)) {
922 icon = get_default_icon(pkgid);
926 ErrPrint("Heap: %s\n", strerror(errno));
929 icon = get_default_icon(pkgid);
934 sqlite3_finalize(stmt);
940 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
949 language = strdup(lang);
951 ErrPrint("Error: %s\n", strerror(errno));
955 language = cur_locale();
966 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
967 if (ret != SQLITE_OK) {
968 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
974 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
975 if (ret != SQLITE_OK) {
976 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
980 ret = sqlite3_bind_text(stmt, 2, language, -1, NULL);
981 if (ret != SQLITE_OK) {
982 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
986 ret = sqlite3_step(stmt);
987 if (ret == SQLITE_ROW) {
989 tmp = (const char *)sqlite3_column_text(stmt, 0);
990 if (!tmp || !strlen(tmp)) {
991 name = get_default_name(pkgid);
995 ErrPrint("Heap: %s\n", strerror(errno));
998 name = get_default_name(pkgid);
1002 sqlite3_reset(stmt);
1003 sqlite3_finalize(stmt);
1009 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
1016 if (!w || !h || !cnt || !pkgid)
1023 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1024 if (ret != SQLITE_OK) {
1025 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1030 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1031 if (ret != SQLITE_OK) {
1032 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1033 sqlite3_reset(stmt);
1034 sqlite3_finalize(stmt);
1039 if (*cnt > NR_OF_SIZE_LIST)
1040 *cnt = NR_OF_SIZE_LIST;
1043 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1044 size = sqlite3_column_int(stmt, 0);
1045 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
1049 sqlite3_reset(stmt);
1050 sqlite3_finalize(stmt);
1057 EAPI char *livebox_service_libexec(const char *pkgid)
1074 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1075 if (ret != SQLITE_OK) {
1076 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1080 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1081 if (ret != SQLITE_OK) {
1082 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1083 sqlite3_finalize(stmt);
1087 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1088 if (ret != SQLITE_OK) {
1089 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1090 sqlite3_finalize(stmt);
1094 if (sqlite3_step(stmt) != SQLITE_ROW) {
1095 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1096 sqlite3_reset(stmt);
1097 sqlite3_finalize(stmt);
1099 libexec = util_conf_get_libexec(pkgid);
1100 DbgPrint("Fallback to conf checker: %s\n", libexec);
1104 appid = (char *)sqlite3_column_text(stmt, 0);
1105 if (!appid || !strlen(appid)) {
1106 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1107 sqlite3_reset(stmt);
1108 sqlite3_finalize(stmt);
1112 path = (char *)sqlite3_column_text(stmt, 1);
1113 if (!path || !strlen(path)) {
1114 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1115 sqlite3_reset(stmt);
1116 sqlite3_finalize(stmt);
1120 libexec = strdup(path);
1122 ErrPrint("Heap: %s\n", strerror(errno));
1123 sqlite3_reset(stmt);
1124 sqlite3_finalize(stmt);
1128 DbgPrint("libexec: %s\n", libexec);
1130 sqlite3_reset(stmt);
1131 sqlite3_finalize(stmt);
1137 static inline char *get_lb_pkgname_by_appid(const char *appid)
1153 ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
1154 if (ret != SQLITE_OK) {
1155 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1160 ret = sqlite3_bind_text(stmt, 1, appid, -1, NULL);
1161 if (ret != SQLITE_OK) {
1162 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1166 ret = sqlite3_bind_text(stmt, 2, appid, -1, NULL);
1167 if (ret != SQLITE_OK) {
1168 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1172 if (sqlite3_step(stmt) != SQLITE_ROW) {
1173 ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
1177 tmp = (char *)sqlite3_column_text(stmt, 0);
1178 if (tmp && strlen(tmp)) {
1179 pkgid = strdup(tmp);
1181 ErrPrint("Heap: %s\n", strerror(errno));
1185 sqlite3_reset(stmt);
1186 sqlite3_finalize(stmt);
1191 EAPI char *livebox_service_pkgname(const char *appid)
1194 pkgmgr_appinfo_h handle;
1201 lb_pkgname = get_lb_pkgname_by_appid(appid);
1207 * Try to get the package id using given appid
1209 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1210 if (ret != PKGMGR_R_OK) {
1211 ErrPrint("Failed to get appinfo\n");
1215 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1216 if (ret != PKGMGR_R_OK) {
1217 pkgmgr_appinfo_destroy_appinfo(handle);
1218 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1222 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1223 pkgmgr_appinfo_destroy_appinfo(handle);
1225 if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
1226 return strdup(appid);
1231 EAPI char *livebox_service_provider_name(const char *lbid)
1237 char *str = "com.samsung.";
1242 while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
1244 if (seq < 2 && lbid[idx] == '.') {
1250 if (!str[idx] && lbid[idx]) {
1252 return strdup(lbid);
1253 } else if (seq < 2) {
1255 if (lbid[idx] == '.') {
1257 } else if (!lbid[idx]) {
1258 ErrPrint("Invalid lbid: %s\n", lbid);
1270 ret = strdup(lbid + stage);
1272 ErrPrint("Error: %s\n", strerror(errno));
1279 EAPI char *livebox_service_appid(const char *pkgname)
1285 int is_prime __attribute__((__unused__));
1296 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
1297 if (ret != SQLITE_OK) {
1298 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1302 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, NULL);
1303 if (ret != SQLITE_OK) {
1304 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1305 sqlite3_reset(stmt);
1306 sqlite3_finalize(stmt);
1310 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, NULL);
1311 if (ret != SQLITE_OK) {
1312 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1313 sqlite3_reset(stmt);
1314 sqlite3_finalize(stmt);
1318 ret = sqlite3_step(stmt);
1319 if (ret != SQLITE_ROW) {
1320 pkgmgr_appinfo_h pkg_handle;
1323 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
1324 sqlite3_reset(stmt);
1325 sqlite3_finalize(stmt);
1327 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
1328 if (ret != PKGMGR_R_OK) {
1329 ErrPrint("Failed to get appinfo: %s\n", pkgname);
1333 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
1334 if (ret != PKGMGR_R_OK) {
1335 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1336 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1340 appid = strdup(new_appid);
1342 ErrPrint("Heap: %s\n", strerror(errno));
1344 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1348 tmp = (char *)sqlite3_column_text(stmt, 0);
1349 if (!tmp || !strlen(tmp)) {
1350 ErrPrint("APPID is NIL\n");
1351 sqlite3_reset(stmt);
1352 sqlite3_finalize(stmt);
1356 appid = strdup(tmp);
1358 ErrPrint("Heap: %s\n", strerror(errno));
1359 sqlite3_reset(stmt);
1360 sqlite3_finalize(stmt);
1364 is_prime = sqlite3_column_int(stmt, 1);
1366 sqlite3_reset(stmt);
1367 sqlite3_finalize(stmt);
1373 EAPI char *livebox_service_lb_script_path(const char *pkgid)
1390 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1391 if (ret != SQLITE_OK) {
1392 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1396 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1397 if (ret != SQLITE_OK) {
1398 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1399 sqlite3_finalize(stmt);
1403 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1404 if (ret != SQLITE_OK) {
1405 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1406 sqlite3_finalize(stmt);
1410 ret = sqlite3_step(stmt);
1411 if (ret != SQLITE_ROW) {
1412 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1413 sqlite3_reset(stmt);
1414 sqlite3_finalize(stmt);
1418 appid = (char *)sqlite3_column_text(stmt, 0);
1419 if (!appid || !strlen(appid)) {
1420 ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
1421 sqlite3_reset(stmt);
1422 sqlite3_finalize(stmt);
1426 lb_src = (char *)sqlite3_column_text(stmt, 1);
1427 if (!lb_src || !strlen(lb_src)) {
1428 ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
1429 sqlite3_reset(stmt);
1430 sqlite3_finalize(stmt);
1434 path = strdup(lb_src);
1436 ErrPrint("Heap: %s\n", strerror(errno));
1437 sqlite3_reset(stmt);
1438 sqlite3_finalize(stmt);
1442 DbgPrint("LB Src: %s\n", path);
1444 sqlite3_reset(stmt);
1445 sqlite3_finalize(stmt);
1451 EAPI char *livebox_service_lb_script_group(const char *pkgid)
1467 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1468 if (ret != SQLITE_OK) {
1469 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1473 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1474 if (ret != SQLITE_OK) {
1475 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1476 sqlite3_finalize(stmt);
1480 ret = sqlite3_step(stmt);
1481 if (ret != SQLITE_ROW) {
1482 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1483 sqlite3_reset(stmt);
1484 sqlite3_finalize(stmt);
1488 tmp = (char *)sqlite3_column_text(stmt, 0);
1489 if (tmp && strlen(tmp)) {
1490 group = strdup(tmp);
1492 ErrPrint("Heap: %s\n", strerror(errno));
1495 sqlite3_reset(stmt);
1496 sqlite3_finalize(stmt);
1502 EAPI char *livebox_service_pd_script_path(const char *pkgid)
1519 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
1520 if (ret != SQLITE_OK) {
1521 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1525 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1526 if (ret != SQLITE_OK) {
1527 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1528 sqlite3_finalize(stmt);
1532 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1533 if (ret != SQLITE_OK) {
1534 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1535 sqlite3_finalize(stmt);
1539 ret = sqlite3_step(stmt);
1540 if (ret != SQLITE_ROW) {
1541 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1542 sqlite3_reset(stmt);
1543 sqlite3_finalize(stmt);
1547 appid = (char *)sqlite3_column_text(stmt, 0);
1548 if (!appid || !strlen(appid)) {
1549 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1550 sqlite3_reset(stmt);
1551 sqlite3_finalize(stmt);
1555 pd_src = (char *)sqlite3_column_text(stmt, 1);
1556 if (!pd_src || !strlen(pd_src)) {
1557 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1558 sqlite3_reset(stmt);
1559 sqlite3_finalize(stmt);
1563 path = strdup(pd_src);
1565 ErrPrint("Heap: %s\n", strerror(errno));
1566 sqlite3_reset(stmt);
1567 sqlite3_finalize(stmt);
1571 DbgPrint("PD Src: %s\n", path);
1572 sqlite3_reset(stmt);
1573 sqlite3_finalize(stmt);
1579 EAPI char *livebox_service_pd_script_group(const char *pkgid)
1595 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1596 if (ret != SQLITE_OK) {
1597 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1601 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1602 if (ret != SQLITE_OK) {
1603 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1604 sqlite3_finalize(stmt);
1608 ret = sqlite3_step(stmt);
1609 if (ret != SQLITE_ROW) {
1610 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1611 sqlite3_reset(stmt);
1612 sqlite3_finalize(stmt);
1616 tmp = (char *)sqlite3_column_text(stmt, 0);
1617 if (tmp && strlen(tmp)) {
1618 group = strdup(tmp);
1620 ErrPrint("Heap: %s\n", strerror(errno));
1622 sqlite3_reset(stmt);
1623 sqlite3_finalize(stmt);
1629 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
1633 const char *cluster;
1645 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
1646 if (ret != SQLITE_OK) {
1647 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1652 while (sqlite3_step(stmt) == SQLITE_ROW) {
1653 cluster = (const char *)sqlite3_column_text(stmt, 0);
1654 if (!cluster || !strlen(cluster))
1657 if (cb(cluster, data) < 0)
1663 sqlite3_reset(stmt);
1664 sqlite3_finalize(stmt);
1670 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
1674 const char *category;
1678 if (!cluster || !cb)
1685 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
1686 if (ret != SQLITE_OK) {
1687 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1693 while (sqlite3_step(stmt) == SQLITE_ROW) {
1694 category = (const char *)sqlite3_column_text(stmt, 0);
1695 if (!category || !strlen(category))
1698 if (cb(cluster, category, data) < 0)
1704 sqlite3_reset(stmt);
1705 sqlite3_finalize(stmt);
1711 EAPI int livebox_service_init(void)
1713 if (s_info.handle) {
1714 DbgPrint("Already initialized\n");
1715 s_info.init_count++;
1719 s_info.handle = open_db();
1720 if (s_info.handle) {
1721 s_info.init_count++;
1728 EAPI int livebox_service_fini(void)
1730 if (!s_info.handle || s_info.init_count <= 0) {
1731 ErrPrint("Service is not initialized\n");
1735 s_info.init_count--;
1736 if (s_info.init_count > 0) {
1737 DbgPrint("Init count %d\n", s_info.init_count);
1741 db_util_close(s_info.handle);
1742 s_info.handle = NULL;
1746 EAPI int livebox_service_get_size(int type, int *width, int *height)
1757 return convert_size_from_type(type, width, height);
1760 EAPI int livebox_service_size_type(int width, int height)
1764 if (update_resolution() < 0)
1765 ErrPrint("Failed to update the size list\n");
1767 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
1768 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
1774 return LB_SIZE_TYPE_1x1;
1776 return LB_SIZE_TYPE_2x1;
1778 return LB_SIZE_TYPE_2x2;
1780 return LB_SIZE_TYPE_4x1;
1782 return LB_SIZE_TYPE_4x2;
1784 return LB_SIZE_TYPE_4x3;
1786 return LB_SIZE_TYPE_4x4;
1788 return LB_SIZE_TYPE_EASY_1x1;
1790 return LB_SIZE_TYPE_EASY_3x1;
1792 return LB_SIZE_TYPE_EASY_3x3;
1797 return LB_SIZE_TYPE_UNKNOWN;