Skip to content

Commit 44b58ab

Browse files
author
Matthew Xie
committed
Check the bluetooth state for getUuid call
Donnot make the bluetoothservice.getUuids call if the bluetooth is not on. Also get rid of all the necessary locks on BluetoothService for get property call. It had a lock on BluetoothAdapterProperty. bug5472114 Change-Id: I383472ae6006fc1f0129c960c8a44ed0df027a43
1 parent e562287 commit 44b58ab

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

core/java/android/bluetooth/BluetoothAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ public String getName() {
533533
* @hide
534534
*/
535535
public ParcelUuid[] getUuids() {
536+
if (getState() != STATE_ON) return null;
536537
try {
537538
return mService.getUuids();
538539
} catch (RemoteException e) {Log.e(TAG, "", e);}

core/java/android/server/BluetoothService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ public synchronized boolean setScanMode(int mode, int duration) {
809809
}
810810
}
811811

812-
/*package*/ synchronized String getProperty(String name, boolean checkState) {
812+
/*package*/ String getProperty(String name, boolean checkState) {
813813
// If checkState is false, check if the event loop is running.
814814
// before making the call to Bluez
815815
if (checkState) {
@@ -853,14 +853,14 @@ public synchronized String getName() {
853853
return getProperty("Name", false);
854854
}
855855

856-
public synchronized ParcelUuid[] getUuids() {
856+
public ParcelUuid[] getUuids() {
857857
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
858858
String value = getProperty("UUIDs", true);
859859
if (value == null) return null;
860860
return convertStringToParcelUuid(value);
861861
}
862862

863-
private synchronized ParcelUuid[] convertStringToParcelUuid(String value) {
863+
private ParcelUuid[] convertStringToParcelUuid(String value) {
864864
String[] uuidStrings = null;
865865
// The UUIDs are stored as a "," separated string.
866866
uuidStrings = value.split(",");
@@ -933,7 +933,7 @@ public synchronized boolean setRemoteAlias(String address, String alias) {
933933
* @return The discoverability window of the device, in seconds. A negative
934934
* value indicates an error.
935935
*/
936-
public synchronized int getDiscoverableTimeout() {
936+
public int getDiscoverableTimeout() {
937937
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
938938
String timeout = getProperty("DiscoverableTimeout", true);
939939
if (timeout != null)
@@ -942,7 +942,7 @@ public synchronized int getDiscoverableTimeout() {
942942
return -1;
943943
}
944944

945-
public synchronized int getScanMode() {
945+
public int getScanMode() {
946946
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
947947
if (!isEnabledInternal())
948948
return BluetoothAdapter.SCAN_MODE_NONE;
@@ -968,7 +968,7 @@ public synchronized boolean cancelDiscovery() {
968968
return stopDiscoveryNative();
969969
}
970970

971-
public synchronized boolean isDiscovering() {
971+
public boolean isDiscovering() {
972972
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
973973

974974
String discoveringProperty = getProperty("Discovering", false);
@@ -2384,7 +2384,7 @@ void removeProfileState(String address) {
23842384
mDeviceProfileState.remove(address);
23852385
}
23862386

2387-
synchronized String[] getKnownDevices() {
2387+
String[] getKnownDevices() {
23882388
String[] bonds = null;
23892389
String val = getProperty("Devices", true);
23902390
if (val != null) {

0 commit comments

Comments
 (0)