summaryrefslogtreecommitdiffstats
path: root/core/java/android/server
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/server')
-rw-r--r--core/java/android/server/BluetoothA2dpService.java25
-rw-r--r--core/java/android/server/BluetoothAdapterStateMachine.java32
-rw-r--r--core/java/android/server/BluetoothBondState.java1
-rw-r--r--core/java/android/server/BluetoothEventLoop.java2
-rwxr-xr-xcore/java/android/server/BluetoothService.java37
5 files changed, 39 insertions, 58 deletions
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index fd277d0..f498bb2 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -187,24 +187,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
return false;
}
- private synchronized boolean addAudioSink(BluetoothDevice device) {
- String path = mBluetoothService.getObjectPathFromAddress(device.getAddress());
- String propValues[] = (String []) getSinkPropertiesNative(path);
- if (propValues == null) {
- Log.e(TAG, "Error while getting AudioSink properties for device: " + device);
- return false;
- }
- Integer state = null;
- // Properties are name-value pairs
- for (int i = 0; i < propValues.length; i+=2) {
- if (propValues[i].equals(PROPERTY_STATE)) {
- state = new Integer(convertBluezSinkStringToState(propValues[i+1]));
- break;
- }
+ private synchronized void addAudioSink(BluetoothDevice device) {
+ if (mAudioDevices.get(device) == null) {
+ mAudioDevices.put(device, BluetoothA2dp.STATE_DISCONNECTED);
}
- mAudioDevices.put(device, state);
- handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTED, state);
- return true;
}
private synchronized void onBluetoothEnable() {
@@ -259,9 +245,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
return false;
}
- if (mAudioDevices.get(device) == null && !addAudioSink(device)) {
- return false;
- }
+ addAudioSink(device);
String path = mBluetoothService.getObjectPathFromAddress(device.getAddress());
if (path == null) {
@@ -495,6 +479,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
// This is for an incoming connection for a device not known to us.
// We have authorized it and bluez state has changed.
addAudioSink(device);
+ handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTED, state);
} else {
if (state == BluetoothA2dp.STATE_PLAYING && mPlayingA2dpDevice == null) {
mPlayingA2dpDevice = device;
diff --git a/core/java/android/server/BluetoothAdapterStateMachine.java b/core/java/android/server/BluetoothAdapterStateMachine.java
index 83f5a9f..cb18ade 100644
--- a/core/java/android/server/BluetoothAdapterStateMachine.java
+++ b/core/java/android/server/BluetoothAdapterStateMachine.java
@@ -156,7 +156,7 @@ final class BluetoothAdapterStateMachine extends StateMachine {
private class PowerOff extends State {
@Override
public void enter() {
- if (DBG) log("Enter PowerOff: ");
+ if (DBG) log("Enter PowerOff: " + getCurrentMessage().what);
}
@Override
public boolean processMessage(Message message) {
@@ -280,7 +280,7 @@ final class BluetoothAdapterStateMachine extends StateMachine {
@Override
public void enter() {
- if (DBG) log("Enter WarmUp");
+ if (DBG) log("Enter WarmUp: " + getCurrentMessage().what);
}
@Override
@@ -319,7 +319,7 @@ final class BluetoothAdapterStateMachine extends StateMachine {
private class HotOff extends State {
@Override
public void enter() {
- if (DBG) log("Enter HotOff:");
+ if (DBG) log("Enter HotOff: " + getCurrentMessage().what);
}
@Override
@@ -380,8 +380,7 @@ final class BluetoothAdapterStateMachine extends StateMachine {
@Override
public void enter() {
- int what = getCurrentMessage().what;
- if (DBG) log("Enter Switching: " + what);
+ if (DBG) log("Enter Switching: " + getCurrentMessage().what);
}
@Override
public boolean processMessage(Message message) {
@@ -390,13 +389,12 @@ final class BluetoothAdapterStateMachine extends StateMachine {
boolean retValue = HANDLED;
switch(message.what) {
case BECAME_PAIRABLE:
- String[] propVal = {"Pairable", mBluetoothService.getProperty("Pairable")};
- mEventLoop.onPropertyChanged(propVal);
-
- // run bluetooth now that it's turned on
- mBluetoothService.runBluetooth();
+ mBluetoothService.initBluetoothAfterTurningOn();
transitionTo(mBluetoothOn);
broadcastState(BluetoothAdapter.STATE_ON);
+ // run bluetooth now that it's turned on
+ // Note runBluetooth should be called only in adapter STATE_ON
+ mBluetoothService.runBluetooth();
break;
case BECAME_NON_PAIRABLE:
if (mBluetoothService.getAdapterConnectionState() ==
@@ -438,11 +436,10 @@ final class BluetoothAdapterStateMachine extends StateMachine {
}
private class BluetoothOn extends State {
- private boolean mPersistBluetoothOff = false;
@Override
public void enter() {
- if (DBG) log("Enter BluetoothOn: " + mPersistBluetoothOff);
+ if (DBG) log("Enter BluetoothOn: " + getCurrentMessage().what);
}
@Override
public boolean processMessage(Message message) {
@@ -500,7 +497,7 @@ final class BluetoothAdapterStateMachine extends StateMachine {
@Override
public void enter() {
- if (DBG) log("Enter PerProcessState");
+ if (DBG) log("Enter PerProcessState: " + getCurrentMessage().what);
}
@Override
@@ -523,14 +520,11 @@ final class BluetoothAdapterStateMachine extends StateMachine {
case USER_TURN_ON:
broadcastState(BluetoothAdapter.STATE_TURNING_ON);
persistSwitchSetting(true);
-
- String[] propVal = {"Pairable", mBluetoothService.getProperty("Pairable")};
- mEventLoop.onPropertyChanged(propVal);
-
- // run bluetooth now that it's turned on
- mBluetoothService.runBluetooth();
+ mBluetoothService.initBluetoothAfterTurningOn();
transitionTo(mBluetoothOn);
broadcastState(BluetoothAdapter.STATE_ON);
+ // run bluetooth now that it's turned on
+ mBluetoothService.runBluetooth();
break;
case USER_TURN_OFF:
broadcastState(BluetoothAdapter.STATE_TURNING_OFF);
diff --git a/core/java/android/server/BluetoothBondState.java b/core/java/android/server/BluetoothBondState.java
index 30a8b2a..4e2608e 100644
--- a/core/java/android/server/BluetoothBondState.java
+++ b/core/java/android/server/BluetoothBondState.java
@@ -90,6 +90,7 @@ class BluetoothBondState {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
mContext.registerReceiver(mReceiver, filter);
+ readAutoPairingData();
}
synchronized void setPendingOutgoingBonding(String address) {
diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java
index afc9676..d73f8c9 100644
--- a/core/java/android/server/BluetoothEventLoop.java
+++ b/core/java/android/server/BluetoothEventLoop.java
@@ -354,12 +354,10 @@ class BluetoothEventLoop {
Intent intent;
adapterProperties.setProperty(name, propValues[1]);
if (propValues[1].equals("true")) {
- mBluetoothService.setIsDiscovering(true);
intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
} else {
// Stop the discovery.
mBluetoothService.cancelDiscovery();
- mBluetoothService.setIsDiscovering(false);
intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
}
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index 8419f23..28546dc 100755
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -96,7 +96,6 @@ public class BluetoothService extends IBluetooth.Stub {
private boolean mIsAirplaneToggleable;
private BluetoothAdapterStateMachine mBluetoothState;
private boolean mRestart = false; // need to call enable() after disable()
- private boolean mIsDiscovering;
private int[] mAdapterSdpHandles;
private ParcelUuid[] mAdapterUuids;
@@ -213,8 +212,6 @@ public class BluetoothService extends IBluetooth.Stub {
disableNative();
}
- mIsDiscovering = false;
-
mBondState = new BluetoothBondState(context, this);
mAdapterProperties = new BluetoothAdapterProperties(context, this);
mDeviceProperties = new BluetoothDeviceProperties(this);
@@ -411,7 +408,6 @@ public class BluetoothService extends IBluetooth.Stub {
intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
- mIsDiscovering = false;
mAdapterProperties.clear();
mServiceRecordToPid.clear();
@@ -482,8 +478,6 @@ public class BluetoothService extends IBluetooth.Stub {
if (!setupNativeDataNative()) {
return false;
}
- mIsDiscovering = false;
-
switchConnectable(false);
updateSdpRecords();
return true;
@@ -587,16 +581,21 @@ public class BluetoothService extends IBluetooth.Stub {
}
/**
+ * This method is called immediately before Bluetooth module is turned on after
+ * the adapter became pariable.
+ * It inits bond state and profile state before STATE_ON intent is broadcasted.
+ */
+ /*package*/ void initBluetoothAfterTurningOn() {
+ mBondState.initBondState();
+ initProfileState();
+ }
+
+ /**
* This method is called immediately after Bluetooth module is turned on.
* It starts auto-connection and places bluetooth on sign onto the battery
* stats
*/
/*package*/ void runBluetooth() {
- mIsDiscovering = false;
- mBondState.readAutoPairingData();
- mBondState.initBondState();
- initProfileState();
-
autoConnect();
// Log bluetooth on to battery stats.
@@ -787,12 +786,14 @@ public class BluetoothService extends IBluetooth.Stub {
}
if (allowOnlyInOnState) {
- setPropertyBoolean("Pairable", pairable);
setPropertyBoolean("Discoverable", discoverable);
+ setPropertyBoolean("Pairable", pairable);
} else {
// allowed to set the property through native layer directly
- setAdapterPropertyBooleanNative("Pairable", pairable ? 1 : 0);
setAdapterPropertyBooleanNative("Discoverable", discoverable ? 1 : 0);
+ // do setting pairable after setting discoverable since the adapter
+ // state machine uses pairable event for state change
+ setAdapterPropertyBooleanNative("Pairable", pairable ? 1 : 0);
}
return true;
}
@@ -949,11 +950,13 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean isDiscovering() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mIsDiscovering;
- }
- /* package */ void setIsDiscovering(boolean isDiscovering) {
- mIsDiscovering = isDiscovering;
+ String discoveringProperty = mAdapterProperties.getProperty("Discovering");
+ if (discoveringProperty == null) {
+ return false;
+ }
+
+ return discoveringProperty.equals("true");
}
private boolean isBondingFeasible(String address) {