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

Commit 0fada668 authored by Nancy Chen's avatar Nancy Chen Committed by Android Git Automerger
Browse files

am b3c4b285: Merge "Remove ability to enable/disable phoneaccounts (3/6)" into lmp-dev

* commit 'b3c4b285':
  Remove ability to enable/disable phoneaccounts (3/6)
parents 7c1d5c56 b3c4b285
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -319,9 +319,9 @@ public final class CallsManager extends Call.ListenerBase {
        // as if a phoneAccount was not specified (does the default behavior instead).
        // Note: We will not attempt to dial with a requested phoneAccount if it is disabled.
        if (phoneAccountHandle != null) {
            List<PhoneAccountHandle> enabledAccounts =
                    app.getPhoneAccountRegistrar().getEnabledPhoneAccounts(handle.getScheme());
            if (!enabledAccounts.contains(phoneAccountHandle)) {
            List<PhoneAccountHandle> accounts =
                    app.getPhoneAccountRegistrar().getCallCapablePhoneAccounts(handle.getScheme());
            if (!accounts.contains(phoneAccountHandle)) {
                phoneAccountHandle = null;
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -928,7 +928,7 @@ final class ConnectionServiceWrapper extends ServiceBinder<IConnectionService> {
        // Make a list of ConnectionServices that are listed as being associated with SIM accounts
        final Set<ConnectionServiceWrapper> simServices = Collections.newSetFromMap(
                new ConcurrentHashMap<ConnectionServiceWrapper, Boolean>(8, 0.9f, 1));
        for (PhoneAccountHandle handle : registrar.getEnabledPhoneAccounts()) {
        for (PhoneAccountHandle handle : registrar.getCallCapablePhoneAccounts()) {
            PhoneAccount account = registrar.getPhoneAccount(handle);
            if ((account.getCapabilities() & PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION) != 0) {
                ConnectionServiceWrapper service =
+14 −125
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.server.telecom;

import android.Manifest;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
@@ -120,7 +118,7 @@ public final class PhoneAccountRegistrar {
            }
        }

        List<PhoneAccountHandle> outgoing = getEnabledPhoneAccounts(uriScheme);
        List<PhoneAccountHandle> outgoing = getCallCapablePhoneAccounts(uriScheme);
        switch (outgoing.size()) {
            case 0:
                // There are no accounts, so there can be no default
@@ -265,43 +263,42 @@ public final class PhoneAccountRegistrar {
    }

    /**
     * Determines the number of enabled and disabled {@link PhoneAccount}s.
     * Determines the number of all {@link PhoneAccount}s.
     *
     * @return The number of enabled and disabled {@link PhoneAccount}s
     * @return The total number {@link PhoneAccount}s.
     */
    public int getAllPhoneAccountsCount() {
        return mState.accounts.size();
    }

    /**
     * Retrieves a list of all enabled call provider phone accounts.
     * Retrieves a list of all call provider phone accounts.
     *
     * @return The phone account handles.
     */
    public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
    public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
        return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER);
    }

    /**
     * Retrieves a list of all enabled phone account call provider phone accounts supporting the
     * Retrieves a list of all phone account call provider phone accounts supporting the
     * specified URI scheme.
     *
     * @param uriScheme The URI scheme.
     * @return The phone account handles.
     */
    public List<PhoneAccountHandle> getEnabledPhoneAccounts(String uriScheme) {
        return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER, uriScheme,
                false /* includeDisabled */);
    public List<PhoneAccountHandle> getCallCapablePhoneAccounts(String uriScheme) {
        return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER, uriScheme);
    }

    /**
     * Retrieves a list of all enabled phone account handles with the connection manager capability.
     * Retrieves a list of all phone account handles with the connection manager capability.
     *
     * @return The phone account handles.
     */
    public List<PhoneAccountHandle> getConnectionManagerPhoneAccounts() {
        return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CONNECTION_MANAGER,
                null /* supportedUriScheme */, false /* includeDisabled */);
                null /* supportedUriScheme */);
    }

    public PhoneAccount getPhoneAccount(PhoneAccountHandle handle) {
@@ -313,44 +310,6 @@ public final class PhoneAccountRegistrar {
        return null;
    }

    /**
     * Changes the enabled state of the {@link PhoneAccount} identified by a
     * {@link PhoneAccountHandle}.
     *
     * @param handle The {@link PhoneAccountHandle}.
     * @param isEnabled The new enabled state of the {@link PhoneAccount}.
     */
    public void setPhoneAccountEnabled(PhoneAccountHandle handle, boolean isEnabled) {
        PhoneAccount existing = getPhoneAccount(handle);
        if (existing.isEnabled() == isEnabled) {
            return;
        }

        // Do not permit PhoneAccounts which are marked as always enabled to be disabled.
        if (existing.hasCapabilities(PhoneAccount.CAPABILITY_ALWAYS_ENABLED)) {
            return;
        }

        // If we are disabling the current default outgoing phone account or Sim call manager we
        // need to null out those preferences.
        if (!isEnabled) {
            if (mState.defaultOutgoing != null && mState.defaultOutgoing.equals(handle)) {
                setUserSelectedOutgoingPhoneAccount(null);
            }

            if (mState.simCallManager != null && mState.simCallManager.equals(handle)) {
                setSimCallManager(null);
            }
        }

        PhoneAccount.Builder builder = existing.toBuilder().setEnabled(isEnabled);
        PhoneAccount replacement = builder.build();
        addOrReplacePhoneAccount(replacement);

        // Notify the package which registered this PhoneAccount of its new enabled state.
        notifyPhoneAccountEnabledStateChanged(replacement.getAccountHandle(), isEnabled);
    }

    // TODO: Should we implement an artificial limit for # of accounts associated with a single
    // ComponentName?
    public void registerPhoneAccount(PhoneAccount account) {
@@ -363,13 +322,6 @@ public final class PhoneAccountRegistrar {
                    "PhoneAccount connection service requires BIND_CONNECTION_SERVICE permission.");
        }

        // If there is an existing PhoneAccount already registered with this handle, copy its
        // enabled state to the new phone account.
        PhoneAccount existing = getPhoneAccount(account.getAccountHandle());
        if (existing != null) {
            account = account.toBuilder().setEnabled(existing.isEnabled()).build();
        }

        addOrReplacePhoneAccount(account);
    }

@@ -488,72 +440,27 @@ public final class PhoneAccountRegistrar {
     * @param flags Flags which the {@code PhoneAccount} must have.
     */
    private List<PhoneAccountHandle> getPhoneAccountHandles(int flags) {
        return getPhoneAccountHandles(flags, null, false /* includeDisabled */);
        return getPhoneAccountHandles(flags, null);
    }

    /**
     * Returns a list of phone account handles with the specified flag, supporting the specified
     * URI scheme.  By default, only enabled phone accounts are included, unless the
     * {@code includeDisabled} parameter is set {@code true}.
     * URI scheme.
     *
     * @param flags Flags which the {@code PhoneAccount} must have.
     * @param uriScheme URI schemes the PhoneAccount must handle.  {@code Null} bypasses the
     *                  URI scheme check.
     * @param includeDisabled When {@code true}, the list of phone accounts handles includes those
     *                        which are marked as disabled.
     */
    private List<PhoneAccountHandle> getPhoneAccountHandles(int flags, String uriScheme,
            boolean includeDisabled) {
    private List<PhoneAccountHandle> getPhoneAccountHandles(int flags, String uriScheme) {
        List<PhoneAccountHandle> accountHandles = new ArrayList<>();
        for (PhoneAccount m : mState.accounts) {
            if ((includeDisabled || m.isEnabled()) && m.hasCapabilities(flags) &&
                    (uriScheme == null || m.supportsUriScheme(uriScheme))) {
            if (m.hasCapabilities(flags) && (uriScheme == null || m.supportsUriScheme(uriScheme))) {
                accountHandles.add(m.getAccountHandle());
            }
        }
        return accountHandles;
    }

    /**
     * Notifies the package which registered a {@link PhoneAccount} that it has been enabled.
     * Only broadcasts the intent if the package has a {@link android.content.BroadcastReceiver}
     * registered for the intent.
     *
     * @param phoneAccountHandle The {@link PhoneAccountHandle} which has been enabled or disabled.
     * @param isEnabled {@code True} if the {@link PhoneAccount} is enabled, false otherwise.
     */
    private void notifyPhoneAccountEnabledStateChanged(PhoneAccountHandle phoneAccountHandle,
            boolean isEnabled) {
        Intent intent;

        if (isEnabled) {
            intent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_ENABLED);
        } else {
            intent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_DISABLED);
        }
        intent.setPackage(phoneAccountHandle.getComponentName().getPackageName());
        intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);

        if (isReceiverListening(intent)) {
            Log.i(this, "notifyPhoneAccountEnabledState %s %s", phoneAccountHandle,
                    (isEnabled ? "enabled" : "disabled"));
            mContext.sendBroadcast(intent);
        }
    }

    /**
     * Determines there is a {@link android.content.BroadcastReceiver} listening for an
     * {@link Intent}.
     *
     * @param intent The {@link Intent}.
     * @return {@code True} if there is a listener.
     */
    private boolean isReceiverListening(Intent intent) {
        PackageManager pm = mContext.getPackageManager();
        final List<ResolveInfo> activities = pm.queryBroadcastReceivers(intent, 0);
        return !(activities.isEmpty());
    }

    /**
     * The state of this {@code PhoneAccountRegistrar}.
     */
@@ -840,7 +747,6 @@ public final class PhoneAccountRegistrar {
        private static final String LABEL = "label";
        private static final String SHORT_DESCRIPTION = "short_description";
        private static final String SUPPORTED_URI_SCHEMES = "supported_uri_schemes";
        private static final String ENABLED = "enabled";
        private static final String TRUE = "true";
        private static final String FALSE = "false";

@@ -863,7 +769,6 @@ public final class PhoneAccountRegistrar {
                writeTextSafely(LABEL, o.getLabel(), serializer);
                writeTextSafely(SHORT_DESCRIPTION, o.getShortDescription(), serializer);
                writeStringList(SUPPORTED_URI_SCHEMES, o.getSupportedUriSchemes(), serializer);
                writeTextSafely(ENABLED, o.isEnabled() ? TRUE : FALSE, serializer);

                serializer.endTag(null, CLASS_PHONE_ACCOUNT);
            }
@@ -881,7 +786,6 @@ public final class PhoneAccountRegistrar {
                String label = null;
                String shortDescription = null;
                List<String> supportedUriSchemes = null;
                boolean enabled = false;

                while (XmlUtils.nextElementWithin(parser, outerDepth)) {
                    if (parser.getName().equals(ACCOUNT_HANDLE)) {
@@ -909,9 +813,6 @@ public final class PhoneAccountRegistrar {
                        shortDescription = parser.getText();
                    } else if (parser.getName().equals(SUPPORTED_URI_SCHEMES)) {
                        supportedUriSchemes = readStringList(parser);
                    } else if (parser.getName().equals(ENABLED)) {
                        parser.next();
                        enabled = parser.getText().equals(TRUE);
                    }
                }

@@ -936,17 +837,6 @@ public final class PhoneAccountRegistrar {
                    }
                }

                // Prior to version 3, PhoneAccounts didn't include the enabled option.  Enable
                // all TelephonyConnectionService phone accounts by default.
                if (version < 3) {
                    ComponentName telephonyComponentName = new ComponentName("com.android.phone",
                            "com.android.services.telephony.TelephonyConnectionService");

                    if (accountHandle.getComponentName().equals(telephonyComponentName)) {
                        enabled = true;
                    }
                }

                return PhoneAccount.builder(accountHandle, label)
                        .setAddress(address)
                        .setSubscriptionAddress(subscriptionAddress)
@@ -954,7 +844,6 @@ public final class PhoneAccountRegistrar {
                        .setIconResId(iconResId)
                        .setShortDescription(shortDescription)
                        .setSupportedUriSchemes(supportedUriSchemes)
                        .setEnabled(enabled)
                        .build();
            }
            return null;
+5 −33
Original line number Diff line number Diff line
@@ -193,11 +193,11 @@ public class TelecomServiceImpl extends ITelecomService.Stub {
    }

    @Override
    public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
    public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
        try {
            return mPhoneAccountRegistrar.getEnabledPhoneAccounts();
            return mPhoneAccountRegistrar.getCallCapablePhoneAccounts();
        } catch (Exception e) {
            Log.e(this, e, "getEnabledPhoneAccounts");
            Log.e(this, e, "getCallCapablePhoneAccounts");
            throw e;
        }
    }
@@ -205,7 +205,7 @@ public class TelecomServiceImpl extends ITelecomService.Stub {
    @Override
    public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
        try {
            return mPhoneAccountRegistrar.getEnabledPhoneAccounts(uriScheme);
            return mPhoneAccountRegistrar.getCallCapablePhoneAccounts(uriScheme);
        } catch (Exception e) {
            Log.e(this, e, "getPhoneAccountsSupportingScheme");
            throw e;
@@ -294,24 +294,7 @@ public class TelecomServiceImpl extends ITelecomService.Stub {
                enforceRegisterProviderOrSubscriptionPermission();
            }

            // If the account is marked as enabled or has CAPABILITY_ALWAYS_ENABLED set, check to
            // ensure the caller has modify permission.  If they do not, set the account to be
            // disabled and remove CAPABILITY_ALWAYS_ENABLED.
            if (account.isEnabled() ||
                    account.hasCapabilities(PhoneAccount.CAPABILITY_ALWAYS_ENABLED)) {
                try {
            enforceModifyPermission();
                } catch (SecurityException e) {
                    // Caller does not have modify permission, so change account to disabled by
                    // default and remove the CAPABILITY_ALWAYS_ENABLED capability.
                    int capabilities = account.getCapabilities() &
                            ~PhoneAccount.CAPABILITY_ALWAYS_ENABLED;
                    account = account.toBuilder()
                            .setEnabled(false)
                            .setCapabilities(capabilities)
                            .build();
                }
            }

            mPhoneAccountRegistrar.registerPhoneAccount(account);
        } catch (Exception e) {
@@ -320,17 +303,6 @@ public class TelecomServiceImpl extends ITelecomService.Stub {
        }
    }

    @Override
    public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) {
        try {
            enforceModifyPermission();
            mPhoneAccountRegistrar.setPhoneAccountEnabled(account, isEnabled);
        } catch (Exception e) {
            Log.e(this, e, "setPhoneAccountEnabled %s %d", account, isEnabled ? 1 : 0);
            throw e;
        }
    }

    @Override
    public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
        try {
+1 −1
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ public class CallServiceNotifier {
    public void showAllPhoneAccounts(Context context) {
        TelecomManager telecomManager =
                (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
        List<PhoneAccountHandle> accounts = telecomManager.getEnabledPhoneAccounts();
        List<PhoneAccountHandle> accounts = telecomManager.getCallCapablePhoneAccounts();

        Toast.makeText(context, accounts.toString(), Toast.LENGTH_LONG).show();
    }
Loading