API cleanup for PhoneAccount.
Bug: 17390175
Bug: 17329632
Change-Id: I133cc2cdaa5c3abbdc88920a4995b4af570c53ef
diff --git a/src/com/android/telecomm/PhoneAccountRegistrar.java b/src/com/android/telecomm/PhoneAccountRegistrar.java
index 74cdf90..4223b63 100644
--- a/src/com/android/telecomm/PhoneAccountRegistrar.java
+++ b/src/com/android/telecomm/PhoneAccountRegistrar.java
@@ -718,8 +718,8 @@
new XmlSerialization<PhoneAccount>() {
private static final String CLASS_PHONE_ACCOUNT = "phone_account";
private static final String ACCOUNT_HANDLE = "account_handle";
- private static final String HANDLE = "handle";
- private static final String SUBSCRIPTION_NUMBER = "subscription_number";
+ private static final String ADDRESS = "handle";
+ private static final String SUBSCRIPTION_ADDRESS = "subscription_number";
private static final String CAPABILITIES = "capabilities";
private static final String ICON_RES_ID = "icon_res_id";
private static final String LABEL = "label";
@@ -738,8 +738,8 @@
serializer.endTag(null, ACCOUNT_HANDLE);
}
- writeTextSafely(HANDLE, o.getHandle(), serializer);
- writeTextSafely(SUBSCRIPTION_NUMBER, o.getSubscriptionNumber(), serializer);
+ writeTextSafely(ADDRESS, o.getAddress(), serializer);
+ writeTextSafely(SUBSCRIPTION_ADDRESS, o.getSubscriptionAddress(), serializer);
writeTextSafely(CAPABILITIES, Integer.toString(o.getCapabilities()), serializer);
writeTextSafely(ICON_RES_ID, Integer.toString(o.getIconResId()), serializer);
writeTextSafely(LABEL, o.getLabel(), serializer);
@@ -755,8 +755,8 @@
if (parser.getName().equals(CLASS_PHONE_ACCOUNT)) {
int outerDepth = parser.getDepth();
PhoneAccountHandle accountHandle = null;
- Uri handle = null;
- String subscriptionNumber = null;
+ Uri address = null;
+ Uri subscriptionAddress = null;
int capabilities = 0;
int iconResId = 0;
String label = null;
@@ -768,12 +768,13 @@
parser.nextTag();
accountHandle = sPhoneAccountHandleXml.readFromXml(parser, version,
context);
- } else if (parser.getName().equals(HANDLE)) {
+ } else if (parser.getName().equals(ADDRESS)) {
parser.next();
- handle = Uri.parse(parser.getText());
- } else if (parser.getName().equals(SUBSCRIPTION_NUMBER)) {
+ address = Uri.parse(parser.getText());
+ } else if (parser.getName().equals(SUBSCRIPTION_ADDRESS)) {
parser.next();
- subscriptionNumber = parser.getText();
+ String nextText = parser.getText();
+ subscriptionAddress = nextText == null ? null : Uri.parse(nextText);
} else if (parser.getName().equals(CAPABILITIES)) {
parser.next();
capabilities = Integer.parseInt(parser.getText());
@@ -812,15 +813,13 @@
}
}
- return PhoneAccount.builder()
- .withAccountHandle(accountHandle)
- .withHandle(handle)
- .withSubscriptionNumber(subscriptionNumber)
- .withCapabilities(capabilities)
- .withIconResId(iconResId)
- .withLabel(label)
- .withShortDescription(shortDescription)
- .withSupportedUriSchemes(supportedUriSchemes)
+ return PhoneAccount.builder(accountHandle, label)
+ .setAddress(address)
+ .setSubscriptionAddress(subscriptionAddress)
+ .setCapabilities(capabilities)
+ .setIconResId(iconResId)
+ .setShortDescription(shortDescription)
+ .setSupportedUriSchemes(supportedUriSchemes)
.build();
}
return null;
diff --git a/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java b/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
index e99c395..59047da 100644
--- a/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
+++ b/tests/src/com/android/telecomm/testapps/CallServiceNotifier.java
@@ -31,6 +31,7 @@
import android.util.Log;
import android.widget.Toast;
+import java.util.Arrays;
import java.util.List;
/**
@@ -98,45 +99,42 @@
telecommManager.clearAccounts(context.getPackageName());
- telecommManager.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(
+ telecommManager.registerPhoneAccount(PhoneAccount.builder(
new PhoneAccountHandle(
new ComponentName(context, TestConnectionService.class),
- CALL_PROVIDER_ID))
- .withHandle(Uri.parse("tel:555-TEST"))
- .withSubscriptionNumber("555-TEST")
- .withCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
- .withIconResId(R.drawable.stat_sys_phone_call)
- .withLabel("TelecommTestApp Call Provider")
- .withShortDescription("a short description for the call provider")
- .withSupportedUriScheme(PhoneAccount.SCHEME_TEL)
+ CALL_PROVIDER_ID),
+ "TelecommTestApp Call Provider")
+ .setAddress(Uri.parse("tel:555-TEST"))
+ .setSubscriptionAddress(Uri.parse("tel:555-TEST"))
+ .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
+ .setIconResId(R.drawable.stat_sys_phone_call)
+ .setShortDescription("a short description for the call provider")
+ .setSupportedUriSchemes(Arrays.asList("tel"))
.build());
- telecommManager.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(
+ telecommManager.registerPhoneAccount(PhoneAccount.builder(
new PhoneAccountHandle(
new ComponentName(context, TestConnectionService.class),
- SIM_SUBSCRIPTION_ID))
- .withHandle(Uri.parse("tel:555-TSIM"))
- .withSubscriptionNumber("555-TSIM")
- .withCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER |
+ SIM_SUBSCRIPTION_ID),
+ "TelecommTestApp SIM Subscription")
+ .setAddress(Uri.parse("tel:555-TSIM"))
+ .setSubscriptionAddress(Uri.parse("tel:555-TSIM"))
+ .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER |
PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)
- .withIconResId(R.drawable.stat_sys_phone_call)
- .withLabel("TelecommTestApp SIM Subscription")
- .withShortDescription("a short description for the sim subscription")
+ .setIconResId(R.drawable.stat_sys_phone_call)
+ .setShortDescription("a short description for the sim subscription")
.build());
- telecommManager.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(
+ telecommManager.registerPhoneAccount(PhoneAccount.builder(
new PhoneAccountHandle(
new ComponentName(context, TestConnectionManager.class),
- CONNECTION_MANAGER_ID))
- .withHandle(Uri.parse("tel:555-CMGR"))
- .withSubscriptionNumber("555-CMGR")
- .withCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER)
- .withIconResId(R.drawable.stat_sys_phone_call)
- .withLabel("TelecommTestApp CONNECTION MANAGER")
- .withShortDescription("a short description for the connection manager")
+ CONNECTION_MANAGER_ID),
+ "TelecommTestApp CONNECTION MANAGER")
+ .setAddress(Uri.parse("tel:555-CMGR"))
+ .setSubscriptionAddress(Uri.parse("tel:555-CMGR"))
+ .setCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER)
+ .setIconResId(R.drawable.stat_sys_phone_call)
+ .setShortDescription("a short description for the connection manager")
.build());
}
diff --git a/tests/src/com/android/telecomm/tests/unit/PhoneAccountRegistrarTest.java b/tests/src/com/android/telecomm/tests/unit/PhoneAccountRegistrarTest.java
index b64714e..939cdf6 100644
--- a/tests/src/com/android/telecomm/tests/unit/PhoneAccountRegistrarTest.java
+++ b/tests/src/com/android/telecomm/tests/unit/PhoneAccountRegistrarTest.java
@@ -46,59 +46,55 @@
@Override
public void setUp() {
mRegistrar = new PhoneAccountRegistrar(getContext(), FILE_NAME);
- mRegistrar.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(
- new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id0"))
- .withHandle(Uri.parse("tel:555-1212"))
- .withSubscriptionNumber("555-1212")
- .withCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER)
- .withIconResId(0)
- .withLabel("label0")
- .withShortDescription("desc0")
+ mRegistrar.registerPhoneAccount(PhoneAccount.builder(
+ new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id0"),
+ "label0")
+ .setAddress(Uri.parse("tel:555-1212"))
+ .setSubscriptionAddress(Uri.parse("tel:555-1212"))
+ .setCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER)
+ .setIconResId(0)
+ .setShortDescription("desc0")
.build());
- mRegistrar.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(
- new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id1"))
- .withHandle(Uri.parse("tel:555-1212"))
- .withSubscriptionNumber("555-1212")
- .withCapabilities(
+ mRegistrar.registerPhoneAccount(PhoneAccount.builder(
+ new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id1"),
+ "label1")
+ .setAddress(Uri.parse("tel:555-1212"))
+ .setSubscriptionAddress(Uri.parse("tel:555-1212"))
+ .setCapabilities(
PhoneAccount.CAPABILITY_CALL_PROVIDER
| PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION
)
- .withIconResId(0)
- .withLabel("label1")
- .withShortDescription("desc1")
+ .setIconResId(0)
+ .setShortDescription("desc1")
.build());
- mRegistrar.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(
- new PhoneAccountHandle(new ComponentName("pkg1", "cls1"), "id2"))
- .withHandle(Uri.parse("tel:555-1212"))
- .withSubscriptionNumber("555-1212")
- .withCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
- .withIconResId(0)
- .withLabel("label2")
- .withShortDescription("desc2")
+ mRegistrar.registerPhoneAccount(PhoneAccount.builder(
+ new PhoneAccountHandle(new ComponentName("pkg1", "cls1"), "id2"),
+ "label2")
+ .setAddress(Uri.parse("tel:555-1212"))
+ .setSubscriptionAddress(Uri.parse("tel:555-1212"))
+ .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
+ .setIconResId(0)
+ .setShortDescription("desc2")
.build());
- mRegistrar.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(
- new PhoneAccountHandle(new ComponentName("pkg1", "cls1"), "id3"))
- .withHandle(Uri.parse("tel:555-1212"))
- .withSubscriptionNumber("555-1212")
- .withCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
- .withIconResId(0)
- .withLabel("label2")
- .withShortDescription("desc2")
+ mRegistrar.registerPhoneAccount(PhoneAccount.builder(
+ new PhoneAccountHandle(new ComponentName("sippkg", "sipcls"), "id4"),
+ "label2")
+ .setAddress(Uri.parse("sip:test@sip.com"))
+ .setSubscriptionAddress(Uri.parse("test"))
+ .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
+ .setIconResId(0)
+ .setShortDescription("desc2")
+ .setSupportedUriSchemes(Arrays.asList(PhoneAccount.SCHEME_TEL))
.build());
- mRegistrar.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(
- new PhoneAccountHandle(new ComponentName("sippkg", "sipcls"), "id4"))
- .withHandle(Uri.parse("sip:test@sip.com"))
- .withSubscriptionNumber("test")
- .withCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
- .withIconResId(0)
- .withLabel("label2")
- .withShortDescription("desc2")
- .withSupportedUriScheme(PhoneAccount.SCHEME_TEL)
+ mRegistrar.registerPhoneAccount(PhoneAccount.builder(
+ new PhoneAccountHandle(new ComponentName("sippkg", "sipcls"), "id4"),
+ "label2")
+ .setAddress(Uri.parse("sip:test@sip.com"))
+ .setSubscriptionAddress(Uri.parse("test"))
+ .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
+ .setIconResId(0)
+ .setShortDescription("desc2")
+ .setSupportedUriSchemes(Arrays.asList(PhoneAccount.SCHEME_TEL))
.build());
}
@@ -158,12 +154,8 @@
PhoneAccountHandle result = roundTrip(this, input,
PhoneAccountRegistrar.sPhoneAccountHandleXml, mContext);
assertPhoneAccountHandleEquals(input, result);
- PhoneAccountHandle inputN =
- new PhoneAccountHandle(
- new ComponentName(
- "pkg0", // ctor does not allow null
- "cls0"), // ctor does not allow null
- null);
+
+ PhoneAccountHandle inputN = new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), null);
PhoneAccountHandle resultN = roundTrip(this, inputN,
PhoneAccountRegistrar.sPhoneAccountHandleXml, mContext);
Log.i(this, "inputN = %s, resultN = %s", inputN, resultN);
@@ -173,8 +165,8 @@
private void assertPhoneAccountEquals(PhoneAccount a, PhoneAccount b) {
if (a != b) {
assertPhoneAccountHandleEquals(a.getAccountHandle(), b.getAccountHandle());
- assertEquals(a.getHandle(), b.getHandle());
- assertEquals(a.getSubscriptionNumber(), b.getSubscriptionNumber());
+ assertEquals(a.getAddress(), b.getAddress());
+ assertEquals(a.getSubscriptionAddress(), b.getSubscriptionAddress());
assertEquals(a.getCapabilities(), b.getCapabilities());
assertEquals(a.getIconResId(), b.getIconResId());
assertEquals(a.getLabel(), b.getLabel());
@@ -188,7 +180,10 @@
PhoneAccount result = roundTrip(this, input, PhoneAccountRegistrar.sPhoneAccountXml,
mContext);
assertPhoneAccountEquals(input, result);
- PhoneAccount inputN = PhoneAccount.builder().build();
+
+ PhoneAccountHandle handleN =
+ new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), null);
+ PhoneAccount inputN = PhoneAccount.builder(handleN, "label").build();
PhoneAccount resultN = roundTrip(this, inputN, PhoneAccountRegistrar.sPhoneAccountXml,
mContext);
assertPhoneAccountEquals(inputN, resultN);
@@ -272,27 +267,27 @@
// If have one account but not suitable, default returns null
mRegistrar.unregisterPhoneAccount(
new PhoneAccountHandle(new ComponentName("pkg1", "cls1"), "id3"));
- mRegistrar.registerPhoneAccount(PhoneAccount.builder()
- .withAccountHandle(new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id0"))
- .withHandle(Uri.parse("tel:555-1212"))
- .withSubscriptionNumber("555-1212")
- .withCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER)
- .withIconResId(0)
- .withLabel("label0")
- .withShortDescription("desc0")
+ mRegistrar.registerPhoneAccount(PhoneAccount.builder(
+ new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id0"),
+ "label0")
+ .setAddress(Uri.parse("tel:555-1212"))
+ .setSubscriptionAddress(Uri.parse("tel:555-1212"))
+ .setCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER)
+ .setIconResId(0)
+ .setShortDescription("desc0")
.build());
assertEquals(null, mRegistrar.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL));
}
private static PhoneAccount makeQuickAccount(String pkg, String cls, String id, int idx) {
- return PhoneAccount.builder()
- .withAccountHandle(new PhoneAccountHandle(new ComponentName(pkg, cls), id))
- .withHandle(Uri.parse("http://foo.com/" + idx))
- .withSubscriptionNumber("555-000" + idx)
- .withCapabilities(idx)
- .withIconResId(idx)
- .withLabel("label" + idx)
- .withShortDescription("desc" + idx)
+ return PhoneAccount.builder(
+ new PhoneAccountHandle(new ComponentName(pkg, cls), id),
+ "label" + idx)
+ .setAddress(Uri.parse("http://foo.com/" + idx))
+ .setSubscriptionAddress(Uri.parse("tel:555-000" + idx))
+ .setCapabilities(idx)
+ .setIconResId(idx)
+ .setShortDescription("desc" + idx)
.build();
}