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

Commit 8071bf41 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Update RoleManagerAdapter to be Work-Profile aware

Currently, RoleManagerAdapter gets the default app names redirection and
screening by looking at the primary user. We also bind to the CallScreening service as the primary user. Instead, we should be grabbing the appropriate user from the call (namely, from the account handle).

There is also an issue placing MO calls from work sims which is tied to
the call redirection flow. The phone account being used for the call is
checked against the CallManager's current user, which is always the
system. This results in calls ending up in the disconnected state.

Bug: 256241185
Bug: 263303152
Test: Unit tests, Manual
Change-Id: I7bbbe6e447dad3640f83e0de3bd6b48ae66b0a85
parent b9694ff9
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -212,8 +212,9 @@ public class CallScreeningServiceHelper {
                serviceConnection,
                Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                | Context.BIND_SCHEDULE_LIKE_TOP_APP,
                UserHandle.CURRENT)) {
            Log.d(TAG, "bindService, found service, waiting for it to connect");
                userHandle)) {
            Log.d(TAG,"bindServiceAsUser, found service,"
                    + "waiting for it to connect to user: %s", userHandle);
            return true;
        }

+25 −9
Original line number Diff line number Diff line
@@ -651,9 +651,11 @@ public class CallsManager extends Call.ListenerBase
    }

    @Override
    @VisibleForTesting
    public void onSuccessfulOutgoingCall(Call call, int callState) {
        Log.v(this, "onSuccessfulOutgoingCall, %s", call);
        call.setPostCallPackageName(getRoleManagerAdapter().getDefaultCallScreeningApp());
        call.setPostCallPackageName(getRoleManagerAdapter().getDefaultCallScreeningApp(
                call.getUserHandleFromTargetPhoneAccount()));

        setCallState(call, callState, "successful outgoing call");
        if (!mCalls.contains(call)) {
@@ -718,8 +720,11 @@ public class CallsManager extends Call.ListenerBase
    private IncomingCallFilterGraph setUpCallFilterGraph(Call incomingCall) {
        incomingCall.setIsUsingCallFiltering(true);
        String carrierPackageName = getCarrierPackageName();
        String defaultDialerPackageName = TelecomManager.from(mContext).getDefaultDialerPackage();
        String userChosenPackageName = getRoleManagerAdapter().getDefaultCallScreeningApp();
        UserHandle userHandle = incomingCall.getUserHandleFromTargetPhoneAccount();
        String defaultDialerPackageName = TelecomManager.from(mContext).
                getDefaultDialerPackage(userHandle);
        String userChosenPackageName = getRoleManagerAdapter().
                getDefaultCallScreeningApp(userHandle);
        AppLabelProxy appLabelProxy = packageName -> AppLabelProxy.Util.getAppLabel(
                mContext.getPackageManager(), packageName);
        ParcelableCallUtils.Converter converter = new ParcelableCallUtils.Converter();
@@ -834,7 +839,9 @@ public class CallsManager extends Call.ListenerBase

        if (result.shouldAllowCall) {
            incomingCall.setPostCallPackageName(
                    getRoleManagerAdapter().getDefaultCallScreeningApp());
                    getRoleManagerAdapter().getDefaultCallScreeningApp(
                            incomingCall.getUserHandleFromTargetPhoneAccount()
                    ));

            Log.i(this, "onCallFilteringComplete: allow call.");
            if (hasMaximumManagedRingingCalls(incomingCall)) {
@@ -1880,6 +1887,8 @@ public class CallsManager extends Call.ListenerBase
            dialerSelectPhoneAccountFuture.thenAcceptBothAsync(contactLookupFuture,
                    (callPhoneAccountHandlePair, uriCallerInfoPair) -> {
                        Call theCall = callPhoneAccountHandlePair.first;
                        UserHandle userHandleForCallScreening = theCall.
                                getUserHandleFromTargetPhoneAccount();
                        boolean isInContacts = uriCallerInfoPair.second != null
                                && uriCallerInfoPair.second.contactExists;
                        Log.d(CallsManager.this, "outgoingCallIdStage: isInContacts=%s",
@@ -1890,10 +1899,12 @@ public class CallsManager extends Call.ListenerBase
                        PackageManager packageManager = mContext.getPackageManager();
                        int permission = packageManager.checkPermission(
                                Manifest.permission.READ_CONTACTS,
                                mRoleManagerAdapter.getDefaultCallScreeningApp());
                                mRoleManagerAdapter.
                                        getDefaultCallScreeningApp(userHandleForCallScreening));
                        Log.d(CallsManager.this,
                                "default call screening service package %s has permissions=%s",
                                mRoleManagerAdapter.getDefaultCallScreeningApp(),
                                mRoleManagerAdapter.
                                        getDefaultCallScreeningApp(userHandleForCallScreening),
                                permission == PackageManager.PERMISSION_GRANTED);
                        if ((!isInContacts) || (permission == PackageManager.PERMISSION_GRANTED)) {
                            bindForOutgoingCallerId(theCall);
@@ -2004,7 +2015,8 @@ public class CallsManager extends Call.ListenerBase
    private void bindForOutgoingCallerId(Call theCall) {
        // Find the user chosen call screening app.
        String callScreeningApp =
                mRoleManagerAdapter.getDefaultCallScreeningApp();
                mRoleManagerAdapter.getDefaultCallScreeningApp(
                        theCall.getUserHandleFromTargetPhoneAccount());

        CompletableFuture future =
                new CallScreeningServiceHelper(mContext,
@@ -2160,14 +2172,18 @@ public class CallsManager extends Call.ListenerBase

        boolean endEarly = false;
        String disconnectReason = "";
        String callRedirectionApp = mRoleManagerAdapter.getDefaultCallRedirectionApp();
        String callRedirectionApp = mRoleManagerAdapter.getDefaultCallRedirectionApp(
                phoneAccountHandle.getUserHandle());
        PhoneAccount phoneAccount = mPhoneAccountRegistrar
                .getPhoneAccountUnchecked(phoneAccountHandle);
        if (phoneAccount != null
                && !phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_MULTI_USER)) {
            // Note that mCurrentUserHandle may not actually be the current user, i.e.
            // in the case of work profiles
            UserHandle currentUserHandle = call.getUserHandleFromTargetPhoneAccount();
            // Check if the phoneAccountHandle belongs to the current user
            if (phoneAccountHandle != null &&
                    !phoneAccountHandle.getUserHandle().equals(mCurrentUserHandle)) {
                    !phoneAccountHandle.getUserHandle().equals(currentUserHandle)) {
                phoneAccountHandle = null;
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -372,7 +372,7 @@ public class NewOutgoingCallIntentBroadcaster {
             * broadcasting.
             */
            callRedirectionWithService = callRedirectionProcessor
                    .canMakeCallRedirectionWithService();
                    .canMakeCallRedirectionWithServiceAsUser(mCall.getInitiatingUser());
            if (callRedirectionWithService) {
                callRedirectionProcessor.performCallRedirection(mCall.getInitiatingUser());
            }
+2 −2
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ public interface RoleManagerAdapter {
     * redirection role.
     * @return the package name of the app filling the role, {@code null} otherwise}.
     */
    String getDefaultCallRedirectionApp();
    String getDefaultCallRedirectionApp(UserHandle userHandle);

    /**
     * Override the {@link android.app.role.RoleManager} call redirection app with another value.
@@ -56,7 +56,7 @@ public interface RoleManagerAdapter {
     * screening role.
     * @return the package name of the app filling the role, {@code null} otherwise}.
     */
    String getDefaultCallScreeningApp();
    String getDefaultCallScreeningApp(UserHandle userHandle);

    /**
     * Override the {@link android.app.role.RoleManager} call screening app with another value.
+11 −10
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.role.RoleManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.UserHandle;
import android.telecom.Log;

@@ -50,11 +51,11 @@ public class RoleManagerAdapterImpl implements RoleManagerAdapter {
    }

    @Override
    public String getDefaultCallRedirectionApp() {
    public String getDefaultCallRedirectionApp(UserHandle userHandleForCallRedirection) {
        if (mOverrideDefaultCallRedirectionApp != null) {
            return mOverrideDefaultCallRedirectionApp;
        }
        return getRoleManagerCallRedirectionApp();
        return getRoleManagerCallRedirectionApp(userHandleForCallRedirection);
    }

    @Override
@@ -63,11 +64,11 @@ public class RoleManagerAdapterImpl implements RoleManagerAdapter {
    }

    @Override
    public String getDefaultCallScreeningApp() {
    public String getDefaultCallScreeningApp(UserHandle userHandleForCallScreening) {
        if (mOverrideDefaultCallScreeningApp != null) {
            return mOverrideDefaultCallScreeningApp;
        }
        return getRoleManagerCallScreeningApp();
        return getRoleManagerCallScreeningApp(userHandleForCallScreening);
    }

    @Override
@@ -118,9 +119,9 @@ public class RoleManagerAdapterImpl implements RoleManagerAdapter {
        mCurrentUserHandle = currentUserHandle;
    }

    private String getRoleManagerCallScreeningApp() {
    private String getRoleManagerCallScreeningApp(UserHandle userHandle) {
        List<String> roleHolders = mRoleManager.getRoleHoldersAsUser(ROLE_CALL_SCREENING,
                mCurrentUserHandle);
                userHandle);
        if (roleHolders == null || roleHolders.isEmpty()) {
            return null;
        }
@@ -141,9 +142,9 @@ public class RoleManagerAdapterImpl implements RoleManagerAdapter {
        return new ArrayList<>();
    }

    private String getRoleManagerCallRedirectionApp() {
    private String getRoleManagerCallRedirectionApp(UserHandle userHandle) {
        List<String> roleHolders = mRoleManager.getRoleHoldersAsUser(ROLE_CALL_REDIRECTION_APP,
                mCurrentUserHandle);
                userHandle);
        if (roleHolders == null || roleHolders.isEmpty()) {
            return null;
        }
@@ -184,7 +185,7 @@ public class RoleManagerAdapterImpl implements RoleManagerAdapter {
            pw.print("(override ");
            pw.print(mOverrideDefaultCallRedirectionApp);
            pw.print(") ");
            pw.print(getRoleManagerCallRedirectionApp());
            pw.print(getRoleManagerCallRedirectionApp(Binder.getCallingUserHandle()));
        }
        pw.println();

@@ -193,7 +194,7 @@ public class RoleManagerAdapterImpl implements RoleManagerAdapter {
            pw.print("(override ");
            pw.print(mOverrideDefaultCallScreeningApp);
            pw.print(") ");
            pw.print(getRoleManagerCallScreeningApp());
            pw.print(getRoleManagerCallScreeningApp(Binder.getCallingUserHandle()));
        }
        pw.println();

Loading