Move headset hook from Telephony to Telecomm. (1/2)

Also sets up the mute and speakerphone statusbar icons triggered by
their respective states (including triggering from the headset hook).

Bug: 15190069
Change-Id: I990110816ec37c168e3646290a538be3cd23be35
diff --git a/src/com/android/telecomm/CallAudioManager.java b/src/com/android/telecomm/CallAudioManager.java
index 43b102b..865e3ca 100644
--- a/src/com/android/telecomm/CallAudioManager.java
+++ b/src/com/android/telecomm/CallAudioManager.java
@@ -29,21 +29,23 @@
 final class CallAudioManager extends CallsManagerListenerBase {
     private static final int STREAM_NONE = -1;
 
+    private final StatusBarNotifier mStatusBarNotifier;
     private final AudioManager mAudioManager;
     private final WiredHeadsetManager mWiredHeadsetManager;
     private final BluetoothManager mBluetoothManager;
+
     private CallAudioState mAudioState;
     private int mAudioFocusStreamType;
     private boolean mIsRinging;
     private boolean mIsTonePlaying;
     private boolean mWasSpeakerOn;
 
-    CallAudioManager() {
-        Context context = TelecommApp.getInstance();
+    CallAudioManager(Context context, StatusBarNotifier statusBarNotifier) {
+        mStatusBarNotifier = statusBarNotifier;
         mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
         mWiredHeadsetManager = new WiredHeadsetManager(this);
         mBluetoothManager = new BluetoothManager(context, this);
-        mAudioState = getInitialAudioState(null);
+        saveAudioState(getInitialAudioState(null));
         mAudioFocusStreamType = STREAM_NONE;
     }
 
@@ -100,6 +102,10 @@
         updateAudioForForegroundCall();
     }
 
+    void toggleMute() {
+        mute(!mAudioState.isMuted);
+    }
+
     void mute(boolean shouldMute) {
         Log.v(this, "mute, shouldMute: %b", shouldMute);
 
@@ -206,9 +212,15 @@
         return mBluetoothManager.isBluetoothAvailable();
     }
 
+    private void saveAudioState(CallAudioState audioState) {
+        mAudioState = audioState;
+        mStatusBarNotifier.notifyMute(mAudioState.isMuted);
+        mStatusBarNotifier.notifySpeakerphone(mAudioState.route == CallAudioState.ROUTE_SPEAKER);
+    }
+
     private void setSystemAudioState(boolean isMuted, int route, int supportedRouteMask) {
         CallAudioState oldAudioState = mAudioState;
-        mAudioState = new CallAudioState(isMuted, route, supportedRouteMask);
+        saveAudioState(new CallAudioState(isMuted, route, supportedRouteMask));
         Log.i(this, "changing audio state from %s to %s", oldAudioState, mAudioState);
 
         // Mute.