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

Commit dc1770da authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix the system car mode ui type wrongly returned as nonUI type."

parents dd756b98 0cb985a9
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -1291,12 +1291,11 @@ public class InCallController extends CallsManagerListenerBase {
                serviceInfo.packageName) == PackageManager.PERMISSION_GRANTED;
        boolean isCarModeUIService = serviceInfo.metaData != null &&
                serviceInfo.metaData.getBoolean(
                        TelecomManager.METADATA_IN_CALL_SERVICE_CAR_MODE_UI, false) &&
                (hasControlInCallPermission || isThirdPartyCompanionApp);
                        TelecomManager.METADATA_IN_CALL_SERVICE_CAR_MODE_UI, false);
        if (isCarModeUIService) {
            // ThirdPartyInCallService shouldn't be used when role manager hasn't assigned any car
            // mode role holders, i.e. packageName is null.
            if (isUIService || (isThirdPartyCompanionApp && packageName != null)) {
            if (hasControlInCallPermission || (isThirdPartyCompanionApp && packageName != null)) {
                return IN_CALL_SERVICE_TYPE_CAR_MODE_UI;
            }
        }
@@ -1311,7 +1310,7 @@ public class InCallController extends CallsManagerListenerBase {

        // Also allow any in-call service that has the control-experience permission (to ensure
        // that it is a system app) and doesn't claim to show any UI.
        if (!isUIService) {
        if (!isUIService && !isCarModeUIService) {
            if (hasControlInCallPermission && !isThirdPartyCompanionApp) {
                return IN_CALL_SERVICE_TYPE_NON_UI;
            }
+44 −0
Original line number Diff line number Diff line
@@ -604,12 +604,56 @@ public class InCallControllerTests extends TelecomTestCase {
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
                eq(UserHandle.CURRENT));
        // Verify bind car mode ui
        assertEquals(1, bindIntentCaptor.getAllValues().size());
        Intent bindIntent = bindIntentCaptor.getAllValues().get(0);
        assertEquals(InCallService.SERVICE_INTERFACE, bindIntent.getAction());
        assertEquals(CAR_PKG, bindIntent.getComponent().getPackageName());
        assertEquals(CAR_CLASS, bindIntent.getComponent().getClassName());
    }

    @MediumTest
    @Test
    public void testNoBindToInvalidService_CarModeUI() throws Exception {
        setupMocks(true /* isExternalCall */);
        setupMockPackageManager(true /* default */, true /* system */, true /* external calls */);

        when(mMockRoleManagerAdapter.getCarModeDialerApp()).thenReturn(CAR_PKG);
        when(mMockPackageManager.checkPermission(
                matches(Manifest.permission.CALL_COMPANION_APP),
                matches(CAR_PKG))).thenReturn(PackageManager.PERMISSION_DENIED);
        // Enable car mode
        when(mMockSystemStateHelper.isCarMode()).thenReturn(true);
        mInCallController.bindToServices(mMockCall);

        // Query for the different InCallServices
        ArgumentCaptor<Intent> queryIntentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mMockPackageManager, times(4)).queryIntentServicesAsUser(
                queryIntentCaptor.capture(),
                eq(PackageManager.GET_META_DATA), eq(CURRENT_USER_ID));
        // Verify call for default dialer InCallService
        assertEquals(DEF_PKG, queryIntentCaptor.getAllValues().get(0).getPackage());
        // Verify call for system dialer InCallService
        assertEquals(null, queryIntentCaptor.getAllValues().get(1).getPackage());
        // Verify call for invalid car mode ui InCallServices
        assertEquals(CAR_PKG, queryIntentCaptor.getAllValues().get(2).getPackage());
        // Verify call for non-UI InCallServices
        assertEquals(null, queryIntentCaptor.getAllValues().get(3).getPackage());

        // Bind InCallServices
        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mMockContext, times(1)).bindServiceAsUser(
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE),
                eq(UserHandle.CURRENT));
        // Verify bind to default package, instead of the invalid car mode ui.
        assertEquals(1, bindIntentCaptor.getAllValues().size());
        Intent bindIntent = bindIntentCaptor.getAllValues().get(0);
        assertEquals(InCallService.SERVICE_INTERFACE, bindIntent.getAction());
        assertEquals(DEF_PKG, bindIntent.getComponent().getPackageName());
        assertEquals(DEF_CLASS, bindIntent.getComponent().getClassName());
    }

    private void setupMocks(boolean isExternalCall) {
        when(mMockCallsManager.getCurrentUserHandle()).thenReturn(mUserHandle);
        when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);