Merge "Don't start video call if already in a video call." into lmp-mr1-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9ecc6bb..a5d8d9f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -83,6 +83,9 @@
<!-- Call failure message displayed in an error dialog used to indicate that a phone number was not provided -->
<string name="outgoing_call_error_no_phone_number_supplied">Call not sent, no valid number entered.</string>
+ <!-- Message shown when the user tries to make a video call when already in a video call. -->
+ <string name ="duplicate_video_call_not_allowed">Call cannot be added at this time.</string>
+
<!-- missing voicemail number -->
<!-- Title of the "Missing voicemail number" dialog -->
<string name="no_vm_number">Missing voicemail number</string>
diff --git a/src/com/android/server/telecom/CallReceiver.java b/src/com/android/server/telecom/CallReceiver.java
index 3e6cbca..8654b7f 100644
--- a/src/com/android/server/telecom/CallReceiver.java
+++ b/src/com/android/server/telecom/CallReceiver.java
@@ -9,8 +9,10 @@
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
+import android.telecom.VideoProfile;
import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
+import android.widget.Toast;
/**
* Single point of entry for all outgoing and incoming calls. {@link CallActivity} serves as a
@@ -44,6 +46,10 @@
* @param intent Call intent containing data about the handle to call.
*/
static void processOutgoingCallIntent(Context context, Intent intent) {
+ if (shouldPreventDuplicateVideoCall(context, intent)) {
+ return;
+ }
+
Uri handle = intent.getData();
String scheme = handle.getScheme();
String uriString = handle.getSchemeSpecificPart();
@@ -149,4 +155,28 @@
errorIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivityAsUser(errorIntent, UserHandle.CURRENT);
}
+
+ /**
+ * Whether an outgoing video call should be prevented from going out. Namely, don't allow an
+ * outgoing video call if there is already an ongoing video call. Notify the user if their call
+ * is not sent.
+ *
+ * @return {@code true} if the outgoing call is a video call and should be prevented from going
+ * out, {@code false} otherwise.
+ */
+ private static boolean shouldPreventDuplicateVideoCall(Context context, Intent intent) {
+ int intentVideoState = intent.getIntExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE,
+ VideoProfile.VideoState.AUDIO_ONLY);
+ if (intentVideoState == VideoProfile.VideoState.AUDIO_ONLY
+ || !getCallsManager().hasVideoCall()) {
+ return false;
+ } else {
+ // Display an error toast to the user.
+ Toast.makeText(
+ context,
+ context.getResources().getString(R.string.duplicate_video_call_not_allowed),
+ Toast.LENGTH_LONG).show();
+ return true;
+ }
+ }
}
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 38fbd3e..86d9f01 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -32,6 +32,7 @@
import android.telecom.PhoneAccountHandle;
import android.telecom.PhoneCapabilities;
import android.telecom.TelecomManager;
+import android.telecom.VideoProfile;
import android.telephony.TelephonyManager;
import com.android.internal.util.IndentingPrintWriter;
@@ -312,6 +313,15 @@
return false;
}
+ boolean hasVideoCall() {
+ for (Call call : mCalls) {
+ if (call.getVideoState() != VideoProfile.VideoState.AUDIO_ONLY) {
+ return true;
+ }
+ }
+ return false;
+ }
+
AudioState getAudioState() {
return mCallAudioManager.getAudioState();
}