Remove audio handling from telephony. (1/2)

Bug: 16175960
Change-Id: Id4ec9963f559b4cd1870c18b91521afca8d8f153
diff --git a/src/com/android/phone/AudioRouter.java b/src/com/android/phone/AudioRouter.java
deleted file mode 100644
index 3c8e9d3..0000000
--- a/src/com/android/phone/AudioRouter.java
+++ /dev/null
@@ -1,395 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone;
-
-import com.google.common.collect.Lists;
-
-import android.content.Context;
-import android.os.SystemProperties;
-import android.provider.MediaStore.Audio;
-import android.util.Log;
-
-import com.android.internal.telephony.CallManager;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.phone.BluetoothManager.BluetoothIndicatorListener;
-import com.android.phone.WiredHeadsetManager.WiredHeadsetListener;
-import com.android.services.telephony.common.AudioMode;
-
-import java.util.List;
-
-/**
- * Responsible for Routing in-call audio and maintaining routing state.
- */
-/* package */ class AudioRouter implements BluetoothIndicatorListener, WiredHeadsetListener {
-
-    private static String LOG_TAG = AudioRouter.class.getSimpleName();
-    private static final boolean DBG =
-            (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
-    private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
-
-    private static final boolean ON = true;
-    private static final boolean OFF = false;
-
-    private final Context mContext;
-    private final BluetoothManager mBluetoothManager;
-    private final WiredHeadsetManager mWiredHeadsetManager;
-    private final CallManager mCallManager;
-    private final List<AudioModeListener> mListeners = Lists.newArrayList();
-    private int mAudioMode = AudioMode.EARPIECE;
-    private int mPreviousMode = AudioMode.EARPIECE;
-    private int mSupportedModes = AudioMode.ALL_MODES;
-
-    public AudioRouter(Context context, BluetoothManager bluetoothManager,
-            WiredHeadsetManager wiredHeadsetManager, CallManager callManager) {
-        mContext = context;
-        mBluetoothManager = bluetoothManager;
-        mWiredHeadsetManager = wiredHeadsetManager;
-        mCallManager = callManager;
-
-        init();
-    }
-
-    /**
-     * Return the current audio mode.
-     */
-    public int getAudioMode() {
-        return mAudioMode;
-    }
-
-    /**
-     * Returns the currently supported audio modes.
-     */
-    public int getSupportedAudioModes() {
-        return mSupportedModes;
-    }
-
-    /**
-     * Returns the current mute state.
-     */
-    public boolean getMute() {
-        return PhoneUtils.getMute();
-    }
-
-    /**
-     * Add a listener to audio mode changes.
-     */
-    public void addAudioModeListener(AudioModeListener listener) {
-        if (!mListeners.contains(listener)) {
-            mListeners.add(listener);
-
-            // For first notification, mPreviousAudioMode doesn't make sense.
-            listener.onAudioModeChange(mAudioMode, getMute());
-            listener.onSupportedAudioModeChange(mSupportedModes);
-        }
-    }
-
-    /**
-     * Remove  listener.
-     */
-    public void removeAudioModeListener(AudioModeListener listener) {
-        if (mListeners.contains(listener)) {
-            mListeners.remove(listener);
-        }
-    }
-
-    /**
-     * Sets the audio mode to the mode that is passed in.
-     */
-    public void setAudioMode(int mode) {
-        logD("setAudioMode " + AudioMode.toString(mode));
-        boolean error = false;
-
-        // changes WIRED_OR_EARPIECE to appropriate single entry WIRED_HEADSET or EARPIECE
-        mode = selectWiredOrEarpiece(mode);
-
-        // If mode is unsupported, do nothing.
-        if ((calculateSupportedModes() | mode) == 0) {
-            Log.wtf(LOG_TAG, "Asking to set to a mode that is unsupported: " + mode);
-            return;
-        }
-
-        if (AudioMode.SPEAKER == mode) {
-            turnOnOffBluetooth(OFF);
-            turnOnOffSpeaker(ON);
-
-        } else if (AudioMode.BLUETOOTH == mode) {
-            if (mBluetoothManager.isBluetoothAvailable()) {
-                // Manually turn the speaker phone off, instead of allowing the
-                // Bluetooth audio routing to handle it, since there's other
-                // important state-updating that needs to happen in the
-                // PhoneUtils.turnOnSpeaker() method.
-                // (Similarly, whenever the user turns *on* the speaker, we
-                // manually disconnect the active bluetooth headset;
-                // see toggleSpeaker() and/or switchInCallAudio().)
-                turnOnOffSpeaker(OFF);
-                if (!turnOnOffBluetooth(ON)) {
-                    error = true;
-                }
-            } else {
-                Log.e(LOG_TAG, "Asking to turn on bluetooth when no bluetooth available. " +
-                        "supportedModes: " + AudioMode.toString(calculateSupportedModes()));
-                error = true;
-            }
-
-        // Wired headset and earpiece work the same way
-        } else if (AudioMode.EARPIECE == mode || AudioMode.WIRED_HEADSET == mode) {
-            turnOnOffBluetooth(OFF);
-            turnOnOffSpeaker(OFF);
-
-        } else {
-            error = true;
-        }
-
-        if (error) {
-            mode = calculateModeFromCurrentState();
-            Log.e(LOG_TAG, "There was an error in setting new audio mode. " +
-                    "Resetting mode to " + AudioMode.toString(mode) + ".");
-
-        }
-
-        updateAudioModeTo(mode);
-    }
-
-    /**
-     * Turns on speaker.
-     */
-    public void setSpeaker(boolean on) {
-        logD("setSpeaker " + on);
-
-        if (on) {
-            setAudioMode(AudioMode.SPEAKER);
-        } else {
-            setAudioMode(AudioMode.WIRED_OR_EARPIECE);
-        }
-    }
-
-    public void onMuteChange(boolean muted) {
-        logD("onMuteChange: " + muted);
-        notifyListeners();
-    }
-
-    /**
-     * Called when the bluetooth connection changes.
-     * We adjust the audio mode according to the state we receive.
-     */
-    @Override
-    public void onBluetoothIndicationChange(boolean isConnected, BluetoothManager btManager) {
-        logD("onBluetoothIndicationChange " + isConnected);
-
-        // this will read the new bluetooth mode appropriately
-        updateAudioModeTo(calculateModeFromCurrentState());
-    }
-
-    /**
-     * Called when the state of the wired headset changes.
-     */
-    @Override
-    public void onWiredHeadsetConnection(boolean pluggedIn) {
-        logD("onWireHeadsetConnection " + pluggedIn);
-
-        // Since the presence of a wired headset or bluetooth affects the
-        // speakerphone, update the "speaker" state.  We ONLY want to do
-        // this on the wired headset connect / disconnect events for now
-        // though.
-        final boolean isOffhook = (mCallManager.getState() == PhoneConstants.State.OFFHOOK);
-
-        int newMode = mAudioMode;
-
-        // Change state only if we are not using bluetooth
-        if (!mBluetoothManager.isBluetoothHeadsetAudioOn()) {
-
-            // Do special logic with speakerphone if we have an ongoing (offhook) call.
-            if (isOffhook) {
-                if (!pluggedIn) {
-                    // if the state is "not connected", restore the speaker state.
-                    PhoneUtils.restoreSpeakerMode(mContext);
-
-                    if (PhoneUtils.isSpeakerOn(mContext)) {
-                        newMode = AudioMode.SPEAKER;
-                    } else {
-                        newMode = AudioMode.EARPIECE;
-                    }
-                } else {
-                    // if the state is "connected", force the speaker off without
-                    // storing the state.
-                    PhoneUtils.turnOnSpeaker(mContext, false, false);
-
-                    newMode = AudioMode.WIRED_HEADSET;
-                }
-
-            // if we are outside of a phone call, the logic is simpler
-            } else {
-                newMode = pluggedIn ? AudioMode.WIRED_HEADSET : AudioMode.EARPIECE;
-            }
-        }
-
-        updateAudioModeTo(newMode);
-    }
-
-    /**
-     * Changes WIRED_OR_EARPIECE to appropriate single entry WIRED_HEADSET or EARPIECE.
-     * If mode passed it is not WIRED_OR_EARPIECE, this is a no-op and simply returns
-     * the unchanged mode parameter.
-     */
-    private int selectWiredOrEarpiece(int mode) {
-        // Since they are mutually exclusive and one is ALWAYS valid, we allow a special input of
-        // WIRED_OR_EARPIECE so that callers dont have to make a call to check which is supported
-        // before calling setAudioMode.
-        if (mode == AudioMode.WIRED_OR_EARPIECE) {
-            mode = AudioMode.WIRED_OR_EARPIECE & mSupportedModes;
-
-            if (mode == 0) {
-                Log.wtf(LOG_TAG, "One of wired headset or earpiece should always be valid.");
-                // assume earpiece in this case.
-                mode = AudioMode.EARPIECE;
-            }
-        }
-
-        return mode;
-    }
-
-    /**
-     * Turns on/off bluetooth.  If bluetooth is already in the correct mode, this does
-     * nothing.
-     */
-    private boolean turnOnOffBluetooth(boolean onOff) {
-        if (mBluetoothManager.isBluetoothAvailable()) {
-            final boolean isAlreadyOn = mBluetoothManager.isBluetoothAudioConnected();
-
-            if (onOff && !isAlreadyOn) {
-                mBluetoothManager.connectBluetoothAudio();
-            } else if (!onOff && isAlreadyOn) {
-                mBluetoothManager.disconnectBluetoothAudio();
-            }
-        } else if (onOff) {
-            Log.e(LOG_TAG, "Asking to turn on bluetooth, but there is no bluetooth availabled.");
-            return false;
-        }
-
-        return true;
-    }
-
-    /**
-     * Turn on/off speaker.
-     */
-    private void turnOnOffSpeaker(boolean onOff) {
-        if (PhoneUtils.isSpeakerOn(mContext) != onOff) {
-            PhoneUtils.turnOnSpeaker(mContext, onOff, true /* storeState */);
-        }
-    }
-
-    private void init() {
-        mBluetoothManager.addBluetoothIndicatorListener(this);
-        mWiredHeadsetManager.addWiredHeadsetListener(this);
-    }
-
-    /**
-     * Reads the state of the world to determine Audio mode.
-     */
-    private int calculateModeFromCurrentState() {
-
-        int mode = AudioMode.EARPIECE;
-
-        // There is a very specific ordering here
-        if (mBluetoothManager.showBluetoothIndication()) {
-            mode = AudioMode.BLUETOOTH;
-        } else if (PhoneUtils.isSpeakerOn(mContext)) {
-            mode = AudioMode.SPEAKER;
-        } else if (mWiredHeadsetManager.isHeadsetPlugged()) {
-            mode = AudioMode.WIRED_HEADSET;
-        }
-
-        logD("calculateModeFromCurrentState " + AudioMode.toString(mode));
-
-        return mode;
-    }
-
-    /**
-     * Changes the audio mode to the mode in the parameter.
-     */
-    private void updateAudioModeTo(int mode) {
-        int oldSupportedModes = mSupportedModes;
-
-        mSupportedModes = calculateSupportedModes();
-
-        // This is a weird state that shouldn't happen, but we get called here
-        // once we've changed the audio layers so lets log the error, but assume
-        // that it went through. If it happens it is likely it is a race condition
-        // that will resolve itself when we get updates on the mode change.
-        if ((mSupportedModes & mode) == 0) {
-            Log.e(LOG_TAG, "Setting audio mode to an unsupported mode: " +
-                    AudioMode.toString(mode) + ", supported (" +
-                    AudioMode.toString(mSupportedModes) + ")");
-        }
-
-        boolean doNotify = oldSupportedModes != mSupportedModes;
-
-        // only update if it really changed.
-        if (mAudioMode != mode) {
-            Log.i(LOG_TAG, "Audio mode changing to " + AudioMode.toString(mode));
-            doNotify = true;
-        }
-
-        mPreviousMode = mAudioMode;
-        mAudioMode = mode;
-
-        if (doNotify) {
-            notifyListeners();
-        }
-    }
-
-    /**
-     * Gets the updates supported modes from the state of the audio systems.
-     */
-    private int calculateSupportedModes() {
-        // speaker phone always a supported state
-        int supportedModes = AudioMode.SPEAKER;
-
-        if (mWiredHeadsetManager.isHeadsetPlugged()) {
-            supportedModes |= AudioMode.WIRED_HEADSET;
-        } else {
-            supportedModes |= AudioMode.EARPIECE;
-        }
-
-        if (mBluetoothManager.isBluetoothAvailable()) {
-            supportedModes |= AudioMode.BLUETOOTH;
-        }
-
-        return supportedModes;
-    }
-
-    private void notifyListeners() {
-        logD("AudioMode: " + AudioMode.toString(mAudioMode));
-        logD("Supported AudioMode: " + AudioMode.toString(mSupportedModes));
-
-        for (int i = 0; i < mListeners.size(); i++) {
-            mListeners.get(i).onAudioModeChange(mAudioMode, getMute());
-            mListeners.get(i).onSupportedAudioModeChange(mSupportedModes);
-        }
-    }
-
-    public interface AudioModeListener {
-        void onAudioModeChange(int newMode, boolean muted);
-        void onSupportedAudioModeChange(int modeMask);
-    }
-
-    private void logD(String msg) {
-        if (DBG) {
-            Log.d(LOG_TAG, msg);
-        }
-    }
-}
diff --git a/src/com/android/phone/BluetoothPhoneService.java b/src/com/android/phone/BluetoothPhoneService.java
index a2e1288..87940a0 100644
--- a/src/com/android/phone/BluetoothPhoneService.java
+++ b/src/com/android/phone/BluetoothPhoneService.java
@@ -778,7 +778,6 @@
                     if (ringingCall.isRinging()) {
                         if (VDBG) log("CHLD:2 Callwaiting Answer call");
                         PhoneUtils.answerCall(ringingCall);
-                        PhoneUtils.setMute(false);
                         // Setting the second callers state flag to TRUE (i.e. active)
                         cdmaSetSecondCallState(true);
                         return true;
diff --git a/src/com/android/phone/CallController.java b/src/com/android/phone/CallController.java
index 1cb4c80..a42f57d 100644
--- a/src/com/android/phone/CallController.java
+++ b/src/com/android/phone/CallController.java
@@ -482,8 +482,6 @@
                     // Start the timer for 3 Way CallerInfo
                     if (mApp.cdmaPhoneCallState.getCurrentCallState()
                             == CdmaPhoneCallState.PhoneCallState.THRWAY_ACTIVE) {
-                        //Unmute for the second MO call
-                        PhoneUtils.setMute(false);
 
                         // This is a "CDMA 3-way call", which means that you're dialing a
                         // 2nd outgoing call while a previous call is already in progress.
diff --git a/src/com/android/phone/CallNotifier.java b/src/com/android/phone/CallNotifier.java
index 1bab321..674f66d 100644
--- a/src/com/android/phone/CallNotifier.java
+++ b/src/com/android/phone/CallNotifier.java
@@ -352,10 +352,6 @@
                 // onRingbackTone((AsyncResult) msg.obj);
                 break;
 
-            case CallStateMonitor.PHONE_RESEND_MUTE:
-                onResendMute();
-                break;
-
             default:
                 // super.handleMessage(msg);
         }
@@ -1771,15 +1767,6 @@
         }
     }
 
