Enable auto speakerphone for outgoing video calls.

Extended existing logic for auto-enabling speakerphone for incoming video
calls to also apply when making an outgoing call.

Bug: 20090407
Change-Id: Ia3553dbe1d3966998b369724ce78a458f3ab8938

Conflicts:
src/com/android/server/telecom/CallsManager.java
Change-Id: I94e9f62fc02487ed2fe23d56cef207cdf69a6a9b
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 498fd86..d79586f 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -697,6 +697,9 @@
 
         call.setHandle(uriHandle);
         call.setGatewayInfo(gatewayInfo);
+        // Auto-enable speakerphone if the originating intent specified to do so, or if the call
+        // is a video call.
+        call.setStartWithSpeakerphoneOn(speakerphoneOn || isSpeakerphoneAutoEnabled(videoState));
         call.setVideoState(videoState);
 
         if (speakerphoneOn) {
@@ -779,15 +782,32 @@
             // We do not update the UI until we get confirmation of the answer() through
             // {@link #markCallAsActive}.
             call.answer(videoState);
-            if (VideoProfile.isVideo(videoState) &&
-                !mWiredHeadsetManager.isPluggedIn() &&
-                !mCallAudioManager.isBluetoothDeviceAvailable() &&
-                isSpeakerEnabledForVideoCalls()) {
+            if (isSpeakerphoneAutoEnabled(videoState)) {
                 call.setStartWithSpeakerphoneOn(true);
             }
         }
     }
 
+    /**
+     * Determines if the speakerphone should be automatically enabled for the call.  Speakerphone
+     * should be enabled if the call is a video call and bluetooth or the wired headset are not in
+     * use.
+     *
+     * @param videoState The video state of the call.
+     * @return {@code true} if the speakerphone should be enabled.
+     */
+    private boolean isSpeakerphoneAutoEnabled(int videoState) {
+        return VideoProfile.VideoState.isVideo(videoState) &&
+            !mWiredHeadsetManager.isPluggedIn() &&
+            !mCallAudioManager.isBluetoothDeviceAvailable() &&
+            isSpeakerEnabledForVideoCalls();
+    }
+
+    /**
+     * Determines if the speakerphone should be automatically enabled for video calls.
+     *
+     * @return {@code true} if the speakerphone should automatically be enabled.
+     */
     private static boolean isSpeakerEnabledForVideoCalls() {
         return (SystemProperties.getInt(TelephonyProperties.PROPERTY_VIDEOCALL_AUDIO_OUTPUT,
                 PhoneConstants.AUDIO_OUTPUT_DEFAULT) ==