Checking for recent emergency call before deleting voiemail

Bug: 25818151
Change-Id: I6b8b5ebfe1c9555b8394ad7db652e23bbc216f83
diff --git a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
index 23ce8a8..e3870de 100644
--- a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
+++ b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
@@ -31,10 +31,6 @@
 import android.text.TextUtils;
 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;
 import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
@@ -44,6 +40,8 @@
 import com.android.dialer.logging.InteractionEvent;
 import com.android.dialer.logging.Logger;
 
+import java.util.concurrent.TimeUnit;
+
 /**
  * Utility to help with tasks related to filtered numbers.
  */
@@ -53,11 +51,11 @@
     private static final long RECENT_EMERGENCY_CALL_THRESHOLD_MS = 1000 * 60 * 60 * 24 * 2;
 
     // Pref key for storing the time of end of the last emergency call in milliseconds after epoch.
-    private static final String LAST_EMERGENCY_CALL_MS_PREF_KEY = "last_emergency_call_ms";
+    protected static final String LAST_EMERGENCY_CALL_MS_PREF_KEY = "last_emergency_call_ms";
 
     // Pref key for storing whether a notification has been dispatched to notify the user that call
     // blocking has been disabled because of a recent emergency call.
-    private static final String NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY =
+    protected static final String NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY =
             "notified_call_blocking_disabled_by_emergency_call";
 
     public static final String CALL_BLOCKING_NOTIFICATION_TAG = "call_blocking";
@@ -241,6 +239,10 @@
             return false;
         }
 
+        if (hasRecentEmergencyCall(context)) {
+            return false;
+        }
+
         final Cursor cursor = context.getContentResolver().query(
                 FilteredNumber.CONTENT_URI,
                 new String[] {
diff --git a/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java b/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java
index 180295c..ccd95ab 100644
--- a/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java
+++ b/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java
@@ -15,6 +15,7 @@
  */
 package com.android.dialer.filterednumber;
 
+import android.preference.PreferenceManager;
 import android.test.AndroidTestCase;
 
 import com.android.contacts.common.test.mocks.ContactsMockContext;
@@ -46,6 +47,12 @@
     public void setUp() throws Exception {
         super.setUp();
         mContext = new ContactsMockContext(getContext(), FilteredNumberContract.AUTHORITY);
+
+        // Reset whether an emergency number was dialed
+        PreferenceManager.getDefaultSharedPreferences(mContext)
+                .edit()
+                .putLong(FilteredNumbersUtil.LAST_EMERGENCY_CALL_MS_PREF_KEY, 0)
+                .apply();
     }
 
     public void testShouldBlockVoicemail_NotBlocked() {
@@ -78,6 +85,17 @@
                 COUNTRY_ISO, EARLIER_TIME + 30000));
     }
 
+    public void testShouldBlockVoicemail_AfterEmergencyCall() {
+        // Just called emergency services
+        PreferenceManager.getDefaultSharedPreferences(mContext)
+                .edit()
+                .putLong(FilteredNumbersUtil.LAST_EMERGENCY_CALL_MS_PREF_KEY,
+                        System.currentTimeMillis())
+                .apply();
+        assertFalse(FilteredNumbersUtil.shouldBlockVoicemail(mContext, NORMALIZED_NUMBER,
+                COUNTRY_ISO, 0));
+    }
+
     private void setupShouldBlockVoicemailQuery(long creationTimeMs) {
         Query query = mContext.getContactsProvider().expectQuery(FilteredNumber.CONTENT_URI)
                 .withProjection(FILTERED_NUMBER_PROJECTION)