diff options
author | Googler <noreply@google.com> | 2023-11-28 20:43:40 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-11-28 20:44:20 -0800 |
commit | 18d9da31d99667575d00b225c7d9b634f1fbf2ca (patch) | |
tree | 516330bfc2d83d68b897d6ed572a3a0d71142a0f | |
parent | ff6dcc5fc1ab7cb817a13bbea580313785666d83 (diff) | |
download | robolectric-18d9da31d99667575d00b225c7d9b634f1fbf2ca.tar.gz |
Add support for isLeAudioSupported()
This CL adds support for isLeAudioSupported() method in BluetoothAdapter. If the original bluetooth adapter is used in unit tests, then to verify if Le Audio is supported or not, it depends on the bluetooth service and tests fail as there is no control on bluetooth service in test files. Adding setter and getter functions for Le Audio in ShadowBluetoothAdapter helps to overcome this issue.
PiperOrigin-RevId: 586185847
-rw-r--r-- | robolectric/src/test/java/org/robolectric/shadows/ShadowBluetoothAdapterTest.java | 13 | ||||
-rw-r--r-- | shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java | 29 |
2 files changed, 35 insertions, 7 deletions
diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowBluetoothAdapterTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowBluetoothAdapterTest.java index 3e429e5e4..a9c3e8d81 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowBluetoothAdapterTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowBluetoothAdapterTest.java @@ -891,4 +891,17 @@ public class ShadowBluetoothAdapterTest { public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bytes) {} }; } + + @Config(minSdk = TIRAMISU) + @Test + public void canGetAndSetLeAudioSupport() { + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + + // By default LE feature is not supported + assertThat(adapter.isLeAudioSupported()).isEqualTo(BluetoothStatusCodes.FEATURE_NOT_SUPPORTED); + + // set Le audio feature to supported. + shadowOf(adapter).setLeAudioSupported(BluetoothStatusCodes.FEATURE_SUPPORTED); + assertThat(adapter.isLeAudioSupported()).isEqualTo(BluetoothStatusCodes.FEATURE_SUPPORTED); + } } diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java index 90dc027b6..e9d7e4f7b 100644 --- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java +++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBluetoothAdapter.java @@ -100,6 +100,7 @@ public class ShadowBluetoothAdapter { private Duration discoverableTimeout; private boolean isBleScanAlwaysAvailable = true; private boolean isMultipleAdvertisementSupported = true; + private int isLeAudioSupported = BluetoothStatusCodes.FEATURE_NOT_SUPPORTED; private boolean isLeExtendedAdvertisingSupported = true; private boolean isOverridingProxyBehavior; private final Map<Integer, Integer> profileConnectionStateData = new HashMap<>(); @@ -142,12 +143,24 @@ public class ShadowBluetoothAdapter { ClassParameter.from(AttributionSource.class, attributionSource)); } + /** Sets whether the Le Audio is supported or not. Minimum sdk version required is TIRAMISU. */ + public void setLeAudioSupported(int supported) { + isLeAudioSupported = supported; + } + + @Implementation(minSdk = VERSION_CODES.TIRAMISU) + protected int isLeAudioSupported() { + return isLeAudioSupported; + } + /** Determines if getDefaultAdapter() returns the default local adapter (true) or null (false). */ public static void setIsBluetoothSupported(boolean supported) { isBluetoothSupported = supported; } - /** @deprecated use real BluetoothLeAdvertiser instead */ + /** + * @deprecated use real BluetoothLeAdvertiser instead + */ @Deprecated public void setBluetoothLeAdvertiser(BluetoothLeAdvertiser advertiser) { if (RuntimeEnvironment.getApiLevel() <= VERSION_CODES.LOLLIPOP_MR1) { @@ -189,26 +202,26 @@ public class ShadowBluetoothAdapter { protected BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord( String serviceName, UUID uuid) { return ShadowBluetoothServerSocket.newInstance( - BluetoothSocket.TYPE_RFCOMM, /*auth=*/ false, /*encrypt=*/ false, new ParcelUuid(uuid)); + BluetoothSocket.TYPE_RFCOMM, /* auth= */ false, /* encrypt= */ false, new ParcelUuid(uuid)); } @Implementation protected BluetoothServerSocket listenUsingRfcommWithServiceRecord(String serviceName, UUID uuid) throws IOException { return ShadowBluetoothServerSocket.newInstance( - BluetoothSocket.TYPE_RFCOMM, /*auth=*/ false, /*encrypt=*/ true, new ParcelUuid(uuid)); + BluetoothSocket.TYPE_RFCOMM, /* auth= */ false, /* encrypt= */ true, new ParcelUuid(uuid)); } @Implementation(minSdk = Q) protected BluetoothServerSocket listenUsingInsecureL2capChannel() throws IOException { return ShadowBluetoothServerSocket.newInstance( - BluetoothSocket.TYPE_L2CAP, /*auth=*/ false, /*encrypt=*/ true, /*uuid=*/ null); + BluetoothSocket.TYPE_L2CAP, /* auth= */ false, /* encrypt= */ true, /* uuid= */ null); } @Implementation(minSdk = Q) protected BluetoothServerSocket listenUsingL2capChannel() throws IOException { return ShadowBluetoothServerSocket.newInstance( - BluetoothSocket.TYPE_L2CAP, /*auth=*/ false, /*encrypt=*/ true, /*uuid=*/ null); + BluetoothSocket.TYPE_L2CAP, /* auth= */ false, /* encrypt= */ true, /* uuid= */ null); } @Implementation @@ -474,7 +487,9 @@ public class ShadowBluetoothAdapter { this.state = state; } - /** @deprecated Use {@link BluetoothAdapter#enable()} or {@link BluetoothAdapter#disable()}. */ + /** + * @deprecated Use {@link BluetoothAdapter#enable()} or {@link BluetoothAdapter#disable()}. + */ @Deprecated public void setEnabled(boolean enabled) { if (enabled) { @@ -568,7 +583,7 @@ public class ShadowBluetoothAdapter { * Overrides behavior of {@link closeProfileProxy} if {@link * ShadowBluetoothAdapter#setProfileProxy} has been previously called. * - * If the given non-null BluetoothProfile {@code proxy} was previously set for the given {@code + * <p>If the given non-null BluetoothProfile {@code proxy} was previously set for the given {@code * profile} by {@link ShadowBluetoothAdapter#setProfileProxy}, this proxy will be "deactivated". */ @Implementation |