From 88c87664277a3be229041b02258c197ade0519b3 Mon Sep 17 00:00:00 2001 From: hyunho Date: Wed, 16 Oct 2019 10:33:53 +0900 Subject: [PATCH] Support component-based application Change-Id: I28728301e5322d1882d8f13e70de19aa1df09717 Signed-off-by: hyunho --- CMakeLists.txt | 1 + inc/apps_data.h | 1 + inc/apps_package_manager.h | 2 + packaging/org.tizen.homescreen-efl.spec | 1 + src/apps_data.c | 1 + src/apps_db.c | 20 ++- src/apps_package_manager.c | 224 +++++++++++++++++++++++++++++++- src/apps_view.c | 7 + 8 files changed, 249 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 766befe..beab47d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ pkg_check_modules(PKGS REQUIRED capi-ui-efl-util shortcut storage + capi-appfw-component-manager ) SET(PACKAGE_NAME "org.tizen.${PROJECT_NAME}") diff --git a/inc/apps_data.h b/inc/apps_data.h index d8984f4..717cfcd 100755 --- a/inc/apps_data.h +++ b/inc/apps_data.h @@ -35,6 +35,7 @@ typedef struct { Eina_Bool is_folder; int position; char* app_id; + char* component_id; char* pkg_id; char* label_str; char* icon_path_str; diff --git a/inc/apps_package_manager.h b/inc/apps_package_manager.h index b2196f0..15f840e 100755 --- a/inc/apps_package_manager.h +++ b/inc/apps_package_manager.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "apps_data.h" @@ -30,6 +31,7 @@ void apps_package_manager_init(); void apps_package_manager_init_app_manager_event(); Eina_Bool apps_package_manager_get_internal_list(Eina_List **list); Eina_Bool apps_package_manager_get_external_list(Eina_List **list); +Eina_Bool apps_package_manager_get_component_list(Eina_List **list); void apps_package_manager_update_label(const char *app_id, app_data_t *item); #endif /* __APPS_PACKAGE_MANAGER_H__ */ diff --git a/packaging/org.tizen.homescreen-efl.spec b/packaging/org.tizen.homescreen-efl.spec index a7b9c18..dd57999 100644 --- a/packaging/org.tizen.homescreen-efl.spec +++ b/packaging/org.tizen.homescreen-efl.spec @@ -45,6 +45,7 @@ BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(capi-ui-efl-util) BuildRequires: pkgconfig(shortcut) BuildRequires: pkgconfig(storage) +BuildRequires: pkgconfig(capi-appfw-component-manager) BuildRequires: edje-bin BuildRequires: gettext-devel diff --git a/src/apps_data.c b/src/apps_data.c index 2f328bd..090c9c6 100755 --- a/src/apps_data.c +++ b/src/apps_data.c @@ -49,6 +49,7 @@ void apps_data_init(void *data, Ecore_Thread *th) apps_package_manager_init(); apps_package_manager_get_internal_list(&pkg_list); apps_package_manager_get_external_list(&pkg_list); + apps_package_manager_get_component_list(&pkg_list); apps_package_manager_init_app_manager_event(); if (!apps_db_create()) { diff --git a/src/apps_db.c b/src/apps_db.c index 182b1e8..7079ad8 100755 --- a/src/apps_db.c +++ b/src/apps_db.c @@ -40,7 +40,8 @@ enum { COL_IS_REMOVABLE, COL_ICON_PATH, COL_STORAGE_TYPE, - COL_ENABLE + COL_ENABLE, + COL_COMPONENT_ID }; #define CREATE_APPS_DB_TABLE "create table if not exists apps(\ @@ -58,7 +59,8 @@ enum { isRemovable INTEGER,\ iconPath TEXT,\ storage_type INTEGER,\ - enable INTEGER);" + enable INTEGER,\ + component_id TEXT);" #define UPDATE_APPS_DB_TABLE "UPDATE apps set \ parentId=?,\ @@ -74,7 +76,8 @@ enum { isRemovable=?,\ iconPath=?,\ storage_type=?,\ - enable=? WHERE id = ?" + enable=?,\ + component_id=? WHERE id = ?" #define INSERT_APPS_DB_TABLE "INSERT into apps (\ parentId,\ @@ -90,7 +93,8 @@ enum { isRemovable,\ iconPath,\ storage_type,\ - enable) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + enable,\ + component_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" static bool __apps_db_open(void); static bool __apps_db_close(void); @@ -171,6 +175,8 @@ bool apps_db_get_list(Eina_List **apps) item->icon_path_str = (!str || !strlen(str)) ? NULL : strdup(str); item->storage_type = sqlite3_column_int(stmt, COL_STORAGE_TYPE); item->enable = sqlite3_column_int(stmt, COL_ENABLE); + str = (const char *)sqlite3_column_text(stmt, COL_COMPONENT_ID); + item->component_id = (!str || !strlen(str)) ? NULL : strdup(str); *apps = eina_list_append(*apps, item); } sqlite3_finalize(stmt); @@ -220,6 +226,8 @@ bool apps_db_get_app_list(Eina_List **apps) item->icon_path_str = (!str || !strlen(str)) ? NULL : strdup(str); item->storage_type = sqlite3_column_int(stmt, COL_STORAGE_TYPE); item->enable = sqlite3_column_int(stmt, COL_ENABLE); + str = (const char *)sqlite3_column_text(stmt, COL_COMPONENT_ID); + item->component_id = (!str || !strlen(str)) ? NULL : strdup(str); *apps = eina_list_append(*apps, item); } sqlite3_finalize(stmt); @@ -252,7 +260,8 @@ bool apps_db_update(app_data_t *item) sqlite3_bind_text(stmt, 12, item->icon_path_str, -1, SQLITE_TRANSIENT); sqlite3_bind_int(stmt, 13, item->storage_type); sqlite3_bind_int(stmt, 14, item->enable); - sqlite3_bind_int(stmt, 15, item->db_id); + sqlite3_bind_text(stmt, 15, item->component_id, -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 16, item->db_id); ret = sqlite3_step(stmt); if (SQLITE_DONE != ret) { @@ -290,6 +299,7 @@ bool apps_db_insert(app_data_t *item) sqlite3_bind_text(stmt, 12, item->icon_path_str, -1, SQLITE_TRANSIENT); sqlite3_bind_int(stmt, 13, item->storage_type); sqlite3_bind_int(stmt, 14, item->enable); + sqlite3_bind_text(stmt, 15, item->component_id, -1, SQLITE_TRANSIENT); ret = sqlite3_step(stmt); if (SQLITE_DONE != ret) { diff --git a/src/apps_package_manager.c b/src/apps_package_manager.c index 7454bf7..9e6db34 100755 --- a/src/apps_package_manager.c +++ b/src/apps_package_manager.c @@ -37,8 +37,8 @@ static void __apps_package_manager_uninstall(const char *package); static void __apps_package_manager_move(const char *package); static void __apps_app_manager_enable_app(const char *app_id); static void __apps_app_manager_disable_app(const char *app_id); - - +static bool __get_component_frame_app_data_item(component_info_h handle, app_info_h app_info, app_data_t **item); +static bool __component_data_get_apps_info(component_info_h handle, char *package, app_data_t **item); void apps_package_manager_init_app_manager_event() { @@ -167,6 +167,74 @@ Eina_Bool apps_package_manager_get_external_list(Eina_List **list) return true; } +static bool __package_component_info_cb(component_info_h handle, void *user_data) { + app_info_h app_info = NULL; + Eina_List **list = (Eina_List **)user_data; + app_data_t *item = NULL; + char *appid = NULL; + char *package = NULL; + component_info_component_type_e type; + bool result = false; + int ret; + + ret = component_info_get_component_type(handle, &type); + if (ret != COMPONENT_MANAGER_ERROR_NONE) { + __E("Failed to get component type"); + goto OUT; + } + + if (type != COMPONENT_INFO_COMPONENT_TYPE_FRAME) + return true; + + ret = component_info_get_app_id(handle, &appid); + if (ret != COMPONENT_MANAGER_ERROR_NONE) { + __E("Failed to get appid"); + goto OUT; + } + + ret = app_info_create(appid, &app_info); + if (ret != APP_MANAGER_ERROR_NONE) { + __E("Failed to get app_info"); + goto OUT; + } + + ret = app_info_get_package(app_info, &package); + if (ret != APP_MANAGER_ERROR_NONE) { + __E("Failed to get package"); + goto OUT; + } + + result = __component_data_get_apps_info(handle, package, &item); + if (result) { + item->storage_type = apps_data_get_storage_type(item->pkg_id); + *list = eina_list_append(*list, item); + result = true; + } +OUT: + if (app_info) + app_info_destroy(app_info); + if (package) + free(package); + if (appid) + free(appid); + + return result; +} + +Eina_Bool apps_package_manager_get_component_list(Eina_List **list) +{ + __D("Get Component-based apps info"); + int ret; + + ret = component_manager_foreach_component_info(__package_component_info_cb, list); + if (ret != COMPONENT_MANAGER_ERROR_NONE) { + __E("Failed to get component info list"); + return false; + } + + return true; +} + static bool __apps_package_manager_get_internal_item(app_info_h app_handle, void *data) { Eina_List **list = (Eina_List **)data; @@ -293,6 +361,117 @@ ERROR: } +static bool __component_data_get_apps_info(component_info_h handle, char *package, app_data_t **item) +{ + bool nodisplay = false; + int ret; + package_info_h p_handle = NULL; + + app_data_t *new_item = (app_data_t *)malloc(sizeof(app_data_t)); + if (!new_item) { + __E("memory allocation is failed!!!"); + return false; + } + + memset(new_item, 0, sizeof(app_data_t)); + *item = new_item; + + component_info_is_icon_display(handle, &nodisplay); + if (nodisplay) { + __D("Nodisplay is TRUE"); + goto ERROR; + } + + new_item->db_id = INIT_VALUE; + new_item->parent_db_id = APPS_ROOT; + new_item->owner = strdup(TEMP_OWNER); + new_item->is_folder = false; + new_item->position = INIT_VALUE; + new_item->uri = NULL; + new_item->type = APPS_DATA_TYPE_APP; + new_item->enable = true; + + new_item->pkg_id = strdup(package); + if (new_item->pkg_id == NULL) { + __E("fail to dup pkg_id (%s)", package); + goto ERROR; + } + + ret = component_info_get_component_id(handle, &new_item->component_id); + if (COMPONENT_MANAGER_ERROR_NONE != ret) { + __E("component_info_get_component_id return [%d] %s", ret, new_item->component_id); + goto ERROR; + } + __D("%s", new_item->component_id); + + ret = component_info_get_app_id(handle, &new_item->app_id); + if (COMPONENT_MANAGER_ERROR_NONE != ret) { + __E("component_info_get_app_id return [%d] %s", ret, new_item->app_id); + goto ERROR; + } + + ret = component_info_get_label(handle, &new_item->label_str); + if (COMPONENT_MANAGER_ERROR_NONE != ret) { + __E("component_info_get_label return [%d] %s", ret, new_item->label_str); + goto ERROR; + } + + ret = component_info_get_icon(handle, &new_item->icon_path_str); + if (COMPONENT_MANAGER_ERROR_NONE != ret) { + __E("component_info_get_icon return [%d]", ret); + goto ERROR; + } + + __D("%s", new_item->pkg_id); + + ret = package_manager_get_package_info(new_item->pkg_id, &p_handle); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + __E("Failed to inialize package handle for item : %s", new_item->pkg_id); + goto ERROR; + } + + ret = package_info_is_removable_package(p_handle, &new_item->is_removable); + if (PACKAGE_MANAGER_ERROR_NONE != ret) { + __E("package_info_is_removable_package return [%d]", ret); + goto ERROR; + } + + ret = package_info_is_system_package(p_handle, &new_item->is_system); + if (PACKAGE_MANAGER_ERROR_NONE != ret) { + __E("package_info_is_system_package return [%d]", ret); + goto ERROR; + } + + if (!new_item->icon_path_str || !ecore_file_can_read(new_item->icon_path_str)) { + if (new_item->icon_path_str) free(new_item->icon_path_str); + + new_item->icon_path_str = malloc(MAX_FILE_PATH_LEN); + if (!new_item->icon_path_str) { + __E("Malloc unable to assign memory for icon_path_str"); + goto ERROR; + } + snprintf(new_item->icon_path_str, MAX_FILE_PATH_LEN, "%s", util_get_res_file_path(IMAGE_DIR"/default_app_icon.png")); + } + return true; + +ERROR: + if (new_item && new_item->label_str) + free(new_item->label_str); + if (new_item && new_item->icon_path_str) + free(new_item->icon_path_str); + if (new_item && new_item->app_id) + free(new_item->app_id); + if (new_item && new_item->pkg_id) + free(new_item->pkg_id); + if (new_item && new_item->component_id) + free(new_item->component_id); + if (new_item && new_item->owner) + free(new_item->owner); + if (new_item) + free(new_item); + return false; +} + void apps_package_manager_update_label(const char *app_id, app_data_t *item) { app_info_h app_info = NULL; @@ -307,6 +486,42 @@ void apps_package_manager_update_label(const char *app_id, app_data_t *item) } } +static bool __get_component_frame_app_data_item(component_info_h handle, + app_info_h app_info, app_data_t **item) { + char *appid; + char *installed_appid; + char *package = NULL; + component_info_component_type_e type; + bool result = false; + + app_info_get_app_id(app_info, &installed_appid); + component_info_get_app_id(handle, &appid); + component_info_get_component_type(handle, &type); + if (strcmp(appid, installed_appid) == 0 && + type == COMPONENT_INFO_COMPONENT_TYPE_FRAME) { + app_info_get_package(app_info, &package); + result = __component_data_get_apps_info(handle, package, item); + } + + free(package); + free(appid); + free(installed_appid); + return result; +} + +static bool __component_info_cb(component_info_h handle, void *user_data) { + app_info_h app_info = (app_info_h)user_data; + app_data_t *item = NULL; + bool result = false; + + result = __get_component_frame_app_data_item(handle, app_info, &item); + if (result) { + item->storage_type = apps_data_get_storage_type(item->pkg_id); + apps_data_install(item); + } + return true; +} + static bool __apps_data_get_app_info_from_pkg(package_info_app_component_type_e comp_type, const char *app_id, void *data) { int ret = APP_MANAGER_ERROR_NONE; @@ -319,7 +534,9 @@ static bool __apps_data_get_app_info_from_pkg(package_info_app_component_type_e return false; } - if (__apps_data_pkg_get_apps_info(app_info, &item)) { + if (comp_type == PACKAGE_INFO_APP_COMPONENT_TYPE_COMPONENT_BASED) { + component_manager_foreach_component_info(__component_info_cb, app_info); + } else if (__apps_data_pkg_get_apps_info(app_info, &item)) { item->storage_type = apps_data_get_storage_type(item->pkg_id); apps_data_install(item); } @@ -377,6 +594,7 @@ static void __apps_package_manager_install(const char *package) __E("Failed to install app from %s", package); return; } + package_info_destroy(package_info); } diff --git a/src/apps_view.c b/src/apps_view.c index 059d0ed..7275a8c 100755 --- a/src/apps_view.c +++ b/src/apps_view.c @@ -830,6 +830,13 @@ static void __apps_view_icon_clicked_cb(void *data, Evas_Object *obj, const char goto __ret; } + if (item->component_id) { + if (app_control_set_component_id(app_control_handle, item->component_id) != APP_CONTROL_ERROR_NONE) { + __E("[FAILED][app_control_set_component_id]"); + goto __ret; + } + } + if (app_control_set_app_id(app_control_handle, item->app_id) != APP_CONTROL_ERROR_NONE) { __E("[FAILED][app_control_set_app_id]"); goto __ret; -- 2.7.4