diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2009-09-01 09:56:56 -0700 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2009-09-01 19:17:02 -0700 |
commit | 176c3d64a793a41f2a59b19f3964bf02b4e79a06 (patch) | |
tree | 6c769864f3c219591f3c39345803e348a9263571 /core/jni/android_server_BluetoothEventLoop.cpp | |
parent | efa1dd716da3372cc74a201d11de5e0ef1a9fe9a (diff) | |
download | frameworks_base-176c3d64a793a41f2a59b19f3964bf02b4e79a06.zip frameworks_base-176c3d64a793a41f2a59b19f3964bf02b4e79a06.tar.gz frameworks_base-176c3d64a793a41f2a59b19f3964bf02b4e79a06.tar.bz2 |
Wait for HCI to come up if getting the adapter path fails.
Diffstat (limited to 'core/jni/android_server_BluetoothEventLoop.cpp')
-rw-r--r-- | core/jni/android_server_BluetoothEventLoop.cpp | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp index 1bfabd7..8fe7487 100644 --- a/core/jni/android_server_BluetoothEventLoop.cpp +++ b/core/jni/android_server_BluetoothEventLoop.cpp @@ -227,37 +227,58 @@ static jboolean setUpEventLoop(native_data_t *nat) { const char * get_adapter_path(DBusConnection *conn) { - DBusMessage *msg, *reply; + DBusMessage *msg, *reply = NULL; DBusError err; const char *device_path = NULL; - msg = dbus_message_new_method_call("org.bluez", "/", - "org.bluez.Manager", "DefaultAdapter"); - if (!msg) { - LOGE("%s: Can't allocate new method call for GetProperties!", - __FUNCTION__); - return NULL; - } - dbus_message_append_args(msg, DBUS_TYPE_INVALID); - - dbus_error_init(&err); - reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); - dbus_message_unref(msg); + int attempt = 0; + + for (attempt = 0; attempt < 1000 && reply == NULL; attempt ++) { + msg = dbus_message_new_method_call("org.bluez", "/", + "org.bluez.Manager", "DefaultAdapter"); + if (!msg) { + LOGE("%s: Can't allocate new method call for get_adapter_path!", + __FUNCTION__); + return NULL; + } + dbus_message_append_args(msg, DBUS_TYPE_INVALID); + dbus_error_init(&err); + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); - if (!reply) { - if (dbus_error_is_set(&err)) { - LOG_AND_FREE_DBUS_ERROR(&err); + if (!reply) { + if (dbus_error_is_set(&err)) { + if (dbus_error_has_name(&err, + "org.freedesktop.DBus.Error.ServiceUnknown")) { + // bluetoothd is still down, retry + LOG_AND_FREE_DBUS_ERROR(&err); + usleep(10000); // 10 ms + continue; + } else { + // Some other error we weren't expecting + LOG_AND_FREE_DBUS_ERROR(&err); + } + } + goto failed; } - return NULL; } + if (attempt == 1000) { + LOGE("Time out while trying to get Adapter path, is bluetoothd up ?"); + goto failed; + } + if (!dbus_message_get_args(reply, &err, DBUS_TYPE_OBJECT_PATH, &device_path, DBUS_TYPE_INVALID) || !device_path){ if (dbus_error_is_set(&err)) { LOG_AND_FREE_DBUS_ERROR(&err); } - return NULL; + goto failed; } + dbus_message_unref(msg); return device_path; + +failed: + dbus_message_unref(msg); + return NULL; } static int register_agent(native_data_t *nat, @@ -274,6 +295,9 @@ static int register_agent(native_data_t *nat, } nat->adapter = get_adapter_path(nat->conn); + if (nat->adapter == NULL) { + return -1; + } msg = dbus_message_new_method_call("org.bluez", nat->adapter, "org.bluez.Adapter", "RegisterAgent"); if (!msg) { |