Add new functions for component-based app group feature 09/202509/12
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 29 Mar 2019 07:38:45 +0000 (16:38 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 3 Apr 2019 00:23:34 +0000 (09:23 +0900)
Adds:
 - aul_svc_set_caller_instance_id()
 - aul_svc_set_comp_id()
 - aul_svc_get_comp_id()
 - aul_app_group_set_window_v2()
 - aul_app_group_lower_v2()
 - aul_app_group_foreach_leader_ids()
 - aul_app_group_foreach_group_info()
 - aul_app_group_foreach_idle_info()
 - aul_app_group_info_get_id()
 - aul_app_group_info_get_pid()
 - aul_app_group_info_get_appid()
 - aul_app_group_info_get_pkgid()
 - aul_app_group_info_get_window()
 - aul_app_group_info_get_fg_flag()
 - aul_app_group_info_get_status()

Change-Id: I73a8c48434900b8f641c4b63713b8b90892bcffc
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
include/aul_app_group.h [new file with mode: 0644]
include/aul_cmd.h
include/aul_key.h
include/aul_svc.h
src/app_group.c
src/aul_cmd.c
src/aul_launch.c
src/aul_sock.c
src/service.c
tool/app_group_info.c

index 6e714b1..b8bdf8c 100755 (executable)
@@ -68,6 +68,7 @@ SET(HEADERS_LIB_AUL
        aul_svc_internal.h
        aul_key.h
        aul_comp_status.h
+       aul_app_group.h
        )
 
 # Install headers, other files
diff --git a/include/aul_app_group.h b/include/aul_app_group.h
new file mode 100644 (file)
index 0000000..67fa338
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * 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 __AUL_APP_GROUP_H__
+#define __AUL_APP_GROUP_H__
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The AUL application group information handle.
+ * @since_tizen 5.5
+ */
+typedef struct aul_app_group_info_s *aul_app_group_info_h;
+
+/**
+ * @brief Gets the ID.
+ * @since_tizen 5.5
+ * @remarks You should not release @a appid by using free().
+ *
+ * @param[in]   h               The app group info handle
+ * @param[out]  id              The ID
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_id(aul_app_group_info_h h, const char **id);
+
+/**
+ * @brief Gets the process ID.
+ * @since_tizen 5.5
+ *
+ * @param[in]   h               The app group info handle
+ * @param[out]  pid             The process ID
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_pid(aul_app_group_info_h h, pid_t *pid);
+
+/**
+ * @brief Gets the application ID.
+ * @since_tizen 5.5
+ * @remarks You should not release @a appid by using free().
+ *
+ * @param[in]   h               The app group info handle
+ * @param[out]  appid           The application ID
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_appid(aul_app_group_info_h h, const char **appid);
+
+/**
+ * @brief Gets the package ID.
+ * @since_tizen 5.5
+ * @remarks You should not release @a appid by using free().
+ *
+ * @param[in]   h               The app group info handle
+ * @param[out]  pkgid           The package ID
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_pkgid(aul_app_group_info_h h, const char **pkgid);
+
+/**
+ * @brief Gets the window ID.
+ * @since_tizen 5.5
+ *
+ * @param[in]   h               The app group info handle
+ * @param[out]  wid             The window ID
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_window(aul_app_group_info_h h, int *wid);
+
+/**
+ * @brief Gets the flag that the group is running foreground.
+ * @since_tizen 5.5
+ *
+ * @param[in]   h               The app group info handle
+ * @param[out]  fg_flag         The flag of the foreground
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_fg_flag(aul_app_group_info_h h, bool *fg_flag);
+
+/**
+ * @brief Gets the status of the instance.
+ * @since_tizen 5.5
+ *
+ * @param[in]   h               The app group info handle
+ * @param[out]  status          The status
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_info_get_status(aul_app_group_info_h h, int *status);
+
+/**
+ * @brief Retrieves the leader instances.
+ * @since_tizen 5.5
+ *
+ * @param[in]   callback        The callback function
+ * @param[in]   user_data       The user data to be passed the callback function
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_foreach_leader_ids(void (*callback)(const char *, void *),
+               void *user_data);
+
+/**
+ * @brief Retrieves the group instances.
+ * @since_tizen 5.5
+ *
+ * @param[in]   leader_id       The leader ID of the app group.
+ * @param[in]   callback        The callback function
+ * @param[in]   user_data       The user data to be passed the callback function
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_foreach_group_info(const char *leader_id,
+               void (*callback)(aul_app_group_info_h, void *),
+               void *user_data);
+
+/**
+ * @brief Retrieves the idle instances.
+ * @since_tizen 5.5
+ *
+ * @param[in]   callback        The callback function
+ * @param[in]   user_data       The user data to be passed the callback function
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_foreach_idle_info(
+               void (*callback)(aul_app_group_info_h, void *),
+               void *user_data);
+
+/**
+ * @brief Sets the window.
+ * @since_tizen 5.5
+ *
+ * @param[in]   id              The instance ID
+ * @param[in]   wid             The window(surface) ID
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_set_window_v2(const char *id, int wid);
+
+/**
+ * @brief Lowers the window.
+ * @since_tizen 5.5
+ *
+ * @param[in]   id              The instance ID
+ * @param[out]  exit            The flag if it's 'true', the instance should be terminated
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_group_lower_v2(const char *id, bool *exit);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_APP_GROUP_H__ */
index 371d8bf..12d93af 100755 (executable)
@@ -144,6 +144,12 @@ enum app_cmd {
        COMP_NOTIFY_START = 111,
        COMP_NOTIFY_EXIT = 112,
        COMP_STATUS_UPDATE = 113,
+       APP_TERM_INSTANCE_ASYNC = 114,
+       APP_GROUP_SET_WINDOW_V2 = 115,
+       APP_GROUP_LOWER_V2 = 116,
+       APP_GROUP_GET_LEADER_IDS = 117,
+       APP_GROUP_GET_GROUP_INFO = 118,
+       APP_GROUP_GET_IDLE_INFO = 119,
 
        APP_CMD_MAX
 };
index bae439d..5988461 100644 (file)
  * @since_tizen 5.5
  */
 #define AUL_K_COMPONENT_ID              "__AUL_COMPONENT_ID__"
+
+/**
+ * @brief Definition for AUL: The instance ID of the caller.
+ * @since_tizen 5.5
+ */
+#define AUL_K_CALLER_INSTANCE_ID        "__AUL_CALLER_INSTANCE_ID__"
+
+/**
+ * @brief Definition for AUL: The instance ID of the original caller.
+ * @since_tizen 5.5
+ */
+#define AUL_K_ORG_CALLER_INSTANCE_ID    "__AUL_ORG_CALLER_INSTANCE_ID__"
+
+/**
+ * @brief Definition for AUL: The IDs of the app group leader.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LEADER_IDS                "__AUL_LEADER_IDS__"
+
+/**
+ * @brief Definition for AUL: The ID of the app group leader.
+ * @since_tizen 5.5
+ */
+#define AUL_K_LEADER_ID                 "__AUL_LEADER_ID__"
+
+/**
+ * @brief Definition for AUL: The flag of the foreground.
+ * @since_tizen 5.5
+ */
+#define AUL_K_FG_FLAG                   "__AUL_FG_FLAG__"
index a6c553a..5a20d75 100755 (executable)
@@ -1349,6 +1349,41 @@ int aul_svc_send_launch_request_for_uid(bundle *b, int request_code,
 int aul_svc_send_launch_request_sync_for_uid(bundle *b, int request_code,
                bundle **res_b, aul_svc_result_val *res, uid_t uid);
 
+/**
+ * @brief Sets the ID of the caller instance.
+ * @since_tizen 5.5
+ *
+ * @param[in]   b               The bundle object
+ * @param[in]   instance_id     The ID of the caller instance
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ */
+int aul_svc_set_caller_instance_id(bundle *b, const char *instance_id);
+
+/**
+ * @brief Sets the ID of the component.
+ * @since_tizen 5.5
+ *
+ * @param[in]   b               The bundle object
+ * @param[in]   comp_id         The ID of the component
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ */
+int aul_svc_set_comp_id(bundle *b, const char *comp_id);
+
+/**
+ * @brief Gets the ID of the component.
+ * @since_tizen 5.5
+ *
+ * @param[in]   b               The bundle object
+ *
+ * @return      @c a component ID on success,
+ *              otherwise a nullptr
+ */
+const char *aul_svc_get_comp_id(bundle *b);
+
 #ifdef __cplusplus
 }
 #endif
index 80a6c9a..7941975 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2015 - 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.
  * 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 <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <bundle_internal.h>
+
 #include "aul.h"
 #include "aul_api.h"
 #include "aul_util.h"
 #include "aul_sock.h"
 #include "launch.h"
+#include "aul_app_group.h"
+#include "aul_error.h"
+
+struct aul_app_group_info_s {
+       const char *id;
+       pid_t pid;
+       const char *appid;
+       const char *pkgid;
+       int wid;
+       bool fg;
+       int status;
+};
 
 API int aul_app_group_get_window(int pid)
 {
@@ -318,4 +331,333 @@ API int aul_app_group_activate_above(const char *above_appid)
        return ret;
 }
 
+API int aul_app_group_set_window_v2(const char *id, int wid)
+{
+       char buf[32];
+       bundle *b;
+       int ret;
+
+       if (!id) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       b = bundle_create();
+       if (!b) {
+               _E("Out of memory");
+               return AUL_R_ERROR;
+       }
+
+       bundle_add(b, AUL_K_INSTANCE_ID, id);
+       snprintf(buf, sizeof(buf), "%d", wid);
+       bundle_add(b, AUL_K_WID, buf);
+
+       ret = app_send_cmd_with_noreply(AUL_UTIL_PID, APP_GROUP_SET_WINDOW_V2,
+                       b);
+       bundle_free(b);
+
+       return ret;
+}
+
+API int aul_app_group_lower_v2(const char *id, bool *exit)
+{
+       bundle *b;
+       int ret;
+
+       if (!id | !exit) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       b = bundle_create();
+       if (!b) {
+               _E("Out of memory");
+               return AUL_R_ERROR;
+       }
+
+       bundle_add(b, AUL_K_INSTANCE_ID, id);
+
+       ret = app_send_cmd(AUL_UTIL_PID, APP_GROUP_LOWER_V2, b);
+       bundle_free(b);
+       if (ret < 0)
+               return ret;;
+
+       *exit = (bool)ret;
+
+       return AUL_R_OK;
+}
+
+API int aul_app_group_foreach_leader_ids(void (*callback)(const char *, void *),
+               void *user_data)
+{
+       app_pkt_t *pkt = NULL;
+       const char **str_arr;
+       int len = 0;
+       bundle *b;
+       int ret;
+       int fd;
+       int i;
+
+       if (!callback) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       fd = aul_sock_send_raw(AUL_UTIL_PID, getuid(),
+                       APP_GROUP_GET_LEADER_IDS, NULL, 0, AUL_SOCK_ASYNC);
+       if (fd < 0) {
+               _E("Failed to send the request. result(%d)", fd);
+               return aul_error_convert(fd);
+       }
+
+       ret = aul_sock_recv_reply_pkt(fd, &pkt);
+       if (ret < 0 || pkt == NULL) {
+               _E("Failed to receive the packet. result(%d)", ret);
+               return aul_error_convert(ret);
+       }
+
+       b = bundle_decode((const bundle_raw *)pkt->data, pkt->len);
+       if (!b) {
+               _E("Failed to decode bundle data(%s:%d)",
+                               (const char *)pkt->data, pkt->len);
+               free(pkt);
+               return AUL_R_ERROR;
+       }
+       free(pkt);
+
+       str_arr = bundle_get_str_array(b, AUL_K_LEADER_IDS, &len);
+       if (str_arr == NULL || len == 0) {
+               _E("Failed to get data");
+               bundle_free(b);
+               return AUL_R_ERROR;
+       }
+
+       for (i = 0; i < len; i++)
+               callback(str_arr[i], user_data);
+
+       bundle_free(b);
+
+       return AUL_R_OK;
+}
+
+struct app_group_cb_info_s {
+       void (*callback)(aul_app_group_info_h, void *);
+       void *user_data;
+};
+
+static void __foreach_group_info(app_pkt_t *pkt, void *user_data)
+{
+       struct app_group_cb_info_s *cb_info;
+       struct aul_app_group_info_s info = { 0, };
+       bundle *b = NULL;
+       const char *val;
+
+       cb_info = (struct app_group_cb_info_s *)user_data;
+       if (!pkt || !cb_info) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       if (pkt->cmd == APP_GET_INFO_ERROR) {
+               _E("Failed to get app group info");
+               return;
+       }
+
+       if (pkt->opt & AUL_SOCK_BUNDLE)
+               b = bundle_decode(pkt->data, pkt->len);
+
+       if (!b)
+               return;
+
+       info.id = bundle_get_val(b, AUL_K_INSTANCE_ID);
+       if (!info.id)
+               goto end;
+
+       val = bundle_get_val(b, AUL_K_PID);
+       if (!val)
+               goto end;
+
+       if (isdigit(val[0]))
+               info.pid = atoi(val);
+
+       info.appid = bundle_get_val(b, AUL_K_APPID);
+       if (!info.appid)
+               goto end;
+
+       info.pkgid = bundle_get_val(b, AUL_K_PKGID);
+       if (!info.pkgid)
+               goto end;
+
+       val = bundle_get_val(b, AUL_K_WID);
+       if (!val)
+               goto end;
+
+       if (isdigit(val[0]))
+               info.wid = atoi(val);
+
+       val = bundle_get_val(b, AUL_K_FG_FLAG);
+       if (!val)
+               goto end;
+
+       if (isdigit(val[0]))
+               info.fg = (bool)atoi(val);
+
+       val = bundle_get_val(b, AUL_K_STATUS);
+       if (!val)
+               goto end;
+
+       if (isdigit(val[0]))
+               info.status = atoi(val);
+
+       cb_info->callback(&info, cb_info->user_data);
 
+end:
+       bundle_free(b);
+}
+
+API int aul_app_group_foreach_group_info(const char *leader_id,
+               void (*callback)(aul_app_group_info_h, void *),
+               void *user_data)
+{
+       struct app_group_cb_info_s cb_info = {callback, user_data};
+       bundle *b;
+       int ret;
+       int fd;
+
+       if (!leader_id || !callback) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       b = bundle_create();
+       if (!b) {
+               _E("Out of memory");
+               return AUL_R_ERROR;
+       }
+
+       bundle_add(b, AUL_K_LEADER_ID, leader_id);
+
+       fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
+                       APP_GROUP_GET_GROUP_INFO, b, AUL_SOCK_ASYNC);
+       if (fd < 0) {
+               bundle_free(b);
+               return aul_error_convert(fd);
+       }
+       bundle_free(b);
+
+       ret = aul_sock_recv_pkt_with_cb(fd, __foreach_group_info, &cb_info);
+       if (ret < 0)
+               return aul_error_convert(ret);
+
+       return ret;
+}
+
+API int aul_app_group_foreach_idle_info(
+               void (*callback)(aul_app_group_info_h, void *),
+               void *user_data)
+{
+       struct app_group_cb_info_s cb_info = {callback, user_data};
+       int ret;
+       int fd;
+
+       if (!callback) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       fd = aul_sock_send_raw(AUL_UTIL_PID, getuid(),
+                       APP_GROUP_GET_IDLE_INFO, NULL, 0, AUL_SOCK_ASYNC);
+       if (fd < 0)
+               return aul_error_convert(fd);
+
+       ret = aul_sock_recv_pkt_with_cb(fd, __foreach_group_info, &cb_info);
+       if (ret < 0)
+               return aul_error_convert(ret);
+
+       return ret;
+}
+
+API int aul_app_group_info_get_id(aul_app_group_info_h h, const char **id)
+{
+       if (!h | !id) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       *id = h->id;
+
+       return AUL_R_OK;
+}
+
+API int aul_app_group_info_get_pid(aul_app_group_info_h h, pid_t *pid)
+{
+       if (!h || !pid) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       *pid = h->pid;
+
+       return AUL_R_OK;
+}
+
+API int aul_app_group_info_get_appid(aul_app_group_info_h h, const char **appid)
+{
+       if (!h || !appid) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       *appid = h->appid;
+
+       return AUL_R_OK;
+}
+
+
+API int aul_app_group_info_get_pkgid(aul_app_group_info_h h, const char **pkgid)
+{
+       if (!h || !pkgid) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       *pkgid = h->pkgid;
+
+       return AUL_R_OK;
+}
+
+API int aul_app_group_info_get_window(aul_app_group_info_h h, int *wid)
+{
+       if (!h || !wid) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       *wid = h->wid;
+
+       return AUL_R_OK;
+}
+
+API int aul_app_group_info_get_fg_flag(aul_app_group_info_h h, bool *fg_flag)
+{
+       if (!h || !fg_flag) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       *fg_flag = h->fg;
+
+       return AUL_R_OK;
+}
+
+API int aul_app_group_info_get_status(aul_app_group_info_h h, int *status)
+{
+       if (!h || !status) {
+               _E("Invalid parameter");
+               return AUL_R_EINVAL;
+       }
+
+       *status = h->status;
+
+       return AUL_R_OK;
+}
index 7ba1f22..bb54372 100755 (executable)
@@ -252,6 +252,18 @@ API const char *aul_cmd_convert_to_string(int cmd)
                return "COMP_NOTIFY_EXIT";
        case COMP_STATUS_UPDATE:
                return "COMP_STATUS_UPDATE";
