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

Commit 1e71c962 authored by William Escande's avatar William Escande
Browse files

AICS: onExtAudioInStateChanged: skip serialize

Bug: 361263965
Test: atest vc_test
Flag: com.android.bluetooth.flags.leaudio_add_aics_support
Change-Id: Id79e5ae2249ee99eab4749f32e85eb937e60608c
parent 5c4b8b1b
Loading
Loading
Loading
Loading
+20 −13
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_CONNEC
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_DEVICE_AVAILABLE;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED;
@@ -36,6 +35,9 @@ import android.util.Log;
import com.android.bluetooth.btservice.AdapterService;
import com.android.internal.annotations.VisibleForTesting;

import java.util.Arrays;
import java.util.function.Consumer;

class VolumeControlNativeCallback {
    private static final String TAG = VolumeControlNativeCallback.class.getSimpleName();

@@ -52,6 +54,18 @@ class VolumeControlNativeCallback {
        return mAdapterService.getDeviceFromByte(address);
    }

    private void sendMessageToService(Consumer<VolumeControlService> action) {
        if (!mVolumeControlService.isAvailable()) {
            StringBuilder sb = new StringBuilder();
            Arrays.stream(new Throwable().getStackTrace())
                    .skip(1) // skip the inlineStackTrace method in the outputted stack trace
                    .forEach(trace -> sb.append(" [at ").append(trace).append("]"));
            Log.e(TAG, "Action ignored, service not available: " + sb.toString());
            return;
        }
        action.accept(mVolumeControlService);
    }

    @VisibleForTesting
    void onConnectionStateChanged(int state, byte[] address) {
        VolumeControlStackEvent event =
@@ -141,18 +155,11 @@ class VolumeControlNativeCallback {
    }

    @VisibleForTesting
    void onExtAudioInStateChanged(
            int externalInputId, int gainSetting, int mute, int gainMode, byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED);
        event.device = getDevice(address);
        event.valueInt1 = externalInputId;
        event.valueInt2 = gainSetting;
        event.valueInt3 = gainMode;
        event.valueInt4 = mute;

        Log.d(TAG, "onExtAudioInStateChanged: " + event);
        mVolumeControlService.messageFromNative(event);
    void onExtAudioInStateChanged(int id, int gainSetting, int gainMode, int mute, byte[] address) {
        sendMessageToService(
                s ->
                        s.onExtAudioInStateChanged(
                                getDevice(address), id, gainSetting, mute, gainMode));
    }

    @VisibleForTesting
+2 −12
Original line number Diff line number Diff line
@@ -1030,10 +1030,10 @@ public class VolumeControlService extends ProfileService {
        }
    }

    void handleDeviceExtInputStateChanged(
    void onExtAudioInStateChanged(
            BluetoothDevice device, int id, int gainSetting, int mute, int gainMode) {
        String logInfo =
                "handleDeviceExtInputStateChanged("
                "onExtAudioInStateChanged("
                        + ("device:" + device)
                        + (", id" + id)
                        + (" gainSetting: " + gainSetting)
@@ -1184,16 +1184,6 @@ public class VolumeControlService extends ProfileService {
            return;
        }

        if (stackEvent.type == VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED) {
            handleDeviceExtInputStateChanged(
                    device,
                    stackEvent.valueInt1,
                    stackEvent.valueInt2,
                    stackEvent.valueInt4,
                    stackEvent.valueInt3);
            return;
        }

        if (stackEvent.type == VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED) {
            handleDeviceExtInputStatusChanged(device, stackEvent.valueInt1, stackEvent.valueInt2);
            return;
+0 −10
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ public class VolumeControlStackEvent {
    public static final int EVENT_TYPE_EXT_AUDIO_OUT_VOL_OFFSET_CHANGED = 4;
    public static final int EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED = 5;
    public static final int EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED = 6;
    public static final int EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED = 7;
    public static final int EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED = 8;
    public static final int EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED = 9;
    public static final int EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED = 10;
@@ -84,8 +83,6 @@ public class VolumeControlStackEvent {
                return "EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED";
            case EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED:
                return "EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED";
            case EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED:
                return "EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED";
            case EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED:
                return "EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED";
            case EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED:
@@ -111,7 +108,6 @@ public class VolumeControlStackEvent {
            case EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED:
            case EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED:
                return "{ext output id:" + value + "}";
            case EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED:
            case EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED:
            case EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED:
            case EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED:
@@ -131,8 +127,6 @@ public class VolumeControlStackEvent {
                return "{volume:" + value + "}";
            case EVENT_TYPE_DEVICE_AVAILABLE:
                return "{num_ext_inputs:" + value + "}";
            case EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED:
                return "{ext gain val:" + value + "}";
            case EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED:
                return "{status:" + value + "}";
            case EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED:
@@ -145,8 +139,6 @@ public class VolumeControlStackEvent {

    private static String eventTypeValue3ToString(int type, int value) {
        switch (type) {
            case EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED:
                return "{ext gain mode:" + value + "}";
            case EVENT_TYPE_VOLUME_STATE_CHANGED:
                return "{flags:" + value + "}";
            default:
@@ -159,8 +151,6 @@ public class VolumeControlStackEvent {
        switch (type) {
            case EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED:
                return "{gain set max:" + value + "}";
            case EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED:
                return "{mute:" + value + "}";
            default:
                break;
        }
+9 −7
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_CONNEC
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_DEVICE_AVAILABLE;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED;
@@ -28,6 +27,9 @@ import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AU
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_VOL_OFFSET_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_VOLUME_STATE_CHANGED;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.verify;

import android.bluetooth.BluetoothProfile;
@@ -61,6 +63,8 @@ public class VolumeControlNativeCallbackTest {

    @Before
    public void setUp() throws Exception {
        doReturn(true).when(mService).isAvailable();

        mNativeCallback = new VolumeControlNativeCallback(mAdapterService, mService);
    }

@@ -158,16 +162,14 @@ public class VolumeControlNativeCallbackTest {

    @Test
    public void onExtAudioInStateChanged() {
        int externalInputId = 2;
        int id = 2;
        int gainSetting = 1;
        int gainMode = 0;
        int mute = 0;

        mNativeCallback.onExtAudioInStateChanged(externalInputId, gainSetting, mute, gainMode, null);
        verify(mService).messageFromNative(mEvent.capture());
        VolumeControlStackEvent event = mEvent.getValue();

        expect.that(event.type).isEqualTo(EVENT_TYPE_EXT_AUDIO_IN_STATE_CHANGED);
        mNativeCallback.onExtAudioInStateChanged(id, gainSetting, mute, gainMode, null);
        verify(mService)
                .onExtAudioInStateChanged(any(), eq(id), eq(gainSetting), eq(mute), eq(gainMode));
    }

    @Test