From: Hwankyu Jhun Date: Tue, 23 Jul 2019 09:34:28 +0000 (+0900) Subject: Use RUA Manager X-Git-Tag: submit/tizen/20190729.054923^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_6.0;p=profile%2Fwearable%2Fapps%2Fnative%2Ftaskmanager.git Use RUA Manager To prevent API break issue, task-manager uses `rua_manager.h` instead of `rua.h`. Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/librua/+/209983/ Change-Id: Ic5fcc39d8d10e771728f9dfe0e45120d33186220 Signed-off-by: Hwankyu Jhun --- diff --git a/src/App/inc/MainController.h b/src/App/inc/MainController.h index 701742e..d35dc42 100644 --- a/src/App/inc/MainController.h +++ b/src/App/inc/MainController.h @@ -47,7 +47,7 @@ namespace TaskMngr { void update(); void updateIndex(int itemsCount); void updateNoContents(int itemsCount); - TaskListViewItem *createItem(const AppInfo &appInfo); + TaskListViewItem *createItem(std::shared_ptr ruaInfo); private: TaskListView *m_pTaskListView; diff --git a/src/App/inc/TaskListView.h b/src/App/inc/TaskListView.h index 7374047..0120d93 100644 --- a/src/App/inc/TaskListView.h +++ b/src/App/inc/TaskListView.h @@ -96,7 +96,7 @@ namespace TaskMngr Evas_Object *m_pBox; Evas_Object *m_RightPadding; Evas_Object *m_LeftPadding; - AppInfo m_AppInfo; + std::shared_ptr m_RuaInfo; Ecore_Idler *m_pBoxSizeChangedIdler; int m_LastItemsCount; }; diff --git a/src/App/inc/TaskListViewItem.h b/src/App/inc/TaskListViewItem.h index bf38b3d..56fd02c 100644 --- a/src/App/inc/TaskListViewItem.h +++ b/src/App/inc/TaskListViewItem.h @@ -27,7 +27,7 @@ namespace TaskMngr class TaskListViewItem : public View { public: - TaskListViewItem(TaskListView &parent, const AppInfo &appInfo); + TaskListViewItem(TaskListView &parent, std::shared_ptr ruaInfo); virtual ~TaskListViewItem(); static int getWidth(); @@ -54,10 +54,10 @@ namespace TaskMngr void playKillDownAnim(); /** - * @brief Gets AppInfo bound with this item - * @returns reference to AppInfo + * @brief Gets RuaInfo bound with this item + * @returns reference to RuaInfo */ - const AppInfo &getAppInfo() const; + std::shared_ptr& getRuaInfo(); /** * @brief Highlight Icon for screenreader @@ -103,7 +103,7 @@ namespace TaskMngr int m_DownYPos; bool m_IsDragStart; bool m_IsMouseDown; - AppInfo m_AppInfo; + std::shared_ptr m_RuaInfo; DelButton *m_pDelButton; double m_MoveDistance; // 0..1; bool m_IsKillAnimPlaying; diff --git a/src/App/inc/TaskMngrService.h b/src/App/inc/TaskMngrService.h index 3252e38..92dbcf2 100644 --- a/src/App/inc/TaskMngrService.h +++ b/src/App/inc/TaskMngrService.h @@ -17,20 +17,39 @@ #ifndef TaskMngrService_h_ #define TaskMngrService_h_ +#include + #include #include -#include -#include +#include + +#include "Logger.h" namespace TaskMngr { - struct AppInfo { - std::string pkgid; - std::string appid; - std::string instanceId; - std::string name; - std::string icon; - std::string uri; - time_t launchTime; + class RuaInfo { + public: + explicit RuaInfo(rua_info_h raw) : m_Raw(raw) { } + + ~RuaInfo() + { + if (m_Raw) + rua_info_destroy(m_Raw); + } + + std::string getName(); + std::string getIcon(); + std::string getImage(); + + rua_info_h getRaw() const + { + return m_Raw; + } + + private: + rua_info_h m_Raw = nullptr; + std::string m_Name; + std::string m_Icon; + std::string m_Image; }; class TaskMngrService { @@ -41,44 +60,37 @@ namespace TaskMngr { /** * @brief Shutdowns given currently running application. * - * @param[in] appid The ID of the application - * @param[in] instance_id The instance ID of the application + * @param[in] info The RUA information handle * * @return true or false on failure */ - bool killApp(const std::string &appid, const std::string &instanceId = std::string()); + bool killApp(const RuaInfo& info); + /** * @brief Resumes the given application. * - * @param[in] appid The ID of the application - * @param[in] instanceId The instance ID of the application - * @param[in] uri The URI of the data + * @param[in] info The RUA information handle * * @return true or false on failure */ - bool launchApp(const std::string &appid, const std::string &instanceId = std::string(), const std::string &uri = std::string()); + bool launchApp(const RuaInfo& info); /** * @brief Get or create list of launched applications * * @return list with information about launched applications */ - std::vector getAppInfo(); + std::vector> &getRuaInfo(); + private: + bool deleteRua(const RuaInfo& info); + bool sendLaunchRequest(const RuaInfo& info); + static void OnAppControlResultCB(app_control_h request, app_control_error_e result, void *user_data); private: TaskMngrService(const TaskMngrService&) = delete; TaskMngrService& operator=(TaskMngrService) = delete; - void init(); - void finit(); - void filterCreate(); - void findAndAppendApp(); - bool appInfoCb(app_info_h app_info); - void fillAppInfoList(char **table, int &rows, int &cols); - private: - rua_rec m_RuaRecord; - app_info_filter_h m_Filter; - std::vector m_AppInfo; + std::vector> m_RuaInfo; }; } diff --git a/src/App/src/MainController.cpp b/src/App/src/MainController.cpp index 13b3817..9b8da02 100644 --- a/src/App/src/MainController.cpp +++ b/src/App/src/MainController.cpp @@ -47,18 +47,18 @@ MainController::~MainController() { } -TaskListViewItem *MainController::createItem(const AppInfo &appInfo) +TaskListViewItem *MainController::createItem(std::shared_ptr ruaInfo) { - auto item = new TaskListViewItem(*m_pTaskListView, appInfo); + auto item = new TaskListViewItem(*m_pTaskListView, std::move(ruaInfo)); return item; } void MainController::update() { m_pTaskListView->clear(); - auto list = App::getInst().getTaskMngr().getAppInfo(); - for (const AppInfo &appInfo : list) { - auto item = createItem(appInfo); + auto list = App::getInst().getTaskMngr().getRuaInfo(); + for (auto ruaInfo : list) { + auto item = createItem(ruaInfo); if (item) { m_pTaskListView->appendItem(*item); } @@ -127,11 +127,11 @@ void MainController::onCurrentPageChanged(TaskListView &obj) void MainController::onClicked(TaskListViewItem &item) { LOG(""); - App::getInst().getTaskMngr().launchApp(item.getAppInfo().appid, item.getAppInfo().instanceId, item.getAppInfo().uri); + App::getInst().getTaskMngr().launchApp(*item.getRuaInfo()); } void MainController::onItemBeforeDelete(TaskListViewItem &item) { LOG(""); - App::getInst().getTaskMngr().killApp(item.getAppInfo().appid, item.getAppInfo().instanceId); + App::getInst().getTaskMngr().killApp(*item.getRuaInfo()); } diff --git a/src/App/src/TaskListViewItem.cpp b/src/App/src/TaskListViewItem.cpp index a1d28a0..3440f2b 100644 --- a/src/App/src/TaskListViewItem.cpp +++ b/src/App/src/TaskListViewItem.cpp @@ -29,7 +29,7 @@ using namespace TaskMngr; #define HEIGHT ELM_SCALE_SIZE(360) #define ICON_WIDTH ELM_SCALE_SIZE(216) -TaskListViewItem::TaskListViewItem(TaskListView &parent, const AppInfo &appInfo) +TaskListViewItem::TaskListViewItem(TaskListView &parent, std::shared_ptr ruaInfo) : m_Parent(parent) , m_pTaskLayout(nullptr) , m_pLabel(nullptr) @@ -37,7 +37,7 @@ TaskListViewItem::TaskListViewItem(TaskListView &parent, const AppInfo &appInfo) , m_DownYPos(0) , m_IsDragStart(false) , m_IsMouseDown(false) - , m_AppInfo(appInfo) + , m_RuaInfo(std::move(ruaInfo)) , m_pDelButton(nullptr) , m_MoveDistance(0) , m_IsKillAnimPlaying(false) @@ -61,8 +61,11 @@ TaskListViewItem::TaskListViewItem(TaskListView &parent, const AppInfo &appInfo) showDelButton(true); setContent(m_pTaskLayout, "swallow.content"); - setText(m_AppInfo.name); - setIcon(m_AppInfo.icon); + setText(m_RuaInfo->getName()); + if (m_RuaInfo->getImage().empty()) + setIcon(m_RuaInfo->getIcon()); + else + setIcon(m_RuaInfo->getImage()); m_pDelButton = new DelButton(m_pTaskLayout); m_pDelButton->addSmartCb("clicked", makeCbFirst(&TaskListViewItem::onDelButtonClicked), this); @@ -88,9 +91,9 @@ void TaskListViewItem::startAnimator() m_pAnimator = ecore_animator_add(makeCbFirst(&TaskListViewItem::onAnimator), this); } -const AppInfo &TaskListViewItem::getAppInfo() const +std::shared_ptr &TaskListViewItem::getRuaInfo() { - return m_AppInfo; + return m_RuaInfo; } void TaskListViewItem::highlightIcon() @@ -115,7 +118,7 @@ void TaskListViewItem::setIcon(const std::string &path) elm_object_part_content_set(m_pTaskLayout, "img.app_image", icon); m_AoIcon = elm_access_object_register(icon, m_pTaskLayout); - m_AoIcon.setName(m_AppInfo.name); + m_AoIcon.setName(m_RuaInfo->getName()); m_AoIcon.setDescriptionCb(makeCbFirst(&TaskListViewItem::onChangeDescription), this); m_AoIcon.setReadingInfo(ELM_ACCESSIBLE_READING_INFO_TYPE_NAME | ELM_ACCESSIBLE_READING_INFO_TYPE_DESCRIPTION); m_AoIcon.setAccessActionCb(ELM_ACCESS_ACTION_ACTIVATE, makeCbFirst(&TaskListViewItem::onScreenReaderAppClicked), this); diff --git a/src/App/src/TaskMngrService.cpp b/src/App/src/TaskMngrService.cpp index 5041440..740e9b9 100644 --- a/src/App/src/TaskMngrService.cpp +++ b/src/App/src/TaskMngrService.cpp @@ -18,205 +18,193 @@ #include "Logger.h" #include "Callback.h" -#include #include -#include -#include using namespace TaskMngr; -TaskMngrService::TaskMngrService() - : m_RuaRecord() - , m_Filter() +std::string RuaInfo::getName() { - init(); + if (!m_Name.empty()) + return m_Name; + + char* name = nullptr; + rua_info_get_instance_name(getRaw(), &name); + if (name == nullptr) { + rua_info_get_label(getRaw(), &name); + if (name == nullptr) + rua_info_get_app_id(getRaw(), &name); + } + + std::unique_ptr ptr(name, std::free); + + m_Name = std::string(ptr.get()); + return m_Name; } -TaskMngrService::~TaskMngrService() +std::string RuaInfo::getIcon() { - finit(); + if (!m_Icon.empty()) + return m_Icon; + + char* icon = nullptr; + rua_info_get_icon(getRaw(), &icon); + if (icon == nullptr) + return std::string(""); + + std::unique_ptr ptr(icon, std::free); + + m_Icon = std::string(ptr.get()); + return m_Icon; } -bool TaskMngrService::killApp(const std::string &appid, const std::string &instanceId) +std::string RuaInfo::getImage() { - TRACE; - int ret = 0; - bool running = false; - app_context_h context = nullptr; - - if (instanceId.empty()) { - app_manager_is_running(appid.c_str(), &running); - if (running) - app_manager_get_app_context(appid.c_str(), &context); - } else { - app_manager_get_app_context_by_instance_id(appid.c_str(), instanceId.c_str(), &context); - } - - if (context) { - app_manager_terminate_app(context); - app_context_destroy(context); - } - - LOG("terminate app = ", appid); - ret = rua_delete_history_with_instance_id(appid.c_str(), instanceId.c_str()); - - return !ret; + if (!m_Image.empty()) + return m_Image; + + char* image = nullptr; + rua_info_get_image(getRaw(), &image); + if (image == nullptr) + return std::string(""); + + std::unique_ptr ptr(image, std::free); + + m_Image = std::string(ptr.get()); + return m_Image; } -bool TaskMngrService::launchApp(const std::string &appid, const std::string &instanceId, const std::string &uri) +TaskMngrService::TaskMngrService() = default; +TaskMngrService::~TaskMngrService() = default; + +bool TaskMngrService::killApp(const RuaInfo& info) { - TRACE; - int ret = 0; - app_control_h service = nullptr; - app_context_h context = nullptr; - - if (!instanceId.empty()) - app_manager_get_app_context_by_instance_id(appid.c_str(), instanceId.c_str(), &context); - else - app_manager_get_app_context(appid.c_str(), &context); - - if (context) { - LOG("Application ID is running ", appid); - ret = app_manager_resume_app(context); - app_context_destroy(context); - if (ret == APP_MANAGER_ERROR_NONE) - return true; - else - LOG("Failed to resume application ", appid); - } - - app_control_create(&service); - if (!service) - return false; - - app_control_set_operation(service, APP_CONTROL_OPERATION_MAIN); - app_control_set_app_id(service, appid.c_str()); - - if (!uri.empty()) - app_control_set_uri(service, uri.c_str()); - - ret = app_control_send_launch_request(service, nullptr, nullptr); - app_control_destroy(service); - if (ret != APP_CONTROL_ERROR_NONE) { - LOG_ERROR("Failed to send launch request"); - return false; - } - - return true; + rua_context_h context_inst; + int ret = rua_manager_get_rua_context_from_rua_info(info.getRaw(), &context_inst); + if (ret != RUA_ERROR_NONE) { + LOG_ERROR("Failed to get rua context from rua info. error(%d)", ret); + return false; + } + + std::unique_ptr::type, decltype(rua_context_destroy)*> handle(context_inst, rua_context_destroy); + + bool running; + ret = rua_manager_is_running(handle.get(), &running); + if (ret != RUA_ERROR_NONE) { + LOG_ERROR("Failed to check running state. error(%d)", ret); + return false; + } + + if (!running) { + LOG_WARN("The application is not running"); + return deleteRua(info); + } + + ret = rua_manager_terminate(handle.get()); + if (ret != RUA_ERROR_NONE) { + LOG_ERROR("Failed to send terminate request. error(%d)", ret); + return false; + } + + return deleteRua(info); } -std::vector TaskMngrService::getAppInfo() +bool TaskMngrService::launchApp(const RuaInfo& info) { - m_AppInfo.clear(); + rua_context_h context_inst; + int ret = rua_manager_get_rua_context_from_rua_info(info.getRaw(), &context_inst); + if (ret != RUA_ERROR_NONE) { + LOG_ERROR("Failed to get rua context from rua info. error(%d)", ret); + return false; + } - char **table = nullptr; - int rows = 0; - int cols = 0; + std::unique_ptr::type, decltype(rua_context_destroy)*> handle(context_inst, rua_context_destroy); - if (rua_history_load_db(&table, &rows, &cols)) { - LOG_ERROR("rua_history_load_db failed!"); - } + bool running; + ret = rua_manager_is_running(handle.get(), &running); + if (ret != RUA_ERROR_NONE || !running) + return sendLaunchRequest(info); - if (table) { - fillAppInfoList(table, rows, cols); - rua_history_unload_db(&table); - } + ret = rua_manager_resume(handle.get()); + if (ret != RUA_ERROR_NONE) + return sendLaunchRequest(info); - return m_AppInfo; + return true; } -void TaskMngrService::init() +std::vector> &TaskMngrService::getRuaInfo() { - if (rua_init()) { - LOG_ERROR("rua_init failed!"); - } - - filterCreate(); + m_RuaInfo.clear(); + + int ret = rua_manager_foreach_rua_info( + [](rua_info_h info, void* user_data)->bool { + bool taskmanage; + int ret = rua_info_is_managed_by_task_manager(info, &taskmanage); + if (ret != RUA_ERROR_NONE) { + LOG_ERROR("Failed to check taskmanage. error(%d)", ret); + return false; + } + + if (!taskmanage) + return true; + + rua_info_h clone; + ret = rua_info_clone(info, &clone); + if (ret != RUA_ERROR_NONE) { + LOG_ERROR("Failed to clone rua info. error(%d)", ret); + return false; + } + + TaskMngrService* taskmngr = static_cast(user_data); + taskmngr->m_RuaInfo.emplace_back(new RuaInfo(clone)); + return true; + }, this); + if (ret != RUA_ERROR_NONE) + LOG_ERROR("Failed to retrieve rua info. error(%d)", ret); + + return m_RuaInfo; } -void TaskMngrService::finit() +bool TaskMngrService::deleteRua(const RuaInfo& info) { - app_info_filter_destroy(m_Filter); - rua_fini(); -} + int ret = rua_manager_delete_rua_info(info.getRaw()); + if (ret != RUA_ERROR_NONE) { + LOG_ERROR("Failed to delete rua info. error(%d)", ret); + return false; + } -void TaskMngrService::filterCreate() -{ - app_info_filter_create(&m_Filter); - app_info_filter_add_bool(m_Filter, PACKAGE_INFO_PROP_APP_TASKMANAGE, true); + return true; } -void TaskMngrService::findAndAppendApp() +bool TaskMngrService::sendLaunchRequest(const RuaInfo& info) { - app_info_filter_add_string(m_Filter, PACKAGE_INFO_PROP_APP_ID, m_RuaRecord.pkg_name); - app_info_filter_foreach_appinfo(m_Filter, makeCbLast(&TaskMngrService::appInfoCb), this); + app_control_h app_control_inst; + int ret = rua_manager_get_app_control_from_rua_info(info.getRaw(), &app_control_inst); + if (ret != RUA_ERROR_NONE) { + LOG_ERROR("Failed to get app control from rua info. error(%d)", ret); + return false; + } + + std::unique_ptr::type, decltype(app_control_destroy)*> handle(app_control_inst, app_control_destroy); + + ret = app_control_send_launch_request_async(handle.get(), OnAppControlResultCB, nullptr, nullptr); + if (ret != APP_CONTROL_ERROR_NONE) { + LOG_ERROR("Failed to send launch request. error(%d)", ret); + return false; + } + + return true; } -bool TaskMngrService::appInfoCb(app_info_h appInfo) +void TaskMngrService::OnAppControlResultCB(app_control_h request, app_control_error_e result, void *user_data) { - AppInfo item; - char *variable = nullptr; - int ret = 0; - - app_info_get_package(appInfo, &variable); - if (variable) { - item.pkgid = variable; - free(variable); - variable = nullptr; - } - - app_info_get_app_id(appInfo, &variable); - if (variable) { - item.appid = variable; - free(variable); - variable = nullptr; - } - - if (m_RuaRecord.uri) - item.uri = m_RuaRecord.uri; - - if (m_RuaRecord.instance_id) - item.instanceId = m_RuaRecord.instance_id; - - if (m_RuaRecord.instance_name) { - item.name = m_RuaRecord.instance_name; - } else { - app_info_get_label(appInfo, &variable); - if (variable) { - item.name = variable; - free(variable); - variable = nullptr; - } - } - - if (m_RuaRecord.image) { - item.icon = m_RuaRecord.image; // snapshot - } else if (m_RuaRecord.icon) { - item.icon = m_RuaRecord.icon; // icon - } else { - ret = app_info_get_icon(appInfo, &variable); // icon - if (variable) { - item.icon = variable; - free(variable); - variable = nullptr; - } else { - LOG_WARN("icon is null"); - } - } - item.launchTime = m_RuaRecord.launch_time; - - if (item.name.empty() && item.icon.empty()) - return false; - - m_AppInfo.push_back(std::move(item)); - - return true; -} + char *id; + int ret = app_control_get_app_id(request, &id); + if (ret != APP_CONTROL_ERROR_NONE) { + LOG_ERROR("Failed to get application ID"); + return; + } -void TaskMngrService::fillAppInfoList(char **table, int &rows, int &cols) -{ - for (int row = 0; row < rows; ++row) { - rua_history_get_rec(&m_RuaRecord, table, rows, cols, row); - findAndAppendApp(); - } + std::unique_ptr appid(id, std::free); + + LOG_INFO("app_id = %s, result = %d", appid.get(), result); }