#13795: Initial commit for sflphone-android

includes: libexpat libyaml libdbus-c++ commoncpp ccrtp
          libdbus (from android-4.0.4 sources)

TODO:
- git ignores "/jni/sflphone", sflphone repo should be cloned.
- sflphone-android only needs daemon directory. Ideally it should be possible
to clone it without cloning the whole sflphone project.
into sfl-android (commit 6a0fa7a "#13961: Fix cipher handling" has been used here)
- add pjsip-android project as a git submodule
- sflphone-android needs pjsip android project. Ideally daemon git repository
should not embed pjsip. Instead pjsip should be clone from official repositories.

Considering this, structure should have three distincts git repos:

sflphone-android/.git
sflphone-android/jni/ccrtp-1.8.0-android
sflphone-android/jni/commoncpp2-1.8.1-android
sflphone-android/jni/dbus
sflphone-android/jni/libdbus-c++-0.9.0-android
sflphone-android/jni/libexpat
sflphone-android/jni/libyaml

sflphone-android/jni/sflphone-daemon/.git
sflphone-android/jni/sflphone-daemon/src/audio
sflphone-android/jni/sflphone-daemon/src/config
sflphone-android/jni/sflphone-daemon/src/dbus
sflphone-android/jni/sflphone-daemon/src/history
sflphone-android/jni/sflphone-daemon/src/hooks
sflphone-android/jni/sflphone-daemon/src/iax
sflphone-android/jni/sflphone-daemon/src/sip
sflphone-android/jni/sflphone-daemon/src/video

sflphone-android/jni/pjsip-android/.git