-    /**
-     * Toggle mute and unmute requests while keeping the same mute state
-     */
-    private void onResendMute() {
-        boolean muteState = PhoneUtils.getMute();
-        PhoneUtils.setMute(!muteState);
-        PhoneUtils.setMute(muteState);
-    }
-
     private void log(String msg) {
         Log.d(LOG_TAG, msg);
     }
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index df25684..f66ebce 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -60,7 +60,6 @@
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.TelephonyCapabilities;
 import com.android.internal.telephony.TelephonyIntents;
-import com.android.phone.WiredHeadsetManager.WiredHeadsetListener;
 import com.android.phone.common.CallLogAsync;
 import com.android.server.sip.SipService;
 
@@ -141,13 +140,11 @@
     Phone phone;
     PhoneInterfaceManager phoneMgr;
 
-    private AudioRouter audioRouter;
     private BluetoothManager bluetoothManager;
     private CallGatewayManager callGatewayManager;
     private CallStateMonitor callStateMonitor;
     private IBluetoothHeadsetPhone mBluetoothPhone;
     private Ringer ringer;
-    private WiredHeadsetManager wiredHeadsetManager;
 
     static int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
     static boolean sVoiceCapable = true;
@@ -298,10 +295,7 @@
 
                     phoneState = mCM.getState();
                     if (phoneState == PhoneConstants.State.OFFHOOK &&
-                            !wiredHeadsetManager.isHeadsetPlugged() &&
                             !bluetoothManager.isBluetoothHeadsetAudioOn()) {
-                        audioRouter.setSpeaker(inDockMode);
-
                         PhoneUtils.turnOnSpeaker(getApplicationContext(), inDockMode, true);
                     }
                     break;
