AudioModeProvider.java revision 9de3d7c5188c02cabf03799f87d494ee7dc702cb
1/* 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 com.google.android.collect.Lists; 20 21import com.android.services.telephony.common.AudioMode; 22 23import java.util.List; 24 25 26/** 27 * Proxy class for getting and setting the audio mode. 28 */ 29/* package */ class AudioModeProvider { 30 31 private static AudioModeProvider sAudioModeProvider; 32 private int mAudioMode = AudioMode.EARPIECE; 33 private int mSupportedModes = AudioMode.ALL_MODES; 34 private final List<AudioModeListener> mListeners = Lists.newArrayList(); 35 36 public AudioModeProvider() { 37 } 38 39 public void onAudioModeChange(int newMode) { 40 mAudioMode = newMode; 41 42 for (AudioModeListener l : mListeners) { 43 l.onAudioMode(mAudioMode); 44 } 45 } 46 47 public void onSupportedAudioModeChange(int newModeMask) { 48 mSupportedModes = newModeMask; 49 50 for (AudioModeListener l : mListeners) { 51 l.onSupportedAudioMode(mSupportedModes); 52 } 53 } 54 55 public void addListener(AudioModeListener listener) { 56 if (!mListeners.contains(listener)) { 57 mListeners.add(listener); 58 listener.onSupportedAudioMode(mSupportedModes); 59 listener.onAudioMode(mAudioMode); 60 } 61 } 62 63 public void removeListener(AudioModeListener listener) { 64 if (mListeners.contains(listener)) { 65 mListeners.remove(listener); 66 } 67 } 68 69 public int getSupportedModes() { 70 return mSupportedModes; 71 } 72 73 public int getAudioMode() { 74 return mAudioMode; 75 } 76 77 /* package */ interface AudioModeListener { 78 void onAudioMode(int newMode); 79 void onSupportedAudioMode(int modeMask); 80 } 81} 82