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

Commit 7de9f048 authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

Merge changes I682f1e43,Ib5435169 am: f01a7695

parents 7d1c9055 f01a7695
Loading
Loading
Loading
Loading
+45 −6
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.internal.annotations.VisibleForTesting;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -68,6 +69,7 @@ public class BassClientService extends ProfileService {

    private final Map<BluetoothDevice, BassClientStateMachine> mStateMachines = new HashMap<>();
    private final Object mSearchScanCallbackLock = new Object();
    private final Map<Integer, ScanResult> mScanBroadcasts = new HashMap<>();

    private HandlerThread mStateMachinesThread;
    private HandlerThread mCallbackHandlerThread;
@@ -325,8 +327,16 @@ public class BassClientService extends ProfileService {
    }

    private boolean hasRoomForBroadcastSourceAddition(BluetoothDevice device) {
        List<BluetoothLeBroadcastReceiveState> currentAllSources = getAllSources(device);
        return currentAllSources.size() < getMaximumSourceCapacity(device);
        boolean isRoomAvailable = false;
        String emptyBluetoothDevice = "00:00:00:00:00:00";
        for (BluetoothLeBroadcastReceiveState recvState: getAllSources(device)) {
            if (recvState.getSourceDevice().getAddress().equals(emptyBluetoothDevice)) {
                isRoomAvailable = true;
                break;
            }
        }
        log("isRoomAvailable: " + isRoomAvailable);
        return isRoomAvailable;
    }

    private BassClientStateMachine getOrCreateStateMachine(BluetoothDevice device) {
@@ -632,16 +642,29 @@ public class BassClientService extends ProfileService {
                            BassConstants.BAAS_UUID)) {
                        return;
                    }
                    Message msg = mBassUtils.getAutoAssistScanHandler()
                            .obtainMessage(BassConstants.AA_SCAN_SUCCESS);
                    msg.obj = result;
                    mBassUtils.getAutoAssistScanHandler().sendMessage(msg);
                    log( "Broadcast Source Found:" + result.getDevice());
                    byte[] broadcastIdArray = listOfUuids.get(BassConstants.BAAS_UUID);
                    int broadcastId = (int)(((broadcastIdArray[2] & 0xff) << 16)
                            | ((broadcastIdArray[1] & 0xff) << 8)
                            | (broadcastIdArray[0] & 0xff));
                    if (mScanBroadcasts.get(broadcastId) == null) {
                        log("selectBroadcastSource: broadcastId " + broadcastId);
                        mScanBroadcasts.put(broadcastId, result);
                        synchronized (mStateMachines) {
                            for (BassClientStateMachine sm : mStateMachines.values()) {
                                if (sm.isConnected()) {
                                    selectSource(sm.getDevice(), result, false);
                                }
                            }
                        }
                    }
                }

                public void onScanFailed(int errorCode) {
                    Log.e(TAG, "Scan Failure:" + errorCode);
                }
            };
            mScanBroadcasts.clear();
            ScanSettings settings = new ScanSettings.Builder().setCallbackType(
                    ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
                    .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
@@ -687,6 +710,7 @@ public class BassClientService extends ProfileService {
            scanner.stopScan(mSearchScanCallback);
            mSearchScanCallback = null;
            mCallbacks.notifySearchStopped(BluetoothStatusCodes.REASON_LOCAL_APP_REQUEST);
            mScanBroadcasts.clear();
        }
    }

@@ -792,6 +816,7 @@ public class BassClientService extends ProfileService {
        }
        Message message = stateMachine.obtainMessage(BassClientStateMachine.UPDATE_BCAST_SOURCE);
        message.arg1 = sourceId;
        message.arg2 = BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_INVALID;
        message.obj = updatedMetadata;
        stateMachine.sendMessage(message);
    }
@@ -820,6 +845,20 @@ public class BassClientService extends ProfileService {
                    BluetoothStatusCodes.ERROR_REMOTE_LINK_ERROR);
            return;
        }
        BluetoothLeBroadcastReceiveState recvState =
                stateMachine.getBroadcastReceiveStateForSourceId(sourceId);
        BluetoothLeBroadcastMetadata metaData =
                stateMachine.getCurrentBroadcastMetadata(sourceId);
        if (metaData != null && recvState != null && recvState.getPaSyncState() ==
                BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_SYNCHRONIZED) {
            log("Force source to lost PA sync");
            Message message = stateMachine.obtainMessage(
                    BassClientStateMachine.UPDATE_BCAST_SOURCE);
            message.arg1 = sourceId;
            message.arg2 = BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_IDLE;
            message.obj = metaData;
            stateMachine.sendMessage(message);
        }
        Message message = stateMachine.obtainMessage(BassClientStateMachine.REMOVE_BCAST_SOURCE);
        message.arg1 = sourceId;
        stateMachine.sendMessage(message);
