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

Commit 276fa434 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9095712 from f028cb49 to tm-qpr1-release

Change-Id: Iaa55e0298b883b2b6ca866a038e20c0363530b13
parents 2d7043d8 f028cb49
Loading
Loading
Loading
Loading
+76 −41
Original line number Diff line number Diff line
@@ -996,6 +996,13 @@ public class LeAudioService extends ProfileService {
            return;
        }
        mLeAudioNativeInterface.groupSetActive(groupId);
        if (groupId == LE_AUDIO_GROUP_ID_INVALID) {
            /* Native will clear its states and send us group Inactive.
             * However we would like to notify audio framework that LeAudio is not
             * active anymore and does not want to get more audio data.
             */
            handleGroupTransitToInactive(currentlyActiveGroupId);
        }
    }

    /**
@@ -1112,20 +1119,59 @@ public class LeAudioService extends ProfileService {
    }

    private void clearLostDevicesWhileStreaming(LeAudioGroupDescriptor descriptor) {
        synchronized (mGroupLock) {
            if (DBG) {
            Log.d(TAG, " lost dev: " + descriptor.mLostLeadDeviceWhileStreaming);
                Log.d(TAG, "Clearing lost dev: " + descriptor.mLostLeadDeviceWhileStreaming);
            }

        LeAudioStateMachine sm = mStateMachines.get(descriptor.mLostLeadDeviceWhileStreaming);
            LeAudioStateMachine sm =
                    mStateMachines.get(descriptor.mLostLeadDeviceWhileStreaming);
            if (sm != null) {
                LeAudioStackEvent stackEvent =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED);
                        new LeAudioStackEvent(
                                LeAudioStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED);
                stackEvent.device = descriptor.mLostLeadDeviceWhileStreaming;
                stackEvent.valueInt1 = LeAudioStackEvent.CONNECTION_STATE_DISCONNECTED;
                sm.sendMessage(LeAudioStateMachine.STACK_EVENT, stackEvent);
            }
            descriptor.mLostLeadDeviceWhileStreaming = null;
        }
    }

    private void handleGroupTransitToActive(int groupId) {
        synchronized (mGroupLock) {
            LeAudioGroupDescriptor descriptor = getGroupDescriptor(groupId);
            if (descriptor == null || descriptor.mIsActive) {
                Log.e(TAG, "no descriptors for group: " + groupId + " or group already active");
                return;
            }

            descriptor.mIsActive = updateActiveDevices(groupId,
                            ACTIVE_CONTEXTS_NONE, descriptor.mActiveContexts, true);

            if (descriptor.mIsActive) {
                notifyGroupStatusChanged(groupId, LeAudioStackEvent.GROUP_STATUS_ACTIVE);
            }
        }
    }

    private void handleGroupTransitToInactive(int groupId) {
        synchronized (mGroupLock) {
            LeAudioGroupDescriptor descriptor = getGroupDescriptor(groupId);
            if (descriptor == null || !descriptor.mIsActive) {
                Log.e(TAG, "no descriptors for group: " + groupId + " or group already inactive");
                return;
            }

            descriptor.mIsActive = false;
            updateActiveDevices(groupId, descriptor.mActiveContexts,
                    ACTIVE_CONTEXTS_NONE, descriptor.mIsActive);
            /* Clear lost devices */
            if (DBG) Log.d(TAG, "Clear for group: " + groupId);
            clearLostDevicesWhileStreaming(descriptor);
            notifyGroupStatusChanged(groupId, LeAudioStackEvent.GROUP_STATUS_INACTIVE);
        }
    }

    // Suppressed since this is part of a local process
    @SuppressLint("AndroidFrameworkRequiresPermission")
