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

Commit 56bce9d3 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12002618 from 537d46a2 to 24Q4-release

Change-Id: Ic677fa9aae5a517644fe9752a5b72c3bf8c5e7fc
parents 26ee4cea 537d46a2
Loading
Loading
Loading
Loading
+21 −67
Original line number Diff line number Diff line
@@ -14,12 +14,12 @@
 * limitations under the License.
 */

#define LOG_TAG "BluetoothA2dpServiceJni"

#include <string.h>
#define LOG_TAG "bluetooth-a2dp"

#include <cstring>
#include <shared_mutex>

#include "btif/include/btif_av.h"
#include "btif/include/btif_util.h"
#include "com_android_bluetooth.h"
#include "hardware/bt_av.h"
@@ -44,7 +44,6 @@ static struct {
  jmethodID getCodecSpecific4;
} android_bluetooth_BluetoothCodecConfig;

static const btav_source_interface_t* sBluetoothA2dpInterface = nullptr;
static std::vector<btav_a2dp_codec_info_t> supported_codecs;
static std::shared_timed_mutex interface_mutex;

@@ -261,11 +260,8 @@ static void initNative(JNIEnv* env, jobject object,
    return;
  }

  if (sBluetoothA2dpInterface != nullptr) {
  log::warn("Cleaning up A2DP Interface before initializing...");
    sBluetoothA2dpInterface->cleanup();
    sBluetoothA2dpInterface = nullptr;
  }
  btif_av_source_cleanup();

  if (mCallbacksObj != nullptr) {
    log::warn("Cleaning up A2DP callback object");
@@ -285,27 +281,18 @@ static void initNative(JNIEnv* env, jobject object,
    return;
  }

  sBluetoothA2dpInterface =
      (btav_source_interface_t*)btInf->get_profile_interface(
          BT_PROFILE_ADVANCED_AUDIO_ID);
  if (sBluetoothA2dpInterface == nullptr) {
    log::error("Failed to get Bluetooth A2DP Interface");
    return;
  }

  std::vector<btav_a2dp_codec_config_t> codec_priorities =
      prepareCodecPreferences(env, object, codecConfigArray);

  std::vector<btav_a2dp_codec_config_t> codec_offloading =
      prepareCodecPreferences(env, object, codecOffloadingArray);

  bt_status_t status = sBluetoothA2dpInterface->init(
  bt_status_t status = btif_av_source_init(
      &sBluetoothA2dpCallbacks, maxConnectedAudioDevices, codec_priorities,
      codec_offloading, &supported_codecs);
  if (status != BT_STATUS_SUCCESS) {
    log::error("Failed to initialize Bluetooth A2DP, status: {}",
               bt_status_text(status));
    sBluetoothA2dpInterface = nullptr;
    return;
  }
}
@@ -320,10 +307,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
    return;
  }

  if (sBluetoothA2dpInterface != nullptr) {
    sBluetoothA2dpInterface->cleanup();
    sBluetoothA2dpInterface = nullptr;
  }
  btif_av_source_cleanup();

  env->DeleteGlobalRef(android_bluetooth_BluetoothCodecConfig.clazz);
  android_bluetooth_BluetoothCodecConfig.clazz = nullptr;
@@ -335,8 +319,6 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
}

static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
  log::info("{}", fmt::ptr(sBluetoothA2dpInterface));

  jclass android_bluetooth_BluetoothCodecType_clazz = (jclass)env->NewGlobalRef(
      env->FindClass("android/bluetooth/BluetoothCodecType"));
  if (android_bluetooth_BluetoothCodecType_clazz == nullptr) {
@@ -376,11 +358,6 @@ static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
                                  jbyteArray address) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

  jbyte* addr = env->GetByteArrayElements(address, nullptr);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
@@ -389,9 +366,9 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,

  RawAddress bd_addr;
  bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
  log::info("sBluetoothA2dpInterface: {}, {}",
            fmt::ptr(sBluetoothA2dpInterface), bd_addr);
  bt_status_t status = sBluetoothA2dpInterface->connect(bd_addr);

  log::info("{}", bd_addr);
  bt_status_t status = btif_av_source_connect(bd_addr);
  if (status != BT_STATUS_SUCCESS) {
    log::error("Failed A2DP connection, status: {}", bt_status_text(status));
  }
