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

Commit bf22b20b authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Automerger Merge Worker
Browse files

LeAudioService: Handle no Ringtone in the available contexts am: 5ade1182

parents a76c284a 5ade1182
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ public class LeAudioService extends ProfileService {
            mCodecStatus = null;
            mLostLeadDeviceWhileStreaming = null;
            mInbandRingtoneEnabled = isInbandRingtonEnabled;
            mAvailableContexts = 0;
        }

        public Boolean mIsConnected;
@@ -162,6 +163,7 @@ public class LeAudioService extends ProfileService {
        /* This can be non empty only for the streaming time */
        BluetoothDevice mLostLeadDeviceWhileStreaming;
        Boolean mInbandRingtoneEnabled;
        Integer mAvailableContexts;
    }

    private static class LeAudioDeviceDescriptor {
@@ -1506,7 +1508,15 @@ public class LeAudioService extends ProfileService {
                return;
            }

            boolean isRingtoneEnabled = groupDescriptor.mIsActive;
            boolean ringtoneContextAvailable =
                    ((groupDescriptor.mAvailableContexts
                            & BluetoothLeAudio.CONTEXT_TYPE_RINGTONE) != 0);
            if (DBG) {
                Log.d(TAG, "groupId active: " + groupDescriptor.mIsActive
                        + " ringtone supported: " + ringtoneContextAvailable);
            }

            boolean isRingtoneEnabled = (groupDescriptor.mIsActive && ringtoneContextAvailable);

            if (DBG) {
                Log.d(TAG, "updateInbandRingtoneForTheGroup old: "
@@ -1700,6 +1710,8 @@ public class LeAudioService extends ProfileService {
                        }
                    }
                    descriptor.mDirection = direction;
                    descriptor.mAvailableContexts = available_contexts;
                    updateInbandRingtoneForTheGroup(groupId);
                } else {
                    Log.e(TAG, "no descriptors for group: " + groupId);
                }
+56 −4
Original line number Diff line number Diff line
@@ -1028,7 +1028,7 @@ public class LeAudioServiceTest {
    }

    /**
     * Test setting active device group
     * Test setting active device group with Ringtone context
     */
    @Test
    public void testSetActiveDeviceGroup() {
@@ -1037,7 +1037,7 @@ public class LeAudioServiceTest {
        int direction = 1;
        int snkAudioLocation = 3;
        int srcAudioLocation = 4;
        int availableContexts = 5;
        int availableContexts = 5 + BluetoothLeAudio.CONTEXT_TYPE_RINGTONE;

        // Not connected device
        assertThat(mService.setActiveDevice(mSingleDevice)).isFalse();
@@ -1080,6 +1080,58 @@ public class LeAudioServiceTest {
        verify(mTbsService).clearInbandRingtoneSupport(mSingleDevice);
    }

    /**
     * Test setting active device group without Ringtone context
     */
    @Test
    public void testSetActiveDeviceGroupWithoutRingtoneContext() {
        int groupId = 1;
        /* AUDIO_DIRECTION_OUTPUT_BIT = 0x01 */
        int direction = 1;
        int snkAudioLocation = 3;
        int srcAudioLocation = 4;
        int availableContexts = 5;

        // Not connected device
        assertThat(mService.setActiveDevice(mSingleDevice)).isFalse();

        // Connected device
        doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class));
        connectTestDevice(mSingleDevice, testGroupId);

             // Add location support
        LeAudioStackEvent audioConfChangedEvent =
             new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_AUDIO_CONF_CHANGED);
        audioConfChangedEvent.device = mSingleDevice;
        audioConfChangedEvent.valueInt1 = direction;
        audioConfChangedEvent.valueInt2 = groupId;
        audioConfChangedEvent.valueInt3 = snkAudioLocation;
        audioConfChangedEvent.valueInt4 = srcAudioLocation;
        audioConfChangedEvent.valueInt5 = availableContexts;
        mService.messageFromNative(audioConfChangedEvent);

        assertThat(mService.setActiveDevice(mSingleDevice)).isTrue();
        verify(mNativeInterface).groupSetActive(groupId);


        //Set group and device as active
        LeAudioStackEvent groupStatusChangedEvent =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_GROUP_STATUS_CHANGED);
        groupStatusChangedEvent.valueInt1 = groupId;
        groupStatusChangedEvent.valueInt2 = LeAudioStackEvent.GROUP_STATUS_ACTIVE;
        mService.messageFromNative(groupStatusChangedEvent);

        // no active device
        assertThat(mService.setActiveDevice(null)).isTrue();
        verify(mNativeInterface).groupSetActive(BluetoothLeAudio.GROUP_ID_INVALID);

        //Set group and device as inactive active
        groupStatusChangedEvent.valueInt2 = LeAudioStackEvent.GROUP_STATUS_INACTIVE;
        mService.messageFromNative(groupStatusChangedEvent);

        verify(mTbsService, times(0)).clearInbandRingtoneSupport(mSingleDevice);
    }

    /**
     * Test getting active device
     */
@@ -1358,7 +1410,7 @@ public class LeAudioServiceTest {
        int direction = 1;
        int snkAudioLocation = 3;
        int srcAudioLocation = 4;
        int availableContexts = 5;
        int availableContexts = 5 + BluetoothLeAudio.CONTEXT_TYPE_RINGTONE;;
        int groupStatus = LeAudioStackEvent.GROUP_STATUS_ACTIVE;
        BluetoothDevice leadDevice;
        BluetoothDevice memberDevice = mLeftDevice;
@@ -1429,7 +1481,7 @@ public class LeAudioServiceTest {
        int direction = 1;
        int snkAudioLocation = 3;
        int srcAudioLocation = 4;
        int availableContexts = 5;
        int availableContexts = 5 + BluetoothLeAudio.CONTEXT_TYPE_RINGTONE;;
        int groupStatus = LeAudioStackEvent.GROUP_STATUS_ACTIVE;
        BluetoothDevice leadDevice;
        BluetoothDevice memberDevice = mLeftDevice;