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

Commit c27d8299 authored by Chen Chen's avatar Chen Chen Committed by Automerger Merge Worker
Browse files

SpatialAudio: Add API to switch buffer size am: a81d2c64 am: ed2bc6fa

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1954936

Change-Id: I4c46ac3efa166a7e97503c6a689d2cc6a60f6b85
parents df1fb92e ed2bc6fa
Loading
Loading
Loading
Loading
+34 −1
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ static jmethodID method_addressConsolidateCallback;
static jmethodID method_aclStateChangeCallback;
static jmethodID method_discoveryStateChangeCallback;
static jmethodID method_linkQualityReportCallback;
static jmethodID method_switchBufferSizeCallback;
static jmethodID method_setWakeAlarm;
static jmethodID method_acquireWakeLock;
static jmethodID method_releaseWakeLock;
@@ -598,6 +599,34 @@ static void link_quality_report_callback(
      (jint)negative_acknowledgement_count);
}

static void switch_buffer_size_callback(RawAddress* bd_addr,
                                        bool is_low_latency_buffer_size) {

  if (!bd_addr) {
    ALOGE("Address is null in %s", __func__);
    return;
  }
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;

  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("Error while allocating in: %s", __func__);
    return;
  }

  sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                 (jbyte*)bd_addr);

  ALOGV("%s: SwitchBufferSizeCallback: %s", __func__,
        is_low_latency_buffer_size ? "true" : "false");

  sCallbackEnv->CallVoidMethod(
      sJniCallbacksObj, method_switchBufferSizeCallback, addr.get(),
      (jboolean)is_low_latency_buffer_size);
}

static void callback_thread_event(bt_cb_thread_evt event) {
  if (event == ASSOCIATE_JVM) {
    JavaVMAttachArgs args;
@@ -674,7 +703,8 @@ static bt_callbacks_t sBluetoothCallbacks = {sizeof(sBluetoothCallbacks),
                                             le_test_mode_recv_callback,
                                             energy_info_recv_callback,
                                             link_quality_report_callback,
                                             generate_local_oob_data_callback};
                                             generate_local_oob_data_callback,
                                             switch_buffer_size_callback};

// The callback to call when the wake alarm fires.
static alarm_cb sAlarmCallback;
@@ -893,6 +923,9 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
  method_linkQualityReportCallback = env->GetMethodID(
      jniCallbackClass, "linkQualityReportCallback", "(JIIIIII)V");

  method_switchBufferSizeCallback =
      env->GetMethodID(jniCallbackClass, "switchBufferSizeCallback", "([BZ)V");

  method_setWakeAlarm = env->GetMethodID(clazz, "setWakeAlarm", "(JZ)Z");
  method_acquireWakeLock =
      env->GetMethodID(clazz, "acquireWakeLock", "(Ljava/lang/String;)Z");
+6 −0
Original line number Diff line number Diff line
@@ -145,4 +145,10 @@
     -->
    <bool name="enable_gd_up_to_scanning_layer">true</bool>

    <!-- Package of fastpair service -->
    <string name="peripheral_link_package">com.google.android.gms</string>
    <!-- Service name of fastpair-->
    <string name="peripheral_link_service">.nearby.discovery.service.DiscoveryService</string>


</resources>
+14 −0
Original line number Diff line number Diff line
@@ -811,6 +811,20 @@ public class AdapterService extends Service {
        }
    }

    void switchBufferSizeCallback(byte[] address, boolean isLowLatencyBufferSize) {
        BluetoothDevice device = getDeviceFromByte(address);
        // Send intent to fastpair
        Intent switchBufferSizeIntent = new Intent(BluetoothDevice.ACTION_SWITCH_BUFFER_SIZE);
        switchBufferSizeIntent.setClassName(
                getString(com.android.bluetooth.R.string.peripheral_link_package),
                getString(com.android.bluetooth.R.string.peripheral_link_package)
                        + getString(com.android.bluetooth.R.string.peripheral_link_service));
        switchBufferSizeIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        switchBufferSizeIntent.putExtra(
                BluetoothDevice.EXTRA_LOW_LATENCY_BUFFER_SIZE, isLowLatencyBufferSize);
        sendBroadcast(switchBufferSizeIntent);
    }

    /**
     * Enable/disable BluetoothInCallService
     *
+4 −0
Original line number Diff line number Diff line
@@ -106,4 +106,8 @@ final class JniCallbacks {
                packets_not_receive_count, negative_acknowledgement_count);
    }

    void switchBufferSizeCallback(byte[] mac_address, boolean is_low_latency_buffer_size) {
        mAdapterService.switchBufferSizeCallback(mac_address, is_low_latency_buffer_size);
    }

}
+30 −0
Original line number Diff line number Diff line
@@ -231,6 +231,25 @@ public final class BluetoothDevice implements Parcelable, Attributable {
    public static final String ACTION_BATTERY_LEVEL_CHANGED =
            "android.bluetooth.device.action.BATTERY_LEVEL_CHANGED";

    /**
     * Broadcast Action: Indicates the audio buffer size should be switched
     * between a low latency buffer size and a higher and larger latency buffer size.
     * <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
     * #EXTRA_LOW_LATENCY_BUFFER_SIZE}.
     *
     * @hide
     */
    @SuppressLint("ActionValue")
    @RequiresBluetoothConnectPermission
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
    })
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    @SystemApi
    public static final String ACTION_SWITCH_BUFFER_SIZE =
            "android.bluetooth.device.action.SWITCH_BUFFER_SIZE";

    /**
     * Used as an Integer extra field in {@link #ACTION_BATTERY_LEVEL_CHANGED}
     * intent. It contains the most recently retrieved battery level information
@@ -310,6 +329,17 @@ public final class BluetoothDevice implements Parcelable, Attributable {
     */
    public static final String EXTRA_PREVIOUS_BOND_STATE =
            "android.bluetooth.device.extra.PREVIOUS_BOND_STATE";

    /**
     * Used as a boolean extra field to indicate if audio buffer size is low latency or not
     *
     * @hide
     */
    @SuppressLint("ActionValue")
    @SystemApi
    public static final String EXTRA_LOW_LATENCY_BUFFER_SIZE =
            "android.bluetooth.device.extra.LOW_LATENCY_BUFFER_SIZE";

    /**
     * Indicates the remote device is not bonded (paired).
     * <p>There is no shared link key with the remote device, so communication
Loading