+       case APP_TERM_INSTANCE_ASYNC:
+               return "APP_TERM_INSTANCE_ASYNC";
+       case APP_GROUP_SET_WINDOW_V2:
+               return "APP_GROUP_SET_WINDOW_V2";
+       case APP_GROUP_LOWER_V2:
+               return "APP_GROUP_LOWER_V2";
+       case APP_GROUP_GET_LEADER_IDS:
+               return "APP_GROUP_GET_LEADER_IDS";
+       case APP_GROUP_GET_GROUP_INFO:
+               return "APP_GROUP_GET_GROUP_INFO";
+       case APP_GROUP_GET_IDLE_INFO:
+               return "APP_GROUP_GET_IDLE_INFO";
        default:
                return "CUSTOM_COMMAND";
        }
index 7d1bf55..6153307 100644 (file)
@@ -219,6 +219,11 @@ static void __dispatch_watchdog_ping(aul_request_h req)
                        tv.tv_sec, tv.tv_usec);
 }
 
+static void __dispatch_app_term_inst(aul_request_h req)
+{
+       __invoke_aul_handler(AUL_TERMINATE, req->b);
+}
+
 static dispatcher __dispatcher[] = {
        [APP_START] = __dispatch_app_start,
        [APP_START_RES] = __dispatch_app_start,
@@ -244,6 +249,7 @@ static dispatcher __dispatcher[] = {
        [WATCHDOG_PING] = __dispatch_watchdog_ping,
        [APP_SEND_LAUNCH_REQUEST] = __dispatch_app_start,
        [APP_SEND_LAUNCH_REQUEST_SYNC] = __dispatch_app_start,
+       [APP_TERM_INSTANCE_ASYNC] = __dispatch_app_term_inst,
 };
 
 static gboolean __aul_launch_handler(GIOChannel *io, GIOCondition condition,
index 1d7ee36..c2e523f 100644 (file)
@@ -627,6 +627,14 @@ API int aul_sock_recv_reply_pkt(int fd, app_pkt_t **ret_pkt)
 {
        int ret;
 
+       if (fd < 0 || fd > sysconf(_SC_OPEN_MAX))
+               return -EINVAL;
+
+       if (!ret_pkt) {
+               close(fd);
+               return -EINVAL;
+       }
+
        ret = __recv_pkt(fd, ret_pkt);
        close(fd);
 
index cced83e..ba0bb0c 100755 (executable)
@@ -2238,3 +2238,28 @@ API int aul_svc_info_destroy(aul_svc_info_h h)
 
        return AUL_SVC_RET_OK;
 }
+
+API int aul_svc_set_caller_instance_id(bundle *b, const char *instance_id)
+{
+       if (!b) {
+               _E("Invalid parameter");
+               return AUL_SVC_RET_EINVAL;
+       }
+
+       return __set_bundle(b, AUL_K_CALLER_INSTANCE_ID, instance_id);
+}
+
+API int aul_svc_set_comp_id(bundle *b, const char *comp_id)
+{
+       if (!b) {
+               _E("Invalid parameter");
+               return AUL_SVC_RET_EINVAL;
+       }
+
+       return __set_bundle(b, AUL_K_COMPONENT_ID, comp_id);
+}
+
+API const char *aul_svc_get_comp_id(bundle *b)
+{
+       return bundle_get_val(b, AUL_K_COMPONENT_ID);
+}
index d5b36dc..effba67 100644 (file)
+/*
+ * Copyright (c) 2015 - 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 "aul.h"
 
-static void print_app_status(int status);
+#include "aul.h"
+#include "aul_app_group.h"
 
-static void print_idle_info(void)
+static void __foreach_idle_group_info(aul_app_group_info_h info,
+               void *user_data)
 {
-       int cnt = 0;
-       int *pids = NULL;
-       int i;
-       char appid_buf[1024] = {0,};
-       int ret;
-
-       aul_app_group_get_idle_pids(&cnt, &pids);
-       printf("< Idle : %d >\n", cnt);
-       if (pids) {
-               for (i = 0; i < cnt; ++i) {
-                       printf("---------------------------\n");
-                       printf("  pid : %d\n", pids[i]);
-                       ret = aul_app_get_appid_bypid(pids[i], appid_buf, sizeof(appid_buf) - 1);
-
-                       if (ret != AUL_R_OK)
-                               appid_buf[0] = '\0';
-
-                       printf("  appid : %s\n", appid_buf);
-               }
-
-               free(pids);
-       }
+       int *idle_count = (int *)user_data;
+       const char *id = NULL;
+       pid_t pid = -1;
+       const char *appid = NULL;
+
+       (*idle_count)++;
+       aul_app_group_info_get_id(info, &id);
+       aul_app_group_info_get_pid(info, &pid);
+       aul_app_group_info_get_appid(info, &appid);
+
+       printf("---------------------------\n");
+       printf(" - id    : %s\n", id);
+       printf(" - pid   : %d\n", pid);
+       printf(" - appid : %s\n", appid);
+       printf("\n");
 }
 
-static int print_info(void)
+static void __print_idle_info(void)
 {
-       int *leader_pids = NULL;
-       int *member_pids = NULL;
-       int group_cnt = 0;
-       int member_cnt = 0;
-       int win_id = 0;
-       int group_num = 0;
-       int member_num = 0;
-       int app_status = -1;
-       int ret = 0;
-       char appid_buf[1024] = {0,};
-       char pkgid_buf[1024] = {0,};
-       int fg;
-
-       aul_app_group_get_leader_pids(&group_cnt, &leader_pids);
-       printf("App group count : %d\n", group_cnt);
-       printf("\n");
-
-       if (group_cnt == 0) {
-               printf("No app groups\n");
-               goto FINISH;
-       }
-
-       for (group_num = 0; group_num < group_cnt; group_num++) {
-               aul_app_group_get_group_pids(leader_pids[group_num], &member_cnt, &member_pids);
-
-               printf("< Group : %d >\n", group_num + 1);
-               printf("member cnt : %d\n", member_cnt);
-               printf("\n");
-
-               for (member_num = 0; member_num < member_cnt; member_num++) {
-                       ret = aul_app_get_appid_bypid(member_pids[member_num], appid_buf, sizeof(appid_buf) - 1);
-                       if (ret != AUL_R_OK)
-                               appid_buf[0] = '\0';
-
-                       ret = aul_app_get_pkgid_bypid(member_pids[member_num], pkgid_buf, sizeof(pkgid_buf) - 1);
-                       if (ret != AUL_R_OK)
-                               pkgid_buf[0] = '\0';
-
-                       win_id = aul_app_group_get_window(member_pids[member_num]);
-                       fg = aul_app_group_get_fg_flag(member_pids[member_num]);
-
-                       printf("--- member   : %d\n", member_num + 1);
-                       printf("  - app id   : %s\n", appid_buf);
-                       printf("  - pkg id   : %s\n", pkgid_buf);
-                       printf("  - pid      : %d\n", member_pids[member_num]);
-                       printf("  - win id   : %d\n", win_id);
-                       if (fg)
-                               printf("  - fg group : TRUE\n");
-                       else
-                               printf("  - fg group : FALSE\n");
-
-                       app_status = aul_app_get_status_bypid(member_pids[member_num]);
-                       print_app_status(app_status);
-                       printf("\n");
-               }
-               printf("==================================\n");
-               printf("\n");
-               free(member_pids);
-               member_pids = NULL;
-       }
-
-FINISH:
-       if (leader_pids != NULL)
-               free(leader_pids);
-       if (leader_pids != NULL)
-               free(member_pids);
+       int idle_count = 0;
 
-       return 0;
+       aul_app_group_foreach_idle_info(__foreach_idle_group_info,
+                       (void *)&idle_count);
+       printf("< Idle count : %d >\n", idle_count);
 }
 
-static void print_app_status(int status)
+static void __print_status(int status)
 {
        switch (status) {
        case STATUS_LAUNCHING:
@@ -135,14 +83,77 @@ static void print_app_status(int status)
        };
 }
 
+static void __foreach_group_info(aul_app_group_info_h info, void *user_data)
+{
+       int *member_count = (int *)user_data;
+       const char *id = NULL;
+       pid_t pid = -1;
+       const char *appid = NULL;
+       const char *pkgid = NULL;
+       int wid = 0;
+       bool fg = false;
+       int status = -1;
+
+       (*member_count)++;
+       aul_app_group_info_get_id(info, &id);
+       aul_app_group_info_get_pid(info, &pid);
+       aul_app_group_info_get_appid(info, &appid);
+       aul_app_group_info_get_pkgid(info, &pkgid);
+       aul_app_group_info_get_window(info, &wid);
+       aul_app_group_info_get_fg_flag(info, &fg);
+       aul_app_group_info_get_status(info, &status);
+
+       printf("--- member   : %d\n", *member_count);
+       printf("  - id       : %s\n", id);
+       printf("  - pid      : %d\n", pid);
+       printf("  - app id   : %s\n", appid);
+       printf("  - pkg id   : %s\n", pkgid);
+       printf("  - win id   : %d\n", wid);
+       printf("  - fg group : %s\n", fg ? "true" : "false");
+       __print_status(status);
+       printf("\n");
+}
+
+static void __foreach_leader_ids(const char *leader_id, void *user_data)
+{
+       int *group_count = (int *)user_data;
+       int member_count = 0;
+
+       (*group_count)++;
+       printf("----------------------------------\n");
+       printf("< Group : %d >\n", *group_count);
+
+       aul_app_group_foreach_group_info(leader_id, __foreach_group_info,
+                       (void *)&member_count);
+       printf("Member count: %d\n", member_count);
+       printf("\n");
+}
+
+static void __print_info(void)
+{
+       int group_count = 0;
+       int ret;
+
+       ret = aul_app_group_foreach_leader_ids(__foreach_leader_ids,
+                       (void *)&group_count);
+       if (ret < 0) {
+               printf("No app group\n");
+               return;
+       }
+
+       printf("==================================\n");
+       printf("\n");
+       printf("App Group count: %d\n", group_count);
+}
+
 int main(int argc, char** argv)
 {
        printf("\n");
        printf("### App Group Informantion ###\n");
        printf("\n");
 
-       print_info();
-       print_idle_info();
+       __print_info();
+       __print_idle_info();
 
        printf("### end ###\n");