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

Commit 3d0357ff authored by Pranav Madapurmath's avatar Pranav Madapurmath Committed by Automerger Merge Worker
Browse files

Merge "Fix secondary user unable to access in-call screen" into udc-dev am:...

Merge "Fix secondary user unable to access in-call screen" into udc-dev am: 2f070090 am: d261bdec

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/services/Telecomm/+/22572812



Change-Id: I28dd257f1fdf39cf3fd05fa2cf0c34b209b51ba4
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1d3c2447 d261bdec
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -336,6 +336,10 @@ public class InCallController extends CallsManagerListenerBase implements
            mIsConnected = true;
            mInCallServiceInfo.setBindingStartTime(mClockProxy.elapsedRealtime());
            UserHandle userToBind = getUserFromCall(call);
            boolean isManagedProfile = UserUtil.isManagedProfile(mContext, userToBind);
            // Note that UserHandle.CURRENT fails to capture the work profile, so we need to handle
            // it separately to ensure that the ICS is bound to the appropriate user.
            userToBind = isManagedProfile ? userToBind : UserHandle.CURRENT;
            if (!mContext.bindServiceAsUser(intent, mServiceConnection,
                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS
+27 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.compat.testing.PlatformCompatChangeRule;
import android.net.Uri;
@@ -152,6 +153,7 @@ public class InCallControllerTests extends TelecomTestCase {
    @Mock InCallController.InCallServiceInfo mInCallServiceInfo;
    @Mock private AnomalyReporterAdapter mAnomalyReporterAdapter;
    @Mock UserManager mMockUserManager;
    @Mock UserInfo mMockUserInfo;

    @Rule
    public TestRule compatChangeRule = new PlatformCompatChangeRule();
@@ -292,6 +294,11 @@ public class InCallControllerTests extends TelecomTestCase {
                .thenReturn(PackageManager.PERMISSION_DENIED);

        when(mMockCallsManager.getAudioState()).thenReturn(new CallAudioState(false, 0, 0));

        when(mMockContext.getSystemService(eq(Context.USER_SERVICE))).thenReturn(mMockUserManager);
        // Mock user info to allow binding on user stored in the phone account (mUserHandle).
        when(mMockUserManager.getUserInfo(anyInt())).thenReturn(mMockUserInfo);
        when(mMockUserInfo.isManagedProfile()).thenReturn(true);
    }

    @Override
@@ -1580,6 +1587,26 @@ public class InCallControllerTests extends TelecomTestCase {
                android.telecom.Call.EXTRA_IS_SUPPRESSED_BY_DO_NOT_DISTURB));
    }

    @Test
    public void testSecondaryUserCallBindToCurrentUser() throws Exception {
        setupMocks(true /* isExternalCall */);
        setupMockPackageManager(true /* default */, true /* system */, false /* external calls */);
        // Force the difference between the phone account user and current user. This is supposed to
        // simulate a secondary user placing a call over an unassociated sim.
        assertFalse(mUserHandle.equals(UserHandle.USER_CURRENT));
        when(mMockUserInfo.isManagedProfile()).thenReturn(false);

        mInCallController.bindToServices(mMockCall);

        // Bind InCallService on UserHandle.CURRENT and not the user from the call (mUserHandle)
        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                eq(serviceBindingFlags),
                eq(UserHandle.CURRENT));
    }

    private void setupMocks(boolean isExternalCall) {
        setupMocks(isExternalCall, false /* isSelfManagedCall */);
    }