diff options
author | Rahul Sabnis <rahulsabnis@google.com> | 2022-10-25 14:47:18 -0700 |
---|---|---|
committer | Rahul Sabnis <rahulsabnis@google.com> | 2022-12-09 06:58:04 -0800 |
commit | e13772c1745d04dd23535c540796996b47a17686 (patch) | |
tree | 6802623c41b358f50eb18effb844f3208514ddfc | |
parent | 696fabc5da2a427c4fc125abeb460d7baf13d632 (diff) | |
download | sl4a-e13772c1745d04dd23535c540796996b47a17686.tar.gz |
Adds an sl4a event on socket connection state and allows for specifying
a BluetoothDevice object address when bonding OOB
Bug: 261979930
Test: system/gd/cert/run --sl4a_sl4a --clean
Change-Id: If03594cceea399c2c9503a4e3c5e6b9f90c2ad15
2 files changed, 31 insertions, 9 deletions
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java index 8e54d810..6cdea2bc 100644 --- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java +++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java @@ -635,32 +635,39 @@ public class BluetoothConnectionFacade extends RpcReceiver { } /** - * Bond to a device using Out of Band Data over LE transport. + * Bond to a device using Out of Band Data over LE transport. Note that there is a distinction + * between the address with type supplied in the oob data and the address and type of the + * BluetoothDevice object. * - * @param address String representation of address like "00:11:22:33:44:55" + * @param oobDataAddress is the MAC address to be used in the oob data + * @param oobDataAddressType is the BluetoothDevice.AddressType for the oob data MAC address * @param transport String "1", "2", "3" to match TRANSPORT_* * @param c Hex String of the 16 octet confirmation * @param r Hex String of the 16 octet randomizer - * @param addressType type of address provided to match BluetoothDevice#ADDRESS_TYPE_* + * @param address String representation of MAC address for the BluetoothDevice object + * @param addressType the BluetoothDevice.AddressType for the BluetoothDevice object */ @Rpc(description = "Creates and Out of Band LE bond.") - public void bluetoothCreateLeBondOutOfBand(@RpcParameter(name = "address") String address, + public void bluetoothCreateLeBondOutOfBand( + @RpcParameter(name = "oobDataAddress") String oobDataAddress, + @RpcParameter(name = "oobDataAddressType") Integer oobDataAddressType, @RpcParameter(name = "c") String c, @RpcParameter(name = "r") String r, + @RpcParameter(name = "address") String address, @RpcParameter(name = "addressType") @RpcDefault("1") Integer addressType) { Log.d("bluetoothCreateLeBondOutOfBand(" + address + ", " + addressType + "," + c + ", " + r + ")"); BluetoothDevice remoteDevice = mBluetoothAdapter.getRemoteLeDevice(address, addressType); byte[] addressBytes = new byte[7]; int i = 0; - for (String s : address.split(":")) { + for (String s : oobDataAddress.split(":")) { addressBytes[i] = hexStringToByteArray(s)[0]; i++; } - // Inserts the address type if one is provided - if (addressType == BluetoothDevice.ADDRESS_TYPE_PUBLIC - || addressType == BluetoothDevice.ADDRESS_TYPE_RANDOM) { - addressBytes[i] = addressType.byteValue(); + // Inserts the oob address type if one is provided + if (oobDataAddressType == BluetoothDevice.ADDRESS_TYPE_PUBLIC + || oobDataAddressType == BluetoothDevice.ADDRESS_TYPE_RANDOM) { + addressBytes[i] = oobDataAddressType.byteValue(); } OobData p192 = null; diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothSocketConnFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothSocketConnFacade.java index 18ca8588..49efe6cf 100644 --- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothSocketConnFacade.java +++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothSocketConnFacade.java @@ -21,6 +21,7 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothServerSocket; import android.bluetooth.BluetoothSocket; +import android.os.Bundle; import com.googlecode.android_scripting.Log; import com.googlecode.android_scripting.facade.EventFacade; @@ -55,6 +56,9 @@ public class BluetoothSocketConnFacade extends RpcReceiver { private AcceptThread mAcceptThread; private byte mTxPktIndex = 0; + private final Bundle mGoodNews; + private final Bundle mBadNews; + private static final String DEFAULT_PSM = "161"; //=0x00A1 // UUID for SL4A. @@ -68,6 +72,11 @@ public class BluetoothSocketConnFacade extends RpcReceiver { mEventFacade = manager.getReceiver(EventFacade.class); mService = manager.getService(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + + mGoodNews = new Bundle(); + mGoodNews.putBoolean("Status", true); + mBadNews = new Bundle(); + mBadNews.putBoolean("Status", false); } private BluetoothConnection getConnection(String connID) throws IOException { @@ -731,9 +740,15 @@ public class BluetoothSocketConnFacade extends RpcReceiver { mConnUuid = addConnection(conn); Log.d("ConnectThread:run: isConnected=" + mSocket.isConnected() + ", address=" + mSocket.getRemoteDevice().getAddress() + ", uuid=" + mConnUuid); + if (mSocket.isConnected()) { + mEventFacade.postEvent("BluetoothSocketConnectSuccess", mGoodNews); + } else { + mEventFacade.postEvent("BluetoothSocketConnectError", mBadNews); + } } catch (IOException connectException) { Log.e("ConnectThread::run(): Error: Connection Unsuccessful"); cancel(); + mEventFacade.postEvent("BluetoothSocketConnectError", mBadNews); return; } } |