Merge "Merge "Fix exception handling in getState() binder cache" into rvc-dev am: 773cc6249e am: e46da26d89" into rvc-d1-dev-plus-aosp am: 01d981fa4c
Change-Id: Idfc358ad10d38e67bb4f40d4f15f81a46b8ba761
This commit is contained in:
@@ -979,17 +979,14 @@ public final class BluetoothAdapter {
|
|||||||
8, BLUETOOTH_GET_STATE_CACHE_PROPERTY) {
|
8, BLUETOOTH_GET_STATE_CACHE_PROPERTY) {
|
||||||
@Override
|
@Override
|
||||||
protected Integer recompute(Void query) {
|
protected Integer recompute(Void query) {
|
||||||
|
// This function must be called while holding the
|
||||||
|
// mServiceLock, and with mService not null. The public
|
||||||
|
// getState() method makes this guarantee.
|
||||||
try {
|
try {
|
||||||
mServiceLock.readLock().lock();
|
return mService.getState();
|
||||||
if (mService != null) {
|
|
||||||
return mService.getState();
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "", e);
|
throw e.rethrowFromSystemServer();
|
||||||
} finally {
|
|
||||||
mServiceLock.readLock().unlock();
|
|
||||||
}
|
}
|
||||||
return BluetoothAdapter.STATE_OFF;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1016,7 +1013,24 @@ public final class BluetoothAdapter {
|
|||||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||||
@AdapterState
|
@AdapterState
|
||||||
public int getState() {
|
public int getState() {
|
||||||
int state = mBluetoothGetStateCache.query(null);
|
int state = BluetoothAdapter.STATE_OFF;
|
||||||
|
|
||||||
|
try {
|
||||||
|
mServiceLock.readLock().lock();
|
||||||
|
// The test for mService must either be outside the cache, or
|
||||||
|
// the cache must be invalidated when mService changes.
|
||||||
|
if (mService != null) {
|
||||||
|
state = mBluetoothGetStateCache.query(null);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
if (e.getCause() instanceof RemoteException) {
|
||||||
|
Log.e(TAG, "", e.getCause());
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
mServiceLock.readLock().unlock();
|
||||||
|
}
|
||||||
|
|
||||||
// Consider all internal states as OFF
|
// Consider all internal states as OFF
|
||||||
if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_ON
|
if (state == BluetoothAdapter.STATE_BLE_ON || state == BluetoothAdapter.STATE_BLE_TURNING_ON
|
||||||
|
|||||||
Reference in New Issue
Block a user