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

Commit 53039cc4 authored by Pranav Madapurmath's avatar Pranav Madapurmath Committed by Android (Google) Code Review
Browse files

Merge "Make Telecom CallRedirectionService work-profile aware."

parents b2bfc9e2 3b3e81ce
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -364,7 +364,7 @@ public class NewOutgoingCallIntentBroadcaster {
            callRedirectionWithService = callRedirectionProcessor
                    .canMakeCallRedirectionWithService();
            if (callRedirectionWithService) {
                callRedirectionProcessor.performCallRedirection();
                callRedirectionProcessor.performCallRedirection(mCall.getInitiatingUser());
            }
        }

+13 −11
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class CallRedirectionProcessor implements CallRedirectionCallback {
            mServiceType = serviceType;
        }

        private void process() {
        private void process(UserHandle userHandleForCallRedirection) {
            Intent intent = new Intent(CallRedirectionService.SERVICE_INTERFACE)
                    .setComponent(mComponentName);
            ServiceConnection connection = new CallRedirectionServiceConnection();
@@ -83,7 +83,7 @@ public class CallRedirectionProcessor implements CallRedirectionCallback {
                    connection,
                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                    | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS,
                    UserHandle.CURRENT)) {
                    userHandleForCallRedirection)) {
                Log.d(this, "bindService, found " + mServiceType + " call redirection service,"
                        + " waiting for it to connect");
                mConnection = connection;
@@ -327,7 +327,8 @@ public class CallRedirectionProcessor implements CallRedirectionCallback {
                                mPhoneAccountHandle, mRedirectionGatewayInfo, mSpeakerphoneOn,
                                mVideoState, mShouldCancelCall, mUiAction);
                    } else {
                        performCarrierCallRedirection();
                        // Use the current user for carrier call redirection
                        performCarrierCallRedirection(UserHandle.CURRENT);
                    }
                } else if (mIsCarrierRedirectionPending) {
                    Log.addEvent(mCall, LogUtils.Events.REDIRECTION_COMPLETED_CARRIER);
@@ -343,39 +344,40 @@ public class CallRedirectionProcessor implements CallRedirectionCallback {
    /**
     * The entry to perform call redirection of the call from (@link CallsManager)
     */
    public void performCallRedirection() {
    public void performCallRedirection(UserHandle userHandleForCallRedirection) {
        // If the Gateway Info is set with intent, only request with carrier call redirection.
        if (mRedirectionGatewayInfo != null) {
            performCarrierCallRedirection();
            // Use the current user for carrier call redirection
            performCarrierCallRedirection(UserHandle.CURRENT);
        } else {
            performUserDefinedCallRedirection();
            performUserDefinedCallRedirection(userHandleForCallRedirection);
        }
    }

    private void performUserDefinedCallRedirection() {
    private void performUserDefinedCallRedirection(UserHandle userHandleForCallRedirection) {
        Log.d(this, "performUserDefinedCallRedirection");
        ComponentName componentName =
                mCallRedirectionProcessorHelper.getUserDefinedCallRedirectionService();
        if (componentName != null) {
            mAttempt = new CallRedirectionAttempt(componentName, SERVICE_TYPE_USER_DEFINED);
            mAttempt.process();
            mAttempt.process(userHandleForCallRedirection);
            mIsUserDefinedRedirectionPending = true;
            processTimeoutForCallRedirection(SERVICE_TYPE_USER_DEFINED);
        } else {
            Log.i(this, "There are no user-defined call redirection services installed on this"
                    + " device.");
            performCarrierCallRedirection();
            performCarrierCallRedirection(UserHandle.CURRENT);
        }
    }

    private void performCarrierCallRedirection() {
    private void performCarrierCallRedirection(UserHandle userHandleForCallRedirection) {
        Log.d(this, "performCarrierCallRedirection");
        ComponentName componentName =
                mCallRedirectionProcessorHelper.getCarrierCallRedirectionService(
                        mPhoneAccountHandle);
        if (componentName != null) {
            mAttempt = new CallRedirectionAttempt(componentName, SERVICE_TYPE_CARRIER);
            mAttempt.process();
            mAttempt.process(userHandleForCallRedirection);
            mIsCarrierRedirectionPending = true;
            processTimeoutForCallRedirection(SERVICE_TYPE_CARRIER);
        } else {
+12 −12
Original line number Diff line number Diff line
@@ -193,9 +193,9 @@ public class CallRedirectionProcessorTest extends TelecomTestCase {
        startProcessWithNoGateWayInfo();
        disableUserDefinedCallRedirectionService();
        disableCarrierCallRedirectionService();
        mProcessor.performCallRedirection();
        mProcessor.performCallRedirection(UserHandle.CURRENT);
        verify(mContext, times(0)).bindServiceAsUser(any(Intent.class),
                any(ServiceConnection.class), anyInt(), any(UserHandle.class));
                any(ServiceConnection.class), anyInt(), eq(UserHandle.CURRENT));
        verify(mCallsManager, times(1)).onCallRedirectionComplete(eq(mCall), eq(mHandle),
                eq(mPhoneAccountHandle), eq(null), eq(SPEAKER_PHONE_ON), eq(VIDEO_STATE),
                eq(false), eq(CallRedirectionProcessor.UI_TYPE_NO_ACTION));
@@ -208,9 +208,9 @@ public class CallRedirectionProcessorTest extends TelecomTestCase {
        waitForHandlerAction(mProcessor.getHandler(), HANDLER_TIMEOUT_DELAY);
        disableUserDefinedCallRedirectionService();
        enableCarrierCallRedirectionService();
        mProcessor.performCallRedirection();
        mProcessor.performCallRedirection(UserHandle.CURRENT);
        verify(mContext, times(1)).bindServiceAsUser(any(Intent.class),
                any(ServiceConnection.class), anyInt(), any(UserHandle.class));
                any(ServiceConnection.class), anyInt(), eq(UserHandle.CURRENT));
        verify(mCallsManager, times(0)).onCallRedirectionComplete(eq(mCall), any(),
                eq(mPhoneAccountHandle), eq(null), eq(SPEAKER_PHONE_ON), eq(VIDEO_STATE),
                eq(false), eq(CallRedirectionProcessor.UI_TYPE_NO_ACTION));
@@ -228,9 +228,9 @@ public class CallRedirectionProcessorTest extends TelecomTestCase {
        waitForHandlerAction(mProcessor.getHandler(), HANDLER_TIMEOUT_DELAY);
        enableUserDefinedCallRedirectionService();
        disableCarrierCallRedirectionService();
        mProcessor.performCallRedirection();
        mProcessor.performCallRedirection(UserHandle.CURRENT);
        verify(mContext, times(1)).bindServiceAsUser(any(Intent.class),
                any(ServiceConnection.class), anyInt(), any(UserHandle.class));
                any(ServiceConnection.class), anyInt(), eq(UserHandle.CURRENT));
        verify(mCallsManager, times(0)).onCallRedirectionComplete(eq(mCall), any(),
                eq(mPhoneAccountHandle), eq(null), eq(SPEAKER_PHONE_ON), eq(VIDEO_STATE),
                eq(false), eq(CallRedirectionProcessor.UI_TYPE_USER_DEFINED_TIMEOUT));
@@ -256,10 +256,10 @@ public class CallRedirectionProcessorTest extends TelecomTestCase {
        waitForHandlerAction(mProcessor.getHandler(), HANDLER_TIMEOUT_DELAY);
        enableUserDefinedCallRedirectionService();
        enableCarrierCallRedirectionService();
        mProcessor.performCallRedirection();
        mProcessor.performCallRedirection(UserHandle.CURRENT);

        verify(mContext, times(1)).bindServiceAsUser(any(Intent.class),
                any(ServiceConnection.class), anyInt(), any(UserHandle.class));
                any(ServiceConnection.class), anyInt(), eq(UserHandle.CURRENT));
        verify(mCallsManager, times(0)).onCallRedirectionComplete(eq(mCall), any(),
                eq(mPhoneAccountHandle), eq(null), eq(SPEAKER_PHONE_ON), eq(VIDEO_STATE),
                eq(false), eq(CallRedirectionProcessor.UI_TYPE_USER_DEFINED_TIMEOUT));
@@ -294,9 +294,9 @@ public class CallRedirectionProcessorTest extends TelecomTestCase {
        startProcessWithGateWayInfo();
        enableUserDefinedCallRedirectionService();
        enableCarrierCallRedirectionService();
        mProcessor.performCallRedirection();
        mProcessor.performCallRedirection(UserHandle.CURRENT);
        verify(mContext, times(1)).bindServiceAsUser(any(Intent.class),
                any(ServiceConnection.class), anyInt(), any(UserHandle.class));
                any(ServiceConnection.class), anyInt(), eq(UserHandle.CURRENT));
        verify(mCallsManager, times(0)).onCallRedirectionComplete(eq(mCall), any(),
                eq(mPhoneAccountHandle), eq(null), eq(SPEAKER_PHONE_ON), eq(VIDEO_STATE),
                eq(false), eq(CallRedirectionProcessor.UI_TYPE_NO_ACTION));
@@ -313,13 +313,13 @@ public class CallRedirectionProcessorTest extends TelecomTestCase {
        enableUserDefinedCallRedirectionService();
        disableCarrierCallRedirectionService();

        mProcessor.performCallRedirection();
        mProcessor.performCallRedirection(UserHandle.CURRENT);

        // Capture binding and mock it out.
        ArgumentCaptor<ServiceConnection> serviceConnectionCaptor = ArgumentCaptor.forClass(
                ServiceConnection.class);
        verify(mContext, times(1)).bindServiceAsUser(any(Intent.class),
                serviceConnectionCaptor.capture(), anyInt(), any(UserHandle.class));
                serviceConnectionCaptor.capture(), anyInt(), eq(UserHandle.CURRENT));

        // Mock out a service which performed a redirection
        IBinder mockBinder = mock(IBinder.class);