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_need_frame(const char *pkgid, int size_type)
868 ErrPrint("Unable to open a DB\n");
872 ret = sqlite3_prepare_v2(handle, "SELECT need_frame FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
873 if (ret != SQLITE_OK) {
874 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
881 lbid = livebox_service_pkgname(pkgid);
883 ErrPrint("Invalid appid (%s)\n", pkgid);
888 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
890 if (ret != SQLITE_OK) {
891 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
896 ret = sqlite3_bind_int(stmt, 2, size_type);
897 if (ret != SQLITE_OK) {
898 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
903 ret = sqlite3_step(stmt);
904 if (ret == SQLITE_ROW) {
905 ret = !!sqlite3_column_int(stmt, 0);
908 ErrPrint("There is no such result\n");
912 sqlite3_finalize(stmt);
917 EAPI int livebox_service_touch_effect(const char *pkgid, int size_type)
926 ErrPrint("Unable to open a DB\n");
930 ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
931 if (ret != SQLITE_OK) {
932 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
939 * This function will validate the "pkgid"
940 * call the exported API in the exported API is not recomended
943 lbid = livebox_service_pkgname(pkgid);
945 ErrPrint("Invalid appid (%s)\n", pkgid);
950 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
952 if (ret != SQLITE_OK) {
953 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
958 ret = sqlite3_bind_int(stmt, 2, size_type);
959 if (ret != SQLITE_OK) {
960 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
965 ret = sqlite3_step(stmt);
966 if (ret == SQLITE_ROW) {
967 ret = !!sqlite3_column_int(stmt, 0);
969 ret = 1; /*!< Default true: In this case the DB is corrupted. */
970 ErrPrint("There is no result\n");
975 sqlite3_finalize(stmt);
980 EAPI int livebox_service_mouse_event(const char *pkgid)
991 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
992 if (ret != SQLITE_OK) {
993 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
998 lbid = livebox_service_pkgname(pkgid);
1000 ErrPrint("Failed to get lbid: %s\n", pkgid);
1005 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1007 if (ret != SQLITE_OK) {
1008 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1013 ret = sqlite3_step(stmt);
1014 if (ret == SQLITE_ROW) {
1015 ret = !!sqlite3_column_int(stmt, 0);
1017 ret = 0; /*!< Default is false, In this case the DB is corrupted */
1018 ErrPrint("There is no result.\n");
1022 sqlite3_reset(stmt);
1023 sqlite3_finalize(stmt);
1028 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
1033 char *preview = NULL;
1039 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
1040 if (ret != SQLITE_OK) {
1041 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1046 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1047 if (ret != SQLITE_OK) {
1048 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1052 ret = sqlite3_bind_int(stmt, 2, size_type);
1053 if (ret != SQLITE_OK) {
1054 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1058 ret = sqlite3_step(stmt);
1059 if (ret == SQLITE_ROW) {
1061 tmp = (const char *)sqlite3_column_text(stmt, 0);
1062 if (tmp && strlen(tmp)) {
1063 preview = strdup(tmp);
1065 ErrPrint("Heap: %s\n", strerror(errno));
1070 sqlite3_reset(stmt);
1071 sqlite3_finalize(stmt);
1076 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
1085 language = strdup(lang);
1087 ErrPrint("Heap: %s\n", strerror(errno));
1091 language = cur_locale();
1102 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1103 if (ret != SQLITE_OK) {
1104 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1110 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1111 if (ret != SQLITE_OK) {
1112 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1116 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1117 if (ret != SQLITE_OK) {
1118 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1122 ret = sqlite3_step(stmt);
1123 if (ret == SQLITE_ROW) {
1125 tmp = (const char *)sqlite3_column_text(stmt, 0);
1126 if (!tmp || !strlen(tmp)) {
1127 icon = get_default_icon(pkgid);
1131 ErrPrint("Heap: %s\n", strerror(errno));
1134 icon = get_default_icon(pkgid);
1138 sqlite3_reset(stmt);
1139 sqlite3_finalize(stmt);
1145 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
1154 language = strdup(lang);
1156 ErrPrint("Error: %s\n", strerror(errno));
1160 language = cur_locale();
1171 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1172 if (ret != SQLITE_OK) {
1173 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1179 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1180 if (ret != SQLITE_OK) {
1181 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1185 ret = sqlite3_bind_text(stmt, 2, language, -1, SQLITE_TRANSIENT);
1186 if (ret != SQLITE_OK) {
1187 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1191 ret = sqlite3_step(stmt);
1192 if (ret == SQLITE_ROW) {
1194 tmp = (const char *)sqlite3_column_text(stmt, 0);
1195 if (!tmp || !strlen(tmp)) {
1196 name = get_default_name(pkgid);
1200 ErrPrint("Heap: %s\n", strerror(errno));
1203 name = get_default_name(pkgid);
1207 sqlite3_reset(stmt);
1208 sqlite3_finalize(stmt);
1214 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
1221 if (!w || !h || !cnt || !pkgid)
1222 return LB_STATUS_ERROR_INVALID;
1226 return LB_STATUS_ERROR_IO;
1228 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1229 if (ret != SQLITE_OK) {
1230 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1231 ret = LB_STATUS_ERROR_IO;
1235 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1236 if (ret != SQLITE_OK) {
1237 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1238 sqlite3_reset(stmt);
1239 sqlite3_finalize(stmt);
1240 ret = LB_STATUS_ERROR_IO;
1244 if (*cnt > NR_OF_SIZE_LIST)
1245 *cnt = NR_OF_SIZE_LIST;
1248 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1249 size = sqlite3_column_int(stmt, 0);
1250 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
1254 sqlite3_reset(stmt);
1255 sqlite3_finalize(stmt);
1262 EAPI char *livebox_service_libexec(const char *pkgid)
1279 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1280 if (ret != SQLITE_OK) {
1281 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1285 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1286 if (ret != SQLITE_OK) {
1287 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1288 sqlite3_finalize(stmt);
1292 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1293 if (ret != SQLITE_OK) {
1294 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1295 sqlite3_finalize(stmt);
1299 if (sqlite3_step(stmt) != SQLITE_ROW) {
1300 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1301 sqlite3_reset(stmt);
1302 sqlite3_finalize(stmt);
1304 libexec = util_conf_get_libexec(pkgid);
1305 DbgPrint("Fallback to conf checker: %s\n", libexec);
1309 appid = (char *)sqlite3_column_text(stmt, 0);
1310 if (!appid || !strlen(appid)) {
1311 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1312 sqlite3_reset(stmt);
1313 sqlite3_finalize(stmt);
1317 path = (char *)sqlite3_column_text(stmt, 1);
1318 if (!path || !strlen(path)) {
1319 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1320 sqlite3_reset(stmt);
1321 sqlite3_finalize(stmt);
1325 libexec = strdup(path);
1327 ErrPrint("Heap: %s\n", strerror(errno));
1328 sqlite3_reset(stmt);
1329 sqlite3_finalize(stmt);
1333 DbgPrint("libexec: %s\n", libexec);
1335 sqlite3_reset(stmt);
1336 sqlite3_finalize(stmt);
1342 EAPI char *livebox_service_pkgname(const char *appid)
1345 pkgmgr_appinfo_h handle;
1352 lb_pkgname = get_lb_pkgname_by_appid(appid);
1358 * Try to get the package id using given appid
1360 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1361 if (ret != PKGMGR_R_OK) {
1362 ErrPrint("Failed to get appinfo\n");
1366 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1367 if (ret != PKGMGR_R_OK) {
1368 pkgmgr_appinfo_destroy_appinfo(handle);
1369 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1373 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1374 pkgmgr_appinfo_destroy_appinfo(handle);
1376 if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
1377 return strdup(appid);
1382 EAPI char *livebox_service_provider_name(const char *lbid)
1388 char *str = SAMSUNG_PREFIX;
1393 while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
1395 if (seq < 2 && lbid[idx] == '.') {
1401 if (!str[idx] && lbid[idx]) {
1403 return strdup(lbid);
1404 } else if (seq < 2) {
1406 if (lbid[idx] == '.') {
1408 } else if (!lbid[idx]) {
1409 ErrPrint("Invalid lbid: %s\n", lbid);
1421 ret = strdup(lbid + stage);
1423 ErrPrint("Error: %s\n", strerror(errno));
1430 EAPI int livebox_service_is_enabled(const char *lbid)
1439 pkgname = livebox_service_appid(lbid);
1443 ret = ail_get_appinfo(pkgname, &ai);
1444 if (ret != AIL_ERROR_OK) {
1449 if (ail_appinfo_get_bool(ai, AIL_PROP_X_SLP_ENABLED_BOOL, &enabled) != AIL_ERROR_OK)
1452 ail_destroy_appinfo(ai);
1454 return enabled == true;
1458 EAPI int livebox_service_is_primary(const char *lbid)
1471 ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
1472 if (ret != SQLITE_OK) {
1473 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1478 ret = sqlite3_bind_text(stmt, 1, lbid, -1, SQLITE_TRANSIENT);
1479 if (ret != SQLITE_OK) {
1480 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1484 ret = sqlite3_step(stmt);
1485 if (ret != SQLITE_ROW) {
1486 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1490 ret = sqlite3_column_int(stmt, 1);
1493 sqlite3_reset(stmt);
1494 sqlite3_finalize(stmt);
1500 * appid == Package ID
1501 * pkgid == Livebox ID
1503 EAPI char *livebox_service_appid(const char *pkgname)
1509 int is_prime __attribute__((__unused__));
1520 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
1521 if (ret != SQLITE_OK) {
1522 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1526 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1527 if (ret != SQLITE_OK) {
1528 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1529 sqlite3_reset(stmt);
1530 sqlite3_finalize(stmt);
1534 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, SQLITE_TRANSIENT);
1535 if (ret != SQLITE_OK) {
1536 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1537 sqlite3_reset(stmt);
1538 sqlite3_finalize(stmt);
1542 ret = sqlite3_step(stmt);
1543 if (ret != SQLITE_ROW) {
1544 pkgmgr_appinfo_h pkg_handle;
1547 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
1548 sqlite3_reset(stmt);
1549 sqlite3_finalize(stmt);
1551 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
1552 if (ret != PKGMGR_R_OK) {
1553 ErrPrint("Failed to get appinfo: %s\n", pkgname);
1557 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
1558 if (ret != PKGMGR_R_OK) {
1559 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1560 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1564 appid = strdup(new_appid);
1566 ErrPrint("Heap: %s\n", strerror(errno));
1568 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1572 tmp = (char *)sqlite3_column_text(stmt, 0);
1573 if (!tmp || !strlen(tmp)) {
1574 ErrPrint("APPID is NIL\n");
1575 sqlite3_reset(stmt);
1576 sqlite3_finalize(stmt);
1580 appid = strdup(tmp);
1582 ErrPrint("Heap: %s\n", strerror(errno));
1583 sqlite3_reset(stmt);
1584 sqlite3_finalize(stmt);
1588 is_prime = sqlite3_column_int(stmt, 1);
1590 sqlite3_reset(stmt);
1591 sqlite3_finalize(stmt);
1597 EAPI char *livebox_service_lb_script_path(const char *pkgid)
1614 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1615 if (ret != SQLITE_OK) {
1616 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1620 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1621 if (ret != SQLITE_OK) {
1622 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1623 sqlite3_finalize(stmt);
1627 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1628 if (ret != SQLITE_OK) {
1629 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1630 sqlite3_finalize(stmt);
1634 ret = sqlite3_step(stmt);
1635 if (ret != SQLITE_ROW) {
1636 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1637 sqlite3_reset(stmt);
1638 sqlite3_finalize(stmt);
1642 appid = (char *)sqlite3_column_text(stmt, 0);
1643 if (!appid || !strlen(appid)) {
1644 ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
1645 sqlite3_reset(stmt);
1646 sqlite3_finalize(stmt);
1650 lb_src = (char *)sqlite3_column_text(stmt, 1);
1651 if (!lb_src || !strlen(lb_src)) {
1652 ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
1653 sqlite3_reset(stmt);
1654 sqlite3_finalize(stmt);
1658 path = strdup(lb_src);
1660 ErrPrint("Heap: %s\n", strerror(errno));
1661 sqlite3_reset(stmt);
1662 sqlite3_finalize(stmt);
1666 DbgPrint("LB Src: %s\n", path);
1668 sqlite3_reset(stmt);
1669 sqlite3_finalize(stmt);
1675 EAPI char *livebox_service_lb_script_group(const char *pkgid)
1691 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1692 if (ret != SQLITE_OK) {
1693 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1697 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1698 if (ret != SQLITE_OK) {
1699 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1700 sqlite3_finalize(stmt);
1704 ret = sqlite3_step(stmt);
1705 if (ret != SQLITE_ROW) {
1706 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1707 sqlite3_reset(stmt);
1708 sqlite3_finalize(stmt);
1712 tmp = (char *)sqlite3_column_text(stmt, 0);
1713 if (tmp && strlen(tmp)) {
1714 group = strdup(tmp);
1716 ErrPrint("Heap: %s\n", strerror(errno));
1719 sqlite3_reset(stmt);
1720 sqlite3_finalize(stmt);
1726 EAPI char *livebox_service_pd_script_path(const char *pkgid)
1743 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
1744 if (ret != SQLITE_OK) {
1745 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1749 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1750 if (ret != SQLITE_OK) {
1751 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1752 sqlite3_finalize(stmt);
1756 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_TRANSIENT);
1757 if (ret != SQLITE_OK) {
1758 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1759 sqlite3_finalize(stmt);
1763 ret = sqlite3_step(stmt);
1764 if (ret != SQLITE_ROW) {
1765 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1766 sqlite3_reset(stmt);
1767 sqlite3_finalize(stmt);
1771 appid = (char *)sqlite3_column_text(stmt, 0);
1772 if (!appid || !strlen(appid)) {
1773 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1774 sqlite3_reset(stmt);
1775 sqlite3_finalize(stmt);
1779 pd_src = (char *)sqlite3_column_text(stmt, 1);
1780 if (!pd_src || !strlen(pd_src)) {
1781 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1782 sqlite3_reset(stmt);
1783 sqlite3_finalize(stmt);
1787 path = strdup(pd_src);
1789 ErrPrint("Heap: %s\n", strerror(errno));
1790 sqlite3_reset(stmt);
1791 sqlite3_finalize(stmt);
1795 DbgPrint("PD Src: %s\n", path);
1796 sqlite3_reset(stmt);
1797 sqlite3_finalize(stmt);
1803 EAPI char *livebox_service_pd_script_group(const char *pkgid)
1819 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1820 if (ret != SQLITE_OK) {
1821 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1825 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_TRANSIENT);
1826 if (ret != SQLITE_OK) {
1827 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1828 sqlite3_finalize(stmt);
1832 ret = sqlite3_step(stmt);
1833 if (ret != SQLITE_ROW) {
1834 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1835 sqlite3_reset(stmt);
1836 sqlite3_finalize(stmt);
1840 tmp = (char *)sqlite3_column_text(stmt, 0);
1841 if (tmp && strlen(tmp)) {
1842 group = strdup(tmp);
1844 ErrPrint("Heap: %s\n", strerror(errno));
1846 sqlite3_reset(stmt);
1847 sqlite3_finalize(stmt);
1853 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
1857 const char *cluster;
1862 return LB_STATUS_ERROR_INVALID;
1866 return LB_STATUS_ERROR_IO;
1869 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
1870 if (ret != SQLITE_OK) {
1871 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1872 cnt = LB_STATUS_ERROR_IO;
1876 while (sqlite3_step(stmt) == SQLITE_ROW) {
1877 cluster = (const char *)sqlite3_column_text(stmt, 0);
1878 if (!cluster || !strlen(cluster))
1881 if (cb(cluster, data) < 0)
1887 sqlite3_reset(stmt);
1888 sqlite3_finalize(stmt);
1894 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
1898 const char *category;
1902 if (!cluster || !cb)
1903 return LB_STATUS_ERROR_INVALID;
1907 return LB_STATUS_ERROR_IO;
1909 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
1910 if (ret != SQLITE_OK) {
1911 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1912 cnt = LB_STATUS_ERROR_IO;
1917 while (sqlite3_step(stmt) == SQLITE_ROW) {
1918 category = (const char *)sqlite3_column_text(stmt, 0);
1919 if (!category || !strlen(category))
1922 if (cb(cluster, category, data) < 0)
1928 sqlite3_reset(stmt);
1929 sqlite3_finalize(stmt);
1935 EAPI int livebox_service_init(void)
1937 if (s_info.handle) {
1938 DbgPrint("Already initialized\n");
1939 s_info.init_count++;
1943 s_info.handle = open_db();
1944 if (s_info.handle) {
1945 s_info.init_count++;
1949 return LB_STATUS_ERROR_IO;
1952 EAPI int livebox_service_fini(void)
1954 if (!s_info.handle || s_info.init_count <= 0) {
1955 ErrPrint("Service is not initialized\n");
1956 return LB_STATUS_ERROR_IO;
1959 s_info.init_count--;
1960 if (s_info.init_count > 0) {
1961 DbgPrint("Init count %d\n", s_info.init_count);
1965 db_util_close(s_info.handle);
1966 s_info.handle = NULL;
1970 EAPI int livebox_service_get_size(int type, int *width, int *height)
1981 return convert_size_from_type(type, width, height);
1984 EAPI int livebox_service_size_type(int width, int height)
1988 if (update_resolution() < 0)
1989 ErrPrint("Failed to update the size list\n");
1991 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
1992 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
1998 return LB_SIZE_TYPE_1x1;
2000 return LB_SIZE_TYPE_2x1;
2002 return LB_SIZE_TYPE_2x2;
2004 return LB_SIZE_TYPE_4x1;
2006 return LB_SIZE_TYPE_4x2;
2008 return LB_SIZE_TYPE_4x3;
2010 return LB_SIZE_TYPE_4x4;
2012 return LB_SIZE_TYPE_EASY_1x1;
2014 return LB_SIZE_TYPE_EASY_3x1;
2016 return LB_SIZE_TYPE_EASY_3x3;
2018 return LB_SIZE_TYPE_0x0;
2023 return LB_SIZE_TYPE_UNKNOWN;