summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2017-07-20 09:01:13 +0900
committerHwanKyu Jhun <h.jhun@samsung.com>2017-09-21 11:57:58 +0000
commit09723d1984ff9720d541623b5860a2ecdb3b1cd4 (patch)
treeacb47465c98266f3da7cc9d87dd1e5a43f19d2f9
parent9bef28b880ecb09897d16020c1aca09f103d13c7 (diff)
downloadaul-1-09723d1984ff9720d541623b5860a2ecdb3b1cd4.tar.gz
aul-1-09723d1984ff9720d541623b5860a2ecdb3b1cd4.tar.bz2
aul-1-09723d1984ff9720d541623b5860a2ecdb3b1cd4.zip
Add new APIs to get running widget info
Adds: - aul_widget_info_foreach() - aul_widget_info_foreach_for_uid() - aul_widget_info_get_pid() - aul_widget_info_get_surface_id() - aul_widget_info_get_widget_id() - aul_widget_info_get_instance_id() - aul_widget_info_get_app_id() - aul_widget_info_get_package_id() - aul_widget_info_get_app_path() Change-Id: Ib5a346092730474deeaebbb81a3ff9dd919a4217 Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--include/aul_cmd.h1
-rwxr-xr-xinclude/aul_widget.h133
-rw-r--r--src/widget.c241
4 files changed, 376 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7ec40c45..b4759948 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,6 +59,7 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_cmd.h DESTINATION include/
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_app_com.h DESTINATION include/aul)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_screen_connector.h DESTINATION include/aul)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_window.h DESTINATION include/aul)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_widget.h DESTINATION include/aul)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec_list.txt DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/miregex DESTINATION ${SHARE_INSTALL_PREFIX}/aul )
diff --git a/include/aul_cmd.h b/include/aul_cmd.h
index 79772e0d..de9b305e 100644
--- a/include/aul_cmd.h
+++ b/include/aul_cmd.h
@@ -125,6 +125,7 @@ enum app_cmd {
APP_GET_APPID_BY_SURFACE_ID = 94,
APP_GET_INSTANCE_ID_BY_SURFACE_ID = 95,
UPDATE_SCREEN_VIEWER_STATUS = 96,
+ WIDGET_RUNNING_INFO = 97,
APP_CMD_MAX
};
diff --git a/include/aul_widget.h b/include/aul_widget.h
new file mode 100755
index 00000000..892d0815
--- /dev/null
+++ b/include/aul_widget.h
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @par Description:
+ * Widget information handle.
+ */
+typedef struct aul_widget_info_s *aul_widget_info_h;
+
+/**
+ * @par Description:
+ * Called to get the widget information
+ * @param[in] info The handle of the widget information
+ * @param[in] user_data The user data passed from the foreach function
+ *
+ * @pre aul_widget_info_foreach() will invoke this callback.
+ * @see aul_widget_info_foreach()
+ */
+typedef void (*aul_widget_info_cb)(aul_widget_info_h info, void *user_data);
+
+/**
+ * @par Description:
+ * Retrieves all widget information of running widget applications.
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/internal/default/platform
+ * @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
+ * @post This function invokes aul_widget_info_cb() for each widget information.
+ * @see aul_widget_info_cb()
+ */
+int aul_widget_info_foreach(aul_widget_info_cb callback, void *user_data);
+int aul_widget_info_foreach_for_uid(aul_widget_info_cb callback,
+ void *user_data, uid_t uid);
+
+/**
+ * @par Description:
+ * Gets the process ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] pid The process ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_widget_info_get_pid(aul_widget_info_h info, pid_t *pid);
+
+/**
+ * @par Description:
+ * Gets the surface ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] surf The surface ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ */
+int aul_widget_info_get_surface_id(aul_widget_info_h info, unsigned int *surf);
+
+/**
+ * @par Description:
+ * Gets the widget ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] widget_id The widget ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a widget_id must be released using free().
+ */
+int aul_widget_info_get_widget_id(aul_widget_info_h info, char **widget_id);
+
+/**
+ * @par Description:
+ * Gets the widget instance ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] instance_id The widget instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a instance_id must be released using free().
+ */
+int aul_widget_info_get_instance_id(aul_widget_info_h info, char **instance_id);
+
+/**
+ * @par Description:
+ * Gets the application ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] app_id The application ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a app_id must be released using free().
+ */
+int aul_widget_info_get_app_id(aul_widget_info_h info, char **app_id);
+
+/**
+ * @par Description:
+ * Gets the package ID with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] package_id The package ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a app_id must be released using free().
+ */
+int aul_widget_info_get_package_id(aul_widget_info_h info, char **package_id);
+
+/**
+ * @par Description:
+ * Gets the path with the given handle.
+ * @param[in] info The handle of the widget information
+ * @param[out] app_path The path of the widget application
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @remarks The @a app_id must be released using free().
+ */
+int aul_widget_info_get_app_path(aul_widget_info_h info, char **app_path);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/widget.c b/src/widget.c
index 6b1bc815..95d33f04 100644
--- a/src/widget.c
+++ b/src/widget.c
@@ -15,15 +15,36 @@
*/
#define _GNU_SOURCE
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
#include <glib.h>
#include <bundle.h>
+#include <bundle_internal.h>
+
#include "aul.h"
#include "aul_util.h"
#include "aul_sock.h"
#include "aul_cmd.h"
#include "aul_error.h"
#include "launch.h"
+#include "aul_widget.h"
+
+struct aul_widget_info_s {
+ char *widget_id;
+ char *instance_id;
+ char *app_id;
+ char *package_id;
+ char *app_path;
+ unsigned int surf;
+ pid_t pid;
+};
+
+struct widget_cb_info {
+ aul_widget_info_cb callback;
+ void *user_data;
+};
static const char *__to_appid(const char *widget_id)
{
@@ -263,3 +284,223 @@ API int aul_widget_instance_count(const char *widget_id)
return ret;
}
+
+static void __foreach_widget_info(app_pkt_t *pkt, void *user_data)
+{
+ struct widget_cb_info *cb_info = (struct widget_cb_info *)user_data;
+ struct aul_widget_info_s info = { 0, };
+ bundle *b = NULL;
+ const char *val;
+
+ if (pkt == NULL || cb_info == NULL) {
+ _E("Invalid parameter");
+ return;
+ }
+
+ if (pkt->cmd == APP_GET_INFO_ERROR) {
+ _E("Failed to get widget info");
+ return;
+ }
+
+ if (pkt->opt & AUL_SOCK_BUNDLE)
+ b = bundle_decode(pkt->data, pkt->len);
+
+ if (b == NULL)
+ return;
+
+ bundle_get_str(b, AUL_K_WIDGET_ID, &info.widget_id);
+ if (info.widget_id == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ bundle_get_str(b, AUL_K_WIDGET_INSTANCE_ID, &info.instance_id);
+ if (info.instance_id == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ bundle_get_str(b, AUL_K_APPID, &info.app_id);
+ if (info.app_id == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ bundle_get_str(b, AUL_K_PKGID, &info.package_id);
+ if (info.package_id == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ bundle_get_str(b, AUL_K_EXEC, &info.app_path);
+ if (info.app_path == NULL) {
+ bundle_free(b);
+ return;
+ }
+
+ val = bundle_get_val(b, AUL_K_WID);
+ if (val && isdigit(*val))
+ info.surf = strtoul(val, NULL, 10);
+
+ val = bundle_get_val(b, AUL_K_PID);
+ if (val && isdigit(*val))
+ info.pid = atoi(val);
+
+ cb_info->callback(&info, cb_info->user_data);
+
+ bundle_free(b);
+}
+
+API int aul_widget_info_foreach_for_uid(aul_widget_info_cb callback,
+ void *user_data, uid_t uid)
+{
+ struct widget_cb_info cb_info = {callback, user_data};
+ char buf[MAX_PID_STR_BUFSZ];
+ bundle *b;
+ int fd;
+ int r;
+
+ if (callback == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ b = bundle_create();
+ if (b == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ snprintf(buf, sizeof(buf), "%u", uid);
+ r = bundle_add_str(b, AUL_K_TARGET_UID, buf);
+ if (r != BUNDLE_ERROR_NONE) {
+ _E("Failed to add target uid(%u)", uid);
+ bundle_free(b);
+ return AUL_R_ERROR;
+ }
+
+ fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, WIDGET_RUNNING_INFO,
+ b, AUL_SOCK_ASYNC);
+ if (fd < 0) {
+ bundle_free(b);
+ return aul_error_convert(fd);
+ }
+
+ r = aul_sock_recv_pkt_with_cb(fd, __foreach_widget_info, &cb_info);
+ if (r < 0)
+ return aul_error_convert(r);
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_foreach(aul_widget_info_cb callback, void *user_data)
+{
+ return aul_widget_info_foreach_for_uid(callback, user_data, getuid());
+}
+
+API int aul_widget_info_get_pid(aul_widget_info_h info, pid_t *pid)
+{
+ if (info == NULL || pid == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *pid = info->pid;
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_surface_id(aul_widget_info_h info,
+ unsigned int *surf)
+{
+ if (info == NULL || surf == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *surf = info->surf;
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_widget_id(aul_widget_info_h info, char **widget_id)
+{
+ if (info == NULL || widget_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *widget_id = strdup(info->widget_id);
+ if (*widget_id == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_instance_id(aul_widget_info_h info,
+ char **instance_id)
+{
+ if (info == NULL || instance_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *instance_id = strdup(info->instance_id);
+ if (*instance_id == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_app_id(aul_widget_info_h info, char **app_id)
+{
+ if (info == NULL || app_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *app_id = strdup(info->app_id);
+ if (*app_id == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_package_id(aul_widget_info_h info,
+ char **package_id)
+{
+ if (info == NULL || package_id == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *package_id = strdup(info->package_id);
+ if (*package_id == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}
+
+API int aul_widget_info_get_app_path(aul_widget_info_h info, char **app_path)
+{
+ if (info == NULL || app_path == NULL) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ *app_path = strdup(info->app_path);
+ if (*app_path == NULL) {
+ _E("Out of memory");
+ return AUL_R_ERROR;
+ }
+
+ return AUL_R_OK;
+}