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

Commit 065ebfb9 authored by Grant Menke's avatar Grant Menke
Browse files

Prevent exit car mode from clearing projection entry.

When Telecom handles exiting car mode, we do not want to clear the automotive projection car mode app entry. This CL adds logic to prevent that and a unit test to confirm that SetAutomaotiveProjection overrides handleEnterCarMode on Telecom's side.

Bug: 268218294
Test: atest CarModeTrackerTest#testInterleaveCarModeAndProjectionMode
Change-Id: I0706b531b53223e8d6217d9a2ba2712cbc97e0e2
parent fec9fe98
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -150,7 +150,9 @@ public class CarModeTracker {
        Log.i(this, "handleExitCarMode: packageName=%s, priority=%d", packageName, priority);
        mCarModeChangeLog.log("exitCarMode: packageName=" + packageName + ", priority="
                + priority);
        mCarModeApps.removeIf(c -> c.getPriority() == priority);

        //Remove the car mode app with specified priority without clearing out the projection entry.
        mCarModeApps.removeIf(c -> c.getPriority() == priority && !c.hasSetAutomotiveProjection());
    }

    public void handleSetAutomotiveProjection(@NonNull String packageName) {
+22 −0
Original line number Diff line number Diff line
@@ -235,6 +235,28 @@ public class CarModeTrackerTest extends TelecomTestCase {
        assertTrue(mCarModeTracker.isInCarMode());
    }

    /**
     * Verifies that setting automotive projection overrides entering car mode with the highest
     * priority of 0. Also ensures exiting car mode doesn't interfere with the automotive
     * projection being set.
     */
    @Test
    public void testInterleaveCarModeAndProjectionMode() {
        mCarModeTracker.handleEnterCarMode(0, CAR_MODE_APP1_PACKAGE_NAME);
        assertEquals(CAR_MODE_APP1_PACKAGE_NAME, mCarModeTracker.getCurrentCarModePackage());
        assertTrue(mCarModeTracker.isInCarMode());

        mCarModeTracker.handleSetAutomotiveProjection(CAR_MODE_APP2_PACKAGE_NAME);
        assertEquals(CAR_MODE_APP2_PACKAGE_NAME, mCarModeTracker.getCurrentCarModePackage());
        assertTrue(mCarModeTracker.isInCarMode());

        mCarModeTracker.handleExitCarMode(0, CAR_MODE_APP1_PACKAGE_NAME);
        assertEquals(CAR_MODE_APP2_PACKAGE_NAME, mCarModeTracker.getCurrentCarModePackage());
        assertTrue(mCarModeTracker.isInCarMode());

        mCarModeTracker.handleReleaseAutomotiveProjection();
    }

    /**
     * Verifies that if we set automotive projection more than once with the same package, nothing
     * changes.