@@ -402,11 +379,6 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
                                     jbyteArray address) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

  jbyte* addr = env->GetByteArrayElements(address, nullptr);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
@@ -415,9 +387,9 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,

  RawAddress bd_addr;
  bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
  log::info("sBluetoothA2dpInterface: {}, {}",
            fmt::ptr(sBluetoothA2dpInterface), bd_addr);
  bt_status_t status = sBluetoothA2dpInterface->disconnect(bd_addr);

  log::info("{}", bd_addr);
  bt_status_t status = btif_av_source_disconnect(bd_addr);
  if (status != BT_STATUS_SUCCESS) {
    log::error("Failed A2DP disconnection, status: {}", bt_status_text(status));
  }
@@ -428,13 +400,8 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,
                                       jbyteArray address, jboolean silence) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

  jbyte* addr = env->GetByteArrayElements(address, nullptr);

  RawAddress bd_addr = RawAddress::kEmpty;
  if (addr) {
    bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
@@ -442,11 +409,9 @@ static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,
  if (bd_addr == RawAddress::kEmpty) {
    return JNI_FALSE;
  }
  log::info("sBluetoothA2dpInterface: {}, {}: silence: {}",
            fmt::ptr(sBluetoothA2dpInterface), bd_addr,
            static_cast<bool>(silence));
  bt_status_t status =
      sBluetoothA2dpInterface->set_silence_device(bd_addr, silence);

  log::info("{}: silence={}", bd_addr, silence);
  bt_status_t status = btif_av_source_set_silence_device(bd_addr, silence);
  if (status != BT_STATUS_SUCCESS) {
    log::error("Failed A2DP set_silence_device, status: {}",
               bt_status_text(status));
@@ -458,20 +423,15 @@ static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,
static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
                                      jbyteArray address) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

  jbyte* addr = env->GetByteArrayElements(address, nullptr);

  RawAddress bd_addr = RawAddress::kEmpty;
  if (addr) {
    bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
  }
  log::info("sBluetoothA2dpInterface: {}, {}",
            fmt::ptr(sBluetoothA2dpInterface), bd_addr);
  bt_status_t status = sBluetoothA2dpInterface->set_active_device(bd_addr);

  log::info("{}", bd_addr);
  bt_status_t status = btif_av_source_set_active_device(bd_addr);
  if (status != BT_STATUS_SUCCESS) {
    log::error("Failed A2DP set_active_device, status: {}",
               bt_status_text(status));
@@ -484,11 +444,6 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
                                               jbyteArray address,
                                               jobjectArray codecConfigArray) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothA2dpInterface) {
    log::error("Failed to get the Bluetooth A2DP Interface");
    return JNI_FALSE;
  }

  jbyte* addr = env->GetByteArrayElements(address, nullptr);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