@@ -406,17 +400,11 @@
             // Monitors call activity from the telephony layer
             callStateMonitor = new CallStateMonitor(mCM);
 
-            // Manages wired headset state
-            wiredHeadsetManager = new WiredHeadsetManager(this);
-
             // Bluetooth manager
             bluetoothManager = new BluetoothManager();
 
             ringer = Ringer.init(this, bluetoothManager);
 
-            // Audio router
-            audioRouter = new AudioRouter(this, bluetoothManager, wiredHeadsetManager, mCM);
-
             phoneMgr = PhoneInterfaceManager.init(this, phone);
 
             // Create the CallNotifer singleton, which handles
@@ -527,14 +515,6 @@
         return bluetoothManager;
     }
 
-    /* package */ WiredHeadsetManager getWiredHeadsetManager() {
-        return wiredHeadsetManager;
-    }
-
-    /* package */ AudioRouter getAudioRouter() {
-        return audioRouter;
-    }
-
     /* package */ CallManager getCallManager() {
         return mCM;
     }
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index 06dacb8..bc9bf63 100644
--- a/src/com/android/phone/PhoneUtils.java
+++ b/src/com/android/phone/PhoneUtils.java
@@ -104,10 +104,6 @@
     /** Speaker state, persisting between wired headset connection events */
     private static boolean sIsSpeakerEnabled = false;
 
