summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java14
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java11
2 files changed, 25 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
index 3c36c4438bca..145b62cd12b5 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
@@ -74,6 +74,9 @@ public class BluetoothUtils {
ImmutableSet.of(
BluetoothProfile.A2DP, BluetoothProfile.LE_AUDIO, BluetoothProfile.HEARING_AID);
+ private static final String TEMP_BOND_TYPE = "TEMP_BOND_TYPE";
+ private static final String TEMP_BOND_DEVICE_METADATA_VALUE = "le_audio_sharing";
+
private static ErrorListener sErrorListener;
public static int getConnectionStateSummary(int connectionState) {
@@ -1138,4 +1141,15 @@ public class BluetoothUtils {
}
return saDevice;
}
+
+ /**
+ * Verifies if the device is temporary bond in audio sharing.
+ *
+ * @param bluetoothDevice the BluetoothDevice to verify
+ * @return if the device is temporary bond
+ */
+ public static boolean isTemporaryBondDevice(@Nullable BluetoothDevice bluetoothDevice) {
+ String metadataValue = getFastPairCustomizedField(bluetoothDevice, TEMP_BOND_TYPE);
+ return Objects.equals(metadataValue, TEMP_BOND_DEVICE_METADATA_VALUE);
+ }
}
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
index ab9f871444b4..d49447f05011 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
@@ -96,6 +96,7 @@ public class BluetoothUtilsTest {
private Context mContext;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private static final String STRING_METADATA = "string_metadata";
+ private static final String LE_AUDIO_SHARING_METADATA = "le_audio_sharing";
private static final String BOOL_METADATA = "true";
private static final String INT_METADATA = "25";
private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25;
@@ -104,6 +105,8 @@ public class BluetoothUtilsTest {
"<HEARABLE_CONTROL_SLICE_WITH_WIDTH>"
+ STRING_METADATA
+ "</HEARABLE_CONTROL_SLICE_WITH_WIDTH>";
+ private static final String TEMP_BOND_METADATA =
+ "<TEMP_BOND_TYPE>" + LE_AUDIO_SHARING_METADATA + "</TEMP_BOND_TYPE>";
private static final String TEST_EXCLUSIVE_MANAGER_PACKAGE = "com.test.manager";
private static final String TEST_EXCLUSIVE_MANAGER_COMPONENT = "com.test.manager/.component";
private static final int TEST_BROADCAST_ID = 25;
@@ -1303,4 +1306,12 @@ public class BluetoothUtilsTest {
assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isTrue();
}
+
+ @Test
+ public void isTemporaryBondDevice_hasMetadata_returnsTrue() {
+ when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS))
+ .thenReturn(TEMP_BOND_METADATA.getBytes());
+
+ assertThat(BluetoothUtils.isTemporaryBondDevice(mBluetoothDevice)).isTrue();
+ }
}