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

Commit 9c2f489c authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I77552129,I9708db62,Ibfb4d480,Ieac5e4aa,Id79e5ae2 into main

* changes:
  AICS: onExtAudioInGainPropsChanged: skip serialize
  AICS: onExtAudioInDescriptionChanged: skip serialize
  AICS: onExtAudioInTypeChanged: skip serialize
  AICS: onExtAudioInStatusChanged: skip serialize
  AICS: onExtAudioInStateChanged: skip serialize
parents abc9fd95 da8c535b
Loading
Loading
Loading
Loading
+29 −56
Original line number Diff line number Diff line
@@ -18,11 +18,6 @@ package com.android.bluetooth.vc;

import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED;
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;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_VOL_OFFSET_CHANGED;
@@ -36,6 +31,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 +50,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,68 +151,31 @@ 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
    void onExtAudioInStatusChanged(int externalInputId, int status, byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED);
        event.device = getDevice(address);
        event.valueInt1 = externalInputId;
        event.valueInt2 = status;

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

    @VisibleForTesting
    void onExtAudioInTypeChanged(int externalInputId, int type, byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED);
        event.device = getDevice(address);
        event.valueInt1 = externalInputId;
        event.valueInt2 = type;

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

    @VisibleForTesting
    void onExtAudioInDescriptionChanged(int externalInputId, String descr, byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED);
        event.device = getDevice(address);
        event.valueInt1 = externalInputId;
        event.valueString1 = descr;

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

    @VisibleForTesting
    void onExtAudioInGainPropsChanged(
            int externalInputId, int unit, int min, int max, byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED);
        event.device = getDevice(address);
        event.valueInt1 = externalInputId;
        event.valueInt2 = unit;
        event.valueInt3 = min;
        event.valueInt4 = max;

        Log.d(TAG, "onExtAudioInGainPropsChanged: " + event);
        mVolumeControlService.messageFromNative(event);
    void onExtAudioInGainPropsChanged(int id, int unit, int min, int max, byte[] address) {
        sendMessageToService(
                s -> s.onExtAudioInGainPropsChanged(getDevice(address), id, unit, min, max));
    }
}
+10 −48
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)
@@ -1051,9 +1051,9 @@ public class VolumeControlService extends ProfileService {
        input.setState(id, gainSetting, mute, gainMode);
    }

    void handleDeviceExtInputStatusChanged(BluetoothDevice device, int id, int status) {
    void onExtAudioInStatusChanged(BluetoothDevice device, int id, int status) {
        String logInfo =
                "handleDeviceExtInputStatusChanged("
                "onExtAudioInStatusChanged("
                        + ("device:" + device)
                        + (", id" + id)
                        + (", status" + status)
@@ -1074,9 +1074,9 @@ public class VolumeControlService extends ProfileService {
        input.setStatus(id, status);
    }

    void handleDeviceExtInputTypeChanged(BluetoothDevice device, int id, int type) {
    void onExtAudioInTypeChanged(BluetoothDevice device, int id, int type) {
        String logInfo =
                "handleDeviceExtInputTypeChanged("
                "onExtAudioInTypeChanged("
                        + ("device:" + device)
                        + (", id" + id)
                        + (", type" + type)
@@ -1097,10 +1097,9 @@ public class VolumeControlService extends ProfileService {
        input.setType(id, type);
    }

    void handleDeviceExtInputDescriptionChanged(
            BluetoothDevice device, int id, String description) {
    void onExtAudioInDescriptionChanged(BluetoothDevice device, int id, String description) {
        String logInfo =
                "handleDeviceExtInputDescriptionChanged("
                "onExtAudioInDescriptionChanged("
                        + ("device:" + device)
                        + (", id" + id)
                        + (", description" + description)
@@ -1121,10 +1120,9 @@ public class VolumeControlService extends ProfileService {
        input.setDescription(id, description);
    }

    void handleDeviceExtInputGainPropsChanged(
            BluetoothDevice device, int id, int unit, int min, int max) {
    void onExtAudioInGainPropsChanged(BluetoothDevice device, int id, int unit, int min, int max) {
        String logInfo =
                "handleDeviceExtInputGainPropsChanged("
                "onExtAudioInGainPropsChanged("
                        + ("device:" + device)
                        + (", id" + id)
                        + (" unit: " + unit + " min" + min + " max:" + max)
@@ -1184,42 +1182,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;
        }

        if (stackEvent.type == VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED) {
            handleDeviceExtInputTypeChanged(device, stackEvent.valueInt1, stackEvent.valueInt2);
            return;
        }

        if (stackEvent.type == VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED) {
            handleDeviceExtInputDescriptionChanged(
                    device, stackEvent.valueInt1, stackEvent.valueString1);
            return;
        }

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

        synchronized (mStateMachines) {
            VolumeControlStateMachine sm = mStateMachines.get(device);
            if (sm == null) {
+0 −44
Original line number Diff line number Diff line
@@ -29,18 +29,12 @@ 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;
    public static final int EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED = 11;

    public int type;
    public BluetoothDevice device;
    public int valueInt1;
    public int valueInt2;
    public int valueInt3;
    public int valueInt4;
    public boolean valueBool1;
    public boolean valueBool2;
    public String valueString1;
@@ -60,7 +54,6 @@ public class VolumeControlStackEvent {
        result.append(", valueInt1:").append(eventTypeValue1ToString(type, valueInt1));
        result.append(", valueInt2:").append(eventTypeValue2ToString(type, valueInt2));
        result.append(", valueInt3:").append(eventTypeValue3ToString(type, valueInt3));
        result.append(", valueInt4:").append(eventTypeValue4ToString(type, valueInt4));
        result.append(", valueBool1:").append(eventTypeValueBool1ToString(type, valueBool1));
        result.append(", valueBool2:").append(eventTypeValueBool2ToString(type, valueBool2));
        result.append(", valueString1:").append(eventTypeString1ToString(type, valueString1));
@@ -84,16 +77,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:
                return "EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED";
            case EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED:
                return "EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED";
            case EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED:
                return "EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED";
            default:
                return "EVENT_TYPE_UNKNOWN:" + type;
        }
@@ -111,12 +94,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:
            case EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED:
                return "{ext input id:" + value + "}";
            default:
                break;
        }
@@ -131,12 +108,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:
                return "{type:" + value + "}";
            default:
                break;
        }
@@ -145,8 +116,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:
@@ -155,18 +124,6 @@ public class VolumeControlStackEvent {
        return Integer.toString(value);
    }

    private static String eventTypeValue4ToString(int type, int value) {
        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;
        }
        return Integer.toString(value);
    }

    private static String eventTypeValueBool1ToString(int type, boolean value) {
        switch (type) {
            case EVENT_TYPE_VOLUME_STATE_CHANGED:
@@ -190,7 +147,6 @@ public class VolumeControlStackEvent {
    private static String eventTypeString1ToString(int type, String value) {
        switch (type) {
            case EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED:
            case EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED:
                return "{description:" + value + "}";
            default:
                break;
+21 −35
Original line number Diff line number Diff line
@@ -18,16 +18,14 @@ package com.android.bluetooth.vc;

import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED;
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;
import static com.android.bluetooth.vc.VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED;
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 +59,8 @@ public class VolumeControlNativeCallbackTest {

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

        mNativeCallback = new VolumeControlNativeCallback(mAdapterService, mService);
    }

@@ -158,65 +158,51 @@ 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
    public void onExtAudioInStatusChanged() {
        int externalInputId = 2;
        int id = 2;
        int status = 1;

        mNativeCallback.onExtAudioInStatusChanged(externalInputId, status, null);
        verify(mService).messageFromNative(mEvent.capture());
        VolumeControlStackEvent event = mEvent.getValue();

        expect.that(event.type).isEqualTo(EVENT_TYPE_EXT_AUDIO_IN_STATUS_CHANGED);
        mNativeCallback.onExtAudioInStatusChanged(id, status, null);
        verify(mService).onExtAudioInStatusChanged(any(), eq(id), eq(status));
    }

    @Test
    public void onExtAudioInTypeChanged() {
        int externalInputId = 2;
        int id = 2;
        int type = 1;

        mNativeCallback.onExtAudioInTypeChanged(externalInputId, type, null);
        verify(mService).messageFromNative(mEvent.capture());
        VolumeControlStackEvent event = mEvent.getValue();

        expect.that(event.type).isEqualTo(EVENT_TYPE_EXT_AUDIO_IN_TYPE_CHANGED);
        mNativeCallback.onExtAudioInTypeChanged(id, type, null);
        verify(mService).onExtAudioInTypeChanged(any(), eq(id), eq(type));
    }

    @Test
    public void onExtAudioInDescriptionChanged() {
        int externalInputId = 2;
        int id = 2;
        String descr = "microphone";

        mNativeCallback.onExtAudioInDescriptionChanged(externalInputId, descr, null);
        verify(mService).messageFromNative(mEvent.capture());
        VolumeControlStackEvent event = mEvent.getValue();

        expect.that(event.type).isEqualTo(EVENT_TYPE_EXT_AUDIO_IN_DESCR_CHANGED);
        mNativeCallback.onExtAudioInDescriptionChanged(id, descr, null);
        verify(mService).onExtAudioInDescriptionChanged(any(), eq(id), eq(descr));
    }

    @Test
    public void onExtAudioInGainPropsChanged() {
        int externalInputId = 2;
        int id = 2;
        int unit = 1;
        int min = 0;
        int max = 100;

        mNativeCallback.onExtAudioInGainPropsChanged(externalInputId, unit, min, max, null);
        verify(mService).messageFromNative(mEvent.capture());
        VolumeControlStackEvent event = mEvent.getValue();

        expect.that(event.type).isEqualTo(EVENT_TYPE_EXT_AUDIO_IN_GAIN_PROPS_CHANGED);
        mNativeCallback.onExtAudioInGainPropsChanged(id, unit, min, max, null);
        verify(mService).onExtAudioInGainPropsChanged(any(), eq(id), eq(unit), eq(min), eq(max));
    }
}