-    /** Hash table to store mute (Boolean) values based upon the connection.*/
-    private static Hashtable<Connection, Boolean> sConnectionMuteTable =
-        new Hashtable<Connection, Boolean>();
-
     /** Static handler for the connection/mute tracking */
     private static ConnectionHandler mConnectionHandler;
 
@@ -173,70 +169,6 @@
                         answerCall(frC.ringing);
                     }
                     break;
-                case PHONE_STATE_CHANGED:
-                    AsyncResult ar = (AsyncResult) msg.obj;
-                    if (DBG) log("ConnectionHandler: updating mute state for each connection");
-
-                    CallManager cm = (CallManager) ar.userObj;
-
-                    // update the foreground connections, if there are new connections.
-                    // Have to get all foreground calls instead of the active one
-                    // because there may two foreground calls co-exist in shore period
-                    // (a racing condition based on which phone changes firstly)
-                    // Otherwise the connection may get deleted.
-                    List<Connection> fgConnections = new ArrayList<Connection>();
-                    for (Call fgCall : cm.getForegroundCalls()) {
-                        if (!fgCall.isIdle()) {
-                            fgConnections.addAll(fgCall.getConnections());
-                        }
-                    }
-                    for (Connection cn : fgConnections) {
-                        if (sConnectionMuteTable.get(cn) == null) {
-                            sConnectionMuteTable.put(cn, Boolean.FALSE);
-                        }
-                    }
-
-                    // mute is connection based operation, we need loop over
-                    // all background calls instead of the first one to update
-                    // the background connections, if there are new connections.
-                    List<Connection> bgConnections = new ArrayList<Connection>();
-                    for (Call bgCall : cm.getBackgroundCalls()) {
-                        if (!bgCall.isIdle()) {
-                            bgConnections.addAll(bgCall.getConnections());
-                        }
-                    }
-                    for (Connection cn : bgConnections) {
-                        if (sConnectionMuteTable.get(cn) == null) {
-                          sConnectionMuteTable.put(cn, Boolean.FALSE);
-                        }
-                    }
-
-                    // Check to see if there are any lingering connections here
-                    // (disconnected connections), use old-school iterators to avoid
-                    // concurrent modification exceptions.
-                    Connection cn;
-                    for (Iterator<Connection> cnlist = sConnectionMuteTable.keySet().iterator();
-                            cnlist.hasNext();) {
-                        cn = cnlist.next();
-                        if (!fgConnections.contains(cn) && !bgConnections.contains(cn)) {
-                            if (DBG) log("connection '" + cn + "' not accounted for, removing.");
-                            cnlist.remove();
-                        }
-                    }
-
-                    // Restore the mute state of the foreground call if we're not IDLE,
-                    // otherwise just clear the mute state. This is really saying that
-                    // as long as there is one or more connections, we should update
-                    // the mute state with the earliest connection on the foreground
-                    // call, and that with no connections, we should be back to a
-                    // non-mute state.
-                    if (cm.getState() != PhoneConstants.State.IDLE) {
-                        restoreMuteState();
-                    } else {
-                        setMuteInternal(cm.getFgPhone(), false);
-                    }
-
-                    break;
             }
         }
     }
