+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;
+}