Signed-off-by: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
diff --git a/jni/dbus/test/name-test/.gitignore b/jni/dbus/test/name-test/.gitignore
new file mode 100644
index 0000000..7e4233e
--- /dev/null
+++ b/jni/dbus/test/name-test/.gitignore
@@ -0,0 +1,10 @@
+.deps
+.libs
+Makefile
+Makefile.in
+test-names
+test-pending-call-dispatch
+test-pending-call-timeout
+test-threads-init
+test-ids
+run-with-tmp-session-bus.conf
diff --git a/jni/dbus/test/name-test/Makefile.am b/jni/dbus/test/name-test/Makefile.am
new file mode 100644
index 0000000..11dc56d
--- /dev/null
+++ b/jni/dbus/test/name-test/Makefile.am
@@ -0,0 +1,67 @@
+INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) $(DBUS_TEST_CFLAGS) -DDBUS_COMPILATION
+
+## note that TESTS has special meaning (stuff to use in make check)
+## so if adding tests not to be run in make check, don't add them to 
+## TESTS
+if DBUS_BUILD_TESTS
+TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=@abs_top_builddir@ DBUS_TOP_SRCDIR=@abs_top_srcdir@
+TESTS=run-test.sh run-test-systemserver.sh
+else
+TESTS=
+endif
+
+EXTRA_DIST=run-test.sh run-test-systemserver.sh test-wait-for-echo.py test-activation-forking.py
+
+if DBUS_BUILD_TESTS
+
+## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we
+## build even when not doing "make check"
+noinst_PROGRAMS=test-pending-call-dispatch test-pending-call-timeout test-threads-init test-ids test-shutdown test-privserver test-privserver-client
+
+AM_CPPFLAGS = -DDBUS_STATIC_BUILD
+test_pending_call_dispatch_SOURCES =		\
+	test-pending-call-dispatch.c
+
+test_pending_call_dispatch_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
+test_pending_call_dispatch_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+test_pending_call_timeout_SOURCES =		\
+	test-pending-call-timeout.c
+
+test_pending_call_timeout_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
+test_pending_call_timeout_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+test_threads_init_SOURCES =            \
+	test-threads-init.c
+
+test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
+test_threads_init_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+test_ids_SOURCES =            \
+	test-ids.c
+
+test_ids_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
+test_ids_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+test_shutdown_SOURCES =            \
+	test-shutdown.c
+
+test_shutdown_CFLAGS=
+test_shutdown_LDADD=$(top_builddir)/dbus/libdbus-internal.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
+test_shutdown_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+test_privserver_SOURCES =            \
+	test-privserver.c
+
+test_privserver_CFLAGS=
+test_privserver_LDADD=$(top_builddir)/dbus/libdbus-internal.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
+test_privserver_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+test_privserver_client_SOURCES =            \
+	test-privserver-client.c
+
+test_privserver_client_CFLAGS=
+test_privserver_client_LDADD=$(top_builddir)/dbus/libdbus-internal.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
+test_privserver_client_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+endif
diff --git a/jni/dbus/test/name-test/run-test-systemserver.sh b/jni/dbus/test/name-test/run-test-systemserver.sh
new file mode 100755
index 0000000..d3b8d55
--- /dev/null
+++ b/jni/dbus/test/name-test/run-test-systemserver.sh
@@ -0,0 +1,50 @@
+#! /bin/sh
+die()
+{
+    if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+        echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
+        kill -9 $DBUS_SESSION_BUS_PID
+    fi
+    echo $SCRIPTNAME: $* >&2
+
+    exit 1
+}
+
+SCRIPTNAME=$0
+MODE=$1
+
+## so the tests can complain if you fail to use the script to launch them
+DBUS_TEST_NAME_RUN_TEST_SCRIPT=1
+export DBUS_TEST_NAME_RUN_TEST_SCRIPT
+
+SOURCE_CONFIG_FILE=$DBUS_TOP_SRCDIR/test/name-test/tmp-session-like-system.conf
+export SOURCE_CONFIG_FILE
+# Rerun ourselves with tmp session bus if we're not already
+if test -z "$DBUS_TEST_NAME_IN_SYS_RUN_TEST"; then
+  DBUS_TEST_NAME_IN_SYS_RUN_TEST=1
+  export DBUS_TEST_NAME_IN_SYS_RUN_TEST
+  exec $DBUS_TOP_SRCDIR/tools/run-with-tmp-session-bus.sh $SCRIPTNAME $MODE
+fi 
+
+if test -n "$DBUS_TEST_MONITOR"; then
+  dbus-monitor --session &
+fi
+
+echo "running test-expected-echo-fail"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/tools/dbus-send --print-reply --dest=org.freedesktop.DBus.TestSuiteEchoService /org/freedesktop/TestSuite org.freedesktop.TestSuite.Echo string:hi >echo-error-output.tmp 2>&1
+if ! grep -q 'DBus.Error' echo-error-output.tmp; then
+  echo "Didn't get expected failure; output was:"
+  echo "====="
+  cat echo-error-output.tmp
+  echo "====="
+  exit 1
+fi
+
+echo "running test echo signal"
+if ! python $DBUS_TOP_SRCDIR/test/name-test/test-wait-for-echo.py; then
+  echo "Failed test-wait-for-echo"
+  exit 1
+fi
+
+
+exit 0
diff --git a/jni/dbus/test/name-test/run-test.sh b/jni/dbus/test/name-test/run-test.sh
new file mode 100644
index 0000000..832ce0a
--- /dev/null
+++ b/jni/dbus/test/name-test/run-test.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+
+die()
+{
+    if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+        echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
+        kill -9 $DBUS_SESSION_BUS_PID
+    fi
+    echo $SCRIPTNAME: $* >&2
+
+    exit 1
+}
+
+
+SCRIPTNAME=$0
+MODE=$1
+
+## so the tests can complain if you fail to use the script to launch them
+DBUS_TEST_NAME_RUN_TEST_SCRIPT=1
+export DBUS_TEST_NAME_RUN_TEST_SCRIPT
+
+# Rerun ourselves with tmp session bus if we're not already
+if test -z "$DBUS_TEST_NAME_IN_RUN_TEST"; then
+  DBUS_TEST_NAME_IN_RUN_TEST=1
+  export DBUS_TEST_NAME_IN_RUN_TEST
+  exec $DBUS_TOP_SRCDIR/tools/run-with-tmp-session-bus.sh $SCRIPTNAME $MODE
+fi 
+
+if test -n "$DBUS_TEST_MONITOR"; then
+  dbus-monitor --session &
+fi
+
+echo "running test-ids"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-ids || die "test-ids failed"
+
+echo "running test-pending-call-dispatch"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-pending-call-dispatch || die "test-pending-call-dispatch failed"
+
+echo "running test-pending-call-timeout"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-pending-call-timeout || die "test-pending-call-timeout failed"
+
+echo "running test-threads-init"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-threads-init || die "test-threads-init failed"
+
+echo "running test-privserver-client"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-privserver-client || die "test-privserver-client failed"
+
+echo "running test-shutdown"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-shutdown || die "test-shutdown failed"
+
+echo "running test activation forking"
+if ! python $DBUS_TOP_SRCDIR/test/name-test/test-activation-forking.py; then
+  echo "Failed test-activation-forking"
+  exit 1
+fi
diff --git a/jni/dbus/test/name-test/test-activation-forking.py b/jni/dbus/test/name-test/test-activation-forking.py
new file mode 100644
index 0000000..0d82075
--- /dev/null
+++ b/jni/dbus/test/name-test/test-activation-forking.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+import os,sys
+
+try:
+    import gobject
+    import dbus
+    import dbus.mainloop.glib
+except:
+    print "Failed import, aborting test"
+    sys.exit(0)
+
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+loop = gobject.MainLoop()
+
+exitcode = 0
+
+bus = dbus.SessionBus()
+bus_iface = dbus.Interface(bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus'), 'org.freedesktop.DBus')
+
+o = bus.get_object('org.freedesktop.DBus.TestSuiteForkingEchoService', '/org/freedesktop/TestSuite')
+i = dbus.Interface(o, 'org.freedesktop.TestSuite')
+
+# Start it up
+reply = i.Echo("hello world")
+print "TestSuiteForkingEchoService initial reply OK"
+
+def ignore(*args, **kwargs):
+    pass
+
+# Now monitor for exits, when that happens, start it up again.
+# The goal here is to try to hit any race conditions in activation.
+counter = 0
+def on_forking_echo_owner_changed(name, old, new):
+    global counter
+    global o
+    global i
+    if counter > 10:
+        print "Activated 10 times OK, TestSuiteForkingEchoService pass"
+        loop.quit()
+        return
+    counter += 1
+    if new == '':
+        o = bus.get_object('org.freedesktop.DBus.TestSuiteForkingEchoService', '/org/freedesktop/TestSuite')
+        i = dbus.Interface(o, 'org.freedesktop.TestSuite')
+        i.Echo("counter %r" % counter)
+        i.Exit(reply_handler=ignore, error_handler=ignore)
+
+bus_iface.connect_to_signal('NameOwnerChanged', on_forking_echo_owner_changed, arg0='org.freedesktop.DBus.TestSuiteForkingEchoService')
+
+i.Exit(reply_handler=ignore, error_handler=ignore)
+
+def check_counter():
+    if counter == 0:
+        print "Failed to get NameOwnerChanged for TestSuiteForkingEchoService"
+        sys.exit(1)
+gobject.timeout_add(15000, check_counter)
+
+loop.run()
+sys.exit(0)
diff --git a/jni/dbus/test/name-test/test-ids.c b/jni/dbus/test/name-test/test-ids.c
new file mode 100644
index 0000000..8f63d04
--- /dev/null
+++ b/jni/dbus/test/name-test/test-ids.c
@@ -0,0 +1,56 @@
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-connection-internal.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+static void
+die (const char *message)
+{
+  fprintf (stderr, "*** test-ids: %s", message);
+  exit (1);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  DBusError error;
+  DBusConnection *connection;
+  char *id;
+  char *server_id;
+  
+  dbus_error_init (&error);
+  connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
+  if (connection == NULL)
+    {
+      fprintf (stderr, "*** Failed to open connection to system bus: %s\n",
+               error.message);
+      dbus_error_free (&error);
+      return 1;
+    }
+
+  server_id = dbus_connection_get_server_id (connection);
+  if (server_id == NULL)
+    die ("No bus server ID retrieved\n");
+  /* printf("'%s'\n", server_id); */
+  if (strlen (server_id) != 32)
+    die ("Bus server id should have length 32\n");
+  dbus_free (server_id);
+
+  id = dbus_bus_get_id (connection, NULL);
+  if (id == NULL)
+    die ("No bus ID retrieved\n");
+  /* printf("'%s'\n", id); */
+  if (strlen (id) != 32)
+    die ("Bus ID should have length 32\n");
+  dbus_free (id);  
+  
+  _dbus_verbose ("*** Test IDs exiting\n");
+  
+  return 0;
+}
diff --git a/jni/dbus/test/name-test/test-pending-call-dispatch.c b/jni/dbus/test/name-test/test-pending-call-dispatch.c
new file mode 100644
index 0000000..57582d4
--- /dev/null
+++ b/jni/dbus/test/name-test/test-pending-call-dispatch.c
@@ -0,0 +1,124 @@
+/**
+* Test to make sure we don't get stuck polling a dbus connection
+* which has no data on the socket.  This was an issue where
+* one pending call would read all the data off the bus
+* and the second pending call would not check to see
+* if its data had already been read before polling the connection
+* and blocking.
+**/
+
+#include <config.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-sysdeps.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static void
+_run_iteration (DBusConnection *conn)
+{
+  DBusPendingCall *echo_pending;
+  DBusPendingCall *dbus_pending;
+  DBusMessage *method;
+  DBusMessage *reply;
+  char *echo = "echo";
+
+  /* send the first message */
+  method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
+                                         "/org/freedesktop/TestSuite",
+                                         "org.freedesktop.TestSuite",
+                                         "Echo");
+
+  dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
+  dbus_connection_send_with_reply (conn, method, &echo_pending, -1);
+  dbus_message_unref (method);
+  
+  /* send the second message */
+  method = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                         DBUS_PATH_DBUS,
+                                         "org.freedesktop.Introspectable",
+                                         "Introspect");
+
+  dbus_connection_send_with_reply (conn, method, &dbus_pending, -1);
+  dbus_message_unref (method);
+
+  /* block on the second message (should return immediately) */
+  dbus_pending_call_block (dbus_pending);
+
+  /* block on the first message */
+  /* if it does not return immediately chances 
+     are we hit the block in poll bug */
+  dbus_pending_call_block (echo_pending);
+
+  /* check the reply only to make sure we
+     are not getting errors unrelated
+     to the block in poll bug */
+  reply = dbus_pending_call_steal_reply (echo_pending);
+
+  if (reply == NULL)
+    {
+      printf ("Failed: Reply is NULL ***\n");
+      exit (1);
+    }
+
+  if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
+    {
+      printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
+      exit (1);
+    } 
+
+  dbus_message_unref (reply);
+  dbus_pending_call_unref (dbus_pending);
+  dbus_pending_call_unref (echo_pending);
+  
+}
+
+int
+main (int argc, char *argv[])
+{
+  long start_tv_sec, start_tv_usec;
+  long end_tv_sec, end_tv_usec;
+  int i;
+  DBusMessage *method;
+  DBusConnection *conn;
+  DBusError error;
+
+  /* Time each iteration and make sure it doesn't take more than 5 seconds
+     to complete.  Outside influences may cause connections to take longer
+     but if it does and we are stuck in a poll call then we know the 
+     stuck in poll bug has come back to haunt us */
+
+  printf ("*** Testing stuck in poll\n");
+
+  dbus_error_init (&error);
+
+  conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
+
+  /* run 100 times to make sure */
+  for (i = 0; i < 100; i++)
+    {
+      long delta;
+      
+      _dbus_get_current_time (&start_tv_sec, &start_tv_usec);
+      _run_iteration (conn);
+      _dbus_get_current_time (&end_tv_sec, &end_tv_usec);
+
+      /* we just care about seconds */
+      delta = end_tv_sec - start_tv_sec;
+      printf ("Iter %i: %lis\n", i, delta);
+      if (delta >= 5)
+        {
+	  printf ("Failed: looks like we might have been be stuck in poll ***\n");
+	  exit (1);
+	}
+    }
+ 
+  method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
+                                         "/org/freedesktop/TestSuite",
+                                         "org.freedesktop.TestSuite",
+                                         "Exit");
+  dbus_connection_send (conn, method, NULL);
+  dbus_message_unref (method);
+
+  printf ("Success ***\n");
+  exit (0);
+}
diff --git a/jni/dbus/test/name-test/test-pending-call-timeout.c b/jni/dbus/test/name-test/test-pending-call-timeout.c
new file mode 100644
index 0000000..381113b
--- /dev/null
+++ b/jni/dbus/test/name-test/test-pending-call-timeout.c
@@ -0,0 +1,103 @@
+/**
+* Test to make sure that pending calls succeed when given a default,
+* specific and infinite timeout.
+**/
+
+#include <config.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-sysdeps.h>
+#include <stdio.h>
+#include <limits.h>
+#include <stdlib.h>
+
+static void
+_method_call (DBusConnection *conn,
+	      int             timeout_milliseconds)
+{
+  DBusPendingCall *pending;
+  DBusMessage *method;
+  DBusMessage *reply;
+  char *echo = "echo";
+
+  /* send the message */
+  method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
+                                         "/org/freedesktop/TestSuite",
+                                         "org.freedesktop.TestSuite",
+                                         "DelayEcho");
+
+  dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
+  dbus_connection_send_with_reply (conn, method, &pending, timeout_milliseconds);
+  dbus_message_unref (method);
+  
+  /* block on the message */
+  dbus_pending_call_block (pending);
+
+  /* check the reply only to make sure we
+     are not getting errors unrelated
+     to the block in poll bug */
+  reply = dbus_pending_call_steal_reply (pending);
+
+  if (reply == NULL)
+    {
+      printf ("Failed: Reply is NULL ***\n");
+      exit (1);
+    }
+
+  if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
+    {
+      printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
+      exit (1);
+    } 
+
+  dbus_message_unref (reply);
+  dbus_pending_call_unref (pending);
+}
+
+static void
+_run_iteration (DBusConnection *conn)
+{
+  _method_call (conn, -1);
+  _method_call (conn, 10000);
+  _method_call (conn, INT_MAX);
+}
+
+int
+main (int argc, char *argv[])
+{
+  long start_tv_sec, start_tv_usec;
+  long end_tv_sec, end_tv_usec;
+  int i;
+  DBusMessage *method;
+  DBusConnection *conn;
+  DBusError error;
+
+  printf ("*** Testing pending call timeouts\n");
+
+  dbus_error_init (&error);
+
+  conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
+
+  /* run 100 times to make sure */
+  for (i = 0; i < 100; i++)
+    {
+      long delta;
+      
+      _dbus_get_current_time (&start_tv_sec, &start_tv_usec);
+      _run_iteration (conn);
+      _dbus_get_current_time (&end_tv_sec, &end_tv_usec);
+
+      /* we just care about seconds */
+      delta = end_tv_sec - start_tv_sec;
+      printf ("Iter %i: %lis\n", i, delta);
+    }
+ 
+  method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
+                                         "/org/freedesktop/TestSuite",
+                                         "org.freedesktop.TestSuite",
+                                         "Exit");
+  dbus_connection_send (conn, method, NULL);
+  dbus_message_unref (method);
+
+  printf ("Success ***\n");
+  exit (0);
+}
diff --git a/jni/dbus/test/name-test/test-privserver-client.c b/jni/dbus/test/name-test/test-privserver-client.c
new file mode 100644
index 0000000..d02eea8
--- /dev/null
+++ b/jni/dbus/test/name-test/test-privserver-client.c
@@ -0,0 +1,117 @@
+#include <config.h>
+#include "../test-utils.h"
+
+static void
+die (const char *message, ...)
+{
+  va_list args;
+  va_start (args, message);
+  vfprintf (stderr, message, args);
+  va_end (args);
+  exit (1);
+}
+
+static DBusHandlerResult 
+filter_private_message (DBusConnection     *connection,
+                        DBusMessage        *message,
+                        void               *user_data)
+{
+  if (dbus_message_is_signal (message,
+                              DBUS_INTERFACE_LOCAL,
+                              "Disconnected"))
+    {
+       DBusLoop *loop = user_data;      
+       _dbus_loop_quit (loop);
+       return DBUS_HANDLER_RESULT_HANDLED;
+    }
+  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void
+open_shutdown_private_connection (dbus_bool_t use_guid)
+{
+  DBusError error;
+  DBusLoop *loop;
+  DBusConnection *session;
+  DBusMessage *msg;
+  DBusMessage *reply;
+  DBusConnection *privconn;
+  char *addr;
+  char *comma;
+
+  dbus_error_init (&error);
+
+  loop = _dbus_loop_new ();
+
+  session = dbus_bus_get (DBUS_BUS_SESSION, &error);
+  if (!session)
+    die ("couldn't access session bus\n");
+  dbus_connection_set_exit_on_disconnect (session, FALSE);
+  msg = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuite.PrivServer",
+                                      "/",
+                                      "org.freedesktop.DBus.TestSuite.PrivServer",
+                                      "GetPrivateAddress");
+  if (!(reply = dbus_connection_send_with_reply_and_block (session, msg, -1, &error)))
+    die ("couldn't send message: %s\n", error.message);
+  dbus_message_unref (msg);
+  if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID))
+    die ("couldn't parse message replym\n");
+  printf ("got private temp address %s\n", addr);
+  addr = strdup (addr);
+  if (!use_guid)
+    {
+      char *comma = strrchr (addr, ',');
+      if (comma)
+        *comma = '\0';
+    }
+  privconn = dbus_connection_open (addr, &error);
+  free (addr);
+  if (!privconn)
+    die ("couldn't connect to server direct connection: %s\n", error.message);
+  dbus_message_unref (reply);
+
+  dbus_connection_set_exit_on_disconnect (privconn, FALSE);
+  dbus_connection_add_filter (privconn, filter_private_message, loop, NULL);
+  test_connection_setup (loop, privconn);
+
+  msg = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuite.PrivServer",
+                                      "/",
+                                      "org.freedesktop.DBus.TestSuite.PrivServer",
+                                      "Quit");
+  if (!dbus_connection_send (session, msg, NULL))
+    die ("couldn't send Quit message\n");
+  dbus_message_unref (msg);
+
+  _dbus_loop_run (loop);  
+
+  test_connection_shutdown (loop, session);
+  dbus_connection_unref (session);
+
+  test_connection_shutdown (loop, privconn);
+  dbus_connection_remove_filter (privconn, filter_private_message, loop);
+  dbus_connection_unref (privconn);
+
+  _dbus_loop_unref (loop);
+}
+
+int
+main (int argc, char *argv[])
+{
+  open_shutdown_private_connection (TRUE);
+
+  dbus_shutdown ();
+
+  open_shutdown_private_connection (TRUE);
+
+  dbus_shutdown ();
+
+  open_shutdown_private_connection (FALSE);
+
+  dbus_shutdown ();
+
+  open_shutdown_private_connection (FALSE);
+
+  dbus_shutdown ();
+
+  return 0;
+}
diff --git a/jni/dbus/test/name-test/test-privserver.c b/jni/dbus/test/name-test/test-privserver.c
new file mode 100644
index 0000000..39a98b7
--- /dev/null
+++ b/jni/dbus/test/name-test/test-privserver.c
@@ -0,0 +1,123 @@
+#include <config.h>
+#include "../test-utils.h"
+
+static void
+die (const char *message, ...)
+{
+  va_list args;
+  va_start (args, message);
+  vfprintf (stderr, message, args);
+  va_end (args);
+  exit (1);
+}
+
+typedef struct TestServiceData TestServiceData;
+
+struct TestServiceData
+{
+  DBusLoop *loop;
+  char *private_addr;
+};
+
+static void
+new_connection_callback (DBusServer     *server,
+                         DBusConnection *new_connection,
+                         void           *data)
+{
+  TestServiceData *testdata = data;
+
+  if (!test_connection_setup (testdata->loop, new_connection))
+    dbus_connection_close (new_connection);
+}
+
+static DBusHandlerResult 
+filter_session_message (DBusConnection     *connection,
+                        DBusMessage        *message,
+                        void               *user_data)
+{
+  TestServiceData *testdata = user_data;
+
+  if (dbus_message_is_method_call (message,
+                                   "org.freedesktop.DBus.TestSuite.PrivServer",
+                                   "GetPrivateAddress"))
+    {
+       DBusMessage *reply;
+       reply = dbus_message_new_method_return (message);
+       dbus_message_append_args (reply, DBUS_TYPE_STRING, 
+                                 &(testdata->private_addr), DBUS_TYPE_INVALID);
+       dbus_connection_send (connection, reply, NULL);
+       dbus_message_unref (reply);
+       return DBUS_HANDLER_RESULT_HANDLED;
+    }
+  else if (dbus_message_is_method_call (message,
+                                   "org.freedesktop.DBus.TestSuite.PrivServer",
+                                   "Quit"))
+    {
+      fprintf (stderr, "server exiting loop\n");
+      _dbus_loop_quit (testdata->loop);
+      return DBUS_HANDLER_RESULT_HANDLED;
+    }
+  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+int
+main (int argc, char *argv[])
+{
+  DBusServer *server;
+  DBusError error;
+  DBusLoop *loop;
+  DBusConnection *session;
+  TestServiceData *testdata;
+
+  dbus_error_init (&error);
+
+  loop = _dbus_loop_new ();
+
+  testdata = dbus_new (TestServiceData, 1);
+  testdata->loop = loop;
+
+  session = dbus_bus_get (DBUS_BUS_SESSION, &error);
+  if (!session)
+    die ("couldn't access session bus");
+
+  test_connection_setup (loop, session);
+
+  dbus_bus_request_name (session, "org.freedesktop.DBus.TestSuite.PrivServer", 0, &error);
+  if (dbus_error_is_set (&error))
+    die ("couldn't request name: %s", error.message);
+
+  if (!dbus_connection_add_filter (session, filter_session_message, testdata, NULL))
+    die ("couldn't add filter");
+
+#ifdef DBUS_CMAKE
+  server = dbus_server_listen (TEST_LISTEN, &error);
+#else
+  server = dbus_server_listen ("unix:tmpdir=/tmp", &error);
+#endif
+  if (!server)
+    die (error.message);
+  testdata->private_addr = dbus_server_get_address (server);
+  printf ("test server listening on %s\n", testdata->private_addr);
+
+  dbus_server_set_new_connection_function (server, new_connection_callback,
+                                           testdata, NULL);
+
+  if (!test_server_setup (loop, server))
+    die ("server setup failed");
+
+  fprintf (stderr, "server running mainloop\n");
+  _dbus_loop_run (loop);
+  fprintf (stderr, "server mainloop quit\n");
+
+  test_server_shutdown (loop, server);
+
+  test_connection_shutdown (loop, session);
+
+  dbus_connection_unref (session);
+
+  _dbus_loop_unref (loop);
+
+  dbus_free (testdata);
+
+  return 0;
+}
diff --git a/jni/dbus/test/name-test/test-shutdown.c b/jni/dbus/test/name-test/test-shutdown.c
new file mode 100644
index 0000000..526c1cb
--- /dev/null
+++ b/jni/dbus/test/name-test/test-shutdown.c
@@ -0,0 +1,68 @@
+
+#include <config.h>
+#include "../test-utils.h"
+
+static DBusLoop *loop;
+
+static void
+die (const char *message)
+{
+  fprintf (stderr, "*** test-shutdown: %s", message);
+  exit (1);
+}
+
+static void
+open_destroy_shared_session_bus_connection (void)
+{
+  DBusError error;
+  DBusConnection *connection;
+  char *session_addr_no_guid;
+  char *comma;
+  
+  dbus_error_init (&error);
+
+  session_addr_no_guid = strdup (getenv ("DBUS_SESSION_BUS_ADDRESS"));
+  comma = strchr (session_addr_no_guid, ',');
+  if (comma == NULL)
+    die ("Couldn't find GUID in session bus address");
+  *comma = '\0';
+    
+  connection = dbus_connection_open (session_addr_no_guid, &error);
+  free (session_addr_no_guid);
+  if (connection == NULL)
+    die ("Failed to open connection to temp session bus\n");
+
+  loop = _dbus_loop_new ();
+  if (loop == NULL)
+    die ("No memory\n");
+  
+  if (!test_connection_setup (loop, connection))
+    die ("No memory\n");
+
+  test_connection_shutdown (loop, connection);
+ 
+  _dbus_loop_unref (loop);
+
+  dbus_connection_unref (connection); 
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  open_destroy_shared_session_bus_connection ();
+
+  dbus_shutdown ();
+
+  open_destroy_shared_session_bus_connection ();
+
+  dbus_shutdown ();
+
+  open_destroy_shared_session_bus_connection ();
+
+  dbus_shutdown ();
+
+  _dbus_verbose ("*** Test shutdown exiting\n");
+  
+  return 0;
+}
diff --git a/jni/dbus/test/name-test/test-threads-init.c b/jni/dbus/test/name-test/test-threads-init.c
new file mode 100644
index 0000000..5e22852
--- /dev/null
+++ b/jni/dbus/test/name-test/test-threads-init.c
@@ -0,0 +1,180 @@
+/**
+ * Test to make sure late thread initialization works
+ */
+
+#include <config.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-sysdeps.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <dbus/dbus-internals.h>
+#include <dbus/dbus-connection-internal.h>
+
+static void
+_run_iteration (DBusConnection *conn)
+{
+  DBusPendingCall *echo_pending;
+  DBusPendingCall *dbus_pending;
+  DBusMessage *method;
+  DBusMessage *reply;
+  char *echo = "echo";
+
+  /* send the first message */
+  method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
+                                         "/org/freedesktop/TestSuite",
+                                         "org.freedesktop.TestSuite",
+                                         "Echo");
+
+  dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
+  dbus_connection_send_with_reply (conn, method, &echo_pending, -1);
+  dbus_message_unref (method);
+  
+  /* send the second message */
+  method = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+                                         DBUS_PATH_DBUS,
+                                         "org.freedesktop.Introspectable",
+                                         "Introspect");
+
+  dbus_connection_send_with_reply (conn, method, &dbus_pending, -1);
+  dbus_message_unref (method);
+
+  /* block on the second message (should return immediately) */
+  dbus_pending_call_block (dbus_pending);
+
+  /* block on the first message */
+  /* if it does not return immediately chances 
+     are we hit the block in poll bug */
+  dbus_pending_call_block (echo_pending);
+
+  /* check the reply only to make sure we
+     are not getting errors unrelated
+     to the block in poll bug */
+  reply = dbus_pending_call_steal_reply (echo_pending);
+
+  if (reply == NULL)
+    {
+      printf ("Failed: Reply is NULL ***\n");
+      exit (1);
+    }
+
+  if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
+    {
+      printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
+      exit (1);
+    } 
+
+  dbus_message_unref (reply);
+  dbus_pending_call_unref (dbus_pending);
+  dbus_pending_call_unref (echo_pending);
+  
+}
+static void
+check_mutex_lock (DBusMutex *mutex1, 
+                  DBusMutex *mutex2, 
+                  dbus_bool_t is_same)
+{
+  _dbus_assert (mutex1 != NULL);
+  _dbus_assert (mutex2 != NULL);
+  
+  if (is_same)
+    {
+      _dbus_assert (mutex1 == mutex2);
+    }
+  else
+    {
+      _dbus_assert (mutex1 != mutex2);
+    }
+}
+
+static void
+check_condvar_lock (DBusCondVar *condvar1,  
+                    DBusCondVar *condvar2,   
+                    dbus_bool_t is_same)
+{
+  _dbus_assert (condvar1 != NULL);
+  _dbus_assert (condvar2 != NULL);
+
+  if (is_same)
+    {
+      _dbus_assert (condvar1 == condvar2);
+    }
+  else
+    {
+      _dbus_assert (condvar1 != condvar2);
+    }
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  DBusMessage *method;
+  DBusConnection *conn;
+  DBusError error;
+  DBusMutex *mutex1, *dispatch_mutex1, *io_path_mutex1;
+  DBusCondVar *dispatch_cond1, *io_path_cond1;
+  DBusMutex *mutex2, *dispatch_mutex2, *io_path_mutex2;
+  DBusCondVar *dispatch_cond2, *io_path_cond2;
+
+  printf ("*** Testing late thread init\n");
+
+  dbus_error_init (&error);
+
+  conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
+
+  _dbus_connection_test_get_locks (conn, &mutex1, 
+                                         &dispatch_mutex1, 
+                                         &io_path_mutex1,
+                                         &dispatch_cond1,
+                                         &io_path_cond1);
+  _run_iteration (conn);
+  _dbus_connection_test_get_locks (conn, &mutex2,
+                                         &dispatch_mutex2,
+                                         &io_path_mutex2,
+                                         &dispatch_cond2,
+                                         &io_path_cond2);
+
+  check_mutex_lock (mutex1, mutex2, TRUE);
+  check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE);
+  check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE);
+  check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE);
+  check_condvar_lock (io_path_cond1, io_path_cond2, TRUE);
+
+  dbus_threads_init_default ();
+
+  _dbus_connection_test_get_locks (conn, &mutex1,
+                                         &dispatch_mutex1,
+                                         &io_path_mutex1,
+                                         &dispatch_cond1,
+                                         &io_path_cond1);
+
+  check_mutex_lock (mutex1, mutex2, FALSE);
+  check_mutex_lock (dispatch_mutex1, dispatch_mutex2, FALSE);
+  check_mutex_lock (io_path_mutex1, io_path_mutex2, FALSE);
+  check_condvar_lock (dispatch_cond1, dispatch_cond2, FALSE);
+  check_condvar_lock (io_path_cond1, io_path_cond2, FALSE);
+
+  _run_iteration (conn);
+  _dbus_connection_test_get_locks (conn, &mutex2,
+                                         &dispatch_mutex2,
+                                         &io_path_mutex2,
+                                         &dispatch_cond2,
+                                         &io_path_cond2);
+
+  check_mutex_lock (mutex1, mutex2, TRUE);
+  check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE);
+  check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE);
+  check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE);
+  check_condvar_lock (io_path_cond1, io_path_cond2, TRUE);
+
+  method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
+                                         "/org/freedesktop/TestSuite",
+                                         "org.freedesktop.TestSuite",
+                                         "Exit");
+  dbus_connection_send (conn, method, NULL);
+  dbus_message_unref (method);
+
+  printf ("Success ***\n");
+  exit (0);
+}
diff --git a/jni/dbus/test/name-test/test-wait-for-echo.py b/jni/dbus/test/name-test/test-wait-for-echo.py
new file mode 100755
index 0000000..bd09e45
--- /dev/null
+++ b/jni/dbus/test/name-test/test-wait-for-echo.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+import os,sys
+
+try:
+    import gobject
+    import dbus
+    import dbus.mainloop.glib
+except:
+    print "Failed import, aborting test"
+    sys.exit(0)
+
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+loop = gobject.MainLoop()
+
+exitcode = 0
+
+def handle_noreceipt():
+    print "Failed to get signal"
+    global exitcode
+    exitcode = 1
+    loop.quit()
+
+gobject.timeout_add(7000, handle_noreceipt)
+
+bus = dbus.SessionBus()
+
+def sighandler(*args, **kwargs):
+    print "got signal"
+    loop.quit()   
+
+bus.add_signal_receiver(sighandler, dbus_interface='org.freedesktop.TestSuite', signal_name='Foo')
+
+o = bus.get_object('org.freedesktop.DBus.TestSuiteEchoService', '/org/freedesktop/TestSuite')
+i = dbus.Interface(o, 'org.freedesktop.TestSuite')
+def nullhandler(*args, **kwargs):
+    pass
+i.EmitFoo(reply_handler=nullhandler, error_handler=nullhandler)
+
+loop.run()
+sys.exit(exitcode)
diff --git a/jni/dbus/test/name-test/tmp-session-like-system.conf b/jni/dbus/test/name-test/tmp-session-like-system.conf
new file mode 100644
index 0000000..29ab115
--- /dev/null
+++ b/jni/dbus/test/name-test/tmp-session-like-system.conf
@@ -0,0 +1,91 @@
+<!-- This configuration file controls the per-user-login-session message bus.
+     Add a session-local.conf and edit that rather than changing this 
+     file directly. -->
+
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+  <!-- Our well-known bus type, don't change this -->
+  <type>session</type>
+
+  <!-- If we fork, keep the user's original umask to avoid affecting
+       the behavior of child processes. -->
+  <keep_umask/>
+
+  <syslog/>
+
+  <listen>unix:tmpdir=/tmp</listen>
+
+  <standard_session_servicedirs />
+
+  <!-- intended to match system bus -->
+  <policy context="default">
+    <!-- All users can connect to system bus -->
+    <allow user="*"/>
+
+    <!-- Holes must be punched in service configuration files for
+         name ownership and sending method calls -->
+    <deny own="*"/>
+    <deny send_type="method_call"/>
+
+    <!-- Signals and reply messages (method returns, errors) are allowed
+         by default -->
+    <allow send_type="signal"/>
+    <allow send_requested_reply="true" send_type="method_return"/>
+    <allow send_requested_reply="true" send_type="error"/>
+
+    <!-- All messages may be received by default -->
+    <allow receive_type="method_call"/>
+    <allow receive_type="method_return"/>
+    <allow receive_type="error"/>
+    <allow receive_type="signal"/>
+
+    <!-- Allow anyone to talk to the message bus -->
+    <allow send_destination="org.freedesktop.DBus"/>
+    <!-- But disallow some specific bus services -->
+    <deny send_destination="org.freedesktop.DBus"
+          send_interface="org.freedesktop.DBus"
+          send_member="UpdateActivationEnvironment"/>
+
+    <!-- Specific to the test suite -->
+    <allow own="org.freedesktop.DBus.TestSuiteEchoService"/>
+    <allow send_destination="org.freedesktop.DBus.TestSuiteEchoService"
+           send_interface="org.freedesktop.DBus.Introspectable"/>
+    <allow send_destination="org.freedesktop.DBus.TestSuiteEchoService"
+           send_interface="org.freedesktop.TestSuite"
+           send_member="EmitFoo"/>
+  </policy>
+
+  <policy context="default">
+     <allow own="org.freedesktop.DBus.TestSuiteEchoService"/>
+     <allow send_destination="org.freedesktop.DBus.TestSuiteEchoService"
+            send_interface="org.freedesktop.DBus.Introspectable"/>
+     <allow send_destination="org.freedesktop.DBus.TestSuiteEchoService"
+            send_interface="org.freedesktop.TestSuite"
+            send_member="EmitFoo"/>
+  </policy>
+
+  <!-- For the session bus, override the default relatively-low limits 
+       with essentially infinite limits, since the bus is just running 
+       as the user anyway, using up bus resources is not something we need 
+       to worry about. In some cases, we do set the limits lower than 
+       "all available memory" if exceeding the limit is almost certainly a bug, 
+       having the bus enforce a limit is nicer than a huge memory leak. But the 
+       intent is that these limits should never be hit. -->
+
+  <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max -->
+  <limit name="max_incoming_bytes">1000000000</limit>
+  <limit name="max_outgoing_bytes">1000000000</limit>
+  <limit name="max_message_size">1000000000</limit>
+  <limit name="service_start_timeout">120000</limit>  
+  <limit name="auth_timeout">240000</limit>
+  <limit name="max_completed_connections">100000</limit>  
+  <limit name="max_incomplete_connections">10000</limit>
+  <limit name="max_connections_per_user">100000</limit>
+  <limit name="max_pending_service_starts">10000</limit>
+  <limit name="max_names_per_connection">50000</limit>
+  <limit name="max_match_rules_per_connection">50000</limit>
+  <limit name="max_replies_per_connection">50000</limit>
+  <limit name="reply_timeout">300000</limit>
+
+</busconfig>