@@ -499,11 +454,10 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
  bd_addr.FromOctets(reinterpret_cast<const uint8_t*>(addr));
  std::vector<btav_a2dp_codec_config_t> codec_preferences =
      prepareCodecPreferences(env, object, codecConfigArray);
  log::info("sBluetoothA2dpInterface: {}, {}: {}",
            fmt::ptr(sBluetoothA2dpInterface), bd_addr,
  log::info("{}: {}", bd_addr,
            btav_a2dp_codec_config_t::PrintCodecs(codec_preferences));
  bt_status_t status =
      sBluetoothA2dpInterface->config_codec(bd_addr, codec_preferences);
      btif_av_source_set_codec_config_preference(bd_addr, codec_preferences);
  if (status != BT_STATUS_SUCCESS) {
    log::error("Failed codec configuration, status: {}",
               bt_status_text(status));
+11 −0
Original line number Diff line number Diff line
@@ -1541,6 +1541,16 @@ static jboolean sspReplyNative(JNIEnv* env, jobject /* obj */,
  return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static jboolean setScanModeNative(JNIEnv* /* env */, jobject /* obj */,
                                  jint mode) {
  log::verbose("");

  if (!sBluetoothInterface) return JNI_FALSE;

  sBluetoothInterface->set_scan_mode((bt_scan_mode_t)mode);
  return JNI_TRUE;
}

static jboolean setAdapterPropertyNative(JNIEnv* env, jobject /* obj */,
                                         jint type, jbyteArray value) {
  log::verbose("");
@@ -2144,6 +2154,7 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
      {"cleanupNative", "()V", (void*)cleanupNative},
      {"enableNative", "()Z", (void*)enableNative},
      {"disableNative", "()Z", (void*)disableNative},
      {"setScanModeNative", "(I)Z", (void*)setScanModeNative},
      {"setAdapterPropertyNative", "(I[B)Z", (void*)setAdapterPropertyNative},
      {"getAdapterPropertiesNative", "()Z", (void*)getAdapterPropertiesNative},
      {"getAdapterPropertyNative", "(I)Z", (void*)getAdapterPropertyNative},
+21 −12
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.le_audio.LeAudioService;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

import java.nio.charset.StandardCharsets;
@@ -3260,7 +3261,8 @@ public class BassClientService extends ProfileService {
        private static final int MSG_RECEIVESTATE_CHANGED = 12;
        private static final int MSG_SOURCE_LOST = 13;

        private final RemoteCallbackList<IBluetoothLeBroadcastAssistantCallback> mCallbacks =
        @GuardedBy("mCallbacksList")
        private final RemoteCallbackList<IBluetoothLeBroadcastAssistantCallback> mCallbacksList =
                new RemoteCallbackList<>();

        Callbacks(Looper looper) {
@@ -3268,11 +3270,15 @@ public class BassClientService extends ProfileService {
        }

        public void register(IBluetoothLeBroadcastAssistantCallback callback) {
            mCallbacks.register(callback);
            synchronized (mCallbacksList) {
                mCallbacksList.register(callback);
            }
        }

        public void unregister(IBluetoothLeBroadcastAssistantCallback callback) {
            mCallbacks.unregister(callback);
            synchronized (mCallbacksList) {
                mCallbacksList.unregister(callback);
            }
        }

        private void checkForPendingGroupOpRequest(Message msg) {
@@ -3309,17 +3315,20 @@ public class BassClientService extends ProfileService {
        @Override
        public void handleMessage(Message msg) {
            checkForPendingGroupOpRequest(msg);
            final int n = mCallbacks.beginBroadcast();

            synchronized (mCallbacksList) {
                final int n = mCallbacksList.beginBroadcast();
                for (int i = 0; i < n; i++) {
                    final IBluetoothLeBroadcastAssistantCallback callback =
                        mCallbacks.getBroadcastItem(i);
                            mCallbacksList.getBroadcastItem(i);
                    try {
                        invokeCallback(callback, msg);
                    } catch (RemoteException e) {
                        continue;
                    }
                }
            mCallbacks.finishBroadcast();
                mCallbacksList.finishBroadcast();
            }
        }

        private static class ObjParams {
+1 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.bluetooth.btservice;

public final class AbstractionLayer {
    // Do not modify without updating the HAL files.
    // Do not modify without migrating data in the config

    // TODO: Some of the constants are repeated from BluetoothAdapter.java.
    // Get rid of them and maintain just one.
@@ -34,7 +35,6 @@ public final class AbstractionLayer {
    static final int BT_PROPERTY_CLASS_OF_DEVICE = 0x04;
    static final int BT_PROPERTY_TYPE_OF_DEVICE = 0x05;
    static final int BT_PROPERTY_SERVICE_RECORD = 0x06;
    static final int BT_PROPERTY_ADAPTER_SCAN_MODE = 0x07;
    static final int BT_PROPERTY_ADAPTER_BONDED_DEVICES = 0x08;
    static final int BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT = 0x09;

+6 −0
Original line number Diff line number Diff line
@@ -89,6 +89,10 @@ public class AdapterNativeInterface {
        return disableNative();
    }

    boolean setScanMode(int mode) {
        return setScanModeNative(mode);
    }

    boolean setAdapterProperty(int type, byte[] val) {
        return setAdapterPropertyNative(type, val);
    }
@@ -283,6 +287,8 @@ public class AdapterNativeInterface {

    private native boolean disableNative();

    private native boolean setScanModeNative(int mode);

    private native boolean setAdapterPropertyNative(int type, byte[] val);

    private native boolean getAdapterPropertiesNative();
Loading