*
*/
-
+#define _GNU_SOURCE
#include <stdio.h>
+#include <dbus/dbus-glib-lowlevel.h>
#include "app_signal.h"
#include "aul_api.h"
static int (*_app_launch_handler) (int pid, void *data);
static void *_app_launch_data;
+static int (*_app_launch_handler2) (int pid, const char *app_id, void *data);
+static void *_app_launch_data2;
+
static int (*_booting_done_handler) (int pid, void *data);
static void *_booting_done_data;
static int (*_cooldown_handler) (const char *cooldown_status, void *data);
static void *_cooldown_data;
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
-static int (*_lcd_status_handler) (const char *lcd_status, void *data);
-static void *_lcd_status_data;
-#endif
-
static DBusConnection *bus;
static int app_dbus_signal_handler_initialized = 0;
+DBusError err;
+DBusConnection* conn = NULL;
+
static DBusHandlerResult
__app_dbus_signal_filter(DBusConnection *conn, DBusMessage *message,
void *user_data)
if (dbus_message_is_signal(
message, interface, AUL_DBUS_APPDEAD_SIGNAL)) {
- if (dbus_message_get_args(message, &error, DBUS_TYPE_UINT32,
- &pid, DBUS_TYPE_INVALID) == FALSE) {
- _E("Failed to get data: %s", error.message);
- dbus_error_free(&error);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- if (_app_dead_handler)
+ if (_app_dead_handler) {
+ if (dbus_message_get_args(message, &error,
+ DBUS_TYPE_UINT32, &pid,
+ DBUS_TYPE_INVALID) == FALSE) {
+ _E("Failed to get data: %s", error.message);
+ dbus_error_free(&error);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
_app_dead_handler(pid, _app_dead_data);
+ }
} else if (dbus_message_is_signal(
message, interface, AUL_DBUS_APPLAUNCH_SIGNAL)) {
- if (dbus_message_get_args(message, &error, DBUS_TYPE_UINT32,
- &pid, DBUS_TYPE_INVALID) == FALSE) {
- _E("Failed to get data: %s", error.message);
- dbus_error_free(&error);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (_app_launch_handler || _app_launch_handler2) {
+ const char *app_id = NULL;
+
+ if (dbus_message_get_args(message, &error,
+ DBUS_TYPE_UINT32, &pid,
+ DBUS_TYPE_STRING, &app_id,
+ DBUS_TYPE_INVALID) == FALSE) {
+ _E("Failed to get data: %s", error.message);
+ dbus_error_free(&error);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (_app_launch_handler)
+ _app_launch_handler(pid, _app_launch_data);
+
+ if (_app_launch_handler2)
+ _app_launch_handler2(pid, app_id, _app_launch_data2);
}
- if (_app_launch_handler)
- _app_launch_handler(pid, _app_launch_data);
} else if (dbus_message_is_signal(
message, interface, SYSTEM_SIGNAL_BOOTING_DONE)) {
if (_booting_done_handler)
_booting_done_handler(pid, _booting_done_data);
} else if (dbus_message_is_signal(
message, interface, RESOURCED_SIGNAL_PROCESS_STATUS)) {
- if (dbus_message_get_args(message, &error, DBUS_TYPE_INT32,&status,
- DBUS_TYPE_INT32,&pid, DBUS_TYPE_INVALID) == FALSE) {
- _E("Failed to get data: %s", error.message);
- dbus_error_free(&error);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- if (_status_handler)
+ if (_status_handler) {
+ if (dbus_message_get_args(message, &error,
+ DBUS_TYPE_INT32,&status,
+ DBUS_TYPE_INT32,&pid,
+ DBUS_TYPE_INVALID) == FALSE) {
+ _E("Failed to get data: %s", error.message);
+ dbus_error_free(&error);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
_status_handler(pid, status, _status_data);
+ }
} else if (dbus_message_is_signal(
message, interface, SYSTEM_SIGNAL_COOLDOWN_CHANGED)) {
- if (dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &cooldown_status,
- DBUS_TYPE_INVALID) == FALSE) {
- _E("Failed to get data: %s", error.message);
- dbus_error_free(&error);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- if (_cooldown_handler)
+ if (_cooldown_handler) {
+ if (dbus_message_get_args(message, &error,
+ DBUS_TYPE_STRING, &cooldown_status,
+ DBUS_TYPE_INVALID) == FALSE) {
+ _E("Failed to get data: %s", error.message);
+ dbus_error_free(&error);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
_cooldown_handler(cooldown_status, _cooldown_data);
+ }
}
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
- else if (dbus_message_is_signal(
- message, interface, DEVICED_SIGNAL_LCD_ON)) {
- if (_lcd_status_handler)
- _lcd_status_handler(DEVICED_SIGNAL_LCD_ON, _lcd_status_data);
- } else if (dbus_message_is_signal(
- message, interface, DEVICED_SIGNAL_LCD_OFF)) {
- if (_lcd_status_handler)
- _lcd_status_handler(DEVICED_SIGNAL_LCD_OFF, _lcd_status_data);
- }
-#endif
return DBUS_HANDLER_RESULT_HANDLED;
}
-int __app_dbus_signal_handler_init(void)
-{
- int ret = 0;
-
- if (app_dbus_signal_handler_initialized)
- return 0;
-
- ret = __app_dbus_signal_handler_init_with_param(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE);
-
- app_dbus_signal_handler_initialized = 1;
-
- return ret;
-}
-
-int __app_dbus_signal_handler_init_with_param(const char* path, const char* interface)
+static int __app_dbus_signal_handler_init_with_param(const char* path, const char* interface)
{
DBusError error;
char rule[MAX_LOCAL_BUFSZ];
return -1;
}
- if (dbus_connection_add_filter(bus,
+ if (dbus_connection_add_filter(bus,
__app_dbus_signal_filter, NULL, NULL) == FALSE) {
_E("add filter fail");
return -1;
return 0;
}
-int __app_dbus_signal_handler_fini(void)
+static int __app_dbus_signal_handler_init(void)
{
int ret = 0;
- if (!app_dbus_signal_handler_initialized)
+ if (app_dbus_signal_handler_initialized)
return 0;
- ret = __app_dbus_signal_handler_fini_with_param(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE);
+ ret = __app_dbus_signal_handler_init_with_param(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE);
- app_dbus_signal_handler_initialized = 0;
+ app_dbus_signal_handler_initialized = 1;
return ret;
}
-int __app_dbus_signal_handler_fini_with_param(const char* path, const char* interface)
+static int __app_dbus_signal_handler_fini_with_param(const char* path, const char* interface)
{
DBusError error;
char rule[MAX_LOCAL_BUFSZ];
return 0;
}
+static int __app_dbus_signal_handler_fini(void)
+{
+ int ret = 0;
+
+ if (!app_dbus_signal_handler_initialized)
+ return 0;
+
+ ret = __app_dbus_signal_handler_fini_with_param(AUL_DBUS_PATH, AUL_DBUS_SIGNAL_INTERFACE);
+
+ app_dbus_signal_handler_initialized = 0;
+
+ return ret;
+}
+
SLPAPI int aul_listen_app_dead_signal(int (*func) (int, void *), void *data)
{
if (func) {
_E("error app signal init");
return AUL_R_ERROR;
}
- } else if (_app_launch_handler == NULL) {
+ } else if (_app_launch_handler == NULL && _app_launch_handler2 == NULL) {
if (__app_dbus_signal_handler_fini() < 0) {
_E("error app signal fini");
return AUL_R_ERROR;
_E("error app signal init");
return AUL_R_ERROR;
}
- } else if (_app_dead_handler == NULL) {
+ } else if (_app_launch_handler2 == NULL && _app_dead_handler == NULL) {
if (__app_dbus_signal_handler_fini() < 0) {
_E("error app signal fini");
return AUL_R_ERROR;
return AUL_R_OK;
}
+SLPAPI int aul_listen_app_launch_signal_v2(int (*func) (int, const char *, void *), void *data)
+{
+ if (func) {
+ if (__app_dbus_signal_handler_init() < 0) {
+ _E("error app signal init");
+ return AUL_R_ERROR;
+ }
+ } else if (_app_launch_handler == NULL && _app_dead_handler == NULL) {
+ if (__app_dbus_signal_handler_fini() < 0) {
+ _E("error app signal fini");
+ return AUL_R_ERROR;
+ }
+ }
+
+ _app_launch_handler2 = func;
+ _app_launch_data2 = data;
+
+ return AUL_R_OK;
+}
+
SLPAPI int aul_listen_booting_done_signal(int (*func) (int, void *), void *data)
{
if (func) {
return AUL_R_OK;
}
-#ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
-SLPAPI int aul_listen_lcd_status_signal(int (*func) (const char *, void *), void *data)
-{
- if (func) {
- if (__app_dbus_signal_handler_init_with_param(DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY) < 0) {
- _E("error app signal init");
- return AUL_R_ERROR;
- }
- }
- _lcd_status_handler = func;
- _lcd_status_data = data;
-
- return AUL_R_OK;
-}
-#endif
-
SLPAPI int aul_update_freezer_status(int pid, const char* type)
{
DBusError err;
dbus_error_init(&err);
+ _W("send_update_freezer_status, pid: %d, type: %s", pid, type);
+
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
if (!conn) {
_E("Fail to dbus_bus_get : %s", err.message);
ret = -1;
}
- _D("Send a freezer signal pid: %d, type: %s", pid, type);
-
if (!dbus_connection_send(conn, msg, &serial)) {
_E("Failed to send a D-Bus Message.");
ret = -1;
}
+int __app_status_dbus_init(void)
+{
+ int ret = 0;
+
+ if (conn)
+ return 0;
+
+ dbus_error_init(&err);
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+
+ return ret;
+}
+
+SLPAPI int aul_send_app_launch_request_signal(int pid, const char* appid, const char* pkgid, const char* type)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+
+ int ret = -1;
+
+ __app_status_dbus_init();
+
+ _W("send_app_launch_signal, pid: %d, appid: %s", pid, appid);
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_LAUNCH_REQUEST);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+ return ret;
+}
+
+SLPAPI int aul_send_app_resume_request_signal(int pid, const char* appid, const char* pkgid, const char* type)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+ const char *empty_string = "";
+
+ int ret = -1;
+
+ __app_status_dbus_init();
+
+ _W("send_app_resume_signal, pid: %d, appid: %s", pid, appid);
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_RESUME_REQUEST);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if(appid) {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ } else {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+
+ return ret;
+}
+
+SLPAPI int aul_send_app_terminate_request_signal(int pid, const char* appid, const char* pkgid, const char *type)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+ const char *empty_string = "";
+
+ int ret = -1;
+
+ __app_status_dbus_init();
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_TERMINATE_REQUEST);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if(appid) {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ } else {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+
+ return ret;
+
+}
+
+SLPAPI int aul_send_app_status_change_signal(int pid, const char* appid, const char* pkgid, const char* status, const char *type)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+ const char *empty_string = "";
+
+ int ret = -1;
+
+ _W("send_app_status_change_signal, pid: %d, appid: %s, status: %s", pid, appid, status);
+
+ __app_status_dbus_init();
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_STATUS_CHANGE);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if(appid) {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &pkgid,
+ DBUS_TYPE_STRING, &status,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ } else {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_STRING, &status,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+
+ return ret;
+}
+
+SLPAPI int aul_send_app_terminated_signal(int pid)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+
+ int ret = -1;
+
+ __app_status_dbus_init();
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_TERMINATED);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+ return ret;
+}
+
+SLPAPI int aul_send_app_group_signal(int owner_pid, int child_pid, const char *child_pkgid)
+{
+ DBusMessage* msg = NULL;
+ dbus_uint32_t serial = 0;
+ const char *empty_string = "";
+
+ int ret = -1;
+
+ _W("send_app_group_signal, owner: %d, child: %d", owner_pid, child_pid);
+
+ __app_status_dbus_init();
+
+ msg = dbus_message_new_signal(AUL_APP_STATUS_DBUS_PATH,
+ AUL_APP_STATUS_DBUS_SIGNAL_INTERFACE,
+ AUL_APP_STATUS_DBUS_GROUP);
+ if (!msg) {
+ _E("Could not create DBus Message.");
+ ret = -1;
+ goto end;
+ }
+
+ if (child_pkgid) {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &owner_pid,
+ DBUS_TYPE_INT32, &child_pid,
+ DBUS_TYPE_STRING, &child_pkgid,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ } else {
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &owner_pid,
+ DBUS_TYPE_INT32, &child_pid,
+ DBUS_TYPE_STRING, &empty_string,
+ DBUS_TYPE_INVALID)) {
+ _E("Failed to append a D-Bus Message.");
+ ret = -1;
+ }
+ }
+
+ if (!dbus_connection_send(conn, msg, &serial)) {
+ _E("Failed to send a D-Bus Message.");
+ ret = -1;
+ }
+
+ dbus_connection_flush(conn);
+
+end:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+
+ return ret;
+}