summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/server/BluetoothInputProfileHandler.java26
-rw-r--r--core/java/android/server/BluetoothPanProfileHandler.java28
-rw-r--r--core/java/android/server/BluetoothService.java129
3 files changed, 113 insertions, 70 deletions
diff --git a/core/java/android/server/BluetoothInputProfileHandler.java b/core/java/android/server/BluetoothInputProfileHandler.java
index e6513fd34699..247e297f5031 100644
--- a/core/java/android/server/BluetoothInputProfileHandler.java
+++ b/core/java/android/server/BluetoothInputProfileHandler.java
@@ -60,7 +60,7 @@ final class BluetoothInputProfileHandler {
return sInstance;
}
- synchronized boolean connectInputDevice(BluetoothDevice device,
+ boolean connectInputDevice(BluetoothDevice device,
BluetoothDeviceProfileState state) {
String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
if (objectPath == null ||
@@ -78,7 +78,7 @@ final class BluetoothInputProfileHandler {
return false;
}
- synchronized boolean connectInputDeviceInternal(BluetoothDevice device) {
+ boolean connectInputDeviceInternal(BluetoothDevice device) {
String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
handleInputDeviceStateChange(device, BluetoothInputDevice.STATE_CONNECTING);
if (!mBluetoothService.connectInputDeviceNative(objectPath)) {
@@ -88,7 +88,7 @@ final class BluetoothInputProfileHandler {
return true;
}
- synchronized boolean disconnectInputDevice(BluetoothDevice device,
+ boolean disconnectInputDevice(BluetoothDevice device,
BluetoothDeviceProfileState state) {
String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
if (objectPath == null ||
@@ -105,7 +105,7 @@ final class BluetoothInputProfileHandler {
return false;
}
- synchronized boolean disconnectInputDeviceInternal(BluetoothDevice device) {
+ boolean disconnectInputDeviceInternal(BluetoothDevice device) {
String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
handleInputDeviceStateChange(device, BluetoothInputDevice.STATE_DISCONNECTING);
if (!mBluetoothService.disconnectInputDeviceNative(objectPath)) {
@@ -115,31 +115,31 @@ final class BluetoothInputProfileHandler {
return true;
}
- synchronized int getInputDeviceConnectionState(BluetoothDevice device) {
+ int getInputDeviceConnectionState(BluetoothDevice device) {
if (mInputDevices.get(device) == null) {
return BluetoothInputDevice.STATE_DISCONNECTED;
}
return mInputDevices.get(device);
}
- synchronized List<BluetoothDevice> getConnectedInputDevices() {
+ List<BluetoothDevice> getConnectedInputDevices() {
List<BluetoothDevice> devices = lookupInputDevicesMatchingStates(
new int[] {BluetoothInputDevice.STATE_CONNECTED});
return devices;
}
- synchronized List<BluetoothDevice> getInputDevicesMatchingConnectionStates(int[] states) {
+ List<BluetoothDevice> getInputDevicesMatchingConnectionStates(int[] states) {
List<BluetoothDevice> devices = lookupInputDevicesMatchingStates(states);
return devices;
}
- synchronized int getInputDevicePriority(BluetoothDevice device) {
+ int getInputDevicePriority(BluetoothDevice device) {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.getBluetoothInputDevicePriorityKey(device.getAddress()),
BluetoothInputDevice.PRIORITY_UNDEFINED);
}
- synchronized boolean setInputDevicePriority(BluetoothDevice device, int priority) {
+ boolean setInputDevicePriority(BluetoothDevice device, int priority) {
if (!BluetoothAdapter.checkBluetoothAddress(device.getAddress())) {
return false;
}
@@ -148,7 +148,7 @@ final class BluetoothInputProfileHandler {
priority);
}
- synchronized List<BluetoothDevice> lookupInputDevicesMatchingStates(int[] states) {
+ List<BluetoothDevice> lookupInputDevicesMatchingStates(int[] states) {
List<BluetoothDevice> inputDevices = new ArrayList<BluetoothDevice>();
for (BluetoothDevice device: mInputDevices.keySet()) {
@@ -163,7 +163,7 @@ final class BluetoothInputProfileHandler {
return inputDevices;
}
- private synchronized void handleInputDeviceStateChange(BluetoothDevice device, int state) {
+ private void handleInputDeviceStateChange(BluetoothDevice device, int state) {
int prevState;
if (mInputDevices.get(device) == null) {
prevState = BluetoothInputDevice.STATE_DISCONNECTED;
@@ -194,7 +194,7 @@ final class BluetoothInputProfileHandler {
mBluetoothService.sendConnectionStateChange(device, state, prevState);
}
- synchronized void handleInputDevicePropertyChange(String address, boolean connected) {
+ void handleInputDevicePropertyChange(String address, boolean connected) {
int state = connected ? BluetoothInputDevice.STATE_CONNECTED :
BluetoothInputDevice.STATE_DISCONNECTED;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
@@ -202,7 +202,7 @@ final class BluetoothInputProfileHandler {
handleInputDeviceStateChange(device, state);
}
- synchronized void setInitialInputDevicePriority(BluetoothDevice device, int state) {
+ void setInitialInputDevicePriority(BluetoothDevice device, int state) {
switch (state) {
case BluetoothDevice.BOND_BONDED:
if (getInputDevicePriority(device) == BluetoothInputDevice.PRIORITY_UNDEFINED) {
diff --git a/core/java/android/server/BluetoothPanProfileHandler.java b/core/java/android/server/BluetoothPanProfileHandler.java
index 8925856107e7..0d63e194d228 100644
--- a/core/java/android/server/BluetoothPanProfileHandler.java
+++ b/core/java/android/server/BluetoothPanProfileHandler.java
@@ -76,17 +76,17 @@ final class BluetoothPanProfileHandler {
}
}
- static synchronized BluetoothPanProfileHandler getInstance(Context context,
+ static BluetoothPanProfileHandler getInstance(Context context,
BluetoothService service) {
if (sInstance == null) sInstance = new BluetoothPanProfileHandler(context, service);
return sInstance;
}
- synchronized boolean isTetheringOn() {
+ boolean isTetheringOn() {
return mTetheringOn;
}
- synchronized boolean allowIncomingTethering() {
+ boolean allowIncomingTethering() {
if (isTetheringOn() && getConnectedPanDevices().size() < mMaxPanDevices)
return true;
return false;
@@ -94,7 +94,7 @@ final class BluetoothPanProfileHandler {
private BroadcastReceiver mTetheringReceiver = null;
- synchronized void setBluetoothTethering(boolean value) {
+ void setBluetoothTethering(boolean value) {
if (!value) {
disconnectPanServerDevices();
}
@@ -104,7 +104,7 @@ final class BluetoothPanProfileHandler {
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
mTetheringReceiver = new BroadcastReceiver() {
@Override
- public synchronized void onReceive(Context context, Intent intent) {
+ public void onReceive(Context context, Intent intent) {
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF)
== BluetoothAdapter.STATE_ON) {
mTetheringOn = true;
@@ -118,7 +118,7 @@ final class BluetoothPanProfileHandler {
}
}
- synchronized int getPanDeviceConnectionState(BluetoothDevice device) {
+ int getPanDeviceConnectionState(BluetoothDevice device) {
BluetoothPanDevice panDevice = mPanDevices.get(device);
if (panDevice == null) {
return BluetoothPan.STATE_DISCONNECTED;
@@ -126,7 +126,7 @@ final class BluetoothPanProfileHandler {
return panDevice.mState;
}
- synchronized boolean connectPanDevice(BluetoothDevice device) {
+ boolean connectPanDevice(BluetoothDevice device) {
String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
if (DBG) Log.d(TAG, "connect PAN(" + objectPath + ")");
if (getPanDeviceConnectionState(device) != BluetoothPan.STATE_DISCONNECTED) {
@@ -158,7 +158,7 @@ final class BluetoothPanProfileHandler {
}
}
- private synchronized boolean disconnectPanServerDevices() {
+ private boolean disconnectPanServerDevices() {
debugLog("disconnect all PAN devices");
for (BluetoothDevice device: mPanDevices.keySet()) {
@@ -187,7 +187,7 @@ final class BluetoothPanProfileHandler {
return true;
}
- synchronized List<BluetoothDevice> getConnectedPanDevices() {
+ List<BluetoothDevice> getConnectedPanDevices() {
List<BluetoothDevice> devices = new ArrayList<BluetoothDevice>();
for (BluetoothDevice device: mPanDevices.keySet()) {
@@ -198,7 +198,7 @@ final class BluetoothPanProfileHandler {
return devices;
}
- synchronized List<BluetoothDevice> getPanDevicesMatchingConnectionStates(int[] states) {
+ List<BluetoothDevice> getPanDevicesMatchingConnectionStates(int[] states) {
List<BluetoothDevice> devices = new ArrayList<BluetoothDevice>();
for (BluetoothDevice device: mPanDevices.keySet()) {
@@ -213,7 +213,7 @@ final class BluetoothPanProfileHandler {
return devices;
}
- synchronized boolean disconnectPanDevice(BluetoothDevice device) {
+ boolean disconnectPanDevice(BluetoothDevice device) {
String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
debugLog("disconnect PAN(" + objectPath + ")");
@@ -249,7 +249,7 @@ final class BluetoothPanProfileHandler {
return true;
}
- synchronized void handlePanDeviceStateChange(BluetoothDevice device,
+ void handlePanDeviceStateChange(BluetoothDevice device,
String iface, int state, int role) {
int prevState;
String ifaceAddr = null;
@@ -304,7 +304,7 @@ final class BluetoothPanProfileHandler {
mBluetoothService.sendConnectionStateChange(device, state, prevState);
}
- synchronized void handlePanDeviceStateChange(BluetoothDevice device,
+ void handlePanDeviceStateChange(BluetoothDevice device,
int state, int role) {
handlePanDeviceStateChange(device, null, state, role);
}
@@ -343,7 +343,7 @@ final class BluetoothPanProfileHandler {
}
// configured when we start tethering
- private synchronized String enableTethering(String iface) {
+ private String enableTethering(String iface) {
debugLog("updateTetherState:" + iface);
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index f98d27518fea..2c79385a13e0 100644
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -1928,120 +1928,163 @@ public class BluetoothService extends IBluetooth.Stub {
}
/**** Handlers for PAN Profile ****/
+ // TODO: This needs to be converted to a state machine.
- public synchronized boolean isTetheringOn() {
+ public boolean isTetheringOn() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothPanProfileHandler.isTetheringOn();
+ synchronized (mBluetoothPanProfileHandler) {
+ return mBluetoothPanProfileHandler.isTetheringOn();
+ }
}
- /*package*/ synchronized boolean allowIncomingTethering() {
- return mBluetoothPanProfileHandler.allowIncomingTethering();
+ /*package*/boolean allowIncomingTethering() {
+ synchronized (mBluetoothPanProfileHandler) {
+ return mBluetoothPanProfileHandler.allowIncomingTethering();
+ }
}
- public synchronized void setBluetoothTethering(boolean value) {
+ public void setBluetoothTethering(boolean value) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- mBluetoothPanProfileHandler.setBluetoothTethering(value);
+ synchronized (mBluetoothPanProfileHandler) {
+ mBluetoothPanProfileHandler.setBluetoothTethering(value);
+ }
}
- public synchronized int getPanDeviceConnectionState(BluetoothDevice device) {
+ public int getPanDeviceConnectionState(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothPanProfileHandler.getPanDeviceConnectionState(device);
+ synchronized (mBluetoothPanProfileHandler) {
+ return mBluetoothPanProfileHandler.getPanDeviceConnectionState(device);
+ }
}
- public synchronized boolean connectPanDevice(BluetoothDevice device) {
+ public boolean connectPanDevice(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
- return mBluetoothPanProfileHandler.connectPanDevice(device);
+ synchronized (mBluetoothPanProfileHandler) {
+ return mBluetoothPanProfileHandler.connectPanDevice(device);
+ }
}
- public synchronized List<BluetoothDevice> getConnectedPanDevices() {
+ public List<BluetoothDevice> getConnectedPanDevices() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothPanProfileHandler.getConnectedPanDevices();
+ synchronized (mBluetoothPanProfileHandler) {
+ return mBluetoothPanProfileHandler.getConnectedPanDevices();
+ }
}
- public synchronized List<BluetoothDevice> getPanDevicesMatchingConnectionStates(
+ public List<BluetoothDevice> getPanDevicesMatchingConnectionStates(
int[] states) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothPanProfileHandler.getPanDevicesMatchingConnectionStates(states);
+ synchronized (mBluetoothPanProfileHandler) {
+ return mBluetoothPanProfileHandler.getPanDevicesMatchingConnectionStates(states);
+ }
}
- public synchronized boolean disconnectPanDevice(BluetoothDevice device) {
+ public boolean disconnectPanDevice(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
- return mBluetoothPanProfileHandler.disconnectPanDevice(device);
+ synchronized (mBluetoothPanProfileHandler) {
+ return mBluetoothPanProfileHandler.disconnectPanDevice(device);
+ }
}
- /*package*/ synchronized void handlePanDeviceStateChange(BluetoothDevice device,
+ /*package*/void handlePanDeviceStateChange(BluetoothDevice device,
String iface,
int state,
int role) {
- mBluetoothPanProfileHandler.handlePanDeviceStateChange(device, iface, state, role);
+ synchronized (mBluetoothPanProfileHandler) {
+ mBluetoothPanProfileHandler.handlePanDeviceStateChange(device, iface, state, role);
+ }
}
- /*package*/ synchronized void handlePanDeviceStateChange(BluetoothDevice device,
+ /*package*/void handlePanDeviceStateChange(BluetoothDevice device,
int state, int role) {
- mBluetoothPanProfileHandler.handlePanDeviceStateChange(device, null, state, role);
+ synchronized (mBluetoothPanProfileHandler) {
+ mBluetoothPanProfileHandler.handlePanDeviceStateChange(device, null, state, role);
+ }
}
/**** Handlers for Input Device Profile ****/
+ // This needs to be converted to state machine
- public synchronized boolean connectInputDevice(BluetoothDevice device) {
+ public boolean connectInputDevice(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
BluetoothDeviceProfileState state = mDeviceProfileState.get(device.getAddress());
- return mBluetoothInputProfileHandler.connectInputDevice(device, state);
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.connectInputDevice(device, state);
+ }
}
- public synchronized boolean connectInputDeviceInternal(BluetoothDevice device) {
- return mBluetoothInputProfileHandler.connectInputDeviceInternal(device);
+ public boolean connectInputDeviceInternal(BluetoothDevice device) {
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.connectInputDeviceInternal(device);
+ }
}
- public synchronized boolean disconnectInputDevice(BluetoothDevice device) {
+ public boolean disconnectInputDevice(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
BluetoothDeviceProfileState state = mDeviceProfileState.get(device.getAddress());
- return mBluetoothInputProfileHandler.disconnectInputDevice(device, state);
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.disconnectInputDevice(device, state);
+ }
}
- public synchronized boolean disconnectInputDeviceInternal(BluetoothDevice device) {
- return mBluetoothInputProfileHandler.disconnectInputDeviceInternal(device);
+ public boolean disconnectInputDeviceInternal(BluetoothDevice device) {
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.disconnectInputDeviceInternal(device);
+ }
}
- public synchronized int getInputDeviceConnectionState(BluetoothDevice device) {
+ public int getInputDeviceConnectionState(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothInputProfileHandler.getInputDeviceConnectionState(device);
-
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.getInputDeviceConnectionState(device);
+ }
}
- public synchronized List<BluetoothDevice> getConnectedInputDevices() {
+ public List<BluetoothDevice> getConnectedInputDevices() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothInputProfileHandler.getConnectedInputDevices();
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.getConnectedInputDevices();
+ }
}
- public synchronized List<BluetoothDevice> getInputDevicesMatchingConnectionStates(
+ public List<BluetoothDevice> getInputDevicesMatchingConnectionStates(
int[] states) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothInputProfileHandler.getInputDevicesMatchingConnectionStates(states);
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.getInputDevicesMatchingConnectionStates(states);
+ }
}
- public synchronized int getInputDevicePriority(BluetoothDevice device) {
+ public int getInputDevicePriority(BluetoothDevice device) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothInputProfileHandler.getInputDevicePriority(device);
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.getInputDevicePriority(device);
+ }
}
- public synchronized boolean setInputDevicePriority(BluetoothDevice device, int priority) {
+ public boolean setInputDevicePriority(BluetoothDevice device, int priority) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
- return mBluetoothInputProfileHandler.setInputDevicePriority(device, priority);
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.setInputDevicePriority(device, priority);
+ }
}
- /*package*/synchronized List<BluetoothDevice> lookupInputDevicesMatchingStates(int[] states) {
- return mBluetoothInputProfileHandler.lookupInputDevicesMatchingStates(states);
+ /*package*/List<BluetoothDevice> lookupInputDevicesMatchingStates(int[] states) {
+ synchronized (mBluetoothInputProfileHandler) {
+ return mBluetoothInputProfileHandler.lookupInputDevicesMatchingStates(states);
+ }
}
- /*package*/ synchronized void handleInputDevicePropertyChange(String address, boolean connected) {
- mBluetoothInputProfileHandler.handleInputDevicePropertyChange(address, connected);
+ /*package*/void handleInputDevicePropertyChange(String address, boolean connected) {
+ synchronized (mBluetoothInputProfileHandler) {
+ mBluetoothInputProfileHandler.handleInputDevicePropertyChange(address, connected);
+ }
}
public boolean connectHeadset(String address) {