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

Commit c3d1b1e1 authored by Adrian Roos's avatar Adrian Roos Committed by Gerrit Code Review
Browse files

Merge "Revert "Add VolumeControlNativeInterfaceTest""

parents 48196184 56c55c0f
Loading
Loading
Loading
Loading
+8 −14
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.
    @VisibleForTesting
    void onConnectionStateChanged(int state, byte[] address) {

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

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

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

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

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

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

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

    @VisibleForTesting
    static synchronized void setVolumeControlService(VolumeControlService instance) {
    private static synchronized void setVolumeControlService(VolumeControlService instance) {
        if (DBG) {
            Log.d(TAG, "setVolumeControlService(): set to: " + instance);
        }
+0 −159
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.vc;

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

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

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.TestUtils;

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 VolumeControlNativeInterfaceTest {
    @Mock
    private VolumeControlService mService;

    private VolumeControlNativeInterface mNativeInterface;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        when(mService.isAvailable()).thenReturn(true);
        VolumeControlService.setVolumeControlService(mService);
        mNativeInterface = VolumeControlNativeInterface.getInstance();
    }

    @Test
    public void onConnectionStateChanged() {
        int state = VolumeControlStackEvent.CONNECTION_STATE_CONNECTED;
        byte[] address = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };

        mNativeInterface.onConnectionStateChanged(state, address);

        ArgumentCaptor<VolumeControlStackEvent> event =
                ArgumentCaptor.forClass(VolumeControlStackEvent.class);
        verify(mService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                VolumeControlStackEvent.EVENT_TYPE_CONNECTION_STATE_CHANGED);
    }

    @Test
    public void onVolumeStateChanged() {
        int volume = 3;
        boolean mute = false;
        byte[] address = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
        boolean isAutonomous = false;

        mNativeInterface.onVolumeStateChanged(volume, mute, address, isAutonomous);

        ArgumentCaptor<VolumeControlStackEvent> event =
                ArgumentCaptor.forClass(VolumeControlStackEvent.class);
        verify(mService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                VolumeControlStackEvent.EVENT_TYPE_VOLUME_STATE_CHANGED);
    }

    @Test
    public void onGroupVolumeStateChanged() {
        int volume = 3;
        boolean mute = false;
        int groupId = 1;
        boolean isAutonomous = false;

        mNativeInterface.onGroupVolumeStateChanged(volume, mute, groupId, isAutonomous);

        ArgumentCaptor<VolumeControlStackEvent> event =
                ArgumentCaptor.forClass(VolumeControlStackEvent.class);
        verify(mService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                VolumeControlStackEvent.EVENT_TYPE_VOLUME_STATE_CHANGED);
        assertThat(event.getValue().valueInt1).isEqualTo(groupId);
    }

    @Test
    public void onDeviceAvailable() {
        int numOfExternalOutputs = 3;
        byte[] address = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };

        mNativeInterface.onDeviceAvailable(numOfExternalOutputs, address);

        ArgumentCaptor<VolumeControlStackEvent> event =
                ArgumentCaptor.forClass(VolumeControlStackEvent.class);
        verify(mService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                VolumeControlStackEvent.EVENT_TYPE_DEVICE_AVAILABLE);
    }
    @Test
    public void onExtAudioOutVolumeOffsetChanged() {
        int externalOutputId = 2;
        int offset = 0;
        byte[] address = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };

        mNativeInterface.onExtAudioOutVolumeOffsetChanged(externalOutputId, offset, address);

        ArgumentCaptor<VolumeControlStackEvent> event =
                ArgumentCaptor.forClass(VolumeControlStackEvent.class);
        verify(mService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_VOL_OFFSET_CHANGED);
    }

    @Test
    public void onExtAudioOutLocationChanged() {
        int externalOutputId = 2;
        int location = 100;
        byte[] address = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };

        mNativeInterface.onExtAudioOutLocationChanged(externalOutputId, location, address);

        ArgumentCaptor<VolumeControlStackEvent> event =
                ArgumentCaptor.forClass(VolumeControlStackEvent.class);
        verify(mService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_LOCATION_CHANGED);
    }

    @Test
    public void onExtAudioOutDescriptionChanged() {
        int externalOutputId = 2;
        String descr = "test-descr";
        byte[] address = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };

        mNativeInterface.onExtAudioOutDescriptionChanged(externalOutputId, descr, address);

        ArgumentCaptor<VolumeControlStackEvent> event =
                ArgumentCaptor.forClass(VolumeControlStackEvent.class);
        verify(mService).messageFromNative(event.capture());
        assertThat(event.getValue().type).isEqualTo(
                VolumeControlStackEvent.EVENT_TYPE_EXT_AUDIO_OUT_DESCRIPTION_CHANGED);
    }
}