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

Commit 9fed7229 authored by Alice Kuo's avatar Alice Kuo Committed by Android (Google) Code Review
Browse files

Merge changes I109d599d,I407dc781,I28a371af,I45f67767,I23bb0ccf, ... into tm-d1-dev

* changes:
  leaudio: Use common CCID keeper in unicast and broadcast
  leaudio/testapp: Show broadcast ID also in Hex
  leaudio/testapp: Fix crash on registering callbacks
  leaudio/testapp: Fix threading issue on callback calls
  leaudio/testapp: Select Broadcast Audio parameters with context type
  leaudio: Rework selecting Broadcast Audio stream parameters
parents 5db910a8 352ee339
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
#include "com_android_bluetooth.h"
#include "hardware/bt_le_audio.h"

using bluetooth::le_audio::BroadcastAudioProfile;
using bluetooth::le_audio::BroadcastId;
using bluetooth::le_audio::BroadcastState;
using bluetooth::le_audio::btle_audio_codec_config_t;
@@ -1125,7 +1124,7 @@ static void BroadcasterCleanupNative(JNIEnv* env, jobject object) {
}

static void CreateBroadcastNative(JNIEnv* env, jobject object,
                                  jbyteArray metadata, jint audio_profile,
                                  jbyteArray metadata,
                                  jbyteArray broadcast_code) {
  LOG(INFO) << __func__;
  std::shared_lock<std::shared_timed_mutex> lock(sBroadcasterInterfaceMutex);
@@ -1138,7 +1137,6 @@ static void CreateBroadcastNative(JNIEnv* env, jobject object,
  jbyte* meta = env->GetByteArrayElements(metadata, nullptr);
  sLeAudioBroadcasterInterface->CreateBroadcast(
      std::vector<uint8_t>(meta, meta + env->GetArrayLength(metadata)),
      static_cast<BroadcastAudioProfile>(audio_profile),
      broadcast_code ? std::optional<std::array<uint8_t, 16>>(code_array)
                     : std::nullopt);
  env->ReleaseByteArrayElements(metadata, meta, 0);
@@ -1198,7 +1196,7 @@ static JNINativeMethod sBroadcasterMethods[] = {
    {"initNative", "()V", (void*)BroadcasterInitNative},
    {"stopNative", "()V", (void*)BroadcasterStopNative},
    {"cleanupNative", "()V", (void*)BroadcasterCleanupNative},
    {"createBroadcastNative", "([BI[B)V", (void*)CreateBroadcastNative},
    {"createBroadcastNative", "([B[B)V", (void*)CreateBroadcastNative},
    {"updateMetadataNative", "(I[B)V", (void*)UpdateMetadataNative},
    {"startBroadcastNative", "(I)V", (void*)StartBroadcastNative},
    {"stopBroadcastNative", "(I)V", (void*)StopBroadcastNative},
+3 −4
Original line number Diff line number Diff line
@@ -169,12 +169,11 @@ public class LeAudioBroadcasterNativeInterface {
     * Creates LeAudio Broadcast instance.
     *
     * @param metadata metadata buffer with TLVs
     * @param audioProfile broadcast audio profile
     * @param broadcastCode optional code if broadcast should be encrypted
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public void createBroadcast(byte[] metadata, int audioProfile, byte[] broadcastCode) {
        createBroadcastNative(metadata, audioProfile, broadcastCode);
    public void createBroadcast(byte[] metadata, byte[] broadcastCode) {
        createBroadcastNative(metadata, broadcastCode);
    }

    /**
@@ -241,7 +240,7 @@ public class LeAudioBroadcasterNativeInterface {
    private native void initNative();
    private native void stopNative();
    private native void cleanupNative();
    private native void createBroadcastNative(byte[] metadata, int profile, byte[] broadcastCode);
    private native void createBroadcastNative(byte[] metadata, byte[] broadcastCode);
    private native void updateMetadataNative(int broadcastId, byte[] metadata);
    private native void startBroadcastNative(int broadcastId);
    private native void stopBroadcastNative(int broadcastId);
+1 −9
Original line number Diff line number Diff line
@@ -105,12 +105,6 @@ public class LeAudioService extends ProfileService {
     */
    private static final int ACTIVE_CONTEXTS_NONE = 0;

    /*
     * Brodcast profile used by the lower layers
     */
    private static final int BROADCAST_PROFILE_SONIFICATION = 0;
    private static final int BROADCAST_PROFILE_MEDIA = 1;

    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private HandlerThread mStateMachinesThread;
@@ -662,8 +656,6 @@ public class LeAudioService extends ProfileService {
    /**
     * Creates LeAudio Broadcast instance.
     * @param metadata metadata buffer with TLVs
     * @param audioProfile broadcast audio profile
     * @param broadcastCode optional code if broadcast should be encrypted
     */
    public void createBroadcast(BluetoothLeAudioContentMetadata metadata, byte[] broadcastCode) {
        if (mLeAudioBroadcasterNativeInterface == null) {
@@ -671,7 +663,7 @@ public class LeAudioService extends ProfileService {
            return;
        }
        mLeAudioBroadcasterNativeInterface.createBroadcast(metadata.getRawMetadata(),
                BROADCAST_PROFILE_MEDIA, broadcastCode);
                broadcastCode);
    }

    /**
+2 −3
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ public class LeAudioBroadcastServiceTest {
            BluetoothLeAudioContentMetadata meta) {
        mService.createBroadcast(meta, code);

        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(1),
        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()),
                eq(code));

        // Check if broadcast is started automatically when created
@@ -321,8 +321,7 @@ public class LeAudioBroadcastServiceTest {
        BluetoothLeAudioContentMetadata meta = meta_builder.build();
        mService.createBroadcast(meta, code);

        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(1),
                eq(code));
        verify(mNativeInterface, times(1)).createBroadcast(eq(meta.getRawMetadata()), eq(code));

        LeAudioStackEvent create_event =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_BROADCAST_CREATED);
+30 −24
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ public class BluetoothProxy {
                                                .equals(groupId))
                                .collect(Collectors.toList());
            for (LeAudioDeviceStateWrapper dev : valid_devices) {
                dev.leAudioData.groupStatusMutable.setValue(
                dev.leAudioData.groupStatusMutable.postValue(
                        new Pair<>(groupId, new Pair<>(groupStatus, 0)));
            }
        }
@@ -112,8 +112,8 @@ public class BluetoothProxy {
            LeAudioDeviceStateWrapper valid_device = valid_device_opt.get();
            LeAudioDeviceStateWrapper.LeAudioData svc_data = valid_device.leAudioData;

            svc_data.nodeStatusMutable.setValue(new Pair<>(groupId, GROUP_NODE_ADDED));
            svc_data.groupStatusMutable.setValue(new Pair<>(groupId, new Pair<>(-1, -1)));
            svc_data.nodeStatusMutable.postValue(new Pair<>(groupId, GROUP_NODE_ADDED));
            svc_data.groupStatusMutable.postValue(new Pair<>(groupId, new Pair<>(-1, -1)));
        }
        @Override
        public void onGroupNodeRemoved(BluetoothDevice device, int groupId) {
@@ -141,8 +141,8 @@ public class BluetoothProxy {
            LeAudioDeviceStateWrapper valid_device = valid_device_opt.get();
            LeAudioDeviceStateWrapper.LeAudioData svc_data = valid_device.leAudioData;

            svc_data.nodeStatusMutable.setValue(new Pair<>(groupId, GROUP_NODE_REMOVED));
            svc_data.groupStatusMutable.setValue(new Pair<>(groupId, new Pair<>(-1, -1)));
            svc_data.nodeStatusMutable.postValue(new Pair<>(groupId, GROUP_NODE_REMOVED));
            svc_data.groupStatusMutable.postValue(new Pair<>(groupId, new Pair<>(-1, -1)));
        }
    };

@@ -155,9 +155,9 @@ public class BluetoothProxy {
                int toState =
                        intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
                if (toState == BluetoothAdapter.STATE_ON) {
                    enabledBluetoothMutable.setValue(true);
                    enabledBluetoothMutable.postValue(true);
                } else if (toState == BluetoothAdapter.STATE_OFF) {
                    enabledBluetoothMutable.setValue(false);
                    enabledBluetoothMutable.postValue(false);
                }
            }
        }
@@ -192,10 +192,10 @@ public class BluetoothProxy {
                                            .postValue(toState == BluetoothLeAudio.STATE_CONNECTED);

                                group_id = bluetoothLeAudio.getGroupId(device);
                                svc_data.nodeStatusMutable.setValue(
                                svc_data.nodeStatusMutable.postValue(
                                        new Pair<>(group_id, GROUP_NODE_ADDED));
                                svc_data.groupStatusMutable
                                        .setValue(new Pair<>(group_id, new Pair<>(-1, -1)));
                                        .postValue(new Pair<>(group_id, new Pair<>(-1, -1)));
                                break;
                            }
                        }
@@ -669,18 +669,30 @@ public class BluetoothProxy {
                        break;
                    case BluetoothProfile.HAP_CLIENT:
                        bluetoothHapClient = (BluetoothHapClient) bluetoothProfile;
                        try {
                            bluetoothHapClient.registerCallback(mExecutor, hapCallback);
                        } catch (IllegalArgumentException e) {
                            Log.e("HAP", "Application callback already registered.");
                        }
                        break;
                    case BluetoothProfile.LE_AUDIO_BROADCAST:
                        mBluetoothLeBroadcast = (BluetoothLeBroadcast) bluetoothProfile;
                        try {
                            mBluetoothLeBroadcast.registerCallback(mExecutor, mBroadcasterCallback);
                        } catch (IllegalArgumentException e) {
                            Log.e("Broadcast", "Application callback already registered.");
                        }
                        break;
                    case BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT:
                        Log.d("BluetoothProxy", "LE_AUDIO_BROADCAST_ASSISTANT Service connected");
                        mBluetoothLeBroadcastAssistant = (BluetoothLeBroadcastAssistant)
                                bluetoothProfile;
                        try {
                            mBluetoothLeBroadcastAssistant.registerCallback(mExecutor,
                                mBroadcastAssistantCallback);
                        } catch (IllegalArgumentException e) {
                            Log.e("BASS", "Application callback already registered.");
                        }
                        break;
                }
                queryLeAudioDevices();
@@ -1222,7 +1234,7 @@ public class BluetoothProxy {

            switchToPreviousPresetMethod.invoke(bluetoothHapClient, device);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        return true;
    }
@@ -1239,7 +1251,7 @@ public class BluetoothProxy {

            switchToNextPresetMethod.invoke(bluetoothHapClient, device);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        return true;
    }
@@ -1256,7 +1268,7 @@ public class BluetoothProxy {

            switchToPreviousPresetForGroupMethod.invoke(bluetoothHapClient, group_id);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        return true;
    }
@@ -1273,7 +1285,7 @@ public class BluetoothProxy {

            switchToNextPresetForGroupMethod.invoke(bluetoothHapClient, group_id);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Do nothing
            return false;
        }
        return true;
    }
@@ -1335,16 +1347,10 @@ public class BluetoothProxy {
        return mBroadcastStatusMutableLive;
    }

    public boolean startBroadcast(String programInfo, byte[] code) {
    public boolean startBroadcast(BluetoothLeAudioContentMetadata meta, byte[] code) {
        if (mBluetoothLeBroadcast == null)
            return false;

        BluetoothLeAudioContentMetadata.Builder contentBuilder =
                new BluetoothLeAudioContentMetadata.Builder();
        if (!programInfo.isEmpty()) {
            contentBuilder.setProgramInfo(programInfo);
        }
        mBluetoothLeBroadcast.startBroadcast(contentBuilder.build(), code);
        mBluetoothLeBroadcast.startBroadcast(meta, code);
        return true;
    }

Loading