blob: 698db0ab99610114913caf0fc8e4904e22cf842d [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
2 * Copyright (C) 2013 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
17package com.android.incallui;
18
19import android.telecom.CallAudioState;
20import java.util.ArrayList;
21import java.util.List;
22
23/** Proxy class for getting and setting the audio mode. */
24public class AudioModeProvider {
25 private static final int SUPPORTED_AUDIO_ROUTE_ALL =
26 CallAudioState.ROUTE_EARPIECE
27 | CallAudioState.ROUTE_BLUETOOTH
28 | CallAudioState.ROUTE_WIRED_HEADSET
29 | CallAudioState.ROUTE_SPEAKER;
30
31 private static final AudioModeProvider instance = new AudioModeProvider();
32 private final List<AudioModeListener> listeners = new ArrayList<>();
33 private CallAudioState audioState =
34 new CallAudioState(false, CallAudioState.ROUTE_EARPIECE, SUPPORTED_AUDIO_ROUTE_ALL);
35
36 public static AudioModeProvider getInstance() {
37 return instance;
38 }
39
40 public void onAudioStateChanged(CallAudioState audioState) {
41 if (!this.audioState.equals(audioState)) {
42 this.audioState = audioState;
43 for (AudioModeListener listener : listeners) {
44 listener.onAudioStateChanged(audioState);
45 }
46 }
47 }
48
49 public void addListener(AudioModeListener listener) {
50 if (!listeners.contains(listener)) {
51 listeners.add(listener);
52 listener.onAudioStateChanged(audioState);
53 }
54 }
55
56 public void removeListener(AudioModeListener listener) {
57 listeners.remove(listener);
58 }
59
60 public CallAudioState getAudioState() {
61 return audioState;
62 }
63
64 /** Notified on changes to audio mode. */
65 public interface AudioModeListener {
66
67 void onAudioStateChanged(CallAudioState audioState);
68 }
69}