*/
#include <Elementary.h>
-#include <pkgmgr-info.h>
-#include <rua.h>
+#include <app_manager.h>
+#include <context_history.h>
#include "list.h"
#include "log.h"
#include "main.h"
#include "util.h"
+#include "conf.h"
typedef struct pkginfo {
char *appid;
int pid;
} private_pid_s;
-static struct {
- Eina_Hash *pkginfo_table;
-} private_table_s = {
- .pkginfo_table = NULL,
-};
-
-
static void _pkglist_unretrieve_item(list_type_default_s *default_info)
{
return;
}
- if (default_info->name) {
- free(default_info->name);
- default_info->name = NULL;
- }
- if (default_info->icon) {
- free(default_info->icon);
- default_info->icon = NULL;
- }
- if (default_info->pkgid) {
- free(default_info->pkgid);
- default_info->pkgid = NULL;
- }
- if (default_info->arg) {
- free(default_info->arg);
- default_info->arg = NULL;
- }
- if (default_info->appid) {
- free(default_info->appid);
- default_info->appid = NULL;
- }
- if (default_info) {
- free(default_info);
- default_info = NULL;
- }
-}
+ free(default_info->name);
+ default_info->name = NULL;
+ free(default_info->icon);
+ default_info->icon = NULL;
+ free(default_info->pkgid);
+ default_info->pkgid = NULL;
-static list_type_default_s *_pkglist_retrieve_item(const char *appid, const char *arg, time_t launch_time)
-{
- retv_if(!appid, NULL);
+ free(default_info->arg);
+ default_info->arg = NULL;
- private_pkginfo_s *pkg_info = NULL;
- list_type_default_s *default_info = NULL;
+ free(default_info->appid);
+ default_info->appid = NULL;
- pkg_info = eina_hash_find(private_table_s.pkginfo_table, appid);
- if (!pkg_info) {
- _D("app(%s) is not taskmanage app", appid);
- return NULL;
- }
+ free(default_info);
+ default_info = NULL;
+}
- if (!pkg_info->taskmanage) {
- _D("app(%s) is not taskmanage app", appid);
- return NULL;
- }
+static task_mgr_error_e _get_app_launchtime(Eina_List *pkg_list)
+{
- default_info = calloc(1, sizeof(*default_info));
- retv_if(!default_info, NULL);
+ _D("");
- default_info->taskmanage = pkg_info->taskmanage;
- default_info->launch_time = launch_time;
- default_info->nodisplay = pkg_info->nodisplay;
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ int rec_size = 0;
+ int last_launch_time;
+ char *context_app_id;
+ unsigned pkg_size;
+ unsigned cxt_size;
+ Eina_List *l;
+ list_type_default_s *pkg_info = NULL;
- default_info->appid = strdup(appid);
- goto_if(!default_info->appid, ERROR);
+ context_history_h history_handle;
+ context_history_list_h history_app_list;
+ context_history_record_h history_record;
- if (arg) {
- default_info->arg = strdup(arg);
- goto_if(!default_info->arg, ERROR);
- }
+ ret = context_history_create(&history_handle);
+ retv_if(ret != CONTEXT_HISTORY_ERROR_NONE, TASK_MGR_ERROR_FAIL);
- if (pkg_info->pkgid) {
- default_info->pkgid = strdup(pkg_info->pkgid);
- goto_if(!default_info->pkgid, ERROR);
- } else {
- _E("Fail to get pkgid from pkg info table");
- goto ERROR;
- }
+ ret = context_history_get_list(history_handle, CONTEXT_HISTORY_RECENTLY_USED_APP, NULL, &history_app_list);
- if (pkg_info->icon) {
- default_info->icon = strdup(pkg_info->icon);
- goto_if(!default_info->icon, ERROR);
- } else {
- _E("Fail to get icon from pkg info table");
- goto ERROR;
+ if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+ context_history_destroy(history_handle);
+ return TASK_MGR_ERROR_FAIL;
}
- if (pkg_info->name) {
- default_info->name = strdup(pkg_info->name);
- goto_if(!default_info->name, ERROR);
- } else {
- _E("Fail to get name from pkg info table");
- goto ERROR;
+ ret = context_history_list_get_count(history_app_list, &rec_size);
+ if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+ context_history_list_destroy(history_app_list);
+ context_history_destroy(history_handle);
+ return TASK_MGR_ERROR_FAIL;
}
- _D("list add id : [%s], icon : [%s], name : [%s]", pkg_info->pkgid, pkg_info->icon, pkg_info->name);
-
- return default_info;
+ _D("Num of records: %d", rec_size);
-ERROR:
-
- _pkglist_unretrieve_item(default_info);
- return NULL;
-}
+ int i;
+ for (i = 0; i < rec_size; ++i) {
+ context_history_list_get_current(history_app_list, &history_record);
+ context_history_record_get_int(history_record, CONTEXT_HISTORY_LAST_TIME, &last_launch_time);
+ context_history_record_get_string(history_record, CONTEXT_HISTORY_APP_ID, &context_app_id);
+ if (!context_app_id) {
+ _D("Context_app_id == NULL");
+ context_history_record_destroy(history_record);
+ context_history_list_move_next(history_app_list);
+ continue;
+ }
-#define DEFAULT_ICON IMAGEDIR"/default.png"
-int _get_pkginfo_cb(pkgmgrinfo_appinfo_h app_handle, void *user_data)
-{
- char *appid = NULL;
- char *pkgid = NULL;
- char *name = NULL;
- char *icon = NULL;
- private_pkginfo_s *pkg_info = NULL;
+ EINA_LIST_FOREACH(pkg_list, l, pkg_info) {
- pkg_info = calloc(1, sizeof(*pkg_info));
- retv_if(!pkg_info, PMINFO_R_ERROR);
+ if (!pkg_info || !pkg_info->appid)
+ continue;
- memset(pkg_info, 0, sizeof(private_pkginfo_s));
+ pkg_size = strlen(pkg_info->appid);
+ cxt_size = strlen(context_app_id);
- pkgmgrinfo_appinfo_get_appid(app_handle, &appid);
- goto_if(!appid, ERROR);
+ if (!strncmp(pkg_info->appid, context_app_id,
+ pkg_size > cxt_size ? pkg_size : cxt_size)
+ && strlen(pkg_info->appid) == strlen(context_app_id))
- pkg_info->appid = strdup(appid);
- goto_if(!pkg_info->appid, ERROR);
+ pkg_info->launch_time = last_launch_time;
+ }
- if (PMINFO_R_OK != pkgmgrinfo_appinfo_is_taskmanage(app_handle, &pkg_info->taskmanage)) {
- goto ERROR;
- }
+ free(context_app_id);
- if (PMINFO_R_OK != pkgmgrinfo_appinfo_get_pkgid(app_handle, &pkgid)) {
- goto ERROR;
+ context_history_record_destroy(history_record);
+ context_history_list_move_next(history_app_list);
}
- pkg_info->pkgid = strdup(pkgid);
- goto_if(!pkg_info->pkgid, ERROR);
- if (PMINFO_R_OK != pkgmgrinfo_appinfo_get_icon(app_handle, &icon)) {
- goto ERROR;
- }
- if (icon && 0 == access(icon, F_OK)) {
- pkg_info->icon= strdup(icon);
- } else {
- _D("Fail to access icon path");
- pkg_info->icon = strdup(DEFAULT_ICON);
- }
- goto_if(!pkg_info->icon, ERROR);
+ context_history_list_destroy(history_app_list);
+ context_history_destroy(history_handle);
- if (PMINFO_R_OK != pkgmgrinfo_appinfo_get_label(app_handle, &name)) {
- goto ERROR;
- }
- if (name) {
- pkg_info->name= strdup(name);
- goto_if(!pkg_info->name, ERROR);
- }
+ return TASK_MGR_ERROR_NONE;
- if (PMINFO_R_OK != pkgmgrinfo_appinfo_is_nodisplay(app_handle, &pkg_info->nodisplay)) {
- goto ERROR;
- }
+}
- eina_hash_add(private_table_s.pkginfo_table, pkg_info->appid, pkg_info);
+static void _release_pkg_info(list_type_default_s *pkg_info)
+{
+ _D("");
- return PMINFO_R_OK;
+ if (!pkg_info)
+ return;
-ERROR:
- if (pkg_info->name) free(pkg_info->name);
- if (pkg_info->icon) free(pkg_info->icon);
- if (pkg_info->pkgid) free(pkg_info->pkgid);
- if (pkg_info->appid) free(pkg_info->appid);
+ free(pkg_info->name);
+ free(pkg_info->icon);
+ free(pkg_info->pkgid);
+ free(pkg_info->appid);
free(pkg_info);
- return PMINFO_R_ERROR;
}
-
-
-static task_mgr_error_e _create_pkginfo_table(void)
+static bool _get_pkginfo_cb(app_info_h app_handle, void *user_data)
{
_D("");
- pkgmgrinfo_appinfo_filter_h handle;
- int ret = 0;
+ bool is_running = false;
+ Eina_List **pkg_list = (Eina_List **) user_data;
- private_table_s.pkginfo_table = eina_hash_string_superfast_new(NULL);
+ list_type_default_s *pkg_info = calloc(1, sizeof(list_type_default_s));
+ retv_if(!pkg_info, false);
- ret = pkgmgrinfo_appinfo_filter_create(&handle);
- if (PMINFO_R_OK != ret) {
- return TASK_MGR_ERROR_FAIL;
- }
+ if (app_info_get_app_id(app_handle, &pkg_info->appid) != APP_MANAGER_ERROR_NONE
+ || !pkg_info->appid) {
- ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_TASKMANAGE, 1);
- if (PMINFO_R_OK != ret) {
- pkgmgrinfo_appinfo_filter_destroy(handle);
- return TASK_MGR_ERROR_FAIL;
+ _release_pkg_info(pkg_info);
+ return false;
}
- ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, _get_pkginfo_cb, NULL, getuid());
- if (ret != PMINFO_R_OK) {
- pkgmgrinfo_appinfo_filter_destroy(handle);
- return TASK_MGR_ERROR_FAIL;
+ if (app_manager_is_running(pkg_info->appid, &is_running) != APP_MANAGER_ERROR_NONE
+ || !is_running) {
+
+ _D("Application %s is not running", pkg_info->appid);
+ _release_pkg_info(pkg_info);
+ return true;
}
- pkgmgrinfo_appinfo_filter_destroy(handle);
+ if (app_info_get_package(app_handle, &pkg_info->pkgid) != APP_MANAGER_ERROR_NONE
+ || !pkg_info->pkgid) {
- return TASK_MGR_ERROR_NONE;
-}
+ _release_pkg_info(pkg_info);
+ return false;
+ }
+ if (app_info_get_label(app_handle, &pkg_info->name) != APP_MANAGER_ERROR_NONE
+ || !pkg_info->name) {
+ _release_pkg_info(pkg_info);
+ return false;
+ }
-static Eina_Bool _remove_pkginfo(const Eina_Hash *hash, const void *key, void *data, void *fdata)
-{
- retv_if(!data, EINA_FALSE);
+ if (app_info_is_nodisplay(app_handle, &pkg_info->nodisplay) != APP_MANAGER_ERROR_NONE) {
- private_pkginfo_s *pkg_info = data;
+ _release_pkg_info(pkg_info);
+ return false;
+ }
- if (pkg_info->name) free(pkg_info->name);
- if (pkg_info->icon) free(pkg_info->icon);
- if (pkg_info->pkgid) free(pkg_info->pkgid);
- if (pkg_info->appid) free(pkg_info->appid);
+ if (app_info_get_icon(app_handle, &pkg_info->icon) != APP_MANAGER_ERROR_NONE
+ || !pkg_info->icon) {
- return EINA_TRUE;
-}
+ _release_pkg_info(pkg_info);
+ return false;
+ }
+ if (0 != access(pkg_info->icon, F_OK)) {
+ _D("Fail to access icon path");
+ pkg_info->icon = strdup(util_get_file_path(APP_DIR_RESOURCE, ITEM_LAYOUT_EDJ));
+ }
-static void _destroy_pkginfo_table(void)
-{
- _D("");
+ _D("AppID: %s", pkg_info->appid);
+ _D("PkgID: %s", pkg_info->pkgid);
+ _D("Icon: %s", pkg_info->icon);
+ _D("Label: %s", pkg_info->name);
- eina_hash_foreach(private_table_s.pkginfo_table, _remove_pkginfo, NULL);
- eina_hash_free(private_table_s.pkginfo_table);
- private_table_s.pkginfo_table = NULL;
-}
+ *pkg_list = eina_list_append(*pkg_list, pkg_info);
+ return true;
+}
static int _launch_time_sort_cb(const void *d1, const void *d2)
{
return tmp1->launch_time >= tmp2->launch_time ? -1 : 1;
}
+static task_mgr_error_e _get_running_apps(Eina_List **pkg_list)
+{
+ _D("");
+ app_info_filter_h handle;
+ int ret = 0;
-extern task_mgr_error_e list_sort(Eina_List *list, int (*_sort_cb)(const void *d1, const void *d2))
-{
- retv_if(!list, TASK_MGR_ERROR_INVALID_PARAMETER);
+ ret = app_info_filter_create(&handle);
+ if (ret != APP_MANAGER_ERROR_NONE)
+ return TASK_MGR_ERROR_FAIL;
- list = eina_list_sort(list, eina_list_count(list), _sort_cb);
- retv_if(!list, TASK_MGR_ERROR_FAIL);
+ ret = app_info_filter_add_bool(handle, PACKAGE_INFO_PROP_APP_TASKMANAGE, 1);
+ if (ret != APP_MANAGER_ERROR_NONE) {
+ app_info_filter_destroy(handle);
+ return TASK_MGR_ERROR_FAIL;
+ }
- return TASK_MGR_ERROR_NONE;
-}
+ ret = app_info_filter_foreach_appinfo(handle, _get_pkginfo_cb, pkg_list);
+ if (ret != APP_MANAGER_ERROR_NONE) {
+ app_info_filter_destroy(handle);
+ return TASK_MGR_ERROR_FAIL;
+ }
+ app_info_filter_destroy(handle);
+ return TASK_MGR_ERROR_NONE;
+}
-extern task_mgr_error_e list_create(Eina_List **pkg_list)
+Eina_List *list_sort(Eina_List *list, int (*_sort_cb)(const void *d1, const void *d2))
{
- _D("");
+ retv_if(!list, NULL);
- rua_init();
- char **table = NULL;
- list_type_default_s *default_info = NULL;
+ list = eina_list_sort(list, eina_list_count(list), _sort_cb);
+ retv_if(!list, NULL);
- int nrows = 0, ncols = 0;
- int row = 0;
+ return list;
+}
- retv_if (TASK_MGR_ERROR_NONE != _create_pkginfo_table(), TASK_MGR_ERROR_FAIL);
+extern task_mgr_error_e list_create(Eina_List **pkg_list)
+{
+ int ret = TASK_MGR_ERROR_NONE;
- if (-1 == rua_history_load_db(&table, &nrows, &ncols)) {
- if (table) {
- rua_history_unload_db(&table);
- }
+ ret = _get_running_apps(pkg_list);
+ if (ret != TASK_MGR_ERROR_NONE || !*pkg_list) {
+ list_destroy(*pkg_list);
return TASK_MGR_ERROR_FAIL;
}
- _D("Apps in rua history is %d", nrows);
-
- for (; row < nrows; row++) {
- struct rua_rec rec_result = {0, };
- rua_history_get_rec(&rec_result, table, nrows, ncols, row);
- default_info = _pkglist_retrieve_item(rec_result.pkg_name, rec_result.arg, rec_result.launch_time);
- if (default_info) {
- *pkg_list = eina_list_append(*pkg_list, default_info);
- }
- }
-
- if (*pkg_list && TASK_MGR_ERROR_NONE != list_sort(*pkg_list, _launch_time_sort_cb)) {
- _E("Cannot sort pkg_list");
+ ret = _get_app_launchtime(*pkg_list);
+ if (ret != TASK_MGR_ERROR_NONE || !*pkg_list) {
+ list_destroy(*pkg_list);
+ return TASK_MGR_ERROR_FAIL;
}
- if (!eina_list_count(*pkg_list)) {
- _D("list is empty.");
- _pkglist_unretrieve_item(default_info);
- return TASK_MGR_ERROR_NO_DATA;
-
+ *pkg_list = list_sort(*pkg_list, _launch_time_sort_cb);
+ if (!*pkg_list) {
+ list_destroy(*pkg_list);
+ return TASK_MGR_ERROR_FAIL;
}
return TASK_MGR_ERROR_NONE;
}
-
-
extern void list_destroy(Eina_List *pkg_list)
{
_D("");
list_type_default_s *default_info = NULL;
- _destroy_pkginfo_table();
-
if (!pkg_list) {
_D("pkg_list is null");
return;
}
pkg_list = NULL;
- rua_fini();
}