Disable call blocking after emergency call.

Will be disabled for 48 hours after an emergency call.

+ Add utility for noting last time of an emergency call.
+ Add utility for comparing current time to last time of an
emergency call.
+ If current time is within 48 hours of emergency call, display
text in settings explaining why call blocking is disabled.

Bug: 24418319
Change-Id: I6824340f04fae17b73f17843a9f6ef991afa0327
diff --git a/res/layout/blocked_number_fragment.xml b/res/layout/blocked_number_fragment.xml
index b98b58f..7aff06e 100644
--- a/res/layout/blocked_number_fragment.xml
+++ b/res/layout/blocked_number_fragment.xml
@@ -27,12 +27,4 @@
         android:divider="@null"
         android:headerDividersEnabled="false" />
 
-    <TextView android:id="@android:id/empty"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:paddingStart="@dimen/blocked_number_horizontal_margin"
-        android:paddingTop="@dimen/blocked_number_top_margin"
-        android:paddingBottom="@dimen/blocked_number_bottom_margin"
-        android:text="@string/listNoBlockedNumbers" />
-
 </LinearLayout>
diff --git a/res/layout/blocked_number_header.xml b/res/layout/blocked_number_header.xml
index 3fcdf39..ce1d4fe 100644
--- a/res/layout/blocked_number_header.xml
+++ b/res/layout/blocked_number_header.xml
@@ -19,6 +19,31 @@
     android:layout_height="wrap_content"
     android:orientation="vertical">
 
+    <LinearLayout android:id="@+id/blocked_numbers_disabled_for_emergency"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical"
+        android:layout_marginBottom="8dp"
+        android:padding="16dp"
+        android:visibility="gone">
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/blocked_numbers_disabled_emergency_header_label"
+            android:textStyle="bold"
+            android:textColor="@color/blocked_number_disabled_emergency_header_color"
+            style="@style/BlockedNumbersDescriptionTextStyle" />
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/blocked_numbers_disabled_emergency_desc"
+            style="@style/BlockedNumbersDescriptionTextStyle" />
+
+    </LinearLayout>
+
+
     <android.support.v7.widget.CardView
         android:id="@+id/hide_blocked_calls_setting"
         android:layout_width="match_parent"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index bf7bfb2..d8d0de4 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -132,6 +132,7 @@
     <color name="blocked_number_accent_color">#42A5F5</color>
     <color name="blocked_number_block_color">#F44336</color>
     <color name="blocked_number_header_color">@color/dialer_theme_color</color>
+    <color name="blocked_number_disabled_emergency_header_color">#616161</color>
 
     <!-- Colors for onboarding flow -->
     <color name="onboarding_primary_text_color">#ffffff</color>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9c70dd4..df8d0fa 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -826,6 +826,21 @@
     <!-- Label for the blocked numbers settings section [CHAR LIMIT=30] -->
     <string name="manage_blocked_numbers_label">Blocked numbers</string>
 
+    <!-- Label for a section describing that call blocking is temporarily disabled because an
+         emergency call was made. [CHAR LIMIT=40] -->
+    <string name="blocked_numbers_disabled_emergency_header_label">
+        Call blocking temporarily off
+    </string>
+
+    <!-- Description that call blocking is temporarily disabled because the user called an
+         emergency number, and explains that call blocking will be re-enabled after a buffer
+         period has passed. [CHAR LIMIT=NONE] -->
+    <string name="blocked_numbers_disabled_emergency_desc">
+        Call blocking has been disabled because you contacted emergency services from this phone
+        within the last 48 hours. It will be automatically reenabled once the 48 hour period
+        expires.
+    </string>
+
     <!-- Label for fragment to import numbers from contacts marked as send to voicemail.
          [CHAR_LIMIT=30] -->
     <string name="import_send_to_voicemail_numbers_label">Import numbers</string>
@@ -859,10 +874,6 @@
         [CHAR LIMIT=NONE]-->
     <string name="description_blocked_number_list_delete">Unblock number</string>
 
