summaryrefslogtreecommitdiffstats
path: root/core/java/android/bluetooth/BluetoothDevice.java
diff options
context:
space:
mode:
authorNitin Arora <niarora@codeaurora.org>2015-03-02 15:03:51 -0800
committerAndre Eisenbach <eisenbach@google.com>2015-04-15 23:45:30 -0700
commitd055adbe2c1c65d9346e65209fa8790190bc239e (patch)
treeab1f16a591fd857902c8d094360f31aac38cf305 /core/java/android/bluetooth/BluetoothDevice.java
parentbd3af28fdc38cfe741badb86f9daa2fc6122eabc (diff)
downloadframeworks_base-d055adbe2c1c65d9346e65209fa8790190bc239e.zip
frameworks_base-d055adbe2c1c65d9346e65209fa8790190bc239e.tar.gz
frameworks_base-d055adbe2c1c65d9346e65209fa8790190bc239e.tar.bz2
Bluetooth LE background operation mode (2/2)
Changes include new framework APIs to enable and disable Bluetooth LE separately from Bluetooth Classic. Along with handling the new states in the Bluetooth manager service. Change-Id: Idf667981f48fcbcb6dfda1aa77ea8bab1b2361f0
Diffstat (limited to 'core/java/android/bluetooth/BluetoothDevice.java')
-rw-r--r--core/java/android/bluetooth/BluetoothDevice.java55
1 files changed, 42 insertions, 13 deletions
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index 1fdf9f4..1e82c03 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -606,7 +606,9 @@ public final class BluetoothDevice implements Parcelable {
public void onBluetoothServiceUp(IBluetooth bluetoothService)
throws RemoteException {
synchronized (BluetoothDevice.class) {
- sService = bluetoothService;
+ if (sService == null) {
+ sService = bluetoothService;
+ }
}
}
@@ -616,6 +618,11 @@ public final class BluetoothDevice implements Parcelable {
sService = null;
}
}
+
+ public void onBrEdrDown()
+ {
+ if (DBG) Log.d(TAG, "onBrEdrDown: reached BLE ON state");
+ }
};
/**
* Create a new BluetoothDevice
@@ -1030,7 +1037,7 @@ public final class BluetoothDevice implements Parcelable {
* or null on error
*/
public ParcelUuid[] getUuids() {
- if (sService == null) {
+ if (sService == null || isBluetoothEnabled() == false) {
Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
return null;
}
@@ -1057,7 +1064,7 @@ public final class BluetoothDevice implements Parcelable {
*/
public boolean fetchUuidsWithSdp() {
IBluetooth service = sService;
- if (service == null) {
+ if (service == null || isBluetoothEnabled() == false) {
Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp");
return false;
}
@@ -1099,16 +1106,6 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
- /** @hide */
- public int getServiceChannel(ParcelUuid uuid) {
- //TODO(BT)
- /*
- try {
- return sService.getRemoteServiceChannel(this, uuid);
- } catch (RemoteException e) {Log.e(TAG, "", e);}*/
- return BluetoothDevice.ERROR;
- }
-
/**
* Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN}
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
@@ -1187,6 +1184,15 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
+ boolean isBluetoothEnabled() {
+ boolean ret = false;
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ if (adapter != null && adapter.isEnabled() == true) {
+ ret = true;
+ }
+ return ret;
+ }
+
/**
* Requires {@link android.Manifest.permission#BLUETOOTH}.
* @return Whether the phonebook access is allowed to this device. Can be
@@ -1289,6 +1295,10 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
public BluetoothSocket createRfcommSocket(int channel) throws IOException {
+ if (isBluetoothEnabled() == false) {
+ Log.e(TAG, "Bluetooth is not enabled");
+ throw new IOException();
+ }
return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, channel,
null);
}
@@ -1355,6 +1365,11 @@ public final class BluetoothDevice implements Parcelable {
* insufficient permissions
*/
public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException {
+ if (isBluetoothEnabled() == false) {
+ Log.e(TAG, "Bluetooth is not enabled");
+ throw new IOException();
+ }
+
return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, true, true, this, -1,
new ParcelUuid(uuid));
}
@@ -1388,6 +1403,10 @@ public final class BluetoothDevice implements Parcelable {
* insufficient permissions
*/
public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException {
+ if (isBluetoothEnabled() == false) {
+ Log.e(TAG, "Bluetooth is not enabled");
+ throw new IOException();
+ }
return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, -1,
new ParcelUuid(uuid));
}
@@ -1407,6 +1426,11 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException {
+
+ if (isBluetoothEnabled() == false) {
+ Log.e(TAG, "Bluetooth is not enabled");
+ throw new IOException();
+ }
return new BluetoothSocket(BluetoothSocket.TYPE_RFCOMM, -1, false, false, this, port,
null);
}
@@ -1422,6 +1446,11 @@ public final class BluetoothDevice implements Parcelable {
* @hide
*/
public BluetoothSocket createScoSocket() throws IOException {
+
+ if (isBluetoothEnabled() == false) {
+ Log.e(TAG, "Bluetooth is not enabled");
+ throw new IOException();
+ }
return new BluetoothSocket(BluetoothSocket.TYPE_SCO, -1, true, true, this, -1, null);
}