diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2019-07-15 10:53:36 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2019-07-25 09:00:46 +0900 |
commit | be8d9c31dfa14f558926ea1395743c80933f6136 (patch) | |
tree | 8b74637ad0e3343c6f07d73099366e213b9e14a1 | |
parent | f8e74f71eff86a93dce48dca9d847c18687406fe (diff) | |
download | librua-be8d9c31dfa14f558926ea1395743c80933f6136.tar.gz librua-be8d9c31dfa14f558926ea1395743c80933f6136.tar.bz2 librua-be8d9c31dfa14f558926ea1395743c80933f6136.zip |
Add new APIs for task-manager
Currently, when the rua_rec is changed, the application has crashed if
it uses the rua library. To avoid ABI break issue, new functions are
added.
Adds:
- rua_info_get_app_id()
- rua_info_get_app_path()
- rua_info_get_args()
- rua_info_get_launch_time()
- rua_info_get_instance_id()
- rua_info_get_instance_name()
- rua_info_get_icon()
- rua_info_get_uri()
- rua_info_get_image()
- rua_info_get_component_id()
- rua_info_is_managed_by_task_manager()
- rua_info_get_label()
- rua_info_destroy()
- rua_info_clone()
- rua_context_destroy()
- rua_context_get_app_id()
- rua_context_get_instance_id()
- rua_context_get_component_id()
- rua_manager_foreach_rua_info()
- rua_manager_delete_rua_info()
- rua_manager_delete_all_rua_info()
- rua_manager_get_app_control_from_rua_info()
- rua_manager_get_rua_context_from_rua_info()
- rua_manager_is_running()
- rua_manager_resume()
- rua_manager_terminate()
Change-Id: Iea4a135b1980f855f1f2594b83da4b9a2e80e980
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | include/rua_context.h | 84 | ||||
-rw-r--r-- | include/rua_info.h | 251 | ||||
-rw-r--r-- | include/rua_manager.h | 157 | ||||
-rw-r--r-- | include/rua_types.h | 43 | ||||
-rw-r--r-- | packaging/librua.spec | 2 | ||||
-rw-r--r-- | rua.pc.in | 2 | ||||
-rw-r--r-- | src/rua.c | 6 | ||||
-rw-r--r-- | src/rua_context.c | 268 | ||||
-rw-r--r-- | src/rua_context_internal.h | 41 | ||||
-rw-r--r-- | src/rua_info.c | 926 | ||||
-rw-r--r-- | src/rua_info_internal.h | 35 | ||||
-rw-r--r-- | src/rua_manager.c | 160 | ||||
-rw-r--r-- | src/rua_private.h | 22 |
14 files changed, 1996 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 62af4a8..7d95170 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ AUX_SOURCE_DIRECTORY(src SRCS) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED sqlite3 libtzplatform-config bundle aul gio-2.0 glib-2.0) +pkg_check_modules(pkgs REQUIRED sqlite3 libtzplatform-config bundle aul gio-2.0 glib-2.0 capi-appfw-app-control pkgmgr-info) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -37,5 +37,9 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua.h DESTINATION include/${PR INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_internal.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_stat.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_stat_internal.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_info.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_types.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_context.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_manager.h DESTINATION include/${PROJECT_NAME}) ADD_SUBDIRECTORY(test) diff --git a/include/rua_context.h b/include/rua_context.h new file mode 100644 index 0000000..4931b82 --- /dev/null +++ b/include/rua_context.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#ifndef __RUA_CONTEXT_H__ +#define __RUA_CONTEXT_H__ + +#include <rua_types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The RUA context handle. + * @since_tizen 5.5 + */ +typedef struct rua_context_s *rua_context_h; + +/** + * @brief Destroyes the RUA context handle. + * @since_tizen 5.5 + * + * @param[in] context The RUA context handle + * @return @c 0 on success, + * otherwise a negative error value + */ +int rua_context_destroy(rua_context_h context); + +/** + * @brief Gets the application ID of the instance. + * @since_tizen 5.5 + * @remarks You should release @a app_id using free(). + * + * @param[in] context The RUA context handle + * @param[out] app_id The application ID + * @return @c 0 on success, + * otherwise a negative error value + */ +int rua_context_get_app_id(rua_context_h context, char **app_id); + +/** + * @brief Gets the ID of the instance. + * @details The function returns RUA_ERROR_NONE, event if @a instance_id is null. + * @since_tizen 5.5 + * @remarks You should release @a instance_id using free(). + * + * @param[in] context The RUA context handle + * @param[out] instance_id The instance ID + * @return @c 0 on success, + * otherwise a negative error value + */ +int rua_context_get_instance_id(rua_context_h context, char **instance_id); + +/** + * @brief Gets the component ID of the instance. + * @details The function returns RUA_ERROR_NONE, event if @a component_id is null. + * @since_tizen 5.5 + * @remarks You should release @a component_id using free(). + * + * @param[in] context The RUA context handle + * @param[out] component_id The component ID + * @return @c 0 on success, + * otherwise a negative error value + */ +int rua_context_get_component_id(rua_context_h context, char **component_id); + +#ifdef __cplusplus +} +#endif + +#endif /*__RUA_CONTEXT_H__*/ diff --git a/include/rua_info.h b/include/rua_info.h new file mode 100644 index 0000000..b7b22c9 --- /dev/null +++ b/include/rua_info.h @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#ifndef __RUA_INFO_H__ +#define __RUA_INFO_H__ + +#include <time.h> +#include <sys/types.h> + +#include <rua_types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The RUA information handle. + * @since_tizen 5.5 + */ +typedef struct rua_info_s *rua_info_h; + +/** + * @brief Gets the ID of the application. + * @since_tizen 5.5 + * @remarks You should release @a app_id using free(). + * + * @param[in] info The RUA information handle + * @param[out] app_id The application ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_app_id(rua_info_h info, char **app_id); + +/** + * @brief Gets the path of the application. + * @since_tizen 5.5 + * @remarks You should release @a app_path using free(). + * + * @param[in] info The RUA information handle + * @param[out] app_path The application path + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_app_path(rua_info_h info, char **app_path); + +/** + * @brief Gets the arguments of the application. + * @since_tizen 5.5 + * @remarks You should release @a args using free(). + * + * @param[in] info The RUA information handle + * @param[out] args The arguments + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_args(rua_info_h info, char **args); + +/** + * @brief Gets the launch time of the application. + * @since_tizen 5.5 + * + * @param[in] info The RUA information handle + * @param[out] launch_time The launch time + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_launch_time(rua_info_h info, time_t *launch_time); + +/** + * @brief Gets the instance ID of the application. + * @details The function returns RUA_ERROR_NONE, event if @a instance_id is null. + * @since_tizen 5.5 + * @remarks You should release @a instance_id using free(). + * + * @param[in] info The RUA information handle + * @param[out] instance_id The instance ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_instance_id(rua_info_h info, char **instance_id); + +/** + * @brief Gets the instance name of the application. + * @details The function returns RUA_ERROR_NONE, event if @a instance_name is null. + * @since_tizen 5.5 + * @remarks You should release @a instance_name using free(). + * + * @param[in] info The RUA information handle + * @param[out] instance_name The instance name + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_instance_name(rua_info_h info, char **instance_name); + +/** + * @brief Gets the icon path of the application. + * @details The function returns RUA_ERROR_NONE, event if @a icon is null. + * @since_tizen 5.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/packagemanager.info + * @remarks You should release @a icon using free(). + * + * @param[in] info The RUA information handle + * @param[out] icon The icon path + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_icon(rua_info_h info, char **icon); + +/** + * @brief Gets the URI of the application. + * @details The function returns RUA_ERROR_NONE, event if @a uri is null. + * @since_tizen 5.5 + * @remarks You should release @a uri using free(). + * + * @param[in] info The RUA information handle + * @param[out] uri The URI + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_uri(rua_info_h info, char **uri); + +/** + * @brief Gets the image path of the application. + * @details The function returns RUA_ERROR_NONE, event if @a image is null. + * @since_tizen 5.5 + * @remarks You should release @a image using free(). + * + * @param[in] info The RUA information handle + * @param[out] image The image path + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_image(rua_info_h info, char **image); + +/** + * @brief Gets the component ID of the application. + * @details The function returns RUA_ERROR_NONE, event if @a component_id is null. + * @since_tizen 5.5 + * @remarks You should release @a component_id using free(). + * + * @param[in] info The RUA information handle + * @param[out] component_id The component ID + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_component_id(rua_info_h info, char **component_id); + +/** + * @brief Checks whether the application should be managed by task-manager or not. + * @since_tizen 5.5 + * + * @param[in] info The RUA information handle + * @param[out] managed @c true if the application should be managed by task-manager, \n + * otherwise @c false + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_forach() + */ +int rua_info_is_managed_by_task_manager(rua_info_h info, bool *managed); + +/** + * @brief Gets the label. + * @details The function returns RUA_ERROR_NONE, event if @a label is null. + * @since_tizen 5.5 + * @remarks You should release @a label using free(). + * + * @param[in] info The RUA information handle + * @param[out] label The label + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + */ +int rua_info_get_label(rua_info_h info, char **label); + +/** + * @brief Destroyes the RUA information handle. + * @since_tizen 5.5 + * + * @param[in] info The RUA information handle + * @return @c 0 on success, + * otherwise a negative error value + */ +int rua_info_destroy(rua_info_h info); + +/** + * @brief Creates and returns a copy of the given RUA information handle. + * @since_tizen 5.5 + * @remarks You should release @a clone using rua_info_destroy(). + * + * @param[in] info The RUA information handle + * @param[out] clone If successful, a newly created RUA information handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_destroy() + */ +int rua_info_clone(rua_info_h info, rua_info_h *clone); + +#ifdef __cplusplus +} +#endif + +#endif /*__RUA_INFO_H__*/ diff --git a/include/rua_manager.h b/include/rua_manager.h new file mode 100644 index 0000000..a382d1c --- /dev/null +++ b/include/rua_manager.h @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#ifndef __RUA_MANAGER_H__ +#define __RUA_MANAGER_H__ + +#include <app_control.h> +#include <rua_context.h> +#include <rua_info.h> +#include <rua_types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Called to get the RUA information once for each launched application. + * @since_tizen 5.5 + * @remarks After this callback returns, the handle of the RUA information handle is freed. + * Therefore, if you want to use the handle after returning this callback, you MUST copy it by using rua_info_clone() function. + * + * @param[in] info The RUA information handle + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, \n + * otherwise @c false to break out of the loop + * + * @see rua_manager_foreach_rua_info() + * @see rua_manager_foreach_all_rua_info() + */ +typedef bool (*rua_manager_rua_info_cb)(rua_info_h info, void *user_data); + +/** + * @brief Retrieves all launched applications information. + * @since_tizen 5.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/packagemanager.info + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach_cb() + */ +int rua_manager_foreach_rua_info(rua_manager_rua_info_cb callback, void *user_data); + +/** + * @brief Deletes the RUA information. + * @since_tizen 5.5 + * + * @param[in] info The RUA information handle + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only available for platform level signed applications. + */ +int rua_manager_delete_rua_info(rua_info_h info); + +/** + * @brief Deletes all RUA informations. + * @since_tizen 5.5 + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @remarks This function is only available for platform level signed applications. + */ +int rua_manager_delete_all_rua_info(void); + +/** + * @brief Gets the app_control handle from the given RUA information handle. + * @since_tizen 5.5 + * @remarks You should release @a app_control using app_control_destroy(). + * + * @param[in] info The RUA information handle + * @param[out] app_control The app_control handle + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + * @see app_control_send_launch_request() + * @see app_control_send_launch_request_async() + * @see app_control_destroy() + */ +int rua_manager_get_app_control_from_rua_info(rua_info_h info, app_control_h *app_control); + +/** + * @brief Gets the RUA context handle from the given RUA information handle. + * @since_tizen 5.5 + * @remarks You should release @a context using rua_context_destroy(). + * + * @param[in] info The RUA information handle + * @param[out] context The RUA context handle + * @return @c 0 on success, + * otherwise a negative error value + * + * @see rua_info_foreach() + * @see rua_info_usr_foreach() + * @see rua_context_destroy() + */ +int rua_manager_get_rua_context_from_rua_info(rua_info_h info, rua_context_h *context); + +/** + * @brief Checks whether the instance with the given RUA context handle is running or not. + * @since_tizen 5.5 + * + * @param[in] context The RUA context handle + * @param[out] running @c true if the instance is running, \n + * otherwise @c false if not running + * @return @c 0 on success, + * otherwise a negative error value + */ +int rua_manager_is_running(rua_context_h context, bool *running); + +/** + * @brief Resumes the instance. + * @since_tizen 5.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/appmanager.launch + * + * @param[in] context The RUA context handle + * @return @c 0 on success, + * otherwise a negative error value + */ +int rua_manager_resume(rua_context_h context); + +/** + * @brief Terminates the instance. + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/appmanager.kill + * + * @param[in] context The RUA context handle + * @return @c 0 on succes, + * otherwise a negative error value + */ +int rua_manager_terminate(rua_context_h context); + +#ifdef __cplusplus +} +#endif + +#endif /*__RUA_MANAGER_H__*/ diff --git a/include/rua_types.h b/include/rua_types.h new file mode 100644 index 0000000..d7bf3ec --- /dev/null +++ b/include/rua_types.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#ifndef __RUA_TYPES_H__ +#define __RUA_TYPES_H__ + +#include <tizen.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumeration for RUA error. + * @since_tizen 5.5 + */ +typedef enum { + RUA_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + RUA_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + RUA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + RUA_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + RUA_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< IO error */ + RUA_ERROR_NO_SUCH_APP = TIZEN_ERROR_NO_SUCH_FILE, /**< No such application */ +} rua_error_e; + +#ifdef __cplusplus +} +#endif + +#endif /*__RUA_TYPES_H__*/ diff --git a/packaging/librua.spec b/packaging/librua.spec index afcb564..5282c30 100644 --- a/packaging/librua.spec +++ b/packaging/librua.spec @@ -14,6 +14,8 @@ BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(capi-appfw-app-control) +BuildRequires: pkgconfig(pkgmgr-info) %description Recently used application library @@ -6,6 +6,6 @@ includedir=@INCLUDEDIR@ Name: rua Description: recently used application library Version: @VERSION@ -Requires: bundle +Requires: bundle capi-appfw-app-control Libs: -L${libdir} -lrua Cflags: -I${includedir} @@ -133,9 +133,9 @@ API int rua_clear_history(void) API int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t uid) { - static const char query[] = - "SELECT pkg_name, app_path, arg, launch_time," - " instance_id, instance_name, icon, uri, image, comp_id " + static const char query[] = "SELECT " + "pkg_name, app_path, arg, launch_time, instance_id, " + "instance_name, icon, uri, image, comp_id " "FROM rua_history ORDER BY launch_time DESC"; int r; char *db_err = NULL; diff --git a/src/rua_context.c b/src/rua_context.c new file mode 100644 index 0000000..8b80a16 --- /dev/null +++ b/src/rua_context.c @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <glib.h> +#include <aul.h> +#include <aul_comp_status.h> + +#include "rua_private.h" +#include "rua_info.h" +#include "rua_context.h" +#include "rua_manager.h" + +struct rua_context_s { + char *app_id; + char *instance_id; + char *component_id; +}; + +static void __destroy_rua_context(struct rua_context_s *context) +{ + free(context->component_id); + free(context->instance_id); + free(context->app_id); + free(context); +} + +static struct rua_context_s *__create_rua_context(char *app_id, + char *instance_id, char *component_id) +{ + struct rua_context_s *context; + + context = calloc(1, sizeof(struct rua_context_s)); + if (!context) { + _E("Out of memory"); + return NULL; + } + + context->app_id = app_id; + context->instance_id = instance_id; + context->component_id = component_id; + + return context; +} + +int rua_context_create_from_rua_info(rua_info_h info, + rua_context_h *context) +{ + struct rua_context_s *handle; + char *app_id; + char *instance_id; + char *component_id; + int ret; + + if (!info || !context) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + ret = rua_info_get_app_id(info, &app_id); + if (ret != RUA_ERROR_NONE) + return ret; + + ret = rua_info_get_instance_id(info, &instance_id); + if (ret != RUA_ERROR_NONE) { + free(app_id); + return ret; + } + + ret = rua_info_get_component_id(info, &component_id); + if (ret != RUA_ERROR_NONE) { + free(instance_id); + free(app_id); + return ret; + } + + handle = __create_rua_context(app_id, instance_id, component_id); + if (!handle) { + free(component_id); + free(instance_id); + free(app_id); + return RUA_ERROR_OUT_OF_MEMORY; + } + + *context = handle; + + return RUA_ERROR_NONE; +} + +API int rua_context_destroy(rua_context_h context) +{ + if (!context) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + __destroy_rua_context(context); + + return RUA_ERROR_NONE; +} + +API int rua_context_get_app_id(rua_context_h context, char **app_id) +{ + if (!context || !app_id) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + *app_id = strdup(context->app_id); + if (*app_id == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +API int rua_context_get_instance_id(rua_context_h context, char **instance_id) +{ + if (!context || !instance_id) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (context->instance_id) { + *instance_id = strdup(context->instance_id); + if (*instance_id == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + } else { + *instance_id = NULL; + } + + return RUA_ERROR_NONE; +} + +API int rua_context_get_component_id(rua_context_h context, char **component_id) +{ + if (!context || !component_id) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (context->component_id) { + *component_id = context->component_id; + if (*component_id == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + } else { + *component_id = NULL; + } + + return RUA_ERROR_NONE; +} + +static int __convert_aul_error(int error) +{ + switch (error) { + case AUL_R_EINVAL: + return RUA_ERROR_INVALID_PARAMETER; + case AUL_R_EILLACC: + return RUA_ERROR_PERMISSION_DENIED; + case AUL_R_ENOAPP: + return RUA_ERROR_NO_SUCH_APP; + default: + return RUA_ERROR_IO_ERROR; + } +} + +int rua_context_is_running(rua_context_h context, bool *running) +{ + int ret; + + if (!context || !running) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (context->component_id) { + ret = aul_comp_is_running(context->instance_id, running); + } else if (context->instance_id) { + ret = aul_app_is_running_with_instance_id(context->app_id, + context->instance_id, running); + } else { + ret = aul_app_is_running(context->app_id); + if (ret >= 0) + *running = (bool)ret; + } + + if (ret < 0) { + _E("Failed to check running state"); + return __convert_aul_error(ret); + } + + return RUA_ERROR_NONE; +} + +int rua_context_resume(rua_context_h context) +{ + int ret; + + if (!context) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (context->component_id) { + ret = aul_comp_resume(context->instance_id); + } else if (context->instance_id) { + ret = aul_resume_app_by_instance_id(context->app_id, + context->instance_id); + } else { + ret = aul_resume_app(context->app_id); + } + + if (ret < 0) { + _E("Failed to send the resume request. error(%d)", ret); + return __convert_aul_error(ret); + } + + return RUA_ERROR_NONE; +} + +int rua_context_terminate(rua_context_h context) +{ + int ret; + + if (!context) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (context->component_id) { + ret = aul_comp_terminate(context->instance_id); + } else if (context->instance_id) { + ret = aul_terminate_app_with_instance_id(context->app_id, + context->instance_id); + } else { + ret = aul_terminate_app(context->app_id); + } + + if (ret < 0) { + _E("Failed to send the terminate request. error(%d)", ret); + return __convert_aul_error(ret); + } + + return RUA_ERROR_NONE; +} diff --git a/src/rua_context_internal.h b/src/rua_context_internal.h new file mode 100644 index 0000000..027cddd --- /dev/null +++ b/src/rua_context_internal.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#ifndef __RUA_CONTEXT_INTERNAL_H__ +#define __RUA_CONTEXT_INTERNAL_H__ + +#include <rua_types.h> +#include <rua_context.h> +#include <rua_info.h> + +#ifdef __cplusplus +extern "C" { +#endif + +int rua_context_create_from_rua_info(rua_info_h info, + rua_context_h *context); + +int rua_context_is_running(rua_context_h context, bool *running); + +int rua_context_resume(rua_context_h context); + +int rua_context_terminate(rua_context_h context); + +#ifdef __cplusplus +} +#endif + +#endif /*__RUA_CONTEXT_INTERNAL_H__*/ diff --git a/src/rua_info.c b/src/rua_info.c new file mode 100644 index 0000000..f194256 --- /dev/null +++ b/src/rua_info.c @@ -0,0 +1,926 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <glib.h> +#include <pkgmgr-info.h> +#include <aul.h> +#include <aul_comp_info.h> + +#include "rua.h" +#include "rua_private.h" +#include "rua_info.h" +#include "rua_info_internal.h" + +#define RUA_INFO_START 0 + +enum rua_info_e { + RUA_INFO_APP_ID = RUA_INFO_START, + RUA_INFO_APP_PATH, + RUA_INFO_ARGS, + RUA_INFO_LAUNCH_TIME, + RUA_INFO_INSTANCE_ID, + RUA_INFO_INSTANCE_NAME, + RUA_INFO_ICON, + RUA_INFO_URI, + RUA_INFO_IMAGE, + RUA_INFO_COMPONENT_ID, + RUA_INFO_APP_INFO, + RUA_INFO_COMP_INFO, + RUA_INFO_MAX, +}; + +struct rua_info_s { + char *value[RUA_INFO_MAX]; +}; + +typedef int (*rua_info_add_cb)(struct rua_rec *rec, + struct rua_info_s *info); +typedef void (*rua_info_remove_cb)(void *data); +typedef int (*rua_info_clone_cb)(struct rua_info_s *info, + struct rua_info_s *clone); + +typedef struct _rua_info_vft { + rua_info_add_cb ctor; + rua_info_remove_cb dtor; + rua_info_clone_cb clnr; +} rua_info_vft; + +static int __rua_info_add_app_id(struct rua_rec *rec, + struct rua_info_s *info) +{ + info->value[RUA_INFO_APP_ID] = strdup(rec->pkg_name); + if (!info->value[RUA_INFO_APP_ID]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_app_path(struct rua_rec *rec, + struct rua_info_s *info) +{ + info->value[RUA_INFO_APP_PATH] = strdup(rec->app_path); + if (!info->value[RUA_INFO_APP_PATH]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_args(struct rua_rec *rec, + struct rua_info_s *info) +{ + info->value[RUA_INFO_ARGS] = strdup(rec->arg); + if (!info->value[RUA_INFO_ARGS]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_launch_time(struct rua_rec *rec, + struct rua_info_s *info) +{ + info->value[RUA_INFO_LAUNCH_TIME] = GINT_TO_POINTER(rec->launch_time); + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_instance_id(struct rua_rec *rec, + struct rua_info_s *info) +{ + if (!rec->instance_id) + return RUA_ERROR_NONE; + + info->value[RUA_INFO_INSTANCE_ID] = strdup(rec->instance_id); + if (!info->value[RUA_INFO_INSTANCE_ID]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_instance_name(struct rua_rec *rec, + struct rua_info_s *info) +{ + if (!rec->instance_name) + return RUA_ERROR_NONE; + + info->value[RUA_INFO_INSTANCE_NAME] = strdup(rec->instance_name); + if (!info->value[RUA_INFO_INSTANCE_NAME]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_icon(struct rua_rec *rec, struct rua_info_s *info) +{ + if (!rec->icon) + return RUA_ERROR_NONE; + + info->value[RUA_INFO_ICON] = strdup(rec->icon); + if (!info->value[RUA_INFO_ICON]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_uri(struct rua_rec *rec, struct rua_info_s *info) +{ + if (!rec->uri) + return RUA_ERROR_NONE; + + info->value[RUA_INFO_URI] = strdup(rec->uri); + if (!info->value[RUA_INFO_URI]) { + _E("Ouf of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_image(struct rua_rec *rec, struct rua_info_s *info) +{ + if (!rec->image) + return RUA_ERROR_NONE; + + info->value[RUA_INFO_IMAGE] = strdup(rec->image); + if (!info->value[RUA_INFO_IMAGE]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_component_id(struct rua_rec *rec, + struct rua_info_s *info) +{ + if (!rec->comp_id) + return RUA_ERROR_NONE; + + info->value[RUA_INFO_COMPONENT_ID] = strdup(rec->comp_id); + if (!info->value[RUA_INFO_COMPONENT_ID]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_app_info(struct rua_rec *rec, + struct rua_info_s *info) +{ + pkgmgrinfo_appinfo_h app_info; + int ret; + + ret = pkgmgrinfo_appinfo_get_appinfo(rec->pkg_name, &app_info); + if (ret != PMINFO_R_OK) { + _E("Failed to get appinfo"); + return RUA_ERROR_IO_ERROR; + } + + info->value[RUA_INFO_APP_INFO] = app_info; + + return RUA_ERROR_NONE; +} + +static int __rua_info_add_comp_info(struct rua_rec *rec, + struct rua_info_s *info) +{ + aul_comp_info_h comp_info; + int ret; + + if (!rec->comp_id) + return RUA_ERROR_NONE; + + ret = aul_comp_info_create(rec->comp_id, &comp_info); + if (ret != AUL_R_OK) { + _E("Failed to create comp info"); + return RUA_ERROR_IO_ERROR; + } + + info->value[RUA_INFO_COMP_INFO] = comp_info; + + return RUA_ERROR_NONE; +} + +static void __rua_info_remove_app_info(void *data) +{ + pkgmgrinfo_appinfo_h app_info; + + app_info = (pkgmgrinfo_appinfo_h)data; + pkgmgrinfo_appinfo_destroy_appinfo(app_info); +} + +static void __rua_info_remove_comp_info(void *data) +{ + aul_comp_info_h comp_info; + + comp_info = (aul_comp_info_h)data; + aul_comp_info_destroy(comp_info); +} + +static int __rua_info_clone_app_id(struct rua_info_s *info, + struct rua_info_s *clone) +{ + clone->value[RUA_INFO_APP_ID] = strdup(info->value[RUA_INFO_APP_ID]); + if (!clone->value[RUA_INFO_APP_ID]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_app_path(struct rua_info_s *info, + struct rua_info_s *clone) +{ + clone->value[RUA_INFO_APP_PATH] = + strdup(info->value[RUA_INFO_APP_PATH]); + if (!clone->value[RUA_INFO_APP_PATH]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_args(struct rua_info_s *info, + struct rua_info_s *clone) +{ + clone->value[RUA_INFO_ARGS] = strdup(info->value[RUA_INFO_ARGS]); + if (!clone->value[RUA_INFO_ARGS]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_launch_time(struct rua_info_s *info, + struct rua_info_s *clone) +{ + clone->value[RUA_INFO_LAUNCH_TIME] = info->value[RUA_INFO_LAUNCH_TIME]; + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_instance_id(struct rua_info_s *info, + struct rua_info_s *clone) +{ + if (!info->value[RUA_INFO_INSTANCE_ID]) + return RUA_ERROR_NONE; + + clone->value[RUA_INFO_INSTANCE_ID] = + strdup(info->value[RUA_INFO_INSTANCE_ID]); + if (!clone->value[RUA_INFO_INSTANCE_ID]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_instance_name(struct rua_info_s *info, + struct rua_info_s *clone) +{ + if (!info->value[RUA_INFO_INSTANCE_NAME]) + return RUA_ERROR_NONE; + + clone->value[RUA_INFO_INSTANCE_NAME] = + strdup(info->value[RUA_INFO_INSTANCE_NAME]); + if (!clone->value[RUA_INFO_INSTANCE_NAME]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_icon(struct rua_info_s *info, + struct rua_info_s *clone) +{ + if (!info->value[RUA_INFO_ICON]) + return RUA_ERROR_NONE; + + clone->value[RUA_INFO_ICON] = strdup(info->value[RUA_INFO_ICON]); + if (!clone->value[RUA_INFO_ICON]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_uri(struct rua_info_s *info, + struct rua_info_s *clone) +{ + if (!info->value[RUA_INFO_URI]) + return RUA_ERROR_NONE; + + clone->value[RUA_INFO_URI] = strdup(info->value[RUA_INFO_URI]); + if (!clone->value[RUA_INFO_URI]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_image(struct rua_info_s *info, + struct rua_info_s *clone) +{ + if (!info->value[RUA_INFO_IMAGE]) + return RUA_ERROR_NONE; + + clone->value[RUA_INFO_IMAGE] = strdup(info->value[RUA_INFO_IMAGE]); + if (!clone->value[RUA_INFO_IMAGE]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_component_id(struct rua_info_s *info, + struct rua_info_s *clone) +{ + if (!info->value[RUA_INFO_COMPONENT_ID]) + return RUA_ERROR_NONE; + + clone->value[RUA_INFO_COMPONENT_ID] = + strdup(info->value[RUA_INFO_COMPONENT_ID]); + if (!clone->value[RUA_INFO_COMPONENT_ID]) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_app_info(struct rua_info_s *info, + struct rua_info_s *clone) +{ + pkgmgrinfo_appinfo_h app_info; + int ret; + + ret = pkgmgrinfo_appinfo_clone_appinfo( + info->value[RUA_INFO_APP_INFO], + &app_info); + if (ret != RUA_ERROR_NONE) { + _E("Failed to clone app info"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + clone->value[RUA_INFO_APP_INFO] = app_info; + + return RUA_ERROR_NONE; +} + +static int __rua_info_clone_comp_info(struct rua_info_s *info, + struct rua_info_s *clone) +{ + aul_comp_info_h comp_info; + int ret; + + if (!info->value[RUA_INFO_COMP_INFO]) + return RUA_ERROR_NONE; + + ret = aul_comp_info_clone(info->value[RUA_INFO_COMP_INFO], + &comp_info); + if (ret != RUA_ERROR_NONE) { + _E("Failed to clone comp info"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + clone->value[RUA_INFO_COMP_INFO] = comp_info; + + return RUA_ERROR_NONE; +} + +static rua_info_vft __rua_table[] = { + [RUA_INFO_APP_ID] = { + .ctor = __rua_info_add_app_id, + .dtor = free, + .clnr = __rua_info_clone_app_id + }, + [RUA_INFO_APP_PATH] = { + .ctor = __rua_info_add_app_path, + .dtor = free, + .clnr = __rua_info_clone_app_path + }, + [RUA_INFO_ARGS] = { + .ctor = __rua_info_add_args, + .dtor = free, + .clnr = __rua_info_clone_args + }, + [RUA_INFO_LAUNCH_TIME] = { + .ctor = __rua_info_add_launch_time, + .dtor = NULL, + .clnr = __rua_info_clone_launch_time + }, + [RUA_INFO_INSTANCE_ID] = { + .ctor = __rua_info_add_instance_id, + .dtor = free, + .clnr = __rua_info_clone_instance_id + }, + [RUA_INFO_INSTANCE_NAME] = { + .ctor = __rua_info_add_instance_name, + .dtor = free, + .clnr = __rua_info_clone_instance_name + }, + [RUA_INFO_ICON] = { + .ctor = __rua_info_add_icon, + .dtor = free, + .clnr = __rua_info_clone_icon + }, + [RUA_INFO_URI] = { + .ctor = __rua_info_add_uri, + .dtor = free, + .clnr = __rua_info_clone_uri + }, + [RUA_INFO_IMAGE] = { + .ctor = __rua_info_add_image, + .dtor = free, + .clnr = __rua_info_clone_image + }, + [RUA_INFO_COMPONENT_ID] = { + .ctor = __rua_info_add_component_id, + .dtor = free, + .clnr = __rua_info_clone_component_id + }, + [RUA_INFO_APP_INFO] = { + .ctor = __rua_info_add_app_info, + .dtor = __rua_info_remove_app_info, + .clnr = __rua_info_clone_app_info + }, + [RUA_INFO_COMP_INFO] = { + .ctor = __rua_info_add_comp_info, + .dtor = __rua_info_remove_comp_info, + .clnr = __rua_info_clone_comp_info + }, +}; + +static void __destroy_rua_info(gpointer data) +{ + struct rua_info_s *info = (struct rua_info_s *)data; + int i; + + if (!info) + return; + + for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) { + if (!__rua_table[i].dtor) + continue; + + __rua_table[i].dtor(info->value[i]); + } + + free(info); +} + +static struct rua_info_s *__create_rua_info(struct rua_rec *rec) +{ + struct rua_info_s *info; + int ret; + int i; + + info = calloc(1, sizeof(struct rua_info_s)); + if (!info) { + _E("Out of memory"); + return NULL; + } + + for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) { + if (!__rua_table[i].ctor) + continue; + + ret = __rua_table[i].ctor(rec, info); + if (ret != RUA_ERROR_NONE) { + __destroy_rua_info(info); + return NULL; + } + } + + return info; +} + +static struct rua_info_s *__clone_rua_info(struct rua_info_s *info) +{ + struct rua_info_s *clone; + int ret; + int i; + + clone = calloc(1, sizeof(struct rua_info_s)); + if (!clone) { + _E("Out of memory"); + return NULL; + } + + for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) { + if (!__rua_table[i].clnr) + continue; + + ret = __rua_table[i].clnr(info, clone); + if (ret != RUA_ERROR_NONE) { + __destroy_rua_info(clone); + return NULL; + } + } + + return clone; +} + +int rua_info_foreach(rua_manager_rua_info_cb callback, void *user_data) +{ + return rua_info_usr_foreach(getuid(), callback, user_data); +} + +int rua_info_usr_foreach(uid_t uid, rua_manager_rua_info_cb callback, + void *user_data) +{ + struct rua_info_s *info; + struct rua_rec rec; + GList *list = NULL; + GList *iter; + char **table = NULL; + int nrows = 0; + int ncols = 0; + int row; + int ret; + + if (!callback) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + ret = rua_history_load_db_for_uid(&table, &nrows, &ncols, uid); + if (ret < 0) { + _E("Failed to load rua history"); + return RUA_ERROR_IO_ERROR; + } + + for (row = 0; row < nrows; ++row) { + rua_history_get_rec(&rec, table, nrows, ncols, row); + info = __create_rua_info(&rec); + if (!info) { + rua_history_unload_db(&table); + g_list_free_full(list, __destroy_rua_info); + return RUA_ERROR_OUT_OF_MEMORY; + } + + list = g_list_append(list, info); + } + + rua_history_unload_db(&table); + + iter = list; + while (iter) { + info = (struct rua_info_s *)iter->data; + if (!callback(info, user_data)) + break; + + iter = g_list_next(iter); + } + + g_list_free_full(list, __destroy_rua_info); + + return RUA_ERROR_NONE; +} + +API int rua_info_get_app_id(rua_info_h info, char **app_id) +{ + if (!info || !app_id) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + *app_id = strdup(info->value[RUA_INFO_APP_ID]); + if (*app_id == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +API int rua_info_get_app_path(rua_info_h info, char **app_path) +{ + if (!info || !app_path) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + *app_path = strdup(info->value[RUA_INFO_APP_PATH]); + if (*app_path == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +API int rua_info_get_args(rua_info_h info, char **args) +{ + if (!info || !args) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + *args = strdup(info->value[RUA_INFO_ARGS]); + if (*args == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} + +API int rua_info_get_launch_time(rua_info_h info, time_t *launch_time) +{ + if (!info || !launch_time) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + *launch_time = GPOINTER_TO_INT(info->value[RUA_INFO_LAUNCH_TIME]); + + return RUA_ERROR_NONE; +} + +API int rua_info_get_instance_id(rua_info_h info, char **instance_id) +{ + if (!info || !instance_id) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (info->value[RUA_INFO_INSTANCE_ID]) { + *instance_id = strdup(info->value[RUA_INFO_INSTANCE_ID]); + if (*instance_id == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + } else { + *instance_id = NULL; + } + + return RUA_ERROR_NONE; +} + +API int rua_info_get_instance_name(rua_info_h info, char **instance_name) +{ + if (!info || !instance_name) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (info->value[RUA_INFO_INSTANCE_NAME]) { + *instance_name = strdup(info->value[RUA_INFO_INSTANCE_NAME]); + if (*instance_name == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + } else { + *instance_name = NULL; + } + + return RUA_ERROR_NONE; +} + +static char *__get_icon(rua_info_h info) +{ + pkgmgrinfo_appinfo_h app_info; + aul_comp_info_h comp_info; + char *icon; + int ret; + + if (info->value[RUA_INFO_COMP_INFO]) { + comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO]; + ret = aul_comp_info_get_icon(comp_info, (const char **)&icon); + if (ret != AUL_R_OK) { + _E("Failed to get icon"); + return NULL; + } + } else { + app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO]; + ret = pkgmgrinfo_appinfo_get_icon(app_info, &icon); + if (ret != PMINFO_R_OK) { + _E("Failed to get icon"); + return NULL; + } + } + + if (icon && icon[0] != '\0') + return strdup(icon); + + return NULL; +} + +API int rua_info_get_icon(rua_info_h info, char **icon) +{ + if (!info || !icon) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (info->value[RUA_INFO_ICON]) { + *icon = strdup(info->value[RUA_INFO_ICON]); + if (*icon == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + } else { + *icon = __get_icon(info); + } + + return RUA_ERROR_NONE; +} + +API int rua_info_get_uri(rua_info_h info, char **uri) +{ + if (!info || !uri) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (info->value[RUA_INFO_URI]) { + *uri = info->value[RUA_INFO_URI]; + if (*uri == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + } else { + *uri = NULL; + } + + return RUA_ERROR_NONE; +} + +API int rua_info_get_image(rua_info_h info, char **image) +{ + if (!info || !image) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (info->value[RUA_INFO_IMAGE]) { + *image = info->value[RUA_INFO_IMAGE]; + if (*image == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + } else { + *image = NULL; + } + + return RUA_ERROR_NONE; +} + +API int rua_info_get_component_id(rua_info_h info, char **component_id) +{ + if (!info || !component_id) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (info->value[RUA_INFO_COMPONENT_ID]) { + *component_id = info->value[RUA_INFO_COMPONENT_ID]; + if (*component_id == NULL) { + _E("Out of memory"); + return RUA_ERROR_OUT_OF_MEMORY; + } + } else { + *component_id = NULL; + } + + return RUA_ERROR_NONE; +} + + +API int rua_info_is_managed_by_task_manager(rua_info_h info, bool *managed) +{ + pkgmgrinfo_appinfo_h app_info; + aul_comp_info_h comp_info; + int ret; + + if (!info || !managed) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + if (info->value[RUA_INFO_COMP_INFO]) { + comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO]; + ret = aul_comp_info_is_taskmanage(comp_info, managed); + if (ret != AUL_R_OK) { + _E("Failed to check taskmanage"); + return RUA_ERROR_INVALID_PARAMETER; + } + } else { + app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO]; + ret = pkgmgrinfo_appinfo_is_taskmanage(app_info, managed); + if (ret != PMINFO_R_OK) { + _E("Failed to check taskmanage"); + return RUA_ERROR_INVALID_PARAMETER; + } + } + + return RUA_ERROR_NONE; +} + +static char *__get_label(rua_info_h info) +{ + pkgmgrinfo_appinfo_h app_info; + aul_comp_info_h comp_info; + char *label; + int ret; + + if (info->value[RUA_INFO_COMP_INFO]) { + comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO]; + ret = aul_comp_info_get_label(comp_info, (const char **)&label); + if (ret != AUL_R_OK) { + _E("Failed to get label"); + return NULL; + } + } else { + app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO]; + ret = pkgmgrinfo_appinfo_get_label(app_info, &label); + if (ret != PMINFO_R_OK) { + _E("Failed to get label"); + return NULL; + } + } + + if (label && label[0] != '\0') + return strdup(label); + + return NULL; +} + +API int rua_info_get_label(rua_info_h info, char **label) +{ + if (!info || !label) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + *label = __get_label(info); + + return RUA_ERROR_NONE; +} + +API int rua_info_destroy(rua_info_h info) +{ + if (!info) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + __destroy_rua_info(info); + + return RUA_ERROR_NONE; +} + +API int rua_info_clone(rua_info_h info, rua_info_h *clone) +{ + if (!info || !clone) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + *clone = __clone_rua_info(info); + if (*clone == NULL) { + _E("Failed to clone rua info"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + return RUA_ERROR_NONE; +} diff --git a/src/rua_info_internal.h b/src/rua_info_internal.h new file mode 100644 index 0000000..b0ec66e --- /dev/null +++ b/src/rua_info_internal.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#ifndef __RUA_INFO_INTERNAL_H__ +#define __RUA_INFO_INTERNAL_H__ + +#include <rua_types.h> +#include <rua_manager.h> + +#ifdef __cplusplus +extern "C" { +#endif + +int rua_info_foreach(rua_manager_rua_info_cb, void *user_data); + +int rua_info_usr_foreach(uid_t uid, rua_manager_rua_info_cb, void *user_data); + +#ifdef __cplusplus +} +#endif + +#endif /*__RUA_INFO_INTERNAL_H__*/ diff --git a/src/rua_manager.c b/src/rua_manager.c new file mode 100644 index 0000000..134affe --- /dev/null +++ b/src/rua_manager.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <glib.h> +#include <aul.h> +#include <app_control_internal.h> + +#include "rua.h" +#include "rua_private.h" +#include "rua_manager.h" +#include "rua_context_internal.h" +#include "rua_info_internal.h" + +static int __convert_aul_error(int error) +{ + switch (error) { + case AUL_R_EINVAL: + return RUA_ERROR_INVALID_PARAMETER; + case AUL_R_EILLACC: + return RUA_ERROR_PERMISSION_DENIED; + case AUL_R_ERROR: + return RUA_ERROR_OUT_OF_MEMORY; + default: + return RUA_ERROR_IO_ERROR; + } +} + +API int rua_manager_foreach_rua_info(rua_manager_rua_info_cb callback, + void *user_data) +{ + return rua_info_foreach(callback, user_data); +} + +API int rua_manager_delete_rua_info(rua_info_h info) +{ + char *app_id; + char *instance_id; + int ret; + + if (!info) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + ret = rua_info_get_app_id(info, &app_id); + if (ret != RUA_ERROR_NONE) + return ret; + + ret = rua_info_get_instance_id(info, &instance_id); + if (ret != RUA_ERROR_NONE) { + free(app_id); + return ret; + } + + if (instance_id) { + ret = rua_delete_history_with_instance_id(app_id, + instance_id); + } else { + ret = rua_delete_history_with_pkgname(app_id); + } + + free(instance_id); + free(app_id); + + if (ret < 0) { + _E("Failed to delete RUA history. error(%d)", ret); + return __convert_aul_error(ret); + } + + return RUA_ERROR_NONE; +} + +API int rua_manager_delete_all_rua_info(void) +{ + int ret; + + ret = rua_clear_history(); + if (ret < 0) { + _E("Failed to clear RUA history. error(%d)", ret); + return __convert_aul_error(ret); + } + + return RUA_ERROR_NONE; +} + +API int rua_manager_get_app_control_from_rua_info(rua_info_h info, + app_control_h *app_control) +{ + app_control_h handle; + char *args; + bundle *b; + int ret; + + if (!info || !app_control) { + _E("Invalid parameter"); + return RUA_ERROR_INVALID_PARAMETER; + } + + ret = rua_info_get_args(info, &args); + if (ret != RUA_ERROR_NONE) + return ret; + + b = bundle_decode((bundle_raw *)args, strlen(args)); + free(args); + if (!b) { + _E("Failed to decode bundle"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + ret = app_control_create_request(b, &handle); + bundle_free(b); + if (ret != APP_CONTROL_ERROR_NONE) { + _E("Failed to create app_control handle"); + return RUA_ERROR_OUT_OF_MEMORY; + } + + *app_control = handle; + + return RUA_ERROR_NONE; +} + +API int rua_manager_get_rua_context_from_rua_info(rua_info_h info, + rua_context_h *context) +{ + return rua_context_create_from_rua_info(info, context); +} + +API int rua_manager_is_running(rua_context_h context, bool *running) +{ + return rua_context_is_running(context, running); +} + +API int rua_manager_resume(rua_context_h context) +{ + return rua_context_resume(context); +} + +API int rua_manager_terminate(rua_context_h context) +{ + return rua_context_terminate(context); +} diff --git a/src/rua_private.h b/src/rua_private.h index 08bbd00..fa53318 100644 --- a/src/rua_private.h +++ b/src/rua_private.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ #ifndef __RUA_PRIVATE_H__ #define __RUA_PRIVATE_H__ +#include <dlog.h> + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -30,4 +32,20 @@ #define RUA_DB_NAME ".rua.db" #define RUA_STAT_DB_NAME ".rua_stat.db" -#endif /*__RUA_H__*/ +#ifndef _E +#define _E LOGE +#endif + +#ifndef _W +#define _W LOGW +#endif + +#ifndef _I +#define _I LOGI +#endif + +#ifndef _D +#define _D LOGD +#endif + +#endif /*__RUA_PRIVATE_H__*/ |