Loading src/com/android/server/telecom/Ringer.java +2 −9 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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) { Loading tests/src/com/android/server/telecom/tests/RingerTest.java +38 −15 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
src/com/android/server/telecom/Ringer.java +2 −9 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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) { Loading
tests/src/com/android/server/telecom/tests/RingerTest.java +38 −15 Original line number Diff line number Diff line Loading @@ -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 Loading