Merge "enforce limit on SubscriptionAddress" into udc-dev am: 42a1593624
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/services/Telecomm/+/21674084
Change-Id: Ie84804fec0d238cfaad4dcfdf45fc848028c11e5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/server/telecom/PhoneAccountRegistrar.java b/src/com/android/server/telecom/PhoneAccountRegistrar.java
index a7824b4..3c6934a 100644
--- a/src/com/android/server/telecom/PhoneAccountRegistrar.java
+++ b/src/com/android/server/telecom/PhoneAccountRegistrar.java
@@ -962,18 +962,20 @@
String[] fields =
{"Package Name", "Class Name", "PhoneAccountHandle Id", "Label", "ShortDescription",
- "GroupId", "Address"};
+ "GroupId", "Address", "SubscriptionAddress"};
CharSequence[] args = {handle.getComponentName().getPackageName(),
handle.getComponentName().getClassName(), handle.getId(), account.getLabel(),
account.getShortDescription(), account.getGroupId(),
- (account.getAddress() != null ? account.getAddress().toString() : "")};
+ (account.getAddress() != null ? account.getAddress().toString() : ""),
+ (account.getSubscriptionAddress() != null ?
+ account.getSubscriptionAddress().toString() : "")};
for (int i = 0; i < fields.length; i++) {
if (args[i] != null && args[i].length() > MAX_PHONE_ACCOUNT_FIELD_CHAR_LIMIT) {
EventLog.writeEvent(0x534e4554, "259064622", Binder.getCallingUid(),
"enforceCharacterLimit");
- throw new IllegalArgumentException("The PhoneAccount or PhoneAccountHandle"
- + fields[i] + " field has an invalid character count. PhoneAccount and "
+ throw new IllegalArgumentException("The PhoneAccount or PhoneAccountHandle ["
+ + fields[i] + "] field has an invalid character count. PhoneAccount and "
+ "PhoneAccountHandle String and Char-Sequence fields are limited to "
+ MAX_PHONE_ACCOUNT_FIELD_CHAR_LIMIT + " characters.");
}
diff --git a/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java b/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
index c6cbbbb..cef032f 100644
--- a/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
+++ b/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
@@ -1667,6 +1667,23 @@
}
}
+ /**
+ * Ensure an IllegalArgumentException is thrown when providing a SubscriptionAddress that
+ * exceeds the PhoneAccountRegistrar limit.
+ */
+ @Test
+ public void testLimitOnSubscriptionAddress() throws Exception {
+ String text = "a".repeat(100);
+ PhoneAccount.Builder builder = new PhoneAccount.Builder(makeQuickAccountHandle(TEST_ID),
+ TEST_LABEL).setSubscriptionAddress(Uri.fromParts(text, text, text));
+ try {
+ mRegistrar.enforceCharacterLimit(builder.build());
+ fail("failed to throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // pass test
+ }
+ }
+
private static PhoneAccount.Builder makeBuilderWithBindCapabilities(PhoneAccountHandle handle) {
return new PhoneAccount.Builder(handle, TEST_LABEL)
.setCapabilities(PhoneAccount.CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS);