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.AudioGain;
23 
24 public final class GainBuilder {
25     public static final int MIN_GAIN = 0;
26     public static final int MAX_GAIN = 100;
27     public static final int DEFAULT_GAIN = 50;
28     public static final int STEP_SIZE = 2;
29 
30     private int mMode = AudioGain.MODE_JOINT;
31     private int mMaxValue = MAX_GAIN;
32     private int mMinValue = MIN_GAIN;
33     private int mDefaultValue = DEFAULT_GAIN;
34     private int mStepSize = STEP_SIZE;
35 
setMode(int mode)36     GainBuilder setMode(int mode) {
37         mMode = mode;
38         return this;
39     }
40 
setMaxValue(int maxValue)41     GainBuilder setMaxValue(int maxValue) {
42         mMaxValue = maxValue;
43         return this;
44     }
45 
setMinValue(int minValue)46     GainBuilder setMinValue(int minValue) {
47         mMinValue = minValue;
48         return this;
49     }
50 
setDefaultValue(int defaultValue)51     GainBuilder setDefaultValue(int defaultValue) {
52         mDefaultValue = defaultValue;
53         return this;
54     }
55 
setStepSize(int stepSize)56     GainBuilder setStepSize(int stepSize) {
57         mStepSize = stepSize;
58         return this;
59     }
60 
build()61     AudioGain build() {
62         AudioGain mockGain = mock(AudioGain.class);
63         when(mockGain.mode()).thenReturn(mMode);
64         when(mockGain.maxValue()).thenReturn(mMaxValue);
65         when(mockGain.minValue()).thenReturn(mMinValue);
66         when(mockGain.defaultValue()).thenReturn(mDefaultValue);
67         when(mockGain.stepValue()).thenReturn(mStepSize);
68         return mockGain;
69     }
70 }
71