@@ -328,9 +260,6 @@
                 app.mCM.acceptCall(ringingCall);
                 answered = true;
 
-                // Always reset to "unmuted" for a freshly-answered call
-                setMute(false);
-
                 setAudioMode();
 
                 // Check is phone in any dock, and turn on speaker accordingly
@@ -769,11 +698,6 @@
 
             startGetCallerInfo(context, connection, null, null, gatewayInfo);
 
-            // Always set mute to off when we are dialing an emergency number
-            if (isEmergencyCall) {
-                setMute(false);
-            }
-
             setAudioMode();
 
             if (DBG) log("about to activate speaker");
@@ -882,49 +806,6 @@
         }
     }
 
-    /**
-     * Restore the mute setting from the earliest connection of the
-     * foreground call.
-     */
-    static Boolean restoreMuteState() {
-        Phone phone = PhoneGlobals.getInstance().mCM.getFgPhone();
-
-        //get the earliest connection
-        Connection c = phone.getForegroundCall().getEarliestConnection();
-
-        // only do this if connection is not null.
-        if (c != null) {
-
-            int phoneType = phone.getPhoneType();
-
-            // retrieve the mute value.
-            Boolean shouldMute = null;
-
-            // In CDMA, mute is not maintained per Connection. Single mute apply for
-            // a call where  call can have multiple connections such as
-            // Three way and Call Waiting.  Therefore retrieving Mute state for
-            // latest connection can apply for all connection in that call
-            if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
-                shouldMute = sConnectionMuteTable.get(
-                        phone.getForegroundCall().getLatestConnection());
-            } else if ((phoneType == PhoneConstants.PHONE_TYPE_GSM)
-                    || (phoneType == PhoneConstants.PHONE_TYPE_SIP)
-                    || (phoneType == PhoneConstants.PHONE_TYPE_IMS)
-                    || (phoneType == PhoneConstants.PHONE_TYPE_THIRD_PARTY)) {
-                shouldMute = sConnectionMuteTable.get(c);
-            }
-            if (shouldMute == null) {
-                if (DBG) log("problem retrieving mute value for this connection.");
-                shouldMute = Boolean.FALSE;
-            }
-
-            // set the mute value and return the result.
-            setMute (shouldMute.booleanValue());
-            return shouldMute;
-        }
-        return Boolean.valueOf(getMute());
-    }
-
     static void mergeCalls() {
         mergeCalls(PhoneGlobals.getInstance().mCM);
     }
