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 import static org.mockito.Mockito.mock; 20 import static org.mockito.Mockito.when; 21 22 import android.media.AudioDeviceInfo; 23 import android.media.AudioDevicePort; 24 import android.media.AudioGain; 25 26 public final class AudioDeviceInfoBuilder { 27 28 private String mAddressName; 29 private AudioGain[] mAudioGains; 30 private int mDeviceType = AudioDeviceInfo.TYPE_BUS; 31 private boolean mIsSource; 32 setAudioGains(AudioGain .... audioGains)33 public AudioDeviceInfoBuilder setAudioGains(AudioGain ... audioGains) { 34 mAudioGains = audioGains; 35 return this; 36 } 37 setAddressName(String addressName)38 public AudioDeviceInfoBuilder setAddressName(String addressName) { 39 mAddressName = addressName; 40 return this; 41 } 42 setType(int deviceType)43 public AudioDeviceInfoBuilder setType(int deviceType) { 44 mDeviceType = deviceType; 45 return this; 46 } 47 setIsSource(boolean isSource)48 public AudioDeviceInfoBuilder setIsSource(boolean isSource) { 49 mIsSource = isSource; 50 return this; 51 } 52 build()53 public AudioDeviceInfo build() { 54 AudioDevicePort port = mock(AudioDevicePort.class); 55 when(port.gains()).thenReturn(mAudioGains); 56 57 AudioDeviceInfo audioDeviceInfo = mock(AudioDeviceInfo.class); 58 when(audioDeviceInfo.getAddress()).thenReturn(mAddressName); 59 when(audioDeviceInfo.getType()).thenReturn(mDeviceType); 60 when(audioDeviceInfo.isSource()).thenReturn(mIsSource); 61 when(audioDeviceInfo.isSink()).thenReturn(!mIsSource); 62 when(audioDeviceInfo.getInternalType()) 63 .thenReturn(AudioDeviceInfo.convertDeviceTypeToInternalInputDevice(mDeviceType)); 64 when(audioDeviceInfo.getPort()).thenReturn(port); 65 return audioDeviceInfo; 66 } 67 } 68