Fix ANR in Settings and Phone app.

When we have a lot of devices paired and try to enable bluetooth,
loadBondState will take a some time. During this all UUIDs would
have been registered and we would send out the Bluetooth On intent.
When Settings apps or phone app gets the Bluetooth On intent, they
try to initialize state. However, the enable Thread in Bluetooth Service
is still initializing internal state in loadBondState leading to
ANRs and deadlocks. So register SDP records as the last step of enable Thread.

Change-Id: Iaa0a773e31b9d269f4c56c4f975a0e2973e02d6e
This commit is contained in:
Jaikumar Ganesh
2011-02-11 18:10:31 -08:00
parent 30b8cbe059
commit 9efb1343a0

View File

@@ -561,21 +561,16 @@ public class BluetoothService extends IBluetooth.Stub {
persistBluetoothOnSetting(true);
}
updateSdpRecords();
mIsDiscovering = false;
mBondState.readAutoPairingData();
mBondState.loadBondState();
initProfileState();
// Log bluetooth on to battery stats.
long ident = Binder.clearCallingIdentity();
try {
mBatteryStats.noteBluetoothOn();
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
// This should be the last step of the the enable thread.
// Because this adds SDP records which asynchronously
// broadcasts the Bluetooth On State in updateBluetoothState.
// So we want all internal state setup before this.
updateSdpRecords();
} else {
setBluetoothState(BluetoothAdapter.STATE_OFF);
}
@@ -623,6 +618,11 @@ public class BluetoothService extends IBluetooth.Stub {
}
}
/**
* This function is called from Bluetooth Event Loop when onPropertyChanged
* for adapter comes in with UUID property.
* @param uuidsThe uuids of adapter as reported by Bluez.
*/
synchronized void updateBluetoothState(String uuids) {
if (mBluetoothState == BluetoothAdapter.STATE_TURNING_ON) {
ParcelUuid[] adapterUuids = convertStringToParcelUuid(uuids);
@@ -633,6 +633,15 @@ public class BluetoothService extends IBluetooth.Stub {
String[] propVal = {"Pairable", getProperty("Pairable")};
mEventLoop.onPropertyChanged(propVal);
// Log bluetooth on to battery stats.
long ident = Binder.clearCallingIdentity();
try {
mBatteryStats.noteBluetoothOn();
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
if (mIsAirplaneSensitive && isAirplaneModeOn() && !mIsAirplaneToggleable) {
disable(false);
}