-    <!-- Displayed in the blocked numbers list when there are no blocked numbers.
-        [CHAR LIMIT=NONE] -->
-    <string name="listNoBlockedNumbers">No blocked numbers</string>
-
     <!-- Button to bring up UI to add a number to the blocked call list. [CHAR LIMIT=40] -->
     <string name="blockNumber">Add number</string>
 
diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
index c478b83..7788cbe 100644
--- a/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
+++ b/src/com/android/dialer/filterednumber/BlockedNumbersFragment.java
@@ -52,6 +52,7 @@
 
     private Switch mHideSettingSwitch;
     private View mImportSettings;
+    private View mBlockedNumbersDisabledForEmergency;
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
@@ -80,6 +81,8 @@
         });
 
         mImportSettings = getActivity().findViewById(R.id.import_settings);
+        mBlockedNumbersDisabledForEmergency =
+                getActivity().findViewById(R.id.blocked_numbers_disabled_for_emergency);
 
         getActivity().findViewById(R.id.import_button).setOnClickListener(this);;
         getActivity().findViewById(R.id.view_numbers_button).setOnClickListener(this);
@@ -122,8 +125,14 @@
                     }
                 });
 
-        mHideSettingSwitch.setChecked(FilteredNumbersUtil.shouldHideBlockedCalls(getActivity()));
+        mHideSettingSwitch.setChecked(FilteredNumbersUtil.shouldHideBlockedCalls(getContext()));
         mCallLogQueryHandler.fetchVoicemailStatus();
+
+        if (FilteredNumbersUtil.hasRecentEmergencyCall(getContext())) {
+            mBlockedNumbersDisabledForEmergency.setVisibility(View.VISIBLE);
+        } else {
+            mBlockedNumbersDisabledForEmergency.setVisibility(View.GONE);
+        }
     }
 
     @Override
diff --git a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
index 8bfcea0..b042330 100644
--- a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
+++ b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java
@@ -44,6 +44,11 @@
 public class FilteredNumbersUtil {
 
     private static final String HIDE_BLOCKED_CALLS_PREF_KEY = "hide_blocked_calls";
+    // Pref key for storing the time, in milliseconds after epoch, of end of the last emergency call.
+    private static final String LAST_EMERGENCY_CALL_PREF_KEY = "last_emergency_call";
+
+    // Disable incoming call blocking if there was a call within the past 2 days.
+    private static final long EMERGENCY_CALL_RECENCY_THRESHOLD_MS = 1000 * 60 * 60 * 24 * 2;
 
     public interface CheckForSendToVoicemailContactListener {
         public void onComplete(boolean hasSendToVoicemailContact);
@@ -238,7 +243,32 @@
         }
         PreferenceManager.getDefaultSharedPreferences(context)
                 .edit()
-                .putBoolean(FilteredNumbersUtil.HIDE_BLOCKED_CALLS_PREF_KEY, shouldHide)
+                .putBoolean(HIDE_BLOCKED_CALLS_PREF_KEY, shouldHide)
+                .apply();
+    }
+
+    public static boolean hasRecentEmergencyCall(Context context) {
+        if (context == null) {
+            return false;
+        }
+
+        Long lastEmergencyCallTime = PreferenceManager.getDefaultSharedPreferences(context)
+                .getLong(LAST_EMERGENCY_CALL_PREF_KEY, 0);
+        if (lastEmergencyCallTime == 0) {
+            return false;
+        }
+
+        return (System.currentTimeMillis() - lastEmergencyCallTime)
+                    < EMERGENCY_CALL_RECENCY_THRESHOLD_MS;
+    }
+
+    public static void recordLastEmergencyCallTime(Context context) {
+        if (context == null) {
+            return;
+        }
+        PreferenceManager.getDefaultSharedPreferences(context)
+                .edit()
+                .putLong(LAST_EMERGENCY_CALL_PREF_KEY, System.currentTimeMillis())
                 .apply();
     }