summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Eisenbach <eisenbach@google.com>2015-02-10 00:21:35 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-02-10 00:21:43 +0000
commit455502b7501bdbc55a739083878431c3ba7ef81a (patch)
tree5fa42f4835aef136c4de4184cd781dba97af533b
parenta63ba4287e5c87f41cd7d4b43111fd18f3ec499b (diff)
parent2b8696e3a91194db0bfd876b8cc68843a7ccd080 (diff)
downloadframeworks_base-455502b7501bdbc55a739083878431c3ba7ef81a.zip
frameworks_base-455502b7501bdbc55a739083878431c3ba7ef81a.tar.gz
frameworks_base-455502b7501bdbc55a739083878431c3ba7ef81a.tar.bz2
Merge "Add API to check if a Bluetooth connection is encrypted (1/2)" into lmp-mr1-dev
-rw-r--r--api/system-current.txt2
-rw-r--r--core/java/android/bluetooth/BluetoothDevice.java34
-rw-r--r--core/java/android/bluetooth/IBluetooth.aidl2
3 files changed, 36 insertions, 2 deletions
diff --git a/api/system-current.txt b/api/system-current.txt
index d84b1dc..8d24e83 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -6415,6 +6415,8 @@ package android.bluetooth {
method public java.lang.String getName();
method public int getType();
method public android.os.ParcelUuid[] getUuids();
+ method public boolean isConnected();
+ method public boolean isEncrypted();
method public boolean setPairingConfirmation(boolean);
method public boolean setPin(byte[]);
method public void writeToParcel(android.os.Parcel, int);
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index 5e50b69..bb0d0a3 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -18,6 +18,7 @@ package android.bluetooth;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.annotation.SystemApi;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
@@ -67,6 +68,14 @@ public final class BluetoothDevice implements Parcelable {
private static final boolean DBG = false;
/**
+ * Connection state bitmask as returned by getConnectionState.
+ */
+ private static final int CONNECTION_STATE_DISCONNECTED = 0;
+ private static final int CONNECTION_STATE_CONNECTED = 1;
+ private static final int CONNECTION_STATE_ENCRYPTED_BREDR = 2;
+ private static final int CONNECTION_STATE_ENCRYPTED_LE = 4;
+
+ /**
* Sentinel error value for this class. Guaranteed to not equal any other
* integer constant in this class. Provided as a convenience for functions
* that require a sentinel error value, for example:
@@ -940,13 +949,36 @@ public final class BluetoothDevice implements Parcelable {
* @return True if there is at least one open connection to this device.
* @hide
*/
+ @SystemApi
public boolean isConnected() {
if (sService == null) {
// BT is not enabled, we cannot be connected.
return false;
}
try {
- return sService.isConnected(this);
+ return sService.getConnectionState(this) != CONNECTION_STATE_DISCONNECTED;
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ return false;
+ }
+ }
+
+ /**
+ * Returns whether there is an open connection to this device
+ * that has been encrypted.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH}.
+ *
+ * @return True if there is at least one encrypted connection to this device.
+ * @hide
+ */
+ @SystemApi
+ public boolean isEncrypted() {
+ if (sService == null) {
+ // BT is not enabled, we cannot be connected.
+ return false;
+ }
+ try {
+ return sService.getConnectionState(this) > CONNECTION_STATE_CONNECTED;
} catch (RemoteException e) {
Log.e(TAG, "", e);
return false;
diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl
index cd4535a..dabb1ce 100644
--- a/core/java/android/bluetooth/IBluetooth.aidl
+++ b/core/java/android/bluetooth/IBluetooth.aidl
@@ -59,7 +59,7 @@ interface IBluetooth
boolean cancelBondProcess(in BluetoothDevice device);
boolean removeBond(in BluetoothDevice device);
int getBondState(in BluetoothDevice device);
- boolean isConnected(in BluetoothDevice device);
+ int getConnectionState(in BluetoothDevice device);
String getRemoteName(in BluetoothDevice device);
int getRemoteType(in BluetoothDevice device);