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

Commit afe59e51 authored by Santos Cordon's avatar Santos Cordon
Browse files

Add setting to turn off connection manager support.

connection manager support allows a component to supply alternative
calling methods in place of a SIM-based call.

Bug: 16794451
Change-Id: I7cbe8342bff5ba8e8f20ceb61a1b6fdbee7a543c
parent 944a3da9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -43,4 +43,8 @@
         if this package has not registered any accounts, then it will be ignored.
         [DO NOT TRANSLATE] -->
    <string name="default_connection_manager_component" translatable="false"></string>

    <!-- Flag indicating that wi-fi calling through a connection manager is supported.
         [DO NOT TRANSLATE] -->
    <bool name="connection_manager_enabled" translatable="false">true</bool>
</resources>
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.telecomm;

import android.content.Context;
import android.telecomm.ParcelableConnection;
import android.telecomm.PhoneAccount;
import android.telecomm.PhoneAccountHandle;
@@ -176,6 +177,12 @@ final class CreateConnectionProcessor {
    }

    private boolean shouldSetConnectionManager() {
        Context context = TelecommApp.getInstance();
        if (!context.getResources().getBoolean(R.bool.connection_manager_enabled)) {
            // Connection Manager support has been turned off, disregard.
            return false;
        }

        if (mAttemptRecords.size() == 0) {
            return false;
        }
+1 −13
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public class PhoneAccountPreferencesActivity extends Activity {

            mSimCallManagerAccount.setModel(
                    registrar,
                    getSimCallManagers(registrar),
                    registrar.getAllConnectionManagerPhoneAccounts(),
                    registrar.getSimCallManager(),
                    getString(R.string.do_not_use_sim_call_manager));

@@ -83,17 +83,5 @@ public class PhoneAccountPreferencesActivity extends Activity {
            }
            return false;
        }

        private List<PhoneAccountHandle> getSimCallManagers(PhoneAccountRegistrar registrar) {
            List<PhoneAccountHandle> simCallManagers = new ArrayList<>();
            List<PhoneAccountHandle> allAccounts = registrar.getAllPhoneAccountHandles();
            for (int i = 0; i < allAccounts.size(); i++) {
                PhoneAccount account = registrar.getPhoneAccount(allAccounts.get(i));
                if ((account.getCapabilities() & PhoneAccount.CAPABILITY_CONNECTION_MANAGER) != 0) {
                    simCallManagers.add(allAccounts.get(i));
                }
            }
            return simCallManagers;
        }
    }
}
+30 −6
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import java.io.InputStream;
import java.lang.SecurityException;
import java.lang.String;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
@@ -74,6 +75,7 @@ public final class PhoneAccountRegistrar {

    private final List<Listener> mListeners = new CopyOnWriteArrayList<>();
    private final AtomicFile mAtomicFile;
    private final Context mContext;
    private State mState;

    public PhoneAccountRegistrar(Context context) {
@@ -85,6 +87,7 @@ public final class PhoneAccountRegistrar {
        // TODO: Change file location when Telecomm is part of system
        mAtomicFile = new AtomicFile(new File(context.getFilesDir(), fileName));
        mState = new State();
        mContext = context;
        read();
    }

@@ -148,6 +151,10 @@ public final class PhoneAccountRegistrar {
    }

    public void setSimCallManager(PhoneAccountHandle callManager) {
        if (!isEnabledConnectionManager()) {
            return;
        }

        if (callManager != null) {
            PhoneAccount callManagerAccount = getPhoneAccount(callManager);
            if (callManagerAccount == null) {
@@ -164,6 +171,10 @@ public final class PhoneAccountRegistrar {
    }

    public PhoneAccountHandle getSimCallManager() {
        if (!isEnabledConnectionManager()) {
            return null;
        }

        if (mState.simCallManager != null) {
            // Return the registered sim call manager iff it still exists (we keep a sticky
            // setting to survive account deletion and re-addition)
@@ -175,11 +186,10 @@ public final class PhoneAccountRegistrar {
        }

        // See if the OEM has specified a default one.
        Context context = TelecommApp.getInstance();
        String defaultConnectionMgr =
                context.getResources().getString(R.string.default_connection_manager_component);
                mContext.getResources().getString(R.string.default_connection_manager_component);
        if (!TextUtils.isEmpty(defaultConnectionMgr)) {
            PackageManager pm = context.getPackageManager();
            PackageManager pm = mContext.getPackageManager();

            ComponentName componentName = ComponentName.unflattenFromString(defaultConnectionMgr);
            Intent intent = new Intent(ConnectionService.SERVICE_INTERFACE);
@@ -219,7 +229,14 @@ public final class PhoneAccountRegistrar {
    }

    public List<PhoneAccountHandle> getOutgoingPhoneAccounts() {
        return getCallProviderAccountHandles();
        return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER);
    }

    public List<PhoneAccountHandle> getAllConnectionManagerPhoneAccounts() {
        if (isEnabledConnectionManager()) {
            return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CONNECTION_MANAGER);
        }
        return Collections.emptyList();
    }

    public PhoneAccount getPhoneAccount(PhoneAccountHandle handle) {
@@ -323,6 +340,10 @@ public final class PhoneAccountRegistrar {
        }
    }

    private boolean isEnabledConnectionManager() {
        return mContext.getResources().getBoolean(R.bool.connection_manager_enabled);
    }

    /**
     * Determines if the connection service specified by a {@link PhoneAccountHandle} has the
     * {@link Manifest.permission#BIND_CONNECTION_SERVICE} permission.
@@ -352,10 +373,13 @@ public final class PhoneAccountRegistrar {
        return (account.getCapabilities() & capability) == capability;
    }

    private List<PhoneAccountHandle> getCallProviderAccountHandles() {
    /**
     * Returns a list of phone account handles with the specified flag.
     */
    private List<PhoneAccountHandle> getPhoneAccountHandles(int flags) {
        List<PhoneAccountHandle> accountHandles = new ArrayList<>();
        for (PhoneAccount m : mState.accounts) {
            if (has(m, PhoneAccount.CAPABILITY_CALL_PROVIDER)) {
            if (has(m, flags)) {
                accountHandles.add(m.getAccountHandle());
            }
        }