Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2dd62788 authored by Brandon Maxwell's avatar Brandon Maxwell
Browse files

Checking for recent emergency call before deleting voiemail

Bug: 25818151
Change-Id: I6b8b5ebfe1c9555b8394ad7db652e23bbc216f83
parent 9650e1bb
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -31,10 +31,6 @@ import android.telephony.PhoneNumberUtils;
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.database.FilteredNumberContract.FilteredNumberColumns;
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 @@ public class FilteredNumbersUtil {
    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 @@ public class FilteredNumbersUtil {
            return false;
        }

        if (hasRecentEmergencyCall(context)) {
            return false;
        }

        final Cursor cursor = context.getContentResolver().query(
                FilteredNumber.CONTENT_URI,
                new String[] {
+18 −0
Original line number Diff line number Diff line
@@ -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 class FilteredNumbersUtilTest extends AndroidTestCase {
    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 @@ public class FilteredNumbersUtilTest extends AndroidTestCase {
                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)