Merge "Bluetooth in band ring"
diff --git a/src/com/android/server/telecom/Ringer.java b/src/com/android/server/telecom/Ringer.java
index 36bb4ed..4d97f4d 100644
--- a/src/com/android/server/telecom/Ringer.java
+++ b/src/com/android/server/telecom/Ringer.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.os.VibrationEffect;
 import android.telecom.Log;
+import android.telecom.TelecomManager;
 import android.media.AudioAttributes;
 import android.media.AudioManager;
 import android.net.Uri;
@@ -125,6 +126,7 @@
         boolean isSelfManaged = foregroundCall.isSelfManaged();
 
         boolean isRingerAudible = isVolumeOverZero && shouldRingForContact && isRingtonePresent;
+        boolean hasExternalRinger = hasExternalRinger(foregroundCall);
         // Acquire audio focus under any of the following conditions:
         // 1. Should ring for contact and there's an HFP device attached
         // 2. Volume is over zero, we should ring for the contact, and there's a audible ringtone
@@ -136,14 +138,16 @@
         // Don't do call waiting operations or vibration unless these are false.
         boolean isTheaterModeOn = mSystemSettingsUtil.isTheaterModeOn(mContext);
         boolean letDialerHandleRinging = mInCallController.doesConnectedDialerSupportRinging();
-        boolean endEarly = isTheaterModeOn || letDialerHandleRinging || isSelfManaged;
+        boolean endEarly = isTheaterModeOn || letDialerHandleRinging || isSelfManaged ||
+                hasExternalRinger;
 
         if (endEarly) {
             if (letDialerHandleRinging) {
                 Log.addEvent(foregroundCall, LogUtils.Events.SKIP_RINGING);
             }
             Log.i(this, "Ending early -- isTheaterModeOn=%s, letDialerHandleRinging=%s, " +
-                    "isSelfManaged=%s", isTheaterModeOn, letDialerHandleRinging, isSelfManaged);
+                    "isSelfManaged=%s, hasExternalRinger=%s", isTheaterModeOn,
+                    letDialerHandleRinging, isSelfManaged, hasExternalRinger);
             return shouldAcquireAudioFocus;
         }
 
@@ -241,6 +245,15 @@
         return manager.matchesCallFilter(extras);
     }
 
+    private boolean hasExternalRinger(Call foregroundCall) {
+        Bundle intentExtras = foregroundCall.getIntentExtras();
+        if (intentExtras != null) {
+            return intentExtras.getBoolean(TelecomManager.EXTRA_CALL_EXTERNAL_RINGER, false);
+        } else {
+            return false;
+        }
+    }
+
     private boolean shouldVibrate(Context context, Call call) {
         AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
         int ringerMode = audioManager.getRingerModeInternal();
diff --git a/tests/src/com/android/server/telecom/tests/RingerTest.java b/tests/src/com/android/server/telecom/tests/RingerTest.java
index 47ac174..2a45649 100644
--- a/tests/src/com/android/server/telecom/tests/RingerTest.java
+++ b/tests/src/com/android/server/telecom/tests/RingerTest.java
@@ -24,6 +24,7 @@
 import android.os.Bundle;
 import android.os.VibrationEffect;
 import android.os.Vibrator;
+import android.telecom.TelecomManager;
 import android.test.suitebuilder.annotation.SmallTest;
 
 import com.android.server.telecom.AsyncRingtonePlayer;
@@ -96,6 +97,22 @@
 
     @SmallTest
     @Test
+    public void testNoActionWithExternalRinger() {
+        Bundle externalRingerExtra = new Bundle();
+        externalRingerExtra.putBoolean(TelecomManager.EXTRA_CALL_EXTERNAL_RINGER, true);
+        when(mockCall1.getIntentExtras()).thenReturn(externalRingerExtra);
+        when(mockCall2.getIntentExtras()).thenReturn(externalRingerExtra);
+        // Start call waiting to make sure that it doesn't stop when we start ringing
+        mRingerUnderTest.startCallWaiting(mockCall1);
+        assertFalse(mRingerUnderTest.startRinging(mockCall2, false));
+        verify(mockTonePlayer, never()).stopTone();
+        verify(mockRingtonePlayer, never()).play(any(RingtoneFactory.class), any(Call.class));
+        verify(mockVibrator, never())
+                .vibrate(any(VibrationEffect.class), any(AudioAttributes.class));
+    }
+
+    @SmallTest
+    @Test
     public void testNoActionWhenDialerRings() {
         // Start call waiting to make sure that it doesn't stop when we start ringing
         mRingerUnderTest.startCallWaiting(mockCall1);