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

Commit 1c5926fc authored by Nancy Chen's avatar Nancy Chen
Browse files

Replace get*PhoneAccounts* public API methods with new method (2/3)

Hide getCallCapablePhoneAccounts and getPhoneAccountsSupportingScheme
because a third party app should not be able to see all phone accounts
registered. Replace instead with getPhoneAccountsForPackage(Context)
which will only return the phone accounts registered by a particular package.
Also pass available phone accounts for the user to select from through
Telecom to InCallUI so InCallUI will not be calling the Telecom API
directly to get these accounts.

Bug: 17510811

Change-Id: Ia91972bc4cfa938b743f6b3b165a81d4acd58c45
parent ce1a21ef
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ package com.android.server.telecom;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import android.os.Parcelable;
import android.provider.CallLog.Calls;
import android.telecom.AudioState;
import android.telecom.CallState;
@@ -337,12 +337,25 @@ public final class CallsManager extends Call.ListenerBase {
     * @param extras The optional extras Bundle passed with the intent used for the incoming call.
     */
    Call startOutgoingCall(Uri handle, PhoneAccountHandle phoneAccountHandle, Bundle extras) {
        // Create a call with original handle. The handle may be changed when the call is attached
        // to a connection service, but in most cases will remain the same.
        Call call = new Call(
                mContext,
                mConnectionServiceRepository,
                handle,
                null /* gatewayInfo */,
                null /* connectionManagerPhoneAccount */,
                null /* phoneAccountHandle */,
                false /* isIncoming */,
                false /* isConference */);

        List<PhoneAccountHandle> accounts =
                mPhoneAccountRegistrar.getCallCapablePhoneAccounts(handle.getScheme());

        // Only dial with the requested phoneAccount if it is still valid. Otherwise treat this call
        // 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> accounts =
                    mPhoneAccountRegistrar.getCallCapablePhoneAccounts(handle.getScheme());
            if (!accounts.contains(phoneAccountHandle)) {
                phoneAccountHandle = null;
            }
@@ -359,18 +372,7 @@ public final class CallsManager extends Call.ListenerBase {
            }
        }

        // Create a call with original handle. The handle may be changed when the call is attached
        // to a connection service, but in most cases will remain the same.
        Call call = new Call(
                mContext,
                mConnectionServiceRepository,
                handle,
                null /* gatewayInfo */,
                null /* connectionManagerPhoneAccount */,
                phoneAccountHandle,
                false /* isIncoming */,
                false /* isConference */);
        call.setExtras(extras);
        call.setTargetPhoneAccount(phoneAccountHandle);

        boolean isEmergencyCall = TelephonyUtil.shouldProcessAsEmergency(mContext,
                call.getHandle());
@@ -385,10 +387,13 @@ public final class CallsManager extends Call.ListenerBase {
        if (phoneAccountHandle == null && !isEmergencyCall) {
            // This is the state where the user is expected to select an account
            call.setState(CallState.PRE_DIAL_WAIT);
            extras.putParcelableList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS, accounts);
        } else {
            call.setState(CallState.CONNECTING);
        }

        call.setExtras(extras);

        if (!isPotentialMMICode(handle)) {
            addCall(call);
        } else {
+18 −0
Original line number Diff line number Diff line
@@ -302,6 +302,24 @@ public final class PhoneAccountRegistrar {
        return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER, uriScheme);
    }

    /**
     * Retrieves a list of all phone accounts registered by a specified package.
     *
     * @param packageName The name of the package that registered the phone accounts.
     * @return The phone account handles.
     */
    public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) {
        List<PhoneAccountHandle> accountHandles = new ArrayList<>();
        for (PhoneAccount m : mState.accounts) {
            if (Objects.equals(
                    packageName,
                    m.getAccountHandle().getComponentName().getPackageName())) {
                accountHandles.add(m.getAccountHandle());
            }
        }
        return accountHandles;
    }

    /**
     * Retrieves a list of all phone account handles with the connection manager capability.
     *
+10 −0
Original line number Diff line number Diff line
@@ -203,6 +203,16 @@ public class TelecomServiceImpl extends ITelecomService.Stub {
        }
    }

    @Override
    public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) {
        try {
            return mPhoneAccountRegistrar.getPhoneAccountsForPackage(packageName);
        } catch (Exception e) {
            Log.e(this, e, "getPhoneAccountsForPackage");
            throw e;
        }
    }

    @Override
    public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle) {
        try {