Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb13818e authored by Thomas Stuart's avatar Thomas Stuart Committed by Android (Google) Code Review
Browse files

Merge "fix TelecomManager#getters for transactional accounts" into udc-dev

parents f1651e6b 9837645d
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -873,7 +873,7 @@ public class PhoneAccountRegistrar {
    public void registerPhoneAccount(PhoneAccount account) {
        // Enforce the requirement that a connection service for a phone account has the correct
        // permission.
        if (!hasTransactionalCallCapabilites(account) &&
        if (!hasTransactionalCallCapabilities(account) &&
                !phoneAccountRequiresBindPermission(account.getAccountHandle())) {
            Log.w(this,
                    "Phone account %s does not have BIND_TELECOM_CONNECTION_SERVICE permission.",
@@ -1062,7 +1062,7 @@ public class PhoneAccountRegistrar {
        boolean isNewAccount;

        // add self-managed capability for transactional accounts that are missing it
        if (hasTransactionalCallCapabilites(account) &&
        if (hasTransactionalCallCapabilities(account) &&
                !account.hasCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)) {
            account = account.toBuilder()
                    .setCapabilities(account.getCapabilities()
@@ -1367,13 +1367,13 @@ public class PhoneAccountRegistrar {
     * @return {@code True} if the phone account has permission.
     */
    public boolean phoneAccountRequiresBindPermission(PhoneAccountHandle phoneAccountHandle) {
        List<ResolveInfo> resolveInfos = resolveComponent(phoneAccountHandle);
        if (resolveInfos.isEmpty()) {
            Log.w(this, "phoneAccount %s not found", phoneAccountHandle.getComponentName());
        if (hasTransactionalCallCapabilities(getPhoneAccountUnchecked(phoneAccountHandle))) {
            return false;
        }

        if (hasTransactionalCallCapabilites(getPhoneAccountUnchecked(phoneAccountHandle))) {
        List<ResolveInfo> resolveInfos = resolveComponent(phoneAccountHandle);
        if (resolveInfos.isEmpty()) {
            Log.w(this, "phoneAccount %s not found", phoneAccountHandle.getComponentName());
            return false;
        }

@@ -1396,7 +1396,7 @@ public class PhoneAccountRegistrar {
    }

    @VisibleForTesting
    public boolean hasTransactionalCallCapabilites(PhoneAccount phoneAccount) {
    public boolean hasTransactionalCallCapabilities(PhoneAccount phoneAccount) {
        if (phoneAccount == null) {
            return false;
        }
@@ -1530,7 +1530,10 @@ public class PhoneAccountRegistrar {
            }
            PhoneAccountHandle handle = m.getAccountHandle();

            if (resolveComponent(handle).isEmpty()) {
            // PhoneAccounts with CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS do not require a
            // ConnectionService and will fail [resolveComponent(PhoneAccountHandle)]. Bypass
            // the [resolveComponent(PhoneAccountHandle)] for transactional accounts.
            if (!hasTransactionalCallCapabilities(m) && resolveComponent(handle).isEmpty()) {
                // This component cannot be resolved anymore; skip this one.
                continue;
            }
+21 −5
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
@@ -707,7 +705,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase {
                .setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
                .build();

        assertFalse(mRegistrar.hasTransactionalCallCapabilites(accountWithoutCapability));
        assertFalse(mRegistrar.hasTransactionalCallCapabilities(accountWithoutCapability));

        try {
            mRegistrar.registerPhoneAccount(accountWithoutCapability);
@@ -730,7 +728,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase {
                        PhoneAccount.CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS)
                .build();

        assertTrue(mRegistrar.hasTransactionalCallCapabilites(accountWithCapability));
        assertTrue(mRegistrar.hasTransactionalCallCapabilities(accountWithCapability));

        try {
            mRegistrar.registerPhoneAccount(accountWithCapability);
@@ -752,7 +750,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase {
                        PhoneAccount.CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS)
                .build();

        assertTrue(mRegistrar.hasTransactionalCallCapabilites(accountWithCapability));
        assertTrue(mRegistrar.hasTransactionalCallCapabilities(accountWithCapability));

        try {
            // WHEN
@@ -1684,6 +1682,24 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase {
        }
    }

    /**
     * PhoneAccounts with CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS do not require a
     * ConnectionService. Ensure that such an account can be registered and fetched.
     */
    @Test
    public void testFetchingTransactionalAccounts() {
        PhoneAccount account = makeBuilderWithBindCapabilities(
                makeQuickAccountHandle(TEST_ID)).build();

        try {
            assertEquals(0, mRegistrar.getAllPhoneAccounts(null, true).size());
            registerAndEnableAccount(account);
            assertEquals(1, mRegistrar.getAllPhoneAccounts(null, true).size());
        } finally {
            mRegistrar.unregisterPhoneAccount(account.getAccountHandle());
        }
    }

    private static PhoneAccount.Builder makeBuilderWithBindCapabilities(PhoneAccountHandle handle) {
        return new PhoneAccount.Builder(handle, TEST_LABEL)
                .setCapabilities(PhoneAccount.CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS);