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

Commit 055099e3 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Add API to Add and remove group node

This might be needed for devices which does not support CSIS and for
testing

Bug: 150670922
Tag: #feature
Sponsor: jpawlowski@
Test: atest BluetoothInstrumentationTests

Change-Id: Ie986f3106bb890b95366b491b1849d3abe3d2eec
parent be779e3d
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -218,6 +218,47 @@ static jboolean disconnectLeAudioNative(JNIEnv* env, jobject object,
  return JNI_TRUE;
}

static jboolean groupAddNodeNative(JNIEnv* env, jobject object, jint group_id,
                                   jbyteArray address) {
  jbyte* addr = env->GetByteArrayElements(address, nullptr);

  if (!sLeAudioClientInterface) {
    LOG(ERROR) << __func__ << ": Failed to get the Bluetooth LeAudio Interface";
    return JNI_FALSE;
  }

  if (!addr) {
    jniThrowIOException(env, EINVAL);
    return JNI_FALSE;
  }

  RawAddress* tmpraw = (RawAddress*)addr;
  sLeAudioClientInterface->GroupAddNode(group_id, *tmpraw);
  env->ReleaseByteArrayElements(address, addr, 0);

  return JNI_TRUE;
}

static jboolean groupRemoveNodeNative(JNIEnv* env, jobject object,
                                      jint group_id, jbyteArray address) {

  if (!sLeAudioClientInterface) {
    LOG(ERROR) << __func__ << ": Failed to get the Bluetooth LeAudio Interface";
    return JNI_FALSE;
  }

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

  RawAddress* tmpraw = (RawAddress*)addr;
  sLeAudioClientInterface->GroupRemoveNode(group_id, *tmpraw);
  env->ReleaseByteArrayElements(address, addr, 0);
  return JNI_TRUE;
}

static void groupSetActiveNative(JNIEnv* env, jobject object, jint group_id) {
  LOG(INFO) << __func__;

@@ -235,6 +276,8 @@ static JNINativeMethod sMethods[] = {
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"connectLeAudioNative", "([B)Z", (void*)connectLeAudioNative},
    {"disconnectLeAudioNative", "([B)Z", (void*)disconnectLeAudioNative},
    {"groupAddNodeNative", "(I[B)Z", (void*)groupAddNodeNative},
    {"groupRemoveNodeNative", "(I[B)Z", (void*)groupRemoveNodeNative},
    {"groupSetActiveNative", "(I)V", (void*)groupSetActiveNative},
};

+20 −0
Original line number Diff line number Diff line
@@ -176,6 +176,24 @@ public class LeAudioNativeInterface {
        return disconnectLeAudioNative(getByteAddress(device));
    }

    /**
     * Add new Node into a group.
     * @param groupId group identifier
     * @param device remote device
     */
     public boolean groupAddNode(int groupId, BluetoothDevice device) {
        return groupAddNodeNative(groupId, getByteAddress(device));
    }

    /**
     * Add new Node into a group.
     * @param groupId group identifier
     * @param device remote device
     */
    public boolean groupRemoveNode(int groupId, BluetoothDevice device) {
        return groupRemoveNodeNative(groupId, getByteAddress(device));
    }

    /**
     * Set active group.
     * @param groupId group ID to set as active
@@ -190,5 +208,7 @@ public class LeAudioNativeInterface {
    private native void cleanupNative();
    private native boolean connectLeAudioNative(byte[] address);
    private native boolean disconnectLeAudioNative(byte[] address);
    private native boolean groupAddNodeNative(int groupId, byte[] address);
    private native boolean groupRemoveNodeNative(int groupId, byte[] address);
    private native void groupSetActiveNative(int groupId);
}
+40 −0
Original line number Diff line number Diff line
@@ -413,6 +413,26 @@ public class LeAudioService extends ProfileService {
        }
    }

    /**
     * Add device to the given group.
     * @param groupId group ID the device is being added to
     * @param device the active device
     * @return true on success, otherwise false
     */
    public boolean groupAddNode(int groupId, BluetoothDevice device) {
        return mLeAudioNativeInterface.groupAddNode(groupId, device);
    }

    /**
     * Remove device from a given group.
     * @param groupId group ID the device is being removed from
     * @param device the active device
     * @return true on success, otherwise false
     */
    public boolean groupRemoveNode(int groupId, BluetoothDevice device) {
        return mLeAudioNativeInterface.groupRemoveNode(groupId, device);
    }

    /**
     * Get supported group audio direction from available context.
     *
@@ -1220,6 +1240,26 @@ public class LeAudioService extends ProfileService {
            return service.getGroupId(device);
        }

        @Override
        public boolean groupAddNode(int group_id, BluetoothDevice device,
                                    AttributionSource source) {
            LeAudioService service = getService(source);
            if (service == null) {
                return false;
            }
            return service.groupAddNode(group_id, device);
        }

        @Override
        public boolean groupRemoveNode(int groupId, BluetoothDevice device,
                                       AttributionSource source) {
            LeAudioService service = getService(source);
            if (service == null) {
                return false;
            }
            return service.groupRemoveNode(groupId, device);
        }

        @Override
        public void setVolume(int volume, AttributionSource source) {
            LeAudioService service = getService(source);