INSTALL(FILES ${CMAKE_SOURCE_DIR}/desktop.conf DESTINATION share/install-info)
# AIL init database
-ADD_SUBDIRECTORY(initdb)
-
+ADD_SUBDIRECTORY(tool)
#define AIL_PROP_X_SLP_PKGID_STR "AIL_PROP_X_SLP_PKGID_STR"
#define AIL_PROP_X_SLP_DOMAIN_STR "AIL_PROP_X_SLP_DOMAIN_STR"
#define AIL_PROP_X_SLP_SUBMODEMAINID_STR "AIL_PROP_X_SLP_SUBMODEMAINID_STR"
+#define AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR "AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR"
/**
* @brief integer type properties
snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
for (i = 0; files[i]; i++) {
- ret = chown(files[i], OWNER_ROOT, GROUP_MENU);
+ ret = chown(files[i], OWNER_ROOT, OWNER_ROOT);
if (ret == -1) {
strerror_r(errno, buf, sizeof(buf));
- _E("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, GROUP_MENU, buf);
+ _E("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, OWNER_ROOT, buf);
return AIL_ERROR_FAIL;
}
- ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+ ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (ret == -1) {
strerror_r(errno, buf, sizeof(buf));
_E("FAIL : chmod %s 0664, because %s", db_file, buf);
Name: ail
-Version: 0.2.73
+Version: 0.2.80
Release: 1
License: Apache-2.0
Summary: Application Information Library
%build
CFLAGS+=" -fpic"
+
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS ?DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+%endif
+
%cmake . -DBUILD_PKGTYPE=rpm \
-DSMACK=Off
fi
}
ail_initdb
+mkdir -p /usr/share/applications
+mkdir -p /opt/share/applications
+mkdir -p /opt/dbspace/
+
update_DAC_for_db_file /opt/dbspace/.app_info.db
update_DAC_for_db_file /opt/dbspace/.app_info.db-journal
%{_datadir}/install-info/*
%{_libdir}/libail.so.0
%{_libdir}/libail.so.0.1.0
-
+/usr/bin/ail_initdb
+/usr/bin/ail_fota
+/usr/bin/ail_desktop
+/usr/bin/ail_filter
+/usr/bin/ail_package
+/usr/share/install-info/*
%files devel
%manifest %{name}.manifest
{E_AIL_PROP_X_SLP_APPID_STR, AIL_PROP_X_SLP_APPID_STR},
{E_AIL_PROP_X_SLP_PKGID_STR, AIL_PROP_X_SLP_PKGID_STR},
{E_AIL_PROP_X_SLP_DOMAIN_STR, AIL_PROP_X_SLP_DOMAIN_STR},
- {E_AIL_PROP_X_SLP_SUBMODEMAINID_STR, AIL_PROP_X_SLP_SUBMODEMAINID_STR}
+ {E_AIL_PROP_X_SLP_SUBMODEMAINID_STR, AIL_PROP_X_SLP_SUBMODEMAINID_STR},
+ {E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR, AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR}
};
if(mode & DB_OPEN_RO) {
if (!db_info.dbro) {
- ret = db_util_open_with_options(APP_INFO_DB, &db_info.dbro, SQLITE_OPEN_READONLY, NULL);
+ //ret = db_util_open_with_options(APP_INFO_DB, &db_info.dbro, SQLITE_OPEN_READONLY, NULL);
+ ret = db_util_open(APP_INFO_DB, &db_info.dbro, 0);
retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
}
}
if(mode & DB_OPEN_RW) {
if (!db_info.dbrw) {
- ret = db_util_open(APP_INFO_DB, &db_info.dbrw, DB_UTIL_REGISTER_HOOK_METHOD);
+ ret = db_util_open(APP_INFO_DB, &db_info.dbrw, 0);
retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
}
}
char* x_slp_pkgid;
char* x_slp_domain;
char* x_slp_submodemainid;
+ char* x_slp_installedstorage;
int x_slp_baselayoutwidth;
int x_slp_installedtime;
int nodisplay;
package = _get_package_from_icon(icon);
retv_if(!package, NULL);
+/* "db/setting/theme" is not exist */
+#if 0
theme = vconf_get_str("db/setting/theme");
if (!theme) {
theme = strdup("default");
return NULL;
}
}
+#else
+ theme = strdup("default");
+#endif
len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
icon_with_path = malloc(len);
return AIL_ERROR_OK;
}
+static ail_error_e _read_x_slp_installedstorage(void *data, char *tag, char *value)
+{
+ desktop_info_s *info = data;
+
+ retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
+ retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
+
+ SAFE_FREE_AND_STRDUP(value, info->x_slp_installedstorage);
+ retv_if(!info->x_slp_installedstorage, AIL_ERROR_OUT_OF_MEMORY);
+
+ return AIL_ERROR_OK;
+}
static ail_error_e _read_x_slp_uri(void *data, char *tag, char *value)
{
.value_cb = _read_x_slp_submodemainid,
},
{
+ .field = "x-tizen-installedstorage",
+ .value_cb = _read_x_slp_installedstorage,
+ },
+ {
.field = "x-tizen-uri",
.value_cb = _read_x_slp_uri,
},
if (info->x_slp_appid) len += strlen(info->x_slp_appid);
if (info->desktop) len += strlen(info->desktop);
if (info->x_slp_submodemainid) len += strlen(info->x_slp_submodemainid);
+ if (info->x_slp_installedstorage) len += strlen(info->x_slp_installedstorage);
return len;
}
SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_PKGID_STR], info->x_slp_pkgid);
SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_DOMAIN_STR], info->x_slp_domain);
SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_SUBMODEMAINID_STR], info->x_slp_submodemainid);
+ SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR], info->x_slp_installedstorage);
info->x_slp_installedtime = atoi(values[E_AIL_PROP_X_SLP_INSTALLEDTIME_INT]);
SAFE_FREE_AND_STRDUP(value, info->x_slp_svc);
retv_if (!info->x_slp_svc, AIL_ERROR_OUT_OF_MEMORY);
break;
+ case E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR:
+ SAFE_FREE_AND_STRDUP(value, info->x_slp_installedstorage);
+ retv_if (!info->x_slp_installedstorage, AIL_ERROR_OUT_OF_MEMORY);
+ break;
default:
+ _E("prop[%d] is not defined\n", prop);
return AIL_ERROR_FAIL;
}
"x_slp_pkgid TEXT, "
"x_slp_domain TEXT, "
"x_slp_submodemainid TEXT, "
+ "x_slp_installedstorage TEXT, "
"x_slp_baselayoutwidth INTEGER DEFAULT 0, "
"x_slp_installedtime INTEGER DEFAULT 0, "
"nodisplay INTEGER DEFAULT 0, "
"x_slp_pkgid, "
"x_slp_domain, "
"x_slp_submodemainid, "
+ "x_slp_installedstorage, "
"x_slp_baselayoutwidth, "
"x_slp_installedtime, "
"nodisplay, "
"('%q', '%q', '%q', '%q', '%q', "
"'%q', '%q', '%q', '%q', '%q', "
"'%q', '%q', '%q', '%q', '%q', "
- "'%q', '%q', '%q', '%q',"
+ "'%q', '%q', '%q', '%q', '%q', "
"%d, %d, %d, %d, %d, %d, %d,"
"%d, %d, "
"'%q');",
info->x_slp_pkgid,
info->x_slp_domain,
info->x_slp_submodemainid,
+ info->x_slp_installedstorage,
info->x_slp_baselayoutwidth,
info->x_slp_installedtime,
info->nodisplay,
if (info->localname)
_insert_local_info(info);
- _D("Add (%s).", info->package);
+ _D("Add (%s).", query);
return AIL_ERROR_OK;
}
"x_slp_pkgid='%q', "
"x_slp_domain='%q', "
"x_slp_submodemainid='%q', "
+ "x_slp_installedstorage='%q', "
"x_slp_baselayoutwidth=%d, "
"x_slp_installedtime=%d, "
"nodisplay=%d, "
info->x_slp_pkgid,
info->x_slp_domain,
info->x_slp_submodemainid,
+ info->x_slp_installedstorage,
info->x_slp_baselayoutwidth,
info->x_slp_installedtime,
info->nodisplay,
SAFE_FREE(info->x_slp_pkgid);
SAFE_FREE(info->x_slp_domain);
SAFE_FREE(info->x_slp_submodemainid);
+ SAFE_FREE(info->x_slp_installedstorage);
SAFE_FREE(info->desktop);
if (info->localname) {
g_slist_free_full(info->localname, _name_item_free_func);
}
}
- _D("where = %s", w);
+// _D("where = %s", w);
return strdup(w);
}
char *w;
char *tmp_q;
char *l;
- int r;
- int n;
+ ail_cb_ret_e r;
sqlite3_stmt *stmt;
+ ail_appinfo_h ai;
+ int filter_count = 0;
retv_if(!cnt, AIL_ERROR_INVALID_PARAMETER);
if (db_open(DB_OPEN_RO) != AIL_ERROR_OK)
return AIL_ERROR_DB_FAILED;
- snprintf(q, sizeof(q), "SELECT COUNT (*) FROM %s", SQL_TBL_APP_INFO_WITH_LOCALNAME);
+ snprintf(q, sizeof(q), "SELECT %s FROM %s", SQL_FLD_APP_INFO_WITH_LOCALNAME, SQL_TBL_APP_INFO_WITH_LOCALNAME);
tmp_q = strdup(q);
retv_if (NULL == tmp_q, AIL_ERROR_OUT_OF_MEMORY);
free(l);
free(tmp_q);
- if (filter && filter->list) {
+ if (filter && filter->list) {
w = _get_where_clause(filter);
retv_if (NULL == w, AIL_ERROR_FAIL);
strncat(q, w, sizeof(q)-strlen(q)-1);
q[sizeof(q)-1] = '\0';
free(w);
}
-
- _D("Query = %s",q);
+ else
+ _D("No filter exists. All records are retreived");
if (db_prepare(q, &stmt) != AIL_ERROR_OK) {
+ _E("db_prepare fail for query = %s",q);
return AIL_ERROR_DB_FAILED;
}
- r = db_step(stmt);
- if (r == AIL_ERROR_OK) {
- db_column_int(stmt, 0, &n);
- *cnt = n;
+ ai = appinfo_create();
+
+ appinfo_set_stmt(ai, stmt);
+ while (db_step(stmt) == AIL_ERROR_OK) {
+
+ if(_appinfo_check_installed_storage(ai) != AIL_ERROR_OK)
+ continue;
+
+ filter_count++;
}
db_finalize(stmt);
- return r;
-}
-
+ appinfo_destroy(ai);
+ *cnt = filter_count;
+ return AIL_ERROR_OK;
+}
EXPORT_API ail_error_e ail_filter_list_appinfo_foreach(ail_filter_h filter, ail_list_appinfo_cb cb, void *user_data)
{
else
_D("No filter exists. All records are retreived");
- _D("Query = %s",q);
+// _D("Query = %s",q);
if (db_prepare(q, &stmt) != AIL_ERROR_OK) {
+ _E("db_prepare fail for query = %s",q);
return AIL_ERROR_DB_FAILED;
}
appinfo_set_stmt(ai, stmt);
while (db_step(stmt) == AIL_ERROR_OK) {
+ if(_appinfo_check_installed_storage(ai) != AIL_ERROR_OK)
+ continue;
+
r = cb(ai, user_data);
if (AIL_CB_RET_CANCEL == r)
break;
#define LANGUAGE_LENGTH 2
#define DEFAULT_LOCALE "No Locale"
#define MAX_QUERY_LEN 4096
+#define PKG_SD_PATH "/opt/storage/sdcard/app2sd/"
+#define QUERY_GET_LOCALNAME "select name from localname where package='%s' and locale='%s'"
struct ail_appinfo {
char **values;
return strdup(DEFAULT_LOCALE);
}
-void appinfo_set_stmt(ail_appinfo_h ai, sqlite3_stmt *stmt)
-{
- ai->stmt = stmt;
-}
-
-ail_appinfo_h appinfo_create(void)
-{
- ail_appinfo_h ai;
- ai = calloc(1, sizeof(struct ail_appinfo));
- retv_if (NULL == ai, NULL);
- ai->stmt = NULL;
-
- return ai;
-}
-
-void appinfo_destroy(ail_appinfo_h ai)
-{
- if (ai)
- free(ai);
-}
-
-
-
-static ail_error_e _retrieve_all_column(ail_appinfo_h ai)
+static ail_error_e __retrieve_all_column(ail_appinfo_h ai)
{
int i, j;
ail_error_e err;
return AIL_ERROR_OK;
}
+int _appinfo_check_installed_storage(ail_appinfo_h ai)
+{
+ int index = 0;
+ ail_prop_str_e prop = -1;
+ char *pkgid = NULL;
+ char *installed_storage = NULL;
+ char buf[AIL_SQL_QUERY_MAX_LEN] = {'\0'};
+
+ retv_if(!ai, AIL_ERROR_OK);
+
+ if (ai->stmt) {
+ prop = _ail_convert_to_prop_str(AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR);
+ index = sql_get_app_info_idx(prop);
+ if (db_column_str(ai->stmt, index, &installed_storage) < 0){
+ return AIL_ERROR_OK;
+ }
+
+ prop = _ail_convert_to_prop_str(AIL_PROP_X_SLP_PKGID_STR);
+ index = sql_get_app_info_idx(prop);
+ if (db_column_str(ai->stmt, index, &pkgid) < 0){
+ return AIL_ERROR_OK;
+ }
+ } else {
+ prop = _ail_convert_to_prop_str(AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR);
+ installed_storage = ai->values[prop];
+
+ prop = _ail_convert_to_prop_str(AIL_PROP_X_SLP_PKGID_STR);
+ pkgid = ai->values[prop];
+ }
+
+ if (strcmp(installed_storage, "installed_external") == 0) {
+ snprintf(buf, AIL_SQL_QUERY_MAX_LEN - 1, "%s%s", PKG_SD_PATH, pkgid);
+ if (access(buf, R_OK) != 0) {
+ _E("can not access [%s]", buf);
+ return AIL_ERROR_OK;//tmep, it will be fixed to :: return AIL_ERROR_FAIL;
+ }
+ }
+
+ return AIL_ERROR_OK;
+}
+
+void appinfo_set_stmt(ail_appinfo_h ai, sqlite3_stmt *stmt)
+{
+ ai->stmt = stmt;
+}
+
+ail_appinfo_h appinfo_create(void)
+{
+ ail_appinfo_h ai;
+ ai = calloc(1, sizeof(struct ail_appinfo));
+ retv_if (NULL == ai, NULL);
+ ai->stmt = NULL;
+
+ return ai;
+}
+
+void appinfo_destroy(ail_appinfo_h ai)
+{
+ if (ai)
+ free(ai);
+}
EXPORT_API ail_error_e ail_package_destroy_appinfo(ail_appinfo_h ai)
{
return ail_get_appinfo(package, ai);
}
-
EXPORT_API ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *ai)
{
ail_error_e ret;
(*ai)->stmt = stmt;
- ret = _retrieve_all_column(*ai);
+ ret = _appinfo_check_installed_storage(*ai);
+ if (ret < 0) {
+ db_finalize((*ai)->stmt);
+ break;
+ }
+
+ ret = __retrieve_all_column(*ai);
if (ret < 0) {
db_finalize((*ai)->stmt);
break;
return AIL_ERROR_OK;
}
-#define QUERY_GET_LOCALNAME "select name from localname where package='%s' and locale='%s'"
-
char *appinfo_get_localname(const char *package, char *locale)
{
db_open(DB_OPEN_RO);
snprintf(query, sizeof(query), QUERY_GET_LOCALNAME, package, locale);
- _D("Query = %s",query);
+// _D("Query = %s",query);
retv_if (db_prepare(query, &stmt) < 0, NULL);
do {
E_AIL_PROP_X_SLP_PKGID_STR,
E_AIL_PROP_X_SLP_DOMAIN_STR,
E_AIL_PROP_X_SLP_SUBMODEMAINID_STR,
- E_AIL_PROP_STR_MAX = E_AIL_PROP_X_SLP_SUBMODEMAINID_STR,
+ E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR,
+ E_AIL_PROP_STR_MAX = E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR,
} ail_prop_str_e;
"app_info.X_SLP_PKGID='%s'",
"app_info.X_SLP_DOMAIN='%s'",
"app_info.X_SLP_SUBMODEMAINID='%s'",
+ "app_info.X_SLP_INSTALLEDSTORAGE='%s'",
"app_info.X_SLP_BASELAYOUTWIDTH=%d",
"app_info.X_SLP_INSTALLEDTIME=%d",
"app_info.NODISPLAY=%d",
"app_info.X_SLP_PKGID," \
"app_info.X_SLP_DOMAIN," \
"app_info.X_SLP_SUBMODEMAINID," \
+ "app_info.X_SLP_INSTALLEDSTORAGE," \
"app_info.X_SLP_BASELAYOUTWIDTH," \
"app_info.X_SLP_INSTALLEDTIME," \
"app_info.NODISPLAY," \
--- /dev/null
+#AIL init DB build script
+
+SET(INITDB ail_initdb)
+SET(SRCS src/initdb.c)
+
+SET(FOTA ail_fota)
+SET(FOTASRCS src/ail_fota.c)
+
+SET(DESKTOP ail_desktop)
+SET(DESKSRCS src/ail_desktop.c)
+
+SET(FILTER ail_filter)
+SET(FILTERSRCS src/ail_filter.c)
+
+SET(PKG ail_package)
+SET(PKGSRCS src/ail_package.c)
+
+pkg_check_modules(INITDB_PKGS REQUIRED vconf dlog db-util sqlite3)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
+
+STRING(REPLACE ";" " " EXTRA_CFLAGS "${INITDB_PKGS_CFLAGS}")
+
+ADD_EXECUTABLE(${INITDB} ${SRCS})
+TARGET_LINK_LIBRARIES(${INITDB} ${LIBNAME} ${INITDB_PKGS_LIBRARIES})
+SET_TARGET_PROPERTIES(${INITDB} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
+SET_TARGET_PROPERTIES(${INITDB} PROPERTIES SKIP_BUILD_RPATH true)
+
+INSTALL(TARGETS ${INITDB} DESTINATION ${BINDIR})
+
+ADD_EXECUTABLE(${FOTA} ${FOTASRCS})
+TARGET_LINK_LIBRARIES(${FOTA} ${LIBNAME} ${INITDB_PKGS_LIBRARIES})
+SET_TARGET_PROPERTIES(${FOTA} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
+SET_TARGET_PROPERTIES(${FOTA} PROPERTIES SKIP_BUILD_RPATH true)
+
+INSTALL(TARGETS ${FOTA} DESTINATION ${BINDIR})
+
+ADD_EXECUTABLE(${DESKTOP} ${DESKSRCS})
+TARGET_LINK_LIBRARIES(${DESKTOP} ${LIBNAME} ${INITDB_PKGS_LIBRARIES})
+SET_TARGET_PROPERTIES(${DESKTOP} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
+SET_TARGET_PROPERTIES(${DESKTOP} PROPERTIES SKIP_BUILD_RPATH true)
+
+INSTALL(TARGETS ${DESKTOP} DESTINATION ${BINDIR})
+
+ADD_EXECUTABLE(${FILTER} ${FILTERSRCS})
+TARGET_LINK_LIBRARIES(${FILTER} ${LIBNAME} ${INITDB_PKGS_LIBRARIES})
+SET_TARGET_PROPERTIES(${FILTER} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
+SET_TARGET_PROPERTIES(${FILTER} PROPERTIES SKIP_BUILD_RPATH true)
+
+INSTALL(TARGETS ${FILTER} DESTINATION ${BINDIR})
+
+ADD_EXECUTABLE(${PKG} ${PKGSRCS})
+TARGET_LINK_LIBRARIES(${PKG} ${LIBNAME} ${INITDB_PKGS_LIBRARIES})
+SET_TARGET_PROPERTIES(${PKG} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
+SET_TARGET_PROPERTIES(${PKG} PROPERTIES SKIP_BUILD_RPATH true)
+
+INSTALL(TARGETS ${PKG} DESTINATION ${BINDIR})
\ No newline at end of file
--- /dev/null
+/*
+ * ail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include <ail.h>
+
+
+static void _print_help(const char *cmd)
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "[Add a desktop]\n");
+ fprintf(stderr, " %s add <PACKAGE NAME>\n", cmd);
+ fprintf(stderr, "\n");
+ fprintf(stderr, " Ex) %s add com.samsung.menu-screen\n", cmd);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "[Update a desktop]\n");
+ fprintf(stderr, " %s update <PACKAGE NAME>\n", cmd);
+ fprintf(stderr, "\n");
+ fprintf(stderr, " Ex) %s update com.samsung.menu-screen\n", cmd);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "[Remove a desktop]\n");
+ fprintf(stderr, " %s remove <PACKAGE NAME>\n", cmd);
+ fprintf(stderr, "\n");
+ fprintf(stderr, " Ex) %s remove com.samsung.menu-screen\n", cmd);
+ fprintf(stderr, "\n");
+}
+
+
+
+static ail_error_e _add_desktop(const char *package)
+{
+ ail_error_e ret;
+
+ if (!package) {
+ return AIL_ERROR_FAIL;
+ }
+
+ ret = ail_desktop_add(package);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+
+ return AIL_ERROR_OK;
+}
+
+
+
+static ail_error_e _update_desktop(const char *package)
+{
+ ail_error_e ret;
+
+ if (!package) {
+ return AIL_ERROR_FAIL;
+ }
+
+ ret = ail_desktop_update(package);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+
+ return AIL_ERROR_OK;
+}
+
+
+
+static ail_error_e _remove_desktop(const char *package)
+{
+ ail_error_e ret;
+
+ if (!package) {
+ return AIL_ERROR_FAIL;
+ }
+
+ ret = ail_desktop_remove(package);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+
+ return AIL_ERROR_OK;
+}
+
+
+
+int main(int argc, char** argv)
+{
+ ail_error_e ret = AIL_ERROR_OK;
+
+ if (3 == argc) {
+ if (!strncmp(argv[1], "add", 3)) {
+ ret = _add_desktop(argv[2]);
+ } else if (!strncmp(argv[1], "update", 6)) {
+ ret = _update_desktop(argv[2]);
+ } else if (!strncmp(argv[1], "remove", 6)) {
+ ret = _remove_desktop(argv[2]);
+ } else {
+ fprintf(stderr, "%s is a invalid command\n", argv[1]);
+ }
+ }
+ else {
+ _print_help(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (ret != AIL_ERROR_OK) {
+ fprintf(stderr, "There are some problems\n");
+ }
+
+ return EXIT_SUCCESS;
+}
+
--- /dev/null
+/*
+ * ail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <getopt.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ail.h"
+#include "ail_private.h"
+
+enum {
+ _CMD_UNKNOWN,
+ _CMD_COUNT,
+ _CMD_FILTER,
+};
+
+static void usage(const char *name)
+{
+ fprintf(stderr, "\n");
+ fprintf(stderr, " Usage: %s -c command [options]\n", name);
+ fprintf(stderr, " command:\n");
+ fprintf(stderr, " c : count appinfos by option\n");
+ fprintf(stderr, " f : filter appinfos by option\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, " option:\n");
+ fprintf(stderr, " --package=<pacakge name>\n");
+ fprintf(stderr, " --exec=<exec file>\n");
+ fprintf(stderr, " --name=<title name>\n");
+ fprintf(stderr, " --type=<type>\n");
+ fprintf(stderr, " --icon=<icon file>\n");
+ fprintf(stderr, " --category=<category>\n");
+ fprintf(stderr, " --version=<version>\n");
+ fprintf(stderr, " --mimetype=<mimetype>\n");
+ fprintf(stderr, " --nodisplay=<{0|1}>\n");
+ fprintf(stderr, " --service=<service>\n");
+ fprintf(stderr, " --packagetype=<package type>\n");
+ fprintf(stderr, " --packagecategories=<package category>\n");
+ fprintf(stderr, " --packageid=<package id>\n");
+ fprintf(stderr, " --svc=<action:scheme:mime>\n");
+ fprintf(stderr, " --taskmanage=<{true|false}>\n");
+ fprintf(stderr, " --multiple=<{true|false}>\n");
+ fprintf(stderr, " --removable=<{true|false}>\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, " Example:\n");
+ fprintf(stderr, " %s -n menu-screen -r 1\n", name);
+ fprintf(stderr, "\n");
+}
+
+struct _ail_map_t {
+ int prop;
+ const char *property;
+};
+
+static struct _ail_map_t prop_map[] = {
+ {E_AIL_PROP_PACKAGE_STR, AIL_PROP_PACKAGE_STR},
+ {E_AIL_PROP_EXEC_STR, AIL_PROP_EXEC_STR},
+ {E_AIL_PROP_NAME_STR, AIL_PROP_NAME_STR},
+ {E_AIL_PROP_TYPE_STR, AIL_PROP_TYPE_STR},
+ {E_AIL_PROP_ICON_STR, AIL_PROP_ICON_STR},
+ {E_AIL_PROP_CATEGORIES_STR, AIL_PROP_CATEGORIES_STR},
+ {E_AIL_PROP_VERSION_STR, AIL_PROP_VERSION_STR},
+ {E_AIL_PROP_MIMETYPE_STR, AIL_PROP_MIMETYPE_STR},
+ {E_AIL_PROP_X_SLP_SERVICE_STR, AIL_PROP_X_SLP_SERVICE_STR},
+ {E_AIL_PROP_X_SLP_PACKAGETYPE_STR, AIL_PROP_X_SLP_PACKAGETYPE_STR},
+ {E_AIL_PROP_X_SLP_PACKAGECATEGORIES_STR, AIL_PROP_X_SLP_PACKAGECATEGORIES_STR},
+ {E_AIL_PROP_X_SLP_PACKAGEID_STR, AIL_PROP_X_SLP_PACKAGEID_STR},
+ {E_AIL_PROP_X_SLP_SVC_STR, AIL_PROP_X_SLP_SVC_STR},
+ {E_AIL_PROP_X_SLP_EXE_PATH, AIL_PROP_X_SLP_EXE_PATH},
+ {E_AIL_PROP_NODISPLAY_BOOL, AIL_PROP_NODISPLAY_BOOL},
+ {E_AIL_PROP_X_SLP_TASKMANAGE_BOOL, AIL_PROP_NODISPLAY_BOOL},
+ {E_AIL_PROP_X_SLP_MULTIPLE_BOOL, AIL_PROP_X_SLP_MULTIPLE_BOOL},
+ {E_AIL_PROP_X_SLP_REMOVABLE_BOOL, AIL_PROP_X_SLP_REMOVABLE_BOOL},
+ {E_AIL_PROP_X_SLP_APPID_STR, AIL_PROP_X_SLP_APPID_STR},
+ {E_AIL_PROP_X_SLP_PKGID_STR, AIL_PROP_X_SLP_PKGID_STR},
+ {E_AIL_PROP_X_SLP_DOMAIN_STR, AIL_PROP_X_SLP_DOMAIN_STR},
+ {E_AIL_PROP_X_SLP_SUBMODEMAINID_STR, AIL_PROP_X_SLP_SUBMODEMAINID_STR},
+ {E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR, AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR},
+ {E_AIL_PROP_X_SLP_TEMP_INT, AIL_PROP_X_SLP_TEMP_INT},
+ {E_AIL_PROP_X_SLP_INSTALLEDTIME_INT, AIL_PROP_X_SLP_INSTALLEDTIME_INT},
+ {E_AIL_PROP_NODISPLAY_BOOL, AIL_PROP_NODISPLAY_BOOL},
+ {E_AIL_PROP_X_SLP_TASKMANAGE_BOOL, AIL_PROP_X_SLP_TASKMANAGE_BOOL},
+ {E_AIL_PROP_X_SLP_MULTIPLE_BOOL, AIL_PROP_X_SLP_MULTIPLE_BOOL},
+ {E_AIL_PROP_X_SLP_REMOVABLE_BOOL, AIL_PROP_X_SLP_REMOVABLE_BOOL},
+ {E_AIL_PROP_X_SLP_ISHORIZONTALSCALE_BOOL, AIL_PROP_X_SLP_ISHORIZONTALSCALE_BOOL},
+ {E_AIL_PROP_X_SLP_ENABLED_BOOL, AIL_PROP_X_SLP_ENABLED_BOOL},
+ {E_AIL_PROP_X_SLP_SUBMODE_BOOL, AIL_PROP_X_SLP_SUBMODE_BOOL}
+};
+
+static const char *_ail_convert_to_property(int prop)
+{
+ int i = 0;
+
+ if (prop < E_AIL_PROP_STR_MIN || prop > E_AIL_PROP_BOOL_MAX)
+ return NULL;
+
+ for (i=0 ; i < (E_AIL_PROP_BOOL_MAX + 1) ; i++) {
+ if (prop == prop_map[i].prop) {
+ return prop_map[i].property;
+ }
+ }
+
+ return NULL;
+}
+
+
+
+static int _get_cmd(const char *arg)
+{
+ int r;
+ int a;
+
+ if(!arg)
+ a = 0;
+ else
+ a = (int)*arg;
+
+ switch (a) {
+ case 'c':
+ case 'C':
+ r = _CMD_COUNT;
+ break;
+ case 'f':
+ case 'F':
+ r = _CMD_FILTER;
+ break;
+ default:
+ r = _CMD_UNKNOWN;
+ break;
+ }
+
+ return r;
+}
+
+ail_cb_ret_e appinfo_list_func(const ail_appinfo_h appinfo, void *user_data)
+{
+ char *rs = NULL;
+ int t=-1;
+ bool b = 0;
+ int n = 0;
+ struct element e;
+ int i=0;
+ struct element *p;
+ ail_error_e error = AIL_ERROR_OK;
+ ail_cb_ret_e ret = AIL_CB_RET_CONTINUE;
+ p = &e;
+
+ bool err = false;
+ ret = AIL_CB_RET_CONTINUE;
+ for(i = 0; i< E_AIL_PROP_BOOL_MAX+1 && err==false; i ++) {
+ e.prop = i;
+ ELEMENT_TYPE(p, t);
+ switch(t) {
+ case VAL_TYPE_BOOL:
+ error = ail_appinfo_get_bool(appinfo, _ail_convert_to_property(i), &b);
+ if (error) ret = AIL_CB_RET_CANCEL;
+ printf("%s|",b?"true":"false");
+ break;
+ case VAL_TYPE_INT:
+ ail_appinfo_get_int(appinfo, _ail_convert_to_property(i), &n);
+ if (error) ret = AIL_CB_RET_CANCEL;
+ printf("%d|", n);
+ break;
+ case VAL_TYPE_STR:
+ ail_appinfo_get_str(appinfo, _ail_convert_to_property(i), &rs);
+ if (error) ret = AIL_CB_RET_CANCEL;
+ printf("%s|", rs);
+ break;
+ default:
+ fprintf(stderr, "$$$\n");
+ err = true;
+ break;
+ }
+ }
+ printf("\n");
+ return ret;
+}
+
+
+
+int main(int argc, char *argv[])
+{
+ int o;
+ bool err;
+ ail_filter_h f;
+ int oi;
+ int c;
+ static struct element e;
+ int t;
+
+ f = NULL;
+ oi = -1;
+ c = _CMD_UNKNOWN;
+
+ static const struct option longopts[] = {
+ { "help", 0, NULL, 'h' },
+ { "command", 1, NULL, 'c' },
+ { "package", 1, &(e.prop), E_AIL_PROP_PACKAGE_STR},
+ { "name", 1, &(e.prop), E_AIL_PROP_NAME_STR },
+ { "mimetype", 1, &(e.prop), E_AIL_PROP_MIMETYPE_STR},
+ { "removable", 1, &(e.prop), E_AIL_PROP_X_SLP_REMOVABLE_BOOL },
+ { "exec", 1, &(e.prop), E_AIL_PROP_EXEC_STR},
+ { "type", 1, &(e.prop), E_AIL_PROP_TYPE_STR},
+ { "icon", 1, &(e.prop), E_AIL_PROP_ICON_STR},
+ { "categories", 1, &(e.prop), E_AIL_PROP_CATEGORIES_STR},
+ { "version", 1, &(e.prop), E_AIL_PROP_VERSION_STR},
+ { "mimetype", 1, &(e.prop), E_AIL_PROP_MIMETYPE_STR},
+ { "nodisplay", 1, &(e.prop), E_AIL_PROP_NODISPLAY_BOOL},
+ { "service", 1, &(e.prop), E_AIL_PROP_X_SLP_SERVICE_STR},
+ { "packagetype", 1, &(e.prop), E_AIL_PROP_X_SLP_PACKAGETYPE_STR},
+ { "packagecategories", 1, &(e.prop), E_AIL_PROP_X_SLP_PACKAGECATEGORIES_STR},
+ { "packageid", 1, &(e.prop), E_AIL_PROP_X_SLP_PACKAGEID_STR},
+ { "svc", 1, &(e.prop), E_AIL_PROP_X_SLP_SVC_STR},
+ { "taskmanage", 1, &(e.prop), E_AIL_PROP_X_SLP_TASKMANAGE_BOOL},
+ { "multiple", 1, &(e.prop), E_AIL_PROP_X_SLP_MULTIPLE_BOOL},
+ { "removable", 1, &(e.prop), E_AIL_PROP_X_SLP_REMOVABLE_BOOL},
+ { "appid", 1, &(e.prop), AIL_PROP_X_SLP_APPID_STR},
+ { "pkgid", 1, &(e.prop), AIL_PROP_X_SLP_PKGID_STR},
+ { "submode", 1, &(e.prop), E_AIL_PROP_X_SLP_SUBMODE_BOOL},
+ { "submodemainid", 1, &(e.prop), AIL_PROP_X_SLP_SUBMODEMAINID_STR},
+ { "installedstorage", 1, &(e.prop), AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR},
+ { "domain", 1, &(e.prop), AIL_PROP_X_SLP_DOMAIN_STR},
+ { 0, 0, 0, 0 },
+ };
+
+ if (ail_filter_new(&f) != AIL_ERROR_OK)
+ return -1;
+
+ err = false;
+
+ while (!err && (o = getopt_long(argc, argv, "c:", longopts, &oi)) >= 0) {
+ bool b;
+ struct element *p = &e;
+
+ ELEMENT_TYPE(p, t);
+
+ switch (o) {
+ case 'c':
+ c = _get_cmd(optarg);
+ break;
+ case 0:
+ switch (t) {
+ case VAL_TYPE_BOOL:
+ if(!strcasecmp(optarg, "true") || !strcasecmp(optarg, "1"))
+ b = true;
+ else if (!strcasecmp(optarg, "false") || !strcasecmp(optarg, "0"))
+ b = false;
+ else {
+ err = true;
+ break;
+ }
+ if (ail_filter_add_bool(f, _ail_convert_to_property(e.prop), b) != AIL_ERROR_OK)
+ err = true;
+ break;
+
+ case VAL_TYPE_INT:
+ if (ail_filter_add_int(f, _ail_convert_to_property(e.prop), atoi(optarg)) != AIL_ERROR_OK)
+ err = true;
+ break;
+
+ case VAL_TYPE_STR:
+ if (ail_filter_add_str(f, _ail_convert_to_property(e.prop), optarg) != AIL_ERROR_OK)
+ err = true;
+ break;
+
+ default:
+ err = true;
+ break;
+ }
+ break;
+ default:
+ err = true;
+ break;
+ }
+ }
+
+ if (err) {
+ usage(argv[0]);
+ }
+ else {
+ int n = -1;
+ switch (c) {
+ case _CMD_COUNT:
+ if (ail_filter_count_appinfo(f, &n) != AIL_ERROR_OK){
+ fprintf(stderr, "Error: failed to count appinfo\n");
+ }
+ else
+ fprintf(stderr, "count=%d\n", n);
+ break;
+ case _CMD_FILTER:
+ ail_filter_list_appinfo_foreach(f, appinfo_list_func, NULL);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (f)
+ ail_filter_destroy(f);
+
+ return 0;
+}
--- /dev/null
+/*
+ * ail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include "ail.h"
+#include "ail_private.h"
+
+#define OWNER_ROOT 0
+#define GROUP_MENU 6010
+#define BUFSZE 1024
+#define OPT_DESKTOP_DIRECTORY "/opt/share/applications"
+#define USR_DESKTOP_DIRECTORY "/usr/share/applications"
+#define APP_INFO_DB_FILE "/opt/dbspace/.app_info.db"
+#define APP_INFO_DB_FILE_JOURNAL "/opt/dbspace/.app_info.db-journal"
+#define APP_INFO_DB_LABEL "ail::db"
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) fprintf(stderr, "[AIL_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#ifdef _D
+#undef _D
+#endif
+#define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+static int initdb_count_app(void)
+{
+ ail_filter_h filter;
+ ail_error_e ret;
+ int total = 0;
+
+ ret = ail_filter_new(&filter);
+ if (ret != AIL_ERROR_OK) {
+ return -1;
+ }
+
+ ret = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false);
+ if (ret != AIL_ERROR_OK) {
+ ail_filter_destroy(filter);
+ return -1;
+ }
+
+ ret = ail_filter_count_appinfo(filter, &total);
+ if (ret != AIL_ERROR_OK) {
+ ail_filter_destroy(filter);
+ return -1;
+ }
+
+ ail_filter_destroy(filter);
+
+ return total;
+}
+
+
+
+char* _desktop_to_package(const char* desktop)
+{
+ char *package, *tmp;
+
+ retv_if(!desktop, NULL);
+
+ package = strdup(desktop);
+ retv_if(!package, NULL);
+
+ tmp = strrchr(package, '.');
+ if(tmp == NULL) {
+ _E("[%s] is not a desktop file", package);
+ free(package);
+ return NULL;
+ }
+
+ if (strcmp(tmp, ".desktop")) {
+ _E("%s is not a desktop file", desktop);
+ free(package);
+ return NULL;
+ }
+
+ *tmp = '\0';
+
+ return package;
+}
+
+
+
+int initdb_load_directory(const char *directory)
+{
+ DIR *dir;
+ struct dirent entry, *result;
+ int len, ret;
+ char buf[BUFSZE];
+ int total_cnt = 0;
+ int ok_cnt = 0;
+
+ // desktop file
+ dir = opendir(directory);
+ if (!dir) {
+ if (strerror_r(errno, buf, sizeof(buf)) == 0)
+ _E("Failed to access the [%s] because %s\n", directory, buf);
+ return AIL_ERROR_FAIL;
+ }
+
+ len = strlen(directory) + 1;
+ _D("Loading desktop files from %s", directory);
+
+ for (ret = readdir_r(dir, &entry, &result);
+ ret == 0 && result != NULL;
+ ret = readdir_r(dir, &entry, &result)) {
+ char *package;
+
+ if (entry.d_name[0] == '.') continue;
+ total_cnt++;
+ package = _desktop_to_package(entry.d_name);
+ if (!package) {
+ _E("Failed to convert file to package[%s]", entry.d_name);
+ continue;
+ }
+
+ if (ail_desktop_fota(package) != AIL_ERROR_OK) {
+ _E("Failed to add a package[%s]", package);
+ } else {
+ ok_cnt++;
+ }
+ free(package);
+ }
+
+ _D("Application-Desktop process : Success [%d], fail[%d], total[%d] \n", ok_cnt, total_cnt-ok_cnt, total_cnt);
+ closedir(dir);
+
+ return AIL_ERROR_OK;
+}
+
+
+
+static int initdb_change_perm(const char *db_file)
+{
+ char buf[BUFSZE];
+ char journal_file[BUFSZE];
+ char *files[3];
+ int ret, i;
+
+ files[0] = (char *)db_file;
+ files[1] = journal_file;
+ files[2] = NULL;
+
+ retv_if(!db_file, AIL_ERROR_FAIL);
+
+ snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
+
+ for (i = 0; files[i]; i++) {
+ ret = chown(files[i], OWNER_ROOT, OWNER_ROOT);
+ if (ret == -1) {
+ strerror_r(errno, buf, sizeof(buf));
+ _E("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, OWNER_ROOT, buf);
+ return AIL_ERROR_FAIL;
+ }
+
+ ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (ret == -1) {
+ strerror_r(errno, buf, sizeof(buf));
+ _E("FAIL : chmod %s 0664, because %s", db_file, buf);
+ return AIL_ERROR_FAIL;
+ }
+ }
+
+ return AIL_ERROR_OK;
+}
+
+
+static int __is_authorized()
+{
+ /* ail_init db should be called by as root privilege. */
+
+ uid_t uid = getuid();
+ if ((uid_t) 0 == uid)
+ return 1;
+ else
+ return 0;
+}
+
+int xsystem(const char *argv[])
+{
+ int status = 0;
+ pid_t pid;
+ pid = fork();
+ switch (pid) {
+ case -1:
+ perror("fork failed");
+ return -1;
+ case 0:
+ /* child */
+ execvp(argv[0], (char *const *)argv);
+ _exit(-1);
+ default:
+ /* parent */
+ break;
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ perror("waitpid failed");
+ return -1;
+ }
+ if (WIFSIGNALED(status)) {
+ perror("signal");
+ return -1;
+ }
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ perror("should not happen");
+ return -1;
+ }
+ return WEXITSTATUS(status);
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+
+ if (!__is_authorized()) {
+ fprintf(stderr, "You are not an authorized user!\n");
+ _D("You are not an authorized user!\n");
+ return AIL_ERROR_FAIL;
+ }
+
+ const char *argv_rm[] = { "/bin/rm", APP_INFO_DB_FILE, NULL };
+ xsystem(argv_rm);
+ const char *argv_rmjn[] = { "/bin/rm", APP_INFO_DB_FILE_JOURNAL, NULL };
+ xsystem(argv_rmjn);
+
+ ret = setenv("AIL_INITDB", "1", 1);
+ _D("AIL_INITDB : %d", ret);
+
+ ret = initdb_count_app();
+ if (ret > 0) {
+ _D("Some Apps in the App Info DB.");
+ }
+
+ ret = initdb_load_directory(OPT_DESKTOP_DIRECTORY);
+ if (ret == AIL_ERROR_FAIL) {
+ _E("cannot load opt desktop directory.");
+ }
+
+ ret = initdb_load_directory(USR_DESKTOP_DIRECTORY);
+ if (ret == AIL_ERROR_FAIL) {
+ _E("cannot load usr desktop directory.");
+ }
+
+ ret = initdb_change_perm(APP_INFO_DB_FILE);
+ if (ret == AIL_ERROR_FAIL) {
+ _E("cannot chown.");
+ }
+
+ const char *argv_smack[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE, NULL };
+ xsystem(argv_smack);
+ const char *argv_smackjn[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE_JOURNAL, NULL };
+ xsystem(argv_smackjn);
+
+ return AIL_ERROR_OK;
+}
+
+
+
+// END
--- /dev/null
+/*
+ * ail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include <ail.h>
+#include "ail_private.h"
+
+char *prop_tbl[] = {
+ AIL_PROP_PACKAGE_STR,
+ AIL_PROP_EXEC_STR,
+ AIL_PROP_NAME_STR,
+ AIL_PROP_TYPE_STR,
+ AIL_PROP_ICON_STR,
+ AIL_PROP_CATEGORIES_STR,
+ AIL_PROP_VERSION_STR,
+ AIL_PROP_MIMETYPE_STR,
+ AIL_PROP_X_SLP_SERVICE_STR,
+ AIL_PROP_X_SLP_PACKAGETYPE_STR,
+ AIL_PROP_X_SLP_PACKAGECATEGORIES_STR,
+ AIL_PROP_X_SLP_PACKAGEID_STR,
+ AIL_PROP_X_SLP_SVC_STR,
+ AIL_PROP_X_SLP_EXE_PATH,
+ AIL_PROP_X_SLP_APPID_STR,
+ AIL_PROP_X_SLP_PKGID_STR,
+ AIL_PROP_X_SLP_DOMAIN_STR,
+ AIL_PROP_X_SLP_SUBMODEMAINID_STR,
+ AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR,
+ AIL_PROP_NODISPLAY_BOOL,
+ AIL_PROP_X_SLP_TASKMANAGE_BOOL,
+ AIL_PROP_X_SLP_MULTIPLE_BOOL,
+ AIL_PROP_X_SLP_REMOVABLE_BOOL,
+ AIL_PROP_X_SLP_SUBMODE_BOOL,
+ NULL
+};
+
+
+static void _print_help(const char *cmd)
+{
+ int i;
+
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "[Get appinfo value]\n");
+ fprintf(stderr, " %s get <PACKAGE NAME> <COLUMN NAME>\n", cmd);
+ fprintf(stderr, "\n");
+ fprintf(stderr, " <COLUMN NAME>\n");
+
+ for (i = 0; prop_tbl[i]; i++) {
+ fprintf(stderr, " %s\n", prop_tbl[i]);
+ }
+
+ fprintf(stderr, "\n");
+ fprintf(stderr, " Ex) %s get com.samsung.menu-screen X_SLP_SERVICE\n", cmd);
+ fprintf(stderr, "\n");
+}
+
+
+
+static int _get_property(const char *property)
+{
+ int i;
+
+ if (!property) {
+ return 0;
+ }
+
+ for (i = 0; prop_tbl[i]; i++) {
+ if (!strcasecmp(prop_tbl[i], property)) {
+ return i;
+ }
+ }
+
+ fprintf(stderr, "%s is not found\n", property);
+
+ return -1;
+}
+
+
+
+static ail_error_e _get_appinfo(const char *package, const char *property)
+{
+ ail_appinfo_h handle;
+ ail_error_e ret;
+ int prop, ival;
+ bool bval;
+ char *str;
+ struct element e;
+ struct element *p;
+ int t;
+
+ ret = ail_package_get_appinfo(package, &handle);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+
+ prop = _get_property(property);
+ if (prop < 0) {
+ goto END;
+ }
+
+ e.prop = prop;
+ p = &e;
+ ELEMENT_TYPE(p,t);
+
+ if (t == VAL_TYPE_STR) {
+ ret = ail_appinfo_get_str(handle, property, &str);
+ if (ret != AIL_ERROR_OK) {
+ goto END;
+ }
+ fprintf(stderr, "Package[%s], Property[%s] : %s\n", package, property, str);
+ } else if (t == VAL_TYPE_INT) {
+ ret = ail_appinfo_get_int(handle, property, &ival);
+ if (ret != AIL_ERROR_OK) {
+ goto END;
+ }
+ fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, ival);
+ } else if (t == VAL_TYPE_BOOL) {
+ ret = ail_appinfo_get_bool(handle, property, &bval);
+ if (ret != AIL_ERROR_OK) {
+ goto END;
+ }
+ fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, bval);
+ }
+
+END:
+ ret = ail_package_destroy_appinfo(handle);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+
+ return AIL_ERROR_OK;
+}
+
+int main(int argc, char** argv)
+{
+ ail_error_e ret = AIL_ERROR_OK;
+
+
+ if (4 == argc) {
+ if (!strncmp(argv[1], "get", 3)) {
+ ret = _get_appinfo(argv[2], argv[3]);
+ }
+ }
+ else {
+ _print_help(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (ret != AIL_ERROR_OK) {
+ fprintf(stderr, "There are some problems\n");
+ }
+
+ return EXIT_SUCCESS;
+}
+
+
--- /dev/null
+/*
+ * ail
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include "ail.h"
+#include "ail_private.h"
+
+#define OWNER_ROOT 0
+#define GROUP_MENU 6010
+#define BUFSZE 1024
+#define OPT_DESKTOP_DIRECTORY "/opt/share/applications"
+#define USR_DESKTOP_DIRECTORY "/usr/share/applications"
+#define APP_INFO_DB_FILE "/opt/dbspace/.app_info.db"
+#define APP_INFO_DB_FILE_JOURNAL "/opt/dbspace/.app_info.db-journal"
+#define APP_INFO_DB_LABEL "ail::db"
+
+#ifdef _E
+#undef _E
+#endif
+#define _E(fmt, arg...) fprintf(stderr, "[AIL_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+#ifdef _D
+#undef _D
+#endif
+#define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
+
+static int initdb_count_app(void)
+{
+ ail_filter_h filter;
+ ail_error_e ret;
+ int total = 0;
+
+ ret = ail_filter_new(&filter);
+ if (ret != AIL_ERROR_OK) {
+ return -1;
+ }
+
+ ret = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false);
+ if (ret != AIL_ERROR_OK) {
+ ail_filter_destroy(filter);
+ return -1;
+ }
+
+ ret = ail_filter_count_appinfo(filter, &total);
+ if (ret != AIL_ERROR_OK) {
+ ail_filter_destroy(filter);
+ return -1;
+ }
+
+ ail_filter_destroy(filter);
+
+ return total;
+}
+
+
+
+char* _desktop_to_package(const char* desktop)
+{
+ char *package, *tmp;
+
+ retv_if(!desktop, NULL);
+
+ package = strdup(desktop);
+ retv_if(!package, NULL);
+
+ tmp = strrchr(package, '.');
+ if(tmp == NULL) {
+ _E("[%s] is not a desktop file", package);
+ free(package);
+ return NULL;
+ }
+
+ if (strcmp(tmp, ".desktop")) {
+ _E("%s is not a desktop file", desktop);
+ free(package);
+ return NULL;
+ }
+
+ *tmp = '\0';
+
+ return package;
+}
+
+
+
+int initdb_load_directory(const char *directory)
+{
+ DIR *dir;
+ struct dirent entry, *result;
+ int len, ret;
+ char buf[BUFSZE];
+ int total_cnt = 0;
+ int ok_cnt = 0;
+
+ // desktop file
+ dir = opendir(directory);
+ if (!dir) {
+ if (strerror_r(errno, buf, sizeof(buf)) == 0)
+ _E("Failed to access the [%s] because %s\n", directory, buf);
+ return AIL_ERROR_FAIL;
+ }
+
+ len = strlen(directory) + 1;
+ _D("Loading desktop files from %s", directory);
+
+ for (ret = readdir_r(dir, &entry, &result);
+ ret == 0 && result != NULL;
+ ret = readdir_r(dir, &entry, &result)) {
+ char *package;
+
+ if (entry.d_name[0] == '.') continue;
+ total_cnt++;
+ package = _desktop_to_package(entry.d_name);
+ if (!package) {
+ _E("Failed to convert file to package[%s]", entry.d_name);
+ continue;
+ }
+
+ if (ail_desktop_add(package) != AIL_ERROR_OK) {
+ _E("Failed to add a package[%s]", package);
+ } else {
+ ok_cnt++;
+ }
+ free(package);
+ }
+
+ _D("Application-Desktop process : Success [%d], fail[%d], total[%d] \n", ok_cnt, total_cnt-ok_cnt, total_cnt);
+ closedir(dir);
+
+ return AIL_ERROR_OK;
+}
+
+
+
+static int initdb_change_perm(const char *db_file)
+{
+ char buf[BUFSZE];
+ char journal_file[BUFSZE];
+ char *files[3];
+ int ret, i;
+
+ files[0] = (char *)db_file;
+ files[1] = journal_file;
+ files[2] = NULL;
+
+ retv_if(!db_file, AIL_ERROR_FAIL);
+
+ snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
+
+ for (i = 0; files[i]; i++) {
+ ret = chown(files[i], OWNER_ROOT, OWNER_ROOT);
+ if (ret == -1) {
+ strerror_r(errno, buf, sizeof(buf));
+ _E("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, OWNER_ROOT, buf);
+ return AIL_ERROR_FAIL;
+ }
+
+ ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (ret == -1) {
+ strerror_r(errno, buf, sizeof(buf));
+ _E("FAIL : chmod %s 0664, because %s", db_file, buf);
+ return AIL_ERROR_FAIL;
+ }
+ }
+
+ return AIL_ERROR_OK;
+}
+
+
+static int __is_authorized()
+{
+ /* ail_init db should be called by as root privilege. */
+
+ uid_t uid = getuid();
+ if ((uid_t) 0 == uid)
+ return 1;
+ else
+ return 0;
+}
+
+int xsystem(const char *argv[])
+{
+ int status = 0;
+ pid_t pid;
+ pid = fork();
+ switch (pid) {
+ case -1:
+ perror("fork failed");
+ return -1;
+ case 0:
+ /* child */
+ execvp(argv[0], (char *const *)argv);
+ _exit(-1);
+ default:
+ /* parent */
+ break;
+ }
+ if (waitpid(pid, &status, 0) == -1) {
+ perror("waitpid failed");
+ return -1;
+ }
+ if (WIFSIGNALED(status)) {
+ perror("signal");
+ return -1;
+ }
+ if (!WIFEXITED(status)) {
+ /* shouldn't happen */
+ perror("should not happen");
+ return -1;
+ }
+ return WEXITSTATUS(status);
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+
+ if (!__is_authorized()) {
+ fprintf(stderr, "You are not an authorized user!\n");
+ _D("You are not an authorized user!\n");
+ return AIL_ERROR_FAIL;
+ }
+
+ const char *argv_rm[] = { "/bin/rm", APP_INFO_DB_FILE, NULL };
+ xsystem(argv_rm);
+ const char *argv_rmjn[] = { "/bin/rm", APP_INFO_DB_FILE_JOURNAL, NULL };
+ xsystem(argv_rmjn);
+
+ ret = setenv("AIL_INITDB", "1", 1);
+ _D("AIL_INITDB : %d", ret);
+
+ ret = initdb_count_app();
+ if (ret > 0) {
+ _D("Some Apps in the App Info DB.");
+ }
+
+ ret = initdb_load_directory(OPT_DESKTOP_DIRECTORY);
+ if (ret == AIL_ERROR_FAIL) {
+ _E("cannot load opt desktop directory.");
+ }
+
+ ret = initdb_load_directory(USR_DESKTOP_DIRECTORY);
+ if (ret == AIL_ERROR_FAIL) {
+ _E("cannot load usr desktop directory.");
+ }
+
+ ret = initdb_change_perm(APP_INFO_DB_FILE);
+ if (ret == AIL_ERROR_FAIL) {
+ _E("cannot chown.");
+ }
+
+ const char *argv_smack[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE, NULL };
+ xsystem(argv_smack);
+ const char *argv_smackjn[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE_JOURNAL, NULL };
+ xsystem(argv_smackjn);
+
+ return AIL_ERROR_OK;
+}
+
+
+
+// END
--- /dev/null
+/*
+ * Copyright (c) 2011 Samsung Electronics, Inc.
+ * All rights reserved.
+ *
+ * This software is a confidential and proprietary information
+ * of Samsung Electronics, Inc. ("Confidential Information"). You
+ * shall not disclose such Confidential Information and shall use
+ * it only in accordance with the terms of the license agreement
+ * you entered into with Samsung Electronics.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include <ail.h>
+#include "ail_private.h"
+
--- /dev/null
+
+
+static void _print_help(const char *cmd)
+{
+ int i;
+
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "[Get appinfo value]\n");
+ fprintf(stderr, " %s get <PACKAGE NAME> <COLUMN NAME>\n", cmd);
+ fprintf(stderr, "\n");
+ fprintf(stderr, " <COLUMN NAME>\n");
+
+ for (i = 0; prop_tbl[i]; i++) {
+ fprintf(stderr, " %s\n", prop_tbl[i]);
+ }
+
+ fprintf(stderr, "\n");
+ fprintf(stderr, " Ex) %s get com.samsung.menu-screen X_SLP_SERVICE\n", cmd);
+ fprintf(stderr, "\n");
+}
+
+
+
+static int _get_property(const char *property)
+{
+ int i;
+
+ if (!property) {
+ return 0;
+ }
+
+ for (i = 0; prop_tbl[i]; i++) {
+ if (!strcasecmp(prop_tbl[i], property)) {
+ return i;
+ }
+ }
+
+ fprintf(stderr, "%s is not found\n", property);
+
+ return -1;
+}
+
+
+
+static ail_error_e _get_appinfo(const char *package, const char *property)
+{
+ ail_appinfo_h handle;
+ ail_error_e ret;
+ int prop, ival;
+ bool bval;
+ char *str;
+ struct element e;
+ struct element *p;
+ int t;
+
+ ret = ail_package_get_appinfo(package, &handle);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+
+ prop = _get_property(property);
+ if (prop < 0) {
+ return AIL_ERROR_FAIL;
+ }
+
+ e.prop = prop;
+ p = &e;
+ ELEMENT_TYPE(p,t);
+
+ if (t == VAL_TYPE_STR) {
+ ret = ail_appinfo_get_str(handle, prop, &str);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+ fprintf(stderr, "Package[%s], Property[%s] : %s\n", package, property, str);
+ } else if (t == VAL_TYPE_INT) {
+ ret = ail_appinfo_get_int(handle, prop, &ival);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+ fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, ival);
+ } else if (t == VAL_TYPE_BOOL) {
+ ret = ail_appinfo_get_bool(handle, prop, &bval);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+ fprintf(stderr, "Package[%s], Property[%s] : %d\n", package, property, bval);
+ }
+
+ ret = ail_package_destroy_appinfo(handle);
+ if (ret != AIL_ERROR_OK) {
+ return AIL_ERROR_FAIL;
+ }
+
+ return AIL_ERROR_OK;
+}
+
+int main(int argc, char** argv)
+{
+ ail_error_e ret = AIL_ERROR_OK;
+
+
+ if (4 == argc) {
+ if (!strncmp(argv[1], "get", 3)) {
+ ret = _get_appinfo(argv[2], argv[3]);
+ }
+ }
+ else {
+ _print_help(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (ret != AIL_ERROR_OK) {
+ fprintf(stderr, "There are some problems\n");
+ }
+
+ return EXIT_SUCCESS;
+}
+
+