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

Commit c74eee81 authored by Grzegorz Kolodziejczyk's avatar Grzegorz Kolodziejczyk Committed by Gerrit Code Review
Browse files

Merge "BroadcastReceiveState: improve receive state logging" into main

parents 9230d25a c568ea85
Loading
Loading
Loading
Loading
+11 −22
Original line number Diff line number Diff line
@@ -783,11 +783,11 @@ public class BassClientStateMachine extends StateMachine {
                );
            }
        } else {
            byte metaDataSyncState = receiverState[BassConstants.BCAST_RCVR_STATE_PA_SYNC_IDX];
            byte encryptionStatus = receiverState[BassConstants.BCAST_RCVR_STATE_ENC_STATUS_IDX];
            byte paSyncState = receiverState[BassConstants.BCAST_RCVR_STATE_PA_SYNC_IDX];
            byte bigEncryptionStatus = receiverState[BassConstants.BCAST_RCVR_STATE_ENC_STATUS_IDX];
            byte[] badBroadcastCode = null;
            int badBroadcastCodeLen = 0;
            if (encryptionStatus
            if (bigEncryptionStatus
                    == BluetoothLeBroadcastReceiveState.BIG_ENCRYPTION_STATE_BAD_CODE) {
                badBroadcastCode = new byte[BassConstants.BCAST_RCVR_STATE_BADCODE_SIZE];
                System.arraycopy(
@@ -804,13 +804,13 @@ public class BassClientStateMachine extends StateMachine {
                    + badBroadcastCodeLen + 1;
            ArrayList<BluetoothLeAudioContentMetadata> metadataList =
                    new ArrayList<BluetoothLeAudioContentMetadata>();
            ArrayList<Long> audioSyncState = new ArrayList<Long>();
            ArrayList<Long> bisSyncState = new ArrayList<Long>();
            for (int i = 0; i < numSubGroups; i++) {
                byte[] audioSyncIndex = new byte[BassConstants.BCAST_RCVR_STATE_BIS_SYNC_SIZE];
                System.arraycopy(receiverState, offset, audioSyncIndex, 0,
                byte[] bisSyncIndex = new byte[BassConstants.BCAST_RCVR_STATE_BIS_SYNC_SIZE];
                System.arraycopy(receiverState, offset, bisSyncIndex, 0,
                        BassConstants.BCAST_RCVR_STATE_BIS_SYNC_SIZE);
                offset += BassConstants.BCAST_RCVR_STATE_BIS_SYNC_SIZE;
                audioSyncState.add((long) Utils.byteArrayToInt(audioSyncIndex));
                bisSyncState.add((long) Utils.byteArrayToInt(bisSyncIndex));

                byte metaDataLength = receiverState[offset++];
                if (metaDataLength > 0) {
@@ -851,24 +851,13 @@ public class BassClientStateMachine extends StateMachine {
                    device,
                    sourceAdvSid,
                    broadcastId,
                    (int) metaDataSyncState,
                    (int) encryptionStatus,
                    (int) paSyncState,
                    (int) bigEncryptionStatus,
                    badBroadcastCode,
                    numSubGroups,
                    audioSyncState,
                    bisSyncState,
                    metadataList);
            log("Receiver state: "
                    + "\n\tSource ID: " + sourceId
                    + "\n\tSource Address Type: " + (int) sourceAddressType
                    + "\n\tDevice: " + device
                    + "\n\tSource Adv SID: " + sourceAdvSid
                    + "\n\tBroadcast ID: " + broadcastId
                    + "\n\tMetadata Sync State: " + (int) metaDataSyncState
                    + "\n\tEncryption Status: " + (int) encryptionStatus
                    + "\n\tBad Broadcast Code: " + Arrays.toString(badBroadcastCode)
                    + "\n\tNumber Of Subgroups: " + numSubGroups
                    + "\n\tAudio Sync State: " + audioSyncState
                    + "\n\tMetadata: " + metadataList);
            log(recvState.toString());
        }
        return recvState;
    }
+99 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@@ -185,6 +186,60 @@ public final class BluetoothLeBroadcastReceiveState implements Parcelable {
    private final List<Long> mBisSyncState;
    private final List<BluetoothLeAudioContentMetadata> mSubgroupMetadata;

    private static String paSyncStateToString(int paSyncState) {
        switch (paSyncState) {
            case 0x00:
                return "Not synchronized to PA: [" + Integer.toString(paSyncState) + "]";
            case 0x01:
                return "SyncInfo Request: [" + Integer.toString(paSyncState) + "]";
            case 0x02:
                return "Synchronized to PA: [" + Integer.toString(paSyncState) + "]";
            case 0x03:
                return "Failed to synchronize to PA: [" + Integer.toString(paSyncState) + "]";
            case 0x04:
                return "No PAST: [" + Integer.toString(paSyncState) + "]";
            default:
                return "RFU: [" + Integer.toString(paSyncState) + "]";
        }
    }

    private static String bigEncryptionStateToString(int bigEncryptionState) {
        switch (bigEncryptionState) {
            case 0x00:
                return "Not encrypted: [" + Integer.toString(bigEncryptionState) + "]";
            case 0x01:
                return "Broadcast_Code required: [" + Integer.toString(bigEncryptionState) + "]";
            case 0x02:
                return "Decrypting: [" + Integer.toString(bigEncryptionState) + "]";
            case 0x03:
                return "Bad_Code (incorrect encryption key): ["
                        + Integer.toString(bigEncryptionState)
                        + "]";
            default:
                return "RFU: [" + Integer.toString(bigEncryptionState) + "]";
        }
    }

    private static String bisSyncStateToString(Long bisSyncState, int bisSyncStateIndex) {
        if (bisSyncState == 0) {
            return "Not synchronized to BIS_index["
                    + Integer.toString(bisSyncStateIndex)
                    + "]: ["
                    + String.valueOf(bisSyncState)
                    + "]";
        } else if (bisSyncState > 0 && bisSyncState < 0xFFFFFFFF) {
            return "Synchronized to BIS_index["
                    + Integer.toString(bisSyncStateIndex)
                    + "]: ["
                    + String.valueOf(bisSyncState)
                    + "]";
        } else if (bisSyncState == 0xFFFFFFFF) {
            return "Failed to sync to BIG: [" + String.valueOf(bisSyncState) + "]";
        } else {
            return "[" + String.valueOf(bisSyncState) + "]";
        }
    }

    /**
     * Constructor to create a read-only {@link BluetoothLeBroadcastReceiveState} instance.
     *
@@ -445,6 +500,50 @@ public final class BluetoothLeBroadcastReceiveState implements Parcelable {
        out.writeTypedList(mSubgroupMetadata);
    }

    /**
     * {@inheritDoc}
     *
     * @hide
     */
    @Override
    public String toString() {
        String receiveState =
                ("Receiver state: "
                        + "\n  Source ID:"
                        + mSourceId
                        + "\n  Source Address Type:"
                        + (int) mSourceAddressType
                        + "\n  Source Address:"
                        + mSourceDevice.toString()
                        + "\n  Source Adv SID:"
                        + mSourceAdvertisingSid
                        + "\n  Broadcast ID:"
                        + mBroadcastId
                        + "\n  PA Sync State:"
                        + paSyncStateToString(mPaSyncState)
                        + "\n  BIG Encryption Status:"
                        + bigEncryptionStateToString(mBigEncryptionState)
                        + "\n  Bad Broadcast Code:"
                        + Arrays.toString(mBadCode)
                        + "\n  Number Of Subgroups:"
                        + mNumSubgroups);
        for (int i = 0; i < mNumSubgroups; i++) {
            receiveState +=
                    ("\n    Subgroup index:"
                                    + i
                                    + "\n      BIS Sync State:"
                                    + bisSyncStateToString(mBisSyncState.get(i), i))
                            + "\n      Metadata:"
                            + "\n        ProgramInfo:"
                            + mSubgroupMetadata.get(i).getProgramInfo()
                            + "\n        Language:"
                            + mSubgroupMetadata.get(i).getLanguage()
                            + "\n        RawData:"
                            + Arrays.toString(mSubgroupMetadata.get(i).getRawMetadata());
        }
        return receiveState;
    }

    /**
     * A {@link Parcelable.Creator} to create {@link BluetoothLeBroadcastReceiveState} from parcel.
     * @hide