1 /* 2 * Copyright (C) 2024 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.AudioGain; 24 25 public final class AudioDeviceInfoBuilder { 26 27 private String mAddressName; 28 private AudioGain[] mAudioGains; 29 private int mDeviceType = AudioDeviceInfo.TYPE_BUS; 30 private boolean mIsSource; 31 private boolean mBuilt = false; 32 33 /** 34 * Sets the audio gains. 35 */ setAudioGains(AudioGain .... audioGains)36 public AudioDeviceInfoBuilder setAudioGains(AudioGain ... audioGains) { 37 mAudioGains = audioGains; 38 return this; 39 } 40 41 /** 42 * Sets the address name. 43 */ setAddressName(String addressName)44 public AudioDeviceInfoBuilder setAddressName(String addressName) { 45 mAddressName = addressName; 46 return this; 47 } 48 49 /** 50 * Sets the device type. 51 */ setType(int deviceType)52 public AudioDeviceInfoBuilder setType(int deviceType) { 53 mDeviceType = deviceType; 54 return this; 55 } 56 57 /** 58 * Sets whether is source. 59 */ setIsSource(boolean isSource)60 public AudioDeviceInfoBuilder setIsSource(boolean isSource) { 61 mIsSource = isSource; 62 return this; 63 } 64 65 /** 66 * Builds the audio device info. 67 */ build()68 public AudioDeviceInfo build() { 69 if (mBuilt) { 70 throw new IllegalStateException("A builder is only supposed to be built once"); 71 } 72 mBuilt = true; 73 AudioDeviceInfo audioDeviceInfo = mock(AudioDeviceInfo.class); 74 when(audioDeviceInfo.getAddress()).thenReturn(mAddressName); 75 when(audioDeviceInfo.isSource()).thenReturn(mIsSource); 76 return audioDeviceInfo; 77 } 78 } 79