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

Commit adb4b458 authored by Sal Savage's avatar Sal Savage Committed by Gerrit Code Review
Browse files

Merge "Update test node constructor to use random UUID" into main

parents 508141eb 9545810f
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -182,12 +182,13 @@ public class BrowseTree {
        }

        BrowseNode(BluetoothDevice device) {
            mIsPlayer = true;
            String playerKey = PLAYER_PREFIX + device.getAddress().toString();

            AvrcpItem.Builder aid = new AvrcpItem.Builder();
            aid.setDevice(device);
            aid.setUuid(playerKey);
            if (Flags.randomizeDeviceLevelMediaIds()) {
                aid.setUuid(ROOT + device.getAddress().toString() + UUID.randomUUID().toString());
            } else {
                aid.setUuid(PLAYER_PREFIX + device.getAddress().toString());
            }
            aid.setDisplayableName(Utils.getName(device));
            aid.setTitle(Utils.getName(device));
            aid.setBrowsable(true);
+32 −0
Original line number Diff line number Diff line
@@ -21,13 +21,18 @@ import static com.google.common.truth.Truth.assertThat;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.avrcpcontroller.BrowseTree.BrowseNode;
import com.android.bluetooth.flags.Flags;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -41,6 +46,8 @@ public class BrowseNodeTest {
    private static final String TEST_UUID = "1111";
    private static final String TEST_NAME = "item";

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    private final byte[] mTestAddress = new byte[] {01, 01, 01, 01, 01, 01};
    private BluetoothAdapter mAdapter;
    private BluetoothDevice mTestDevice = null;
@@ -72,6 +79,31 @@ public class BrowseNodeTest {
        assertThat(browseNode.isBrowsable()).isTrue();
    }

    @Test
    @DisableFlags(Flags.FLAG_RANDOMIZE_DEVICE_LEVEL_MEDIA_IDS)
    public void constructor_withBluetoothDevice() {
        BrowseNode browseNode = mBrowseTree.new BrowseNode(mTestDevice);

        assertThat(browseNode.getID()).isNotNull();
        assertThat(browseNode.getDevice()).isEqualTo(mTestDevice);
        assertThat(browseNode.isPlayer()).isFalse();
        assertThat(browseNode.isBrowsable()).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_RANDOMIZE_DEVICE_LEVEL_MEDIA_IDS)
    public void constructor_withBluetoothDevice_withRandomUuid() {
        BrowseNode browseNode1 = mBrowseTree.new BrowseNode(mTestDevice);

        assertThat(browseNode1.getID()).isNotNull();
        assertThat(browseNode1.getDevice()).isEqualTo(mTestDevice);
        assertThat(browseNode1.isPlayer()).isFalse();
        assertThat(browseNode1.isBrowsable()).isTrue();

        BrowseNode browseNode2 = mBrowseTree.new BrowseNode(mTestDevice);
        assertThat(browseNode1.getID()).isNotEqualTo(browseNode2.getID());
    }

    @Test
    public void getExpectedChildren() {
        int expectedChildren = 10;