2 * Copyright 2013 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>
41 #include "livebox-service.h"
42 #include "livebox-errno.h"
44 #define SAMSUNG_PREFIX "com.samsung."
45 #define EAPI __attribute__((visibility("default")))
46 #define DEFAULT_TIMEOUT 2.0
49 static struct supported_size_list {
52 } SIZE_LIST[NR_OF_SIZE_LIST] = {
53 { 172, 172 }, /*!< 1x1 */
54 { 348, 172 }, /*!< 2x1 */
55 { 348, 348 }, /*!< 2x2 */
56 { 700, 172 }, /*!< 4x1 */
57 { 700, 348 }, /*!< 4x2 */
58 { 700, 520 }, /*!< 4x3 */
59 { 700, 700 }, /*!< 4x4 */
60 { 207, 207 }, /*!< 21x21 */
61 { 645, 207 }, /*!< 23x21 */
62 { 645, 645 }, /*!< 23x23 */
63 { 720, 1280 }, /*!< 0x0 */
69 const char *conf_file;
74 .dbfile = "/opt/dbspace/.livebox.db",
75 .conf_file = "/usr/share/data-provider-master/resolution.ini",
80 static inline int update_info(int width_type, int height_type, int width, int height)
84 if (width_type == 1 && height_type == 1) {
85 DbgPrint("1x1 Updated to %dx%d\n", width, height);
87 } else if (width_type == 2 && height_type == 1) {
88 DbgPrint("2x1 Updated to %dx%d\n", width, height);
90 } else if (width_type == 2 && height_type == 2) {
91 DbgPrint("2x2 Updated to %dx%d\n", width, height);
93 } else if (width_type == 4 && height_type == 1) {
94 DbgPrint("4x1 Updated to %dx%d\n", width, height);
96 } else if (width_type == 4 && height_type == 2) {
97 DbgPrint("4x2 Updated to %dx%d\n", width, height);
99 } else if (width_type == 4 && height_type == 3) {
100 DbgPrint("4x3 Updated to %dx%d\n", width, height);
102 } else if (width_type == 4 && height_type == 4) {
103 DbgPrint("4x4 Updated to %dx%d\n", width, height);
105 } else if (width_type == 21 && height_type == 21) {
106 DbgPrint("Easy 1x1 Updated to %dx%d\n", width, height);
108 } else if (width_type == 23 && height_type == 21) {
109 DbgPrint("Easy 3x1 Updated to %dx%d\n", width, height);
111 } else if (width_type == 23 && height_type == 23) {
112 DbgPrint("Easy 3x3 Updated to %dx%d\n", width, height);
114 } else if (width_type == 0 && height_type == 0) {
115 DbgPrint("Special 0x0 Updated to %dx%d\n", width, height);
118 ErrPrint("Unknown size type: %dx%d (%dx%d)\n", width_type, height_type, width, height);
122 SIZE_LIST[idx].w = width;
123 SIZE_LIST[idx].h = height;
127 static inline int update_from_file(void)
135 char buffer[MAX_COLUMN];
149 fp = fopen(s_info.conf_file, "r");
151 ErrPrint("Open failed: %s\n", strerror(errno));
152 return LB_STATUS_ERROR_IO;
161 if (idx == MAX_COLUMN) {
162 ErrPrint("Buffer overflow. Too long line. LINE MUST BE SHOT THAN %d\n", MAX_COLUMN);
168 if (isspace(ch) || ch == EOF)
183 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
184 ErrPrint("Invalid syntax: [%s]\n", buffer);
188 } else if (ch == '=') {
191 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
192 ErrPrint("Invalid syntax: [%s]\n", buffer);
196 } else if (ch == EOF) {
197 ErrPrint("Invalid Syntax\n");
208 if (isspace(ch) || ch == EOF)
216 if (isspace(ch) || ch == EOF) {
220 if (sscanf(buffer, "%dx%d", &width, &height) != 2) {
221 ErrPrint("Invalid syntax: [%s]\n", buffer);
223 } else if (ch == EOF) {
224 updated += update_info(width_type, height_type, width, height);
231 updated += update_info(width_type, height_type, width, height);
236 if (ch == '\n' || ch == '\r' || ch == '\f')
240 if (ch == '\n' || ch == '\r' || ch == '\f')
244 ErrPrint("Unknown status. couldn't be reach to here\n");
250 return NR_OF_SIZE_LIST - updated;
253 static int update_resolution(void)
265 if (s_info.res_resolved)
266 return LB_STATUS_SUCCESS;
268 disp = XOpenDisplay(NULL);
270 ErrPrint("Failed to open a display\n");
271 return LB_STATUS_ERROR_FAULT;
274 root = XDefaultRootWindow(disp);
275 if (!XGetGeometry(disp, root, &dummy, &x, &y, &width, &height, &border, &depth)) {
277 return LB_STATUS_ERROR_FAULT;
280 if (update_from_file() == 0)
281 DbgPrint("Resolution info is all updated by file\n");
283 DbgPrint("Screen resolution: %dx%d\n", width, height);
284 for (i = 0; i < NR_OF_SIZE_LIST; i++) {
285 SIZE_LIST[i].w = (unsigned int)((double)SIZE_LIST[i].w * (double)width / 720.0f);
286 SIZE_LIST[i].h = (unsigned int)((double)SIZE_LIST[i].h * (double)width / 720.0f);
287 DbgPrint("(Ratio)Size is updated [%d] %dx%d\n", i, SIZE_LIST[i].w, SIZE_LIST[i].h);
291 s_info.res_resolved = 1;
292 return LB_STATUS_SUCCESS;
295 static inline sqlite3 *open_db(void)
299 if (!s_info.handle) {
302 ret = db_util_open(s_info.dbfile, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
303 if (ret != SQLITE_OK) {
304 ErrPrint("Failed to open a DB\n");
308 handle = s_info.handle;
314 static inline void close_db(sqlite3 *handle)
317 db_util_close(handle);
320 static inline int convert_size_from_type(enum livebox_size_type type, int *width, int *height)
325 case LB_SIZE_TYPE_1x1: /*!< 172x172 */
328 case LB_SIZE_TYPE_2x1: /*!< 348x172 */
331 case LB_SIZE_TYPE_2x2: /*!< 348x348 */
334 case LB_SIZE_TYPE_4x1: /*!< 700x172 */
337 case LB_SIZE_TYPE_4x2: /*!< 700x348 */
340 case LB_SIZE_TYPE_4x3: /*!< 700x520 */
343 case LB_SIZE_TYPE_4x4: /*!< 700x700 */
346 case LB_SIZE_TYPE_EASY_1x1: /*< 207x207 */
349 case LB_SIZE_TYPE_EASY_3x1: /*!< 645x207 */
352 case LB_SIZE_TYPE_EASY_3x3: /*!< 645x645 */
355 case LB_SIZE_TYPE_0x0: /*!< 720x1280 */
359 return LB_STATUS_ERROR_INVALID;
362 if (update_resolution() < 0)
363 ErrPrint("Failed to update resolution\n");
365 *width = SIZE_LIST[idx].w;
366 *height = SIZE_LIST[idx].h;
367 return LB_STATUS_SUCCESS;
370 EAPI int livebox_service_change_period(const char *pkgname, const char *id, double period)
372 struct packet *packet;
373 struct packet *result;
377 if (!pkgname || !id || period < 0.0f) {
378 ErrPrint("Invalid argument\n");
379 return LB_STATUS_ERROR_INVALID;
382 uri = util_id_to_uri(id);
384 return LB_STATUS_ERROR_MEMORY;
386 packet = packet_create("service_change_period", "ssd", pkgname, uri, period);
389 ErrPrint("Failed to create a packet for period changing\n");
390 return LB_STATUS_ERROR_FAULT;
393 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
394 packet_unref(packet);
397 if (packet_get(result, "i", &ret) != 1) {
398 ErrPrint("Failed to parse a result packet\n");
399 ret = LB_STATUS_ERROR_INVALID;
401 packet_unref(result);
403 ErrPrint("Failed to get result packet\n");
404 ret = LB_STATUS_ERROR_FAULT;
410 EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, const char *cluster, const char *category, int force)
412 struct packet *packet;
413 struct packet *result;
418 ErrPrint("Invalid argument\n");
419 return LB_STATUS_ERROR_INVALID;
422 if (!force && access("/tmp/.live.paused", R_OK) == 0) {
423 DbgPrint("Provider is paused\n");
424 return LB_STATUS_ERROR_CANCEL;
427 uri = util_id_to_uri(id);
429 return LB_STATUS_ERROR_MEMORY;
432 cluster = "user,created";
435 category = "default";
437 packet = packet_create("service_update", "ssss", pkgname, uri, cluster, category);
440 ErrPrint("Failed to create a packet for service_update\n");
441 return LB_STATUS_ERROR_FAULT;
444 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
445 packet_unref(packet);
448 if (packet_get(result, "i", &ret) != 1) {
449 ErrPrint("Failed to parse a result packet\n");
450 ret = LB_STATUS_ERROR_INVALID;
453 packet_unref(result);
455 ErrPrint("Failed to get result packet\n");
456 ret = LB_STATUS_ERROR_FAULT;
462 EAPI int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *pkgname, int is_prime, void *data), void *data)
472 return LB_STATUS_ERROR_INVALID;
476 return LB_STATUS_ERROR_IO;
478 ret = sqlite3_prepare_v2(handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL);
479 if (ret != SQLITE_OK) {
480 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
481 ret = LB_STATUS_ERROR_IO;
486 while (sqlite3_step(stmt) == SQLITE_ROW) {
487 appid = (char *)sqlite3_column_text(stmt, 0);
488 if (!appid || !strlen(appid)) {
489 ErrPrint("APPID is not valid\n");
493 pkgid = (char *)sqlite3_column_text(stmt, 1);
494 if (!pkgid || !strlen(pkgid)) {
495 ErrPrint("pkgid is not valid\n");
499 is_prime = sqlite3_column_int(stmt, 2);
503 if (cb(appid, pkgid, is_prime, data) < 0) {
504 DbgPrint("Callback stopped package crawling\n");
510 sqlite3_finalize(stmt);
517 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
524 if (!types || !cnt || !pkgid)
525 return LB_STATUS_ERROR_INVALID;
529 return LB_STATUS_ERROR_IO;
531 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
532 if (ret != SQLITE_OK) {
533 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
534 ret = LB_STATUS_ERROR_IO;
538 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
539 if (ret != SQLITE_OK) {
540 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
542 sqlite3_finalize(stmt);
543 ret = LB_STATUS_ERROR_IO;
547 if (*cnt > NR_OF_SIZE_LIST)
548 *cnt = NR_OF_SIZE_LIST;
551 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
552 size = sqlite3_column_int(stmt, 0);
559 sqlite3_finalize(stmt);
566 static inline char *cur_locale(void)
569 language = vconf_get_str(VCONFKEY_LANGSET);
586 language = strdup("en-us");
588 ErrPrint("Heap: %s\n", strerror(errno));
594 static inline char *get_default_name(const char *pkgid)
605 ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
606 if (ret != SQLITE_OK) {
607 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
612 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
613 if (ret != SQLITE_OK) {
614 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
618 ret = sqlite3_step(stmt);
619 if (ret == SQLITE_ROW) {
622 tmp = (const char *)sqlite3_column_text(stmt, 0);
623 if (tmp && strlen(tmp)) {
626 ErrPrint("Heap: %s\n", strerror(errno));
632 sqlite3_finalize(stmt);
637 static inline char *get_default_icon(const char *pkgid)
648 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
649 if (ret != SQLITE_OK) {
650 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
655 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
656 if (ret != SQLITE_OK) {
657 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
661 ret = sqlite3_step(stmt);
662 if (ret == SQLITE_ROW) {
665 tmp = (const char *)sqlite3_column_text(stmt, 0);
666 if (tmp && strlen(tmp)) {
669 ErrPrint("Heap: %s\n", strerror(errno));
675 sqlite3_finalize(stmt);
680 EAPI char *livebox_service_content(const char *pkgid)
684 char *content = NULL;
691 ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
692 if (ret != SQLITE_OK) {
693 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
698 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
699 if (ret != SQLITE_OK) {
700 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
704 ret = sqlite3_step(stmt);
705 if (ret == SQLITE_ROW) {
708 tmp = (const char *)sqlite3_column_text(stmt, 0);
709 if (tmp && strlen(tmp)) {
710 content = strdup(tmp);
712 ErrPrint("Heap: %s\n", strerror(errno));
718 sqlite3_finalize(stmt);
723 EAPI char *livebox_service_setup_appid(const char *lbid)
734 ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
735 if (ret != SQLITE_OK) {
736 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
742 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
743 if (ret != SQLITE_OK) {
744 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
748 ret = sqlite3_step(stmt);
749 if (ret == SQLITE_ROW) {
752 tmp = (const char *)sqlite3_column_text(stmt, 0);
753 if (!tmp || !strlen(tmp))
758 ErrPrint("Error: %s\n", strerror(errno));
763 sqlite3_finalize(stmt);
768 EAPI int livebox_service_nodisplay(const char *pkgid)
778 ret = sqlite3_prepare_v2(handle, "SELECT nodisplay FROM client WHERE pkgid = ?", -1, &stmt, NULL);
779 if (ret != SQLITE_OK) {
780 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
785 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
786 if (ret != SQLITE_OK) {
787 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
792 ret = sqlite3_step(stmt);
793 if (ret == SQLITE_ROW)
794 ret = !!sqlite3_column_int(stmt, 0);
800 sqlite3_finalize(stmt);
805 static inline char *get_lb_pkgname_by_appid(const char *appid)
821 ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
822 if (ret != SQLITE_OK) {
823 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
828 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
829 if (ret != SQLITE_OK) {
830 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
834 ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT);
835 if (ret != SQLITE_OK) {
836 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
840 if (sqlite3_step(stmt) != SQLITE_ROW) {
841 ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
845 tmp = (char *)sqlite3_column_text(stmt, 0);
846 if (tmp && strlen(tmp)) {
849 ErrPrint("Heap: %s\n", strerror(errno));
854 sqlite3_finalize(stmt);
859 EAPI int livebox_service_touch_effect(const char *pkgid)
868 ErrPrint("Unable to open a DB\n");
872 ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM client WHERE pkgid = ?", -1, &stmt, NULL);
873 if (ret != SQLITE_OK) {
874 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
881 * This function will validate the "pkgid"
882 * call the exported API in the exported API is not recomended
885 lbid = livebox_service_pkgname(pkgid);
887 ErrPrint("Invalid appid (%s)\n", pkgid);
892 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
894 if (ret != SQLITE_OK) {
895 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
900 ret = sqlite3_step(stmt);
901 if (ret == SQLITE_ROW) {
902 ret = !!sqlite3_column_int(stmt, 0);
904 ret = 1; /*!< Default true: In this case the DB is corrupted. */
905 ErrPrint("There is no result\n");
910 sqlite3_finalize(stmt);
915 EAPI int livebox_service_mouse_event(const char *pkgid)
926 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
927 if (ret != SQLITE_OK) {
928 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
933 lbid = livebox_service_pkgname(pkgid);
935 ErrPrint("Failed to get lbid: %s\n", pkgid);
940 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
942 if (ret != SQLITE_OK) {
943 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
948 ret = sqlite3_step(stmt);
949 if (ret == SQLITE_ROW) {
950 ret = !!sqlite3_column_int(stmt, 0);
952 ret = 0; /*!< Default is false, In this case the DB is corrupted */
953 ErrPrint("There is no result.\n");
958 sqlite3_finalize(stmt);
963 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
968 char *preview = NULL;
974 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
975 if (ret != SQLITE_OK) {
976 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
981 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
982 if (ret != SQLITE_OK) {
983 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
987 ret = sqlite3_bind_int(stmt, 2, size_type);
988 if (ret != SQLITE_OK) {
989 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
993 ret = sqlite3_step(stmt);
994 if (ret == SQLITE_ROW) {
996 tmp = (const char *)sqlite3_column_text(stmt, 0);
997 if (tmp && strlen(tmp)) {
998 preview = strdup(tmp);
1000 ErrPrint("Heap: %s\n", strerror(errno));
1005 sqlite3_reset(stmt);
1006 sqlite3_finalize(stmt);
1011 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
1020 language = strdup(lang);
1022 ErrPrint("Heap: %s\n", strerror(errno));
1026 language = cur_locale();
1037 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1038 if (ret != SQLITE_OK) {
1039 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1045 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1046 if (ret != SQLITE_OK) {
1047 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1051 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1052 if (ret != SQLITE_OK) {
1053 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1057 ret = sqlite3_step(stmt);
1058 if (ret == SQLITE_ROW) {
1060 tmp = (const char *)sqlite3_column_text(stmt, 0);
1061 if (!tmp || !strlen(tmp)) {
1062 icon = get_default_icon(pkgid);
1066 ErrPrint("Heap: %s\n", strerror(errno));
1069 icon = get_default_icon(pkgid);
1073 sqlite3_reset(stmt);
1074 sqlite3_finalize(stmt);
1080 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
1089 language = strdup(lang);
1091 ErrPrint("Error: %s\n", strerror(errno));
1095 language = cur_locale();
1106 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1107 if (ret != SQLITE_OK) {
1108 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1114 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1115 if (ret != SQLITE_OK) {
1116 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1120 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1121 if (ret != SQLITE_OK) {
1122 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1126 ret = sqlite3_step(stmt);
1127 if (ret == SQLITE_ROW) {
1129 tmp = (const char *)sqlite3_column_text(stmt, 0);
1130 if (!tmp || !strlen(tmp)) {
1131 name = get_default_name(pkgid);
1135 ErrPrint("Heap: %s\n", strerror(errno));
1138 name = get_default_name(pkgid);
1142 sqlite3_reset(stmt);
1143 sqlite3_finalize(stmt);
1149 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
1156 if (!w || !h || !cnt || !pkgid)
1157 return LB_STATUS_ERROR_INVALID;
1161 return LB_STATUS_ERROR_IO;
1163 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1164 if (ret != SQLITE_OK) {
1165 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1166 ret = LB_STATUS_ERROR_IO;
1170 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1171 if (ret != SQLITE_OK) {
1172 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1173 sqlite3_reset(stmt);
1174 sqlite3_finalize(stmt);
1175 ret = LB_STATUS_ERROR_IO;
1179 if (*cnt > NR_OF_SIZE_LIST)
1180 *cnt = NR_OF_SIZE_LIST;
1183 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1184 size = sqlite3_column_int(stmt, 0);
1185 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
1189 sqlite3_reset(stmt);
1190 sqlite3_finalize(stmt);
1197 EAPI char *livebox_service_libexec(const char *pkgid)
1214 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1215 if (ret != SQLITE_OK) {
1216 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1220 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1221 if (ret != SQLITE_OK) {
1222 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1223 sqlite3_finalize(stmt);
1227 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1228 if (ret != SQLITE_OK) {
1229 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1230 sqlite3_finalize(stmt);
1234 if (sqlite3_step(stmt) != SQLITE_ROW) {
1235 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1236 sqlite3_reset(stmt);
1237 sqlite3_finalize(stmt);
1239 libexec = util_conf_get_libexec(pkgid);
1240 DbgPrint("Fallback to conf checker: %s\n", libexec);
1244 appid = (char *)sqlite3_column_text(stmt, 0);
1245 if (!appid || !strlen(appid)) {
1246 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1247 sqlite3_reset(stmt);
1248 sqlite3_finalize(stmt);
1252 path = (char *)sqlite3_column_text(stmt, 1);
1253 if (!path || !strlen(path)) {
1254 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1255 sqlite3_reset(stmt);
1256 sqlite3_finalize(stmt);
1260 libexec = strdup(path);
1262 ErrPrint("Heap: %s\n", strerror(errno));
1263 sqlite3_reset(stmt);
1264 sqlite3_finalize(stmt);
1268 DbgPrint("libexec: %s\n", libexec);
1270 sqlite3_reset(stmt);
1271 sqlite3_finalize(stmt);
1277 EAPI char *livebox_service_pkgname(const char *appid)
1280 pkgmgr_appinfo_h handle;
1287 lb_pkgname = get_lb_pkgname_by_appid(appid);
1293 * Try to get the package id using given appid
1295 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1296 if (ret != PKGMGR_R_OK) {
1297 ErrPrint("Failed to get appinfo\n");
1301 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1302 if (ret != PKGMGR_R_OK) {
1303 pkgmgr_appinfo_destroy_appinfo(handle);
1304 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1308 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1309 pkgmgr_appinfo_destroy_appinfo(handle);
1311 if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
1312 return strdup(appid);
1317 EAPI char *livebox_service_provider_name(const char *lbid)
1323 char *str = SAMSUNG_PREFIX;
1328 while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
1330 if (seq < 2 && lbid[idx] == '.') {
1336 if (!str[idx] && lbid[idx]) {
1338 return strdup(lbid);
1339 } else if (seq < 2) {
1341 if (lbid[idx] == '.') {
1343 } else if (!lbid[idx]) {
1344 ErrPrint("Invalid lbid: %s\n", lbid);
1356 ret = strdup(lbid + stage);
1358 ErrPrint("Error: %s\n", strerror(errno));
1365 EAPI int livebox_service_is_enabled(const char *lbid)
1374 pkgname = livebox_service_appid(lbid);
1378 ret = ail_get_appinfo(pkgname, &ai);
1379 if (ret != AIL_ERROR_OK) {
1384 if (ail_appinfo_get_bool(ai, AIL_PROP_X_SLP_ENABLED_BOOL, &enabled) != AIL_ERROR_OK)
1387 ail_destroy_appinfo(ai);
1389 return enabled == true;
1393 EAPI int livebox_service_is_primary(const char *lbid)
1406 ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
1407 if (ret != SQLITE_OK) {
1408 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1413 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1414 if (ret != SQLITE_OK) {
1415 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1419 ret = sqlite3_step(stmt);
1420 if (ret != SQLITE_ROW) {
1421 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1425 ret = sqlite3_column_int(stmt, 1);
1428 sqlite3_reset(stmt);
1429 sqlite3_finalize(stmt);
1435 * appid == Package ID
1436 * pkgid == Livebox ID
1438 EAPI char *livebox_service_appid(const char *pkgname)
1444 int is_prime __attribute__((__unused__));
1455 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
1456 if (ret != SQLITE_OK) {
1457 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1461 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1462 if (ret != SQLITE_OK) {
1463 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1464 sqlite3_reset(stmt);
1465 sqlite3_finalize(stmt);
1469 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT);
1470 if (ret != SQLITE_OK) {
1471 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1472 sqlite3_reset(stmt);
1473 sqlite3_finalize(stmt);
1477 ret = sqlite3_step(stmt);
1478 if (ret != SQLITE_ROW) {
1479 pkgmgr_appinfo_h pkg_handle;
1482 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
1483 sqlite3_reset(stmt);
1484 sqlite3_finalize(stmt);
1486 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
1487 if (ret != PKGMGR_R_OK) {
1488 ErrPrint("Failed to get appinfo: %s\n", pkgname);
1492 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
1493 if (ret != PKGMGR_R_OK) {
1494 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1495 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1499 appid = strdup(new_appid);
1501 ErrPrint("Heap: %s\n", strerror(errno));
1503 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1507 tmp = (char *)sqlite3_column_text(stmt, 0);
1508 if (!tmp || !strlen(tmp)) {
1509 ErrPrint("APPID is NIL\n");
1510 sqlite3_reset(stmt);
1511 sqlite3_finalize(stmt);
1515 appid = strdup(tmp);
1517 ErrPrint("Heap: %s\n", strerror(errno));
1518 sqlite3_reset(stmt);
1519 sqlite3_finalize(stmt);
1523 is_prime = sqlite3_column_int(stmt, 1);
1525 sqlite3_reset(stmt);
1526 sqlite3_finalize(stmt);
1532 EAPI char *livebox_service_lb_script_path(const char *pkgid)
1549 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1550 if (ret != SQLITE_OK) {
1551 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1555 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1556 if (ret != SQLITE_OK) {
1557 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1558 sqlite3_finalize(stmt);
1562 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1563 if (ret != SQLITE_OK) {
1564 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1565 sqlite3_finalize(stmt);
1569 ret = sqlite3_step(stmt);
1570 if (ret != SQLITE_ROW) {
1571 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1572 sqlite3_reset(stmt);
1573 sqlite3_finalize(stmt);
1577 appid = (char *)sqlite3_column_text(stmt, 0);
1578 if (!appid || !strlen(appid)) {
1579 ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
1580 sqlite3_reset(stmt);
1581 sqlite3_finalize(stmt);
1585 lb_src = (char *)sqlite3_column_text(stmt, 1);
1586 if (!lb_src || !strlen(lb_src)) {
1587 ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
1588 sqlite3_reset(stmt);
1589 sqlite3_finalize(stmt);
1593 path = strdup(lb_src);
1595 ErrPrint("Heap: %s\n", strerror(errno));
1596 sqlite3_reset(stmt);
1597 sqlite3_finalize(stmt);
1601 DbgPrint("LB Src: %s\n", path);
1603 sqlite3_reset(stmt);
1604 sqlite3_finalize(stmt);
1610 EAPI char *livebox_service_lb_script_group(const char *pkgid)
1626 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1627 if (ret != SQLITE_OK) {
1628 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1632 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1633 if (ret != SQLITE_OK) {
1634 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1635 sqlite3_finalize(stmt);
1639 ret = sqlite3_step(stmt);
1640 if (ret != SQLITE_ROW) {
1641 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1642 sqlite3_reset(stmt);
1643 sqlite3_finalize(stmt);
1647 tmp = (char *)sqlite3_column_text(stmt, 0);
1648 if (tmp && strlen(tmp)) {
1649 group = strdup(tmp);
1651 ErrPrint("Heap: %s\n", strerror(errno));
1654 sqlite3_reset(stmt);
1655 sqlite3_finalize(stmt);
1661 EAPI char *livebox_service_pd_script_path(const char *pkgid)
1678 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
1679 if (ret != SQLITE_OK) {
1680 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1684 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1685 if (ret != SQLITE_OK) {
1686 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1687 sqlite3_finalize(stmt);
1691 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1692 if (ret != SQLITE_OK) {
1693 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1694 sqlite3_finalize(stmt);
1698 ret = sqlite3_step(stmt);
1699 if (ret != SQLITE_ROW) {
1700 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1701 sqlite3_reset(stmt);
1702 sqlite3_finalize(stmt);
1706 appid = (char *)sqlite3_column_text(stmt, 0);
1707 if (!appid || !strlen(appid)) {
1708 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1709 sqlite3_reset(stmt);
1710 sqlite3_finalize(stmt);
1714 pd_src = (char *)sqlite3_column_text(stmt, 1);
1715 if (!pd_src || !strlen(pd_src)) {
1716 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1717 sqlite3_reset(stmt);
1718 sqlite3_finalize(stmt);
1722 path = strdup(pd_src);
1724 ErrPrint("Heap: %s\n", strerror(errno));
1725 sqlite3_reset(stmt);
1726 sqlite3_finalize(stmt);
1730 DbgPrint("PD Src: %s\n", path);
1731 sqlite3_reset(stmt);
1732 sqlite3_finalize(stmt);
1738 EAPI char *livebox_service_pd_script_group(const char *pkgid)
1754 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1755 if (ret != SQLITE_OK) {
1756 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1760 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1761 if (ret != SQLITE_OK) {
1762 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1763 sqlite3_finalize(stmt);
1767 ret = sqlite3_step(stmt);
1768 if (ret != SQLITE_ROW) {
1769 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1770 sqlite3_reset(stmt);
1771 sqlite3_finalize(stmt);
1775 tmp = (char *)sqlite3_column_text(stmt, 0);
1776 if (tmp && strlen(tmp)) {
1777 group = strdup(tmp);
1779 ErrPrint("Heap: %s\n", strerror(errno));
1781 sqlite3_reset(stmt);
1782 sqlite3_finalize(stmt);
1788 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
1792 const char *cluster;
1797 return LB_STATUS_ERROR_INVALID;
1801 return LB_STATUS_ERROR_IO;
1804 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
1805 if (ret != SQLITE_OK) {
1806 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1807 cnt = LB_STATUS_ERROR_IO;
1811 while (sqlite3_step(stmt) == SQLITE_ROW) {
1812 cluster = (const char *)sqlite3_column_text(stmt, 0);
1813 if (!cluster || !strlen(cluster))
1816 if (cb(cluster, data) < 0)
1822 sqlite3_reset(stmt);
1823 sqlite3_finalize(stmt);
1829 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
1833 const char *category;
1837 if (!cluster || !cb)
1838 return LB_STATUS_ERROR_INVALID;
1842 return LB_STATUS_ERROR_IO;
1844 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
1845 if (ret != SQLITE_OK) {
1846 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1847 cnt = LB_STATUS_ERROR_IO;
1852 while (sqlite3_step(stmt) == SQLITE_ROW) {
1853 category = (const char *)sqlite3_column_text(stmt, 0);
1854 if (!category || !strlen(category))
1857 if (cb(cluster, category, data) < 0)
1863 sqlite3_reset(stmt);
1864 sqlite3_finalize(stmt);
1870 EAPI int livebox_service_init(void)
1872 if (s_info.handle) {
1873 DbgPrint("Already initialized\n");
1874 s_info.init_count++;
1878 s_info.handle = open_db();
1879 if (s_info.handle) {
1880 s_info.init_count++;
1884 return LB_STATUS_ERROR_IO;
1887 EAPI int livebox_service_fini(void)
1889 if (!s_info.handle || s_info.init_count <= 0) {
1890 ErrPrint("Service is not initialized\n");
1891 return LB_STATUS_ERROR_IO;
1894 s_info.init_count--;
1895 if (s_info.init_count > 0) {
1896 DbgPrint("Init count %d\n", s_info.init_count);
1900 db_util_close(s_info.handle);
1901 s_info.handle = NULL;
1905 EAPI int livebox_service_get_size(int type, int *width, int *height)
1916 return convert_size_from_type(type, width, height);
1919 EAPI int livebox_service_size_type(int width, int height)
1923 if (update_resolution() < 0)
1924 ErrPrint("Failed to update the size list\n");
1926 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
1927 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
1933 return LB_SIZE_TYPE_1x1;
1935 return LB_SIZE_TYPE_2x1;
1937 return LB_SIZE_TYPE_2x2;
1939 return LB_SIZE_TYPE_4x1;
1941 return LB_SIZE_TYPE_4x2;
1943 return LB_SIZE_TYPE_4x3;
1945 return LB_SIZE_TYPE_4x4;
1947 return LB_SIZE_TYPE_EASY_1x1;
1949 return LB_SIZE_TYPE_EASY_3x1;
1951 return LB_SIZE_TYPE_EASY_3x3;
1953 return LB_SIZE_TYPE_0x0;
1958 return LB_SIZE_TYPE_UNKNOWN;