@@ -2034,49 +1915,6 @@
         }
     }
 
-    /**
-     *
-     * Mute / umute the foreground phone, which has the current foreground call
-     *
-     * All muting / unmuting from the in-call UI should go through this
-     * wrapper.
-     *
-     * Wrapper around Phone.setMute() and setMicrophoneMute().
-     * It also updates the connectionMuteTable and mute icon in the status bar.
-     *
-     */
-    static void setMute(boolean muted) {
-        CallManager cm = PhoneGlobals.getInstance().mCM;
-
-        // Emergency calls never get muted.
-        if (isInEmergencyCall(cm)) {
-            muted = false;
-        }
-
-        // make the call to mute the audio
-        setMuteInternal(cm.getFgPhone(), muted);
-
-        // update the foreground connections to match.  This includes
-        // all the connections on conference calls.
-        for (Connection cn : cm.getActiveFgCall().getConnections()) {
-            if (sConnectionMuteTable.get(cn) == null) {
-                if (DBG) log("problem retrieving mute value for this connection.");
-            }
-            sConnectionMuteTable.put(cn, Boolean.valueOf(muted));
-        }
-
-        // update the background connections to match.  This includes
-        // all the connections on conference calls.
-        if (cm.hasActiveBgCall()) {
-            for (Connection cn : cm.getFirstActiveBgCall().getConnections()) {
-                if (sConnectionMuteTable.get(cn) == null) {
-                    if (DBG) log("problem retrieving mute value for this connection.");
-                }
-                sConnectionMuteTable.put(cn, Boolean.valueOf(muted));
-            }
-        }
-    }
-
     static boolean isInEmergencyCall(CallManager cm) {
         for (Connection cn : cm.getActiveFgCall().getConnections()) {
             if (PhoneNumberUtils.isLocalEmergencyNumber(PhoneGlobals.getInstance(),
@@ -2088,172 +1926,20 @@
     }
 
     /**
-     * Internally used muting function.
-     */
-    private static void setMuteInternal(Phone phone, boolean muted) {
-        final PhoneGlobals app = PhoneGlobals.getInstance();
-        Context context = phone.getContext();
-        boolean routeToAudioManager =
-            context.getResources().getBoolean(R.bool.send_mic_mute_to_AudioManager);
-        if (routeToAudioManager) {
-            AudioManager audioManager =
-                (AudioManager) phone.getContext().getSystemService(Context.AUDIO_SERVICE);
-            if (DBG) log("setMuteInternal: using setMicrophoneMute(" + muted + ")...");
-            audioManager.setMicrophoneMute(muted);
-        } else {
-            if (DBG) log("setMuteInternal: using phone.setMute(" + muted + ")...");
-            phone.setMute(muted);
-        }
-        app.getAudioRouter().onMuteChange(muted);
-    }
-
-    /**
      * Get the mute state of foreground phone, which has the current
      * foreground call
      */
     static boolean getMute() {
-        final PhoneGlobals app = PhoneGlobals.getInstance();
-
-        boolean routeToAudioManager =
-            app.getResources().getBoolean(R.bool.send_mic_mute_to_AudioManager);
-        if (routeToAudioManager) {
-            AudioManager audioManager =
-                (AudioManager) app.getSystemService(Context.AUDIO_SERVICE);
-            return audioManager.isMicrophoneMute();
-        } else {
-            return app.mCM.getMute();
-        }
+        return false;
     }
 
     /* package */ static void setAudioMode() {
-        setAudioMode(PhoneGlobals.getInstance().mCM);
     }
 
     /**
      * Sets the audio mode per current phone state.
      */
     /* package */ static void setAudioMode(CallManager cm) {
-        if (DBG) Log.d(LOG_TAG, "setAudioMode()..." + cm.getState());
-
-        Context context = PhoneGlobals.getInstance();
-        AudioManager audioManager = (AudioManager)
-                context.getSystemService(Context.AUDIO_SERVICE);
-        int modeBefore = audioManager.getMode();
-        cm.setAudioMode();
-        int modeAfter = audioManager.getMode();
-
-        if (modeBefore != modeAfter) {
-            // Enable stack dump only when actively debugging ("new Throwable()" is expensive!)
-            if (DBG_SETAUDIOMODE_STACK) Log.d(LOG_TAG, "Stack:", new Throwable("stack dump"));
-        } else {
-            if (DBG) Log.d(LOG_TAG, "setAudioMode() no change: "
-                    + audioModeToString(modeBefore));
-        }
-    }
-    private static String audioModeToString(int mode) {
-        switch (mode) {
-            case AudioManager.MODE_INVALID: return "MODE_INVALID";
-            case AudioManager.MODE_CURRENT: return "MODE_CURRENT";
-            case AudioManager.MODE_NORMAL: return "MODE_NORMAL";
-            case AudioManager.MODE_RINGTONE: return "MODE_RINGTONE";
-            case AudioManager.MODE_IN_CALL: return "MODE_IN_CALL";
-            default: return String.valueOf(mode);
-        }
-    }
-
-    /**
-     * Handles the wired headset button while in-call.
-     *
-     * This is called from the PhoneApp, not from the InCallScreen,
-     * since the HEADSETHOOK button means "mute or unmute the current
-     * call" *any* time a call is active, even if the user isn't actually
-     * on the in-call screen.
-     *
-     * @return true if we consumed the event.
-     */
-    /* package */ static boolean handleHeadsetHook(Phone phone, KeyEvent event) {
-        if (DBG) log("handleHeadsetHook()..." + event.getAction() + " " + event.getRepeatCount());
-        final PhoneGlobals app = PhoneGlobals.getInstance();
-
-        // If the phone is totally idle, we ignore HEADSETHOOK events
-        // (and instead let them fall through to the media player.)
-        if (phone.getState() == PhoneConstants.State.IDLE) {
-            return false;
-        }
-
-        // Ok, the phone is in use.
-        // The headset button button means "Answer" if an incoming call is
-        // ringing.  If not, it toggles the mute / unmute state.
-        //
-        // And in any case we *always* consume this event; this means
-        // that the usual mediaplayer-related behavior of the headset
-        // button will NEVER happen while the user is on a call.
-
-        final boolean hasRingingCall = !phone.getRingingCall().isIdle();
-        final boolean hasActiveCall = !phone.getForegroundCall().isIdle();
-        final boolean hasHoldingCall = !phone.getBackgroundCall().isIdle();
-
-        if (hasRingingCall &&
-            event.getRepeatCount() == 0 &&
-            event.getAction() == KeyEvent.ACTION_UP) {
-            // If an incoming call is ringing, answer it (just like with the
-            // CALL button):
-            int phoneType = phone.getPhoneType();
-            if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
-                answerCall(phone.getRingingCall());
-            } else if ((phoneType == PhoneConstants.PHONE_TYPE_GSM)
-                    || (phoneType == PhoneConstants.PHONE_TYPE_SIP)
-                    || (phoneType == PhoneConstants.PHONE_TYPE_IMS)
-                    || (phoneType == PhoneConstants.PHONE_TYPE_THIRD_PARTY)) {
-                if (hasActiveCall && hasHoldingCall) {
-                    if (DBG) log("handleHeadsetHook: ringing (both lines in use) ==> answer!");
-                    answerAndEndActive(app.mCM, phone.getRingingCall());
-                } else {
-                    if (DBG) log("handleHeadsetHook: ringing ==> answer!");
-                    // answerCall() will automatically hold the current
-                    // active call, if there is one.
-                    answerCall(phone.getRingingCall());
-                }
-            } else {
-                throw new IllegalStateException("Unexpected phone type: " + phoneType);
-            }
-        } else {
-            // No incoming ringing call.
-            if (event.isLongPress()) {
-                if (DBG) log("handleHeadsetHook: longpress -> hangup");
-                hangup(app.mCM);
-            }
-            else if (event.getAction() == KeyEvent.ACTION_UP &&
-                     event.getRepeatCount() == 0) {
-                Connection c = phone.getForegroundCall().getLatestConnection();
-                // If it is NOT an emg #, toggle the mute state. Otherwise, ignore the hook.
-                if (c != null && !PhoneNumberUtils.isLocalEmergencyNumber(
-                        PhoneGlobals.getInstance(), c.getAddress())) {
-                    if (getMute()) {
-                        if (DBG) log("handleHeadsetHook: UNmuting...");
-                        setMute(false);
-                    } else {
-                        if (DBG) log("handleHeadsetHook: muting...");
-                        setMute(true);
-                    }
-                }
-            }
-        }
-
-        // Even if the InCallScreen is the current activity, there's no
-        // need to force it to update, because (1) if we answered a
-        // ringing call, the InCallScreen will imminently get a phone
-        // state change event (causing an update), and (2) if we muted or
-        // unmuted, the setMute() call automagically updates the status
-        // bar, and there's no "mute" indication in the InCallScreen
-        // itself (other than the menu item, which only ever stays
-        // onscreen for a second anyway.)
-        // TODO: (2) isn't entirely true anymore. Once we return our result
-        // to the PhoneApp, we ask InCallScreen to update its control widgets
-        // in case we changed mute or speaker state and phones with touch-
-        // screen [toggle] buttons need to update themselves.
-
-        return true;
     }
 
     /**
@@ -2561,13 +2247,13 @@
 
             // TODO: This function should move to AudioRouter
             final BluetoothManager btManager = app.getBluetoothManager();
-            final WiredHeadsetManager wiredHeadset = app.getWiredHeadsetManager();
-            final AudioRouter audioRouter = app.getAudioRouter();
+            //final WiredHeadsetManager wiredHeadset = app.getWiredHeadsetManager();
+            //final AudioRouter audioRouter = app.getAudioRouter();
 
-            if (!wiredHeadset.isHeadsetPlugged() && !btManager.isBluetoothHeadsetAudioOn()) {
-                audioRouter.setSpeaker(true);
+            /*if (!wiredHeadset.isHeadsetPlugged() && !btManager.isBluetoothHeadsetAudioOn()) {
+                //audioRouter.setSpeaker(true);
                 activated = true;
-            }
+            }*/
         }
         return activated;
     }
