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

Commit 16e728fb authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9381392 from 49008ab2 to tm-qpr2-release

Change-Id: Ie3b148efa702597af84d7d4a746249cf7fe85660
parents 3ffb3cea 49008ab2
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -111,7 +111,8 @@ public class LeAudioNativeInterface {
        sendMessageToService(event);
    }

    private void onConnectionStateChanged(int state, byte[] address) {
    @VisibleForTesting
    void onConnectionStateChanged(int state, byte[] address) {
        LeAudioStackEvent event =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED);
        event.device = getDevice(address);
@@ -123,7 +124,8 @@ public class LeAudioNativeInterface {
        sendMessageToService(event);
    }

    private void onGroupStatus(int groupId, int groupStatus) {
    @VisibleForTesting
    void onGroupStatus(int groupId, int groupStatus) {
        LeAudioStackEvent event =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_GROUP_STATUS_CHANGED);
        event.valueInt1 = groupId;
@@ -135,7 +137,8 @@ public class LeAudioNativeInterface {
        sendMessageToService(event);
    }

    private void onGroupNodeStatus(byte[] address, int groupId, int nodeStatus) {
    @VisibleForTesting
    void onGroupNodeStatus(byte[] address, int groupId, int nodeStatus) {
        LeAudioStackEvent event =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_GROUP_NODE_STATUS_CHANGED);
        event.valueInt1 = groupId;
@@ -148,7 +151,8 @@ public class LeAudioNativeInterface {
        sendMessageToService(event);
    }

    private void onAudioConf(int direction, int groupId, int sinkAudioLocation,
    @VisibleForTesting
    void onAudioConf(int direction, int groupId, int sinkAudioLocation,
                             int sourceAudioLocation, int availableContexts) {
        LeAudioStackEvent event =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_AUDIO_CONF_CHANGED);
@@ -164,7 +168,8 @@ public class LeAudioNativeInterface {
        sendMessageToService(event);
    }

    private void onSinkAudioLocationAvailable(byte[] address, int sinkAudioLocation) {
    @VisibleForTesting
    void onSinkAudioLocationAvailable(byte[] address, int sinkAudioLocation) {
        LeAudioStackEvent event =
                new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_SINK_AUDIO_LOCATION_AVAILABLE);
        event.device = getDevice(address);
@@ -176,7 +181,8 @@ public class LeAudioNativeInterface {
        sendMessageToService(event);
    }

    private void onAudioLocalCodecCapabilities(
    @VisibleForTesting
    void onAudioLocalCodecCapabilities(
                            BluetoothLeAudioCodecConfig[] localInputCodecCapabilities,
                            BluetoothLeAudioCodecConfig[] localOutputCodecCapabilities) {
        LeAudioStackEvent event =
@@ -192,7 +198,8 @@ public class LeAudioNativeInterface {
        sendMessageToService(event);
    }

    private void onAudioGroupCodecConf(int groupId, BluetoothLeAudioCodecConfig inputCodecConfig,
    @VisibleForTesting
    void onAudioGroupCodecConf(int groupId, BluetoothLeAudioCodecConfig inputCodecConfig,
                            BluetoothLeAudioCodecConfig outputCodecConfig,
                            BluetoothLeAudioCodecConfig [] inputSelectableCodecConfig,
                            BluetoothLeAudioCodecConfig [] outputSelectableCodecConfig) {
+2 −1
Original line number Diff line number Diff line
@@ -406,7 +406,8 @@ public class LeAudioService extends ProfileService {
        return sLeAudioService;
    }

    private static synchronized void setLeAudioService(LeAudioService instance) {
    @VisibleForTesting
    static synchronized void setLeAudioService(LeAudioService instance) {
        if (DBG) {
            Log.d(TAG, "setLeAudioService(): set to: " + instance);
        }
+14 −8
Original line number Diff line number Diff line
@@ -260,8 +260,8 @@ public class VolumeControlNativeInterface {
    // Callbacks from the native stack back into the Java framework.
    // All callbacks are routed via the Service which will disambiguate which
    // state machine the message should be routed to.

    private void onConnectionStateChanged(int state, byte[] address) {
    @VisibleForTesting
    void onConnectionStateChanged(int state, byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(
                        VolumeControlStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED);
@@ -274,7 +274,8 @@ public class VolumeControlNativeInterface {
        sendMessageToService(event);
    }

    private void onVolumeStateChanged(int volume, boolean mute, byte[] address,
    @VisibleForTesting
    void onVolumeStateChanged(int volume, boolean mute, byte[] address,
            boolean isAutonomous) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(
@@ -291,7 +292,8 @@ public class VolumeControlNativeInterface {
        sendMessageToService(event);
    }

    private void onGroupVolumeStateChanged(int volume, boolean mute, int groupId,
    @VisibleForTesting
    void onGroupVolumeStateChanged(int volume, boolean mute, int groupId,
            boolean isAutonomous) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(
@@ -308,7 +310,8 @@ public class VolumeControlNativeInterface {
        sendMessageToService(event);
    }

    private void onDeviceAvailable(int numOfExternalOutputs,
    @VisibleForTesting
    void onDeviceAvailable(int numOfExternalOutputs,
                                   byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(
@@ -322,7 +325,8 @@ public class VolumeControlNativeInterface {
        sendMessageToService(event);
    }

    private void onExtAudioOutVolumeOffsetChanged(int externalOutputId, int offset,
    @VisibleForTesting
    void onExtAudioOutVolumeOffsetChanged(int externalOutputId, int offset,
                                               byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(
@@ -337,7 +341,8 @@ public class VolumeControlNativeInterface {
        sendMessageToService(event);
    }

    private void onExtAudioOutLocationChanged(int externalOutputId, int location,
    @VisibleForTesting
    void onExtAudioOutLocationChanged(int externalOutputId, int location,
                                               byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(
@@ -352,7 +357,8 @@ public class VolumeControlNativeInterface {
        sendMessageToService(event);
    }

    private void onExtAudioOutDescriptionChanged(int externalOutputId, String descr,
    @VisibleForTesting
    void onExtAudioOutDescriptionChanged(int externalOutputId, String descr,
                                               byte[] address) {
        VolumeControlStackEvent event =
                new VolumeControlStackEvent(
+2 −1
Original line number Diff line number Diff line
@@ -345,7 +345,8 @@ public class VolumeControlService extends ProfileService {
        return sVolumeControlService;
    }

    private static synchronized void setVolumeControlService(VolumeControlService instance) {
    @VisibleForTesting
    static synchronized void setVolumeControlService(VolumeControlService instance) {
        if (DBG) {
            Log.d(TAG, "setVolumeControlService(): set to: " + instance);
        }
+112 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.le_audio;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothLeAudioCodecConfig;
import android.bluetooth.BluetoothLeBroadcastMetadata;

import androidx.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@RunWith(AndroidJUnit4.class)
public class LeAudioBroadcasterNativeInterfaceTest {
    @Mock
    private LeAudioService mMockService;

    private LeAudioBroadcasterNativeInterface mNativeInterface;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        when(mMockService.isAvailable()).thenReturn(true);
        LeAudioService.setLeAudioService(mMockService);
        mNativeInterface = LeAudioBroadcasterNativeInterface.getInstance();
    }

    @After
    public void tearDown() {
        LeAudioService.setLeAudioService(null);
    }

    @Test
    public void onBroadcastCreated() {
        int broadcastId = 1;
        boolean success = true;

        mNativeInterface.onBroadcastCreated(broadcastId, success);

        ArgumentCaptor<LeAudioStackEvent> event =
                ArgumentCaptor.forClass(LeAudioStackEvent.class);
        verify(mMockService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                LeAudioStackEvent.EVENT_TYPE_BROADCAST_CREATED);
    }

    @Test
    public void onBroadcastDestroyed() {
        int broadcastId = 1;

        mNativeInterface.onBroadcastDestroyed(broadcastId);

        ArgumentCaptor<LeAudioStackEvent> event =
                ArgumentCaptor.forClass(LeAudioStackEvent.class);
        verify(mMockService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                LeAudioStackEvent.EVENT_TYPE_BROADCAST_DESTROYED);
    }

    @Test
    public void onBroadcastStateChanged() {
        int broadcastId = 1;
        int state = 0;

        mNativeInterface.onBroadcastStateChanged(broadcastId, state);

        ArgumentCaptor<LeAudioStackEvent> event =
                ArgumentCaptor.forClass(LeAudioStackEvent.class);
        verify(mMockService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                LeAudioStackEvent.EVENT_TYPE_BROADCAST_STATE);
    }

    @Test
    public void onBroadcastMetadataChanged() {
        int broadcastId = 1;
        BluetoothLeBroadcastMetadata metadata = null;

        mNativeInterface.onBroadcastMetadataChanged(broadcastId, metadata);

        ArgumentCaptor<LeAudioStackEvent> event =
                ArgumentCaptor.forClass(LeAudioStackEvent.class);
        verify(mMockService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                LeAudioStackEvent.EVENT_TYPE_BROADCAST_METADATA_CHANGED);
    }
}
Loading