Merge changes from topics "merge BT bond", "parameterize BT enable", "remove BT isEnabled"
* changes: Collapse the implementations of BluetoothDevice.createBond Call parameterized version of IBluetooth.enable Implement isEnabled in terms of getState
This commit is contained in:
@@ -862,18 +862,7 @@ public final class BluetoothAdapter {
|
|||||||
*/
|
*/
|
||||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
try {
|
return getState() == BluetoothAdapter.STATE_ON;
|
||||||
mServiceLock.readLock().lock();
|
|
||||||
if (mService != null) {
|
|
||||||
return mService.isEnabled();
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "", e);
|
|
||||||
} finally {
|
|
||||||
mServiceLock.readLock().unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1131,20 +1131,7 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||||
public boolean createBond() {
|
public boolean createBond() {
|
||||||
final IBluetooth service = sService;
|
return createBond(TRANSPORT_AUTO);
|
||||||
if (service == null) {
|
|
||||||
Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Log.i(TAG, "createBond() for device " + getAddress()
|
|
||||||
+ " called by pid: " + Process.myPid()
|
|
||||||
+ " tid: " + Process.myTid());
|
|
||||||
return service.createBond(this, TRANSPORT_AUTO);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "", e);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1165,23 +1152,7 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public boolean createBond(int transport) {
|
public boolean createBond(int transport) {
|
||||||
final IBluetooth service = sService;
|
return createBondOutOfBand(transport, null);
|
||||||
if (service == null) {
|
|
||||||
Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE) {
|
|
||||||
throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Log.i(TAG, "createBond() for device " + getAddress()
|
|
||||||
+ " called by pid: " + Process.myPid()
|
|
||||||
+ " tid: " + Process.myTid());
|
|
||||||
return service.createBond(this, transport);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "", e);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1209,7 +1180,7 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return service.createBondOutOfBand(this, transport, oobData);
|
return service.createBond(this, transport, oobData);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "", e);
|
Log.e(TAG, "", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -613,22 +613,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
if ((Binder.getCallingUid() != Process.SYSTEM_UID) && (!checkIfCallerIsForegroundUser())) {
|
return getState() == BluetoothAdapter.STATE_ON;
|
||||||
Slog.w(TAG, "isEnabled(): not allowed for non-active and non system user");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mBluetoothLock.readLock().lock();
|
|
||||||
if (mBluetooth != null) {
|
|
||||||
return mBluetooth.isEnabled();
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Slog.e(TAG, "isEnabled()", e);
|
|
||||||
} finally {
|
|
||||||
mBluetoothLock.readLock().unlock();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getState() {
|
public int getState() {
|
||||||
@@ -1766,14 +1751,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
//Do enable request
|
//Do enable request
|
||||||
try {
|
try {
|
||||||
if (!mQuietEnable) {
|
if (!mBluetooth.enable(mQuietEnable)) {
|
||||||
if (!mBluetooth.enable()) {
|
Slog.e(TAG, "IBluetooth.enable() returned false");
|
||||||
Slog.e(TAG, "IBluetooth.enable() returned false");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!mBluetooth.enableNoAutoConnect()) {
|
|
||||||
Slog.e(TAG, "IBluetooth.enableNoAutoConnect() returned false");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "Unable to call enable()", e);
|
Slog.e(TAG, "Unable to call enable()", e);
|
||||||
@@ -2048,14 +2027,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
} else if (mBluetooth != null) {
|
} else if (mBluetooth != null) {
|
||||||
//Enable bluetooth
|
//Enable bluetooth
|
||||||
try {
|
try {
|
||||||
if (!mQuietEnable) {
|
if (!mBluetooth.enable(mQuietEnable)) {
|
||||||
if (!mBluetooth.enable()) {
|
Slog.e(TAG, "IBluetooth.enable() returned false");
|
||||||
Slog.e(TAG, "IBluetooth.enable() returned false");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!mBluetooth.enableNoAutoConnect()) {
|
|
||||||
Slog.e(TAG, "IBluetooth.enableNoAutoConnect() returned false");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.e(TAG, "Unable to call enable()", e);
|
Slog.e(TAG, "Unable to call enable()", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user