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

Commit 36475f25 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I96f7eb8f,If7629907,Icabe59ef,I8afaaf1c,I0a5ed3c2, ... into tm-qpr-dev

* changes:
  LeAudioTestApp: Allow for short broadcast codes
  Broadcaster: Handle short broadcast codes
  Bass: Handle short broadcast codes
  Bass: Fix reversed broadcast code
  LeAudioTestApp/Bass: Allow channel selection
  Bass: Fix BIS sync state channel map
parents 8c994401 817095e1
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -1130,10 +1130,17 @@ static void CreateBroadcastNative(JNIEnv* env, jobject object,
  std::shared_lock<std::shared_timed_mutex> lock(sBroadcasterInterfaceMutex);
  if (!sLeAudioBroadcasterInterface) return;

  std::array<uint8_t, 16> code_array{};
  std::array<uint8_t, 16> code_array{0};
  if (broadcast_code) {
    jsize size = env->GetArrayLength(broadcast_code);
    env->GetByteArrayRegion(broadcast_code, 0, size, (jbyte*)code_array.data());
    if (size > 16) {
      ALOGE("%s: broadcast code to long", __func__);
      return;
    }

    // Padding with zeros on LSB positions if code is shorter than 16 octets
    env->GetByteArrayRegion(broadcast_code, code_array.size() - size, size,
                            (jbyte*)code_array.data());
  }

  jbyte* meta = env->GetByteArrayElements(metadata, nullptr);
+20 −0
Original line number Diff line number Diff line
@@ -1041,6 +1041,7 @@ public class BassClientService extends ProfileService {
            return;
        }

        byte[] code = sourceMetadata.getBroadcastCode();
        for (BluetoothDevice device : devices) {
            BassClientStateMachine stateMachine = getOrCreateStateMachine(device);
            if (stateMachine == null) {
@@ -1070,6 +1071,15 @@ public class BassClientService extends ProfileService {
                        BluetoothStatusCodes.ERROR_LE_BROADCAST_ASSISTANT_DUPLICATE_ADDITION);
                continue;
            }
            if ((code != null) && (code.length != 0)) {
                if ((code.length > 16) || (code.length < 4)) {
                    log("Invalid broadcast code length: " + code.length
                            + ", should be between 4 and 16 octets");
                    mCallbacks.notifySourceAddFailed(device, sourceMetadata,
                            BluetoothStatusCodes.ERROR_BAD_PARAMETERS);
                    continue;
                }
            }

            if (isGroupOp) {
                enqueueSourceGroupOp(device, BassClientStateMachine.ADD_BCAST_SOURCE,
@@ -1104,6 +1114,7 @@ public class BassClientService extends ProfileService {
            return;
        }

        byte[] code = updatedMetadata.getBroadcastCode();
        for (Map.Entry<BluetoothDevice, Integer> deviceSourceIdPair : devices.entrySet()) {
            BluetoothDevice device = deviceSourceIdPair.getKey();
            Integer deviceSourceId = deviceSourceIdPair.getValue();
@@ -1127,6 +1138,15 @@ public class BassClientService extends ProfileService {
                        BluetoothStatusCodes.ERROR_REMOTE_LINK_ERROR);
                continue;
            }
            if ((code != null) && (code.length != 0)) {
                if ((code.length > 16) || (code.length < 4)) {
                    log("Invalid broadcast code length: " + code.length
                            + ", should be between 4 and 16 octets");
                    mCallbacks.notifySourceModifyFailed(device, sourceId,
                            BluetoothStatusCodes.ERROR_BAD_PARAMETERS);
                    continue;
                }
            }
            if (stateMachine.hasPendingSourceOperation()) {
                throw new IllegalStateException("modifySource: source operation already pending");
            }
+15 −15
Original line number Diff line number Diff line
@@ -1225,7 +1225,11 @@ public class BassClientStateMachine extends StateMachine {
        int bisSync = 0;
        for (BluetoothLeBroadcastChannel channel : channels) {
            if (channel.isSelected()) {
                bisSync |= 1 << channel.getChannelIndex();
                if (channel.getChannelIndex() == 0) {
                    Log.e(TAG, "getBisSyncFromChannelPreference: invalid channel index=0");
                    continue;
                }
                bisSync |= 1 << (channel.getChannelIndex() - 1);
            }
        }

@@ -1290,16 +1294,6 @@ public class BassClientStateMachine extends StateMachine {
            stream.write(metadata.getRawMetadata(), 0, metadata.getRawMetadata().length);
        }

        if (metaData.isEncrypted() && metaData.getBroadcastCode().length == 16) {
            if (metaData.getBroadcastCode().length != 16) {
                Log.e(TAG, "Delivered invalid length of broadcast code: " +
                      metaData.getBroadcastCode().length + ", should be 16");
                return null;
            }

            mSetBroadcastCodePending = true;
        }

        byte[] res = stream.toByteArray();
        log("ADD_BCAST_SOURCE in Bytes");
        BassUtils.printByteArray(res);
@@ -1398,10 +1392,8 @@ public class BassClientStateMachine extends StateMachine {
                    + recvState.getSourceId());
            return null;
        }
        // Can Keep as ASCII as is
        String reversePIN = new StringBuffer(new String(metaData.getBroadcastCode()))
                .reverse().toString();
        byte[] actualPIN = reversePIN.getBytes();
        // Broadcast Code
        byte[] actualPIN = metaData.getBroadcastCode();
        if (actualPIN == null) {
            Log.e(TAG, "actual PIN is null");
            return null;
@@ -1409,6 +1401,8 @@ public class BassClientStateMachine extends StateMachine {
            log("byte array broadcast Code:" + Arrays.toString(actualPIN));
            log("pinLength:" + actualPIN.length);
            // Broadcast_Code, Fill the PIN code in the Last Position
            // This effectively adds padding zeros to LSB positions when the broadcast code
            // is shorter than 16 octets
            System.arraycopy(
                    actualPIN, 0, res,
                    (BassConstants.PIN_CODE_CMD_LEN - actualPIN.length), actualPIN.length);
@@ -1545,6 +1539,9 @@ public class BassClientStateMachine extends StateMachine {
                        mBluetoothGatt.writeCharacteristic(mBroadcastScanControlPoint);
                        mPendingOperation = message.what;
                        mPendingMetadata = metaData;
                        if (metaData.isEncrypted() && (metaData.getBroadcastCode() != null)) {
                            mSetBroadcastCodePending = true;
                        }
                        transitionTo(mConnectedProcessing);
                        sendMessageDelayed(GATT_TXN_TIMEOUT, BassConstants.GATT_TXN_TIMEOUT_MS);
                    } else {
@@ -1572,6 +1569,9 @@ public class BassClientStateMachine extends StateMachine {
                        if (paSync == BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_IDLE) {
                            setPendingRemove(sourceId, true);
                        }
                        if (metaData.isEncrypted() && (metaData.getBroadcastCode() != null)) {
                            mSetBroadcastCodePending = true;
                        }
                        mPendingMetadata = metaData;
                        transitionTo(mConnectedProcessing);
                        sendMessageDelayed(GATT_TXN_TIMEOUT, BassConstants.GATT_TXN_TIMEOUT_MS);
+9 −0
Original line number Diff line number Diff line
@@ -664,6 +664,15 @@ public class LeAudioService extends ProfileService {
            Log.w(TAG, "Native interface not available.");
            return;
        }
        boolean isEncrypted = (broadcastCode != null) && (broadcastCode.length != 0);
        if (isEncrypted) {
            if ((broadcastCode.length > 16) || (broadcastCode.length < 4)) {
                Log.e(TAG, "Invalid broadcast code length. Should be from 4 to 16 octets long.");
                return;
            }
        }

        Log.i(TAG, "createBroadcast: isEncrypted=" + (isEncrypted ? "true" : "false"));
        mLeAudioBroadcasterNativeInterface.createBroadcast(metadata.getRawMetadata(),
                broadcastCode);
    }
+3 −3
Original line number Diff line number Diff line
@@ -299,7 +299,7 @@ public class LeAudioBroadcastServiceTest {
    @Test
    public void testCreateBroadcastNative() {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00};
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        mService.mBroadcastCallbacks.register(mCallbacks);

@@ -314,7 +314,7 @@ public class LeAudioBroadcastServiceTest {
    @Test
    public void testCreateBroadcastNativeFailed() {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00};
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        mService.mBroadcastCallbacks.register(mCallbacks);

@@ -340,7 +340,7 @@ public class LeAudioBroadcastServiceTest {
    @Test
    public void testStartStopBroadcastNative() {
        int broadcastId = 243;
        byte[] code = {0x00, 0x01, 0x00};
        byte[] code = {0x00, 0x01, 0x00, 0x02};

        mService.mBroadcastCallbacks.register(mCallbacks);

Loading