summaryrefslogtreecommitdiffstats
path: root/core/java/android/server/BluetoothService.java
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2009-10-12 09:54:39 -0700
committerNick Pelly <npelly@google.com>2009-10-12 10:26:25 -0700
commitbc1fc05c1b3e8c407fa07b25777bf577d5285f49 (patch)
tree1304f6cac5975236e0920624c6658bfd40e205b9 /core/java/android/server/BluetoothService.java
parent6dc3f4e553d333b9f115a222a9a684bb2aa55b5e (diff)
downloadframeworks_base-bc1fc05c1b3e8c407fa07b25777bf577d5285f49.zip
frameworks_base-bc1fc05c1b3e8c407fa07b25777bf577d5285f49.tar.gz
frameworks_base-bc1fc05c1b3e8c407fa07b25777bf577d5285f49.tar.bz2
Delay 500ms between each registering each SDP record using sdptool.
This is to workaround an issue where SDP records will fail to register using sdptool. When we run SystemService.start() it forks sdptool, so if we do this four times in a row these forked processes can run in parallel, and one or more of them fails. There is probably some thready safety issue in sdptool or Bluez that makes it unsafe to run sdptool in parallel. As a workaround, delay 500ms between each run of sdptool to register SDP records when starting Bluetooth. Before this fix it was easy to reproduce problems with service record registration. If you turn BT off/on multiple times you can see that sometimes one or more service records are missing. Repro rate is about 20% in my tests. Result is that remote devices cannot connect to the missing service. After this fix I am unable to reproduce any missing SDP records, after 30+ cycles of BT on/off. Motorola BT team also ran stress tests overnight with this fix and were unable to reproduce the missing SDP records. This is a low risk fix. It does delay some records from being registered by an additional 1.5 seconds (on top of the 3 second delay we already had), so if you try and very quickly connect a BT service after turning BT on it won't work the first time. Do not merge. (I will use a less hacky fix for MR2/Master) Change-Id: I305c181c3194e8ce25e3825320cc2e1ef6d3d3cc Bug: 2180800 DrNo: eastham Joke: Why can't you play cards in the jungle? Because there's too many cheetas!
Diffstat (limited to 'core/java/android/server/BluetoothService.java')
-rw-r--r--core/java/android/server/BluetoothService.java36
1 files changed, 32 insertions, 4 deletions
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index 5c8c7cc..67b30a9 100644
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -208,6 +208,7 @@ public class BluetoothService extends IBluetooth.Stub {
return false;
}
setBluetoothState(BluetoothAdapter.STATE_TURNING_OFF);
+ mHandler.removeMessages(MESSAGE_REGISTER_SDP_RECORDS);
// Allow 3 seconds for profiles to gracefully disconnect
// TODO: Introduce a callback mechanism so that each profile can notify
@@ -327,12 +328,39 @@ public class BluetoothService extends IBluetooth.Stub {
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_REGISTER_SDP_RECORDS:
- //TODO: Don't assume HSP/HFP is running, don't use sdptool,
- if (isEnabled()) {
+ if (!isEnabled()) {
+ return;
+ }
+ // SystemService.start() forks sdptool to register service
+ // records. It can fail to register some records if it is
+ // forked multiple times in a row, probably because there is
+ // some race in sdptool or bluez when operated in parallel.
+ // As a workaround, delay 500ms between each fork of sdptool.
+ // TODO: Don't fork sdptool in order to regsiter service
+ // records, use a DBUS call instead.
+ switch (msg.arg1) {
+ case 1:
+ Log.d(TAG, "Registering hsag record");
SystemService.start("hsag");
+ mHandler.sendMessageDelayed(
+ mHandler.obtainMessage(MESSAGE_REGISTER_SDP_RECORDS, 2, -1), 500);
+ break;
+ case 2:
+ Log.d(TAG, "Registering hfag record");
SystemService.start("hfag");
+ mHandler.sendMessageDelayed(
+ mHandler.obtainMessage(MESSAGE_REGISTER_SDP_RECORDS, 3, -1), 500);
+ break;
+ case 3:
+ Log.d(TAG, "Registering opush record");
SystemService.start("opush");
+ mHandler.sendMessageDelayed(
+ mHandler.obtainMessage(MESSAGE_REGISTER_SDP_RECORDS, 4, -1), 500);
+ break;
+ case 4:
+ Log.d(TAG, "Registering pbap record");
SystemService.start("pbap");
+ break;
}
break;
case MESSAGE_FINISH_DISABLE:
@@ -402,8 +430,8 @@ public class BluetoothService extends IBluetooth.Stub {
}
mIsDiscovering = false;
mBondState.loadBondState();
- mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_REGISTER_SDP_RECORDS),
- 3000);
+ mHandler.sendMessageDelayed(
+ mHandler.obtainMessage(MESSAGE_REGISTER_SDP_RECORDS, 1, -1), 3000);
// Log bluetooth on to battery stats.
long ident = Binder.clearCallingIdentity();