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>
41 #include "livebox-service.h"
43 #define SAMSUNG_PREFIX "com.samsung."
44 #define EAPI __attribute__((visibility("default")))
45 #define DEFAULT_TIMEOUT 2.0
48 static struct supported_size_list {
51 } SIZE_LIST[NR_OF_SIZE_LIST] = {
52 { 172, 172 }, /*!< 1x1 */
53 { 348, 172 }, /*!< 2x1 */
54 { 348, 348 }, /*!< 2x2 */
55 { 700, 172 }, /*!< 4x1 */
56 { 700, 348 }, /*!< 4x2 */
57 { 700, 520 }, /*!< 4x3 */
58 { 700, 700 }, /*!< 4x4 */
59 { 207, 207 }, /*!< 21x21 */
60 { 645, 207 }, /*!< 23x21 */
61 { 645, 645 }, /*!< 23x23 */
67 const char *conf_file;
72 .dbfile = "/opt/dbspace/.livebox.db",
73 .conf_file = "/usr/share/data-provider-master/resolution.ini",
78 static inline int update_info(int width_type, int height_type, int width, int height)
82 if (width_type == 1 && height_type == 1) {
83 DbgPrint("1x1 Updated to %dx%d\n", width, height);
85 } else if (width_type == 2 && height_type == 1) {
86 DbgPrint("2x1 Updated to %dx%d\n", width, height);
88 } else if (width_type == 2 && height_type == 2) {
89 DbgPrint("2x2 Updated to %dx%d\n", width, height);
91 } else if (width_type == 4 && height_type == 1) {
92 DbgPrint("4x1 Updated to %dx%d\n", width, height);
94 } else if (width_type == 4 && height_type == 2) {
95 DbgPrint("4x2 Updated to %dx%d\n", width, height);
97 } else if (width_type == 4 && height_type == 3) {
98 DbgPrint("4x3 Updated to %dx%d\n", width, height);
100 } else if (width_type == 4 && height_type == 4) {
101 DbgPrint("4x4 Updated to %dx%d\n", width, height);
103 } else if (width_type == 21 && height_type == 21) {
104 DbgPrint("Easy 1x1 Updated to %dx%d\n", width, height);
106 } else if (width_type == 23 && height_type == 21) {
107 DbgPrint("Easy 3x1 Updated to %dx%d\n", width, height);
109 } else if (width_type == 23 && height_type == 23) {
110 DbgPrint("Easy 3x3 Updated to %dx%d\n", width, height);
113 ErrPrint("Unknown size type: %dx%d (%dx%d)\n", width_type, height_type, width, height);
117 SIZE_LIST[idx].w = width;
118 SIZE_LIST[idx].h = height;
122 static inline int update_from_file(void)
130 char buffer[MAX_COLUMN];
144 fp = fopen(s_info.conf_file, "r");
146 ErrPrint("Open failed: %s\n", strerror(errno));
156 if (idx == MAX_COLUMN) {
157 ErrPrint("Buffer overflow. Too long line. LINE MUST BE SHOT THAN %d\n", MAX_COLUMN);
163 if (isspace(ch) || ch == EOF)
178 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
179 ErrPrint("Invalid syntax: [%s]\n", buffer);
183 } else if (ch == '=') {
186 if (sscanf(buffer, "%dx%d", &width_type, &height_type) != 2) {
187 ErrPrint("Invalid syntax: [%s]\n", buffer);
191 } else if (ch == EOF) {
192 ErrPrint("Invalid Syntax\n");
203 if (isspace(ch) || ch == EOF)
211 if (isspace(ch) || ch == EOF) {
215 if (sscanf(buffer, "%dx%d", &width, &height) != 2) {
216 ErrPrint("Invalid syntax: [%s]\n", buffer);
218 } else if (ch == EOF) {
219 updated += update_info(width_type, height_type, width, height);
226 updated += update_info(width_type, height_type, width, height);
231 if (ch == '\n' || ch == '\r' || ch == '\f')
235 if (ch == '\n' || ch == '\r' || ch == '\f')
239 ErrPrint("Unknown status. couldn't be reach to here\n");
245 return NR_OF_SIZE_LIST - updated;
248 static int update_resolution(void)
260 if (s_info.res_resolved)
263 disp = XOpenDisplay(NULL);
265 ErrPrint("Failed to open a display\n");
269 root = XDefaultRootWindow(disp);
270 if (!XGetGeometry(disp, root, &dummy, &x, &y, &width, &height, &border, &depth)) {
275 if (update_from_file() == 0)
276 DbgPrint("Resolution info is all updated by file\n");
278 DbgPrint("Screen resolution: %dx%d\n", width, height);
279 for (i = 0; i < NR_OF_SIZE_LIST; i++) {
280 SIZE_LIST[i].w = (unsigned int)((double)SIZE_LIST[i].w * (double)width / 720.0f);
281 SIZE_LIST[i].h = (unsigned int)((double)SIZE_LIST[i].h * (double)width / 720.0f);
282 DbgPrint("(Ratio)Size is updated [%d] %dx%d\n", i, SIZE_LIST[i].w, SIZE_LIST[i].h);
286 s_info.res_resolved = 1;
290 static inline sqlite3 *open_db(void)
294 if (!s_info.handle) {
297 ret = db_util_open(s_info.dbfile, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
298 if (ret != SQLITE_OK) {
299 ErrPrint("Failed to open a DB\n");
303 handle = s_info.handle;
309 static inline void close_db(sqlite3 *handle)
312 db_util_close(handle);
315 static inline int convert_size_from_type(enum livebox_size_type type, int *width, int *height)
320 case LB_SIZE_TYPE_1x1: /*!< 172x172 */
323 case LB_SIZE_TYPE_2x1: /*!< 348x172 */
326 case LB_SIZE_TYPE_2x2: /*!< 348x348 */
329 case LB_SIZE_TYPE_4x1: /*!< 700x172 */
332 case LB_SIZE_TYPE_4x2: /*!< 700x348 */
335 case LB_SIZE_TYPE_4x3: /*!< 700x520 */
338 case LB_SIZE_TYPE_4x4: /*!< 700x700 */
341 case LB_SIZE_TYPE_EASY_1x1: /*< 207x207 */
344 case LB_SIZE_TYPE_EASY_3x1: /*!< 645x207 */
347 case LB_SIZE_TYPE_EASY_3x3: /*!< 645x645 */
354 if (update_resolution() < 0)
355 ErrPrint("Failed to update resolution\n");
357 *width = SIZE_LIST[idx].w;
358 *height = SIZE_LIST[idx].h;
362 EAPI int livebox_service_change_period(const char *pkgname, const char *id, double period)
364 struct packet *packet;
365 struct packet *result;
368 if (!pkgname || !id || period < 0.0f) {
369 ErrPrint("Invalid argument\n");
376 packet = packet_create("service_change_period", "ssd", pkgname, id, period);
378 ErrPrint("Failed to create a packet for period changing\n");
382 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
383 packet_unref(packet);
386 if (packet_get(result, "i", &ret) != 1) {
387 ErrPrint("Failed to parse a result packet\n");
390 packet_unref(result);
392 ErrPrint("Failed to get result packet\n");
399 EAPI int livebox_service_trigger_update(const char *pkgname, const char *id, const char *cluster, const char *category, int force)
401 struct packet *packet;
402 struct packet *result;
406 ErrPrint("Invalid argument\n");
410 if (!force && access("/tmp/.live.paused", R_OK) == 0) {
411 DbgPrint("Provider is paused\n");
419 cluster = "user,created";
422 category = "default";
424 packet = packet_create("service_update", "ssss", pkgname, id, cluster, category);
426 ErrPrint("Failed to create a packet for service_update\n");
430 result = com_core_packet_oneshot_send(SERVICE_SOCKET, packet, DEFAULT_TIMEOUT);
431 packet_unref(packet);
434 if (packet_get(result, "i", &ret) != 1) {
435 ErrPrint("Failed to parse a result packet\n");
439 packet_unref(result);
441 ErrPrint("Failed to get result packet\n");
448 EAPI int livebox_service_get_pkglist(int (*cb)(const char *appid, const char *pkgname, int is_prime, void *data), void *data)
464 ret = sqlite3_prepare_v2(handle, "SELECT appid, pkgid, prime FROM pkgmap", -1, &stmt, NULL);
465 if (ret != SQLITE_OK) {
466 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
472 while (sqlite3_step(stmt) == SQLITE_ROW) {
473 appid = (char *)sqlite3_column_text(stmt, 0);
474 if (!appid || !strlen(appid)) {
475 ErrPrint("APPID is not valid\n");
479 pkgid = (char *)sqlite3_column_text(stmt, 1);
480 if (!pkgid || !strlen(pkgid)) {
481 ErrPrint("pkgid is not valid\n");
485 is_prime = sqlite3_column_int(stmt, 2);
489 if (cb(appid, pkgid, is_prime, data) < 0) {
490 DbgPrint("Callback stopped package crawling\n");
496 sqlite3_finalize(stmt);
503 EAPI int livebox_service_get_supported_size_types(const char *pkgid, int *cnt, int *types)
510 if (!types || !cnt || !pkgid)
517 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
518 if (ret != SQLITE_OK) {
519 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
524 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
525 if (ret != SQLITE_OK) {
526 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
528 sqlite3_finalize(stmt);
533 if (*cnt > NR_OF_SIZE_LIST)
534 *cnt = NR_OF_SIZE_LIST;
537 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
538 size = sqlite3_column_int(stmt, 0);
545 sqlite3_finalize(stmt);
552 static inline char *cur_locale(void)
555 language = vconf_get_str(VCONFKEY_LANGSET);
572 language = strdup("en-us");
574 ErrPrint("Heap: %s\n", strerror(errno));
580 static inline char *get_default_name(const char *pkgid)
591 ret = sqlite3_prepare_v2(handle, "SELECT name FROM client WHERE pkgid = ?", -1, &stmt, NULL);
592 if (ret != SQLITE_OK) {
593 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
598 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
599 if (ret != SQLITE_OK) {
600 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
604 ret = sqlite3_step(stmt);
605 if (ret == SQLITE_ROW) {
608 tmp = (const char *)sqlite3_column_text(stmt, 0);
609 if (tmp && strlen(tmp)) {
612 ErrPrint("Heap: %s\n", strerror(errno));
618 sqlite3_finalize(stmt);
623 static inline char *get_default_icon(const char *pkgid)
634 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM client WHERE pkgid = ?", -1, &stmt, NULL);
635 if (ret != SQLITE_OK) {
636 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
641 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
642 if (ret != SQLITE_OK) {
643 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
647 ret = sqlite3_step(stmt);
648 if (ret == SQLITE_ROW) {
651 tmp = (const char *)sqlite3_column_text(stmt, 0);
652 if (tmp && strlen(tmp)) {
655 ErrPrint("Heap: %s\n", strerror(errno));
661 sqlite3_finalize(stmt);
666 EAPI char *livebox_service_content(const char *pkgid)
670 char *content = NULL;
677 ret = sqlite3_prepare_v2(handle, "SELECT content FROM client WHERE pkgid = ?", -1, &stmt, NULL);
678 if (ret != SQLITE_OK) {
679 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
684 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
685 if (ret != SQLITE_OK) {
686 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
690 ret = sqlite3_step(stmt);
691 if (ret == SQLITE_ROW) {
694 tmp = (const char *)sqlite3_column_text(stmt, 0);
695 if (tmp && strlen(tmp)) {
696 content = strdup(tmp);
698 ErrPrint("Heap: %s\n", strerror(errno));
704 sqlite3_finalize(stmt);
709 EAPI char *livebox_service_setup_appid(const char *lbid)
720 ret = sqlite3_prepare_v2(handle, "SELECT setup FROM client WHERE pkgid = ?", -1, &stmt, NULL);
721 if (ret != SQLITE_OK) {
722 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
728 ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
729 if (ret != SQLITE_OK) {
730 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
734 ret = sqlite3_step(stmt);
735 if (ret == SQLITE_ROW) {
738 tmp = (const char *)sqlite3_column_text(stmt, 0);
739 if (!tmp || !strlen(tmp))
744 ErrPrint("Error: %s\n", strerror(errno));
749 sqlite3_finalize(stmt);
754 EAPI int livebox_service_nodisplay(const char *pkgid)
764 ret = sqlite3_prepare_v2(handle, "SELECT nodisplay FROM client WHERE pkgid = ?", -1, &stmt, NULL);
765 if (ret != SQLITE_OK) {
766 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
771 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
772 if (ret != SQLITE_OK) {
773 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
778 ret = sqlite3_step(stmt);
779 if (ret == SQLITE_ROW)
780 ret = !!sqlite3_column_int(stmt, 0);
786 sqlite3_finalize(stmt);
791 static inline char *get_lb_pkgname_by_appid(const char *appid)
807 ret = sqlite3_prepare_v2(handle, "SELECT pkgid FROM pkgmap WHERE (appid = ? AND prime = 1) OR pkgid = ?", -1, &stmt, NULL);
808 if (ret != SQLITE_OK) {
809 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
814 ret = sqlite3_bind_text(stmt, 1, appid, -1, NULL);
815 if (ret != SQLITE_OK) {
816 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
820 ret = sqlite3_bind_text(stmt, 2, appid, -1, NULL);
821 if (ret != SQLITE_OK) {
822 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
826 if (sqlite3_step(stmt) != SQLITE_ROW) {
827 ErrPrint("Error: %s (has no record? - %s)\n", sqlite3_errmsg(handle), appid);
831 tmp = (char *)sqlite3_column_text(stmt, 0);
832 if (tmp && strlen(tmp)) {
835 ErrPrint("Heap: %s\n", strerror(errno));
840 sqlite3_finalize(stmt);
845 EAPI int livebox_service_touch_effect(const char *pkgid)
854 ErrPrint("Unable to open a DB\n");
858 ret = sqlite3_prepare_v2(handle, "SELECT touch_effect FROM client WHERE pkgid = ?", -1, &stmt, NULL);
859 if (ret != SQLITE_OK) {
860 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
867 * This function will validate the "pkgid"
868 * call the exported API in the exported API is not recomended
871 lbid = livebox_service_pkgname(pkgid);
873 ErrPrint("Invalid appid (%s)\n", pkgid);
878 ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
880 if (ret != SQLITE_OK) {
881 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
886 ret = sqlite3_step(stmt);
887 if (ret == SQLITE_ROW) {
888 ret = !!sqlite3_column_int(stmt, 0);
890 ret = 1; /*!< Default true: In this case the DB is corrupted. */
891 ErrPrint("There is no result\n");
896 sqlite3_finalize(stmt);
901 EAPI int livebox_service_mouse_event(const char *pkgid)
912 ret = sqlite3_prepare_v2(handle, "SELECT mouse_event FROM client WHERE pkgid = ?", -1, &stmt, NULL);
913 if (ret != SQLITE_OK) {
914 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
919 lbid = livebox_service_pkgname(pkgid);
921 ErrPrint("Failed to get lbid: %s\n", pkgid);
926 ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
928 if (ret != SQLITE_OK) {
929 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
934 ret = sqlite3_step(stmt);
935 if (ret == SQLITE_ROW) {
936 ret = !!sqlite3_column_int(stmt, 0);
938 ret = 0; /*!< Default is false, In this case the DB is corrupted */
939 ErrPrint("There is no result.\n");
944 sqlite3_finalize(stmt);
949 EAPI char *livebox_service_preview(const char *pkgid, int size_type)
954 char *preview = NULL;
960 ret = sqlite3_prepare_v2(handle, "SELECT preview FROM box_size WHERE pkgid = ? AND size_type = ?", -1, &stmt, NULL);
961 if (ret != SQLITE_OK) {
962 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
967 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
968 if (ret != SQLITE_OK) {
969 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
973 ret = sqlite3_bind_int(stmt, 2, size_type);
974 if (ret != SQLITE_OK) {
975 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
979 ret = sqlite3_step(stmt);
980 if (ret == SQLITE_ROW) {
982 tmp = (const char *)sqlite3_column_text(stmt, 0);
983 if (tmp && strlen(tmp)) {
984 preview = strdup(tmp);
986 ErrPrint("Heap: %s\n", strerror(errno));
992 sqlite3_finalize(stmt);
997 EAPI char *livebox_service_i18n_icon(const char *pkgid, const char *lang)
1006 language = strdup(lang);
1008 ErrPrint("Heap: %s\n", strerror(errno));
1012 language = cur_locale();
1023 ret = sqlite3_prepare_v2(handle, "SELECT icon FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1024 if (ret != SQLITE_OK) {
1025 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1031 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1032 if (ret != SQLITE_OK) {
1033 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1037 ret = sqlite3_bind_text(stmt, 2, language, -1, NULL);
1038 if (ret != SQLITE_OK) {
1039 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1043 ret = sqlite3_step(stmt);
1044 if (ret == SQLITE_ROW) {
1046 tmp = (const char *)sqlite3_column_text(stmt, 0);
1047 if (!tmp || !strlen(tmp)) {
1048 icon = get_default_icon(pkgid);
1052 ErrPrint("Heap: %s\n", strerror(errno));
1055 icon = get_default_icon(pkgid);
1059 sqlite3_reset(stmt);
1060 sqlite3_finalize(stmt);
1066 EAPI char *livebox_service_i18n_name(const char *pkgid, const char *lang)
1075 language = strdup(lang);
1077 ErrPrint("Error: %s\n", strerror(errno));
1081 language = cur_locale();
1092 ret = sqlite3_prepare_v2(handle, "SELECT name FROM i18n WHERE pkgid = ? AND lang = ?", -1, &stmt, NULL);
1093 if (ret != SQLITE_OK) {
1094 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1100 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1101 if (ret != SQLITE_OK) {
1102 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1106 ret = sqlite3_bind_text(stmt, 2, language, -1, NULL);
1107 if (ret != SQLITE_OK) {
1108 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1112 ret = sqlite3_step(stmt);
1113 if (ret == SQLITE_ROW) {
1115 tmp = (const char *)sqlite3_column_text(stmt, 0);
1116 if (!tmp || !strlen(tmp)) {
1117 name = get_default_name(pkgid);
1121 ErrPrint("Heap: %s\n", strerror(errno));
1124 name = get_default_name(pkgid);
1128 sqlite3_reset(stmt);
1129 sqlite3_finalize(stmt);
1135 EAPI int livebox_service_get_supported_sizes(const char *pkgid, int *cnt, int *w, int *h)
1142 if (!w || !h || !cnt || !pkgid)
1149 ret = sqlite3_prepare_v2(handle, "SELECT size_type FROM box_size WHERE pkgid = ? ORDER BY size_type ASC", -1, &stmt, NULL);
1150 if (ret != SQLITE_OK) {
1151 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1156 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1157 if (ret != SQLITE_OK) {
1158 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1159 sqlite3_reset(stmt);
1160 sqlite3_finalize(stmt);
1165 if (*cnt > NR_OF_SIZE_LIST)
1166 *cnt = NR_OF_SIZE_LIST;
1169 while (sqlite3_step(stmt) == SQLITE_ROW && ret < *cnt) {
1170 size = sqlite3_column_int(stmt, 0);
1171 ret += (convert_size_from_type(size, w + ret, h + ret) == 0);
1175 sqlite3_reset(stmt);
1176 sqlite3_finalize(stmt);
1183 EAPI char *livebox_service_libexec(const char *pkgid)
1200 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.libexec FROM pkgmap, provider WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1201 if (ret != SQLITE_OK) {
1202 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1206 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1207 if (ret != SQLITE_OK) {
1208 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1209 sqlite3_finalize(stmt);
1213 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1214 if (ret != SQLITE_OK) {
1215 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1216 sqlite3_finalize(stmt);
1220 if (sqlite3_step(stmt) != SQLITE_ROW) {
1221 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1222 sqlite3_reset(stmt);
1223 sqlite3_finalize(stmt);
1225 libexec = util_conf_get_libexec(pkgid);
1226 DbgPrint("Fallback to conf checker: %s\n", libexec);
1230 appid = (char *)sqlite3_column_text(stmt, 0);
1231 if (!appid || !strlen(appid)) {
1232 ErrPrint("Invalid appid: %s\n", sqlite3_errmsg(handle));
1233 sqlite3_reset(stmt);
1234 sqlite3_finalize(stmt);
1238 path = (char *)sqlite3_column_text(stmt, 1);
1239 if (!path || !strlen(path)) {
1240 ErrPrint("Invalid libexec: %s\n", sqlite3_errmsg(handle));
1241 sqlite3_reset(stmt);
1242 sqlite3_finalize(stmt);
1246 libexec = strdup(path);
1248 ErrPrint("Heap: %s\n", strerror(errno));
1249 sqlite3_reset(stmt);
1250 sqlite3_finalize(stmt);
1254 DbgPrint("libexec: %s\n", libexec);
1256 sqlite3_reset(stmt);
1257 sqlite3_finalize(stmt);
1263 EAPI char *livebox_service_pkgname(const char *appid)
1266 pkgmgr_appinfo_h handle;
1273 lb_pkgname = get_lb_pkgname_by_appid(appid);
1279 * Try to get the package id using given appid
1281 ret = pkgmgr_appinfo_get_appinfo(appid, &handle);
1282 if (ret != PKGMGR_R_OK) {
1283 ErrPrint("Failed to get appinfo\n");
1287 ret = pkgmgr_appinfo_get_pkgname(handle, &new_appid);
1288 if (ret != PKGMGR_R_OK) {
1289 pkgmgr_appinfo_destroy_appinfo(handle);
1290 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1294 lb_pkgname = get_lb_pkgname_by_appid(new_appid);
1295 pkgmgr_appinfo_destroy_appinfo(handle);
1297 if (!lb_pkgname && util_validate_livebox_package(appid) == 0)
1298 return strdup(appid);
1303 EAPI char *livebox_service_provider_name(const char *lbid)
1309 char *str = SAMSUNG_PREFIX;
1314 while (str[idx] && lbid[idx] && lbid[idx] == str[idx]) {
1316 if (seq < 2 && lbid[idx] == '.') {
1322 if (!str[idx] && lbid[idx]) {
1324 return strdup(lbid);
1325 } else if (seq < 2) {
1327 if (lbid[idx] == '.') {
1329 } else if (!lbid[idx]) {
1330 ErrPrint("Invalid lbid: %s\n", lbid);
1342 ret = strdup(lbid + stage);
1344 ErrPrint("Error: %s\n", strerror(errno));
1351 EAPI int livebox_service_is_enabled(const char *lbid)
1360 pkgname = livebox_service_appid(lbid);
1364 ret = ail_get_appinfo(pkgname, &ai);
1365 if (ret != AIL_ERROR_OK) {
1370 if (ail_appinfo_get_bool(ai, AIL_PROP_X_SLP_ENABLED_BOOL, &enabled) != AIL_ERROR_OK)
1373 ail_destroy_appinfo(ai);
1375 return enabled == true;
1379 EAPI int livebox_service_is_primary(const char *lbid)
1392 ret = sqlite3_prepare_v2(handle, "SELECT prime FROM pkgmap WHERE pkgid = ?", -1, &stmt, NULL);
1393 if (ret != SQLITE_OK) {
1394 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1399 ret = sqlite3_bind_text(stmt, 1, lbid, -1, NULL);
1400 if (ret != SQLITE_OK) {
1401 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1405 ret = sqlite3_step(stmt);
1406 if (ret != SQLITE_ROW) {
1407 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1411 ret = sqlite3_column_int(stmt, 1);
1414 sqlite3_reset(stmt);
1415 sqlite3_finalize(stmt);
1421 * appid == Package ID
1422 * pkgid == Livebox ID
1424 EAPI char *livebox_service_appid(const char *pkgname)
1430 int is_prime __attribute__((__unused__));
1441 ret = sqlite3_prepare_v2(handle, "SELECT appid, prime FROM pkgmap WHERE pkgid = ? OR appid = ?", -1, &stmt, NULL);
1442 if (ret != SQLITE_OK) {
1443 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1447 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, NULL);
1448 if (ret != SQLITE_OK) {
1449 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1450 sqlite3_reset(stmt);
1451 sqlite3_finalize(stmt);
1455 ret = sqlite3_bind_text(stmt, 2, pkgname, -1, NULL);
1456 if (ret != SQLITE_OK) {
1457 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1458 sqlite3_reset(stmt);
1459 sqlite3_finalize(stmt);
1463 ret = sqlite3_step(stmt);
1464 if (ret != SQLITE_ROW) {
1465 pkgmgr_appinfo_h pkg_handle;
1468 ErrPrint("Has no record?: %s\n", sqlite3_errmsg(handle));
1469 sqlite3_reset(stmt);
1470 sqlite3_finalize(stmt);
1472 ret = pkgmgr_appinfo_get_appinfo(pkgname, &pkg_handle);
1473 if (ret != PKGMGR_R_OK) {
1474 ErrPrint("Failed to get appinfo: %s\n", pkgname);
1478 ret = pkgmgr_appinfo_get_pkgname(pkg_handle, &new_appid);
1479 if (ret != PKGMGR_R_OK) {
1480 ErrPrint("Failed to get pkgname for (%s)\n", appid);
1481 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1485 appid = strdup(new_appid);
1487 ErrPrint("Heap: %s\n", strerror(errno));
1489 pkgmgr_appinfo_destroy_appinfo(pkg_handle);
1493 tmp = (char *)sqlite3_column_text(stmt, 0);
1494 if (!tmp || !strlen(tmp)) {
1495 ErrPrint("APPID is NIL\n");
1496 sqlite3_reset(stmt);
1497 sqlite3_finalize(stmt);
1501 appid = strdup(tmp);
1503 ErrPrint("Heap: %s\n", strerror(errno));
1504 sqlite3_reset(stmt);
1505 sqlite3_finalize(stmt);
1509 is_prime = sqlite3_column_int(stmt, 1);
1511 sqlite3_reset(stmt);
1512 sqlite3_finalize(stmt);
1518 EAPI char *livebox_service_lb_script_path(const char *pkgid)
1535 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.box_src FROM provider, pkgmap WHERE pkgmap.pkgid = ? AND provider.pkgid = ?", -1, &stmt, NULL);
1536 if (ret != SQLITE_OK) {
1537 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1541 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1542 if (ret != SQLITE_OK) {
1543 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1544 sqlite3_finalize(stmt);
1548 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1549 if (ret != SQLITE_OK) {
1550 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1551 sqlite3_finalize(stmt);
1555 ret = sqlite3_step(stmt);
1556 if (ret != SQLITE_ROW) {
1557 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1558 sqlite3_reset(stmt);
1559 sqlite3_finalize(stmt);
1563 appid = (char *)sqlite3_column_text(stmt, 0);
1564 if (!appid || !strlen(appid)) {
1565 ErrPrint("Invalid appid : %s\n", sqlite3_errmsg(handle));
1566 sqlite3_reset(stmt);
1567 sqlite3_finalize(stmt);
1571 lb_src = (char *)sqlite3_column_text(stmt, 1);
1572 if (!lb_src || !strlen(lb_src)) {
1573 ErrPrint("No records for lb src : %s\n", sqlite3_errmsg(handle));
1574 sqlite3_reset(stmt);
1575 sqlite3_finalize(stmt);
1579 path = strdup(lb_src);
1581 ErrPrint("Heap: %s\n", strerror(errno));
1582 sqlite3_reset(stmt);
1583 sqlite3_finalize(stmt);
1587 DbgPrint("LB Src: %s\n", path);
1589 sqlite3_reset(stmt);
1590 sqlite3_finalize(stmt);
1596 EAPI char *livebox_service_lb_script_group(const char *pkgid)
1612 ret = sqlite3_prepare_v2(handle, "SELECT box_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1613 if (ret != SQLITE_OK) {
1614 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1618 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1619 if (ret != SQLITE_OK) {
1620 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1621 sqlite3_finalize(stmt);
1625 ret = sqlite3_step(stmt);
1626 if (ret != SQLITE_ROW) {
1627 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1628 sqlite3_reset(stmt);
1629 sqlite3_finalize(stmt);
1633 tmp = (char *)sqlite3_column_text(stmt, 0);
1634 if (tmp && strlen(tmp)) {
1635 group = strdup(tmp);
1637 ErrPrint("Heap: %s\n", strerror(errno));
1640 sqlite3_reset(stmt);
1641 sqlite3_finalize(stmt);
1647 EAPI char *livebox_service_pd_script_path(const char *pkgid)
1664 ret = sqlite3_prepare_v2(handle, "SELECT pkgmap.appid, provider.pd_src FROM provider, pkgmap WHERE provider.pkgid = ? AND pkgmap.pkgid = ?", -1, &stmt, NULL);
1665 if (ret != SQLITE_OK) {
1666 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1670 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1671 if (ret != SQLITE_OK) {
1672 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1673 sqlite3_finalize(stmt);
1677 ret = sqlite3_bind_text(stmt, 2, pkgid, -1, NULL);
1678 if (ret != SQLITE_OK) {
1679 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1680 sqlite3_finalize(stmt);
1684 ret = sqlite3_step(stmt);
1685 if (ret != SQLITE_ROW) {
1686 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1687 sqlite3_reset(stmt);
1688 sqlite3_finalize(stmt);
1692 appid = (char *)sqlite3_column_text(stmt, 0);
1693 if (!appid || !strlen(appid)) {
1694 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1695 sqlite3_reset(stmt);
1696 sqlite3_finalize(stmt);
1700 pd_src = (char *)sqlite3_column_text(stmt, 1);
1701 if (!pd_src || !strlen(pd_src)) {
1702 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1703 sqlite3_reset(stmt);
1704 sqlite3_finalize(stmt);
1708 path = strdup(pd_src);
1710 ErrPrint("Heap: %s\n", strerror(errno));
1711 sqlite3_reset(stmt);
1712 sqlite3_finalize(stmt);
1716 DbgPrint("PD Src: %s\n", path);
1717 sqlite3_reset(stmt);
1718 sqlite3_finalize(stmt);
1724 EAPI char *livebox_service_pd_script_group(const char *pkgid)
1740 ret = sqlite3_prepare_v2(handle, "SELECT pd_group FROM provider WHERE pkgid = ?", -1, &stmt, NULL);
1741 if (ret != SQLITE_OK) {
1742 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1746 ret = sqlite3_bind_text(stmt, 1, pkgid, -1, NULL);
1747 if (ret != SQLITE_OK) {
1748 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1749 sqlite3_finalize(stmt);
1753 ret = sqlite3_step(stmt);
1754 if (ret != SQLITE_ROW) {
1755 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1756 sqlite3_reset(stmt);
1757 sqlite3_finalize(stmt);
1761 tmp = (char *)sqlite3_column_text(stmt, 0);
1762 if (tmp && strlen(tmp)) {
1763 group = strdup(tmp);
1765 ErrPrint("Heap: %s\n", strerror(errno));
1767 sqlite3_reset(stmt);
1768 sqlite3_finalize(stmt);
1774 EAPI int livebox_service_enumerate_cluster_list(int (*cb)(const char *cluster, void *data), void *data)
1778 const char *cluster;
1790 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT cluster FROM groupinfo", -1, &stmt, NULL);
1791 if (ret != SQLITE_OK) {
1792 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1797 while (sqlite3_step(stmt) == SQLITE_ROW) {
1798 cluster = (const char *)sqlite3_column_text(stmt, 0);
1799 if (!cluster || !strlen(cluster))
1802 if (cb(cluster, data) < 0)
1808 sqlite3_reset(stmt);
1809 sqlite3_finalize(stmt);
1815 EAPI int livebox_service_enumerate_category_list(const char *cluster, int (*cb)(const char *cluster, const char *category, void *data), void *data)
1819 const char *category;
1823 if (!cluster || !cb)
1830 ret = sqlite3_prepare_v2(handle, "SELECT DISTINCT category FROM groupinfo WHERE cluster = ?", -1, &stmt, NULL);
1831 if (ret != SQLITE_OK) {
1832 ErrPrint("Error: %s\n", sqlite3_errmsg(handle));
1838 while (sqlite3_step(stmt) == SQLITE_ROW) {
1839 category = (const char *)sqlite3_column_text(stmt, 0);
1840 if (!category || !strlen(category))
1843 if (cb(cluster, category, data) < 0)
1849 sqlite3_reset(stmt);
1850 sqlite3_finalize(stmt);
1856 EAPI int livebox_service_init(void)
1858 if (s_info.handle) {
1859 DbgPrint("Already initialized\n");
1860 s_info.init_count++;
1864 s_info.handle = open_db();
1865 if (s_info.handle) {
1866 s_info.init_count++;
1873 EAPI int livebox_service_fini(void)
1875 if (!s_info.handle || s_info.init_count <= 0) {
1876 ErrPrint("Service is not initialized\n");
1880 s_info.init_count--;
1881 if (s_info.init_count > 0) {
1882 DbgPrint("Init count %d\n", s_info.init_count);
1886 db_util_close(s_info.handle);
1887 s_info.handle = NULL;
1891 EAPI int livebox_service_get_size(int type, int *width, int *height)
1902 return convert_size_from_type(type, width, height);
1905 EAPI int livebox_service_size_type(int width, int height)
1909 if (update_resolution() < 0)
1910 ErrPrint("Failed to update the size list\n");
1912 for (idx = 0; idx < NR_OF_SIZE_LIST; idx++) {
1913 if (SIZE_LIST[idx].w == width && SIZE_LIST[idx].h == height)
1919 return LB_SIZE_TYPE_1x1;
1921 return LB_SIZE_TYPE_2x1;
1923 return LB_SIZE_TYPE_2x2;
1925 return LB_SIZE_TYPE_4x1;
1927 return LB_SIZE_TYPE_4x2;
1929 return LB_SIZE_TYPE_4x3;
1931 return LB_SIZE_TYPE_4x4;
1933 return LB_SIZE_TYPE_EASY_1x1;
1935 return LB_SIZE_TYPE_EASY_3x1;
1937 return LB_SIZE_TYPE_EASY_3x3;
1942 return LB_SIZE_TYPE_UNKNOWN;