1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.audio; 18 19 20 import static android.media.AudioAttributes.USAGE_MEDIA; 21 22 import static org.mockito.Mockito.mock; 23 import static org.mockito.Mockito.when; 24 25 import android.media.AudioAttributes; 26 import android.media.AudioDeviceInfo; 27 import android.media.AudioPlaybackConfiguration; 28 29 final class AudioPlaybackConfigurationBuilder { 30 private @AudioAttributes.AttributeUsage int mUsage = USAGE_MEDIA; 31 private boolean mIsActive = true; 32 private String mDeviceAddress = ""; 33 setUsage(@udioAttributes.AttributeUsage int usage)34 AudioPlaybackConfigurationBuilder setUsage(@AudioAttributes.AttributeUsage int usage) { 35 mUsage = usage; 36 return this; 37 } 38 setDeviceAddress(String deviceAddress)39 AudioPlaybackConfigurationBuilder setDeviceAddress(String deviceAddress) { 40 mDeviceAddress = deviceAddress; 41 return this; 42 } 43 setInactive()44 AudioPlaybackConfigurationBuilder setInactive() { 45 mIsActive = false; 46 return this; 47 } 48 build()49 AudioPlaybackConfiguration build() { 50 AudioPlaybackConfiguration configuration = mock(AudioPlaybackConfiguration.class); 51 AudioAttributes attributes = new AudioAttributes.Builder().setUsage(mUsage).build(); 52 AudioDeviceInfo outputDevice = generateOutAudioDeviceInfo(mDeviceAddress); 53 when(configuration.getAudioAttributes()).thenReturn(attributes); 54 when(configuration.getAudioDeviceInfo()).thenReturn(outputDevice); 55 when(configuration.isActive()).thenReturn(mIsActive); 56 return configuration; 57 } 58 generateOutAudioDeviceInfo(String address)59 private AudioDeviceInfo generateOutAudioDeviceInfo(String address) { 60 AudioDeviceInfo audioDeviceInfo = mock(AudioDeviceInfo.class); 61 when(audioDeviceInfo.getAddress()).thenReturn(address); 62 when(audioDeviceInfo.getType()).thenReturn(AudioDeviceInfo.TYPE_BUS); 63 when(audioDeviceInfo.isSource()).thenReturn(false); 64 when(audioDeviceInfo.isSink()).thenReturn(true); 65 when(audioDeviceInfo.getInternalType()).thenReturn(AudioDeviceInfo 66 .convertDeviceTypeToInternalInputDevice(AudioDeviceInfo.TYPE_BUS)); 67 return audioDeviceInfo; 68 } 69 } 70