Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40e16b58 authored by Ze Li's avatar Ze Li
Browse files

[Temp bonding] Function to verify if the device is temporary bonding

Test: atest: com.android.settingslib.bluetooth.BluetoothUtilsTest
Bug: 362859132
Flag: EXEMPT utils function
Change-Id: I28601c53b0cd9350a4ee7cbac3b2bfb94177a378
parent 00b503d4
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -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();
    }
}