From 7d0a017b568ac0ca4133206872b503d4965e796e Mon Sep 17 00:00:00 2001 From: Brandon Maxwell Date: Wed, 11 Nov 2015 16:36:16 -0800 Subject: Blocking number suppresses voicemails in the same minute ~ Modified FilteredNumbersUtil to check if a voicemail needs to be blocked by checking if the voicemail date matches the block date to the minute, rather than millisecond ~ Modified FilteredNumbersUtil#shouldBlockVoicemail to improve readability + Added tests to verify FilteredNumbersUtil#shouldBlockVoicemail Bug: 25346075 Change-Id: I9851a574f0d13b7f09c99438810454770c88aa8b --- .../dialer/filterednumber/FilteredNumbersUtil.java | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java index 4cc8e7594..76d391357 100644 --- a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java +++ b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java @@ -35,6 +35,7 @@ import android.widget.Toast; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.TimeUnit; import com.android.contacts.common.testing.NeededForTesting; import com.android.dialer.R; @@ -247,21 +248,21 @@ public class FilteredNumbersUtil { FilteredNumberColumns.NORMALIZED_NUMBER + "=?", new String[] { normalizedNumber }, null); - - boolean shouldBlock = false; - if (cursor != null) { - try { - if (cursor.moveToFirst()) { - // Block if number is found and it was added before this voicemail was received. - final long numberBlockedTimeMs = cursor.getLong(0); - shouldBlock = cursor.getCount() > 0 && voicemailDateMs > numberBlockedTimeMs; - } - } finally { - cursor.close(); - } + if (cursor == null) { + return false; + } + try { + /* + * Block if number is found and it was added before this voicemail was received. + * The VVM's date is reported with precision to the minute, even though its + * magnitude is in milliseconds, so we perform the comparison in minutes. + */ + return cursor.moveToFirst() && + TimeUnit.MINUTES.convert(voicemailDateMs, TimeUnit.MILLISECONDS) >= + TimeUnit.MINUTES.convert(cursor.getLong(0), TimeUnit.MILLISECONDS); + } finally { + cursor.close(); } - - return shouldBlock; } public static boolean hasRecentEmergencyCall(Context context) { -- cgit v1.2.3