Improve parsing of conference participant addresses.
Add unit tests.
Handle tel: addresses with extra information in them which should be
stripped off.
Test: Unit test.
Bug: 27090466
Change-Id: I31209d5b7a2522175e66c9e030789d9bffe0d13a
diff --git a/src/com/android/services/telephony/ConferenceParticipantConnection.java b/src/com/android/services/telephony/ConferenceParticipantConnection.java
index ed7ad44..19dda54 100644
--- a/src/com/android/services/telephony/ConferenceParticipantConnection.java
+++ b/src/com/android/services/telephony/ConferenceParticipantConnection.java
@@ -16,6 +16,7 @@
package com.android.services.telephony;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
@@ -70,7 +71,7 @@
address = null;
} else {
String countryIso = getCountryIso(parentConnection.getCall().getPhone());
- address = getParticipantAddress(participant, countryIso);
+ address = getParticipantAddress(participant.getHandle(), countryIso);
}
setAddress(address, presentation);
setCallerDisplayName(participant.getDisplayName(), presentation);
@@ -212,21 +213,19 @@
* Conference event package data contains SIP URIs, so we try to extract the phone number and
* format into a typical tel: style URI.
*
- * @param participant The conference participant.
+ * @param address The conference participant's address.
* @param countryIso The country ISO of the current subscription; used when formatting the
* participant phone number to E.164 format.
* @return The participant's address URI.
*/
- private Uri getParticipantAddress(ConferenceParticipant participant, String countryIso) {
- Uri address = participant.getHandle();
+ @VisibleForTesting
+ public static Uri getParticipantAddress(Uri address, String countryIso) {
if (address == null) {
return address;
}
-
- // If the participant's address is already a TEL scheme, just return it as is.
- if (PhoneAccount.SCHEME_TEL.equals(address.getScheme())) {
- return address;
- }
+ // Even if address is already in tel: format, still parse it and rebuild.
+ // This is to recognize tel URIs such as:
+ // tel:6505551212;phone-context=ims.mnc012.mcc034.3gppnetwork.org
// Conference event package participants are identified using SIP URIs (see RFC3261).
// A valid SIP uri has the format: sip:user:password@host:port;uri-parameters?headers
diff --git a/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java b/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java
new file mode 100644
index 0000000..73fe0af
--- /dev/null
+++ b/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 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.services.telephony;
+
+import android.net.Uri;
+import android.support.test.runner.AndroidJUnit4;
+import android.telecom.Conference;
+import android.telecom.ConferenceParticipant;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static com.android.services.telephony.ConferenceParticipantConnection.getParticipantAddress;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests proper parsing of conference event package participant addresses.
+ */
+@RunWith(AndroidJUnit4.class)
+public class ConferenceParticipantConnectionTest {
+
+ @Test
+ public void testParticipantParseSimpleTel() {
+ assertUrisEqual(Uri.parse("tel:+16505551212"),
+ getParticipantAddress(Uri.parse("tel:6505551212"), "US"));
+ }
+
+ @Test
+ public void testParticipantParseTelExtended() {
+ assertUrisEqual(Uri.parse("tel:+16505551212"),
+ getParticipantAddress(Uri.parse("tel:6505551212;phone-context=blah"), "US"));
+ }
+
+ @Test
+ public void testParticipantParseSip() {
+ assertUrisEqual(Uri.parse("tel:+16505551212"),
+ getParticipantAddress(Uri.parse("sip:16505551212;phone-context=blah.com@host.com"),
+ "US"));
+ }
+
+ @Test
+ public void testParticipantParseSip2() {
+ assertUrisEqual(Uri.parse("tel:+12125551212"),
+ getParticipantAddress(Uri.parse("sip:+1-212-555-1212@something.com;user=phone"),
+ "US"));
+ }
+
+ @Test
+ public void testParticipantParseTelJp() {
+ assertUrisEqual(Uri.parse("tel:+819066570660"),
+ getParticipantAddress(Uri.parse(
+ "tel:09066570660;phone-context=ims.mnc020.mcc440.3gppnetwork.org"),
+ "JP"));
+ }
+
+ @Test
+ public void testParticipantParseSipJp() {
+ assertUrisEqual(Uri.parse("tel:+819066571180"),
+ getParticipantAddress(Uri.parse(
+ "sip:+819066571180@ims.mnc020.mcc440.3gppnetwork.org;user=phone"),
+ "JP"));
+ }
+
+ private void assertUrisEqual(Uri expected, Uri actual) {
+ assertEquals(expected.getScheme(), actual.getScheme());
+ assertEquals(expected.getSchemeSpecificPart(), actual.getSchemeSpecificPart());
+ }
+}