diff options
Diffstat (limited to 'core/java/android/bluetooth')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothDevice.java | 102 | ||||
| -rw-r--r-- | core/java/android/bluetooth/BluetoothIntent.java | 23 | ||||
| -rw-r--r-- | core/java/android/bluetooth/IBluetoothDevice.aidl | 10 | ||||
| -rw-r--r-- | core/java/android/bluetooth/IBluetoothDeviceCallback.aidl | 1 |
4 files changed, 74 insertions, 62 deletions
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index d1f71c5..d613e1c 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -39,6 +39,28 @@ public class BluetoothDevice { public static final int RESULT_FAILURE = -1; public static final int RESULT_SUCCESS = 0; + /** We do not have a link key for the remote device, and are therefore not + * bonded */ + public static final int BOND_NOT_BONDED = 0; + /** We have a link key for the remote device, and are probably bonded. */ + public static final int BOND_BONDED = 1; + /** We are currently attempting bonding */ + public static final int BOND_BONDING = 2; + + //TODO: Unify these result codes in BluetoothResult or BluetoothError + /** A bond attempt failed because pins did not match, or remote device did + * not respond to pin request in time */ + public static final int UNBOND_REASON_AUTH_FAILED = 1; + /** A bond attempt failed because the other side explicilty rejected + * bonding */ + public static final int UNBOND_REASON_AUTH_REJECTED = 2; + /** A bond attempt failed because we cancelled the bonding process */ + public static final int UNBOND_REASON_CANCELLED = 3; + /** A bond attempt failed because we could not contact the remote device */ + public static final int UNBOND_REASON_AUTH_REMOTE_DEVICE_DOWN = 4; + /** An existing bond was explicitly revoked */ + public static final int UNBOND_REASON_REMOVED = 5; + private static final String TAG = "BluetoothDevice"; private final IBluetoothDevice mService; @@ -325,42 +347,36 @@ public class BluetoothDevice { /** * Create a bonding with a remote bluetooth device. * - * This is an asynchronous call. BluetoothIntent.BONDING_CREATED_ACTION - * will be broadcast if and when the remote device is successfully bonded. + * This is an asynchronous call. The result of this bonding attempt can be + * observed through BluetoothIntent.BOND_STATE_CHANGED_ACTION intents. * * @param address the remote device Bluetooth address. - * @return false if we cannot create a bonding to that device, true if - * there were no problems beginning the bonding process. + * @return false If there was an immediate problem creating the bonding, + * true otherwise. */ - public boolean createBonding(String address) { - return createBonding(address, null); + public boolean createBond(String address) { + try { + return mService.createBond(address); + } catch (RemoteException e) {Log.e(TAG, "", e);} + return false; } /** - * Create a bonding with a remote bluetooth device. - * - * This is an asynchronous call. onCreateBondingResult() of your callback - * will be called when the call is complete, with either RESULT_SUCCESS or - * RESULT_FAILURE. - * - * In addition to the callback, BluetoothIntent.BONDING_CREATED_ACTION will - * be broadcast if the remote device is successfully bonded. - * - * @param address The remote device Bluetooth address. - * @param callback Your callback, null is ok. - * @return true if your callback was successfully registered, or false if - * there was an error, implying your callback will never be called. + * Cancel an in-progress bonding request started with createBond. */ - public boolean createBonding(String address, IBluetoothDeviceCallback callback) { + public boolean cancelBondProcess(String address) { try { - return mService.createBonding(address, callback); + return mService.cancelBondProcess(address); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } - public boolean cancelBondingProcess(String address) { + /** + * Remove an already exisiting bonding (delete the link key). + */ + public boolean removeBond(String address) { try { - return mService.cancelBondingProcess(address); + return mService.removeBond(address); } catch (RemoteException e) {Log.e(TAG, "", e);} return false; } @@ -382,48 +398,34 @@ public class BluetoothDevice { * * This function does not check if the remote device is in range. * + * Remote devices that have an in-progress bonding attempt are not + * returned. + * * @return bluetooth hardware addresses of remote devices that are * bonded. Array size is 0 if no devices are bonded. Null on error. */ - public String[] listBondings() { + public String[] listBonds() { try { - return mService.listBondings(); + return mService.listBonds(); } catch (RemoteException e) {Log.e(TAG, "", e);} return null; } /** - * Check if a remote device is bonded (paired) to the local device. + * Get the bonding state of a remote device. * - * Bonding (pairing) is the process by which the user enters a pin code for - * the device, which generates a shared link key, allowing for - * authentication and encryption of future connections. In Android we - * require bonding before RFCOMM or SCO connections can be made to a remote - * device. - * - * This function checks if we have a link key with the remote device. It - * does not cause any RF transmission, and does not check if the remote - * device still has it's link key with us. If the other side no longer has - * a link key then the RFCOMM or SCO connection attempt will result in an - * error. - * - * This function does not check if the remote device is in range. + * Result is one of: + * BluetoothError.* + * BOND_* * * @param address Bluetooth hardware address of the remote device to check. - * @return true if bonded, false otherwise and on error. + * @return Result code */ - public boolean hasBonding(String address) { + public int getBondState(String address) { try { - return mService.hasBonding(address); + return mService.getBondState(address); } catch (RemoteException e) {Log.e(TAG, "", e);} - return false; - } - - public boolean removeBonding(String address) { - try { - return mService.removeBonding(address); - } catch (RemoteException e) {Log.e(TAG, "", e);} - return false; + return BluetoothError.ERROR_IPC; } public String getRemoteName(String address) { diff --git a/core/java/android/bluetooth/BluetoothIntent.java b/core/java/android/bluetooth/BluetoothIntent.java index 8e22791..57c46f9 100644 --- a/core/java/android/bluetooth/BluetoothIntent.java +++ b/core/java/android/bluetooth/BluetoothIntent.java @@ -45,6 +45,12 @@ public interface BluetoothIntent { "android.bluetooth.intent.HEADSET_STATE"; public static final String HEADSET_PREVIOUS_STATE = "android.bluetooth.intent.HEADSET_PREVIOUS_STATE"; + public static final String BOND_STATE = + "android.bluetooth.intent.BOND_STATE"; + public static final String BOND_PREVIOUS_STATE = + "android.bluetooth.intent.BOND_PREVIOUS_STATE"; + public static final String REASON = + "android.bluetooth.intent.REASON"; @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ENABLED_ACTION = @@ -105,12 +111,17 @@ public interface BluetoothIntent { public static final String REMOTE_ALIAS_CLEARED_ACTION = "android.bluetooth.intent.action.REMOTE_ALIAS_CLEARED"; - @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) - public static final String BONDING_CREATED_ACTION = - "android.bluetooth.intent.action.BONDING_CREATED"; - @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) - public static final String BONDING_REMOVED_ACTION = - "android.bluetooth.intent.action.BONDING_REMOVED"; + /** + * Broadcast when the bond state of a remote device changes. + * Has string extra ADDRESS and int extras BOND_STATE and + * BOND_PREVIOUS_STATE. + * If BOND_STATE is BluetoothDevice.BOND_NOT_BONDED then will + * also have an int extra REASON with a value of: + * BluetoothDevice.BOND_RESULT_* + * */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String BOND_STATE_CHANGED_ACTION = + "android.bluetooth.intent.action.BOND_STATE_CHANGED_ACTION"; @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String HEADSET_STATE_CHANGED_ACTION = diff --git a/core/java/android/bluetooth/IBluetoothDevice.aidl b/core/java/android/bluetooth/IBluetoothDevice.aidl index e7cc8ed..59f679f 100644 --- a/core/java/android/bluetooth/IBluetoothDevice.aidl +++ b/core/java/android/bluetooth/IBluetoothDevice.aidl @@ -57,11 +57,11 @@ interface IBluetoothDevice boolean isAclConnected(in String address); boolean disconnectRemoteDeviceAcl(in String address); - boolean createBonding(in String address, in IBluetoothDeviceCallback callback); - boolean cancelBondingProcess(in String address); - String[] listBondings(); - boolean hasBonding(in String address); - boolean removeBonding(in String address); + boolean createBond(in String address); + boolean cancelBondProcess(in String address); + boolean removeBond(in String address); + String[] listBonds(); + int getBondState(in String address); String getRemoteName(in String address); String getRemoteAlias(in String address); diff --git a/core/java/android/bluetooth/IBluetoothDeviceCallback.aidl b/core/java/android/bluetooth/IBluetoothDeviceCallback.aidl index 86f44dd..d25bd56 100644 --- a/core/java/android/bluetooth/IBluetoothDeviceCallback.aidl +++ b/core/java/android/bluetooth/IBluetoothDeviceCallback.aidl @@ -21,7 +21,6 @@ package android.bluetooth; */ oneway interface IBluetoothDeviceCallback { - void onCreateBondingResult(in String address, int result); void onGetRemoteServiceChannelResult(in String address, int channel); void onEnableResult(int result); |
