summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-20 22:50:30 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-20 22:50:30 +0000
commitaa581ae16276d69b43522056cd45e73b4cff1666 (patch)
tree25d7a269433d4707ccbef8bc8c7acb61b2790aa3
parent8f1c5d95461151fe096ca6a3f783b9491caa39f3 (diff)
parent918c1b8107023996d66f34173e316c5dd8d58b81 (diff)
downloadTelecomm-android14-qpr2-s1-release.tar.gz
Change-Id: Ieb18dfd590de71630f88a288d96b7251782525d5
-rw-r--r--src/com/android/server/telecom/PhoneAccountRegistrar.java61
-rw-r--r--tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java34
2 files changed, 7 insertions, 88 deletions
diff --git a/src/com/android/server/telecom/PhoneAccountRegistrar.java b/src/com/android/server/telecom/PhoneAccountRegistrar.java
index 5f23e4d70..b462856b7 100644
--- a/src/com/android/server/telecom/PhoneAccountRegistrar.java
+++ b/src/com/android/server/telecom/PhoneAccountRegistrar.java
@@ -934,15 +934,13 @@ public class PhoneAccountRegistrar {
* @throws IllegalArgumentException if MAX_PHONE_ACCOUNT_REGISTRATIONS are reached
*/
private void enforceMaxPhoneAccountLimit(@NonNull PhoneAccount account) {
- List<PhoneAccount> unverifiedAccounts = getAccountsForPackage_BypassResolveComp(
- account.getAccountHandle().getComponentName().getPackageName(),
- account.getAccountHandle().getUserHandle());
- // verify each phone account is backed by a valid ConnectionService. If the
- // ConnectionService has been disabled or cannot be resolved, unregister the accounts.
- List<PhoneAccount> verifiedAccounts =
- cleanupUnresolvableConnectionServiceAccounts(unverifiedAccounts);
- // enforce the max phone account limit for the application registering accounts
- if (verifiedAccounts.size() >= MAX_PHONE_ACCOUNT_REGISTRATIONS) {
+ final PhoneAccountHandle accountHandle = account.getAccountHandle();
+ final UserHandle user = accountHandle.getUserHandle();
+ final ComponentName componentName = accountHandle.getComponentName();
+
+ if (getPhoneAccountHandles(0, null, componentName.getPackageName(),
+ true /* includeDisabled */, user, false /* crossUserAccess */).size()
+ >= MAX_PHONE_ACCOUNT_REGISTRATIONS) {
EventLog.writeEvent(0x534e4554, "259064622", Binder.getCallingUid(),
"enforceMaxPhoneAccountLimit");
throw new IllegalArgumentException(
@@ -1589,51 +1587,6 @@ public class PhoneAccountRegistrar {
}
/**
- * This getter should be used when you want to bypass the {@link
- * PhoneAccountRegistrar#resolveComponent(PhoneAccountHandle)} check when fetching accounts
- */
- @VisibleForTesting
- public List<PhoneAccount> getAccountsForPackage_BypassResolveComp(String packageName,
- UserHandle userHandle) {
- List<PhoneAccount> accounts = new ArrayList<>(mState.accounts.size());
- for (PhoneAccount m : mState.accounts) {
- PhoneAccountHandle handle = m.getAccountHandle();
-
- if (packageName != null && !packageName.equals(
- handle.getComponentName().getPackageName())) {
- // Not the right package name; skip this one.
- continue;
- }
-
- if (!isVisibleForUser(m, userHandle, false)) {
- // Account is not visible for the current user; skip this one.
- continue;
- }
- accounts.add(m);
- }
- return accounts;
- }
-
- @VisibleForTesting
- public List<PhoneAccount> cleanupUnresolvableConnectionServiceAccounts(
- List<PhoneAccount> accounts) {
- ArrayList<PhoneAccount> verifiedAccounts = new ArrayList<>();
- for (PhoneAccount account : accounts) {
- PhoneAccountHandle handle = account.getAccountHandle();
- // if the ConnectionService has been disabled or can longer be found, remove the handle
- if (resolveComponent(handle).isEmpty()) {
- Log.i(this,
- "Cannot resolve the ConnectionService for handle=[%s]; unregistering"
- + " account", handle);
- unregisterPhoneAccount(handle);
- } else {
- verifiedAccounts.add(account);
- }
- }
- return verifiedAccounts;
- }
-
- /**
* Clean up the orphan {@code PhoneAccount}. An orphan {@code PhoneAccount} is a phone
* account that does not have a {@code UserHandle} or belongs to a deleted package.
*
diff --git a/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java b/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
index 9fcb87a38..e573bb81f 100644
--- a/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
+++ b/tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java
@@ -353,40 +353,6 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase {
PhoneAccount.SCHEME_TEL));
}
- /**
- * Verify when a {@link android.telecom.ConnectionService} is disabled or cannot be resolved,
- * all phone accounts are unregistered when calling
- * {@link PhoneAccountRegistrar#getAccountsForPackage_BypassResolveComp(String, UserHandle)}.
- */
- @Test
- public void testCannotResolveServiceUnregistersAccounts() throws Exception {
- ComponentName componentName = makeQuickConnectionServiceComponentName();
- PhoneAccount account = makeQuickAccountBuilder("0", 0, USER_HANDLE_10)
- .setCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER
- | PhoneAccount.CAPABILITY_CALL_PROVIDER).build();
- // add the ConnectionService and register a single phone account for it
- mComponentContextFixture.addConnectionService(componentName,
- Mockito.mock(IConnectionService.class));
- registerAndEnableAccount(account);
- // verify the start state
- assertEquals(1,
- mRegistrar.getAccountsForPackage_BypassResolveComp(componentName.getPackageName(),
- USER_HANDLE_10).size());
- // remove the ConnectionService so that the account cannot be resolved anymore
- mComponentContextFixture.removeConnectionService(componentName,
- Mockito.mock(IConnectionService.class));
- // verify the account is unregistered when fetching the phone accounts for the package
- assertEquals(1,
- mRegistrar.getAccountsForPackage_BypassResolveComp(componentName.getPackageName(),
- USER_HANDLE_10).size());
- assertEquals(0,mRegistrar.cleanupUnresolvableConnectionServiceAccounts(
- mRegistrar.getAccountsForPackage_BypassResolveComp(componentName.getPackageName(),
- USER_HANDLE_10)).size());
- assertEquals(0,
- mRegistrar.getAccountsForPackage_BypassResolveComp(componentName.getPackageName(),
- USER_HANDLE_10).size());
- }
-
@MediumTest
@Test
public void testSimCallManager() throws Exception {