@@ -1153,10 +1199,14 @@ public class LeAudioService extends ProfileService {
                        switch (stackEvent.valueInt1) {
                            case LeAudioStackEvent.CONNECTION_STATE_DISCONNECTING:
                            case LeAudioStackEvent.CONNECTION_STATE_DISCONNECTED:
                                boolean disconnectDueToUnbond =
                                        (BluetoothDevice.BOND_NONE
                                                == mAdapterService.getBondState(device));
                                if (descriptor != null && (Objects.equals(device,
                                        mActiveAudioOutDevice)
                                        || Objects.equals(device, mActiveAudioInDevice))
                                        && (getConnectedPeerDevices(groupId).size() > 1)) {
                                        && (getConnectedPeerDevices(groupId).size() > 1)
                                        && !disconnectDueToUnbond) {

                                    if (DBG) Log.d(TAG, "Adding to lost devices : " + device);
                                    descriptor.mLostLeadDeviceWhileStreaming = device;
@@ -1278,47 +1328,19 @@ public class LeAudioService extends ProfileService {
        } else if (stackEvent.type == LeAudioStackEvent.EVENT_TYPE_GROUP_STATUS_CHANGED) {
            int groupId = stackEvent.valueInt1;
            int groupStatus = stackEvent.valueInt2;
            boolean notifyGroupStatus = false;

            switch (groupStatus) {
                case LeAudioStackEvent.GROUP_STATUS_ACTIVE: {
                    LeAudioGroupDescriptor descriptor = getGroupDescriptor(groupId);
                    if (descriptor != null) {
                        if (!descriptor.mIsActive) {
                            descriptor.mIsActive = updateActiveDevices(groupId,
                                    ACTIVE_CONTEXTS_NONE, descriptor.mActiveContexts, true);
                            notifyGroupStatus = descriptor.mIsActive;
                        }
                    } else {
                        Log.e(TAG, "no descriptors for group: " + groupId);
                    }
                    handleGroupTransitToActive(groupId);
                    break;
                }
                case LeAudioStackEvent.GROUP_STATUS_INACTIVE: {
                    LeAudioGroupDescriptor descriptor = getGroupDescriptor(groupId);
                    if (descriptor != null) {
                        if (descriptor.mIsActive) {
                            descriptor.mIsActive = false;
                            updateActiveDevices(groupId, descriptor.mActiveContexts,
                                    ACTIVE_CONTEXTS_NONE, descriptor.mIsActive);
                            notifyGroupStatus = true;
                            /* Clear lost devices */
                            if (DBG) Log.d(TAG, "Clear for group: " + groupId);
                            clearLostDevicesWhileStreaming(descriptor);
                        }
                    } else {
                        Log.e(TAG, "no descriptors for group: " + groupId);
                    }
                    handleGroupTransitToInactive(groupId);
                    break;
                }
                default:
                    break;
            }

            if (notifyGroupStatus) {
                notifyGroupStatusChanged(groupId, groupStatus);
            }

        } else if (stackEvent.type == LeAudioStackEvent.EVENT_TYPE_BROADCAST_CREATED) {
            int broadcastId = stackEvent.valueInt1;
            boolean success = stackEvent.valueBool1;
@@ -1501,6 +1523,8 @@ public class LeAudioService extends ProfileService {
                return;
            }
            if (sm.getConnectionState() != BluetoothProfile.STATE_DISCONNECTED) {
                Log.w(TAG, "Device is not disconnected yet.");
                disconnect(device);
                return;
            }
            removeStateMachine(device);
@@ -1839,6 +1863,10 @@ public class LeAudioService extends ProfileService {

    private void handleGroupNodeAdded(BluetoothDevice device, int groupId) {
        synchronized (mGroupLock) {
            if (DBG) {
                Log.d(TAG, "Device " + device + " added to group " + groupId);
            }

            mDeviceGroupIdMap.put(device, groupId);
            LeAudioGroupDescriptor descriptor = mGroupDescriptors.get(groupId);
            if (descriptor == null) {
@@ -1863,7 +1891,14 @@ public class LeAudioService extends ProfileService {
    }

    private void handleGroupNodeRemoved(BluetoothDevice device, int groupId) {
        if (DBG) {
            Log.d(TAG, "Removing device " + device + " grom group " + groupId);
        }

        LeAudioGroupDescriptor descriptor = getGroupDescriptor(groupId);
        if (DBG) {
            Log.d(TAG, "Lost lead device is " + descriptor.mLostLeadDeviceWhileStreaming);
        }
        if (Objects.equals(device, descriptor.mLostLeadDeviceWhileStreaming)) {
            clearLostDevicesWhileStreaming(descriptor);
        }
+1 −0
Original line number Diff line number Diff line
@@ -1322,6 +1322,7 @@ public class LeAudioServiceTest {
        verify(mAudioManager, times(1)).handleBluetoothActiveDeviceChanged(eq(leadDevice), any(),
                        any(BluetoothProfileConnectionInfo.class));

        doReturn(BluetoothDevice.BOND_BONDED).when(mAdapterService).getBondState(leadDevice);
        verifyActiveDeviceStateIntent(TIMEOUT_MS, leadDevice);
        injectNoVerifyDeviceDisconnected(leadDevice);

+4 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ cc_library_static {
        "le_audio/devices.cc",
        "le_audio/hal_verifier.cc",
        "le_audio/state_machine.cc",
        "le_audio/storage_helper.cc",
        "le_audio/client_parser.cc",
        "le_audio/client_audio.cc",
        "le_audio/le_audio_utils.cc",
@@ -572,6 +573,8 @@ cc_test {
        "test/common/mock_controller.cc",
        "le_audio/state_machine.cc",
        "le_audio/state_machine_test.cc",
        "le_audio/storage_helper.cc",
        "le_audio/storage_helper_test.cc",
        "le_audio/mock_codec_manager.cc",
    ],
    data: [
@@ -638,6 +641,7 @@ cc_test {
        "le_audio/metrics_collector_test.cc",
        "le_audio/mock_iso_manager.cc",
        "le_audio/mock_state_machine.cc",
        "le_audio/storage_helper.cc",
        "test/common/btm_api_mock.cc",
        "test/common/bta_gatt_api_mock.cc",
        "test/common/bta_gatt_queue_mock.cc",
+16 −1
Original line number Diff line number Diff line
@@ -69,7 +69,22 @@ class LeAudioClient {
  virtual void SetInCall(bool in_call) = 0;

  virtual std::vector<RawAddress> GetGroupDevices(const int group_id) = 0;
  static void AddFromStorage(const RawAddress& addr, bool autoconnect);
  static void AddFromStorage(const RawAddress& addr, bool autoconnect,
                             int sink_audio_location, int source_audio_location,
                             int sink_supported_context_types,
                             int source_supported_context_types,
                             const std::vector<uint8_t>& handles,
                             const std::vector<uint8_t>& sink_pacs,
                             const std::vector<uint8_t>& source_pacs,
                             const std::vector<uint8_t>& ases);
  static bool GetHandlesForStorage(const RawAddress& addr,
                                   std::vector<uint8_t>& out);
  static bool GetSinkPacsForStorage(const RawAddress& addr,
                                    std::vector<uint8_t>& out);
  static bool GetSourcePacsForStorage(const RawAddress& addr,
                                      std::vector<uint8_t>& out);
  static bool GetAsesForStorage(const RawAddress& addr,
                                std::vector<uint8_t>& out);
  static bool IsLeAudioClientRunning();

  static void InitializeAudioSetConfigurationProvider(void);
+233 −65

File changed.

Preview size limit exceeded, changes collapsed.

Loading