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

Commit 9545810f authored by Sal Savage's avatar Sal Savage
Browse files

Update test node constructor to use random UUID

BrowseNode has a device based constructor, which is used by tests to
create nodes. Its not current used anywhere for real during AVRCP
browsing with real devices (the state machine doesn't call the
onConnected() function that calls it in BrowseTree). This constructor
should still use the UUID based method for creating a media id.

In the future, we can use this constructor directly in code as well.

Bug: 332367017
Bug: 363009246
Test: atest BrowseNodeTest.java
Change-Id: I78818607bb3c32dd684cd4a4d3ea95e67fc53fe6
parent a1bc39ed
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -182,12 +182,13 @@ public class BrowseTree {
        }
        }


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

            AvrcpItem.Builder aid = new AvrcpItem.Builder();
            AvrcpItem.Builder aid = new AvrcpItem.Builder();
            aid.setDevice(device);
            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.setDisplayableName(Utils.getName(device));
            aid.setTitle(Utils.getName(device));
            aid.setTitle(Utils.getName(device));
            aid.setBrowsable(true);
            aid.setBrowsable(true);
+32 −0
Original line number Original line Diff line number Diff line
@@ -21,13 +21,18 @@ import static com.google.common.truth.Truth.assertThat;
import android.annotation.SuppressLint;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
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.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.AndroidJUnit4;


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


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


@@ -41,6 +46,8 @@ public class BrowseNodeTest {
    private static final String TEST_UUID = "1111";
    private static final String TEST_UUID = "1111";
    private static final String TEST_NAME = "item";
    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 final byte[] mTestAddress = new byte[] {01, 01, 01, 01, 01, 01};
    private BluetoothAdapter mAdapter;
    private BluetoothAdapter mAdapter;
    private BluetoothDevice mTestDevice = null;
    private BluetoothDevice mTestDevice = null;
@@ -72,6 +79,31 @@ public class BrowseNodeTest {
        assertThat(browseNode.isBrowsable()).isTrue();
        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
    @Test
    public void getExpectedChildren() {
    public void getExpectedChildren() {
        int expectedChildren = 10;
        int expectedChildren = 10;