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

Commit 84a3384a authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudioTestApp/Bass: Allow channel selection

Numerical imput allows to set channel preference map.

For example value of 3 (0b11) selects channel #1 and #2,
4 (0b100) selects channel #3 and so on.

Tag: #feature
Bug: 240885642
Test: manual - logs verification
Change-Id: I0a5ed3c2b8b9b12a7df9848fc947cb3aecfdcdf4
parent 7de61c7a
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ package com.android.bluetooth.leaudio;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeBroadcastChannel;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastSubgroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -36,6 +38,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.Objects;
import java.util.List;


public class BroadcastScanActivity extends AppCompatActivity {
@@ -85,6 +88,10 @@ public class BroadcastScanActivity extends AppCompatActivity {
                View alertView =
                        inflater.inflate(R.layout.broadcast_scan_add_encrypted_source_dialog,
                                         null);

                final EditText channels_input_text =
                        alertView.findViewById(R.id.broadcast_channel_map);

                final EditText code_input_text =
                        alertView.findViewById(R.id.broadcast_code_input);
                BluetoothLeBroadcastMetadata.Builder builder = new
@@ -119,6 +126,27 @@ public class BroadcastScanActivity extends AppCompatActivity {
                               .build();
                    }

                    if ((channels_input_text.getText() != null)
                            && (channels_input_text.getText().length() != 0)) {
                        int channelMap = Integer.parseInt(channels_input_text.getText().toString());
                        // Apply a single channel map preference to all subgroups
                        for (BluetoothLeBroadcastSubgroup subGroup : metadata.getSubgroups()) {
                            List<BluetoothLeBroadcastChannel> channels = subGroup.getChannels();
                            for (int i = 0; i < channels.size(); i++) {
                                BluetoothLeBroadcastChannel channel = channels.get(i);
                                // Set the channel preference value according to the map
                                if (channel.getChannelIndex() != 0) {
                                    if ((channelMap & (1 << (channel.getChannelIndex() - 1))) != 0) {
                                        BluetoothLeBroadcastChannel.Builder bob
                                                = new BluetoothLeBroadcastChannel.Builder(channel);
                                        bob.setSelected(true);
                                        channels.set(i, bob.build());
                                    }
                                }
                            }
                        }
                    }

                    Toast.makeText(recyclerView.getContext(), "Adding broadcast source"
                                    + " broadcastId=" + broadcastId, Toast.LENGTH_SHORT).show();
                    mViewModel.addBroadcastSource(device, metadata);
+21 −0
Original line number Diff line number Diff line
@@ -29,4 +29,25 @@
            android:inputType="textMultiLine|textFilter" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textViewChannelMap"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Channel Map:" />
        <EditText
            android:id="@+id/broadcast_channel_map"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:digits="123456789"
            android:inputType="number"
            android:maxLength="3"/>
    </LinearLayout>

</LinearLayout>