break;
case APP_STATUS_UPDATE:
status = (int *)pkt->data;
- ret = _status_update_app_info_list(cr.pid, *status, cr.uid);
+ if (*status == STATUS_NORESTART) {
+ appid = _status_app_get_appid_bypid(cr.pid);
+ ai = appinfo_find(cr.uid, appid);
+ appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "norestart");
+ } else {
+ ret = _status_update_app_info_list(cr.pid, *status, cr.uid);
+ }
//__send_result_to_client(clifd, ret);
close(clifd);
break;
+ case APP_GET_STATUS:
+ memcpy(&pid, pkt->data, sizeof(int));
+ ret = _status_get_app_info_status(pid, 0);
+ __send_result_to_client(clifd, ret);
+ break;
case APP_RELEASED:
appid = malloc(MAX_PACKAGE_STR_SIZE);
if (appid == NULL) {
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
#include <glib.h>
#include <aul.h>
#include <string.h>
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 && uid == info_t->uid) {
+ if (pid == info_t->pid &&
+ (uid == 0) ? true : (uid == info_t->uid)) {
return info_t->status;
}
}
APP_GROUP_GET_GROUP_PIDS,
APP_GROUP_RESUME,
APP_GROUP_GET_LEADER_PID,
+ APP_GET_STATUS,
/* for special purpose */
AMD_RELOAD_APPINFO,
STATUS_VISIBLE,
STATUS_BG,
STATUS_DYING,
- STATUS_HOME
+ STATUS_HOME,
+ STATUS_NORESTART,
+ STATUS_SERVICE
};
/** @} */
int aul_remove_caller_cb(int pid);
int aul_invoke_caller_cb(int pid);
+/**
+ * @par Description:
+ * This API gets status of specified application process id.
+ * @par Purpose:
+ * This API's purpose is to get the application's status.
+ *
+ * @param[in] pid pid of application
+ * @return 0 or greater if success, nagative value if fail
+ * @retval STATUS_LAUNCHING
+ * @retval STATUS_CREATED
+ * @retval STATUS_FOCUS
+ * @retval STATUS_VISIBLE
+ * @retval STATUS_BG
+ * @retval STATUS_DYING
+ * @retval STATUS_HOME
+ * @retval STATUS_NORESTART
+ * @see
+ * aul_status_update
+ * @pre
+ * None
+ * @post
+ * None
+ * @code
+ * #include <aul.h>
+ *
+ * int iterfunc(const aul_app_info *info, void *data)
+ * {
+ * int status;
+ * status = aul_app_get_status_bypid(info->pid);
+ * if (status == STATUS_FOCUS) {
+ * printf("%s has focus", info->app_id);
+ * (int *)data = info->pid;
+ * return -1;
+ * }
+ * return 0;
+ * }
+ *
+ * int find_focus_app_pid()
+ * {
+ * int pid = 0;
+ * aul_app_get_running_app_info(iterfunc, &pid);
+ * return pid;
+ * }
+ * @endcode
+ * @remark
+ * None
+ */
+int aul_app_get_status_bypid(int pid);
+
+/**
+ * @par Description
+ * This API sets callback function that on application status changed.
+ * @par Purpose:
+ * This API's purpose is to listen the application's status changed within
+ * the caller process. In general, a library that required to release resource on
+ * application's status may use this API.
+ *
+ * @param[in] func callback function
+ * @param[in] data user data
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - general error
+ * @see
+ * aul_remove_status_local_cb
+ * @pre
+ * None
+ * @post
+ * None
+ * @code
+ * #include <aul.h>
+ *
+ * int status_changed(int status, void *data)
+ * {
+ * if (status == STATUS_FOCUS)
+ * printf("%d has focus\n", getpid());
+ *
+ * if (status == STATUS_VISIBLE)
+ * printf("%d resume\n", getpid());
+ *
+ * if (status == STATUS_BG0
+ * printf("%d pause\n", getpid());
+ * }
+ *
+ * void listen_app_status()
+ * {
+ * aul_add_status_local_cb(status_changed, NULL);
+ * }
+ * @endcode
+ * @remark
+ * None
+ *
+ */
+int aul_add_status_local_cb(int (*func) (int, void *), void *data);
+
+/**
+ * @par Description
+ * This API unsets callback function that on application status changed.
+ * @par Purpose:
+ * This API's purpose is to remove callback that added by
+ * aul_add_status_local_cb.
+ *
+ * @param[in] func callback function
+ * @param[in] data user data
+ * @return 0 if success, negative value if fail
+ * @retval AUL_R_OK - success
+ * @retval AUL_R_ERROR - general error
+ *
+ * @pre
+ * None
+ * @post
+ * None
+ * @see
+ * aul_add_status_local_cb
+ * @code
+ * #include <aul.h>
+ *
+ * int status_changed(int status, void *data)
+ * {
+ * if (status == STATUS_FOCUS)
+ * printf("%d has focus\n", getpid());
+ *
+ * if (status == STATUS_VISIBLE)
+ * printf("%d resume\n", getpid());
+ *
+ * if (status == STATUS_BG0
+ * printf("%d pause\n", getpid());
+ * }
+ *
+ * void listen_app_status()
+ * {
+ * aul_add_status_local_cb(status_changed, NULL);
+ * }
+ *
+ * void ignore_app_status()
+ * {
+ * aul_remove_status_local_cb(status_changed, NULL);
+ * }
+ *
+ * @endcode
+ * @remark
+ * None
+ *
+ */
+int aul_remove_status_local_cb(int (*func) (int, void *), void *data);
+int aul_invoke_status_local_cb(int status);
+
typedef int (*data_control_provider_handler_fn) (bundle *b, int request_id, void *data);
int aul_set_data_control_provider_cb(data_control_provider_handler_fn handler);
int aul_unset_data_control_provider_cb(void);
#include "aul_api.h"
#include "launch.h"
+typedef struct _app_status_cb_info_t {
+ int (*handler) (int status, void *data);
+ void *data;
+ struct _app_status_cb_info_t *next;
+} app_status_cb_info_t;
+
+app_status_cb_info_t *app_status_cb = NULL;
+
+static int app_status = STATUS_LAUNCHING;
+
SLPAPI int aul_status_update(int status)
{
int ret;
+ app_status_cb_info_t *cb = app_status_cb;
+
+ app_status = status;
ret = __app_send_raw_with_noreply(AUL_UTIL_PID, APP_STATUS_UPDATE, (unsigned char *)&status, sizeof(status));
+ if (!ret) {
+ while (cb) {
+ if (cb->handler) {
+ if (cb->handler(app_status, cb->data) < 0)
+ aul_remove_status_local_cb(cb->handler, cb->data);
+ }
+
+ cb = cb->next;
+ }
+ }
+
+ return ret;
+}
+
+SLPAPI int aul_app_get_status_bypid(int pid)
+{
+ int ret;
+
+ if (pid == getpid()) {
+ return app_status;
+ }
+
+ ret = __app_send_raw(AUL_UTIL_PID, APP_GET_STATUS, (unsigned char *)&pid, sizeof(pid));
+
return ret;
}
+SLPAPI int aul_add_status_local_cb(int (*func)(int status, void *data), void *data)
+{
+ app_status_cb_info_t *cb = app_status_cb;
+
+ if (func == NULL)
+ return -1;
+
+ // check known callback
+ while (cb) {
+ if (cb && cb->handler == func && cb->data == data) {
+ // already in list
+ return 0;
+ }
+ cb = cb->next;
+ }
+
+ cb = (app_status_cb_info_t *)malloc(sizeof(app_status_cb_info_t));
+ if (cb == NULL)
+ return -1;
+
+ cb->handler = func;
+ cb->data = data;
+
+ cb->next = app_status_cb;
+ app_status_cb = cb;
+
+ return 0;
+}
+
+SLPAPI int aul_remove_status_local_cb(int (*func)(int status, void *data), void *data)
+{
+ app_status_cb_info_t *cb = app_status_cb;
+ app_status_cb_info_t *tmp = NULL;
+
+ if (app_status_cb
+ && app_status_cb->handler == func
+ && app_status_cb->data == data) {
+ cb = app_status_cb->next;
+ free(app_status_cb);
+ app_status_cb = cb;
+ return 0;
+ }
+
+ while (cb) {
+ if (cb->next
+ && cb->next->handler == func
+ && cb->next->data == data) {
+ tmp = cb->next->next;
+ free(cb->next);
+ cb->next = tmp;
+ return 0;
+ }
+
+ cb = cb->next;
+ }
+
+ return -1;
+}
+
+SLPAPI int aul_invoke_status_local_cb(int status)
+{
+ app_status_cb_info_t *cb = app_status_cb;
+
+ while (cb) {
+ if (cb->handler) {
+ if (cb->handler(status, cb->data) < 0)
+ aul_remove_status_local_cb(cb->handler, cb->data);
+ }
+
+ cb = cb->next;
+ }
+
+ return 0;
+}
+
SLPAPI int aul_running_list_update(char *appid, char *app_path, char *pid)
{
int ret;
return 0;
}
+static char *status_text[] = {
+ "STATUS_LAUNCHING",
+ "STATUS_CREATED",
+ "STATUS_FOCUS",
+ "STATUS_VISIBLE",
+ "STATUS_BG",
+ "STATUS_DYING",
+ "STATUS_HOME",
+ "STATUS_NORESTART",
+ "STATUS_SERVICE",
+};
+
+static int get_status_pid()
+{
+ int ret;
+ ret = aul_app_get_status_bypid(apn_pid);
+
+ printf("pid: %d status: %d ", apn_pid, ret);
+ if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART)
+ printf("(%s)", status_text[ret]);
+
+ printf("\n");
+
+ return 0;
+}
+
static int update_running_list()
{
aul_running_list_update(gargv[2], gargv[3], gargv[4]);
"[usage] update_list <appid> <app_path> <pid>"},
{"reload", reload_appinfo, "reload appinfo table",
"[usage] reload"},
+ {"get_status_pid", get_status_pid, "aul_app_get_status_bypid test",
+ "[usage] get_status_pid <pid>"},
/*
{"setpkg", set_pkg_func, "set package",
"[usage] setpkg <pkgname> <apppath>"},