+36 −8
Original line number Diff line number Diff line
@@ -436,7 +436,13 @@ public class BassClientStateMachine extends StateMachine {
                channel.setSelected(false);
                subGroup.addChannel(channel.build());
            }
            subGroup.setCodecId(ByteBuffer.wrap(baseLevel2.codecId).getLong());
            byte[] arrayCodecId = baseLevel2.codecId;
            long codeId = (long) ((arrayCodecId[4] & 0xff) << 32
                    | (arrayCodecId[3] & 0xff) << 24
                    | (arrayCodecId[2] & 0xff) << 16
                    | (arrayCodecId[1] & 0xff) << 8
                    | (arrayCodecId[0] & 0xff));
            subGroup.setCodecId(codeId);
            subGroup.setCodecSpecificConfig(BluetoothLeAudioCodecConfigMetadata.
                    fromRawBytes(baseLevel2.codecConfigInfo));
            subGroup.setContentMetadata(BluetoothLeAudioContentMetadata.
@@ -444,6 +450,18 @@ public class BassClientStateMachine extends StateMachine {
            metaData.addSubgroup(subGroup.build());
        }
        metaData.setSourceDevice(device, device.getAddressType());
        byte[] arrayPresentationDelay = baseData.getLevelOne().presentationDelay;
        int presentationDelay = (int) ((arrayPresentationDelay[2] & 0xff) << 16
                | (arrayPresentationDelay[1] & 0xff)
                | (arrayPresentationDelay[0] & 0xff));
        metaData.setPresentationDelayMicros(presentationDelay);
        PeriodicAdvertisementResult result =
                mService.getPeriodicAdvertisementResult(device);
        if (result != null) {
            int broadcastId = result.getBroadcastId();
            log("broadcast ID: " + broadcastId);
            metaData.setBroadcastId(broadcastId);
        }
        return metaData.build();
    }

@@ -634,6 +652,7 @@ public class BassClientStateMachine extends StateMachine {
            byte metaDataSyncState = receiverState[BassConstants.BCAST_RCVR_STATE_PA_SYNC_IDX];
            byte encryptionStatus = receiverState[BassConstants.BCAST_RCVR_STATE_ENC_STATUS_IDX];
            byte[] badBroadcastCode = null;
            int badBroadcastCodeLen = 0;
            if (encryptionStatus
                    == BluetoothLeBroadcastReceiveState.BIG_ENCRYPTION_STATE_BAD_CODE) {
                badBroadcastCode = new byte[BassConstants.BCAST_RCVR_STATE_BADCODE_SIZE];
@@ -644,11 +663,12 @@ public class BassClientStateMachine extends StateMachine {
                        0,
                        BassConstants.BCAST_RCVR_STATE_BADCODE_SIZE);
                badBroadcastCode = reverseBytes(badBroadcastCode);
                badBroadcastCodeLen = BassConstants.BCAST_RCVR_STATE_BADCODE_SIZE;
            }
            byte numSubGroups = receiverState[BassConstants.BCAST_RCVR_STATE_BADCODE_START_IDX
                    + BassConstants.BCAST_RCVR_STATE_BADCODE_SIZE];
                    + badBroadcastCodeLen];
            int offset = BassConstants.BCAST_RCVR_STATE_BADCODE_START_IDX
                    + BassConstants.BCAST_RCVR_STATE_BADCODE_SIZE + 1;
                    + badBroadcastCodeLen + 1;
            ArrayList<BluetoothLeAudioContentMetadata> metadataList =
                    new ArrayList<BluetoothLeAudioContentMetadata>();
            ArrayList<Long> audioSyncState = new ArrayList<Long>();
@@ -660,7 +680,7 @@ public class BassClientStateMachine extends StateMachine {
                log("BIS index byte array: ");
                BassUtils.printByteArray(audioSyncIndex);
                ByteBuffer wrapped = ByteBuffer.wrap(reverseBytes(audioSyncIndex));
                audioSyncState.add(wrapped.getLong());
                audioSyncState.add((long) wrapped.getInt());

                byte metaDataLength = receiverState[offset++];
                if (metaDataLength > 0) {
@@ -1251,7 +1271,7 @@ public class BassClientStateMachine extends StateMachine {
    }

    private byte[] convertBroadcastMetadataToUpdateSourceByteArray(int sourceId,
            BluetoothLeBroadcastMetadata metaData) {
            BluetoothLeBroadcastMetadata metaData, int paSync) {
        BluetoothLeBroadcastReceiveState existingState =
                getBroadcastReceiveStateForSourceId(sourceId);
        if (existingState == null) {
@@ -1283,7 +1303,9 @@ public class BassClientStateMachine extends StateMachine {
        // Source_ID
        res[offset++] = (byte) sourceId;
        // PA_Sync
        if (existingState.getPaSyncState()
        if (paSync != BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_INVALID) {
            res[offset++] = (byte) paSync;
        } else if (existingState.getPaSyncState()
                == BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_SYNCHRONIZED) {
            res[offset++] = (byte) (0x01);
        } else {
@@ -1295,7 +1317,12 @@ public class BassClientStateMachine extends StateMachine {
        // Num_Subgroups
        res[offset++] = numSubGroups;
        for (int i = 0; i < numSubGroups; i++) {
            int bisIndexValue = existingState.getBisSyncState().get(i).intValue();
            int bisIndexValue;
            if (paSync != BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_INVALID) {
                bisIndexValue = 0;
            } else {
                bisIndexValue = existingState.getBisSyncState().get(i).intValue();
            }
            log("UPDATE_BCAST_SOURCE: bisIndexValue : " + bisIndexValue);
            // BIS_Sync
            res[offset++] = (byte) (bisIndexValue & 0x00000000000000FF);
@@ -1493,9 +1520,10 @@ public class BassClientStateMachine extends StateMachine {
                case UPDATE_BCAST_SOURCE:
                    metaData = (BluetoothLeBroadcastMetadata) message.obj;
                    int sourceId = message.arg1;
                    int paSync = message.arg2;
                    log("Updating Broadcast source" + metaData);
                    byte[] updateSourceInfo = convertBroadcastMetadataToUpdateSourceByteArray(
                            sourceId, metaData);
                            sourceId, metaData, paSync);
                    if (updateSourceInfo == null) {
                        Log.e(TAG, "update source: source Info is NULL");
                        break;