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

Commit 2c1e608b authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Fix issue with rebind to dialer on uninstall of app.

Fixed issue where uninstall of a random app while not in car mode would
cause the dialer to disconnect and rebind.

Test: Manually tested by uninstalling an unrelated app and seeing
the problem manifest itself.  Applied fix and verified it no longer causes
a problem.
Test: Manually uninstalled active car mode app and ensured fallback to
dialer UX.
Test: Added two new unit tests for this.
Fixes: 174697155

Change-Id: Icd325615dd13ca622c0004d88c2c4b7c57b4152f
parent 5036ac10
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.