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
diff --git a/src/com/android/server/telecom/Ringer.java b/src/com/android/server/telecom/Ringer.java
index cdacab0..45fb2af 100644
--- a/src/com/android/server/telecom/Ringer.java
+++ b/src/com/android/server/telecom/Ringer.java
@@ -626,10 +626,9 @@
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 @@
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) {
diff --git a/tests/src/com/android/server/telecom/tests/RingerTest.java b/tests/src/com/android/server/telecom/tests/RingerTest.java
index abbfe34..a02415c 100644
--- a/tests/src/com/android/server/telecom/tests/RingerTest.java
+++ b/tests/src/com/android/server/telecom/tests/RingerTest.java
@@ -435,42 +435,65 @@
}
/**
- * 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