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

Commit 32f312ef authored by Thomas Stuart's avatar Thomas Stuart
Browse files

remove setCallIsSuppressedByDoNotDisturb in Ringer#shouldRingForContact

Dialer crashed due to a duplicate key exception. Upon inspection, the
call objects extras should not be manipulated in the Ringer class. Since
the call objects extras are already being set in
CallsManager#onCallFilteringComplete, the setter in shouldRingForContact
can be removed. This will eliminate any duplicate key bug.

Fixes: 279654232
Test:  manual tests (dnd off user alerted, dnd on call suppressed)
       testShouldRingForContact_CallShouldRing,
       testShouldRingForContact_CallSuppressed,
       testShouldRingForContact_matchesCallFilterIsAlreadyComputed
Change-Id: Ic30bbb15626bef43d0626f51d8f2b32737ca78df
parent 390a9d13
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -626,10 +626,9 @@ public class Ringer {
    public boolean shouldRingForContact(Call call) {
        // avoid re-computing manager.matcherCallFilter(Bundle)
        if (call.wasDndCheckComputedForCall()) {
            Log.v(this, "shouldRingForContact: returning computation from DndCallFilter.");
            Log.i(this, "shouldRingForContact: returning computation from DndCallFilter.");
            return !call.isCallSuppressedByDoNotDisturb();
        }

        final Uri contactUri = call.getHandle();
        final Bundle peopleExtras = new Bundle();
        if (contactUri != null) {
@@ -637,13 +636,7 @@ public class Ringer {
            personList.add(new Person.Builder().setUri(contactUri.toString()).build());
            peopleExtras.putParcelableArrayList(Notification.EXTRA_PEOPLE_LIST, personList);
        }

        // query NotificationManager
        boolean shouldRing = mNotificationManager.matchesCallFilter(peopleExtras);
        // store the suppressed status in the call object
        call.setCallIsSuppressedByDoNotDisturb(!shouldRing);

        return shouldRing;
        return mNotificationManager.matchesCallFilter(peopleExtras);
    }

    private boolean hasExternalRinger(Call foregroundCall) {
+38 −15
Original line number Diff line number Diff line
@@ -435,42 +435,65 @@ public class RingerTest extends TelecomTestCase {
    }

    /**
     * assert {@link Ringer#shouldRingForContact(Call, Context) } sets the Call object with suppress
     * caller
     *
     * @throws Exception; should not throw exception.
     * test shouldRingForContact will suppress the incoming call if matchesCallFilter returns
     * false (meaning DND is ON and the caller cannot bypass the settings)
     */
    @Test
    public void testShouldRingForContact_CallSuppressed() throws Exception {
    public void testShouldRingForContact_CallSuppressed() {
        // WHEN
        when(mockCall1.wasDndCheckComputedForCall()).thenReturn(false);
        when(mockCall1.getHandle()).thenReturn(Uri.parse(""));

        when(mContext.getSystemService(NotificationManager.class)).thenReturn(
                mockNotificationManager);
        // suppress the call
        when(mockNotificationManager.matchesCallFilter(any(Bundle.class))).thenReturn(false);

        // THEN
        // run the method under test
        assertFalse(mRingerUnderTest.shouldRingForContact(mockCall1));
        verify(mockCall1, atLeastOnce()).setCallIsSuppressedByDoNotDisturb(true);

        // THEN
        // verify we never set the call object and matchesCallFilter is called
        verify(mockCall1, never()).setCallIsSuppressedByDoNotDisturb(true);
        verify(mockNotificationManager, times(1))
                .matchesCallFilter(any(Bundle.class));
    }

    /**
     * assert {@link Ringer#shouldRingForContact(Call, Context) } sets the Call object with ring
     * caller
     *
     * @throws Exception; should not throw exception.
     * test shouldRingForContact will alert the user of an incoming call if matchesCallFilter
     * returns true (meaning DND is NOT suppressing the caller)
     */
    @Test
    public void testShouldRingForContact_CallShouldRing() throws Exception {
    public void testShouldRingForContact_CallShouldRing() {
        // WHEN
        when(mockCall1.wasDndCheckComputedForCall()).thenReturn(false);
        when(mockCall1.getHandle()).thenReturn(Uri.parse(""));
        // alert the user of the call
        when(mockNotificationManager.matchesCallFilter(any(Bundle.class))).thenReturn(true);

        // THEN
        // run the method under test
        assertTrue(mRingerUnderTest.shouldRingForContact(mockCall1));
        verify(mockCall1, atLeastOnce()).setCallIsSuppressedByDoNotDisturb(false);

        // THEN
        // verify we never set the call object and matchesCallFilter is called
        verify(mockCall1, never()).setCallIsSuppressedByDoNotDisturb(false);
        verify(mockNotificationManager, times(1))
                .matchesCallFilter(any(Bundle.class));
    }

    /**
     * ensure Telecom does not re-query the NotificationManager if the call object already has
     * the result.
     */
    @Test
    public void testShouldRingForContact_matchesCallFilterIsAlreadyComputed() {
        // WHEN
        when(mockCall1.wasDndCheckComputedForCall()).thenReturn(true);
        when(mockCall1.isCallSuppressedByDoNotDisturb()).thenReturn(true);

        // THEN
        assertFalse(mRingerUnderTest.shouldRingForContact(mockCall1));
        verify(mockCall1, never()).setCallIsSuppressedByDoNotDisturb(false);
        verify(mockNotificationManager, never()).matchesCallFilter(any(Bundle.class));
    }

    @Test