/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
- *
- * at-spi-bus-launcher: Manage the a11y bus as a child process
*
- * Copyright 2011 Red Hat, Inc.
+ * at-spi-bus-launcher: Manage the a11y bus as a child process
+ *
+ * Copyright 2011-2018 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include <unistd.h>
#include <string.h>
#include <signal.h>
+#ifdef __linux__
+#include <sys/prctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#endif
#include <sys/wait.h>
#include <errno.h>
#include <stdio.h>
#include <X11/Xatom.h>
#endif
+//TODO: move to vconf/vconf-internal-setting-keys.h?
+#define VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE "db/setting/accessibility/universal-switch/configuration-service"
+#define VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE "db/setting/accessibility/universal-switch/interaction-service"
+
+#define MAX_NUMBER_OF_KEYS_PER_CLIENT 2
+
+#define APP_CONTROL_OPERATION_SCREEN_READ "http://tizen.org/appcontrol/operation/read_screen"
+#define APP_CONTROL_OPERATION_UNIVERSAL_SWITCH "http://tizen.org/appcontrol/operation/universal_switch"
+#include <appsvc.h>
+#include <vconf.h>
+
+//uncomment if you want debug
+//#ifndef TIZEN_ENGINEER_MODE
+//#define TIZEN_ENGINEER_MODE
+//#endif
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "ATSPI_BUS_LAUNCHER"
+
+#include <dlog.h>
+#include <aul.h>
+
+//uncomment this if you want log suring startup
+//seems like dlog is not working at startup time
+#define ATSPI_BUS_LAUNCHER_LOG_TO_FILE
+
+#ifdef ATSPI_BUS_LAUNCHER_LOG_TO_FILE
+FILE *log_file;
+#ifdef LOGD
+#undef LOGD
+#endif
+#define LOGD(arg...) do {if (log_file) {fprintf(log_file, ##arg);fprintf(log_file, "\n"); fflush(log_file);}} while(0)
+#endif
+
+static gboolean _launch_process_repeat_until_success(gpointer user_data);
+
typedef enum {
A11Y_BUS_STATE_IDLE = 0,
A11Y_BUS_STATE_READING_ADDRESS,
} A11yBusState;
typedef struct {
+ const char * name;
+ const char * app_control_operation;
+ const char * vconf_key[MAX_NUMBER_OF_KEYS_PER_CLIENT];
+ int number_of_keys;
+ int launch_repeats;
+ int pid;
+} A11yBusClient;
+
+typedef struct {
GMainLoop *loop;
gboolean launch_immediately;
gboolean a11y_enabled;
gboolean screen_reader_enabled;
+ GHashTable *client_watcher_id;
GDBusConnection *session_bus;
GSettings *a11y_schema;
GSettings *interface_schema;
+ int name_owner_id;
+
+ A11yBusClient screen_reader;
+ A11yBusClient universal_switch;
GDBusProxy *client_proxy;
A11yBusState state;
+
/* -1 == error, 0 == pending, > 0 == running */
int a11y_bus_pid;
char *a11y_bus_address;
+#ifdef HAVE_X11
+ gboolean x11_prop_set;
+#endif
int pipefd[2];
+ int listenfd;
char *a11y_launch_error_message;
} A11yBusLauncher;
-#define SM_DBUS_NAME "org.gnome.SessionManager"
-#define SM_DBUS_PATH "/org/gnome/SessionManager"
-#define SM_DBUS_INTERFACE "org.gnome.SessionManager"
-
-#define SM_CLIENT_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
static A11yBusLauncher *_global_app = NULL;
static const gchar introspection_xml[] =
G_CALLBACK (g_signal_cb), app);
}
-static GDBusProxy *sm_proxy;
-
static void
register_client (A11yBusLauncher *app)
{
GDBusProxyFlags flags;
+ GDBusProxy *sm_proxy;
GError *error;
const gchar *app_id;
const gchar *autostart_id;
GVariant *parameters;
GVariant *variant;
gchar *object_path;
- static gboolean session_registered = FALSE;
- if (session_registered)
- return;
+ flags = G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS;
error = NULL;
+ sm_proxy = g_dbus_proxy_new_sync (app->session_bus, flags, NULL,
+ "org.gnome.SessionManager",
+ "/org/gnome/SessionManager",
+ "org.gnome.SessionManager",
+ NULL, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Failed to get session manager proxy: %s", error->message);
+ g_error_free (error);
+
+ return;
+ }
app_id = "at-spi-bus-launcher";
autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
NULL, client_proxy_ready_cb, app);
g_free (object_path);
-
- session_registered = TRUE;
}
static void
-on_session_signal (GDBusProxy *proxy,
- gchar *sender_name,
- gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
+name_appeared_handler (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
{
A11yBusLauncher *app = user_data;
- if (g_strcmp0 (signal_name, "SessionOver") == 0) {
- g_main_loop_quit (app->loop);
- } else if (g_strcmp0 (signal_name, "SessionRunning") == 0) {
- register_client (app);
- }
-}
-
-static void
-is_session_running_ready_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- GDBusProxy *proxy;
- A11yBusLauncher *app = user_data;
- GVariant *values;
- GError *error = NULL;
- gboolean is_running;
-
- proxy = G_DBUS_PROXY (source_object);
- values = g_dbus_proxy_call_finish (proxy, res, &error);
- if (values) {
- g_variant_get (values, "(b)", &is_running);
- g_variant_unref (values);
- }
- if (is_running) {
- register_client (app);
- }
- }
-
-static gboolean
-session_manager_connect (A11yBusLauncher *app)
-{
- GVariant *res;
- GError *error = NULL;
-
- sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, 0, NULL,
- SM_DBUS_NAME,
- SM_DBUS_PATH,
- SM_DBUS_INTERFACE, NULL, &error);
-
- if (error != NULL)
- {
- g_warning ("Failed to get session manager proxy: %s", error->message);
- g_error_free (error);
-
- return;
- }
-
- g_dbus_proxy_call (sm_proxy,
- "IsSessionRunning", NULL,
- 0, 1000, NULL, is_session_running_ready_cb, app);
-
- g_signal_connect (G_OBJECT (sm_proxy), "g-signal",
- G_CALLBACK (on_session_signal), app);
-
- return (sm_proxy != NULL);
-}
-
-static void
-setup_bus_child (gpointer data)
-{
- A11yBusLauncher *app = data;
- (void) app;
-
- close (app->pipefd[0]);
- dup2 (app->pipefd[1], 3);
- close (app->pipefd[1]);
-
- /* On Linux, tell the bus process to exit if this process goes away */
-#ifdef __linux
-#include <sys/prctl.h>
- prctl (PR_SET_PDEATHSIG, 15);
-#endif
+ register_client (app);
}
/**
{
ssize_t bytes_read;
- while (max_bytes > 1 && (bytes_read = read (fd, buf, MAX (4096, max_bytes - 1))))
+ while (max_bytes > 1 && (bytes_read = read (fd, buf, MIN (4096, max_bytes - 1))))
{
if (bytes_read < 0)
return FALSE;
gpointer data)
{
A11yBusLauncher *app = data;
-
+
app->a11y_bus_pid = -1;
app->state = A11Y_BUS_STATE_ERROR;
if (app->a11y_launch_error_message == NULL)
app->a11y_launch_error_message = g_strdup_printf ("Bus stopped by signal %d", WSTOPSIG (status));
}
g_main_loop_quit (app->loop);
-}
+}
+
+#ifdef DBUS_DAEMON
+static void
+setup_bus_child_daemon (gpointer data)
+{
+ A11yBusLauncher *app = data;
+ (void) app;
+
+ close (app->pipefd[0]);
+ dup2 (app->pipefd[1], 3);
+ close (app->pipefd[1]);
+
+ /* On Linux, tell the bus process to exit if this process goes away */
+#ifdef __linux__
+ prctl (PR_SET_PDEATHSIG, 15);
+#endif
+}
static gboolean
-ensure_a11y_bus (A11yBusLauncher *app)
+ensure_a11y_bus_daemon (A11yBusLauncher *app, char *config_path)
{
+ char *argv[] = { DBUS_DAEMON, config_path, "--nofork", "--print-address", "3", NULL };
GPid pid;
- char *argv[] = { DBUS_DAEMON, NULL, "--nofork", "--print-address", "3", NULL };
char addr_buf[2048];
GError *error = NULL;
- const char *config_path = NULL;
if (app->a11y_bus_pid != 0)
return FALSE;
- if (g_file_test (SYSCONFDIR"/at-spi2/accessibility.conf", G_FILE_TEST_EXISTS))
- config_path = "--config-file="SYSCONFDIR"/at-spi2/accessibility.conf";
- else
- config_path = "--config-file="DATADIR"/defaults/at-spi2/accessibility.conf";
-
- argv[1] = config_path;
+ argv[1] = (char*)config_path;
if (pipe (app->pipefd) < 0)
- g_error ("Failed to create pipe: %s", strerror (errno));
-
+ {
+ char buf[4096] = { 0 };
+ strerror_r (errno, buf, sizeof(buf));
+ g_error ("Failed to create pipe: %s", buf);
+ }
+
+ g_clear_pointer (&app->a11y_launch_error_message, g_free);
+
if (!g_spawn_async (NULL,
argv,
NULL,
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
- setup_bus_child,
+ setup_bus_child_daemon,
app,
&pid,
&error))
app->state = A11Y_BUS_STATE_READING_ADDRESS;
app->a11y_bus_pid = pid;
- g_debug ("Launched a11y bus, child is %ld", (long) pid);
+ LOGD("Launched a11y bus, child is %ld", (long) pid);
if (!unix_read_all_fd_to_string (app->pipefd[0], addr_buf, sizeof (addr_buf)))
{
- app->a11y_launch_error_message = g_strdup_printf ("Failed to read address: %s", strerror (errno));
+ char buf[4096] = { 0 };
+ strerror_r (errno, buf, sizeof(buf));
+ app->a11y_launch_error_message = g_strdup_printf ("Failed to read address: %s", buf);
kill (app->a11y_bus_pid, SIGTERM);
+ app->a11y_bus_pid = -1;
goto error;
}
close (app->pipefd[0]);
app->state = A11Y_BUS_STATE_RUNNING;
/* Trim the trailing newline */
+ if (app->a11y_bus_address) g_free(app->a11y_bus_address);
app->a11y_bus_address = g_strchomp (g_strdup (addr_buf));
- g_debug ("a11y bus address: %s", app->a11y_bus_address);
+ LOGD("a11y bus address: %s", app->a11y_bus_address);
-#ifdef HAVE_X11
- {
- Display *display = XOpenDisplay (NULL);
- if (display)
- {
- Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
- XChangeProperty (display,
- XDefaultRootWindow (display),
- bus_address_atom,
- XA_STRING, 8, PropModeReplace,
- (guchar *) app->a11y_bus_address, strlen (app->a11y_bus_address));
- XFlush (display);
- XCloseDisplay (display);
- }
- }
+ return TRUE;
+
+error:
+ if (app->pipefd[0] > 0) close (app->pipefd[0]);
+ if (app->pipefd[1] > 0) close (app->pipefd[1]);
+ app->state = A11Y_BUS_STATE_ERROR;
+
+ return FALSE;
+}
+#else
+static gboolean
+ensure_a11y_bus_daemon (A11yBusLauncher *app, char *config_path)
+{
+ return FALSE;
+}
#endif
+#ifdef DBUS_BROKER
+static void
+setup_bus_child_broker (gpointer data)
+{
+ A11yBusLauncher *app = data;
+ gchar *pid_str;
+ (void) app;
+
+ dup2 (app->listenfd, 3);
+ close (app->listenfd);
+ g_setenv("LISTEN_FDS", "1", TRUE);
+
+ pid_str = g_strdup_printf("%u", getpid());
+ g_setenv("LISTEN_PID", pid_str, TRUE);
+ g_free(pid_str);
+
+ /* Tell the bus process to exit if this process goes away */
+ prctl (PR_SET_PDEATHSIG, SIGTERM);
+}
+
+static gboolean
+ensure_a11y_bus_broker (A11yBusLauncher *app, char *config_path)
+{
+ char *argv[] = { DBUS_BROKER, config_path, "--scope", "user", NULL };
+ struct sockaddr_un addr = { .sun_family = AF_UNIX };
+ socklen_t addr_len = sizeof(addr);
+ GPid pid;
+ GError *error = NULL;
+
+ if ((app->listenfd = socket (PF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) < 0)
+ {
+ char buf[4096] = { 0 };
+ strerror_r (errno, buf, sizeof(buf));
+ g_error ("Failed to create listening socket: %s", buf);
+ }
+
+ if (bind (app->listenfd, (struct sockaddr *)&addr, sizeof(sa_family_t)) < 0)
+ {
+ char buf[4096] = { 0 };
+ strerror_r (errno, buf, sizeof(buf));
+ g_error ("Failed to bind listening socket: %s", buf);
+ }
+
+ if (getsockname (app->listenfd, (struct sockaddr *)&addr, &addr_len) < 0)
+ {
+ char buf[4096] = { 0 };
+ strerror_r (errno, buf, sizeof(buf));
+ g_error ("Failed to get socket name for listening socket: %s", buf);
+ }
+
+ if (listen (app->listenfd, 1024) < 0)
+ {
+ char buf[4096] = { 0 };
+ strerror_r (errno, buf, sizeof(buf));
+ g_error ("Failed to listen on socket: %s", buf);
+ }
+
+ g_clear_pointer (&app->a11y_launch_error_message, g_free);
+
+ if (!g_spawn_async (NULL,
+ argv,
+ NULL,
+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+ setup_bus_child_broker,
+ app,
+ &pid,
+ &error))
+ {
+ app->a11y_bus_pid = -1;
+ app->a11y_launch_error_message = g_strdup (error->message);
+ g_clear_error (&error);
+ goto error;
+ }
+
+ close (app->listenfd);
+ app->listenfd = -1;
+
+ g_child_watch_add (pid, on_bus_exited, app);
+ app->a11y_bus_pid = pid;
+ g_debug ("Launched a11y bus, child is %ld", (long) pid);
+ app->state = A11Y_BUS_STATE_RUNNING;
+
+ app->a11y_bus_address = g_strconcat("unix:abstract=", addr.sun_path + 1, NULL);
+ g_debug ("a11y bus address: %s", app->a11y_bus_address);
+
return TRUE;
-
- error:
- close (app->pipefd[0]);
- close (app->pipefd[1]);
+
+error:
+ close (app->listenfd);
app->state = A11Y_BUS_STATE_ERROR;
return FALSE;
}
+#else
+static gboolean
+ensure_a11y_bus_broker (A11yBusLauncher *app, char *config_path)
+{
+ return FALSE;
+}
+#endif
+
+static gboolean
+ensure_a11y_bus (A11yBusLauncher *app)
+{
+ char *config_path = NULL;
+ gboolean success = FALSE;
+
+ if (app->a11y_bus_pid != 0)
+ return FALSE;
+
+ if (g_file_test (SYSCONFDIR"/at-spi2/accessibility.conf", G_FILE_TEST_EXISTS))
+ config_path = "--config-file="SYSCONFDIR"/at-spi2/accessibility.conf";
+ else
+ config_path = "--config-file="DATADIR"/defaults/at-spi2/accessibility.conf";
+
+#ifdef WANT_DBUS_BROKER
+ success = ensure_a11y_bus_broker (app, config_path);
+ if (!success)
+ {
+ if (!ensure_a11y_bus_daemon (app, config_path))
+ return FALSE;
+ }
+#else
+ success = ensure_a11y_bus_daemon (app, config_path);
+ if (!success)
+ {
+ if (!ensure_a11y_bus_broker (app, config_path))
+ return FALSE;
+ }
+#endif
+
+#ifdef HAVE_X11
+ if (g_getenv ("DISPLAY") != NULL && g_getenv ("WAYLAND_DISPLAY") == NULL)
+ {
+ Display *display = XOpenDisplay (NULL);
+ if (display)
+ {
+ Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
+ XChangeProperty (display,
+ XDefaultRootWindow (display),
+ bus_address_atom,
+ XA_STRING, 8, PropModeReplace,
+ (guchar *) app->a11y_bus_address, strlen (app->a11y_bus_address));
+ XFlush (display);
+ XCloseDisplay (display);
+ app->x11_prop_set = TRUE;
+ }
+ }
+#endif
+
+ return TRUE;
+}
static void
handle_method_call (GDBusConnection *connection,
&builder,
&invalidated_builder),
NULL);
+
+ g_variant_builder_clear (&builder);
+ g_variant_builder_clear (&invalidated_builder);
}
static void
if (enabled == app->screen_reader_enabled)
return;
- /* If the screen reader is being enabled, we should enable accessibility
- * if it isn't enabled already */
- if (enabled)
- handle_a11y_enabled_change (app, enabled, notify_gsettings);
-
app->screen_reader_enabled = enabled;
if (notify_gsettings && app->a11y_schema)
&builder,
&invalidated_builder),
NULL);
+ g_variant_builder_clear (&builder);
+ g_variant_builder_clear (&invalidated_builder);
+}
+
+static gboolean
+is_client_connected(A11yBusLauncher *app)
+{
+ guint watchers = g_hash_table_size(app->client_watcher_id);
+ LOGD("clients connected: %d", watchers);
+ return watchers > 0;
+}
+
+static void
+remove_client_watch(A11yBusLauncher *app,
+ const gchar *sender)
+{
+ LOGD("Remove client watcher for %s", sender);
+ guint watcher_id = GPOINTER_TO_UINT(g_hash_table_lookup(app->client_watcher_id, sender));
+ if (watcher_id)
+ g_bus_unwatch_name(watcher_id);
+
+ g_hash_table_remove(app->client_watcher_id, sender);
+ if (!is_client_connected(app))
+ handle_a11y_enabled_change (app, FALSE, TRUE);
+}
+
+static void
+on_client_name_vanished (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ A11yBusLauncher *app = user_data;
+ remove_client_watch(app, name);
+}
+
+static void
+add_client_watch(A11yBusLauncher *app,
+ const gchar *sender)
+{
+ LOGD("Add client watcher for %s", sender);
+
+ if (g_hash_table_contains(app->client_watcher_id, sender))
+ {
+ LOGI("Watcher for %s already registered", sender);
+ return;
+ }
+
+ guint watcher_id = g_bus_watch_name(G_BUS_TYPE_SESSION,
+ sender,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ NULL,
+ on_client_name_vanished,
+ app,
+ NULL);
+
+ g_hash_table_insert(app->client_watcher_id, g_strdup(sender), GUINT_TO_POINTER(watcher_id));
+ handle_a11y_enabled_change (app, TRUE, TRUE);
}
static gboolean
A11yBusLauncher *app = user_data;
const gchar *type = g_variant_get_type_string (value);
gboolean enabled;
-
+
if (g_strcmp0 (type, "b") != 0)
{
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
if (g_strcmp0 (property_name, "IsEnabled") == 0)
{
- handle_a11y_enabled_change (app, enabled, TRUE);
+ if (enabled)
+ add_client_watch(app, sender);
+ else
+ remove_client_watch(app, sender);
return TRUE;
}
else if (g_strcmp0 (property_name, "ScreenReaderEnabled") == 0)
A11yBusLauncher *app = user_data;
GError *error;
guint registration_id;
-
+
if (connection == NULL)
{
g_main_loop_quit (app->loop);
}
app->session_bus = connection;
- if (app->launch_immediately)
- {
- ensure_a11y_bus (app);
- if (app->state == A11Y_BUS_STATE_ERROR)
- {
- g_main_loop_quit (app->loop);
- return;
- }
- }
-
error = NULL;
registration_id = g_dbus_connection_register_object (connection,
"/org/a11y/bus",
{
A11yBusLauncher *app = user_data;
- session_manager_connect (app);
+ if (app->launch_immediately)
+ {
+ ensure_a11y_bus (app);
+ if (app->state == A11Y_BUS_STATE_ERROR)
+ {
+ g_main_loop_quit (app->loop);
+ return;
+ }
+ }
+
+ g_bus_watch_name (G_BUS_TYPE_SESSION,
+ "org.gnome.SessionManager",
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ name_appeared_handler, NULL,
+ user_data, NULL);
}
static int sigterm_pipefd[2];
gpointer data)
{
A11yBusLauncher *app = data;
-
+
g_main_loop_quit (app->loop);
return FALSE;
GIOChannel *sigterm_channel;
if (pipe (sigterm_pipefd) < 0)
- g_error ("Failed to create pipe: %s", strerror (errno));
+ {
+ char buf[4096] = { 0 };
+ strerror_r (errno, buf, sizeof(buf));
+ g_error ("Failed to create pipe: %s", buf);
+ }
signal (SIGTERM, sigterm_handler);
sigterm_channel = g_io_channel_unix_new (sigterm_pipefd[0]);
app);
}
-static gboolean
-already_running ()
-{
-#ifdef HAVE_X11
- Atom AT_SPI_BUS;
- Atom actual_type;
- Display *bridge_display;
- int actual_format;
- unsigned char *data = NULL;
- unsigned long nitems;
- unsigned long leftover;
- gboolean result = FALSE;
-
- bridge_display = XOpenDisplay (NULL);
- if (!bridge_display)
- return FALSE;
-
- AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False);
- XGetWindowProperty (bridge_display,
- XDefaultRootWindow (bridge_display),
- AT_SPI_BUS, 0L,
- (long) BUFSIZ, False,
- (Atom) 31, &actual_type, &actual_format,
- &nitems, &leftover, &data);
-
- if (data)
- {
- GDBusConnection *bus;
- bus = g_dbus_connection_new_for_address_sync ((const gchar *)data, 0,
- NULL, NULL, NULL);
- if (bus != NULL)
- {
- result = TRUE;
- g_object_unref (bus);
- }
- }
-
- XCloseDisplay (bridge_display);
- return result;
-#else
- return FALSE;
-#endif
-}
-
static GSettings *
get_schema (const gchar *name)
{
+#if GLIB_CHECK_VERSION (2, 32, 0)
+ GSettingsSchemaSource *source = g_settings_schema_source_get_default ();
+ if (!source) return NULL;
+
+ GSettingsSchema *schema = g_settings_schema_source_lookup (source, name, FALSE);
+
+ if (schema == NULL)
+ return NULL;
+
+ return g_settings_new_full (schema, NULL, NULL);
+#else
const char * const *schemas = NULL;
gint i;
}
return NULL;
+#endif
}
static void
gsettings_key_changed (GSettings *gsettings, const gchar *key, void *user_data)
{
gboolean new_val = g_settings_get_boolean (gsettings, key);
- A11yBusLauncher *app = user_data;
if (!strcmp (key, "toolkit-accessibility"))
handle_a11y_enabled_change (_global_app, new_val, FALSE);
handle_screen_reader_enabled_change (_global_app, new_val, FALSE);
}
+static int
+_process_dead_tracker (int pid, void *data)
+{
+ A11yBusLauncher *app = data;
+
+ if (app->screen_reader.pid > 0 && pid == app->screen_reader.pid)
+ {
+ LOGE("screen reader is dead, pid: %d, restarting", pid);
+ app->screen_reader.pid = 0;
+ g_timeout_add_seconds (2, _launch_process_repeat_until_success, &app->screen_reader);
+ }
+
+ if (app->universal_switch.pid > 0 && pid == app->universal_switch.pid)
+ {
+ LOGE("universal switch is dead, pid: %d, restarting", pid);
+ app->universal_switch.pid = 0;
+ g_timeout_add_seconds (2, _launch_process_repeat_until_success, &app->universal_switch);
+ }
+ return 0;
+}
+
+static void
+_register_process_dead_tracker ()
+{
+ if(_global_app->screen_reader.pid > 0 || _global_app->universal_switch.pid > 0) {
+ LOGD("registering process dead tracker");
+ aul_listen_app_dead_signal(_process_dead_tracker, _global_app);
+ } else {
+ LOGD("unregistering process dead tracker");
+ aul_listen_app_dead_signal(NULL, NULL);
+ }
+}
+
+
+static gboolean
+_launch_client(A11yBusClient *client, gboolean by_vconf_change)
+{
+ LOGD("Launching %s", client->name);
+
+ bundle *kb = NULL;
+ gboolean ret = FALSE;
+
+ kb = bundle_create();
+
+ if (kb == NULL)
+ {
+ LOGD("Can't create bundle");
+ return FALSE;
+ }
+
+ if (by_vconf_change)
+ {
+ if (bundle_add_str(kb, "by_vconf_change", "yes") != BUNDLE_ERROR_NONE)
+ {
+ LOGD("Can't add information to bundle");
+ }
+ }
+
+ int operation_error = appsvc_set_operation(kb, client->app_control_operation);
+ LOGD("appsvc_set_operation: %i", operation_error);
+
+ client->pid = appsvc_run_service(kb, 0, NULL, NULL);
+
+ if (client->pid > 0)
+ {
+ LOGD("Process launched with pid: %i", client->pid);
+ _register_process_dead_tracker();
+ ret = TRUE;
+ }
+ else
+ {
+ LOGD("Can't start %s - error code: %i", client->name, client->pid);
+ }
+
+ bundle_free(kb);
+ return ret;
+}
+
+static gboolean
+_launch_process_repeat_until_success(gpointer user_data) {
+ A11yBusClient *client = user_data;
+
+ if (client->launch_repeats > 100 || client->pid > 0)
+ {
+ //do not try anymore
+ return FALSE;
+ }
+
+ gboolean ret = _launch_client(client, FALSE);
+
+ if (ret)
+ {
+ //we managed to
+ client->launch_repeats = 0;
+ return FALSE;
+ }
+ client->launch_repeats++;
+ //try again
+ return TRUE;
+}
+
+static gboolean
+_terminate_process(int pid)
+{
+ int ret;
+ int ret_aul;
+ if (pid <= 0)
+ return FALSE;
+
+ int status = aul_app_get_status_bypid(pid);
+
+ if (status < 0)
+ {
+ LOGD("App with pid %d already terminated", pid);
+ return TRUE;
+ }
+
+ LOGD("terminate process with pid %d", pid);
+ ret_aul = aul_terminate_pid(pid);
+ if (ret_aul >= 0)
+ {
+ LOGD("Terminating with aul_terminate_pid: return is %d", ret_aul);
+ return TRUE;
+ }
+ else
+ LOGD("aul_terminate_pid failed: return is %d", ret_aul);
+
+ LOGD("Unable to terminate process using aul api. Sending SIGTERM signal");
+ ret = kill(pid, SIGTERM);
+ if (!ret)
+ {
+ return TRUE;
+ }
+
+ LOGD("Unable to terminate process: %d with api or signal.", pid);
+ return FALSE;
+}
+
+static gboolean
+_terminate_client(A11yBusClient *client)
+{
+ LOGD("Terminating %s", client->name);
+ int pid = client->pid;
+ client->pid = 0;
+ _register_process_dead_tracker();
+ gboolean ret = _terminate_process(pid);
+ return ret;
+}
+
+void vconf_client_cb(keynode_t *node, void *user_data)
+{
+ A11yBusClient *client = user_data;
+
+ gboolean client_needed = FALSE;
+ int i;
+ for (i = 0; i < client->number_of_keys; i++) {
+ int status = 0;
+ int ret =vconf_get_bool(client->vconf_key[i], &status);
+ if (ret != 0)
+ {
+ LOGD("Could not read %s key value.\n", client->vconf_key[i]);
+ return;
+ }
+ LOGD("vconf_keynode_get_bool(node): %i", status);
+ if (status < 0)
+ return;
+
+ if (status == 1) {
+ client_needed = TRUE;
+ break;
+ }
+ }
+
+ //check if process really exists (e.g didn't crash)
+ if (client->pid > 0)
+ {
+ int err = kill(client->pid,0);
+ //process doesn't exist
+ if (err == ESRCH)
+ client->pid = 0;
+ }
+
+ LOGD("client_needed: %i, client->pid: %i", client_needed, client->pid);
+ if (!client_needed && (client->pid > 0))
+ _terminate_client(client);
+ else if (client_needed && (client->pid <= 0))
+ _launch_client(client, TRUE);
+}
+
+
+static gboolean register_executable(A11yBusClient *client)
+{
+ gboolean client_needed = FALSE;
+
+ int i;
+ for (i = 0; i < client->number_of_keys; i++) {
+ if (!client->vconf_key[i]) {
+ LOGE("Vconf_key missing for client: %d \n", i);
+ return FALSE;
+ }
+
+ int status = 0;
+ int ret = vconf_get_bool(client->vconf_key[i], &status);
+ if (ret != 0)
+ {
+ LOGD("Could not read %s key value.\n", client->vconf_key[i]);
+ return FALSE;
+ }
+ ret = vconf_notify_key_changed(client->vconf_key[i], vconf_client_cb, client);
+ if (ret != 0)
+ {
+ LOGD("Could not add information level callback\n");
+ return FALSE;
+ }
+ if (status)
+ client_needed = TRUE;
+ }
+
+ if (client_needed)
+ g_timeout_add_seconds(2,_launch_process_repeat_until_success, client);
+ return TRUE;
+}
+
int
main (int argc,
char **argv)
{
- GError *error = NULL;
- GMainLoop *loop;
- GDBusConnection *session_bus;
- int name_owner_id;
+#ifdef ATSPI_BUS_LAUNCHER_LOG_TO_FILE
+ log_file = fopen("/tmp/at-spi-bus-launcher.log", "a");
+#endif
+
+ LOGD("Starting atspi bus launcher");
+
gboolean a11y_set = FALSE;
gboolean screen_reader_set = FALSE;
gint i;
- if (already_running ())
- return 0;
-
_global_app = g_slice_new0 (A11yBusLauncher);
_global_app->loop = g_main_loop_new (NULL, FALSE);
+ _global_app->client_watcher_id = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+ _global_app->screen_reader.name = "screen-reader";
+ _global_app->screen_reader.app_control_operation = APP_CONTROL_OPERATION_SCREEN_READ;
+ _global_app->screen_reader.vconf_key[0] = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS;
+ _global_app->screen_reader.number_of_keys = 1;
+
+ _global_app->universal_switch.name = "universal-switch";
+ _global_app->universal_switch.app_control_operation = APP_CONTROL_OPERATION_UNIVERSAL_SWITCH;
+ _global_app->universal_switch.vconf_key[0] = VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE;
+ _global_app->universal_switch.vconf_key[1] = VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE;
+ _global_app->universal_switch.number_of_keys = 2;
for (i = 1; i < argc; i++)
{
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
g_assert (introspection_data != NULL);
- name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ g_bus_own_name (G_BUS_TYPE_SESSION,
"org.a11y.Bus",
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
on_bus_acquired,
_global_app,
NULL);
+ register_executable (&_global_app->screen_reader);
+ register_executable (&_global_app->universal_switch);
+
g_main_loop_run (_global_app->loop);
if (_global_app->a11y_bus_pid > 0)
kill (_global_app->a11y_bus_pid, SIGTERM);
- /* Clear the X property if our bus is gone; in the case where e.g.
+ /* Clear the X property if our bus is gone; in the case where e.g.
* GDM is launching a login on an X server it was using before,
* we don't want early login processes to pick up the stale address.
*/
#ifdef HAVE_X11
- {
- Display *display = XOpenDisplay (NULL);
- if (display)
- {
- Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
- XDeleteProperty (display,
- XDefaultRootWindow (display),
- bus_address_atom);
+ if (_global_app->x11_prop_set)
+ {
+ Display *display = XOpenDisplay (NULL);
+ if (display)
+ {
+ Atom bus_address_atom = XInternAtom (display, "AT_SPI_BUS", False);
+ XDeleteProperty (display,
+ XDefaultRootWindow (display),
+ bus_address_atom);
- XFlush (display);
- XCloseDisplay (display);
- }
- }
+ XFlush (display);
+ XCloseDisplay (display);
+ }
+ }
#endif
if (_global_app->a11y_launch_error_message)