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

Commit 1c0b19d0 authored by Jack He's avatar Jack He
Browse files

HFP: Add method to disable inband ringing through BSIR (2/2)

* Add sendBsir(boolean, BluetoothDevice) to turn
  in-band ringtone feature ON and OFF dynamically during a service
  level connection with a headset
* Added missing mutex lock in native interface as well

Bug: 70173881
Test: make
Change-Id: I5e0744367c07d0448c72ce15fa6f60ffbd5f4995
parent 633cc911
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -763,6 +763,7 @@ static jboolean phoneStateChangeNative(JNIEnv* env, jobject object,

static jboolean setScoAllowedNative(JNIEnv* env, jobject object,
                                    jboolean value) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothHfpInterface) return JNI_FALSE;

  bt_status_t status =
@@ -773,6 +774,25 @@ static jboolean setScoAllowedNative(JNIEnv* env, jobject object,
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static jboolean sendBsirNative(JNIEnv* env, jobject object, jboolean value,
                               jbyteArray address) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sBluetoothHfpInterface) return JNI_FALSE;

  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
    return JNI_FALSE;
  }

  bt_status_t status =
      sBluetoothHfpInterface->send_bsir(value == JNI_TRUE, (RawAddress*)addr);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed sending BSIR, value=%d, status=%d", value, status);
  }
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
    {"initializeNative", "(IZ)V", (void*)initializeNative},
@@ -797,6 +817,7 @@ static JNINativeMethod sMethods[] = {
    {"phoneStateChangeNative", "(IIILjava/lang/String;I)Z",
     (void*)phoneStateChangeNative},
    {"setScoAllowedNative", "(Z)Z", (void*)setScoAllowedNative},
    {"sendBsirNative", "(Z[B)Z", (void*)sendBsirNative},
};

int register_com_android_bluetooth_hfp(JNIEnv* env) {
+14 −0
Original line number Diff line number Diff line
@@ -421,6 +421,18 @@ public class HeadsetNativeInterface {
        return setScoAllowedNative(value);
    }

    /**
     * Enable or disable in-band ringing for the current service level connection through sending
     * +BSIR AT command
     *
     * @param value True to enable, False to disable
     * @return True on success, False on failure
     */
    @VisibleForTesting
    public boolean sendBsir(BluetoothDevice device,  boolean value) {
        return sendBsirNative(value, Utils.getByteAddress(device));
    }

    /* Native methods */
    private static native void classInitNative();

@@ -461,4 +473,6 @@ public class HeadsetNativeInterface {
            String number, int type);

    private native boolean setScoAllowedNative(boolean value);

    private native boolean sendBsirNative(boolean value, byte[] address);
}