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

Commit b8c2d0dc authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

GTBS: Respect inband configuration

This patch just takes inband ringtone flag from the LeAudioService.
For now, even it is done per device, it will always return single value.
It is done like that as a preparation for following patch which will
alow to handle different configuration per device

Bug: 242685105
Test: atest BluetoothInstrumentationTests
Tag: #feature

Change-Id: I76c02e87b092bbb00070a3543c9a22e46823de85
parent 837e8d56
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattServerCallback;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothManager;
import android.bluetooth.IBluetoothStateChangeCallback;
import android.content.Context;
@@ -36,8 +35,8 @@ import android.os.ParcelUuid;
import android.os.RemoteException;
import android.util.Log;

import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.internal.annotations.VisibleForTesting;

import java.io.ByteArrayOutputStream;
@@ -154,6 +153,14 @@ public class TbsGatt {

        public abstract void onCallControlPointRequest(BluetoothDevice device, int opcode,
                byte[] args);

        /**
         * Check if device has enabled inband ringtone
         *
         * @param device device which is checked for inband ringtone availability
         * @return  {@code true} if enabled, {@code false} otherwise
         */
        public abstract boolean isInbandRingtoneEnabled(BluetoothDevice device);
    }

    TbsGatt(Context context) {
@@ -808,6 +815,14 @@ public class TbsGatt {
            if (value == null) {
                value = new byte[0];
            }
            /* TODO: Properly handle caching for multiple devices.
             * This patch assumes, LeAudio services just uses single value
             * for inband ringtone */
            if (characteristic.getUuid().equals(UUID_STATUS_FLAGS) && (value.length == 2)) {
                if (mCallback.isInbandRingtoneEnabled(device)) {
                    value[0] = (byte) (value[0] | STATUS_FLAG_INBAND_RINGTONE_ENABLED);
                }
            }

            int status;
            if (value.length < offset) {
+10 −3
Original line number Diff line number Diff line
@@ -192,9 +192,6 @@ public class TbsGeneric {
            mTbsGatt.clearSilentModeFlag();
        }

        // Android supports inband ringtone
        mTbsGatt.setInbandRingtoneFlag();

        mReceiver = new Receiver();
        mTbsGatt.getContext().registerReceiver(mReceiver,
                new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION));
@@ -751,6 +748,16 @@ public class TbsGeneric {
            }
        }

        @Override
        public boolean isInbandRingtoneEnabled(BluetoothDevice device) {
            if (!isLeAudioServiceAvailable()) {
                Log.i(TAG, "LeAudio service not available");
                return false;
            }
            int groupId = mLeAudioService.getGroupId(device);
            return mLeAudioService.isInbandRingtoneEnabled(groupId);
        }

        @Override
        public void onCallControlPointRequest(BluetoothDevice device, int opcode, byte[] args) {
            synchronized (TbsGeneric.this) {
+12 −0
Original line number Diff line number Diff line
@@ -558,6 +558,18 @@ public class TbsGattTest {
                aryEq(new byte[] {0x0A}));
    }

    @Test
    public void testHandleIsInbandRingtoneEnabled() {
        prepareDefaultService();
        BluetoothGattCharacteristic characteristic =
                getCharacteristic(TbsGatt.UUID_STATUS_FLAGS);

        mTbsGatt.mGattServerCallback.onCharacteristicReadRequest(mCurrentDevice, 1, 0,
                characteristic);
        // Verify the higher layer callback call
        verify(mMockTbsGattCallback).isInbandRingtoneEnabled(eq(mCurrentDevice));
    }

    @Test
    public void testClientCharacteristicConfiguration() {
        prepareDefaultService();