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

Commit f4eff67b authored by Jack He's avatar Jack He Committed by Gerrit Code Review
Browse files

Merge "Accumulative fixes for LE audio test app"

parents d4457849 0f409764
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -374,6 +374,7 @@ public class BluetoothProxy {

        @Override
        public void onSourceFound(BluetoothLeBroadcastMetadata source) {
            Log.d("BluetoothProxy", "onSourceFound");
            if (mBassEventListener != null) {
                mBassEventListener.onSourceFound(source);
            }
@@ -401,6 +402,7 @@ public class BluetoothProxy {
        @Override
        public void onReceiveStateChanged(BluetoothDevice sink, int sourceId,
                BluetoothLeBroadcastReceiveState state) {
            Log.d("BluetoothProxy", "onReceiveStateChanged");
            if (allLeAudioDevicesMutable.getValue() != null) {
                Optional<LeAudioDeviceStateWrapper> valid_device_opt = allLeAudioDevicesMutable
                        .getValue().stream()
@@ -437,7 +439,7 @@ public class BluetoothProxy {
                 *
                 * Broadcast receiver's endpoint identifier.
                 */

                synchronized(this) {
                    HashMap<Integer, BluetoothLeBroadcastReceiveState> states =
                            svc_data.receiverStatesMutable.getValue();
                    if (states == null)
@@ -448,7 +450,9 @@ public class BluetoothProxy {
                    // synchronous due to getValue() we do here as well
                    // Otherwise we could miss the update and store only the last
                    // receiver ID
                svc_data.receiverStatesMutable.setValue(states);
//                    svc_data.receiverStatesMutable.setValue(states);
                    svc_data.receiverStatesMutable.postValue(states);
                }
            }
        }
    };
@@ -642,6 +646,8 @@ public class BluetoothProxy {
        profileListener = new BluetoothProfile.ServiceListener() {
            @Override
            public void onServiceConnected(int i, BluetoothProfile bluetoothProfile) {
                Log.d("BluetoothProxy", "onServiceConnected(): i = " + i + " bluetoothProfile = " +
                        bluetoothProfile);
                switch (i) {
                    case BluetoothProfile.CSIP_SET_COORDINATOR:
                        bluetoothCsis = (BluetoothCsipSetCoordinator) bluetoothProfile;
@@ -670,6 +676,7 @@ public class BluetoothProxy {
                        mBluetoothLeBroadcast.registerCallback(mExecutor, mBroadcasterCallback);
                        break;
                    case BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT:
                        Log.d("BluetoothProxy", "LE_AUDIO_BROADCAST_ASSISTANT Service connected");
                        mBluetoothLeBroadcastAssistant = (BluetoothLeBroadcastAssistant)
                                bluetoothProfile;
                        mBluetoothLeBroadcastAssistant.registerCallback(mExecutor,
@@ -1364,7 +1371,10 @@ public class BluetoothProxy {
    }

    public int getMaximumNumberOfBroadcast() {
        if (mBluetoothLeBroadcast == null) return 0;
        if (mBluetoothLeBroadcast == null) {
            Log.d("BluetoothProxy", "mBluetoothLeBroadcast is null");
            return 0;
        }
        return mBluetoothLeBroadcast.getMaximumNumberOfBroadcasts();
    }

+3 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package com.android.bluetooth.leaudio;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -114,7 +115,8 @@ public class BroadcastItemsAdapter
            if (mBroadcastPlaybackMap.containsKey(broadcastId)) {
                continue;
            }
            mBroadcastPlaybackMap.remove(broadcastId);
//          mBroadcastPlaybackMap.remove(broadcastId);
            mBroadcastPlaybackMap.put(broadcastId, false);
        }
        notifyDataSetChanged();
    }
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public class BroadcastScanViewModel extends AndroidViewModel {
        @Override
        public void onSourceFound(BluetoothLeBroadcastMetadata source) {
            mScanSessionBroadcasts.put(source.getBroadcastId(), source);
            refreshBroadcasts();
        }

        @Override
+40 −3
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.res.Resources;
import android.os.ParcelUuid;
import android.text.InputFilter;
import android.text.InputType;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -671,16 +672,27 @@ public class LeAudioRecycleViewAdapter
            Map<Integer, BluetoothLeBroadcastReceiveState> states =
                    leAudioDeviceStateWrapper.bassData.receiverStatesMutable.getValue();

            Log.d("LeAudioRecycleViewAdapter",
                    "BluetoothLeBroadcastReceiveState " + holder.bassReceiverIdSpinner.getSelectedItem());
            if (states != null) {
                if (states.containsKey(receiver_id)) {
                    BluetoothLeBroadcastReceiveState state =
                            states.get(holder.bassReceiverIdSpinner.getSelectedItem());
                    final int paSyncState = state.getPaSyncState();
                    final int bigEncryptionState = state.getBigEncryptionState();
                    int paSyncState = state.getPaSyncState();
                    int bigEncryptionState = state.getBigEncryptionState();

                    Resources res = this.parent.getResources();
                    String stateName = null;

                    if (paSyncState == 0xffff) {// invalid sync state
                        paSyncState = PA_SYNC_STATE_IDLE;
                    }
                    if (bigEncryptionState == 0xffff) {// invalid encryption state
                        bigEncryptionState = BIG_ENCRYPTION_STATE_NOT_ENCRYPTED;
                    }
                    Log.d("LeAudioRecycleViewAdapter", "paSyncState " + paSyncState +
                            " bigEncryptionState" + bigEncryptionState);

                    // Set the icon
                    if (paSyncState == PA_SYNC_STATE_IDLE) {
                        holder.bassScanButton.setImageResource(R.drawable.ic_cast_black_24dp);
@@ -1754,6 +1766,11 @@ public class LeAudioRecycleViewAdapter
                    alert.setTitle("Scan and add a source or remove the currently set one.");

                    BluetoothDevice device = devices.get(ViewHolder.this.getAdapterPosition()).device;
                    if (bassReceiverIdSpinner.getSelectedItem() == null) {
                        Toast.makeText(view.getContext(), "Not available",
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    int receiver_id = Integer.parseInt(bassReceiverIdSpinner.getSelectedItem().toString());

                    alert.setPositiveButton("Scan", (dialog, whichButton) -> {
@@ -1780,6 +1797,11 @@ public class LeAudioRecycleViewAdapter
                    alert.setView(pass_input_view);

                    BluetoothDevice device = devices.get(ViewHolder.this.getAdapterPosition()).device;
                    if (bassReceiverIdSpinner.getSelectedItem() == null) {
                        Toast.makeText(view.getContext(), "Not available",
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    int receiver_id = Integer.parseInt(bassReceiverIdSpinner.getSelectedItem().toString());

                    alert.setPositiveButton("Set", (dialog, whichButton) -> {
@@ -1796,6 +1818,11 @@ public class LeAudioRecycleViewAdapter
                    alert.setTitle("Stop the synchronization?");

                    BluetoothDevice device = devices.get(ViewHolder.this.getAdapterPosition()).device;
                    if (bassReceiverIdSpinner.getSelectedItem() == null) {
                        Toast.makeText(view.getContext(), "Not available",
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    int receiver_id = Integer.parseInt(bassReceiverIdSpinner.getSelectedItem().toString());

                    alert.setPositiveButton("Yes", (dialog, whichButton) -> {
@@ -1816,10 +1843,15 @@ public class LeAudioRecycleViewAdapter
                    AlertDialog.Builder alert = new AlertDialog.Builder(itemView.getContext());
                    alert.setTitle("Retry broadcast audio announcement scan?");

                    if (bassReceiverIdSpinner.getSelectedItem() == null) {
                        Toast.makeText(view.getContext(), "Not available",
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    int receiver_id = Integer.parseInt(bassReceiverIdSpinner.getSelectedItem().toString());
                    alert.setPositiveButton("Yes", (dialog, whichButton) -> {
                        // Scan for new announcements
                        Intent intent = new Intent(view.getContext(), BroadcastScanActivity.class);
                        int receiver_id = Integer.parseInt(bassReceiverIdSpinner.getSelectedItem().toString());
                        intent.putExtra(EXTRA_BASS_RECEIVER_ID, receiver_id);
                        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, devices.get(ViewHolder.this.getAdapterPosition()).device);
                        parent.startActivityForResult(intent, 666);
@@ -1834,6 +1866,11 @@ public class LeAudioRecycleViewAdapter
                    alert.setTitle("Stop the synchronization?");

                    BluetoothDevice device = devices.get(ViewHolder.this.getAdapterPosition()).device;
                    if (bassReceiverIdSpinner.getSelectedItem() == null) {
                        Toast.makeText(view.getContext(), "Not available",
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    int receiver_id = Integer.parseInt(bassReceiverIdSpinner.getSelectedItem().toString());

                    alert.setPositiveButton("Yes", (dialog, whichButton) -> {
+2 −2
Original line number Diff line number Diff line
@@ -138,14 +138,14 @@ public class LeAudioViewModel extends AndroidViewModel {

    public boolean removeBroadcastSource(BluetoothDevice sink, int receiver_id) {
        // TODO: Find source ID from receiver_id. What is receiver_id?
        int sourceId = 0;
        int sourceId = receiver_id;
        return bluetoothProxy.removeBroadcastSource(sink, sourceId);
    }

    public boolean setBroadcastCode(BluetoothDevice sink, int receiver_id, byte[] bcast_code) {
        // TODO: Find source ID from receiver_id. What is receiver_id?
        // TODO: Build BluetoothLeBroadcastMetadata with the new bcast_code.
        int sourceId = 0;
        int sourceId = receiver_id;
        BluetoothLeBroadcastMetadata metadata = null;
        return bluetoothProxy.modifyBroadcastSource(sink, sourceId, metadata);
    }