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

Commit c9b32487 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge changes from topic "ble_audio_group_node_ops"

* changes:
  leaudio: Remove not needed group id from the state machine
  leaudio: Improve logging for group events
  leaudio: Set group as inactive on service stop
  leaudio: Add API to Add and remove group node
parents 4c38e2d6 3219c845
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);
}
+66 −11
Original line number Diff line number Diff line
@@ -176,6 +176,20 @@ public class LeAudioService extends ProfileService {
            return true;
        }

        setActiveDevice(null);
        //Don't wait for async call with INACTIVE group status, clean active
        //device for active group.
        for (Map.Entry<Integer, LeAudioGroupDescriptor> entry : mGroupDescriptors.entrySet()) {
            LeAudioGroupDescriptor descriptor = entry.getValue();
            Integer group_id = entry.getKey();
            if (descriptor.mIsActive) {
                descriptor.mIsActive = false;
                updateActiveDevices(group_id, descriptor.mActiveContexts,
                        ACTIVE_CONTEXTS_NONE, descriptor.mIsActive);
                break;
            }
        }

        // Cleanup native interfaces
        mLeAudioNativeInterface.cleanup();
        mLeAudioNativeInterface = null;
@@ -262,7 +276,7 @@ public class LeAudioService extends ProfileService {
                Log.e(TAG, "Ignored connect request for " + device + " : no state machine");
                return false;
            }
            sm.sendMessage(LeAudioStateMachine.CONNECT, groupId);
            sm.sendMessage(LeAudioStateMachine.CONNECT);
        }

        // Connect other devices from this group
@@ -281,10 +295,11 @@ public class LeAudioService extends ProfileService {
                                 + " : no state machine");
                         continue;
                     }
                    sm.sendMessage(LeAudioStateMachine.CONNECT, groupId);
                     sm.sendMessage(LeAudioStateMachine.CONNECT);
                 }
             }
         }

        return true;
    }

@@ -413,6 +428,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 +1255,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);
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ public class LeAudioStackEvent {
            case EVENT_TYPE_GROUP_NODE_STATUS_CHANGED:
                // same as EVENT_TYPE_GROUP_STATUS_CHANGED
            case EVENT_TYPE_GROUP_STATUS_CHANGED:
                // same as EVENT_TYPE_GROUP_STATUS_CHANGED
                return "{group_id:" + Integer.toString(value) + "}";
            case EVENT_TYPE_AUDIO_CONF_CHANGED:
                // FIXME: It should have proper direction names here
                return "{direction:" + value + "}";
+9 −10
Original line number Diff line number Diff line
@@ -157,8 +157,7 @@ final class LeAudioStateMachine extends StateMachine {

            switch (message.what) {
                case CONNECT:
                    int groupId = message.arg1;
                    log("Connecting to " + mDevice + " group " + groupId);
                    log("Connecting to " + mDevice);
                    if (!mNativeInterface.connectLeAudio(mDevice)) {
                        Log.e(TAG, "Disconnected: error connecting to " + mDevice);
                        break;
@@ -184,7 +183,7 @@ final class LeAudioStateMachine extends StateMachine {
                    }
                    switch (event.type) {
                        case LeAudioStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED:
                            processConnectionEvent(event.valueInt1, event.valueInt2);
                            processConnectionEvent(event.valueInt1);
                            break;
                        default:
                            Log.e(TAG, "Disconnected: ignoring stack event: " + event);
@@ -198,7 +197,7 @@ final class LeAudioStateMachine extends StateMachine {
        }

        // in Disconnected state
        private void processConnectionEvent(int state, int groupId) {
        private void processConnectionEvent(int state) {
            switch (state) {
                case LeAudioStackEvent.CONNECTION_STATE_DISCONNECTED:
                    Log.w(TAG, "Ignore LeAudio DISCONNECTED event: " + mDevice);
@@ -285,7 +284,7 @@ final class LeAudioStateMachine extends StateMachine {
                    }
                    switch (event.type) {
                        case LeAudioStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED:
                            processConnectionEvent(event.valueInt1, event.valueInt2);
                            processConnectionEvent(event.valueInt1);
                            break;
                        default:
                            Log.e(TAG, "Connecting: ignoring stack event: " + event);
@@ -299,7 +298,7 @@ final class LeAudioStateMachine extends StateMachine {
        }

        // in Connecting state
        private void processConnectionEvent(int state, int groupId) {
        private void processConnectionEvent(int state) {
            switch (state) {
                case LeAudioStackEvent.CONNECTION_STATE_DISCONNECTED:
                    Log.w(TAG, "Connecting device disconnected: " + mDevice);
@@ -371,7 +370,7 @@ final class LeAudioStateMachine extends StateMachine {
                    }
                    switch (event.type) {
                        case LeAudioStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED:
                            processConnectionEvent(event.valueInt1, event.valueInt2);
                            processConnectionEvent(event.valueInt1);
                            break;
                        default:
                            Log.e(TAG, "Disconnecting: ignoring stack event: " + event);
@@ -385,7 +384,7 @@ final class LeAudioStateMachine extends StateMachine {
        }

        // in Disconnecting state
        private void processConnectionEvent(int state, int groupId) {
        private void processConnectionEvent(int state) {
            switch (state) {
                case LeAudioStackEvent.CONNECTION_STATE_DISCONNECTED:
                    Log.i(TAG, "Disconnected: " + mDevice);
@@ -465,7 +464,7 @@ final class LeAudioStateMachine extends StateMachine {
                    }
                    switch (event.type) {
                        case LeAudioStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED:
                            processConnectionEvent(event.valueInt1, event.valueInt2);
                            processConnectionEvent(event.valueInt1);
                            break;
                        default:
                            Log.e(TAG, "Connected: ignoring stack event: " + event);
@@ -479,7 +478,7 @@ final class LeAudioStateMachine extends StateMachine {
        }

        // in Connected state
        private void processConnectionEvent(int state, int groupId) {
        private void processConnectionEvent(int state) {
            switch (state) {
                case LeAudioStackEvent.CONNECTION_STATE_DISCONNECTED:
                    Log.i(TAG, "Disconnected from " + mDevice);