From b7e029d03c115ed65cdea9b2bba307e882c308e2 Mon Sep 17 00:00:00 2001 From: Jaikumar Ganesh Date: Tue, 9 Mar 2010 15:31:24 -0800 Subject: [PATCH] Add an API to set the link timeout. This fixes the problem where the car dock is powered on and off pretty quickly. Change-Id: I8724641b8c337019f089b005cb236fc90549cf6f --- .../android/server/BluetoothEventLoop.java | 5 +++++ .../java/android/server/BluetoothService.java | 8 +++++++ core/jni/android_server_BluetoothService.cpp | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index f3638284edefb..c0e4600ae24c8 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -374,6 +374,11 @@ class BluetoothEventLoop { Intent intent = null; if (propValues[1].equals("true")) { intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); + // Set the link timeout to 8000 slots (5 sec timeout) + // for bluetooth docks. + if (mBluetoothService.isBluetoothDock(address)) { + mBluetoothService.setLinkTimeout(address, 8000); + } } else { intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); } diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index e7d9d5b22249b..2c7341699d3bb 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -1910,6 +1910,13 @@ public class BluetoothService extends IBluetooth.Stub { return path; } + /*package */ void setLinkTimeout(String address, int num_slots) { + String path = getObjectPathFromAddress(address); + boolean result = setLinkTimeoutNative(path, num_slots); + + if (!result) log("Set Link Timeout to:" + num_slots + " slots failed"); + } + private static void log(String msg) { Log.d(TAG, msg); } @@ -1953,4 +1960,5 @@ public class BluetoothService extends IBluetooth.Stub { private native int addRfcommServiceRecordNative(String name, long uuidMsb, long uuidLsb, short channel); private native boolean removeServiceRecordNative(int handle); + private native boolean setLinkTimeoutNative(String path, int num_slots); } diff --git a/core/jni/android_server_BluetoothService.cpp b/core/jni/android_server_BluetoothService.cpp index ea64305d145f8..4420acab7c603 100644 --- a/core/jni/android_server_BluetoothService.cpp +++ b/core/jni/android_server_BluetoothService.cpp @@ -861,6 +861,26 @@ static jboolean removeServiceRecordNative(JNIEnv *env, jobject object, jint hand return JNI_FALSE; } +static jboolean setLinkTimeoutNative(JNIEnv *env, jobject object, jstring object_path, + jint num_slots) { + LOGV(__FUNCTION__); +#ifdef HAVE_BLUETOOTH + native_data_t *nat = get_native_data(env, object); + if (nat) { + const char *c_object_path = env->GetStringUTFChars(object_path, NULL); + DBusMessage *reply = dbus_func_args(env, nat->conn, + get_adapter_path(env, object), + DBUS_ADAPTER_IFACE, "SetLinkTimeout", + DBUS_TYPE_OBJECT_PATH, &c_object_path, + DBUS_TYPE_UINT32, &num_slots, + DBUS_TYPE_INVALID); + env->ReleaseStringUTFChars(object_path, c_object_path); + return reply ? JNI_TRUE : JNI_FALSE; + } +#endif + return JNI_FALSE; +} + static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ {"classInitNative", "()V", (void*)classInitNative}, @@ -905,6 +925,7 @@ static JNINativeMethod sMethods[] = { {"discoverServicesNative", "(Ljava/lang/String;Ljava/lang/String;)Z", (void *)discoverServicesNative}, {"addRfcommServiceRecordNative", "(Ljava/lang/String;JJS)I", (void *)addRfcommServiceRecordNative}, {"removeServiceRecordNative", "(I)Z", (void *)removeServiceRecordNative}, + {"setLinkTimeoutNative", "(Ljava/lang/String;I)Z", (void *)setLinkTimeoutNative}, }; int register_android_server_BluetoothService(JNIEnv *env) {