diff options
| author | Myles Watson <mylesgw@google.com> | 2022-01-21 10:15:31 -0800 |
|---|---|---|
| committer | Chienyuan Huang <chienyuanhuang@google.com> | 2022-01-27 04:13:37 +0000 |
| commit | e1d39b906f399f3663692f1af04d22a491fda94c (patch) | |
| tree | 212c1daf7e2050f780cdf33b21ae6fe3801676b0 /framework/java/android/bluetooth/BluetoothDevice.java | |
| parent | d172303657c7b212a8d305642b00f2f05f8ca6a0 (diff) | |
Add getRemoteLeDevice to specify ADDRESS_TYPE
Bug: 215724286
Test: cts
Tag: #feature
Change-Id: Id6415cf5f0236a82cb294538c22b5dc22555a6ff
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothDevice.java')
| -rw-r--r-- | framework/java/android/bluetooth/BluetoothDevice.java | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java index 434f4c531d..7e8f009eed 100644 --- a/framework/java/android/bluetooth/BluetoothDevice.java +++ b/framework/java/android/bluetooth/BluetoothDevice.java @@ -1194,28 +1194,46 @@ public final class BluetoothDevice implements Parcelable, Attributable { }; /** - * Create a new BluetoothDevice + * Create a new BluetoothDevice. * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB", * and is validated in this constructor. * * @param address valid Bluetooth MAC address - * @param attributionSource attribution for permission-protected calls + * @param addressType valid address type * @throws RuntimeException Bluetooth is not available on this platform - * @throws IllegalArgumentException address is invalid + * @throws IllegalArgumentException address or addressType is invalid * @hide */ - @UnsupportedAppUsage - /*package*/ BluetoothDevice(String address) { + /*package*/ BluetoothDevice(String address, int addressType) { getService(); // ensures sService is initialized if (!BluetoothAdapter.checkBluetoothAddress(address)) { throw new IllegalArgumentException(address + " is not a valid Bluetooth address"); } + if (addressType != ADDRESS_TYPE_PUBLIC && addressType != ADDRESS_TYPE_RANDOM) { + throw new IllegalArgumentException(addressType + " is not a Bluetooth address type"); + } + mAddress = address; - mAddressType = ADDRESS_TYPE_PUBLIC; + mAddressType = addressType; mAttributionSource = AttributionSource.myAttributionSource(); } + /** + * Create a new BluetoothDevice. + * Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB", + * and is validated in this constructor. + * + * @param address valid Bluetooth MAC address + * @throws RuntimeException Bluetooth is not available on this platform + * @throws IllegalArgumentException address is invalid + * @hide + */ + @UnsupportedAppUsage + /*package*/ BluetoothDevice(String address) { + this(address, ADDRESS_TYPE_PUBLIC); + } + /** {@hide} */ public void setAttributionSource(@NonNull AttributionSource attributionSource) { mAttributionSource = attributionSource; |