diff --git a/src/com/android/phone/WiredHeadsetManager.java b/src/com/android/phone/WiredHeadsetManager.java
deleted file mode 100644
index 4f09db6..0000000
--- a/src/com/android/phone/WiredHeadsetManager.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone;
-
-import com.google.android.collect.Lists;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.SystemProperties;
-import android.util.Log;
-
-import java.util.List;
-
-/**
- * Listens for and caches headset state.  Used By the AudioRouter for maintaining
- * overall audio state for use in the UI layer. Also provides method for connecting the bluetooth
- * headset to the phone call.
- */
-public class WiredHeadsetManager {
-    private static final String LOG_TAG = WiredHeadsetManager.class.getSimpleName();
-    private static final boolean DBG =
-            (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
-    private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
-
-    // True if a wired headset is currently plugged in, based on the state
-    // from the latest Intent.ACTION_HEADSET_PLUG broadcast we received in
-    // mReceiver.onReceive().
-    private boolean mIsHeadsetPlugged = false;
-    private final WiredHeadsetBroadcastReceiver mReceiver;
-    private final List<WiredHeadsetListener> mListeners = Lists.newArrayList();
-
-    public WiredHeadsetManager(Context context) {
-        mReceiver = new WiredHeadsetBroadcastReceiver();
-
-        // Register for misc other intent broadcasts.
-        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
-        context.registerReceiver(mReceiver, intentFilter);
-    }
-
-    /**
-     * Returns connection state of the wires headset.
-     */
-    public boolean isHeadsetPlugged() {
-        return mIsHeadsetPlugged;
-    }
-
-    /**
-     * Add a listener for wired headset connection status.
-     */
-    public void addWiredHeadsetListener(WiredHeadsetListener listener) {
-        if (!mListeners.contains(listener)) {
-            mListeners.add(listener);
-        }
-    }
-
-    /**
-     * Called when we get an event from the system for the headset connection state.
-     */
-    private void onHeadsetConnection(boolean pluggedIn) {
-        if (DBG) {
-            Log.d(LOG_TAG, "Wired headset connected: " +  pluggedIn);
-        }
-        mIsHeadsetPlugged = pluggedIn;
-
-        notifyListeners();
-    }
-
-    private void notifyListeners() {
-        for (int i = 0; i < mListeners.size(); i++) {
-            mListeners.get(i).onWiredHeadsetConnection(mIsHeadsetPlugged);
-        }
-    }
-
-    /**
-     * Receiver for misc intent broadcasts the BluetoothManager cares about.
-     */
-    private class WiredHeadsetBroadcastReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            String action = intent.getAction();
-
-            if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
-                if (VDBG) Log.d(LOG_TAG, "mReceiver: ACTION_HEADSET_PLUG");
-                if (VDBG) Log.d(LOG_TAG, "    state: " + intent.getIntExtra("state", 0));
-                if (VDBG) Log.d(LOG_TAG, "    name: " + intent.getStringExtra("name"));
-                onHeadsetConnection(intent.getIntExtra("state", 0) == 1);
-            }
-        }
-    }
-
-    /**
-     * Listeners for those that want to know about the headset state.
-     */
-    public interface WiredHeadsetListener {
-        void onWiredHeadsetConnection(boolean pluggedIn);
-    }
-}