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

Commit 86d7d884 authored by Tyler Gunn's avatar Tyler Gunn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue with rebind to dialer on uninstall of app." into sc-dev

parents 5a0f908d e52128f5
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -622,6 +622,10 @@ public class InCallController extends CallsManagerListenerBase {
            }
        }

        public boolean isCarMode() {
            return mIsCarMode;
        }

        @Override
        public int connect(Call call) {
            if (mIsConnected) {
@@ -2048,13 +2052,18 @@ public class InCallController extends CallsManagerListenerBase {
                mCarModeTracker.getCarModeApps().stream().collect(Collectors.joining(", ")));
        if (mInCallServiceConnection != null) {
            if (shouldUseCarModeUI()) {
                Log.i(this, "updateCarModeForConnections: potentially update car mode app.");
                mInCallServiceConnection.changeCarModeApp(
                        mCarModeTracker.getCurrentCarModePackage());
            } else {
                if (mInCallServiceConnection.isCarMode()) {
                    Log.i(this, "updateCarModeForConnections: car mode no longer "
                            + "applicable; disabling");
                    mInCallServiceConnection.disableCarMode();
                }
            }
        }
    }

    /**
     * Tracks start of microphone use on binding to the current calling UX.
+46 −0
Original line number Diff line number Diff line
@@ -254,6 +254,27 @@ public class InCallControllerTests extends TelecomTestCase {
        assertFalse(mCarModeTracker.isInCarMode());
    }

    /**
     * Ensure that if we remove a random unrelated app we don't exit car mode.
     */
    @SmallTest
    @Test
    public void testRandomAppRemovalInCarMode() {
        setupMockPackageManager(true /* default */, true /* system */, true /* external calls */);
        when(mMockCallsManager.getCurrentUserHandle()).thenReturn(mUserHandle);
        when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);

        when(mMockSystemStateHelper.isCarModeOrProjectionActive()).thenReturn(true);

        mSystemStateListener.onCarModeChanged(666, CAR_PKG, true);
        verify(mCarModeTracker).handleEnterCarMode(666, CAR_PKG);
        assertTrue(mCarModeTracker.isInCarMode());

        mSystemStateListener.onPackageUninstalled("com.foo.test");
        verify(mCarModeTracker, never()).forceRemove(CAR_PKG);
        assertTrue(mCarModeTracker.isInCarMode());
    }

    @SmallTest
    @Test
    public void testAutomotiveProjectionAppRemoval() {
@@ -963,6 +984,31 @@ public class InCallControllerTests extends TelecomTestCase {
        assertTrue(TextUtils.isEmpty(parcelableCallCaptor.getValue().getContactDisplayName()));
    }

    /**
     * Ensures that the {@link InCallController} will bind to a higher priority car mode service
     * when one becomes available.
     */
    @MediumTest
    @Test
    public void testRandomAppRemovalWhenNotInCarMode() throws Exception {
        setupMocks(true /* isExternalCall */);
        setupMockPackageManager(true /* default */, true /* system */, true /* external calls */);
        // Bind to default dialer.
        mInCallController.bindToServices(mMockCall);

        // Uninstall an unrelated app.
        mSystemStateListener.onPackageUninstalled("com.joe.stuff");

        // Bind InCallServices, just once; we should not re-bind to the same app.
        ArgumentCaptor<Intent> bindIntentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mMockContext).bindServiceAsUser(
                bindIntentCaptor.capture(),
                any(ServiceConnection.class),
                eq(Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
                        | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS),
                eq(UserHandle.CURRENT));
    }

    /**
     * Ensures that the {@link InCallController} will bind to a higher priority car mode service
     * when one becomes available.