summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunghoon Park <jh9216.park@samsung.com>2015-12-15 17:15:56 +0900
committerJunghoon Park <jh9216.park@samsung.com>2015-12-15 17:15:56 +0900
commitde3e7c7da419ab54ccfce214ef2e8268b1a930be (patch)
treeb4f8f53e5f60540948e70c31dce1b93cdb694411
parent8a0850e2b006f30b086289c23eb484610509b76a (diff)
downloadaul-1-de3e7c7da419ab54ccfce214ef2e8268b1a930be.tar.gz
aul-1-de3e7c7da419ab54ccfce214ef2e8268b1a930be.tar.bz2
aul-1-de3e7c7da419ab54ccfce214ef2e8268b1a930be.zip
Add APIs for BG managementsubmit/tizen/20151215.084459
- add types (AIT_COMPTYPE, AIT_BG_CATEGORY) - add _status_find_service_apps() - add _status_check_service_only() - modify app-group to use them - refactor amd_appinfo Change-Id: I2ae6d4684d78d7b16948e12dfb10cfd1f8381d78 Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
-rw-r--r--am_daemon/amd_app_group.c27
-rw-r--r--am_daemon/amd_appinfo.c525
-rw-r--r--am_daemon/amd_appinfo.h9
-rw-r--r--am_daemon/amd_launch.c2
-rw-r--r--am_daemon/amd_request.c2
-rw-r--r--am_daemon/amd_status.c323
-rw-r--r--am_daemon/amd_status.h3
7 files changed, 683 insertions, 208 deletions
diff --git a/am_daemon/amd_app_group.c b/am_daemon/amd_app_group.c
index 9025e71c..41177476 100644
--- a/am_daemon/amd_app_group.c
+++ b/am_daemon/amd_app_group.c
@@ -217,22 +217,25 @@ static GList* __find_removable_apps(int from)
return list;
}
-/*
- * TODO : BG manangement should be merged
+
static void __prepare_to_suspend_services(int pid)
{
+ /*
int dummy;
SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
__app_send_raw_with_noreply(pid, APP_SUSPEND, (unsigned char *)&dummy, sizeof(int));
+ */
}
static void __prepare_to_wake_services(int pid)
{
+ /*
int dummy;
SECURE_LOGD("[__SUSPEND__] pid: %d", pid);
__app_send_raw_with_noreply(pid, APP_WAKE, (unsigned char *)&dummy, sizeof(int));
+ */
}
-*/
+
static void __set_fg_flag(int cpid, int flag, gboolean force)
{
int lpid = app_group_get_leader_pid(cpid);
@@ -245,9 +248,8 @@ static void __set_fg_flag(int cpid, int flag, gboolean force)
GList *list;
GList *i;
app_group_context_t *ac;
-/* BG management
int bg_category = 0x00;
-*/
+
g_hash_table_iter_init(&iter, app_group_hash);
while (g_hash_table_iter_next(&iter, &key, &value)) {
list = (GList *)value;
@@ -260,9 +262,8 @@ static void __set_fg_flag(int cpid, int flag, gboolean force)
appid = _status_app_get_appid_bypid(ac->pid);
ai = appinfo_find(getuid(), appid);
pkgid = appinfo_get_value(ai, AIT_PKGID);
-/* BG management
bg_category = (bool)appinfo_get_value(ai, AIT_BG_CATEGORY);
-*/
+
if (flag) {
_D("send_signal FG %s", appid);
@@ -270,20 +271,18 @@ static void __set_fg_flag(int cpid, int flag, gboolean force)
pkgid,
STATUS_FOREGROUND,
APP_TYPE_UI);
-/* BG management
if (!bg_category)
- _status_find_service_apps(ac->pid, STATUS_VISIBLE, __prepare_to_wake_services, false);
-*/
+ _status_find_service_apps(ac->pid, getuid(), STATUS_VISIBLE, __prepare_to_wake_services, false);
+
} else {
_D("send_signal BG %s", appid);
aul_send_app_status_change_signal(ac->pid, appid,
pkgid,
STATUS_BACKGROUND,
APP_TYPE_UI);
-/* BG management
if (!bg_category)
- _status_find_service_apps(ac->pid, STATUS_BG, __prepare_to_suspend_services, true);
-*/
+ _status_find_service_apps(ac->pid, getuid(), STATUS_BG, __prepare_to_suspend_services, true);
+
}
ac->fg = flag;
}
@@ -579,7 +578,7 @@ static void __do_recycle(app_group_context_t *context)
aul_send_app_status_change_signal(context->pid, appid, pkgid,
STATUS_BACKGROUND,
APP_TYPE_UI);
- /* _status_find_service_apps(context->pid, STATUS_BG, __prepare_to_suspend_services, true); */
+ _status_find_service_apps(context->pid, getuid(), STATUS_BG, __prepare_to_suspend_services, true);
context->fg = 0;
}
recycle_bin = g_list_append(recycle_bin, context);
diff --git a/am_daemon/amd_appinfo.c b/am_daemon/amd_appinfo.c
index a7c15f6d..0f633a8f 100644
--- a/am_daemon/amd_appinfo.c
+++ b/am_daemon/amd_appinfo.c
@@ -46,7 +46,6 @@ struct user_appinfo {
enum _appinfo_idx {
_AI_FILE = 0, /* service filename */
_AI_NAME,
- _AI_COMP,
_AI_EXEC,
_AI_TYPE,
_AI_ONBOOT,
@@ -58,46 +57,41 @@ enum _appinfo_idx {
_AI_PRELOAD,
_AI_STATUS,
_AI_POOL,
+ _AI_COMPTYPE,
_AI_TEP,
_AI_STORAGE_TYPE,
+ _AI_BG_CATEGORY,
_AI_LAUNCH_MODE,
_AI_GLOBAL,
_AI_MAX,
};
#define _AI_START _AI_NAME /* start index */
+typedef int (*appinfo_handler_cb)(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data);
+
struct appinfo_t {
char *name;
enum appinfo_type type;
+ appinfo_handler_cb add;
};
-static struct appinfo_t _appinfos[] = {
- [_AI_NAME] = { "Name", AIT_NAME, },
- [_AI_COMP] = { "Component", AIT_COMP, },
- [_AI_EXEC] = { "Exec", AIT_EXEC, },
- [_AI_TYPE] = { "PkgType", AIT_TYPE, },
- [_AI_ONBOOT] = { "StartOnBoot", AIT_ONBOOT, },
- [_AI_RESTART] = { "AutoRestart", AIT_RESTART, },
- [_AI_MULTI] = { "Multiple", AIT_MULTI, },
- [_AI_HWACC] = { "Hwacceleration", AIT_HWACC, },
- [_AI_PERM] = { "PermissionType", AIT_PERM, },
- [_AI_PKGID] = { "PackageId", AIT_PKGID, },
- [_AI_PRELOAD] = { "Preload", AIT_PRELOAD, },
- [_AI_STATUS] = { "Status", AIT_STATUS, },
- [_AI_POOL] = { "ProcessPool", AIT_POOL, },
- [_AI_TEP] = {"Tep", AIT_TEP},
- [_AI_STORAGE_TYPE] = {"StorageType", AIT_STORAGE_TYPE},
- [_AI_LAUNCH_MODE] = {"launch_mode", AIT_LAUNCH_MODE },
- [_AI_GLOBAL] = {"global", AIT_GLOBAL },
+enum _background_category {
+ _BACKGROUND_CATEGORY_MEDIA = 0x01,
+ _BACKGROUND_CATEGORY_DOWNLOAD = 0x02,
+ _BACKGROUND_CATEGORY_BACKGROUND_NETWORK = 0x04,
+ _BACKGROUND_CATEGORY_LOCATION = 0x08,
+ _BACKGROUND_CATEGORY_SENSOR = 0x10,
+ _BACKGROUND_CATEGORY_IOT_COMMUNICATION = 0x20,
+ _BACKGROUND_CATEGORY_SYSTEM = 0x40
};
struct appinfo {
char *val[_AI_MAX];
};
-int gles = 1;
+static int gles = 1;
-static void _free_appinfo(gpointer data)
+static void __free_appinfo(gpointer data)
{
struct appinfo *c = data;
int i;
@@ -105,13 +99,15 @@ static void _free_appinfo(gpointer data)
if (!c)
return;
- for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++)
- free(c->val[i]);
+ for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++) {
+ if (i != _AI_BG_CATEGORY && c->val[i] != NULL)
+ free(c->val[i]);
+ }
free(c);
}
-static void _free_user_appinfo(gpointer data)
+static void __free_user_appinfo(gpointer data)
{
struct user_appinfo *info = (struct user_appinfo *)data;
@@ -133,179 +129,358 @@ static char *__convert_apptype(const char *type)
return NULL;
}
-static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *data)
+static int __read_background_category(const char *category_name, void *user_data)
{
- struct appinfo *c;
- struct user_appinfo *info = (struct user_appinfo *)data;
- char *exec;
- char *type;
- char *appid;
- char *pkgid;
- char *mode;
- bool multiple;
- bool onboot;
- bool restart;
- bool preload;
- bool process_pool = false;
- bool is_global = false;
- char *tep_name = NULL;
+ struct appinfo *c = user_data;
+ int category = (int)(c->val[_AI_BG_CATEGORY]);
- pkgmgrinfo_installed_storage installed_storage;
- pkgmgrinfo_app_hwacceleration hwacc;
- pkgmgrinfo_app_component component;
- pkgmgrinfo_permission_type permission;
+ if (!category_name)
+ return 0;
- if (!handle) {
- _E("null app handle");
+ if (strncmp(category_name, "disable", strlen("disable")) == 0) {
+ c->val[_AI_BG_CATEGORY] = 0x00;
return -1;
}
- if (pkgmgrinfo_appinfo_get_appid(handle, &appid)) {
+
+ if (strncmp(category_name, "media", strlen("media")) == 0)
+ c->val[_AI_BG_CATEGORY] = (char *)(category | _BACKGROUND_CATEGORY_MEDIA);
+ else if (strncmp(category_name, "download", strlen("download")) == 0)
+ c->val[_AI_BG_CATEGORY] = (char *)(category | _BACKGROUND_CATEGORY_DOWNLOAD);
+ else if (strncmp(category_name, "background-network", strlen("background-network")) == 0)
+ c->val[_AI_BG_CATEGORY] = (char *)(category | _BACKGROUND_CATEGORY_BACKGROUND_NETWORK);
+ else if (strncmp(category_name, "location", strlen("location")) == 0)
+ c->val[_AI_BG_CATEGORY] = (char *)(category | _BACKGROUND_CATEGORY_LOCATION);
+ else if (strncmp(category_name, "sensor", strlen("sensor")) == 0)
+ c->val[_AI_BG_CATEGORY] = (char *)(category | _BACKGROUND_CATEGORY_SENSOR);
+ else if (strncmp(category_name, "iot-communication", strlen("iot-communication")) == 0)
+ c->val[_AI_BG_CATEGORY] = (char *)(category | _BACKGROUND_CATEGORY_IOT_COMMUNICATION);
+ else if (strncmp(category_name, "system", strlen("system")) == 0)
+ c->val[_AI_BG_CATEGORY] = (char *)(category | _BACKGROUND_CATEGORY_SYSTEM);
+
+ return 0;
+}
+
+static int __appinfo_add_name(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ char *appid = NULL;
+
+ if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK) {
_E("fail to get appinfo");
return -1;
}
- g_hash_table_remove(info->tbl, appid);
+ info->val[_AI_NAME] = strdup(appid);
- c = calloc(1, sizeof(struct appinfo));
- if (!c) {
- _E("create appinfo: %s", strerror(errno));
+ return 0;
+}
+
+static int __appinfo_add_exec(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ char *exec = NULL;
+
+ if (pkgmgrinfo_appinfo_get_exec(handle, &exec) != PMINFO_R_OK) {
+ _E("failed to get exec");
return -1;
}
- c->val[_AI_FILE] = strdup(appid);
- c->val[_AI_NAME] = strdup(appid);
+ info->val[_AI_EXEC] = strdup(exec);
+
+ return 0;
+}
+
+static int __appinfo_add_type(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ char *type = NULL;
- if (pkgmgrinfo_appinfo_get_component(handle, &component)) {
- _E("failed to get component");
- _free_appinfo(c);
+ if (pkgmgrinfo_appinfo_get_apptype(handle, &type) != PMINFO_R_OK) {
+ _E("failed to get apptype");
return -1;
}
- if (component == PMINFO_UI_APP) {
- c->val[_AI_COMP] = strdup("ui");
- if (pkgmgrinfo_appinfo_is_multiple(handle, &multiple)) {
- _E("failed to get multiple");
- _free_appinfo(c);
- return -1;
- }
- c->val[_AI_MULTI] = strdup(multiple ? "true" : "false");
- if (pkgmgrinfo_appinfo_is_preload(handle, &preload)) {
- _E("failed to get preload");
- _free_appinfo(c);
- return -1;
- }
- c->val[_AI_PRELOAD] = strdup(preload ? "true" : "false");
- if (pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc)) {
- _E("failed to get hwacc");
- _free_appinfo(c);
- return -1;
- }
- c->val[_AI_HWACC] = strdup(
+ info->val[_AI_TYPE] = __convert_apptype(type);
+
+ return 0;
+}
+
+static int __appinfo_add_onboot(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ bool onboot = false;
+
+ if (pkgmgrinfo_appinfo_is_onboot(handle, &onboot) != PMINFO_R_OK) {
+ _E("failed to get onboot");
+ return -1;
+ }
+
+ info->val[_AI_ONBOOT] = strdup(onboot ? "true" : "false");
+
+ return 0;
+}
+
+static int __appinfo_add_restart(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ bool restart = false;
+
+ if (pkgmgrinfo_appinfo_is_autorestart(handle, &restart) != PMINFO_R_OK) {
+ _E("failed to get restart");
+ return -1;
+ }
+
+ info->val[_AI_RESTART] = strdup(restart ? "true" : "false");
+
+ return 0;
+}
+
+static int __appinfo_add_multi(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ bool multiple = false;
+
+ if (pkgmgrinfo_appinfo_is_multiple(handle, &multiple) != PMINFO_R_OK) {
+ _E("failed to get multiple");
+ return -1;
+ }
+
+ info->val[_AI_MULTI] = strdup(multiple ? "true" : "false");
+
+ return 0;
+}
+
+static int __appinfo_add_hwacc(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ pkgmgrinfo_app_hwacceleration hwacc;
+
+ if (pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc)) {
+ _E("failed to get hwacc");
+ return -1;
+ }
+
+ info->val[_AI_HWACC] = strdup(
(gles == 0 ||
hwacc == PMINFO_HWACCELERATION_NOT_USE_GL) ?
"NOT_USE" :
(hwacc == PMINFO_HWACCELERATION_USE_GL) ?
"USE" :
"SYS");
- c->val[_AI_ONBOOT] = strdup("false");
- c->val[_AI_RESTART] = strdup("false");
- } else {
- c->val[_AI_COMP] = strdup("svc");
- c->val[_AI_MULTI] = strdup("false");
- c->val[_AI_PRELOAD] = strdup("false");
- c->val[_AI_HWACC] = strdup("NOT_USE");
- if (pkgmgrinfo_appinfo_is_onboot(handle, &onboot)) {
- _E("failed to get onboot");
- _free_appinfo(c);
- return -1;
- }
- c->val[_AI_ONBOOT] = strdup(onboot ? "true" : "false");
- if (pkgmgrinfo_appinfo_is_autorestart(handle, &restart)) {
- _E("failed to get restart");
- _free_appinfo(c);
- return -1;
- }
- c->val[_AI_RESTART] = strdup(restart ? "true" : "false");
- }
- if (pkgmgrinfo_appinfo_get_exec(handle, &exec)) {
- _E("failed to get exec");
- _free_appinfo(c);
+ return 0;
+}
+
+static int __appinfo_add_perm(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ pkgmgrinfo_permission_type permission;
+
+ if (pkgmgrinfo_appinfo_get_permission_type(handle,
+ &permission) != PMINFO_R_OK) {
+ _E("failed to get permission type");
return -1;
}
- c->val[_AI_EXEC] = strdup(exec);
- if (pkgmgrinfo_appinfo_get_apptype(handle, &type)) {
- _E("failed to get apptype");
- _free_appinfo(c);
+ info->val[_AI_PERM] = strdup(
+ (permission == PMINFO_PERMISSION_SIGNATURE) ?
+ "signature" :
+ (permission == PMINFO_PERMISSION_PRIVILEGE) ?
+ "privilege" :
+ "normal");
+
+ return 0;
+}
+
+static int __appinfo_add_pkgid(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ char *pkgid = NULL;
+
+ if (pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK) {
+ _E("failed to get pkgid");
return -1;
}
- c->val[_AI_TYPE] = __convert_apptype(type);
- if (pkgmgrinfo_appinfo_get_permission_type(handle, &permission)) {
- _E("failed to get permission type");
- _free_appinfo(c);
+ info->val[_AI_PKGID] = strdup(pkgid);
+
+ return 0;
+}
+
+static int __appinfo_add_preload(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ bool preload = false;
+
+ if (pkgmgrinfo_appinfo_is_preload(handle, &preload) != PMINFO_R_OK) {
+ _E("failed to get preload");
return -1;
}
- c->val[_AI_PERM] = strdup(
- (permission == PMINFO_PERMISSION_SIGNATURE) ?
- "signature" :
- (permission == PMINFO_PERMISSION_PRIVILEGE) ?
- "privilege" :
- "normal");
- if (pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid)) {
- _E("failed to get pkgid");
- _free_appinfo(c);
+
+ info->val[_AI_PRELOAD] = strdup(preload ? "true" : "false");
+
+ return 0;
+}
+
+static int __appinfo_add_status(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ info->val[_AI_STATUS] = strdup("installed");
+
+ return 0;
+}
+
+static int __appinfo_add_pool(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ bool process_pool = false;
+
+ if (pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool) != PMINFO_R_OK) {
+ _E("failed to get process_pool");
return -1;
}
- c->val[_AI_PKGID] = strdup(pkgid);
- c->val[_AI_STATUS] = strdup("installed");
- if (pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool)) {
- _E("failed to get process_pool");
- _free_appinfo(c);
+ info->val[_AI_POOL] = strdup(process_pool ? "true" : "false");
+
+ return 0;
+}
+
+static int __appinfo_add_comptype(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ char *component_type = NULL;
+
+ if (pkgmgrinfo_appinfo_get_component_type(handle,
+ &component_type) != PMINFO_R_OK) {
+ _E("failed to get component type");
return -1;
}
- if (process_pool == false)
- c->val[_AI_POOL] = strdup("false");
- else
- c->val[_AI_POOL] = strdup("true");
+ info->val[_AI_COMPTYPE] = strdup(component_type);
- if (pkgmgrinfo_pkginfo_get_tep_name((pkgmgrinfo_pkginfo_h)info->extra_data, &tep_name)) {
+ return 0;
+}
+
+static int __appinfo_add_tep(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ char *tep_name = NULL;
+ struct user_appinfo *user_data = (struct user_appinfo *)data;
+
+ if (pkgmgrinfo_pkginfo_get_tep_name((pkgmgrinfo_pkginfo_h)user_data->extra_data,
+ &tep_name) != PMINFO_R_OK) {
_E("failed to get tep_name");
- c->val[_AI_TEP] = NULL;
+ info->val[_AI_TEP] = NULL;
} else {
- c->val[_AI_TEP] = strdup(tep_name);
+ info->val[_AI_TEP] = strdup(tep_name);
}
- if (pkgmgrinfo_pkginfo_is_for_all_users((pkgmgrinfo_pkginfo_h)info->extra_data, &is_global)) {
- _E("get pkginfo failed");
- return -1;
- }
+ return 0;
+}
- if (is_global)
- c->val[_AI_GLOBAL] = strdup("true");
- else
- c->val[_AI_GLOBAL] = strdup("false");
+static int __appinfo_add_storage_type(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ pkgmgrinfo_installed_storage installed_storage;
- if (pkgmgrinfo_appinfo_get_installed_storage_location(handle, &installed_storage) == PMINFO_R_OK) {
+ if (pkgmgrinfo_appinfo_get_installed_storage_location(handle,
+ &installed_storage) == PMINFO_R_OK) {
if (installed_storage == PMINFO_INTERNAL_STORAGE)
- c->val[_AI_STORAGE_TYPE] = strdup("internal");
+ info->val[_AI_STORAGE_TYPE] = strdup("internal");
else if (installed_storage == PMINFO_EXTERNAL_STORAGE)
- c->val[_AI_STORAGE_TYPE] = strdup("external");
+ info->val[_AI_STORAGE_TYPE] = strdup("external");
} else {
- c->val[_AI_STORAGE_TYPE] = strdup("internal");
+ info->val[_AI_STORAGE_TYPE] = strdup("internal");
}
- if (pkgmgrinfo_appinfo_get_launch_mode(handle, &mode)) {
+ return 0;
+}
+
+static int __appinfo_add_bg_category(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ info->val[_AI_BG_CATEGORY] = 0x0;
+ if (pkgmgrinfo_appinfo_foreach_background_category(handle,
+ __read_background_category, info) != PMINFO_R_OK) {
+ _E("Failed to get background category");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __appinfo_add_launch_mode(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ char *mode = NULL;
+
+ if (pkgmgrinfo_appinfo_get_launch_mode(handle, &mode) != PMINFO_R_OK) {
_E("failed to get launch_mode");
- _free_appinfo(c);
return -1;
}
- c->val[_AI_LAUNCH_MODE] = strdup(mode ? mode : "single");
- SECURE_LOGD("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]);
+ info->val[_AI_LAUNCH_MODE] = strdup(mode ? mode : "single");
+
+ return 0;
+}
+
+static int __appinfo_add_global(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data)
+{
+ bool is_global = false;
+ struct user_appinfo *user_data = (struct user_appinfo *)data;
+
+ if (pkgmgrinfo_pkginfo_is_for_all_users((pkgmgrinfo_pkginfo_h)user_data->extra_data,
+ &is_global) != PMINFO_R_OK) {
+ _E("get pkginfo failed");
+ return -1;
+ }
+
+ info->val[_AI_GLOBAL] = strdup(is_global ? "true" : "false");
+
+ return 0;
+}
+
+static struct appinfo_t _appinfos[] = {
+ [_AI_NAME] = { "Name", AIT_NAME, __appinfo_add_name },
+ [_AI_EXEC] = { "Exec", AIT_EXEC, __appinfo_add_exec },
+ [_AI_TYPE] = { "PkgType", AIT_TYPE, __appinfo_add_type },
+ [_AI_ONBOOT] = { "StartOnBoot", AIT_ONBOOT, __appinfo_add_onboot },
+ [_AI_RESTART] = { "AutoRestart", AIT_RESTART, __appinfo_add_restart },
+ [_AI_MULTI] = { "Multiple", AIT_MULTI, __appinfo_add_multi },
+ [_AI_HWACC] = { "Hwacceleration", AIT_HWACC, __appinfo_add_hwacc },
+ [_AI_PERM] = { "PermissionType", AIT_PERM, __appinfo_add_perm },
+ [_AI_PKGID] = { "PackageId", AIT_PKGID, __appinfo_add_pkgid },
+ [_AI_PRELOAD] = { "Preload", AIT_PRELOAD, __appinfo_add_preload },
+ [_AI_STATUS] = { "Status", AIT_STATUS, __appinfo_add_status },
+ [_AI_POOL] = { "ProcessPool", AIT_POOL, __appinfo_add_pool },
+ [_AI_COMPTYPE] = { "ComponentType", AIT_COMPTYPE, __appinfo_add_comptype },
+ [_AI_TEP] = {"Tep", AIT_TEP, __appinfo_add_tep},
+ [_AI_STORAGE_TYPE] = {"StorageType", AIT_STORAGE_TYPE, __appinfo_add_storage_type },
+ [_AI_BG_CATEGORY] = { "BackgroundCategory", AIT_BG_CATEGORY, __appinfo_add_bg_category },
+ [_AI_LAUNCH_MODE] = {"launch_mode", AIT_LAUNCH_MODE, __appinfo_add_launch_mode },
+ [_AI_GLOBAL] = {"global", AIT_GLOBAL, __appinfo_add_global },
+};
+
+static int __appinfo_insert_handler (const pkgmgrinfo_appinfo_h handle,
+ void *data)
+{
+ int i;
+ struct appinfo *c;
+ struct user_appinfo *info = (struct user_appinfo *)data;
+ char *appid;
+
+ if (!handle) {
+ _E("null app handle");
+ return -1;
+ }
+
+ if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK) {
+ _E("fail to get appinfo");
+ return -1;
+ }
+
+ g_hash_table_remove(info->tbl, appid);
+
+ c = calloc(1, sizeof(struct appinfo));
+ if (!c) {
+ _E("create appinfo: %s", strerror(errno));
+ return -1;
+ }
+
+ c->val[_AI_FILE] = strdup(appid);
+
+ for (i = 0; i < _AI_MAX; i++) {
+ if (_appinfos[i].add && _appinfos[i].add(handle, c, info) < 0) {
+ __free_appinfo(c);
+ return -1;
+ }
+ }
+
+ SECURE_LOGD("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMPTYPE],
+ c->val[_AI_TYPE]);
g_hash_table_insert(info->tbl, c->val[_AI_FILE], c);
@@ -328,7 +503,7 @@ static int __pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
info->extra_data = handle;
if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP,
- __app_info_insert_handler, user_data,
+ __appinfo_insert_handler, user_data,
info->uid)) {
_E("get appinfo failed");
return -1;
@@ -337,7 +512,7 @@ static int __pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
return 0;
}
-static void _remove_user_appinfo(uid_t uid)
+static void __remove_user_appinfo(uid_t uid)
{
g_hash_table_remove(user_tbl, GINT_TO_POINTER(uid));
}
@@ -355,7 +530,7 @@ static void __handle_onboot(void *user_data, const char *appid,
}
}
-static struct user_appinfo *_add_user_appinfo(uid_t uid)
+static struct user_appinfo *__add_user_appinfo(uid_t uid)
{
int r;
struct user_appinfo *info;
@@ -368,7 +543,7 @@ static struct user_appinfo *_add_user_appinfo(uid_t uid)
info->uid = uid;
info->tbl = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
- _free_appinfo);
+ __free_appinfo);
if (info->tbl == NULL) {
_E("out of memory");
free(info);
@@ -379,7 +554,7 @@ static struct user_appinfo *_add_user_appinfo(uid_t uid)
r = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, info, info->uid);
if (r != PMINFO_R_OK) {
- _remove_user_appinfo(uid);
+ __remove_user_appinfo(uid);
return NULL;
}
@@ -394,7 +569,7 @@ static struct user_appinfo *_add_user_appinfo(uid_t uid)
return info;
}
-static struct user_appinfo *_find_user_appinfo(uid_t uid)
+static struct user_appinfo *__find_user_appinfo(uid_t uid)
{
return g_hash_table_lookup(user_tbl, GINT_TO_POINTER(uid));
}
@@ -438,11 +613,11 @@ static gboolean __appinfo_remove_cb(gpointer key, gpointer value, gpointer data)
return FALSE;
}
-static void _appinfo_delete_on_event(uid_t uid, const char *pkgid)
+static void __appinfo_delete_on_event(uid_t uid, const char *pkgid)
{
struct user_appinfo *info;
- info = _find_user_appinfo(uid);
+ info = __find_user_appinfo(uid);
if (info == NULL) {
_E("cannot find appinfo for uid %d", uid);
return;
@@ -452,7 +627,7 @@ static void _appinfo_delete_on_event(uid_t uid, const char *pkgid)
(gpointer)pkgid);
}
-static void _appinfo_insert_on_event(uid_t uid, const char *pkgid)
+static void __appinfo_insert_on_event(uid_t uid, const char *pkgid)
{
appinfo_insert(uid, pkgid);
appinfo_foreach(uid, __handle_onboot, (void *)(intptr_t)uid);
@@ -488,12 +663,12 @@ static int __package_event_cb(uid_t target_uid, int req_id,
return 0;
if (!strcasecmp(op, "uninstall")) {
- _appinfo_delete_on_event(target_uid, pkgid);
+ __appinfo_delete_on_event(target_uid, pkgid);
} else if (!strcasecmp(op, "install")) {
- _appinfo_insert_on_event(target_uid, pkgid);
+ __appinfo_insert_on_event(target_uid, pkgid);
} else if (!strcasecmp(op, "update")) {
- _appinfo_delete_on_event(target_uid, pkgid);
- _appinfo_insert_on_event(target_uid, pkgid);
+ __appinfo_delete_on_event(target_uid, pkgid);
+ __appinfo_insert_on_event(target_uid, pkgid);
}
g_hash_table_remove(pkg_pending, pkgid);
@@ -502,7 +677,7 @@ static int __package_event_cb(uid_t target_uid, int req_id,
return 0;
}
-static int _init_package_event_handler(void)
+static int __init_package_event_handler(void)
{
pc = pkgmgr_client_new(PC_LISTENING);
if (pc == NULL)
@@ -514,7 +689,7 @@ static int _init_package_event_handler(void)
return 0;
}
-static void _fini_package_event_handler(void)
+static void __fini_package_event_handler(void)
{
pkgmgr_client_free(pc);
}
@@ -540,7 +715,7 @@ int appinfo_init(void)
fclose(fp);
user_tbl = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
- _free_user_appinfo);
+ __free_user_appinfo);
if (user_tbl == NULL)
return -1;
@@ -550,13 +725,13 @@ int appinfo_init(void)
return -1;
- global_appinfo = _add_user_appinfo(GLOBAL_USER);
+ global_appinfo = __add_user_appinfo(GLOBAL_USER);
if (global_appinfo == NULL) {
appinfo_fini();
return -1;
}
- if (_init_package_event_handler()) {
+ if (__init_package_event_handler()) {
appinfo_fini();
return -1;
}
@@ -568,7 +743,7 @@ void appinfo_fini(void)
{
g_hash_table_destroy(user_tbl);
g_hash_table_destroy(pkg_pending);
- _fini_package_event_handler();
+ __fini_package_event_handler();
}
struct appinfo *appinfo_find(uid_t caller_uid, const char *appid)
@@ -577,9 +752,9 @@ struct appinfo *appinfo_find(uid_t caller_uid, const char *appid)
struct appinfo *ai;
/* search from user table */
- info = _find_user_appinfo(caller_uid);
+ info = __find_user_appinfo(caller_uid);
if (info == NULL) {
- info = _add_user_appinfo(caller_uid);
+ info = __add_user_appinfo(caller_uid);
if (info == NULL)
return NULL;
}
@@ -592,7 +767,7 @@ struct appinfo *appinfo_find(uid_t caller_uid, const char *appid)
return NULL;
/* search again from global table */
- info = _find_user_appinfo(GLOBAL_USER);
+ info = __find_user_appinfo(GLOBAL_USER);
if (info == NULL) {
_E("cannot find global appinfo table!");
return NULL;
@@ -606,9 +781,9 @@ int appinfo_insert(uid_t uid, const char *pkgid)
struct user_appinfo *info;
pkgmgrinfo_pkginfo_h handle;
- info = _find_user_appinfo(uid);
+ info = __find_user_appinfo(uid);
if (info == NULL) {
- info = _add_user_appinfo(uid);
+ info = __add_user_appinfo(uid);
if (info == NULL)
_E("load appinfo for uid %d failed", uid);
return 0;
@@ -621,7 +796,7 @@ int appinfo_insert(uid_t uid, const char *pkgid)
info->extra_data = handle;
if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP,
- __app_info_insert_handler,
+ __appinfo_insert_handler,
info, info->uid)) {
_E("add appinfo of pkg %s failed", pkgid);
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
@@ -633,7 +808,7 @@ int appinfo_insert(uid_t uid, const char *pkgid)
return 0;
}
-static void _reload_appinfo(gpointer key, gpointer value, gpointer user_data)
+static void __reload_appinfo(gpointer key, gpointer value, gpointer user_data)
{
int r;
struct user_appinfo *info = (struct user_appinfo *)value;
@@ -642,7 +817,7 @@ static void _reload_appinfo(gpointer key, gpointer value, gpointer user_data)
r = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, info, info->uid);
if (r != PMINFO_R_OK) {
- _remove_user_appinfo(info->uid);
+ __remove_user_appinfo(info->uid);
return;
}
@@ -651,7 +826,7 @@ static void _reload_appinfo(gpointer key, gpointer value, gpointer user_data)
void appinfo_reload(void)
{
- g_hash_table_foreach(user_tbl, _reload_appinfo, NULL);
+ g_hash_table_foreach(user_tbl, __reload_appinfo, NULL);
}
const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
@@ -711,7 +886,7 @@ struct _cbinfo {
void *cb_data;
};
-static void _iter_cb(gpointer key, gpointer value, gpointer user_data)
+static void __iter_cb(gpointer key, gpointer value, gpointer user_data)
{
struct _cbinfo *cbi = user_data;
@@ -723,9 +898,9 @@ void appinfo_foreach(uid_t uid, appinfo_iter_callback cb, void *user_data)
struct user_appinfo *info;
struct _cbinfo cbi;
- info = _find_user_appinfo(uid);
+ info = __find_user_appinfo(uid);
if (info == NULL) {
- info = _add_user_appinfo(uid);
+ info = __add_user_appinfo(uid);
if (info == NULL)
return;
}
@@ -739,7 +914,7 @@ void appinfo_foreach(uid_t uid, appinfo_iter_callback cb, void *user_data)
cbi.cb = cb;
cbi.cb_data = user_data;
- g_hash_table_foreach(info->tbl, _iter_cb, &cbi);
+ g_hash_table_foreach(info->tbl, __iter_cb, &cbi);
}
int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type)
diff --git a/am_daemon/amd_appinfo.h b/am_daemon/amd_appinfo.h
index bf05b104..764b56a3 100644
--- a/am_daemon/amd_appinfo.h
+++ b/am_daemon/amd_appinfo.h
@@ -24,7 +24,6 @@ struct appinfo;
enum appinfo_type {
AIT_NAME,
- AIT_COMP,
AIT_EXEC,
AIT_TYPE,
AIT_ONBOOT, /* start on boot: boolean */
@@ -36,15 +35,19 @@ enum appinfo_type {
AIT_PRELOAD,
AIT_STATUS,
AIT_POOL,
+ AIT_COMPTYPE,
AIT_TEP,
AIT_STORAGE_TYPE,
+ AIT_BG_CATEGORY,
AIT_LAUNCH_MODE,
AIT_GLOBAL,
AIT_MAX
};
-#define APP_TYPE_UI "ui"
-#define APP_TYPE_SERVICE "svc"
+#define APP_TYPE_SERVICE "svcapp"
+#define APP_TYPE_UI "uiapp"
+#define APP_TYPE_WIDGET "widgetapp"
+#define APP_TYPE_WATCH "watchapp"
int appinfo_init(void);
void appinfo_fini(void);
diff --git a/am_daemon/amd_launch.c b/am_daemon/amd_launch.c
index 0e632d19..92daffdc 100644
--- a/am_daemon/amd_launch.c
+++ b/am_daemon/amd_launch.c
@@ -813,7 +813,7 @@ int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid,
if (!multiple || strncmp(multiple, "false", 5) == 0)
pid = _status_app_is_running(appid, caller_uid);
- component_type = appinfo_get_value(ai, AIT_COMP);
+ component_type = appinfo_get_value(ai, AIT_COMPTYPE);
if (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0) {
pid = __get_pid_for_app_group(appid, pid, caller_uid, kb,
&lpid, &can_attach, &new_process, &launch_mode, &is_subapp);
diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c
index cfb68614..6dfaec6f 100644
--- a/am_daemon/amd_request.c
+++ b/am_daemon/amd_request.c
@@ -279,7 +279,7 @@ static int __app_process_by_pid(int cmd,
ai = appinfo_find(cr->uid, appid);
if (ai) {
pkgid = appinfo_get_value(ai, AIT_PKGID);
- type = appinfo_get_value(ai, AIT_COMP);
+ type = appinfo_get_value(ai, AIT_COMPTYPE);
}
if (ai && (cmd == APP_RESUME_BY_PID || cmd == APP_PAUSE_BY_PID))
diff --git a/am_daemon/amd_status.c b/am_daemon/amd_status.c
index 88a0f82b..c7ab0244 100644
--- a/am_daemon/amd_status.c
+++ b/am_daemon/amd_status.c
@@ -40,17 +40,182 @@
#include "menu_db_util.h"
#include "amd_app_group.h"
-typedef struct _app_status_info_t {
- char appid[MAX_PACKAGE_STR_SIZE];
- char app_path[MAX_PACKAGE_APP_PATH_SIZE];
+typedef struct _pkg_status_info_t {
+ char *pkgid;
+ int status;
+ GSList *ui_list;
+ GSList *svc_list;
+} pkg_status_info_t;
+
+typedef struct _app_status_info_t{
+ char *appid;
+ char *app_path;
+ char *pkgid;
int status;
int pid;
int pad_pid;
bool is_subapp;
+ pkg_status_info_t *pkginfo;
uid_t uid;
} app_status_info_t;
static GSList *app_status_info_list = NULL;
+static GHashTable *pkg_status_info_table = NULL;
+
+static void __add_pkg_info(const char *pkgid, app_status_info_t *appinfo)
+{
+ pkg_status_info_t *pkginfo = NULL;
+
+ if (pkgid == NULL || appinfo == NULL) {
+ _E("empty arguments: %s", pkgid == NULL ? (appinfo == NULL ? "appinfo, pkgid" : "pkgid") : "appinfo");
+ return;
+ }
+
+ if (pkg_status_info_table == NULL)
+ pkg_status_info_table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+
+ pkginfo = g_hash_table_lookup(pkg_status_info_table, pkgid);
+ if (pkginfo == NULL) {
+ pkginfo = (pkg_status_info_t *)malloc(sizeof(pkg_status_info_t));
+ if (pkginfo == NULL) {
+ _E("failed to allocate memory");
+ return;
+ }
+
+ memset(pkginfo, 0, sizeof(pkg_status_info_t));
+ pkginfo->pkgid = strdup(pkgid);
+ if (pkginfo->pkgid == NULL) {
+ free(pkginfo);
+ _E("failed to allocate memory");
+ return;
+ }
+
+ g_hash_table_insert(pkg_status_info_table, pkginfo->pkgid, pkginfo);
+ }
+
+ pkginfo->status = appinfo->status;
+ appinfo->pkginfo = pkginfo;
+
+ if (appinfo->status == STATUS_SERVICE)
+ pkginfo->svc_list = g_slist_append(pkginfo->svc_list, appinfo);
+ else
+ pkginfo->ui_list = g_slist_append(pkginfo->ui_list, appinfo);
+}
+
+static int __get_ui_app_status_pkg_info(pkg_status_info_t *pkginfo)
+{
+ app_status_info_t *appinfo = NULL;
+ GSList *iter = NULL;
+ int status = STATUS_BG;
+
+ if (pkginfo == NULL)
+ return -1;
+
+ iter = pkginfo->ui_list;
+ while (iter) {
+ appinfo = (app_status_info_t *)iter->data;
+ if (appinfo->status != STATUS_BG)
+ status = appinfo->status;
+
+ iter = g_slist_next(iter);
+ }
+
+ return status;
+}
+
+static int __update_pkg_info(const char *pkgid, app_status_info_t *appinfo)
+{
+ pkg_status_info_t *pkginfo = NULL;
+ int ret = 0;
+
+ if (pkgid == NULL || appinfo == NULL)
+ return -1;
+
+ if (pkg_status_info_table == NULL)
+ return -1;
+
+ pkginfo = (pkg_status_info_t *)g_hash_table_lookup(pkg_status_info_table, pkgid);
+ if (pkginfo == NULL) {
+ _E("pkgid(%s) is not on list");
+ return -1;
+ }
+
+ if (pkginfo->ui_list) {
+ ret = __get_ui_app_status_pkg_info(pkginfo);
+ if (ret > -1)
+ pkginfo->status = ret;
+ } else {
+ pkginfo->status = STATUS_SERVICE;
+ }
+
+ return 0;
+}
+
+
+static void __remove_pkg_info(const char *pkgid, app_status_info_t *appinfo, uid_t caller_uid)
+{
+ pkg_status_info_t *pkginfo = NULL;
+ const struct appinfo *ai = NULL;
+ const char *component_type = NULL;
+
+ if (pkgid == NULL || appinfo == NULL) {
+ _E("empty arguments: %s", pkgid == NULL ? (appinfo == NULL ? "appinfo, pkgid" : "pkgid") : "appinfo");
+ return;
+ }
+
+ ai = appinfo_find(caller_uid, appinfo->appid);
+ component_type = appinfo_get_value(ai, AIT_COMPTYPE);
+
+ pkginfo = (pkg_status_info_t *)g_hash_table_lookup(pkg_status_info_table, pkgid);
+ if (pkginfo == NULL) {
+ _E("pkgid(%s) is not on list");
+ return;
+ }
+
+ if (component_type && strcmp(component_type, APP_TYPE_SERVICE) == 0) {
+ if (pkginfo->svc_list) {
+ pkginfo->svc_list = g_slist_remove(pkginfo->svc_list, appinfo);
+ _D("STATUS_SERVICE : appid(%s)", appinfo->appid);
+ }
+ } else {
+ if (pkginfo->ui_list) {
+ pkginfo->ui_list = g_slist_remove(pkginfo->ui_list, appinfo);
+ _D("~STATUS_SERVICE : appid(%s)", appinfo->appid);
+ }
+ }
+
+ if (!pkginfo->svc_list && !pkginfo->ui_list) {
+ g_hash_table_remove(pkg_status_info_table, pkgid);
+ if (pkginfo->pkgid) {
+ free(pkginfo->pkgid);
+ pkginfo->pkgid = NULL;
+ }
+ free(pkginfo);
+ }
+}
+
+static void __destroy_app_status_info(app_status_info_t *info_t)
+{
+ if (info_t == NULL)
+ return;
+
+ if (info_t->appid) {
+ free(info_t->appid);
+ info_t->appid = NULL;
+ }
+
+ if (info_t->app_path) {
+ free(info_t->app_path);
+ info_t->app_path = NULL;
+ }
+
+ if (info_t->pkgid) {
+ free(info_t->pkgid);
+ info_t->pkgid = NULL;
+ }
+
+ free(info_t);
+}
int _status_add_app_info_list(const char *appid, const char *app_path, int pid,
int pad_pid, bool is_subapp, uid_t uid)
@@ -58,6 +223,12 @@ int _status_add_app_info_list(const char *appid, const char *app_path, int pid,
GSList *iter;
GSList *iter_next;
app_status_info_t *info_t;
+ const struct appinfo *ai;
+ const char *component_type = NULL;
+ const char *pkgid = NULL;
+
+ if (!appid || !app_path)
+ return -1;
GSLIST_FOREACH_SAFE(app_status_info_list, iter, iter_next) {
info_t = (app_status_info_t *)iter->data;
@@ -67,33 +238,58 @@ int _status_add_app_info_list(const char *appid, const char *app_path, int pid,
else {
/* PID is unique so if it is exist but user value is not correct remove it. */
app_status_info_list = g_slist_remove(app_status_info_list, info_t);
- free(info_t);
+ __remove_pkg_info(info_t->pkgid, info_t, uid);
+ __destroy_app_status_info(info_t);
break;
}
}
}
+ ai = appinfo_find(uid, appid);
+
info_t = malloc(sizeof(app_status_info_t));
if (info_t == NULL) {
_E("out of memory");
return -1;
}
- strncpy(info_t->appid, appid, MAX_PACKAGE_STR_SIZE-1);
- strncpy(info_t->app_path, app_path, MAX_PACKAGE_APP_PATH_SIZE-1);
- info_t->status = STATUS_LAUNCHING;
+
+ memset(info_t, 0, sizeof(app_status_info_t));
+
+ info_t->appid = strdup(appid);
+ if (info_t->appid == NULL)
+ goto error;
+
+ info_t->app_path = strdup(app_path);
+ if (info_t->app_path == NULL)
+ goto error;
+
+ component_type = appinfo_get_value(ai, AIT_COMPTYPE);
+ if (component_type && strcmp(component_type, APP_TYPE_SERVICE) == 0)
+ info_t->status = STATUS_SERVICE;
+ else
+ info_t->status = STATUS_LAUNCHING;
+
+ pkgid = appinfo_get_value(ai, AIT_PKGID);
+ if (pkgid == NULL)
+ goto error;
+
info_t->pid = pid;
info_t->pad_pid = pad_pid;
info_t->is_subapp = is_subapp;
info_t->uid = uid;
- app_status_info_list = g_slist_append(app_status_info_list, info_t);
+ info_t->pkgid = strdup(pkgid);
+ if (info_t->pkgid == NULL)
+ goto error;
- for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) {
- info_t = (app_status_info_t *)iter->data;
-
- SECURE_LOGD(" [%d] : %s, %d, %d", info_t->uid, info_t->appid, info_t->pid, info_t->status);
- }
+ app_status_info_list = g_slist_append(app_status_info_list, info_t);
+ __add_pkg_info(pkgid, info_t);
+ _D("pid(%d) appid(%s) pkgid(%s) comp(%s)", pid, appid, pkgid, component_type);
return 0;
+error:
+ __destroy_app_status_info(info_t);
+
+ return -1;
}
int _status_update_app_info_list(int pid, int status, uid_t uid)
@@ -101,10 +297,14 @@ int _status_update_app_info_list(int pid, int status, uid_t uid)
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
+ _D("pid(%d) status(%d)", pid, status);
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) {
info_t = (app_status_info_t *)iter->data;
if ((pid == info_t->pid) && ((info_t->uid == uid) || (info_t->uid == 0))) {
info_t->status = status;
+ __update_pkg_info(info_t->pkgid, info_t);
+
+ _D("pid(%d) appid(%s) pkgid(%s) status(%d)", pid, info_t->appid, info_t->pkgid, info_t->status);
break;
}
}
@@ -142,7 +342,8 @@ int _status_remove_app_info_list(int pid, uid_t uid)
info_t = (app_status_info_t *)iter->data;
if ((pid == info_t->pid) && ((info_t->uid == uid) || (info_t->uid == 0))) {
app_status_info_list = g_slist_remove(app_status_info_list, info_t);
- free(info_t);
+ __remove_pkg_info(info_t->pkgid, info_t, uid);
+ __destroy_app_status_info(info_t);
break;
}
}
@@ -165,6 +366,100 @@ int _status_get_app_info_status(int pid, uid_t uid)
return app_group_get_status(pid);
}
+static gint __find_app_bypid(gconstpointer app_data, gconstpointer pid_data)
+{
+ int pid = GPOINTER_TO_INT(pid_data);
+ app_status_info_t *appinfo = (app_status_info_t *)app_data;
+
+ if (appinfo && pid && appinfo->pid == pid)
+ return 0;
+
+ return -1;
+}
+
+void _status_find_service_apps(int pid, uid_t uid, enum app_status status, void (*send_event_to_svc_core) (int), bool suspend)
+{
+ GSList *app_list = NULL;
+ GSList *svc_list = NULL;
+ app_status_info_t *info_t = NULL;
+ app_status_info_t *svc_info_t = NULL;
+ const struct appinfo *ai = NULL;
+ int bg_allowed = 0x00;
+
+ app_list = g_slist_find_custom(app_status_info_list, GINT_TO_POINTER(pid), __find_app_bypid);
+
+ if (!app_list) {
+ _E("unable to find app by pid:%d", pid);
+ return;
+ }
+
+ info_t = (app_status_info_t *)app_list->data;
+ if (info_t && info_t->pkginfo && info_t->pkginfo->status == status)
+ svc_list = info_t->pkginfo->svc_list;
+
+ while (svc_list) {
+ svc_info_t = (app_status_info_t *)svc_list->data;
+ if (svc_info_t) {
+ ai = appinfo_find(uid, svc_info_t->appid);
+ bg_allowed = (int)appinfo_get_value(ai, AIT_BG_CATEGORY);
+ if (!bg_allowed) {
+ send_event_to_svc_core(svc_info_t->pid);
+ /* TODO: APIs should be prepared
+ if (suspend)
+ _amd_suspend_add_timer(svc_info_t->pid, ai);
+ else
+ _amd_suspend_remove_timer(svc_info_t->pid);
+ */
+ }
+ }
+ svc_list = g_slist_next(svc_list);
+ }
+}
+
+void _status_check_service_only(int pid, uid_t uid, void (*send_event_to_svc_core) (int))
+{
+ GSList *app_list = NULL;
+ GSList *ui_list = NULL;
+ app_status_info_t *info_t = NULL;
+ app_status_info_t *ui_info_t = NULL;
+ int ui_cnt = 0;
+
+ app_list = g_slist_find_custom(app_status_info_list, GINT_TO_POINTER(pid), __find_app_bypid);
+
+ if (!app_list) {
+ _E("unable to find app by pid:%d", pid);
+ return;
+ }
+
+ info_t = (app_status_info_t *)app_list->data;
+ ui_list = info_t->pkginfo->ui_list;
+ while (ui_list) {
+ ui_info_t = (app_status_info_t *)ui_list->data;
+ if (ui_info_t && _status_app_is_running_v2(ui_info_t->appid, uid) > 0)
+ ui_cnt++;
+ ui_list = g_slist_next(ui_list);
+ }
+
+ if (ui_cnt == 0) {
+ const char *appid = NULL;
+ const struct appinfo *ai = NULL;
+ int bg_allowed = 0x00;
+
+ appid = _status_app_get_appid_bypid(pid);
+ if (appid) {
+ ai = appinfo_find(uid, appid);
+ bg_allowed = (int)appinfo_get_value(ai, AIT_BG_CATEGORY);
+
+ if (!bg_allowed) {
+ send_event_to_svc_core(pid);
+ /* TODO: APIs should be prepared
+ _amd_suspend_add_timer(pid, ai);
+ */
+ }
+ }
+ }
+}
+
int _status_app_is_running(const char *appid, uid_t uid)
{
GSList *iter = NULL;
diff --git a/am_daemon/amd_status.h b/am_daemon/amd_status.h
index f4a6e7a8..0c50a006 100644
--- a/am_daemon/amd_status.h
+++ b/am_daemon/amd_status.h
@@ -23,6 +23,7 @@
#include <sys/types.h>
#include <glib.h>
#include <stdbool.h>
+#include <aul.h>
int _status_add_app_info_list(const char *appid, const char *app_path, int pid, int pad_pid, bool is_subapp, uid_t uid);
int _status_update_app_info_list(int pid, int status, uid_t uid);
@@ -32,6 +33,8 @@ int _status_get_app_info_status(int pid, uid_t uid);
int _status_send_running_appinfo(int fd, uid_t uid);
int _status_app_is_running(const char *appid, uid_t uid);
int _status_app_is_running_v2(const char *appid, uid_t caller_uid);
+void _status_find_service_apps(int pid, uid_t uid, enum app_status status, void (*send_event_to_svc_core) (int), bool suspend);
+void _status_check_service_only(int pid, uid_t uid, void (*send_event_to_svc_core) (int));
char *_status_app_get_appid_bypid(int pid);
int _status_get_appid_bypid(int fd, int pid);
int _status_get_pkgid_bypid(int fd, int pid);